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