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