blob: 26ebd18f4ce99238f7db4af2e3a062d444f01834 [file] [log] [blame]
xf.li771eb062025-02-09 23:05:11 -08001/**************************************************************************
2*
3* Copyright (c) 2013 ZTE Corporation.
4*
5***************************************************************************
6* Ä£ ¿é Ãû : sms
7* ÎÄ ¼þ Ãû : sms_main.c
8* Ïà¹ØÎļþ :
9* ʵÏÖ¹¦ÄÜ : SMSÏûÏ¢Á÷³Ì¿ØÖÆ´¦Àí
10* ×÷ Õß : ÕÅ·Ò
11* °æ ±¾ : V1.0
12* Íê³ÉÈÕÆÚ : 2017.2.9
13* ÆäËü˵Ã÷ :
14**************************************************************************/
15
16/**************************************************************************
17* #includeÇø
18**************************************************************************/
xf.libfc6e712025-02-07 01:54:34 -080019#include <errno.h>
20#include <sys/msg.h>
21#include <semaphore.h>
22#include <limits.h>
23#include <pthread.h>
xf.li771eb062025-02-09 23:05:11 -080024
xf.libfc6e712025-02-07 01:54:34 -080025#include "sms_code.h"
xf.li771eb062025-02-09 23:05:11 -080026/**************************************************************************
27* ³£Á¿¶¨ÒåÇø
28**************************************************************************/
29//#define MODULE_ID_SMS_LOCAL 0x2001
30/**************************************************************************
31* Êý¾Ý½á¹¹¶¨ÒåÇø
32**************************************************************************/
33typedef VOID (*pAtWeb_SmsMsgProc)(UINT8 *pDatabuf);
34
35typedef struct
36{
37 UINT32 msg_id;
38 VOID (*func_ptr)(UINT8 *pDatabuf);
39 BOOL need_block;//ÊÇ·ñÐèÒª×èÈû£¬Èç¹û×èÈû£¬ÐèÒª½«ÏûϢתµ½ÄÚ²¿Ï̴߳¦Àí
40}T_zSmsHandleTable;
41
42
43/**************************************************************************
44* staticº¯ÊýÉùÃ÷Çø
45**************************************************************************/
46
47VOID atWeb_SendSms(UINT8 *pDatabuf);
48VOID atWeb_DelSmsByIndex(UINT8 *pDatabuf);
49VOID atWeb_DelSmsByType(UINT8 *pDatabuf);
50VOID atWeb_ReadSms(UINT8 *pDatabuf);
51VOID atWeb_SaveSms(UINT8 *pDatabuf);
52VOID atWeb_SetSms(UINT8 *pDatabuf);
53VOID atWeb_OutdateSmsCheck(UINT8 *pDatabuf);
54
55int zSms_SendZmgrReq(int index);
56
57/**************************************************************************
58* È«¾Ö±äÁ¿¶¨ÒåÇø
59**************************************************************************/
60extern UINT8 g_zUfiSms_MemFullFlag[ZTE_WMS_MEMORY_MAX];
61extern T_zSms_SendSmsReq g_zUfiSms_FinalCmgsBuf;
62extern int g_zUfiSms_CurConcatSegNo;
63extern T_zUfiSms_DbStoreData g_zUfiSms_DbStoreData[ZTE_WMS_CONCAT_SMS_COUNT_MAX];
64extern int g_zUfiSms_SendFailedCount;
65extern int g_zUfiSms_ConcatTotalNum;
66extern UINT8 g_zUfiSms_IsConcatSendSuc;
67
68//ÔÚcmgrÇëÇóÖмǼindex£¬ÓÃÓÚÓ¦´ðÏûÏ¢ÖеĴ洢
69int iSmsIndex = 0;
70int g_zSms_MsqId = -1;
71int g_zSms_LocalMsqId = -1;
72sem_t g_sms_sem_id;
73T_zSms_optRsp g_smsOptRsp = {0};
74
75
76static const T_zSmsHandleTable SmsHandleWebTab[] =
77{
78 {MSG_CMD_SEND_SMS, atWeb_SendSms, TRUE},
79 {MSG_CMD_DEL_SMS_BY_INDEX, atWeb_DelSmsByIndex, TRUE},
80 //{MSG_CMD_DEL_SMS_BY_TYPE, atWeb_DelSmsByType},
81 {MSG_CMD_SMS_MODIFY_TAG, atWeb_ReadSms, TRUE},
82 {MSG_CMD_DRAFTS_SAVE, atWeb_SaveSms, FALSE}, //corem
83 {MSG_CMD_SMS_LOCATION_SET, atWeb_SetSms, TRUE},
84 {MSG_CMD_SMS_OUTDATE_CHECK, atWeb_OutdateSmsCheck, TRUE},
85 {0, NULL, FALSE}
86};
87
88
89/**************************************************************************
90* º¯ÊýʵÏÖÇø
91**************************************************************************/
92
93// pDatabufΪpstMsg->aucDataBuf
94VOID atWeb_SendSms(UINT8 *pDatabuf)
95{
96 T_zGoaheadMsgBuf *ptMessage = NULL;
97 T_zUfiSms_StatusInfo tStatus = {0};
98 assert(pDatabuf != NULL);
99
100 ptMessage = (T_zGoaheadMsgBuf *)pDatabuf;
101
102 zUfiSms_InitCmdStatus(&tStatus,WMS_SMS_CMD_MSG_SEND);
103
104
105 //pthread_mutex_lock(&smsdb_mutex);
106 (void)zUfiSms_SendRawSms((T_zUfiSms_SendReq *)ptMessage->msg_data);
107 //pthread_mutex_unlock(&smsdb_mutex);
108}
109
110VOID atWeb_DelSmsByIndex(UINT8 *pDatabuf)
111{
112 T_zUfiSms_DelReq tDelReq = {0};
113 T_zUfiSms_CmdStatus result = WMS_CMD_PROCESSING;
114 T_zUfiSms_StatusInfo tStatus = {0};
115 assert(pDatabuf != NULL);
116
117 printf("[SMS] atWeb_DelSmsByIndex recv msg\n");
118 memcpy(&tDelReq, pDatabuf,sizeof(T_zUfiSms_DelReq));
119
120 zUfiSms_InitCmdStatus(&tStatus,WMS_SMS_CMD_MSG_DELETE);
121 result = zUfiSms_DeleteSms(&tDelReq);
122
123 tStatus.cmd_status = result;
124 (void)zUfiSms_SetCmdStatus(&tStatus);
125 zUfiMmi_SendSmsStatus();
126}
127
128VOID atWeb_DelSmsByType(UINT8 *pDatabuf)
129{
130 #if 0
131 WEB_DEL_SMS_BY_TYPE *req = NULL;
132 req = (WEB_DEL_SMS_BY_TYPE *)pDatabuf;
133 assert(req != NULL);
134 if(req->eLocation != ZSMS_LOCATION_SIM)
135 {
136 ZTE_LOG(LOG_ERR, "zSms_PrepDelByType para NULL.\n");
137 return;
138 }
139 zSms_ChangeMainState(ZSMS_STATE_DELING);
140 ZTE_LOG(LOG_DEBUG, "zSms_PrepDelByType pstReq->eBoxName=%d\n",req->eBoxName);
141 SMS_DeleteRecordFromXML(SMS_LOCATION_SIM, 0, req->eBoxName);
142 if (req->eBoxName == SMS_INBOX)
143 {
144 sms_LoadSmsFromSim();
145 }
146 #endif
147}
148//¶ÌÐÅ״̬ÓÉδ¶Á±äΪÒѶÁ
149VOID atWeb_ReadSms(UINT8 *pDatabuf)
150{
151 T_zGoaheadMsgBuf * ptMessage = NULL;
152 T_zUfiSms_CmdStatus result = WMS_CMD_PROCESSING;
153 T_zUfiSms_StatusInfo tStatus = {0};
154 assert(pDatabuf != NULL);
155
156 ptMessage = (T_zGoaheadMsgBuf *)pDatabuf;
157
158 zUfiSms_InitCmdStatus(&tStatus,WMS_SMS_CMD_MSG_MODIFY_TAG);
159 result = zUfiSms_ModifySmsTag((T_zUfiSms_ModifyFlag *)ptMessage->msg_data);
160
161 tStatus.cmd_status = result;
162 (void)zUfiSms_SetCmdStatus(&tStatus);
163}
164
165VOID atWeb_SaveSms(UINT8 *pDatabuf)
166{
167 T_zGoaheadMsgBuf * ptMessage = NULL;
168 T_zUfiSms_CmdStatus result = WMS_CMD_PROCESSING;
169 T_zUfiSms_StatusInfo tStatus = {0};
170 assert(pDatabuf != NULL);
171
172 ptMessage = (T_zGoaheadMsgBuf *)pDatabuf;
173
174 zUfiSms_InitCmdStatus(&tStatus,WMS_SMS_CMD_MSG_WRITE);
175 result = zUfiSms_WriteRawSms((T_zUfiSms_SaveReq *)ptMessage->msg_data);
176
177 if(g_zUfiSms_MemFullFlag[ZTE_WMS_MEMORY_NV])
178 {
179 tStatus.err_code = ZTE_SMS_CMS_MEM_FULL;
180 printf("[SMS] atWeb_SaveSms mem full\n");
181 }
182 tStatus.cmd_status = result;
183 (void)zUfiSms_SetCmdStatus(&tStatus);
184
185 //zSms_ChangeMainState(ZSMS_STATE_SAVING);
186 zUfiSms_ChangeMainState(SMS_STATE_SAVING);
187 sc_cfg_set(NV_SMS_SAVE_RESULT, "ok");
188
189}
190
191VOID atWeb_SetSms(UINT8 *pDatabuf)
192{
193 T_zGoaheadMsgBuf * ptMessage = NULL;
194 T_zUfiSms_CmdStatus result = WMS_CMD_PROCESSING;
195 T_zUfiSms_StatusInfo tStatus = {0};
196
197 printf( "INTO atWeb_SetSms.\n");
198
199 assert(pDatabuf != NULL);
200
201 ptMessage = (T_zGoaheadMsgBuf *)pDatabuf;
202
203 zUfiSms_InitCmdStatus(&tStatus,WMS_SMS_CMD_CFG_SET_PARAMETERS);
204 result = zUfiSms_SetSmsPara((T_zUfiSms_ParaInfo *)ptMessage->msg_data);
205
206 tStatus.cmd_status = result;
207 (void)zUfiSms_SetCmdStatus(&tStatus);
208}
209
210VOID atWeb_OutdateSmsCheck(UINT8 *pDatabuf)
211{
212 T_zUfiSms_DelReq tSmsDel = {0};
213
214 zUfiSms_CheckDbOutdateSms(ZTE_WMS_DB_NV_TABLE, &tSmsDel);
215 printf("----out coun nvt: %d----\n",tSmsDel.all_or_count);
216 //for(i=0;i<tSmsDel.all_or_count;i++)printf("----out id: %d----\n",tSmsDel.id[i]);
217
218 if(tSmsDel.all_or_count > 0)
219 {
220 atWeb_DelSmsByIndex(&tSmsDel);
221 }
222
223 memset(&tSmsDel, 0, sizeof(T_zUfiSms_DelReq));
224 zUfiSms_CheckDbOutdateSms(ZTE_WMS_DB_SIM_TABLE, &tSmsDel);
225 printf("----out count sim: %d----\n",tSmsDel.all_or_count);
226 //for(i=0;i<tSmsDel.all_or_count;i++)printf("----out id: %d----\n",tSmsDel.id[i]);
227
228 if(tSmsDel.all_or_count > 0)
229 {
230 atWeb_DelSmsByIndex(&tSmsDel);
231 }
232}
233
234VOID zSms_HandleWebMsg(MSG_BUF *ptMsgBuf)
235{
236 UINT32 i = 0;
237 assert(ptMsgBuf != NULL);
238
239 printf("sms recv msg from webserver:%d\n", ptMsgBuf->usMsgCmd);
240 while(0 != SmsHandleWebTab[i].msg_id)
241 {
242 if(ptMsgBuf->usMsgCmd == SmsHandleWebTab[i].msg_id)
243 {
244 if(SmsHandleWebTab[i].need_block && ptMsgBuf->src_id != MODULE_ID_SMS)
245 {
246 ipc_send_message(MODULE_ID_SMS, MODULE_ID_SMS_LOCAL, ptMsgBuf->usMsgCmd, ptMsgBuf->usDataLen, (unsigned char *)ptMsgBuf->aucDataBuf, 0);
247 }
248 else if(NULL != SmsHandleWebTab[i].func_ptr)
249 {
250 SmsHandleWebTab[i].func_ptr(ptMsgBuf->aucDataBuf);
251 }
252 break;
253 }
254 i++;
255 }
256}
257
258
259//
260SINT32 zSms_SendMsg(USHORT Msg_cmd,USHORT us_DataLen,UCHAR *pData)
261{
262 printf( "sms send msg cmd:%d\n", Msg_cmd);
263 ipc_send_message(MODULE_ID_SMS, MODULE_ID_AT_CTL, Msg_cmd, us_DataLen, (unsigned char *)pData,0);
264
265 return 0;
266}
267
268
269/*¶ÔÓ¦atSms_SendCmgsReq*/
270SINT32 zSms_SendCmgsReq(VOID)
271{
272 T_zSms_SendSmsReq sendSmsInfo = {0};
273
274 memset(&sendSmsInfo, 0x00, sizeof(T_zSms_SendSmsReq));
275 sendSmsInfo.length = g_zUfiSms_FinalCmgsBuf.length;
276
277 if(strlen(g_zUfiSms_FinalCmgsBuf.pdu)< ZSMS_PDU_SIZE-1)
278 {
279 memcpy(sendSmsInfo.pdu, g_zUfiSms_FinalCmgsBuf.pdu, strlen(g_zUfiSms_FinalCmgsBuf.pdu));
280 }
281 else
282 {
283 printf("[SMS] atSms_SendCmgsReq pdu too long:%s\n",g_zUfiSms_FinalCmgsBuf.pdu);
284 memcpy(sendSmsInfo.pdu, g_zUfiSms_FinalCmgsBuf.pdu, ZSMS_PDU_SIZE-2);
285 }
286 // Ìí¼Ó½áβ·û
287 *(sendSmsInfo.pdu + strlen(g_zUfiSms_FinalCmgsBuf.pdu)) = ZSMS_CTRL_Z_CHAR;
288#if 1//corem for debug
289 printf("[SMS] atSms_SendCmgsReq send data\n");
290 printf("\n[SMS]%s\n",sendSmsInfo.pdu);
xf.libfc6e712025-02-07 01:54:34 -0800291#endif
xf.li771eb062025-02-09 23:05:11 -0800292
293 zSms_SendMsg(MSG_CMD_SENDSMS_REQ, sizeof(T_zSms_SendSmsReq), &sendSmsInfo);
294
295 sem_wait(&g_sms_sem_id);
296
297 if(g_smsOptRsp.result == 1)
298 {
299 return ZSMS_RESULT_OK;
300 }
301 else
302 {
303 return ZSMS_RESULT_ERROR;
304 }
305}
306
307VOID zSms_RecvCmgsOk(VOID)
308{
309 printf("sms sended success. \n");
310 g_zUfiSms_CurConcatSegNo++;
311
312 if(g_zUfiSms_CurConcatSegNo > ZTE_WMS_CONCAT_SMS_COUNT_MAX)
313 {
314 return;
315 }
316
317 //·¢Ëͳɹ¦Ò»½Ú
318 g_zUfiSms_DbStoreData[g_zUfiSms_CurConcatSegNo-1].tag = WMS_TAG_TYPE_MO_SENT_V01;
319
320 zUfiSms_CmgsRespProc();
321}
322
323VOID zSms_RecvCmgsErr(VOID)
324{
325 printf("sms sended fail. \n");
326 g_zUfiSms_CurConcatSegNo++;
327 if(g_zUfiSms_CurConcatSegNo > ZTE_WMS_CONCAT_SMS_COUNT_MAX)
328 {
329 return;
330 }
331
332 //ʧ°ÜÊýÁ¿£¬×îÖÕдÈëÊý¾Ý¿â
333 g_zUfiSms_SendFailedCount++;
334
335 printf("send sms failed,so write sms to draftbox.\n");
336 g_zUfiSms_DbStoreData[g_zUfiSms_CurConcatSegNo-1].tag = WMS_TAG_TYPE_MO_NOT_SENT_V01;
337 if(g_zUfiSms_ConcatTotalNum > 1)
338 {
339 // ³¤¶ÌÐÅ·¢ËÍʧ°Ü£¬ÖÃΪfalse
340 g_zUfiSms_IsConcatSendSuc = FALSE;
341 }
342
343 zUfiSms_CmgsRespProc();
344}
345
346/*¶ÔÓ¦atSms_SendCmgdReq*/
347SINT32 zSms_SendCmgdReq(UINT8 index)
348{
349 T_zSms_DelSmsReq delSmsReq = {0};
350
351 delSmsReq.index = index;
352
353 zSms_SendMsg(MSG_CMD_DELSMS_REQ, sizeof(T_zSms_DelSmsReq), &delSmsReq);
354
355 sem_wait(&g_sms_sem_id);
356
357 if(g_smsOptRsp.result == 1)
358 {
359 return ZSMS_RESULT_OK;
360 }
361 else
362 {
363 return ZSMS_RESULT_ERROR;
364 }
365}
366
367VOID zSms_RecvCmgdOk(VOID)
368{
369 CHAR strUsed[10] = {0};
370 int used = 0;
371 int tmp_i = 0;
372
373 sc_cfg_set(NV_SMS_DEL_RESULT, "ok");
374 printf("[SMS] set sim_del_result to OK. \n");
375
376 sc_cfg_get(ZTE_WMS_NVCONFIG_SIM_CARD_USED,strUsed,sizeof(strUsed));
377
378 tmp_i = atoi(strUsed); //kw 3
379 if(tmp_i < 0 || tmp_i > INT_MAX-1) {
380 at_print(LOG_ERR,"[SMS]WMS_NVCONFIG_SIM_CARD_USED tmp_i err:%d\n", tmp_i);
381 tmp_i = 0;
382 }
383
384 used = tmp_i - 1;
385 if(used < 0)
386 {
387 used = 0;
388 }
389 memset(&strUsed, 0, 10);
390 snprintf(strUsed,sizeof(strUsed),"%d", used);
391 sc_cfg_set(ZTE_WMS_NVCONFIG_SIM_CARD_USED, strUsed);
392}
393
394VOID zSms_RecvCmgdErr(VOID)
395{
396
397 sc_cfg_set(NV_SMS_DEL_RESULT, "fail");
398 printf("[SMS] set sim_del_result to fail. \n");
399}
400
401VOID zSms_RecvCmgdFinish(VOID)
402{
403 char StrValue[10] = {0};
404 CHAR strTotal[10] = {0};
405 CHAR strUsed[10] = {0};
406 int total = 0;
407 int used = 0;
408 int remain = 0;
409
410 sc_cfg_get(ZTE_WMS_NVCONFIG_SIM_CARD_USED,strUsed,sizeof(strUsed));
411 used = atoi(strUsed);
412 if(used < 0 || used > INT_MAX-1) { //kw 3
413 at_print(LOG_ERR,"[SMS]WMS_NVCONFIG_SIM_CARD_USED err:%d\n", used);
414 used = 0;
415 }
416 sc_cfg_get(ZTE_WMS_NVCONFIG_SIM_CARD_TOTAL,strTotal,sizeof(strTotal));
417 total = atoi(strTotal);
418 if(total < 0 || total > INT_MAX-1) { //kw 3
419 at_print(LOG_ERR,"[SMS]WMS_NVCONFIG_SIM_CARD_TOTAL err:%d\n", total);
420 total = 0;
421 }
422
423 remain = total - used;
424 if(remain < 0)
425 {
426 remain = 0;
427 }
428
429 memset(&StrValue, 0, 10);
430 snprintf(StrValue,sizeof(StrValue),"%d", remain);
431 sc_cfg_set(ZTE_WMS_NVCONFIG_SIM_CARD_REMAIN,StrValue);
432 printf("[SMS] zUfiSms_DeleteSimSms used=%d,remain=%d,total=%d\n",used,remain,total);
433 zUfiSms_ChangeMainState(SMS_STATE_DELED);
434 sc_cfg_set(NV_SMS_DB_CHANGE,"1");
435}
436
437/*¶ÔÓ¦atSms_SendZmenaReq*/
438int zSms_SendZmenaReq(SINT32 avail)
439{
440 T_zSms_StroageReq storageReq = {0};
441
442 storageReq.type = avail;
443
444 zSms_SendMsg(MSG_CMD_STORAGE_CAP_REQ, sizeof(T_zSms_StroageReq), &storageReq);
445
446 sem_wait(&g_sms_sem_id);
447
448 if(g_smsOptRsp.result == 1)
449 {
450 return ZSMS_RESULT_OK;
451 }
452 else
453 {
454 return ZSMS_RESULT_ERROR;
455 }
456}
457
458//SMS²»¹ØÐÄcmgrµÄÏìÓ¦
459/*¶ÔÓ¦atSms_SendCmgrReq*/
460int zSms_SendCmgrReq(UINT8 index)
461{
462 T_zSms_ModifyTagReq modTagReq = {0};
463
464 modTagReq.index = index;
465
466 zSms_SendMsg(MSG_CMD_MODIFY_TAG_REQ, sizeof(T_zSms_ModifyTagReq), &modTagReq);
467
468 sem_wait(&g_sms_sem_id);
469
470 if(g_smsOptRsp.result == 1)
471 {
472 return ZSMS_RESULT_OK;
473 }
474 else
475 {
476 return ZSMS_RESULT_ERROR;
477 }
478}
479
480/*¶ÔÓ¦ atBase_SendAtCscaSetReq*/
481int zSms_SetCscaReq(PSTR sca)
482{
483 T_zSms_SetScaReq setscareq;
484
485 strncpy(setscareq.sca, sca, sizeof(setscareq.sca)-1);
486
487 zSms_SendMsg(MSG_CMD_SCA_SET_REQ, sizeof(T_zSms_SetScaReq), &setscareq);
488
489 sem_wait(&g_sms_sem_id);
490
491 if(g_smsOptRsp.result == 1)
492 {
493 return ZSMS_RESULT_OK;
494 }
495 else
496 {
497 return ZSMS_RESULT_ERROR;
498 }
499}
500
501/*¶ÔÓ¦atBase_SendAtCnmiReq*/
502int zSms_SendCnmiReq(PSTR pAtCmdPara)
503{
504 T_zSms_NotifySetReq notifySetReq = {0};
505
506 if(0 == strcmp(pAtCmdPara, "sim"))
507 {
508 notifySetReq.mt = 1;
509 }
510 else
511 {
512 notifySetReq.mt = 2;
513 }
514
515 zSms_SendMsg(MSG_CMD_NOTIFY_SET_REQ, sizeof(T_zSms_NotifySetReq), &notifySetReq);
516
517 sem_wait(&g_sms_sem_id);
518
519 if(g_smsOptRsp.result == 1)
520 {
521 return ZSMS_RESULT_OK;
522 }
523 else
524 {
525 return ZSMS_RESULT_ERROR;
526 }
527}
528
529/*¶ÔÓ¦atSms_RecvCmtRsp*/
530VOID zSms_RecvCmtInd(UINT8 *pDatabuf)
531{
532 //ÅжÏÊÇ·ñÖ§³ÖSMS
533 //added by wenqin 2016-5-18
534 CHAR needSMS[50] = {0};
535
536 sc_cfg_get(NV_NEED_SUPPORT_SMS,needSMS,sizeof(needSMS));
537 if(0 == strcmp(needSMS, "no"))
538 {
539 printf("[SMS]atSms_RecvCmtRsp needSMS=no!");
540 return;
541 }
542
543 T_zSms_SmsInd tCmtRsp = {0};
544
545 memcpy(&tCmtRsp, (T_zSms_SmsInd*)pDatabuf, sizeof(T_zSms_SmsInd));
546
547 //pthread_mutex_lock(&smsdb_mutex);
548 zUfiSms_CmtRespProc(&tCmtRsp);
549 zUfiMmi_SendSmsStatus();
550 //pthread_mutex_unlock(&smsdb_mutex);
551 sc_cfg_set(NV_SMS_RECV_RESULT, "ok");
552
553}
554
555/*¶ÔÓ¦atSms_RecvCmtiRsp */
556VOID zSms_RecvCmtiInd(UINT8 *pDatabuf)
557{
558 char sms_Main_state[30] = {0};
559 T_zSms_SmsIndexInd *smsIdxInd = (T_zSms_SmsIndexInd*)pDatabuf;
560
561 //ÅжÏÊÇ·ñÖ§³ÖSMS
562 //added by wenqin 2016-5-18
563 CHAR needSMS[50] = {0};
564 sc_cfg_get(NV_NEED_SUPPORT_SMS,needSMS,sizeof(needSMS));
565 if(0 == strcmp(needSMS, "no"))
566 {
567 printf("[SMS]atSms_RecvCmtRsp needSMS=no!");
568 return;
569 }
570
571 //ɾ³ý¹ý³ÌÖв»½ÓÊÜжÌÐÅ
572 sc_cfg_get(NV_SMS_STATE,sms_Main_state,sizeof(sms_Main_state));
573 if(strcmp(sms_Main_state,"sms_deling")==0)
574 {
575 printf("[SMS] atSms_RecvCmtiRsp: sms_deling\n");
576 return;
577 }
578
579 if(0 == strncmp("SM", smsIdxInd->storetype, 2))
580 {
581 zUfiSms_SetSmsLocation(SMS_LOCATION_SIM);
582 zUfiSms_ChangeMainState(SMS_STATE_RECVING);
583 //send ZMGR
584 zSms_SendZmgrReq(smsIdxInd->index);
585 }
586 else //Ä£¿éÔÚÖØÆôºó¾­³£³öÏÖ¶ÌÐŴ洢λÖÃΪSRµÄÇé¿ö
587 {
588 printf("[SMS] atSms_RecvCmtiRsp :store location not SM.\n");
589 }
590 sc_cfg_set(NV_SMS_RECV_RESULT, "");
591}
592
593/*¶ÔÓ¦atSms_RecvCdsRsp*/
594VOID zSms_RecvCdsInd(UINT8 *pDatabuf)
595{
596 //ÅжÏÊÇ·ñÖ§³ÖSMS
597 //added by wenqin 2016-5-18
598 CHAR needSMS[50] = {0};
599 sc_cfg_get(NV_NEED_SUPPORT_SMS,needSMS,sizeof(needSMS));
600 if(0 == strcmp(needSMS, "no"))
601 {
602 printf("[SMS]atSms_RecvCmtRsp needSMS=no!");
603 return;
604 }
605
606 T_zSms_SmsInd tCmtRsp = {0};
607
608 memcpy(&tCmtRsp, (T_zSms_SmsInd*)pDatabuf, sizeof(T_zSms_SmsInd));
609
610 //pthread_mutex_lock(&smsdb_mutex);
611 zUfiSms_CdsRespProc(&tCmtRsp);
612 zUfiMmi_SendSmsStatus();
613 //pthread_mutex_unlock(&smsdb_mutex);
614 sc_cfg_set(NV_SMS_RECV_RESULT, "ok");
615}
616
617
618/*¶ÔÓ¦atSms_RecvCdsiRsp*/
619VOID zSms_RecvCdsiInd(UINT8 *pDatabuf)
620{
621 char sms_Main_state[30] = {0};
622 T_zSms_SmsIndexInd *smsIdxInd = (T_zSms_SmsIndexInd*)pDatabuf;
623
624 //ÅжÏÊÇ·ñÖ§³ÖSMS
625 //added by wenqin 2016-5-18
626 CHAR needSMS[50] = {0};
627 sc_cfg_get(NV_NEED_SUPPORT_SMS,needSMS,sizeof(needSMS));
628 if(0 == strcmp(needSMS, "no"))
629 {
630 printf("[SMS]atSms_RecvCmtRsp needSMS=no!");
631 return;
632 }
633
634 //ɾ³ý¹ý³ÌÖв»½ÓÊÜжÌÐÅ
635 sc_cfg_get(NV_SMS_STATE,sms_Main_state,sizeof(sms_Main_state));
636 if(strcmp(sms_Main_state,"sms_deling")==0)
637 {
638 printf("[SMS] atSms_RecvCdsiRsp: sms_deling\n");
639 return;
640 }
641
642 if(0 == strncmp("SM", smsIdxInd->storetype, 2))
643 {
644 zUfiSms_SetSmsLocation(SMS_LOCATION_SIM);
645 zUfiSms_ChangeMainState(SMS_STATE_RECVING);
646 //send ZMGR
647 zSms_SendZmgrReq(smsIdxInd->index);
648 }
649 else //Ä£¿éÔÚÖØÆôºó¾­³£³öÏÖ¶ÌÐŴ洢λÖÃΪSRµÄÇé¿ö
650 {
651 printf("[SMS] atSms_RecvCdsiRsp :store location not SM.\n");
652 }
653 sc_cfg_set(NV_SMS_RECV_RESULT, "");
654}
655
656
657/*¶ÔÓ¦atSms_SendCnmaReq*/
658int zSms_SendCnmaReq(int ack_mode)
659{
660 T_zSms_SmsAckReq ackReq = {0};
661 CHAR ackPduStr[50] = {0};
662
663 ackReq.ackmode = ack_mode;
664
665 if(ack_mode == 2)
666 {
667 zUfiSms_EncodePdu_DeliverReport(ackPduStr, 0xD3);
668 memcpy(ackReq.pdu, ackPduStr, strlen(ackPduStr));
669#if 0
670 if(strlen(ackPduStr)< ZSMS_PDU_SIZE-1)
671 {
672 memcpy(ackReq.pdu, ackPduStr, strlen(ackPduStr));
673 }
674 else
675 {
676 at_print(LOG_DEBUG"[SMS] atSms_SendCnmaReq pdu too long:%s\n",ackPduStr);
677 memcpy(ackReq.pdu, ackPduStr, ZSMS_PDU_SIZE-2);
678 }
xf.libfc6e712025-02-07 01:54:34 -0800679#endif
xf.li771eb062025-02-09 23:05:11 -0800680 // Ìí¼Ó½áβ·û
681 *(ackReq.pdu + strlen(ackPduStr)) = ZSMS_CTRL_Z_CHAR;
682 printf("[SMS] atSms_SendCnmaReq. pdu= %s\n", ackReq.pdu);
683
684 ackReq.length = strlen(ackPduStr)/2;
685 }
686
687 zSms_SendMsg(MSG_CMD_SMSACK_REQ, sizeof(T_zSms_SmsAckReq), &ackReq);
688
689 sem_wait(&g_sms_sem_id);
690
691 if(g_smsOptRsp.result == 1)
692 {
693 return ZSMS_RESULT_OK;
694 }
695 else
696 {
697 return ZSMS_RESULT_ERROR;
698 }
699}
700
701
702/*¶ÔÓ¦atSms_SendZmgrReq*/
703int zSms_SendZmgrReq(int index)
704{
705 T_zSms_ReadSmsReq readSmsReq = {0};
706
707 iSmsIndex = index;
708 printf("[SMS] atSms_SendZmgrReq Get index:%d.\n",iSmsIndex);
709
710 readSmsReq.index = index;
711 zSms_SendMsg(MSG_CMD_READSMS_REQ, sizeof(T_zSms_ReadSmsReq), &readSmsReq);
712
713 //´Ë´¦²»ÄÜ×èÈûµÈ´ý
714 return 0;
715}
716
717/*¶ÔÓ¦atSms_RecvZmgrRsp */
718VOID zSms_RecvZmgrRsp(UINT8 *pDatabuf)
719{
720 T_zSms_SmsInd tCmgrRsp = {0};
721
722 memcpy(&tCmgrRsp, (T_zSms_SmsInd*)pDatabuf, sizeof(T_zSms_SmsInd));
723
724 tCmgrRsp.index = iSmsIndex;
725
726 zUfiSms_ZmgrRespProc(&tCmgrRsp);
727 zUfiMmi_SendSmsStatus();
728
729}
730
731VOID zSms_RecvZmgrOk(UINT8 *pDatabuf)
732{
733 T_zSms_optRsp smsOptRsp = {0};
734
735 memcpy(&smsOptRsp, (T_zSms_optRsp*)pDatabuf, sizeof(T_zSms_optRsp));
736 if(smsOptRsp.result == 1)
737 {
738 sc_cfg_set(NV_SMS_RECV_RESULT, "ok");
739 }
740 else
741 {
742 printf("[SMS] atSms_RecvZmgrErr SMS zmgr is fail\n");
743
744 sc_cfg_set(NV_SMS_RECV_RESULT, "fail");
745 zUfiSms_ChangeMainState(SMS_STATE_RECVED);
746
747 }
748}
749
750VOID zSms_RecvZpbicInd(UINT8 *pDatabuf)
751{
752 T_zAt_ZpbicRes *ptPara = ZUFI_NULL;
753 if(pDatabuf == NULL)
754 {
755 return;
756 }
757 ptPara = (T_zAt_ZpbicRes*)(pDatabuf);
758
759 if((1 == ptPara->result) && (0 == ptPara->opertype))
760 {
761 //ÅжÏNV,added by wenqin 2016-5-18
762 CHAR needSms[50]={0};
763 sc_cfg_get(NV_NEED_SUPPORT_SMS,needSms,sizeof(needSms));
764 if(0 != strcmp(needSms,"no"))
765 {
766 zSvr_Zpbic_Sms_Init();
767 }
768 }
769}
770
771
772
773VOID zSms_RecvCpmsInd(UINT8 *pDatabuf)
774{
775 T_zSms_CpmsInd *cpmsInd = (T_zSms_CpmsInd*)pDatabuf;
776 CHAR strBuf[10] = {0};
777 int remainSpace = 0;
778
779 snprintf(strBuf,sizeof(strBuf),"%d", cpmsInd->total);
780 sc_cfg_set(ZTE_WMS_NVCONFIG_SIM_CARD_TOTAL,strBuf);
781 sc_cfg_set(ZTE_WMS_NVCONFIG_SIM_CAPABILITY,strBuf);
782
783 memset(&strBuf, 0, 10);
784 snprintf(strBuf,sizeof(strBuf),"%d", cpmsInd->used);
785 sc_cfg_set(ZTE_WMS_NVCONFIG_SIM_CARD_USED,strBuf);
786
787 remainSpace = cpmsInd->total - cpmsInd->used;
788 memset(&strBuf, 0, 10);
789 snprintf(strBuf,sizeof(strBuf),"%d", remainSpace);
790 sc_cfg_set(ZTE_WMS_NVCONFIG_SIM_CARD_REMAIN,strBuf);
791
792 sc_cfg_set(NV_SMS_STORE,"ok");
793
794}
795
796/**************************************************************************
797* º¯ÊýÃû³Æ: VOID atBase_PreProcRes(char *)
798* ¹¦ÄÜÃèÊö: Ô¤´¦Àí²ÎÊýÐк¯Êý¡£ÎªÁË·½±ã½âÎö²ÎÊýÐУ¬ÔÚ½âÎö֮ǰ£¬ÏÈÔ¤´¦Àí¸Ã²Î
799* ÊýÐУ¬¶ÔÓÚ·Ö¸î²ÎÊýµÄ¶ººÅ£¬ÓÿոñÌæ»»£¬¶ÔÓÚ×Ö·û´®ÐͲÎÊýÖеĿոñ
800* ÓÿոñÌæ»»·ûÌæ»»£¬¶ÔÓÚ±êʶ×Ö·û´®µÄË«ÒýºÅÓèÒÔɾ³ý£¬¶ÔÓÚ¿ÕµÄ×Ö·û
801* ²ÎÊý˵Ã÷: (IN) pParaLine : ´ýÔ¤´¦ÀíµÄ×Ö·û´®²ÎÊýÐУ»
802* (OUT)pParaLine : Ô¤´¦ÀíºóµÄ×Ö·û´®²ÎÊýÐУ»
803* ·µ »Ø Öµ:
804* ÆäËü˵Ã÷:ÒÆÖ²
805**************************************************************************/
806#define AT_CMD_MAX 64
807
808#define ZAT_TAB_REPLACE ((unsigned char )(0xFC)) /* ÖÆ±í·ûÌæ»»·û */
809#define ZAT_NULL_FILL ((unsigned char )(0xFD)) /* ¿Õ´®Õ¼Î»·û */
810#define ZAT_SPACE_REPLACE ((unsigned char )(0xFE)) /* ¿Õ¸ñÌæ»»·û */
811#define ZAT_LF_REPLACE ((unsigned char )(0xFB)) /* LFÌæ»»·û */
812#define ZAT_CR_REPLACE ((unsigned char )(0xFA)) /* CRÌæ»»·û */
813static void atBase_PreProcRes(char *pParaLine, int paraSize)//×Ö·û´®¸ñʽ»¯Ê¹Ó㬺óÐøÐèÒªÓÅ»¯£¬¼òµ¥»¯
814{
815 signed long flg = 0;
816 unsigned long i = 0;
817 unsigned long length = 0;
818 char *pSource = pParaLine;
819 char *pDest = NULL;
820
821 char *pStrDestMalloc = (char *)malloc(AT_CMD_MAX);
822 if(NULL == pStrDestMalloc)
823 {
824 return;
825 }
826 memset(pStrDestMalloc, 0, AT_CMD_MAX);
827
828 assert(pParaLine != NULL);
829 pDest = pStrDestMalloc;
830 length = strlen(pParaLine);
831 if ((length == 0) || (length >= AT_CMD_MAX))
832 {
833 free(pStrDestMalloc);
834 return;
835 }
836 for (i = 0; (i < length )&& (pDest - pStrDestMalloc < AT_CMD_MAX); i++)
837 {
838 if ('"' == *pSource)
839 {
840 flg = (0 == flg)?1:0; /* Ë«ÒýºÅ ɾ³ý */
841 if ('"' == *(pSource + 1)) /* ÐǺźóÃæ½ô¸úÐǺţ¬²åÈë¿Õ´®Õ¼Î»·û */
842 {
843 *pDest++ = (char)ZAT_NULL_FILL;
844 }
845 }
846 else if ((',' == *pSource) && (0 == flg))
847 {
848 *pDest++ = ' '; /* Ë«ÒýºÅÍâÃæµÄ¶ººÅ£¬Ìæ»»³É¿Õ¸ñ */
849 if(',' == *(pSource + 1)) /* ¶ººÅºóÃæ½ô¸ú¶ººÅ£¬»òÕßÒÔ¶ººÅ½á⣬²åÈë¿Õ´®Õ¼Î»·û */
850 {
851 *pDest++ = '9'; //±£Áô²ÎÊýÓÃ9ÔÝʱ´úÌæ
852 }
853 else if('\0' == *(pSource + 1)) /* ¶ººÅºóÃæ½ô¸ú¶ººÅ£¬»òÕßÒÔ¶ººÅ½á⣬²åÈë¿Õ´®Õ¼Î»·û */
854 {
855 *pDest++ = (char)ZAT_NULL_FILL;
856 }
857 }
858 else
859 {
860 //*pDest++ = ((' ' == *pSource) && (1 == flg))?(char)ZAT_SPACE_REPLACE:((('\t' == *pSource) && (1 == flg))?(char)ZAT_TAB_REPLACE:((('\n' == *pSource) && (1 == flg))?(char)ZAT_LF_REPLACE:((('\r' == *pSource) && (1 == flg))?(char)ZAT_CR_REPLACE:(*pSource))));
861 if((' ' == *pSource) && (1 == flg))
862 {
863 *pDest++ = (char)ZAT_SPACE_REPLACE;
864 }
865 else if(('\t' == *pSource) && (1 == flg))
866 {
867 *pDest++ = (char)ZAT_TAB_REPLACE;
868 }
869 else if(('\n' == *pSource) && (1 == flg))
870 {
871 *pDest++ = (char)ZAT_LF_REPLACE;
872 }
873 else if(('\r' == *pSource) && (1 == flg))
874 {
875 *pDest++ = (char)ZAT_CR_REPLACE;
876 }
877 else
878 {
879 *pDest++ = *pSource;
880 }
881 }
882 pSource++;
883 }
884 memset(pParaLine, 0, paraSize); /* ½«Ô¤´¦ÀíºóµÄÄÚÈÝ¿½±´»Ø²ÎÊýÐÐÖÐ */
885 strncpy(pParaLine, pStrDestMalloc,paraSize-1);
886 free(pStrDestMalloc);
887}
888
889//´æ´¢¶ÌÐÅÖÐÐÄ
890VOID zSms_RecvCscaInd(UINT8 *pDatabuf)
891{
892 T_zSms_CscaInd cscaInd = {0};
893
894 #if 1//corem for debug
895 printf("[SMScorem]zSms_RecvCscaInd databuf:%s\n",pDatabuf);
896 #endif
897 atBase_PreProcRes(pDatabuf, strlen(pDatabuf));
898
899 sscanf(pDatabuf, "%21s %21s", cscaInd.sca, cscaInd.tosca);
900 #if 1//corem for debug
901 printf("[SMScorem]zSms_RecvCscaInd sca:%s, tosca%s\n", cscaInd.sca, cscaInd.tosca);
902 #endif
903 sc_cfg_set(NV_SMS_CENTER_NUM,cscaInd.sca);
904 zUfiSms_SetScaPara(cscaInd.sca);
905}
906
907
908VOID zSms_RecvZmglInd(UINT8 *pDatabuf)
909{
910 zUfiSms_CmglRespProc((T_zSms_SmsInd*)pDatabuf);
911}
912
913
914int zSms_SendSmsInitReq(VOID)
915{
916 zSms_SendMsg(MSG_CMD_SMSINIT_REQ, 0, NULL);
917 return 0;
918}
919
920VOID zSms_initAtOk(VOID)
921{
922 T_zUfiSms_StatusInfo tStatus = {0};
923 //´Ë´¦»áµ¼ÖÂcmglÔÙ·¢Ò»´Î¼ÓÔØµ½ME´¦
924 //zUfiSms_ChangeMainState(SMS_STATE_LOADED);
925 sc_cfg_set(NV_SMS_STORE,"ok");
926
927 sc_cfg_set(NV_SMS_LOAD_RESULT, "ok");
928 tStatus.cmd_status = WMS_CMD_SUCCESS;
929 tStatus.cmd = WMS_SMS_CMD_INIT;
930 (void)zUfiSms_SetCmdStatus(&tStatus);
931 zUfiSms_ChangeMainState(SMS_STATE_LOADED);
932}
933
934VOID zSms_initAtErr(VOID)
935{
936 T_zUfiSms_StatusInfo tStatus = {0};
937
938 sc_cfg_set(NV_SMS_LOAD_RESULT, "fail");
939 zUfiSms_ChangeMainState(SMS_STATE_LOADED);
940
941 tStatus.cmd_status = WMS_CMD_FAILED;
942 tStatus.cmd = WMS_SMS_CMD_INIT;
943 (void)zUfiSms_SetCmdStatus(&tStatus);
944}
945
946VOID zSms_RecvSmsInitRst(UINT8 *pDatabuf)
947{
948 memcpy(&g_smsOptRsp, pDatabuf, sizeof(T_zSms_optRsp));
949
950 if(g_smsOptRsp.result == 1)
951 {
952 zSms_initAtOk();
953 }
954 else
955 {
956 zSms_initAtErr();
957 }
958}
959
960
961
962
963UINT8 zSms_SmsMsgCreat(VOID)
964{
965 g_zSms_MsqId = msgget(MODULE_ID_SMS, IPC_CREAT | 0600);
966 if(g_zSms_MsqId == -1)
967 {
968 return ZUFI_FAIL;
969 }
970 g_zSms_LocalMsqId = msgget(MODULE_ID_SMS_LOCAL, IPC_CREAT | 0600);
971 if(g_zSms_LocalMsqId == -1)
972 {
973 return ZUFI_FAIL;
974 }
975 sem_init(&g_sms_sem_id, 0 ,0);
976
977 return ZUFI_SUCC;
978}
979
980void zSms_HandleAtctlLocalMsg(MSG_BUF *ptMsgBuf)
981{
982 assert(ptMsgBuf != NULL);
983 printf( "sms local recv msg cmd:%d\n", ptMsgBuf->usMsgCmd);
984 switch(ptMsgBuf->usMsgCmd)
985 {
986 case MSG_CMD_ZPBIC_IND:
987 zSms_RecvZpbicInd(ptMsgBuf->aucDataBuf);
988 break;
989 case MSG_CMD_ZMGL_IND:
990 zSms_RecvZmglInd(ptMsgBuf->aucDataBuf);
991 break;
992 case MSG_CMD_NEWSMS_STATUS_IND:
993 zSms_RecvCdsInd(ptMsgBuf->aucDataBuf);
994 break;
995 case MSG_CMD_NEWSMS_IND:
996 zSms_RecvCmtInd(ptMsgBuf->aucDataBuf);
997 default:
998 break;
999
1000 }
1001}
1002
1003VOID zSms_HandleAtctlMsg(MSG_BUF *ptMsgBuf)
1004{
1005 assert(ptMsgBuf != NULL);
1006 printf( "sms recv msg cmd:%d\n", ptMsgBuf->usMsgCmd);
1007 switch(ptMsgBuf->usMsgCmd)
1008 {
1009 case MSG_CMD_SENDSMS_RSP:
1010 case MSG_CMD_DELSMS_RSP:
1011 case MSG_CMD_STORAGE_CAP_RSP:
1012 case MSG_CMD_MODIFY_TAG_RSP:
1013 case MSG_CMD_NOTIFY_SET_RSP:
1014 case MSG_CMD_SCA_SET_RSP:
1015 case MSG_CMD_SMSACK_RSP:
1016 {
1017 memcpy(&g_smsOptRsp, ptMsgBuf->aucDataBuf, sizeof(T_zSms_optRsp));
1018 sem_post(&g_sms_sem_id);
1019 }
1020 break;
1021 case MSG_CMD_CPMS_IND:
1022 zSms_RecvCpmsInd(ptMsgBuf->aucDataBuf);
1023 break;
1024 case MSG_CMD_CSCA_IND:
1025 zSms_RecvCscaInd(ptMsgBuf->aucDataBuf);
1026 break;
1027 case MSG_CMD_ZMGR_IND://ZMGR¶ÁÒ»Ìõ¶ÌÐÅÖÐ;µÄÉϱ¨ÐÅÏ¢
1028 zSms_RecvZmgrRsp(ptMsgBuf->aucDataBuf);
1029 break;
1030 case MSG_CMD_READSMS_RSP://ZMGR¶ÁÒ»Ìõ¶ÌÐŽáÊø£¬OK/ERROR
1031 zSms_RecvZmgrOk(ptMsgBuf->aucDataBuf);
1032 break;
1033 case MSG_CMD_SMSINIT_RSP:
1034 zSms_RecvSmsInitRst(ptMsgBuf->aucDataBuf);
1035 break;
1036 case MSG_CMD_NEWSMS_INDEX_IND:
1037 zSms_RecvCmtiInd(ptMsgBuf->aucDataBuf);
1038 break;
1039
1040 case MSG_CMD_NEWSMS_STATUS_INDEX_IND:
1041 zSms_RecvCdsiInd(ptMsgBuf->aucDataBuf);
1042 break;
1043 case MSG_CMD_NEWSMS_IND:
1044 case MSG_CMD_ZPBIC_IND:
1045 case MSG_CMD_ZMGL_IND:
1046 case MSG_CMD_NEWSMS_STATUS_IND:
1047 ipc_send_message(MODULE_ID_SMS, MODULE_ID_SMS_LOCAL, ptMsgBuf->usMsgCmd, ptMsgBuf->usDataLen, (unsigned char *)ptMsgBuf->aucDataBuf,0);
1048 break;
1049
1050 default:
1051 break;
1052
1053 }
1054}
1055
1056VOID zSms_HandleResetToFactory()
1057{
1058 CHAR clearSms[50] = {0};
1059
1060 sc_cfg_get(NV_CLEAR_SMS_WHEN_RESTORE,clearSms,sizeof(clearSms));
1061
1062 printf("atWeb_RestoreFactorySetting entered! \n");
1063 printf("clear_sms_when_restore=%s \n", clearSms);
1064 if(strcmp(clearSms, "yes") == 0)
1065 {
1066 printf("zUfiSms_DropAllTable entered! \n");
1067 zUfiSms_DropAllTable();
1068 }
1069 else
1070 {
1071 printf("zUfiSms_DropAllTableExceptSms entered! \n");
1072 zUfiSms_DropAllTableExceptSms();
1073 }
1074 ipc_send_message(MODULE_ID_SMS, MODULE_ID_MAIN_CTRL, MSG_CMD_RESET_RSP, 0, NULL,0);
1075}
1076
1077void zSms_HandleMainCtrlMsg(MSG_BUF *ptMsgBuf)
1078{
1079 assert(ptMsgBuf != NULL);
1080 printf( "sms recv main ctrl msg cmd:%d\n", ptMsgBuf->usMsgCmd);
1081 switch(ptMsgBuf->usMsgCmd)
1082 {
1083 case MSG_CMD_RESET_NOTIFY:
1084 zSms_HandleResetToFactory(ptMsgBuf->aucDataBuf);
1085 break;
1086 default:
1087 break;
1088
1089 }
1090}
1091
1092
1093void sms_msg_thread_proc(void* arg)
1094{
1095 int iRet = 0;
1096 MSG_BUF stMsg = {0};
1097 int msgSize = sizeof(MSG_BUF) - sizeof(long);
1098 int queueId = *((int*)arg);
1099 prctl(PR_SET_NAME, "sms_local", 0, 0, 0);
1100 while(1)
1101 {
1102 iRet = 0;
1103 memset(&stMsg, 0x00, sizeof(MSG_BUF));
1104 iRet = msgrcv(queueId, &stMsg, msgSize, 0, 0);
1105 if (iRet >= 0)
1106 {
1107 switch (stMsg.src_id)
1108 {
1109 case MODULE_ID_WEB_CGI:
1110 {
1111 zSms_HandleWebMsg(&stMsg);
1112 break;
1113 }
1114 case MODULE_ID_AT_CTL:
1115 {
1116 zSms_HandleAtctlMsg(&stMsg);
1117 break;
1118 }
1119 case MODULE_ID_SMS:
1120 {
1121 zSms_HandleWebMsg(&stMsg);
1122 zSms_HandleAtctlLocalMsg(&stMsg);
1123 break;
1124 }
1125 case MODULE_ID_MAIN_CTRL:
1126 {
1127 zSms_HandleMainCtrlMsg(&stMsg);
1128 break;
1129 }
1130 default:
1131 {
1132 break;
1133 }
1134 }
1135 }
1136 else
1137 {
1138 at_print(AT_DEBUG,"errno = %d, errmsg = %s\n", errno,strerror(errno));
1139 }
1140 }
1141}
1142
1143
1144int sms_main(int argc, char* argv[])
1145{
1146 pthread_t recv_thread_tid = 0;
1147 MSG_BUF msgBuf = {0};
1148 CHAR needSMS[50] = {0};
1149 prctl(PR_SET_NAME, "sms_main", 0, 0, 0);
1150 //¸ù¾ÝNV³õʼ»¯´òÓ¡¼¶±ð£¬²¢×¢²á¶¯Ì¬µ÷Õû´òÓ¡¼¶±ðÐźÅÁ¿
1151 loglevel_init();
1152
1153 //ÅжÏNV,added by wenqin 2016-5-18
1154 sc_cfg_get(NV_NEED_SUPPORT_SMS,needSMS,sizeof(needSMS));
1155 if(0 != strcmp(needSMS, "no"))
1156 {
1157 zUfiSms_InitDb();
1158 zUfiSms_CfgSmsNvInit();
1159 zUfiMmi_SendSmsStatus();
1160 zSms_SmsMsgCreat();
1161 }
1162 else
1163 {
1164 return -1;
1165 }
1166 printf("sms app init finished, will to receive msg, msgid:%d\n", g_zSms_MsqId);
1167 //¸ÃÏß³ÌÓÃÓÚ´¦ÀíÄÚ²¿×èÈûµÄÏûÏ¢£¬¶ÔÓ¦ÏûÏ¢µÄsourceIdÊÇMODULE_ID_SMS
1168 if(pthread_create(&recv_thread_tid, NULL, sms_msg_thread_proc, (void*)(&g_zSms_LocalMsqId)) == -1)
1169 {
1170 assert(0);
1171 }
1172 //Ö÷Ïß³ÌÓÃÓÚ´¦ÀíÍⲿ½ÓÊÕÏûÏ¢£¬¶ÔÓ¦ÏûÏ¢µÄsourceId·ÇMODULE_ID_SMS
1173 sms_msg_thread_proc(&g_zSms_MsqId);
1174 return 0;
1175}
1176