blob: a0f0afb0048f5992f3497a14fe216803f6331d2f [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
b.liu9e8584b2024-11-06 19:21:28 +080030#ifndef TEMP_FAILURE_RETRY
liubin281ac462023-07-19 14:22:54 +080031#define TEMP_FAILURE_RETRY(exp) ({ \
32 typeof (exp) _rc; \
33 do { \
34 _rc = (exp); \
35 } while (_rc == -1 && errno == EINTR); \
36 _rc; })
b.liu9e8584b2024-11-06 19:21:28 +080037#endif
liubin281ac462023-07-19 14:22:54 +080038
39#define BUFFER_SIZE 2048
40#define UEVENT_USIM_DEV "/devices/virtual/usim_event/usim0"
41#define MBTK_BOOT_SERVER_READY "/etc/init.d/mbtk_boot_server_ready"
b.liubb590492024-06-13 16:42:08 +080042#define MBTK_BOOT_NET_READY "/etc/init.d/mbtk_boot_net_ready"
43#define MBTK_RILD_PID_FILE "/var/run/mbtk_rild.pid"
44#define MBTK_RILD_TEMP_FILE "/tmp/mbtk_rild.count"
liubin281ac462023-07-19 14:22:54 +080045
46struct cooling_device
47{
48 const char *name;
49 const char *action;
50 const char *path;
51 const char *event;
52 const char *subsystem;
53};
54static pthread_t uevnet_task_id;
55extern net_info_t net_info;
56extern mbtK_cell_pack_info_t cell_info;
57extern info_cgact_wait_t cgact_wait;
58extern bool at_process;
yq.wangd58f71e2024-08-21 23:45:31 -070059extern bool at_cfun_command;
b.liubb590492024-06-13 16:42:08 +080060static bool is_first_boot = FALSE;
liubin281ac462023-07-19 14:22:54 +080061
62void setRadioPower(int isOn);
b.liu9e8584b2024-11-06 19:21:28 +080063int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, const void *data, int data_len);
liubin281ac462023-07-19 14:22:54 +080064int mbtk_signal_log(char *data);
65
66/* Called on command thread */
67static void onATTimeout()
68{
69 LOGI("AT channel timeout; closing\n");
70 at_close();
71}
72
73/* Called on command or reader thread */
74static void onATReaderClosed()
75{
76 LOGI("AT channel closed\n");
77 at_close();
78}
79
80//int req_time_set(int type, char *time, int *cme_err);
81static int metis_strptime(char *str_time)
82{
83 struct tm stm;
b.liu9e8584b2024-11-06 19:21:28 +080084// char dateTime[30];
liubin281ac462023-07-19 14:22:54 +080085 struct timeval tv;
86 if(strptime(str_time, "%Y-%m-%d %H:%M:%S",&stm) != NULL)
87 {
88 time_t _t = mktime(&stm);
89 tv.tv_sec = _t;
90 if(settimeofday(&tv, NULL)) {
91 LOG("Set time fail:%d", errno);
92 return -1;
93 } else {
94 LOG("Set time to %s.", str_time);
95 return 0;
96 }
97 } else {
98 LOG("Set time fail.");
99 return -1;
100 }
101}
102
103static void* ntp_pthread_run(void* arg)
104{
105 // Waitting for network connected.
106 while(mbtk_net_state_get() == MBTK_NET_STATE_OFF) {
107 sleep(1);
108 }
109 LOG("Network is connected.");
110
111 char time_type[10];
112 while(1){
113 memset(time_type, 0, 10);
114 property_get("persist.mbtk.time_type", time_type, "0");
115 if(atoi(time_type) == MBTK_TIME_TYPE_NTP) // NTP time
116 {
117 char time_str[100] = {0};
118 time_t time = 0;
119 while((time = (time_t)mbtk_at_systime()) == 0) {
120 usleep(100000);
121 }
122 struct tm *tm_t;
123 tm_t = localtime(&time);
124 strftime(time_str,128,"%F %T",tm_t);
125
126 // NTP time
127 metis_strptime(time_str);
128 } else {
129 break;
130 }
131
132 sleep(64); // Sleep 64s.
133 }
134 return NULL;
135}
136
137static void ntp_thread_start()
138{
139 pthread_t ntp_pid;
140 pthread_attr_t thread_attr;
141 pthread_attr_init(&thread_attr);
142 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
143 {
144 LOG("pthread_attr_setdetachstate() fail.");
145 return;
146 }
147
148 if(pthread_create(&ntp_pid, &thread_attr, ntp_pthread_run, NULL))
149 {
150 LOG("pthread_create() fail.");
151 }
152}
153
b.liubb590492024-06-13 16:42:08 +0800154static void mbtk_net_ready()
155{
156 // /etc/init.d/mbtk_boot_net_ready
157 if(is_first_boot) {
158 if(access(MBTK_BOOT_NET_READY , X_OK) == 0) {
159 LOGD("Exec : %s", MBTK_BOOT_NET_READY);
b.liu9e8584b2024-11-06 19:21:28 +0800160 mbtk_system(MBTK_BOOT_NET_READY);
b.liubb590492024-06-13 16:42:08 +0800161 } else {
162 LOGE("%s can not exec.", MBTK_BOOT_NET_READY);
163 }
164 is_first_boot = FALSE; // Only one time.
165 } else {
166 LOGD("No exec : %s", MBTK_BOOT_NET_READY);
167 }
168}
169
liubin281ac462023-07-19 14:22:54 +0800170bool sms_cmt = false;
171mbtk_sim_card_info sim_info_reg={0};
172static void onUnsolicited(const char *s, const char *sms_pdu)
173{
174 LOGV("URC : %s", s);
175 // MBTK_AT_READY
176 if (strStartsWith(s, "MBTK_AT_READY")) // AT ready.
177 {
178
179 }
180#if 0
181 else if(strStartsWith(s, "*SIMDETEC:")) // *SIMDETEC:1,SIM
182 {
183 const char* ptr = strstr(s, ",");
184 if(ptr)
185 {
186 ptr++; // Jump ','
187 if(memcmp(ptr, "SIM", 3) == 0)
188 net_info.sim_state = MBTK_SIM_STATE_READY;
189 else
190 net_info.sim_state = MBTK_SIM_STATE_ABSENT;
191 }
192 }
193#endif
194 else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
195 {
196 const char* ptr = s + strlen("*RADIOPOWER:");
197 while(*ptr != '\0' && *ptr == ' ' )
198 {
199 ptr++;
200 }
201
202 uint8 state;
203 if(*ptr == '1') {
204 //net_info.radio_state = MBTK_RADIO_STATE_ON;
205 // mbtk_radio_ready_cb();
206 state = (uint8)1;
207 } else {
208 //net_info.radio_state = MBTK_RADIO_STATE_OFF;
209 state = (uint8)0;
210 }
211 urc_msg_distribute(true, INFO_URC_MSG_RADIO_STATE, &state, sizeof(uint8));
212 }
213 // "CONNECT"
214 else if(strStartsWith(s, "CONNECT"))
215 {
216 if(cgact_wait.waitting && cgact_wait.act) {
217 cgact_wait.waitting = false;
218 }
219
yq.wangf98110c2025-06-11 14:50:04 +0800220 //uint8 data_pdp;
221 //data_pdp = 1; //
222 //urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
liubin281ac462023-07-19 14:22:54 +0800223 }
224 // +CGEV:
225 // +CGEV: NW DEACT <cid>,<cid>
226 // +CGEV: ME DEACT <cid>,<cid>
227 // +CGEV: NW PDN DEACT <cid>
228 // +CGEV: ME PDN DEACT <cid>
229 // +CGEV: NW DETACH
230 // +CGEV: ME DETACH
231 //
232 // +CGEV: NW ACT <cid>,<cid>
233 // +CGEV: ME ACT <cid>,<cid>
234 // +CGEV: EPS PDN ACT <cid>
235 // +CGEV: ME PDN ACT <cid>,<reason>,<cid>
236 // +CGEV: ME PDN ACT <cid>,<reason>
237 // +CGEV: NW PDN ACT <cid>
238 // +CGEV: EPS ACT <cid>
239 // +CGEV: NW MODIFY <cid>,<reason>
240 // +CGEV: NW REATTACH
241 else if(strStartsWith(s, "+CGEV:"))
242 {
yq.wangf98110c2025-06-11 14:50:04 +0800243 if(at_process && !at_cfun_command)
244 {
245 mbtk_pdp_cb_info_s pdp_cb_info;
246 memset(&pdp_cb_info, 0x00, sizeof(mbtk_pdp_cb_info_s));
247 pdp_cb_info.auto_urc = false;
248 if(cgact_wait.act)
249 {
250 if(strStartsWith(s, "+CGEV: ME PDN ACT ")) // +CGEV: ME PDN ACT 15,4
251 {
252 if(cgact_wait.cid == atoi(s + 18))
253 {
liubin281ac462023-07-19 14:22:54 +0800254 cgact_wait.waitting = false;
255 }
256
yq.wangf98110c2025-06-11 14:50:04 +0800257 pdp_cb_info.cid = atoi(s + 18);
258 pdp_cb_info.connect_state = true;
259#if 0
liubin281ac462023-07-19 14:22:54 +0800260 char* tmp_s = memdup(s + 18,strlen(s + 18));
261 char* free_ptr = tmp_s;
262 char *line = tmp_s;
263 int tmp_int;
264 if (at_tok_start(&line) < 0)
265 {
266 goto at_PDP_CREG_EXIT;
267 }
268 if (at_tok_nextint(&line, &tmp_int) < 0)
269 {
270 goto at_PDP_CREG_EXIT;
271 }
272 if (at_tok_nextint(&line, &tmp_int) < 0)
273 {
274 goto at_PDP_CREG_EXIT;
275 }
yq.wangf98110c2025-06-11 14:50:04 +0800276 pdp_cb_info.pdp_result = tmp_int;
liubin281ac462023-07-19 14:22:54 +0800277at_PDP_CREG_EXIT:
278 free(free_ptr);
yq.wangf98110c2025-06-11 14:50:04 +0800279 free_ptr = NULL;
liubin281ac462023-07-19 14:22:54 +0800280 //data_pdp = (uint8)atoi(s + 20); //reason
281 if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
282 {
283 if(data_pdp == 0)
284 {
285 data_pdp = 25;
286 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
287 //data_pdp = cgact_wait.cid + 200;
288 }
289 else if(data_pdp == 1)
290 {
291 data_pdp = 26;
292 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
293 }
294 else if(data_pdp == 2)
295 {
296 data_pdp = 27;
297 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
298 }
299 else if(data_pdp == 3)
300 {
301 data_pdp = 27;
302 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
303 }
304 else
305 {
306
307 }
308 if(cgact_wait.cid != 0)
309 {
310 data_pdp = cgact_wait.cid + 200;
b.liuf77b86c2024-11-09 13:24:10 +0800311 urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
liubin281ac462023-07-19 14:22:54 +0800312 }
313 }
yq.wangf98110c2025-06-11 14:50:04 +0800314#endif
315 urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
liubin281ac462023-07-19 14:22:54 +0800316 }
yq.wangf98110c2025-06-11 14:50:04 +0800317 else if(strStartsWith(s, "+CGEV: NW MODIFY ")) // +CGEV: NW MODIFY 1,4
318 {
319 if(cgact_wait.cid == atoi(s + 17))
320 {
liubin281ac462023-07-19 14:22:54 +0800321 cgact_wait.waitting = false;
322 }
yq.wangf98110c2025-06-11 14:50:04 +0800323
324 pdp_cb_info.cid = atoi(s + 17);
325 pdp_cb_info.connect_state = true;
326 //urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
327 }
328 }
329 else
330 {
331 if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) // +CGEV: ME PDN DEACT 1
332 {
333 if(cgact_wait.cid == atoi(s + 20))
liubin281ac462023-07-19 14:22:54 +0800334 {
yq.wangf98110c2025-06-11 14:50:04 +0800335 cgact_wait.waitting = false;
liubin281ac462023-07-19 14:22:54 +0800336 }
yq.wangf98110c2025-06-11 14:50:04 +0800337
338 pdp_cb_info.cid = atoi(s + 20);
339 pdp_cb_info.connect_state = false;
340 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
liubin281ac462023-07-19 14:22:54 +0800341 }
342 }
yq.wangf98110c2025-06-11 14:50:04 +0800343 }
344 else
345 {
liubin281ac462023-07-19 14:22:54 +0800346 // +CGEV: NW PDN DEACT <cid>
liubin281ac462023-07-19 14:22:54 +0800347 // +CGEV: EPS PDN ACT 1
348 // +CGEV: ME PDN ACT 8,1
liubin281ac462023-07-19 14:22:54 +0800349 // +CGEV: ME PDN ACT 2,4
yq.wangf98110c2025-06-11 14:50:04 +0800350 mbtk_pdp_cb_info_s pdp_cb_info;
351 memset(&pdp_cb_info, 0x00, sizeof(mbtk_pdp_cb_info_s));
352 pdp_cb_info.auto_urc = true;
353 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) // +CGEV: NW PDN DEACT <cid>
354 {
355 pdp_cb_info.cid = (uint8)atoi(s + 20);
356 pdp_cb_info.connect_state = false;
357 urc_msg_distribute(true, INFO_URC_MSG_CGEV, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
358 }
359 else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) // +CGEV: EPS PDN ACT <cid>
360 {
361 pdp_cb_info.cid = (uint8)atoi(s + 19);
362 pdp_cb_info.connect_state = true;
363 }
364 else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) // +CGEV: EPS PDN DEACT <cid>
365 {
366 pdp_cb_info.cid = (uint8)atoi(s + 20);
367 pdp_cb_info.connect_state = false;
368 urc_msg_distribute(true, INFO_URC_MSG_CGEV, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
369 }
370 else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) // +CGEV: ME PDN ACT <cid>,1
371 {
372 pdp_cb_info.cid = (uint8)atoi(s + 18);
373 pdp_cb_info.connect_state = true;
374 //urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
liubin281ac462023-07-19 14:22:54 +0800375
yq.wangf98110c2025-06-11 14:50:04 +0800376#if 0
liubin281ac462023-07-19 14:22:54 +0800377 char* tmp_s = memdup(s + 18,strlen(s + 18));
378 char* free_ptr = tmp_s;
379 char *line = tmp_s;
380 int tmp_int;
381 if (at_tok_start(&line) < 0)
382 {
383 goto PDP_CREG_EXIT;
384 }
385 if (at_tok_nextint(&line, &tmp_int) < 0)
386 {
387 goto PDP_CREG_EXIT;
388 }
389 if (at_tok_nextint(&line, &tmp_int) < 0)
390 {
391 goto PDP_CREG_EXIT;
392 }
393 data_pdp = tmp_int;
394PDP_CREG_EXIT:
395 free(free_ptr);
396 //data_pdp = (uint8)atoi(s + 20); //reason
397 if(data[1] >= 1 && data[1] < 8)
398 {
399 if(data_pdp == 0)
400 {
401 data_pdp = 25;
402 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
403 }
404 else if(data_pdp == 1)
405 {
406 data_pdp = 26;
407 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
408 }
409 else if(data_pdp == 2)
410 {
411 data_pdp = 27;
412 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
413 }
414 else if(data_pdp == 3)
415 {
416 data_pdp = 27;
417 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
418 }
419 else
420 {
421
422 }
wangyouqiang65884152023-10-25 19:54:15 +0800423 data_pdp = data[1] + 200;
b.liuf77b86c2024-11-09 13:24:10 +0800424 urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
wangyouqiang3947b302024-07-04 17:26:08 +0800425 data[1] = 0;
liubin281ac462023-07-19 14:22:54 +0800426 }
yq.wangf98110c2025-06-11 14:50:04 +0800427#endif
428
429 }
430 else
431 {
liubin281ac462023-07-19 14:22:54 +0800432 LOGI("No process : %s", s);
433 }
b.liubcf86c92024-08-19 19:48:28 +0800434
yq.wangf98110c2025-06-11 14:50:04 +0800435 //urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
liubin281ac462023-07-19 14:22:54 +0800436 }
437 }
438 // +CREG: 1, "8010", "000060a5", 0, 2, 0
439 // +CREG: 1, "8330", "06447347", 7, 2, 0
440 // +CEREG: 1, "8330", "06447347", 7
441 // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
442 // $CREG: 1, "8010", "000060a7", 0,, 2, 0
443 // +CGREG: 1
444 else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
445 || strStartsWith(s, "+CEREG:")) // LTE data registed.
446 {
b.liu9e8584b2024-11-06 19:21:28 +0800447 const char* tmp_s = s + 7;
liuyang67f4bac2024-06-26 17:06:13 +0800448 static bool net_led_gms_wcdma = FALSE;
449 static bool net_led_lte = FALSE;
liubin281ac462023-07-19 14:22:54 +0800450 while(*tmp_s && *tmp_s == ' ')
451 tmp_s++;
b.liufe320632024-01-17 20:38:08 +0800452 uint8 data[2];
453 data[0] = (uint8)atoi(tmp_s); // Reg State.
liubin281ac462023-07-19 14:22:54 +0800454
b.liubcf86c92024-08-19 19:48:28 +0800455 if(strStartsWith(s, "+CGREG:"))
liuyang67f4bac2024-06-26 17:06:13 +0800456 {
457 data[1] = 0; // GMS/WCDMA
458 if(data[0] == 1)
459 {
460 net_led_gms_wcdma = TRUE;
461 }
462 else
463 {
464 net_led_gms_wcdma = FALSE;
465 }
b.liubcf86c92024-08-19 19:48:28 +0800466
467 }
468 else
liuyang67f4bac2024-06-26 17:06:13 +0800469 {
470 data[1] = 1; // LTE
471 if(data[0] == 1)
472 {
473 net_led_lte = TRUE;
474 }
475 else
476 {
477 net_led_lte = FALSE;
478 }
479 }
b.liubcf86c92024-08-19 19:48:28 +0800480
liuyang67f4bac2024-06-26 17:06:13 +0800481 if(FALSE == net_led_gms_wcdma && FALSE == net_led_lte)
482 {
483 mbtk_net_led_set(MBTK_NET_LED_SEARCH_NETWORK);
484 }
485 else
486 {
487 mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
488 mbtk_net_ready();
b.liufe320632024-01-17 20:38:08 +0800489 }
490
491 urc_msg_distribute(true, INFO_URC_MSG_NET_PS_REG_STATE, data, sizeof(data));
liuyang37623a02024-06-20 15:21:39 +0800492 urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
liubin281ac462023-07-19 14:22:54 +0800493 }
494 // +CREG: 1, "8010", "000060a5", 0, 2, 0
495 // +CREG: 1, "8330", "06447347", 7, 2, 0
496 // +CREG: 0
497 else if(strStartsWith(s, "+CREG:")) // GMS/WCDMA/LTE CS registed.
498 {
499 uint8 data[3];
500 data[0] = (uint8)MBTK_NET_CS_STATE;
501 char* tmp_s = memdup(s,strlen(s));
502 char* free_ptr = tmp_s;
503 char *line = tmp_s;
504 int tmp_int;
505 char *tmp_str;
506 if (at_tok_start(&line) < 0)
507 {
508 goto CREG_EXIT;
509 }
510 if (at_tok_nextint(&line, &tmp_int) < 0)
511 {
512 goto CREG_EXIT;
513 }
514 data[1] = (uint8)tmp_int; // Reg State.
515 if (data[1])
516 {
517 if (at_tok_nextstr(&line, &tmp_str) < 0)
518 {
519 goto CREG_EXIT;
520 }
521 if (at_tok_nextstr(&line, &tmp_str) < 0)
522 {
523 goto CREG_EXIT;
524 }
525 if (at_tok_nextint(&line, &tmp_int) < 0)
526 {
527 goto CREG_EXIT;
528 }
529 data[2] = (uint8)tmp_int; // AcT
530 } else {
531 data[2] = (uint8)0xFF; // AcT
532 }
yq.wangf98110c2025-06-11 14:50:04 +0800533#if 0
liubin281ac462023-07-19 14:22:54 +0800534 if(data[1] == 5)
535 {
536 uint8 data_pdp;
537 data_pdp = 5; //
538 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
539 }
yq.wangf98110c2025-06-11 14:50:04 +0800540#endif
liubin281ac462023-07-19 14:22:54 +0800541 urc_msg_distribute(false, INFO_URC_MSG_NET_CS_REG_STATE, data, sizeof(data));
liuyang37623a02024-06-20 15:21:39 +0800542 urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
liubin281ac462023-07-19 14:22:54 +0800543CREG_EXIT:
544 free(free_ptr);
545 }
546 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
547 else if(strStartsWith(s, "+CLCC:"))
548 {
549 mbtk_call_info_t reg;
550 reg.call_wait = MBTK_CLCC;
551 char* tmp_s = memdup(s,strlen(s));
552 char* free_ptr = tmp_s;
553 char *line = tmp_s;
554 int tmp_int;
555 char *tmp_str;
556 int err;
557
558 err = at_tok_start(&line);
559 if (err < 0)
560 {
561 goto CLCC_EXIT;
562 }
563 err = at_tok_nextint(&line, &tmp_int); // dir1
564 if (err < 0)
565 {
566 goto CLCC_EXIT;
567 }
568 reg.dir1 = (uint8)tmp_int;
569 err = at_tok_nextint(&line, &tmp_int);// dir
570 if (err < 0)
571 {
572 goto CLCC_EXIT;
573 }
574 reg.dir = (uint8)tmp_int;
575 err = at_tok_nextint(&line, &tmp_int);// state
576 if (err < 0)
577 {
578 goto CLCC_EXIT;
579 }
580 reg.state = (uint8)tmp_int;
581 err = at_tok_nextint(&line, &tmp_int);// mode
582 if (err < 0)
583 {
584 goto CLCC_EXIT;
585 }
586 reg.mode = (uint8)tmp_int;
587 err = at_tok_nextint(&line, &tmp_int);// mpty
588 if (err < 0)
589 {
590 goto CLCC_EXIT;
591 }
592 reg.mpty = (uint8)tmp_int;
593 err = at_tok_nextstr(&line, &tmp_str); // phone_number
594 if (err < 0)
595 {
596 goto CLCC_EXIT;
597 }
598
599 memset(reg.phone_number,0,sizeof(reg.phone_number));
600 memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
601 err = at_tok_nextint(&line, &tmp_int);// tpye
602 if (err < 0)
603 {
604 goto CLCC_EXIT;
605 }
606 reg.type = (uint8)tmp_int;
607
r.xiaoe1404b32024-05-23 22:43:39 -0700608 if(reg.state == 2 || reg.state == 3 || reg.state == 0)
609 {
610 mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
611 }
612
r.xiao195e2522024-05-31 03:19:02 -0700613 if(reg.state == 4 && reg.dir == 1)
614 {
615 mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
616 }
617
618
liuyang4d7ac4b2024-11-21 16:25:22 +0800619 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800620CLCC_EXIT:
621 free(free_ptr);
622 }
623 // +CPAS: 4
624 else if(strStartsWith(s, "+CPAS:"))
625 {
626 mbtk_call_info_t reg;
627 reg.call_wait = 0;
628 char* tmp_s = memdup(s,strlen(s));
629 char* free_ptr = tmp_s;
630 char *line = tmp_s;
631 int tmp_int;
632 int err;
633
634 memset(&reg,0,sizeof(reg));
635
636 err = at_tok_start(&line);
637 if (err < 0)
638 {
639 goto CPAS_EXIT;
640 }
641 err = at_tok_nextint(&line, &tmp_int);
642 if (err < 0)
643 {
644 goto CPAS_EXIT;
645 }
646 reg.pas = (uint8)tmp_int;
647 reg.call_wait = MBTK_CPAS;
liuyang4d7ac4b2024-11-21 16:25:22 +0800648 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800649CPAS_EXIT:
650 free(free_ptr);
651 }
652 // +CALLDISCONNECT: 1
653 else if(strStartsWith(s, "+CALLDISCONNECT:"))
654 {
655 mbtk_call_info_t reg;
656 reg.call_wait = 0;
657 char* tmp_s = memdup(s,strlen(s));
658 char* free_ptr = tmp_s;
659 char *line = tmp_s;
660 int tmp_int;
661 int err;
662
663 memset(&reg,0,sizeof(reg));
664
665 err = at_tok_start(&line);
666 if (err < 0)
667 {
668 goto CALLDISCONNECTED_EXIT;
669 }
670 err = at_tok_nextint(&line, &tmp_int);
671 if (err < 0)
672 {
673 goto CALLDISCONNECTED_EXIT;
674 }
675 reg.disconnected_id = tmp_int;
676 reg.call_wait = MBTK_DISCONNECTED;
r.xiaoe1404b32024-05-23 22:43:39 -0700677
678 if(reg.call_wait == MBTK_DISCONNECTED)
679 {
680 mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
681 }
682
liuyang4d7ac4b2024-11-21 16:25:22 +0800683 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800684
685CALLDISCONNECTED_EXIT:
686 free(free_ptr);
687 }
688 // *SIMDETEC:1,SIM
689 else if(strStartsWith(s, "*SIMDETEC:"))
690 {
liuyange22a25e2024-05-23 19:41:52 +0800691 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
692 {
693 net_info.sim_state = MBTK_SIM_ABSENT;
694 }
b.liubb590492024-06-13 16:42:08 +0800695
liubin281ac462023-07-19 14:22:54 +0800696 sim_info_reg.sim = -1;
697 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
698 sim_info_reg.sim = 0;
699 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
700 sim_info_reg.sim = 1;
yq.wangf98110c2025-06-11 14:50:04 +0800701#if 0
liubin281ac462023-07-19 14:22:54 +0800702 if(sim_info_reg.sim == 0)
703 {
704 uint8 data_pdp;
705 data_pdp = 11; //
706 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
707 }
yq.wangf98110c2025-06-11 14:50:04 +0800708#endif
liubin281ac462023-07-19 14:22:54 +0800709 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
710 }
711 // *EUICC:1
712/*0: SIM
7131: USIM
7142: TEST SIM
7153: TEST USIM
7164: UNKNOWN
717Note: *EUICC:
718*/
719 else if(strStartsWith(s, "*EUICC:"))
720 {
yq.wangb184fc22024-08-19 00:54:30 -0700721 sim_info_reg.sim = -1;
liubin281ac462023-07-19 14:22:54 +0800722 sim_info_reg.sim_card_type = -1;
723 if(strStartsWith(s, "*EUICC: 0"))
724 sim_info_reg.sim_card_type = 1;
725 else if(strStartsWith(s, "*EUICC: 1"))
726 sim_info_reg.sim_card_type = 2;
727 else if(strStartsWith(s, "*EUICC: 2"))
728 sim_info_reg.sim_card_type = 1;
729 else if(strStartsWith(s, "*EUICC: 3"))
730 sim_info_reg.sim_card_type = 2;
731 else if(strStartsWith(s, "*EUICC: 4"))
732 sim_info_reg.sim_card_type = 0;
733 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
734 }
735 // +CPIN: SIM PIN
736 else if(strStartsWith(s, "+CPIN:"))
737 {
738 sim_info_reg.sim = -1;
739 if(strStartsWith(s, "+CPIN: READY"))
liuyange22a25e2024-05-23 19:41:52 +0800740 {
liubin281ac462023-07-19 14:22:54 +0800741 sim_info_reg.sim = 1;
liuyange22a25e2024-05-23 19:41:52 +0800742 net_info.sim_state = MBTK_SIM_READY;
743 }
liubin281ac462023-07-19 14:22:54 +0800744 else if(strStartsWith(s, "+CPIN: SIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800745 {
liubin281ac462023-07-19 14:22:54 +0800746 sim_info_reg.sim = 2;
liuyange22a25e2024-05-23 19:41:52 +0800747 net_info.sim_state = MBTK_SIM_PIN;
748 }
liubin281ac462023-07-19 14:22:54 +0800749 else if(strStartsWith(s, "+CPIN: SIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800750 {
liubin281ac462023-07-19 14:22:54 +0800751 sim_info_reg.sim = 3;
liuyange22a25e2024-05-23 19:41:52 +0800752 net_info.sim_state = MBTK_SIM_PUK;
753 }
liubin281ac462023-07-19 14:22:54 +0800754 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800755 {
liubin281ac462023-07-19 14:22:54 +0800756 sim_info_reg.sim = 4;
liuyange22a25e2024-05-23 19:41:52 +0800757 net_info.sim_state = MBTK_SIM_ABSENT;
758 }
liubin281ac462023-07-19 14:22:54 +0800759 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800760 {
liubin281ac462023-07-19 14:22:54 +0800761 sim_info_reg.sim = 5;
liuyange22a25e2024-05-23 19:41:52 +0800762 net_info.sim_state = MBTK_SIM_ABSENT;
763 }
liubin281ac462023-07-19 14:22:54 +0800764 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800765 {
liubin281ac462023-07-19 14:22:54 +0800766 sim_info_reg.sim = 6;
liuyange22a25e2024-05-23 19:41:52 +0800767 net_info.sim_state = MBTK_SIM_ABSENT;
768 }
liubin281ac462023-07-19 14:22:54 +0800769 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800770 {
liubin281ac462023-07-19 14:22:54 +0800771 sim_info_reg.sim = 7;
liuyange22a25e2024-05-23 19:41:52 +0800772 net_info.sim_state = MBTK_SIM_ABSENT;
773 }
liubin281ac462023-07-19 14:22:54 +0800774 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
liuyange22a25e2024-05-23 19:41:52 +0800775 {
liubin281ac462023-07-19 14:22:54 +0800776 sim_info_reg.sim = 8;
liuyange22a25e2024-05-23 19:41:52 +0800777 net_info.sim_state = MBTK_SIM_ABSENT;
778 }
liubin281ac462023-07-19 14:22:54 +0800779 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
liuyange22a25e2024-05-23 19:41:52 +0800780 {
liubin281ac462023-07-19 14:22:54 +0800781 sim_info_reg.sim = 9;
liuyange22a25e2024-05-23 19:41:52 +0800782 net_info.sim_state = MBTK_SIM_ABSENT;
783 }
liubin281ac462023-07-19 14:22:54 +0800784 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800785 {
liubin281ac462023-07-19 14:22:54 +0800786 sim_info_reg.sim = 10;
liuyange22a25e2024-05-23 19:41:52 +0800787 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
788 }
liubin281ac462023-07-19 14:22:54 +0800789 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800790 {
liubin281ac462023-07-19 14:22:54 +0800791 sim_info_reg.sim = 11;
liuyange22a25e2024-05-23 19:41:52 +0800792 net_info.sim_state = MBTK_SIM_ABSENT;
793 }
liubin281ac462023-07-19 14:22:54 +0800794 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
liuyange22a25e2024-05-23 19:41:52 +0800795 {
liubin281ac462023-07-19 14:22:54 +0800796 sim_info_reg.sim = 12;
liuyange22a25e2024-05-23 19:41:52 +0800797 net_info.sim_state = MBTK_SIM_ABSENT;
798 }
liubin281ac462023-07-19 14:22:54 +0800799 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800800 {
liubin281ac462023-07-19 14:22:54 +0800801 sim_info_reg.sim = 13;
liuyange22a25e2024-05-23 19:41:52 +0800802 net_info.sim_state = MBTK_SIM_ABSENT;
803 }
liubin281ac462023-07-19 14:22:54 +0800804 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800805 {
liubin281ac462023-07-19 14:22:54 +0800806 sim_info_reg.sim = 14;
liuyange22a25e2024-05-23 19:41:52 +0800807 net_info.sim_state = MBTK_SIM_ABSENT;
808 }
liubin281ac462023-07-19 14:22:54 +0800809 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800810 {
liubin281ac462023-07-19 14:22:54 +0800811 sim_info_reg.sim = 15;
liuyange22a25e2024-05-23 19:41:52 +0800812 net_info.sim_state = MBTK_SIM_ABSENT;
813 }
liubin281ac462023-07-19 14:22:54 +0800814 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800815 {
liubin281ac462023-07-19 14:22:54 +0800816 sim_info_reg.sim = 16;
liuyange22a25e2024-05-23 19:41:52 +0800817 net_info.sim_state = MBTK_SIM_ABSENT;
818 }
liubin281ac462023-07-19 14:22:54 +0800819 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800820 {
liubin281ac462023-07-19 14:22:54 +0800821 sim_info_reg.sim = 17;
liuyange22a25e2024-05-23 19:41:52 +0800822 net_info.sim_state = MBTK_SIM_ABSENT;
823 }
liubin281ac462023-07-19 14:22:54 +0800824 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
liuyange22a25e2024-05-23 19:41:52 +0800825 {
826 sim_info_reg.sim = 18;
827 net_info.sim_state = MBTK_SIM_ABSENT;
828 }
liubin281ac462023-07-19 14:22:54 +0800829 else
830 sim_info_reg.sim = 20;
yq.wangf98110c2025-06-11 14:50:04 +0800831#if 0
liubin281ac462023-07-19 14:22:54 +0800832 if(sim_info_reg.sim == 18)
833 {
834 uint8 data_pdp;
835 data_pdp = 11; //
836 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
837 }
yq.wangf98110c2025-06-11 14:50:04 +0800838#endif
liubin281ac462023-07-19 14:22:54 +0800839 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
840 }
841 // +CMT: ,23
842 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
843 else if(strStartsWith(s, "+CMT:") || sms_cmt)
844 {
845 if(!sms_cmt){
846 sms_cmt = true;
847 }else{
848 sms_cmt = false;
849 }
850 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
851 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
852 }
853#if 0
854 // LTE data registed.
855 // +CEREG: 1, "8330", "06447347", 7
856 else if(strStartsWith(s, "+CEREG:"))
857 {
858 char* tmp_s = memdup(s,strlen(s));
859 char* free_ptr = tmp_s;
860 char *line = tmp_s;
861 int tmp_int;
862 char *tmp_str;
863 if (at_tok_start(&line) < 0)
864 {
865 goto CREG_EXIT;
866 }
867 if (at_tok_nextint(&line, &tmp_int) < 0)
868 {
869 goto CREG_EXIT;
870 }
871 uint8 data = (uint8)tmp_int; // Reg State.
872
873 urc_msg_distribute(INFO_URC_MSG_NET_REG_STATE, &data, sizeof(uint8));
874CREG_EXIT:
875 free(free_ptr);
876 }
877#endif
878 /*
879 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
880 // <rsrp>,<rsrq>, <sinr>,
881 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
882 // cellId,subFrameAssignType,specialSubframePatterns,transMode
883 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
884 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
885 // dlBer, ulBer,
886 // diversitySinr, diversityRssi
887 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
888 0, 0, 0,
889 1, 10, 0, 1, 0, 1059, 78, 3959566565,
890 105149248, 2, 7, 7,
891 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
892 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
893 0, 0,
894 7, 44
895 */
896 else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
897 {
898 // tac, PCI, dlEuarfcn, ulEuarfcn, band
899 if(cell_info.running) {
900 int tmp_int;
901 int i = 0;
902 char* tmp_s = memdup(s,strlen(s));
903 char* free_ptr = tmp_s;
904 char *line = tmp_s;
905 if (at_tok_start(&line) < 0)
906 {
907 goto EEMLTESVC_EXIT;
908 }
909
910 if (at_tok_nextint(&line, &tmp_int) < 0)
911 {
912 goto EEMLTESVC_EXIT;
913 }
914 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
915 if (at_tok_nextint(&line, &tmp_int) < 0)
916 {
917 goto EEMLTESVC_EXIT;
918 }
919 if (at_tok_nextint(&line, &tmp_int) < 0)
920 {
921 goto EEMLTESVC_EXIT;
922 }
923 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
924 /*
925 // Jump 2 integer.
926 i = 0;
927 while(i < 2) {
928 if (at_tok_nextint(&line, &tmp_int) < 0)
929 {
930 goto EEMLTESVC_EXIT;
931 }
932 i++;
933 }
934 */
935 if (at_tok_nextint(&line, &tmp_int) < 0)
936 {
937 goto EEMLTESVC_EXIT;
938 }
939 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //tac
940 if (at_tok_nextint(&line, &tmp_int) < 0)
941 {
942 goto EEMLTESVC_EXIT;
943 }
944 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //pci
945 if (at_tok_nextint(&line, &tmp_int) < 0)
946 {
947 goto EEMLTESVC_EXIT;
948 }
949 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //dl arfcn
q.huange9dae462025-06-21 14:00:29 +0800950 if (at_tok_nextint(&line, &tmp_int) < 0) //ul arfcn
liubin281ac462023-07-19 14:22:54 +0800951 {
952 goto EEMLTESVC_EXIT;
953 }
liubin281ac462023-07-19 14:22:54 +0800954 if (at_tok_nextint(&line, &tmp_int) < 0)
955 {
956 goto EEMLTESVC_EXIT;
957 }
958 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //band
959 if (at_tok_nextint(&line, &tmp_int) < 0)
960 {
961 goto EEMLTESVC_EXIT;
962 }
963 if (at_tok_nextint(&line, &tmp_int) < 0)
964 {
965 goto EEMLTESVC_EXIT;
966 }
q.huange9dae462025-06-21 14:00:29 +0800967 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //rsrp
liubin281ac462023-07-19 14:22:54 +0800968 if (at_tok_nextint(&line, &tmp_int) < 0)
969 {
970 goto EEMLTESVC_EXIT;
971 }
q.huange9dae462025-06-21 14:00:29 +0800972 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //rsrq
liubin281ac462023-07-19 14:22:54 +0800973
q.huange9dae462025-06-21 14:00:29 +0800974 if (at_tok_nextint(&line, &tmp_int) < 0)
975 {
976 goto EEMLTESVC_EXIT;
977 }
978
979 cell_info.cell[cell_info.cell_num].value11 = (uint32)tmp_int; //sinr
980
981 for(i =0; i < 9; i++)
liubin281ac462023-07-19 14:22:54 +0800982 {
983 if (at_tok_nextint(&line, &tmp_int) < 0)
984 {
985 goto EEMLTESVC_EXIT;
986 }
987 }
988 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //cell identiy
989
b.liuaec91492025-05-24 10:52:26 +0800990 for(i =0; i < 28; i++)
991 {
992 if (at_tok_nextint(&line, &tmp_int) < 0)
993 {
994 goto EEMLTESVC_EXIT;
995 }
996 }
997
998 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //dlBler
999
q.huange9dae462025-06-21 14:00:29 +08001000 for(i =0; i < 14; i++)
1001 {
1002 if (at_tok_nextint(&line, &tmp_int) < 0)
1003 {
1004 goto EEMLTESVC_EXIT;
1005 }
1006 }
1007
1008 cell_info.cell[cell_info.cell_num].value12 = (uint32)tmp_int; //fdd or tdd //63
1009
liubin281ac462023-07-19 14:22:54 +08001010 cell_info.cell_num++;
1011
b.liuaec91492025-05-24 10:52:26 +08001012 LOG("LTESVC cell_num : %d", cell_info.cell_num);
1013
1014
liubin281ac462023-07-19 14:22:54 +08001015EEMLTESVC_EXIT:
1016 free(free_ptr);
1017 }
1018 }
1019 /*
1020 // index,phyCellId,euArfcn,rsrp,rsrq
1021 +EEMLTEINTER: 0, 65535, 38950, 0, 0
1022 */
q.huange9dae462025-06-21 14:00:29 +08001023 else if(strStartsWith(s, "+EEMLTEINTRA:")) // LTE Í¬ÆµÐ¡Çø
1024 {
1025 // phyCellId,euArfcn,rsrp,rsrq
1026 if(cell_info.running) {
1027 int tmp_int;
1028 char* tmp_s = memdup(s,strlen(s));
1029 char* free_ptr = tmp_s;
1030 char *line = tmp_s;
1031 if (at_tok_start(&line) < 0)
1032 {
1033 goto EEMLTEINTRA_EXIT;
1034 }
1035 if (at_tok_nextint(&line, &tmp_int) < 0) //index
1036 {
1037 goto EEMLTEINTRA_EXIT;
1038 }
1039 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1040 {
1041 goto EEMLTEINTRA_EXIT;
1042 }
1043 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //phycellid
1044 if (at_tok_nextint(&line, &tmp_int) < 0)
1045 {
1046 goto EEMLTEINTRA_EXIT;
1047 }
1048 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //arfcn
1049 if (at_tok_nextint(&line, &tmp_int) < 0)
1050 {
1051 goto EEMLTEINTRA_EXIT;
1052 }
1053 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //rsrp
1054 LOG("cell line : %s", line);
1055 if (at_tok_nextint(&line, &tmp_int) < 0)
1056 {
1057 goto EEMLTEINTRA_EXIT;
1058 }
1059 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //rsrq
1060
1061 cell_info.cell[cell_info.cell_num].value7 =0x7FFFFFFF;//mnc
1062
1063 cell_info.cell_num++;
1064EEMLTEINTRA_EXIT:
1065 free(free_ptr);
1066 }
1067 }
1068 // Do nothing
1069 else if(strStartsWith(s, "+EEMLTEINTER:")) // LTE ÒìÆµ/Ð¡Çø
liubin281ac462023-07-19 14:22:54 +08001070 {
1071 // phyCellId,euArfcn,rsrp,rsrq
1072 if(cell_info.running) {
1073 int tmp_int;
1074 char* tmp_s = memdup(s,strlen(s));
1075 char* free_ptr = tmp_s;
1076 char *line = tmp_s;
1077 if (at_tok_start(&line) < 0)
1078 {
1079 goto EEMLTEINTER_EXIT;
1080 }
q.huange9dae462025-06-21 14:00:29 +08001081 if (at_tok_nextint(&line, &tmp_int) < 0) //index
liubin281ac462023-07-19 14:22:54 +08001082 {
1083 goto EEMLTEINTER_EXIT;
1084 }
1085 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1086 {
1087 goto EEMLTEINTER_EXIT;
1088 }
q.huange9dae462025-06-21 14:00:29 +08001089 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //phy cell id
liubin281ac462023-07-19 14:22:54 +08001090 if (at_tok_nextint(&line, &tmp_int) < 0)
1091 {
1092 goto EEMLTEINTER_EXIT;
1093 }
q.huange9dae462025-06-21 14:00:29 +08001094 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //arfcn
liubin281ac462023-07-19 14:22:54 +08001095 if (at_tok_nextint(&line, &tmp_int) < 0)
1096 {
1097 goto EEMLTEINTER_EXIT;
1098 }
q.huange9dae462025-06-21 14:00:29 +08001099 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //rsrp
liubin281ac462023-07-19 14:22:54 +08001100 LOG("cell line : %s", line);
1101 if (at_tok_nextint(&line, &tmp_int) < 0)
1102 {
1103 goto EEMLTEINTER_EXIT;
1104 }
q.huange9dae462025-06-21 14:00:29 +08001105 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //rsrq
liubin281ac462023-07-19 14:22:54 +08001106 if (at_tok_nextint(&line, &tmp_int) < 0)
1107 {
1108 LOG("cell tmp_int : %d", tmp_int);
1109 goto EEMLTEINTER_EXIT;
1110 }
q.huange9dae462025-06-21 14:00:29 +08001111 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //cellid
liubin281ac462023-07-19 14:22:54 +08001112 LOG("cell value5 : %d", cell_info.cell[cell_info.cell_num].value5);
b.liuaec91492025-05-24 10:52:26 +08001113
1114 LOG("after cellid cell line : %s", line);
1115 if (at_tok_nextint(&line, &tmp_int) < 0)
1116 {
1117 goto EEMLTEINTER_EXIT;
1118 }
1119 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
1120
q.huange9dae462025-06-21 14:00:29 +08001121 if (at_tok_nextint(&line, &tmp_int) < 0) //length of mnc
b.liuaec91492025-05-24 10:52:26 +08001122 {
1123 LOG("exit");
1124 goto EEMLTEINTER_EXIT;
q.huange9dae462025-06-21 14:00:29 +08001125 }
b.liuaec91492025-05-24 10:52:26 +08001126
1127 if (at_tok_nextint(&line, &tmp_int) < 0)
1128 {
1129 LOG("exit");
1130 goto EEMLTEINTER_EXIT;
1131 }
1132
1133 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
1134
q.huange9dae462025-06-21 14:00:29 +08001135 if (at_tok_nextint(&line, &tmp_int) < 0)
b.liuaec91492025-05-24 10:52:26 +08001136 {
1137 LOG("exit");
1138 goto EEMLTEINTER_EXIT;
q.huange9dae462025-06-21 14:00:29 +08001139 }
1140 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //tac
1141 LOG("cell value8 : %u", (uint32)cell_info.cell[cell_info.cell_num].value8);
b.liuaec91492025-05-24 10:52:26 +08001142
b.liuaec91492025-05-24 10:52:26 +08001143
q.huange9dae462025-06-21 14:00:29 +08001144 for(int i =0; i < 8; i++)
b.liuaec91492025-05-24 10:52:26 +08001145 {
q.huange9dae462025-06-21 14:00:29 +08001146 if (at_tok_nextint(&line, &tmp_int) < 0) //1 cell id 2 rslevel
1147 // 3 thresh low 4 thresh_high 5 cell_priority 6 refSignalPower 7 bandwidth 8 band
b.liuaec91492025-05-24 10:52:26 +08001148 {
1149 LOG("exit i = %d",i);
1150 goto EEMLTEINTER_EXIT;
1151 }
1152 }
1153
1154 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //band
1155 LOG("cell value9 : %d", cell_info.cell[cell_info.cell_num].value9);
1156 if (at_tok_nextint(&line, &tmp_int) < 0)
1157 {
1158 LOG("exit");
1159 goto EEMLTEINTER_EXIT;
1160 }
1161
1162 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //rssi
1163
liubin281ac462023-07-19 14:22:54 +08001164 cell_info.cell_num++;
1165EEMLTEINTER_EXIT:
1166 free(free_ptr);
1167 }
1168 }
1169 // Do nothing
1170 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
1171 {
1172 if(cell_info.running) {
1173
1174 }
1175 }
1176 // WCDMA
1177 /*
1178 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1179
1180 // if sCMeasPresent == 1
1181 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1182 // endif
1183
1184 // if sCParamPresent == 1
1185 // rac, nom, mcc, mnc_len, mnc, lac, ci,
1186 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1187 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1188 // endif
1189
1190 // if ueOpStatusPresent == 1
1191 // rrcState, numLinks, srncId, sRnti,
1192 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1193 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1194 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1195 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1196 // endif
1197 //
1198 +EEMUMTSSVC: 3, 1, 1, 1,
1199 -80, 27, -6, -18, -115, -32768,
1200 1, 1, 1120, 2, 1, 61697, 168432821,
1201 15, 24, 10763, 0, 0, 0, 0,
1202 128, 128, 65535, 0, 0,
1203 2, 255, 65535, 4294967295,
1204 0, 0, 0, 0, 0, 0,
1205 0, 0, 0, 0, 0, 0, 1, 1,
1206 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1207 0, 0, 0, 0, 0, 0
1208 */
1209 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1210 {
1211 // lac, ci, arfcn
1212 if(cell_info.running) {
1213 int tmp_int;
1214 int i = 0;
1215 char* tmp_s = memdup(s,strlen(s));
1216 char* free_ptr = tmp_s;
1217 char *line = tmp_s;
1218 if (at_tok_start(&line) < 0)
1219 {
1220 goto EEMUMTSSVC_EXIT;
1221 }
1222 // Jump 12 integer.
1223 i = 0;
1224 while(i < 12) {
1225 if (at_tok_nextint(&line, &tmp_int) < 0)
1226 {
1227 goto EEMUMTSSVC_EXIT;
1228 }
1229 i++;
1230 }
1231 // mcc
1232 if (at_tok_nextint(&line, &tmp_int) < 0)
1233 {
1234 goto EEMUMTSSVC_EXIT;
1235 }
1236 cell_info.cell[cell_info.cell_num].value4= (uint32)tmp_int;
1237 // mnc
1238 if (at_tok_nextint(&line, &tmp_int) < 0)
1239 {
1240 goto EEMUMTSSVC_EXIT;
1241 }
1242 cell_info.cell[cell_info.cell_num].value5= (uint32)tmp_int;
1243 // lac
1244 if (at_tok_nextint(&line, &tmp_int) < 0)
1245 {
1246 goto EEMUMTSSVC_EXIT;
1247 }
1248 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1249 // ci
1250 if (at_tok_nextint(&line, &tmp_int) < 0)
1251 {
1252 goto EEMUMTSSVC_EXIT;
1253 }
1254 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1255
1256 if (at_tok_nextint(&line, &tmp_int) < 0)
1257 {
1258 goto EEMUMTSSVC_EXIT;
1259 }
1260 // cpi
1261 if (at_tok_nextint(&line, &tmp_int) < 0)
1262 {
1263 goto EEMUMTSSVC_EXIT;
1264 }
1265 cell_info.cell[cell_info.cell_num].value6= (uint32)tmp_int;
1266 /*
1267 // Jump 2 integer.
1268 i = 0;
1269 while(i < 2) {
1270 if (at_tok_nextint(&line, &tmp_int) < 0)
1271 {
1272 goto EEMUMTSSVC_EXIT;
1273 }
1274 i++;
1275 }
1276 */
1277 // arfcn
1278 if (at_tok_nextint(&line, &tmp_int) < 0)
1279 {
1280 goto EEMUMTSSVC_EXIT;
1281 }
1282 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1283
1284 cell_info.cell_num++;
1285EEMUMTSSVC_EXIT:
1286 free(free_ptr);
1287 }
1288 }
1289 /*
1290 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1291 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1292 */
1293 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1294 {
1295 // lac, ci, arfcn
1296 if(cell_info.running) {
1297 int tmp_int;
1298 int i = 0;
1299 char* tmp_s = memdup(s,strlen(s));
1300 char* free_ptr = tmp_s;
1301 char *line = tmp_s;
1302 if (at_tok_start(&line) < 0)
1303 {
1304 goto EEMUMTSINTRA_EXIT;
1305 }
1306 // Jump 8 integer.
1307 i = 0;
1308 while(i < 8) {
1309 if (at_tok_nextint(&line, &tmp_int) < 0)
1310 {
1311 goto EEMUMTSINTRA_EXIT;
1312 }
1313 i++;
1314 }
1315
1316 // lac
1317 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1318 {
1319 goto EEMUMTSINTRA_EXIT;
1320 }
1321 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1322
1323 // ci
1324 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1325 {
1326 goto EEMUMTSINTRA_EXIT;
1327 }
1328 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1329
1330 // arfcn
1331 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1332 {
1333 goto EEMUMTSINTRA_EXIT;
1334 }
1335 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1336
1337 cell_info.cell_num++;
1338EEMUMTSINTRA_EXIT:
1339 free(free_ptr);
1340 }
1341 }
1342 /*
1343 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1344 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1345 */
1346 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1347 {
1348 // lac, ci, arfcn
1349 if(cell_info.running) {
1350 int tmp_int;
1351 int i = 0;
1352 char* tmp_s = memdup(s,strlen(s));
1353 char* free_ptr = tmp_s;
1354 char *line = tmp_s;
1355 if (at_tok_start(&line) < 0)
1356 {
1357 goto EEMUMTSINTERRAT_EXIT;
1358 }
1359 // Jump 7 integer.
1360 i = 0;
1361 while(i < 7) {
1362 if (at_tok_nextint(&line, &tmp_int) < 0)
1363 {
1364 goto EEMUMTSINTERRAT_EXIT;
1365 }
1366 i++;
1367 }
1368
1369 // lac
1370 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1371 {
1372 goto EEMUMTSINTERRAT_EXIT;
1373 }
1374 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1375
1376 // ci
1377 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1378 {
1379 goto EEMUMTSINTERRAT_EXIT;
1380 }
1381 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1382
1383 // arfcn
1384 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1385 {
1386 goto EEMUMTSINTERRAT_EXIT;
1387 }
1388 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1389
1390 cell_info.cell_num++;
1391EEMUMTSINTERRAT_EXIT:
1392 free(free_ptr);
1393 }
1394 }
1395 // GSM
1396 // +EEMGINFOBASIC: 2
1397 // Do nothing.
1398 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1399 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1400 {
1401 if(cell_info.running) {
1402
1403 }
1404 }
1405 /*
1406 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1407 // bsic, C1, C2, TA, TxPwr,
1408 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1409 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1410 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1411 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1412 // gsmBand,channelMode
1413 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1414 63, 36, 146, 1, 7,
1415 46, 42, 42, 7, 0,
1416 53, 0, 8, 0, 1, 6, 53,
1417 2, 0, 146, 42, 54, 0, 1,
1418 1, 32, 0, 0, 0, 0,
1419 0, 0
1420 */
1421 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1422 {
1423 // lac, ci, arfcn, bsic
1424 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1425 if(cell_info.running) {
1426 int tmp_int;
1427 int i = 0;
1428 char* tmp_s = memdup(s,strlen(s));
1429 char* free_ptr = tmp_s;
1430 char *line = tmp_s;
1431 if (at_tok_start(&line) < 0)
1432 {
1433 goto EEMGINFOSVC_EXIT;
1434 }
1435
1436 // mcc
1437 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1438 {
1439 goto EEMGINFOSVC_EXIT;
1440 }
1441 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1442
1443 //mnc_len
1444 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1445 {
1446 goto EEMGINFOSVC_EXIT;
1447 }
1448 // mnc
1449 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1450 {
1451 goto EEMGINFOSVC_EXIT;
1452 }
1453 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1454
1455 /*
1456 // Jump 3 integer.
1457 i = 0;
1458 while(i < 3) {
1459 if (at_tok_nextint(&line, &tmp_int) < 0)
1460 {
1461 goto EEMGINFOSVC_EXIT;
1462 }
1463 i++;
1464 }
1465 */
1466 // lac
1467 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1468 {
1469 goto EEMGINFOSVC_EXIT;
1470 }
1471 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1472
1473 // ci
1474 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1475 {
1476 goto EEMGINFOSVC_EXIT;
1477 }
1478 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1479
1480 // Jump 2 integer.
1481 i = 0;
1482 while(i < 2) {
1483 if (at_tok_nextint(&line, &tmp_int) < 0)
1484 {
1485 goto EEMGINFOSVC_EXIT;
1486 }
1487 i++;
1488 }
1489
1490 // bsic
1491 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1492 {
1493 goto EEMGINFOSVC_EXIT;
1494 }
1495 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1496
1497 // Jump 15 integer.
1498 i = 0;
1499 while(i < 15) {
1500 if (at_tok_nextint(&line, &tmp_int) < 0)
1501 {
1502 goto EEMGINFOSVC_EXIT;
1503 }
1504 i++;
1505 }
1506
1507 // arfcn
1508 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1509 {
1510 goto EEMGINFOSVC_EXIT;
1511 }
1512 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1513
1514 cell_info.cell_num++;
1515EEMGINFOSVC_EXIT:
1516 free(free_ptr);
1517 }
1518 }
1519 /*
1520 // PS_attached, attach_type, service_type, tx_power, c_value,
1521 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1522 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1523 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1524 +EEMGINFOPS: 1, 255, 0, 0, 0,
1525 0, 0, 268435501, 1, 0, 0,
1526 4, 0, 96, 0, 0, 0,
1527 0, 0, 0, 65535, 0, 13350
1528 */
1529 // Do nothing.
1530 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1531 {
1532 if(cell_info.running) {
1533
1534 }
1535 }
1536 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1537 {
1538 if(cell_info.running) {
1539 int tmp_int;
1540 int i = 0;
1541 char* tmp_s = memdup(s,strlen(s));
1542 char* free_ptr = tmp_s;
1543 char *line = tmp_s;
1544 if (at_tok_start(&line) < 0)
1545 {
1546 goto EEMGINFOPS_EXIT;
1547 }
1548
1549 // nc_num
1550 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1551 {
1552 LOG("cell_info.running 1= %d\n.",cell_info.running);
1553 goto EEMGINFOPS_EXIT;
1554 }
1555 // mcc
1556 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1557 {
1558 LOG("cell_info.running 2= %d\n.",cell_info.running);
1559 goto EEMGINFOPS_EXIT;
1560 }
1561 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1562
1563 // mnc
1564 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1565 {
1566 LOG("cell_info.running 3= %d\n.",cell_info.running);
1567 goto EEMGINFOPS_EXIT;
1568 }
1569 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1570
1571 // lac
1572 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1573 {
1574 LOG("cell_info.running 4= %d\n.",cell_info.running);
1575 goto EEMGINFOPS_EXIT;
1576 }
1577 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1578
1579 // rac
1580 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1581 {
1582 LOG("cell_info.running 5= %d\n.",cell_info.running);
1583 goto EEMGINFOPS_EXIT;
1584 }
1585
1586 // ci
1587 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1588 {
1589 LOG("cell_info.running 6= %d\n.",cell_info.running);
1590 goto EEMGINFOPS_EXIT;
1591 }
1592 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1593
1594 // rx_lv
1595 if (at_tok_nextint(&line, &tmp_int) < 0)
1596 {
1597 LOG("cell_info.running 7= %d\n.",cell_info.running);
1598 goto EEMGINFOPS_EXIT;
1599 }
1600
1601 // bsic
1602 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1603 {
1604 LOG("cell_info.running 8= %d\n.",cell_info.running);
1605 goto EEMGINFOPS_EXIT;
1606 }
1607 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1608
1609 // Jump 2 integer.
1610 i = 0;
1611 while(i < 2) {
1612 if (at_tok_nextint(&line, &tmp_int) < 0)
1613 {
1614 LOG("cell_info.running 9= %d\n.",cell_info.running);
1615 goto EEMGINFOPS_EXIT;
1616 }
1617 i++;
1618 }
1619
1620 // arfcn
1621 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1622 {
1623 LOG("cell_info.running 10 = %d\n.",cell_info.running);
1624 goto EEMGINFOPS_EXIT;
1625 }
1626 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1627
1628 cell_info.cell_num++;
1629EEMGINFOPS_EXIT:
1630 free(free_ptr);
1631 }
1632 }
1633 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"
1634 {
1635
1636 }
1637 else
1638 {
1639 LOGV("Unknown URC : %s", s);
1640 }
1641}
1642
1643static int openSocket(const char* sockname)
1644{
1645 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
1646 if (sock < 0)
1647 {
1648 LOGE("Error create socket: %s\n", strerror(errno));
1649 return -1;
1650 }
1651 struct sockaddr_un addr;
1652 memset(&addr, 0, sizeof(addr));
1653 addr.sun_family = AF_UNIX;
1654 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
1655 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
1656 {
1657 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
1658 sleep(1);
1659 }
1660
1661#if 0
1662 int sk_flags = fcntl(sock, F_GETFL, 0);
1663 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
1664#endif
1665
1666 return sock;
1667}
1668
b.liu9e8584b2024-11-06 19:21:28 +08001669#if 0
liubin281ac462023-07-19 14:22:54 +08001670static void ril_get_cgpaddr_ip_process()
1671{
1672 int err, skip;
1673 ATResponse *p_response = NULL;
1674 char *line;
1675 char *ipv4 = NULL, *ipv6 = NULL;
1676 err = at_send_command_singleline("AT+CGPADDR", "+CGPADDR:", &p_response);
1677 if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
1678 {
1679 LOGE("+CGPADDR exec error.");
1680 goto error;
1681 }
1682
1683 // +CGPADDR: 1, "10.51.59.229", "254.128.0.0.0.0.0.0.0.1.0.0.111.176.63.99"
1684 // +CGPADDR: 1, "10.124.139.131"
1685 line = p_response->p_intermediates->line;
1686 err = at_tok_start(&line);
1687 if (err < 0)
1688 {
1689 goto error;
1690 }
1691
1692 err = at_tok_nextint(&line, &skip);
1693 if (err < 0)
1694 {
1695 goto error;
1696 }
1697
1698 if (!at_tok_hasmore(&line))
1699 {
1700 goto error;
1701 }
1702
1703 err = at_tok_nextstr(&line, &ipv4);
1704 if (err < 0)
1705 {
1706 LOGE("Get IPv4 fail.");
1707 goto error;
1708 }
1709
1710 if (at_tok_hasmore(&line))
1711 {
1712 err = at_tok_nextstr(&line, &ipv6);
1713 if (err < 0)
1714 {
1715 LOGE("Get IPv6 fail.");
1716 goto error;
1717 }
1718 }
1719 else
1720 {
1721 LOGD("No IPv6 Found.");
1722 }
1723
1724 if(ipv6)
1725 {
1726 LOGD("IPv6 : %s", ipv6);
1727 }
1728
1729 if(ipv4)
1730 {
1731 LOGD("IPv4 : %s", ipv4);
1732
1733// ril_net_dev_config("ccinet0", ipv4, NULL);
1734 }
1735error:
1736 at_response_free(p_response);
1737}
b.liu9e8584b2024-11-06 19:21:28 +08001738#endif
liubin281ac462023-07-19 14:22:54 +08001739
1740static void sim_state_change(bool plug_in) {
1741 if(plug_in) {
1742 // If radio on,must off in the first.
1743 if(net_info.radio_state == MBTK_RADIO_STATE_ON) {
1744 setRadioPower(0);
1745 }
1746 setRadioPower(1);
1747 } else {
1748 setRadioPower(0);
1749 }
1750}
1751
1752static int open_uevent_socket()
1753{
1754 struct sockaddr_nl addr;
1755 int sz = 64*1024;
1756 int s = 0;
1757
1758 memset(&addr, 0, sizeof(addr));
1759 addr.nl_family = AF_NETLINK;
1760 addr.nl_pid = getpid();
1761 addr.nl_groups = 0xffffffff;
1762
1763 s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
1764 if (s < 0)
1765 {
1766 LOGE("socket() fail.[%d]", errno);
1767 return -1;
1768 }
1769
1770 setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz));
1771
1772 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0)
1773 {
1774 close(s);
1775 return -1;
1776 }
1777
1778 return s;
1779}
1780
1781static void parse_uevent(const char *msg, int msg_len, struct cooling_device *cdev)
1782{
1783 // change@/devices/virtual/usim_event/usim0\0
1784 // ACTION=change\0
1785 // DEVPATH=/devices/virtual/usim_event/usim0\0
1786 // SUBSYSTEM=usim_event\0
1787 // USIM_NAME=usim0\0
1788 // USIM_EVENT=plugout\0
1789 // SEQNUM=704
1790 int i = 0;
1791 while (i < msg_len)
1792 {
1793 if(*(msg + i) == '\0')
1794 {
1795 i++;
1796 continue;
1797 }
1798 if (!strncmp(msg + i, "USIM_NAME=", 10))
1799 {
1800 i += 10;
1801 cdev->name = msg + i;
1802 i += strlen(msg + i);
1803 }
1804 else if (!strncmp(msg + i, "ACTION=", 7))
1805 {
1806 i += 7;
1807 cdev->action = msg + i;
1808 i += strlen(msg + i);
1809 }
1810 else if (!strncmp(msg + i, "DEVPATH=", 8))
1811 {
1812 i += 8;
1813 cdev->path = msg + i;
1814 i += strlen(msg + i);
1815 }
1816 else if (!strncmp(msg + i, "USIM_EVENT=", 11))
1817 {
1818 i += 11;
1819 cdev->event = msg + i;
1820 i += strlen(msg + i);
1821 }
1822 else if (!strncmp(msg + i, "SUBSYSTEM=", 10))
1823 {
1824 i += 10;
1825 cdev->subsystem = msg + i;
1826 i += strlen(msg + i);
1827 }
1828 else
1829 {
1830 i++;
1831 }
1832 }
1833
1834 if(!strncmp(cdev->path, UEVENT_USIM_DEV, sizeof(UEVENT_USIM_DEV))
1835 && !strncmp(cdev->action, "change", 5))
1836 {
1837 LOGD("event { name=%s, action=%s, path=%s, subsystem=%s, event=%s}",
1838 cdev->name, cdev->action, cdev->path, cdev->subsystem, cdev->event);
1839 if(!strcmp(cdev->event, "plugout"))
1840 {
1841 sim_state_change(FALSE);
1842 }
1843 else if(!strcmp(cdev->event, "plugin"))
1844 {
1845 sim_state_change(TRUE);
1846 }
1847 else
1848 {
1849 LOGE("usim evnet error!");
1850 }
1851 }
1852}
1853
1854static void* uevnet_run(void *payload)
1855{
1856 int socket_fd = -1;
1857 char msg[BUFFER_SIZE+2];
1858 int n;
1859
1860 socket_fd = open_uevent_socket();
1861 if(socket_fd > 0)
1862 {
1863 while(1)
1864 {
1865 if((n = recv(socket_fd, msg, BUFFER_SIZE, 0)) > 0)
1866 {
1867 struct cooling_device cdev;
1868 memset(&cdev, 0x0, sizeof(cdev));
1869
1870 if(n == BUFFER_SIZE)
1871 continue;
1872 msg[n] = '\0';
1873 // 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
1874 log_hex("UEVENT", msg, n);
1875 parse_uevent(msg, n, &cdev);
1876 }
1877 else
1878 {
1879 LOGE("recv msg error.");
1880 }
1881 }
1882 }
1883
1884 LOGD("UEVENT Thread exit!!!");
1885 return NULL;
1886}
1887
1888int uevent_main()
1889{
1890 mbtk_task_info task;
1891 task.task_id = &uevnet_task_id;
1892 task.thread_run = uevnet_run;
1893 task.args = NULL;
1894 return mbtk_task_start(&task);
1895}
1896
1897/*
1898int ril_main()
1899{
1900 return mbtk_task_queue_start(&ril_task, ril_main_run);
1901}
1902*/
1903
1904int mbtk_info_server_start();
1905int InProduction_Mode(void);
1906void server_ready_set(void);
1907
b.liu9e8584b2024-11-06 19:21:28 +08001908#if 0
liubin281ac462023-07-19 14:22:54 +08001909
1910/*
1911 *Get mtdblock which name is ASR_FLAG
1912 *return path if found, else return NULL
1913 */
1914static int asrFlagPathGet(char *asr_flag_path)
1915{
1916 char buf[128];
1917 unsigned char find = 0;
1918 FILE *fd = fopen("/proc/mtd", "r");
1919 if (fd == NULL) {
1920 LOGE("Open MTD failed!");
1921 return -1;
1922 }
1923
1924 memset(buf, '\0', 128);
1925 while (fgets(buf, 128, fd) != NULL) {
1926 if(strstr(buf, "asr_flag")) {
1927 char *p = strstr(buf, "mtd");
1928 if(p)
1929 {
1930 int bln;
1931 sscanf(p, "mtd%d", &bln);
1932 sprintf(asr_flag_path, "/dev/mtdblock%d", bln);
1933 find = 1;
1934 break;
1935 }
1936 }
1937 memset(buf, '\0', 128);
1938 }
1939
1940 fclose(fd);
1941 return ((find == 1) ? 0 : -1);
1942}
b.liu9e8584b2024-11-06 19:21:28 +08001943
liubin281ac462023-07-19 14:22:54 +08001944static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)
1945{
1946 int ret, fd;
1947 if (!path)
1948 return -1;
1949
1950 fd = open(path, O_RDONLY);
1951 if (fd < 0) {
1952 LOGE("readFromMTD open error,%d", errno);
1953 return -1;
1954 }
1955
1956 ret = lseek(fd, offset, SEEK_SET);
1957 if (ret < 0) {
1958 close(fd);
1959 LOGE("readFromMTD lseek error,%d", errno);
1960 return -1;
1961 }
1962 ret = read(fd, buf, size);
1963 if (ret < 0) {
1964 close(fd);
1965 LOGE("readFromMTD read error,%d", errno);
1966 return -1;
1967 }
1968 close(fd);
1969 return 0;
1970}
1971
1972static int writeToMTD(const char *path, unsigned int offset, void *buf, int size)
1973{
1974 int ret, fd;
1975
1976 if (!path)
1977 return -1;
1978
1979 fd = open(path, O_RDWR | O_SYNC);
1980 if (fd < 0)
1981 return -1;
1982
1983 ret = lseek(fd, offset, SEEK_SET);
1984 if (ret < 0) {
1985 close(fd);
1986 return -1;
1987 }
1988 ret = write(fd, buf, size);
1989 if (ret < 0) {
1990 LOGE("writetomtd:write error:%d", errno);
1991 close(fd);
1992 return -1;
1993 }
1994
1995 close(fd);
1996 return 0;
1997}
b.liu9e8584b2024-11-06 19:21:28 +08001998#endif
liubin281ac462023-07-19 14:22:54 +08001999static void fota_result_check()
2000{
2001#if 0
2002 ASR_flag tag;
2003 char asr_flag_path[30] = {0};
2004 if(asrFlagPathGet(asr_flag_path)) {
2005 LOGE("getAsrFlagPath() fail.");
2006 return;
2007 }
2008
2009 if(readFromMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
2010 {
2011 LOGE("Get FOTA result fail.");
2012 }
2013 else
2014 {
2015 LOGD("FOTA result : %d, %d", tag.fota_result[0], tag.fota_result[1]);
2016 tag.fota_result[0] = 0;
2017 tag.fota_result[1] = 0;
2018 if(writeToMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
2019 {
2020 LOGE("FOTA result update fail.");
2021 } else {
2022 LOGD("FOTA result update success.");
2023 }
2024 }
2025#endif
2026}
2027
b.liubb590492024-06-13 16:42:08 +08002028static void mbtk_ril_ready()
liubin281ac462023-07-19 14:22:54 +08002029{
2030 // /etc/init.d/mbtk_boot_server_ready
b.liubb590492024-06-13 16:42:08 +08002031 if(is_first_boot) {
2032 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
2033 LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
b.liu9e8584b2024-11-06 19:21:28 +08002034 mbtk_system(MBTK_BOOT_SERVER_READY);
b.liubb590492024-06-13 16:42:08 +08002035 } else {
2036 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
2037 }
liubin281ac462023-07-19 14:22:54 +08002038 } else {
b.liubb590492024-06-13 16:42:08 +08002039 LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
liubin281ac462023-07-19 14:22:54 +08002040 }
2041}
2042
2043#if 1
2044int main(int argc, char *argv[])
2045{
2046 mbtk_log_init("radio", "MBTK_RIL");
b.liubb590492024-06-13 16:42:08 +08002047
b.liubcf86c92024-08-19 19:48:28 +08002048 MBTK_SOURCE_INFO_PRINT("mbtk_rild");
2049
b.liubb590492024-06-13 16:42:08 +08002050#ifdef MBTK_DUMP_SUPPORT
2051 mbtk_debug_open(NULL, TRUE);
2052#endif
2053
2054// Using Killall,the file lock may be not release.
2055#if 0
2056 if(app_already_running(MBTK_RILD_PID_FILE)) {
2057 LOGW("daemon already running.");
2058 exit(1);
2059 }
2060#endif
2061
liubin281ac462023-07-19 14:22:54 +08002062 LOGI("mbtk_ril start.");
2063
b.liubb590492024-06-13 16:42:08 +08002064 int fd = open(MBTK_RILD_TEMP_FILE, O_CREAT | O_RDWR, 0644);
2065 if(fd > 0) {
b.liu9e8584b2024-11-06 19:21:28 +08002066 char buff[100] = {0};
b.liubb590492024-06-13 16:42:08 +08002067 int count = 0;
2068 if(read(fd, buff, sizeof(buff)) > 0) {
2069 count = atoi(buff);
2070 } else {
2071 count = 0;
2072 }
2073
2074 if(count <= 0) {
2075 is_first_boot = TRUE;
2076 count = 0;
2077 } else {
2078 is_first_boot = FALSE;
2079 }
2080
2081 count++;
2082 memset(buff, 0, sizeof(buff));
2083 snprintf(buff, sizeof(buff), "%d", count);
b.liu9e8584b2024-11-06 19:21:28 +08002084 mbtk_write(fd, buff, strlen(buff));
b.liubb590492024-06-13 16:42:08 +08002085 close(fd);
2086 } else {
2087 is_first_boot = FALSE;
2088 LOGE("Open %s fail:%d", MBTK_RILD_TEMP_FILE, errno);
2089 LOGW("Will not exec %s and %s.", MBTK_BOOT_SERVER_READY, MBTK_BOOT_NET_READY);
2090 }
2091
liubin281ac462023-07-19 14:22:54 +08002092 if(InProduction_Mode()) {
2093 LOGI("Is Production Mode, will exit...");
2094 exit(0);
2095 }
2096
2097 int at_sock = openSocket("/tmp/atcmd_at");
2098 if(at_sock < 0)
2099 {
2100 LOGE("Open AT Socket Fail[%d].", errno);
2101 return -1;
2102 }
2103 int uart_sock = openSocket("/tmp/atcmd_urc");
2104 if(uart_sock < 0)
2105 {
2106 LOGE("Open Uart Socket Fail[%d].", errno);
2107 return -1;
2108 }
2109
2110 at_set_on_reader_closed(onATReaderClosed);
2111 at_set_on_timeout(onATTimeout);
2112
2113 if(at_open(at_sock, uart_sock, onUnsolicited))
2114 {
2115 LOGE("Start AT thread fail.");
2116 return -1;
2117 }
2118
2119#if 1
2120 if(at_handshake())
2121 {
2122 LOGE("AT handshake fail.");
2123 return -1;
2124 }
2125#endif
2126
2127 LOGD("AT OK.");
2128
2129 if(mbtk_info_server_start())
2130 {
2131 LOGE("mbtk_info_server_start() fail.");
2132 return -1;
2133 }
b.liubb590492024-06-13 16:42:08 +08002134
liuyang15f493d2024-09-12 17:45:41 +08002135 char led_enable_str[10];
2136 memset(led_enable_str, 0, 10);
2137 property_get("persist.mbtk.led_enable", led_enable_str, "1");
2138 if(atoi(led_enable_str) == 1) { // NTP time
2139 LOG("Start LED thread.");
2140 mbtk_led_init();
2141 }
liubin281ac462023-07-19 14:22:54 +08002142
2143#if 0
2144 if(uevent_main())
2145 {
2146 LOGE("Start uevent thread fail.");
2147 return -1;
2148 }
2149#endif
2150
2151 char time_type[10];
2152 memset(time_type, 0, 10);
2153 property_get("persist.mbtk.time_type", time_type, "0");
2154 if(atoi(time_type) == MBTK_TIME_TYPE_NTP) { // NTP time
2155 LOG("Start NTP thread.");
2156 ntp_thread_start();
2157 }
2158
2159 fota_result_check();
2160
b.liubb590492024-06-13 16:42:08 +08002161 mbtk_ril_ready();
liubin281ac462023-07-19 14:22:54 +08002162
2163 server_ready_set();//Set the server readiness state
2164 while(1)
2165 {
2166 sleep(24 * 60 * 60);
2167 }
2168
2169 LOGD("!!!mbtk_ril exit!!!");
2170 return 0;
2171}
2172
2173#else
2174int main()
2175{
2176 char buff[BUFFER_SIZE + 1] = {0};
2177 if(!mbtk_at("AT+CFUN=1", buff, BUFFER_SIZE))
2178 {
2179 LOGD("+CFUN RSP:%s", buff);
2180 while(1)
2181 {
2182 sleep(1);
2183 memset(buff, 0x0, BUFFER_SIZE + 1);
2184 if(!mbtk_at("AT+CGPADDR", buff, BUFFER_SIZE))
2185 {
2186 LOGD("+CGPADDR RSP:%s", buff);
2187 if(strstr(buff, "+CGPADDR:"))
2188 {
2189 // +CGPADDR: 1, "10.99.223.168", "254.128.0.0.0.0.0.0.0.1.0.0.117.9.250.59"
2190 //
2191 // OK
2192 char *ip_start = NULL;
2193 char *ip_end = NULL;
2194 char ipv4[50] = {0};
2195 ip_start = strstr(buff,"\"");
2196 if(ip_start)
2197 ip_end = strstr(ip_start + 1, "\"");
2198 if(ip_start && ip_end && ip_end - ip_start - 1 > 0)
2199 {
2200 memcpy(ipv4, ip_start + 1, ip_end - ip_start - 1);
2201 LOGD("IP : %s", ipv4);
2202 if(!mbtk_ifc_open())
2203 {
2204 in_addr_t addr;
2205 inet_aton(ipv4,(struct in_addr *)&addr);
2206 LOGD("IP : %s -> %x", ipv4, addr);
2207 if(!mbtk_ifc_set_addr("ccinet0", addr, 0))
2208 {
2209 mbtk_ifc_up("ccinet0");
2210 }
2211
2212 mbtk_ifc_close();
2213 }
2214
2215 system("route add default dev ccinet0");
2216
2217 LOGD("Set IP success.");
2218 }
2219 else
2220 {
2221 LOGD("Get IP fail.");
2222 }
2223
2224 break;
2225 }
2226 }
2227 }
2228 }
2229
2230 return 0;
2231}
2232#endif