blob: 8741e8d0150f5bf08f2e0a66e5c7e7ca7c296ff4 [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
r.xiao195e2522024-05-31 03:19:02 -0700551 if(reg.state == 4 && reg.dir == 1)
552 {
553 mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
554 }
555
556
liubin281ac462023-07-19 14:22:54 +0800557 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
558CLCC_EXIT:
559 free(free_ptr);
560 }
561 // +CPAS: 4
562 else if(strStartsWith(s, "+CPAS:"))
563 {
564 mbtk_call_info_t reg;
565 reg.call_wait = 0;
566 char* tmp_s = memdup(s,strlen(s));
567 char* free_ptr = tmp_s;
568 char *line = tmp_s;
569 int tmp_int;
570 int err;
571
572 memset(&reg,0,sizeof(reg));
573
574 err = at_tok_start(&line);
575 if (err < 0)
576 {
577 goto CPAS_EXIT;
578 }
579 err = at_tok_nextint(&line, &tmp_int);
580 if (err < 0)
581 {
582 goto CPAS_EXIT;
583 }
584 reg.pas = (uint8)tmp_int;
585 reg.call_wait = MBTK_CPAS;
586 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
587CPAS_EXIT:
588 free(free_ptr);
589 }
590 // +CALLDISCONNECT: 1
591 else if(strStartsWith(s, "+CALLDISCONNECT:"))
592 {
593 mbtk_call_info_t reg;
594 reg.call_wait = 0;
595 char* tmp_s = memdup(s,strlen(s));
596 char* free_ptr = tmp_s;
597 char *line = tmp_s;
598 int tmp_int;
599 int err;
600
601 memset(&reg,0,sizeof(reg));
602
603 err = at_tok_start(&line);
604 if (err < 0)
605 {
606 goto CALLDISCONNECTED_EXIT;
607 }
608 err = at_tok_nextint(&line, &tmp_int);
609 if (err < 0)
610 {
611 goto CALLDISCONNECTED_EXIT;
612 }
613 reg.disconnected_id = tmp_int;
614 reg.call_wait = MBTK_DISCONNECTED;
r.xiaoe1404b32024-05-23 22:43:39 -0700615
616 if(reg.call_wait == MBTK_DISCONNECTED)
617 {
618 mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
619 }
620
liubin281ac462023-07-19 14:22:54 +0800621 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
622
623CALLDISCONNECTED_EXIT:
624 free(free_ptr);
625 }
626 // *SIMDETEC:1,SIM
627 else if(strStartsWith(s, "*SIMDETEC:"))
628 {
liuyange22a25e2024-05-23 19:41:52 +0800629 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
630 {
631 net_info.sim_state = MBTK_SIM_ABSENT;
632 }
633
liubin281ac462023-07-19 14:22:54 +0800634 sim_info_reg.sim = -1;
635 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
636 sim_info_reg.sim = 0;
637 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
638 sim_info_reg.sim = 1;
639 if(sim_info_reg.sim == 0)
640 {
641 uint8 data_pdp;
642 data_pdp = 11; //
643 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
644 }
645 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
646 }
647 // *EUICC:1
648/*0: SIM
6491: USIM
6502: TEST SIM
6513: TEST USIM
6524: UNKNOWN
653Note: *EUICC:
654*/
655 else if(strStartsWith(s, "*EUICC:"))
656 {
657 sim_info_reg.sim_card_type = -1;
658 if(strStartsWith(s, "*EUICC: 0"))
659 sim_info_reg.sim_card_type = 1;
660 else if(strStartsWith(s, "*EUICC: 1"))
661 sim_info_reg.sim_card_type = 2;
662 else if(strStartsWith(s, "*EUICC: 2"))
663 sim_info_reg.sim_card_type = 1;
664 else if(strStartsWith(s, "*EUICC: 3"))
665 sim_info_reg.sim_card_type = 2;
666 else if(strStartsWith(s, "*EUICC: 4"))
667 sim_info_reg.sim_card_type = 0;
668 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
669 }
670 // +CPIN: SIM PIN
671 else if(strStartsWith(s, "+CPIN:"))
672 {
673 sim_info_reg.sim = -1;
674 if(strStartsWith(s, "+CPIN: READY"))
liuyange22a25e2024-05-23 19:41:52 +0800675 {
liubin281ac462023-07-19 14:22:54 +0800676 sim_info_reg.sim = 1;
liuyange22a25e2024-05-23 19:41:52 +0800677 net_info.sim_state = MBTK_SIM_READY;
678 }
liubin281ac462023-07-19 14:22:54 +0800679 else if(strStartsWith(s, "+CPIN: SIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800680 {
liubin281ac462023-07-19 14:22:54 +0800681 sim_info_reg.sim = 2;
liuyange22a25e2024-05-23 19:41:52 +0800682 net_info.sim_state = MBTK_SIM_PIN;
683 }
liubin281ac462023-07-19 14:22:54 +0800684 else if(strStartsWith(s, "+CPIN: SIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800685 {
liubin281ac462023-07-19 14:22:54 +0800686 sim_info_reg.sim = 3;
liuyange22a25e2024-05-23 19:41:52 +0800687 net_info.sim_state = MBTK_SIM_PUK;
688 }
liubin281ac462023-07-19 14:22:54 +0800689 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800690 {
liubin281ac462023-07-19 14:22:54 +0800691 sim_info_reg.sim = 4;
liuyange22a25e2024-05-23 19:41:52 +0800692 net_info.sim_state = MBTK_SIM_ABSENT;
693 }
liubin281ac462023-07-19 14:22:54 +0800694 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800695 {
liubin281ac462023-07-19 14:22:54 +0800696 sim_info_reg.sim = 5;
liuyange22a25e2024-05-23 19:41:52 +0800697 net_info.sim_state = MBTK_SIM_ABSENT;
698 }
liubin281ac462023-07-19 14:22:54 +0800699 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800700 {
liubin281ac462023-07-19 14:22:54 +0800701 sim_info_reg.sim = 6;
liuyange22a25e2024-05-23 19:41:52 +0800702 net_info.sim_state = MBTK_SIM_ABSENT;
703 }
liubin281ac462023-07-19 14:22:54 +0800704 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800705 {
liubin281ac462023-07-19 14:22:54 +0800706 sim_info_reg.sim = 7;
liuyange22a25e2024-05-23 19:41:52 +0800707 net_info.sim_state = MBTK_SIM_ABSENT;
708 }
liubin281ac462023-07-19 14:22:54 +0800709 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
liuyange22a25e2024-05-23 19:41:52 +0800710 {
liubin281ac462023-07-19 14:22:54 +0800711 sim_info_reg.sim = 8;
liuyange22a25e2024-05-23 19:41:52 +0800712 net_info.sim_state = MBTK_SIM_ABSENT;
713 }
liubin281ac462023-07-19 14:22:54 +0800714 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
liuyange22a25e2024-05-23 19:41:52 +0800715 {
liubin281ac462023-07-19 14:22:54 +0800716 sim_info_reg.sim = 9;
liuyange22a25e2024-05-23 19:41:52 +0800717 net_info.sim_state = MBTK_SIM_ABSENT;
718 }
liubin281ac462023-07-19 14:22:54 +0800719 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800720 {
liubin281ac462023-07-19 14:22:54 +0800721 sim_info_reg.sim = 10;
liuyange22a25e2024-05-23 19:41:52 +0800722 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
723 }
liubin281ac462023-07-19 14:22:54 +0800724 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800725 {
liubin281ac462023-07-19 14:22:54 +0800726 sim_info_reg.sim = 11;
liuyange22a25e2024-05-23 19:41:52 +0800727 net_info.sim_state = MBTK_SIM_ABSENT;
728 }
liubin281ac462023-07-19 14:22:54 +0800729 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
liuyange22a25e2024-05-23 19:41:52 +0800730 {
liubin281ac462023-07-19 14:22:54 +0800731 sim_info_reg.sim = 12;
liuyange22a25e2024-05-23 19:41:52 +0800732 net_info.sim_state = MBTK_SIM_ABSENT;
733 }
liubin281ac462023-07-19 14:22:54 +0800734 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800735 {
liubin281ac462023-07-19 14:22:54 +0800736 sim_info_reg.sim = 13;
liuyange22a25e2024-05-23 19:41:52 +0800737 net_info.sim_state = MBTK_SIM_ABSENT;
738 }
liubin281ac462023-07-19 14:22:54 +0800739 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800740 {
liubin281ac462023-07-19 14:22:54 +0800741 sim_info_reg.sim = 14;
liuyange22a25e2024-05-23 19:41:52 +0800742 net_info.sim_state = MBTK_SIM_ABSENT;
743 }
liubin281ac462023-07-19 14:22:54 +0800744 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800745 {
liubin281ac462023-07-19 14:22:54 +0800746 sim_info_reg.sim = 15;
liuyange22a25e2024-05-23 19:41:52 +0800747 net_info.sim_state = MBTK_SIM_ABSENT;
748 }
liubin281ac462023-07-19 14:22:54 +0800749 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800750 {
liubin281ac462023-07-19 14:22:54 +0800751 sim_info_reg.sim = 16;
liuyange22a25e2024-05-23 19:41:52 +0800752 net_info.sim_state = MBTK_SIM_ABSENT;
753 }
liubin281ac462023-07-19 14:22:54 +0800754 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800755 {
liubin281ac462023-07-19 14:22:54 +0800756 sim_info_reg.sim = 17;
liuyange22a25e2024-05-23 19:41:52 +0800757 net_info.sim_state = MBTK_SIM_ABSENT;
758 }
liubin281ac462023-07-19 14:22:54 +0800759 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
liuyange22a25e2024-05-23 19:41:52 +0800760 {
761 sim_info_reg.sim = 18;
762 net_info.sim_state = MBTK_SIM_ABSENT;
763 }
liubin281ac462023-07-19 14:22:54 +0800764 else
765 sim_info_reg.sim = 20;
766
767 if(sim_info_reg.sim == 18)
768 {
769 uint8 data_pdp;
770 data_pdp = 11; //
771 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
772 }
773
774 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
775 }
776 // +CMT: ,23
777 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
778 else if(strStartsWith(s, "+CMT:") || sms_cmt)
779 {
780 if(!sms_cmt){
781 sms_cmt = true;
782 }else{
783 sms_cmt = false;
784 }
785 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
786 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
787 }
788#if 0
789 // LTE data registed.
790 // +CEREG: 1, "8330", "06447347", 7
791 else if(strStartsWith(s, "+CEREG:"))
792 {
793 char* tmp_s = memdup(s,strlen(s));
794 char* free_ptr = tmp_s;
795 char *line = tmp_s;
796 int tmp_int;
797 char *tmp_str;
798 if (at_tok_start(&line) < 0)
799 {
800 goto CREG_EXIT;
801 }
802 if (at_tok_nextint(&line, &tmp_int) < 0)
803 {
804 goto CREG_EXIT;
805 }
806 uint8 data = (uint8)tmp_int; // Reg State.
807
808 urc_msg_distribute(INFO_URC_MSG_NET_REG_STATE, &data, sizeof(uint8));
809CREG_EXIT:
810 free(free_ptr);
811 }
812#endif
813 /*
814 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
815 // <rsrp>,<rsrq>, <sinr>,
816 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
817 // cellId,subFrameAssignType,specialSubframePatterns,transMode
818 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
819 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
820 // dlBer, ulBer,
821 // diversitySinr, diversityRssi
822 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
823 0, 0, 0,
824 1, 10, 0, 1, 0, 1059, 78, 3959566565,
825 105149248, 2, 7, 7,
826 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
827 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
828 0, 0,
829 7, 44
830 */
831 else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
832 {
833 // tac, PCI, dlEuarfcn, ulEuarfcn, band
834 if(cell_info.running) {
835 int tmp_int;
836 int i = 0;
837 char* tmp_s = memdup(s,strlen(s));
838 char* free_ptr = tmp_s;
839 char *line = tmp_s;
840 if (at_tok_start(&line) < 0)
841 {
842 goto EEMLTESVC_EXIT;
843 }
844
845 if (at_tok_nextint(&line, &tmp_int) < 0)
846 {
847 goto EEMLTESVC_EXIT;
848 }
849 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
850 if (at_tok_nextint(&line, &tmp_int) < 0)
851 {
852 goto EEMLTESVC_EXIT;
853 }
854 if (at_tok_nextint(&line, &tmp_int) < 0)
855 {
856 goto EEMLTESVC_EXIT;
857 }
858 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
859 /*
860 // Jump 2 integer.
861 i = 0;
862 while(i < 2) {
863 if (at_tok_nextint(&line, &tmp_int) < 0)
864 {
865 goto EEMLTESVC_EXIT;
866 }
867 i++;
868 }
869 */
870 if (at_tok_nextint(&line, &tmp_int) < 0)
871 {
872 goto EEMLTESVC_EXIT;
873 }
874 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //tac
875 if (at_tok_nextint(&line, &tmp_int) < 0)
876 {
877 goto EEMLTESVC_EXIT;
878 }
879 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //pci
880 if (at_tok_nextint(&line, &tmp_int) < 0)
881 {
882 goto EEMLTESVC_EXIT;
883 }
884 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //dl arfcn
885 if (at_tok_nextint(&line, &tmp_int) < 0)
886 {
887 goto EEMLTESVC_EXIT;
888 }
889 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //ul arfcn
890 if (at_tok_nextint(&line, &tmp_int) < 0)
891 {
892 goto EEMLTESVC_EXIT;
893 }
894 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //band
895 if (at_tok_nextint(&line, &tmp_int) < 0)
896 {
897 goto EEMLTESVC_EXIT;
898 }
899 if (at_tok_nextint(&line, &tmp_int) < 0)
900 {
901 goto EEMLTESVC_EXIT;
902 }
903 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //cid
904 if (at_tok_nextint(&line, &tmp_int) < 0)
905 {
906 goto EEMLTESVC_EXIT;
907 }
908 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //rsrp
909
910 for(i =0; i < 10; i++)
911 {
912 if (at_tok_nextint(&line, &tmp_int) < 0)
913 {
914 goto EEMLTESVC_EXIT;
915 }
916 }
917 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //cell identiy
918
919 cell_info.cell_num++;
920
921EEMLTESVC_EXIT:
922 free(free_ptr);
923 }
924 }
925 /*
926 // index,phyCellId,euArfcn,rsrp,rsrq
927 +EEMLTEINTER: 0, 65535, 38950, 0, 0
928 */
929 else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
930 {
931 // phyCellId,euArfcn,rsrp,rsrq
932 if(cell_info.running) {
933 int tmp_int;
934 char* tmp_s = memdup(s,strlen(s));
935 char* free_ptr = tmp_s;
936 char *line = tmp_s;
937 if (at_tok_start(&line) < 0)
938 {
939 goto EEMLTEINTER_EXIT;
940 }
941 if (at_tok_nextint(&line, &tmp_int) < 0)
942 {
943 goto EEMLTEINTER_EXIT;
944 }
945 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
946 {
947 goto EEMLTEINTER_EXIT;
948 }
949 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
950 if (at_tok_nextint(&line, &tmp_int) < 0)
951 {
952 goto EEMLTEINTER_EXIT;
953 }
954 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
955 if (at_tok_nextint(&line, &tmp_int) < 0)
956 {
957 goto EEMLTEINTER_EXIT;
958 }
959 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
960 LOG("cell line : %s", line);
961 if (at_tok_nextint(&line, &tmp_int) < 0)
962 {
963 goto EEMLTEINTER_EXIT;
964 }
965 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
966 if (at_tok_nextint(&line, &tmp_int) < 0)
967 {
968 LOG("cell tmp_int : %d", tmp_int);
969 goto EEMLTEINTER_EXIT;
970 }
971 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
972 LOG("cell value5 : %d", cell_info.cell[cell_info.cell_num].value5);
973 cell_info.cell_num++;
974EEMLTEINTER_EXIT:
975 free(free_ptr);
976 }
977 }
978 // Do nothing
979 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
980 {
981 if(cell_info.running) {
982
983 }
984 }
985 // WCDMA
986 /*
987 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
988
989 // if sCMeasPresent == 1
990 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
991 // endif
992
993 // if sCParamPresent == 1
994 // rac, nom, mcc, mnc_len, mnc, lac, ci,
995 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
996 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
997 // endif
998
999 // if ueOpStatusPresent == 1
1000 // rrcState, numLinks, srncId, sRnti,
1001 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1002 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1003 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1004 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1005 // endif
1006 //
1007 +EEMUMTSSVC: 3, 1, 1, 1,
1008 -80, 27, -6, -18, -115, -32768,
1009 1, 1, 1120, 2, 1, 61697, 168432821,
1010 15, 24, 10763, 0, 0, 0, 0,
1011 128, 128, 65535, 0, 0,
1012 2, 255, 65535, 4294967295,
1013 0, 0, 0, 0, 0, 0,
1014 0, 0, 0, 0, 0, 0, 1, 1,
1015 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1016 0, 0, 0, 0, 0, 0
1017 */
1018 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1019 {
1020 // lac, ci, arfcn
1021 if(cell_info.running) {
1022 int tmp_int;
1023 int i = 0;
1024 char* tmp_s = memdup(s,strlen(s));
1025 char* free_ptr = tmp_s;
1026 char *line = tmp_s;
1027 if (at_tok_start(&line) < 0)
1028 {
1029 goto EEMUMTSSVC_EXIT;
1030 }
1031 // Jump 12 integer.
1032 i = 0;
1033 while(i < 12) {
1034 if (at_tok_nextint(&line, &tmp_int) < 0)
1035 {
1036 goto EEMUMTSSVC_EXIT;
1037 }
1038 i++;
1039 }
1040 // mcc
1041 if (at_tok_nextint(&line, &tmp_int) < 0)
1042 {
1043 goto EEMUMTSSVC_EXIT;
1044 }
1045 cell_info.cell[cell_info.cell_num].value4= (uint32)tmp_int;
1046 // mnc
1047 if (at_tok_nextint(&line, &tmp_int) < 0)
1048 {
1049 goto EEMUMTSSVC_EXIT;
1050 }
1051 cell_info.cell[cell_info.cell_num].value5= (uint32)tmp_int;
1052 // lac
1053 if (at_tok_nextint(&line, &tmp_int) < 0)
1054 {
1055 goto EEMUMTSSVC_EXIT;
1056 }
1057 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1058 // ci
1059 if (at_tok_nextint(&line, &tmp_int) < 0)
1060 {
1061 goto EEMUMTSSVC_EXIT;
1062 }
1063 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1064
1065 if (at_tok_nextint(&line, &tmp_int) < 0)
1066 {
1067 goto EEMUMTSSVC_EXIT;
1068 }
1069 // cpi
1070 if (at_tok_nextint(&line, &tmp_int) < 0)
1071 {
1072 goto EEMUMTSSVC_EXIT;
1073 }
1074 cell_info.cell[cell_info.cell_num].value6= (uint32)tmp_int;
1075 /*
1076 // Jump 2 integer.
1077 i = 0;
1078 while(i < 2) {
1079 if (at_tok_nextint(&line, &tmp_int) < 0)
1080 {
1081 goto EEMUMTSSVC_EXIT;
1082 }
1083 i++;
1084 }
1085 */
1086 // arfcn
1087 if (at_tok_nextint(&line, &tmp_int) < 0)
1088 {
1089 goto EEMUMTSSVC_EXIT;
1090 }
1091 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1092
1093 cell_info.cell_num++;
1094EEMUMTSSVC_EXIT:
1095 free(free_ptr);
1096 }
1097 }
1098 /*
1099 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1100 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1101 */
1102 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1103 {
1104 // lac, ci, arfcn
1105 if(cell_info.running) {
1106 int tmp_int;
1107 int i = 0;
1108 char* tmp_s = memdup(s,strlen(s));
1109 char* free_ptr = tmp_s;
1110 char *line = tmp_s;
1111 if (at_tok_start(&line) < 0)
1112 {
1113 goto EEMUMTSINTRA_EXIT;
1114 }
1115 // Jump 8 integer.
1116 i = 0;
1117 while(i < 8) {
1118 if (at_tok_nextint(&line, &tmp_int) < 0)
1119 {
1120 goto EEMUMTSINTRA_EXIT;
1121 }
1122 i++;
1123 }
1124
1125 // lac
1126 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1127 {
1128 goto EEMUMTSINTRA_EXIT;
1129 }
1130 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1131
1132 // ci
1133 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1134 {
1135 goto EEMUMTSINTRA_EXIT;
1136 }
1137 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1138
1139 // arfcn
1140 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1141 {
1142 goto EEMUMTSINTRA_EXIT;
1143 }
1144 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1145
1146 cell_info.cell_num++;
1147EEMUMTSINTRA_EXIT:
1148 free(free_ptr);
1149 }
1150 }
1151 /*
1152 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1153 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1154 */
1155 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1156 {
1157 // lac, ci, arfcn
1158 if(cell_info.running) {
1159 int tmp_int;
1160 int i = 0;
1161 char* tmp_s = memdup(s,strlen(s));
1162 char* free_ptr = tmp_s;
1163 char *line = tmp_s;
1164 if (at_tok_start(&line) < 0)
1165 {
1166 goto EEMUMTSINTERRAT_EXIT;
1167 }
1168 // Jump 7 integer.
1169 i = 0;
1170 while(i < 7) {
1171 if (at_tok_nextint(&line, &tmp_int) < 0)
1172 {
1173 goto EEMUMTSINTERRAT_EXIT;
1174 }
1175 i++;
1176 }
1177
1178 // lac
1179 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1180 {
1181 goto EEMUMTSINTERRAT_EXIT;
1182 }
1183 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1184
1185 // ci
1186 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1187 {
1188 goto EEMUMTSINTERRAT_EXIT;
1189 }
1190 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1191
1192 // arfcn
1193 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1194 {
1195 goto EEMUMTSINTERRAT_EXIT;
1196 }
1197 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1198
1199 cell_info.cell_num++;
1200EEMUMTSINTERRAT_EXIT:
1201 free(free_ptr);
1202 }
1203 }
1204 // GSM
1205 // +EEMGINFOBASIC: 2
1206 // Do nothing.
1207 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1208 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1209 {
1210 if(cell_info.running) {
1211
1212 }
1213 }
1214 /*
1215 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1216 // bsic, C1, C2, TA, TxPwr,
1217 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1218 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1219 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1220 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1221 // gsmBand,channelMode
1222 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1223 63, 36, 146, 1, 7,
1224 46, 42, 42, 7, 0,
1225 53, 0, 8, 0, 1, 6, 53,
1226 2, 0, 146, 42, 54, 0, 1,
1227 1, 32, 0, 0, 0, 0,
1228 0, 0
1229 */
1230 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1231 {
1232 // lac, ci, arfcn, bsic
1233 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1234 if(cell_info.running) {
1235 int tmp_int;
1236 int i = 0;
1237 char* tmp_s = memdup(s,strlen(s));
1238 char* free_ptr = tmp_s;
1239 char *line = tmp_s;
1240 if (at_tok_start(&line) < 0)
1241 {
1242 goto EEMGINFOSVC_EXIT;
1243 }
1244
1245 // mcc
1246 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1247 {
1248 goto EEMGINFOSVC_EXIT;
1249 }
1250 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1251
1252 //mnc_len
1253 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1254 {
1255 goto EEMGINFOSVC_EXIT;
1256 }
1257 // mnc
1258 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1259 {
1260 goto EEMGINFOSVC_EXIT;
1261 }
1262 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1263
1264 /*
1265 // Jump 3 integer.
1266 i = 0;
1267 while(i < 3) {
1268 if (at_tok_nextint(&line, &tmp_int) < 0)
1269 {
1270 goto EEMGINFOSVC_EXIT;
1271 }
1272 i++;
1273 }
1274 */
1275 // lac
1276 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1277 {
1278 goto EEMGINFOSVC_EXIT;
1279 }
1280 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1281
1282 // ci
1283 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1284 {
1285 goto EEMGINFOSVC_EXIT;
1286 }
1287 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1288
1289 // Jump 2 integer.
1290 i = 0;
1291 while(i < 2) {
1292 if (at_tok_nextint(&line, &tmp_int) < 0)
1293 {
1294 goto EEMGINFOSVC_EXIT;
1295 }
1296 i++;
1297 }
1298
1299 // bsic
1300 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1301 {
1302 goto EEMGINFOSVC_EXIT;
1303 }
1304 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1305
1306 // Jump 15 integer.
1307 i = 0;
1308 while(i < 15) {
1309 if (at_tok_nextint(&line, &tmp_int) < 0)
1310 {
1311 goto EEMGINFOSVC_EXIT;
1312 }
1313 i++;
1314 }
1315
1316 // arfcn
1317 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1318 {
1319 goto EEMGINFOSVC_EXIT;
1320 }
1321 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1322
1323 cell_info.cell_num++;
1324EEMGINFOSVC_EXIT:
1325 free(free_ptr);
1326 }
1327 }
1328 /*
1329 // PS_attached, attach_type, service_type, tx_power, c_value,
1330 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1331 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1332 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1333 +EEMGINFOPS: 1, 255, 0, 0, 0,
1334 0, 0, 268435501, 1, 0, 0,
1335 4, 0, 96, 0, 0, 0,
1336 0, 0, 0, 65535, 0, 13350
1337 */
1338 // Do nothing.
1339 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1340 {
1341 if(cell_info.running) {
1342
1343 }
1344 }
1345 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1346 {
1347 if(cell_info.running) {
1348 int tmp_int;
1349 int i = 0;
1350 char* tmp_s = memdup(s,strlen(s));
1351 char* free_ptr = tmp_s;
1352 char *line = tmp_s;
1353 if (at_tok_start(&line) < 0)
1354 {
1355 goto EEMGINFOPS_EXIT;
1356 }
1357
1358 // nc_num
1359 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1360 {
1361 LOG("cell_info.running 1= %d\n.",cell_info.running);
1362 goto EEMGINFOPS_EXIT;
1363 }
1364 // mcc
1365 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1366 {
1367 LOG("cell_info.running 2= %d\n.",cell_info.running);
1368 goto EEMGINFOPS_EXIT;
1369 }
1370 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1371
1372 // mnc
1373 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1374 {
1375 LOG("cell_info.running 3= %d\n.",cell_info.running);
1376 goto EEMGINFOPS_EXIT;
1377 }
1378 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1379
1380 // lac
1381 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1382 {
1383 LOG("cell_info.running 4= %d\n.",cell_info.running);
1384 goto EEMGINFOPS_EXIT;
1385 }
1386 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1387
1388 // rac
1389 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1390 {
1391 LOG("cell_info.running 5= %d\n.",cell_info.running);
1392 goto EEMGINFOPS_EXIT;
1393 }
1394
1395 // ci
1396 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1397 {
1398 LOG("cell_info.running 6= %d\n.",cell_info.running);
1399 goto EEMGINFOPS_EXIT;
1400 }
1401 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1402
1403 // rx_lv
1404 if (at_tok_nextint(&line, &tmp_int) < 0)
1405 {
1406 LOG("cell_info.running 7= %d\n.",cell_info.running);
1407 goto EEMGINFOPS_EXIT;
1408 }
1409
1410 // bsic
1411 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1412 {
1413 LOG("cell_info.running 8= %d\n.",cell_info.running);
1414 goto EEMGINFOPS_EXIT;
1415 }
1416 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1417
1418 // Jump 2 integer.
1419 i = 0;
1420 while(i < 2) {
1421 if (at_tok_nextint(&line, &tmp_int) < 0)
1422 {
1423 LOG("cell_info.running 9= %d\n.",cell_info.running);
1424 goto EEMGINFOPS_EXIT;
1425 }
1426 i++;
1427 }
1428
1429 // arfcn
1430 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1431 {
1432 LOG("cell_info.running 10 = %d\n.",cell_info.running);
1433 goto EEMGINFOPS_EXIT;
1434 }
1435 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1436
1437 cell_info.cell_num++;
1438EEMGINFOPS_EXIT:
1439 free(free_ptr);
1440 }
1441 }
1442 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"
1443 {
1444
1445 }
1446 else
1447 {
1448 LOGV("Unknown URC : %s", s);
1449 }
1450}
1451
1452static int openSocket(const char* sockname)
1453{
1454 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
1455 if (sock < 0)
1456 {
1457 LOGE("Error create socket: %s\n", strerror(errno));
1458 return -1;
1459 }
1460 struct sockaddr_un addr;
1461 memset(&addr, 0, sizeof(addr));
1462 addr.sun_family = AF_UNIX;
1463 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
1464 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
1465 {
1466 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
1467 sleep(1);
1468 }
1469
1470#if 0
1471 int sk_flags = fcntl(sock, F_GETFL, 0);
1472 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
1473#endif
1474
1475 return sock;
1476}
1477
1478static void ril_get_cgpaddr_ip_process()
1479{
1480 int err, skip;
1481 ATResponse *p_response = NULL;
1482 char *line;
1483 char *ipv4 = NULL, *ipv6 = NULL;
1484 err = at_send_command_singleline("AT+CGPADDR", "+CGPADDR:", &p_response);
1485 if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
1486 {
1487 LOGE("+CGPADDR exec error.");
1488 goto error;
1489 }
1490
1491 // +CGPADDR: 1, "10.51.59.229", "254.128.0.0.0.0.0.0.0.1.0.0.111.176.63.99"
1492 // +CGPADDR: 1, "10.124.139.131"
1493 line = p_response->p_intermediates->line;
1494 err = at_tok_start(&line);
1495 if (err < 0)
1496 {
1497 goto error;
1498 }
1499
1500 err = at_tok_nextint(&line, &skip);
1501 if (err < 0)
1502 {
1503 goto error;
1504 }
1505
1506 if (!at_tok_hasmore(&line))
1507 {
1508 goto error;
1509 }
1510
1511 err = at_tok_nextstr(&line, &ipv4);
1512 if (err < 0)
1513 {
1514 LOGE("Get IPv4 fail.");
1515 goto error;
1516 }
1517
1518 if (at_tok_hasmore(&line))
1519 {
1520 err = at_tok_nextstr(&line, &ipv6);
1521 if (err < 0)
1522 {
1523 LOGE("Get IPv6 fail.");
1524 goto error;
1525 }
1526 }
1527 else
1528 {
1529 LOGD("No IPv6 Found.");
1530 }
1531
1532 if(ipv6)
1533 {
1534 LOGD("IPv6 : %s", ipv6);
1535 }
1536
1537 if(ipv4)
1538 {
1539 LOGD("IPv4 : %s", ipv4);
1540
1541// ril_net_dev_config("ccinet0", ipv4, NULL);
1542 }
1543error:
1544 at_response_free(p_response);
1545}
1546
1547static void sim_state_change(bool plug_in) {
1548 if(plug_in) {
1549 // If radio on,must off in the first.
1550 if(net_info.radio_state == MBTK_RADIO_STATE_ON) {
1551 setRadioPower(0);
1552 }
1553 setRadioPower(1);
1554 } else {
1555 setRadioPower(0);
1556 }
1557}
1558
1559static int open_uevent_socket()
1560{
1561 struct sockaddr_nl addr;
1562 int sz = 64*1024;
1563 int s = 0;
1564
1565 memset(&addr, 0, sizeof(addr));
1566 addr.nl_family = AF_NETLINK;
1567 addr.nl_pid = getpid();
1568 addr.nl_groups = 0xffffffff;
1569
1570 s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
1571 if (s < 0)
1572 {
1573 LOGE("socket() fail.[%d]", errno);
1574 return -1;
1575 }
1576
1577 setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz));
1578
1579 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0)
1580 {
1581 close(s);
1582 return -1;
1583 }
1584
1585 return s;
1586}
1587
1588static void parse_uevent(const char *msg, int msg_len, struct cooling_device *cdev)
1589{
1590 // change@/devices/virtual/usim_event/usim0\0
1591 // ACTION=change\0
1592 // DEVPATH=/devices/virtual/usim_event/usim0\0
1593 // SUBSYSTEM=usim_event\0
1594 // USIM_NAME=usim0\0
1595 // USIM_EVENT=plugout\0
1596 // SEQNUM=704
1597 int i = 0;
1598 while (i < msg_len)
1599 {
1600 if(*(msg + i) == '\0')
1601 {
1602 i++;
1603 continue;
1604 }
1605 if (!strncmp(msg + i, "USIM_NAME=", 10))
1606 {
1607 i += 10;
1608 cdev->name = msg + i;
1609 i += strlen(msg + i);
1610 }
1611 else if (!strncmp(msg + i, "ACTION=", 7))
1612 {
1613 i += 7;
1614 cdev->action = msg + i;
1615 i += strlen(msg + i);
1616 }
1617 else if (!strncmp(msg + i, "DEVPATH=", 8))
1618 {
1619 i += 8;
1620 cdev->path = msg + i;
1621 i += strlen(msg + i);
1622 }
1623 else if (!strncmp(msg + i, "USIM_EVENT=", 11))
1624 {
1625 i += 11;
1626 cdev->event = msg + i;
1627 i += strlen(msg + i);
1628 }
1629 else if (!strncmp(msg + i, "SUBSYSTEM=", 10))
1630 {
1631 i += 10;
1632 cdev->subsystem = msg + i;
1633 i += strlen(msg + i);
1634 }
1635 else
1636 {
1637 i++;
1638 }
1639 }
1640
1641 if(!strncmp(cdev->path, UEVENT_USIM_DEV, sizeof(UEVENT_USIM_DEV))
1642 && !strncmp(cdev->action, "change", 5))
1643 {
1644 LOGD("event { name=%s, action=%s, path=%s, subsystem=%s, event=%s}",
1645 cdev->name, cdev->action, cdev->path, cdev->subsystem, cdev->event);
1646 if(!strcmp(cdev->event, "plugout"))
1647 {
1648 sim_state_change(FALSE);
1649 }
1650 else if(!strcmp(cdev->event, "plugin"))
1651 {
1652 sim_state_change(TRUE);
1653 }
1654 else
1655 {
1656 LOGE("usim evnet error!");
1657 }
1658 }
1659}
1660
1661static void* uevnet_run(void *payload)
1662{
1663 int socket_fd = -1;
1664 char msg[BUFFER_SIZE+2];
1665 int n;
1666
1667 socket_fd = open_uevent_socket();
1668 if(socket_fd > 0)
1669 {
1670 while(1)
1671 {
1672 if((n = recv(socket_fd, msg, BUFFER_SIZE, 0)) > 0)
1673 {
1674 struct cooling_device cdev;
1675 memset(&cdev, 0x0, sizeof(cdev));
1676
1677 if(n == BUFFER_SIZE)
1678 continue;
1679 msg[n] = '\0';
1680 // 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
1681 log_hex("UEVENT", msg, n);
1682 parse_uevent(msg, n, &cdev);
1683 }
1684 else
1685 {
1686 LOGE("recv msg error.");
1687 }
1688 }
1689 }
1690
1691 LOGD("UEVENT Thread exit!!!");
1692 return NULL;
1693}
1694
1695int uevent_main()
1696{
1697 mbtk_task_info task;
1698 task.task_id = &uevnet_task_id;
1699 task.thread_run = uevnet_run;
1700 task.args = NULL;
1701 return mbtk_task_start(&task);
1702}
1703
1704/*
1705int ril_main()
1706{
1707 return mbtk_task_queue_start(&ril_task, ril_main_run);
1708}
1709*/
1710
1711int mbtk_info_server_start();
1712int InProduction_Mode(void);
1713void server_ready_set(void);
1714
1715
1716/*
1717 *Get mtdblock which name is ASR_FLAG
1718 *return path if found, else return NULL
1719 */
1720static int asrFlagPathGet(char *asr_flag_path)
1721{
1722 char buf[128];
1723 unsigned char find = 0;
1724 FILE *fd = fopen("/proc/mtd", "r");
1725 if (fd == NULL) {
1726 LOGE("Open MTD failed!");
1727 return -1;
1728 }
1729
1730 memset(buf, '\0', 128);
1731 while (fgets(buf, 128, fd) != NULL) {
1732 if(strstr(buf, "asr_flag")) {
1733 char *p = strstr(buf, "mtd");
1734 if(p)
1735 {
1736 int bln;
1737 sscanf(p, "mtd%d", &bln);
1738 sprintf(asr_flag_path, "/dev/mtdblock%d", bln);
1739 find = 1;
1740 break;
1741 }
1742 }
1743 memset(buf, '\0', 128);
1744 }
1745
1746 fclose(fd);
1747 return ((find == 1) ? 0 : -1);
1748}
1749
1750static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)
1751{
1752 int ret, fd;
1753 if (!path)
1754 return -1;
1755
1756 fd = open(path, O_RDONLY);
1757 if (fd < 0) {
1758 LOGE("readFromMTD open error,%d", errno);
1759 return -1;
1760 }
1761
1762 ret = lseek(fd, offset, SEEK_SET);
1763 if (ret < 0) {
1764 close(fd);
1765 LOGE("readFromMTD lseek error,%d", errno);
1766 return -1;
1767 }
1768 ret = read(fd, buf, size);
1769 if (ret < 0) {
1770 close(fd);
1771 LOGE("readFromMTD read error,%d", errno);
1772 return -1;
1773 }
1774 close(fd);
1775 return 0;
1776}
1777
1778static int writeToMTD(const char *path, unsigned int offset, void *buf, int size)
1779{
1780 int ret, fd;
1781
1782 if (!path)
1783 return -1;
1784
1785 fd = open(path, O_RDWR | O_SYNC);
1786 if (fd < 0)
1787 return -1;
1788
1789 ret = lseek(fd, offset, SEEK_SET);
1790 if (ret < 0) {
1791 close(fd);
1792 return -1;
1793 }
1794 ret = write(fd, buf, size);
1795 if (ret < 0) {
1796 LOGE("writetomtd:write error:%d", errno);
1797 close(fd);
1798 return -1;
1799 }
1800
1801 close(fd);
1802 return 0;
1803}
1804
1805static void fota_result_check()
1806{
1807#if 0
1808 ASR_flag tag;
1809 char asr_flag_path[30] = {0};
1810 if(asrFlagPathGet(asr_flag_path)) {
1811 LOGE("getAsrFlagPath() fail.");
1812 return;
1813 }
1814
1815 if(readFromMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
1816 {
1817 LOGE("Get FOTA result fail.");
1818 }
1819 else
1820 {
1821 LOGD("FOTA result : %d, %d", tag.fota_result[0], tag.fota_result[1]);
1822 tag.fota_result[0] = 0;
1823 tag.fota_result[1] = 0;
1824 if(writeToMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
1825 {
1826 LOGE("FOTA result update fail.");
1827 } else {
1828 LOGD("FOTA result update success.");
1829 }
1830 }
1831#endif
1832}
1833
1834static void mbtk_server_ready()
1835{
1836 // /etc/init.d/mbtk_boot_server_ready
1837 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
1838 system(MBTK_BOOT_SERVER_READY);
1839 } else {
1840 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
1841 }
1842}
1843
1844#if 1
1845int main(int argc, char *argv[])
1846{
1847 mbtk_log_init("radio", "MBTK_RIL");
1848 LOGI("mbtk_ril start.");
1849
1850 if(InProduction_Mode()) {
1851 LOGI("Is Production Mode, will exit...");
1852 exit(0);
1853 }
1854
1855 int at_sock = openSocket("/tmp/atcmd_at");
1856 if(at_sock < 0)
1857 {
1858 LOGE("Open AT Socket Fail[%d].", errno);
1859 return -1;
1860 }
1861 int uart_sock = openSocket("/tmp/atcmd_urc");
1862 if(uart_sock < 0)
1863 {
1864 LOGE("Open Uart Socket Fail[%d].", errno);
1865 return -1;
1866 }
1867
1868 at_set_on_reader_closed(onATReaderClosed);
1869 at_set_on_timeout(onATTimeout);
1870
1871 if(at_open(at_sock, uart_sock, onUnsolicited))
1872 {
1873 LOGE("Start AT thread fail.");
1874 return -1;
1875 }
1876
1877#if 1
1878 if(at_handshake())
1879 {
1880 LOGE("AT handshake fail.");
1881 return -1;
1882 }
1883#endif
1884
1885 LOGD("AT OK.");
1886
1887 if(mbtk_info_server_start())
1888 {
1889 LOGE("mbtk_info_server_start() fail.");
1890 return -1;
1891 }
wangyouqiang38e53362024-01-23 10:53:48 +08001892
1893#ifdef MBTK_PROJECT_T108
1894 mbtk_led_init();
1895#endif
liubin281ac462023-07-19 14:22:54 +08001896
1897#if 0
1898 if(uevent_main())
1899 {
1900 LOGE("Start uevent thread fail.");
1901 return -1;
1902 }
1903#endif
1904
1905 char time_type[10];
1906 memset(time_type, 0, 10);
1907 property_get("persist.mbtk.time_type", time_type, "0");
1908 if(atoi(time_type) == MBTK_TIME_TYPE_NTP) { // NTP time
1909 LOG("Start NTP thread.");
1910 ntp_thread_start();
1911 }
1912
1913 fota_result_check();
1914
1915 mbtk_server_ready();
1916
1917 server_ready_set();//Set the server readiness state
1918 while(1)
1919 {
1920 sleep(24 * 60 * 60);
1921 }
1922
1923 LOGD("!!!mbtk_ril exit!!!");
1924 return 0;
1925}
1926
1927#else
1928int main()
1929{
1930 char buff[BUFFER_SIZE + 1] = {0};
1931 if(!mbtk_at("AT+CFUN=1", buff, BUFFER_SIZE))
1932 {
1933 LOGD("+CFUN RSP:%s", buff);
1934 while(1)
1935 {
1936 sleep(1);
1937 memset(buff, 0x0, BUFFER_SIZE + 1);
1938 if(!mbtk_at("AT+CGPADDR", buff, BUFFER_SIZE))
1939 {
1940 LOGD("+CGPADDR RSP:%s", buff);
1941 if(strstr(buff, "+CGPADDR:"))
1942 {
1943 // +CGPADDR: 1, "10.99.223.168", "254.128.0.0.0.0.0.0.0.1.0.0.117.9.250.59"
1944 //
1945 // OK
1946 char *ip_start = NULL;
1947 char *ip_end = NULL;
1948 char ipv4[50] = {0};
1949 ip_start = strstr(buff,"\"");
1950 if(ip_start)
1951 ip_end = strstr(ip_start + 1, "\"");
1952 if(ip_start && ip_end && ip_end - ip_start - 1 > 0)
1953 {
1954 memcpy(ipv4, ip_start + 1, ip_end - ip_start - 1);
1955 LOGD("IP : %s", ipv4);
1956 if(!mbtk_ifc_open())
1957 {
1958 in_addr_t addr;
1959 inet_aton(ipv4,(struct in_addr *)&addr);
1960 LOGD("IP : %s -> %x", ipv4, addr);
1961 if(!mbtk_ifc_set_addr("ccinet0", addr, 0))
1962 {
1963 mbtk_ifc_up("ccinet0");
1964 }
1965
1966 mbtk_ifc_close();
1967 }
1968
1969 system("route add default dev ccinet0");
1970
1971 LOGD("Set IP success.");
1972 }
1973 else
1974 {
1975 LOGD("Get IP fail.");
1976 }
1977
1978 break;
1979 }
1980 }
1981 }
1982 }
1983
1984 return 0;
1985}
1986#endif