blob: b532837311c6503cb4073db0448f116d38769f0d [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <sys/socket.h>
5#include <errno.h>
6#include <fcntl.h>
7#include <string.h>
8#include <netinet/in.h>
9#include <arpa/inet.h>
10#include <linux/un.h>
11#include <linux/netlink.h>
12#include <cutils/properties.h>
13#include <time.h>
14#include <sys/time.h>
15
16//#include "cploader.h"
17#include "mbtk_log.h"
18#include "mbtk_ifc.h"
19#include "mbtk_type.h"
20#include "atchannel.h"
21#include "at_tok.h"
22#include "mbtk_utils.h"
23#include "mbtk_task.h"
24#include "mbtk_info.h"
25#include "mbtk_ntp.h"
26#include "mbtk_net_control.h"
27#include "info_data.h"
wangyouqiang38e53362024-01-23 10:53:48 +080028#include "mbtk_led.h"
liubin281ac462023-07-19 14:22:54 +080029
30#define TEMP_FAILURE_RETRY(exp) ({ \
31 typeof (exp) _rc; \
32 do { \
33 _rc = (exp); \
34 } while (_rc == -1 && errno == EINTR); \
35 _rc; })
36
37#define BUFFER_SIZE 2048
38#define UEVENT_USIM_DEV "/devices/virtual/usim_event/usim0"
39#define MBTK_BOOT_SERVER_READY "/etc/init.d/mbtk_boot_server_ready"
40
41struct cooling_device
42{
43 const char *name;
44 const char *action;
45 const char *path;
46 const char *event;
47 const char *subsystem;
48};
49static pthread_t uevnet_task_id;
50extern net_info_t net_info;
51extern mbtK_cell_pack_info_t cell_info;
52extern info_cgact_wait_t cgact_wait;
53extern bool at_process;
54
55void setRadioPower(int isOn);
56int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len);
57int mbtk_signal_log(char *data);
58
59/* Called on command thread */
60static void onATTimeout()
61{
62 LOGI("AT channel timeout; closing\n");
63 at_close();
64}
65
66/* Called on command or reader thread */
67static void onATReaderClosed()
68{
69 LOGI("AT channel closed\n");
70 at_close();
71}
72
73//int req_time_set(int type, char *time, int *cme_err);
74static int metis_strptime(char *str_time)
75{
76 struct tm stm;
77 char dateTime[30];
78 struct timeval tv;
79 if(strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm) != NULL)
80 {
81 time_t _t = mktime(&stm);
82 tv.tv_sec = _t;
83 if(settimeofday(&tv, NULL)) {
84 LOG("Set time fail:%d", errno);
85 return -1;
86 } else {
87 LOG("Set time to %s.", str_time);
88 return 0;
89 }
90 } else {
91 LOG("Set time fail.");
92 return -1;
93 }
94}
95
96static void* ntp_pthread_run(void* arg)
97{
98 // Waitting for network connected.
99 while(mbtk_net_state_get() == MBTK_NET_STATE_OFF) {
100 sleep(1);
101 }
102 LOG("Network is connected.");
103
104 char time_type[10];
105 while(1){
106 memset(time_type, 0, 10);
107 property_get("persist.mbtk.time_type", time_type, "0");
108 if(atoi(time_type) == MBTK_TIME_TYPE_NTP) // NTP time
109 {
110 char time_str[100] = {0};
111 time_t time = 0;
112 while((time = (time_t)mbtk_at_systime()) == 0) {
113 usleep(100000);
114 }
115 struct tm *tm_t;
116 tm_t = localtime(&time);
117 strftime(time_str,128,"%F %T",tm_t);
118
119 // NTP time
120 metis_strptime(time_str);
121 } else {
122 break;
123 }
124
125 sleep(64); // Sleep 64s.
126 }
127 return NULL;
128}
129
130static void ntp_thread_start()
131{
132 pthread_t ntp_pid;
133 pthread_attr_t thread_attr;
134 pthread_attr_init(&thread_attr);
135 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
136 {
137 LOG("pthread_attr_setdetachstate() fail.");
138 return;
139 }
140
141 if(pthread_create(&ntp_pid, &thread_attr, ntp_pthread_run, NULL))
142 {
143 LOG("pthread_create() fail.");
144 }
145}
146
147bool sms_cmt = false;
148mbtk_sim_card_info sim_info_reg={0};
149static void onUnsolicited(const char *s, const char *sms_pdu)
150{
151 LOGV("URC : %s", s);
152 // MBTK_AT_READY
153 if (strStartsWith(s, "MBTK_AT_READY")) // AT ready.
154 {
155
156 }
157#if 0
158 else if(strStartsWith(s, "*SIMDETEC:")) // *SIMDETEC:1,SIM
159 {
160 const char* ptr = strstr(s, ",");
161 if(ptr)
162 {
163 ptr++; // Jump ','
164 if(memcmp(ptr, "SIM", 3) == 0)
165 net_info.sim_state = MBTK_SIM_STATE_READY;
166 else
167 net_info.sim_state = MBTK_SIM_STATE_ABSENT;
168 }
169 }
170#endif
171 else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
172 {
173 const char* ptr = s + strlen("*RADIOPOWER:");
174 while(*ptr != '\0' && *ptr == ' ' )
175 {
176 ptr++;
177 }
178
179 uint8 state;
180 if(*ptr == '1') {
181 //net_info.radio_state = MBTK_RADIO_STATE_ON;
182 // mbtk_radio_ready_cb();
183 state = (uint8)1;
184 } else {
185 //net_info.radio_state = MBTK_RADIO_STATE_OFF;
186 state = (uint8)0;
187 }
188 urc_msg_distribute(true, INFO_URC_MSG_RADIO_STATE, &state, sizeof(uint8));
189 }
190 // "CONNECT"
191 else if(strStartsWith(s, "CONNECT"))
192 {
193 if(cgact_wait.waitting && cgact_wait.act) {
194 cgact_wait.waitting = false;
195 }
196
197 uint8 data_pdp;
198 data_pdp = 1; //
199 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
200 }
201 // +CGEV:
202 // +CGEV: NW DEACT <cid>,<cid>
203 // +CGEV: ME DEACT <cid>,<cid>
204 // +CGEV: NW PDN DEACT <cid>
205 // +CGEV: ME PDN DEACT <cid>
206 // +CGEV: NW DETACH
207 // +CGEV: ME DETACH
208 //
209 // +CGEV: NW ACT <cid>,<cid>
210 // +CGEV: ME ACT <cid>,<cid>
211 // +CGEV: EPS PDN ACT <cid>
212 // +CGEV: ME PDN ACT <cid>,<reason>,<cid>
213 // +CGEV: ME PDN ACT <cid>,<reason>
214 // +CGEV: NW PDN ACT <cid>
215 // +CGEV: EPS ACT <cid>
216 // +CGEV: NW MODIFY <cid>,<reason>
217 // +CGEV: NW REATTACH
218 else if(strStartsWith(s, "+CGEV:"))
219 {
220 if(at_process) {
221 if(cgact_wait.act) {
222 if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT 15,4
223 if(cgact_wait.cid == atoi(s + 18)) {
224 cgact_wait.waitting = false;
225 }
226
227 uint8 data_pdp;
228 char* tmp_s = memdup(s + 18,strlen(s + 18));
229 char* free_ptr = tmp_s;
230 char *line = tmp_s;
231 int tmp_int;
232 if (at_tok_start(&line) < 0)
233 {
234 goto at_PDP_CREG_EXIT;
235 }
236 if (at_tok_nextint(&line, &tmp_int) < 0)
237 {
238 goto at_PDP_CREG_EXIT;
239 }
240 if (at_tok_nextint(&line, &tmp_int) < 0)
241 {
242 goto at_PDP_CREG_EXIT;
243 }
244 data_pdp = tmp_int;
245at_PDP_CREG_EXIT:
246 free(free_ptr);
247
248 //data_pdp = (uint8)atoi(s + 20); //reason
249 if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
250 {
251 if(data_pdp == 0)
252 {
253 data_pdp = 25;
254 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
255 //data_pdp = cgact_wait.cid + 200;
256 }
257 else if(data_pdp == 1)
258 {
259 data_pdp = 26;
260 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
261 }
262 else if(data_pdp == 2)
263 {
264 data_pdp = 27;
265 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
266 }
267 else if(data_pdp == 3)
268 {
269 data_pdp = 27;
270 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
271 }
272 else
273 {
274
275 }
276 if(cgact_wait.cid != 0)
277 {
278 data_pdp = cgact_wait.cid + 200;
279 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
280 }
281 }
282 } else if(strStartsWith(s, "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY 1,4
283 if(cgact_wait.cid == atoi(s + 17)) {
284 cgact_wait.waitting = false;
285 }
286 }
287 } else {
288 if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
289 if(cgact_wait.cid == atoi(s + 20)) {
290 cgact_wait.waitting = false;
291 }
292 uint8 data_pdp;
293 data_pdp = 0; //
294 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
295 if(cgact_wait.cid != 0)
296 {
297 data_pdp = cgact_wait.cid + 100;
298 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
299 }
300 }
301 }
302 } else {
303 // apn_state_set
304
305 // +CGEV: NW PDN DEACT <cid>
306
307 // +CGEV: EPS PDN ACT 1
308 // +CGEV: ME PDN ACT 8,1
309
310 // +CGEV: ME PDN ACT 2,4
311 uint8 data[2] = {0xFF};
312 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
313 //apn_state_set(atoi(s + 20), false);
314 data[0] = (uint8)0;
315 data[1] = (uint8)atoi(s + 20);
316
317 uint8 data_pdp;
318 data_pdp = 0; //
319 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
wangyouqiang65884152023-10-25 19:54:15 +0800320 data_pdp = data[1] + 100;
liubin281ac462023-07-19 14:22:54 +0800321 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
322 } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
323 //apn_state_set(atoi(s + 19), true);
b.liuf37bd332024-03-18 13:51:24 +0800324#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
wangyouqianged88c722023-11-22 16:33:43 +0800325 //data[0] = (uint8)1;
326 //data[1] = (uint8)atoi(s + 19);
327#else
liubin281ac462023-07-19 14:22:54 +0800328 data[0] = (uint8)1;
329 data[1] = (uint8)atoi(s + 19);
wangyouqianged88c722023-11-22 16:33:43 +0800330#endif
wangyouqiang65884152023-10-25 19:54:15 +0800331 } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
332 //apn_state_set(atoi(s + 19), true);
333 data[0] = (uint8)0;
334 data[1] = (uint8)atoi(s + 20);
335
336 uint8 data_pdp;
337 data_pdp = 0; //
338 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
339 data_pdp = data[1] + 100;
340 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
liubin281ac462023-07-19 14:22:54 +0800341 } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
342 //apn_state_set(atoi(s + 18), true);
343 data[0] = (uint8)1;
344 data[1] = (uint8)atoi(s + 18);
345
346 uint8 data_pdp;
347 char* tmp_s = memdup(s + 18,strlen(s + 18));
348 char* free_ptr = tmp_s;
349 char *line = tmp_s;
350 int tmp_int;
351 if (at_tok_start(&line) < 0)
352 {
353 goto PDP_CREG_EXIT;
354 }
355 if (at_tok_nextint(&line, &tmp_int) < 0)
356 {
357 goto PDP_CREG_EXIT;
358 }
359 if (at_tok_nextint(&line, &tmp_int) < 0)
360 {
361 goto PDP_CREG_EXIT;
362 }
363 data_pdp = tmp_int;
364PDP_CREG_EXIT:
365 free(free_ptr);
366 //data_pdp = (uint8)atoi(s + 20); //reason
367 if(data[1] >= 1 && data[1] < 8)
368 {
369 if(data_pdp == 0)
370 {
371 data_pdp = 25;
372 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
373 }
374 else if(data_pdp == 1)
375 {
376 data_pdp = 26;
377 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
378 }
379 else if(data_pdp == 2)
380 {
381 data_pdp = 27;
382 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
383 }
384 else if(data_pdp == 3)
385 {
386 data_pdp = 27;
387 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
388 }
389 else
390 {
391
392 }
b.liufe320632024-01-17 20:38:08 +0800393
wangyouqiang65884152023-10-25 19:54:15 +0800394 data_pdp = data[1] + 200;
395 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
liubin281ac462023-07-19 14:22:54 +0800396 }
397 } else {
398 LOGI("No process : %s", s);
399 }
400
401 urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
402 }
403 }
404 // +CREG: 1, "8010", "000060a5", 0, 2, 0
405 // +CREG: 1, "8330", "06447347", 7, 2, 0
406 // +CEREG: 1, "8330", "06447347", 7
407 // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
408 // $CREG: 1, "8010", "000060a7", 0,, 2, 0
409 // +CGREG: 1
410 else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
411 || strStartsWith(s, "+CEREG:")) // LTE data registed.
412 {
413 char* tmp_s = s + 7;
414 while(*tmp_s && *tmp_s == ' ')
415 tmp_s++;
b.liufe320632024-01-17 20:38:08 +0800416 uint8 data[2];
417 data[0] = (uint8)atoi(tmp_s); // Reg State.
liubin281ac462023-07-19 14:22:54 +0800418
b.liufe320632024-01-17 20:38:08 +0800419 if(strStartsWith(s, "+CGREG:")) {
420 data[1] = 0; // GMS/WCDMA
421 } else {
422 data[1] = 1; // LTE
wangyouqiang38e53362024-01-23 10:53:48 +0800423 if(data[0] == 1)
424 {
425 mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
426 }
427 else
428 {
429 mbtk_net_led_set(MBTK_NET_LED_SEARCH_NETWORK);
430 }
b.liufe320632024-01-17 20:38:08 +0800431 }
432
433 urc_msg_distribute(true, INFO_URC_MSG_NET_PS_REG_STATE, data, sizeof(data));
liubin281ac462023-07-19 14:22:54 +0800434 }
435 // +CREG: 1, "8010", "000060a5", 0, 2, 0
436 // +CREG: 1, "8330", "06447347", 7, 2, 0
437 // +CREG: 0
438 else if(strStartsWith(s, "+CREG:")) // GMS/WCDMA/LTE CS registed.
439 {
440 uint8 data[3];
441 data[0] = (uint8)MBTK_NET_CS_STATE;
442 char* tmp_s = memdup(s,strlen(s));
443 char* free_ptr = tmp_s;
444 char *line = tmp_s;
445 int tmp_int;
446 char *tmp_str;
447 if (at_tok_start(&line) < 0)
448 {
449 goto CREG_EXIT;
450 }
451 if (at_tok_nextint(&line, &tmp_int) < 0)
452 {
453 goto CREG_EXIT;
454 }
455 data[1] = (uint8)tmp_int; // Reg State.
456 if (data[1])
457 {
458 if (at_tok_nextstr(&line, &tmp_str) < 0)
459 {
460 goto CREG_EXIT;
461 }
462 if (at_tok_nextstr(&line, &tmp_str) < 0)
463 {
464 goto CREG_EXIT;
465 }
466 if (at_tok_nextint(&line, &tmp_int) < 0)
467 {
468 goto CREG_EXIT;
469 }
470 data[2] = (uint8)tmp_int; // AcT
471 } else {
472 data[2] = (uint8)0xFF; // AcT
473 }
474 if(data[1] == 5)
475 {
476 uint8 data_pdp;
477 data_pdp = 5; //
478 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
479 }
480 urc_msg_distribute(false, INFO_URC_MSG_NET_CS_REG_STATE, data, sizeof(data));
481CREG_EXIT:
482 free(free_ptr);
483 }
484 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
485 else if(strStartsWith(s, "+CLCC:"))
486 {
487 mbtk_call_info_t reg;
488 reg.call_wait = MBTK_CLCC;
489 char* tmp_s = memdup(s,strlen(s));
490 char* free_ptr = tmp_s;
491 char *line = tmp_s;
492 int tmp_int;
493 char *tmp_str;
494 int err;
495
496 err = at_tok_start(&line);
497 if (err < 0)
498 {
499 goto CLCC_EXIT;
500 }
501 err = at_tok_nextint(&line, &tmp_int); // dir1
502 if (err < 0)
503 {
504 goto CLCC_EXIT;
505 }
506 reg.dir1 = (uint8)tmp_int;
507 err = at_tok_nextint(&line, &tmp_int);// dir
508 if (err < 0)
509 {
510 goto CLCC_EXIT;
511 }
512 reg.dir = (uint8)tmp_int;
513 err = at_tok_nextint(&line, &tmp_int);// state
514 if (err < 0)
515 {
516 goto CLCC_EXIT;
517 }
518 reg.state = (uint8)tmp_int;
519 err = at_tok_nextint(&line, &tmp_int);// mode
520 if (err < 0)
521 {
522 goto CLCC_EXIT;
523 }
524 reg.mode = (uint8)tmp_int;
525 err = at_tok_nextint(&line, &tmp_int);// mpty
526 if (err < 0)
527 {
528 goto CLCC_EXIT;
529 }
530 reg.mpty = (uint8)tmp_int;
531 err = at_tok_nextstr(&line, &tmp_str); // phone_number
532 if (err < 0)
533 {
534 goto CLCC_EXIT;
535 }
536
537 memset(reg.phone_number,0,sizeof(reg.phone_number));
538 memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
539 err = at_tok_nextint(&line, &tmp_int);// tpye
540 if (err < 0)
541 {
542 goto CLCC_EXIT;
543 }
544 reg.type = (uint8)tmp_int;
545
r.xiaoe1404b32024-05-23 22:43:39 -0700546 if(reg.state == 2 || reg.state == 3 || reg.state == 0)
547 {
548 mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
549 }
550
liubin281ac462023-07-19 14:22:54 +0800551 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
552CLCC_EXIT:
553 free(free_ptr);
554 }
555 // +CPAS: 4
556 else if(strStartsWith(s, "+CPAS:"))
557 {
558 mbtk_call_info_t reg;
559 reg.call_wait = 0;
560 char* tmp_s = memdup(s,strlen(s));
561 char* free_ptr = tmp_s;
562 char *line = tmp_s;
563 int tmp_int;
564 int err;
565
566 memset(&reg,0,sizeof(reg));
567
568 err = at_tok_start(&line);
569 if (err < 0)
570 {
571 goto CPAS_EXIT;
572 }
573 err = at_tok_nextint(&line, &tmp_int);
574 if (err < 0)
575 {
576 goto CPAS_EXIT;
577 }
578 reg.pas = (uint8)tmp_int;
579 reg.call_wait = MBTK_CPAS;
580 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
581CPAS_EXIT:
582 free(free_ptr);
583 }
584 // +CALLDISCONNECT: 1
585 else if(strStartsWith(s, "+CALLDISCONNECT:"))
586 {
587 mbtk_call_info_t reg;
588 reg.call_wait = 0;
589 char* tmp_s = memdup(s,strlen(s));
590 char* free_ptr = tmp_s;
591 char *line = tmp_s;
592 int tmp_int;
593 int err;
594
595 memset(&reg,0,sizeof(reg));
596
597 err = at_tok_start(&line);
598 if (err < 0)
599 {
600 goto CALLDISCONNECTED_EXIT;
601 }
602 err = at_tok_nextint(&line, &tmp_int);
603 if (err < 0)
604 {
605 goto CALLDISCONNECTED_EXIT;
606 }
607 reg.disconnected_id = tmp_int;
608 reg.call_wait = MBTK_DISCONNECTED;
r.xiaoe1404b32024-05-23 22:43:39 -0700609
610 if(reg.call_wait == MBTK_DISCONNECTED)
611 {
612 mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
613 }
614
liubin281ac462023-07-19 14:22:54 +0800615 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
616
617CALLDISCONNECTED_EXIT:
618 free(free_ptr);
619 }
620 // *SIMDETEC:1,SIM
621 else if(strStartsWith(s, "*SIMDETEC:"))
622 {
liuyange22a25e2024-05-23 19:41:52 +0800623 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
624 {
625 net_info.sim_state = MBTK_SIM_ABSENT;
626 }
627
liubin281ac462023-07-19 14:22:54 +0800628 sim_info_reg.sim = -1;
629 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
630 sim_info_reg.sim = 0;
631 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
632 sim_info_reg.sim = 1;
633 if(sim_info_reg.sim == 0)
634 {
635 uint8 data_pdp;
636 data_pdp = 11; //
637 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
638 }
639 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
640 }
641 // *EUICC:1
642/*0: SIM
6431: USIM
6442: TEST SIM
6453: TEST USIM
6464: UNKNOWN
647Note: *EUICC:
648*/
649 else if(strStartsWith(s, "*EUICC:"))
650 {
651 sim_info_reg.sim_card_type = -1;
652 if(strStartsWith(s, "*EUICC: 0"))
653 sim_info_reg.sim_card_type = 1;
654 else if(strStartsWith(s, "*EUICC: 1"))
655 sim_info_reg.sim_card_type = 2;
656 else if(strStartsWith(s, "*EUICC: 2"))
657 sim_info_reg.sim_card_type = 1;
658 else if(strStartsWith(s, "*EUICC: 3"))
659 sim_info_reg.sim_card_type = 2;
660 else if(strStartsWith(s, "*EUICC: 4"))
661 sim_info_reg.sim_card_type = 0;
662 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
663 }
664 // +CPIN: SIM PIN
665 else if(strStartsWith(s, "+CPIN:"))
666 {
667 sim_info_reg.sim = -1;
668 if(strStartsWith(s, "+CPIN: READY"))
liuyange22a25e2024-05-23 19:41:52 +0800669 {
liubin281ac462023-07-19 14:22:54 +0800670 sim_info_reg.sim = 1;
liuyange22a25e2024-05-23 19:41:52 +0800671 net_info.sim_state = MBTK_SIM_READY;
672 }
liubin281ac462023-07-19 14:22:54 +0800673 else if(strStartsWith(s, "+CPIN: SIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800674 {
liubin281ac462023-07-19 14:22:54 +0800675 sim_info_reg.sim = 2;
liuyange22a25e2024-05-23 19:41:52 +0800676 net_info.sim_state = MBTK_SIM_PIN;
677 }
liubin281ac462023-07-19 14:22:54 +0800678 else if(strStartsWith(s, "+CPIN: SIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800679 {
liubin281ac462023-07-19 14:22:54 +0800680 sim_info_reg.sim = 3;
liuyange22a25e2024-05-23 19:41:52 +0800681 net_info.sim_state = MBTK_SIM_PUK;
682 }
liubin281ac462023-07-19 14:22:54 +0800683 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800684 {
liubin281ac462023-07-19 14:22:54 +0800685 sim_info_reg.sim = 4;
liuyange22a25e2024-05-23 19:41:52 +0800686 net_info.sim_state = MBTK_SIM_ABSENT;
687 }
liubin281ac462023-07-19 14:22:54 +0800688 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800689 {
liubin281ac462023-07-19 14:22:54 +0800690 sim_info_reg.sim = 5;
liuyange22a25e2024-05-23 19:41:52 +0800691 net_info.sim_state = MBTK_SIM_ABSENT;
692 }
liubin281ac462023-07-19 14:22:54 +0800693 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800694 {
liubin281ac462023-07-19 14:22:54 +0800695 sim_info_reg.sim = 6;
liuyange22a25e2024-05-23 19:41:52 +0800696 net_info.sim_state = MBTK_SIM_ABSENT;
697 }
liubin281ac462023-07-19 14:22:54 +0800698 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800699 {
liubin281ac462023-07-19 14:22:54 +0800700 sim_info_reg.sim = 7;
liuyange22a25e2024-05-23 19:41:52 +0800701 net_info.sim_state = MBTK_SIM_ABSENT;
702 }
liubin281ac462023-07-19 14:22:54 +0800703 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
liuyange22a25e2024-05-23 19:41:52 +0800704 {
liubin281ac462023-07-19 14:22:54 +0800705 sim_info_reg.sim = 8;
liuyange22a25e2024-05-23 19:41:52 +0800706 net_info.sim_state = MBTK_SIM_ABSENT;
707 }
liubin281ac462023-07-19 14:22:54 +0800708 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
liuyange22a25e2024-05-23 19:41:52 +0800709 {
liubin281ac462023-07-19 14:22:54 +0800710 sim_info_reg.sim = 9;
liuyange22a25e2024-05-23 19:41:52 +0800711 net_info.sim_state = MBTK_SIM_ABSENT;
712 }
liubin281ac462023-07-19 14:22:54 +0800713 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800714 {
liubin281ac462023-07-19 14:22:54 +0800715 sim_info_reg.sim = 10;
liuyange22a25e2024-05-23 19:41:52 +0800716 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
717 }
liubin281ac462023-07-19 14:22:54 +0800718 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800719 {
liubin281ac462023-07-19 14:22:54 +0800720 sim_info_reg.sim = 11;
liuyange22a25e2024-05-23 19:41:52 +0800721 net_info.sim_state = MBTK_SIM_ABSENT;
722 }
liubin281ac462023-07-19 14:22:54 +0800723 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
liuyange22a25e2024-05-23 19:41:52 +0800724 {
liubin281ac462023-07-19 14:22:54 +0800725 sim_info_reg.sim = 12;
liuyange22a25e2024-05-23 19:41:52 +0800726 net_info.sim_state = MBTK_SIM_ABSENT;
727 }
liubin281ac462023-07-19 14:22:54 +0800728 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800729 {
liubin281ac462023-07-19 14:22:54 +0800730 sim_info_reg.sim = 13;
liuyange22a25e2024-05-23 19:41:52 +0800731 net_info.sim_state = MBTK_SIM_ABSENT;
732 }
liubin281ac462023-07-19 14:22:54 +0800733 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800734 {
liubin281ac462023-07-19 14:22:54 +0800735 sim_info_reg.sim = 14;
liuyange22a25e2024-05-23 19:41:52 +0800736 net_info.sim_state = MBTK_SIM_ABSENT;
737 }
liubin281ac462023-07-19 14:22:54 +0800738 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800739 {
liubin281ac462023-07-19 14:22:54 +0800740 sim_info_reg.sim = 15;
liuyange22a25e2024-05-23 19:41:52 +0800741 net_info.sim_state = MBTK_SIM_ABSENT;
742 }
liubin281ac462023-07-19 14:22:54 +0800743 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800744 {
liubin281ac462023-07-19 14:22:54 +0800745 sim_info_reg.sim = 16;
liuyange22a25e2024-05-23 19:41:52 +0800746 net_info.sim_state = MBTK_SIM_ABSENT;
747 }
liubin281ac462023-07-19 14:22:54 +0800748 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800749 {
liubin281ac462023-07-19 14:22:54 +0800750 sim_info_reg.sim = 17;
liuyange22a25e2024-05-23 19:41:52 +0800751 net_info.sim_state = MBTK_SIM_ABSENT;
752 }
liubin281ac462023-07-19 14:22:54 +0800753 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
liuyange22a25e2024-05-23 19:41:52 +0800754 {
755 sim_info_reg.sim = 18;
756 net_info.sim_state = MBTK_SIM_ABSENT;
757 }
liubin281ac462023-07-19 14:22:54 +0800758 else
759 sim_info_reg.sim = 20;
760
761 if(sim_info_reg.sim == 18)
762 {
763 uint8 data_pdp;
764 data_pdp = 11; //
765 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
766 }
767
768 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
769 }
770 // +CMT: ,23
771 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
772 else if(strStartsWith(s, "+CMT:") || sms_cmt)
773 {
774 if(!sms_cmt){
775 sms_cmt = true;
776 }else{
777 sms_cmt = false;
778 }
779 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
780 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
781 }
782#if 0
783 // LTE data registed.
784 // +CEREG: 1, "8330", "06447347", 7
785 else if(strStartsWith(s, "+CEREG:"))
786 {
787 char* tmp_s = memdup(s,strlen(s));
788 char* free_ptr = tmp_s;
789 char *line = tmp_s;
790 int tmp_int;
791 char *tmp_str;
792 if (at_tok_start(&line) < 0)
793 {
794 goto CREG_EXIT;
795 }
796 if (at_tok_nextint(&line, &tmp_int) < 0)
797 {
798 goto CREG_EXIT;
799 }
800 uint8 data = (uint8)tmp_int; // Reg State.
801
802 urc_msg_distribute(INFO_URC_MSG_NET_REG_STATE, &data, sizeof(uint8));
803CREG_EXIT:
804 free(free_ptr);
805 }
806#endif
807 /*
808 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
809 // <rsrp>,<rsrq>, <sinr>,
810 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
811 // cellId,subFrameAssignType,specialSubframePatterns,transMode
812 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
813 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
814 // dlBer, ulBer,
815 // diversitySinr, diversityRssi
816 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
817 0, 0, 0,
818 1, 10, 0, 1, 0, 1059, 78, 3959566565,
819 105149248, 2, 7, 7,
820 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
821 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
822 0, 0,
823 7, 44
824 */
825 else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
826 {
827 // tac, PCI, dlEuarfcn, ulEuarfcn, band
828 if(cell_info.running) {
829 int tmp_int;
830 int i = 0;
831 char* tmp_s = memdup(s,strlen(s));
832 char* free_ptr = tmp_s;
833 char *line = tmp_s;
834 if (at_tok_start(&line) < 0)
835 {
836 goto EEMLTESVC_EXIT;
837 }
838
839 if (at_tok_nextint(&line, &tmp_int) < 0)
840 {
841 goto EEMLTESVC_EXIT;
842 }
843 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
844 if (at_tok_nextint(&line, &tmp_int) < 0)
845 {
846 goto EEMLTESVC_EXIT;
847 }
848 if (at_tok_nextint(&line, &tmp_int) < 0)
849 {
850 goto EEMLTESVC_EXIT;
851 }
852 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
853 /*
854 // Jump 2 integer.
855 i = 0;
856 while(i < 2) {
857 if (at_tok_nextint(&line, &tmp_int) < 0)
858 {
859 goto EEMLTESVC_EXIT;
860 }
861 i++;
862 }
863 */
864 if (at_tok_nextint(&line, &tmp_int) < 0)
865 {
866 goto EEMLTESVC_EXIT;
867 }
868 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //tac
869 if (at_tok_nextint(&line, &tmp_int) < 0)
870 {
871 goto EEMLTESVC_EXIT;
872 }
873 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //pci
874 if (at_tok_nextint(&line, &tmp_int) < 0)
875 {
876 goto EEMLTESVC_EXIT;
877 }
878 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //dl arfcn
879 if (at_tok_nextint(&line, &tmp_int) < 0)
880 {
881 goto EEMLTESVC_EXIT;
882 }
883 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //ul arfcn
884 if (at_tok_nextint(&line, &tmp_int) < 0)
885 {
886 goto EEMLTESVC_EXIT;
887 }
888 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //band
889 if (at_tok_nextint(&line, &tmp_int) < 0)
890 {
891 goto EEMLTESVC_EXIT;
892 }
893 if (at_tok_nextint(&line, &tmp_int) < 0)
894 {
895 goto EEMLTESVC_EXIT;
896 }
897 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //cid
898 if (at_tok_nextint(&line, &tmp_int) < 0)
899 {
900 goto EEMLTESVC_EXIT;
901 }
902 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //rsrp
903
904 for(i =0; i < 10; i++)
905 {
906 if (at_tok_nextint(&line, &tmp_int) < 0)
907 {
908 goto EEMLTESVC_EXIT;
909 }
910 }
911 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //cell identiy
912
913 cell_info.cell_num++;
914
915EEMLTESVC_EXIT:
916 free(free_ptr);
917 }
918 }
919 /*
920 // index,phyCellId,euArfcn,rsrp,rsrq
921 +EEMLTEINTER: 0, 65535, 38950, 0, 0
922 */
923 else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
924 {
925 // phyCellId,euArfcn,rsrp,rsrq
926 if(cell_info.running) {
927 int tmp_int;
928 char* tmp_s = memdup(s,strlen(s));
929 char* free_ptr = tmp_s;
930 char *line = tmp_s;
931 if (at_tok_start(&line) < 0)
932 {
933 goto EEMLTEINTER_EXIT;
934 }
935 if (at_tok_nextint(&line, &tmp_int) < 0)
936 {
937 goto EEMLTEINTER_EXIT;
938 }
939 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
940 {
941 goto EEMLTEINTER_EXIT;
942 }
943 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
944 if (at_tok_nextint(&line, &tmp_int) < 0)
945 {
946 goto EEMLTEINTER_EXIT;
947 }
948 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
949 if (at_tok_nextint(&line, &tmp_int) < 0)
950 {
951 goto EEMLTEINTER_EXIT;
952 }
953 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
954 LOG("cell line : %s", line);
955 if (at_tok_nextint(&line, &tmp_int) < 0)
956 {
957 goto EEMLTEINTER_EXIT;
958 }
959 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
960 if (at_tok_nextint(&line, &tmp_int) < 0)
961 {
962 LOG("cell tmp_int : %d", tmp_int);
963 goto EEMLTEINTER_EXIT;
964 }
965 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
966 LOG("cell value5 : %d", cell_info.cell[cell_info.cell_num].value5);
967 cell_info.cell_num++;
968EEMLTEINTER_EXIT:
969 free(free_ptr);
970 }
971 }
972 // Do nothing
973 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
974 {
975 if(cell_info.running) {
976
977 }
978 }
979 // WCDMA
980 /*
981 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
982
983 // if sCMeasPresent == 1
984 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
985 // endif
986
987 // if sCParamPresent == 1
988 // rac, nom, mcc, mnc_len, mnc, lac, ci,
989 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
990 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
991 // endif
992
993 // if ueOpStatusPresent == 1
994 // rrcState, numLinks, srncId, sRnti,
995 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
996 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
997 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
998 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
999 // endif
1000 //
1001 +EEMUMTSSVC: 3, 1, 1, 1,
1002 -80, 27, -6, -18, -115, -32768,
1003 1, 1, 1120, 2, 1, 61697, 168432821,
1004 15, 24, 10763, 0, 0, 0, 0,
1005 128, 128, 65535, 0, 0,
1006 2, 255, 65535, 4294967295,
1007 0, 0, 0, 0, 0, 0,
1008 0, 0, 0, 0, 0, 0, 1, 1,
1009 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1010 0, 0, 0, 0, 0, 0
1011 */
1012 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1013 {
1014 // lac, ci, arfcn
1015 if(cell_info.running) {
1016 int tmp_int;
1017 int i = 0;
1018 char* tmp_s = memdup(s,strlen(s));
1019 char* free_ptr = tmp_s;
1020 char *line = tmp_s;
1021 if (at_tok_start(&line) < 0)
1022 {
1023 goto EEMUMTSSVC_EXIT;
1024 }
1025 // Jump 12 integer.
1026 i = 0;
1027 while(i < 12) {
1028 if (at_tok_nextint(&line, &tmp_int) < 0)
1029 {
1030 goto EEMUMTSSVC_EXIT;
1031 }
1032 i++;
1033 }
1034 // mcc
1035 if (at_tok_nextint(&line, &tmp_int) < 0)
1036 {
1037 goto EEMUMTSSVC_EXIT;
1038 }
1039 cell_info.cell[cell_info.cell_num].value4= (uint32)tmp_int;
1040 // mnc
1041 if (at_tok_nextint(&line, &tmp_int) < 0)
1042 {
1043 goto EEMUMTSSVC_EXIT;
1044 }
1045 cell_info.cell[cell_info.cell_num].value5= (uint32)tmp_int;
1046 // lac
1047 if (at_tok_nextint(&line, &tmp_int) < 0)
1048 {
1049 goto EEMUMTSSVC_EXIT;
1050 }
1051 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1052 // ci
1053 if (at_tok_nextint(&line, &tmp_int) < 0)
1054 {
1055 goto EEMUMTSSVC_EXIT;
1056 }
1057 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1058
1059 if (at_tok_nextint(&line, &tmp_int) < 0)
1060 {
1061 goto EEMUMTSSVC_EXIT;
1062 }
1063 // cpi
1064 if (at_tok_nextint(&line, &tmp_int) < 0)
1065 {
1066 goto EEMUMTSSVC_EXIT;
1067 }
1068 cell_info.cell[cell_info.cell_num].value6= (uint32)tmp_int;
1069 /*
1070 // Jump 2 integer.
1071 i = 0;
1072 while(i < 2) {
1073 if (at_tok_nextint(&line, &tmp_int) < 0)
1074 {
1075 goto EEMUMTSSVC_EXIT;
1076 }
1077 i++;
1078 }
1079 */
1080 // arfcn
1081 if (at_tok_nextint(&line, &tmp_int) < 0)
1082 {
1083 goto EEMUMTSSVC_EXIT;
1084 }
1085 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1086
1087 cell_info.cell_num++;
1088EEMUMTSSVC_EXIT:
1089 free(free_ptr);
1090 }
1091 }
1092 /*
1093 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1094 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1095 */
1096 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1097 {
1098 // lac, ci, arfcn
1099 if(cell_info.running) {
1100 int tmp_int;
1101 int i = 0;
1102 char* tmp_s = memdup(s,strlen(s));
1103 char* free_ptr = tmp_s;
1104 char *line = tmp_s;
1105 if (at_tok_start(&line) < 0)
1106 {
1107 goto EEMUMTSINTRA_EXIT;
1108 }
1109 // Jump 8 integer.
1110 i = 0;
1111 while(i < 8) {
1112 if (at_tok_nextint(&line, &tmp_int) < 0)
1113 {
1114 goto EEMUMTSINTRA_EXIT;
1115 }
1116 i++;
1117 }
1118
1119 // lac
1120 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1121 {
1122 goto EEMUMTSINTRA_EXIT;
1123 }
1124 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1125
1126 // ci
1127 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1128 {
1129 goto EEMUMTSINTRA_EXIT;
1130 }
1131 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1132
1133 // arfcn
1134 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1135 {
1136 goto EEMUMTSINTRA_EXIT;
1137 }
1138 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1139
1140 cell_info.cell_num++;
1141EEMUMTSINTRA_EXIT:
1142 free(free_ptr);
1143 }
1144 }
1145 /*
1146 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1147 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1148 */
1149 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1150 {
1151 // lac, ci, arfcn
1152 if(cell_info.running) {
1153 int tmp_int;
1154 int i = 0;
1155 char* tmp_s = memdup(s,strlen(s));
1156 char* free_ptr = tmp_s;
1157 char *line = tmp_s;
1158 if (at_tok_start(&line) < 0)
1159 {
1160 goto EEMUMTSINTERRAT_EXIT;
1161 }
1162 // Jump 7 integer.
1163 i = 0;
1164 while(i < 7) {
1165 if (at_tok_nextint(&line, &tmp_int) < 0)
1166 {
1167 goto EEMUMTSINTERRAT_EXIT;
1168 }
1169 i++;
1170 }
1171
1172 // lac
1173 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1174 {
1175 goto EEMUMTSINTERRAT_EXIT;
1176 }
1177 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1178
1179 // ci
1180 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1181 {
1182 goto EEMUMTSINTERRAT_EXIT;
1183 }
1184 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1185
1186 // arfcn
1187 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1188 {
1189 goto EEMUMTSINTERRAT_EXIT;
1190 }
1191 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1192
1193 cell_info.cell_num++;
1194EEMUMTSINTERRAT_EXIT:
1195 free(free_ptr);
1196 }
1197 }
1198 // GSM
1199 // +EEMGINFOBASIC: 2
1200 // Do nothing.
1201 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1202 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1203 {
1204 if(cell_info.running) {
1205
1206 }
1207 }
1208 /*
1209 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1210 // bsic, C1, C2, TA, TxPwr,
1211 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1212 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1213 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1214 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1215 // gsmBand,channelMode
1216 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1217 63, 36, 146, 1, 7,
1218 46, 42, 42, 7, 0,
1219 53, 0, 8, 0, 1, 6, 53,
1220 2, 0, 146, 42, 54, 0, 1,
1221 1, 32, 0, 0, 0, 0,
1222 0, 0
1223 */
1224 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1225 {
1226 // lac, ci, arfcn, bsic
1227 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1228 if(cell_info.running) {
1229 int tmp_int;
1230 int i = 0;
1231 char* tmp_s = memdup(s,strlen(s));
1232 char* free_ptr = tmp_s;
1233 char *line = tmp_s;
1234 if (at_tok_start(&line) < 0)
1235 {
1236 goto EEMGINFOSVC_EXIT;
1237 }
1238
1239 // mcc
1240 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1241 {
1242 goto EEMGINFOSVC_EXIT;
1243 }
1244 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1245
1246 //mnc_len
1247 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1248 {
1249 goto EEMGINFOSVC_EXIT;
1250 }
1251 // mnc
1252 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1253 {
1254 goto EEMGINFOSVC_EXIT;
1255 }
1256 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1257
1258 /*
1259 // Jump 3 integer.
1260 i = 0;
1261 while(i < 3) {
1262 if (at_tok_nextint(&line, &tmp_int) < 0)
1263 {
1264 goto EEMGINFOSVC_EXIT;
1265 }
1266 i++;
1267 }
1268 */
1269 // lac
1270 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1271 {
1272 goto EEMGINFOSVC_EXIT;
1273 }
1274 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1275
1276 // ci
1277 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1278 {
1279 goto EEMGINFOSVC_EXIT;
1280 }
1281 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1282
1283 // Jump 2 integer.
1284 i = 0;
1285 while(i < 2) {
1286 if (at_tok_nextint(&line, &tmp_int) < 0)
1287 {
1288 goto EEMGINFOSVC_EXIT;
1289 }
1290 i++;
1291 }
1292
1293 // bsic
1294 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1295 {
1296 goto EEMGINFOSVC_EXIT;
1297 }
1298 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1299
1300 // Jump 15 integer.
1301 i = 0;
1302 while(i < 15) {
1303 if (at_tok_nextint(&line, &tmp_int) < 0)
1304 {
1305 goto EEMGINFOSVC_EXIT;
1306 }
1307 i++;
1308 }
1309
1310 // arfcn
1311 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1312 {
1313 goto EEMGINFOSVC_EXIT;
1314 }
1315 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1316
1317 cell_info.cell_num++;
1318EEMGINFOSVC_EXIT:
1319 free(free_ptr);
1320 }
1321 }
1322 /*
1323 // PS_attached, attach_type, service_type, tx_power, c_value,
1324 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1325 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1326 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1327 +EEMGINFOPS: 1, 255, 0, 0, 0,
1328 0, 0, 268435501, 1, 0, 0,
1329 4, 0, 96, 0, 0, 0,
1330 0, 0, 0, 65535, 0, 13350
1331 */
1332 // Do nothing.
1333 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1334 {
1335 if(cell_info.running) {
1336
1337 }
1338 }
1339 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1340 {
1341 if(cell_info.running) {
1342 int tmp_int;
1343 int i = 0;
1344 char* tmp_s = memdup(s,strlen(s));
1345 char* free_ptr = tmp_s;
1346 char *line = tmp_s;
1347 if (at_tok_start(&line) < 0)
1348 {
1349 goto EEMGINFOPS_EXIT;
1350 }
1351
1352 // nc_num
1353 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1354 {
1355 LOG("cell_info.running 1= %d\n.",cell_info.running);
1356 goto EEMGINFOPS_EXIT;
1357 }
1358 // mcc
1359 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1360 {
1361 LOG("cell_info.running 2= %d\n.",cell_info.running);
1362 goto EEMGINFOPS_EXIT;
1363 }
1364 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1365
1366 // mnc
1367 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1368 {
1369 LOG("cell_info.running 3= %d\n.",cell_info.running);
1370 goto EEMGINFOPS_EXIT;
1371 }
1372 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1373
1374 // lac
1375 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1376 {
1377 LOG("cell_info.running 4= %d\n.",cell_info.running);
1378 goto EEMGINFOPS_EXIT;
1379 }
1380 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1381
1382 // rac
1383 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1384 {
1385 LOG("cell_info.running 5= %d\n.",cell_info.running);
1386 goto EEMGINFOPS_EXIT;
1387 }
1388
1389 // ci
1390 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1391 {
1392 LOG("cell_info.running 6= %d\n.",cell_info.running);
1393 goto EEMGINFOPS_EXIT;
1394 }
1395 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1396
1397 // rx_lv
1398 if (at_tok_nextint(&line, &tmp_int) < 0)
1399 {
1400 LOG("cell_info.running 7= %d\n.",cell_info.running);
1401 goto EEMGINFOPS_EXIT;
1402 }
1403
1404 // bsic
1405 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1406 {
1407 LOG("cell_info.running 8= %d\n.",cell_info.running);
1408 goto EEMGINFOPS_EXIT;
1409 }
1410 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1411
1412 // Jump 2 integer.
1413 i = 0;
1414 while(i < 2) {
1415 if (at_tok_nextint(&line, &tmp_int) < 0)
1416 {
1417 LOG("cell_info.running 9= %d\n.",cell_info.running);
1418 goto EEMGINFOPS_EXIT;
1419 }
1420 i++;
1421 }
1422
1423 // arfcn
1424 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1425 {
1426 LOG("cell_info.running 10 = %d\n.",cell_info.running);
1427 goto EEMGINFOPS_EXIT;
1428 }
1429 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1430
1431 cell_info.cell_num++;
1432EEMGINFOPS_EXIT:
1433 free(free_ptr);
1434 }
1435 }
1436 else if(strStartsWith(s, "+ZGIPDNS:")) // +ZGIPDNS: 1,"IPV4V6","10.156.239.245","10.156.239.246","223.87.253.100","223.87.253.253","fe80:0000:0000:0000:0001:0001:9b8c:7c0c","fe80::1:1:9b8c:7c0d","2409:8062:2000:2::1","2409:8062:2000:2::2"
1437 {
1438
1439 }
1440 else
1441 {
1442 LOGV("Unknown URC : %s", s);
1443 }
1444}
1445
1446static int openSocket(const char* sockname)
1447{
1448 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
1449 if (sock < 0)
1450 {
1451 LOGE("Error create socket: %s\n", strerror(errno));
1452 return -1;
1453 }
1454 struct sockaddr_un addr;
1455 memset(&addr, 0, sizeof(addr));
1456 addr.sun_family = AF_UNIX;
1457 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
1458 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
1459 {
1460 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
1461 sleep(1);
1462 }
1463
1464#if 0
1465 int sk_flags = fcntl(sock, F_GETFL, 0);
1466 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
1467#endif
1468
1469 return sock;
1470}
1471
1472static void ril_get_cgpaddr_ip_process()
1473{
1474 int err, skip;
1475 ATResponse *p_response = NULL;
1476 char *line;
1477 char *ipv4 = NULL, *ipv6 = NULL;
1478 err = at_send_command_singleline("AT+CGPADDR", "+CGPADDR:", &p_response);
1479 if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
1480 {
1481 LOGE("+CGPADDR exec error.");
1482 goto error;
1483 }
1484
1485 // +CGPADDR: 1, "10.51.59.229", "254.128.0.0.0.0.0.0.0.1.0.0.111.176.63.99"
1486 // +CGPADDR: 1, "10.124.139.131"
1487 line = p_response->p_intermediates->line;
1488 err = at_tok_start(&line);
1489 if (err < 0)
1490 {
1491 goto error;
1492 }
1493
1494 err = at_tok_nextint(&line, &skip);
1495 if (err < 0)
1496 {
1497 goto error;
1498 }
1499
1500 if (!at_tok_hasmore(&line))
1501 {
1502 goto error;
1503 }
1504
1505 err = at_tok_nextstr(&line, &ipv4);
1506 if (err < 0)
1507 {
1508 LOGE("Get IPv4 fail.");
1509 goto error;
1510 }
1511
1512 if (at_tok_hasmore(&line))
1513 {
1514 err = at_tok_nextstr(&line, &ipv6);
1515 if (err < 0)
1516 {
1517 LOGE("Get IPv6 fail.");
1518 goto error;
1519 }
1520 }
1521 else
1522 {
1523 LOGD("No IPv6 Found.");
1524 }
1525
1526 if(ipv6)
1527 {
1528 LOGD("IPv6 : %s", ipv6);
1529 }
1530
1531 if(ipv4)
1532 {
1533 LOGD("IPv4 : %s", ipv4);
1534
1535// ril_net_dev_config("ccinet0", ipv4, NULL);
1536 }
1537error:
1538 at_response_free(p_response);
1539}
1540
1541static void sim_state_change(bool plug_in) {
1542 if(plug_in) {
1543 // If radio on,must off in the first.
1544 if(net_info.radio_state == MBTK_RADIO_STATE_ON) {
1545 setRadioPower(0);
1546 }
1547 setRadioPower(1);
1548 } else {
1549 setRadioPower(0);
1550 }
1551}
1552
1553static int open_uevent_socket()
1554{
1555 struct sockaddr_nl addr;
1556 int sz = 64*1024;
1557 int s = 0;
1558
1559 memset(&addr, 0, sizeof(addr));
1560 addr.nl_family = AF_NETLINK;
1561 addr.nl_pid = getpid();
1562 addr.nl_groups = 0xffffffff;
1563
1564 s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
1565 if (s < 0)
1566 {
1567 LOGE("socket() fail.[%d]", errno);
1568 return -1;
1569 }
1570
1571 setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz));
1572
1573 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0)
1574 {
1575 close(s);
1576 return -1;
1577 }
1578
1579 return s;
1580}
1581
1582static void parse_uevent(const char *msg, int msg_len, struct cooling_device *cdev)
1583{
1584 // change@/devices/virtual/usim_event/usim0\0
1585 // ACTION=change\0
1586 // DEVPATH=/devices/virtual/usim_event/usim0\0
1587 // SUBSYSTEM=usim_event\0
1588 // USIM_NAME=usim0\0
1589 // USIM_EVENT=plugout\0
1590 // SEQNUM=704
1591 int i = 0;
1592 while (i < msg_len)
1593 {
1594 if(*(msg + i) == '\0')
1595 {
1596 i++;
1597 continue;
1598 }
1599 if (!strncmp(msg + i, "USIM_NAME=", 10))
1600 {
1601 i += 10;
1602 cdev->name = msg + i;
1603 i += strlen(msg + i);
1604 }
1605 else if (!strncmp(msg + i, "ACTION=", 7))
1606 {
1607 i += 7;
1608 cdev->action = msg + i;
1609 i += strlen(msg + i);
1610 }
1611 else if (!strncmp(msg + i, "DEVPATH=", 8))
1612 {
1613 i += 8;
1614 cdev->path = msg + i;
1615 i += strlen(msg + i);
1616 }
1617 else if (!strncmp(msg + i, "USIM_EVENT=", 11))
1618 {
1619 i += 11;
1620 cdev->event = msg + i;
1621 i += strlen(msg + i);
1622 }
1623 else if (!strncmp(msg + i, "SUBSYSTEM=", 10))
1624 {
1625 i += 10;
1626 cdev->subsystem = msg + i;
1627 i += strlen(msg + i);
1628 }
1629 else
1630 {
1631 i++;
1632 }
1633 }
1634
1635 if(!strncmp(cdev->path, UEVENT_USIM_DEV, sizeof(UEVENT_USIM_DEV))
1636 && !strncmp(cdev->action, "change", 5))
1637 {
1638 LOGD("event { name=%s, action=%s, path=%s, subsystem=%s, event=%s}",
1639 cdev->name, cdev->action, cdev->path, cdev->subsystem, cdev->event);
1640 if(!strcmp(cdev->event, "plugout"))
1641 {
1642 sim_state_change(FALSE);
1643 }
1644 else if(!strcmp(cdev->event, "plugin"))
1645 {
1646 sim_state_change(TRUE);
1647 }
1648 else
1649 {
1650 LOGE("usim evnet error!");
1651 }
1652 }
1653}
1654
1655static void* uevnet_run(void *payload)
1656{
1657 int socket_fd = -1;
1658 char msg[BUFFER_SIZE+2];
1659 int n;
1660
1661 socket_fd = open_uevent_socket();
1662 if(socket_fd > 0)
1663 {
1664 while(1)
1665 {
1666 if((n = recv(socket_fd, msg, BUFFER_SIZE, 0)) > 0)
1667 {
1668 struct cooling_device cdev;
1669 memset(&cdev, 0x0, sizeof(cdev));
1670
1671 if(n == BUFFER_SIZE)
1672 continue;
1673 msg[n] = '\0';
1674 // change@/devices/virtual/usim_event/usim0\0ACTION=change\0DEVPATH=/devices/virtual/usim_event/usim0\0SUBSYSTEM=usim_event\0USIM_NAME=usim0\0USIM_EVENT=plugout\0SEQNUM=704
1675 log_hex("UEVENT", msg, n);
1676 parse_uevent(msg, n, &cdev);
1677 }
1678 else
1679 {
1680 LOGE("recv msg error.");
1681 }
1682 }
1683 }
1684
1685 LOGD("UEVENT Thread exit!!!");
1686 return NULL;
1687}
1688
1689int uevent_main()
1690{
1691 mbtk_task_info task;
1692 task.task_id = &uevnet_task_id;
1693 task.thread_run = uevnet_run;
1694 task.args = NULL;
1695 return mbtk_task_start(&task);
1696}
1697
1698/*
1699int ril_main()
1700{
1701 return mbtk_task_queue_start(&ril_task, ril_main_run);
1702}
1703*/
1704
1705int mbtk_info_server_start();
1706int InProduction_Mode(void);
1707void server_ready_set(void);
1708
1709
1710/*
1711 *Get mtdblock which name is ASR_FLAG
1712 *return path if found, else return NULL
1713 */
1714static int asrFlagPathGet(char *asr_flag_path)
1715{
1716 char buf[128];
1717 unsigned char find = 0;
1718 FILE *fd = fopen("/proc/mtd", "r");
1719 if (fd == NULL) {
1720 LOGE("Open MTD failed!");
1721 return -1;
1722 }
1723
1724 memset(buf, '\0', 128);
1725 while (fgets(buf, 128, fd) != NULL) {
1726 if(strstr(buf, "asr_flag")) {
1727 char *p = strstr(buf, "mtd");
1728 if(p)
1729 {
1730 int bln;
1731 sscanf(p, "mtd%d", &bln);
1732 sprintf(asr_flag_path, "/dev/mtdblock%d", bln);
1733 find = 1;
1734 break;
1735 }
1736 }
1737 memset(buf, '\0', 128);
1738 }
1739
1740 fclose(fd);
1741 return ((find == 1) ? 0 : -1);
1742}
1743
1744static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)
1745{
1746 int ret, fd;
1747 if (!path)
1748 return -1;
1749
1750 fd = open(path, O_RDONLY);
1751 if (fd < 0) {
1752 LOGE("readFromMTD open error,%d", errno);
1753 return -1;
1754 }
1755
1756 ret = lseek(fd, offset, SEEK_SET);
1757 if (ret < 0) {
1758 close(fd);
1759 LOGE("readFromMTD lseek error,%d", errno);
1760 return -1;
1761 }
1762 ret = read(fd, buf, size);
1763 if (ret < 0) {
1764 close(fd);
1765 LOGE("readFromMTD read error,%d", errno);
1766 return -1;
1767 }
1768 close(fd);
1769 return 0;
1770}
1771
1772static int writeToMTD(const char *path, unsigned int offset, void *buf, int size)
1773{
1774 int ret, fd;
1775
1776 if (!path)
1777 return -1;
1778
1779 fd = open(path, O_RDWR | O_SYNC);
1780 if (fd < 0)
1781 return -1;
1782
1783 ret = lseek(fd, offset, SEEK_SET);
1784 if (ret < 0) {
1785 close(fd);
1786 return -1;
1787 }
1788 ret = write(fd, buf, size);
1789 if (ret < 0) {
1790 LOGE("writetomtd:write error:%d", errno);
1791 close(fd);
1792 return -1;
1793 }
1794
1795 close(fd);
1796 return 0;
1797}
1798
1799static void fota_result_check()
1800{
1801#if 0
1802 ASR_flag tag;
1803 char asr_flag_path[30] = {0};
1804 if(asrFlagPathGet(asr_flag_path)) {
1805 LOGE("getAsrFlagPath() fail.");
1806 return;
1807 }
1808
1809 if(readFromMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
1810 {
1811 LOGE("Get FOTA result fail.");
1812 }
1813 else
1814 {
1815 LOGD("FOTA result : %d, %d", tag.fota_result[0], tag.fota_result[1]);
1816 tag.fota_result[0] = 0;
1817 tag.fota_result[1] = 0;
1818 if(writeToMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
1819 {
1820 LOGE("FOTA result update fail.");
1821 } else {
1822 LOGD("FOTA result update success.");
1823 }
1824 }
1825#endif
1826}
1827
1828static void mbtk_server_ready()
1829{
1830 // /etc/init.d/mbtk_boot_server_ready
1831 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
1832 system(MBTK_BOOT_SERVER_READY);
1833 } else {
1834 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
1835 }
1836}
1837
1838#if 1
1839int main(int argc, char *argv[])
1840{
1841 mbtk_log_init("radio", "MBTK_RIL");
1842 LOGI("mbtk_ril start.");
1843
1844 if(InProduction_Mode()) {
1845 LOGI("Is Production Mode, will exit...");
1846 exit(0);
1847 }
1848
1849 int at_sock = openSocket("/tmp/atcmd_at");
1850 if(at_sock < 0)
1851 {
1852 LOGE("Open AT Socket Fail[%d].", errno);
1853 return -1;
1854 }
1855 int uart_sock = openSocket("/tmp/atcmd_urc");
1856 if(uart_sock < 0)
1857 {
1858 LOGE("Open Uart Socket Fail[%d].", errno);
1859 return -1;
1860 }
1861
1862 at_set_on_reader_closed(onATReaderClosed);
1863 at_set_on_timeout(onATTimeout);
1864
1865 if(at_open(at_sock, uart_sock, onUnsolicited))
1866 {
1867 LOGE("Start AT thread fail.");
1868 return -1;
1869 }
1870
1871#if 1
1872 if(at_handshake())
1873 {
1874 LOGE("AT handshake fail.");
1875 return -1;
1876 }
1877#endif
1878
1879 LOGD("AT OK.");
1880
1881 if(mbtk_info_server_start())
1882 {
1883 LOGE("mbtk_info_server_start() fail.");
1884 return -1;
1885 }
wangyouqiang38e53362024-01-23 10:53:48 +08001886
1887#ifdef MBTK_PROJECT_T108
1888 mbtk_led_init();
1889#endif
liubin281ac462023-07-19 14:22:54 +08001890
1891#if 0
1892 if(uevent_main())
1893 {
1894 LOGE("Start uevent thread fail.");
1895 return -1;
1896 }
1897#endif
1898
1899 char time_type[10];
1900 memset(time_type, 0, 10);
1901 property_get("persist.mbtk.time_type", time_type, "0");
1902 if(atoi(time_type) == MBTK_TIME_TYPE_NTP) { // NTP time
1903 LOG("Start NTP thread.");
1904 ntp_thread_start();
1905 }
1906
1907 fota_result_check();
1908
1909 mbtk_server_ready();
1910
1911 server_ready_set();//Set the server readiness state
1912 while(1)
1913 {
1914 sleep(24 * 60 * 60);
1915 }
1916
1917 LOGD("!!!mbtk_ril exit!!!");
1918 return 0;
1919}
1920
1921#else
1922int main()
1923{
1924 char buff[BUFFER_SIZE + 1] = {0};
1925 if(!mbtk_at("AT+CFUN=1", buff, BUFFER_SIZE))
1926 {
1927 LOGD("+CFUN RSP:%s", buff);
1928 while(1)
1929 {
1930 sleep(1);
1931 memset(buff, 0x0, BUFFER_SIZE + 1);
1932 if(!mbtk_at("AT+CGPADDR", buff, BUFFER_SIZE))
1933 {
1934 LOGD("+CGPADDR RSP:%s", buff);
1935 if(strstr(buff, "+CGPADDR:"))
1936 {
1937 // +CGPADDR: 1, "10.99.223.168", "254.128.0.0.0.0.0.0.0.1.0.0.117.9.250.59"
1938 //
1939 // OK
1940 char *ip_start = NULL;
1941 char *ip_end = NULL;
1942 char ipv4[50] = {0};
1943 ip_start = strstr(buff,"\"");
1944 if(ip_start)
1945 ip_end = strstr(ip_start + 1, "\"");
1946 if(ip_start && ip_end && ip_end - ip_start - 1 > 0)
1947 {
1948 memcpy(ipv4, ip_start + 1, ip_end - ip_start - 1);
1949 LOGD("IP : %s", ipv4);
1950 if(!mbtk_ifc_open())
1951 {
1952 in_addr_t addr;
1953 inet_aton(ipv4,(struct in_addr *)&addr);
1954 LOGD("IP : %s -> %x", ipv4, addr);
1955 if(!mbtk_ifc_set_addr("ccinet0", addr, 0))
1956 {
1957 mbtk_ifc_up("ccinet0");
1958 }
1959
1960 mbtk_ifc_close();
1961 }
1962
1963 system("route add default dev ccinet0");
1964
1965 LOGD("Set IP success.");
1966 }
1967 else
1968 {
1969 LOGD("Get IP fail.");
1970 }
1971
1972 break;
1973 }
1974 }
1975 }
1976 }
1977
1978 return 0;
1979}
1980#endif