blob: 22e739caa0e4ea731c52bb7b206bb82cf394d4e1 [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
220 uint8 data_pdp;
221 data_pdp = 1; //
222 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
223 }
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.wangd58f71e2024-08-21 23:45:31 -0700243 if(at_process && !at_cfun_command) {
liubin281ac462023-07-19 14:22:54 +0800244 if(cgact_wait.act) {
245 if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT 15,4
246 if(cgact_wait.cid == atoi(s + 18)) {
247 cgact_wait.waitting = false;
248 }
249
250 uint8 data_pdp;
251 char* tmp_s = memdup(s + 18,strlen(s + 18));
252 char* free_ptr = tmp_s;
253 char *line = tmp_s;
254 int tmp_int;
255 if (at_tok_start(&line) < 0)
256 {
257 goto at_PDP_CREG_EXIT;
258 }
259 if (at_tok_nextint(&line, &tmp_int) < 0)
260 {
261 goto at_PDP_CREG_EXIT;
262 }
263 if (at_tok_nextint(&line, &tmp_int) < 0)
264 {
265 goto at_PDP_CREG_EXIT;
266 }
267 data_pdp = tmp_int;
268at_PDP_CREG_EXIT:
269 free(free_ptr);
270
271 //data_pdp = (uint8)atoi(s + 20); //reason
272 if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
273 {
274 if(data_pdp == 0)
275 {
276 data_pdp = 25;
277 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
278 //data_pdp = cgact_wait.cid + 200;
279 }
280 else if(data_pdp == 1)
281 {
282 data_pdp = 26;
283 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
284 }
285 else if(data_pdp == 2)
286 {
287 data_pdp = 27;
288 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
289 }
290 else if(data_pdp == 3)
291 {
292 data_pdp = 27;
293 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
294 }
295 else
296 {
297
298 }
299 if(cgact_wait.cid != 0)
300 {
301 data_pdp = cgact_wait.cid + 200;
b.liuf77b86c2024-11-09 13:24:10 +0800302 urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
liubin281ac462023-07-19 14:22:54 +0800303 }
304 }
305 } else if(strStartsWith(s, "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY 1,4
306 if(cgact_wait.cid == atoi(s + 17)) {
307 cgact_wait.waitting = false;
308 }
309 }
310 } else {
311 if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
312 if(cgact_wait.cid == atoi(s + 20)) {
313 cgact_wait.waitting = false;
314 }
315 uint8 data_pdp;
316 data_pdp = 0; //
317 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
318 if(cgact_wait.cid != 0)
319 {
320 data_pdp = cgact_wait.cid + 100;
321 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
322 }
323 }
324 }
325 } else {
326 // apn_state_set
327
328 // +CGEV: NW PDN DEACT <cid>
329
330 // +CGEV: EPS PDN ACT 1
331 // +CGEV: ME PDN ACT 8,1
332
333 // +CGEV: ME PDN ACT 2,4
334 uint8 data[2] = {0xFF};
335 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
336 //apn_state_set(atoi(s + 20), false);
337 data[0] = (uint8)0;
338 data[1] = (uint8)atoi(s + 20);
339
340 uint8 data_pdp;
341 data_pdp = 0; //
342 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
wangyouqiang65884152023-10-25 19:54:15 +0800343 data_pdp = data[1] + 100;
liubin281ac462023-07-19 14:22:54 +0800344 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
345 } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
346 //apn_state_set(atoi(s + 19), true);
b.liuf37bd332024-03-18 13:51:24 +0800347#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
wangyouqianged88c722023-11-22 16:33:43 +0800348 //data[0] = (uint8)1;
349 //data[1] = (uint8)atoi(s + 19);
350#else
liubin281ac462023-07-19 14:22:54 +0800351 data[0] = (uint8)1;
352 data[1] = (uint8)atoi(s + 19);
wangyouqianged88c722023-11-22 16:33:43 +0800353#endif
wangyouqiang65884152023-10-25 19:54:15 +0800354 } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
355 //apn_state_set(atoi(s + 19), true);
356 data[0] = (uint8)0;
357 data[1] = (uint8)atoi(s + 20);
358
359 uint8 data_pdp;
360 data_pdp = 0; //
361 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
362 data_pdp = data[1] + 100;
363 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
liubin281ac462023-07-19 14:22:54 +0800364 } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
365 //apn_state_set(atoi(s + 18), true);
366 data[0] = (uint8)1;
367 data[1] = (uint8)atoi(s + 18);
368
369 uint8 data_pdp;
370 char* tmp_s = memdup(s + 18,strlen(s + 18));
371 char* free_ptr = tmp_s;
372 char *line = tmp_s;
373 int tmp_int;
374 if (at_tok_start(&line) < 0)
375 {
376 goto PDP_CREG_EXIT;
377 }
378 if (at_tok_nextint(&line, &tmp_int) < 0)
379 {
380 goto PDP_CREG_EXIT;
381 }
382 if (at_tok_nextint(&line, &tmp_int) < 0)
383 {
384 goto PDP_CREG_EXIT;
385 }
386 data_pdp = tmp_int;
387PDP_CREG_EXIT:
388 free(free_ptr);
389 //data_pdp = (uint8)atoi(s + 20); //reason
390 if(data[1] >= 1 && data[1] < 8)
391 {
392 if(data_pdp == 0)
393 {
394 data_pdp = 25;
395 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
396 }
397 else if(data_pdp == 1)
398 {
399 data_pdp = 26;
400 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
401 }
402 else if(data_pdp == 2)
403 {
404 data_pdp = 27;
405 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
406 }
407 else if(data_pdp == 3)
408 {
409 data_pdp = 27;
410 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
411 }
412 else
413 {
414
415 }
b.liufe320632024-01-17 20:38:08 +0800416
wangyouqiang65884152023-10-25 19:54:15 +0800417 data_pdp = data[1] + 200;
b.liuf77b86c2024-11-09 13:24:10 +0800418 urc_msg_distribute(true, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
wangyouqiang3947b302024-07-04 17:26:08 +0800419 data[1] = 0;
liubin281ac462023-07-19 14:22:54 +0800420 }
421 } else {
422 LOGI("No process : %s", s);
423 }
b.liubcf86c92024-08-19 19:48:28 +0800424
wangyouqiang3947b302024-07-04 17:26:08 +0800425 urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
liubin281ac462023-07-19 14:22:54 +0800426 }
427 }
428 // +CREG: 1, "8010", "000060a5", 0, 2, 0
429 // +CREG: 1, "8330", "06447347", 7, 2, 0
430 // +CEREG: 1, "8330", "06447347", 7
431 // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
432 // $CREG: 1, "8010", "000060a7", 0,, 2, 0
433 // +CGREG: 1
434 else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
435 || strStartsWith(s, "+CEREG:")) // LTE data registed.
436 {
b.liu9e8584b2024-11-06 19:21:28 +0800437 const char* tmp_s = s + 7;
liuyang67f4bac2024-06-26 17:06:13 +0800438 static bool net_led_gms_wcdma = FALSE;
439 static bool net_led_lte = FALSE;
liubin281ac462023-07-19 14:22:54 +0800440 while(*tmp_s && *tmp_s == ' ')
441 tmp_s++;
b.liufe320632024-01-17 20:38:08 +0800442 uint8 data[2];
443 data[0] = (uint8)atoi(tmp_s); // Reg State.
liubin281ac462023-07-19 14:22:54 +0800444
b.liubcf86c92024-08-19 19:48:28 +0800445 if(strStartsWith(s, "+CGREG:"))
liuyang67f4bac2024-06-26 17:06:13 +0800446 {
447 data[1] = 0; // GMS/WCDMA
448 if(data[0] == 1)
449 {
450 net_led_gms_wcdma = TRUE;
451 }
452 else
453 {
454 net_led_gms_wcdma = FALSE;
455 }
b.liubcf86c92024-08-19 19:48:28 +0800456
457 }
458 else
liuyang67f4bac2024-06-26 17:06:13 +0800459 {
460 data[1] = 1; // LTE
461 if(data[0] == 1)
462 {
463 net_led_lte = TRUE;
464 }
465 else
466 {
467 net_led_lte = FALSE;
468 }
469 }
b.liubcf86c92024-08-19 19:48:28 +0800470
liuyang67f4bac2024-06-26 17:06:13 +0800471 if(FALSE == net_led_gms_wcdma && FALSE == net_led_lte)
472 {
473 mbtk_net_led_set(MBTK_NET_LED_SEARCH_NETWORK);
474 }
475 else
476 {
477 mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
478 mbtk_net_ready();
b.liufe320632024-01-17 20:38:08 +0800479 }
480
481 urc_msg_distribute(true, INFO_URC_MSG_NET_PS_REG_STATE, data, sizeof(data));
liuyang37623a02024-06-20 15:21:39 +0800482 urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
liubin281ac462023-07-19 14:22:54 +0800483 }
484 // +CREG: 1, "8010", "000060a5", 0, 2, 0
485 // +CREG: 1, "8330", "06447347", 7, 2, 0
486 // +CREG: 0
487 else if(strStartsWith(s, "+CREG:")) // GMS/WCDMA/LTE CS registed.
488 {
489 uint8 data[3];
490 data[0] = (uint8)MBTK_NET_CS_STATE;
491 char* tmp_s = memdup(s,strlen(s));
492 char* free_ptr = tmp_s;
493 char *line = tmp_s;
494 int tmp_int;
495 char *tmp_str;
496 if (at_tok_start(&line) < 0)
497 {
498 goto CREG_EXIT;
499 }
500 if (at_tok_nextint(&line, &tmp_int) < 0)
501 {
502 goto CREG_EXIT;
503 }
504 data[1] = (uint8)tmp_int; // Reg State.
505 if (data[1])
506 {
507 if (at_tok_nextstr(&line, &tmp_str) < 0)
508 {
509 goto CREG_EXIT;
510 }
511 if (at_tok_nextstr(&line, &tmp_str) < 0)
512 {
513 goto CREG_EXIT;
514 }
515 if (at_tok_nextint(&line, &tmp_int) < 0)
516 {
517 goto CREG_EXIT;
518 }
519 data[2] = (uint8)tmp_int; // AcT
520 } else {
521 data[2] = (uint8)0xFF; // AcT
522 }
523 if(data[1] == 5)
524 {
525 uint8 data_pdp;
526 data_pdp = 5; //
527 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
528 }
529 urc_msg_distribute(false, INFO_URC_MSG_NET_CS_REG_STATE, data, sizeof(data));
liuyang37623a02024-06-20 15:21:39 +0800530 urc_msg_distribute(true, INFO_URC_MSG_NET_STATE_LOG, NULL, 0);
liubin281ac462023-07-19 14:22:54 +0800531CREG_EXIT:
532 free(free_ptr);
533 }
534 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
535 else if(strStartsWith(s, "+CLCC:"))
536 {
537 mbtk_call_info_t reg;
538 reg.call_wait = MBTK_CLCC;
539 char* tmp_s = memdup(s,strlen(s));
540 char* free_ptr = tmp_s;
541 char *line = tmp_s;
542 int tmp_int;
543 char *tmp_str;
544 int err;
545
546 err = at_tok_start(&line);
547 if (err < 0)
548 {
549 goto CLCC_EXIT;
550 }
551 err = at_tok_nextint(&line, &tmp_int); // dir1
552 if (err < 0)
553 {
554 goto CLCC_EXIT;
555 }
556 reg.dir1 = (uint8)tmp_int;
557 err = at_tok_nextint(&line, &tmp_int);// dir
558 if (err < 0)
559 {
560 goto CLCC_EXIT;
561 }
562 reg.dir = (uint8)tmp_int;
563 err = at_tok_nextint(&line, &tmp_int);// state
564 if (err < 0)
565 {
566 goto CLCC_EXIT;
567 }
568 reg.state = (uint8)tmp_int;
569 err = at_tok_nextint(&line, &tmp_int);// mode
570 if (err < 0)
571 {
572 goto CLCC_EXIT;
573 }
574 reg.mode = (uint8)tmp_int;
575 err = at_tok_nextint(&line, &tmp_int);// mpty
576 if (err < 0)
577 {
578 goto CLCC_EXIT;
579 }
580 reg.mpty = (uint8)tmp_int;
581 err = at_tok_nextstr(&line, &tmp_str); // phone_number
582 if (err < 0)
583 {
584 goto CLCC_EXIT;
585 }
586
587 memset(reg.phone_number,0,sizeof(reg.phone_number));
588 memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
589 err = at_tok_nextint(&line, &tmp_int);// tpye
590 if (err < 0)
591 {
592 goto CLCC_EXIT;
593 }
594 reg.type = (uint8)tmp_int;
595
r.xiaoe1404b32024-05-23 22:43:39 -0700596 if(reg.state == 2 || reg.state == 3 || reg.state == 0)
597 {
598 mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
599 }
600
r.xiao195e2522024-05-31 03:19:02 -0700601 if(reg.state == 4 && reg.dir == 1)
602 {
603 mbtk_net_led_set(MBTK_NET_LED_CALL_CONNECT);
604 }
605
606
liuyang4d7ac4b2024-11-21 16:25:22 +0800607 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800608CLCC_EXIT:
609 free(free_ptr);
610 }
611 // +CPAS: 4
612 else if(strStartsWith(s, "+CPAS:"))
613 {
614 mbtk_call_info_t reg;
615 reg.call_wait = 0;
616 char* tmp_s = memdup(s,strlen(s));
617 char* free_ptr = tmp_s;
618 char *line = tmp_s;
619 int tmp_int;
620 int err;
621
622 memset(&reg,0,sizeof(reg));
623
624 err = at_tok_start(&line);
625 if (err < 0)
626 {
627 goto CPAS_EXIT;
628 }
629 err = at_tok_nextint(&line, &tmp_int);
630 if (err < 0)
631 {
632 goto CPAS_EXIT;
633 }
634 reg.pas = (uint8)tmp_int;
635 reg.call_wait = MBTK_CPAS;
liuyang4d7ac4b2024-11-21 16:25:22 +0800636 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800637CPAS_EXIT:
638 free(free_ptr);
639 }
640 // +CALLDISCONNECT: 1
641 else if(strStartsWith(s, "+CALLDISCONNECT:"))
642 {
643 mbtk_call_info_t reg;
644 reg.call_wait = 0;
645 char* tmp_s = memdup(s,strlen(s));
646 char* free_ptr = tmp_s;
647 char *line = tmp_s;
648 int tmp_int;
649 int err;
650
651 memset(&reg,0,sizeof(reg));
652
653 err = at_tok_start(&line);
654 if (err < 0)
655 {
656 goto CALLDISCONNECTED_EXIT;
657 }
658 err = at_tok_nextint(&line, &tmp_int);
659 if (err < 0)
660 {
661 goto CALLDISCONNECTED_EXIT;
662 }
663 reg.disconnected_id = tmp_int;
664 reg.call_wait = MBTK_DISCONNECTED;
r.xiaoe1404b32024-05-23 22:43:39 -0700665
666 if(reg.call_wait == MBTK_DISCONNECTED)
667 {
668 mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
669 }
670
liuyang4d7ac4b2024-11-21 16:25:22 +0800671 urc_msg_distribute(true, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
liubin281ac462023-07-19 14:22:54 +0800672
673CALLDISCONNECTED_EXIT:
674 free(free_ptr);
675 }
676 // *SIMDETEC:1,SIM
677 else if(strStartsWith(s, "*SIMDETEC:"))
678 {
liuyange22a25e2024-05-23 19:41:52 +0800679 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
680 {
681 net_info.sim_state = MBTK_SIM_ABSENT;
682 }
b.liubb590492024-06-13 16:42:08 +0800683
liubin281ac462023-07-19 14:22:54 +0800684 sim_info_reg.sim = -1;
685 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
686 sim_info_reg.sim = 0;
687 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
688 sim_info_reg.sim = 1;
689 if(sim_info_reg.sim == 0)
690 {
691 uint8 data_pdp;
692 data_pdp = 11; //
693 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
694 }
695 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
696 }
697 // *EUICC:1
698/*0: SIM
6991: USIM
7002: TEST SIM
7013: TEST USIM
7024: UNKNOWN
703Note: *EUICC:
704*/
705 else if(strStartsWith(s, "*EUICC:"))
706 {
yq.wangb184fc22024-08-19 00:54:30 -0700707 sim_info_reg.sim = -1;
liubin281ac462023-07-19 14:22:54 +0800708 sim_info_reg.sim_card_type = -1;
709 if(strStartsWith(s, "*EUICC: 0"))
710 sim_info_reg.sim_card_type = 1;
711 else if(strStartsWith(s, "*EUICC: 1"))
712 sim_info_reg.sim_card_type = 2;
713 else if(strStartsWith(s, "*EUICC: 2"))
714 sim_info_reg.sim_card_type = 1;
715 else if(strStartsWith(s, "*EUICC: 3"))
716 sim_info_reg.sim_card_type = 2;
717 else if(strStartsWith(s, "*EUICC: 4"))
718 sim_info_reg.sim_card_type = 0;
719 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
720 }
721 // +CPIN: SIM PIN
722 else if(strStartsWith(s, "+CPIN:"))
723 {
724 sim_info_reg.sim = -1;
725 if(strStartsWith(s, "+CPIN: READY"))
liuyange22a25e2024-05-23 19:41:52 +0800726 {
liubin281ac462023-07-19 14:22:54 +0800727 sim_info_reg.sim = 1;
liuyange22a25e2024-05-23 19:41:52 +0800728 net_info.sim_state = MBTK_SIM_READY;
729 }
liubin281ac462023-07-19 14:22:54 +0800730 else if(strStartsWith(s, "+CPIN: SIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800731 {
liubin281ac462023-07-19 14:22:54 +0800732 sim_info_reg.sim = 2;
liuyange22a25e2024-05-23 19:41:52 +0800733 net_info.sim_state = MBTK_SIM_PIN;
734 }
liubin281ac462023-07-19 14:22:54 +0800735 else if(strStartsWith(s, "+CPIN: SIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800736 {
liubin281ac462023-07-19 14:22:54 +0800737 sim_info_reg.sim = 3;
liuyange22a25e2024-05-23 19:41:52 +0800738 net_info.sim_state = MBTK_SIM_PUK;
739 }
liubin281ac462023-07-19 14:22:54 +0800740 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800741 {
liubin281ac462023-07-19 14:22:54 +0800742 sim_info_reg.sim = 4;
liuyange22a25e2024-05-23 19:41:52 +0800743 net_info.sim_state = MBTK_SIM_ABSENT;
744 }
liubin281ac462023-07-19 14:22:54 +0800745 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800746 {
liubin281ac462023-07-19 14:22:54 +0800747 sim_info_reg.sim = 5;
liuyange22a25e2024-05-23 19:41:52 +0800748 net_info.sim_state = MBTK_SIM_ABSENT;
749 }
liubin281ac462023-07-19 14:22:54 +0800750 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800751 {
liubin281ac462023-07-19 14:22:54 +0800752 sim_info_reg.sim = 6;
liuyange22a25e2024-05-23 19:41:52 +0800753 net_info.sim_state = MBTK_SIM_ABSENT;
754 }
liubin281ac462023-07-19 14:22:54 +0800755 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800756 {
liubin281ac462023-07-19 14:22:54 +0800757 sim_info_reg.sim = 7;
liuyange22a25e2024-05-23 19:41:52 +0800758 net_info.sim_state = MBTK_SIM_ABSENT;
759 }
liubin281ac462023-07-19 14:22:54 +0800760 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
liuyange22a25e2024-05-23 19:41:52 +0800761 {
liubin281ac462023-07-19 14:22:54 +0800762 sim_info_reg.sim = 8;
liuyange22a25e2024-05-23 19:41:52 +0800763 net_info.sim_state = MBTK_SIM_ABSENT;
764 }
liubin281ac462023-07-19 14:22:54 +0800765 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
liuyange22a25e2024-05-23 19:41:52 +0800766 {
liubin281ac462023-07-19 14:22:54 +0800767 sim_info_reg.sim = 9;
liuyange22a25e2024-05-23 19:41:52 +0800768 net_info.sim_state = MBTK_SIM_ABSENT;
769 }
liubin281ac462023-07-19 14:22:54 +0800770 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800771 {
liubin281ac462023-07-19 14:22:54 +0800772 sim_info_reg.sim = 10;
liuyange22a25e2024-05-23 19:41:52 +0800773 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
774 }
liubin281ac462023-07-19 14:22:54 +0800775 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800776 {
liubin281ac462023-07-19 14:22:54 +0800777 sim_info_reg.sim = 11;
liuyange22a25e2024-05-23 19:41:52 +0800778 net_info.sim_state = MBTK_SIM_ABSENT;
779 }
liubin281ac462023-07-19 14:22:54 +0800780 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
liuyange22a25e2024-05-23 19:41:52 +0800781 {
liubin281ac462023-07-19 14:22:54 +0800782 sim_info_reg.sim = 12;
liuyange22a25e2024-05-23 19:41:52 +0800783 net_info.sim_state = MBTK_SIM_ABSENT;
784 }
liubin281ac462023-07-19 14:22:54 +0800785 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800786 {
liubin281ac462023-07-19 14:22:54 +0800787 sim_info_reg.sim = 13;
liuyange22a25e2024-05-23 19:41:52 +0800788 net_info.sim_state = MBTK_SIM_ABSENT;
789 }
liubin281ac462023-07-19 14:22:54 +0800790 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800791 {
liubin281ac462023-07-19 14:22:54 +0800792 sim_info_reg.sim = 14;
liuyange22a25e2024-05-23 19:41:52 +0800793 net_info.sim_state = MBTK_SIM_ABSENT;
794 }
liubin281ac462023-07-19 14:22:54 +0800795 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800796 {
liubin281ac462023-07-19 14:22:54 +0800797 sim_info_reg.sim = 15;
liuyange22a25e2024-05-23 19:41:52 +0800798 net_info.sim_state = MBTK_SIM_ABSENT;
799 }
liubin281ac462023-07-19 14:22:54 +0800800 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
liuyange22a25e2024-05-23 19:41:52 +0800801 {
liubin281ac462023-07-19 14:22:54 +0800802 sim_info_reg.sim = 16;
liuyange22a25e2024-05-23 19:41:52 +0800803 net_info.sim_state = MBTK_SIM_ABSENT;
804 }
liubin281ac462023-07-19 14:22:54 +0800805 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
liuyange22a25e2024-05-23 19:41:52 +0800806 {
liubin281ac462023-07-19 14:22:54 +0800807 sim_info_reg.sim = 17;
liuyange22a25e2024-05-23 19:41:52 +0800808 net_info.sim_state = MBTK_SIM_ABSENT;
809 }
liubin281ac462023-07-19 14:22:54 +0800810 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
liuyange22a25e2024-05-23 19:41:52 +0800811 {
812 sim_info_reg.sim = 18;
813 net_info.sim_state = MBTK_SIM_ABSENT;
814 }
liubin281ac462023-07-19 14:22:54 +0800815 else
816 sim_info_reg.sim = 20;
817
818 if(sim_info_reg.sim == 18)
819 {
820 uint8 data_pdp;
821 data_pdp = 11; //
822 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
823 }
824
825 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
826 }
827 // +CMT: ,23
828 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
829 else if(strStartsWith(s, "+CMT:") || sms_cmt)
830 {
831 if(!sms_cmt){
832 sms_cmt = true;
833 }else{
834 sms_cmt = false;
835 }
836 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
837 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
838 }
839#if 0
840 // LTE data registed.
841 // +CEREG: 1, "8330", "06447347", 7
842 else if(strStartsWith(s, "+CEREG:"))
843 {
844 char* tmp_s = memdup(s,strlen(s));
845 char* free_ptr = tmp_s;
846 char *line = tmp_s;
847 int tmp_int;
848 char *tmp_str;
849 if (at_tok_start(&line) < 0)
850 {
851 goto CREG_EXIT;
852 }
853 if (at_tok_nextint(&line, &tmp_int) < 0)
854 {
855 goto CREG_EXIT;
856 }
857 uint8 data = (uint8)tmp_int; // Reg State.
858
859 urc_msg_distribute(INFO_URC_MSG_NET_REG_STATE, &data, sizeof(uint8));
860CREG_EXIT:
861 free(free_ptr);
862 }
863#endif
864 /*
865 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
866 // <rsrp>,<rsrq>, <sinr>,
867 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
868 // cellId,subFrameAssignType,specialSubframePatterns,transMode
869 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
870 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
871 // dlBer, ulBer,
872 // diversitySinr, diversityRssi
873 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
874 0, 0, 0,
875 1, 10, 0, 1, 0, 1059, 78, 3959566565,
876 105149248, 2, 7, 7,
877 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
878 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
879 0, 0,
880 7, 44
881 */
882 else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
883 {
884 // tac, PCI, dlEuarfcn, ulEuarfcn, band
885 if(cell_info.running) {
886 int tmp_int;
887 int i = 0;
888 char* tmp_s = memdup(s,strlen(s));
889 char* free_ptr = tmp_s;
890 char *line = tmp_s;
891 if (at_tok_start(&line) < 0)
892 {
893 goto EEMLTESVC_EXIT;
894 }
895
896 if (at_tok_nextint(&line, &tmp_int) < 0)
897 {
898 goto EEMLTESVC_EXIT;
899 }
900 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int; //mcc
901 if (at_tok_nextint(&line, &tmp_int) < 0)
902 {
903 goto EEMLTESVC_EXIT;
904 }
905 if (at_tok_nextint(&line, &tmp_int) < 0)
906 {
907 goto EEMLTESVC_EXIT;
908 }
909 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
910 /*
911 // Jump 2 integer.
912 i = 0;
913 while(i < 2) {
914 if (at_tok_nextint(&line, &tmp_int) < 0)
915 {
916 goto EEMLTESVC_EXIT;
917 }
918 i++;
919 }
920 */
921 if (at_tok_nextint(&line, &tmp_int) < 0)
922 {
923 goto EEMLTESVC_EXIT;
924 }
925 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int; //tac
926 if (at_tok_nextint(&line, &tmp_int) < 0)
927 {
928 goto EEMLTESVC_EXIT;
929 }
930 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int; //pci
931 if (at_tok_nextint(&line, &tmp_int) < 0)
932 {
933 goto EEMLTESVC_EXIT;
934 }
935 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int; //dl arfcn
936 if (at_tok_nextint(&line, &tmp_int) < 0)
937 {
938 goto EEMLTESVC_EXIT;
939 }
940 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //ul arfcn
941 if (at_tok_nextint(&line, &tmp_int) < 0)
942 {
943 goto EEMLTESVC_EXIT;
944 }
945 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int; //band
946 if (at_tok_nextint(&line, &tmp_int) < 0)
947 {
948 goto EEMLTESVC_EXIT;
949 }
950 if (at_tok_nextint(&line, &tmp_int) < 0)
951 {
952 goto EEMLTESVC_EXIT;
953 }
954 cell_info.cell[cell_info.cell_num].value8 = (uint32)tmp_int; //cid
955 if (at_tok_nextint(&line, &tmp_int) < 0)
956 {
957 goto EEMLTESVC_EXIT;
958 }
959 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //rsrp
960
961 for(i =0; i < 10; i++)
962 {
963 if (at_tok_nextint(&line, &tmp_int) < 0)
964 {
965 goto EEMLTESVC_EXIT;
966 }
967 }
968 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //cell identiy
969
b.liuaec91492025-05-24 10:52:26 +0800970 for(i =0; i < 28; i++)
971 {
972 if (at_tok_nextint(&line, &tmp_int) < 0)
973 {
974 goto EEMLTESVC_EXIT;
975 }
976 }
977
978 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int; //dlBler
979
liubin281ac462023-07-19 14:22:54 +0800980 cell_info.cell_num++;
981
b.liuaec91492025-05-24 10:52:26 +0800982 LOG("LTESVC cell_num : %d", cell_info.cell_num);
983
984
liubin281ac462023-07-19 14:22:54 +0800985EEMLTESVC_EXIT:
986 free(free_ptr);
987 }
988 }
989 /*
990 // index,phyCellId,euArfcn,rsrp,rsrq
991 +EEMLTEINTER: 0, 65535, 38950, 0, 0
992 */
993 else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
994 {
995 // phyCellId,euArfcn,rsrp,rsrq
996 if(cell_info.running) {
997 int tmp_int;
998 char* tmp_s = memdup(s,strlen(s));
999 char* free_ptr = tmp_s;
1000 char *line = tmp_s;
1001 if (at_tok_start(&line) < 0)
1002 {
1003 goto EEMLTEINTER_EXIT;
1004 }
1005 if (at_tok_nextint(&line, &tmp_int) < 0)
1006 {
1007 goto EEMLTEINTER_EXIT;
1008 }
1009 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1010 {
1011 goto EEMLTEINTER_EXIT;
1012 }
1013 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1014 if (at_tok_nextint(&line, &tmp_int) < 0)
1015 {
1016 goto EEMLTEINTER_EXIT;
1017 }
1018 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1019 if (at_tok_nextint(&line, &tmp_int) < 0)
1020 {
1021 goto EEMLTEINTER_EXIT;
1022 }
1023 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1024 LOG("cell line : %s", line);
1025 if (at_tok_nextint(&line, &tmp_int) < 0)
1026 {
1027 goto EEMLTEINTER_EXIT;
1028 }
1029 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1030 if (at_tok_nextint(&line, &tmp_int) < 0)
1031 {
1032 LOG("cell tmp_int : %d", tmp_int);
1033 goto EEMLTEINTER_EXIT;
1034 }
1035 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1036 LOG("cell value5 : %d", cell_info.cell[cell_info.cell_num].value5);
b.liuaec91492025-05-24 10:52:26 +08001037
1038 LOG("after cellid 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].value6 = (uint32)tmp_int; //mcc
1044
1045 if (at_tok_nextint(&line, &tmp_int) < 0)
1046 {
1047 LOG("exit");
1048 goto EEMLTEINTER_EXIT;
1049 }
1050
1051 if (at_tok_nextint(&line, &tmp_int) < 0)
1052 {
1053 LOG("exit");
1054 goto EEMLTEINTER_EXIT;
1055 }
1056
1057 cell_info.cell[cell_info.cell_num].value7 = (uint32)tmp_int; //mnc
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].value8 = (uint32)tmp_int; //cellId
1072 LOG("cell value8 : %u", (uint32)cell_info.cell[cell_info.cell_num].value9);
1073 for(int i =0; i < 5; i++)
1074 {
1075 if (at_tok_nextint(&line, &tmp_int) < 0)
1076 {
1077 LOG("exit i = %d",i);
1078 goto EEMLTEINTER_EXIT;
1079 }
1080 }
1081
1082 cell_info.cell[cell_info.cell_num].value9 = (uint32)tmp_int; //band
1083 LOG("cell value9 : %d", cell_info.cell[cell_info.cell_num].value9);
1084 if (at_tok_nextint(&line, &tmp_int) < 0)
1085 {
1086 LOG("exit");
1087 goto EEMLTEINTER_EXIT;
1088 }
1089
1090 cell_info.cell[cell_info.cell_num].value10 = (uint32)tmp_int; //rssi
1091
liubin281ac462023-07-19 14:22:54 +08001092 cell_info.cell_num++;
1093EEMLTEINTER_EXIT:
1094 free(free_ptr);
1095 }
1096 }
1097 // Do nothing
1098 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
1099 {
1100 if(cell_info.running) {
1101
1102 }
1103 }
1104 // WCDMA
1105 /*
1106 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1107
1108 // if sCMeasPresent == 1
1109 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1110 // endif
1111
1112 // if sCParamPresent == 1
1113 // rac, nom, mcc, mnc_len, mnc, lac, ci,
1114 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1115 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1116 // endif
1117
1118 // if ueOpStatusPresent == 1
1119 // rrcState, numLinks, srncId, sRnti,
1120 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1121 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1122 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1123 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1124 // endif
1125 //
1126 +EEMUMTSSVC: 3, 1, 1, 1,
1127 -80, 27, -6, -18, -115, -32768,
1128 1, 1, 1120, 2, 1, 61697, 168432821,
1129 15, 24, 10763, 0, 0, 0, 0,
1130 128, 128, 65535, 0, 0,
1131 2, 255, 65535, 4294967295,
1132 0, 0, 0, 0, 0, 0,
1133 0, 0, 0, 0, 0, 0, 1, 1,
1134 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1135 0, 0, 0, 0, 0, 0
1136 */
1137 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1138 {
1139 // lac, ci, arfcn
1140 if(cell_info.running) {
1141 int tmp_int;
1142 int i = 0;
1143 char* tmp_s = memdup(s,strlen(s));
1144 char* free_ptr = tmp_s;
1145 char *line = tmp_s;
1146 if (at_tok_start(&line) < 0)
1147 {
1148 goto EEMUMTSSVC_EXIT;
1149 }
1150 // Jump 12 integer.
1151 i = 0;
1152 while(i < 12) {
1153 if (at_tok_nextint(&line, &tmp_int) < 0)
1154 {
1155 goto EEMUMTSSVC_EXIT;
1156 }
1157 i++;
1158 }
1159 // mcc
1160 if (at_tok_nextint(&line, &tmp_int) < 0)
1161 {
1162 goto EEMUMTSSVC_EXIT;
1163 }
1164 cell_info.cell[cell_info.cell_num].value4= (uint32)tmp_int;
1165 // mnc
1166 if (at_tok_nextint(&line, &tmp_int) < 0)
1167 {
1168 goto EEMUMTSSVC_EXIT;
1169 }
1170 cell_info.cell[cell_info.cell_num].value5= (uint32)tmp_int;
1171 // lac
1172 if (at_tok_nextint(&line, &tmp_int) < 0)
1173 {
1174 goto EEMUMTSSVC_EXIT;
1175 }
1176 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1177 // ci
1178 if (at_tok_nextint(&line, &tmp_int) < 0)
1179 {
1180 goto EEMUMTSSVC_EXIT;
1181 }
1182 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1183
1184 if (at_tok_nextint(&line, &tmp_int) < 0)
1185 {
1186 goto EEMUMTSSVC_EXIT;
1187 }
1188 // cpi
1189 if (at_tok_nextint(&line, &tmp_int) < 0)
1190 {
1191 goto EEMUMTSSVC_EXIT;
1192 }
1193 cell_info.cell[cell_info.cell_num].value6= (uint32)tmp_int;
1194 /*
1195 // Jump 2 integer.
1196 i = 0;
1197 while(i < 2) {
1198 if (at_tok_nextint(&line, &tmp_int) < 0)
1199 {
1200 goto EEMUMTSSVC_EXIT;
1201 }
1202 i++;
1203 }
1204 */
1205 // arfcn
1206 if (at_tok_nextint(&line, &tmp_int) < 0)
1207 {
1208 goto EEMUMTSSVC_EXIT;
1209 }
1210 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1211
1212 cell_info.cell_num++;
1213EEMUMTSSVC_EXIT:
1214 free(free_ptr);
1215 }
1216 }
1217 /*
1218 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1219 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1220 */
1221 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1222 {
1223 // lac, ci, arfcn
1224 if(cell_info.running) {
1225 int tmp_int;
1226 int i = 0;
1227 char* tmp_s = memdup(s,strlen(s));
1228 char* free_ptr = tmp_s;
1229 char *line = tmp_s;
1230 if (at_tok_start(&line) < 0)
1231 {
1232 goto EEMUMTSINTRA_EXIT;
1233 }
1234 // Jump 8 integer.
1235 i = 0;
1236 while(i < 8) {
1237 if (at_tok_nextint(&line, &tmp_int) < 0)
1238 {
1239 goto EEMUMTSINTRA_EXIT;
1240 }
1241 i++;
1242 }
1243
1244 // lac
1245 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1246 {
1247 goto EEMUMTSINTRA_EXIT;
1248 }
1249 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1250
1251 // ci
1252 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1253 {
1254 goto EEMUMTSINTRA_EXIT;
1255 }
1256 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1257
1258 // arfcn
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].value3 = (uint32)tmp_int;
1264
1265 cell_info.cell_num++;
1266EEMUMTSINTRA_EXIT:
1267 free(free_ptr);
1268 }
1269 }
1270 /*
1271 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1272 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1273 */
1274 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1275 {
1276 // lac, ci, arfcn
1277 if(cell_info.running) {
1278 int tmp_int;
1279 int i = 0;
1280 char* tmp_s = memdup(s,strlen(s));
1281 char* free_ptr = tmp_s;
1282 char *line = tmp_s;
1283 if (at_tok_start(&line) < 0)
1284 {
1285 goto EEMUMTSINTERRAT_EXIT;
1286 }
1287 // Jump 7 integer.
1288 i = 0;
1289 while(i < 7) {
1290 if (at_tok_nextint(&line, &tmp_int) < 0)
1291 {
1292 goto EEMUMTSINTERRAT_EXIT;
1293 }
1294 i++;
1295 }
1296
1297 // lac
1298 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1299 {
1300 goto EEMUMTSINTERRAT_EXIT;
1301 }
1302 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1303
1304 // ci
1305 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1306 {
1307 goto EEMUMTSINTERRAT_EXIT;
1308 }
1309 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1310
1311 // arfcn
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].value3 = (uint32)tmp_int;
1317
1318 cell_info.cell_num++;
1319EEMUMTSINTERRAT_EXIT:
1320 free(free_ptr);
1321 }
1322 }
1323 // GSM
1324 // +EEMGINFOBASIC: 2
1325 // Do nothing.
1326 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1327 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1328 {
1329 if(cell_info.running) {
1330
1331 }
1332 }
1333 /*
1334 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1335 // bsic, C1, C2, TA, TxPwr,
1336 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1337 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1338 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1339 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1340 // gsmBand,channelMode
1341 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1342 63, 36, 146, 1, 7,
1343 46, 42, 42, 7, 0,
1344 53, 0, 8, 0, 1, 6, 53,
1345 2, 0, 146, 42, 54, 0, 1,
1346 1, 32, 0, 0, 0, 0,
1347 0, 0
1348 */
1349 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1350 {
1351 // lac, ci, arfcn, bsic
1352 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1353 if(cell_info.running) {
1354 int tmp_int;
1355 int i = 0;
1356 char* tmp_s = memdup(s,strlen(s));
1357 char* free_ptr = tmp_s;
1358 char *line = tmp_s;
1359 if (at_tok_start(&line) < 0)
1360 {
1361 goto EEMGINFOSVC_EXIT;
1362 }
1363
1364 // mcc
1365 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1366 {
1367 goto EEMGINFOSVC_EXIT;
1368 }
1369 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1370
1371 //mnc_len
1372 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1373 {
1374 goto EEMGINFOSVC_EXIT;
1375 }
1376 // mnc
1377 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1378 {
1379 goto EEMGINFOSVC_EXIT;
1380 }
1381 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1382
1383 /*
1384 // Jump 3 integer.
1385 i = 0;
1386 while(i < 3) {
1387 if (at_tok_nextint(&line, &tmp_int) < 0)
1388 {
1389 goto EEMGINFOSVC_EXIT;
1390 }
1391 i++;
1392 }
1393 */
1394 // lac
1395 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1396 {
1397 goto EEMGINFOSVC_EXIT;
1398 }
1399 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1400
1401 // ci
1402 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1403 {
1404 goto EEMGINFOSVC_EXIT;
1405 }
1406 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1407
1408 // Jump 2 integer.
1409 i = 0;
1410 while(i < 2) {
1411 if (at_tok_nextint(&line, &tmp_int) < 0)
1412 {
1413 goto EEMGINFOSVC_EXIT;
1414 }
1415 i++;
1416 }
1417
1418 // bsic
1419 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1420 {
1421 goto EEMGINFOSVC_EXIT;
1422 }
1423 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1424
1425 // Jump 15 integer.
1426 i = 0;
1427 while(i < 15) {
1428 if (at_tok_nextint(&line, &tmp_int) < 0)
1429 {
1430 goto EEMGINFOSVC_EXIT;
1431 }
1432 i++;
1433 }
1434
1435 // arfcn
1436 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1437 {
1438 goto EEMGINFOSVC_EXIT;
1439 }
1440 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1441
1442 cell_info.cell_num++;
1443EEMGINFOSVC_EXIT:
1444 free(free_ptr);
1445 }
1446 }
1447 /*
1448 // PS_attached, attach_type, service_type, tx_power, c_value,
1449 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1450 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1451 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1452 +EEMGINFOPS: 1, 255, 0, 0, 0,
1453 0, 0, 268435501, 1, 0, 0,
1454 4, 0, 96, 0, 0, 0,
1455 0, 0, 0, 65535, 0, 13350
1456 */
1457 // Do nothing.
1458 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1459 {
1460 if(cell_info.running) {
1461
1462 }
1463 }
1464 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1465 {
1466 if(cell_info.running) {
1467 int tmp_int;
1468 int i = 0;
1469 char* tmp_s = memdup(s,strlen(s));
1470 char* free_ptr = tmp_s;
1471 char *line = tmp_s;
1472 if (at_tok_start(&line) < 0)
1473 {
1474 goto EEMGINFOPS_EXIT;
1475 }
1476
1477 // nc_num
1478 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1479 {
1480 LOG("cell_info.running 1= %d\n.",cell_info.running);
1481 goto EEMGINFOPS_EXIT;
1482 }
1483 // mcc
1484 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1485 {
1486 LOG("cell_info.running 2= %d\n.",cell_info.running);
1487 goto EEMGINFOPS_EXIT;
1488 }
1489 cell_info.cell[cell_info.cell_num].value5 = (uint32)tmp_int;
1490
1491 // mnc
1492 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1493 {
1494 LOG("cell_info.running 3= %d\n.",cell_info.running);
1495 goto EEMGINFOPS_EXIT;
1496 }
1497 cell_info.cell[cell_info.cell_num].value6 = (uint32)tmp_int;
1498
1499 // lac
1500 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1501 {
1502 LOG("cell_info.running 4= %d\n.",cell_info.running);
1503 goto EEMGINFOPS_EXIT;
1504 }
1505 cell_info.cell[cell_info.cell_num].value1 = (uint32)tmp_int;
1506
1507 // rac
1508 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1509 {
1510 LOG("cell_info.running 5= %d\n.",cell_info.running);
1511 goto EEMGINFOPS_EXIT;
1512 }
1513
1514 // ci
1515 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1516 {
1517 LOG("cell_info.running 6= %d\n.",cell_info.running);
1518 goto EEMGINFOPS_EXIT;
1519 }
1520 cell_info.cell[cell_info.cell_num].value2 = (uint32)tmp_int;
1521
1522 // rx_lv
1523 if (at_tok_nextint(&line, &tmp_int) < 0)
1524 {
1525 LOG("cell_info.running 7= %d\n.",cell_info.running);
1526 goto EEMGINFOPS_EXIT;
1527 }
1528
1529 // bsic
1530 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1531 {
1532 LOG("cell_info.running 8= %d\n.",cell_info.running);
1533 goto EEMGINFOPS_EXIT;
1534 }
1535 cell_info.cell[cell_info.cell_num].value4 = (uint32)tmp_int;
1536
1537 // Jump 2 integer.
1538 i = 0;
1539 while(i < 2) {
1540 if (at_tok_nextint(&line, &tmp_int) < 0)
1541 {
1542 LOG("cell_info.running 9= %d\n.",cell_info.running);
1543 goto EEMGINFOPS_EXIT;
1544 }
1545 i++;
1546 }
1547
1548 // arfcn
1549 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1550 {
1551 LOG("cell_info.running 10 = %d\n.",cell_info.running);
1552 goto EEMGINFOPS_EXIT;
1553 }
1554 cell_info.cell[cell_info.cell_num].value3 = (uint32)tmp_int;
1555
1556 cell_info.cell_num++;
1557EEMGINFOPS_EXIT:
1558 free(free_ptr);
1559 }
1560 }
1561 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"
1562 {
1563
1564 }
1565 else
1566 {
1567 LOGV("Unknown URC : %s", s);
1568 }
1569}
1570
1571static int openSocket(const char* sockname)
1572{
1573 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
1574 if (sock < 0)
1575 {
1576 LOGE("Error create socket: %s\n", strerror(errno));
1577 return -1;
1578 }
1579 struct sockaddr_un addr;
1580 memset(&addr, 0, sizeof(addr));
1581 addr.sun_family = AF_UNIX;
1582 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
1583 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
1584 {
1585 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
1586 sleep(1);
1587 }
1588
1589#if 0
1590 int sk_flags = fcntl(sock, F_GETFL, 0);
1591 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
1592#endif
1593
1594 return sock;
1595}
1596
b.liu9e8584b2024-11-06 19:21:28 +08001597#if 0
liubin281ac462023-07-19 14:22:54 +08001598static void ril_get_cgpaddr_ip_process()
1599{
1600 int err, skip;
1601 ATResponse *p_response = NULL;
1602 char *line;
1603 char *ipv4 = NULL, *ipv6 = NULL;
1604 err = at_send_command_singleline("AT+CGPADDR", "+CGPADDR:", &p_response);
1605 if ((err < 0) || (p_response == NULL) || (p_response->success == 0))
1606 {
1607 LOGE("+CGPADDR exec error.");
1608 goto error;
1609 }
1610
1611 // +CGPADDR: 1, "10.51.59.229", "254.128.0.0.0.0.0.0.0.1.0.0.111.176.63.99"
1612 // +CGPADDR: 1, "10.124.139.131"
1613 line = p_response->p_intermediates->line;
1614 err = at_tok_start(&line);
1615 if (err < 0)
1616 {
1617 goto error;
1618 }
1619
1620 err = at_tok_nextint(&line, &skip);
1621 if (err < 0)
1622 {
1623 goto error;
1624 }
1625
1626 if (!at_tok_hasmore(&line))
1627 {
1628 goto error;
1629 }
1630
1631 err = at_tok_nextstr(&line, &ipv4);
1632 if (err < 0)
1633 {
1634 LOGE("Get IPv4 fail.");
1635 goto error;
1636 }
1637
1638 if (at_tok_hasmore(&line))
1639 {
1640 err = at_tok_nextstr(&line, &ipv6);
1641 if (err < 0)
1642 {
1643 LOGE("Get IPv6 fail.");
1644 goto error;
1645 }
1646 }
1647 else
1648 {
1649 LOGD("No IPv6 Found.");
1650 }
1651
1652 if(ipv6)
1653 {
1654 LOGD("IPv6 : %s", ipv6);
1655 }
1656
1657 if(ipv4)
1658 {
1659 LOGD("IPv4 : %s", ipv4);
1660
1661// ril_net_dev_config("ccinet0", ipv4, NULL);
1662 }
1663error:
1664 at_response_free(p_response);
1665}
b.liu9e8584b2024-11-06 19:21:28 +08001666#endif
liubin281ac462023-07-19 14:22:54 +08001667
1668static void sim_state_change(bool plug_in) {
1669 if(plug_in) {
1670 // If radio on,must off in the first.
1671 if(net_info.radio_state == MBTK_RADIO_STATE_ON) {
1672 setRadioPower(0);
1673 }
1674 setRadioPower(1);
1675 } else {
1676 setRadioPower(0);
1677 }
1678}
1679
1680static int open_uevent_socket()
1681{
1682 struct sockaddr_nl addr;
1683 int sz = 64*1024;
1684 int s = 0;
1685
1686 memset(&addr, 0, sizeof(addr));
1687 addr.nl_family = AF_NETLINK;
1688 addr.nl_pid = getpid();
1689 addr.nl_groups = 0xffffffff;
1690
1691 s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT);
1692 if (s < 0)
1693 {
1694 LOGE("socket() fail.[%d]", errno);
1695 return -1;
1696 }
1697
1698 setsockopt(s, SOL_SOCKET, SO_RCVBUFFORCE, &sz, sizeof(sz));
1699
1700 if (bind(s, (struct sockaddr *) &addr, sizeof(addr)) < 0)
1701 {
1702 close(s);
1703 return -1;
1704 }
1705
1706 return s;
1707}
1708
1709static void parse_uevent(const char *msg, int msg_len, struct cooling_device *cdev)
1710{
1711 // change@/devices/virtual/usim_event/usim0\0
1712 // ACTION=change\0
1713 // DEVPATH=/devices/virtual/usim_event/usim0\0
1714 // SUBSYSTEM=usim_event\0
1715 // USIM_NAME=usim0\0
1716 // USIM_EVENT=plugout\0
1717 // SEQNUM=704
1718 int i = 0;
1719 while (i < msg_len)
1720 {
1721 if(*(msg + i) == '\0')
1722 {
1723 i++;
1724 continue;
1725 }
1726 if (!strncmp(msg + i, "USIM_NAME=", 10))
1727 {
1728 i += 10;
1729 cdev->name = msg + i;
1730 i += strlen(msg + i);
1731 }
1732 else if (!strncmp(msg + i, "ACTION=", 7))
1733 {
1734 i += 7;
1735 cdev->action = msg + i;
1736 i += strlen(msg + i);
1737 }
1738 else if (!strncmp(msg + i, "DEVPATH=", 8))
1739 {
1740 i += 8;
1741 cdev->path = msg + i;
1742 i += strlen(msg + i);
1743 }
1744 else if (!strncmp(msg + i, "USIM_EVENT=", 11))
1745 {
1746 i += 11;
1747 cdev->event = msg + i;
1748 i += strlen(msg + i);
1749 }
1750 else if (!strncmp(msg + i, "SUBSYSTEM=", 10))
1751 {
1752 i += 10;
1753 cdev->subsystem = msg + i;
1754 i += strlen(msg + i);
1755 }
1756 else
1757 {
1758 i++;
1759 }
1760 }
1761
1762 if(!strncmp(cdev->path, UEVENT_USIM_DEV, sizeof(UEVENT_USIM_DEV))
1763 && !strncmp(cdev->action, "change", 5))
1764 {
1765 LOGD("event { name=%s, action=%s, path=%s, subsystem=%s, event=%s}",
1766 cdev->name, cdev->action, cdev->path, cdev->subsystem, cdev->event);
1767 if(!strcmp(cdev->event, "plugout"))
1768 {
1769 sim_state_change(FALSE);
1770 }
1771 else if(!strcmp(cdev->event, "plugin"))
1772 {
1773 sim_state_change(TRUE);
1774 }
1775 else
1776 {
1777 LOGE("usim evnet error!");
1778 }
1779 }
1780}
1781
1782static void* uevnet_run(void *payload)
1783{
1784 int socket_fd = -1;
1785 char msg[BUFFER_SIZE+2];
1786 int n;
1787
1788 socket_fd = open_uevent_socket();
1789 if(socket_fd > 0)
1790 {
1791 while(1)
1792 {
1793 if((n = recv(socket_fd, msg, BUFFER_SIZE, 0)) > 0)
1794 {
1795 struct cooling_device cdev;
1796 memset(&cdev, 0x0, sizeof(cdev));
1797
1798 if(n == BUFFER_SIZE)
1799 continue;
1800 msg[n] = '\0';
1801 // 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
1802 log_hex("UEVENT", msg, n);
1803 parse_uevent(msg, n, &cdev);
1804 }
1805 else
1806 {
1807 LOGE("recv msg error.");
1808 }
1809 }
1810 }
1811
1812 LOGD("UEVENT Thread exit!!!");
1813 return NULL;
1814}
1815
1816int uevent_main()
1817{
1818 mbtk_task_info task;
1819 task.task_id = &uevnet_task_id;
1820 task.thread_run = uevnet_run;
1821 task.args = NULL;
1822 return mbtk_task_start(&task);
1823}
1824
1825/*
1826int ril_main()
1827{
1828 return mbtk_task_queue_start(&ril_task, ril_main_run);
1829}
1830*/
1831
1832int mbtk_info_server_start();
1833int InProduction_Mode(void);
1834void server_ready_set(void);
1835
b.liu9e8584b2024-11-06 19:21:28 +08001836#if 0
liubin281ac462023-07-19 14:22:54 +08001837
1838/*
1839 *Get mtdblock which name is ASR_FLAG
1840 *return path if found, else return NULL
1841 */
1842static int asrFlagPathGet(char *asr_flag_path)
1843{
1844 char buf[128];
1845 unsigned char find = 0;
1846 FILE *fd = fopen("/proc/mtd", "r");
1847 if (fd == NULL) {
1848 LOGE("Open MTD failed!");
1849 return -1;
1850 }
1851
1852 memset(buf, '\0', 128);
1853 while (fgets(buf, 128, fd) != NULL) {
1854 if(strstr(buf, "asr_flag")) {
1855 char *p = strstr(buf, "mtd");
1856 if(p)
1857 {
1858 int bln;
1859 sscanf(p, "mtd%d", &bln);
1860 sprintf(asr_flag_path, "/dev/mtdblock%d", bln);
1861 find = 1;
1862 break;
1863 }
1864 }
1865 memset(buf, '\0', 128);
1866 }
1867
1868 fclose(fd);
1869 return ((find == 1) ? 0 : -1);
1870}
b.liu9e8584b2024-11-06 19:21:28 +08001871
liubin281ac462023-07-19 14:22:54 +08001872static int readFromMTD(const char *path, unsigned int offset, void *buf, int size)
1873{
1874 int ret, fd;
1875 if (!path)
1876 return -1;
1877
1878 fd = open(path, O_RDONLY);
1879 if (fd < 0) {
1880 LOGE("readFromMTD open error,%d", errno);
1881 return -1;
1882 }
1883
1884 ret = lseek(fd, offset, SEEK_SET);
1885 if (ret < 0) {
1886 close(fd);
1887 LOGE("readFromMTD lseek error,%d", errno);
1888 return -1;
1889 }
1890 ret = read(fd, buf, size);
1891 if (ret < 0) {
1892 close(fd);
1893 LOGE("readFromMTD read error,%d", errno);
1894 return -1;
1895 }
1896 close(fd);
1897 return 0;
1898}
1899
1900static int writeToMTD(const char *path, unsigned int offset, void *buf, int size)
1901{
1902 int ret, fd;
1903
1904 if (!path)
1905 return -1;
1906
1907 fd = open(path, O_RDWR | O_SYNC);
1908 if (fd < 0)
1909 return -1;
1910
1911 ret = lseek(fd, offset, SEEK_SET);
1912 if (ret < 0) {
1913 close(fd);
1914 return -1;
1915 }
1916 ret = write(fd, buf, size);
1917 if (ret < 0) {
1918 LOGE("writetomtd:write error:%d", errno);
1919 close(fd);
1920 return -1;
1921 }
1922
1923 close(fd);
1924 return 0;
1925}
b.liu9e8584b2024-11-06 19:21:28 +08001926#endif
liubin281ac462023-07-19 14:22:54 +08001927static void fota_result_check()
1928{
1929#if 0
1930 ASR_flag tag;
1931 char asr_flag_path[30] = {0};
1932 if(asrFlagPathGet(asr_flag_path)) {
1933 LOGE("getAsrFlagPath() fail.");
1934 return;
1935 }
1936
1937 if(readFromMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
1938 {
1939 LOGE("Get FOTA result fail.");
1940 }
1941 else
1942 {
1943 LOGD("FOTA result : %d, %d", tag.fota_result[0], tag.fota_result[1]);
1944 tag.fota_result[0] = 0;
1945 tag.fota_result[1] = 0;
1946 if(writeToMTD(asr_flag_path, ASR_FLAG_OFFSET, &tag, sizeof(tag)) < 0)
1947 {
1948 LOGE("FOTA result update fail.");
1949 } else {
1950 LOGD("FOTA result update success.");
1951 }
1952 }
1953#endif
1954}
1955
b.liubb590492024-06-13 16:42:08 +08001956static void mbtk_ril_ready()
liubin281ac462023-07-19 14:22:54 +08001957{
1958 // /etc/init.d/mbtk_boot_server_ready
b.liubb590492024-06-13 16:42:08 +08001959 if(is_first_boot) {
1960 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
1961 LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
b.liu9e8584b2024-11-06 19:21:28 +08001962 mbtk_system(MBTK_BOOT_SERVER_READY);
b.liubb590492024-06-13 16:42:08 +08001963 } else {
1964 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
1965 }
liubin281ac462023-07-19 14:22:54 +08001966 } else {
b.liubb590492024-06-13 16:42:08 +08001967 LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
liubin281ac462023-07-19 14:22:54 +08001968 }
1969}
1970
1971#if 1
1972int main(int argc, char *argv[])
1973{
1974 mbtk_log_init("radio", "MBTK_RIL");
b.liubb590492024-06-13 16:42:08 +08001975
b.liubcf86c92024-08-19 19:48:28 +08001976 MBTK_SOURCE_INFO_PRINT("mbtk_rild");
1977
b.liubb590492024-06-13 16:42:08 +08001978#ifdef MBTK_DUMP_SUPPORT
1979 mbtk_debug_open(NULL, TRUE);
1980#endif
1981
1982// Using Killall,the file lock may be not release.
1983#if 0
1984 if(app_already_running(MBTK_RILD_PID_FILE)) {
1985 LOGW("daemon already running.");
1986 exit(1);
1987 }
1988#endif
1989
liubin281ac462023-07-19 14:22:54 +08001990 LOGI("mbtk_ril start.");
1991
b.liubb590492024-06-13 16:42:08 +08001992 int fd = open(MBTK_RILD_TEMP_FILE, O_CREAT | O_RDWR, 0644);
1993 if(fd > 0) {
b.liu9e8584b2024-11-06 19:21:28 +08001994 char buff[100] = {0};
b.liubb590492024-06-13 16:42:08 +08001995 int count = 0;
1996 if(read(fd, buff, sizeof(buff)) > 0) {
1997 count = atoi(buff);
1998 } else {
1999 count = 0;
2000 }
2001
2002 if(count <= 0) {
2003 is_first_boot = TRUE;
2004 count = 0;
2005 } else {
2006 is_first_boot = FALSE;
2007 }
2008
2009 count++;
2010 memset(buff, 0, sizeof(buff));
2011 snprintf(buff, sizeof(buff), "%d", count);
b.liu9e8584b2024-11-06 19:21:28 +08002012 mbtk_write(fd, buff, strlen(buff));
b.liubb590492024-06-13 16:42:08 +08002013 close(fd);
2014 } else {
2015 is_first_boot = FALSE;
2016 LOGE("Open %s fail:%d", MBTK_RILD_TEMP_FILE, errno);
2017 LOGW("Will not exec %s and %s.", MBTK_BOOT_SERVER_READY, MBTK_BOOT_NET_READY);
2018 }
2019
liubin281ac462023-07-19 14:22:54 +08002020 if(InProduction_Mode()) {
2021 LOGI("Is Production Mode, will exit...");
2022 exit(0);
2023 }
2024
2025 int at_sock = openSocket("/tmp/atcmd_at");
2026 if(at_sock < 0)
2027 {
2028 LOGE("Open AT Socket Fail[%d].", errno);
2029 return -1;
2030 }
2031 int uart_sock = openSocket("/tmp/atcmd_urc");
2032 if(uart_sock < 0)
2033 {
2034 LOGE("Open Uart Socket Fail[%d].", errno);
2035 return -1;
2036 }
2037
2038 at_set_on_reader_closed(onATReaderClosed);
2039 at_set_on_timeout(onATTimeout);
2040
2041 if(at_open(at_sock, uart_sock, onUnsolicited))
2042 {
2043 LOGE("Start AT thread fail.");
2044 return -1;
2045 }
2046
2047#if 1
2048 if(at_handshake())
2049 {
2050 LOGE("AT handshake fail.");
2051 return -1;
2052 }
2053#endif
2054
2055 LOGD("AT OK.");
2056
2057 if(mbtk_info_server_start())
2058 {
2059 LOGE("mbtk_info_server_start() fail.");
2060 return -1;
2061 }
b.liubb590492024-06-13 16:42:08 +08002062
liuyang15f493d2024-09-12 17:45:41 +08002063 char led_enable_str[10];
2064 memset(led_enable_str, 0, 10);
2065 property_get("persist.mbtk.led_enable", led_enable_str, "1");
2066 if(atoi(led_enable_str) == 1) { // NTP time
2067 LOG("Start LED thread.");
2068 mbtk_led_init();
2069 }
liubin281ac462023-07-19 14:22:54 +08002070
2071#if 0
2072 if(uevent_main())
2073 {
2074 LOGE("Start uevent thread fail.");
2075 return -1;
2076 }
2077#endif
2078
2079 char time_type[10];
2080 memset(time_type, 0, 10);
2081 property_get("persist.mbtk.time_type", time_type, "0");
2082 if(atoi(time_type) == MBTK_TIME_TYPE_NTP) { // NTP time
2083 LOG("Start NTP thread.");
2084 ntp_thread_start();
2085 }
2086
2087 fota_result_check();
2088
b.liubb590492024-06-13 16:42:08 +08002089 mbtk_ril_ready();
liubin281ac462023-07-19 14:22:54 +08002090
2091 server_ready_set();//Set the server readiness state
2092 while(1)
2093 {
2094 sleep(24 * 60 * 60);
2095 }
2096
2097 LOGD("!!!mbtk_ril exit!!!");
2098 return 0;
2099}
2100
2101#else
2102int main()
2103{
2104 char buff[BUFFER_SIZE + 1] = {0};
2105 if(!mbtk_at("AT+CFUN=1", buff, BUFFER_SIZE))
2106 {
2107 LOGD("+CFUN RSP:%s", buff);
2108 while(1)
2109 {
2110 sleep(1);
2111 memset(buff, 0x0, BUFFER_SIZE + 1);
2112 if(!mbtk_at("AT+CGPADDR", buff, BUFFER_SIZE))
2113 {
2114 LOGD("+CGPADDR RSP:%s", buff);
2115 if(strstr(buff, "+CGPADDR:"))
2116 {
2117 // +CGPADDR: 1, "10.99.223.168", "254.128.0.0.0.0.0.0.0.1.0.0.117.9.250.59"
2118 //
2119 // OK
2120 char *ip_start = NULL;
2121 char *ip_end = NULL;
2122 char ipv4[50] = {0};
2123 ip_start = strstr(buff,"\"");
2124 if(ip_start)
2125 ip_end = strstr(ip_start + 1, "\"");
2126 if(ip_start && ip_end && ip_end - ip_start - 1 > 0)
2127 {
2128 memcpy(ipv4, ip_start + 1, ip_end - ip_start - 1);
2129 LOGD("IP : %s", ipv4);
2130 if(!mbtk_ifc_open())
2131 {
2132 in_addr_t addr;
2133 inet_aton(ipv4,(struct in_addr *)&addr);
2134 LOGD("IP : %s -> %x", ipv4, addr);
2135 if(!mbtk_ifc_set_addr("ccinet0", addr, 0))
2136 {
2137 mbtk_ifc_up("ccinet0");
2138 }
2139
2140 mbtk_ifc_close();
2141 }
2142
2143 system("route add default dev ccinet0");
2144
2145 LOGD("Set IP success.");
2146 }
2147 else
2148 {
2149 LOGD("Get IP fail.");
2150 }
2151
2152 break;
2153 }
2154 }
2155 }
2156 }
2157
2158 return 0;
2159}
2160#endif