blob: 438c748af22d236a5f83daef841974d0faf183e5 [file] [log] [blame]
b.liufd87baf2024-11-15 15:30:38 +08001/*
2* main.c
3*
4* mbtk_rild main file.
5*
6* The main functions are as follows:
7* 1. Execute boot script /etc/init.d/mbtk_boot_server_ready after AT is ready(Only execute one time).
8* 2. Execute boot script /etc/init.d/mbtk_boot_net_ready after network is ready(Only execute one time).
9* 3. Set the frequency band based on the relevant information in the "device_info" partition.
10* 4. Create socket server(The client implementation in API).
11* 5. Create 3 connections between atcmdsrv, related devices: /tmp/atcmd_at ,
12* /tmp/atcmd_at_1 , /tmp/atcmd_at_2
13*/
14/******************************************************************************
15
16 EDIT HISTORY FOR FILE
17
18 WHEN WHO WHAT,WHERE,WHY
19-------- -------- -------------------------------------------------------
202024/08/13 LiuBin Initial version
21
22******************************************************************************/
b.liu87afc4c2024-08-14 17:33:45 +080023#include <stdio.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include <sys/socket.h>
27#include <errno.h>
28#include <fcntl.h>
29#include <string.h>
30#include <netinet/in.h>
31#include <arpa/inet.h>
32#include <linux/un.h>
33#include <linux/netlink.h>
34#include <cutils/properties.h>
35#include <time.h>
36#include <sys/time.h>
37#include <signal.h>
38#include <sys/epoll.h>
39#include <pthread.h>
40
41
42//#include "cploader.h"
43#include "mbtk_log.h"
44#include "mbtk_ifc.h"
45#include "mbtk_type.h"
46#include "atchannel.h"
47#include "at_tok.h"
48#include "mbtk_utils.h"
49#include "mbtk_task.h"
50#include "ril_info.h"
51#include "mbtk_ntp.h"
52#include "mbtk_net_control.h"
53#include "mbtk_ril.h"
54#include "mbtk_str.h"
55#include "mbtk_queue.h"
b.liufd87baf2024-11-15 15:30:38 +080056#include "mbtk_file.h"
b.liu87afc4c2024-08-14 17:33:45 +080057
b.liu62240ee2024-11-07 17:52:45 +080058#ifndef TEMP_FAILURE_RETRY
b.liu87afc4c2024-08-14 17:33:45 +080059#define TEMP_FAILURE_RETRY(exp) ({ \
60 typeof (exp) _rc; \
61 do { \
62 _rc = (exp); \
63 } while (_rc == -1 && errno == EINTR); \
64 _rc; })
b.liu62240ee2024-11-07 17:52:45 +080065#endif
b.liu87afc4c2024-08-14 17:33:45 +080066
67#define BUFFER_SIZE 2048
68#define UEVENT_USIM_DEV "/devices/virtual/usim_event/usim0"
69#define MBTK_BOOT_SERVER_READY "/etc/init.d/mbtk_boot_server_ready"
70#define MBTK_BOOT_NET_READY "/etc/init.d/mbtk_boot_net_ready"
71#define MBTK_RILD_PID_FILE "/var/run/mbtk_rild.pid"
72#define MBTK_RILD_FILE_NET_READY "/tmp/mbtk_rild.net_ready"
73#define MBTK_RILD_FILE_SER_READY "/tmp/mbtk_rild.ser_ready"
b.liu15f456b2024-10-31 20:16:06 +080074#define RIL_CALL_NUM_MAX 10
b.liu87afc4c2024-08-14 17:33:45 +080075
76static bool ril_net_ready = FALSE; // Only one time.
77static bool ril_server_ready = FALSE; // Only one time.
78ril_band_info_t band_info;
79ril_info_t ril_info;
b.liu15f456b2024-10-31 20:16:06 +080080static mbtk_ril_call_state_info_t call_list[RIL_CALL_NUM_MAX];
b.liuaced4f92024-12-31 11:14:51 +080081static bool cmt_found = FALSE;
82
b.liub4772072024-08-15 14:47:03 +080083extern mbtk_cell_pack_info_t cell_info;
b.liubcf86c92024-08-19 19:48:28 +080084extern ril_cgact_wait_t cgact_wait;
b.liufd87baf2024-11-15 15:30:38 +080085extern int ril_cid_start;
b.liu87afc4c2024-08-14 17:33:45 +080086
87// int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len);
88// int mbtk_signal_log(char *data);
89int InProduction_Mode(void);
90mbtk_ril_err_enum dev_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
91mbtk_ril_err_enum call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
92mbtk_ril_err_enum sim_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
93mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
b.liu15f456b2024-10-31 20:16:06 +080094mbtk_ril_err_enum data_call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
b.liu87afc4c2024-08-14 17:33:45 +080095mbtk_ril_err_enum pb_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
96mbtk_ril_err_enum sms_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
b.liu15f456b2024-10-31 20:16:06 +080097mbtk_ril_err_enum ecall_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
98
b.liub171c9a2024-11-12 19:23:29 +080099void data_call_retry(ATPortType_enum port, mbtk_ril_net_reg_state_info_t *reg_state);
b.liuafdf2c62024-11-12 11:10:44 +0800100
b.liu15f456b2024-10-31 20:16:06 +0800101void data_call_state_change_cb(int cid, bool action, bool auto_change, int reason);
102static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack);
b.liu472cfaf2024-12-19 19:08:19 +0800103int req_band_set(ATPortType_enum port, mbtk_band_info_t* band, int *cme_err);
b.liu87afc4c2024-08-14 17:33:45 +0800104
105/* Called on command thread */
106static void onATTimeout()
107{
108 LOGI("AT channel timeout; closing\n");
b.liub171c9a2024-11-12 19:23:29 +0800109 at_close(ATPORTTYPE_0);
b.liufd87baf2024-11-15 15:30:38 +0800110 at_close(ATPORTTYPE_1);
111 at_close(ATPORTTYPE_2);
b.liu87afc4c2024-08-14 17:33:45 +0800112}
113
114/* Called on command or reader thread */
115static void onATReaderClosed()
116{
117 LOGI("AT channel closed\n");
b.liub171c9a2024-11-12 19:23:29 +0800118 at_close(ATPORTTYPE_0);
b.liufd87baf2024-11-15 15:30:38 +0800119 at_close(ATPORTTYPE_1);
120 at_close(ATPORTTYPE_2);
b.liu87afc4c2024-08-14 17:33:45 +0800121}
122
123static void sock_cli_free_func(void *data)
124{
125 if (data)
126 {
127 sock_cli_info_t *info = (sock_cli_info_t*) data;
128 LOGD("Free Socket client[fd = %d].", info->fd);
129 free(info);
130 }
131}
132
b.liufd87baf2024-11-15 15:30:38 +0800133bool asr_auto_data_call_enable()
134{
135 /*
136 uci show wan_default.default.enable
137 wan_default.default.enable='1'
138
139 uci get wan_default.default.enable
140 1
141 */
142 char buff[128] = {0};
143 if(mbtk_cmd_line("uci get wan_default.default.enable", buff, sizeof(buff)) && strlen(buff) > 0) {
144 return buff[0] == '1' ? TRUE : FALSE;
145 } else {
146 return FALSE;
147 }
148}
149
b.liu87afc4c2024-08-14 17:33:45 +0800150/*
151* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
152*/
153static int net_ready_set()
154{
155 int ret = -1;
156 int fd = open(MBTK_RILD_FILE_NET_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
157 if(fd > 0) {
158 if(write(fd, "1", 1) == 1) {
159 ret = 0;
160 ril_net_ready = TRUE;
161 }
162 close(fd);
163 } else {
164 LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
165 }
166
167 return ret;
168}
169
170/*
171* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
172*/
173static int ser_ready_set()
174{
175 int ret = -1;
176 int fd = open(MBTK_RILD_FILE_SER_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
177 if(fd > 0) {
178 if(write(fd, "1", 1) == 1) {
179 ret = 0;
180 ril_server_ready = TRUE;
181 }
182 close(fd);
183 } else {
184 LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
185 }
186
187 return ret;
188}
189
190/*
191* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
192*/
193static void ready_state_update()
194{
195 int fd = open(MBTK_RILD_FILE_NET_READY, O_RDONLY, 0644);
196 char buff[10];
197 if(fd > 0) {
198 if(read(fd, buff, sizeof(buff)) > 0) {
199 ril_net_ready = TRUE;
200 } else {
201 ril_net_ready = FALSE;
202 }
203
204 close(fd);
205 } else {
206 ril_net_ready = FALSE;
207 LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
208 }
209
210 fd = open(MBTK_RILD_FILE_SER_READY, O_RDONLY, 0644);
211 if(fd > 0) {
212 if(read(fd, buff, sizeof(buff)) > 0) {
213 ril_server_ready = TRUE;
214 } else {
215 ril_server_ready = FALSE;
216 }
217
218 close(fd);
219 } else {
220 ril_server_ready = FALSE;
221 LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
222 }
223}
224
225static void mbtk_net_ready()
226{
227 // /etc/init.d/mbtk_boot_net_ready
228 if(!ril_net_ready) {
229 if(access(MBTK_BOOT_NET_READY , X_OK) == 0) {
230 LOGD("Exec : %s", MBTK_BOOT_NET_READY);
b.liu62240ee2024-11-07 17:52:45 +0800231 mbtk_system(MBTK_BOOT_NET_READY);
b.liu87afc4c2024-08-14 17:33:45 +0800232 } else {
233 LOGE("%s can not exec.", MBTK_BOOT_NET_READY);
234 }
235 net_ready_set();
236 } else {
237 LOGD("No exec : %s", MBTK_BOOT_NET_READY);
238 }
239}
240
241static void mbtk_ril_ready()
242{
243 // /etc/init.d/mbtk_boot_server_ready
244 if(!ril_server_ready) {
245 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
246 LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
b.liu62240ee2024-11-07 17:52:45 +0800247 mbtk_system(MBTK_BOOT_SERVER_READY);
b.liu87afc4c2024-08-14 17:33:45 +0800248 } else {
249 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
250 }
251 ser_ready_set();
252 } else {
253 LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
254 }
255}
256
257static sock_cli_info_t* cli_find(int fd)
258{
259 sock_cli_info_t *result = NULL;
260 list_first(ril_info.sock_client_list);
261 while ((result = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
262 {
263 if (result->fd == fd)
264 return result;
265 }
266
267 return NULL;
268}
269
270static void cli_close(sock_cli_info_t* client)
271{
272 struct epoll_event ev;
273 memset(&ev,0,sizeof(struct epoll_event));
274 ev.data.fd = client->fd;
275 ev.events = EPOLLIN | EPOLLERR | EPOLLET;
276 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_DEL, client->fd, &ev);
277
278 close(client->fd);
279
280 if(list_remove(ril_info.sock_client_list, client))
281 {
282 sock_cli_free_func(client);
283 }
284}
285
b.liub171c9a2024-11-12 19:23:29 +0800286static void ril_error_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, int err)
b.liu87afc4c2024-08-14 17:33:45 +0800287{
b.liub171c9a2024-11-12 19:23:29 +0800288 ril_msg_pack_info_t* pack = ril_msg_pack_creat(port, RIL_MSG_TYPE_RSP, ril_id, msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +0800289 if(pack)
290 {
291 pack->err = (uint16)err;
292 ril_pack_send(fd, pack);
293 ril_msg_pack_free(pack);
294 }
295 else
296 {
297 LOGW("ril_msg_pack_creat() fail.");
298 }
299}
300
b.liub171c9a2024-11-12 19:23:29 +0800301void ril_rsp_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len)
b.liu10a34102024-08-20 20:36:24 +0800302{
b.liub171c9a2024-11-12 19:23:29 +0800303 ril_msg_pack_info_t* pack = ril_msg_pack_creat(port, RIL_MSG_TYPE_RSP, ril_id, msg_index, data, data_len);
b.liu87afc4c2024-08-14 17:33:45 +0800304 if(pack)
305 {
306 pack->err = (uint16)MBTK_RIL_ERR_SUCCESS;
307#if 0
308 if(data != NULL && data_len > 0)
309 {
310 pack->data_len = (uint16)data_len;
311 pack->data = (uint8*)mbtk_memcpy(data, data_len);
312 }
313#endif
314 ril_pack_send(fd, pack);
315 ril_msg_pack_free(pack);
316 }
317 else
318 {
319 LOGW("ril_msg_pack_creat() fail.");
320 }
321}
322
323void ril_ind_pack_send(int fd, int msg_id, const void* data, int data_len)
324{
b.liub171c9a2024-11-12 19:23:29 +0800325 ril_msg_pack_info_t* pack = ril_msg_pack_creat(ATPORTTYPE_NON, RIL_MSG_TYPE_IND, msg_id, RIL_MSG_INDEX_INVALID, data, data_len);
b.liu87afc4c2024-08-14 17:33:45 +0800326 if(pack)
327 {
328 pack->err = (uint16)0;
329#if 0
330 if(data != NULL && data_len > 0)
331 {
332 pack->data_len = (uint16)data_len;
333 pack->data = (uint8*)mbtk_memcpy(data, data_len);
334 }
335#endif
336 ril_pack_send(fd, pack);
337 ril_msg_pack_free(pack);
338 }
339 else
340 {
341 LOGW("ril_msg_pack_creat() fail.");
342 }
343}
344
b.liufd87baf2024-11-15 15:30:38 +0800345void ril_state_change(ril_msg_id_enum msg_id, const void *data, int data_len)
b.liu15f456b2024-10-31 20:16:06 +0800346{
347 sock_cli_info_t *cli = NULL;
348 list_first(ril_info.sock_client_list);
349 while ((cli = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
350 {
351 if(cli->ind_num > 0) {
352 int i;
353 for(i = 0; i < IND_REGISTER_MAX; i++) {
354 if(cli->ind_register[i] == msg_id) {
355 ril_ind_pack_send(cli->fd, msg_id, data, data_len);
356 break;
357 }
358 }
359 }
360 }
361}
362
b.liu9e8584b2024-11-06 19:21:28 +0800363static int urc_msg_distribute(bool async_process, ril_msg_id_enum msg_id, const void *data, int data_len)
b.liu15f456b2024-10-31 20:16:06 +0800364{
365 // Send urc msg to client.
366 if(msg_id > RIL_MSG_ID_IND_BEGIN && msg_id < RIL_MSG_ID_IND_END) {
b.liufd87baf2024-11-15 15:30:38 +0800367 if(msg_id == RIL_MSG_ID_IND_PDP_STATE_CHANGE) {
368 mbtk_ril_pdp_state_info_t *info = (mbtk_ril_pdp_state_info_t*)data;
369 if(info->action && !info->ip_info_valid) {
370 LOGD("PDP action but no IP information, not send.");
371 } else {
372 ril_state_change(msg_id, data, data_len);
373 }
374 } else {
375 ril_state_change(msg_id, data, data_len);
376 }
b.liu15f456b2024-10-31 20:16:06 +0800377 }
378
379 // Async process urc msg.
380 if(async_process) {
381 ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
382 if(msg) {
383 msg->msg = msg_id;
384 msg->data = mbtk_memcpy(data, data_len);
385 msg->data_len = data_len;
386 if(msg->data == NULL) {
387 LOGE("mbtk_memcpy() fail.");
388 return -1;
389 }
390
391 return send_pack_to_queue(NULL, msg);
392 } else {
393 LOGE("malloc() fail.");
394 return -1;
395 }
396 }
397
398 return 0;
399}
400
401// *SIMDETEC:1,SIM
402// *EUICC:1
403// +CPIN: SIM PIN
404static void urc_sim_state_change_process(const char *s, const char *sms_pdu)
405{
406 mbtk_ril_sim_state_info_t state;
407 memset(&state, 0, sizeof(mbtk_ril_sim_state_info_t));
408 state.sim_type = MBTK_UNKNOWN;
409
b.liufd87baf2024-11-15 15:30:38 +0800410 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800411 char *line = tmp_s;
412 int tmp_int;
413 char *tmp_str;
414
415 if(strStartsWith(s, "*SIMDETEC:")) {
416 if (at_tok_start(&line) < 0)
417 {
418 goto SIM_STATE_EXIT;
419 }
420 if (at_tok_nextint(&line, &tmp_int) < 0)
421 {
422 goto SIM_STATE_EXIT;
423 }
424 if (at_tok_nextstr(&line, &tmp_str) < 0)
425 {
426 goto SIM_STATE_EXIT;
427 }
428
429 if(tmp_str) {
430 if(strcmp(tmp_str, "NOS") == 0) {
431 state.sim_type = ril_info.sim_type;
432 state.sim_state = MBTK_SIM_STATE_ABSENT;
433 ril_info.sim_state = MBTK_SIM_STATE_ABSENT;
434 urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
435 } else if(strcmp(tmp_str, "SIM") == 0) {
436 state.sim_type = ril_info.sim_type;
437 state.sim_state = MBTK_SIM_STATE_NOT_READY;
438 ril_info.sim_state = MBTK_SIM_STATE_NOT_READY;
439 urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
440 }
441 }
442 } else if(strStartsWith(s, "+CPIN:")){
443 if(strStartsWith(s, "+CPIN: READY"))
444 {
445 state.sim_state = MBTK_SIM_STATE_READY;
446 }
447 else if(strStartsWith(s, "+CPIN: SIM PIN"))
448 {
449 state.sim_state = MBTK_SIM_STATE_SIM_PIN;
450 }
451 else if(strStartsWith(s, "+CPIN: SIM PUK"))
452 {
453 state.sim_state = MBTK_SIM_STATE_SIM_PUK;
454 }
455 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
456 {
457 state.sim_state = MBTK_SIM_STATE_PH_SIMLOCK_PIN;
458 }
459 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
460 {
461 state.sim_state = MBTK_SIM_STATE_PH_SIMLOCK_PUK;
462 }
463 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
464 {
465 state.sim_state = MBTK_SIM_STATE_PH_FSIM_PIN;
466 }
467 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
468 {
469 state.sim_state = MBTK_SIM_STATE_PH_FSIM_PUK;
470 }
471 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
472 {
473 state.sim_state = MBTK_SIM_STATE_SIM_PIN2;
474 }
475 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
476 {
477 state.sim_state = MBTK_SIM_STATE_SIM_PUK2;
478 }
479 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
480 {
481 state.sim_state = MBTK_SIM_STATE_PH_NET_PIN;
482 }
483 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
484 {
485 state.sim_state = MBTK_SIM_STATE_PH_NET_PUK;
486 }
487 else if(strStartsWith(s, "+CPIN: PH-NETSUB PIN"))
488 {
489 state.sim_state = MBTK_SIM_STATE_PH_NETSUB_PIN;
490 }
491 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
492 {
493 state.sim_state = MBTK_SIM_STATE_PH_NETSUB_PUK;
494 }
495 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
496 {
497 state.sim_state = MBTK_SIM_STATE_PH_SP_PIN;
498 }
499 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
500 {
501 state.sim_state = MBTK_SIM_STATE_PH_SP_PUK;
502 }
503 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
504 {
505 state.sim_state = MBTK_SIM_STATE_PH_CORP_PIN;
506 }
507 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
508 {
509 state.sim_state = MBTK_SIM_STATE_PH_CORP_PUK;
510 }
511 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
512 {
513 state.sim_state = MBTK_SIM_STATE_ABSENT;
514 }
515
516 state.sim_type = ril_info.sim_type;
517 ril_info.sim_state = state.sim_state;
518
b.liufd87baf2024-11-15 15:30:38 +0800519 urc_msg_distribute(true, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
b.liu15f456b2024-10-31 20:16:06 +0800520 } else if(strStartsWith(s, "*EUICC:")){
521 if (at_tok_start(&line) < 0)
522 {
523 goto SIM_STATE_EXIT;
524 }
525 if (at_tok_nextint(&line, &tmp_int) < 0)
526 {
527 goto SIM_STATE_EXIT;
528 }
529 ril_info.sim_type = (mbtk_sim_card_type_enum)tmp_int;
530 } else {
531 LOGW("Unknown URC.");
532 }
533
534SIM_STATE_EXIT:
535 free(tmp_s);
536}
537
538// +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
539// +CALLDISCONNECT: 1
540// +CPAS: 4
541static void urc_call_state_change_process(const char *s, const char *sms_pdu)
542{
b.liufd87baf2024-11-15 15:30:38 +0800543 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800544 char *line = tmp_s;
545 int tmp_int;
546 char *tmp_str;
547
548 if(strStartsWith(s, "+CLCC:")) {
549 if (at_tok_start(&line) < 0)
550 {
551 goto CALL_STATE_EXIT;
552 }
553 if (at_tok_nextint(&line, &tmp_int) < 0) // call id
554 {
555 goto CALL_STATE_EXIT;
556 }
557
558 int i = 0;
559 while(i < RIL_CALL_NUM_MAX) {
560 if(call_list[i].call_id == tmp_int)
561 break;
562 i++;
563 }
564 if(i == RIL_CALL_NUM_MAX) { // No found this call id.
565 i = 0;
566 while(i < RIL_CALL_NUM_MAX) { // Find next empty call item.
567 if(call_list[i].call_id == 0)
568 break;
569 i++;
570 }
571 call_list[i].call_id = tmp_int;
572 }
573
574 LOGD("Found call id : %d", call_list[i].call_id);
575
576 if (at_tok_nextint(&line, &tmp_int) < 0) // dir
577 {
578 goto CALL_STATE_EXIT;
579 }
580 call_list[i].dir = (mbtk_ril_call_dir_enum)tmp_int;
581
582 if (at_tok_nextint(&line, &tmp_int) < 0) // state
583 {
584 goto CALL_STATE_EXIT;
585 }
586 call_list[i].state = (mbtk_ril_call_state_enum)tmp_int;
587
588 if (at_tok_nextint(&line, &tmp_int) < 0) // mode
589 {
590 goto CALL_STATE_EXIT;
591 }
592
593 if (at_tok_nextint(&line, &tmp_int) < 0) // mpty
594 {
595 goto CALL_STATE_EXIT;
596 }
597
598 if (at_tok_nextstr(&line, &tmp_str) < 0) // number
599 {
600 goto CALL_STATE_EXIT;
601 }
602 memset(call_list[i].call_number, 0, sizeof(call_list[i].call_number));
603 if(tmp_str && strlen(tmp_str) > 0) {
604 memcpy(call_list[i].call_number, tmp_str, strlen(tmp_str));
605 }
606
607 if (at_tok_nextint(&line, &tmp_int) < 0) // type
608 {
609 goto CALL_STATE_EXIT;
610 }
611 call_list[i].num_type = (mbtk_ril_call_num_type_enum)tmp_int;
612
613 urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));
614 } else if(strStartsWith(s, "+CALLDISCONNECT:")){
615 if (at_tok_start(&line) < 0)
616 {
617 goto CALL_STATE_EXIT;
618 }
619 if (at_tok_nextint(&line, &tmp_int) < 0) // call id
620 {
621 goto CALL_STATE_EXIT;
622 }
623
624 int i = 0;
625 while(i < RIL_CALL_NUM_MAX) {
626 if(call_list[i].call_id == tmp_int)
627 break;
628 i++;
629 }
630
631 if(i == RIL_CALL_NUM_MAX) { // No found this call id.
632 LOGE("No found this call id : %d", tmp_int);
633 goto CALL_STATE_EXIT;
634 }
635
636 call_list[i].state = MBTK_RIL_CALL_STATE_DISCONNECT;
637
638 urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));
639
640 // Reset after call disconnect.
641 memset(&(call_list[i]), 0, sizeof(mbtk_ril_call_state_info_t));
642 } else if(strStartsWith(s, "+CPAS:")){
643
644 } else {
645 LOGW("Unknown URC.");
646 }
647
648CALL_STATE_EXIT:
649 free(tmp_s);
650}
651
652// *ECALLDATA: <urc_id>[,<urc_data>]
653static void urc_ecall_state_change_process(const char *s, const char *sms_pdu)
654{
655 mbtk_ril_ecall_state_info_t ecall_state;
656 memset(&ecall_state, 0, sizeof(mbtk_ril_ecall_state_info_t));
657
b.liufd87baf2024-11-15 15:30:38 +0800658 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800659 char *line = tmp_s;
660 int tmp_int;
661 char *tmp_str;
662 if (at_tok_start(&line) < 0)
663 {
664 goto ECALLDATA_EXIT;
665 }
666 if (at_tok_nextint(&line, &tmp_int) < 0)
667 {
668 goto ECALLDATA_EXIT;
669 }
670 ecall_state.urc_id = (uint8)tmp_int; // urc_id
671 if (at_tok_nextstr(&line, &tmp_str) < 0)
672 {
673 goto ECALLDATA_EXIT;
674 }
675
676 if(tmp_str && strlen(tmp_str) > 0) {
677 memcpy(ecall_state.urc_data, tmp_str, strlen(tmp_str));
678 }
679
680 urc_msg_distribute(false, RIL_MSG_ID_IND_ECALL_STATE_CHANGE, &ecall_state, sizeof(mbtk_ril_ecall_state_info_t));
681ECALLDATA_EXIT:
682 free(tmp_s);
683}
684
685// +CMT: ,23
686// 0891683108200855F6240D91688189911196F10000221130717445230331D90C
687static void urc_sms_state_change_process(const char *s, const char *sms_pdu)
688{
b.liuaced4f92024-12-31 11:14:51 +0800689 mbtk_ril_sms_state_info_t sms_info;
690 memset(&sms_info, 0, sizeof(mbtk_ril_sms_state_info_t));
691 char* tmp_s = memdup(s,strlen(s) + 1);
692 char *line = tmp_s;
693 char *tmp_str;
694 if (at_tok_start(&line) < 0)
695 {
696 goto CMT_EXIT;
697 }
698 if (at_tok_nextstr(&line, &tmp_str) < 0)
699 {
700 goto CMT_EXIT;
701 }
702 if (at_tok_nextstr(&line, &tmp_str) < 0)
703 {
704 goto CMT_EXIT;
705 }
706 sms_info.pdu_len = (uint16)atoi(tmp_str);
707 memcpy(sms_info.pdu, sms_pdu, strlen(sms_pdu));
b.liu15f456b2024-10-31 20:16:06 +0800708
b.liuaced4f92024-12-31 11:14:51 +0800709 urc_msg_distribute(false, RIL_MSG_ID_IND_SMS_STATE_CHANGE, &sms_info, sizeof(mbtk_ril_sms_state_info_t));
710CMT_EXIT:
711 free(tmp_s);
b.liu15f456b2024-10-31 20:16:06 +0800712}
713
714// +CREG: 1, "8010", "000060a5", 0, 2, 0
715// +CREG: 1, "8330", "06447347", 7, 2, 0
716// +CEREG: 1, "8330", "06447347", 7
717// $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
718// $CREG: 1, "8010", "000060a7", 0,, 2, 0
719// +CGREG: 1
720static void urc_net_reg_state_change_process(const char *s, const char *sms_pdu)
721{
722 mbtk_ril_net_reg_state_info_t state;
723 memset(&state, 0, sizeof(mbtk_ril_net_reg_state_info_t));
724 state.tech = MBTK_RADIO_TECH_UNKNOWN;
725
726 if(strStartsWith(s, "+CREG:"))
727 {
728 state.type = MBTK_NET_REG_TYPE_CALL;
729 } else if(strStartsWith(s, "+CGREG:")) {
730 state.type = MBTK_NET_REG_TYPE_DATA_GSM_WCDMA;
731 } else {
732 state.type = MBTK_NET_REG_TYPE_DATA_LTE;
733 }
734
b.liufd87baf2024-11-15 15:30:38 +0800735 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800736 char *line = tmp_s;
737 int tmp_int;
738 char *tmp_str;
739 if (at_tok_start(&line) < 0)
740 {
741 goto CGREG_EXIT;
742 }
743 if (at_tok_nextint(&line, &tmp_int) < 0)
744 {
745 goto CGREG_EXIT;
746 }
747 state.reg_state = (mbtk_net_reg_state_enum)tmp_int; // Reg State.
748 if (state.reg_state) // Reg
749 {
750 if (at_tok_nextstr(&line, &tmp_str) < 0)
751 {
752 goto CGREG_EXIT;
753 }
b.liufd87baf2024-11-15 15:30:38 +0800754
b.liu15f456b2024-10-31 20:16:06 +0800755 if (at_tok_nextstr(&line, &tmp_str) < 0)
756 {
757 goto CGREG_EXIT;
758 }
b.liufd87baf2024-11-15 15:30:38 +0800759
b.liu15f456b2024-10-31 20:16:06 +0800760 if (at_tok_nextint(&line, &tmp_int) < 0)
761 {
762 goto CGREG_EXIT;
763 }
b.liufd87baf2024-11-15 15:30:38 +0800764
b.liu15f456b2024-10-31 20:16:06 +0800765 state.tech = (mbtk_radio_technology_enum)tmp_int; // AcT
766 }
767
b.liu62240ee2024-11-07 17:52:45 +0800768 if(state.reg_state == MBTK_NET_REG_STATE_HOME
769 || state.reg_state == MBTK_NET_REG_STATE_ROAMING) {
770 mbtk_net_ready();
771 }
772
b.liuafdf2c62024-11-12 11:10:44 +0800773 // Should restart data call if necessary.
774 urc_msg_distribute(true, RIL_MSG_ID_IND_NET_REG_STATE_CHANGE, &state, sizeof(mbtk_ril_net_reg_state_info_t));
b.liu15f456b2024-10-31 20:16:06 +0800775CGREG_EXIT:
776 free(tmp_s);
777}
778
779static void urc_pdp_state_change_process(const char *s, const char *sms_pdu)
b.liubcf86c92024-08-19 19:48:28 +0800780{
781 // "CONNECT"
782 if(strStartsWith(s, "CONNECT"))
783 {
784#if 1
785 if(cgact_wait.waitting && cgact_wait.act) {
786 cgact_wait.waitting = false;
787 }
788#endif
789 }
790 // +CGEV:
791 // +CGEV: NW DEACT <cid>,<cid>
792 // +CGEV: ME DEACT <cid>,<cid>
793 // +CGEV: NW PDN DEACT <cid>
794 // +CGEV: ME PDN DEACT <cid>
795 // +CGEV: NW DETACH
796 // +CGEV: ME DETACH
797 //
798 // +CGEV: NW ACT <cid>,<cid>
799 // +CGEV: ME ACT <cid>,<cid>
800 // +CGEV: EPS PDN ACT <cid>
801 // +CGEV: ME PDN ACT <cid>,<reason>,<cid>
802 // +CGEV: ME PDN ACT <cid>,<reason>
803 // +CGEV: NW PDN ACT <cid>
804 // +CGEV: EPS ACT <cid>
805 // +CGEV: NW MODIFY <cid>,<reason>
806 // +CGEV: NW REATTACH
807
808 /*
809 +CGEV: NW DETACH
810 +CGEV: ME DETACH
811 +CGEV: NW CLASS <class>
812 +CGEV: ME CLASS <class>
813 +CGEV: NW PDN ACT <cid>
814 +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
815 +CGEV: NW ACT <p_cid>, <cid>, <event_type>
816 +CGEV: ME ACT <p_cid>, <cid>, <event_type>
817 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
818 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
819 +CGEV: NW PDN DEACT <cid>
820 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
821 +CGEV: ME PDN DEACT <cid>
822 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
823 +CGEV: NW DEACT <p_cid>, <cid>, <event_type>
824 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
825 +CGEV: ME DEACT <p_cid>, <cid>, <event_type>
826 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
827 +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
828 +CGEV: ME MODIFY <cid>, <change_reason>, <event_type>
829 +CGEV: REJECT <PDP_type>, <PDP_addr>
830 +CGEV: NW REACT <PDP_type>, <PDP_addr>, [<cid>]
831 */
832 else if(strStartsWith(s, "+CGEV:"))
833 {
834#if 1
835 // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
836 // "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
837 // "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
838 // "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
839 // "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
840 // "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
841 // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
b.liu15f456b2024-10-31 20:16:06 +0800842 mbtk_ril_pdp_state_info_t cgev_info;
843 memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));
b.liu62240ee2024-11-07 17:52:45 +0800844 int cid, reason = 0;
845 memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));
846 if (sscanf(s, "+CGEV: NW PDN DEACT %d", &cid) == 1) {
847 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800848 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800849 } else if (sscanf(s, "+CGEV: ME PDN DEACT %d", &cid) == 1) {
850 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800851 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800852 } else if(sscanf(s, "+CGEV: ME PDN ACT %d,%d", &cid, &reason) == 2
853 || sscanf(s, "+CGEV: ME PDN ACT %d", &cid) == 1) {
854 cgev_info.cid = (uint16)cid;
855 cgev_info.reason = (uint16)reason;
b.liu15f456b2024-10-31 20:16:06 +0800856 cgev_info.action = TRUE;
b.liubcf86c92024-08-19 19:48:28 +0800857 } else if (!strcmp(s, "+CGEV: ME DETACH")) {
858 if(cgact_wait.waitting) {
b.liu15f456b2024-10-31 20:16:06 +0800859 cgev_info.cid = cgact_wait.cid;
b.liubcf86c92024-08-19 19:48:28 +0800860 }
b.liu15f456b2024-10-31 20:16:06 +0800861 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800862 } else if (sscanf(s, "+CGEV: NW MODIFY %d,%d", &cid, &reason) == 2) {
863 cgev_info.cid = (uint16)cid;
864 cgev_info.reason = (uint16)reason;
b.liu15f456b2024-10-31 20:16:06 +0800865 cgev_info.action = TRUE;
b.liu62240ee2024-11-07 17:52:45 +0800866 } else if(sscanf(s, "+CGEV: EPS PDN ACT %d", &cid) == 1) {
867 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800868 cgev_info.action = TRUE;
b.liubcf86c92024-08-19 19:48:28 +0800869 } else {
870 LOGD(">>>>>>>>>No process +CGEV <<<<<<<<<");
871 return;
872 }
b.liu15f456b2024-10-31 20:16:06 +0800873 cgev_info.auto_change = !cgact_wait.waitting;
b.liubcf86c92024-08-19 19:48:28 +0800874
875 if(cgact_wait.act) {
b.liu15f456b2024-10-31 20:16:06 +0800876 if(cgact_wait.waitting && cgev_info.action && cgact_wait.cid == cgev_info.cid) {
b.liubcf86c92024-08-19 19:48:28 +0800877 cgact_wait.waitting = false;
878 }
879 } else {
b.liu15f456b2024-10-31 20:16:06 +0800880 if(cgact_wait.waitting && !cgev_info.action && cgact_wait.cid == cgev_info.cid) {
b.liubcf86c92024-08-19 19:48:28 +0800881 cgact_wait.waitting = false;
882 }
883 }
884
b.liu15f456b2024-10-31 20:16:06 +0800885 LOGD("+CGEV:cid - %d, act - %d, auto_change - %d, reason - %d", cgev_info.cid, cgev_info.action,
886 cgev_info.auto_change, cgev_info.reason);
b.liu15f456b2024-10-31 20:16:06 +0800887 if(cgev_info.cid >= MBTK_APN_CID_MIN && cgev_info.cid <= MBTK_APN_CID_MAX) {
b.liuafdf2c62024-11-12 11:10:44 +0800888 data_call_state_change_cb(cgev_info.cid, cgev_info.action, cgev_info.auto_change, cgev_info.reason);
b.liu15f456b2024-10-31 20:16:06 +0800889 urc_msg_distribute(false, RIL_MSG_ID_IND_PDP_STATE_CHANGE, &cgev_info, sizeof(mbtk_ril_pdp_state_info_t));
890 }
891
b.liubcf86c92024-08-19 19:48:28 +0800892#else
893 if(at_process) {
894 if(cgact_wait.act) {
895 if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT 15,4
896 if(cgact_wait.cid == atoi(s + 18)) {
897 cgact_wait.waitting = false;
898 }
899
900 uint8 data_pdp;
901 char* tmp_s = memdup(s + 18,strlen(s + 18));
902 char* free_ptr = tmp_s;
903 char *line = tmp_s;
904 int tmp_int;
905 if (at_tok_start(&line) < 0)
906 {
907 goto at_PDP_CREG_EXIT;
908 }
909 if (at_tok_nextint(&line, &tmp_int) < 0)
910 {
911 goto at_PDP_CREG_EXIT;
912 }
913 if (at_tok_nextint(&line, &tmp_int) < 0)
914 {
915 goto at_PDP_CREG_EXIT;
916 }
917 data_pdp = tmp_int;
918at_PDP_CREG_EXIT:
919 free(free_ptr);
920
921 //data_pdp = (uint8)atoi(s + 20); //reason
922 if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
923 {
924 if(data_pdp == 0)
925 {
926 data_pdp = 25;
927 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
928 //data_pdp = cgact_wait.cid + 200;
929 }
930 else if(data_pdp == 1)
931 {
932 data_pdp = 26;
933 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
934 }
935 else if(data_pdp == 2)
936 {
937 data_pdp = 27;
938 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
939 }
940 else if(data_pdp == 3)
941 {
942 data_pdp = 27;
943 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
944 }
945 else
946 {
947
948 }
949 if(cgact_wait.cid != 0)
950 {
951 data_pdp = cgact_wait.cid + 200;
952 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
953 }
954 }
955 } else if(strStartsWith(s, "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY 1,4
956 if(cgact_wait.cid == atoi(s + 17)) {
957 cgact_wait.waitting = false;
958 }
959 }
960 } else {
961 if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
962 if(cgact_wait.cid == atoi(s + 20)) {
963 cgact_wait.waitting = false;
964 }
965 uint8 data_pdp;
966 data_pdp = 0; //
967 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
968 if(cgact_wait.cid != 0)
969 {
970 data_pdp = cgact_wait.cid + 100;
971 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
972 }
973 }
974 }
975 } else {
976 // apn_state_set
977
978 // +CGEV: NW PDN DEACT <cid>
979
980 // +CGEV: EPS PDN ACT 1
981 // +CGEV: ME PDN ACT 8,1
982
983 // +CGEV: ME PDN ACT 2,4
984 uint8 data[2] = {0xFF};
985 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
986 //apn_state_set(atoi(s + 20), false);
987 data[0] = (uint8)0;
988 data[1] = (uint8)atoi(s + 20);
989
990 uint8 data_pdp;
991 data_pdp = 0; //
992 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
993 data_pdp = data[1] + 100;
994 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
995 } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
996 //apn_state_set(atoi(s + 19), true);
997#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
998 //data[0] = (uint8)1;
999 //data[1] = (uint8)atoi(s + 19);
1000#else
1001 data[0] = (uint8)1;
1002 data[1] = (uint8)atoi(s + 19);
1003#endif
1004 } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
1005 //apn_state_set(atoi(s + 19), true);
1006 data[0] = (uint8)0;
1007 data[1] = (uint8)atoi(s + 20);
1008
1009 uint8 data_pdp;
1010 data_pdp = 0; //
1011 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1012 data_pdp = data[1] + 100;
1013 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1014 } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
1015 //apn_state_set(atoi(s + 18), true);
1016 data[0] = (uint8)1;
1017 data[1] = (uint8)atoi(s + 18);
1018
1019 uint8 data_pdp;
1020 char* tmp_s = memdup(s + 18,strlen(s + 18));
1021 char* free_ptr = tmp_s;
1022 char *line = tmp_s;
1023 int tmp_int;
1024 if (at_tok_start(&line) < 0)
1025 {
1026 goto PDP_CREG_EXIT;
1027 }
1028 if (at_tok_nextint(&line, &tmp_int) < 0)
1029 {
1030 goto PDP_CREG_EXIT;
1031 }
1032 if (at_tok_nextint(&line, &tmp_int) < 0)
1033 {
1034 goto PDP_CREG_EXIT;
1035 }
1036 data_pdp = tmp_int;
1037PDP_CREG_EXIT:
1038 free(free_ptr);
1039 //data_pdp = (uint8)atoi(s + 20); //reason
1040 if(data[1] >= 1 && data[1] < 8)
1041 {
1042 if(data_pdp == 0)
1043 {
1044 data_pdp = 25;
1045 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1046 }
1047 else if(data_pdp == 1)
1048 {
1049 data_pdp = 26;
1050 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1051 }
1052 else if(data_pdp == 2)
1053 {
1054 data_pdp = 27;
1055 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1056 }
1057 else if(data_pdp == 3)
1058 {
1059 data_pdp = 27;
1060 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1061 }
1062 else
1063 {
1064
1065 }
1066
1067 data_pdp = data[1] + 200;
1068 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1069 data[1] = 0;
1070 }
1071 } else {
1072 LOGI("No process : %s", s);
1073 }
1074
1075 urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
1076 }
1077#endif
1078 } else {
1079 LOGW("Unknown PDP URC : %s", s);
1080 }
1081}
1082
1083
1084static void urc_cell_info_process(const char *s, const char *sms_pdu)
b.liub4772072024-08-15 14:47:03 +08001085{
1086 /*
1087 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
1088 // <rsrp>,<rsrq>, <sinr>,
1089 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
1090 // cellId,subFrameAssignType,specialSubframePatterns,transMode
1091 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
1092 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
1093 // dlBer, ulBer,
1094 // diversitySinr, diversityRssi
1095 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
1096 0, 0, 0,
1097 1, 10, 0, 1, 0, 1059, 78, 3959566565,
1098 105149248, 2, 7, 7,
1099 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
1100 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
1101 0, 0,
1102 7, 44
1103 */
1104 if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
1105 {
1106 // tac, PCI, dlEuarfcn, ulEuarfcn, band
1107 if(cell_info.running) {
1108 int tmp_int;
1109 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001110 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001111 char* free_ptr = tmp_s;
1112 char *line = tmp_s;
1113 if (at_tok_start(&line) < 0)
1114 {
1115 goto EEMLTESVC_EXIT;
1116 }
1117
1118 if (at_tok_nextint(&line, &tmp_int) < 0)
1119 {
1120 goto EEMLTESVC_EXIT;
1121 }
1122 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int; //mcc
1123 if (at_tok_nextint(&line, &tmp_int) < 0)
1124 {
1125 goto EEMLTESVC_EXIT;
1126 }
1127 if (at_tok_nextint(&line, &tmp_int) < 0)
1128 {
1129 goto EEMLTESVC_EXIT;
1130 }
1131 cell_info.cell_list.cell[cell_info.cell_list.num].value7 = (uint32)tmp_int; //mnc
1132 /*
1133 // Jump 2 integer.
1134 i = 0;
1135 while(i < 2) {
1136 if (at_tok_nextint(&line, &tmp_int) < 0)
1137 {
1138 goto EEMLTESVC_EXIT;
1139 }
1140 i++;
1141 }
1142 */
1143 if (at_tok_nextint(&line, &tmp_int) < 0)
1144 {
1145 goto EEMLTESVC_EXIT;
1146 }
1147 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int; //tac
1148 if (at_tok_nextint(&line, &tmp_int) < 0)
1149 {
1150 goto EEMLTESVC_EXIT;
1151 }
1152 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int; //pci
1153 if (at_tok_nextint(&line, &tmp_int) < 0)
1154 {
1155 goto EEMLTESVC_EXIT;
1156 }
1157 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int; //dl arfcn
1158 if (at_tok_nextint(&line, &tmp_int) < 0)
1159 {
1160 goto EEMLTESVC_EXIT;
1161 }
1162 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int; //ul arfcn
1163 if (at_tok_nextint(&line, &tmp_int) < 0)
1164 {
1165 goto EEMLTESVC_EXIT;
1166 }
1167 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int; //band
1168 if (at_tok_nextint(&line, &tmp_int) < 0)
1169 {
1170 goto EEMLTESVC_EXIT;
1171 }
1172 if (at_tok_nextint(&line, &tmp_int) < 0)
1173 {
1174 goto EEMLTESVC_EXIT;
1175 }
1176 cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int; //cid
1177 if (at_tok_nextint(&line, &tmp_int) < 0)
1178 {
1179 goto EEMLTESVC_EXIT;
1180 }
1181 cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int; //rsrp
1182
1183 for(i =0; i < 10; i++)
1184 {
1185 if (at_tok_nextint(&line, &tmp_int) < 0)
1186 {
1187 goto EEMLTESVC_EXIT;
1188 }
1189 }
1190 cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int; //cell identiy
1191
1192 cell_info.cell_list.num++;
1193
1194EEMLTESVC_EXIT:
1195 free(free_ptr);
1196 }
1197 }
1198 /*
1199 // index,phyCellId,euArfcn,rsrp,rsrq
1200 +EEMLTEINTER: 0, 65535, 38950, 0, 0
1201 */
1202 else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
1203 {
1204 // phyCellId,euArfcn,rsrp,rsrq
1205 if(cell_info.running) {
1206 int tmp_int;
b.liufd87baf2024-11-15 15:30:38 +08001207 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001208 char* free_ptr = tmp_s;
1209 char *line = tmp_s;
1210 if (at_tok_start(&line) < 0)
1211 {
1212 goto EEMLTEINTER_EXIT;
1213 }
1214 if (at_tok_nextint(&line, &tmp_int) < 0)
1215 {
1216 goto EEMLTEINTER_EXIT;
1217 }
1218 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1219 {
1220 goto EEMLTEINTER_EXIT;
1221 }
1222 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1223 if (at_tok_nextint(&line, &tmp_int) < 0)
1224 {
1225 goto EEMLTEINTER_EXIT;
1226 }
1227 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1228 if (at_tok_nextint(&line, &tmp_int) < 0)
1229 {
1230 goto EEMLTEINTER_EXIT;
1231 }
1232 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1233 LOG("cell line : %s", line);
1234 if (at_tok_nextint(&line, &tmp_int) < 0)
1235 {
1236 goto EEMLTEINTER_EXIT;
1237 }
1238 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1239 if (at_tok_nextint(&line, &tmp_int) < 0)
1240 {
1241 LOG("cell tmp_int : %d", tmp_int);
1242 goto EEMLTEINTER_EXIT;
1243 }
1244 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1245 LOG("cell value5 : %d", cell_info.cell_list.cell[cell_info.cell_list.num].value5);
1246 cell_info.cell_list.num++;
1247EEMLTEINTER_EXIT:
1248 free(free_ptr);
1249 }
1250 }
1251 // Do nothing
1252 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
1253 {
1254 if(cell_info.running) {
1255
1256 }
1257 }
1258 // WCDMA
1259 /*
1260 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1261
1262 // if sCMeasPresent == 1
1263 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1264 // endif
1265
1266 // if sCParamPresent == 1
1267 // rac, nom, mcc, mnc_len, mnc, lac, ci,
1268 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1269 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1270 // endif
1271
1272 // if ueOpStatusPresent == 1
1273 // rrcState, numLinks, srncId, sRnti,
1274 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1275 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1276 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1277 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1278 // endif
1279 //
1280 +EEMUMTSSVC: 3, 1, 1, 1,
1281 -80, 27, -6, -18, -115, -32768,
1282 1, 1, 1120, 2, 1, 61697, 168432821,
1283 15, 24, 10763, 0, 0, 0, 0,
1284 128, 128, 65535, 0, 0,
1285 2, 255, 65535, 4294967295,
1286 0, 0, 0, 0, 0, 0,
1287 0, 0, 0, 0, 0, 0, 1, 1,
1288 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1289 0, 0, 0, 0, 0, 0
1290 */
1291 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1292 {
1293 // lac, ci, arfcn
1294 if(cell_info.running) {
1295 int tmp_int;
1296 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001297 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001298 char* free_ptr = tmp_s;
1299 char *line = tmp_s;
1300 if (at_tok_start(&line) < 0)
1301 {
1302 goto EEMUMTSSVC_EXIT;
1303 }
1304 // Jump 12 integer.
1305 i = 0;
1306 while(i < 12) {
1307 if (at_tok_nextint(&line, &tmp_int) < 0)
1308 {
1309 goto EEMUMTSSVC_EXIT;
1310 }
1311 i++;
1312 }
1313 // mcc
1314 if (at_tok_nextint(&line, &tmp_int) < 0)
1315 {
1316 goto EEMUMTSSVC_EXIT;
1317 }
1318 cell_info.cell_list.cell[cell_info.cell_list.num].value4= (uint32)tmp_int;
1319 // mnc
1320 if (at_tok_nextint(&line, &tmp_int) < 0)
1321 {
1322 goto EEMUMTSSVC_EXIT;
1323 }
1324 cell_info.cell_list.cell[cell_info.cell_list.num].value5= (uint32)tmp_int;
1325 // lac
1326 if (at_tok_nextint(&line, &tmp_int) < 0)
1327 {
1328 goto EEMUMTSSVC_EXIT;
1329 }
1330 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1331 // ci
1332 if (at_tok_nextint(&line, &tmp_int) < 0)
1333 {
1334 goto EEMUMTSSVC_EXIT;
1335 }
1336 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1337
1338 if (at_tok_nextint(&line, &tmp_int) < 0)
1339 {
1340 goto EEMUMTSSVC_EXIT;
1341 }
1342 // cpi
1343 if (at_tok_nextint(&line, &tmp_int) < 0)
1344 {
1345 goto EEMUMTSSVC_EXIT;
1346 }
1347 cell_info.cell_list.cell[cell_info.cell_list.num].value6= (uint32)tmp_int;
1348 /*
1349 // Jump 2 integer.
1350 i = 0;
1351 while(i < 2) {
1352 if (at_tok_nextint(&line, &tmp_int) < 0)
1353 {
1354 goto EEMUMTSSVC_EXIT;
1355 }
1356 i++;
1357 }
1358 */
1359 // arfcn
1360 if (at_tok_nextint(&line, &tmp_int) < 0)
1361 {
1362 goto EEMUMTSSVC_EXIT;
1363 }
1364 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1365
1366 cell_info.cell_list.num++;
1367EEMUMTSSVC_EXIT:
1368 free(free_ptr);
1369 }
1370 }
1371 /*
1372 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1373 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1374 */
1375 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1376 {
1377 // lac, ci, arfcn
1378 if(cell_info.running) {
1379 int tmp_int;
1380 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001381 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001382 char* free_ptr = tmp_s;
1383 char *line = tmp_s;
1384 if (at_tok_start(&line) < 0)
1385 {
1386 goto EEMUMTSINTRA_EXIT;
1387 }
1388 // Jump 8 integer.
1389 i = 0;
1390 while(i < 8) {
1391 if (at_tok_nextint(&line, &tmp_int) < 0)
1392 {
1393 goto EEMUMTSINTRA_EXIT;
1394 }
1395 i++;
1396 }
1397
1398 // lac
1399 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1400 {
1401 goto EEMUMTSINTRA_EXIT;
1402 }
1403 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1404
1405 // ci
1406 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1407 {
1408 goto EEMUMTSINTRA_EXIT;
1409 }
1410 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1411
1412 // arfcn
1413 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1414 {
1415 goto EEMUMTSINTRA_EXIT;
1416 }
1417 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1418
1419 cell_info.cell_list.num++;
1420EEMUMTSINTRA_EXIT:
1421 free(free_ptr);
1422 }
1423 }
1424 /*
1425 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1426 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1427 */
1428 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1429 {
1430 // lac, ci, arfcn
1431 if(cell_info.running) {
1432 int tmp_int;
1433 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001434 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001435 char* free_ptr = tmp_s;
1436 char *line = tmp_s;
1437 if (at_tok_start(&line) < 0)
1438 {
1439 goto EEMUMTSINTERRAT_EXIT;
1440 }
1441 // Jump 7 integer.
1442 i = 0;
1443 while(i < 7) {
1444 if (at_tok_nextint(&line, &tmp_int) < 0)
1445 {
1446 goto EEMUMTSINTERRAT_EXIT;
1447 }
1448 i++;
1449 }
1450
1451 // lac
1452 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1453 {
1454 goto EEMUMTSINTERRAT_EXIT;
1455 }
1456 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1457
1458 // ci
1459 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1460 {
1461 goto EEMUMTSINTERRAT_EXIT;
1462 }
1463 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1464
1465 // arfcn
1466 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1467 {
1468 goto EEMUMTSINTERRAT_EXIT;
1469 }
1470 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1471
1472 cell_info.cell_list.num++;
1473EEMUMTSINTERRAT_EXIT:
1474 free(free_ptr);
1475 }
1476 }
1477 // GSM
1478 // +EEMGINFOBASIC: 2
1479 // Do nothing.
1480 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1481 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1482 {
1483 if(cell_info.running) {
1484
1485 }
1486 }
1487 /*
1488 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1489 // bsic, C1, C2, TA, TxPwr,
1490 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1491 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1492 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1493 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1494 // gsmBand,channelMode
1495 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1496 63, 36, 146, 1, 7,
1497 46, 42, 42, 7, 0,
1498 53, 0, 8, 0, 1, 6, 53,
1499 2, 0, 146, 42, 54, 0, 1,
1500 1, 32, 0, 0, 0, 0,
1501 0, 0
1502 */
1503 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1504 {
1505 // lac, ci, arfcn, bsic
1506 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1507 if(cell_info.running) {
1508 int tmp_int;
1509 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001510 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001511 char* free_ptr = tmp_s;
1512 char *line = tmp_s;
1513 if (at_tok_start(&line) < 0)
1514 {
1515 goto EEMGINFOSVC_EXIT;
1516 }
1517
1518 // mcc
1519 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1520 {
1521 goto EEMGINFOSVC_EXIT;
1522 }
1523 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1524
1525 //mnc_len
1526 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1527 {
1528 goto EEMGINFOSVC_EXIT;
1529 }
1530 // mnc
1531 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1532 {
1533 goto EEMGINFOSVC_EXIT;
1534 }
1535 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1536
1537 /*
1538 // Jump 3 integer.
1539 i = 0;
1540 while(i < 3) {
1541 if (at_tok_nextint(&line, &tmp_int) < 0)
1542 {
1543 goto EEMGINFOSVC_EXIT;
1544 }
1545 i++;
1546 }
1547 */
1548 // lac
1549 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1550 {
1551 goto EEMGINFOSVC_EXIT;
1552 }
1553 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1554
1555 // ci
1556 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1557 {
1558 goto EEMGINFOSVC_EXIT;
1559 }
1560 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1561
1562 // Jump 2 integer.
1563 i = 0;
1564 while(i < 2) {
1565 if (at_tok_nextint(&line, &tmp_int) < 0)
1566 {
1567 goto EEMGINFOSVC_EXIT;
1568 }
1569 i++;
1570 }
1571
1572 // bsic
1573 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1574 {
1575 goto EEMGINFOSVC_EXIT;
1576 }
1577 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1578
1579 // Jump 15 integer.
1580 i = 0;
1581 while(i < 15) {
1582 if (at_tok_nextint(&line, &tmp_int) < 0)
1583 {
1584 goto EEMGINFOSVC_EXIT;
1585 }
1586 i++;
1587 }
1588
1589 // arfcn
1590 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1591 {
1592 goto EEMGINFOSVC_EXIT;
1593 }
1594 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1595
1596 cell_info.cell_list.num++;
1597EEMGINFOSVC_EXIT:
1598 free(free_ptr);
1599 }
1600 }
1601 /*
1602 // PS_attached, attach_type, service_type, tx_power, c_value,
1603 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1604 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1605 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1606 +EEMGINFOPS: 1, 255, 0, 0, 0,
1607 0, 0, 268435501, 1, 0, 0,
1608 4, 0, 96, 0, 0, 0,
1609 0, 0, 0, 65535, 0, 13350
1610 */
1611 // Do nothing.
1612 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1613 {
1614 if(cell_info.running) {
1615
1616 }
1617 }
1618 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1619 {
1620 if(cell_info.running) {
1621 int tmp_int;
1622 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001623 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001624 char* free_ptr = tmp_s;
1625 char *line = tmp_s;
1626 if (at_tok_start(&line) < 0)
1627 {
1628 goto EEMGINFOPS_EXIT;
1629 }
1630
1631 // nc_num
1632 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1633 {
1634 LOG("cell_info.running 1= %d\n.",cell_info.running);
1635 goto EEMGINFOPS_EXIT;
1636 }
1637 // mcc
1638 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1639 {
1640 LOG("cell_info.running 2= %d\n.",cell_info.running);
1641 goto EEMGINFOPS_EXIT;
1642 }
1643 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1644
1645 // mnc
1646 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1647 {
1648 LOG("cell_info.running 3= %d\n.",cell_info.running);
1649 goto EEMGINFOPS_EXIT;
1650 }
1651 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1652
1653 // lac
1654 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1655 {
1656 LOG("cell_info.running 4= %d\n.",cell_info.running);
1657 goto EEMGINFOPS_EXIT;
1658 }
1659 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1660
1661 // rac
1662 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1663 {
1664 LOG("cell_info.running 5= %d\n.",cell_info.running);
1665 goto EEMGINFOPS_EXIT;
1666 }
1667
1668 // ci
1669 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1670 {
1671 LOG("cell_info.running 6= %d\n.",cell_info.running);
1672 goto EEMGINFOPS_EXIT;
1673 }
1674 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1675
1676 // rx_lv
1677 if (at_tok_nextint(&line, &tmp_int) < 0)
1678 {
1679 LOG("cell_info.running 7= %d\n.",cell_info.running);
1680 goto EEMGINFOPS_EXIT;
1681 }
1682
1683 // bsic
1684 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1685 {
1686 LOG("cell_info.running 8= %d\n.",cell_info.running);
1687 goto EEMGINFOPS_EXIT;
1688 }
1689 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1690
1691 // Jump 2 integer.
1692 i = 0;
1693 while(i < 2) {
1694 if (at_tok_nextint(&line, &tmp_int) < 0)
1695 {
1696 LOG("cell_info.running 9= %d\n.",cell_info.running);
1697 goto EEMGINFOPS_EXIT;
1698 }
1699 i++;
1700 }
1701
1702 // arfcn
1703 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1704 {
1705 LOG("cell_info.running 10 = %d\n.",cell_info.running);
1706 goto EEMGINFOPS_EXIT;
1707 }
1708 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1709
1710 cell_info.cell_list.num++;
1711EEMGINFOPS_EXIT:
1712 free(free_ptr);
1713 }
1714 } else {
1715 LOGW("Unknown CELL URC : %s", s);
1716 }
1717}
1718
b.liu87afc4c2024-08-14 17:33:45 +08001719
1720static void onUnsolicited(const char *s, const char *sms_pdu)
1721{
b.liufd87baf2024-11-15 15:30:38 +08001722 LOGV("URC : %s", s);
b.liu87afc4c2024-08-14 17:33:45 +08001723 // MBTK_AT_READY
b.liuaced4f92024-12-31 11:14:51 +08001724 // +CMT: ,23
1725 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
1726 // Get PDU data.
1727 if(cmt_found) {
1728 cmt_found = FALSE;
1729 urc_sms_state_change_process(s, sms_pdu);
1730 } else if (strStartsWith(s, "MBTK_AT_READY")) { // AT ready.
b.liu87afc4c2024-08-14 17:33:45 +08001731
b.liubcf86c92024-08-19 19:48:28 +08001732 } else if(strStartsWith(s, "CONNECT") || strStartsWith(s, "+CGEV:")) {
b.liu15f456b2024-10-31 20:16:06 +08001733 urc_pdp_state_change_process(s, sms_pdu);
b.liubcf86c92024-08-19 19:48:28 +08001734 } else if(strStartsWith(s, "+EEMLTESVC:") || strStartsWith(s, "+EEMLTEINTER:")
1735 || strStartsWith(s, "+EEMLTEINTRA:") || strStartsWith(s, "+EEMLTEINTERRAT:")
1736 || strStartsWith(s, "+EEMUMTSSVC:") || strStartsWith(s, "+EEMUMTSINTRA:")
1737 || strStartsWith(s, "+EEMUMTSINTERRAT:") || strStartsWith(s, "+EEMGINFOBASIC:")
1738 || strStartsWith(s, "+EEMGINFOSVC:") || strStartsWith(s, "+EEMGINFOPS:")
1739 || strStartsWith(s, "+EEMGINFONC:")) {
1740 urc_cell_info_process(s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08001741 }
1742 else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
1743 {
1744 const char* ptr = s + strlen("*RADIOPOWER:");
1745 while(*ptr != '\0' && *ptr == ' ' )
1746 {
1747 ptr++;
1748 }
1749
b.liu15f456b2024-10-31 20:16:06 +08001750 mbtk_ril_radio_state_info_t state;
1751 memset(&state, 0, sizeof(mbtk_ril_radio_state_info_t));
b.liu87afc4c2024-08-14 17:33:45 +08001752 if(*ptr == '1') {
b.liu15f456b2024-10-31 20:16:06 +08001753 state.radio_state = MBTK_RADIO_STATE_FULL_FUNC;
b.liu87afc4c2024-08-14 17:33:45 +08001754 } else {
b.liu15f456b2024-10-31 20:16:06 +08001755 state.radio_state = MBTK_RADIO_STATE_MINI_FUNC;
b.liu87afc4c2024-08-14 17:33:45 +08001756 }
b.liu15f456b2024-10-31 20:16:06 +08001757 urc_msg_distribute(true, RIL_MSG_ID_IND_RADIO_STATE_CHANGE, &state, sizeof(mbtk_ril_radio_state_info_t));
b.liu87afc4c2024-08-14 17:33:45 +08001758 }
1759 // +CREG: 1, "8010", "000060a5", 0, 2, 0
1760 // +CREG: 1, "8330", "06447347", 7, 2, 0
1761 // +CEREG: 1, "8330", "06447347", 7
1762 // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
1763 // $CREG: 1, "8010", "000060a7", 0,, 2, 0
1764 // +CGREG: 1
1765 else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
b.liu15f456b2024-10-31 20:16:06 +08001766 || strStartsWith(s, "+CEREG:") // LTE data registed.
1767 || strStartsWith(s, "+CREG:")) // GMS/WCDMA/LTE CS registed.
b.liu87afc4c2024-08-14 17:33:45 +08001768 {
b.liu15f456b2024-10-31 20:16:06 +08001769 urc_net_reg_state_change_process(s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08001770 }
b.liu15f456b2024-10-31 20:16:06 +08001771 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
1772 else if(strStartsWith(s, "+CLCC:")
1773 || strStartsWith(s, "+CPAS:")
1774 || strStartsWith(s, "+CALLDISCONNECT:"))
b.liu87afc4c2024-08-14 17:33:45 +08001775 {
b.liu15f456b2024-10-31 20:16:06 +08001776 urc_call_state_change_process(s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08001777 }
b.liu15f456b2024-10-31 20:16:06 +08001778 else if(strStartsWith(s, "*SIMDETEC:")
1779 || strStartsWith(s, "*EUICC:")
1780 || strStartsWith(s, "+CPIN:"))
1781 {
1782 urc_sim_state_change_process(s, sms_pdu);
1783 }
1784 else if(strStartsWith(s, "+CMT:"))
1785 {
b.liuaced4f92024-12-31 11:14:51 +08001786 cmt_found = TRUE;
b.liu15f456b2024-10-31 20:16:06 +08001787 urc_sms_state_change_process(s, sms_pdu);
1788 }
1789 else if(strStartsWith(s, "*ECALLDATA:"))
1790 {
1791 urc_ecall_state_change_process(s, sms_pdu);
1792 }
1793#if 0
b.liu87afc4c2024-08-14 17:33:45 +08001794 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
1795 else if(strStartsWith(s, "+CLCC:"))
1796 {
1797 mbtk_call_info_t reg;
1798 reg.call_wait = MBTK_CLCC;
1799 char* tmp_s = memdup(s,strlen(s));
1800 char* free_ptr = tmp_s;
1801 char *line = tmp_s;
1802 int tmp_int;
1803 char *tmp_str;
1804 int err;
1805
1806 err = at_tok_start(&line);
1807 if (err < 0)
1808 {
1809 goto CLCC_EXIT;
1810 }
1811 err = at_tok_nextint(&line, &tmp_int); // dir1
1812 if (err < 0)
1813 {
1814 goto CLCC_EXIT;
1815 }
1816 reg.dir1 = (uint8)tmp_int;
1817 err = at_tok_nextint(&line, &tmp_int);// dir
1818 if (err < 0)
1819 {
1820 goto CLCC_EXIT;
1821 }
1822 reg.dir = (uint8)tmp_int;
1823 err = at_tok_nextint(&line, &tmp_int);// state
1824 if (err < 0)
1825 {
1826 goto CLCC_EXIT;
1827 }
1828 reg.state = (uint8)tmp_int;
1829 err = at_tok_nextint(&line, &tmp_int);// mode
1830 if (err < 0)
1831 {
1832 goto CLCC_EXIT;
1833 }
1834 reg.mode = (uint8)tmp_int;
1835 err = at_tok_nextint(&line, &tmp_int);// mpty
1836 if (err < 0)
1837 {
1838 goto CLCC_EXIT;
1839 }
1840 reg.mpty = (uint8)tmp_int;
1841 err = at_tok_nextstr(&line, &tmp_str); // phone_number
1842 if (err < 0)
1843 {
1844 goto CLCC_EXIT;
1845 }
1846
1847 memset(reg.phone_number,0,sizeof(reg.phone_number));
1848 memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
1849 err = at_tok_nextint(&line, &tmp_int);// tpye
1850 if (err < 0)
1851 {
1852 goto CLCC_EXIT;
1853 }
1854 reg.type = (uint8)tmp_int;
1855 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
1856CLCC_EXIT:
1857 free(free_ptr);
1858 }
1859 // +CPAS: 4
1860 else if(strStartsWith(s, "+CPAS:"))
1861 {
1862 mbtk_call_info_t reg;
1863 reg.call_wait = 0;
1864 char* tmp_s = memdup(s,strlen(s));
1865 char* free_ptr = tmp_s;
1866 char *line = tmp_s;
1867 int tmp_int;
1868 int err;
1869
1870 memset(&reg,0,sizeof(reg));
1871
1872 err = at_tok_start(&line);
1873 if (err < 0)
1874 {
1875 goto CPAS_EXIT;
1876 }
1877 err = at_tok_nextint(&line, &tmp_int);
1878 if (err < 0)
1879 {
1880 goto CPAS_EXIT;
1881 }
1882 reg.pas = (uint8)tmp_int;
1883 reg.call_wait = MBTK_CPAS;
1884 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
1885CPAS_EXIT:
1886 free(free_ptr);
1887 }
1888 // +CALLDISCONNECT: 1
1889 else if(strStartsWith(s, "+CALLDISCONNECT:"))
1890 {
1891 mbtk_call_info_t reg;
1892 reg.call_wait = 0;
1893 char* tmp_s = memdup(s,strlen(s));
1894 char* free_ptr = tmp_s;
1895 char *line = tmp_s;
1896 int tmp_int;
1897 int err;
1898
1899 memset(&reg,0,sizeof(reg));
1900
1901 err = at_tok_start(&line);
1902 if (err < 0)
1903 {
1904 goto CALLDISCONNECTED_EXIT;
1905 }
1906 err = at_tok_nextint(&line, &tmp_int);
1907 if (err < 0)
1908 {
1909 goto CALLDISCONNECTED_EXIT;
1910 }
1911 reg.disconnected_id = tmp_int;
1912 reg.call_wait = MBTK_DISCONNECTED;
1913
1914 if(reg.call_wait == MBTK_DISCONNECTED)
1915 {
1916 //mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
1917 }
1918
1919 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
1920
1921CALLDISCONNECTED_EXIT:
1922 free(free_ptr);
1923 }
1924 // *SIMDETEC:1,SIM
1925 else if(strStartsWith(s, "*SIMDETEC:"))
1926 {
1927 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
1928 {
1929 net_info.sim_state = MBTK_SIM_ABSENT;
1930 }
1931
1932 sim_info_reg.sim = -1;
1933 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
1934 sim_info_reg.sim = 0;
1935 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
1936 sim_info_reg.sim = 1;
1937 if(sim_info_reg.sim == 0)
1938 {
1939 uint8 data_pdp;
1940 data_pdp = 11; //
1941 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1942 }
1943 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
1944 }
1945 // *EUICC:1
1946/*0: SIM
19471: USIM
19482: TEST SIM
19493: TEST USIM
19504: UNKNOWN
1951Note: *EUICC:
1952*/
1953 else if(strStartsWith(s, "*EUICC:"))
1954 {
1955 sim_info_reg.sim_card_type = -1;
1956 if(strStartsWith(s, "*EUICC: 0"))
1957 sim_info_reg.sim_card_type = 1;
1958 else if(strStartsWith(s, "*EUICC: 1"))
1959 sim_info_reg.sim_card_type = 2;
1960 else if(strStartsWith(s, "*EUICC: 2"))
1961 sim_info_reg.sim_card_type = 1;
1962 else if(strStartsWith(s, "*EUICC: 3"))
1963 sim_info_reg.sim_card_type = 2;
1964 else if(strStartsWith(s, "*EUICC: 4"))
1965 sim_info_reg.sim_card_type = 0;
1966 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
1967 }
1968 // +CPIN: SIM PIN
1969 else if(strStartsWith(s, "+CPIN:"))
1970 {
1971 sim_info_reg.sim = -1;
1972 if(strStartsWith(s, "+CPIN: READY"))
1973 {
1974 sim_info_reg.sim = 1;
1975 net_info.sim_state = MBTK_SIM_READY;
1976 }
1977 else if(strStartsWith(s, "+CPIN: SIM PIN"))
1978 {
1979 sim_info_reg.sim = 2;
1980 net_info.sim_state = MBTK_SIM_PIN;
1981 }
1982 else if(strStartsWith(s, "+CPIN: SIM PUK"))
1983 {
1984 sim_info_reg.sim = 3;
1985 net_info.sim_state = MBTK_SIM_PUK;
1986 }
1987 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
1988 {
1989 sim_info_reg.sim = 4;
1990 net_info.sim_state = MBTK_SIM_ABSENT;
1991 }
1992 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
1993 {
1994 sim_info_reg.sim = 5;
1995 net_info.sim_state = MBTK_SIM_ABSENT;
1996 }
1997 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
1998 {
1999 sim_info_reg.sim = 6;
2000 net_info.sim_state = MBTK_SIM_ABSENT;
2001 }
2002 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
2003 {
2004 sim_info_reg.sim = 7;
2005 net_info.sim_state = MBTK_SIM_ABSENT;
2006 }
2007 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
2008 {
2009 sim_info_reg.sim = 8;
2010 net_info.sim_state = MBTK_SIM_ABSENT;
2011 }
2012 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
2013 {
2014 sim_info_reg.sim = 9;
2015 net_info.sim_state = MBTK_SIM_ABSENT;
2016 }
2017 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
2018 {
2019 sim_info_reg.sim = 10;
2020 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
2021 }
2022 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
2023 {
2024 sim_info_reg.sim = 11;
2025 net_info.sim_state = MBTK_SIM_ABSENT;
2026 }
2027 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
2028 {
2029 sim_info_reg.sim = 12;
2030 net_info.sim_state = MBTK_SIM_ABSENT;
2031 }
2032 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
2033 {
2034 sim_info_reg.sim = 13;
2035 net_info.sim_state = MBTK_SIM_ABSENT;
2036 }
2037 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
2038 {
2039 sim_info_reg.sim = 14;
2040 net_info.sim_state = MBTK_SIM_ABSENT;
2041 }
2042 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
2043 {
2044 sim_info_reg.sim = 15;
2045 net_info.sim_state = MBTK_SIM_ABSENT;
2046 }
2047 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
2048 {
2049 sim_info_reg.sim = 16;
2050 net_info.sim_state = MBTK_SIM_ABSENT;
2051 }
2052 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
2053 {
2054 sim_info_reg.sim = 17;
2055 net_info.sim_state = MBTK_SIM_ABSENT;
2056 }
2057 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
2058 {
2059 sim_info_reg.sim = 18;
2060 net_info.sim_state = MBTK_SIM_ABSENT;
2061 }
2062 else
2063 sim_info_reg.sim = 20;
2064
2065 if(sim_info_reg.sim == 18)
2066 {
2067 uint8 data_pdp;
2068 data_pdp = 11; //
2069 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
2070 }
2071
2072 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
2073 }
2074 // +CMT: ,23
2075 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
2076 else if(strStartsWith(s, "+CMT:") || sms_cmt)
2077 {
2078 if(!sms_cmt){
2079 sms_cmt = true;
2080 }else{
2081 sms_cmt = false;
2082 }
2083 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
2084 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
2085 }
b.liub4772072024-08-15 14:47:03 +08002086#endif
b.liu87afc4c2024-08-14 17:33:45 +08002087 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"
2088 {
2089
2090 }
2091 else
2092 {
2093 LOGV("Unknown URC : %s", s);
2094 }
b.liu87afc4c2024-08-14 17:33:45 +08002095}
2096
2097static int openSocket(const char* sockname)
2098{
2099 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
2100 if (sock < 0)
2101 {
2102 LOGE("Error create socket: %s\n", strerror(errno));
2103 return -1;
2104 }
2105 struct sockaddr_un addr;
2106 memset(&addr, 0, sizeof(addr));
2107 addr.sun_family = AF_UNIX;
2108 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
2109 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
2110 {
2111 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
2112 sleep(1);
2113 }
2114
2115#if 0
2116 int sk_flags = fcntl(sock, F_GETFL, 0);
2117 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
2118#endif
2119
2120 return sock;
2121}
2122
2123static void ril_at_ready_process()
2124{
b.liub171c9a2024-11-12 19:23:29 +08002125 ril_info.radio_state = ril_radio_state_get(ATPORTTYPE_0);
b.liu87afc4c2024-08-14 17:33:45 +08002126 if (ril_info.radio_state != MBTK_RADIO_STATE_FULL_FUNC)
2127 {
b.liub171c9a2024-11-12 19:23:29 +08002128 ril_radio_state_set(ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);
b.liu87afc4c2024-08-14 17:33:45 +08002129 }
2130
2131 if(ril_info.radio_state == MBTK_RADIO_STATE_FULL_FUNC)
2132 {
b.liub171c9a2024-11-12 19:23:29 +08002133 at_send_command(ATPORTTYPE_0, "AT+CEREG=2", NULL);
b.liu87afc4c2024-08-14 17:33:45 +08002134 }
2135
b.liub171c9a2024-11-12 19:23:29 +08002136 ril_info.sim_state = ril_sim_state_get(ATPORTTYPE_0);
b.liu87afc4c2024-08-14 17:33:45 +08002137 if(ril_info.sim_state == MBTK_SIM_STATE_READY)
2138 {
2139 LOGD("SIM READY!");
b.liub171c9a2024-11-12 19:23:29 +08002140 at_send_command(ATPORTTYPE_0, "AT+COPS=3", NULL);
b.liu87afc4c2024-08-14 17:33:45 +08002141
2142 // Set APN from prop.
b.liub171c9a2024-11-12 19:23:29 +08002143 apn_auto_conf_from_prop(ATPORTTYPE_0);
b.liu87afc4c2024-08-14 17:33:45 +08002144 }
2145 else
2146 {
2147 LOGE("SIM NOT READY!");
2148 }
2149}
2150
2151static void ind_regisger(sock_cli_info_t* cli_info, uint16 ind)
2152{
2153 uint32 i = 0;
2154 while(i < cli_info->ind_num)
2155 {
2156 if(cli_info->ind_register[i] == ind)
2157 break;
2158 i++;
2159 }
2160
2161 if(i == cli_info->ind_num) // No found IND
2162 {
2163 cli_info->ind_register[i] = ind;
2164 cli_info->ind_num++;
2165 LOGD("Register IND : %s", id2str(ind));
2166 }
2167 else
2168 {
2169 LOGW("IND had exist.");
2170 }
2171}
2172
2173// Process AT URC data
2174static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack)
b.liub171c9a2024-11-12 19:23:29 +08002175{
2176 if(cli_info) {
2177 if(ril_info.msg_queue[cli_info->port].count >= PACK_PROCESS_QUEUE_MAX)
2178 {
2179 LOGE("Packet process queue is full");
2180 return -1;
2181 }
2182 } else {
2183 if(ril_info.msg_queue[ATPORTTYPE_0].count >= PACK_PROCESS_QUEUE_MAX)
2184 {
2185 LOGE("Packet process queue is full");
2186 return -1;
2187 }
2188 }
b.liu87afc4c2024-08-14 17:33:45 +08002189
2190 ril_msg_queue_info_t *item = (ril_msg_queue_info_t*)malloc(sizeof(ril_msg_queue_info_t));
2191 if(!item)
2192 {
2193 LOGE("malloc() fail[%d].", errno);
2194 return -1;
2195 }
2196 item->cli_info = cli_info;
b.liub171c9a2024-11-12 19:23:29 +08002197 item->pack = pack;
2198
2199 if(cli_info) {
2200 mbtk_queue_put(&(ril_info.msg_queue[cli_info->port]), item);
2201
2202 // If thread is waitting,continue it.
2203 pthread_mutex_lock(&(ril_info.msg_mutex[cli_info->port]));
2204 pthread_cond_signal(&(ril_info.msg_cond[cli_info->port]));
2205 pthread_mutex_unlock(&(ril_info.msg_mutex[cli_info->port]));
2206 } else { // URC message, is null.
2207 mbtk_queue_put(&(ril_info.msg_queue[ATPORTTYPE_0]), item);
2208
2209 // If thread is waitting,continue it.
2210 pthread_mutex_lock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
2211 pthread_cond_signal(&(ril_info.msg_cond[ATPORTTYPE_0]));
2212 pthread_mutex_unlock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
2213 }
b.liu87afc4c2024-08-14 17:33:45 +08002214
2215 return 0;
2216}
2217
2218
2219static void pack_distribute(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
2220{
2221 // Register IND Message.
b.liu15f456b2024-10-31 20:16:06 +08002222 if(pack->msg_type == RIL_MSG_TYPE_REQ)
2223 {
2224 if(pack->msg_id > RIL_MSG_ID_IND_BEGIN
2225 && pack->msg_id < RIL_MSG_ID_IND_END) {
2226 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
2227 if(cli_info->ind_num >= IND_REGISTER_MAX)
2228 {
2229 LOGE("IND if full.");
2230 err = MBTK_RIL_ERR_IND_FULL;
2231 }
2232 else
2233 {
2234 ind_regisger(cli_info, pack->msg_id);
2235 }
2236
b.liub171c9a2024-11-12 19:23:29 +08002237 ril_error_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, err);
b.liu15f456b2024-10-31 20:16:06 +08002238
2239 ril_msg_pack_free(pack);
2240 } else {
b.liub171c9a2024-11-12 19:23:29 +08002241 LOGD("Start process REQ(%s, Port : %d), Length : %d", id2str(pack->msg_id), cli_info->port, pack->data_len);
b.liu15f456b2024-10-31 20:16:06 +08002242 if(0 && pack->data_len > 0)
2243 {
2244 log_hex("DATA", pack->data, pack->data_len);
2245 }
2246
2247 // Send to REQ_process_thread process.
2248 send_pack_to_queue(cli_info, pack);
2249
2250 // For test.
2251 // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS);
2252 }
2253 } else {
2254 LOGE("Pack type error : %d", pack->msg_type);
2255 }
b.liu87afc4c2024-08-14 17:33:45 +08002256}
2257
2258// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
2259// Otherwise, do not call pack_error_send().
2260static mbtk_ril_err_enum pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
2261{
2262 if(pack->msg_id > RIL_MSG_ID_DEV_BEGIN && pack->msg_id < RIL_MSG_ID_DEV_END) {
2263 return dev_pack_req_process(cli_info, pack);
2264 } else if(pack->msg_id > RIL_MSG_ID_SIM_BEGIN && pack->msg_id < RIL_MSG_ID_SIM_END) {
2265 return sim_pack_req_process(cli_info, pack);
2266 } else if(pack->msg_id > RIL_MSG_ID_NET_BEGIN && pack->msg_id < RIL_MSG_ID_NET_END) {
2267 return net_pack_req_process(cli_info, pack);
b.liu15f456b2024-10-31 20:16:06 +08002268 } else if(pack->msg_id > RIL_MSG_ID_DATA_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_DATA_CALL_END) {
2269 return data_call_pack_req_process(cli_info, pack);
b.liu87afc4c2024-08-14 17:33:45 +08002270 } else if(pack->msg_id > RIL_MSG_ID_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_CALL_END) {
2271 return call_pack_req_process(cli_info, pack);
2272 } else if(pack->msg_id > RIL_MSG_ID_SMS_BEGIN && pack->msg_id < RIL_MSG_ID_SMS_END) {
2273 return sms_pack_req_process(cli_info, pack);
2274 } else if(pack->msg_id > RIL_MSG_ID_PB_BEGIN && pack->msg_id < RIL_MSG_ID_PB_END) {
2275 return pb_pack_req_process(cli_info, pack);
b.liu15f456b2024-10-31 20:16:06 +08002276 } else if(pack->msg_id > RIL_MSG_ID_ECALL_BEGIN && pack->msg_id < RIL_MSG_ID_ECALL_END) {
2277 return ecall_pack_req_process(cli_info, pack);
b.liu87afc4c2024-08-14 17:33:45 +08002278 } else {
2279 LOGW("Unknown msg id : %d", pack->msg_id);
2280 return MBTK_RIL_ERR_FORMAT;
2281 }
2282}
2283
2284static void urc_msg_process(ril_urc_msg_info_t *msg)
2285{
b.liu472cfaf2024-12-19 19:08:19 +08002286 // data can be NULL (For RIL_URC_MSG_BAND_SET)
b.liu15f456b2024-10-31 20:16:06 +08002287 if(!msg->data || msg->data_len <= 0) {
b.liu472cfaf2024-12-19 19:08:19 +08002288 LOGW("URC data is NULL.");
2289 // return;
b.liu15f456b2024-10-31 20:16:06 +08002290 }
2291
b.liu87afc4c2024-08-14 17:33:45 +08002292 switch(msg->msg) {
b.liu15f456b2024-10-31 20:16:06 +08002293 case RIL_MSG_ID_IND_RADIO_STATE_CHANGE:
2294 {
2295 mbtk_ril_radio_state_info_t *state = (mbtk_ril_radio_state_info_t*)msg->data;
2296 LOGD("Radio state : %d", state->radio_state);
b.liu87afc4c2024-08-14 17:33:45 +08002297 break;
b.liu15f456b2024-10-31 20:16:06 +08002298 }
b.liufd87baf2024-11-15 15:30:38 +08002299 case RIL_MSG_ID_IND_SIM_STATE_CHANGE:
2300 {
2301 mbtk_ril_sim_state_info_t *state = (mbtk_ril_sim_state_info_t*)msg->data;
2302 if(state->sim_state == MBTK_SIM_STATE_READY) {
2303 LOGD("SIM READY!");
2304 at_send_command(ATPORTTYPE_0, "AT+COPS=3", NULL);
2305
2306 // Set APN from prop.
2307 apn_auto_conf_from_prop(ATPORTTYPE_0);
2308 }
2309 }
b.liuafdf2c62024-11-12 11:10:44 +08002310 case RIL_MSG_ID_IND_NET_REG_STATE_CHANGE:
2311 {
2312 mbtk_ril_net_reg_state_info_t *reg_state = (mbtk_ril_net_reg_state_info_t*)msg->data;
b.liub171c9a2024-11-12 19:23:29 +08002313 data_call_retry(ATPORTTYPE_0, reg_state);
b.liuafdf2c62024-11-12 11:10:44 +08002314 break;
2315 }
b.liu472cfaf2024-12-19 19:08:19 +08002316 case RIL_URC_MSG_BAND_SET:
2317 {
2318 int cme_err = MBTK_RIL_ERR_CME_NON;
2319 if(req_band_set(ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2320 {
2321 LOGE("Set band fail.");
2322 }
2323 else // Set band success.
2324 {
2325 // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));
2326 band_info.band_set_success = TRUE;
2327 if(band_info.band_area == MBTK_MODEM_BAND_AREA_CN) {
2328 property_set("persist.mbtk.band_config", "CN");
2329 } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_EU) {
2330 property_set("persist.mbtk.band_config", "EU");
2331 } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_SA) {
2332 property_set("persist.mbtk.band_config", "SA");
2333 } else {
2334 property_set("persist.mbtk.band_config", "ALL");
2335 }
2336 LOGD("Set band success.");
2337 }
2338 break;
2339 }
b.liu87afc4c2024-08-14 17:33:45 +08002340 default:
2341 {
2342 LOGE("Unknown URC : %d", msg->msg);
2343 break;
2344 }
2345 }
2346}
2347
2348// Read client conn/msg and push into ril_info.msg_queue.
2349static void* ril_read_pthread(void* arg)
2350{
2351 UNUSED(arg);
2352 ril_info.epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1);
2353 if(ril_info.epoll_fd < 0)
2354 {
2355 LOGE("epoll_create() fail[%d].", errno);
2356 return NULL;
2357 }
2358
2359 uint32 event = EPOLLIN | EPOLLET;
2360 struct epoll_event ev;
2361 ev.data.fd = ril_info.sock_listen_fd;
2362 ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
2363 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, ril_info.sock_listen_fd, &ev);
2364
2365 int nready = -1;
2366 struct epoll_event epoll_events[EPOLL_LISTEN_MAX];
2367 while(1)
2368 {
2369 nready = epoll_wait(ril_info.epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
2370 if(nready > 0)
2371 {
2372 sock_cli_info_t *cli_info = NULL;
2373 int i;
2374 for(i = 0; i < nready; i++)
2375 {
2376 LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events);
2377 if(epoll_events[i].events & EPOLLHUP) // Client Close.
2378 {
2379 if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL)
2380 {
2381 cli_close(cli_info);
2382 }
2383 else
2384 {
2385 LOG("Unknown client[fd = %d].", epoll_events[i].data.fd);
2386 }
2387 }
2388 else if(epoll_events[i].events & EPOLLIN)
2389 {
2390 if(epoll_events[i].data.fd == ril_info.sock_listen_fd) // New clients connected.
2391 {
2392 int client_fd = -1;
2393 while(1)
2394 {
2395 struct sockaddr_in cliaddr;
2396 socklen_t clilen = sizeof(cliaddr);
2397 client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen);
2398 if(client_fd < 0)
2399 {
2400 if(errno == EAGAIN)
2401 {
2402 LOG("All client connect get.");
2403 }
2404 else
2405 {
2406 LOG("accept() error[%d].", errno);
2407 }
2408 break;
2409 }
2410 // Set O_NONBLOCK
2411 int flags = fcntl(client_fd, F_GETFL, 0);
2412 if (flags > 0)
2413 {
2414 flags |= O_NONBLOCK;
2415 if (fcntl(client_fd, F_SETFL, flags) < 0)
2416 {
2417 LOG("Set flags error:%d", errno);
2418 }
2419 }
2420
2421 memset(&ev,0,sizeof(struct epoll_event));
2422 ev.data.fd = client_fd;
2423 ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET;
2424 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, client_fd, &ev);
2425
2426 sock_cli_info_t *info = (sock_cli_info_t*)malloc(sizeof(sock_cli_info_t));
2427 if(info)
2428 {
2429 memset(info, 0, sizeof(sock_cli_info_t));
2430 info->fd = client_fd;
b.liub171c9a2024-11-12 19:23:29 +08002431
2432 // Default AT port.
2433 info->port = ATPORTTYPE_0;
2434
b.liu87afc4c2024-08-14 17:33:45 +08002435 list_add(ril_info.sock_client_list, info);
2436 LOG("Add New Client FD Into List.");
2437
b.liu15f456b2024-10-31 20:16:06 +08002438 // Send msg RIL_MSG_ID_IND_SER_STATE_CHANGE to client.
2439 mbtk_ril_ser_state_enum state = MBTK_RIL_SER_STATE_READY;
2440 ril_ind_pack_send(client_fd, RIL_MSG_ID_IND_SER_STATE_CHANGE, &state, 1);
b.liu87afc4c2024-08-14 17:33:45 +08002441 }
2442 else
2443 {
2444 LOG("malloc() fail.");
2445 }
2446 }
2447 }
2448 else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive.
2449 {
2450 // Read and process every message.
2451 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
2452 ril_msg_pack_info_t** pack = ril_pack_recv(cli_info->fd, true, &err);
b.liub171c9a2024-11-12 19:23:29 +08002453
b.liu87afc4c2024-08-14 17:33:45 +08002454 // Parse packet error,send error response to client.
2455 if(pack == NULL)
2456 {
b.liub171c9a2024-11-12 19:23:29 +08002457 ril_error_pack_send(cli_info->port, cli_info->fd, RIL_MSG_ID_UNKNOWN, RIL_MSG_INDEX_INVALID, err);
b.liu87afc4c2024-08-14 17:33:45 +08002458 }
2459 else
2460 {
2461 ril_msg_pack_info_t** pack_ptr = pack;
2462 while(*pack_ptr)
b.liub171c9a2024-11-12 19:23:29 +08002463 {
2464 // Update AT port in the first.
2465 cli_info->port = (ATPortType_enum)((*pack_ptr)->at_port);
2466
b.liu87afc4c2024-08-14 17:33:45 +08002467 pack_distribute(cli_info, *pack_ptr);
2468 // Not free,will free in pack_process() or packet process thread.
2469 //mbtk_info_pack_free(pack_ptr);
2470 pack_ptr++;
2471 }
2472
2473 free(pack);
2474 }
2475 }
2476 else
2477 {
2478 LOG("Unknown socket : %d", epoll_events[i].data.fd);
2479 }
2480 }
2481 else
2482 {
2483 LOG("Unknown event : %x", epoll_events[i].events);
2484 }
2485 }
2486 }
2487 else
2488 {
2489 LOG("epoll_wait() fail[%d].", errno);
2490 }
2491 }
2492
2493 return NULL;
2494}
2495
2496static void* ril_process_thread(void* arg)
2497{
b.liub171c9a2024-11-12 19:23:29 +08002498 UNUSED(arg);
2499 ATPortType_enum *port = (ATPortType_enum*)arg;
b.liu87afc4c2024-08-14 17:33:45 +08002500 ril_msg_queue_info_t* item = NULL;
2501
b.liub171c9a2024-11-12 19:23:29 +08002502 pthread_mutex_lock(&(ril_info.msg_mutex[*port]));
b.liu87afc4c2024-08-14 17:33:45 +08002503 while(TRUE)
2504 {
b.liub171c9a2024-11-12 19:23:29 +08002505 if(mbtk_queue_empty(&(ril_info.msg_queue[*port])))
b.liu87afc4c2024-08-14 17:33:45 +08002506 {
b.liufd87baf2024-11-15 15:30:38 +08002507 LOG("[Port-%d]Packet process wait...", *port);
b.liub171c9a2024-11-12 19:23:29 +08002508 pthread_cond_wait(&(ril_info.msg_cond[*port]), &(ril_info.msg_mutex[*port]));
b.liufd87baf2024-11-15 15:30:38 +08002509 LOG("[Port-%d]Packet process continue...", *port);
b.liu87afc4c2024-08-14 17:33:45 +08002510 }
2511 else
2512 {
2513 LOG("Packet process queue not empty,continue...");
2514 }
2515
2516 // Process all information request.
2517 mbtk_ril_err_enum err;
b.liub171c9a2024-11-12 19:23:29 +08002518 while((item = (ril_msg_queue_info_t*)mbtk_queue_get(&(ril_info.msg_queue[*port]))) != NULL)
b.liu87afc4c2024-08-14 17:33:45 +08002519 {
2520 if(item->cli_info) { // REQ form client.
2521 ril_msg_pack_info_t *pack = (ril_msg_pack_info_t*)item->pack;
2522 LOGD("Process REQ %s.", id2str(pack->msg_id));
b.liub171c9a2024-11-12 19:23:29 +08002523 ril_info.at_process[*port] = true;
b.liu87afc4c2024-08-14 17:33:45 +08002524 err = pack_req_process(item->cli_info, pack);
2525 if(err != MBTK_RIL_ERR_SUCCESS)
2526 {
b.liub171c9a2024-11-12 19:23:29 +08002527 ril_error_pack_send(item->cli_info->port, item->cli_info->fd, pack->msg_id, pack->msg_index, err);
b.liu87afc4c2024-08-14 17:33:45 +08002528 }
b.liub171c9a2024-11-12 19:23:29 +08002529 ril_info.at_process[*port] = false;
b.liu87afc4c2024-08-14 17:33:45 +08002530 ril_msg_pack_free(pack);
2531 free(item);
b.liu15f456b2024-10-31 20:16:06 +08002532 } else { // REQ from myself.
2533 if(item->pack) {
2534 ril_urc_msg_info_t *urc = (ril_urc_msg_info_t*)item->pack;
2535 LOGD("Process URC %d.", urc->msg);
2536 urc_msg_process(urc);
2537 if(urc->data)
2538 free(urc->data);
2539 free(urc);
2540 }
b.liu87afc4c2024-08-14 17:33:45 +08002541 }
2542 }
2543 }
b.liub171c9a2024-11-12 19:23:29 +08002544 pthread_mutex_unlock(&(ril_info.msg_mutex[*port]));
2545
2546 free(port);
2547
b.liu87afc4c2024-08-14 17:33:45 +08002548 return NULL;
2549}
2550
2551/*
2552AT*BAND=15,78,147,482,134742231
2553
2554OK
2555*/
2556static void* band_config_thread()
2557{
2558 mbtk_device_info_modem_t info_modem;
2559 memset(&band_info.band_support, 0, sizeof(mbtk_band_info_t));
2560 memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
2561 band_info.band_set_success = FALSE;
2562 if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
2563 LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
2564 band_info.band_area = MBTK_MODEM_BAND_AREA_ALL;
b.liu472cfaf2024-12-19 19:08:19 +08002565 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
b.liu87afc4c2024-08-14 17:33:45 +08002566 band_info.band_support.gsm_band = MBTK_BAND_ALL_GSM_DEFAULT;
2567 band_info.band_support.umts_band = MBTK_BAND_ALL_WCDMA_DEFAULT;
2568 band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
2569 band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
2570 band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
2571 } else {
2572 band_info.band_area = info_modem.band_area;
b.liuaced4f92024-12-31 11:14:51 +08002573#ifdef MBTK_DEV_INFO_VERSION_2
b.liu472cfaf2024-12-19 19:08:19 +08002574 if(info_modem.net_pref < MBTK_NET_PREF_MAX) {
2575 band_info.band_support.net_pref = info_modem.net_pref;
2576 } else {
2577 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
2578 }
2579#else
2580 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
2581#endif
b.liu87afc4c2024-08-14 17:33:45 +08002582 band_info.band_support.gsm_band = info_modem.band_gsm;
2583 band_info.band_support.umts_band = info_modem.band_wcdma;
2584 band_info.band_support.tdlte_band = info_modem.band_tdlte;
2585 band_info.band_support.fddlte_band = info_modem.band_fddlte;
2586 band_info.band_support.lte_ext_band = info_modem.band_lte_ext;
2587 }
2588
b.liu62240ee2024-11-07 17:52:45 +08002589// bool is_first = TRUE;
b.liu87afc4c2024-08-14 17:33:45 +08002590 while(!band_info.band_set_success) {
2591 // Set band.
b.liu472cfaf2024-12-19 19:08:19 +08002592#if 1
2593 ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
2594 if(msg) {
2595 msg->msg = RIL_URC_MSG_BAND_SET;
2596 msg->data = NULL;//mbtk_memcpy(&band_info, sizeof(ril_band_info_t));
2597 msg->data_len = 0; //sizeof(ril_band_info_t);
b.liu87afc4c2024-08-14 17:33:45 +08002598#if 0
b.liu472cfaf2024-12-19 19:08:19 +08002599 if(msg->data == NULL) {
2600 LOGE("mbtk_memcpy() fail.");
2601 break;
b.liu87afc4c2024-08-14 17:33:45 +08002602 }
b.liu472cfaf2024-12-19 19:08:19 +08002603#endif
2604 send_pack_to_queue(NULL, msg);
2605
b.liu87afc4c2024-08-14 17:33:45 +08002606 sleep(5);
b.liu472cfaf2024-12-19 19:08:19 +08002607 } else {
2608 LOG("malloc() fail[%d].", errno);
2609 break;
b.liu87afc4c2024-08-14 17:33:45 +08002610 }
2611#else
2612 sleep(5);
2613#endif
2614 }
2615
2616 LOGD("Set Band thread exit.");
2617 return NULL;
2618}
2619
2620
2621int ril_server_start()
2622{
2623 signal(SIGPIPE, SIG_IGN);
2624
2625 memset(&ril_info, 0, sizeof(ril_info_t));
2626 memset(&band_info, 0, sizeof(ril_band_info_t));
2627 memset(&band_info.band_support, 0xFF, sizeof(mbtk_band_info_t));
2628
2629 //check cfun and sim card status
2630 ril_at_ready_process();
2631
2632 //any AT instruction that is not sent through pack_process_thread needs to precede the thread
2633 //thread create
2634 if(ril_info.sock_listen_fd > 0)
2635 {
2636 LOGE("Information Server Has Started.");
2637 return -1;
2638 }
2639
2640 struct sockaddr_un server_addr;
2641 ril_info.sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
2642 if(ril_info.sock_listen_fd < 0)
2643 {
2644 LOGE("socket() fail[%d].", errno);
2645 return -1;
2646 }
2647
2648 // Set O_NONBLOCK
2649 int flags = fcntl(ril_info.sock_listen_fd, F_GETFL, 0);
2650 if (flags < 0)
2651 {
2652 LOGE("Get flags error:%d", errno);
2653 goto error;
2654 }
2655 flags |= O_NONBLOCK;
2656 if (fcntl(ril_info.sock_listen_fd, F_SETFL, flags) < 0)
2657 {
2658 LOGE("Set flags error:%d", errno);
2659 goto error;
2660 }
2661
2662 unlink(RIL_SOCK_NAME);
2663 memset(&server_addr, 0, sizeof(struct sockaddr_un));
2664 server_addr.sun_family = AF_LOCAL;
2665 strcpy(server_addr.sun_path, RIL_SOCK_NAME);
2666 if(bind(ril_info.sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)))
2667 {
2668 LOGE("bind() fail[%d].", errno);
2669 goto error;
2670 }
2671
2672 if(listen(ril_info.sock_listen_fd, SOCK_CLIENT_MAX))
2673 {
2674 LOGE("listen() fail[%d].", errno);
2675 goto error;
2676 }
2677
2678 ril_info.sock_client_list = list_create(sock_cli_free_func);
2679 if(ril_info.sock_client_list == NULL)
2680 {
2681 LOGE("list_create() fail.");
2682 goto error;
2683 }
2684
b.liub171c9a2024-11-12 19:23:29 +08002685 mbtk_queue_init(&(ril_info.msg_queue[ATPORTTYPE_0]));
2686 pthread_mutex_init(&(ril_info.msg_mutex[ATPORTTYPE_0]), NULL);
2687 pthread_cond_init(&(ril_info.msg_cond[ATPORTTYPE_0]), NULL);
b.liu87afc4c2024-08-14 17:33:45 +08002688
b.liu62240ee2024-11-07 17:52:45 +08002689 pthread_t info_pid, pack_pid/*, monitor_pid, urc_pid, bootconn_pid*/;
b.liu87afc4c2024-08-14 17:33:45 +08002690 pthread_attr_t thread_attr;
2691 pthread_attr_init(&thread_attr);
2692 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
2693 {
2694 LOGE("pthread_attr_setdetachstate() fail.");
2695 goto error;
2696 }
2697
2698 if(pthread_create(&info_pid, &thread_attr, ril_read_pthread, NULL))
2699 {
2700 LOGE("pthread_create() fail.");
2701 goto error;
2702 }
b.liub171c9a2024-11-12 19:23:29 +08002703
2704 ATPortType_enum *port_0 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
2705 *port_0 = ATPORTTYPE_0;
2706 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_0))
b.liu87afc4c2024-08-14 17:33:45 +08002707 {
2708 LOGE("pthread_create() fail.");
2709 goto error;
b.liub171c9a2024-11-12 19:23:29 +08002710 }
2711
2712 ATPortType_enum *port_1 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
2713 *port_1 = ATPORTTYPE_1;
2714 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_1))
2715 {
2716 LOGE("pthread_create() fail.");
2717 goto error;
2718 }
b.liufd87baf2024-11-15 15:30:38 +08002719
b.liu61eedc92024-11-13 16:07:00 +08002720 ATPortType_enum *port_2 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
2721 *port_2 = ATPORTTYPE_2;
2722 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_2))
b.liufd87baf2024-11-15 15:30:38 +08002723 {
b.liu61eedc92024-11-13 16:07:00 +08002724 LOGE("pthread_create() fail.");
b.liufd87baf2024-11-15 15:30:38 +08002725 goto error;
b.liu61eedc92024-11-13 16:07:00 +08002726 }
b.liufd87baf2024-11-15 15:30:38 +08002727
b.liu87afc4c2024-08-14 17:33:45 +08002728 // Set Band
2729 // AT*BAND=15,78,147,482,134742231
2730 char buff[10];
2731 memset(buff, 0, 10);
2732 property_get("persist.mbtk.band_config", buff, "");
2733 if(strlen(buff) == 0) {
2734 pthread_t band_pid;
2735 if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL))
2736 {
2737 LOGE("pthread_create() fail.");
2738 }
2739 }
2740
b.liufd87baf2024-11-15 15:30:38 +08002741 pthread_attr_destroy(&thread_attr);
2742
2743 if(asr_auto_data_call_enable()) {
2744 ril_cid_start = MBTK_RIL_CID_2;
2745
2746 char def_cid[10] = {0};
2747 char prop_data[100] = {0};
2748 int cid = -1;
2749 sprintf(def_cid, "%d", MBTK_RIL_CID_DEF); // Default route and DNS is CID 1.
2750 memset(prop_data, 0, sizeof(prop_data));
2751 if(property_get(MBTK_DEF_DNS_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
2752 cid = atoi(prop_data);
2753 }
2754
2755 if(cid == MBTK_RIL_CID_DEF) {
2756 if(file_link("/tmp/resolv.conf", "/etc/resolv.conf")) {
2757 LOGE("Create link file fail.");
2758 }
2759 }
2760 } else {
2761 ril_cid_start = MBTK_RIL_CID_DEF;
2762 }
b.liu87afc4c2024-08-14 17:33:45 +08002763
b.liufd87baf2024-11-15 15:30:38 +08002764 LOGD("MBTK Ril Server Start[CID start with : %d]...", ril_cid_start);
b.liu87afc4c2024-08-14 17:33:45 +08002765
2766 return 0;
2767error:
2768 if(ril_info.sock_client_list) {
2769 list_free(ril_info.sock_client_list);
2770 ril_info.sock_client_list = NULL;
2771 }
2772
2773 if(ril_info.sock_listen_fd > 0) {
2774 close(ril_info.sock_listen_fd);
2775 ril_info.sock_listen_fd = -1;
2776 }
2777 return -1;
2778}
2779
b.liu87afc4c2024-08-14 17:33:45 +08002780int main(int argc, char *argv[])
2781{
2782 mbtk_log_init("radio", "MBTK_RIL");
2783
b.liubcf86c92024-08-19 19:48:28 +08002784 MBTK_SOURCE_INFO_PRINT("mbtk_rild");
2785
b.liu87afc4c2024-08-14 17:33:45 +08002786#ifdef MBTK_DUMP_SUPPORT
2787 mbtk_debug_open(NULL, TRUE);
2788#endif
2789
2790// Using Killall,the file lock may be not release.
2791#if 0
2792 if(app_already_running(MBTK_RILD_PID_FILE)) {
2793 LOGW("daemon already running.");
2794 exit(1);
2795 }
2796#endif
2797
2798 LOGI("mbtk_rild start.");
2799
2800 if(InProduction_Mode()) {
2801 LOGI("Is Production Mode, will exit...");
2802 exit(0);
2803 }
2804
2805 ready_state_update();
2806
2807 int at_sock = openSocket("/tmp/atcmd_at");
2808 if(at_sock < 0)
2809 {
2810 LOGE("Open AT Socket Fail[%d].", errno);
2811 return -1;
2812 }
2813 int uart_sock = openSocket("/tmp/atcmd_urc");
2814 if(uart_sock < 0)
2815 {
2816 LOGE("Open Uart Socket Fail[%d].", errno);
2817 return -1;
2818 }
2819
b.liub171c9a2024-11-12 19:23:29 +08002820 int at_sock_1 = openSocket("/tmp/atcmd_at_1");
2821 if(at_sock_1 < 0)
b.liu87afc4c2024-08-14 17:33:45 +08002822 {
b.liub171c9a2024-11-12 19:23:29 +08002823 LOGE("Open AT Socket Fail[%d].", errno);
b.liu87afc4c2024-08-14 17:33:45 +08002824 return -1;
2825 }
2826
b.liu61eedc92024-11-13 16:07:00 +08002827 int at_sock_2 = openSocket("/tmp/atcmd_at_2");
2828 if(at_sock_2 < 0)
2829 {
2830 LOGE("Open AT Socket Fail[%d].", errno);
2831 return -1;
2832 }
2833
b.liub171c9a2024-11-12 19:23:29 +08002834 at_set_on_reader_closed(onATReaderClosed);
2835 at_set_on_timeout(onATTimeout);
2836
2837 if(at_open(ATPORTTYPE_0, at_sock, uart_sock, onUnsolicited))
2838 {
2839 LOGE("Start AT_0 thread fail.");
2840 return -1;
2841 }
2842
2843 if(at_open(ATPORTTYPE_1, at_sock_1, uart_sock, onUnsolicited))
2844 {
2845 LOGE("Start AT_1 thread fail.");
2846 return -1;
2847 }
2848
b.liu61eedc92024-11-13 16:07:00 +08002849 if(at_open(ATPORTTYPE_2, at_sock_2, uart_sock, onUnsolicited))
2850 {
2851 LOGE("Start AT_1 thread fail.");
2852 return -1;
2853 }
2854
b.liub171c9a2024-11-12 19:23:29 +08002855 if(at_handshake(ATPORTTYPE_0))
b.liu87afc4c2024-08-14 17:33:45 +08002856 {
2857 LOGE("AT handshake fail.");
2858 return -1;
2859 }
2860
2861 LOGD("AT OK.");
2862
2863 if(ril_server_start())
2864 {
2865 LOGE("ril_server_start() fail.");
2866 return -1;
2867 }
2868
2869 mbtk_ril_ready();
2870
2871 while(1)
2872 {
2873 sleep(24 * 60 * 60);
2874 }
2875
2876 LOGD("!!!mbtk_ril exit!!!");
2877 return 0;
2878}