blob: a527ed13836ada95986696d17848805717cf0d45 [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
950 if (at_tok_nextint(&line, &tmp_int) < 0)
951 {
952 goto EEMLTESVC_EXIT;
953 }
954 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //ul arfcn
955 if (at_tok_nextint(&line, &tmp_int) < 0)
956 {
957 goto EEMLTESVC_EXIT;
958 }
959 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //band
960 if (at_tok_nextint(&line, &tmp_int) < 0)
961 {
962 goto EEMLTESVC_EXIT;
963 }
964 if (at_tok_nextint(&line, &tmp_int) < 0)
965 {
966 goto EEMLTESVC_EXIT;
967 }
968 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //cid
969 if (at_tok_nextint(&line, &tmp_int) < 0)
970 {
971 goto EEMLTESVC_EXIT;
972 }
973 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //rsrp
974
975 for(i =0; i < 10; i++)
976 {
977 if (at_tok_nextint(&line, &tmp_int) < 0)
978 {
979 goto EEMLTESVC_EXIT;
980 }
981 }
982 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //cell identiy
983
b.liuaec91492025-05-24 10:52:26 +0800984 for(i =0; i < 28; i++)
985 {
986 if (at_tok_nextint(&line, &tmp_int) < 0)
987 {
988 goto EEMLTESVC_EXIT;
989 }
990 }
991
992 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //dlBler
993
liubin281ac462023-07-19 14:22:54 +0800994 cell_info.cell_num++;
995
b.liuaec91492025-05-24 10:52:26 +0800996 LOG("LTESVC cell_num : %d", cell_info.cell_num);
997
998
liubin281ac462023-07-19 14:22:54 +0800999EEMLTESVC_EXIT:
1000 free(free_ptr);
1001 }
1002 }
1003 /*
1004 // index,phyCellId,euArfcn,rsrp,rsrq
1005 +EEMLTEINTER: 0, 65535, 38950, 0, 0
1006 */
1007 else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
1008 {
1009 // phyCellId,euArfcn,rsrp,rsrq
1010 if(cell_info.running) {
1011 int tmp_int;
1012 char* tmp_s = memdup(s,strlen(s));
1013 char* free_ptr = tmp_s;
1014 char *line = tmp_s;
1015 if (at_tok_start(&line) < 0)
1016 {
1017 goto EEMLTEINTER_EXIT;
1018 }
1019 if (at_tok_nextint(&line, &tmp_int) < 0)
1020 {
1021 goto EEMLTEINTER_EXIT;
1022 }
1023 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1024 {
1025 goto EEMLTEINTER_EXIT;
1026 }
1027 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1028 if (at_tok_nextint(&line, &tmp_int) < 0)
1029 {
1030 goto EEMLTEINTER_EXIT;
1031 }
1032 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1033 if (at_tok_nextint(&line, &tmp_int) < 0)
1034 {
1035 goto EEMLTEINTER_EXIT;
1036 }
1037 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1038 LOG("cell line : %s", line);
1039 if (at_tok_nextint(&line, &tmp_int) < 0)
1040 {
1041 goto EEMLTEINTER_EXIT;
1042 }
1043 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1044 if (at_tok_nextint(&line, &tmp_int) < 0)
1045 {
1046 LOG("cell tmp_int : %d", tmp_int);
1047 goto EEMLTEINTER_EXIT;
1048 }
1049 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1050 LOG("cell value5 : %d", cell_info.cell[cell_info.cell_num].value5);
b.liuaec91492025-05-24 10:52:26 +08001051
1052 LOG("after cellid cell line : %s", line);
1053 if (at_tok_nextint(&line, &tmp_int) < 0)
1054 {
1055 goto EEMLTEINTER_EXIT;
1056 }
1057 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
1058
1059 if (at_tok_nextint(&line, &tmp_int) < 0)
1060 {
1061 LOG("exit");
1062 goto EEMLTEINTER_EXIT;
1063 }
1064
1065 if (at_tok_nextint(&line, &tmp_int) < 0)
1066 {
1067 LOG("exit");
1068 goto EEMLTEINTER_EXIT;
1069 }
1070
1071 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
1072
1073 if (at_tok_nextint(&line, &tmp_int) < 0)
1074 {
1075 LOG("exit");
1076 goto EEMLTEINTER_EXIT;
1077 }
1078
1079 if (at_tok_nextint(&line, &tmp_int) < 0)
1080 {
1081 LOG("exit");
1082 goto EEMLTEINTER_EXIT;
1083 }
1084
1085 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //cellId
1086 LOG("cell value8 : %u", (uint32)cell_info.cell[cell_info.cell_num].value9);
1087 for(int i =0; i < 5; i++)
1088 {
1089 if (at_tok_nextint(&line, &tmp_int) < 0)
1090 {
1091 LOG("exit i = %d",i);
1092 goto EEMLTEINTER_EXIT;
1093 }
1094 }
1095
1096 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //band
1097 LOG("cell value9 : %d", cell_info.cell[cell_info.cell_num].value9);
1098 if (at_tok_nextint(&line, &tmp_int) < 0)
1099 {
1100 LOG("exit");
1101 goto EEMLTEINTER_EXIT;
1102 }
1103
1104 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //rssi
1105
liubin281ac462023-07-19 14:22:54 +08001106 cell_info.cell_num++;
1107EEMLTEINTER_EXIT:
1108 free(free_ptr);
1109 }
1110 }
1111 // Do nothing
1112 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
1113 {
1114 if(cell_info.running) {
1115
1116 }
1117 }
1118 // WCDMA
1119 /*
1120 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1121
1122 // if sCMeasPresent == 1
1123 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1124 // endif
1125
1126 // if sCParamPresent == 1
1127 // rac, nom, mcc, mnc_len, mnc, lac, ci,
1128 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1129 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1130 // endif
1131
1132 // if ueOpStatusPresent == 1
1133 // rrcState, numLinks, srncId, sRnti,
1134 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1135 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1136 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1137 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1138 // endif
1139 //
1140 +EEMUMTSSVC: 3, 1, 1, 1,
1141 -80, 27, -6, -18, -115, -32768,
1142 1, 1, 1120, 2, 1, 61697, 168432821,
1143 15, 24, 10763, 0, 0, 0, 0,
1144 128, 128, 65535, 0, 0,
1145 2, 255, 65535, 4294967295,
1146 0, 0, 0, 0, 0, 0,
1147 0, 0, 0, 0, 0, 0, 1, 1,
1148 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1149 0, 0, 0, 0, 0, 0
1150 */
1151 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1152 {
1153 // lac, ci, arfcn
1154 if(cell_info.running) {
1155 int tmp_int;
1156 int i = 0;
1157 char* tmp_s = memdup(s,strlen(s));
1158 char* free_ptr = tmp_s;
1159 char *line = tmp_s;
1160 if (at_tok_start(&line) < 0)
1161 {
1162 goto EEMUMTSSVC_EXIT;
1163 }
1164 // Jump 12 integer.
1165 i = 0;
1166 while(i < 12) {
1167 if (at_tok_nextint(&line, &tmp_int) < 0)
1168 {
1169 goto EEMUMTSSVC_EXIT;
1170 }
1171 i++;
1172 }
1173 // mcc
1174 if (at_tok_nextint(&line, &tmp_int) < 0)
1175 {
1176 goto EEMUMTSSVC_EXIT;
1177 }
1178 cell_info.cell[cell_info.cell_num].value4= (uint32)tmp_int;
1179 // mnc
1180 if (at_tok_nextint(&line, &tmp_int) < 0)
1181 {
1182 goto EEMUMTSSVC_EXIT;
1183 }
1184 cell_info.cell[cell_info.cell_num].value5= (uint32)tmp_int;
1185 // lac
1186 if (at_tok_nextint(&line, &tmp_int) < 0)
1187 {
1188 goto EEMUMTSSVC_EXIT;
1189 }
1190 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1191 // ci
1192 if (at_tok_nextint(&line, &tmp_int) < 0)
1193 {
1194 goto EEMUMTSSVC_EXIT;
1195 }
1196 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1197
1198 if (at_tok_nextint(&line, &tmp_int) < 0)
1199 {
1200 goto EEMUMTSSVC_EXIT;
1201 }
1202 // cpi
1203 if (at_tok_nextint(&line, &tmp_int) < 0)
1204 {
1205 goto EEMUMTSSVC_EXIT;
1206 }
1207 cell_info.cell[cell_info.cell_num].value6= (uint32)tmp_int;
1208 /*
1209 // Jump 2 integer.
1210 i = 0;
1211 while(i < 2) {
1212 if (at_tok_nextint(&line, &tmp_int) < 0)
1213 {
1214 goto EEMUMTSSVC_EXIT;
1215 }
1216 i++;
1217 }
1218 */
1219 // arfcn
1220 if (at_tok_nextint(&line, &tmp_int) < 0)
1221 {
1222 goto EEMUMTSSVC_EXIT;
1223 }
1224 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1225
1226 cell_info.cell_num++;
1227EEMUMTSSVC_EXIT:
1228 free(free_ptr);
1229 }
1230 }
1231 /*
1232 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1233 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1234 */
1235 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1236 {
1237 // lac, ci, arfcn
1238 if(cell_info.running) {
1239 int tmp_int;
1240 int i = 0;
1241 char* tmp_s = memdup(s,strlen(s));
1242 char* free_ptr = tmp_s;
1243 char *line = tmp_s;
1244 if (at_tok_start(&line) < 0)
1245 {
1246 goto EEMUMTSINTRA_EXIT;
1247 }
1248 // Jump 8 integer.
1249 i = 0;
1250 while(i < 8) {
1251 if (at_tok_nextint(&line, &tmp_int) < 0)
1252 {
1253 goto EEMUMTSINTRA_EXIT;
1254 }
1255 i++;
1256 }
1257
1258 // lac
1259 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1260 {
1261 goto EEMUMTSINTRA_EXIT;
1262 }
1263 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1264
1265 // ci
1266 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1267 {
1268 goto EEMUMTSINTRA_EXIT;
1269 }
1270 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1271
1272 // arfcn
1273 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1274 {
1275 goto EEMUMTSINTRA_EXIT;
1276 }
1277 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1278
1279 cell_info.cell_num++;
1280EEMUMTSINTRA_EXIT:
1281 free(free_ptr);
1282 }
1283 }
1284 /*
1285 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1286 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1287 */
1288 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1289 {
1290 // lac, ci, arfcn
1291 if(cell_info.running) {
1292 int tmp_int;
1293 int i = 0;
1294 char* tmp_s = memdup(s,strlen(s));
1295 char* free_ptr = tmp_s;
1296 char *line = tmp_s;
1297 if (at_tok_start(&line) < 0)
1298 {
1299 goto EEMUMTSINTERRAT_EXIT;
1300 }
1301 // Jump 7 integer.
1302 i = 0;
1303 while(i < 7) {
1304 if (at_tok_nextint(&line, &tmp_int) < 0)
1305 {
1306 goto EEMUMTSINTERRAT_EXIT;
1307 }
1308 i++;
1309 }
1310
1311 // lac
1312 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1313 {
1314 goto EEMUMTSINTERRAT_EXIT;
1315 }
1316 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1317
1318 // ci
1319 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1320 {
1321 goto EEMUMTSINTERRAT_EXIT;
1322 }
1323 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1324
1325 // arfcn
1326 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1327 {
1328 goto EEMUMTSINTERRAT_EXIT;
1329 }
1330 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1331
1332 cell_info.cell_num++;
1333EEMUMTSINTERRAT_EXIT:
1334 free(free_ptr);
1335 }
1336 }
1337 // GSM
1338 // +EEMGINFOBASIC: 2
1339 // Do nothing.
1340 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1341 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1342 {
1343 if(cell_info.running) {
1344
1345 }
1346 }
1347 /*
1348 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1349 // bsic, C1, C2, TA, TxPwr,
1350 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1351 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1352 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1353 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1354 // gsmBand,channelMode
1355 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1356 63, 36, 146, 1, 7,
1357 46, 42, 42, 7, 0,
1358 53, 0, 8, 0, 1, 6, 53,
1359 2, 0, 146, 42, 54, 0, 1,
1360 1, 32, 0, 0, 0, 0,
1361 0, 0
1362 */
1363 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1364 {
1365 // lac, ci, arfcn, bsic
1366 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1367 if(cell_info.running) {
1368 int tmp_int;
1369 int i = 0;
1370 char* tmp_s = memdup(s,strlen(s));
1371 char* free_ptr = tmp_s;
1372 char *line = tmp_s;
1373 if (at_tok_start(&line) < 0)
1374 {
1375 goto EEMGINFOSVC_EXIT;
1376 }
1377
1378 // mcc
1379 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1380 {
1381 goto EEMGINFOSVC_EXIT;
1382 }
1383 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1384
1385 //mnc_len
1386 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1387 {
1388 goto EEMGINFOSVC_EXIT;
1389 }
1390 // mnc
1391 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1392 {
1393 goto EEMGINFOSVC_EXIT;
1394 }
1395 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1396
1397 /*
1398 // Jump 3 integer.
1399 i = 0;
1400 while(i < 3) {
1401 if (at_tok_nextint(&line, &tmp_int) < 0)
1402 {
1403 goto EEMGINFOSVC_EXIT;
1404 }
1405 i++;
1406 }
1407 */
1408 // lac
1409 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1410 {
1411 goto EEMGINFOSVC_EXIT;
1412 }
1413 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1414
1415 // ci
1416 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1417 {
1418 goto EEMGINFOSVC_EXIT;
1419 }
1420 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1421
1422 // Jump 2 integer.
1423 i = 0;
1424 while(i < 2) {
1425 if (at_tok_nextint(&line, &tmp_int) < 0)
1426 {
1427 goto EEMGINFOSVC_EXIT;
1428 }
1429 i++;
1430 }
1431
1432 // bsic
1433 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1434 {
1435 goto EEMGINFOSVC_EXIT;
1436 }
1437 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1438
1439 // Jump 15 integer.
1440 i = 0;
1441 while(i < 15) {
1442 if (at_tok_nextint(&line, &tmp_int) < 0)
1443 {
1444 goto EEMGINFOSVC_EXIT;
1445 }
1446 i++;
1447 }
1448
1449 // arfcn
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].value3 = (uint32)tmp_int;
1455
1456 cell_info.cell_num++;
1457EEMGINFOSVC_EXIT:
1458 free(free_ptr);
1459 }
1460 }
1461 /*
1462 // PS_attached, attach_type, service_type, tx_power, c_value,
1463 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1464 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1465 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1466 +EEMGINFOPS: 1, 255, 0, 0, 0,
1467 0, 0, 268435501, 1, 0, 0,
1468 4, 0, 96, 0, 0, 0,
1469 0, 0, 0, 65535, 0, 13350
1470 */
1471 // Do nothing.
1472 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1473 {
1474 if(cell_info.running) {
1475
1476 }
1477 }
1478 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1479 {
1480 if(cell_info.running) {
1481 int tmp_int;
1482 int i = 0;
1483 char* tmp_s = memdup(s,strlen(s));
1484 char* free_ptr = tmp_s;
1485 char *line = tmp_s;
1486 if (at_tok_start(&line) < 0)
1487 {
1488 goto EEMGINFOPS_EXIT;
1489 }
1490
1491 // nc_num
1492 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1493 {
1494 LOG("cell_info.running 1= %d\n.",cell_info.running);
1495 goto EEMGINFOPS_EXIT;
1496 }
1497 // mcc
1498 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1499 {
1500 LOG("cell_info.running 2= %d\n.",cell_info.running);
1501 goto EEMGINFOPS_EXIT;
1502 }
1503 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1504
1505 // mnc
1506 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1507 {
1508 LOG("cell_info.running 3= %d\n.",cell_info.running);
1509 goto EEMGINFOPS_EXIT;
1510 }
1511 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1512
1513 // lac
1514 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1515 {
1516 LOG("cell_info.running 4= %d\n.",cell_info.running);
1517 goto EEMGINFOPS_EXIT;
1518 }
1519 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1520
1521 // rac
1522 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1523 {
1524 LOG("cell_info.running 5= %d\n.",cell_info.running);
1525 goto EEMGINFOPS_EXIT;
1526 }
1527
1528 // ci
1529 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1530 {
1531 LOG("cell_info.running 6= %d\n.",cell_info.running);
1532 goto EEMGINFOPS_EXIT;
1533 }
1534 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1535
1536 // rx_lv
1537 if (at_tok_nextint(&line, &tmp_int) < 0)
1538 {
1539 LOG("cell_info.running 7= %d\n.",cell_info.running);
1540 goto EEMGINFOPS_EXIT;
1541 }
1542
1543 // bsic
1544 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1545 {
1546 LOG("cell_info.running 8= %d\n.",cell_info.running);
1547 goto EEMGINFOPS_EXIT;
1548 }
1549 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1550
1551 // Jump 2 integer.
1552 i = 0;
1553 while(i < 2) {
1554 if (at_tok_nextint(&line, &tmp_int) < 0)
1555 {
1556 LOG("cell_info.running 9= %d\n.",cell_info.running);
1557 goto EEMGINFOPS_EXIT;
1558 }
1559 i++;
1560 }
1561
1562 // arfcn
1563 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1564 {
1565 LOG("cell_info.running 10 = %d\n.",cell_info.running);
1566 goto EEMGINFOPS_EXIT;
1567 }
1568 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1569
1570 cell_info.cell_num++;
1571EEMGINFOPS_EXIT:
1572 free(free_ptr);
1573 }
1574 }
1575 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"
1576 {
1577
1578 }
1579 else
1580 {
1581 LOGV("Unknown URC : %s", s);
1582 }
1583}
1584
1585static int openSocket(const char* sockname)
1586{
1587 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
1588 if (sock < 0)
1589 {
1590 LOGE("Error create socket: %s\n", strerror(errno));
1591 return -1;
1592 }
1593 struct sockaddr_un addr;
1594 memset(&addr, 0, sizeof(addr));
1595 addr.sun_family = AF_UNIX;
1596 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
1597 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
1598 {
1599 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
1600 sleep(1);
1601 }
1602
1603#if 0
1604 int sk_flags = fcntl(sock, F_GETFL, 0);
1605 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
1606#endif
1607
1608 return sock;
1609}
1610
b.liu9e8584b2024-11-06 19:21:28 +08001611#if 0
liubin281ac462023-07-19 14:22:54 +08001612static void ril_get_cgpaddr_ip_process()
1613{
1614 int err, skip;
1615 ATResponse *p_response = NULL;
1616 char *line;
1617 char *ipv4 = NULL, *ipv6 = NULL;
1618 err = at_send_command_singleline("AT+CGPADDR", "+CGPADDR:", &p_response);
1619 if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
1620 {
1621 LOGE("+CGPADDR exec error.");
1622 goto error;
1623 }
1624
1625 // +CGPADDR: 1, "10.51.59.229", "254.128.0.0.0.0.0.0.0.1.0.0.111.176.63.99"
1626 // +CGPADDR: 1, "10.124.139.131"
1627 line = p_response->p_intermediates->line;
1628 err = at_tok_start(&line);
1629 if (err < 0)
1630 {
1631 goto error;
1632 }
1633
1634 err = at_tok_nextint(&line, &skip);
1635 if (err < 0)
1636 {
1637 goto error;
1638 }
1639
1640 if (!at_tok_hasmore(&line))
1641 {
1642 goto error;
1643 }
1644
1645 err = at_tok_nextstr(&line, &ipv4);
1646 if (err < 0)
1647 {
1648 LOGE("Get IPv4 fail.");
1649 goto error;
1650 }
1651
1652 if (at_tok_hasmore(&line))
1653 {
1654 err = at_tok_nextstr(&line, &ipv6);
1655 if (err < 0)
1656 {
1657 LOGE("Get IPv6 fail.");
1658 goto error;
1659 }
1660 }
1661 else
1662 {
1663 LOGD("No IPv6 Found.");
1664 }
1665
1666 if(ipv6)
1667 {
1668 LOGD("IPv6 : %s", ipv6);
1669 }
1670
1671 if(ipv4)
1672 {
1673 LOGD("IPv4 : %s", ipv4);
1674
1675// ril_net_dev_config("ccinet0", ipv4, NULL);
1676 }
1677error:
1678 at_response_free(p_response);
1679}
b.liu9e8584b2024-11-06 19:21:28 +08001680#endif
liubin281ac462023-07-19 14:22:54 +08001681
1682static void sim_state_change(bool plug_in) {
1683 if(plug_in) {
1684 // If radio on,must off in the first.
1685 if(net_info.radio_state == MBTK_RADIO_STATE_ON) {
1686 setRadioPower(0);
1687 }
1688 setRadioPower(1);
1689 } else {
1690 setRadioPower(0);
1691 }
1692}
1693
1694static int open_uevent_socket()
1695{
1696 struct sockaddr_nl addr;
1697 int sz = 64*1024;
1698 int s = 0;
1699
1700 memset(&addr, 0, sizeof(addr));
1701 addr.nl_family = AF_NETLINK;
1702 addr.nl_pid = getpid();
1703 addr.nl_groups = 0xffffffff;
1704
1705 s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
1706 if (s < 0)
1707 {
1708 LOGE("socket() fail.[%d]", errno);
1709 return -1;
1710 }
1711
1712 setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz));
1713
1714 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0)
1715 {
1716 close(s);
1717 return -1;
1718 }
1719
1720 return s;
1721}
1722
1723static void parse_uevent(const char *msg, int msg_len, struct cooling_device *cdev)
1724{
1725 // change@/devices/virtual/usim_event/usim0\0
1726 // ACTION=change\0
1727 // DEVPATH=/devices/virtual/usim_event/usim0\0
1728 // SUBSYSTEM=usim_event\0
1729 // USIM_NAME=usim0\0
1730 // USIM_EVENT=plugout\0
1731 // SEQNUM=704
1732 int i = 0;
1733 while (i < msg_len)
1734 {
1735 if(*(msg + i) == '\0')
1736 {
1737 i++;
1738 continue;
1739 }
1740 if (!strncmp(msg + i, "USIM_NAME=", 10))
1741 {
1742 i += 10;
1743 cdev->name = msg + i;
1744 i += strlen(msg + i);
1745 }
1746 else if (!strncmp(msg + i, "ACTION=", 7))
1747 {
1748 i += 7;
1749 cdev->action = msg + i;
1750 i += strlen(msg + i);
1751 }
1752 else if (!strncmp(msg + i, "DEVPATH=", 8))
1753 {
1754 i += 8;
1755 cdev->path = msg + i;
1756 i += strlen(msg + i);
1757 }
1758 else if (!strncmp(msg + i, "USIM_EVENT=", 11))
1759 {
1760 i += 11;
1761 cdev->event = msg + i;
1762 i += strlen(msg + i);
1763 }
1764 else if (!strncmp(msg + i, "SUBSYSTEM=", 10))
1765 {
1766 i += 10;
1767 cdev->subsystem = msg + i;
1768 i += strlen(msg + i);
1769 }
1770 else
1771 {
1772 i++;
1773 }
1774 }
1775
1776 if(!strncmp(cdev->path, UEVENT_USIM_DEV, sizeof(UEVENT_USIM_DEV))
1777 && !strncmp(cdev->action, "change", 5))
1778 {
1779 LOGD("event { name=%s, action=%s, path=%s, subsystem=%s, event=%s}",
1780 cdev->name, cdev->action, cdev->path, cdev->subsystem, cdev->event);
1781 if(!strcmp(cdev->event, "plugout"))
1782 {
1783 sim_state_change(FALSE);
1784 }
1785 else if(!strcmp(cdev->event, "plugin"))
1786 {
1787 sim_state_change(TRUE);
1788 }
1789 else
1790 {
1791 LOGE("usim evnet error!");
1792 }
1793 }
1794}
1795
1796static void* uevnet_run(void *payload)
1797{
1798 int socket_fd = -1;
1799 char msg[BUFFER_SIZE+2];
1800 int n;
1801
1802 socket_fd = open_uevent_socket();
1803 if(socket_fd > 0)
1804 {
1805 while(1)
1806 {
1807 if((n = recv(socket_fd, msg, BUFFER_SIZE, 0)) > 0)
1808 {
1809 struct cooling_device cdev;
1810 memset(&cdev, 0x0, sizeof(cdev));
1811
1812 if(n == BUFFER_SIZE)
1813 continue;
1814 msg[n] = '\0';
1815 // 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
1816 log_hex("UEVENT", msg, n);
1817 parse_uevent(msg, n, &cdev);
1818 }
1819 else
1820 {
1821 LOGE("recv msg error.");
1822 }
1823 }
1824 }
1825
1826 LOGD("UEVENT Thread exit!!!");
1827 return NULL;
1828}
1829
1830int uevent_main()
1831{
1832 mbtk_task_info task;
1833 task.task_id = &uevnet_task_id;
1834 task.thread_run = uevnet_run;
1835 task.args = NULL;
1836 return mbtk_task_start(&task);
1837}
1838
1839/*
1840int ril_main()
1841{
1842 return mbtk_task_queue_start(&ril_task, ril_main_run);
1843}
1844*/
1845
1846int mbtk_info_server_start();
1847int InProduction_Mode(void);
1848void server_ready_set(void);
1849
b.liu9e8584b2024-11-06 19:21:28 +08001850#if 0
liubin281ac462023-07-19 14:22:54 +08001851
1852/*
1853 *Get mtdblock which name is ASR_FLAG
1854 *return path if found, else return NULL
1855 */
1856static int asrFlagPathGet(char *asr_flag_path)
1857{
1858 char buf[128];
1859 unsigned char find = 0;
1860 FILE *fd = fopen("/proc/mtd", "r");
1861 if (fd == NULL) {
1862 LOGE("Open MTD failed!");
1863 return -1;
1864 }
1865
1866 memset(buf, '\0', 128);
1867 while (fgets(buf, 128, fd) != NULL) {
1868 if(strstr(buf, "asr_flag")) {
1869 char *p = strstr(buf, "mtd");
1870 if(p)
1871 {
1872 int bln;
1873 sscanf(p, "mtd%d", &bln);
1874 sprintf(asr_flag_path, "/dev/mtdblock%d", bln);
1875 find = 1;
1876 break;
1877 }
1878 }
1879 memset(buf, '\0', 128);
1880 }
1881
1882 fclose(fd);
1883 return ((find == 1) ? 0 : -1);
1884}
b.liu9e8584b2024-11-06 19:21:28 +08001885
liubin281ac462023-07-19 14:22:54 +08001886static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)
1887{
1888 int ret, fd;
1889 if (!path)
1890 return -1;
1891
1892 fd = open(path, O_RDONLY);
1893 if (fd < 0) {
1894 LOGE("readFromMTD open error,%d", errno);
1895 return -1;
1896 }
1897
1898 ret = lseek(fd, offset, SEEK_SET);
1899 if (ret < 0) {
1900 close(fd);
1901 LOGE("readFromMTD lseek error,%d", errno);
1902 return -1;
1903 }
1904 ret = read(fd, buf, size);
1905 if (ret < 0) {
1906 close(fd);
1907 LOGE("readFromMTD read error,%d", errno);
1908 return -1;
1909 }
1910 close(fd);
1911 return 0;
1912}
1913
1914static int writeToMTD(const char *path, unsigned int offset, void *buf, int size)
1915{
1916 int ret, fd;
1917
1918 if (!path)
1919 return -1;
1920
1921 fd = open(path, O_RDWR | O_SYNC);
1922 if (fd < 0)
1923 return -1;
1924
1925 ret = lseek(fd, offset, SEEK_SET);
1926 if (ret < 0) {
1927 close(fd);
1928 return -1;
1929 }
1930 ret = write(fd, buf, size);
1931 if (ret < 0) {
1932 LOGE("writetomtd:write error:%d", errno);
1933 close(fd);
1934 return -1;
1935 }
1936
1937 close(fd);
1938 return 0;
1939}
b.liu9e8584b2024-11-06 19:21:28 +08001940#endif
liubin281ac462023-07-19 14:22:54 +08001941static void fota_result_check()
1942{
1943#if 0
1944 ASR_flag tag;
1945 char asr_flag_path[30] = {0};
1946 if(asrFlagPathGet(asr_flag_path)) {
1947 LOGE("getAsrFlagPath() fail.");
1948 return;
1949 }
1950
1951 if(readFromMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
1952 {
1953 LOGE("Get FOTA result fail.");
1954 }
1955 else
1956 {
1957 LOGD("FOTA result : %d, %d", tag.fota_result[0], tag.fota_result[1]);
1958 tag.fota_result[0] = 0;
1959 tag.fota_result[1] = 0;
1960 if(writeToMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
1961 {
1962 LOGE("FOTA result update fail.");
1963 } else {
1964 LOGD("FOTA result update success.");
1965 }
1966 }
1967#endif
1968}
1969
b.liubb590492024-06-13 16:42:08 +08001970static void mbtk_ril_ready()
liubin281ac462023-07-19 14:22:54 +08001971{
1972 // /etc/init.d/mbtk_boot_server_ready
b.liubb590492024-06-13 16:42:08 +08001973 if(is_first_boot) {
1974 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
1975 LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
b.liu9e8584b2024-11-06 19:21:28 +08001976 mbtk_system(MBTK_BOOT_SERVER_READY);
b.liubb590492024-06-13 16:42:08 +08001977 } else {
1978 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
1979 }
liubin281ac462023-07-19 14:22:54 +08001980 } else {
b.liubb590492024-06-13 16:42:08 +08001981 LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
liubin281ac462023-07-19 14:22:54 +08001982 }
1983}
1984
1985#if 1
1986int main(int argc, char *argv[])
1987{
1988 mbtk_log_init("radio", "MBTK_RIL");
b.liubb590492024-06-13 16:42:08 +08001989
b.liubcf86c92024-08-19 19:48:28 +08001990 MBTK_SOURCE_INFO_PRINT("mbtk_rild");
1991
b.liubb590492024-06-13 16:42:08 +08001992#ifdef MBTK_DUMP_SUPPORT
1993 mbtk_debug_open(NULL, TRUE);
1994#endif
1995
1996// Using Killall,the file lock may be not release.
1997#if 0
1998 if(app_already_running(MBTK_RILD_PID_FILE)) {
1999 LOGW("daemon already running.");
2000 exit(1);
2001 }
2002#endif
2003
liubin281ac462023-07-19 14:22:54 +08002004 LOGI("mbtk_ril start.");
2005
b.liubb590492024-06-13 16:42:08 +08002006 int fd = open(MBTK_RILD_TEMP_FILE, O_CREAT | O_RDWR, 0644);
2007 if(fd > 0) {
b.liu9e8584b2024-11-06 19:21:28 +08002008 char buff[100] = {0};
b.liubb590492024-06-13 16:42:08 +08002009 int count = 0;
2010 if(read(fd, buff, sizeof(buff)) > 0) {
2011 count = atoi(buff);
2012 } else {
2013 count = 0;
2014 }
2015
2016 if(count <= 0) {
2017 is_first_boot = TRUE;
2018 count = 0;
2019 } else {
2020 is_first_boot = FALSE;
2021 }
2022
2023 count++;
2024 memset(buff, 0, sizeof(buff));
2025 snprintf(buff, sizeof(buff), "%d", count);
b.liu9e8584b2024-11-06 19:21:28 +08002026 mbtk_write(fd, buff, strlen(buff));
b.liubb590492024-06-13 16:42:08 +08002027 close(fd);
2028 } else {
2029 is_first_boot = FALSE;
2030 LOGE("Open %s fail:%d", MBTK_RILD_TEMP_FILE, errno);
2031 LOGW("Will not exec %s and %s.", MBTK_BOOT_SERVER_READY, MBTK_BOOT_NET_READY);
2032 }
2033
liubin281ac462023-07-19 14:22:54 +08002034 if(InProduction_Mode()) {
2035 LOGI("Is Production Mode, will exit...");
2036 exit(0);
2037 }
2038
2039 int at_sock = openSocket("/tmp/atcmd_at");
2040 if(at_sock < 0)
2041 {
2042 LOGE("Open AT Socket Fail[%d].", errno);
2043 return -1;
2044 }
2045 int uart_sock = openSocket("/tmp/atcmd_urc");
2046 if(uart_sock < 0)
2047 {
2048 LOGE("Open Uart Socket Fail[%d].", errno);
2049 return -1;
2050 }
2051
2052 at_set_on_reader_closed(onATReaderClosed);
2053 at_set_on_timeout(onATTimeout);
2054
2055 if(at_open(at_sock, uart_sock, onUnsolicited))
2056 {
2057 LOGE("Start AT thread fail.");
2058 return -1;
2059 }
2060
2061#if 1
2062 if(at_handshake())
2063 {
2064 LOGE("AT handshake fail.");
2065 return -1;
2066 }
2067#endif
2068
2069 LOGD("AT OK.");
2070
2071 if(mbtk_info_server_start())
2072 {
2073 LOGE("mbtk_info_server_start() fail.");
2074 return -1;
2075 }
b.liubb590492024-06-13 16:42:08 +08002076
liuyang15f493d2024-09-12 17:45:41 +08002077 char led_enable_str[10];
2078 memset(led_enable_str, 0, 10);
2079 property_get("persist.mbtk.led_enable", led_enable_str, "1");
2080 if(atoi(led_enable_str) == 1) { // NTP time
2081 LOG("Start LED thread.");
2082 mbtk_led_init();
2083 }
liubin281ac462023-07-19 14:22:54 +08002084
2085#if 0
2086 if(uevent_main())
2087 {
2088 LOGE("Start uevent thread fail.");
2089 return -1;
2090 }
2091#endif
2092
2093 char time_type[10];
2094 memset(time_type, 0, 10);
2095 property_get("persist.mbtk.time_type", time_type, "0");
2096 if(atoi(time_type) == MBTK_TIME_TYPE_NTP) { // NTP time
2097 LOG("Start NTP thread.");
2098 ntp_thread_start();
2099 }
2100
2101 fota_result_check();
2102
b.liubb590492024-06-13 16:42:08 +08002103 mbtk_ril_ready();
liubin281ac462023-07-19 14:22:54 +08002104
2105 server_ready_set();//Set the server readiness state
2106 while(1)
2107 {
2108 sleep(24 * 60 * 60);
2109 }
2110
2111 LOGD("!!!mbtk_ril exit!!!");
2112 return 0;
2113}
2114
2115#else
2116int main()
2117{
2118 char buff[BUFFER_SIZE + 1] = {0};
2119 if(!mbtk_at("AT+CFUN=1", buff, BUFFER_SIZE))
2120 {
2121 LOGD("+CFUN RSP:%s", buff);
2122 while(1)
2123 {
2124 sleep(1);
2125 memset(buff, 0x0, BUFFER_SIZE + 1);
2126 if(!mbtk_at("AT+CGPADDR", buff, BUFFER_SIZE))
2127 {
2128 LOGD("+CGPADDR RSP:%s", buff);
2129 if(strstr(buff, "+CGPADDR:"))
2130 {
2131 // +CGPADDR: 1, "10.99.223.168", "254.128.0.0.0.0.0.0.0.1.0.0.117.9.250.59"
2132 //
2133 // OK
2134 char *ip_start = NULL;
2135 char *ip_end = NULL;
2136 char ipv4[50] = {0};
2137 ip_start = strstr(buff,"\"");
2138 if(ip_start)
2139 ip_end = strstr(ip_start + 1, "\"");
2140 if(ip_start && ip_end && ip_end - ip_start - 1 > 0)
2141 {
2142 memcpy(ipv4, ip_start + 1, ip_end - ip_start - 1);
2143 LOGD("IP : %s", ipv4);
2144 if(!mbtk_ifc_open())
2145 {
2146 in_addr_t addr;
2147 inet_aton(ipv4,(struct in_addr *)&addr);
2148 LOGD("IP : %s -> %x", ipv4, addr);
2149 if(!mbtk_ifc_set_addr("ccinet0", addr, 0))
2150 {
2151 mbtk_ifc_up("ccinet0");
2152 }
2153
2154 mbtk_ifc_close();
2155 }
2156
2157 system("route add default dev ccinet0");
2158
2159 LOGD("Set IP success.");
2160 }
2161 else
2162 {
2163 LOGD("Get IP fail.");
2164 }
2165
2166 break;
2167 }
2168 }
2169 }
2170 }
2171
2172 return 0;
2173}
2174#endif