blob: 2c40612f8b14c6c88a35aaec53fb388d16fa7798 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/**************************************************************************
2*
3* Copyright (c) 2013 ZTE Corporation.
4*
5***************************************************************************
6* Ä£ ¿é Ãû : Cc
7* ÎÄ ¼þ Ãû : Cc_main.c
8* Ïà¹ØÎļþ :
9* ʵÏÖ¹¦ÄÜ : µç»°ÒµÎñÃüÁî·¢Ëͺͽá¹û´¦ÀíÄ£¿éº¯Êý¶¨Òå
10* ×÷ Õß :
11* °æ ±¾ :
12* Íê³ÉÈÕÆÚ :
13* ÆäËü˵Ã÷ :
14**************************************************************************/
15
16/**************************************************************************
17* Ð޸ļǼ :
18***************************************************************************/
19
20/**************************************************************************
21* #includeÇø
22**************************************************************************/
23#include <errno.h>
24//#include <signal.h>
25#include <stdio.h>
26#include <string.h>
27#include <stdlib.h>
28//#include <time.h>
29#include <fcntl.h>
30#include "cc_main.h"
31#include "cc_proc.h"
32#include "cc_com.h"
33#include "cc_at.h"
34#include <sys/types.h>
35#ifdef TEST_CCAPP
36#include "soft_timer.h"
37#endif
38
39
40
41/**************************************************************************
42* ³£Á¿¶¨ÒåÇø
43**************************************************************************/
44/**************************************************************************
45* Êý¾Ý½á¹¹¶¨ÒåÇø
46**************************************************************************/
47extern T_CC_APP_AtIndProcItem gCcAppAtIndProc[];
48extern SINT32 gCcAppRecvAtIndCnt;
49T_zCc_CallDetail g_Cc_CallDetail;
50char g_zCcApp_AtIndBuf[ZCC_APP_AT_BUF_MAX_LEN+1];
51/**************************************************************************
52* staticº¯ÊýÉùÃ÷Çø
53**************************************************************************/
54/**************************************************************************
55* È«¾Ö±äÁ¿¶¨ÒåÇø
56**************************************************************************/
57static SINT32 g_zCc_MsqId = NULL;
58//static SINT32 g_zCc_AtIndRspId = NULL;
59SINT32 g_zCc_AtRspId = NULL;
60
61
62static SINT32 g_zCc_getSlicEv_threadId = -1;
63
64int zCc_sleep(long ms)
65{
66 struct timeval tv;
67 tv.tv_sec = 0;
68 tv.tv_usec = ms * 1000;
69 return select(0, NULL, NULL, NULL, &tv);
70}
71VOID zCc_SlicMsgProc(MSG_BUF *ptMsgBuf)
72{
73 assert(ptMsgBuf != NULL);
74 //g_Cc_CallDetail.curEvt = ptMsgBuf->usMsgCmd;
75 if (ptMsgBuf->usMsgCmd == ZCC_DTMF_E && g_Cc_CallDetail.dCount < ZDIAL_NUM_MAX)
76 {
77 g_Cc_CallDetail.digits[g_Cc_CallDetail.dCount++] = ptMsgBuf->aucDataBuf[0];
78 ccapp_log("zCc_SlicMsgProc digit[%d]=%s", g_Cc_CallDetail.dCount, g_Cc_CallDetail.digits);
79 printf("[ccapp_debug]:collect number digit[%d]=%s\n",g_Cc_CallDetail.dCount,g_Cc_CallDetail.digits);
80 }
81}
82
83VOID zCc_SendMsgToSub(MSG_BUF *pMsg)
84{
85 MSG_BUF *ptMsgBuf = (MSG_BUF*)malloc(sizeof(MSG_BUF));
86 SINT32 iMsgQueueId = ZAT_INVALID_ID;
87
88 if(ptMsgBuf == NULL)
89 return;
90 memcpy(ptMsgBuf, pMsg, sizeof(MSG_BUF));
91
92 iMsgQueueId = msgget(MODULE_ID_CALL_CTRL_LOCAL, 0);
93 if (iMsgQueueId != ZAT_INVALID_ID)
94 {
95 ptMsgBuf->lMsgType = MSG_TYPE_DEFAULT;
96 ptMsgBuf->dst_id = MODULE_ID_CALL_CTRL_LOCAL;
97 if (msgsnd(iMsgQueueId, ptMsgBuf, sizeof(MSG_BUF) - sizeof(LONG), 0) < 0)
98 {
99 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s zCc_SendMsgToSub fail!!!\n",__FUNCTION__);
100 }
101 else
102 {
103 //zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s zCc_SendMsgToSub ptMsgBuf->usMsgCmd = %d, errno = %d <---\n",__FUNCTION__,ptMsgBuf->usMsgCmd,errno);
104 }
105 }
106 free(ptMsgBuf);
107}
108
109void* zCcApp_AtIndReader(void * ptr)
110{
111 int ret = -1;
112 int ReadLen = -1;
113 MSG_BUF QueueMsg = {0};
114 while(1)
115 {
116 ReadLen = msgrcv(g_zCc_AtRspId,&QueueMsg, sizeof(MSG_BUF)-sizeof(LONG), 0, 0);
117 if (ReadLen > 0)
118 {
119 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s msgrcv QueueMsg.aucDataBuf = %d \n",__FUNCTION__,QueueMsg.usMsgCmd);
120 ret = zCcApp_AtIndRspProc(&QueueMsg);
121 }
122 else
123 {
124 continue;
125 }
126
127 }
128}
129
130VOID zCc_AtRecvMsgProc(MSG_BUF *ptMsgBuf)
131{
132 assert(ptMsgBuf != NULL);
133 ULONG cmdId = ptMsgBuf->usMsgCmd;
134 SINT32 i ;
135 SINT32 ret = -1;
136
137 for(i=0;i< gCcAppRecvAtIndCnt;i++)
138 {
139 if(cmdId == gCcAppAtIndProc[i].cmdId)
140 {
141 if(NULL!= gCcAppAtIndProc[i].AtIndProcFun)
142 {
143 ret = gCcAppAtIndProc[i].AtIndProcFun(ptMsgBuf);
144 }
145 break;
146 }
147 }
148}
149
150static VOID zCc_SetRj11LedStatus(char* LedStatus)
151{
152 int ret = 0;
153
154 sc_cfg_set("cc_rj11_status", LedStatus);
155
156 ret = ipc_send_message(MODULE_ID_CALL_CTRL, MODULE_ID_MMI, MSG_CMD_RJ11_STATUS_INFO, 0, NULL, 0);
157 if (ret != 0) {
158 printf("zCc_SetRj11LedStatus %s failed\n", LedStatus);
159 } else {
160 printf("zCc_SetRj11LedStatus %s success\n", LedStatus);
161 }
162}
163
164VOID* zCcApp_getSlicEv_entry(VOID *pBUf)
165{
166 MSG_BUF msgBuf = {0};
167 unsigned char bEvent = EV_UNKONWN;
168 DWORD dtmf1 = 0;
169 char dtmf;
170
171 while (1)
172 {
173 if (SLIC_SUCCESS == SLIC_MsgRev(&bEvent, &dtmf1))
174 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s zCcApp_getSlicEv_entry recv msg %d\n",__FUNCTION__,bEvent);
175
176 printf("[ccapp_debug]: get slic event, bEvent = %d, dtmf1=%d\n",bEvent, dtmf1);
177
178 switch (bEvent)
179 {
180 case EV_FXS_HOOKON:
181 msgBuf.usMsgCmd = ZCC_RELEASE_E;
182 msgBuf.src_id = MODULE_ID_SLIC;
183 zCc_SendMsgToSub(&msgBuf); /* ·¢¹Ò»ú ʼþ¸øÖ÷Ïß³Ì */
184 break;
185 case EV_FXS_HOOKOFF:
186 msgBuf.usMsgCmd = ZCC_SEIZE_E;
187 msgBuf.src_id = MODULE_ID_SLIC;
188 zCc_SendMsgToSub(&msgBuf); /* ·¢Õª»úʼþ¸øÖ÷Ïß³Ì */
189 break;
190 case EV_FXS_COLLECT_DIG:// '0'-'9', '*', '#'
191 dtmf = dtmf1;
192 msgBuf.usMsgCmd = ZCC_DTMF_E;
193 msgBuf.src_id = MODULE_ID_SLIC;
194 msgBuf.aucDataBuf[0] = (UINT8)(dtmf);
195 msgBuf.usDataLen = 1;
196 zCc_SendMsgToSub(&msgBuf); /* ·¢DTMF ʼþ¸øÖ÷Ïß³Ì */
197 break;
198 case EV_FXS_FLASH:
199 msgBuf.usMsgCmd = ZCC_FLASH_E;
200 msgBuf.src_id = MODULE_ID_SLIC;
201 zCc_SendMsgToSub(&msgBuf); /* ·¢FLASH ʼþ¸øÖ÷Ïß³Ì */
202 break;
203 case EV_LT_RINGER_REN:
204 if (dtmf1 == 1) {
205 zCc_SetRj11LedStatus("ledon");
206 } else {
207 zCc_SetRj11LedStatus("ledoff");
208 }
209 break;
210 default:/* ÆäËûʼþ¶ªÆú²»´¦Àí*/
211 break;
212 }
213
214 //zCc_sleep(10);
215 }
216}
217
218#define MAX_DIGIT_MAP_NUM 20
219#define MAX_DIGIT_MAP_WHOLE_LEN 256
220#define MAX_PHONE_NUM_SIZE 32
221char tz_digitmap[MAX_DIGIT_MAP_NUM][MAX_PHONE_NUM_SIZE+1];//phone list
222int frist_get_map = 0;
223
224//(2xxxxxx|3xxxxxx|4xxxxxx|5xxxxxx|7xxxxxx|0[1-9][0-9]xxxxxxx|00xxxxxxxxxxxxxx|6xxx|8xxx|1xxx|*xx|#xx)
225void get_digit_map_list()
226{
227 int i = 0;
228 int j = 0;
229 char buff[256] = {0};
230 char *str = NULL;
231
232 //sc_cfg_set("digitmap_str", "(2xxxxxx|3xxxxxx|4xxxxxx|5xxxxxx|7xxxxxx|0[1-9][0-9]xxxxxxx|00xxxxxxxxxxxxxx|6xxx|8xxx|1xxx|*xx|#xx)");
233 //sc_cfg_save();
234 sc_cfg_get("digitmap_str",buff,sizeof(buff));
235 if (strlen(buff) == 0)
236 return;
237
238 str = buff;
239 if(*str == '(')
240 str++;
241
242 while(*str != 0)
243 {
244 if(*str == '|')
245 {
246 tz_digitmap[i][j] = 0;
247 i++;
248 j = 0;
249 }
250 else if(*str == ')')
251 {
252 break;
253 }
254 else
255 {
256 tz_digitmap[i][j] = *str;
257 j++;
258 }
259 str++;
260 }
261
262}
263
264int digit_map_call(char *num)
265{
266 int i = 0;
267 int j = 0;
268 int n = 0;
269 char flag = 0;
270 char switch_str[4] = {0};
271 static char buff[32+1] = {0};
272
273
274 sc_cfg_get("digitmap_switch",switch_str,sizeof(switch_str));
275 if(strcmp(switch_str, "0") == 0)
276 {
277 return 0;
278 }
279
280 if(0 == frist_get_map)
281 {
282 get_digit_map_list();
283 frist_get_map = 1;
284 }
285
286 strncpy(buff, num,sizeof(buff)-1);
287 //printf("buff:%s\n", buff);
288
289
290 for(i = 0; i < MAX_DIGIT_MAP_NUM; i++)
291 {
292 if(strlen(tz_digitmap[i]) != 0)
293 {
294 while(((j+n) <= MAX_PHONE_NUM_SIZE) && (tz_digitmap[i][j] != 0) && (buff[j] != 0))
295 {
296 if(tz_digitmap[i][j+n] == '[' )
297 {
298 n++;
299 while(((j+n) <= MAX_PHONE_NUM_SIZE) && tz_digitmap[i][j+n] != ']')
300 {
301 if(((j+n+2) <= MAX_PHONE_NUM_SIZE) && tz_digitmap[i][j+n+1] == '-')
302 {
303 if(tz_digitmap[i][j+n] <= buff[j] && buff[j] <= tz_digitmap[i][j+n+2])
304 {
305 //printf("digit_map:%c, %c, %c\n", tz_digitmap[i][j+n], tz_digitmap[i][j+n+2], buff[j]);
306 flag = 1;
307 }
308 n+=3;
309 }
310 else
311 {
312 if(tz_digitmap[i][j+n] == buff[j])
313 {
314 flag = 1;
315 }
316 n++;
317 }
318 }
319
320 if(flag == 0)
321 {
322 break;
323 }
324
325 flag = 0;
326
327
328 }
329 else
330 {
331 if(tz_digitmap[i][j+n] != buff[j])
332 {
333 if(!(tz_digitmap[i][j+n] == 'X' || tz_digitmap[i][j+n] == 'x'))
334 break;
335 }
336 }
337 j++;
338 if(((j+n) <= MAX_PHONE_NUM_SIZE) && (tz_digitmap[i][j+n] == 0) && (buff[j] == 0))
339 {
340 //ccapp_log("digit_map_call do Match: %d, %s, %s\n", i, tz_digitmap[i], buff);
341 return 1;
342 }
343 }
344 }
345 n = 0;
346 j = 0;
347 }
348
349 return 0;
350}
351
352#ifdef TEST_CCAPP
353VOID* zCc_main(VOID * pbuf)
354{
355 MSG_BUF QueueMsg = {0};
356 int MainQeueId = -1;
357 int ret = -1;
358 UINT8 bMsgType =1;
359 int fd = -1;
360 pthread_attr_t AtIndReaderAttr;
361 pthread_t AtIndReaderThreadId;
362
363 pthread_attr_init(&AtIndReaderAttr);
364 pthread_attr_setstacksize(&AtIndReaderAttr,4*1024);
365 fd = zCcApp_GetAtIndFd();
366 AtIndReaderThreadId = pthread_create(&AtIndReaderThreadId, NULL, zCcApp_AtIndReader, (void*)&fd);
367 if(AtIndReaderThreadId < 0)
368 {
369 return NULL;
370 }
371 while (1)
372 {
373 ret = msgrcv(MainQeueId, &QueueMsg, sizeof(MSG_BUF), bMsgType, 0);
374 if(ret == -1)
375 {
376 return NULL;
377 }
378 else
379 {
380 switch (QueueMsg.src_id)
381 {
382 case MODULE_ID_CALL_CTRL: // AT Ind msg
383 zCc_AtRecvMsgProc(&QueueMsg);
384 break;
385
386 case MODULE_ID_SLIC: // message from slic
387 default:
388 zCc_SlicMsgProc(&QueueMsg);
389 break;
390 }
391 zCc_RunMaster(&QueueMsg);
392 }
393 }
394
395}
396#endif
397#ifndef TEST_CCAPP
398
399static int polarity_reversal_flag = 0;
400int get_polarity_reversal_flag(void)
401{
402 return polarity_reversal_flag;
403}
404
405void check_polarity_reversal_cfg(void)
406{
407 int rt;
408 char buf[32];
409
410 memset(buf, 0, sizeof(buf));
411 rt = sc_cfg_get("polarity_reversal",buf,sizeof(buf));
412 if (rt != 0 || strlen(buf) == 0)
413 {
414 sc_cfg_set("polarity_reversal", "0");
415 sc_cfg_save();
416
417 polarity_reversal_flag = 0;
418 return ;
419 }
420
421 polarity_reversal_flag = atoi(buf);
422}
423
424void check_wb_mode_cfg(void)
425{
426 int rt;
427 int val;
428 char buf[64];
429
430 memset(buf, 0, sizeof(buf));
431 rt = sc_cfg_get("wb_mode",buf,sizeof(buf));
432 if (rt != 0 || strlen(buf) == 0)
433 {
434 sc_cfg_set("wb_mode", "1");
435 sc_cfg_save();
436
437 val = 1;
438 }
439 else
440 val = atoi(buf);
441
442 sprintf(buf, "at_cmd AT+ZIMSAMRW=%d", (val==0)?0:1);
443 soft_system(buf);
444
445 sprintf(buf, "echo \"at_cmd AT+ZIMSAMRW=%d\" > /tmp/log.ZIMSAMRW", (val==0)?0:1);
446 soft_system(buf);
447}
448
449
450int main(VOID)
451{
452 MSG_BUF QueueMsg = {0};
453 int ret = -1;
454 pthread_t CcAppMainThreadId;
455 pthread_attr_t AtIndReaderAttr;
456 pthread_t AtIndReaderThreadId;
457 SLIC_Initial();
458 SLIC_Dev_Init();
459 soft_system("at_cmd AT+ZIMSTEST=\"EMCALL_TO_NORMAL\",1 ");
460
461 check_wb_mode_cfg();
462 check_polarity_reversal_cfg();
463
464 g_zCc_MsqId = msgget(MODULE_ID_CALL_CTRL_LOCAL, IPC_CREAT | 0600);
465 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s g_zCc_MsqId %d, errno:%d\n",__FUNCTION__,g_zCc_MsqId,errno);
466 if (g_zCc_MsqId == ZAT_INVALID_ID)
467 {
468 return 0;
469 }
470
471 g_zCc_AtRspId = msgget(MODULE_ID_CALL_CTRL, IPC_CREAT | 0600);
472 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s g_zCc_AtRspId %d, errno:%d\n",__FUNCTION__,g_zCc_AtRspId,errno);
473
474 if (g_zCc_AtRspId == ZAT_INVALID_ID)
475 {
476 return 0;
477 }
478
479 g_zCc_getSlicEv_threadId = pthread_create(&CcAppMainThreadId, NULL, zCcApp_getSlicEv_entry,0);
480
481 if(g_zCc_getSlicEv_threadId!=0)
482 {
483 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s pthread_create zCc_getSlicEv error, errno = %d \n",__FUNCTION__,errno);
484 return -1;
485 }
486 else
487 {
488 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s pthread_create zCc_getSlicEv succ\n",__FUNCTION__);
489 }
490
491 pthread_attr_init(&AtIndReaderAttr);
492 pthread_attr_setstacksize(&AtIndReaderAttr,4*1024);
493 ret = pthread_create(&AtIndReaderThreadId, NULL, zCcApp_AtIndReader, 0);
494 pthread_attr_destroy(&AtIndReaderAttr); //kw 2
495 if(ret != 0) //cov m
496 {
497 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s pthread_create zCcApp_AtIndReader error, errno = %d \n",__FUNCTION__,errno);
498 return -1;
499 }
500 else
501 {
502 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s pthread_create zCcApp_AtIndReader succ\n",__FUNCTION__);
503 }
504
505 zCc_SendAtImsPlusReq(1,1);//ÉèÖÃimsplusÉϱ¨
506
507 while (1)
508 {
509 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","BACK TO main\n");
510 ret = msgrcv(g_zCc_MsqId, &QueueMsg, sizeof(MSG_BUF)-sizeof(LONG), 0, 0);
511 if(ret==-1)
512 {
513 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","%s msgrcv return ret= %d errno=%d\n",__FUNCTION__,ret, errno);
514 continue;
515 }
516 else
517 {
518 switch (QueueMsg.src_id)
519 {
520 case MODULE_ID_SLIC: // message from slic
521 zCc_SlicMsgProc(&QueueMsg);
522 break;
523 default: // AT Ind msg
524 zte_log_append(__FILE__, __LINE__, "zte_ccapp.log","recv msg %d from at_ctl\n",QueueMsg.usMsgCmd);
525 if (QueueMsg.usMsgCmd==MSG_CMD_ZIMSPLUS_IND
526 ||QueueMsg.usMsgCmd==MSG_CMD_DSCI_IND
527 ||QueueMsg.usMsgCmd==MSG_CMD_ZCPI
528 ||QueueMsg.usMsgCmd==MSG_CMD_ZVOICECHNL)
529 {
530 zCc_CheckSlaveState("in zCc_AtRecvMsgProc");
531 zCc_AtRecvMsgProc(&QueueMsg);
532 }
533 break;
534 }
535 if (QueueMsg.usMsgCmd==MSG_CMD_VTS_RSP)
536 {
537 zCcApp_Vts_Rsp();
538 }
539 zCc_RunMaster(&QueueMsg);
540 }
541 }
542
543return 0;
544}
545#endif
546