blob: c4befdfb35009d4a5d93b3c4465331308edf67b8 [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
b.liu60c2f1f2024-12-31 12:54:45 +0800212024/12/31 LiuBin Add new sms urc process(+CMT)
b.liufd87baf2024-11-15 15:30:38 +080022
23******************************************************************************/
b.liu87afc4c2024-08-14 17:33:45 +080024#include <stdio.h>
25#include <stdlib.h>
26#include <unistd.h>
27#include <sys/socket.h>
28#include <errno.h>
29#include <fcntl.h>
30#include <string.h>
31#include <netinet/in.h>
32#include <arpa/inet.h>
33#include <linux/un.h>
34#include <linux/netlink.h>
35#include <cutils/properties.h>
36#include <time.h>
37#include <sys/time.h>
38#include <signal.h>
39#include <sys/epoll.h>
40#include <pthread.h>
41
42
43//#include "cploader.h"
44#include "mbtk_log.h"
45#include "mbtk_ifc.h"
46#include "mbtk_type.h"
47#include "atchannel.h"
48#include "at_tok.h"
49#include "mbtk_utils.h"
50#include "mbtk_task.h"
51#include "ril_info.h"
52#include "mbtk_ntp.h"
53#include "mbtk_net_control.h"
54#include "mbtk_ril.h"
55#include "mbtk_str.h"
56#include "mbtk_queue.h"
b.liufd87baf2024-11-15 15:30:38 +080057#include "mbtk_file.h"
b.liu87afc4c2024-08-14 17:33:45 +080058
b.liu62240ee2024-11-07 17:52:45 +080059#ifndef TEMP_FAILURE_RETRY
b.liu87afc4c2024-08-14 17:33:45 +080060#define TEMP_FAILURE_RETRY(exp) ({ \
61 typeof (exp) _rc; \
62 do { \
63 _rc = (exp); \
64 } while (_rc == -1 && errno == EINTR); \
65 _rc; })
b.liu62240ee2024-11-07 17:52:45 +080066#endif
b.liu87afc4c2024-08-14 17:33:45 +080067
68#define BUFFER_SIZE 2048
69#define UEVENT_USIM_DEV "/devices/virtual/usim_event/usim0"
70#define MBTK_BOOT_SERVER_READY "/etc/init.d/mbtk_boot_server_ready"
71#define MBTK_BOOT_NET_READY "/etc/init.d/mbtk_boot_net_ready"
72#define MBTK_RILD_PID_FILE "/var/run/mbtk_rild.pid"
73#define MBTK_RILD_FILE_NET_READY "/tmp/mbtk_rild.net_ready"
74#define MBTK_RILD_FILE_SER_READY "/tmp/mbtk_rild.ser_ready"
b.liu15f456b2024-10-31 20:16:06 +080075#define RIL_CALL_NUM_MAX 10
b.liu87afc4c2024-08-14 17:33:45 +080076
77static bool ril_net_ready = FALSE; // Only one time.
78static bool ril_server_ready = FALSE; // Only one time.
79ril_band_info_t band_info;
80ril_info_t ril_info;
b.liu15f456b2024-10-31 20:16:06 +080081static mbtk_ril_call_state_info_t call_list[RIL_CALL_NUM_MAX];
b.liuaced4f92024-12-31 11:14:51 +080082static bool cmt_found = FALSE;
83
b.liub4772072024-08-15 14:47:03 +080084extern mbtk_cell_pack_info_t cell_info;
b.liubcf86c92024-08-19 19:48:28 +080085extern ril_cgact_wait_t cgact_wait;
b.liufd87baf2024-11-15 15:30:38 +080086extern int ril_cid_start;
b.liu87afc4c2024-08-14 17:33:45 +080087
88// int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len);
89// int mbtk_signal_log(char *data);
90int InProduction_Mode(void);
91mbtk_ril_err_enum dev_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
92mbtk_ril_err_enum call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
93mbtk_ril_err_enum sim_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
94mbtk_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 +080095mbtk_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 +080096mbtk_ril_err_enum pb_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
97mbtk_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 +080098mbtk_ril_err_enum ecall_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
99
b.liu7ca612c2025-04-25 09:23:36 +0800100void data_call_retry(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_net_reg_state_info_t *reg_state);
b.liuafdf2c62024-11-12 11:10:44 +0800101
b.liu7ca612c2025-04-25 09:23:36 +0800102void data_call_state_change_cb(mbtk_sim_type_enum sim_id, int cid, bool action, bool auto_change, int reason);
b.liu15f456b2024-10-31 20:16:06 +0800103static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack);
b.liu7ca612c2025-04-25 09:23:36 +0800104int req_band_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t* band, int *cme_err);
105int req_dual_sim_get(ATPortType_enum port, mbtk_sim_type_enum *sim_id, int *cme_err);
106
107ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port)
108{
109 return (ATPortId_enum)(sim_id * ATPORTTYPE_NUM + port);
110}
b.liu87afc4c2024-08-14 17:33:45 +0800111
112/* Called on command thread */
113static void onATTimeout()
114{
115 LOGI("AT channel timeout; closing\n");
b.liu7ca612c2025-04-25 09:23:36 +0800116 at_close(ATPORTID_SIM1_0);
117 at_close(ATPORTID_SIM1_1);
118 at_close(ATPORTID_SIM1_2);
119 at_close(ATPORTID_SIM2_0);
120 at_close(ATPORTID_SIM2_1);
121 at_close(ATPORTID_SIM2_2);
b.liu87afc4c2024-08-14 17:33:45 +0800122}
123
124/* Called on command or reader thread */
125static void onATReaderClosed()
126{
127 LOGI("AT channel closed\n");
b.liu7ca612c2025-04-25 09:23:36 +0800128 at_close(ATPORTID_SIM1_0);
129 at_close(ATPORTID_SIM1_1);
130 at_close(ATPORTID_SIM1_2);
131 at_close(ATPORTID_SIM2_0);
132 at_close(ATPORTID_SIM2_1);
133 at_close(ATPORTID_SIM2_2);
b.liu87afc4c2024-08-14 17:33:45 +0800134}
135
b.liu571445f2025-02-13 10:22:55 +0800136static void sock_cli_free_func(void *data)
137{
138 if (data)
139 {
b.liu87afc4c2024-08-14 17:33:45 +0800140 sock_cli_info_t *info = (sock_cli_info_t*) data;
141 LOGD("Free Socket client[fd = %d].", info->fd);
b.liu571445f2025-02-13 10:22:55 +0800142 free(info);
143 }
b.liu87afc4c2024-08-14 17:33:45 +0800144}
145
b.liufd87baf2024-11-15 15:30:38 +0800146bool asr_auto_data_call_enable()
147{
148 /*
149 uci show wan_default.default.enable
150 wan_default.default.enable='1'
151
152 uci get wan_default.default.enable
153 1
154 */
155 char buff[128] = {0};
156 if(mbtk_cmd_line("uci get wan_default.default.enable", buff, sizeof(buff)) && strlen(buff) > 0) {
157 return buff[0] == '1' ? TRUE : FALSE;
158 } else {
159 return FALSE;
160 }
161}
162
b.liu87afc4c2024-08-14 17:33:45 +0800163/*
164* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
165*/
166static int net_ready_set()
167{
168 int ret = -1;
169 int fd = open(MBTK_RILD_FILE_NET_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
170 if(fd > 0) {
171 if(write(fd, "1", 1) == 1) {
172 ret = 0;
173 ril_net_ready = TRUE;
174 }
175 close(fd);
176 } else {
177 LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
178 }
179
180 return ret;
181}
182
183/*
184* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
185*/
186static int ser_ready_set()
187{
188 int ret = -1;
189 int fd = open(MBTK_RILD_FILE_SER_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
190 if(fd > 0) {
191 if(write(fd, "1", 1) == 1) {
192 ret = 0;
193 ril_server_ready = TRUE;
194 }
195 close(fd);
196 } else {
197 LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
198 }
199
200 return ret;
201}
202
203/*
204* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
205*/
206static void ready_state_update()
207{
208 int fd = open(MBTK_RILD_FILE_NET_READY, O_RDONLY, 0644);
209 char buff[10];
210 if(fd > 0) {
211 if(read(fd, buff, sizeof(buff)) > 0) {
212 ril_net_ready = TRUE;
213 } else {
214 ril_net_ready = FALSE;
215 }
216
217 close(fd);
218 } else {
219 ril_net_ready = FALSE;
220 LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
221 }
222
223 fd = open(MBTK_RILD_FILE_SER_READY, O_RDONLY, 0644);
224 if(fd > 0) {
225 if(read(fd, buff, sizeof(buff)) > 0) {
226 ril_server_ready = TRUE;
227 } else {
228 ril_server_ready = FALSE;
229 }
230
231 close(fd);
232 } else {
233 ril_server_ready = FALSE;
234 LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
235 }
236}
237
238static void mbtk_net_ready()
239{
240 // /etc/init.d/mbtk_boot_net_ready
241 if(!ril_net_ready) {
242 if(access(MBTK_BOOT_NET_READY , X_OK) == 0) {
243 LOGD("Exec : %s", MBTK_BOOT_NET_READY);
b.liu62240ee2024-11-07 17:52:45 +0800244 mbtk_system(MBTK_BOOT_NET_READY);
b.liu87afc4c2024-08-14 17:33:45 +0800245 } else {
246 LOGE("%s can not exec.", MBTK_BOOT_NET_READY);
247 }
248 net_ready_set();
249 } else {
250 LOGD("No exec : %s", MBTK_BOOT_NET_READY);
251 }
252}
253
254static void mbtk_ril_ready()
255{
256 // /etc/init.d/mbtk_boot_server_ready
257 if(!ril_server_ready) {
258 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
259 LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
b.liu62240ee2024-11-07 17:52:45 +0800260 mbtk_system(MBTK_BOOT_SERVER_READY);
b.liu87afc4c2024-08-14 17:33:45 +0800261 } else {
262 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
263 }
264 ser_ready_set();
265 } else {
266 LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
267 }
268}
269
270static sock_cli_info_t* cli_find(int fd)
b.liu571445f2025-02-13 10:22:55 +0800271{
b.liu87afc4c2024-08-14 17:33:45 +0800272 sock_cli_info_t *result = NULL;
273 list_first(ril_info.sock_client_list);
274 while ((result = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
b.liu571445f2025-02-13 10:22:55 +0800275 {
276 if (result->fd == fd)
277 return result;
278 }
279
280 return NULL;
b.liu87afc4c2024-08-14 17:33:45 +0800281}
282
283static void cli_close(sock_cli_info_t* client)
b.liu571445f2025-02-13 10:22:55 +0800284{
285 struct epoll_event ev;
286 memset(&ev,0,sizeof(struct epoll_event));
287 ev.data.fd = client->fd;
288 ev.events = EPOLLIN | EPOLLERR | EPOLLET;
b.liu87afc4c2024-08-14 17:33:45 +0800289 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_DEL, client->fd, &ev);
b.liu571445f2025-02-13 10:22:55 +0800290
291 close(client->fd);
292
b.liu87afc4c2024-08-14 17:33:45 +0800293 if(list_remove(ril_info.sock_client_list, client))
b.liu571445f2025-02-13 10:22:55 +0800294 {
295 sock_cli_free_func(client);
296 }
297}
298
b.liu7ca612c2025-04-25 09:23:36 +0800299static void ril_error_pack_send(mbtk_sim_type_enum sim_id, ATPortType_enum port, int fd, int ril_id, int msg_index, int err)
b.liu571445f2025-02-13 10:22:55 +0800300{
b.liu7ca612c2025-04-25 09:23:36 +0800301 ril_msg_pack_info_t* pack = ril_msg_pack_creat(sim_id, port, RIL_MSG_TYPE_RSP, ril_id, msg_index, NULL, 0);
b.liu571445f2025-02-13 10:22:55 +0800302 if(pack)
b.liu87afc4c2024-08-14 17:33:45 +0800303 {
304 pack->err = (uint16)err;
305 ril_pack_send(fd, pack);
306 ril_msg_pack_free(pack);
b.liu571445f2025-02-13 10:22:55 +0800307 }
308 else
309 {
b.liu87afc4c2024-08-14 17:33:45 +0800310 LOGW("ril_msg_pack_creat() fail.");
b.liu571445f2025-02-13 10:22:55 +0800311 }
312}
313
b.liu7ca612c2025-04-25 09:23:36 +0800314void ril_rsp_pack_send(mbtk_sim_type_enum sim_id, ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len)
b.liu10a34102024-08-20 20:36:24 +0800315{
b.liu7ca612c2025-04-25 09:23:36 +0800316 ril_msg_pack_info_t* pack = ril_msg_pack_creat(sim_id, port, RIL_MSG_TYPE_RSP, ril_id, msg_index, data, data_len);
b.liu571445f2025-02-13 10:22:55 +0800317 if(pack)
318 {
b.liu87afc4c2024-08-14 17:33:45 +0800319 pack->err = (uint16)MBTK_RIL_ERR_SUCCESS;
320#if 0
b.liu571445f2025-02-13 10:22:55 +0800321 if(data != NULL && data_len > 0)
322 {
323 pack->data_len = (uint16)data_len;
b.liu87afc4c2024-08-14 17:33:45 +0800324 pack->data = (uint8*)mbtk_memcpy(data, data_len);
325 }
326#endif
327 ril_pack_send(fd, pack);
328 ril_msg_pack_free(pack);
b.liu571445f2025-02-13 10:22:55 +0800329 }
330 else
331 {
b.liu87afc4c2024-08-14 17:33:45 +0800332 LOGW("ril_msg_pack_creat() fail.");
b.liu571445f2025-02-13 10:22:55 +0800333 }
b.liu87afc4c2024-08-14 17:33:45 +0800334}
335
b.liu7ca612c2025-04-25 09:23:36 +0800336void ril_ind_pack_send(mbtk_sim_type_enum sim_id, int fd, int msg_id, const void* data, int data_len)
b.liu571445f2025-02-13 10:22:55 +0800337{
b.liu7ca612c2025-04-25 09:23:36 +0800338 ril_msg_pack_info_t* pack = ril_msg_pack_creat(sim_id, ATPORTTYPE_NON, RIL_MSG_TYPE_IND, msg_id, RIL_MSG_INDEX_INVALID, data, data_len);
b.liu571445f2025-02-13 10:22:55 +0800339 if(pack)
340 {
b.liu87afc4c2024-08-14 17:33:45 +0800341 pack->err = (uint16)0;
342#if 0
b.liu571445f2025-02-13 10:22:55 +0800343 if(data != NULL && data_len > 0)
344 {
345 pack->data_len = (uint16)data_len;
b.liu87afc4c2024-08-14 17:33:45 +0800346 pack->data = (uint8*)mbtk_memcpy(data, data_len);
347 }
348#endif
349 ril_pack_send(fd, pack);
350 ril_msg_pack_free(pack);
b.liu571445f2025-02-13 10:22:55 +0800351 }
352 else
353 {
b.liu87afc4c2024-08-14 17:33:45 +0800354 LOGW("ril_msg_pack_creat() fail.");
b.liu571445f2025-02-13 10:22:55 +0800355 }
b.liu87afc4c2024-08-14 17:33:45 +0800356}
357
b.liufd87baf2024-11-15 15:30:38 +0800358void ril_state_change(ril_msg_id_enum msg_id, const void *data, int data_len)
b.liu571445f2025-02-13 10:22:55 +0800359{
b.liu15f456b2024-10-31 20:16:06 +0800360 sock_cli_info_t *cli = NULL;
361 list_first(ril_info.sock_client_list);
362 while ((cli = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
b.liu571445f2025-02-13 10:22:55 +0800363 {
364 if(cli->ind_num > 0) {
365 int i;
366 for(i = 0; i < IND_REGISTER_MAX; i++) {
b.liu15f456b2024-10-31 20:16:06 +0800367 if(cli->ind_register[i] == msg_id) {
b.liu7ca612c2025-04-25 09:23:36 +0800368 ril_ind_pack_send(MBTK_SIM_1, cli->fd, msg_id, data, data_len);
b.liu571445f2025-02-13 10:22:55 +0800369 break;
370 }
371 }
372 }
373 }
b.liu15f456b2024-10-31 20:16:06 +0800374}
375
b.liu9e8584b2024-11-06 19:21:28 +0800376static 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 +0800377{
378 // Send urc msg to client.
379 if(msg_id > RIL_MSG_ID_IND_BEGIN && msg_id < RIL_MSG_ID_IND_END) {
b.liufd87baf2024-11-15 15:30:38 +0800380 if(msg_id == RIL_MSG_ID_IND_PDP_STATE_CHANGE) {
381 mbtk_ril_pdp_state_info_t *info = (mbtk_ril_pdp_state_info_t*)data;
382 if(info->action && !info->ip_info_valid) {
383 LOGD("PDP action but no IP information, not send.");
384 } else {
385 ril_state_change(msg_id, data, data_len);
386 }
387 } else {
388 ril_state_change(msg_id, data, data_len);
389 }
b.liu15f456b2024-10-31 20:16:06 +0800390 }
391
392 // Async process urc msg.
b.liu571445f2025-02-13 10:22:55 +0800393 if(async_process) {
b.liu15f456b2024-10-31 20:16:06 +0800394 ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
395 if(msg) {
396 msg->msg = msg_id;
397 msg->data = mbtk_memcpy(data, data_len);
398 msg->data_len = data_len;
399 if(msg->data == NULL) {
400 LOGE("mbtk_memcpy() fail.");
401 return -1;
402 }
403
404 return send_pack_to_queue(NULL, msg);
405 } else {
406 LOGE("malloc() fail.");
407 return -1;
408 }
409 }
410
411 return 0;
412}
413
414// *SIMDETEC:1,SIM
415// *EUICC:1
416// +CPIN: SIM PIN
b.liu7ca612c2025-04-25 09:23:36 +0800417static void urc_sim_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
b.liu15f456b2024-10-31 20:16:06 +0800418{
419 mbtk_ril_sim_state_info_t state;
420 memset(&state, 0, sizeof(mbtk_ril_sim_state_info_t));
421 state.sim_type = MBTK_UNKNOWN;
b.liu7ca612c2025-04-25 09:23:36 +0800422 state.sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800423
b.liufd87baf2024-11-15 15:30:38 +0800424 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800425 char *line = tmp_s;
426 int tmp_int;
427 char *tmp_str;
428
429 if(strStartsWith(s, "*SIMDETEC:")) {
430 if (at_tok_start(&line) < 0)
431 {
432 goto SIM_STATE_EXIT;
433 }
434 if (at_tok_nextint(&line, &tmp_int) < 0)
435 {
436 goto SIM_STATE_EXIT;
437 }
438 if (at_tok_nextstr(&line, &tmp_str) < 0)
439 {
440 goto SIM_STATE_EXIT;
441 }
442
443 if(tmp_str) {
444 if(strcmp(tmp_str, "NOS") == 0) {
b.liu7ca612c2025-04-25 09:23:36 +0800445 state.sim_type = ril_info.sim_type[sim_id];
b.liu15f456b2024-10-31 20:16:06 +0800446 state.sim_state = MBTK_SIM_STATE_ABSENT;
b.liu7ca612c2025-04-25 09:23:36 +0800447 ril_info.sim_state[sim_id] = MBTK_SIM_STATE_ABSENT;
b.liu15f456b2024-10-31 20:16:06 +0800448 urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
449 } else if(strcmp(tmp_str, "SIM") == 0) {
b.liu7ca612c2025-04-25 09:23:36 +0800450 state.sim_type = ril_info.sim_type[sim_id];
b.liu15f456b2024-10-31 20:16:06 +0800451 state.sim_state = MBTK_SIM_STATE_NOT_READY;
b.liu7ca612c2025-04-25 09:23:36 +0800452 ril_info.sim_state[sim_id] = MBTK_SIM_STATE_NOT_READY;
b.liu15f456b2024-10-31 20:16:06 +0800453 urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
454 }
455 }
456 } else if(strStartsWith(s, "+CPIN:")){
457 if(strStartsWith(s, "+CPIN: READY"))
458 {
459 state.sim_state = MBTK_SIM_STATE_READY;
460 }
461 else if(strStartsWith(s, "+CPIN: SIM PIN"))
462 {
463 state.sim_state = MBTK_SIM_STATE_SIM_PIN;
464 }
465 else if(strStartsWith(s, "+CPIN: SIM PUK"))
466 {
467 state.sim_state = MBTK_SIM_STATE_SIM_PUK;
468 }
469 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
470 {
471 state.sim_state = MBTK_SIM_STATE_PH_SIMLOCK_PIN;
472 }
473 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
474 {
475 state.sim_state = MBTK_SIM_STATE_PH_SIMLOCK_PUK;
476 }
477 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
478 {
479 state.sim_state = MBTK_SIM_STATE_PH_FSIM_PIN;
480 }
481 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
482 {
483 state.sim_state = MBTK_SIM_STATE_PH_FSIM_PUK;
484 }
485 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
486 {
487 state.sim_state = MBTK_SIM_STATE_SIM_PIN2;
488 }
489 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
490 {
491 state.sim_state = MBTK_SIM_STATE_SIM_PUK2;
492 }
493 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
494 {
495 state.sim_state = MBTK_SIM_STATE_PH_NET_PIN;
496 }
497 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
498 {
499 state.sim_state = MBTK_SIM_STATE_PH_NET_PUK;
500 }
501 else if(strStartsWith(s, "+CPIN: PH-NETSUB PIN"))
502 {
503 state.sim_state = MBTK_SIM_STATE_PH_NETSUB_PIN;
504 }
505 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
506 {
507 state.sim_state = MBTK_SIM_STATE_PH_NETSUB_PUK;
508 }
509 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
510 {
511 state.sim_state = MBTK_SIM_STATE_PH_SP_PIN;
512 }
513 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
514 {
515 state.sim_state = MBTK_SIM_STATE_PH_SP_PUK;
516 }
517 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
518 {
519 state.sim_state = MBTK_SIM_STATE_PH_CORP_PIN;
520 }
521 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
522 {
523 state.sim_state = MBTK_SIM_STATE_PH_CORP_PUK;
524 }
525 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
526 {
527 state.sim_state = MBTK_SIM_STATE_ABSENT;
528 }
529
b.liu7ca612c2025-04-25 09:23:36 +0800530 state.sim_type = ril_info.sim_type[sim_id];
531 ril_info.sim_state[sim_id] = state.sim_state;
b.liu15f456b2024-10-31 20:16:06 +0800532
b.liufd87baf2024-11-15 15:30:38 +0800533 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 +0800534 } else if(strStartsWith(s, "*EUICC:")){
535 if (at_tok_start(&line) < 0)
536 {
537 goto SIM_STATE_EXIT;
538 }
539 if (at_tok_nextint(&line, &tmp_int) < 0)
540 {
541 goto SIM_STATE_EXIT;
542 }
b.liu7ca612c2025-04-25 09:23:36 +0800543 ril_info.sim_type[sim_id] = (mbtk_sim_card_type_enum)tmp_int;
b.liu15f456b2024-10-31 20:16:06 +0800544 } else {
545 LOGW("Unknown URC.");
546 }
547
548SIM_STATE_EXIT:
549 free(tmp_s);
550}
551
552// +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
553// +CALLDISCONNECT: 1
554// +CPAS: 4
b.liu7ca612c2025-04-25 09:23:36 +0800555static void urc_call_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
b.liu15f456b2024-10-31 20:16:06 +0800556{
b.liufd87baf2024-11-15 15:30:38 +0800557 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800558 char *line = tmp_s;
559 int tmp_int;
560 char *tmp_str;
561
562 if(strStartsWith(s, "+CLCC:")) {
563 if (at_tok_start(&line) < 0)
564 {
565 goto CALL_STATE_EXIT;
566 }
567 if (at_tok_nextint(&line, &tmp_int) < 0) // call id
568 {
569 goto CALL_STATE_EXIT;
570 }
571
572 int i = 0;
573 while(i < RIL_CALL_NUM_MAX) {
574 if(call_list[i].call_id == tmp_int)
575 break;
576 i++;
577 }
578 if(i == RIL_CALL_NUM_MAX) { // No found this call id.
579 i = 0;
580 while(i < RIL_CALL_NUM_MAX) { // Find next empty call item.
581 if(call_list[i].call_id == 0)
582 break;
583 i++;
584 }
585 call_list[i].call_id = tmp_int;
586 }
587
588 LOGD("Found call id : %d", call_list[i].call_id);
589
b.liu7ca612c2025-04-25 09:23:36 +0800590 call_list[i].sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800591 if (at_tok_nextint(&line, &tmp_int) < 0) // dir
592 {
593 goto CALL_STATE_EXIT;
594 }
595 call_list[i].dir = (mbtk_ril_call_dir_enum)tmp_int;
596
597 if (at_tok_nextint(&line, &tmp_int) < 0) // state
598 {
599 goto CALL_STATE_EXIT;
600 }
601 call_list[i].state = (mbtk_ril_call_state_enum)tmp_int;
602
603 if (at_tok_nextint(&line, &tmp_int) < 0) // mode
604 {
605 goto CALL_STATE_EXIT;
606 }
607
608 if (at_tok_nextint(&line, &tmp_int) < 0) // mpty
609 {
610 goto CALL_STATE_EXIT;
611 }
612
613 if (at_tok_nextstr(&line, &tmp_str) < 0) // number
614 {
615 goto CALL_STATE_EXIT;
616 }
617 memset(call_list[i].call_number, 0, sizeof(call_list[i].call_number));
618 if(tmp_str && strlen(tmp_str) > 0) {
619 memcpy(call_list[i].call_number, tmp_str, strlen(tmp_str));
620 }
621
622 if (at_tok_nextint(&line, &tmp_int) < 0) // type
623 {
624 goto CALL_STATE_EXIT;
625 }
626 call_list[i].num_type = (mbtk_ril_call_num_type_enum)tmp_int;
627
628 urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));
629 } else if(strStartsWith(s, "+CALLDISCONNECT:")){
630 if (at_tok_start(&line) < 0)
631 {
632 goto CALL_STATE_EXIT;
633 }
634 if (at_tok_nextint(&line, &tmp_int) < 0) // call id
635 {
636 goto CALL_STATE_EXIT;
637 }
638
639 int i = 0;
640 while(i < RIL_CALL_NUM_MAX) {
641 if(call_list[i].call_id == tmp_int)
642 break;
643 i++;
644 }
645
646 if(i == RIL_CALL_NUM_MAX) { // No found this call id.
647 LOGE("No found this call id : %d", tmp_int);
648 goto CALL_STATE_EXIT;
649 }
650
651 call_list[i].state = MBTK_RIL_CALL_STATE_DISCONNECT;
b.liu7ca612c2025-04-25 09:23:36 +0800652 call_list[i].sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800653
654 urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));
655
656 // Reset after call disconnect.
657 memset(&(call_list[i]), 0, sizeof(mbtk_ril_call_state_info_t));
658 } else if(strStartsWith(s, "+CPAS:")){
659
660 } else {
661 LOGW("Unknown URC.");
662 }
663
664CALL_STATE_EXIT:
665 free(tmp_s);
666}
667
668// *ECALLDATA: <urc_id>[,<urc_data>]
b.liu7ca612c2025-04-25 09:23:36 +0800669static void urc_ecall_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
b.liu15f456b2024-10-31 20:16:06 +0800670{
671 mbtk_ril_ecall_state_info_t ecall_state;
672 memset(&ecall_state, 0, sizeof(mbtk_ril_ecall_state_info_t));
b.liu7ca612c2025-04-25 09:23:36 +0800673 ecall_state.sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800674
b.liufd87baf2024-11-15 15:30:38 +0800675 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800676 char *line = tmp_s;
677 int tmp_int;
678 char *tmp_str;
679 if (at_tok_start(&line) < 0)
680 {
681 goto ECALLDATA_EXIT;
682 }
683 if (at_tok_nextint(&line, &tmp_int) < 0)
684 {
685 goto ECALLDATA_EXIT;
686 }
b.liu15f456b2024-10-31 20:16:06 +0800687
b.liu29ead772025-05-26 17:51:20 +0800688 if(strStartsWith(s, "*ECALLDATA:")) {
689 ecall_state.urc_id = (uint8)tmp_int; // urc_id
690 if (at_tok_nextstr(&line, &tmp_str) < 0)
691 {
692 goto ECALLDATA_EXIT;
693 }
694
695 if(tmp_str && strlen(tmp_str) > 0) {
696 memcpy(ecall_state.urc_data, tmp_str, strlen(tmp_str));
697 }
698 } else { // +ECALLDIALRETRY: <retry_time>
699 ecall_state.urc_id = (uint8)(MBTK_ECALL_RETRY_START_BY_URC_ID + tmp_int); // ecall end.
b.liu15f456b2024-10-31 20:16:06 +0800700 }
701
702 urc_msg_distribute(false, RIL_MSG_ID_IND_ECALL_STATE_CHANGE, &ecall_state, sizeof(mbtk_ril_ecall_state_info_t));
703ECALLDATA_EXIT:
704 free(tmp_s);
705}
706
707// +CMT: ,23
708// 0891683108200855F6240D91688189911196F10000221130717445230331D90C
b.liu7ca612c2025-04-25 09:23:36 +0800709static void urc_sms_state_change_process(mbtk_sim_type_enum sim_id, const char *s, bool is_pdu)
b.liu15f456b2024-10-31 20:16:06 +0800710{
b.liu0bb1c8e2024-12-31 14:44:40 +0800711 static mbtk_ril_sms_state_info_t sms_info;
b.liu7ca612c2025-04-25 09:23:36 +0800712 memset(&sms_info, 0, sizeof(mbtk_ril_sms_state_info_t));
713 sms_info.sim_id = sim_id;
714
b.liu0bb1c8e2024-12-31 14:44:40 +0800715 if(!is_pdu) {
b.liu60c2f1f2024-12-31 12:54:45 +0800716 char* tmp_s = memdup(s,strlen(s) + 1);
717 char *line = tmp_s;
718 char *tmp_str;
719 if (at_tok_start(&line) < 0)
720 {
721 goto CMT_EXIT;
722 }
723 if (at_tok_nextstr(&line, &tmp_str) < 0)
724 {
725 goto CMT_EXIT;
726 }
727 if (at_tok_nextstr(&line, &tmp_str) < 0)
728 {
729 goto CMT_EXIT;
730 }
731 sms_info.pdu_len = (uint16)atoi(tmp_str);
b.liu60c2f1f2024-12-31 12:54:45 +0800732 CMT_EXIT:
733 free(tmp_s);
b.liu0bb1c8e2024-12-31 14:44:40 +0800734 } else {
735 LOGD("PDU : %s", s);
736 memcpy(sms_info.pdu, s, strlen(s));
737 urc_msg_distribute(false, RIL_MSG_ID_IND_SMS_STATE_CHANGE, &sms_info, sizeof(mbtk_ril_sms_state_info_t));
b.liu60c2f1f2024-12-31 12:54:45 +0800738 }
b.liu15f456b2024-10-31 20:16:06 +0800739}
740
741// +CREG: 1, "8010", "000060a5", 0, 2, 0
742// +CREG: 1, "8330", "06447347", 7, 2, 0
743// +CEREG: 1, "8330", "06447347", 7
744// $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
745// $CREG: 1, "8010", "000060a7", 0,, 2, 0
746// +CGREG: 1
b.liubeb61cc2025-02-13 10:38:29 +0800747// +C5GREG: 1,"00280386","07e920010",11,1,"01"
b.liu7ca612c2025-04-25 09:23:36 +0800748static void urc_net_reg_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
b.liu15f456b2024-10-31 20:16:06 +0800749{
750 mbtk_ril_net_reg_state_info_t state;
751 memset(&state, 0, sizeof(mbtk_ril_net_reg_state_info_t));
752 state.tech = MBTK_RADIO_TECH_UNKNOWN;
b.liu7ca612c2025-04-25 09:23:36 +0800753 state.sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800754
755 if(strStartsWith(s, "+CREG:"))
756 {
757 state.type = MBTK_NET_REG_TYPE_CALL;
758 } else if(strStartsWith(s, "+CGREG:")) {
759 state.type = MBTK_NET_REG_TYPE_DATA_GSM_WCDMA;
b.liubeb61cc2025-02-13 10:38:29 +0800760 } else if(strStartsWith(s, "+C5GREG:")) {
761 state.type = MBTK_NET_REG_TYPE_DATA_NR;
b.liu15f456b2024-10-31 20:16:06 +0800762 } else {
763 state.type = MBTK_NET_REG_TYPE_DATA_LTE;
764 }
765
b.liufd87baf2024-11-15 15:30:38 +0800766 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800767 char *line = tmp_s;
768 int tmp_int;
769 char *tmp_str;
770 if (at_tok_start(&line) < 0)
771 {
772 goto CGREG_EXIT;
773 }
774 if (at_tok_nextint(&line, &tmp_int) < 0)
775 {
776 goto CGREG_EXIT;
777 }
778 state.reg_state = (mbtk_net_reg_state_enum)tmp_int; // Reg State.
b.liubeb61cc2025-02-13 10:38:29 +0800779 if (state.reg_state && at_tok_hasmore(&line)) // Reg
b.liu15f456b2024-10-31 20:16:06 +0800780 {
b.liubeb61cc2025-02-13 10:38:29 +0800781 if (at_tok_nextstr(&line, &tmp_str) < 0) // tac
b.liu15f456b2024-10-31 20:16:06 +0800782 {
783 goto CGREG_EXIT;
784 }
b.liubeb61cc2025-02-13 10:38:29 +0800785 state.tac = (uint64)strtoull(tmp_str, NULL, 16);
b.liufd87baf2024-11-15 15:30:38 +0800786
b.liubeb61cc2025-02-13 10:38:29 +0800787 if (at_tok_nextstr(&line, &tmp_str) < 0) // ci
b.liu15f456b2024-10-31 20:16:06 +0800788 {
789 goto CGREG_EXIT;
790 }
b.liubeb61cc2025-02-13 10:38:29 +0800791 state.ci = (uint64)strtoull(tmp_str, NULL, 16);
b.liufd87baf2024-11-15 15:30:38 +0800792
b.liu15f456b2024-10-31 20:16:06 +0800793 if (at_tok_nextint(&line, &tmp_int) < 0)
794 {
795 goto CGREG_EXIT;
796 }
797 state.tech = (mbtk_radio_technology_enum)tmp_int; // AcT
798 }
799
b.liu62240ee2024-11-07 17:52:45 +0800800 if(state.reg_state == MBTK_NET_REG_STATE_HOME
801 || state.reg_state == MBTK_NET_REG_STATE_ROAMING) {
802 mbtk_net_ready();
803 }
804
b.liuafdf2c62024-11-12 11:10:44 +0800805 // Should restart data call if necessary.
806 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 +0800807CGREG_EXIT:
808 free(tmp_s);
809}
810
b.liu7ca612c2025-04-25 09:23:36 +0800811static void urc_pdp_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
b.liubcf86c92024-08-19 19:48:28 +0800812{
813 // "CONNECT"
814 if(strStartsWith(s, "CONNECT"))
815 {
816#if 1
817 if(cgact_wait.waitting && cgact_wait.act) {
818 cgact_wait.waitting = false;
819 }
820#endif
821 }
822 // +CGEV:
823 // +CGEV: NW DEACT <cid>,<cid>
824 // +CGEV: ME DEACT <cid>,<cid>
825 // +CGEV: NW PDN DEACT <cid>
826 // +CGEV: ME PDN DEACT <cid>
827 // +CGEV: NW DETACH
828 // +CGEV: ME DETACH
829 //
830 // +CGEV: NW ACT <cid>,<cid>
831 // +CGEV: ME ACT <cid>,<cid>
832 // +CGEV: EPS PDN ACT <cid>
833 // +CGEV: ME PDN ACT <cid>,<reason>,<cid>
834 // +CGEV: ME PDN ACT <cid>,<reason>
835 // +CGEV: NW PDN ACT <cid>
836 // +CGEV: EPS ACT <cid>
837 // +CGEV: NW MODIFY <cid>,<reason>
838 // +CGEV: NW REATTACH
839
840 /*
841 +CGEV: NW DETACH
842 +CGEV: ME DETACH
843 +CGEV: NW CLASS <class>
844 +CGEV: ME CLASS <class>
845 +CGEV: NW PDN ACT <cid>
846 +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
847 +CGEV: NW ACT <p_cid>, <cid>, <event_type>
848 +CGEV: ME ACT <p_cid>, <cid>, <event_type>
849 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
850 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
851 +CGEV: NW PDN DEACT <cid>
852 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
853 +CGEV: ME PDN DEACT <cid>
854 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
855 +CGEV: NW DEACT <p_cid>, <cid>, <event_type>
856 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
857 +CGEV: ME DEACT <p_cid>, <cid>, <event_type>
858 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
859 +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
860 +CGEV: ME MODIFY <cid>, <change_reason>, <event_type>
861 +CGEV: REJECT <PDP_type>, <PDP_addr>
862 +CGEV: NW REACT <PDP_type>, <PDP_addr>, [<cid>]
863 */
864 else if(strStartsWith(s, "+CGEV:"))
865 {
866#if 1
867 // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
868 // "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
869 // "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
870 // "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
871 // "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
872 // "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
873 // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
b.liu15f456b2024-10-31 20:16:06 +0800874 mbtk_ril_pdp_state_info_t cgev_info;
875 memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));
b.liu7ca612c2025-04-25 09:23:36 +0800876 cgev_info.sim_id = sim_id;
b.liu62240ee2024-11-07 17:52:45 +0800877 int cid, reason = 0;
b.liu62240ee2024-11-07 17:52:45 +0800878 if (sscanf(s, "+CGEV: NW PDN DEACT %d", &cid) == 1) {
879 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800880 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800881 } else if (sscanf(s, "+CGEV: ME PDN DEACT %d", &cid) == 1) {
882 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800883 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800884 } else if(sscanf(s, "+CGEV: ME PDN ACT %d,%d", &cid, &reason) == 2
885 || sscanf(s, "+CGEV: ME PDN ACT %d", &cid) == 1) {
886 cgev_info.cid = (uint16)cid;
887 cgev_info.reason = (uint16)reason;
b.liu15f456b2024-10-31 20:16:06 +0800888 cgev_info.action = TRUE;
b.liubcf86c92024-08-19 19:48:28 +0800889 } else if (!strcmp(s, "+CGEV: ME DETACH")) {
890 if(cgact_wait.waitting) {
b.liu15f456b2024-10-31 20:16:06 +0800891 cgev_info.cid = cgact_wait.cid;
b.liubcf86c92024-08-19 19:48:28 +0800892 }
b.liu15f456b2024-10-31 20:16:06 +0800893 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800894 } else if (sscanf(s, "+CGEV: NW MODIFY %d,%d", &cid, &reason) == 2) {
895 cgev_info.cid = (uint16)cid;
896 cgev_info.reason = (uint16)reason;
b.liu15f456b2024-10-31 20:16:06 +0800897 cgev_info.action = TRUE;
b.liu62240ee2024-11-07 17:52:45 +0800898 } else if(sscanf(s, "+CGEV: EPS PDN ACT %d", &cid) == 1) {
899 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800900 cgev_info.action = TRUE;
b.liubcf86c92024-08-19 19:48:28 +0800901 } else {
902 LOGD(">>>>>>>>>No process +CGEV <<<<<<<<<");
903 return;
904 }
b.liu15f456b2024-10-31 20:16:06 +0800905 cgev_info.auto_change = !cgact_wait.waitting;
b.liubcf86c92024-08-19 19:48:28 +0800906
907 if(cgact_wait.act) {
b.liu15f456b2024-10-31 20:16:06 +0800908 if(cgact_wait.waitting && cgev_info.action && cgact_wait.cid == cgev_info.cid) {
b.liubcf86c92024-08-19 19:48:28 +0800909 cgact_wait.waitting = false;
910 }
911 } else {
b.liu15f456b2024-10-31 20:16:06 +0800912 if(cgact_wait.waitting && !cgev_info.action && cgact_wait.cid == cgev_info.cid) {
b.liubcf86c92024-08-19 19:48:28 +0800913 cgact_wait.waitting = false;
914 }
915 }
916
b.liu15f456b2024-10-31 20:16:06 +0800917 LOGD("+CGEV:cid - %d, act - %d, auto_change - %d, reason - %d", cgev_info.cid, cgev_info.action,
918 cgev_info.auto_change, cgev_info.reason);
b.liu15f456b2024-10-31 20:16:06 +0800919 if(cgev_info.cid >= MBTK_APN_CID_MIN && cgev_info.cid <= MBTK_APN_CID_MAX) {
b.liu7ca612c2025-04-25 09:23:36 +0800920 data_call_state_change_cb(sim_id, cgev_info.cid, cgev_info.action, cgev_info.auto_change, cgev_info.reason);
b.liu15f456b2024-10-31 20:16:06 +0800921 urc_msg_distribute(false, RIL_MSG_ID_IND_PDP_STATE_CHANGE, &cgev_info, sizeof(mbtk_ril_pdp_state_info_t));
922 }
923
b.liubcf86c92024-08-19 19:48:28 +0800924#else
925 if(at_process) {
926 if(cgact_wait.act) {
927 if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT 15,4
928 if(cgact_wait.cid == atoi(s + 18)) {
929 cgact_wait.waitting = false;
930 }
931
932 uint8 data_pdp;
933 char* tmp_s = memdup(s + 18,strlen(s + 18));
934 char* free_ptr = tmp_s;
935 char *line = tmp_s;
936 int tmp_int;
937 if (at_tok_start(&line) < 0)
938 {
939 goto at_PDP_CREG_EXIT;
940 }
941 if (at_tok_nextint(&line, &tmp_int) < 0)
942 {
943 goto at_PDP_CREG_EXIT;
944 }
945 if (at_tok_nextint(&line, &tmp_int) < 0)
946 {
947 goto at_PDP_CREG_EXIT;
948 }
949 data_pdp = tmp_int;
950at_PDP_CREG_EXIT:
951 free(free_ptr);
952
953 //data_pdp = (uint8)atoi(s + 20); //reason
954 if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
955 {
956 if(data_pdp == 0)
957 {
958 data_pdp = 25;
959 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
960 //data_pdp = cgact_wait.cid + 200;
961 }
962 else if(data_pdp == 1)
963 {
964 data_pdp = 26;
965 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
966 }
967 else if(data_pdp == 2)
968 {
969 data_pdp = 27;
970 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
971 }
972 else if(data_pdp == 3)
973 {
974 data_pdp = 27;
975 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
976 }
977 else
978 {
979
980 }
981 if(cgact_wait.cid != 0)
982 {
983 data_pdp = cgact_wait.cid + 200;
984 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
985 }
986 }
987 } else if(strStartsWith(s, "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY 1,4
988 if(cgact_wait.cid == atoi(s + 17)) {
989 cgact_wait.waitting = false;
990 }
991 }
992 } else {
993 if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
994 if(cgact_wait.cid == atoi(s + 20)) {
995 cgact_wait.waitting = false;
996 }
997 uint8 data_pdp;
998 data_pdp = 0; //
999 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1000 if(cgact_wait.cid != 0)
1001 {
1002 data_pdp = cgact_wait.cid + 100;
1003 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1004 }
1005 }
1006 }
1007 } else {
1008 // apn_state_set
1009
1010 // +CGEV: NW PDN DEACT <cid>
1011
1012 // +CGEV: EPS PDN ACT 1
1013 // +CGEV: ME PDN ACT 8,1
1014
1015 // +CGEV: ME PDN ACT 2,4
1016 uint8 data[2] = {0xFF};
1017 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
1018 //apn_state_set(atoi(s + 20), false);
1019 data[0] = (uint8)0;
1020 data[1] = (uint8)atoi(s + 20);
1021
1022 uint8 data_pdp;
1023 data_pdp = 0; //
1024 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1025 data_pdp = data[1] + 100;
1026 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1027 } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
1028 //apn_state_set(atoi(s + 19), true);
1029#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
1030 //data[0] = (uint8)1;
1031 //data[1] = (uint8)atoi(s + 19);
1032#else
1033 data[0] = (uint8)1;
1034 data[1] = (uint8)atoi(s + 19);
1035#endif
1036 } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
1037 //apn_state_set(atoi(s + 19), true);
1038 data[0] = (uint8)0;
1039 data[1] = (uint8)atoi(s + 20);
1040
1041 uint8 data_pdp;
1042 data_pdp = 0; //
1043 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1044 data_pdp = data[1] + 100;
1045 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1046 } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
1047 //apn_state_set(atoi(s + 18), true);
1048 data[0] = (uint8)1;
1049 data[1] = (uint8)atoi(s + 18);
1050
1051 uint8 data_pdp;
1052 char* tmp_s = memdup(s + 18,strlen(s + 18));
1053 char* free_ptr = tmp_s;
1054 char *line = tmp_s;
1055 int tmp_int;
1056 if (at_tok_start(&line) < 0)
1057 {
1058 goto PDP_CREG_EXIT;
1059 }
1060 if (at_tok_nextint(&line, &tmp_int) < 0)
1061 {
1062 goto PDP_CREG_EXIT;
1063 }
1064 if (at_tok_nextint(&line, &tmp_int) < 0)
1065 {
1066 goto PDP_CREG_EXIT;
1067 }
1068 data_pdp = tmp_int;
1069PDP_CREG_EXIT:
1070 free(free_ptr);
1071 //data_pdp = (uint8)atoi(s + 20); //reason
1072 if(data[1] >= 1 && data[1] < 8)
1073 {
1074 if(data_pdp == 0)
1075 {
1076 data_pdp = 25;
1077 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1078 }
1079 else if(data_pdp == 1)
1080 {
1081 data_pdp = 26;
1082 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1083 }
1084 else if(data_pdp == 2)
1085 {
1086 data_pdp = 27;
1087 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1088 }
1089 else if(data_pdp == 3)
1090 {
1091 data_pdp = 27;
1092 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1093 }
1094 else
1095 {
1096
1097 }
1098
1099 data_pdp = data[1] + 200;
1100 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1101 data[1] = 0;
1102 }
1103 } else {
1104 LOGI("No process : %s", s);
1105 }
1106
1107 urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
1108 }
1109#endif
1110 } else {
1111 LOGW("Unknown PDP URC : %s", s);
1112 }
1113}
1114
1115
b.liu7ca612c2025-04-25 09:23:36 +08001116static void urc_cell_info_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
b.liub4772072024-08-15 14:47:03 +08001117{
b.liubeb61cc2025-02-13 10:38:29 +08001118 // +EEMNRSVC: <mcc>,<lenOfMnc>,<mnc>,<tac>,<phyCellId>,<dlNrArfcn>,<dlScs>,<ulNrArfcn>,<ulScs>,<sulNrArfcn>,<sulScs>,<band>,<dlBandwidth>,<cellId>,<IsRedCapCell>,<longDRXCyclePresent>,<shortDRXCyclePresent>,<longDRXCycle>,<shortDRXCycle>,<pagingCycle>,
1119 // <rsrp>,<rsrq>,<sinr>,<rssi>,<qRxLevMin>,<qQualMin>,<srxlev>,
1120 // <pathLoss>,
1121 // <dlBler>,<averDlPRB>,<averDlMcs>,<averDlPortNum>,<averCQI>,<averLi>,<averRi>,<dlThroughPut>,<dlPeakThroughPut>,
1122 // <ulBler>,<averUlPRB>,<averUlMcs>,<averUlPortNum>,<currPuschTxPower>,<currPucchTxPower>,<grantTotal>,<ulThroughPut>,<ulPeakThroughPut>,
1123 // <nrrcModeState>,<nmmState>,<serviceState>,<IsSingleNmmRejectCause>,<NMMRejectCause>,<amfRegionId>,<amfSetId>,<amfPointer>,<nrTmsi>,
1124 // <ulBandwidth>,<dlInitialBwpFreq>,<ulInitialBwpFreq>
1125 /*
1126 +EEMNRSVC: 1120, 2, 0, 2622342, 137, 158650, 0, 146678, 0, 0, 255, 28, 79, 620598788208, 0, 0, 0, 0, 0, 64,
1127 86, 65, 86, 51, 20, 0, 49,
1128 0,
1129 0, 0, 0, 0, 38, 0, 8, 0, 0,
1130 0, 256, 24, 16, 13, 20, 2, 2, 0,
1131 1, 10, 0, 1, 0, 9, 128, 5, 2358781729,
1132 79, 788390, 733390
1133 */
1134 if(strStartsWith(s, "+EEMNRSVC:")) {
1135 // mcc,lenOfMnc,mnc,tac,PCI,dlNrArfcn,ulNrArfcn,band,rsrp,rsrq,sinr,rssi
1136 // cellID
1137 if(cell_info.running) {
1138 int tmp_int;
1139 int i = 0;
1140 char* tmp_s = memdup(s,strlen(s) + 1);
1141 char* free_ptr = tmp_s;
1142 char *line = tmp_s;
1143 char *tmp_str;
1144 if (at_tok_start(&line) < 0)
1145 {
1146 goto EEMNRSVC_EXIT;
1147 }
1148
1149 if (at_tok_nextint(&line, &tmp_int) < 0) // mcc
1150 {
1151 goto EEMNRSVC_EXIT;
1152 }
1153 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1154
1155 if (at_tok_nextint(&line, &tmp_int) < 0) // lenOfMnc
1156 {
1157 goto EEMNRSVC_EXIT;
1158 }
1159 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1160 if (at_tok_nextint(&line, &tmp_int) < 0) // mnc
1161 {
1162 goto EEMNRSVC_EXIT;
1163 }
1164 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1165
1166 if (at_tok_nextint(&line, &tmp_int) < 0) // tac
1167 {
1168 goto EEMNRSVC_EXIT;
1169 }
1170 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1171
1172 if (at_tok_nextint(&line, &tmp_int) < 0) // pci
1173 {
1174 goto EEMNRSVC_EXIT;
1175 }
1176 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1177
1178 if (at_tok_nextint(&line, &tmp_int) < 0) // dlNrArfcn
1179 {
1180 goto EEMNRSVC_EXIT;
1181 }
1182 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1183
1184 if (at_tok_nextint(&line, &tmp_int) < 0) // dlScs
1185 {
1186 goto EEMNRSVC_EXIT;
1187 }
1188
1189 if (at_tok_nextint(&line, &tmp_int) < 0) // ulNrArfcn
1190 {
1191 goto EEMNRSVC_EXIT;
1192 }
1193 cell_info.cell_list.cell[cell_info.cell_list.num].value7 = (uint32)tmp_int;
1194
1195 // <ulScs>,<sulNrArfcn>,<sulScs>
1196 for(i =0; i < 3; i++)
1197 {
1198 if (at_tok_nextint(&line, &tmp_int) < 0)
1199 {
1200 goto EEMNRSVC_EXIT;
1201 }
1202 }
1203
1204 if (at_tok_nextint(&line, &tmp_int) < 0) // band
1205 {
1206 goto EEMNRSVC_EXIT;
1207 }
1208 cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int;
1209
1210
1211 if (at_tok_nextint(&line, &tmp_int) < 0) // dlBandwidth
1212 {
1213 goto EEMNRSVC_EXIT;
1214 }
1215
1216
1217 if (at_tok_nextstr(&line, &tmp_str) < 0) // cellId
1218 {
1219 goto EEMNRSVC_EXIT;
1220 }
1221 // LOGD("cellID-str : %s", tmp_str);
1222 cell_info.cell_list.cell[cell_info.cell_list.num].value64_1 = (uint64)strtoull(tmp_str, NULL, 10);
1223 // LOGD("cellID : %llu", cell_info.cell_list.cell[cell_info.cell_list.num].value64_1);
1224
1225 // <IsRedCapCell>,<longDRXCyclePresent>,<shortDRXCyclePresent>,<longDRXCycle>,<shortDRXCycle>,<pagingCycle>
1226 for(i =0; i < 6; i++)
1227 {
1228 if (at_tok_nextint(&line, &tmp_int) < 0)
1229 {
1230 goto EEMNRSVC_EXIT;
1231 }
1232 }
1233
1234 if (at_tok_nextint(&line, &tmp_int) < 0) // <rsrp>
1235 {
1236 goto EEMNRSVC_EXIT;
1237 }
1238 cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int;
1239
1240 if (at_tok_nextint(&line, &tmp_int) < 0) // <rsrq>
1241 {
1242 goto EEMNRSVC_EXIT;
1243 }
1244 cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int;
1245
1246 if (at_tok_nextint(&line, &tmp_int) < 0) // <sinr>
1247 {
1248 goto EEMNRSVC_EXIT;
1249 }
1250 cell_info.cell_list.cell[cell_info.cell_list.num].value11 = (uint32)tmp_int;
1251
1252 if (at_tok_nextint(&line, &tmp_int) < 0) // <rssi>
1253 {
1254 goto EEMNRSVC_EXIT;
1255 }
1256 cell_info.cell_list.cell[cell_info.cell_list.num].value12 = (uint32)tmp_int;
1257
1258 cell_info.cell_list.num++;
1259
1260EEMNRSVC_EXIT:
1261 free(free_ptr);
1262 }
1263 }
1264 // +EEMNRINTER: <index>,<phyCellId>,<nrArfcn>,<dlScs>,<rsrp>,<rsrq>,<sinr>,<srxlev>,<mcc>,<lenOfMnc>,<mnc>,<tac>,<cellId>
1265 /* +EEMNRINTER: 0, 508, 723360, 0, 39, 64, -8, 1, 0, 0, 0, 0, 4294967295 */
1266 /* +EEMNRINTER: 1, 254, 723360, 0, 45, 72, 1, 7, 0, 0, 0, 0, 4294967295 */
1267 /* +EEMNRINTER: 2, 595, 723360, 0, 40, 65, -5, 3, 0, 0, 0, 0, 4294967295 */
1268 else if(strStartsWith(s, "+EEMNRINTER:")) {
1269 // phyCellId,nrArfcn,rsrp,rsrq
1270 if(cell_info.running) {
1271 int tmp_int;
1272 char* tmp_s = memdup(s,strlen(s) + 1);
1273 char* free_ptr = tmp_s;
1274 char *line = tmp_s;
1275 if (at_tok_start(&line) < 0)
1276 {
1277 goto EEMNRINTER_EXIT;
1278 }
1279 if (at_tok_nextint(&line, &tmp_int) < 0) // index
1280 {
1281 goto EEMNRINTER_EXIT;
1282 }
1283 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int > 1007) // phyCellId (0 - 1007)
1284 {
1285 goto EEMNRINTER_EXIT;
1286 }
1287 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1288 if (at_tok_nextint(&line, &tmp_int) < 0) // nrArfcn
1289 {
1290 goto EEMNRINTER_EXIT;
1291 }
1292 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1293 if (at_tok_nextint(&line, &tmp_int) < 0) // dlScs
1294 {
1295 goto EEMNRINTER_EXIT;
1296 }
1297 if (at_tok_nextint(&line, &tmp_int) < 0) // rsrp
1298 {
1299 goto EEMNRINTER_EXIT;
1300 }
1301 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1302 if (at_tok_nextint(&line, &tmp_int) < 0) // rsrq
1303 {
1304 goto EEMNRINTER_EXIT;
1305 }
1306 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1307
1308 cell_info.cell_list.num++;
1309EEMNRINTER_EXIT:
1310 free(free_ptr);
1311 }
1312 }
1313 // +EEMNRINTERRAT:<net_type>,<numInterRATEutra>,
1314 // <earfcn>,<physCellId>,<rsrp>,<rsrq>,<sinr>,<mcc>,<lenOfMnc>,<mnc>,<tac>
1315 // ......
1316 // <earfcn>,<physCellId>,<rsrp>,<rsrq>,<sinr>,<mcc>,<lenOfMnc>,<mnc>,<tac>
1317 /*
1318 +EEMNRINTERRAT: 2, 6, // LTE
1319 1300, 423, 0, 0, 0, 0, 0, 0, 0,
1320 1300, 137, 0, 0, 0, 0, 0, 0, 0,
1321 1300, 149, 0, 0, 0, 0, 0, 0, 0,
1322 1300, 494, 0, 0, 0, 0, 0, 0, 0,
1323 1300, 337, 0, 0, 0, 0, 0, 0, 0,
1324 1300, 288, 0, 0, 0, 0, 0, 0, 0
1325 */
1326 /*
1327 +EEMNRINTERRAT: 1, 0 // UMTS
1328 */
1329 else if(strStartsWith(s, "+EEMNRINTERRAT:")) {
1330 // phyCellId,nrArfcn,rsrp,rsrq
1331 if(cell_info.running) {
1332 int tmp_int;
1333 char* tmp_s = memdup(s,strlen(s) + 1);
1334 char* free_ptr = tmp_s;
1335 char *line = tmp_s;
1336 if (at_tok_start(&line) < 0)
1337 {
1338 goto EEMNRINTERRAT_EXIT;
1339 }
1340 if (at_tok_nextint(&line, &tmp_int) < 0) // net_type
1341 {
1342 goto EEMNRINTERRAT_EXIT;
1343 }
1344
1345#define CI_DEV_EM_NETWORK_LTE 2
1346
1347 // Only support LTE.
1348 if(tmp_int == CI_DEV_EM_NETWORK_LTE) { // LTE
1349 int num;
1350 int i, j;
1351 if (at_tok_nextint(&line, &num) < 0) // numInterRATEutra
1352 {
1353 goto EEMNRINTERRAT_EXIT;
1354 }
1355 LOGD("LTE-RAT num : %d", num);
1356 for(i = 0; i < num; i++) {
1357 if (at_tok_nextint(&line, &tmp_int) < 0) // earfcn
1358 {
1359 goto EEMNRINTERRAT_EXIT;
1360 }
1361 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1362
1363 if (at_tok_nextint(&line, &tmp_int) < 0) // physCellId
1364 {
1365 goto EEMNRINTERRAT_EXIT;
1366 }
1367 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1368
1369 if (at_tok_nextint(&line, &tmp_int) < 0) // rsrp
1370 {
1371 goto EEMNRINTERRAT_EXIT;
1372 }
1373 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1374
1375 if (at_tok_nextint(&line, &tmp_int) < 0) // rsrq
1376 {
1377 goto EEMNRINTERRAT_EXIT;
1378 }
1379 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1380
1381 // Jump 5 items.
1382 j = 0;
1383 while(j < 5) {
1384 if (at_tok_nextint(&line, &tmp_int) < 0)
1385 {
1386 goto EEMNRINTERRAT_EXIT;
1387 }
1388 j++;
1389 }
1390
1391 cell_info.cell_list.num++;
1392 }
1393 }
1394EEMNRINTERRAT_EXIT:
1395 free(free_ptr);
1396 }
1397 }
b.liub4772072024-08-15 14:47:03 +08001398 /*
1399 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
1400 // <rsrp>,<rsrq>, <sinr>,
1401 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
1402 // cellId,subFrameAssignType,specialSubframePatterns,transMode
1403 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
1404 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
1405 // dlBer, ulBer,
1406 // diversitySinr, diversityRssi
1407 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
1408 0, 0, 0,
1409 1, 10, 0, 1, 0, 1059, 78, 3959566565,
1410 105149248, 2, 7, 7,
1411 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
1412 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
1413 0, 0,
1414 7, 44
1415 */
b.liubeb61cc2025-02-13 10:38:29 +08001416 else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
b.liub4772072024-08-15 14:47:03 +08001417 {
1418 // tac, PCI, dlEuarfcn, ulEuarfcn, band
1419 if(cell_info.running) {
1420 int tmp_int;
1421 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001422 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001423 char* free_ptr = tmp_s;
1424 char *line = tmp_s;
1425 if (at_tok_start(&line) < 0)
1426 {
1427 goto EEMLTESVC_EXIT;
1428 }
1429
1430 if (at_tok_nextint(&line, &tmp_int) < 0)
1431 {
1432 goto EEMLTESVC_EXIT;
1433 }
1434 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int; //mcc
1435 if (at_tok_nextint(&line, &tmp_int) < 0)
1436 {
1437 goto EEMLTESVC_EXIT;
1438 }
1439 if (at_tok_nextint(&line, &tmp_int) < 0)
1440 {
1441 goto EEMLTESVC_EXIT;
1442 }
1443 cell_info.cell_list.cell[cell_info.cell_list.num].value7 = (uint32)tmp_int; //mnc
1444 /*
1445 // Jump 2 integer.
1446 i = 0;
1447 while(i < 2) {
1448 if (at_tok_nextint(&line, &tmp_int) < 0)
1449 {
1450 goto EEMLTESVC_EXIT;
1451 }
1452 i++;
1453 }
1454 */
1455 if (at_tok_nextint(&line, &tmp_int) < 0)
1456 {
1457 goto EEMLTESVC_EXIT;
1458 }
1459 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int; //tac
1460 if (at_tok_nextint(&line, &tmp_int) < 0)
1461 {
1462 goto EEMLTESVC_EXIT;
1463 }
1464 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int; //pci
1465 if (at_tok_nextint(&line, &tmp_int) < 0)
1466 {
1467 goto EEMLTESVC_EXIT;
1468 }
1469 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int; //dl arfcn
1470 if (at_tok_nextint(&line, &tmp_int) < 0)
1471 {
1472 goto EEMLTESVC_EXIT;
1473 }
1474 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int; //ul arfcn
1475 if (at_tok_nextint(&line, &tmp_int) < 0)
1476 {
1477 goto EEMLTESVC_EXIT;
1478 }
1479 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int; //band
1480 if (at_tok_nextint(&line, &tmp_int) < 0)
1481 {
1482 goto EEMLTESVC_EXIT;
1483 }
1484 if (at_tok_nextint(&line, &tmp_int) < 0)
1485 {
1486 goto EEMLTESVC_EXIT;
1487 }
1488 cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int; //cid
1489 if (at_tok_nextint(&line, &tmp_int) < 0)
1490 {
1491 goto EEMLTESVC_EXIT;
1492 }
1493 cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int; //rsrp
1494
1495 for(i =0; i < 10; i++)
1496 {
1497 if (at_tok_nextint(&line, &tmp_int) < 0)
1498 {
1499 goto EEMLTESVC_EXIT;
1500 }
1501 }
1502 cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int; //cell identiy
1503
1504 cell_info.cell_list.num++;
1505
1506EEMLTESVC_EXIT:
1507 free(free_ptr);
1508 }
1509 }
1510 /*
1511 // index,phyCellId,euArfcn,rsrp,rsrq
1512 +EEMLTEINTER: 0, 65535, 38950, 0, 0
1513 */
1514 else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
1515 {
1516 // phyCellId,euArfcn,rsrp,rsrq
1517 if(cell_info.running) {
1518 int tmp_int;
b.liufd87baf2024-11-15 15:30:38 +08001519 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001520 char* free_ptr = tmp_s;
1521 char *line = tmp_s;
1522 if (at_tok_start(&line) < 0)
1523 {
1524 goto EEMLTEINTER_EXIT;
1525 }
1526 if (at_tok_nextint(&line, &tmp_int) < 0)
1527 {
1528 goto EEMLTEINTER_EXIT;
1529 }
1530 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1531 {
1532 goto EEMLTEINTER_EXIT;
1533 }
1534 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1535 if (at_tok_nextint(&line, &tmp_int) < 0)
1536 {
1537 goto EEMLTEINTER_EXIT;
1538 }
1539 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1540 if (at_tok_nextint(&line, &tmp_int) < 0)
1541 {
1542 goto EEMLTEINTER_EXIT;
1543 }
1544 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1545 LOG("cell line : %s", line);
1546 if (at_tok_nextint(&line, &tmp_int) < 0)
1547 {
1548 goto EEMLTEINTER_EXIT;
1549 }
1550 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1551 if (at_tok_nextint(&line, &tmp_int) < 0)
1552 {
1553 LOG("cell tmp_int : %d", tmp_int);
1554 goto EEMLTEINTER_EXIT;
1555 }
1556 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1557 LOG("cell value5 : %d", cell_info.cell_list.cell[cell_info.cell_list.num].value5);
1558 cell_info.cell_list.num++;
1559EEMLTEINTER_EXIT:
1560 free(free_ptr);
1561 }
1562 }
1563 // Do nothing
1564 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
1565 {
1566 if(cell_info.running) {
1567
1568 }
1569 }
1570 // WCDMA
1571 /*
1572 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1573
1574 // if sCMeasPresent == 1
1575 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1576 // endif
1577
1578 // if sCParamPresent == 1
1579 // rac, nom, mcc, mnc_len, mnc, lac, ci,
1580 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1581 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1582 // endif
1583
1584 // if ueOpStatusPresent == 1
1585 // rrcState, numLinks, srncId, sRnti,
1586 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1587 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1588 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1589 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1590 // endif
1591 //
1592 +EEMUMTSSVC: 3, 1, 1, 1,
1593 -80, 27, -6, -18, -115, -32768,
1594 1, 1, 1120, 2, 1, 61697, 168432821,
1595 15, 24, 10763, 0, 0, 0, 0,
1596 128, 128, 65535, 0, 0,
1597 2, 255, 65535, 4294967295,
1598 0, 0, 0, 0, 0, 0,
1599 0, 0, 0, 0, 0, 0, 1, 1,
1600 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1601 0, 0, 0, 0, 0, 0
1602 */
1603 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1604 {
1605 // lac, ci, arfcn
1606 if(cell_info.running) {
1607 int tmp_int;
1608 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001609 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001610 char* free_ptr = tmp_s;
1611 char *line = tmp_s;
1612 if (at_tok_start(&line) < 0)
1613 {
1614 goto EEMUMTSSVC_EXIT;
1615 }
1616 // Jump 12 integer.
1617 i = 0;
1618 while(i < 12) {
1619 if (at_tok_nextint(&line, &tmp_int) < 0)
1620 {
1621 goto EEMUMTSSVC_EXIT;
1622 }
1623 i++;
1624 }
1625 // mcc
1626 if (at_tok_nextint(&line, &tmp_int) < 0)
1627 {
1628 goto EEMUMTSSVC_EXIT;
1629 }
1630 cell_info.cell_list.cell[cell_info.cell_list.num].value4= (uint32)tmp_int;
1631 // mnc
1632 if (at_tok_nextint(&line, &tmp_int) < 0)
1633 {
1634 goto EEMUMTSSVC_EXIT;
1635 }
1636 cell_info.cell_list.cell[cell_info.cell_list.num].value5= (uint32)tmp_int;
1637 // lac
1638 if (at_tok_nextint(&line, &tmp_int) < 0)
1639 {
1640 goto EEMUMTSSVC_EXIT;
1641 }
1642 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1643 // ci
1644 if (at_tok_nextint(&line, &tmp_int) < 0)
1645 {
1646 goto EEMUMTSSVC_EXIT;
1647 }
1648 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1649
1650 if (at_tok_nextint(&line, &tmp_int) < 0)
1651 {
1652 goto EEMUMTSSVC_EXIT;
1653 }
1654 // cpi
1655 if (at_tok_nextint(&line, &tmp_int) < 0)
1656 {
1657 goto EEMUMTSSVC_EXIT;
1658 }
1659 cell_info.cell_list.cell[cell_info.cell_list.num].value6= (uint32)tmp_int;
1660 /*
1661 // Jump 2 integer.
1662 i = 0;
1663 while(i < 2) {
1664 if (at_tok_nextint(&line, &tmp_int) < 0)
1665 {
1666 goto EEMUMTSSVC_EXIT;
1667 }
1668 i++;
1669 }
1670 */
1671 // arfcn
1672 if (at_tok_nextint(&line, &tmp_int) < 0)
1673 {
1674 goto EEMUMTSSVC_EXIT;
1675 }
1676 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1677
1678 cell_info.cell_list.num++;
1679EEMUMTSSVC_EXIT:
1680 free(free_ptr);
1681 }
1682 }
1683 /*
1684 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1685 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1686 */
1687 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1688 {
1689 // lac, ci, arfcn
1690 if(cell_info.running) {
1691 int tmp_int;
1692 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001693 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001694 char* free_ptr = tmp_s;
1695 char *line = tmp_s;
1696 if (at_tok_start(&line) < 0)
1697 {
1698 goto EEMUMTSINTRA_EXIT;
1699 }
1700 // Jump 8 integer.
1701 i = 0;
1702 while(i < 8) {
1703 if (at_tok_nextint(&line, &tmp_int) < 0)
1704 {
1705 goto EEMUMTSINTRA_EXIT;
1706 }
1707 i++;
1708 }
1709
1710 // lac
1711 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1712 {
1713 goto EEMUMTSINTRA_EXIT;
1714 }
1715 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1716
1717 // ci
1718 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1719 {
1720 goto EEMUMTSINTRA_EXIT;
1721 }
1722 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1723
1724 // arfcn
1725 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1726 {
1727 goto EEMUMTSINTRA_EXIT;
1728 }
1729 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1730
1731 cell_info.cell_list.num++;
1732EEMUMTSINTRA_EXIT:
1733 free(free_ptr);
1734 }
1735 }
1736 /*
1737 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1738 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1739 */
1740 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1741 {
1742 // lac, ci, arfcn
1743 if(cell_info.running) {
1744 int tmp_int;
1745 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001746 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001747 char* free_ptr = tmp_s;
1748 char *line = tmp_s;
1749 if (at_tok_start(&line) < 0)
1750 {
1751 goto EEMUMTSINTERRAT_EXIT;
1752 }
1753 // Jump 7 integer.
1754 i = 0;
1755 while(i < 7) {
1756 if (at_tok_nextint(&line, &tmp_int) < 0)
1757 {
1758 goto EEMUMTSINTERRAT_EXIT;
1759 }
1760 i++;
1761 }
1762
1763 // lac
1764 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1765 {
1766 goto EEMUMTSINTERRAT_EXIT;
1767 }
1768 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1769
1770 // ci
1771 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1772 {
1773 goto EEMUMTSINTERRAT_EXIT;
1774 }
1775 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1776
1777 // arfcn
1778 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1779 {
1780 goto EEMUMTSINTERRAT_EXIT;
1781 }
1782 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1783
1784 cell_info.cell_list.num++;
1785EEMUMTSINTERRAT_EXIT:
1786 free(free_ptr);
1787 }
1788 }
1789 // GSM
1790 // +EEMGINFOBASIC: 2
1791 // Do nothing.
1792 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1793 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1794 {
1795 if(cell_info.running) {
1796
1797 }
1798 }
1799 /*
1800 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1801 // bsic, C1, C2, TA, TxPwr,
1802 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1803 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1804 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1805 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1806 // gsmBand,channelMode
1807 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1808 63, 36, 146, 1, 7,
1809 46, 42, 42, 7, 0,
1810 53, 0, 8, 0, 1, 6, 53,
1811 2, 0, 146, 42, 54, 0, 1,
1812 1, 32, 0, 0, 0, 0,
1813 0, 0
1814 */
1815 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1816 {
1817 // lac, ci, arfcn, bsic
1818 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1819 if(cell_info.running) {
1820 int tmp_int;
1821 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001822 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001823 char* free_ptr = tmp_s;
1824 char *line = tmp_s;
1825 if (at_tok_start(&line) < 0)
1826 {
1827 goto EEMGINFOSVC_EXIT;
1828 }
1829
1830 // mcc
1831 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1832 {
1833 goto EEMGINFOSVC_EXIT;
1834 }
1835 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1836
1837 //mnc_len
1838 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1839 {
1840 goto EEMGINFOSVC_EXIT;
1841 }
1842 // mnc
1843 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1844 {
1845 goto EEMGINFOSVC_EXIT;
1846 }
1847 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1848
1849 /*
1850 // Jump 3 integer.
1851 i = 0;
1852 while(i < 3) {
1853 if (at_tok_nextint(&line, &tmp_int) < 0)
1854 {
1855 goto EEMGINFOSVC_EXIT;
1856 }
1857 i++;
1858 }
1859 */
1860 // lac
1861 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1862 {
1863 goto EEMGINFOSVC_EXIT;
1864 }
1865 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1866
1867 // ci
1868 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1869 {
1870 goto EEMGINFOSVC_EXIT;
1871 }
1872 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1873
1874 // Jump 2 integer.
1875 i = 0;
1876 while(i < 2) {
1877 if (at_tok_nextint(&line, &tmp_int) < 0)
1878 {
1879 goto EEMGINFOSVC_EXIT;
1880 }
1881 i++;
1882 }
1883
1884 // bsic
1885 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1886 {
1887 goto EEMGINFOSVC_EXIT;
1888 }
1889 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1890
1891 // Jump 15 integer.
1892 i = 0;
1893 while(i < 15) {
1894 if (at_tok_nextint(&line, &tmp_int) < 0)
1895 {
1896 goto EEMGINFOSVC_EXIT;
1897 }
1898 i++;
1899 }
1900
1901 // arfcn
1902 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1903 {
1904 goto EEMGINFOSVC_EXIT;
1905 }
1906 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1907
1908 cell_info.cell_list.num++;
1909EEMGINFOSVC_EXIT:
1910 free(free_ptr);
1911 }
1912 }
1913 /*
1914 // PS_attached, attach_type, service_type, tx_power, c_value,
1915 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1916 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1917 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1918 +EEMGINFOPS: 1, 255, 0, 0, 0,
1919 0, 0, 268435501, 1, 0, 0,
1920 4, 0, 96, 0, 0, 0,
1921 0, 0, 0, 65535, 0, 13350
1922 */
1923 // Do nothing.
1924 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1925 {
1926 if(cell_info.running) {
1927
1928 }
1929 }
1930 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1931 {
1932 if(cell_info.running) {
1933 int tmp_int;
1934 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001935 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001936 char* free_ptr = tmp_s;
1937 char *line = tmp_s;
1938 if (at_tok_start(&line) < 0)
1939 {
1940 goto EEMGINFOPS_EXIT;
1941 }
1942
1943 // nc_num
1944 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1945 {
1946 LOG("cell_info.running 1= %d\n.",cell_info.running);
1947 goto EEMGINFOPS_EXIT;
1948 }
1949 // mcc
1950 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1951 {
1952 LOG("cell_info.running 2= %d\n.",cell_info.running);
1953 goto EEMGINFOPS_EXIT;
1954 }
1955 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1956
1957 // mnc
1958 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1959 {
1960 LOG("cell_info.running 3= %d\n.",cell_info.running);
1961 goto EEMGINFOPS_EXIT;
1962 }
1963 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1964
1965 // lac
1966 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1967 {
1968 LOG("cell_info.running 4= %d\n.",cell_info.running);
1969 goto EEMGINFOPS_EXIT;
1970 }
1971 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1972
1973 // rac
1974 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1975 {
1976 LOG("cell_info.running 5= %d\n.",cell_info.running);
1977 goto EEMGINFOPS_EXIT;
1978 }
1979
1980 // ci
1981 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1982 {
1983 LOG("cell_info.running 6= %d\n.",cell_info.running);
1984 goto EEMGINFOPS_EXIT;
1985 }
1986 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1987
1988 // rx_lv
1989 if (at_tok_nextint(&line, &tmp_int) < 0)
1990 {
1991 LOG("cell_info.running 7= %d\n.",cell_info.running);
1992 goto EEMGINFOPS_EXIT;
1993 }
1994
1995 // bsic
1996 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1997 {
1998 LOG("cell_info.running 8= %d\n.",cell_info.running);
1999 goto EEMGINFOPS_EXIT;
2000 }
2001 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
2002
2003 // Jump 2 integer.
2004 i = 0;
2005 while(i < 2) {
2006 if (at_tok_nextint(&line, &tmp_int) < 0)
2007 {
2008 LOG("cell_info.running 9= %d\n.",cell_info.running);
2009 goto EEMGINFOPS_EXIT;
2010 }
2011 i++;
2012 }
2013
2014 // arfcn
2015 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
2016 {
2017 LOG("cell_info.running 10 = %d\n.",cell_info.running);
2018 goto EEMGINFOPS_EXIT;
2019 }
2020 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
2021
2022 cell_info.cell_list.num++;
2023EEMGINFOPS_EXIT:
2024 free(free_ptr);
2025 }
2026 } else {
2027 LOGW("Unknown CELL URC : %s", s);
2028 }
2029}
2030
b.liu87afc4c2024-08-14 17:33:45 +08002031
b.liu7ca612c2025-04-25 09:23:36 +08002032static void onUnsolicited(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
b.liu87afc4c2024-08-14 17:33:45 +08002033{
b.liufd87baf2024-11-15 15:30:38 +08002034 LOGV("URC : %s", s);
b.liu87afc4c2024-08-14 17:33:45 +08002035 // MBTK_AT_READY
b.liuaced4f92024-12-31 11:14:51 +08002036 // +CMT: ,23
2037 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
2038 // Get PDU data.
2039 if(cmt_found) {
2040 cmt_found = FALSE;
b.liu7ca612c2025-04-25 09:23:36 +08002041 urc_sms_state_change_process(sim_id, s, true);
b.liuaced4f92024-12-31 11:14:51 +08002042 } else if (strStartsWith(s, "MBTK_AT_READY")) { // AT ready.
b.liu87afc4c2024-08-14 17:33:45 +08002043
b.liubcf86c92024-08-19 19:48:28 +08002044 } else if(strStartsWith(s, "CONNECT") || strStartsWith(s, "+CGEV:")) {
b.liu7ca612c2025-04-25 09:23:36 +08002045 urc_pdp_state_change_process(sim_id, s, sms_pdu);
b.liubeb61cc2025-02-13 10:38:29 +08002046 } else if(strStartsWith(s, "+EEMNRSVC:") || strStartsWith(s, "+EEMNRINTER:")
2047 || strStartsWith(s, "+EEMNRINTERRAT:")
2048 || strStartsWith(s, "+EEMLTESVC:") || strStartsWith(s, "+EEMLTEINTER:")
b.liubcf86c92024-08-19 19:48:28 +08002049 || strStartsWith(s, "+EEMLTEINTRA:") || strStartsWith(s, "+EEMLTEINTERRAT:")
2050 || strStartsWith(s, "+EEMUMTSSVC:") || strStartsWith(s, "+EEMUMTSINTRA:")
2051 || strStartsWith(s, "+EEMUMTSINTERRAT:") || strStartsWith(s, "+EEMGINFOBASIC:")
2052 || strStartsWith(s, "+EEMGINFOSVC:") || strStartsWith(s, "+EEMGINFOPS:")
2053 || strStartsWith(s, "+EEMGINFONC:")) {
b.liu7ca612c2025-04-25 09:23:36 +08002054 urc_cell_info_process(sim_id, s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08002055 }
2056 else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
2057 {
2058 const char* ptr = s + strlen("*RADIOPOWER:");
2059 while(*ptr != '\0' && *ptr == ' ' )
2060 {
2061 ptr++;
2062 }
2063
b.liu15f456b2024-10-31 20:16:06 +08002064 mbtk_ril_radio_state_info_t state;
2065 memset(&state, 0, sizeof(mbtk_ril_radio_state_info_t));
b.liu7ca612c2025-04-25 09:23:36 +08002066 state.sim_id = sim_id;
b.liu87afc4c2024-08-14 17:33:45 +08002067 if(*ptr == '1') {
b.liu15f456b2024-10-31 20:16:06 +08002068 state.radio_state = MBTK_RADIO_STATE_FULL_FUNC;
b.liu87afc4c2024-08-14 17:33:45 +08002069 } else {
b.liu15f456b2024-10-31 20:16:06 +08002070 state.radio_state = MBTK_RADIO_STATE_MINI_FUNC;
b.liu87afc4c2024-08-14 17:33:45 +08002071 }
b.liu15f456b2024-10-31 20:16:06 +08002072 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 +08002073 }
2074 // +CREG: 1, "8010", "000060a5", 0, 2, 0
2075 // +CREG: 1, "8330", "06447347", 7, 2, 0
2076 // +CEREG: 1, "8330", "06447347", 7
2077 // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
2078 // $CREG: 1, "8010", "000060a7", 0,, 2, 0
2079 // +CGREG: 1
b.liubeb61cc2025-02-13 10:38:29 +08002080 // +C5GREG: 1,"00280386","07e920010",11,1,"01"
b.liu87afc4c2024-08-14 17:33:45 +08002081 else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
b.liu15f456b2024-10-31 20:16:06 +08002082 || strStartsWith(s, "+CEREG:") // LTE data registed.
b.liubeb61cc2025-02-13 10:38:29 +08002083 || strStartsWith(s, "+CREG:") // GMS/WCDMA/LTE CS registed.
2084 || strStartsWith(s, "+C5GREG:")) // NR data registed.
b.liu87afc4c2024-08-14 17:33:45 +08002085 {
b.liu7ca612c2025-04-25 09:23:36 +08002086 urc_net_reg_state_change_process(sim_id, s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08002087 }
b.liu15f456b2024-10-31 20:16:06 +08002088 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
2089 else if(strStartsWith(s, "+CLCC:")
2090 || strStartsWith(s, "+CPAS:")
2091 || strStartsWith(s, "+CALLDISCONNECT:"))
b.liu87afc4c2024-08-14 17:33:45 +08002092 {
b.liu7ca612c2025-04-25 09:23:36 +08002093 urc_call_state_change_process(sim_id, s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08002094 }
b.liu15f456b2024-10-31 20:16:06 +08002095 else if(strStartsWith(s, "*SIMDETEC:")
2096 || strStartsWith(s, "*EUICC:")
2097 || strStartsWith(s, "+CPIN:"))
2098 {
b.liu7ca612c2025-04-25 09:23:36 +08002099 urc_sim_state_change_process(sim_id, s, sms_pdu);
b.liu15f456b2024-10-31 20:16:06 +08002100 }
2101 else if(strStartsWith(s, "+CMT:"))
2102 {
b.liuaced4f92024-12-31 11:14:51 +08002103 cmt_found = TRUE;
b.liu7ca612c2025-04-25 09:23:36 +08002104 urc_sms_state_change_process(sim_id, s, false);
b.liu15f456b2024-10-31 20:16:06 +08002105 }
b.liu29ead772025-05-26 17:51:20 +08002106 else if(strStartsWith(s, "*ECALLDATA:")
2107 || strStartsWith(s, "+ECALLDIALRETRY:"))
b.liu15f456b2024-10-31 20:16:06 +08002108 {
b.liu7ca612c2025-04-25 09:23:36 +08002109 urc_ecall_state_change_process(sim_id, s, sms_pdu);
b.liu15f456b2024-10-31 20:16:06 +08002110 }
2111#if 0
b.liu87afc4c2024-08-14 17:33:45 +08002112 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
2113 else if(strStartsWith(s, "+CLCC:"))
2114 {
2115 mbtk_call_info_t reg;
2116 reg.call_wait = MBTK_CLCC;
2117 char* tmp_s = memdup(s,strlen(s));
2118 char* free_ptr = tmp_s;
2119 char *line = tmp_s;
2120 int tmp_int;
2121 char *tmp_str;
2122 int err;
2123
2124 err = at_tok_start(&line);
2125 if (err < 0)
2126 {
2127 goto CLCC_EXIT;
2128 }
2129 err = at_tok_nextint(&line, &tmp_int); // dir1
2130 if (err < 0)
2131 {
2132 goto CLCC_EXIT;
2133 }
2134 reg.dir1 = (uint8)tmp_int;
2135 err = at_tok_nextint(&line, &tmp_int);// dir
2136 if (err < 0)
2137 {
2138 goto CLCC_EXIT;
2139 }
2140 reg.dir = (uint8)tmp_int;
2141 err = at_tok_nextint(&line, &tmp_int);// state
2142 if (err < 0)
2143 {
2144 goto CLCC_EXIT;
2145 }
2146 reg.state = (uint8)tmp_int;
2147 err = at_tok_nextint(&line, &tmp_int);// mode
2148 if (err < 0)
2149 {
2150 goto CLCC_EXIT;
2151 }
2152 reg.mode = (uint8)tmp_int;
2153 err = at_tok_nextint(&line, &tmp_int);// mpty
2154 if (err < 0)
2155 {
2156 goto CLCC_EXIT;
2157 }
2158 reg.mpty = (uint8)tmp_int;
2159 err = at_tok_nextstr(&line, &tmp_str); // phone_number
2160 if (err < 0)
2161 {
2162 goto CLCC_EXIT;
2163 }
2164
2165 memset(reg.phone_number,0,sizeof(reg.phone_number));
2166 memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
2167 err = at_tok_nextint(&line, &tmp_int);// tpye
2168 if (err < 0)
2169 {
2170 goto CLCC_EXIT;
2171 }
2172 reg.type = (uint8)tmp_int;
2173 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
2174CLCC_EXIT:
2175 free(free_ptr);
2176 }
2177 // +CPAS: 4
2178 else if(strStartsWith(s, "+CPAS:"))
2179 {
2180 mbtk_call_info_t reg;
2181 reg.call_wait = 0;
2182 char* tmp_s = memdup(s,strlen(s));
2183 char* free_ptr = tmp_s;
2184 char *line = tmp_s;
2185 int tmp_int;
2186 int err;
2187
2188 memset(&reg,0,sizeof(reg));
2189
2190 err = at_tok_start(&line);
2191 if (err < 0)
2192 {
2193 goto CPAS_EXIT;
2194 }
2195 err = at_tok_nextint(&line, &tmp_int);
2196 if (err < 0)
2197 {
2198 goto CPAS_EXIT;
2199 }
2200 reg.pas = (uint8)tmp_int;
2201 reg.call_wait = MBTK_CPAS;
2202 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
2203CPAS_EXIT:
2204 free(free_ptr);
2205 }
2206 // +CALLDISCONNECT: 1
2207 else if(strStartsWith(s, "+CALLDISCONNECT:"))
2208 {
2209 mbtk_call_info_t reg;
2210 reg.call_wait = 0;
2211 char* tmp_s = memdup(s,strlen(s));
2212 char* free_ptr = tmp_s;
2213 char *line = tmp_s;
2214 int tmp_int;
2215 int err;
2216
2217 memset(&reg,0,sizeof(reg));
2218
2219 err = at_tok_start(&line);
2220 if (err < 0)
2221 {
2222 goto CALLDISCONNECTED_EXIT;
2223 }
2224 err = at_tok_nextint(&line, &tmp_int);
2225 if (err < 0)
2226 {
2227 goto CALLDISCONNECTED_EXIT;
2228 }
2229 reg.disconnected_id = tmp_int;
2230 reg.call_wait = MBTK_DISCONNECTED;
2231
2232 if(reg.call_wait == MBTK_DISCONNECTED)
2233 {
2234 //mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
2235 }
2236
2237 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
2238
2239CALLDISCONNECTED_EXIT:
2240 free(free_ptr);
2241 }
2242 // *SIMDETEC:1,SIM
2243 else if(strStartsWith(s, "*SIMDETEC:"))
2244 {
2245 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
2246 {
2247 net_info.sim_state = MBTK_SIM_ABSENT;
2248 }
2249
2250 sim_info_reg.sim = -1;
2251 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
2252 sim_info_reg.sim = 0;
2253 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
2254 sim_info_reg.sim = 1;
2255 if(sim_info_reg.sim == 0)
2256 {
2257 uint8 data_pdp;
2258 data_pdp = 11; //
2259 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
2260 }
2261 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
2262 }
2263 // *EUICC:1
2264/*0: SIM
22651: USIM
22662: TEST SIM
22673: TEST USIM
22684: UNKNOWN
2269Note: *EUICC:
2270*/
2271 else if(strStartsWith(s, "*EUICC:"))
2272 {
2273 sim_info_reg.sim_card_type = -1;
2274 if(strStartsWith(s, "*EUICC: 0"))
2275 sim_info_reg.sim_card_type = 1;
2276 else if(strStartsWith(s, "*EUICC: 1"))
2277 sim_info_reg.sim_card_type = 2;
2278 else if(strStartsWith(s, "*EUICC: 2"))
2279 sim_info_reg.sim_card_type = 1;
2280 else if(strStartsWith(s, "*EUICC: 3"))
2281 sim_info_reg.sim_card_type = 2;
2282 else if(strStartsWith(s, "*EUICC: 4"))
2283 sim_info_reg.sim_card_type = 0;
2284 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
2285 }
2286 // +CPIN: SIM PIN
2287 else if(strStartsWith(s, "+CPIN:"))
2288 {
2289 sim_info_reg.sim = -1;
2290 if(strStartsWith(s, "+CPIN: READY"))
2291 {
2292 sim_info_reg.sim = 1;
2293 net_info.sim_state = MBTK_SIM_READY;
2294 }
2295 else if(strStartsWith(s, "+CPIN: SIM PIN"))
2296 {
2297 sim_info_reg.sim = 2;
2298 net_info.sim_state = MBTK_SIM_PIN;
2299 }
2300 else if(strStartsWith(s, "+CPIN: SIM PUK"))
2301 {
2302 sim_info_reg.sim = 3;
2303 net_info.sim_state = MBTK_SIM_PUK;
2304 }
2305 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
2306 {
2307 sim_info_reg.sim = 4;
2308 net_info.sim_state = MBTK_SIM_ABSENT;
2309 }
2310 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
2311 {
2312 sim_info_reg.sim = 5;
2313 net_info.sim_state = MBTK_SIM_ABSENT;
2314 }
2315 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
2316 {
2317 sim_info_reg.sim = 6;
2318 net_info.sim_state = MBTK_SIM_ABSENT;
2319 }
2320 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
2321 {
2322 sim_info_reg.sim = 7;
2323 net_info.sim_state = MBTK_SIM_ABSENT;
2324 }
2325 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
2326 {
2327 sim_info_reg.sim = 8;
2328 net_info.sim_state = MBTK_SIM_ABSENT;
2329 }
2330 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
2331 {
2332 sim_info_reg.sim = 9;
2333 net_info.sim_state = MBTK_SIM_ABSENT;
2334 }
2335 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
2336 {
2337 sim_info_reg.sim = 10;
2338 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
2339 }
2340 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
2341 {
2342 sim_info_reg.sim = 11;
2343 net_info.sim_state = MBTK_SIM_ABSENT;
2344 }
2345 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
2346 {
2347 sim_info_reg.sim = 12;
2348 net_info.sim_state = MBTK_SIM_ABSENT;
2349 }
2350 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
2351 {
2352 sim_info_reg.sim = 13;
2353 net_info.sim_state = MBTK_SIM_ABSENT;
2354 }
2355 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
2356 {
2357 sim_info_reg.sim = 14;
2358 net_info.sim_state = MBTK_SIM_ABSENT;
2359 }
2360 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
2361 {
2362 sim_info_reg.sim = 15;
2363 net_info.sim_state = MBTK_SIM_ABSENT;
2364 }
2365 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
2366 {
2367 sim_info_reg.sim = 16;
2368 net_info.sim_state = MBTK_SIM_ABSENT;
2369 }
2370 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
2371 {
2372 sim_info_reg.sim = 17;
2373 net_info.sim_state = MBTK_SIM_ABSENT;
2374 }
2375 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
2376 {
2377 sim_info_reg.sim = 18;
2378 net_info.sim_state = MBTK_SIM_ABSENT;
2379 }
2380 else
2381 sim_info_reg.sim = 20;
2382
2383 if(sim_info_reg.sim == 18)
2384 {
2385 uint8 data_pdp;
2386 data_pdp = 11; //
2387 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
2388 }
2389
2390 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
2391 }
2392 // +CMT: ,23
2393 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
2394 else if(strStartsWith(s, "+CMT:") || sms_cmt)
2395 {
2396 if(!sms_cmt){
2397 sms_cmt = true;
2398 }else{
2399 sms_cmt = false;
2400 }
2401 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
2402 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
2403 }
b.liub4772072024-08-15 14:47:03 +08002404#endif
b.liu87afc4c2024-08-14 17:33:45 +08002405 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"
2406 {
2407
2408 }
2409 else
2410 {
2411 LOGV("Unknown URC : %s", s);
2412 }
b.liu87afc4c2024-08-14 17:33:45 +08002413}
2414
b.liu7ca612c2025-04-25 09:23:36 +08002415static void onUnsolicited1(const char *s, const char *sms_pdu)
2416{
2417 onUnsolicited(MBTK_SIM_1, s, sms_pdu);
2418}
2419
2420static void onUnsolicited2(const char *s, const char *sms_pdu)
2421{
2422 onUnsolicited(MBTK_SIM_2, s, sms_pdu);
2423}
2424
b.liu87afc4c2024-08-14 17:33:45 +08002425static int openSocket(const char* sockname)
2426{
2427 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
2428 if (sock < 0)
2429 {
2430 LOGE("Error create socket: %s\n", strerror(errno));
2431 return -1;
2432 }
2433 struct sockaddr_un addr;
2434 memset(&addr, 0, sizeof(addr));
2435 addr.sun_family = AF_UNIX;
2436 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
2437 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
2438 {
2439 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
2440 sleep(1);
2441 }
2442
2443#if 0
2444 int sk_flags = fcntl(sock, F_GETFL, 0);
2445 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
2446#endif
2447
2448 return sock;
2449}
2450
b.liu571445f2025-02-13 10:22:55 +08002451static void ril_at_ready_process()
b.liu7ca612c2025-04-25 09:23:36 +08002452{
2453 // SIM1 radio state config.
2454 ril_info.radio_state[MBTK_SIM_1] = ril_radio_state_get(MBTK_SIM_1, ATPORTTYPE_0);
2455 if (ril_info.radio_state[MBTK_SIM_1] != MBTK_RADIO_STATE_FULL_FUNC)
b.liu571445f2025-02-13 10:22:55 +08002456 {
b.liu7ca612c2025-04-25 09:23:36 +08002457 ril_radio_state_set(MBTK_SIM_1, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);
b.liu87afc4c2024-08-14 17:33:45 +08002458 }
b.liu571445f2025-02-13 10:22:55 +08002459
b.liu7ca612c2025-04-25 09:23:36 +08002460 if(ril_info.radio_state[MBTK_SIM_1] == MBTK_RADIO_STATE_FULL_FUNC)
b.liu87afc4c2024-08-14 17:33:45 +08002461 {
b.liu7ca612c2025-04-25 09:23:36 +08002462 at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+CEREG=2", NULL);
2463 }
2464
2465 // SIM2 radio state config.
2466 ril_info.radio_state[MBTK_SIM_2] = ril_radio_state_get(MBTK_SIM_2, ATPORTTYPE_0);
2467 if (ril_info.radio_state[MBTK_SIM_2] != MBTK_RADIO_STATE_FULL_FUNC)
b.liu571445f2025-02-13 10:22:55 +08002468 {
b.liu7ca612c2025-04-25 09:23:36 +08002469 ril_radio_state_set(MBTK_SIM_2, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);
2470 }
2471
2472 if(ril_info.radio_state[MBTK_SIM_2] == MBTK_RADIO_STATE_FULL_FUNC)
2473 {
2474 at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+CEREG=2", NULL);
2475 }
2476
2477 // SIM1 state config.
2478 ril_info.sim_state[MBTK_SIM_1] = ril_sim_state_get(MBTK_SIM_1, ATPORTTYPE_0);
2479 if(ril_info.sim_state[MBTK_SIM_1] == MBTK_SIM_STATE_READY)
2480 {
2481 LOGD("SIM1 READY!");
2482 at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+COPS=3", NULL);
b.liu87afc4c2024-08-14 17:33:45 +08002483
2484 // Set APN from prop.
b.liu7ca612c2025-04-25 09:23:36 +08002485 apn_auto_conf_from_prop(MBTK_SIM_1, ATPORTTYPE_0);
b.liu571445f2025-02-13 10:22:55 +08002486 }
2487 else
2488 {
b.liu7ca612c2025-04-25 09:23:36 +08002489 LOGE("SIM1 NOT READY!");
2490 }
2491
2492 // SIM2 state config.
2493 ril_info.sim_state[MBTK_SIM_2] = ril_sim_state_get(MBTK_SIM_2, ATPORTTYPE_0);
2494 if(ril_info.sim_state[MBTK_SIM_2] == MBTK_SIM_STATE_READY)
2495 {
2496 LOGD("SIM1 READY!");
2497 at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+COPS=3", NULL);
2498
2499 // Set APN from prop.
2500 apn_auto_conf_from_prop(MBTK_SIM_2, ATPORTTYPE_0);
2501 }
2502 else
2503 {
2504 LOGE("SIM1 NOT READY!");
2505 }
2506
2507 if(req_dual_sim_get(ATPORTTYPE_0, &(ril_info.cur_sim_id), NULL)) {
2508 LOGE("req_dual_sim_get() fail, so set to SIM1.");
2509 ril_info.cur_sim_id = MBTK_SIM_1;
2510 } else {
2511 LOGD("Current SIM : %d", ril_info.cur_sim_id);
b.liu87afc4c2024-08-14 17:33:45 +08002512 }
2513}
2514
2515static void ind_regisger(sock_cli_info_t* cli_info, uint16 ind)
b.liu571445f2025-02-13 10:22:55 +08002516{
2517 uint32 i = 0;
2518 while(i < cli_info->ind_num)
2519 {
2520 if(cli_info->ind_register[i] == ind)
2521 break;
2522 i++;
2523 }
2524
2525 if(i == cli_info->ind_num) // No found IND
2526 {
2527 cli_info->ind_register[i] = ind;
2528 cli_info->ind_num++;
b.liu87afc4c2024-08-14 17:33:45 +08002529 LOGD("Register IND : %s", id2str(ind));
b.liu571445f2025-02-13 10:22:55 +08002530 }
2531 else
2532 {
b.liu87afc4c2024-08-14 17:33:45 +08002533 LOGW("IND had exist.");
b.liu571445f2025-02-13 10:22:55 +08002534 }
b.liu87afc4c2024-08-14 17:33:45 +08002535}
2536
b.liu571445f2025-02-13 10:22:55 +08002537// Process AT URC data
b.liu87afc4c2024-08-14 17:33:45 +08002538static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack)
b.liub171c9a2024-11-12 19:23:29 +08002539{
2540 if(cli_info) {
2541 if(ril_info.msg_queue[cli_info->port].count >= PACK_PROCESS_QUEUE_MAX)
2542 {
2543 LOGE("Packet process queue is full");
2544 return -1;
2545 }
2546 } else {
2547 if(ril_info.msg_queue[ATPORTTYPE_0].count >= PACK_PROCESS_QUEUE_MAX)
2548 {
2549 LOGE("Packet process queue is full");
2550 return -1;
2551 }
2552 }
b.liu571445f2025-02-13 10:22:55 +08002553
b.liu87afc4c2024-08-14 17:33:45 +08002554 ril_msg_queue_info_t *item = (ril_msg_queue_info_t*)malloc(sizeof(ril_msg_queue_info_t));
b.liu571445f2025-02-13 10:22:55 +08002555 if(!item)
2556 {
b.liu87afc4c2024-08-14 17:33:45 +08002557 LOGE("malloc() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08002558 return -1;
2559 }
2560 item->cli_info = cli_info;
b.liub171c9a2024-11-12 19:23:29 +08002561 item->pack = pack;
2562
2563 if(cli_info) {
2564 mbtk_queue_put(&(ril_info.msg_queue[cli_info->port]), item);
2565
2566 // If thread is waitting,continue it.
2567 pthread_mutex_lock(&(ril_info.msg_mutex[cli_info->port]));
2568 pthread_cond_signal(&(ril_info.msg_cond[cli_info->port]));
2569 pthread_mutex_unlock(&(ril_info.msg_mutex[cli_info->port]));
2570 } else { // URC message, is null.
2571 mbtk_queue_put(&(ril_info.msg_queue[ATPORTTYPE_0]), item);
2572
2573 // If thread is waitting,continue it.
2574 pthread_mutex_lock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
2575 pthread_cond_signal(&(ril_info.msg_cond[ATPORTTYPE_0]));
2576 pthread_mutex_unlock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
2577 }
b.liu571445f2025-02-13 10:22:55 +08002578
2579 return 0;
b.liu87afc4c2024-08-14 17:33:45 +08002580}
2581
2582
2583static void pack_distribute(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
b.liu571445f2025-02-13 10:22:55 +08002584{
2585 // Register IND Message.
b.liu15f456b2024-10-31 20:16:06 +08002586 if(pack->msg_type == RIL_MSG_TYPE_REQ)
2587 {
2588 if(pack->msg_id > RIL_MSG_ID_IND_BEGIN
2589 && pack->msg_id < RIL_MSG_ID_IND_END) {
2590 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
2591 if(cli_info->ind_num >= IND_REGISTER_MAX)
2592 {
2593 LOGE("IND if full.");
2594 err = MBTK_RIL_ERR_IND_FULL;
2595 }
2596 else
2597 {
2598 ind_regisger(cli_info, pack->msg_id);
2599 }
2600
b.liu7ca612c2025-04-25 09:23:36 +08002601 ril_error_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, err);
b.liu15f456b2024-10-31 20:16:06 +08002602
2603 ril_msg_pack_free(pack);
2604 } else {
b.liub171c9a2024-11-12 19:23:29 +08002605 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 +08002606 if(0 && pack->data_len > 0)
2607 {
2608 log_hex("DATA", pack->data, pack->data_len);
2609 }
2610
2611 // Send to REQ_process_thread process.
2612 send_pack_to_queue(cli_info, pack);
2613
2614 // For test.
2615 // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS);
2616 }
2617 } else {
2618 LOGE("Pack type error : %d", pack->msg_type);
2619 }
b.liu87afc4c2024-08-14 17:33:45 +08002620}
2621
b.liu571445f2025-02-13 10:22:55 +08002622// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
2623// Otherwise, do not call pack_error_send().
b.liu87afc4c2024-08-14 17:33:45 +08002624static mbtk_ril_err_enum pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
b.liu571445f2025-02-13 10:22:55 +08002625{
b.liu87afc4c2024-08-14 17:33:45 +08002626 if(pack->msg_id > RIL_MSG_ID_DEV_BEGIN && pack->msg_id < RIL_MSG_ID_DEV_END) {
2627 return dev_pack_req_process(cli_info, pack);
2628 } else if(pack->msg_id > RIL_MSG_ID_SIM_BEGIN && pack->msg_id < RIL_MSG_ID_SIM_END) {
2629 return sim_pack_req_process(cli_info, pack);
2630 } else if(pack->msg_id > RIL_MSG_ID_NET_BEGIN && pack->msg_id < RIL_MSG_ID_NET_END) {
2631 return net_pack_req_process(cli_info, pack);
b.liu15f456b2024-10-31 20:16:06 +08002632 } else if(pack->msg_id > RIL_MSG_ID_DATA_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_DATA_CALL_END) {
2633 return data_call_pack_req_process(cli_info, pack);
b.liu87afc4c2024-08-14 17:33:45 +08002634 } else if(pack->msg_id > RIL_MSG_ID_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_CALL_END) {
2635 return call_pack_req_process(cli_info, pack);
2636 } else if(pack->msg_id > RIL_MSG_ID_SMS_BEGIN && pack->msg_id < RIL_MSG_ID_SMS_END) {
2637 return sms_pack_req_process(cli_info, pack);
2638 } else if(pack->msg_id > RIL_MSG_ID_PB_BEGIN && pack->msg_id < RIL_MSG_ID_PB_END) {
2639 return pb_pack_req_process(cli_info, pack);
b.liu15f456b2024-10-31 20:16:06 +08002640 } else if(pack->msg_id > RIL_MSG_ID_ECALL_BEGIN && pack->msg_id < RIL_MSG_ID_ECALL_END) {
2641 return ecall_pack_req_process(cli_info, pack);
b.liu87afc4c2024-08-14 17:33:45 +08002642 } else {
2643 LOGW("Unknown msg id : %d", pack->msg_id);
2644 return MBTK_RIL_ERR_FORMAT;
2645 }
2646}
2647
2648static void urc_msg_process(ril_urc_msg_info_t *msg)
b.liu571445f2025-02-13 10:22:55 +08002649{
b.liu472cfaf2024-12-19 19:08:19 +08002650 // data can be NULL (For RIL_URC_MSG_BAND_SET)
b.liu15f456b2024-10-31 20:16:06 +08002651 if(!msg->data || msg->data_len <= 0) {
b.liu472cfaf2024-12-19 19:08:19 +08002652 LOGW("URC data is NULL.");
2653 // return;
b.liu15f456b2024-10-31 20:16:06 +08002654 }
2655
b.liu571445f2025-02-13 10:22:55 +08002656 switch(msg->msg) {
b.liu15f456b2024-10-31 20:16:06 +08002657 case RIL_MSG_ID_IND_RADIO_STATE_CHANGE:
2658 {
2659 mbtk_ril_radio_state_info_t *state = (mbtk_ril_radio_state_info_t*)msg->data;
2660 LOGD("Radio state : %d", state->radio_state);
b.liu571445f2025-02-13 10:22:55 +08002661 break;
b.liu15f456b2024-10-31 20:16:06 +08002662 }
b.liufd87baf2024-11-15 15:30:38 +08002663 case RIL_MSG_ID_IND_SIM_STATE_CHANGE:
2664 {
2665 mbtk_ril_sim_state_info_t *state = (mbtk_ril_sim_state_info_t*)msg->data;
2666 if(state->sim_state == MBTK_SIM_STATE_READY) {
2667 LOGD("SIM READY!");
2668 at_send_command(ATPORTTYPE_0, "AT+COPS=3", NULL);
2669
2670 // Set APN from prop.
b.liu7ca612c2025-04-25 09:23:36 +08002671 apn_auto_conf_from_prop(state->sim_id, ATPORTTYPE_0);
b.liufd87baf2024-11-15 15:30:38 +08002672 }
2673 }
b.liuafdf2c62024-11-12 11:10:44 +08002674 case RIL_MSG_ID_IND_NET_REG_STATE_CHANGE:
2675 {
2676 mbtk_ril_net_reg_state_info_t *reg_state = (mbtk_ril_net_reg_state_info_t*)msg->data;
b.liu7ca612c2025-04-25 09:23:36 +08002677 data_call_retry(reg_state->sim_id, ATPORTTYPE_0, reg_state);
b.liuafdf2c62024-11-12 11:10:44 +08002678 break;
2679 }
b.liu472cfaf2024-12-19 19:08:19 +08002680 case RIL_URC_MSG_BAND_SET:
2681 {
2682 int cme_err = MBTK_RIL_ERR_CME_NON;
b.liu7ca612c2025-04-25 09:23:36 +08002683 if(req_band_set(MBTK_SIM_1, ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu472cfaf2024-12-19 19:08:19 +08002684 {
b.liu7ca612c2025-04-25 09:23:36 +08002685 LOGE("Set SIM1 band fail.");
b.liu472cfaf2024-12-19 19:08:19 +08002686 }
2687 else // Set band success.
2688 {
b.liu7ca612c2025-04-25 09:23:36 +08002689 LOGD("Set SIM1 band success.");
2690 cme_err = MBTK_RIL_ERR_CME_NON;
2691 if(req_band_set(MBTK_SIM_2, ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2692 {
2693 LOGE("Set SIM2 band fail.");
b.liu472cfaf2024-12-19 19:08:19 +08002694 }
b.liu7ca612c2025-04-25 09:23:36 +08002695 else // Set band success.
2696 {
2697 LOGD("Set SIM2 band success.");
2698 // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));
2699 band_info.band_set_success = TRUE;
2700 if(band_info.band_area == MBTK_MODEM_BAND_AREA_CN) {
2701 property_set("persist.mbtk.band_config", "CN");
2702 } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_EU) {
2703 property_set("persist.mbtk.band_config", "EU");
2704 } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_SA) {
2705 property_set("persist.mbtk.band_config", "SA");
2706 } else {
2707 property_set("persist.mbtk.band_config", "ALL");
2708 }
2709 }
b.liu472cfaf2024-12-19 19:08:19 +08002710 }
2711 break;
2712 }
b.liu571445f2025-02-13 10:22:55 +08002713 default:
2714 {
2715 LOGE("Unknown URC : %d", msg->msg);
2716 break;
2717 }
2718 }
b.liu87afc4c2024-08-14 17:33:45 +08002719}
2720
2721// Read client conn/msg and push into ril_info.msg_queue.
2722static void* ril_read_pthread(void* arg)
b.liu571445f2025-02-13 10:22:55 +08002723{
2724 UNUSED(arg);
b.liu87afc4c2024-08-14 17:33:45 +08002725 ril_info.epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1);
2726 if(ril_info.epoll_fd < 0)
b.liu571445f2025-02-13 10:22:55 +08002727 {
b.liu87afc4c2024-08-14 17:33:45 +08002728 LOGE("epoll_create() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08002729 return NULL;
2730 }
2731
2732 uint32 event = EPOLLIN | EPOLLET;
2733 struct epoll_event ev;
b.liu87afc4c2024-08-14 17:33:45 +08002734 ev.data.fd = ril_info.sock_listen_fd;
b.liu571445f2025-02-13 10:22:55 +08002735 ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
b.liu87afc4c2024-08-14 17:33:45 +08002736 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, ril_info.sock_listen_fd, &ev);
b.liu571445f2025-02-13 10:22:55 +08002737
2738 int nready = -1;
2739 struct epoll_event epoll_events[EPOLL_LISTEN_MAX];
2740 while(1)
2741 {
b.liu87afc4c2024-08-14 17:33:45 +08002742 nready = epoll_wait(ril_info.epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
b.liu571445f2025-02-13 10:22:55 +08002743 if(nready > 0)
2744 {
b.liu87afc4c2024-08-14 17:33:45 +08002745 sock_cli_info_t *cli_info = NULL;
b.liu571445f2025-02-13 10:22:55 +08002746 int i;
2747 for(i = 0; i < nready; i++)
2748 {
2749 LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events);
2750 if(epoll_events[i].events & EPOLLHUP) // Client Close.
2751 {
2752 if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL)
2753 {
2754 cli_close(cli_info);
2755 }
2756 else
2757 {
2758 LOG("Unknown client[fd = %d].", epoll_events[i].data.fd);
2759 }
2760 }
2761 else if(epoll_events[i].events & EPOLLIN)
2762 {
b.liu87afc4c2024-08-14 17:33:45 +08002763 if(epoll_events[i].data.fd == ril_info.sock_listen_fd) // New clients connected.
b.liu571445f2025-02-13 10:22:55 +08002764 {
2765 int client_fd = -1;
2766 while(1)
2767 {
2768 struct sockaddr_in cliaddr;
2769 socklen_t clilen = sizeof(cliaddr);
2770 client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen);
2771 if(client_fd < 0)
2772 {
2773 if(errno == EAGAIN)
2774 {
2775 LOG("All client connect get.");
2776 }
2777 else
2778 {
2779 LOG("accept() error[%d].", errno);
2780 }
2781 break;
2782 }
2783 // Set O_NONBLOCK
2784 int flags = fcntl(client_fd, F_GETFL, 0);
2785 if (flags > 0)
2786 {
2787 flags |= O_NONBLOCK;
2788 if (fcntl(client_fd, F_SETFL, flags) < 0)
2789 {
2790 LOG("Set flags error:%d", errno);
2791 }
2792 }
2793
2794 memset(&ev,0,sizeof(struct epoll_event));
2795 ev.data.fd = client_fd;
2796 ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET;
b.liu87afc4c2024-08-14 17:33:45 +08002797 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, client_fd, &ev);
b.liu571445f2025-02-13 10:22:55 +08002798
b.liu87afc4c2024-08-14 17:33:45 +08002799 sock_cli_info_t *info = (sock_cli_info_t*)malloc(sizeof(sock_cli_info_t));
b.liu571445f2025-02-13 10:22:55 +08002800 if(info)
2801 {
b.liu87afc4c2024-08-14 17:33:45 +08002802 memset(info, 0, sizeof(sock_cli_info_t));
2803 info->fd = client_fd;
b.liub171c9a2024-11-12 19:23:29 +08002804
2805 // Default AT port.
2806 info->port = ATPORTTYPE_0;
b.liu7ca612c2025-04-25 09:23:36 +08002807 info->sim_id = MBTK_SIM_1;
b.liub171c9a2024-11-12 19:23:29 +08002808
b.liu87afc4c2024-08-14 17:33:45 +08002809 list_add(ril_info.sock_client_list, info);
2810 LOG("Add New Client FD Into List.");
2811
b.liu15f456b2024-10-31 20:16:06 +08002812 // Send msg RIL_MSG_ID_IND_SER_STATE_CHANGE to client.
2813 mbtk_ril_ser_state_enum state = MBTK_RIL_SER_STATE_READY;
b.liu7ca612c2025-04-25 09:23:36 +08002814 ril_ind_pack_send(MBTK_SIM_1, client_fd, RIL_MSG_ID_IND_SER_STATE_CHANGE, &state, 1);
b.liu571445f2025-02-13 10:22:55 +08002815 }
2816 else
2817 {
2818 LOG("malloc() fail.");
2819 }
2820 }
2821 }
2822 else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive.
2823 {
2824 // Read and process every message.
b.liu87afc4c2024-08-14 17:33:45 +08002825 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
2826 ril_msg_pack_info_t** pack = ril_pack_recv(cli_info->fd, true, &err);
b.liub171c9a2024-11-12 19:23:29 +08002827
b.liu571445f2025-02-13 10:22:55 +08002828 // Parse packet error,send error response to client.
2829 if(pack == NULL)
2830 {
b.liu7ca612c2025-04-25 09:23:36 +08002831 ril_error_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, RIL_MSG_ID_UNKNOWN, RIL_MSG_INDEX_INVALID, err);
b.liu571445f2025-02-13 10:22:55 +08002832 }
2833 else
2834 {
b.liu87afc4c2024-08-14 17:33:45 +08002835 ril_msg_pack_info_t** pack_ptr = pack;
b.liu571445f2025-02-13 10:22:55 +08002836 while(*pack_ptr)
b.liub171c9a2024-11-12 19:23:29 +08002837 {
2838 // Update AT port in the first.
2839 cli_info->port = (ATPortType_enum)((*pack_ptr)->at_port);
b.liu7ca612c2025-04-25 09:23:36 +08002840 cli_info->sim_id = (mbtk_sim_type_enum)((*pack_ptr)->sim_id);
2841 if(cli_info->sim_id == MBTK_SIM_AUTO) {
2842 cli_info->sim_id = ril_info.cur_sim_id;
2843 LOGD("Auto sim => %d", cli_info->sim_id);
2844 }
b.liub171c9a2024-11-12 19:23:29 +08002845
b.liu571445f2025-02-13 10:22:55 +08002846 pack_distribute(cli_info, *pack_ptr);
2847 // Not free,will free in pack_process() or packet process thread.
2848 //mbtk_info_pack_free(pack_ptr);
2849 pack_ptr++;
2850 }
2851
2852 free(pack);
2853 }
2854 }
2855 else
2856 {
2857 LOG("Unknown socket : %d", epoll_events[i].data.fd);
2858 }
2859 }
2860 else
2861 {
2862 LOG("Unknown event : %x", epoll_events[i].events);
2863 }
2864 }
2865 }
2866 else
2867 {
2868 LOG("epoll_wait() fail[%d].", errno);
2869 }
2870 }
2871
2872 return NULL;
b.liu87afc4c2024-08-14 17:33:45 +08002873}
2874
b.liubeb61cc2025-02-13 10:38:29 +08002875static void band_support_init()
2876{
2877 mbtk_device_info_modem_t info_modem;
2878 memset(&band_info.band_support, 0, sizeof(mbtk_band_info_t));
2879 memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
b.liubeb61cc2025-02-13 10:38:29 +08002880 if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
2881 LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
2882 band_info.band_area = MBTK_MODEM_BAND_AREA_ALL;
2883#ifdef MBTK_5G_SUPPORT
2884 band_info.band_support.net_pref = MBTK_NET_PREF_LTE_NR_NR_PREF; // 19
2885 band_info.net_support = MBTK_NET_SUPPORT_4G | MBTK_NET_SUPPORT_5G;
2886
2887 band_info.band_support.gsm_band = 0;
2888 band_info.band_support.umts_band = 0;
2889 band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
2890 band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
2891 band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
2892
2893 band_info.band_support.nr_3_band = MBTK_BAND_ALL_NR_3_DEFAULT;
2894 band_info.band_support.nr_2_band = MBTK_BAND_ALL_NR_2_DEFAULT;
2895 band_info.band_support.nr_1_band = MBTK_BAND_ALL_NR_1_DEFAULT;
2896 band_info.band_support.nr_0_band = MBTK_BAND_ALL_NR_0_DEFAULT;
2897#else
2898 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
2899 band_info.net_support = MBTK_NET_SUPPORT_2G | MBTK_NET_SUPPORT_3G | MBTK_NET_SUPPORT_4G;
2900
2901 band_info.band_support.gsm_band = MBTK_BAND_ALL_GSM_DEFAULT;
2902 band_info.band_support.umts_band = MBTK_BAND_ALL_WCDMA_DEFAULT;
2903 band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
2904 band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
2905 band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
2906
2907 band_info.band_support.nr_3_band = 0;
2908 band_info.band_support.nr_2_band = 0;
2909 band_info.band_support.nr_1_band = 0;
2910 band_info.band_support.nr_0_band = 0;
2911#endif
2912 } else {
b.liub7530d22025-06-16 19:49:05 +08002913 if(info_modem.version == DEV_INFO_VERSION_V1) {
2914 band_info.band_area = info_modem.modem.v1.band_area;
2915 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
2916 band_info.band_support.gsm_band = info_modem.modem.v1.band_gsm;
2917 band_info.band_support.umts_band = info_modem.modem.v1.band_wcdma;
2918 band_info.band_support.tdlte_band = info_modem.modem.v1.band_tdlte;
2919 band_info.band_support.fddlte_band = info_modem.modem.v1.band_fddlte;
2920 band_info.band_support.lte_ext_band = info_modem.modem.v1.band_lte_ext;
b.liubeb61cc2025-02-13 10:38:29 +08002921 } else {
b.liub7530d22025-06-16 19:49:05 +08002922 band_info.band_area = info_modem.modem.v2.band_area;
2923 band_info.net_support = info_modem.modem.v2.net_support;
2924 if(info_modem.modem.v2.net_pref < MBTK_NET_PREF_MAX) {
2925 band_info.band_support.net_pref = info_modem.modem.v2.net_pref;
b.liubeb61cc2025-02-13 10:38:29 +08002926 } else {
b.liub7530d22025-06-16 19:49:05 +08002927 if(band_info.net_support & MBTK_NET_SUPPORT_5G) {
2928 band_info.band_support.net_pref = MBTK_NET_PREF_LTE_NR_NR_PREF; // 19
2929 } else {
2930 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
2931 }
b.liubeb61cc2025-02-13 10:38:29 +08002932 }
b.liub7530d22025-06-16 19:49:05 +08002933 band_info.band_support.gsm_band = info_modem.modem.v2.band_gsm;
2934 band_info.band_support.umts_band = info_modem.modem.v2.band_wcdma;
2935 band_info.band_support.tdlte_band = info_modem.modem.v2.band_tdlte;
2936 band_info.band_support.fddlte_band = info_modem.modem.v2.band_fddlte;
2937 band_info.band_support.lte_ext_band = info_modem.modem.v2.band_lte_ext;
b.liubeb61cc2025-02-13 10:38:29 +08002938
b.liub7530d22025-06-16 19:49:05 +08002939 band_info.band_support.nr_3_band = info_modem.modem.v2.band_nr_3;
2940 band_info.band_support.nr_2_band = info_modem.modem.v2.band_nr_2;
2941 band_info.band_support.nr_1_band = info_modem.modem.v2.band_nr_1;
2942 band_info.band_support.nr_0_band = info_modem.modem.v2.band_nr_0;
2943 }
b.liubeb61cc2025-02-13 10:38:29 +08002944 }
b.liubeb61cc2025-02-13 10:38:29 +08002945}
2946
b.liu571445f2025-02-13 10:22:55 +08002947static void* ril_process_thread(void* arg)
2948{
2949 UNUSED(arg);
2950 ATPortType_enum *port = (ATPortType_enum*)arg;
2951 ril_msg_queue_info_t* item = NULL;
2952
2953 pthread_mutex_lock(&(ril_info.msg_mutex[*port]));
2954 while(TRUE)
2955 {
2956 if(mbtk_queue_empty(&(ril_info.msg_queue[*port])))
2957 {
2958 LOG("[Port-%d]Packet process wait...", *port);
2959 pthread_cond_wait(&(ril_info.msg_cond[*port]), &(ril_info.msg_mutex[*port]));
2960 LOG("[Port-%d]Packet process continue...", *port);
2961 }
2962 else
2963 {
2964 LOG("Packet process queue not empty,continue...");
2965 }
2966
2967 // Process all information request.
2968 mbtk_ril_err_enum err;
2969 while((item = (ril_msg_queue_info_t*)mbtk_queue_get(&(ril_info.msg_queue[*port]))) != NULL)
2970 {
2971 if(item->cli_info) { // REQ form client.
2972 ril_msg_pack_info_t *pack = (ril_msg_pack_info_t*)item->pack;
2973 LOGD("Process REQ %s.", id2str(pack->msg_id));
2974 ril_info.at_process[*port] = true;
2975 err = pack_req_process(item->cli_info, pack);
2976 if(err != MBTK_RIL_ERR_SUCCESS)
2977 {
b.liu7ca612c2025-04-25 09:23:36 +08002978 ril_error_pack_send(item->cli_info->sim_id, item->cli_info->port, item->cli_info->fd, pack->msg_id, pack->msg_index, err);
b.liu571445f2025-02-13 10:22:55 +08002979 }
2980 ril_info.at_process[*port] = false;
2981 ril_msg_pack_free(pack);
2982 free(item);
2983 } else { // REQ from myself.
2984 if(item->pack) {
2985 ril_urc_msg_info_t *urc = (ril_urc_msg_info_t*)item->pack;
2986 LOGD("Process URC %d.", urc->msg);
2987 urc_msg_process(urc);
2988 if(urc->data)
2989 free(urc->data);
2990 free(urc);
2991 }
2992 }
2993 }
2994 }
2995 pthread_mutex_unlock(&(ril_info.msg_mutex[*port]));
2996
2997 free(port);
2998
2999 return NULL;
3000}
3001
3002/*
3003AT*BAND=15,78,147,482,134742231
3004
3005OK
3006*/
3007static void* band_config_thread()
3008{
b.liu571445f2025-02-13 10:22:55 +08003009 band_info.band_set_success = FALSE;
b.liu62240ee2024-11-07 17:52:45 +08003010// bool is_first = TRUE;
b.liu87afc4c2024-08-14 17:33:45 +08003011 while(!band_info.band_set_success) {
3012 // Set band.
b.liu472cfaf2024-12-19 19:08:19 +08003013#if 1
3014 ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
3015 if(msg) {
3016 msg->msg = RIL_URC_MSG_BAND_SET;
3017 msg->data = NULL;//mbtk_memcpy(&band_info, sizeof(ril_band_info_t));
3018 msg->data_len = 0; //sizeof(ril_band_info_t);
b.liu87afc4c2024-08-14 17:33:45 +08003019#if 0
b.liu571445f2025-02-13 10:22:55 +08003020 if(msg->data == NULL) {
3021 LOGE("mbtk_memcpy() fail.");
3022 break;
3023 }
b.liu472cfaf2024-12-19 19:08:19 +08003024#endif
3025 send_pack_to_queue(NULL, msg);
3026
b.liu571445f2025-02-13 10:22:55 +08003027 sleep(5);
b.liu472cfaf2024-12-19 19:08:19 +08003028 } else {
3029 LOG("malloc() fail[%d].", errno);
3030 break;
b.liu87afc4c2024-08-14 17:33:45 +08003031 }
3032#else
3033 sleep(5);
3034#endif
b.liu571445f2025-02-13 10:22:55 +08003035 }
3036
3037 LOGD("Set Band thread exit.");
3038 return NULL;
3039}
b.liu87afc4c2024-08-14 17:33:45 +08003040
3041
3042int ril_server_start()
b.liu571445f2025-02-13 10:22:55 +08003043{
b.liu87afc4c2024-08-14 17:33:45 +08003044 signal(SIGPIPE, SIG_IGN);
3045
3046 memset(&ril_info, 0, sizeof(ril_info_t));
3047 memset(&band_info, 0, sizeof(ril_band_info_t));
3048 memset(&band_info.band_support, 0xFF, sizeof(mbtk_band_info_t));
b.liu571445f2025-02-13 10:22:55 +08003049
3050 //check cfun and sim card status
3051 ril_at_ready_process();
b.liubeb61cc2025-02-13 10:38:29 +08003052
3053 // Init support band.
3054 band_support_init();
b.liu571445f2025-02-13 10:22:55 +08003055
3056 //any AT instruction that is not sent through pack_process_thread needs to precede the thread
3057 //thread create
b.liu87afc4c2024-08-14 17:33:45 +08003058 if(ril_info.sock_listen_fd > 0)
b.liu571445f2025-02-13 10:22:55 +08003059 {
b.liu87afc4c2024-08-14 17:33:45 +08003060 LOGE("Information Server Has Started.");
b.liu571445f2025-02-13 10:22:55 +08003061 return -1;
3062 }
3063
3064 struct sockaddr_un server_addr;
b.liu87afc4c2024-08-14 17:33:45 +08003065 ril_info.sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
3066 if(ril_info.sock_listen_fd < 0)
b.liu571445f2025-02-13 10:22:55 +08003067 {
b.liu87afc4c2024-08-14 17:33:45 +08003068 LOGE("socket() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08003069 return -1;
3070 }
3071
3072 // Set O_NONBLOCK
b.liu87afc4c2024-08-14 17:33:45 +08003073 int flags = fcntl(ril_info.sock_listen_fd, F_GETFL, 0);
b.liu571445f2025-02-13 10:22:55 +08003074 if (flags < 0)
3075 {
b.liu87afc4c2024-08-14 17:33:45 +08003076 LOGE("Get flags error:%d", errno);
b.liu571445f2025-02-13 10:22:55 +08003077 goto error;
3078 }
3079 flags |= O_NONBLOCK;
b.liu87afc4c2024-08-14 17:33:45 +08003080 if (fcntl(ril_info.sock_listen_fd, F_SETFL, flags) < 0)
b.liu571445f2025-02-13 10:22:55 +08003081 {
b.liu87afc4c2024-08-14 17:33:45 +08003082 LOGE("Set flags error:%d", errno);
b.liu571445f2025-02-13 10:22:55 +08003083 goto error;
3084 }
3085
b.liu87afc4c2024-08-14 17:33:45 +08003086 unlink(RIL_SOCK_NAME);
b.liu571445f2025-02-13 10:22:55 +08003087 memset(&server_addr, 0, sizeof(struct sockaddr_un));
3088 server_addr.sun_family = AF_LOCAL;
b.liu87afc4c2024-08-14 17:33:45 +08003089 strcpy(server_addr.sun_path, RIL_SOCK_NAME);
3090 if(bind(ril_info.sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)))
b.liu571445f2025-02-13 10:22:55 +08003091 {
b.liu87afc4c2024-08-14 17:33:45 +08003092 LOGE("bind() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08003093 goto error;
3094 }
3095
b.liu87afc4c2024-08-14 17:33:45 +08003096 if(listen(ril_info.sock_listen_fd, SOCK_CLIENT_MAX))
b.liu571445f2025-02-13 10:22:55 +08003097 {
b.liu87afc4c2024-08-14 17:33:45 +08003098 LOGE("listen() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08003099 goto error;
3100 }
3101
b.liu87afc4c2024-08-14 17:33:45 +08003102 ril_info.sock_client_list = list_create(sock_cli_free_func);
3103 if(ril_info.sock_client_list == NULL)
b.liu571445f2025-02-13 10:22:55 +08003104 {
b.liu87afc4c2024-08-14 17:33:45 +08003105 LOGE("list_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003106 goto error;
b.liu87afc4c2024-08-14 17:33:45 +08003107 }
3108
b.liub171c9a2024-11-12 19:23:29 +08003109 mbtk_queue_init(&(ril_info.msg_queue[ATPORTTYPE_0]));
3110 pthread_mutex_init(&(ril_info.msg_mutex[ATPORTTYPE_0]), NULL);
3111 pthread_cond_init(&(ril_info.msg_cond[ATPORTTYPE_0]), NULL);
b.liu571445f2025-02-13 10:22:55 +08003112
b.liu62240ee2024-11-07 17:52:45 +08003113 pthread_t info_pid, pack_pid/*, monitor_pid, urc_pid, bootconn_pid*/;
b.liu571445f2025-02-13 10:22:55 +08003114 pthread_attr_t thread_attr;
3115 pthread_attr_init(&thread_attr);
3116 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
3117 {
b.liu87afc4c2024-08-14 17:33:45 +08003118 LOGE("pthread_attr_setdetachstate() fail.");
b.liu571445f2025-02-13 10:22:55 +08003119 goto error;
3120 }
3121
b.liu87afc4c2024-08-14 17:33:45 +08003122 if(pthread_create(&info_pid, &thread_attr, ril_read_pthread, NULL))
b.liu571445f2025-02-13 10:22:55 +08003123 {
b.liu87afc4c2024-08-14 17:33:45 +08003124 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003125 goto error;
3126 }
b.liub171c9a2024-11-12 19:23:29 +08003127
3128 ATPortType_enum *port_0 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
b.liu7ca612c2025-04-25 09:23:36 +08003129 *port_0 = MBTK_AT_PORT_DEF;
b.liub171c9a2024-11-12 19:23:29 +08003130 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_0))
b.liu571445f2025-02-13 10:22:55 +08003131 {
b.liu87afc4c2024-08-14 17:33:45 +08003132 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003133 goto error;
b.liub171c9a2024-11-12 19:23:29 +08003134 }
3135
3136 ATPortType_enum *port_1 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
b.liu7ca612c2025-04-25 09:23:36 +08003137 *port_1 = MBTK_AT_PORT_VOICE;
b.liub171c9a2024-11-12 19:23:29 +08003138 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_1))
b.liu571445f2025-02-13 10:22:55 +08003139 {
b.liub171c9a2024-11-12 19:23:29 +08003140 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003141 goto error;
b.liub171c9a2024-11-12 19:23:29 +08003142 }
b.liufd87baf2024-11-15 15:30:38 +08003143
b.liu61eedc92024-11-13 16:07:00 +08003144 ATPortType_enum *port_2 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
b.liu7ca612c2025-04-25 09:23:36 +08003145 *port_2 = MBTK_AT_PORT_DATA;
b.liu61eedc92024-11-13 16:07:00 +08003146 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_2))
b.liu571445f2025-02-13 10:22:55 +08003147 {
b.liu61eedc92024-11-13 16:07:00 +08003148 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003149 goto error;
b.liu61eedc92024-11-13 16:07:00 +08003150 }
b.liu571445f2025-02-13 10:22:55 +08003151
3152 // Set Band
3153 // AT*BAND=15,78,147,482,134742231
3154 char buff[10];
3155 memset(buff, 0, 10);
3156 property_get("persist.mbtk.band_config", buff, "");
3157 if(strlen(buff) == 0) {
3158 pthread_t band_pid;
3159 if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL))
3160 {
b.liu87afc4c2024-08-14 17:33:45 +08003161 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003162 }
3163 }
3164
b.liufd87baf2024-11-15 15:30:38 +08003165 pthread_attr_destroy(&thread_attr);
3166
3167 if(asr_auto_data_call_enable()) {
3168 ril_cid_start = MBTK_RIL_CID_2;
3169
3170 char def_cid[10] = {0};
3171 char prop_data[100] = {0};
3172 int cid = -1;
3173 sprintf(def_cid, "%d", MBTK_RIL_CID_DEF); // Default route and DNS is CID 1.
3174 memset(prop_data, 0, sizeof(prop_data));
3175 if(property_get(MBTK_DEF_DNS_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
3176 cid = atoi(prop_data);
3177 }
3178
3179 if(cid == MBTK_RIL_CID_DEF) {
3180 if(file_link("/tmp/resolv.conf", "/etc/resolv.conf")) {
3181 LOGE("Create link file fail.");
3182 }
3183 }
3184 } else {
3185 ril_cid_start = MBTK_RIL_CID_DEF;
3186 }
b.liu571445f2025-02-13 10:22:55 +08003187
b.liufd87baf2024-11-15 15:30:38 +08003188 LOGD("MBTK Ril Server Start[CID start with : %d]...", ril_cid_start);
b.liu571445f2025-02-13 10:22:55 +08003189
3190 return 0;
b.liu87afc4c2024-08-14 17:33:45 +08003191error:
3192 if(ril_info.sock_client_list) {
3193 list_free(ril_info.sock_client_list);
3194 ril_info.sock_client_list = NULL;
3195 }
3196
3197 if(ril_info.sock_listen_fd > 0) {
3198 close(ril_info.sock_listen_fd);
3199 ril_info.sock_listen_fd = -1;
3200 }
b.liu571445f2025-02-13 10:22:55 +08003201 return -1;
b.liu87afc4c2024-08-14 17:33:45 +08003202}
3203
b.liu87afc4c2024-08-14 17:33:45 +08003204int main(int argc, char *argv[])
3205{
3206 mbtk_log_init("radio", "MBTK_RIL");
3207
b.liubcf86c92024-08-19 19:48:28 +08003208 MBTK_SOURCE_INFO_PRINT("mbtk_rild");
3209
b.liu87afc4c2024-08-14 17:33:45 +08003210#ifdef MBTK_DUMP_SUPPORT
3211 mbtk_debug_open(NULL, TRUE);
3212#endif
3213
3214// Using Killall,the file lock may be not release.
3215#if 0
3216 if(app_already_running(MBTK_RILD_PID_FILE)) {
3217 LOGW("daemon already running.");
3218 exit(1);
3219 }
3220#endif
3221
3222 LOGI("mbtk_rild start.");
3223
3224 if(InProduction_Mode()) {
3225 LOGI("Is Production Mode, will exit...");
3226 exit(0);
3227 }
3228
3229 ready_state_update();
3230
3231 int at_sock = openSocket("/tmp/atcmd_at");
3232 if(at_sock < 0)
3233 {
3234 LOGE("Open AT Socket Fail[%d].", errno);
3235 return -1;
3236 }
3237 int uart_sock = openSocket("/tmp/atcmd_urc");
3238 if(uart_sock < 0)
3239 {
3240 LOGE("Open Uart Socket Fail[%d].", errno);
3241 return -1;
3242 }
3243
b.liub171c9a2024-11-12 19:23:29 +08003244 int at_sock_1 = openSocket("/tmp/atcmd_at_1");
3245 if(at_sock_1 < 0)
b.liu87afc4c2024-08-14 17:33:45 +08003246 {
b.liub171c9a2024-11-12 19:23:29 +08003247 LOGE("Open AT Socket Fail[%d].", errno);
b.liu87afc4c2024-08-14 17:33:45 +08003248 return -1;
3249 }
3250
b.liu61eedc92024-11-13 16:07:00 +08003251 int at_sock_2 = openSocket("/tmp/atcmd_at_2");
3252 if(at_sock_2 < 0)
3253 {
3254 LOGE("Open AT Socket Fail[%d].", errno);
3255 return -1;
3256 }
3257
b.liu7ca612c2025-04-25 09:23:36 +08003258 int uart_sock1 = openSocket("/tmp/atcmd_urc1");
3259 if(uart_sock1 < 0)
3260 {
3261 LOGE("Open Uart Socket Fail[%d].", errno);
3262 return -1;
3263 }
3264
3265 int at_sock1 = openSocket("/tmp/atcmd_at1");
3266 if(at_sock1 < 0)
3267 {
3268 LOGE("Open AT Socket Fail[%d].", errno);
3269 return -1;
3270 }
3271
3272 int at_sock1_1 = openSocket("/tmp/atcmd_at1_1");
3273 if(at_sock1_1 < 0)
3274 {
3275 LOGE("Open AT Socket Fail[%d].", errno);
3276 return -1;
3277 }
3278
3279 int at_sock1_2 = openSocket("/tmp/atcmd_at1_2");
3280 if(at_sock1_2 < 0)
3281 {
3282 LOGE("Open AT Socket Fail[%d].", errno);
3283 return -1;
3284 }
3285
b.liub171c9a2024-11-12 19:23:29 +08003286 at_set_on_reader_closed(onATReaderClosed);
3287 at_set_on_timeout(onATTimeout);
3288
b.liu7ca612c2025-04-25 09:23:36 +08003289 if(at_open(ATPORTID_SIM1_0, at_sock, uart_sock, onUnsolicited1))
b.liub171c9a2024-11-12 19:23:29 +08003290 {
3291 LOGE("Start AT_0 thread fail.");
3292 return -1;
3293 }
3294
b.liu7ca612c2025-04-25 09:23:36 +08003295 if(at_open(ATPORTID_SIM1_1, at_sock_1, uart_sock, onUnsolicited1))
b.liub171c9a2024-11-12 19:23:29 +08003296 {
3297 LOGE("Start AT_1 thread fail.");
3298 return -1;
3299 }
3300
b.liu7ca612c2025-04-25 09:23:36 +08003301 if(at_open(ATPORTID_SIM1_2, at_sock_2, uart_sock, onUnsolicited1))
b.liu61eedc92024-11-13 16:07:00 +08003302 {
3303 LOGE("Start AT_1 thread fail.");
3304 return -1;
3305 }
3306
b.liu7ca612c2025-04-25 09:23:36 +08003307 if(at_handshake(ATPORTID_SIM1_0))
b.liu87afc4c2024-08-14 17:33:45 +08003308 {
b.liu7ca612c2025-04-25 09:23:36 +08003309 LOGE("SIM1 AT handshake fail.");
b.liu87afc4c2024-08-14 17:33:45 +08003310 return -1;
3311 }
3312
b.liu7ca612c2025-04-25 09:23:36 +08003313 LOGD("SIM1 AT OK.");
3314
3315 if(at_open(ATPORTID_SIM2_0, at_sock1, uart_sock1, onUnsolicited2))
3316 {
3317 LOGE("Start AT_0 thread fail.");
3318 return -1;
3319 }
3320
3321 if(at_open(ATPORTID_SIM2_1, at_sock1_1, uart_sock1, onUnsolicited2))
3322 {
3323 LOGE("Start AT_1 thread fail.");
3324 return -1;
3325 }
3326
3327 if(at_open(ATPORTID_SIM2_2, at_sock1_2, uart_sock1, onUnsolicited2))
3328 {
3329 LOGE("Start AT_1 thread fail.");
3330 return -1;
3331 }
3332
yq.wang3c5808d2025-05-08 17:39:19 +08003333 usleep(100 * 1000);
3334
b.liu7ca612c2025-04-25 09:23:36 +08003335 if(at_handshake(ATPORTID_SIM2_0))
3336 {
3337 LOGE("SIM2 AT handshake fail.");
3338 return -1;
3339 }
3340
3341 LOGD("SIM2 AT OK.");
b.liu87afc4c2024-08-14 17:33:45 +08003342
3343 if(ril_server_start())
3344 {
3345 LOGE("ril_server_start() fail.");
3346 return -1;
3347 }
3348
3349 mbtk_ril_ready();
3350
3351 while(1)
3352 {
3353 sleep(24 * 60 * 60);
3354 }
3355
3356 LOGD("!!!mbtk_ril exit!!!");
3357 return 0;
3358}