blob: f66830d68b6e0fb1847ca40185520f6d98962688 [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{
q.huanga0261872025-08-01 19:44:59 +0800174 LOGI("URC : %s", s); //LYNQ_ASR_BUG2001_Q.HUANG_20250731_change_level_from_v_2_info
liubin281ac462023-07-19 14:22:54 +0800175 // 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;
q.huanga0261872025-08-01 19:44:59 +0800248
249 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) // +CGEV: NW PDN DEACT 1
250 {
251 pdp_cb_info.cid = atoi(s + 20);
252 pdp_cb_info.auto_urc=true;
253 pdp_cb_info.connect_state = false;
254 urc_msg_distribute(true, INFO_URC_MSG_CGEV, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
255 }
256 else if(cgact_wait.act)
yq.wangf98110c2025-06-11 14:50:04 +0800257 {
258 if(strStartsWith(s, "+CGEV: ME PDN ACT ")) // +CGEV: ME PDN ACT 15,4
259 {
260 if(cgact_wait.cid == atoi(s + 18))
261 {
liubin281ac462023-07-19 14:22:54 +0800262 cgact_wait.waitting = false;
263 }
264
yq.wangf98110c2025-06-11 14:50:04 +0800265 pdp_cb_info.cid = atoi(s + 18);
266 pdp_cb_info.connect_state = true;
267#if 0
liubin281ac462023-07-19 14:22:54 +0800268 char* tmp_s = memdup(s + 18,strlen(s + 18));
269 char* free_ptr = tmp_s;
270 char *line = tmp_s;
271 int tmp_int;
272 if (at_tok_start(&line) < 0)
273 {
274 goto at_PDP_CREG_EXIT;
275 }
276 if (at_tok_nextint(&line, &tmp_int) < 0)
277 {
278 goto at_PDP_CREG_EXIT;
279 }
280 if (at_tok_nextint(&line, &tmp_int) < 0)
281 {
282 goto at_PDP_CREG_EXIT;
283 }
yq.wangf98110c2025-06-11 14:50:04 +0800284 pdp_cb_info.pdp_result = tmp_int;
liubin281ac462023-07-19 14:22:54 +0800285at_PDP_CREG_EXIT:
286 free(free_ptr);
yq.wangf98110c2025-06-11 14:50:04 +0800287 free_ptr = NULL;
liubin281ac462023-07-19 14:22:54 +0800288 //data_pdp = (uint8)atoi(s + 20); //reason
289 if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
290 {
291 if(data_pdp == 0)
292 {
293 data_pdp = 25;
294 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
295 //data_pdp = cgact_wait.cid + 200;
296 }
297 else if(data_pdp == 1)
298 {
299 data_pdp = 26;
300 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
301 }
302 else if(data_pdp == 2)
303 {
304 data_pdp = 27;
305 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
306 }
307 else if(data_pdp == 3)
308 {
309 data_pdp = 27;
310 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
311 }
312 else
313 {
314
315 }
316 if(cgact_wait.cid != 0)
317 {
318 data_pdp = cgact_wait.cid + 200;
b.liuf77b86c2024-11-09 13:24:10 +0800319 urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
liubin281ac462023-07-19 14:22:54 +0800320 }
321 }
yq.wangf98110c2025-06-11 14:50:04 +0800322#endif
323 urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
liubin281ac462023-07-19 14:22:54 +0800324 }
yq.wangf98110c2025-06-11 14:50:04 +0800325 else if(strStartsWith(s, "+CGEV: NW MODIFY ")) // +CGEV: NW MODIFY 1,4
326 {
327 if(cgact_wait.cid == atoi(s + 17))
328 {
liubin281ac462023-07-19 14:22:54 +0800329 cgact_wait.waitting = false;
330 }
yq.wangf98110c2025-06-11 14:50:04 +0800331
332 pdp_cb_info.cid = atoi(s + 17);
333 pdp_cb_info.connect_state = true;
334 //urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
335 }
q.huanga0261872025-08-01 19:44:59 +0800336 else
337 {
338 LOGI("No process : %s in cgact ture process", s);
339 }
yq.wangf98110c2025-06-11 14:50:04 +0800340 }
q.huanga0261872025-08-01 19:44:59 +0800341 else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) // +CGEV: ME PDN DEACT 1
342 {
343 if(cgact_wait.cid == atoi(s + 20))
344 {
345 cgact_wait.waitting = false;
346 }
347
348 pdp_cb_info.cid = atoi(s + 20);
349 pdp_cb_info.connect_state = false;
350 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
351 }
yq.wangf98110c2025-06-11 14:50:04 +0800352 else
353 {
q.huanga0261872025-08-01 19:44:59 +0800354 LOGI("No process : %s in AT process", s);
liubin281ac462023-07-19 14:22:54 +0800355 }
yq.wangf98110c2025-06-11 14:50:04 +0800356 }
357 else
358 {
liubin281ac462023-07-19 14:22:54 +0800359 // +CGEV: NW PDN DEACT <cid>
liubin281ac462023-07-19 14:22:54 +0800360 // +CGEV: EPS PDN ACT 1
361 // +CGEV: ME PDN ACT 8,1
liubin281ac462023-07-19 14:22:54 +0800362 // +CGEV: ME PDN ACT 2,4
yq.wangf98110c2025-06-11 14:50:04 +0800363 mbtk_pdp_cb_info_s pdp_cb_info;
364 memset(&pdp_cb_info, 0x00, sizeof(mbtk_pdp_cb_info_s));
365 pdp_cb_info.auto_urc = true;
366 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) // +CGEV: NW PDN DEACT <cid>
367 {
368 pdp_cb_info.cid = (uint8)atoi(s + 20);
369 pdp_cb_info.connect_state = false;
370 urc_msg_distribute(true, INFO_URC_MSG_CGEV, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
371 }
372 else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) // +CGEV: EPS PDN ACT <cid>
373 {
374 pdp_cb_info.cid = (uint8)atoi(s + 19);
375 pdp_cb_info.connect_state = true;
376 }
377 else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) // +CGEV: EPS PDN DEACT <cid>
378 {
379 pdp_cb_info.cid = (uint8)atoi(s + 20);
380 pdp_cb_info.connect_state = false;
381 urc_msg_distribute(true, INFO_URC_MSG_CGEV, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
382 }
383 else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) // +CGEV: ME PDN ACT <cid>,1
384 {
385 pdp_cb_info.cid = (uint8)atoi(s + 18);
386 pdp_cb_info.connect_state = true;
387 //urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &pdp_cb_info, sizeof(mbtk_pdp_cb_info_s));
liubin281ac462023-07-19 14:22:54 +0800388
yq.wangf98110c2025-06-11 14:50:04 +0800389#if 0
liubin281ac462023-07-19 14:22:54 +0800390 char* tmp_s = memdup(s + 18,strlen(s + 18));
391 char* free_ptr = tmp_s;
392 char *line = tmp_s;
393 int tmp_int;
394 if (at_tok_start(&line) < 0)
395 {
396 goto PDP_CREG_EXIT;
397 }
398 if (at_tok_nextint(&line, &tmp_int) < 0)
399 {
400 goto PDP_CREG_EXIT;
401 }
402 if (at_tok_nextint(&line, &tmp_int) < 0)
403 {
404 goto PDP_CREG_EXIT;
405 }
406 data_pdp = tmp_int;
407PDP_CREG_EXIT:
408 free(free_ptr);
409 //data_pdp = (uint8)atoi(s + 20); //reason
410 if(data[1] >= 1 && data[1] < 8)
411 {
412 if(data_pdp == 0)
413 {
414 data_pdp = 25;
415 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
416 }
417 else if(data_pdp == 1)
418 {
419 data_pdp = 26;
420 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
421 }
422 else if(data_pdp == 2)
423 {
424 data_pdp = 27;
425 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
426 }
427 else if(data_pdp == 3)
428 {
429 data_pdp = 27;
430 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
431 }
432 else
433 {
434
435 }
wangyouqiang65884152023-10-25 19:54:15 +0800436 data_pdp = data[1] + 200;
b.liuf77b86c2024-11-09 13:24:10 +0800437 urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
wangyouqiang3947b302024-07-04 17:26:08 +0800438 data[1] = 0;
liubin281ac462023-07-19 14:22:54 +0800439 }
yq.wangf98110c2025-06-11 14:50:04 +0800440#endif
441
442 }
443 else
444 {
liubin281ac462023-07-19 14:22:54 +0800445 LOGI("No process : %s", s);
446 }
b.liubcf86c92024-08-19 19:48:28 +0800447
yq.wangf98110c2025-06-11 14:50:04 +0800448 //urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
liubin281ac462023-07-19 14:22:54 +0800449 }
450 }
451 // +CREG: 1, "8010", "000060a5", 0, 2, 0
452 // +CREG: 1, "8330", "06447347", 7, 2, 0
453 // +CEREG: 1, "8330", "06447347", 7
454 // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
455 // $CREG: 1, "8010", "000060a7", 0,, 2, 0
456 // +CGREG: 1
457 else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
458 || strStartsWith(s, "+CEREG:")) // LTE data registed.
459 {
b.liu9e8584b2024-11-06 19:21:28 +0800460 const char* tmp_s = s + 7;
liuyang67f4bac2024-06-26 17:06:13 +0800461 static bool net_led_gms_wcdma = FALSE;
462 static bool net_led_lte = FALSE;
liubin281ac462023-07-19 14:22:54 +0800463 while(*tmp_s && *tmp_s == ' ')
464 tmp_s++;
b.liufe320632024-01-17 20:38:08 +0800465 uint8 data[2];
466 data[0] = (uint8)atoi(tmp_s); // Reg State.
liubin281ac462023-07-19 14:22:54 +0800467
b.liubcf86c92024-08-19 19:48:28 +0800468 if(strStartsWith(s, "+CGREG:"))
liuyang67f4bac2024-06-26 17:06:13 +0800469 {
470 data[1] = 0; // GMS/WCDMA
471 if(data[0] == 1)
472 {
473 net_led_gms_wcdma = TRUE;
474 }
475 else
476 {
477 net_led_gms_wcdma = FALSE;
478 }
b.liubcf86c92024-08-19 19:48:28 +0800479
480 }
481 else
liuyang67f4bac2024-06-26 17:06:13 +0800482 {
483 data[1] = 1; // LTE
484 if(data[0] == 1)
485 {
486 net_led_lte = TRUE;
487 }
488 else
489 {
490 net_led_lte = FALSE;
491 }
492 }
b.liubcf86c92024-08-19 19:48:28 +0800493
liuyang67f4bac2024-06-26 17:06:13 +0800494 if(FALSE == net_led_gms_wcdma && FALSE == net_led_lte)
495 {
496 mbtk_net_led_set(MBTK_NET_LED_SEARCH_NETWORK);
497 }
498 else
499 {
500 mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
501 mbtk_net_ready();
b.liufe320632024-01-17 20:38:08 +0800502 }
503
504 urc_msg_distribute(true, INFO_URC_MSG_NET_PS_REG_STATE, data, sizeof(data));
liuyang37623a02024-06-20 15:21:39 +0800505 urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
liubin281ac462023-07-19 14:22:54 +0800506 }
507 // +CREG: 1, "8010", "000060a5", 0, 2, 0
508 // +CREG: 1, "8330", "06447347", 7, 2, 0
509 // +CREG: 0
510 else if(strStartsWith(s, "+CREG:")) // GMS/WCDMA/LTE CS registed.
511 {
512 uint8 data[3];
513 data[0] = (uint8)MBTK_NET_CS_STATE;
514 char* tmp_s = memdup(s,strlen(s));
515 char* free_ptr = tmp_s;
516 char *line = tmp_s;
517 int tmp_int;
518 char *tmp_str;
519 if (at_tok_start(&line) < 0)
520 {
521 goto CREG_EXIT;
522 }
523 if (at_tok_nextint(&line, &tmp_int) < 0)
524 {
525 goto CREG_EXIT;
526 }
527 data[1] = (uint8)tmp_int; // Reg State.
528 if (data[1])
529 {
530 if (at_tok_nextstr(&line, &tmp_str) < 0)
531 {
532 goto CREG_EXIT;
533 }
534 if (at_tok_nextstr(&line, &tmp_str) < 0)
535 {
536 goto CREG_EXIT;
537 }
538 if (at_tok_nextint(&line, &tmp_int) < 0)
539 {
540 goto CREG_EXIT;
541 }
542 data[2] = (uint8)tmp_int; // AcT
543 } else {
544 data[2] = (uint8)0xFF; // AcT
545 }
yq.wangf98110c2025-06-11 14:50:04 +0800546#if 0
liubin281ac462023-07-19 14:22:54 +0800547 if(data[1] == 5)
548 {
549 uint8 data_pdp;
550 data_pdp = 5; //
551 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
552 }
yq.wangf98110c2025-06-11 14:50:04 +0800553#endif
liubin281ac462023-07-19 14:22:54 +0800554 urc_msg_distribute(false, INFO_URC_MSG_NET_CS_REG_STATE, data, sizeof(data));
liuyang37623a02024-06-20 15:21:39 +0800555 urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
liubin281ac462023-07-19 14:22:54 +0800556CREG_EXIT:
557 free(free_ptr);
558 }
559 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
560 else if(strStartsWith(s, "+CLCC:"))
561 {
562 mbtk_call_info_t reg;
563 reg.call_wait = MBTK_CLCC;
564 char* tmp_s = memdup(s,strlen(s));
565 char* free_ptr = tmp_s;
566 char *line = tmp_s;
567 int tmp_int;
568 char *tmp_str;
569 int err;
570
571 err = at_tok_start(&line);
572 if (err < 0)
573 {
574 goto CLCC_EXIT;
575 }
576 err = at_tok_nextint(&line, &tmp_int); // dir1
577 if (err < 0)
578 {
579 goto CLCC_EXIT;
580 }
581 reg.dir1 = (uint8)tmp_int;
582 err = at_tok_nextint(&line, &tmp_int);// dir
583 if (err < 0)
584 {
585 goto CLCC_EXIT;
586 }
587 reg.dir = (uint8)tmp_int;
588 err = at_tok_nextint(&line, &tmp_int);// state
589 if (err < 0)
590 {
591 goto CLCC_EXIT;
592 }
593 reg.state = (uint8)tmp_int;
594 err = at_tok_nextint(&line, &tmp_int);// mode
595 if (err < 0)
596 {
597 goto CLCC_EXIT;
598 }
599 reg.mode = (uint8)tmp_int;
600 err = at_tok_nextint(&line, &tmp_int);// mpty
601 if (err < 0)
602 {
603 goto CLCC_EXIT;
604 }
605 reg.mpty = (uint8)tmp_int;
606 err = at_tok_nextstr(&line, &tmp_str); // phone_number
607 if (err < 0)
608 {
609 goto CLCC_EXIT;
610 }
611
612 memset(reg.phone_number,0,sizeof(reg.phone_number));
613 memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
614 err = at_tok_nextint(&line, &tmp_int);// tpye
615 if (err < 0)
616 {
617 goto CLCC_EXIT;
618 }
619 reg.type = (uint8)tmp_int;
620
r.xiaoe1404b32024-05-23 22:43:39 -0700621 if(reg.state == 2 || reg.state == 3 || reg.state == 0)
622 {
623 mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
624 }
625
r.xiao195e2522024-05-31 03:19:02 -0700626 if(reg.state == 4 && reg.dir == 1)
627 {
628 mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
629 }
630
631
liuyang4d7ac4b2024-11-21 16:25:22 +0800632 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800633CLCC_EXIT:
634 free(free_ptr);
635 }
636 // +CPAS: 4
637 else if(strStartsWith(s, "+CPAS:"))
638 {
639 mbtk_call_info_t reg;
640 reg.call_wait = 0;
641 char* tmp_s = memdup(s,strlen(s));
642 char* free_ptr = tmp_s;
643 char *line = tmp_s;
644 int tmp_int;
645 int err;
646
647 memset(&reg,0,sizeof(reg));
648
649 err = at_tok_start(&line);
650 if (err < 0)
651 {
652 goto CPAS_EXIT;
653 }
654 err = at_tok_nextint(&line, &tmp_int);
655 if (err < 0)
656 {
657 goto CPAS_EXIT;
658 }
659 reg.pas = (uint8)tmp_int;
660 reg.call_wait = MBTK_CPAS;
liuyang4d7ac4b2024-11-21 16:25:22 +0800661 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800662CPAS_EXIT:
663 free(free_ptr);
664 }
665 // +CALLDISCONNECT: 1
666 else if(strStartsWith(s, "+CALLDISCONNECT:"))
667 {
668 mbtk_call_info_t reg;
669 reg.call_wait = 0;
670 char* tmp_s = memdup(s,strlen(s));
671 char* free_ptr = tmp_s;
672 char *line = tmp_s;
673 int tmp_int;
674 int err;
675
676 memset(&reg,0,sizeof(reg));
677
678 err = at_tok_start(&line);
679 if (err < 0)
680 {
681 goto CALLDISCONNECTED_EXIT;
682 }
683 err = at_tok_nextint(&line, &tmp_int);
684 if (err < 0)
685 {
686 goto CALLDISCONNECTED_EXIT;
687 }
688 reg.disconnected_id = tmp_int;
689 reg.call_wait = MBTK_DISCONNECTED;
r.xiaoe1404b32024-05-23 22:43:39 -0700690
691 if(reg.call_wait == MBTK_DISCONNECTED)
692 {
693 mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
694 }
695
liuyang4d7ac4b2024-11-21 16:25:22 +0800696 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800697
698CALLDISCONNECTED_EXIT:
699 free(free_ptr);
700 }
701 // *SIMDETEC:1,SIM
702 else if(strStartsWith(s, "*SIMDETEC:"))
703 {
liuyange22a25e2024-05-23 19:41:52 +0800704 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
705 {
706 net_info.sim_state = MBTK_SIM_ABSENT;
707 }
b.liubb590492024-06-13 16:42:08 +0800708
liubin281ac462023-07-19 14:22:54 +0800709 sim_info_reg.sim = -1;
710 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
711 sim_info_reg.sim = 0;
712 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
713 sim_info_reg.sim = 1;
yq.wangf98110c2025-06-11 14:50:04 +0800714#if 0
liubin281ac462023-07-19 14:22:54 +0800715 if(sim_info_reg.sim == 0)
716 {
717 uint8 data_pdp;
718 data_pdp = 11; //
719 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
720 }
yq.wangf98110c2025-06-11 14:50:04 +0800721#endif
liubin281ac462023-07-19 14:22:54 +0800722 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
723 }
724 // *EUICC:1
725/*0: SIM
7261: USIM
7272: TEST SIM
7283: TEST USIM
7294: UNKNOWN
730Note: *EUICC:
731*/
732 else if(strStartsWith(s, "*EUICC:"))
733 {
yq.wangb184fc22024-08-19 00:54:30 -0700734 sim_info_reg.sim = -1;
liubin281ac462023-07-19 14:22:54 +0800735 sim_info_reg.sim_card_type = -1;
736 if(strStartsWith(s, "*EUICC: 0"))
737 sim_info_reg.sim_card_type = 1;
738 else if(strStartsWith(s, "*EUICC: 1"))
739 sim_info_reg.sim_card_type = 2;
740 else if(strStartsWith(s, "*EUICC: 2"))
741 sim_info_reg.sim_card_type = 1;
742 else if(strStartsWith(s, "*EUICC: 3"))
743 sim_info_reg.sim_card_type = 2;
744 else if(strStartsWith(s, "*EUICC: 4"))
745 sim_info_reg.sim_card_type = 0;
746 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
747 }
748 // +CPIN: SIM PIN
749 else if(strStartsWith(s, "+CPIN:"))
750 {
751 sim_info_reg.sim = -1;
752 if(strStartsWith(s, "+CPIN: READY"))
liuyange22a25e2024-05-23 19:41:52 +0800753 {
liubin281ac462023-07-19 14:22:54 +0800754 sim_info_reg.sim = 1;
liuyange22a25e2024-05-23 19:41:52 +0800755 net_info.sim_state = MBTK_SIM_READY;
756 }
liubin281ac462023-07-19 14:22:54 +0800757 else if(strStartsWith(s, "+CPIN: SIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800758 {
liubin281ac462023-07-19 14:22:54 +0800759 sim_info_reg.sim = 2;
liuyange22a25e2024-05-23 19:41:52 +0800760 net_info.sim_state = MBTK_SIM_PIN;
761 }
liubin281ac462023-07-19 14:22:54 +0800762 else if(strStartsWith(s, "+CPIN: SIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800763 {
liubin281ac462023-07-19 14:22:54 +0800764 sim_info_reg.sim = 3;
liuyange22a25e2024-05-23 19:41:52 +0800765 net_info.sim_state = MBTK_SIM_PUK;
766 }
liubin281ac462023-07-19 14:22:54 +0800767 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800768 {
liubin281ac462023-07-19 14:22:54 +0800769 sim_info_reg.sim = 4;
liuyange22a25e2024-05-23 19:41:52 +0800770 net_info.sim_state = MBTK_SIM_ABSENT;
771 }
liubin281ac462023-07-19 14:22:54 +0800772 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800773 {
liubin281ac462023-07-19 14:22:54 +0800774 sim_info_reg.sim = 5;
liuyange22a25e2024-05-23 19:41:52 +0800775 net_info.sim_state = MBTK_SIM_ABSENT;
776 }
liubin281ac462023-07-19 14:22:54 +0800777 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800778 {
liubin281ac462023-07-19 14:22:54 +0800779 sim_info_reg.sim = 6;
liuyange22a25e2024-05-23 19:41:52 +0800780 net_info.sim_state = MBTK_SIM_ABSENT;
781 }
liubin281ac462023-07-19 14:22:54 +0800782 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800783 {
liubin281ac462023-07-19 14:22:54 +0800784 sim_info_reg.sim = 7;
liuyange22a25e2024-05-23 19:41:52 +0800785 net_info.sim_state = MBTK_SIM_ABSENT;
786 }
liubin281ac462023-07-19 14:22:54 +0800787 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
liuyange22a25e2024-05-23 19:41:52 +0800788 {
liubin281ac462023-07-19 14:22:54 +0800789 sim_info_reg.sim = 8;
liuyange22a25e2024-05-23 19:41:52 +0800790 net_info.sim_state = MBTK_SIM_ABSENT;
791 }
liubin281ac462023-07-19 14:22:54 +0800792 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
liuyange22a25e2024-05-23 19:41:52 +0800793 {
liubin281ac462023-07-19 14:22:54 +0800794 sim_info_reg.sim = 9;
liuyange22a25e2024-05-23 19:41:52 +0800795 net_info.sim_state = MBTK_SIM_ABSENT;
796 }
liubin281ac462023-07-19 14:22:54 +0800797 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800798 {
liubin281ac462023-07-19 14:22:54 +0800799 sim_info_reg.sim = 10;
liuyange22a25e2024-05-23 19:41:52 +0800800 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
801 }
liubin281ac462023-07-19 14:22:54 +0800802 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800803 {
liubin281ac462023-07-19 14:22:54 +0800804 sim_info_reg.sim = 11;
liuyange22a25e2024-05-23 19:41:52 +0800805 net_info.sim_state = MBTK_SIM_ABSENT;
806 }
liubin281ac462023-07-19 14:22:54 +0800807 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
liuyange22a25e2024-05-23 19:41:52 +0800808 {
liubin281ac462023-07-19 14:22:54 +0800809 sim_info_reg.sim = 12;
liuyange22a25e2024-05-23 19:41:52 +0800810 net_info.sim_state = MBTK_SIM_ABSENT;
811 }
liubin281ac462023-07-19 14:22:54 +0800812 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800813 {
liubin281ac462023-07-19 14:22:54 +0800814 sim_info_reg.sim = 13;
liuyange22a25e2024-05-23 19:41:52 +0800815 net_info.sim_state = MBTK_SIM_ABSENT;
816 }
liubin281ac462023-07-19 14:22:54 +0800817 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800818 {
liubin281ac462023-07-19 14:22:54 +0800819 sim_info_reg.sim = 14;
liuyange22a25e2024-05-23 19:41:52 +0800820 net_info.sim_state = MBTK_SIM_ABSENT;
821 }
liubin281ac462023-07-19 14:22:54 +0800822 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800823 {
liubin281ac462023-07-19 14:22:54 +0800824 sim_info_reg.sim = 15;
liuyange22a25e2024-05-23 19:41:52 +0800825 net_info.sim_state = MBTK_SIM_ABSENT;
826 }
liubin281ac462023-07-19 14:22:54 +0800827 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800828 {
liubin281ac462023-07-19 14:22:54 +0800829 sim_info_reg.sim = 16;
liuyange22a25e2024-05-23 19:41:52 +0800830 net_info.sim_state = MBTK_SIM_ABSENT;
831 }
liubin281ac462023-07-19 14:22:54 +0800832 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800833 {
liubin281ac462023-07-19 14:22:54 +0800834 sim_info_reg.sim = 17;
liuyange22a25e2024-05-23 19:41:52 +0800835 net_info.sim_state = MBTK_SIM_ABSENT;
836 }
liubin281ac462023-07-19 14:22:54 +0800837 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
liuyange22a25e2024-05-23 19:41:52 +0800838 {
839 sim_info_reg.sim = 18;
840 net_info.sim_state = MBTK_SIM_ABSENT;
841 }
liubin281ac462023-07-19 14:22:54 +0800842 else
843 sim_info_reg.sim = 20;
yq.wangf98110c2025-06-11 14:50:04 +0800844#if 0
liubin281ac462023-07-19 14:22:54 +0800845 if(sim_info_reg.sim == 18)
846 {
847 uint8 data_pdp;
848 data_pdp = 11; //
849 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
850 }
yq.wangf98110c2025-06-11 14:50:04 +0800851#endif
liubin281ac462023-07-19 14:22:54 +0800852 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
853 }
854 // +CMT: ,23
855 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
856 else if(strStartsWith(s, "+CMT:") || sms_cmt)
857 {
858 if(!sms_cmt){
859 sms_cmt = true;
860 }else{
861 sms_cmt = false;
862 }
863 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
864 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
865 }
866#if 0
867 // LTE data registed.
868 // +CEREG: 1, "8330", "06447347", 7
869 else if(strStartsWith(s, "+CEREG:"))
870 {
871 char* tmp_s = memdup(s,strlen(s));
872 char* free_ptr = tmp_s;
873 char *line = tmp_s;
874 int tmp_int;
875 char *tmp_str;
876 if (at_tok_start(&line) < 0)
877 {
878 goto CREG_EXIT;
879 }
880 if (at_tok_nextint(&line, &tmp_int) < 0)
881 {
882 goto CREG_EXIT;
883 }
884 uint8 data = (uint8)tmp_int; // Reg State.
885
886 urc_msg_distribute(INFO_URC_MSG_NET_REG_STATE, &data, sizeof(uint8));
887CREG_EXIT:
888 free(free_ptr);
889 }
890#endif
891 /*
892 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
893 // <rsrp>,<rsrq>, <sinr>,
894 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
895 // cellId,subFrameAssignType,specialSubframePatterns,transMode
896 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
897 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
898 // dlBer, ulBer,
899 // diversitySinr, diversityRssi
900 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
901 0, 0, 0,
902 1, 10, 0, 1, 0, 1059, 78, 3959566565,
903 105149248, 2, 7, 7,
904 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
905 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
906 0, 0,
907 7, 44
908 */
909 else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
910 {
911 // tac, PCI, dlEuarfcn, ulEuarfcn, band
912 if(cell_info.running) {
913 int tmp_int;
914 int i = 0;
915 char* tmp_s = memdup(s,strlen(s));
916 char* free_ptr = tmp_s;
917 char *line = tmp_s;
918 if (at_tok_start(&line) < 0)
919 {
920 goto EEMLTESVC_EXIT;
921 }
922
923 if (at_tok_nextint(&line, &tmp_int) < 0)
924 {
925 goto EEMLTESVC_EXIT;
926 }
927 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
928 if (at_tok_nextint(&line, &tmp_int) < 0)
929 {
930 goto EEMLTESVC_EXIT;
931 }
932 if (at_tok_nextint(&line, &tmp_int) < 0)
933 {
934 goto EEMLTESVC_EXIT;
935 }
936 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
937 /*
938 // Jump 2 integer.
939 i = 0;
940 while(i < 2) {
941 if (at_tok_nextint(&line, &tmp_int) < 0)
942 {
943 goto EEMLTESVC_EXIT;
944 }
945 i++;
946 }
947 */
948 if (at_tok_nextint(&line, &tmp_int) < 0)
949 {
950 goto EEMLTESVC_EXIT;
951 }
952 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //tac
953 if (at_tok_nextint(&line, &tmp_int) < 0)
954 {
955 goto EEMLTESVC_EXIT;
956 }
957 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //pci
958 if (at_tok_nextint(&line, &tmp_int) < 0)
959 {
960 goto EEMLTESVC_EXIT;
961 }
962 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //dl arfcn
q.huange9dae462025-06-21 14:00:29 +0800963 if (at_tok_nextint(&line, &tmp_int) < 0) //ul arfcn
liubin281ac462023-07-19 14:22:54 +0800964 {
965 goto EEMLTESVC_EXIT;
966 }
liubin281ac462023-07-19 14:22:54 +0800967 if (at_tok_nextint(&line, &tmp_int) < 0)
968 {
969 goto EEMLTESVC_EXIT;
970 }
971 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //band
972 if (at_tok_nextint(&line, &tmp_int) < 0)
973 {
974 goto EEMLTESVC_EXIT;
975 }
976 if (at_tok_nextint(&line, &tmp_int) < 0)
977 {
978 goto EEMLTESVC_EXIT;
979 }
q.huange9dae462025-06-21 14:00:29 +0800980 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //rsrp
liubin281ac462023-07-19 14:22:54 +0800981 if (at_tok_nextint(&line, &tmp_int) < 0)
982 {
983 goto EEMLTESVC_EXIT;
984 }
q.huange9dae462025-06-21 14:00:29 +0800985 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //rsrq
liubin281ac462023-07-19 14:22:54 +0800986
q.huange9dae462025-06-21 14:00:29 +0800987 if (at_tok_nextint(&line, &tmp_int) < 0)
988 {
989 goto EEMLTESVC_EXIT;
990 }
991
992 cell_info.cell[cell_info.cell_num].value11 = (uint32)tmp_int; //sinr
993
994 for(i =0; i < 9; i++)
liubin281ac462023-07-19 14:22:54 +0800995 {
996 if (at_tok_nextint(&line, &tmp_int) < 0)
997 {
998 goto EEMLTESVC_EXIT;
999 }
1000 }
1001 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //cell identiy
1002
b.liuaec91492025-05-24 10:52:26 +08001003 for(i =0; i < 28; i++)
1004 {
1005 if (at_tok_nextint(&line, &tmp_int) < 0)
1006 {
1007 goto EEMLTESVC_EXIT;
1008 }
1009 }
1010
1011 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //dlBler
1012
q.huange9dae462025-06-21 14:00:29 +08001013 for(i =0; i < 14; i++)
1014 {
1015 if (at_tok_nextint(&line, &tmp_int) < 0)
1016 {
1017 goto EEMLTESVC_EXIT;
1018 }
1019 }
1020
1021 cell_info.cell[cell_info.cell_num].value12 = (uint32)tmp_int; //fdd or tdd //63
1022
liubin281ac462023-07-19 14:22:54 +08001023 cell_info.cell_num++;
1024
b.liuaec91492025-05-24 10:52:26 +08001025 LOG("LTESVC cell_num : %d", cell_info.cell_num);
1026
1027
liubin281ac462023-07-19 14:22:54 +08001028EEMLTESVC_EXIT:
1029 free(free_ptr);
1030 }
1031 }
1032 /*
1033 // index,phyCellId,euArfcn,rsrp,rsrq
1034 +EEMLTEINTER: 0, 65535, 38950, 0, 0
1035 */
q.huange9dae462025-06-21 14:00:29 +08001036 else if(strStartsWith(s, "+EEMLTEINTRA:")) // LTE Í¬ÆµÐ¡Çø
1037 {
1038 // phyCellId,euArfcn,rsrp,rsrq
1039 if(cell_info.running) {
1040 int tmp_int;
1041 char* tmp_s = memdup(s,strlen(s));
1042 char* free_ptr = tmp_s;
1043 char *line = tmp_s;
1044 if (at_tok_start(&line) < 0)
1045 {
1046 goto EEMLTEINTRA_EXIT;
1047 }
1048 if (at_tok_nextint(&line, &tmp_int) < 0) //index
1049 {
1050 goto EEMLTEINTRA_EXIT;
1051 }
1052 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1053 {
1054 goto EEMLTEINTRA_EXIT;
1055 }
1056 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //phycellid
1057 if (at_tok_nextint(&line, &tmp_int) < 0)
1058 {
1059 goto EEMLTEINTRA_EXIT;
1060 }
1061 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //arfcn
1062 if (at_tok_nextint(&line, &tmp_int) < 0)
1063 {
1064 goto EEMLTEINTRA_EXIT;
1065 }
1066 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //rsrp
1067 LOG("cell line : %s", line);
1068 if (at_tok_nextint(&line, &tmp_int) < 0)
1069 {
1070 goto EEMLTEINTRA_EXIT;
1071 }
1072 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //rsrq
1073
1074 cell_info.cell[cell_info.cell_num].value7 =0x7FFFFFFF;//mnc
1075
1076 cell_info.cell_num++;
1077EEMLTEINTRA_EXIT:
1078 free(free_ptr);
1079 }
1080 }
1081 // Do nothing
1082 else if(strStartsWith(s, "+EEMLTEINTER:")) // LTE ÒìÆµ/Ð¡Çø
liubin281ac462023-07-19 14:22:54 +08001083 {
1084 // phyCellId,euArfcn,rsrp,rsrq
1085 if(cell_info.running) {
1086 int tmp_int;
1087 char* tmp_s = memdup(s,strlen(s));
1088 char* free_ptr = tmp_s;
1089 char *line = tmp_s;
1090 if (at_tok_start(&line) < 0)
1091 {
1092 goto EEMLTEINTER_EXIT;
1093 }
q.huange9dae462025-06-21 14:00:29 +08001094 if (at_tok_nextint(&line, &tmp_int) < 0) //index
liubin281ac462023-07-19 14:22:54 +08001095 {
1096 goto EEMLTEINTER_EXIT;
1097 }
1098 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1099 {
1100 goto EEMLTEINTER_EXIT;
1101 }
q.huange9dae462025-06-21 14:00:29 +08001102 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //phy cell id
liubin281ac462023-07-19 14:22:54 +08001103 if (at_tok_nextint(&line, &tmp_int) < 0)
1104 {
1105 goto EEMLTEINTER_EXIT;
1106 }
q.huange9dae462025-06-21 14:00:29 +08001107 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //arfcn
liubin281ac462023-07-19 14:22:54 +08001108 if (at_tok_nextint(&line, &tmp_int) < 0)
1109 {
1110 goto EEMLTEINTER_EXIT;
1111 }
q.huange9dae462025-06-21 14:00:29 +08001112 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //rsrp
liubin281ac462023-07-19 14:22:54 +08001113 LOG("cell line : %s", line);
1114 if (at_tok_nextint(&line, &tmp_int) < 0)
1115 {
1116 goto EEMLTEINTER_EXIT;
1117 }
q.huange9dae462025-06-21 14:00:29 +08001118 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //rsrq
liubin281ac462023-07-19 14:22:54 +08001119 if (at_tok_nextint(&line, &tmp_int) < 0)
1120 {
1121 LOG("cell tmp_int : %d", tmp_int);
1122 goto EEMLTEINTER_EXIT;
1123 }
q.huange9dae462025-06-21 14:00:29 +08001124 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //cellid
liubin281ac462023-07-19 14:22:54 +08001125 LOG("cell value5 : %d", cell_info.cell[cell_info.cell_num].value5);
b.liuaec91492025-05-24 10:52:26 +08001126
1127 LOG("after cellid cell line : %s", line);
1128 if (at_tok_nextint(&line, &tmp_int) < 0)
1129 {
1130 goto EEMLTEINTER_EXIT;
1131 }
1132 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
1133
q.huange9dae462025-06-21 14:00:29 +08001134 if (at_tok_nextint(&line, &tmp_int) < 0) //length of mnc
b.liuaec91492025-05-24 10:52:26 +08001135 {
1136 LOG("exit");
1137 goto EEMLTEINTER_EXIT;
q.huange9dae462025-06-21 14:00:29 +08001138 }
b.liuaec91492025-05-24 10:52:26 +08001139
1140 if (at_tok_nextint(&line, &tmp_int) < 0)
1141 {
1142 LOG("exit");
1143 goto EEMLTEINTER_EXIT;
1144 }
1145
1146 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
1147
q.huange9dae462025-06-21 14:00:29 +08001148 if (at_tok_nextint(&line, &tmp_int) < 0)
b.liuaec91492025-05-24 10:52:26 +08001149 {
1150 LOG("exit");
1151 goto EEMLTEINTER_EXIT;
q.huange9dae462025-06-21 14:00:29 +08001152 }
1153 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //tac
1154 LOG("cell value8 : %u", (uint32)cell_info.cell[cell_info.cell_num].value8);
b.liuaec91492025-05-24 10:52:26 +08001155
b.liuaec91492025-05-24 10:52:26 +08001156
q.huange9dae462025-06-21 14:00:29 +08001157 for(int i =0; i < 8; i++)
b.liuaec91492025-05-24 10:52:26 +08001158 {
q.huange9dae462025-06-21 14:00:29 +08001159 if (at_tok_nextint(&line, &tmp_int) < 0) //1 cell id 2 rslevel
1160 // 3 thresh low 4 thresh_high 5 cell_priority 6 refSignalPower 7 bandwidth 8 band
b.liuaec91492025-05-24 10:52:26 +08001161 {
1162 LOG("exit i = %d",i);
1163 goto EEMLTEINTER_EXIT;
1164 }
1165 }
1166
1167 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //band
1168 LOG("cell value9 : %d", cell_info.cell[cell_info.cell_num].value9);
1169 if (at_tok_nextint(&line, &tmp_int) < 0)
1170 {
1171 LOG("exit");
1172 goto EEMLTEINTER_EXIT;
1173 }
1174
1175 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //rssi
1176
liubin281ac462023-07-19 14:22:54 +08001177 cell_info.cell_num++;
1178EEMLTEINTER_EXIT:
1179 free(free_ptr);
1180 }
1181 }
1182 // Do nothing
1183 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
1184 {
1185 if(cell_info.running) {
1186
1187 }
1188 }
1189 // WCDMA
1190 /*
1191 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1192
1193 // if sCMeasPresent == 1
1194 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1195 // endif
1196
1197 // if sCParamPresent == 1
1198 // rac, nom, mcc, mnc_len, mnc, lac, ci,
1199 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1200 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1201 // endif
1202
1203 // if ueOpStatusPresent == 1
1204 // rrcState, numLinks, srncId, sRnti,
1205 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1206 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1207 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1208 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1209 // endif
1210 //
1211 +EEMUMTSSVC: 3, 1, 1, 1,
1212 -80, 27, -6, -18, -115, -32768,
1213 1, 1, 1120, 2, 1, 61697, 168432821,
1214 15, 24, 10763, 0, 0, 0, 0,
1215 128, 128, 65535, 0, 0,
1216 2, 255, 65535, 4294967295,
1217 0, 0, 0, 0, 0, 0,
1218 0, 0, 0, 0, 0, 0, 1, 1,
1219 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1220 0, 0, 0, 0, 0, 0
1221 */
1222 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1223 {
1224 // lac, ci, arfcn
1225 if(cell_info.running) {
1226 int tmp_int;
1227 int i = 0;
1228 char* tmp_s = memdup(s,strlen(s));
1229 char* free_ptr = tmp_s;
1230 char *line = tmp_s;
1231 if (at_tok_start(&line) < 0)
1232 {
1233 goto EEMUMTSSVC_EXIT;
1234 }
1235 // Jump 12 integer.
1236 i = 0;
1237 while(i < 12) {
1238 if (at_tok_nextint(&line, &tmp_int) < 0)
1239 {
1240 goto EEMUMTSSVC_EXIT;
1241 }
1242 i++;
1243 }
1244 // mcc
1245 if (at_tok_nextint(&line, &tmp_int) < 0)
1246 {
1247 goto EEMUMTSSVC_EXIT;
1248 }
1249 cell_info.cell[cell_info.cell_num].value4= (uint32)tmp_int;
1250 // mnc
1251 if (at_tok_nextint(&line, &tmp_int) < 0)
1252 {
1253 goto EEMUMTSSVC_EXIT;
1254 }
1255 cell_info.cell[cell_info.cell_num].value5= (uint32)tmp_int;
1256 // lac
1257 if (at_tok_nextint(&line, &tmp_int) < 0)
1258 {
1259 goto EEMUMTSSVC_EXIT;
1260 }
1261 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1262 // ci
1263 if (at_tok_nextint(&line, &tmp_int) < 0)
1264 {
1265 goto EEMUMTSSVC_EXIT;
1266 }
1267 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1268
1269 if (at_tok_nextint(&line, &tmp_int) < 0)
1270 {
1271 goto EEMUMTSSVC_EXIT;
1272 }
1273 // cpi
1274 if (at_tok_nextint(&line, &tmp_int) < 0)
1275 {
1276 goto EEMUMTSSVC_EXIT;
1277 }
1278 cell_info.cell[cell_info.cell_num].value6= (uint32)tmp_int;
1279 /*
1280 // Jump 2 integer.
1281 i = 0;
1282 while(i < 2) {
1283 if (at_tok_nextint(&line, &tmp_int) < 0)
1284 {
1285 goto EEMUMTSSVC_EXIT;
1286 }
1287 i++;
1288 }
1289 */
1290 // arfcn
1291 if (at_tok_nextint(&line, &tmp_int) < 0)
1292 {
1293 goto EEMUMTSSVC_EXIT;
1294 }
1295 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1296
1297 cell_info.cell_num++;
1298EEMUMTSSVC_EXIT:
1299 free(free_ptr);
1300 }
1301 }
1302 /*
1303 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1304 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1305 */
1306 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1307 {
1308 // lac, ci, arfcn
1309 if(cell_info.running) {
1310 int tmp_int;
1311 int i = 0;
1312 char* tmp_s = memdup(s,strlen(s));
1313 char* free_ptr = tmp_s;
1314 char *line = tmp_s;
1315 if (at_tok_start(&line) < 0)
1316 {
1317 goto EEMUMTSINTRA_EXIT;
1318 }
1319 // Jump 8 integer.
1320 i = 0;
1321 while(i < 8) {
1322 if (at_tok_nextint(&line, &tmp_int) < 0)
1323 {
1324 goto EEMUMTSINTRA_EXIT;
1325 }
1326 i++;
1327 }
1328
1329 // lac
1330 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1331 {
1332 goto EEMUMTSINTRA_EXIT;
1333 }
1334 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1335
1336 // ci
1337 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1338 {
1339 goto EEMUMTSINTRA_EXIT;
1340 }
1341 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1342
1343 // arfcn
1344 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1345 {
1346 goto EEMUMTSINTRA_EXIT;
1347 }
1348 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1349
1350 cell_info.cell_num++;
1351EEMUMTSINTRA_EXIT:
1352 free(free_ptr);
1353 }
1354 }
1355 /*
1356 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1357 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1358 */
1359 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1360 {
1361 // lac, ci, arfcn
1362 if(cell_info.running) {
1363 int tmp_int;
1364 int i = 0;
1365 char* tmp_s = memdup(s,strlen(s));
1366 char* free_ptr = tmp_s;
1367 char *line = tmp_s;
1368 if (at_tok_start(&line) < 0)
1369 {
1370 goto EEMUMTSINTERRAT_EXIT;
1371 }
1372 // Jump 7 integer.
1373 i = 0;
1374 while(i < 7) {
1375 if (at_tok_nextint(&line, &tmp_int) < 0)
1376 {
1377 goto EEMUMTSINTERRAT_EXIT;
1378 }
1379 i++;
1380 }
1381
1382 // lac
1383 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1384 {
1385 goto EEMUMTSINTERRAT_EXIT;
1386 }
1387 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1388
1389 // ci
1390 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1391 {
1392 goto EEMUMTSINTERRAT_EXIT;
1393 }
1394 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1395
1396 // arfcn
1397 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1398 {
1399 goto EEMUMTSINTERRAT_EXIT;
1400 }
1401 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1402
1403 cell_info.cell_num++;
1404EEMUMTSINTERRAT_EXIT:
1405 free(free_ptr);
1406 }
1407 }
1408 // GSM
1409 // +EEMGINFOBASIC: 2
1410 // Do nothing.
1411 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1412 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1413 {
1414 if(cell_info.running) {
1415
1416 }
1417 }
1418 /*
1419 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1420 // bsic, C1, C2, TA, TxPwr,
1421 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1422 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1423 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1424 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1425 // gsmBand,channelMode
1426 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1427 63, 36, 146, 1, 7,
1428 46, 42, 42, 7, 0,
1429 53, 0, 8, 0, 1, 6, 53,
1430 2, 0, 146, 42, 54, 0, 1,
1431 1, 32, 0, 0, 0, 0,
1432 0, 0
1433 */
1434 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1435 {
1436 // lac, ci, arfcn, bsic
1437 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1438 if(cell_info.running) {
1439 int tmp_int;
1440 int i = 0;
1441 char* tmp_s = memdup(s,strlen(s));
1442 char* free_ptr = tmp_s;
1443 char *line = tmp_s;
1444 if (at_tok_start(&line) < 0)
1445 {
1446 goto EEMGINFOSVC_EXIT;
1447 }
1448
1449 // mcc
1450 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1451 {
1452 goto EEMGINFOSVC_EXIT;
1453 }
1454 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1455
1456 //mnc_len
1457 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1458 {
1459 goto EEMGINFOSVC_EXIT;
1460 }
1461 // mnc
q.huang8a993672025-06-24 16:19:46 +08001462 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
liubin281ac462023-07-19 14:22:54 +08001463 {
1464 goto EEMGINFOSVC_EXIT;
1465 }
1466 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
q.huang8a993672025-06-24 16:19:46 +08001467
liubin281ac462023-07-19 14:22:54 +08001468 // lac
1469 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1470 {
1471 goto EEMGINFOSVC_EXIT;
1472 }
1473 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1474
1475 // ci
1476 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1477 {
1478 goto EEMGINFOSVC_EXIT;
1479 }
1480 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1481
q.huang8a993672025-06-24 16:19:46 +08001482 // Jump 2 integer, get 3rd number
liubin281ac462023-07-19 14:22:54 +08001483 i = 0;
q.huang8a993672025-06-24 16:19:46 +08001484 while(i < 3) {
liubin281ac462023-07-19 14:22:54 +08001485 if (at_tok_nextint(&line, &tmp_int) < 0)
1486 {
1487 goto EEMGINFOSVC_EXIT;
1488 }
1489 i++;
1490 }
1491
1492 // bsic
q.huang8a993672025-06-24 16:19:46 +08001493 if ( tmp_int < 0 || tmp_int >= 65536)
liubin281ac462023-07-19 14:22:54 +08001494 {
1495 goto EEMGINFOSVC_EXIT;
1496 }
1497 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1498
q.huang8a993672025-06-24 16:19:46 +08001499 // Jump 4 integer, get 5rd number
liubin281ac462023-07-19 14:22:54 +08001500 i = 0;
q.huang8a993672025-06-24 16:19:46 +08001501 while(i < 5) {
1502 if (at_tok_nextint(&line, &tmp_int) < 0)
1503 {
1504 goto EEMGINFOSVC_EXIT;
1505 }
1506 i++;
1507 }
1508
1509 cell_info.cell[cell_info.cell_num].value7=tmp_int; //rxlev
1510
1511 // Jump 10 integer, get 11rd number
1512 i = 0;
1513 while(i < 11) {
liubin281ac462023-07-19 14:22:54 +08001514 if (at_tok_nextint(&line, &tmp_int) < 0)
1515 {
1516 goto EEMGINFOSVC_EXIT;
1517 }
1518 i++;
1519 }
1520
1521 // arfcn
q.huang8a993672025-06-24 16:19:46 +08001522 if (tmp_int < 0 || tmp_int >= 65536)
liubin281ac462023-07-19 14:22:54 +08001523 {
1524 goto EEMGINFOSVC_EXIT;
1525 }
1526 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1527
1528 cell_info.cell_num++;
1529EEMGINFOSVC_EXIT:
1530 free(free_ptr);
1531 }
1532 }
1533 /*
1534 // PS_attached, attach_type, service_type, tx_power, c_value,
1535 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1536 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1537 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1538 +EEMGINFOPS: 1, 255, 0, 0, 0,
1539 0, 0, 268435501, 1, 0, 0,
1540 4, 0, 96, 0, 0, 0,
1541 0, 0, 0, 65535, 0, 13350
1542 */
1543 // Do nothing.
1544 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1545 {
1546 if(cell_info.running) {
1547
1548 }
1549 }
1550 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1551 {
1552 if(cell_info.running) {
1553 int tmp_int;
1554 int i = 0;
1555 char* tmp_s = memdup(s,strlen(s));
1556 char* free_ptr = tmp_s;
1557 char *line = tmp_s;
1558 if (at_tok_start(&line) < 0)
1559 {
1560 goto EEMGINFOPS_EXIT;
1561 }
1562
1563 // nc_num
1564 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1565 {
1566 LOG("cell_info.running 1= %d\n.",cell_info.running);
1567 goto EEMGINFOPS_EXIT;
1568 }
1569 // mcc
1570 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1571 {
1572 LOG("cell_info.running 2= %d\n.",cell_info.running);
1573 goto EEMGINFOPS_EXIT;
1574 }
1575 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1576
1577 // mnc
1578 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1579 {
1580 LOG("cell_info.running 3= %d\n.",cell_info.running);
1581 goto EEMGINFOPS_EXIT;
1582 }
1583 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1584
1585 // lac
1586 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1587 {
1588 LOG("cell_info.running 4= %d\n.",cell_info.running);
1589 goto EEMGINFOPS_EXIT;
1590 }
1591 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1592
1593 // rac
1594 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1595 {
1596 LOG("cell_info.running 5= %d\n.",cell_info.running);
1597 goto EEMGINFOPS_EXIT;
1598 }
1599
1600 // ci
1601 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1602 {
1603 LOG("cell_info.running 6= %d\n.",cell_info.running);
1604 goto EEMGINFOPS_EXIT;
1605 }
1606 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1607
1608 // rx_lv
1609 if (at_tok_nextint(&line, &tmp_int) < 0)
1610 {
1611 LOG("cell_info.running 7= %d\n.",cell_info.running);
1612 goto EEMGINFOPS_EXIT;
1613 }
1614
1615 // bsic
1616 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1617 {
1618 LOG("cell_info.running 8= %d\n.",cell_info.running);
1619 goto EEMGINFOPS_EXIT;
1620 }
1621 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1622
1623 // Jump 2 integer.
1624 i = 0;
1625 while(i < 2) {
1626 if (at_tok_nextint(&line, &tmp_int) < 0)
1627 {
1628 LOG("cell_info.running 9= %d\n.",cell_info.running);
1629 goto EEMGINFOPS_EXIT;
1630 }
1631 i++;
1632 }
1633
1634 // arfcn
1635 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1636 {
1637 LOG("cell_info.running 10 = %d\n.",cell_info.running);
1638 goto EEMGINFOPS_EXIT;
1639 }
1640 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1641
1642 cell_info.cell_num++;
1643EEMGINFOPS_EXIT:
1644 free(free_ptr);
1645 }
1646 }
1647 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"
1648 {
1649
1650 }
1651 else
1652 {
1653 LOGV("Unknown URC : %s", s);
1654 }
1655}
1656
1657static int openSocket(const char* sockname)
1658{
1659 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
1660 if (sock < 0)
1661 {
1662 LOGE("Error create socket: %s\n", strerror(errno));
1663 return -1;
1664 }
1665 struct sockaddr_un addr;
1666 memset(&addr, 0, sizeof(addr));
1667 addr.sun_family = AF_UNIX;
1668 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
1669 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
1670 {
1671 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
1672 sleep(1);
1673 }
1674
1675#if 0
1676 int sk_flags = fcntl(sock, F_GETFL, 0);
1677 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
1678#endif
1679
1680 return sock;
1681}
1682
b.liu9e8584b2024-11-06 19:21:28 +08001683#if 0
liubin281ac462023-07-19 14:22:54 +08001684static void ril_get_cgpaddr_ip_process()
1685{
1686 int err, skip;
1687 ATResponse *p_response = NULL;
1688 char *line;
1689 char *ipv4 = NULL, *ipv6 = NULL;
1690 err = at_send_command_singleline("AT+CGPADDR", "+CGPADDR:", &p_response);
1691 if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
1692 {
1693 LOGE("+CGPADDR exec error.");
1694 goto error;
1695 }
1696
1697 // +CGPADDR: 1, "10.51.59.229", "254.128.0.0.0.0.0.0.0.1.0.0.111.176.63.99"
1698 // +CGPADDR: 1, "10.124.139.131"
1699 line = p_response->p_intermediates->line;
1700 err = at_tok_start(&line);
1701 if (err < 0)
1702 {
1703 goto error;
1704 }
1705
1706 err = at_tok_nextint(&line, &skip);
1707 if (err < 0)
1708 {
1709 goto error;
1710 }
1711
1712 if (!at_tok_hasmore(&line))
1713 {
1714 goto error;
1715 }
1716
1717 err = at_tok_nextstr(&line, &ipv4);
1718 if (err < 0)
1719 {
1720 LOGE("Get IPv4 fail.");
1721 goto error;
1722 }
1723
1724 if (at_tok_hasmore(&line))
1725 {
1726 err = at_tok_nextstr(&line, &ipv6);
1727 if (err < 0)
1728 {
1729 LOGE("Get IPv6 fail.");
1730 goto error;
1731 }
1732 }
1733 else
1734 {
1735 LOGD("No IPv6 Found.");
1736 }
1737
1738 if(ipv6)
1739 {
1740 LOGD("IPv6 : %s", ipv6);
1741 }
1742
1743 if(ipv4)
1744 {
1745 LOGD("IPv4 : %s", ipv4);
1746
1747// ril_net_dev_config("ccinet0", ipv4, NULL);
1748 }
1749error:
1750 at_response_free(p_response);
1751}
b.liu9e8584b2024-11-06 19:21:28 +08001752#endif
liubin281ac462023-07-19 14:22:54 +08001753
1754static void sim_state_change(bool plug_in) {
1755 if(plug_in) {
1756 // If radio on,must off in the first.
1757 if(net_info.radio_state == MBTK_RADIO_STATE_ON) {
1758 setRadioPower(0);
1759 }
1760 setRadioPower(1);
1761 } else {
1762 setRadioPower(0);
1763 }
1764}
1765
1766static int open_uevent_socket()
1767{
1768 struct sockaddr_nl addr;
1769 int sz = 64*1024;
1770 int s = 0;
1771
1772 memset(&addr, 0, sizeof(addr));
1773 addr.nl_family = AF_NETLINK;
1774 addr.nl_pid = getpid();
1775 addr.nl_groups = 0xffffffff;
1776
1777 s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
1778 if (s < 0)
1779 {
1780 LOGE("socket() fail.[%d]", errno);
1781 return -1;
1782 }
1783
1784 setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz));
1785
1786 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0)
1787 {
1788 close(s);
1789 return -1;
1790 }
1791
1792 return s;
1793}
1794
1795static void parse_uevent(const char *msg, int msg_len, struct cooling_device *cdev)
1796{
1797 // change@/devices/virtual/usim_event/usim0\0
1798 // ACTION=change\0
1799 // DEVPATH=/devices/virtual/usim_event/usim0\0
1800 // SUBSYSTEM=usim_event\0
1801 // USIM_NAME=usim0\0
1802 // USIM_EVENT=plugout\0
1803 // SEQNUM=704
1804 int i = 0;
1805 while (i < msg_len)
1806 {
1807 if(*(msg + i) == '\0')
1808 {
1809 i++;
1810 continue;
1811 }
1812 if (!strncmp(msg + i, "USIM_NAME=", 10))
1813 {
1814 i += 10;
1815 cdev->name = msg + i;
1816 i += strlen(msg + i);
1817 }
1818 else if (!strncmp(msg + i, "ACTION=", 7))
1819 {
1820 i += 7;
1821 cdev->action = msg + i;
1822 i += strlen(msg + i);
1823 }
1824 else if (!strncmp(msg + i, "DEVPATH=", 8))
1825 {
1826 i += 8;
1827 cdev->path = msg + i;
1828 i += strlen(msg + i);
1829 }
1830 else if (!strncmp(msg + i, "USIM_EVENT=", 11))
1831 {
1832 i += 11;
1833 cdev->event = msg + i;
1834 i += strlen(msg + i);
1835 }
1836 else if (!strncmp(msg + i, "SUBSYSTEM=", 10))
1837 {
1838 i += 10;
1839 cdev->subsystem = msg + i;
1840 i += strlen(msg + i);
1841 }
1842 else
1843 {
1844 i++;
1845 }
1846 }
1847
1848 if(!strncmp(cdev->path, UEVENT_USIM_DEV, sizeof(UEVENT_USIM_DEV))
1849 && !strncmp(cdev->action, "change", 5))
1850 {
1851 LOGD("event { name=%s, action=%s, path=%s, subsystem=%s, event=%s}",
1852 cdev->name, cdev->action, cdev->path, cdev->subsystem, cdev->event);
1853 if(!strcmp(cdev->event, "plugout"))
1854 {
1855 sim_state_change(FALSE);
1856 }
1857 else if(!strcmp(cdev->event, "plugin"))
1858 {
1859 sim_state_change(TRUE);
1860 }
1861 else
1862 {
1863 LOGE("usim evnet error!");
1864 }
1865 }
1866}
1867
1868static void* uevnet_run(void *payload)
1869{
1870 int socket_fd = -1;
1871 char msg[BUFFER_SIZE+2];
1872 int n;
1873
1874 socket_fd = open_uevent_socket();
1875 if(socket_fd > 0)
1876 {
1877 while(1)
1878 {
1879 if((n = recv(socket_fd, msg, BUFFER_SIZE, 0)) > 0)
1880 {
1881 struct cooling_device cdev;
1882 memset(&cdev, 0x0, sizeof(cdev));
1883
1884 if(n == BUFFER_SIZE)
1885 continue;
1886 msg[n] = '\0';
1887 // 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
1888 log_hex("UEVENT", msg, n);
1889 parse_uevent(msg, n, &cdev);
1890 }
1891 else
1892 {
1893 LOGE("recv msg error.");
1894 }
1895 }
1896 }
1897
1898 LOGD("UEVENT Thread exit!!!");
1899 return NULL;
1900}
1901
1902int uevent_main()
1903{
1904 mbtk_task_info task;
1905 task.task_id = &uevnet_task_id;
1906 task.thread_run = uevnet_run;
1907 task.args = NULL;
1908 return mbtk_task_start(&task);
1909}
1910
1911/*
1912int ril_main()
1913{
1914 return mbtk_task_queue_start(&ril_task, ril_main_run);
1915}
1916*/
1917
1918int mbtk_info_server_start();
1919int InProduction_Mode(void);
1920void server_ready_set(void);
1921
b.liu9e8584b2024-11-06 19:21:28 +08001922#if 0
liubin281ac462023-07-19 14:22:54 +08001923
1924/*
1925 *Get mtdblock which name is ASR_FLAG
1926 *return path if found, else return NULL
1927 */
1928static int asrFlagPathGet(char *asr_flag_path)
1929{
q.huang8a993672025-06-24 16:19:46 +08001930 char buf[128];
1931 unsigned char find = 0;
liubin281ac462023-07-19 14:22:54 +08001932 FILE *fd = fopen("/proc/mtd", "r");
q.huang8a993672025-06-24 16:19:46 +08001933 if (fd == NULL) {
liubin281ac462023-07-19 14:22:54 +08001934 LOGE("Open MTD failed!");
1935 return -1;
q.huang8a993672025-06-24 16:19:46 +08001936 }
liubin281ac462023-07-19 14:22:54 +08001937
q.huang8a993672025-06-24 16:19:46 +08001938 memset(buf, '\0', 128);
1939 while (fgets(buf, 128, fd) != NULL) {
1940 if(strstr(buf, "asr_flag")) {
1941 char *p = strstr(buf, "mtd");
1942 if(p)
1943 {
1944 int bln;
1945 sscanf(p, "mtd%d", &bln);
1946 sprintf(asr_flag_path, "/dev/mtdblock%d", bln);
1947 find = 1;
1948 break;
1949 }
1950 }
1951 memset(buf, '\0', 128);
1952 }
liubin281ac462023-07-19 14:22:54 +08001953
q.huang8a993672025-06-24 16:19:46 +08001954 fclose(fd);
liubin281ac462023-07-19 14:22:54 +08001955 return ((find == 1) ? 0 : -1);
1956}
b.liu9e8584b2024-11-06 19:21:28 +08001957
liubin281ac462023-07-19 14:22:54 +08001958static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)
1959{
q.huang8a993672025-06-24 16:19:46 +08001960 int ret, fd;
1961 if (!path)
1962 return -1;
liubin281ac462023-07-19 14:22:54 +08001963
q.huang8a993672025-06-24 16:19:46 +08001964 fd = open(path, O_RDONLY);
1965 if (fd < 0) {
liubin281ac462023-07-19 14:22:54 +08001966 LOGE("readFromMTD open error,%d", errno);
q.huang8a993672025-06-24 16:19:46 +08001967 return -1;
1968 }
liubin281ac462023-07-19 14:22:54 +08001969
q.huang8a993672025-06-24 16:19:46 +08001970 ret = lseek(fd, offset, SEEK_SET);
1971 if (ret < 0) {
1972 close(fd);
liubin281ac462023-07-19 14:22:54 +08001973 LOGE("readFromMTD lseek error,%d", errno);
q.huang8a993672025-06-24 16:19:46 +08001974 return -1;
1975 }
1976 ret = read(fd, buf, size);
1977 if (ret < 0) {
1978 close(fd);
liubin281ac462023-07-19 14:22:54 +08001979 LOGE("readFromMTD read error,%d", errno);
q.huang8a993672025-06-24 16:19:46 +08001980 return -1;
1981 }
1982 close(fd);
1983 return 0;
liubin281ac462023-07-19 14:22:54 +08001984}
1985
1986static int writeToMTD(const char *path, unsigned int offset, void *buf, int size)
1987{
q.huang8a993672025-06-24 16:19:46 +08001988 int ret, fd;
liubin281ac462023-07-19 14:22:54 +08001989
q.huang8a993672025-06-24 16:19:46 +08001990 if (!path)
1991 return -1;
liubin281ac462023-07-19 14:22:54 +08001992
q.huang8a993672025-06-24 16:19:46 +08001993 fd = open(path, O_RDWR | O_SYNC);
1994 if (fd < 0)
1995 return -1;
liubin281ac462023-07-19 14:22:54 +08001996
q.huang8a993672025-06-24 16:19:46 +08001997 ret = lseek(fd, offset, SEEK_SET);
1998 if (ret < 0) {
1999 close(fd);
2000 return -1;
2001 }
2002 ret = write(fd, buf, size);
2003 if (ret < 0) {
liubin281ac462023-07-19 14:22:54 +08002004 LOGE("writetomtd:write error:%d", errno);
q.huang8a993672025-06-24 16:19:46 +08002005 close(fd);
2006 return -1;
2007 }
liubin281ac462023-07-19 14:22:54 +08002008
q.huang8a993672025-06-24 16:19:46 +08002009 close(fd);
2010 return 0;
liubin281ac462023-07-19 14:22:54 +08002011}
b.liu9e8584b2024-11-06 19:21:28 +08002012#endif
liubin281ac462023-07-19 14:22:54 +08002013static void fota_result_check()
2014{
2015#if 0
2016 ASR_flag tag;
2017 char asr_flag_path[30] = {0};
2018 if(asrFlagPathGet(asr_flag_path)) {
2019 LOGE("getAsrFlagPath() fail.");
2020 return;
2021 }
2022
2023 if(readFromMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
2024 {
2025 LOGE("Get FOTA result fail.");
2026 }
2027 else
2028 {
2029 LOGD("FOTA result : %d, %d", tag.fota_result[0], tag.fota_result[1]);
2030 tag.fota_result[0] = 0;
2031 tag.fota_result[1] = 0;
2032 if(writeToMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
2033 {
2034 LOGE("FOTA result update fail.");
2035 } else {
2036 LOGD("FOTA result update success.");
2037 }
2038 }
2039#endif
2040}
2041
b.liubb590492024-06-13 16:42:08 +08002042static void mbtk_ril_ready()
liubin281ac462023-07-19 14:22:54 +08002043{
2044 // /etc/init.d/mbtk_boot_server_ready
b.liubb590492024-06-13 16:42:08 +08002045 if(is_first_boot) {
2046 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
2047 LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
b.liu9e8584b2024-11-06 19:21:28 +08002048 mbtk_system(MBTK_BOOT_SERVER_READY);
b.liubb590492024-06-13 16:42:08 +08002049 } else {
2050 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
2051 }
liubin281ac462023-07-19 14:22:54 +08002052 } else {
b.liubb590492024-06-13 16:42:08 +08002053 LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
liubin281ac462023-07-19 14:22:54 +08002054 }
2055}
2056
2057#if 1
2058int main(int argc, char *argv[])
2059{
2060 mbtk_log_init("radio", "MBTK_RIL");
b.liubb590492024-06-13 16:42:08 +08002061
b.liubcf86c92024-08-19 19:48:28 +08002062 MBTK_SOURCE_INFO_PRINT("mbtk_rild");
2063
b.liubb590492024-06-13 16:42:08 +08002064#ifdef MBTK_DUMP_SUPPORT
2065 mbtk_debug_open(NULL, TRUE);
2066#endif
2067
2068// Using Killall,the file lock may be not release.
2069#if 0
2070 if(app_already_running(MBTK_RILD_PID_FILE)) {
2071 LOGW("daemon already running.");
2072 exit(1);
2073 }
2074#endif
2075
liubin281ac462023-07-19 14:22:54 +08002076 LOGI("mbtk_ril start.");
2077
b.liubb590492024-06-13 16:42:08 +08002078 int fd = open(MBTK_RILD_TEMP_FILE, O_CREAT | O_RDWR, 0644);
2079 if(fd > 0) {
b.liu9e8584b2024-11-06 19:21:28 +08002080 char buff[100] = {0};
b.liubb590492024-06-13 16:42:08 +08002081 int count = 0;
2082 if(read(fd, buff, sizeof(buff)) > 0) {
2083 count = atoi(buff);
2084 } else {
2085 count = 0;
2086 }
2087
2088 if(count <= 0) {
2089 is_first_boot = TRUE;
2090 count = 0;
2091 } else {
2092 is_first_boot = FALSE;
2093 }
2094
2095 count++;
2096 memset(buff, 0, sizeof(buff));
2097 snprintf(buff, sizeof(buff), "%d", count);
b.liu9e8584b2024-11-06 19:21:28 +08002098 mbtk_write(fd, buff, strlen(buff));
b.liubb590492024-06-13 16:42:08 +08002099 close(fd);
2100 } else {
2101 is_first_boot = FALSE;
2102 LOGE("Open %s fail:%d", MBTK_RILD_TEMP_FILE, errno);
2103 LOGW("Will not exec %s and %s.", MBTK_BOOT_SERVER_READY, MBTK_BOOT_NET_READY);
2104 }
2105
liubin281ac462023-07-19 14:22:54 +08002106 if(InProduction_Mode()) {
2107 LOGI("Is Production Mode, will exit...");
2108 exit(0);
2109 }
2110
2111 int at_sock = openSocket("/tmp/atcmd_at");
2112 if(at_sock < 0)
2113 {
2114 LOGE("Open AT Socket Fail[%d].", errno);
2115 return -1;
2116 }
2117 int uart_sock = openSocket("/tmp/atcmd_urc");
2118 if(uart_sock < 0)
2119 {
2120 LOGE("Open Uart Socket Fail[%d].", errno);
2121 return -1;
2122 }
2123
2124 at_set_on_reader_closed(onATReaderClosed);
2125 at_set_on_timeout(onATTimeout);
2126
2127 if(at_open(at_sock, uart_sock, onUnsolicited))
2128 {
2129 LOGE("Start AT thread fail.");
2130 return -1;
2131 }
2132
2133#if 1
2134 if(at_handshake())
2135 {
2136 LOGE("AT handshake fail.");
2137 return -1;
2138 }
2139#endif
2140
2141 LOGD("AT OK.");
2142
2143 if(mbtk_info_server_start())
2144 {
2145 LOGE("mbtk_info_server_start() fail.");
2146 return -1;
2147 }
b.liubb590492024-06-13 16:42:08 +08002148
liuyang15f493d2024-09-12 17:45:41 +08002149 char led_enable_str[10];
2150 memset(led_enable_str, 0, 10);
2151 property_get("persist.mbtk.led_enable", led_enable_str, "1");
2152 if(atoi(led_enable_str) == 1) { // NTP time
2153 LOG("Start LED thread.");
2154 mbtk_led_init();
2155 }
liubin281ac462023-07-19 14:22:54 +08002156
2157#if 0
2158 if(uevent_main())
2159 {
2160 LOGE("Start uevent thread fail.");
2161 return -1;
2162 }
2163#endif
2164
2165 char time_type[10];
2166 memset(time_type, 0, 10);
2167 property_get("persist.mbtk.time_type", time_type, "0");
2168 if(atoi(time_type) == MBTK_TIME_TYPE_NTP) { // NTP time
2169 LOG("Start NTP thread.");
2170 ntp_thread_start();
2171 }
2172
2173 fota_result_check();
2174
b.liubb590492024-06-13 16:42:08 +08002175 mbtk_ril_ready();
liubin281ac462023-07-19 14:22:54 +08002176
2177 server_ready_set();//Set the server readiness state
2178 while(1)
2179 {
2180 sleep(24 * 60 * 60);
2181 }
2182
2183 LOGD("!!!mbtk_ril exit!!!");
2184 return 0;
2185}
2186
2187#else
2188int main()
2189{
2190 char buff[BUFFER_SIZE + 1] = {0};
2191 if(!mbtk_at("AT+CFUN=1", buff, BUFFER_SIZE))
2192 {
2193 LOGD("+CFUN RSP:%s", buff);
2194 while(1)
2195 {
2196 sleep(1);
2197 memset(buff, 0x0, BUFFER_SIZE + 1);
2198 if(!mbtk_at("AT+CGPADDR", buff, BUFFER_SIZE))
2199 {
2200 LOGD("+CGPADDR RSP:%s", buff);
2201 if(strstr(buff, "+CGPADDR:"))
2202 {
2203 // +CGPADDR: 1, "10.99.223.168", "254.128.0.0.0.0.0.0.0.1.0.0.117.9.250.59"
2204 //
2205 // OK
2206 char *ip_start = NULL;
2207 char *ip_end = NULL;
2208 char ipv4[50] = {0};
2209 ip_start = strstr(buff,"\"");
2210 if(ip_start)
2211 ip_end = strstr(ip_start + 1, "\"");
2212 if(ip_start && ip_end && ip_end - ip_start - 1 > 0)
2213 {
2214 memcpy(ipv4, ip_start + 1, ip_end - ip_start - 1);
2215 LOGD("IP : %s", ipv4);
2216 if(!mbtk_ifc_open())
2217 {
2218 in_addr_t addr;
2219 inet_aton(ipv4,(struct in_addr *)&addr);
2220 LOGD("IP : %s -> %x", ipv4, addr);
2221 if(!mbtk_ifc_set_addr("ccinet0", addr, 0))
2222 {
2223 mbtk_ifc_up("ccinet0");
2224 }
2225
2226 mbtk_ifc_close();
2227 }
2228
2229 system("route add default dev ccinet0");
2230
2231 LOGD("Set IP success.");
2232 }
2233 else
2234 {
2235 LOGD("Get IP fail.");
2236 }
2237
2238 break;
2239 }
2240 }
2241 }
2242 }
2243
2244 return 0;
2245}
2246#endif