blob: 7f68de39b325a03216506fcd817d76095b8015b1 [file] [log] [blame]
b.liu87afc4c2024-08-14 17:33:45 +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#include <signal.h>
16#include <sys/epoll.h>
17#include <pthread.h>
18
19
20//#include "cploader.h"
21#include "mbtk_log.h"
22#include "mbtk_ifc.h"
23#include "mbtk_type.h"
24#include "atchannel.h"
25#include "at_tok.h"
26#include "mbtk_utils.h"
27#include "mbtk_task.h"
28#include "ril_info.h"
29#include "mbtk_ntp.h"
30#include "mbtk_net_control.h"
31#include "mbtk_ril.h"
32#include "mbtk_str.h"
33#include "mbtk_queue.h"
34
35#define TEMP_FAILURE_RETRY(exp) ({ \
36 typeof (exp) _rc; \
37 do { \
38 _rc = (exp); \
39 } while (_rc == -1 && errno == EINTR); \
40 _rc; })
41
42#define BUFFER_SIZE 2048
43#define UEVENT_USIM_DEV "/devices/virtual/usim_event/usim0"
44#define MBTK_BOOT_SERVER_READY "/etc/init.d/mbtk_boot_server_ready"
45#define MBTK_BOOT_NET_READY "/etc/init.d/mbtk_boot_net_ready"
46#define MBTK_RILD_PID_FILE "/var/run/mbtk_rild.pid"
47#define MBTK_RILD_FILE_NET_READY "/tmp/mbtk_rild.net_ready"
48#define MBTK_RILD_FILE_SER_READY "/tmp/mbtk_rild.ser_ready"
49
50static bool ril_net_ready = FALSE; // Only one time.
51static bool ril_server_ready = FALSE; // Only one time.
52ril_band_info_t band_info;
53ril_info_t ril_info;
b.liub4772072024-08-15 14:47:03 +080054extern mbtk_cell_pack_info_t cell_info;
b.liubcf86c92024-08-19 19:48:28 +080055extern ril_cgact_wait_t cgact_wait;
b.liu87afc4c2024-08-14 17:33:45 +080056
57// int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len);
58// int mbtk_signal_log(char *data);
59int InProduction_Mode(void);
60mbtk_ril_err_enum dev_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
61mbtk_ril_err_enum call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
62mbtk_ril_err_enum sim_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
63mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
64mbtk_ril_err_enum pb_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
65mbtk_ril_err_enum sms_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
66
67/* Called on command thread */
68static void onATTimeout()
69{
70 LOGI("AT channel timeout; closing\n");
71 at_close();
72}
73
74/* Called on command or reader thread */
75static void onATReaderClosed()
76{
77 LOGI("AT channel closed\n");
78 at_close();
79}
80
81static void sock_cli_free_func(void *data)
82{
83 if (data)
84 {
85 sock_cli_info_t *info = (sock_cli_info_t*) data;
86 LOGD("Free Socket client[fd = %d].", info->fd);
87 free(info);
88 }
89}
90
91/*
92* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
93*/
94static int net_ready_set()
95{
96 int ret = -1;
97 int fd = open(MBTK_RILD_FILE_NET_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
98 if(fd > 0) {
99 if(write(fd, "1", 1) == 1) {
100 ret = 0;
101 ril_net_ready = TRUE;
102 }
103 close(fd);
104 } else {
105 LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
106 }
107
108 return ret;
109}
110
111/*
112* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
113*/
114static int ser_ready_set()
115{
116 int ret = -1;
117 int fd = open(MBTK_RILD_FILE_SER_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
118 if(fd > 0) {
119 if(write(fd, "1", 1) == 1) {
120 ret = 0;
121 ril_server_ready = TRUE;
122 }
123 close(fd);
124 } else {
125 LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
126 }
127
128 return ret;
129}
130
131/*
132* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
133*/
134static void ready_state_update()
135{
136 int fd = open(MBTK_RILD_FILE_NET_READY, O_RDONLY, 0644);
137 char buff[10];
138 if(fd > 0) {
139 if(read(fd, buff, sizeof(buff)) > 0) {
140 ril_net_ready = TRUE;
141 } else {
142 ril_net_ready = FALSE;
143 }
144
145 close(fd);
146 } else {
147 ril_net_ready = FALSE;
148 LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
149 }
150
151 fd = open(MBTK_RILD_FILE_SER_READY, O_RDONLY, 0644);
152 if(fd > 0) {
153 if(read(fd, buff, sizeof(buff)) > 0) {
154 ril_server_ready = TRUE;
155 } else {
156 ril_server_ready = FALSE;
157 }
158
159 close(fd);
160 } else {
161 ril_server_ready = FALSE;
162 LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
163 }
164}
165
166static void mbtk_net_ready()
167{
168 // /etc/init.d/mbtk_boot_net_ready
169 if(!ril_net_ready) {
170 if(access(MBTK_BOOT_NET_READY , X_OK) == 0) {
171 LOGD("Exec : %s", MBTK_BOOT_NET_READY);
172 system(MBTK_BOOT_NET_READY);
173 } else {
174 LOGE("%s can not exec.", MBTK_BOOT_NET_READY);
175 }
176 net_ready_set();
177 } else {
178 LOGD("No exec : %s", MBTK_BOOT_NET_READY);
179 }
180}
181
182static void mbtk_ril_ready()
183{
184 // /etc/init.d/mbtk_boot_server_ready
185 if(!ril_server_ready) {
186 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
187 LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
188 system(MBTK_BOOT_SERVER_READY);
189 } else {
190 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
191 }
192 ser_ready_set();
193 } else {
194 LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
195 }
196}
197
198static sock_cli_info_t* cli_find(int fd)
199{
200 sock_cli_info_t *result = NULL;
201 list_first(ril_info.sock_client_list);
202 while ((result = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
203 {
204 if (result->fd == fd)
205 return result;
206 }
207
208 return NULL;
209}
210
211static void cli_close(sock_cli_info_t* client)
212{
213 struct epoll_event ev;
214 memset(&ev,0,sizeof(struct epoll_event));
215 ev.data.fd = client->fd;
216 ev.events = EPOLLIN | EPOLLERR | EPOLLET;
217 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_DEL, client->fd, &ev);
218
219 close(client->fd);
220
221 if(list_remove(ril_info.sock_client_list, client))
222 {
223 sock_cli_free_func(client);
224 }
225}
226
227static void ril_error_pack_send(int fd, int ril_id, int msg_index, int err)
228{
229 ril_msg_pack_info_t* pack = ril_msg_pack_creat(RIL_MSG_TYPE_RSP, ril_id, msg_index, NULL, 0);
230 if(pack)
231 {
232 pack->err = (uint16)err;
233 ril_pack_send(fd, pack);
234 ril_msg_pack_free(pack);
235 }
236 else
237 {
238 LOGW("ril_msg_pack_creat() fail.");
239 }
240}
241
242void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len)
243{
244 ril_msg_pack_info_t* pack = ril_msg_pack_creat(RIL_MSG_TYPE_RSP, ril_id, msg_index, data, data_len);
245 if(pack)
246 {
247 pack->err = (uint16)MBTK_RIL_ERR_SUCCESS;
248#if 0
249 if(data != NULL && data_len > 0)
250 {
251 pack->data_len = (uint16)data_len;
252 pack->data = (uint8*)mbtk_memcpy(data, data_len);
253 }
254#endif
255 ril_pack_send(fd, pack);
256 ril_msg_pack_free(pack);
257 }
258 else
259 {
260 LOGW("ril_msg_pack_creat() fail.");
261 }
262}
263
264void ril_ind_pack_send(int fd, int msg_id, const void* data, int data_len)
265{
266 ril_msg_pack_info_t* pack = ril_msg_pack_creat(RIL_MSG_TYPE_IND, msg_id, RIL_MSG_INDEX_INVALID, data, data_len);
267 if(pack)
268 {
269 pack->err = (uint16)0;
270#if 0
271 if(data != NULL && data_len > 0)
272 {
273 pack->data_len = (uint16)data_len;
274 pack->data = (uint8*)mbtk_memcpy(data, data_len);
275 }
276#endif
277 ril_pack_send(fd, pack);
278 ril_msg_pack_free(pack);
279 }
280 else
281 {
282 LOGW("ril_msg_pack_creat() fail.");
283 }
284}
285
b.liubcf86c92024-08-19 19:48:28 +0800286static void urc_pdp_state_process(const char *s, const char *sms_pdu)
287{
288 // "CONNECT"
289 if(strStartsWith(s, "CONNECT"))
290 {
291#if 1
292 if(cgact_wait.waitting && cgact_wait.act) {
293 cgact_wait.waitting = false;
294 }
295#endif
296 }
297 // +CGEV:
298 // +CGEV: NW DEACT <cid>,<cid>
299 // +CGEV: ME DEACT <cid>,<cid>
300 // +CGEV: NW PDN DEACT <cid>
301 // +CGEV: ME PDN DEACT <cid>
302 // +CGEV: NW DETACH
303 // +CGEV: ME DETACH
304 //
305 // +CGEV: NW ACT <cid>,<cid>
306 // +CGEV: ME ACT <cid>,<cid>
307 // +CGEV: EPS PDN ACT <cid>
308 // +CGEV: ME PDN ACT <cid>,<reason>,<cid>
309 // +CGEV: ME PDN ACT <cid>,<reason>
310 // +CGEV: NW PDN ACT <cid>
311 // +CGEV: EPS ACT <cid>
312 // +CGEV: NW MODIFY <cid>,<reason>
313 // +CGEV: NW REATTACH
314
315 /*
316 +CGEV: NW DETACH
317 +CGEV: ME DETACH
318 +CGEV: NW CLASS <class>
319 +CGEV: ME CLASS <class>
320 +CGEV: NW PDN ACT <cid>
321 +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
322 +CGEV: NW ACT <p_cid>, <cid>, <event_type>
323 +CGEV: ME ACT <p_cid>, <cid>, <event_type>
324 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
325 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
326 +CGEV: NW PDN DEACT <cid>
327 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
328 +CGEV: ME PDN DEACT <cid>
329 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
330 +CGEV: NW DEACT <p_cid>, <cid>, <event_type>
331 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
332 +CGEV: ME DEACT <p_cid>, <cid>, <event_type>
333 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
334 +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
335 +CGEV: ME MODIFY <cid>, <change_reason>, <event_type>
336 +CGEV: REJECT <PDP_type>, <PDP_addr>
337 +CGEV: NW REACT <PDP_type>, <PDP_addr>, [<cid>]
338 */
339 else if(strStartsWith(s, "+CGEV:"))
340 {
341#if 1
342 // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
343 // "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
344 // "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
345 // "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
346 // "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
347 // "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
348 // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
349 int cid = -1;
350 int reason = -1;
351 bool act = FALSE;
352 if (sscanf(s, "+CGEV: NW PDN DEACT %d", &cid) == 1) {
353 act = FALSE;
354 } else if (sscanf(s, "+CGEV: ME PDN DEACT %d", &cid) == 1) {
355 act = FALSE;
356 } else if(sscanf(s, "+CGEV: ME PDN ACT %d,%d", &cid, &reason) == 2
357 || sscanf(s, "+CGEV: ME PDN ACT %d", &cid) == 1) {
358 act = TRUE;
359 } else if (!strcmp(s, "+CGEV: ME DETACH")) {
360 if(cgact_wait.waitting) {
361 cid = cgact_wait.cid;
362 }
363 act = FALSE;
364 } else if (sscanf(s, "+CGEV: NW MODIFY %d,%d", &cid, &reason) == 2) {
365 act = TRUE;
366 } else if(sscanf(s, "+CGEV: EPS PDN ACT %d", &cid) == 1) {
367 act = TRUE;
368 } else {
369 LOGD(">>>>>>>>>No process +CGEV <<<<<<<<<");
370 return;
371 }
372
373 if(cgact_wait.act) {
374 if(cgact_wait.waitting && act && cgact_wait.cid == cid) {
375 cgact_wait.waitting = false;
376 }
377 } else {
378 if(cgact_wait.waitting && !act && cgact_wait.cid == cid) {
379 cgact_wait.waitting = false;
380 }
381 }
382
383 LOGD("+CGEV:cid - %d, act - %d, reason - %d", cid, act, reason);
384#else
385 if(at_process) {
386 if(cgact_wait.act) {
387 if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT 15,4
388 if(cgact_wait.cid == atoi(s + 18)) {
389 cgact_wait.waitting = false;
390 }
391
392 uint8 data_pdp;
393 char* tmp_s = memdup(s + 18,strlen(s + 18));
394 char* free_ptr = tmp_s;
395 char *line = tmp_s;
396 int tmp_int;
397 if (at_tok_start(&line) < 0)
398 {
399 goto at_PDP_CREG_EXIT;
400 }
401 if (at_tok_nextint(&line, &tmp_int) < 0)
402 {
403 goto at_PDP_CREG_EXIT;
404 }
405 if (at_tok_nextint(&line, &tmp_int) < 0)
406 {
407 goto at_PDP_CREG_EXIT;
408 }
409 data_pdp = tmp_int;
410at_PDP_CREG_EXIT:
411 free(free_ptr);
412
413 //data_pdp = (uint8)atoi(s + 20); //reason
414 if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
415 {
416 if(data_pdp == 0)
417 {
418 data_pdp = 25;
419 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
420 //data_pdp = cgact_wait.cid + 200;
421 }
422 else if(data_pdp == 1)
423 {
424 data_pdp = 26;
425 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
426 }
427 else if(data_pdp == 2)
428 {
429 data_pdp = 27;
430 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
431 }
432 else if(data_pdp == 3)
433 {
434 data_pdp = 27;
435 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
436 }
437 else
438 {
439
440 }
441 if(cgact_wait.cid != 0)
442 {
443 data_pdp = cgact_wait.cid + 200;
444 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
445 }
446 }
447 } else if(strStartsWith(s, "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY 1,4
448 if(cgact_wait.cid == atoi(s + 17)) {
449 cgact_wait.waitting = false;
450 }
451 }
452 } else {
453 if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
454 if(cgact_wait.cid == atoi(s + 20)) {
455 cgact_wait.waitting = false;
456 }
457 uint8 data_pdp;
458 data_pdp = 0; //
459 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
460 if(cgact_wait.cid != 0)
461 {
462 data_pdp = cgact_wait.cid + 100;
463 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
464 }
465 }
466 }
467 } else {
468 // apn_state_set
469
470 // +CGEV: NW PDN DEACT <cid>
471
472 // +CGEV: EPS PDN ACT 1
473 // +CGEV: ME PDN ACT 8,1
474
475 // +CGEV: ME PDN ACT 2,4
476 uint8 data[2] = {0xFF};
477 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
478 //apn_state_set(atoi(s + 20), false);
479 data[0] = (uint8)0;
480 data[1] = (uint8)atoi(s + 20);
481
482 uint8 data_pdp;
483 data_pdp = 0; //
484 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
485 data_pdp = data[1] + 100;
486 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
487 } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
488 //apn_state_set(atoi(s + 19), true);
489#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
490 //data[0] = (uint8)1;
491 //data[1] = (uint8)atoi(s + 19);
492#else
493 data[0] = (uint8)1;
494 data[1] = (uint8)atoi(s + 19);
495#endif
496 } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
497 //apn_state_set(atoi(s + 19), true);
498 data[0] = (uint8)0;
499 data[1] = (uint8)atoi(s + 20);
500
501 uint8 data_pdp;
502 data_pdp = 0; //
503 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
504 data_pdp = data[1] + 100;
505 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
506 } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
507 //apn_state_set(atoi(s + 18), true);
508 data[0] = (uint8)1;
509 data[1] = (uint8)atoi(s + 18);
510
511 uint8 data_pdp;
512 char* tmp_s = memdup(s + 18,strlen(s + 18));
513 char* free_ptr = tmp_s;
514 char *line = tmp_s;
515 int tmp_int;
516 if (at_tok_start(&line) < 0)
517 {
518 goto PDP_CREG_EXIT;
519 }
520 if (at_tok_nextint(&line, &tmp_int) < 0)
521 {
522 goto PDP_CREG_EXIT;
523 }
524 if (at_tok_nextint(&line, &tmp_int) < 0)
525 {
526 goto PDP_CREG_EXIT;
527 }
528 data_pdp = tmp_int;
529PDP_CREG_EXIT:
530 free(free_ptr);
531 //data_pdp = (uint8)atoi(s + 20); //reason
532 if(data[1] >= 1 && data[1] < 8)
533 {
534 if(data_pdp == 0)
535 {
536 data_pdp = 25;
537 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
538 }
539 else if(data_pdp == 1)
540 {
541 data_pdp = 26;
542 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
543 }
544 else if(data_pdp == 2)
545 {
546 data_pdp = 27;
547 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
548 }
549 else if(data_pdp == 3)
550 {
551 data_pdp = 27;
552 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
553 }
554 else
555 {
556
557 }
558
559 data_pdp = data[1] + 200;
560 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
561 data[1] = 0;
562 }
563 } else {
564 LOGI("No process : %s", s);
565 }
566
567 urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
568 }
569#endif
570 } else {
571 LOGW("Unknown PDP URC : %s", s);
572 }
573}
574
575
576static void urc_cell_info_process(const char *s, const char *sms_pdu)
b.liub4772072024-08-15 14:47:03 +0800577{
578 /*
579 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
580 // <rsrp>,<rsrq>, <sinr>,
581 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
582 // cellId,subFrameAssignType,specialSubframePatterns,transMode
583 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
584 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
585 // dlBer, ulBer,
586 // diversitySinr, diversityRssi
587 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
588 0, 0, 0,
589 1, 10, 0, 1, 0, 1059, 78, 3959566565,
590 105149248, 2, 7, 7,
591 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
592 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
593 0, 0,
594 7, 44
595 */
596 if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
597 {
598 // tac, PCI, dlEuarfcn, ulEuarfcn, band
599 if(cell_info.running) {
600 int tmp_int;
601 int i = 0;
602 char* tmp_s = memdup(s,strlen(s));
603 char* free_ptr = tmp_s;
604 char *line = tmp_s;
605 if (at_tok_start(&line) < 0)
606 {
607 goto EEMLTESVC_EXIT;
608 }
609
610 if (at_tok_nextint(&line, &tmp_int) < 0)
611 {
612 goto EEMLTESVC_EXIT;
613 }
614 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int; //mcc
615 if (at_tok_nextint(&line, &tmp_int) < 0)
616 {
617 goto EEMLTESVC_EXIT;
618 }
619 if (at_tok_nextint(&line, &tmp_int) < 0)
620 {
621 goto EEMLTESVC_EXIT;
622 }
623 cell_info.cell_list.cell[cell_info.cell_list.num].value7 = (uint32)tmp_int; //mnc
624 /*
625 // Jump 2 integer.
626 i = 0;
627 while(i < 2) {
628 if (at_tok_nextint(&line, &tmp_int) < 0)
629 {
630 goto EEMLTESVC_EXIT;
631 }
632 i++;
633 }
634 */
635 if (at_tok_nextint(&line, &tmp_int) < 0)
636 {
637 goto EEMLTESVC_EXIT;
638 }
639 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int; //tac
640 if (at_tok_nextint(&line, &tmp_int) < 0)
641 {
642 goto EEMLTESVC_EXIT;
643 }
644 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int; //pci
645 if (at_tok_nextint(&line, &tmp_int) < 0)
646 {
647 goto EEMLTESVC_EXIT;
648 }
649 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int; //dl arfcn
650 if (at_tok_nextint(&line, &tmp_int) < 0)
651 {
652 goto EEMLTESVC_EXIT;
653 }
654 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int; //ul arfcn
655 if (at_tok_nextint(&line, &tmp_int) < 0)
656 {
657 goto EEMLTESVC_EXIT;
658 }
659 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int; //band
660 if (at_tok_nextint(&line, &tmp_int) < 0)
661 {
662 goto EEMLTESVC_EXIT;
663 }
664 if (at_tok_nextint(&line, &tmp_int) < 0)
665 {
666 goto EEMLTESVC_EXIT;
667 }
668 cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int; //cid
669 if (at_tok_nextint(&line, &tmp_int) < 0)
670 {
671 goto EEMLTESVC_EXIT;
672 }
673 cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int; //rsrp
674
675 for(i =0; i < 10; i++)
676 {
677 if (at_tok_nextint(&line, &tmp_int) < 0)
678 {
679 goto EEMLTESVC_EXIT;
680 }
681 }
682 cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int; //cell identiy
683
684 cell_info.cell_list.num++;
685
686EEMLTESVC_EXIT:
687 free(free_ptr);
688 }
689 }
690 /*
691 // index,phyCellId,euArfcn,rsrp,rsrq
692 +EEMLTEINTER: 0, 65535, 38950, 0, 0
693 */
694 else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
695 {
696 // phyCellId,euArfcn,rsrp,rsrq
697 if(cell_info.running) {
698 int tmp_int;
699 char* tmp_s = memdup(s,strlen(s));
700 char* free_ptr = tmp_s;
701 char *line = tmp_s;
702 if (at_tok_start(&line) < 0)
703 {
704 goto EEMLTEINTER_EXIT;
705 }
706 if (at_tok_nextint(&line, &tmp_int) < 0)
707 {
708 goto EEMLTEINTER_EXIT;
709 }
710 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
711 {
712 goto EEMLTEINTER_EXIT;
713 }
714 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
715 if (at_tok_nextint(&line, &tmp_int) < 0)
716 {
717 goto EEMLTEINTER_EXIT;
718 }
719 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
720 if (at_tok_nextint(&line, &tmp_int) < 0)
721 {
722 goto EEMLTEINTER_EXIT;
723 }
724 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
725 LOG("cell line : %s", line);
726 if (at_tok_nextint(&line, &tmp_int) < 0)
727 {
728 goto EEMLTEINTER_EXIT;
729 }
730 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
731 if (at_tok_nextint(&line, &tmp_int) < 0)
732 {
733 LOG("cell tmp_int : %d", tmp_int);
734 goto EEMLTEINTER_EXIT;
735 }
736 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
737 LOG("cell value5 : %d", cell_info.cell_list.cell[cell_info.cell_list.num].value5);
738 cell_info.cell_list.num++;
739EEMLTEINTER_EXIT:
740 free(free_ptr);
741 }
742 }
743 // Do nothing
744 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
745 {
746 if(cell_info.running) {
747
748 }
749 }
750 // WCDMA
751 /*
752 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
753
754 // if sCMeasPresent == 1
755 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
756 // endif
757
758 // if sCParamPresent == 1
759 // rac, nom, mcc, mnc_len, mnc, lac, ci,
760 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
761 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
762 // endif
763
764 // if ueOpStatusPresent == 1
765 // rrcState, numLinks, srncId, sRnti,
766 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
767 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
768 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
769 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
770 // endif
771 //
772 +EEMUMTSSVC: 3, 1, 1, 1,
773 -80, 27, -6, -18, -115, -32768,
774 1, 1, 1120, 2, 1, 61697, 168432821,
775 15, 24, 10763, 0, 0, 0, 0,
776 128, 128, 65535, 0, 0,
777 2, 255, 65535, 4294967295,
778 0, 0, 0, 0, 0, 0,
779 0, 0, 0, 0, 0, 0, 1, 1,
780 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
781 0, 0, 0, 0, 0, 0
782 */
783 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
784 {
785 // lac, ci, arfcn
786 if(cell_info.running) {
787 int tmp_int;
788 int i = 0;
789 char* tmp_s = memdup(s,strlen(s));
790 char* free_ptr = tmp_s;
791 char *line = tmp_s;
792 if (at_tok_start(&line) < 0)
793 {
794 goto EEMUMTSSVC_EXIT;
795 }
796 // Jump 12 integer.
797 i = 0;
798 while(i < 12) {
799 if (at_tok_nextint(&line, &tmp_int) < 0)
800 {
801 goto EEMUMTSSVC_EXIT;
802 }
803 i++;
804 }
805 // mcc
806 if (at_tok_nextint(&line, &tmp_int) < 0)
807 {
808 goto EEMUMTSSVC_EXIT;
809 }
810 cell_info.cell_list.cell[cell_info.cell_list.num].value4= (uint32)tmp_int;
811 // mnc
812 if (at_tok_nextint(&line, &tmp_int) < 0)
813 {
814 goto EEMUMTSSVC_EXIT;
815 }
816 cell_info.cell_list.cell[cell_info.cell_list.num].value5= (uint32)tmp_int;
817 // lac
818 if (at_tok_nextint(&line, &tmp_int) < 0)
819 {
820 goto EEMUMTSSVC_EXIT;
821 }
822 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
823 // ci
824 if (at_tok_nextint(&line, &tmp_int) < 0)
825 {
826 goto EEMUMTSSVC_EXIT;
827 }
828 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
829
830 if (at_tok_nextint(&line, &tmp_int) < 0)
831 {
832 goto EEMUMTSSVC_EXIT;
833 }
834 // cpi
835 if (at_tok_nextint(&line, &tmp_int) < 0)
836 {
837 goto EEMUMTSSVC_EXIT;
838 }
839 cell_info.cell_list.cell[cell_info.cell_list.num].value6= (uint32)tmp_int;
840 /*
841 // Jump 2 integer.
842 i = 0;
843 while(i < 2) {
844 if (at_tok_nextint(&line, &tmp_int) < 0)
845 {
846 goto EEMUMTSSVC_EXIT;
847 }
848 i++;
849 }
850 */
851 // arfcn
852 if (at_tok_nextint(&line, &tmp_int) < 0)
853 {
854 goto EEMUMTSSVC_EXIT;
855 }
856 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
857
858 cell_info.cell_list.num++;
859EEMUMTSSVC_EXIT:
860 free(free_ptr);
861 }
862 }
863 /*
864 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
865 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
866 */
867 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
868 {
869 // lac, ci, arfcn
870 if(cell_info.running) {
871 int tmp_int;
872 int i = 0;
873 char* tmp_s = memdup(s,strlen(s));
874 char* free_ptr = tmp_s;
875 char *line = tmp_s;
876 if (at_tok_start(&line) < 0)
877 {
878 goto EEMUMTSINTRA_EXIT;
879 }
880 // Jump 8 integer.
881 i = 0;
882 while(i < 8) {
883 if (at_tok_nextint(&line, &tmp_int) < 0)
884 {
885 goto EEMUMTSINTRA_EXIT;
886 }
887 i++;
888 }
889
890 // lac
891 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
892 {
893 goto EEMUMTSINTRA_EXIT;
894 }
895 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
896
897 // ci
898 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
899 {
900 goto EEMUMTSINTRA_EXIT;
901 }
902 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
903
904 // arfcn
905 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
906 {
907 goto EEMUMTSINTRA_EXIT;
908 }
909 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
910
911 cell_info.cell_list.num++;
912EEMUMTSINTRA_EXIT:
913 free(free_ptr);
914 }
915 }
916 /*
917 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
918 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
919 */
920 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
921 {
922 // lac, ci, arfcn
923 if(cell_info.running) {
924 int tmp_int;
925 int i = 0;
926 char* tmp_s = memdup(s,strlen(s));
927 char* free_ptr = tmp_s;
928 char *line = tmp_s;
929 if (at_tok_start(&line) < 0)
930 {
931 goto EEMUMTSINTERRAT_EXIT;
932 }
933 // Jump 7 integer.
934 i = 0;
935 while(i < 7) {
936 if (at_tok_nextint(&line, &tmp_int) < 0)
937 {
938 goto EEMUMTSINTERRAT_EXIT;
939 }
940 i++;
941 }
942
943 // lac
944 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
945 {
946 goto EEMUMTSINTERRAT_EXIT;
947 }
948 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
949
950 // ci
951 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
952 {
953 goto EEMUMTSINTERRAT_EXIT;
954 }
955 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
956
957 // arfcn
958 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
959 {
960 goto EEMUMTSINTERRAT_EXIT;
961 }
962 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
963
964 cell_info.cell_list.num++;
965EEMUMTSINTERRAT_EXIT:
966 free(free_ptr);
967 }
968 }
969 // GSM
970 // +EEMGINFOBASIC: 2
971 // Do nothing.
972 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
973 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
974 {
975 if(cell_info.running) {
976
977 }
978 }
979 /*
980 // mcc, mnc_len, mnc, lac, ci, nom, nco,
981 // bsic, C1, C2, TA, TxPwr,
982 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
983 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
984 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
985 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
986 // gsmBand,channelMode
987 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
988 63, 36, 146, 1, 7,
989 46, 42, 42, 7, 0,
990 53, 0, 8, 0, 1, 6, 53,
991 2, 0, 146, 42, 54, 0, 1,
992 1, 32, 0, 0, 0, 0,
993 0, 0
994 */
995 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
996 {
997 // lac, ci, arfcn, bsic
998 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
999 if(cell_info.running) {
1000 int tmp_int;
1001 int i = 0;
1002 char* tmp_s = memdup(s,strlen(s));
1003 char* free_ptr = tmp_s;
1004 char *line = tmp_s;
1005 if (at_tok_start(&line) < 0)
1006 {
1007 goto EEMGINFOSVC_EXIT;
1008 }
1009
1010 // mcc
1011 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1012 {
1013 goto EEMGINFOSVC_EXIT;
1014 }
1015 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1016
1017 //mnc_len
1018 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1019 {
1020 goto EEMGINFOSVC_EXIT;
1021 }
1022 // mnc
1023 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1024 {
1025 goto EEMGINFOSVC_EXIT;
1026 }
1027 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1028
1029 /*
1030 // Jump 3 integer.
1031 i = 0;
1032 while(i < 3) {
1033 if (at_tok_nextint(&line, &tmp_int) < 0)
1034 {
1035 goto EEMGINFOSVC_EXIT;
1036 }
1037 i++;
1038 }
1039 */
1040 // lac
1041 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1042 {
1043 goto EEMGINFOSVC_EXIT;
1044 }
1045 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1046
1047 // ci
1048 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1049 {
1050 goto EEMGINFOSVC_EXIT;
1051 }
1052 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1053
1054 // Jump 2 integer.
1055 i = 0;
1056 while(i < 2) {
1057 if (at_tok_nextint(&line, &tmp_int) < 0)
1058 {
1059 goto EEMGINFOSVC_EXIT;
1060 }
1061 i++;
1062 }
1063
1064 // bsic
1065 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1066 {
1067 goto EEMGINFOSVC_EXIT;
1068 }
1069 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1070
1071 // Jump 15 integer.
1072 i = 0;
1073 while(i < 15) {
1074 if (at_tok_nextint(&line, &tmp_int) < 0)
1075 {
1076 goto EEMGINFOSVC_EXIT;
1077 }
1078 i++;
1079 }
1080
1081 // arfcn
1082 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1083 {
1084 goto EEMGINFOSVC_EXIT;
1085 }
1086 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1087
1088 cell_info.cell_list.num++;
1089EEMGINFOSVC_EXIT:
1090 free(free_ptr);
1091 }
1092 }
1093 /*
1094 // PS_attached, attach_type, service_type, tx_power, c_value,
1095 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1096 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1097 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1098 +EEMGINFOPS: 1, 255, 0, 0, 0,
1099 0, 0, 268435501, 1, 0, 0,
1100 4, 0, 96, 0, 0, 0,
1101 0, 0, 0, 65535, 0, 13350
1102 */
1103 // Do nothing.
1104 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1105 {
1106 if(cell_info.running) {
1107
1108 }
1109 }
1110 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1111 {
1112 if(cell_info.running) {
1113 int tmp_int;
1114 int i = 0;
1115 char* tmp_s = memdup(s,strlen(s));
1116 char* free_ptr = tmp_s;
1117 char *line = tmp_s;
1118 if (at_tok_start(&line) < 0)
1119 {
1120 goto EEMGINFOPS_EXIT;
1121 }
1122
1123 // nc_num
1124 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1125 {
1126 LOG("cell_info.running 1= %d\n.",cell_info.running);
1127 goto EEMGINFOPS_EXIT;
1128 }
1129 // mcc
1130 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1131 {
1132 LOG("cell_info.running 2= %d\n.",cell_info.running);
1133 goto EEMGINFOPS_EXIT;
1134 }
1135 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1136
1137 // mnc
1138 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1139 {
1140 LOG("cell_info.running 3= %d\n.",cell_info.running);
1141 goto EEMGINFOPS_EXIT;
1142 }
1143 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1144
1145 // lac
1146 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1147 {
1148 LOG("cell_info.running 4= %d\n.",cell_info.running);
1149 goto EEMGINFOPS_EXIT;
1150 }
1151 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1152
1153 // rac
1154 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1155 {
1156 LOG("cell_info.running 5= %d\n.",cell_info.running);
1157 goto EEMGINFOPS_EXIT;
1158 }
1159
1160 // ci
1161 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1162 {
1163 LOG("cell_info.running 6= %d\n.",cell_info.running);
1164 goto EEMGINFOPS_EXIT;
1165 }
1166 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1167
1168 // rx_lv
1169 if (at_tok_nextint(&line, &tmp_int) < 0)
1170 {
1171 LOG("cell_info.running 7= %d\n.",cell_info.running);
1172 goto EEMGINFOPS_EXIT;
1173 }
1174
1175 // bsic
1176 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1177 {
1178 LOG("cell_info.running 8= %d\n.",cell_info.running);
1179 goto EEMGINFOPS_EXIT;
1180 }
1181 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1182
1183 // Jump 2 integer.
1184 i = 0;
1185 while(i < 2) {
1186 if (at_tok_nextint(&line, &tmp_int) < 0)
1187 {
1188 LOG("cell_info.running 9= %d\n.",cell_info.running);
1189 goto EEMGINFOPS_EXIT;
1190 }
1191 i++;
1192 }
1193
1194 // arfcn
1195 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1196 {
1197 LOG("cell_info.running 10 = %d\n.",cell_info.running);
1198 goto EEMGINFOPS_EXIT;
1199 }
1200 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1201
1202 cell_info.cell_list.num++;
1203EEMGINFOPS_EXIT:
1204 free(free_ptr);
1205 }
1206 } else {
1207 LOGW("Unknown CELL URC : %s", s);
1208 }
1209}
1210
b.liu87afc4c2024-08-14 17:33:45 +08001211
1212static void onUnsolicited(const char *s, const char *sms_pdu)
1213{
1214 LOGD("URC : %s", s);
b.liu87afc4c2024-08-14 17:33:45 +08001215 // MBTK_AT_READY
1216 if (strStartsWith(s, "MBTK_AT_READY")) // AT ready.
1217 {
1218
b.liubcf86c92024-08-19 19:48:28 +08001219 } else if(strStartsWith(s, "CONNECT") || strStartsWith(s, "+CGEV:")) {
1220 urc_pdp_state_process(s, sms_pdu);
1221 } else if(strStartsWith(s, "+EEMLTESVC:") || strStartsWith(s, "+EEMLTEINTER:")
1222 || strStartsWith(s, "+EEMLTEINTRA:") || strStartsWith(s, "+EEMLTEINTERRAT:")
1223 || strStartsWith(s, "+EEMUMTSSVC:") || strStartsWith(s, "+EEMUMTSINTRA:")
1224 || strStartsWith(s, "+EEMUMTSINTERRAT:") || strStartsWith(s, "+EEMGINFOBASIC:")
1225 || strStartsWith(s, "+EEMGINFOSVC:") || strStartsWith(s, "+EEMGINFOPS:")
1226 || strStartsWith(s, "+EEMGINFONC:")) {
1227 urc_cell_info_process(s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08001228 }
b.liub4772072024-08-15 14:47:03 +08001229#if 0
b.liu87afc4c2024-08-14 17:33:45 +08001230 else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
1231 {
1232 const char* ptr = s + strlen("*RADIOPOWER:");
1233 while(*ptr != '\0' && *ptr == ' ' )
1234 {
1235 ptr++;
1236 }
1237
1238 uint8 state;
1239 if(*ptr == '1') {
1240 //net_info.radio_state = MBTK_RADIO_STATE_ON;
1241 // mbtk_radio_ready_cb();
1242 state = (uint8)1;
1243 } else {
1244 //net_info.radio_state = MBTK_RADIO_STATE_OFF;
1245 state = (uint8)0;
1246 }
1247 urc_msg_distribute(true, INFO_URC_MSG_RADIO_STATE, &state, sizeof(uint8));
1248 }
b.liubcf86c92024-08-19 19:48:28 +08001249 else {
b.liu87afc4c2024-08-14 17:33:45 +08001250 // apn_state_set
1251
1252 // +CGEV: NW PDN DEACT <cid>
1253
1254 // +CGEV: EPS PDN ACT 1
1255 // +CGEV: ME PDN ACT 8,1
1256
1257 // +CGEV: ME PDN ACT 2,4
1258 uint8 data[2] = {0xFF};
1259 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
1260 //apn_state_set(atoi(s + 20), false);
1261 data[0] = (uint8)0;
1262 data[1] = (uint8)atoi(s + 20);
1263
1264 uint8 data_pdp;
1265 data_pdp = 0; //
1266 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1267 data_pdp = data[1] + 100;
1268 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1269 } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
1270 //apn_state_set(atoi(s + 19), true);
1271 data[0] = (uint8)1;
1272 data[1] = (uint8)atoi(s + 19);
1273 } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
1274 //apn_state_set(atoi(s + 19), true);
1275 data[0] = (uint8)0;
1276 data[1] = (uint8)atoi(s + 20);
1277
1278 uint8 data_pdp;
1279 data_pdp = 0; //
1280 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1281 data_pdp = data[1] + 100;
1282 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1283 } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
1284 //apn_state_set(atoi(s + 18), true);
1285 data[0] = (uint8)1;
1286 data[1] = (uint8)atoi(s + 18);
1287
1288 uint8 data_pdp;
1289 char* tmp_s = memdup(s + 18,strlen(s + 18));
1290 char* free_ptr = tmp_s;
1291 char *line = tmp_s;
1292 int tmp_int;
1293 if (at_tok_start(&line) < 0)
1294 {
1295 goto PDP_CREG_EXIT;
1296 }
1297 if (at_tok_nextint(&line, &tmp_int) < 0)
1298 {
1299 goto PDP_CREG_EXIT;
1300 }
1301 if (at_tok_nextint(&line, &tmp_int) < 0)
1302 {
1303 goto PDP_CREG_EXIT;
1304 }
1305 data_pdp = tmp_int;
1306PDP_CREG_EXIT:
1307 free(free_ptr);
1308 //data_pdp = (uint8)atoi(s + 20); //reason
1309 if(data[1] >= 1 && data[1] < 8)
1310 {
1311 if(data_pdp == 0)
1312 {
1313 data_pdp = 25;
1314 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1315 }
1316 else if(data_pdp == 1)
1317 {
1318 data_pdp = 26;
1319 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1320 }
1321 else if(data_pdp == 2)
1322 {
1323 data_pdp = 27;
1324 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1325 }
1326 else if(data_pdp == 3)
1327 {
1328 data_pdp = 27;
1329 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1330 }
1331 else
1332 {
1333
1334 }
1335
1336 data_pdp = data[1] + 200;
1337 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1338 data[1] = 0;
1339 }
1340 } else {
1341 LOGI("No process : %s", s);
1342 }
1343
1344 urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
1345 }
1346 }
1347 // +CREG: 1, "8010", "000060a5", 0, 2, 0
1348 // +CREG: 1, "8330", "06447347", 7, 2, 0
1349 // +CEREG: 1, "8330", "06447347", 7
1350 // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
1351 // $CREG: 1, "8010", "000060a7", 0,, 2, 0
1352 // +CGREG: 1
1353 else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
1354 || strStartsWith(s, "+CEREG:")) // LTE data registed.
1355 {
1356 char* tmp_s = s + 7;
1357 static bool net_led_gms_wcdma = FALSE;
1358 static bool net_led_lte = FALSE;
1359 while(*tmp_s && *tmp_s == ' ')
1360 tmp_s++;
1361 uint8 data[2];
1362 data[0] = (uint8)atoi(tmp_s); // Reg State.
1363
1364 if(strStartsWith(s, "+CGREG:"))
1365 {
1366 data[1] = 0; // GMS/WCDMA
1367 if(data[0] == 1)
1368 {
1369 net_led_gms_wcdma = TRUE;
1370 }
1371 else
1372 {
1373 net_led_gms_wcdma = FALSE;
1374 }
1375
1376 }
1377 else
1378 {
1379 data[1] = 1; // LTE
1380 if(data[0] == 1)
1381 {
1382 net_led_lte = TRUE;
1383 }
1384 else
1385 {
1386 net_led_lte = FALSE;
1387 }
1388 }
1389
1390 if(FALSE == net_led_gms_wcdma && FALSE == net_led_lte)
1391 {
1392 //mbtk_net_led_set(MBTK_NET_LED_SEARCH_NETWORK);
1393 }
1394 else
1395 {
1396 //mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
1397 mbtk_net_ready();
1398 }
1399
1400 urc_msg_distribute(true, INFO_URC_MSG_NET_PS_REG_STATE, data, sizeof(data));
1401 urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
1402 }
1403 // +CREG: 1, "8010", "000060a5", 0, 2, 0
1404 // +CREG: 1, "8330", "06447347", 7, 2, 0
1405 // +CREG: 0
1406 else if(strStartsWith(s, "+CREG:")) // GMS/WCDMA/LTE CS registed.
1407 {
1408 uint8 data[3];
1409 data[0] = (uint8)MBTK_NET_CS_STATE;
1410 char* tmp_s = memdup(s,strlen(s));
1411 char* free_ptr = tmp_s;
1412 char *line = tmp_s;
1413 int tmp_int;
1414 char *tmp_str;
1415 if (at_tok_start(&line) < 0)
1416 {
1417 goto CREG_EXIT;
1418 }
1419 if (at_tok_nextint(&line, &tmp_int) < 0)
1420 {
1421 goto CREG_EXIT;
1422 }
1423 data[1] = (uint8)tmp_int; // Reg State.
1424 if (data[1])
1425 {
1426 if (at_tok_nextstr(&line, &tmp_str) < 0)
1427 {
1428 goto CREG_EXIT;
1429 }
1430 if (at_tok_nextstr(&line, &tmp_str) < 0)
1431 {
1432 goto CREG_EXIT;
1433 }
1434 if (at_tok_nextint(&line, &tmp_int) < 0)
1435 {
1436 goto CREG_EXIT;
1437 }
1438 data[2] = (uint8)tmp_int; // AcT
1439 } else {
1440 data[2] = (uint8)0xFF; // AcT
1441 }
1442 if(data[1] == 5)
1443 {
1444 uint8 data_pdp;
1445 data_pdp = 5; //
1446 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1447 }
1448 urc_msg_distribute(false, INFO_URC_MSG_NET_CS_REG_STATE, data, sizeof(data));
1449 urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
1450CREG_EXIT:
1451 free(free_ptr);
1452 }
1453 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
1454 else if(strStartsWith(s, "+CLCC:"))
1455 {
1456 mbtk_call_info_t reg;
1457 reg.call_wait = MBTK_CLCC;
1458 char* tmp_s = memdup(s,strlen(s));
1459 char* free_ptr = tmp_s;
1460 char *line = tmp_s;
1461 int tmp_int;
1462 char *tmp_str;
1463 int err;
1464
1465 err = at_tok_start(&line);
1466 if (err < 0)
1467 {
1468 goto CLCC_EXIT;
1469 }
1470 err = at_tok_nextint(&line, &tmp_int); // dir1
1471 if (err < 0)
1472 {
1473 goto CLCC_EXIT;
1474 }
1475 reg.dir1 = (uint8)tmp_int;
1476 err = at_tok_nextint(&line, &tmp_int);// dir
1477 if (err < 0)
1478 {
1479 goto CLCC_EXIT;
1480 }
1481 reg.dir = (uint8)tmp_int;
1482 err = at_tok_nextint(&line, &tmp_int);// state
1483 if (err < 0)
1484 {
1485 goto CLCC_EXIT;
1486 }
1487 reg.state = (uint8)tmp_int;
1488 err = at_tok_nextint(&line, &tmp_int);// mode
1489 if (err < 0)
1490 {
1491 goto CLCC_EXIT;
1492 }
1493 reg.mode = (uint8)tmp_int;
1494 err = at_tok_nextint(&line, &tmp_int);// mpty
1495 if (err < 0)
1496 {
1497 goto CLCC_EXIT;
1498 }
1499 reg.mpty = (uint8)tmp_int;
1500 err = at_tok_nextstr(&line, &tmp_str); // phone_number
1501 if (err < 0)
1502 {
1503 goto CLCC_EXIT;
1504 }
1505
1506 memset(reg.phone_number,0,sizeof(reg.phone_number));
1507 memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
1508 err = at_tok_nextint(&line, &tmp_int);// tpye
1509 if (err < 0)
1510 {
1511 goto CLCC_EXIT;
1512 }
1513 reg.type = (uint8)tmp_int;
1514 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
1515CLCC_EXIT:
1516 free(free_ptr);
1517 }
1518 // +CPAS: 4
1519 else if(strStartsWith(s, "+CPAS:"))
1520 {
1521 mbtk_call_info_t reg;
1522 reg.call_wait = 0;
1523 char* tmp_s = memdup(s,strlen(s));
1524 char* free_ptr = tmp_s;
1525 char *line = tmp_s;
1526 int tmp_int;
1527 int err;
1528
1529 memset(&reg,0,sizeof(reg));
1530
1531 err = at_tok_start(&line);
1532 if (err < 0)
1533 {
1534 goto CPAS_EXIT;
1535 }
1536 err = at_tok_nextint(&line, &tmp_int);
1537 if (err < 0)
1538 {
1539 goto CPAS_EXIT;
1540 }
1541 reg.pas = (uint8)tmp_int;
1542 reg.call_wait = MBTK_CPAS;
1543 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
1544CPAS_EXIT:
1545 free(free_ptr);
1546 }
1547 // +CALLDISCONNECT: 1
1548 else if(strStartsWith(s, "+CALLDISCONNECT:"))
1549 {
1550 mbtk_call_info_t reg;
1551 reg.call_wait = 0;
1552 char* tmp_s = memdup(s,strlen(s));
1553 char* free_ptr = tmp_s;
1554 char *line = tmp_s;
1555 int tmp_int;
1556 int err;
1557
1558 memset(&reg,0,sizeof(reg));
1559
1560 err = at_tok_start(&line);
1561 if (err < 0)
1562 {
1563 goto CALLDISCONNECTED_EXIT;
1564 }
1565 err = at_tok_nextint(&line, &tmp_int);
1566 if (err < 0)
1567 {
1568 goto CALLDISCONNECTED_EXIT;
1569 }
1570 reg.disconnected_id = tmp_int;
1571 reg.call_wait = MBTK_DISCONNECTED;
1572
1573 if(reg.call_wait == MBTK_DISCONNECTED)
1574 {
1575 //mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
1576 }
1577
1578 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
1579
1580CALLDISCONNECTED_EXIT:
1581 free(free_ptr);
1582 }
1583 // *SIMDETEC:1,SIM
1584 else if(strStartsWith(s, "*SIMDETEC:"))
1585 {
1586 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
1587 {
1588 net_info.sim_state = MBTK_SIM_ABSENT;
1589 }
1590
1591 sim_info_reg.sim = -1;
1592 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
1593 sim_info_reg.sim = 0;
1594 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
1595 sim_info_reg.sim = 1;
1596 if(sim_info_reg.sim == 0)
1597 {
1598 uint8 data_pdp;
1599 data_pdp = 11; //
1600 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1601 }
1602 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
1603 }
1604 // *EUICC:1
1605/*0: SIM
16061: USIM
16072: TEST SIM
16083: TEST USIM
16094: UNKNOWN
1610Note: *EUICC:
1611*/
1612 else if(strStartsWith(s, "*EUICC:"))
1613 {
1614 sim_info_reg.sim_card_type = -1;
1615 if(strStartsWith(s, "*EUICC: 0"))
1616 sim_info_reg.sim_card_type = 1;
1617 else if(strStartsWith(s, "*EUICC: 1"))
1618 sim_info_reg.sim_card_type = 2;
1619 else if(strStartsWith(s, "*EUICC: 2"))
1620 sim_info_reg.sim_card_type = 1;
1621 else if(strStartsWith(s, "*EUICC: 3"))
1622 sim_info_reg.sim_card_type = 2;
1623 else if(strStartsWith(s, "*EUICC: 4"))
1624 sim_info_reg.sim_card_type = 0;
1625 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
1626 }
1627 // +CPIN: SIM PIN
1628 else if(strStartsWith(s, "+CPIN:"))
1629 {
1630 sim_info_reg.sim = -1;
1631 if(strStartsWith(s, "+CPIN: READY"))
1632 {
1633 sim_info_reg.sim = 1;
1634 net_info.sim_state = MBTK_SIM_READY;
1635 }
1636 else if(strStartsWith(s, "+CPIN: SIM PIN"))
1637 {
1638 sim_info_reg.sim = 2;
1639 net_info.sim_state = MBTK_SIM_PIN;
1640 }
1641 else if(strStartsWith(s, "+CPIN: SIM PUK"))
1642 {
1643 sim_info_reg.sim = 3;
1644 net_info.sim_state = MBTK_SIM_PUK;
1645 }
1646 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
1647 {
1648 sim_info_reg.sim = 4;
1649 net_info.sim_state = MBTK_SIM_ABSENT;
1650 }
1651 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
1652 {
1653 sim_info_reg.sim = 5;
1654 net_info.sim_state = MBTK_SIM_ABSENT;
1655 }
1656 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
1657 {
1658 sim_info_reg.sim = 6;
1659 net_info.sim_state = MBTK_SIM_ABSENT;
1660 }
1661 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
1662 {
1663 sim_info_reg.sim = 7;
1664 net_info.sim_state = MBTK_SIM_ABSENT;
1665 }
1666 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
1667 {
1668 sim_info_reg.sim = 8;
1669 net_info.sim_state = MBTK_SIM_ABSENT;
1670 }
1671 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
1672 {
1673 sim_info_reg.sim = 9;
1674 net_info.sim_state = MBTK_SIM_ABSENT;
1675 }
1676 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
1677 {
1678 sim_info_reg.sim = 10;
1679 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
1680 }
1681 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
1682 {
1683 sim_info_reg.sim = 11;
1684 net_info.sim_state = MBTK_SIM_ABSENT;
1685 }
1686 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
1687 {
1688 sim_info_reg.sim = 12;
1689 net_info.sim_state = MBTK_SIM_ABSENT;
1690 }
1691 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
1692 {
1693 sim_info_reg.sim = 13;
1694 net_info.sim_state = MBTK_SIM_ABSENT;
1695 }
1696 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
1697 {
1698 sim_info_reg.sim = 14;
1699 net_info.sim_state = MBTK_SIM_ABSENT;
1700 }
1701 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
1702 {
1703 sim_info_reg.sim = 15;
1704 net_info.sim_state = MBTK_SIM_ABSENT;
1705 }
1706 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
1707 {
1708 sim_info_reg.sim = 16;
1709 net_info.sim_state = MBTK_SIM_ABSENT;
1710 }
1711 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
1712 {
1713 sim_info_reg.sim = 17;
1714 net_info.sim_state = MBTK_SIM_ABSENT;
1715 }
1716 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
1717 {
1718 sim_info_reg.sim = 18;
1719 net_info.sim_state = MBTK_SIM_ABSENT;
1720 }
1721 else
1722 sim_info_reg.sim = 20;
1723
1724 if(sim_info_reg.sim == 18)
1725 {
1726 uint8 data_pdp;
1727 data_pdp = 11; //
1728 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1729 }
1730
1731 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
1732 }
1733 // +CMT: ,23
1734 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
1735 else if(strStartsWith(s, "+CMT:") || sms_cmt)
1736 {
1737 if(!sms_cmt){
1738 sms_cmt = true;
1739 }else{
1740 sms_cmt = false;
1741 }
1742 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
1743 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
1744 }
1745#if 0
1746 // LTE data registed.
1747 // +CEREG: 1, "8330", "06447347", 7
1748 else if(strStartsWith(s, "+CEREG:"))
1749 {
1750 char* tmp_s = memdup(s,strlen(s));
1751 char* free_ptr = tmp_s;
1752 char *line = tmp_s;
1753 int tmp_int;
1754 char *tmp_str;
1755 if (at_tok_start(&line) < 0)
1756 {
1757 goto CREG_EXIT;
1758 }
1759 if (at_tok_nextint(&line, &tmp_int) < 0)
1760 {
1761 goto CREG_EXIT;
1762 }
1763 uint8 data = (uint8)tmp_int; // Reg State.
1764
1765 urc_msg_distribute(INFO_URC_MSG_NET_REG_STATE, &data, sizeof(uint8));
1766CREG_EXIT:
1767 free(free_ptr);
1768 }
1769#endif
b.liu87afc4c2024-08-14 17:33:45 +08001770
b.liub4772072024-08-15 14:47:03 +08001771#endif
b.liu87afc4c2024-08-14 17:33:45 +08001772 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"
1773 {
1774
1775 }
1776 else
1777 {
1778 LOGV("Unknown URC : %s", s);
1779 }
b.liu87afc4c2024-08-14 17:33:45 +08001780}
1781
1782static int openSocket(const char* sockname)
1783{
1784 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
1785 if (sock < 0)
1786 {
1787 LOGE("Error create socket: %s\n", strerror(errno));
1788 return -1;
1789 }
1790 struct sockaddr_un addr;
1791 memset(&addr, 0, sizeof(addr));
1792 addr.sun_family = AF_UNIX;
1793 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
1794 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
1795 {
1796 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
1797 sleep(1);
1798 }
1799
1800#if 0
1801 int sk_flags = fcntl(sock, F_GETFL, 0);
1802 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
1803#endif
1804
1805 return sock;
1806}
1807
1808static void ril_at_ready_process()
1809{
1810 ril_info.radio_state = ril_radio_state_get();
1811 if (ril_info.radio_state != MBTK_RADIO_STATE_FULL_FUNC)
1812 {
1813 ril_radio_state_set(MBTK_RADIO_STATE_FULL_FUNC, FALSE);
1814 }
1815
1816 if(ril_info.radio_state == MBTK_RADIO_STATE_FULL_FUNC)
1817 {
1818 at_send_command("AT+CEREG=2", NULL);
1819 }
1820
1821 ril_info.sim_state = ril_sim_state_get();
1822 if(ril_info.sim_state == MBTK_SIM_STATE_READY)
1823 {
1824 LOGD("SIM READY!");
b.liub4772072024-08-15 14:47:03 +08001825 at_send_command("AT+COPS=3", NULL);
b.liu87afc4c2024-08-14 17:33:45 +08001826
1827 // Set APN from prop.
1828 apn_auto_conf_from_prop();
1829 }
1830 else
1831 {
1832 LOGE("SIM NOT READY!");
1833 }
1834}
1835
1836static void ind_regisger(sock_cli_info_t* cli_info, uint16 ind)
1837{
1838 uint32 i = 0;
1839 while(i < cli_info->ind_num)
1840 {
1841 if(cli_info->ind_register[i] == ind)
1842 break;
1843 i++;
1844 }
1845
1846 if(i == cli_info->ind_num) // No found IND
1847 {
1848 cli_info->ind_register[i] = ind;
1849 cli_info->ind_num++;
1850 LOGD("Register IND : %s", id2str(ind));
1851 }
1852 else
1853 {
1854 LOGW("IND had exist.");
1855 }
1856}
1857
1858// Process AT URC data
1859static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack)
1860{
1861 if(ril_info.msg_queue.count >= PACK_PROCESS_QUEUE_MAX)
1862 {
1863 LOGE("Packet process queue is full");
1864 return -1;
1865 }
1866
1867 ril_msg_queue_info_t *item = (ril_msg_queue_info_t*)malloc(sizeof(ril_msg_queue_info_t));
1868 if(!item)
1869 {
1870 LOGE("malloc() fail[%d].", errno);
1871 return -1;
1872 }
1873 item->cli_info = cli_info;
1874 item->pack = pack;
1875 mbtk_queue_put(&ril_info.msg_queue, item);
1876
1877 // If thread is waitting,continue it.
1878 pthread_mutex_lock(&ril_info.msg_mutex);
1879 pthread_cond_signal(&ril_info.msg_cond);
1880 pthread_mutex_unlock(&ril_info.msg_mutex);
1881
1882 return 0;
1883}
1884
1885
1886static void pack_distribute(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
1887{
1888 // Register IND Message.
1889 if(pack->msg_type == RIL_MSG_TYPE_IND)
1890 {
1891 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
1892 if(cli_info->ind_num >= IND_REGISTER_MAX)
1893 {
1894 LOGE("IND if full.");
1895 err = MBTK_RIL_ERR_IND_FULL;
1896 }
1897 else
1898 {
1899 ind_regisger(cli_info, pack->msg_id);
1900 }
1901
1902 ril_error_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, err);
1903
1904 ril_msg_pack_free(pack);
1905 }
1906 else // Request Information.
1907 {
1908 LOGD("Start process REQ(%s), Length : %d", id2str(pack->msg_id), pack->data_len);
1909 if(0 && pack->data_len > 0)
1910 {
1911 log_hex("DATA", pack->data, pack->data_len);
1912 }
1913
1914 // Send to REQ_process_thread process.
1915 send_pack_to_queue(cli_info, pack);
1916
1917 // For test.
1918 // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS);
1919 }
1920}
1921
1922// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
1923// Otherwise, do not call pack_error_send().
1924static mbtk_ril_err_enum pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
1925{
1926 if(pack->msg_id > RIL_MSG_ID_DEV_BEGIN && pack->msg_id < RIL_MSG_ID_DEV_END) {
1927 return dev_pack_req_process(cli_info, pack);
1928 } else if(pack->msg_id > RIL_MSG_ID_SIM_BEGIN && pack->msg_id < RIL_MSG_ID_SIM_END) {
1929 return sim_pack_req_process(cli_info, pack);
1930 } else if(pack->msg_id > RIL_MSG_ID_NET_BEGIN && pack->msg_id < RIL_MSG_ID_NET_END) {
1931 return net_pack_req_process(cli_info, pack);
1932 } else if(pack->msg_id > RIL_MSG_ID_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_CALL_END) {
1933 return call_pack_req_process(cli_info, pack);
1934 } else if(pack->msg_id > RIL_MSG_ID_SMS_BEGIN && pack->msg_id < RIL_MSG_ID_SMS_END) {
1935 return sms_pack_req_process(cli_info, pack);
1936 } else if(pack->msg_id > RIL_MSG_ID_PB_BEGIN && pack->msg_id < RIL_MSG_ID_PB_END) {
1937 return pb_pack_req_process(cli_info, pack);
1938 } else {
1939 LOGW("Unknown msg id : %d", pack->msg_id);
1940 return MBTK_RIL_ERR_FORMAT;
1941 }
1942}
1943
1944static void urc_msg_process(ril_urc_msg_info_t *msg)
1945{
1946 uint8 *data = NULL;
1947 if(msg->data) {
1948 data = (uint8*)msg->data;
1949 }
1950 switch(msg->msg) {
1951 case RIL_URC_MSG_RADIO_STATE:
1952 {
1953 break;
1954 }
1955 default:
1956 {
1957 LOGE("Unknown URC : %d", msg->msg);
1958 break;
1959 }
1960 }
1961}
1962
1963// Read client conn/msg and push into ril_info.msg_queue.
1964static void* ril_read_pthread(void* arg)
1965{
1966 UNUSED(arg);
1967 ril_info.epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1);
1968 if(ril_info.epoll_fd < 0)
1969 {
1970 LOGE("epoll_create() fail[%d].", errno);
1971 return NULL;
1972 }
1973
1974 uint32 event = EPOLLIN | EPOLLET;
1975 struct epoll_event ev;
1976 ev.data.fd = ril_info.sock_listen_fd;
1977 ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
1978 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, ril_info.sock_listen_fd, &ev);
1979
1980 int nready = -1;
1981 struct epoll_event epoll_events[EPOLL_LISTEN_MAX];
1982 while(1)
1983 {
1984 nready = epoll_wait(ril_info.epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
1985 if(nready > 0)
1986 {
1987 sock_cli_info_t *cli_info = NULL;
1988 int i;
1989 for(i = 0; i < nready; i++)
1990 {
1991 LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events);
1992 if(epoll_events[i].events & EPOLLHUP) // Client Close.
1993 {
1994 if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL)
1995 {
1996 cli_close(cli_info);
1997 }
1998 else
1999 {
2000 LOG("Unknown client[fd = %d].", epoll_events[i].data.fd);
2001 }
2002 }
2003 else if(epoll_events[i].events & EPOLLIN)
2004 {
2005 if(epoll_events[i].data.fd == ril_info.sock_listen_fd) // New clients connected.
2006 {
2007 int client_fd = -1;
2008 while(1)
2009 {
2010 struct sockaddr_in cliaddr;
2011 socklen_t clilen = sizeof(cliaddr);
2012 client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen);
2013 if(client_fd < 0)
2014 {
2015 if(errno == EAGAIN)
2016 {
2017 LOG("All client connect get.");
2018 }
2019 else
2020 {
2021 LOG("accept() error[%d].", errno);
2022 }
2023 break;
2024 }
2025 // Set O_NONBLOCK
2026 int flags = fcntl(client_fd, F_GETFL, 0);
2027 if (flags > 0)
2028 {
2029 flags |= O_NONBLOCK;
2030 if (fcntl(client_fd, F_SETFL, flags) < 0)
2031 {
2032 LOG("Set flags error:%d", errno);
2033 }
2034 }
2035
2036 memset(&ev,0,sizeof(struct epoll_event));
2037 ev.data.fd = client_fd;
2038 ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET;
2039 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, client_fd, &ev);
2040
2041 sock_cli_info_t *info = (sock_cli_info_t*)malloc(sizeof(sock_cli_info_t));
2042 if(info)
2043 {
2044 memset(info, 0, sizeof(sock_cli_info_t));
2045 info->fd = client_fd;
2046 list_add(ril_info.sock_client_list, info);
2047 LOG("Add New Client FD Into List.");
2048
2049 // Send msg RIL_MSG_ID_IND_SER_READY to client.
2050 ril_ind_pack_send(client_fd, RIL_MSG_ID_IND_SER_READY, NULL, 0);
2051 }
2052 else
2053 {
2054 LOG("malloc() fail.");
2055 }
2056 }
2057 }
2058 else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive.
2059 {
2060 // Read and process every message.
2061 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
2062 ril_msg_pack_info_t** pack = ril_pack_recv(cli_info->fd, true, &err);
2063
2064 // Parse packet error,send error response to client.
2065 if(pack == NULL)
2066 {
2067 ril_error_pack_send(cli_info->fd, RIL_MSG_ID_UNKNOWN, RIL_MSG_INDEX_INVALID, err);
2068 }
2069 else
2070 {
2071 ril_msg_pack_info_t** pack_ptr = pack;
2072 while(*pack_ptr)
2073 {
2074 pack_distribute(cli_info, *pack_ptr);
2075 // Not free,will free in pack_process() or packet process thread.
2076 //mbtk_info_pack_free(pack_ptr);
2077 pack_ptr++;
2078 }
2079
2080 free(pack);
2081 }
2082 }
2083 else
2084 {
2085 LOG("Unknown socket : %d", epoll_events[i].data.fd);
2086 }
2087 }
2088 else
2089 {
2090 LOG("Unknown event : %x", epoll_events[i].events);
2091 }
2092 }
2093 }
2094 else
2095 {
2096 LOG("epoll_wait() fail[%d].", errno);
2097 }
2098 }
2099
2100 return NULL;
2101}
2102
2103static void* ril_process_thread(void* arg)
2104{
2105 UNUSED(arg);
2106 ril_msg_queue_info_t* item = NULL;
2107
2108 pthread_mutex_lock(&ril_info.msg_mutex);
2109 while(TRUE)
2110 {
2111 if(mbtk_queue_empty(&ril_info.msg_queue))
2112 {
2113 LOG("Packet process wait...");
2114 pthread_cond_wait(&ril_info.msg_cond, &ril_info.msg_mutex);
2115 LOG("Packet process continue...");
2116 }
2117 else
2118 {
2119 LOG("Packet process queue not empty,continue...");
2120 }
2121
2122 // Process all information request.
2123 mbtk_ril_err_enum err;
2124 while((item = (ril_msg_queue_info_t*)mbtk_queue_get(&ril_info.msg_queue)) != NULL)
2125 {
2126 if(item->cli_info) { // REQ form client.
2127 ril_msg_pack_info_t *pack = (ril_msg_pack_info_t*)item->pack;
2128 LOGD("Process REQ %s.", id2str(pack->msg_id));
2129 ril_info.at_process = true;
2130 err = pack_req_process(item->cli_info, pack);
2131 if(err != MBTK_RIL_ERR_SUCCESS)
2132 {
2133 ril_error_pack_send(item->cli_info->fd, pack->msg_id, pack->msg_index, err);
2134 }
2135 ril_info.at_process = false;
2136 ril_msg_pack_free(pack);
2137 free(item);
2138 } else { // REQ from myself.
2139 ril_urc_msg_info_t *urc = (ril_urc_msg_info_t*)item->pack;
2140 LOGD("Process URC %d.", urc->msg);
2141 urc_msg_process(urc);
2142 if(urc->data)
2143 free(urc->data);
2144 free(urc);
2145 }
2146 }
2147 }
2148 pthread_mutex_unlock(&ril_info.msg_mutex);
2149 return NULL;
2150}
2151
2152/*
2153AT*BAND=15,78,147,482,134742231
2154
2155OK
2156*/
2157static void* band_config_thread()
2158{
2159 mbtk_device_info_modem_t info_modem;
2160 memset(&band_info.band_support, 0, sizeof(mbtk_band_info_t));
2161 memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
2162 band_info.band_set_success = FALSE;
2163 if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
2164 LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
2165 band_info.band_area = MBTK_MODEM_BAND_AREA_ALL;
2166 band_info.band_support.net_pref = MBTK_NET_PREF_UNUSE;
2167 band_info.band_support.gsm_band = MBTK_BAND_ALL_GSM_DEFAULT;
2168 band_info.band_support.umts_band = MBTK_BAND_ALL_WCDMA_DEFAULT;
2169 band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
2170 band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
2171 band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
2172 } else {
2173 band_info.band_area = info_modem.band_area;
2174 band_info.band_support.net_pref = MBTK_NET_PREF_UNUSE;
2175 band_info.band_support.gsm_band = info_modem.band_gsm;
2176 band_info.band_support.umts_band = info_modem.band_wcdma;
2177 band_info.band_support.tdlte_band = info_modem.band_tdlte;
2178 band_info.band_support.fddlte_band = info_modem.band_fddlte;
2179 band_info.band_support.lte_ext_band = info_modem.band_lte_ext;
2180 }
2181
2182 bool is_first = TRUE;
2183 while(!band_info.band_set_success) {
2184 // Set band.
2185#if 0
2186 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
2187 if(!urc)
2188 {
2189 LOG("malloc() fail[%d].", errno);
2190 break;
2191 } else {
2192 urc->msg = INFO_URC_MSG_SET_BAND;
2193 urc->data = NULL;
2194 urc->data_len = 0;
2195 send_pack_to_queue(NULL, urc);
2196
2197 if(is_first) {
2198 is_first = FALSE;
2199 } else {
2200 LOGE("*BAND exec error, will retry in 5s.");
2201 }
2202 sleep(5);
2203 }
2204#else
2205 sleep(5);
2206#endif
2207 }
2208
2209 LOGD("Set Band thread exit.");
2210 return NULL;
2211}
2212
2213
2214int ril_server_start()
2215{
2216 signal(SIGPIPE, SIG_IGN);
2217
2218 memset(&ril_info, 0, sizeof(ril_info_t));
2219 memset(&band_info, 0, sizeof(ril_band_info_t));
2220 memset(&band_info.band_support, 0xFF, sizeof(mbtk_band_info_t));
2221
2222 //check cfun and sim card status
2223 ril_at_ready_process();
2224
2225 //any AT instruction that is not sent through pack_process_thread needs to precede the thread
2226 //thread create
2227 if(ril_info.sock_listen_fd > 0)
2228 {
2229 LOGE("Information Server Has Started.");
2230 return -1;
2231 }
2232
2233 struct sockaddr_un server_addr;
2234 ril_info.sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
2235 if(ril_info.sock_listen_fd < 0)
2236 {
2237 LOGE("socket() fail[%d].", errno);
2238 return -1;
2239 }
2240
2241 // Set O_NONBLOCK
2242 int flags = fcntl(ril_info.sock_listen_fd, F_GETFL, 0);
2243 if (flags < 0)
2244 {
2245 LOGE("Get flags error:%d", errno);
2246 goto error;
2247 }
2248 flags |= O_NONBLOCK;
2249 if (fcntl(ril_info.sock_listen_fd, F_SETFL, flags) < 0)
2250 {
2251 LOGE("Set flags error:%d", errno);
2252 goto error;
2253 }
2254
2255 unlink(RIL_SOCK_NAME);
2256 memset(&server_addr, 0, sizeof(struct sockaddr_un));
2257 server_addr.sun_family = AF_LOCAL;
2258 strcpy(server_addr.sun_path, RIL_SOCK_NAME);
2259 if(bind(ril_info.sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)))
2260 {
2261 LOGE("bind() fail[%d].", errno);
2262 goto error;
2263 }
2264
2265 if(listen(ril_info.sock_listen_fd, SOCK_CLIENT_MAX))
2266 {
2267 LOGE("listen() fail[%d].", errno);
2268 goto error;
2269 }
2270
2271 ril_info.sock_client_list = list_create(sock_cli_free_func);
2272 if(ril_info.sock_client_list == NULL)
2273 {
2274 LOGE("list_create() fail.");
2275 goto error;
2276 }
2277
2278 mbtk_queue_init(&ril_info.msg_queue);
2279 pthread_mutex_init(&ril_info.msg_mutex, NULL);
2280 pthread_cond_init(&ril_info.msg_cond, NULL);
2281
2282 pthread_t info_pid, pack_pid, monitor_pid, urc_pid, bootconn_pid;
2283 pthread_attr_t thread_attr;
2284 pthread_attr_init(&thread_attr);
2285 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
2286 {
2287 LOGE("pthread_attr_setdetachstate() fail.");
2288 goto error;
2289 }
2290
2291 if(pthread_create(&info_pid, &thread_attr, ril_read_pthread, NULL))
2292 {
2293 LOGE("pthread_create() fail.");
2294 goto error;
2295 }
2296
2297 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, NULL))
2298 {
2299 LOGE("pthread_create() fail.");
2300 goto error;
2301 }
2302
2303 // Set Band
2304 // AT*BAND=15,78,147,482,134742231
2305 char buff[10];
2306 memset(buff, 0, 10);
2307 property_get("persist.mbtk.band_config", buff, "");
2308 if(strlen(buff) == 0) {
2309 pthread_t band_pid;
2310 if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL))
2311 {
2312 LOGE("pthread_create() fail.");
2313 }
2314 }
2315
2316 pthread_attr_destroy(&thread_attr);
2317
2318 LOGD("MBTK Ril Server Start...");
2319
2320 return 0;
2321error:
2322 if(ril_info.sock_client_list) {
2323 list_free(ril_info.sock_client_list);
2324 ril_info.sock_client_list = NULL;
2325 }
2326
2327 if(ril_info.sock_listen_fd > 0) {
2328 close(ril_info.sock_listen_fd);
2329 ril_info.sock_listen_fd = -1;
2330 }
2331 return -1;
2332}
2333
b.liu87afc4c2024-08-14 17:33:45 +08002334int main(int argc, char *argv[])
2335{
2336 mbtk_log_init("radio", "MBTK_RIL");
2337
b.liubcf86c92024-08-19 19:48:28 +08002338 MBTK_SOURCE_INFO_PRINT("mbtk_rild");
2339
b.liu87afc4c2024-08-14 17:33:45 +08002340#ifdef MBTK_DUMP_SUPPORT
2341 mbtk_debug_open(NULL, TRUE);
2342#endif
2343
2344// Using Killall,the file lock may be not release.
2345#if 0
2346 if(app_already_running(MBTK_RILD_PID_FILE)) {
2347 LOGW("daemon already running.");
2348 exit(1);
2349 }
2350#endif
2351
2352 LOGI("mbtk_rild start.");
2353
2354 if(InProduction_Mode()) {
2355 LOGI("Is Production Mode, will exit...");
2356 exit(0);
2357 }
2358
2359 ready_state_update();
2360
2361 int at_sock = openSocket("/tmp/atcmd_at");
2362 if(at_sock < 0)
2363 {
2364 LOGE("Open AT Socket Fail[%d].", errno);
2365 return -1;
2366 }
2367 int uart_sock = openSocket("/tmp/atcmd_urc");
2368 if(uart_sock < 0)
2369 {
2370 LOGE("Open Uart Socket Fail[%d].", errno);
2371 return -1;
2372 }
2373
2374 at_set_on_reader_closed(onATReaderClosed);
2375 at_set_on_timeout(onATTimeout);
2376
2377 if(at_open(at_sock, uart_sock, onUnsolicited))
2378 {
2379 LOGE("Start AT thread fail.");
2380 return -1;
2381 }
2382
2383 if(at_handshake())
2384 {
2385 LOGE("AT handshake fail.");
2386 return -1;
2387 }
2388
2389 LOGD("AT OK.");
2390
2391 if(ril_server_start())
2392 {
2393 LOGE("ril_server_start() fail.");
2394 return -1;
2395 }
2396
2397 mbtk_ril_ready();
2398
2399 while(1)
2400 {
2401 sleep(24 * 60 * 60);
2402 }
2403
2404 LOGD("!!!mbtk_ril exit!!!");
2405 return 0;
2406}