blob: 0447e255bfdd51db45a4372dab29a381c7fb9fbe [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"
hong.liu7d2fa902025-07-23 04:41:53 -070075#define MBTK_RILD_REQ_SLOT1_CHANNEL0 "/tmp/atcmd_at" //SIM 1 channel 0 request socket
76#define MBTK_RILD_REQ_SLOT1_CHANNEL1 "/tmp/atcmd_at_1" //SIM 1 channel 1 request socket
77#define MBTK_RILD_REQ_SLOT1_CHANNEL2 "/tmp/atcmd_at_2" //SIM 1 channel 2 request socket
78#define MBTK_RILD_URC_SLOT1 "/tmp/atcmd_urc" //SIM 1 unsolicite socket
79
80#define MBTK_RILD_REQ_SLOT2_CHANNEL0 "/tmp/atcmd_at1" //SIM 2 channel 0 request socket
81#define MBTK_RILD_REQ_SLOT2_CHANNEL1 "/tmp/atcmd_at1_2" //SIM 2 channel 1 request socket
82#define MBTK_RILD_REQ_SLOT2_CHANNEL2 "/tmp/atcmd_at2_2" //SIM 2 channel 2 request socket
83#define MBTK_RILD_URC_SLOT2 "/tmp/atcmd_urc1" //SIM 2 unsolicite socket
84
b.liu15f456b2024-10-31 20:16:06 +080085#define RIL_CALL_NUM_MAX 10
b.liu87afc4c2024-08-14 17:33:45 +080086
87static bool ril_net_ready = FALSE; // Only one time.
88static bool ril_server_ready = FALSE; // Only one time.
89ril_band_info_t band_info;
90ril_info_t ril_info;
b.liu15f456b2024-10-31 20:16:06 +080091static mbtk_ril_call_state_info_t call_list[RIL_CALL_NUM_MAX];
b.liuaced4f92024-12-31 11:14:51 +080092static bool cmt_found = FALSE;
hong.liu7d2fa902025-07-23 04:41:53 -070093//#define LYNQ_DSDS_SUPPORT 1
b.liuaced4f92024-12-31 11:14:51 +080094
b.liub4772072024-08-15 14:47:03 +080095extern mbtk_cell_pack_info_t cell_info;
b.liubcf86c92024-08-19 19:48:28 +080096extern ril_cgact_wait_t cgact_wait;
b.liufd87baf2024-11-15 15:30:38 +080097extern int ril_cid_start;
b.liu87afc4c2024-08-14 17:33:45 +080098
99// int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len);
100// int mbtk_signal_log(char *data);
101int InProduction_Mode(void);
102mbtk_ril_err_enum dev_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
103mbtk_ril_err_enum call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
104mbtk_ril_err_enum sim_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
105mbtk_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 +0800106mbtk_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 +0800107mbtk_ril_err_enum pb_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
108mbtk_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 +0800109mbtk_ril_err_enum ecall_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
110
b.liu7ca612c2025-04-25 09:23:36 +0800111void 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 +0800112
b.liu7ca612c2025-04-25 09:23:36 +0800113void 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 +0800114static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack);
b.liu7ca612c2025-04-25 09:23:36 +0800115int req_band_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t* band, int *cme_err);
116int req_dual_sim_get(ATPortType_enum port, mbtk_sim_type_enum *sim_id, int *cme_err);
117
118ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port)
119{
120 return (ATPortId_enum)(sim_id * ATPORTTYPE_NUM + port);
121}
b.liu87afc4c2024-08-14 17:33:45 +0800122
123/* Called on command thread */
124static void onATTimeout()
125{
126 LOGI("AT channel timeout; closing\n");
b.liu7ca612c2025-04-25 09:23:36 +0800127 at_close(ATPORTID_SIM1_0);
128 at_close(ATPORTID_SIM1_1);
129 at_close(ATPORTID_SIM1_2);
hong.liu7d2fa902025-07-23 04:41:53 -0700130#ifdef LYNQ_DSDS_SUPPORT
b.liu7ca612c2025-04-25 09:23:36 +0800131 at_close(ATPORTID_SIM2_0);
132 at_close(ATPORTID_SIM2_1);
133 at_close(ATPORTID_SIM2_2);
hong.liu7d2fa902025-07-23 04:41:53 -0700134#endif
b.liu87afc4c2024-08-14 17:33:45 +0800135}
136
137/* Called on command or reader thread */
138static void onATReaderClosed()
139{
140 LOGI("AT channel closed\n");
b.liu7ca612c2025-04-25 09:23:36 +0800141 at_close(ATPORTID_SIM1_0);
142 at_close(ATPORTID_SIM1_1);
143 at_close(ATPORTID_SIM1_2);
hong.liu7d2fa902025-07-23 04:41:53 -0700144#ifdef LYNQ_DSDS_SUPPORT
b.liu7ca612c2025-04-25 09:23:36 +0800145 at_close(ATPORTID_SIM2_0);
146 at_close(ATPORTID_SIM2_1);
147 at_close(ATPORTID_SIM2_2);
hong.liu7d2fa902025-07-23 04:41:53 -0700148#endif
b.liu87afc4c2024-08-14 17:33:45 +0800149}
150
b.liu571445f2025-02-13 10:22:55 +0800151static void sock_cli_free_func(void *data)
152{
153 if (data)
154 {
b.liu87afc4c2024-08-14 17:33:45 +0800155 sock_cli_info_t *info = (sock_cli_info_t*) data;
156 LOGD("Free Socket client[fd = %d].", info->fd);
b.liu571445f2025-02-13 10:22:55 +0800157 free(info);
158 }
b.liu87afc4c2024-08-14 17:33:45 +0800159}
160
b.liufd87baf2024-11-15 15:30:38 +0800161bool asr_auto_data_call_enable()
162{
163 /*
164 uci show wan_default.default.enable
165 wan_default.default.enable='1'
166
167 uci get wan_default.default.enable
168 1
169 */
170 char buff[128] = {0};
171 if(mbtk_cmd_line("uci get wan_default.default.enable", buff, sizeof(buff)) && strlen(buff) > 0) {
172 return buff[0] == '1' ? TRUE : FALSE;
173 } else {
174 return FALSE;
175 }
176}
177
b.liu87afc4c2024-08-14 17:33:45 +0800178/*
179* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
180*/
181static int net_ready_set()
182{
183 int ret = -1;
184 int fd = open(MBTK_RILD_FILE_NET_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
185 if(fd > 0) {
186 if(write(fd, "1", 1) == 1) {
187 ret = 0;
188 ril_net_ready = TRUE;
189 }
190 close(fd);
191 } else {
192 LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
193 }
194
195 return ret;
196}
197
198/*
199* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
200*/
201static int ser_ready_set()
202{
203 int ret = -1;
204 int fd = open(MBTK_RILD_FILE_SER_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
205 if(fd > 0) {
206 if(write(fd, "1", 1) == 1) {
207 ret = 0;
208 ril_server_ready = TRUE;
209 }
210 close(fd);
211 } else {
212 LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
213 }
214
215 return ret;
216}
217
218/*
219* Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
220*/
221static void ready_state_update()
222{
223 int fd = open(MBTK_RILD_FILE_NET_READY, O_RDONLY, 0644);
224 char buff[10];
225 if(fd > 0) {
226 if(read(fd, buff, sizeof(buff)) > 0) {
227 ril_net_ready = TRUE;
228 } else {
229 ril_net_ready = FALSE;
230 }
231
232 close(fd);
233 } else {
234 ril_net_ready = FALSE;
235 LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
236 }
237
238 fd = open(MBTK_RILD_FILE_SER_READY, O_RDONLY, 0644);
239 if(fd > 0) {
240 if(read(fd, buff, sizeof(buff)) > 0) {
241 ril_server_ready = TRUE;
242 } else {
243 ril_server_ready = FALSE;
244 }
245
246 close(fd);
247 } else {
248 ril_server_ready = FALSE;
249 LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
250 }
251}
252
253static void mbtk_net_ready()
254{
255 // /etc/init.d/mbtk_boot_net_ready
256 if(!ril_net_ready) {
257 if(access(MBTK_BOOT_NET_READY , X_OK) == 0) {
258 LOGD("Exec : %s", MBTK_BOOT_NET_READY);
b.liu62240ee2024-11-07 17:52:45 +0800259 mbtk_system(MBTK_BOOT_NET_READY);
b.liu87afc4c2024-08-14 17:33:45 +0800260 } else {
261 LOGE("%s can not exec.", MBTK_BOOT_NET_READY);
262 }
263 net_ready_set();
264 } else {
265 LOGD("No exec : %s", MBTK_BOOT_NET_READY);
266 }
267}
268
269static void mbtk_ril_ready()
270{
271 // /etc/init.d/mbtk_boot_server_ready
272 if(!ril_server_ready) {
273 if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
274 LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
b.liu62240ee2024-11-07 17:52:45 +0800275 mbtk_system(MBTK_BOOT_SERVER_READY);
b.liu87afc4c2024-08-14 17:33:45 +0800276 } else {
277 LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
278 }
279 ser_ready_set();
280 } else {
281 LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
282 }
283}
284
285static sock_cli_info_t* cli_find(int fd)
b.liu571445f2025-02-13 10:22:55 +0800286{
b.liu87afc4c2024-08-14 17:33:45 +0800287 sock_cli_info_t *result = NULL;
288 list_first(ril_info.sock_client_list);
289 while ((result = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
b.liu571445f2025-02-13 10:22:55 +0800290 {
291 if (result->fd == fd)
292 return result;
293 }
294
295 return NULL;
b.liu87afc4c2024-08-14 17:33:45 +0800296}
297
298static void cli_close(sock_cli_info_t* client)
b.liu571445f2025-02-13 10:22:55 +0800299{
300 struct epoll_event ev;
301 memset(&ev,0,sizeof(struct epoll_event));
302 ev.data.fd = client->fd;
303 ev.events = EPOLLIN | EPOLLERR | EPOLLET;
b.liu87afc4c2024-08-14 17:33:45 +0800304 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_DEL, client->fd, &ev);
b.liu571445f2025-02-13 10:22:55 +0800305
306 close(client->fd);
307
b.liu87afc4c2024-08-14 17:33:45 +0800308 if(list_remove(ril_info.sock_client_list, client))
b.liu571445f2025-02-13 10:22:55 +0800309 {
310 sock_cli_free_func(client);
311 }
312}
313
b.liu7ca612c2025-04-25 09:23:36 +0800314static 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 +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, NULL, 0);
b.liu571445f2025-02-13 10:22:55 +0800317 if(pack)
b.liu87afc4c2024-08-14 17:33:45 +0800318 {
319 pack->err = (uint16)err;
320 ril_pack_send(fd, pack);
321 ril_msg_pack_free(pack);
b.liu571445f2025-02-13 10:22:55 +0800322 }
323 else
324 {
b.liu87afc4c2024-08-14 17:33:45 +0800325 LOGW("ril_msg_pack_creat() fail.");
b.liu571445f2025-02-13 10:22:55 +0800326 }
327}
328
b.liu7ca612c2025-04-25 09:23:36 +0800329void 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 +0800330{
b.liu7ca612c2025-04-25 09:23:36 +0800331 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 +0800332 if(pack)
333 {
b.liu87afc4c2024-08-14 17:33:45 +0800334 pack->err = (uint16)MBTK_RIL_ERR_SUCCESS;
335#if 0
b.liu571445f2025-02-13 10:22:55 +0800336 if(data != NULL && data_len > 0)
337 {
338 pack->data_len = (uint16)data_len;
b.liu87afc4c2024-08-14 17:33:45 +0800339 pack->data = (uint8*)mbtk_memcpy(data, data_len);
340 }
341#endif
342 ril_pack_send(fd, pack);
343 ril_msg_pack_free(pack);
b.liu571445f2025-02-13 10:22:55 +0800344 }
345 else
346 {
b.liu87afc4c2024-08-14 17:33:45 +0800347 LOGW("ril_msg_pack_creat() fail.");
b.liu571445f2025-02-13 10:22:55 +0800348 }
b.liu87afc4c2024-08-14 17:33:45 +0800349}
350
b.liu7ca612c2025-04-25 09:23:36 +0800351void 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 +0800352{
b.liu7ca612c2025-04-25 09:23:36 +0800353 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 +0800354 if(pack)
355 {
b.liu87afc4c2024-08-14 17:33:45 +0800356 pack->err = (uint16)0;
357#if 0
b.liu571445f2025-02-13 10:22:55 +0800358 if(data != NULL && data_len > 0)
359 {
360 pack->data_len = (uint16)data_len;
b.liu87afc4c2024-08-14 17:33:45 +0800361 pack->data = (uint8*)mbtk_memcpy(data, data_len);
362 }
363#endif
364 ril_pack_send(fd, pack);
365 ril_msg_pack_free(pack);
b.liu571445f2025-02-13 10:22:55 +0800366 }
367 else
368 {
b.liu87afc4c2024-08-14 17:33:45 +0800369 LOGW("ril_msg_pack_creat() fail.");
b.liu571445f2025-02-13 10:22:55 +0800370 }
b.liu87afc4c2024-08-14 17:33:45 +0800371}
372
b.liufd87baf2024-11-15 15:30:38 +0800373void ril_state_change(ril_msg_id_enum msg_id, const void *data, int data_len)
b.liu571445f2025-02-13 10:22:55 +0800374{
b.liu15f456b2024-10-31 20:16:06 +0800375 sock_cli_info_t *cli = NULL;
376 list_first(ril_info.sock_client_list);
377 while ((cli = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
b.liu571445f2025-02-13 10:22:55 +0800378 {
379 if(cli->ind_num > 0) {
380 int i;
381 for(i = 0; i < IND_REGISTER_MAX; i++) {
b.liu15f456b2024-10-31 20:16:06 +0800382 if(cli->ind_register[i] == msg_id) {
b.liu7ca612c2025-04-25 09:23:36 +0800383 ril_ind_pack_send(MBTK_SIM_1, cli->fd, msg_id, data, data_len);
b.liu571445f2025-02-13 10:22:55 +0800384 break;
385 }
386 }
387 }
388 }
b.liu15f456b2024-10-31 20:16:06 +0800389}
390
b.liu9e8584b2024-11-06 19:21:28 +0800391static 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 +0800392{
393 // Send urc msg to client.
394 if(msg_id > RIL_MSG_ID_IND_BEGIN && msg_id < RIL_MSG_ID_IND_END) {
b.liufd87baf2024-11-15 15:30:38 +0800395 if(msg_id == RIL_MSG_ID_IND_PDP_STATE_CHANGE) {
396 mbtk_ril_pdp_state_info_t *info = (mbtk_ril_pdp_state_info_t*)data;
397 if(info->action && !info->ip_info_valid) {
398 LOGD("PDP action but no IP information, not send.");
399 } else {
400 ril_state_change(msg_id, data, data_len);
401 }
402 } else {
403 ril_state_change(msg_id, data, data_len);
404 }
b.liu15f456b2024-10-31 20:16:06 +0800405 }
406
407 // Async process urc msg.
b.liu571445f2025-02-13 10:22:55 +0800408 if(async_process) {
b.liu15f456b2024-10-31 20:16:06 +0800409 ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
410 if(msg) {
411 msg->msg = msg_id;
412 msg->data = mbtk_memcpy(data, data_len);
413 msg->data_len = data_len;
414 if(msg->data == NULL) {
415 LOGE("mbtk_memcpy() fail.");
416 return -1;
417 }
418
419 return send_pack_to_queue(NULL, msg);
420 } else {
421 LOGE("malloc() fail.");
422 return -1;
423 }
424 }
425
426 return 0;
427}
428
429// *SIMDETEC:1,SIM
430// *EUICC:1
431// +CPIN: SIM PIN
b.liu7ca612c2025-04-25 09:23:36 +0800432static 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 +0800433{
434 mbtk_ril_sim_state_info_t state;
435 memset(&state, 0, sizeof(mbtk_ril_sim_state_info_t));
436 state.sim_type = MBTK_UNKNOWN;
b.liu7ca612c2025-04-25 09:23:36 +0800437 state.sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800438
b.liufd87baf2024-11-15 15:30:38 +0800439 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800440 char *line = tmp_s;
441 int tmp_int;
442 char *tmp_str;
443
444 if(strStartsWith(s, "*SIMDETEC:")) {
445 if (at_tok_start(&line) < 0)
446 {
447 goto SIM_STATE_EXIT;
448 }
449 if (at_tok_nextint(&line, &tmp_int) < 0)
450 {
451 goto SIM_STATE_EXIT;
452 }
453 if (at_tok_nextstr(&line, &tmp_str) < 0)
454 {
455 goto SIM_STATE_EXIT;
456 }
457
458 if(tmp_str) {
459 if(strcmp(tmp_str, "NOS") == 0) {
b.liu7ca612c2025-04-25 09:23:36 +0800460 state.sim_type = ril_info.sim_type[sim_id];
b.liu15f456b2024-10-31 20:16:06 +0800461 state.sim_state = MBTK_SIM_STATE_ABSENT;
b.liu7ca612c2025-04-25 09:23:36 +0800462 ril_info.sim_state[sim_id] = MBTK_SIM_STATE_ABSENT;
b.liu15f456b2024-10-31 20:16:06 +0800463 urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
464 } else if(strcmp(tmp_str, "SIM") == 0) {
b.liu7ca612c2025-04-25 09:23:36 +0800465 state.sim_type = ril_info.sim_type[sim_id];
b.liu15f456b2024-10-31 20:16:06 +0800466 state.sim_state = MBTK_SIM_STATE_NOT_READY;
b.liu7ca612c2025-04-25 09:23:36 +0800467 ril_info.sim_state[sim_id] = MBTK_SIM_STATE_NOT_READY;
b.liu15f456b2024-10-31 20:16:06 +0800468 urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
469 }
470 }
471 } else if(strStartsWith(s, "+CPIN:")){
472 if(strStartsWith(s, "+CPIN: READY"))
473 {
474 state.sim_state = MBTK_SIM_STATE_READY;
475 }
476 else if(strStartsWith(s, "+CPIN: SIM PIN"))
477 {
478 state.sim_state = MBTK_SIM_STATE_SIM_PIN;
479 }
480 else if(strStartsWith(s, "+CPIN: SIM PUK"))
481 {
482 state.sim_state = MBTK_SIM_STATE_SIM_PUK;
483 }
484 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
485 {
486 state.sim_state = MBTK_SIM_STATE_PH_SIMLOCK_PIN;
487 }
488 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
489 {
490 state.sim_state = MBTK_SIM_STATE_PH_SIMLOCK_PUK;
491 }
492 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
493 {
494 state.sim_state = MBTK_SIM_STATE_PH_FSIM_PIN;
495 }
496 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
497 {
498 state.sim_state = MBTK_SIM_STATE_PH_FSIM_PUK;
499 }
500 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
501 {
502 state.sim_state = MBTK_SIM_STATE_SIM_PIN2;
503 }
504 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
505 {
506 state.sim_state = MBTK_SIM_STATE_SIM_PUK2;
507 }
508 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
509 {
510 state.sim_state = MBTK_SIM_STATE_PH_NET_PIN;
511 }
512 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
513 {
514 state.sim_state = MBTK_SIM_STATE_PH_NET_PUK;
515 }
516 else if(strStartsWith(s, "+CPIN: PH-NETSUB PIN"))
517 {
518 state.sim_state = MBTK_SIM_STATE_PH_NETSUB_PIN;
519 }
520 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
521 {
522 state.sim_state = MBTK_SIM_STATE_PH_NETSUB_PUK;
523 }
524 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
525 {
526 state.sim_state = MBTK_SIM_STATE_PH_SP_PIN;
527 }
528 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
529 {
530 state.sim_state = MBTK_SIM_STATE_PH_SP_PUK;
531 }
532 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
533 {
534 state.sim_state = MBTK_SIM_STATE_PH_CORP_PIN;
535 }
536 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
537 {
538 state.sim_state = MBTK_SIM_STATE_PH_CORP_PUK;
539 }
540 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
541 {
542 state.sim_state = MBTK_SIM_STATE_ABSENT;
543 }
544
b.liu7ca612c2025-04-25 09:23:36 +0800545 state.sim_type = ril_info.sim_type[sim_id];
546 ril_info.sim_state[sim_id] = state.sim_state;
b.liu15f456b2024-10-31 20:16:06 +0800547
b.liufd87baf2024-11-15 15:30:38 +0800548 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 +0800549 } else if(strStartsWith(s, "*EUICC:")){
550 if (at_tok_start(&line) < 0)
551 {
552 goto SIM_STATE_EXIT;
553 }
554 if (at_tok_nextint(&line, &tmp_int) < 0)
555 {
556 goto SIM_STATE_EXIT;
557 }
b.liu7ca612c2025-04-25 09:23:36 +0800558 ril_info.sim_type[sim_id] = (mbtk_sim_card_type_enum)tmp_int;
b.liu15f456b2024-10-31 20:16:06 +0800559 } else {
560 LOGW("Unknown URC.");
561 }
562
563SIM_STATE_EXIT:
564 free(tmp_s);
565}
566
567// +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
568// +CALLDISCONNECT: 1
569// +CPAS: 4
b.liu7ca612c2025-04-25 09:23:36 +0800570static 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 +0800571{
b.liufd87baf2024-11-15 15:30:38 +0800572 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800573 char *line = tmp_s;
574 int tmp_int;
575 char *tmp_str;
576
577 if(strStartsWith(s, "+CLCC:")) {
578 if (at_tok_start(&line) < 0)
579 {
580 goto CALL_STATE_EXIT;
581 }
582 if (at_tok_nextint(&line, &tmp_int) < 0) // call id
583 {
584 goto CALL_STATE_EXIT;
585 }
586
587 int i = 0;
588 while(i < RIL_CALL_NUM_MAX) {
589 if(call_list[i].call_id == tmp_int)
590 break;
591 i++;
592 }
593 if(i == RIL_CALL_NUM_MAX) { // No found this call id.
594 i = 0;
595 while(i < RIL_CALL_NUM_MAX) { // Find next empty call item.
596 if(call_list[i].call_id == 0)
597 break;
598 i++;
599 }
600 call_list[i].call_id = tmp_int;
601 }
602
603 LOGD("Found call id : %d", call_list[i].call_id);
604
b.liu7ca612c2025-04-25 09:23:36 +0800605 call_list[i].sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800606 if (at_tok_nextint(&line, &tmp_int) < 0) // dir
607 {
608 goto CALL_STATE_EXIT;
609 }
610 call_list[i].dir = (mbtk_ril_call_dir_enum)tmp_int;
611
612 if (at_tok_nextint(&line, &tmp_int) < 0) // state
613 {
614 goto CALL_STATE_EXIT;
615 }
616 call_list[i].state = (mbtk_ril_call_state_enum)tmp_int;
617
618 if (at_tok_nextint(&line, &tmp_int) < 0) // mode
619 {
620 goto CALL_STATE_EXIT;
621 }
622
623 if (at_tok_nextint(&line, &tmp_int) < 0) // mpty
624 {
625 goto CALL_STATE_EXIT;
626 }
627
628 if (at_tok_nextstr(&line, &tmp_str) < 0) // number
629 {
630 goto CALL_STATE_EXIT;
631 }
632 memset(call_list[i].call_number, 0, sizeof(call_list[i].call_number));
633 if(tmp_str && strlen(tmp_str) > 0) {
634 memcpy(call_list[i].call_number, tmp_str, strlen(tmp_str));
635 }
636
637 if (at_tok_nextint(&line, &tmp_int) < 0) // type
638 {
639 goto CALL_STATE_EXIT;
640 }
641 call_list[i].num_type = (mbtk_ril_call_num_type_enum)tmp_int;
642
643 urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));
644 } else if(strStartsWith(s, "+CALLDISCONNECT:")){
645 if (at_tok_start(&line) < 0)
646 {
647 goto CALL_STATE_EXIT;
648 }
649 if (at_tok_nextint(&line, &tmp_int) < 0) // call id
650 {
651 goto CALL_STATE_EXIT;
652 }
653
654 int i = 0;
655 while(i < RIL_CALL_NUM_MAX) {
656 if(call_list[i].call_id == tmp_int)
657 break;
658 i++;
659 }
660
661 if(i == RIL_CALL_NUM_MAX) { // No found this call id.
662 LOGE("No found this call id : %d", tmp_int);
663 goto CALL_STATE_EXIT;
664 }
665
666 call_list[i].state = MBTK_RIL_CALL_STATE_DISCONNECT;
b.liu7ca612c2025-04-25 09:23:36 +0800667 call_list[i].sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800668
669 urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));
670
671 // Reset after call disconnect.
672 memset(&(call_list[i]), 0, sizeof(mbtk_ril_call_state_info_t));
673 } else if(strStartsWith(s, "+CPAS:")){
674
675 } else {
676 LOGW("Unknown URC.");
677 }
678
679CALL_STATE_EXIT:
680 free(tmp_s);
681}
682
683// *ECALLDATA: <urc_id>[,<urc_data>]
b.liu7ca612c2025-04-25 09:23:36 +0800684static 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 +0800685{
686 mbtk_ril_ecall_state_info_t ecall_state;
687 memset(&ecall_state, 0, sizeof(mbtk_ril_ecall_state_info_t));
b.liu7ca612c2025-04-25 09:23:36 +0800688 ecall_state.sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800689
b.liufd87baf2024-11-15 15:30:38 +0800690 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800691 char *line = tmp_s;
692 int tmp_int;
693 char *tmp_str;
694 if (at_tok_start(&line) < 0)
695 {
696 goto ECALLDATA_EXIT;
697 }
698 if (at_tok_nextint(&line, &tmp_int) < 0)
699 {
700 goto ECALLDATA_EXIT;
701 }
b.liu15f456b2024-10-31 20:16:06 +0800702
b.liu29ead772025-05-26 17:51:20 +0800703 if(strStartsWith(s, "*ECALLDATA:")) {
704 ecall_state.urc_id = (uint8)tmp_int; // urc_id
705 if (at_tok_nextstr(&line, &tmp_str) < 0)
706 {
707 goto ECALLDATA_EXIT;
708 }
709
710 if(tmp_str && strlen(tmp_str) > 0) {
711 memcpy(ecall_state.urc_data, tmp_str, strlen(tmp_str));
712 }
713 } else { // +ECALLDIALRETRY: <retry_time>
714 ecall_state.urc_id = (uint8)(MBTK_ECALL_RETRY_START_BY_URC_ID + tmp_int); // ecall end.
b.liu15f456b2024-10-31 20:16:06 +0800715 }
716
717 urc_msg_distribute(false, RIL_MSG_ID_IND_ECALL_STATE_CHANGE, &ecall_state, sizeof(mbtk_ril_ecall_state_info_t));
718ECALLDATA_EXIT:
719 free(tmp_s);
720}
721
722// +CMT: ,23
723// 0891683108200855F6240D91688189911196F10000221130717445230331D90C
b.liu7ca612c2025-04-25 09:23:36 +0800724static 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 +0800725{
b.liu0bb1c8e2024-12-31 14:44:40 +0800726 static mbtk_ril_sms_state_info_t sms_info;
b.liu7ca612c2025-04-25 09:23:36 +0800727 memset(&sms_info, 0, sizeof(mbtk_ril_sms_state_info_t));
728 sms_info.sim_id = sim_id;
729
b.liu0bb1c8e2024-12-31 14:44:40 +0800730 if(!is_pdu) {
b.liu60c2f1f2024-12-31 12:54:45 +0800731 char* tmp_s = memdup(s,strlen(s) + 1);
732 char *line = tmp_s;
733 char *tmp_str;
734 if (at_tok_start(&line) < 0)
735 {
736 goto CMT_EXIT;
737 }
738 if (at_tok_nextstr(&line, &tmp_str) < 0)
739 {
740 goto CMT_EXIT;
741 }
742 if (at_tok_nextstr(&line, &tmp_str) < 0)
743 {
744 goto CMT_EXIT;
745 }
746 sms_info.pdu_len = (uint16)atoi(tmp_str);
b.liu60c2f1f2024-12-31 12:54:45 +0800747 CMT_EXIT:
748 free(tmp_s);
b.liu0bb1c8e2024-12-31 14:44:40 +0800749 } else {
750 LOGD("PDU : %s", s);
751 memcpy(sms_info.pdu, s, strlen(s));
752 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 +0800753 }
b.liu15f456b2024-10-31 20:16:06 +0800754}
755
756// +CREG: 1, "8010", "000060a5", 0, 2, 0
757// +CREG: 1, "8330", "06447347", 7, 2, 0
758// +CEREG: 1, "8330", "06447347", 7
759// $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
760// $CREG: 1, "8010", "000060a7", 0,, 2, 0
761// +CGREG: 1
b.liubeb61cc2025-02-13 10:38:29 +0800762// +C5GREG: 1,"00280386","07e920010",11,1,"01"
b.liu7ca612c2025-04-25 09:23:36 +0800763static 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 +0800764{
765 mbtk_ril_net_reg_state_info_t state;
766 memset(&state, 0, sizeof(mbtk_ril_net_reg_state_info_t));
767 state.tech = MBTK_RADIO_TECH_UNKNOWN;
b.liu7ca612c2025-04-25 09:23:36 +0800768 state.sim_id = sim_id;
b.liu15f456b2024-10-31 20:16:06 +0800769
770 if(strStartsWith(s, "+CREG:"))
771 {
772 state.type = MBTK_NET_REG_TYPE_CALL;
773 } else if(strStartsWith(s, "+CGREG:")) {
774 state.type = MBTK_NET_REG_TYPE_DATA_GSM_WCDMA;
b.liubeb61cc2025-02-13 10:38:29 +0800775 } else if(strStartsWith(s, "+C5GREG:")) {
776 state.type = MBTK_NET_REG_TYPE_DATA_NR;
b.liu15f456b2024-10-31 20:16:06 +0800777 } else {
778 state.type = MBTK_NET_REG_TYPE_DATA_LTE;
779 }
780
b.liufd87baf2024-11-15 15:30:38 +0800781 char* tmp_s = memdup(s,strlen(s) + 1);
b.liu15f456b2024-10-31 20:16:06 +0800782 char *line = tmp_s;
783 int tmp_int;
784 char *tmp_str;
785 if (at_tok_start(&line) < 0)
786 {
787 goto CGREG_EXIT;
788 }
789 if (at_tok_nextint(&line, &tmp_int) < 0)
790 {
791 goto CGREG_EXIT;
792 }
793 state.reg_state = (mbtk_net_reg_state_enum)tmp_int; // Reg State.
b.liubeb61cc2025-02-13 10:38:29 +0800794 if (state.reg_state && at_tok_hasmore(&line)) // Reg
b.liu15f456b2024-10-31 20:16:06 +0800795 {
b.liubeb61cc2025-02-13 10:38:29 +0800796 if (at_tok_nextstr(&line, &tmp_str) < 0) // tac
b.liu15f456b2024-10-31 20:16:06 +0800797 {
798 goto CGREG_EXIT;
799 }
b.liubeb61cc2025-02-13 10:38:29 +0800800 state.tac = (uint64)strtoull(tmp_str, NULL, 16);
b.liufd87baf2024-11-15 15:30:38 +0800801
b.liubeb61cc2025-02-13 10:38:29 +0800802 if (at_tok_nextstr(&line, &tmp_str) < 0) // ci
b.liu15f456b2024-10-31 20:16:06 +0800803 {
804 goto CGREG_EXIT;
805 }
b.liubeb61cc2025-02-13 10:38:29 +0800806 state.ci = (uint64)strtoull(tmp_str, NULL, 16);
b.liufd87baf2024-11-15 15:30:38 +0800807
b.liu15f456b2024-10-31 20:16:06 +0800808 if (at_tok_nextint(&line, &tmp_int) < 0)
809 {
810 goto CGREG_EXIT;
811 }
812 state.tech = (mbtk_radio_technology_enum)tmp_int; // AcT
813 }
814
b.liu62240ee2024-11-07 17:52:45 +0800815 if(state.reg_state == MBTK_NET_REG_STATE_HOME
816 || state.reg_state == MBTK_NET_REG_STATE_ROAMING) {
817 mbtk_net_ready();
818 }
819
b.liuafdf2c62024-11-12 11:10:44 +0800820 // Should restart data call if necessary.
821 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 +0800822CGREG_EXIT:
823 free(tmp_s);
824}
825
b.liu7ca612c2025-04-25 09:23:36 +0800826static 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 +0800827{
828 // "CONNECT"
829 if(strStartsWith(s, "CONNECT"))
830 {
831#if 1
832 if(cgact_wait.waitting && cgact_wait.act) {
833 cgact_wait.waitting = false;
834 }
835#endif
836 }
837 // +CGEV:
838 // +CGEV: NW DEACT <cid>,<cid>
839 // +CGEV: ME DEACT <cid>,<cid>
840 // +CGEV: NW PDN DEACT <cid>
841 // +CGEV: ME PDN DEACT <cid>
842 // +CGEV: NW DETACH
843 // +CGEV: ME DETACH
844 //
845 // +CGEV: NW ACT <cid>,<cid>
846 // +CGEV: ME ACT <cid>,<cid>
847 // +CGEV: EPS PDN ACT <cid>
848 // +CGEV: ME PDN ACT <cid>,<reason>,<cid>
849 // +CGEV: ME PDN ACT <cid>,<reason>
850 // +CGEV: NW PDN ACT <cid>
851 // +CGEV: EPS ACT <cid>
852 // +CGEV: NW MODIFY <cid>,<reason>
853 // +CGEV: NW REATTACH
854
855 /*
856 +CGEV: NW DETACH
857 +CGEV: ME DETACH
858 +CGEV: NW CLASS <class>
859 +CGEV: ME CLASS <class>
860 +CGEV: NW PDN ACT <cid>
861 +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
862 +CGEV: NW ACT <p_cid>, <cid>, <event_type>
863 +CGEV: ME ACT <p_cid>, <cid>, <event_type>
864 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
865 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
866 +CGEV: NW PDN DEACT <cid>
867 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
868 +CGEV: ME PDN DEACT <cid>
869 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
870 +CGEV: NW DEACT <p_cid>, <cid>, <event_type>
871 +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
872 +CGEV: ME DEACT <p_cid>, <cid>, <event_type>
873 +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
874 +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
875 +CGEV: ME MODIFY <cid>, <change_reason>, <event_type>
876 +CGEV: REJECT <PDP_type>, <PDP_addr>
877 +CGEV: NW REACT <PDP_type>, <PDP_addr>, [<cid>]
878 */
879 else if(strStartsWith(s, "+CGEV:"))
880 {
881#if 1
882 // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
883 // "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
884 // "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
885 // "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
886 // "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
887 // "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
888 // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
b.liu15f456b2024-10-31 20:16:06 +0800889 mbtk_ril_pdp_state_info_t cgev_info;
890 memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));
b.liu7ca612c2025-04-25 09:23:36 +0800891 cgev_info.sim_id = sim_id;
b.liu62240ee2024-11-07 17:52:45 +0800892 int cid, reason = 0;
b.liu62240ee2024-11-07 17:52:45 +0800893 if (sscanf(s, "+CGEV: NW PDN DEACT %d", &cid) == 1) {
894 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800895 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800896 } else if (sscanf(s, "+CGEV: ME PDN DEACT %d", &cid) == 1) {
897 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800898 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800899 } else if(sscanf(s, "+CGEV: ME PDN ACT %d,%d", &cid, &reason) == 2
900 || sscanf(s, "+CGEV: ME PDN ACT %d", &cid) == 1) {
901 cgev_info.cid = (uint16)cid;
902 cgev_info.reason = (uint16)reason;
b.liu15f456b2024-10-31 20:16:06 +0800903 cgev_info.action = TRUE;
b.liubcf86c92024-08-19 19:48:28 +0800904 } else if (!strcmp(s, "+CGEV: ME DETACH")) {
905 if(cgact_wait.waitting) {
b.liu15f456b2024-10-31 20:16:06 +0800906 cgev_info.cid = cgact_wait.cid;
b.liubcf86c92024-08-19 19:48:28 +0800907 }
b.liu15f456b2024-10-31 20:16:06 +0800908 cgev_info.action = FALSE;
b.liu62240ee2024-11-07 17:52:45 +0800909 } else if (sscanf(s, "+CGEV: NW MODIFY %d,%d", &cid, &reason) == 2) {
910 cgev_info.cid = (uint16)cid;
911 cgev_info.reason = (uint16)reason;
b.liu15f456b2024-10-31 20:16:06 +0800912 cgev_info.action = TRUE;
b.liu62240ee2024-11-07 17:52:45 +0800913 } else if(sscanf(s, "+CGEV: EPS PDN ACT %d", &cid) == 1) {
914 cgev_info.cid = (uint16)cid;
b.liu15f456b2024-10-31 20:16:06 +0800915 cgev_info.action = TRUE;
b.liubcf86c92024-08-19 19:48:28 +0800916 } else {
917 LOGD(">>>>>>>>>No process +CGEV <<<<<<<<<");
918 return;
919 }
b.liu15f456b2024-10-31 20:16:06 +0800920 cgev_info.auto_change = !cgact_wait.waitting;
b.liubcf86c92024-08-19 19:48:28 +0800921
922 if(cgact_wait.act) {
b.liu15f456b2024-10-31 20:16:06 +0800923 if(cgact_wait.waitting && cgev_info.action && cgact_wait.cid == cgev_info.cid) {
b.liubcf86c92024-08-19 19:48:28 +0800924 cgact_wait.waitting = false;
925 }
926 } else {
b.liu15f456b2024-10-31 20:16:06 +0800927 if(cgact_wait.waitting && !cgev_info.action && cgact_wait.cid == cgev_info.cid) {
b.liubcf86c92024-08-19 19:48:28 +0800928 cgact_wait.waitting = false;
929 }
930 }
931
b.liu15f456b2024-10-31 20:16:06 +0800932 LOGD("+CGEV:cid - %d, act - %d, auto_change - %d, reason - %d", cgev_info.cid, cgev_info.action,
933 cgev_info.auto_change, cgev_info.reason);
b.liu15f456b2024-10-31 20:16:06 +0800934 if(cgev_info.cid >= MBTK_APN_CID_MIN && cgev_info.cid <= MBTK_APN_CID_MAX) {
b.liu7ca612c2025-04-25 09:23:36 +0800935 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 +0800936 urc_msg_distribute(false, RIL_MSG_ID_IND_PDP_STATE_CHANGE, &cgev_info, sizeof(mbtk_ril_pdp_state_info_t));
937 }
938
b.liubcf86c92024-08-19 19:48:28 +0800939#else
940 if(at_process) {
941 if(cgact_wait.act) {
942 if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT 15,4
943 if(cgact_wait.cid == atoi(s + 18)) {
944 cgact_wait.waitting = false;
945 }
946
947 uint8 data_pdp;
948 char* tmp_s = memdup(s + 18,strlen(s + 18));
949 char* free_ptr = tmp_s;
950 char *line = tmp_s;
951 int tmp_int;
952 if (at_tok_start(&line) < 0)
953 {
954 goto at_PDP_CREG_EXIT;
955 }
956 if (at_tok_nextint(&line, &tmp_int) < 0)
957 {
958 goto at_PDP_CREG_EXIT;
959 }
960 if (at_tok_nextint(&line, &tmp_int) < 0)
961 {
962 goto at_PDP_CREG_EXIT;
963 }
964 data_pdp = tmp_int;
965at_PDP_CREG_EXIT:
966 free(free_ptr);
967
968 //data_pdp = (uint8)atoi(s + 20); //reason
969 if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
970 {
971 if(data_pdp == 0)
972 {
973 data_pdp = 25;
974 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
975 //data_pdp = cgact_wait.cid + 200;
976 }
977 else if(data_pdp == 1)
978 {
979 data_pdp = 26;
980 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
981 }
982 else if(data_pdp == 2)
983 {
984 data_pdp = 27;
985 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
986 }
987 else if(data_pdp == 3)
988 {
989 data_pdp = 27;
990 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
991 }
992 else
993 {
994
995 }
996 if(cgact_wait.cid != 0)
997 {
998 data_pdp = cgact_wait.cid + 200;
999 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1000 }
1001 }
1002 } else if(strStartsWith(s, "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY 1,4
1003 if(cgact_wait.cid == atoi(s + 17)) {
1004 cgact_wait.waitting = false;
1005 }
1006 }
1007 } else {
1008 if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
1009 if(cgact_wait.cid == atoi(s + 20)) {
1010 cgact_wait.waitting = false;
1011 }
1012 uint8 data_pdp;
1013 data_pdp = 0; //
1014 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1015 if(cgact_wait.cid != 0)
1016 {
1017 data_pdp = cgact_wait.cid + 100;
1018 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1019 }
1020 }
1021 }
1022 } else {
1023 // apn_state_set
1024
1025 // +CGEV: NW PDN DEACT <cid>
1026
1027 // +CGEV: EPS PDN ACT 1
1028 // +CGEV: ME PDN ACT 8,1
1029
1030 // +CGEV: ME PDN ACT 2,4
1031 uint8 data[2] = {0xFF};
1032 if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
1033 //apn_state_set(atoi(s + 20), false);
1034 data[0] = (uint8)0;
1035 data[1] = (uint8)atoi(s + 20);
1036
1037 uint8 data_pdp;
1038 data_pdp = 0; //
1039 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1040 data_pdp = data[1] + 100;
1041 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1042 } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
1043 //apn_state_set(atoi(s + 19), true);
1044#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
1045 //data[0] = (uint8)1;
1046 //data[1] = (uint8)atoi(s + 19);
1047#else
1048 data[0] = (uint8)1;
1049 data[1] = (uint8)atoi(s + 19);
1050#endif
1051 } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
1052 //apn_state_set(atoi(s + 19), true);
1053 data[0] = (uint8)0;
1054 data[1] = (uint8)atoi(s + 20);
1055
1056 uint8 data_pdp;
1057 data_pdp = 0; //
1058 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1059 data_pdp = data[1] + 100;
1060 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1061 } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
1062 //apn_state_set(atoi(s + 18), true);
1063 data[0] = (uint8)1;
1064 data[1] = (uint8)atoi(s + 18);
1065
1066 uint8 data_pdp;
1067 char* tmp_s = memdup(s + 18,strlen(s + 18));
1068 char* free_ptr = tmp_s;
1069 char *line = tmp_s;
1070 int tmp_int;
1071 if (at_tok_start(&line) < 0)
1072 {
1073 goto PDP_CREG_EXIT;
1074 }
1075 if (at_tok_nextint(&line, &tmp_int) < 0)
1076 {
1077 goto PDP_CREG_EXIT;
1078 }
1079 if (at_tok_nextint(&line, &tmp_int) < 0)
1080 {
1081 goto PDP_CREG_EXIT;
1082 }
1083 data_pdp = tmp_int;
1084PDP_CREG_EXIT:
1085 free(free_ptr);
1086 //data_pdp = (uint8)atoi(s + 20); //reason
1087 if(data[1] >= 1 && data[1] < 8)
1088 {
1089 if(data_pdp == 0)
1090 {
1091 data_pdp = 25;
1092 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1093 }
1094 else if(data_pdp == 1)
1095 {
1096 data_pdp = 26;
1097 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1098 }
1099 else if(data_pdp == 2)
1100 {
1101 data_pdp = 27;
1102 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1103 }
1104 else if(data_pdp == 3)
1105 {
1106 data_pdp = 27;
1107 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1108 }
1109 else
1110 {
1111
1112 }
1113
1114 data_pdp = data[1] + 200;
1115 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
1116 data[1] = 0;
1117 }
1118 } else {
1119 LOGI("No process : %s", s);
1120 }
1121
1122 urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
1123 }
1124#endif
1125 } else {
1126 LOGW("Unknown PDP URC : %s", s);
1127 }
1128}
1129
1130
b.liu7ca612c2025-04-25 09:23:36 +08001131static 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 +08001132{
b.liubeb61cc2025-02-13 10:38:29 +08001133 // +EEMNRSVC: <mcc>,<lenOfMnc>,<mnc>,<tac>,<phyCellId>,<dlNrArfcn>,<dlScs>,<ulNrArfcn>,<ulScs>,<sulNrArfcn>,<sulScs>,<band>,<dlBandwidth>,<cellId>,<IsRedCapCell>,<longDRXCyclePresent>,<shortDRXCyclePresent>,<longDRXCycle>,<shortDRXCycle>,<pagingCycle>,
1134 // <rsrp>,<rsrq>,<sinr>,<rssi>,<qRxLevMin>,<qQualMin>,<srxlev>,
1135 // <pathLoss>,
1136 // <dlBler>,<averDlPRB>,<averDlMcs>,<averDlPortNum>,<averCQI>,<averLi>,<averRi>,<dlThroughPut>,<dlPeakThroughPut>,
1137 // <ulBler>,<averUlPRB>,<averUlMcs>,<averUlPortNum>,<currPuschTxPower>,<currPucchTxPower>,<grantTotal>,<ulThroughPut>,<ulPeakThroughPut>,
1138 // <nrrcModeState>,<nmmState>,<serviceState>,<IsSingleNmmRejectCause>,<NMMRejectCause>,<amfRegionId>,<amfSetId>,<amfPointer>,<nrTmsi>,
1139 // <ulBandwidth>,<dlInitialBwpFreq>,<ulInitialBwpFreq>
1140 /*
1141 +EEMNRSVC: 1120, 2, 0, 2622342, 137, 158650, 0, 146678, 0, 0, 255, 28, 79, 620598788208, 0, 0, 0, 0, 0, 64,
1142 86, 65, 86, 51, 20, 0, 49,
1143 0,
1144 0, 0, 0, 0, 38, 0, 8, 0, 0,
1145 0, 256, 24, 16, 13, 20, 2, 2, 0,
1146 1, 10, 0, 1, 0, 9, 128, 5, 2358781729,
1147 79, 788390, 733390
1148 */
1149 if(strStartsWith(s, "+EEMNRSVC:")) {
1150 // mcc,lenOfMnc,mnc,tac,PCI,dlNrArfcn,ulNrArfcn,band,rsrp,rsrq,sinr,rssi
1151 // cellID
1152 if(cell_info.running) {
1153 int tmp_int;
1154 int i = 0;
1155 char* tmp_s = memdup(s,strlen(s) + 1);
1156 char* free_ptr = tmp_s;
1157 char *line = tmp_s;
1158 char *tmp_str;
1159 if (at_tok_start(&line) < 0)
1160 {
1161 goto EEMNRSVC_EXIT;
1162 }
1163
1164 if (at_tok_nextint(&line, &tmp_int) < 0) // mcc
1165 {
1166 goto EEMNRSVC_EXIT;
1167 }
1168 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1169
1170 if (at_tok_nextint(&line, &tmp_int) < 0) // lenOfMnc
1171 {
1172 goto EEMNRSVC_EXIT;
1173 }
1174 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1175 if (at_tok_nextint(&line, &tmp_int) < 0) // mnc
1176 {
1177 goto EEMNRSVC_EXIT;
1178 }
1179 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1180
1181 if (at_tok_nextint(&line, &tmp_int) < 0) // tac
1182 {
1183 goto EEMNRSVC_EXIT;
1184 }
1185 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1186
1187 if (at_tok_nextint(&line, &tmp_int) < 0) // pci
1188 {
1189 goto EEMNRSVC_EXIT;
1190 }
1191 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1192
1193 if (at_tok_nextint(&line, &tmp_int) < 0) // dlNrArfcn
1194 {
1195 goto EEMNRSVC_EXIT;
1196 }
1197 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1198
1199 if (at_tok_nextint(&line, &tmp_int) < 0) // dlScs
1200 {
1201 goto EEMNRSVC_EXIT;
1202 }
1203
1204 if (at_tok_nextint(&line, &tmp_int) < 0) // ulNrArfcn
1205 {
1206 goto EEMNRSVC_EXIT;
1207 }
1208 cell_info.cell_list.cell[cell_info.cell_list.num].value7 = (uint32)tmp_int;
1209
1210 // <ulScs>,<sulNrArfcn>,<sulScs>
1211 for(i =0; i < 3; i++)
1212 {
1213 if (at_tok_nextint(&line, &tmp_int) < 0)
1214 {
1215 goto EEMNRSVC_EXIT;
1216 }
1217 }
1218
1219 if (at_tok_nextint(&line, &tmp_int) < 0) // band
1220 {
1221 goto EEMNRSVC_EXIT;
1222 }
1223 cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int;
1224
1225
1226 if (at_tok_nextint(&line, &tmp_int) < 0) // dlBandwidth
1227 {
1228 goto EEMNRSVC_EXIT;
1229 }
1230
1231
1232 if (at_tok_nextstr(&line, &tmp_str) < 0) // cellId
1233 {
1234 goto EEMNRSVC_EXIT;
1235 }
1236 // LOGD("cellID-str : %s", tmp_str);
1237 cell_info.cell_list.cell[cell_info.cell_list.num].value64_1 = (uint64)strtoull(tmp_str, NULL, 10);
1238 // LOGD("cellID : %llu", cell_info.cell_list.cell[cell_info.cell_list.num].value64_1);
1239
1240 // <IsRedCapCell>,<longDRXCyclePresent>,<shortDRXCyclePresent>,<longDRXCycle>,<shortDRXCycle>,<pagingCycle>
1241 for(i =0; i < 6; i++)
1242 {
1243 if (at_tok_nextint(&line, &tmp_int) < 0)
1244 {
1245 goto EEMNRSVC_EXIT;
1246 }
1247 }
1248
1249 if (at_tok_nextint(&line, &tmp_int) < 0) // <rsrp>
1250 {
1251 goto EEMNRSVC_EXIT;
1252 }
1253 cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int;
1254
1255 if (at_tok_nextint(&line, &tmp_int) < 0) // <rsrq>
1256 {
1257 goto EEMNRSVC_EXIT;
1258 }
1259 cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int;
1260
1261 if (at_tok_nextint(&line, &tmp_int) < 0) // <sinr>
1262 {
1263 goto EEMNRSVC_EXIT;
1264 }
1265 cell_info.cell_list.cell[cell_info.cell_list.num].value11 = (uint32)tmp_int;
1266
1267 if (at_tok_nextint(&line, &tmp_int) < 0) // <rssi>
1268 {
1269 goto EEMNRSVC_EXIT;
1270 }
1271 cell_info.cell_list.cell[cell_info.cell_list.num].value12 = (uint32)tmp_int;
1272
1273 cell_info.cell_list.num++;
1274
1275EEMNRSVC_EXIT:
1276 free(free_ptr);
1277 }
1278 }
1279 // +EEMNRINTER: <index>,<phyCellId>,<nrArfcn>,<dlScs>,<rsrp>,<rsrq>,<sinr>,<srxlev>,<mcc>,<lenOfMnc>,<mnc>,<tac>,<cellId>
1280 /* +EEMNRINTER: 0, 508, 723360, 0, 39, 64, -8, 1, 0, 0, 0, 0, 4294967295 */
1281 /* +EEMNRINTER: 1, 254, 723360, 0, 45, 72, 1, 7, 0, 0, 0, 0, 4294967295 */
1282 /* +EEMNRINTER: 2, 595, 723360, 0, 40, 65, -5, 3, 0, 0, 0, 0, 4294967295 */
1283 else if(strStartsWith(s, "+EEMNRINTER:")) {
1284 // phyCellId,nrArfcn,rsrp,rsrq
1285 if(cell_info.running) {
1286 int tmp_int;
1287 char* tmp_s = memdup(s,strlen(s) + 1);
1288 char* free_ptr = tmp_s;
1289 char *line = tmp_s;
1290 if (at_tok_start(&line) < 0)
1291 {
1292 goto EEMNRINTER_EXIT;
1293 }
1294 if (at_tok_nextint(&line, &tmp_int) < 0) // index
1295 {
1296 goto EEMNRINTER_EXIT;
1297 }
1298 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int > 1007) // phyCellId (0 - 1007)
1299 {
1300 goto EEMNRINTER_EXIT;
1301 }
1302 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1303 if (at_tok_nextint(&line, &tmp_int) < 0) // nrArfcn
1304 {
1305 goto EEMNRINTER_EXIT;
1306 }
1307 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1308 if (at_tok_nextint(&line, &tmp_int) < 0) // dlScs
1309 {
1310 goto EEMNRINTER_EXIT;
1311 }
1312 if (at_tok_nextint(&line, &tmp_int) < 0) // rsrp
1313 {
1314 goto EEMNRINTER_EXIT;
1315 }
1316 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1317 if (at_tok_nextint(&line, &tmp_int) < 0) // rsrq
1318 {
1319 goto EEMNRINTER_EXIT;
1320 }
1321 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1322
1323 cell_info.cell_list.num++;
1324EEMNRINTER_EXIT:
1325 free(free_ptr);
1326 }
1327 }
1328 // +EEMNRINTERRAT:<net_type>,<numInterRATEutra>,
1329 // <earfcn>,<physCellId>,<rsrp>,<rsrq>,<sinr>,<mcc>,<lenOfMnc>,<mnc>,<tac>
1330 // ......
1331 // <earfcn>,<physCellId>,<rsrp>,<rsrq>,<sinr>,<mcc>,<lenOfMnc>,<mnc>,<tac>
1332 /*
1333 +EEMNRINTERRAT: 2, 6, // LTE
1334 1300, 423, 0, 0, 0, 0, 0, 0, 0,
1335 1300, 137, 0, 0, 0, 0, 0, 0, 0,
1336 1300, 149, 0, 0, 0, 0, 0, 0, 0,
1337 1300, 494, 0, 0, 0, 0, 0, 0, 0,
1338 1300, 337, 0, 0, 0, 0, 0, 0, 0,
1339 1300, 288, 0, 0, 0, 0, 0, 0, 0
1340 */
1341 /*
1342 +EEMNRINTERRAT: 1, 0 // UMTS
1343 */
1344 else if(strStartsWith(s, "+EEMNRINTERRAT:")) {
1345 // phyCellId,nrArfcn,rsrp,rsrq
1346 if(cell_info.running) {
1347 int tmp_int;
1348 char* tmp_s = memdup(s,strlen(s) + 1);
1349 char* free_ptr = tmp_s;
1350 char *line = tmp_s;
1351 if (at_tok_start(&line) < 0)
1352 {
1353 goto EEMNRINTERRAT_EXIT;
1354 }
1355 if (at_tok_nextint(&line, &tmp_int) < 0) // net_type
1356 {
1357 goto EEMNRINTERRAT_EXIT;
1358 }
1359
1360#define CI_DEV_EM_NETWORK_LTE 2
1361
1362 // Only support LTE.
1363 if(tmp_int == CI_DEV_EM_NETWORK_LTE) { // LTE
1364 int num;
1365 int i, j;
1366 if (at_tok_nextint(&line, &num) < 0) // numInterRATEutra
1367 {
1368 goto EEMNRINTERRAT_EXIT;
1369 }
1370 LOGD("LTE-RAT num : %d", num);
1371 for(i = 0; i < num; i++) {
1372 if (at_tok_nextint(&line, &tmp_int) < 0) // earfcn
1373 {
1374 goto EEMNRINTERRAT_EXIT;
1375 }
1376 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1377
1378 if (at_tok_nextint(&line, &tmp_int) < 0) // physCellId
1379 {
1380 goto EEMNRINTERRAT_EXIT;
1381 }
1382 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1383
1384 if (at_tok_nextint(&line, &tmp_int) < 0) // rsrp
1385 {
1386 goto EEMNRINTERRAT_EXIT;
1387 }
1388 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1389
1390 if (at_tok_nextint(&line, &tmp_int) < 0) // rsrq
1391 {
1392 goto EEMNRINTERRAT_EXIT;
1393 }
1394 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1395
1396 // Jump 5 items.
1397 j = 0;
1398 while(j < 5) {
1399 if (at_tok_nextint(&line, &tmp_int) < 0)
1400 {
1401 goto EEMNRINTERRAT_EXIT;
1402 }
1403 j++;
1404 }
1405
1406 cell_info.cell_list.num++;
1407 }
1408 }
1409EEMNRINTERRAT_EXIT:
1410 free(free_ptr);
1411 }
1412 }
b.liub4772072024-08-15 14:47:03 +08001413 /*
1414 // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
1415 // <rsrp>,<rsrq>, <sinr>,
1416 // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
1417 // cellId,subFrameAssignType,specialSubframePatterns,transMode
1418 // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
1419 // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
1420 // dlBer, ulBer,
1421 // diversitySinr, diversityRssi
1422 +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
1423 0, 0, 0,
1424 1, 10, 0, 1, 0, 1059, 78, 3959566565,
1425 105149248, 2, 7, 7,
1426 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
1427 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
1428 0, 0,
1429 7, 44
1430 */
b.liubeb61cc2025-02-13 10:38:29 +08001431 else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
b.liub4772072024-08-15 14:47:03 +08001432 {
1433 // tac, PCI, dlEuarfcn, ulEuarfcn, band
1434 if(cell_info.running) {
1435 int tmp_int;
1436 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001437 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001438 char* free_ptr = tmp_s;
1439 char *line = tmp_s;
1440 if (at_tok_start(&line) < 0)
1441 {
1442 goto EEMLTESVC_EXIT;
1443 }
1444
1445 if (at_tok_nextint(&line, &tmp_int) < 0)
1446 {
1447 goto EEMLTESVC_EXIT;
1448 }
1449 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int; //mcc
1450 if (at_tok_nextint(&line, &tmp_int) < 0)
1451 {
1452 goto EEMLTESVC_EXIT;
1453 }
1454 if (at_tok_nextint(&line, &tmp_int) < 0)
1455 {
1456 goto EEMLTESVC_EXIT;
1457 }
1458 cell_info.cell_list.cell[cell_info.cell_list.num].value7 = (uint32)tmp_int; //mnc
1459 /*
1460 // Jump 2 integer.
1461 i = 0;
1462 while(i < 2) {
1463 if (at_tok_nextint(&line, &tmp_int) < 0)
1464 {
1465 goto EEMLTESVC_EXIT;
1466 }
1467 i++;
1468 }
1469 */
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].value1 = (uint32)tmp_int; //tac
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].value2 = (uint32)tmp_int; //pci
1480 if (at_tok_nextint(&line, &tmp_int) < 0)
1481 {
1482 goto EEMLTESVC_EXIT;
1483 }
1484 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int; //dl arfcn
1485 if (at_tok_nextint(&line, &tmp_int) < 0)
1486 {
1487 goto EEMLTESVC_EXIT;
1488 }
1489 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int; //ul arfcn
1490 if (at_tok_nextint(&line, &tmp_int) < 0)
1491 {
1492 goto EEMLTESVC_EXIT;
1493 }
1494 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int; //band
1495 if (at_tok_nextint(&line, &tmp_int) < 0)
1496 {
1497 goto EEMLTESVC_EXIT;
1498 }
1499 if (at_tok_nextint(&line, &tmp_int) < 0)
1500 {
1501 goto EEMLTESVC_EXIT;
1502 }
1503 cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int; //cid
1504 if (at_tok_nextint(&line, &tmp_int) < 0)
1505 {
1506 goto EEMLTESVC_EXIT;
1507 }
1508 cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int; //rsrp
1509
1510 for(i =0; i < 10; i++)
1511 {
1512 if (at_tok_nextint(&line, &tmp_int) < 0)
1513 {
1514 goto EEMLTESVC_EXIT;
1515 }
1516 }
1517 cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int; //cell identiy
1518
1519 cell_info.cell_list.num++;
1520
1521EEMLTESVC_EXIT:
1522 free(free_ptr);
1523 }
1524 }
1525 /*
1526 // index,phyCellId,euArfcn,rsrp,rsrq
1527 +EEMLTEINTER: 0, 65535, 38950, 0, 0
1528 */
1529 else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
1530 {
1531 // phyCellId,euArfcn,rsrp,rsrq
1532 if(cell_info.running) {
1533 int tmp_int;
b.liufd87baf2024-11-15 15:30:38 +08001534 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001535 char* free_ptr = tmp_s;
1536 char *line = tmp_s;
1537 if (at_tok_start(&line) < 0)
1538 {
1539 goto EEMLTEINTER_EXIT;
1540 }
1541 if (at_tok_nextint(&line, &tmp_int) < 0)
1542 {
1543 goto EEMLTEINTER_EXIT;
1544 }
1545 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
1546 {
1547 goto EEMLTEINTER_EXIT;
1548 }
1549 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1550 if (at_tok_nextint(&line, &tmp_int) < 0)
1551 {
1552 goto EEMLTEINTER_EXIT;
1553 }
1554 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1555 if (at_tok_nextint(&line, &tmp_int) < 0)
1556 {
1557 goto EEMLTEINTER_EXIT;
1558 }
1559 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1560 LOG("cell line : %s", line);
1561 if (at_tok_nextint(&line, &tmp_int) < 0)
1562 {
1563 goto EEMLTEINTER_EXIT;
1564 }
1565 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1566 if (at_tok_nextint(&line, &tmp_int) < 0)
1567 {
1568 LOG("cell tmp_int : %d", tmp_int);
1569 goto EEMLTEINTER_EXIT;
1570 }
1571 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1572 LOG("cell value5 : %d", cell_info.cell_list.cell[cell_info.cell_list.num].value5);
1573 cell_info.cell_list.num++;
1574EEMLTEINTER_EXIT:
1575 free(free_ptr);
1576 }
1577 }
1578 // Do nothing
1579 else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
1580 {
1581 if(cell_info.running) {
1582
1583 }
1584 }
1585 // WCDMA
1586 /*
1587 // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1588
1589 // if sCMeasPresent == 1
1590 // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1591 // endif
1592
1593 // if sCParamPresent == 1
1594 // rac, nom, mcc, mnc_len, mnc, lac, ci,
1595 // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1596 // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1597 // endif
1598
1599 // if ueOpStatusPresent == 1
1600 // rrcState, numLinks, srncId, sRnti,
1601 // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1602 // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1603 // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1604 // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1605 // endif
1606 //
1607 +EEMUMTSSVC: 3, 1, 1, 1,
1608 -80, 27, -6, -18, -115, -32768,
1609 1, 1, 1120, 2, 1, 61697, 168432821,
1610 15, 24, 10763, 0, 0, 0, 0,
1611 128, 128, 65535, 0, 0,
1612 2, 255, 65535, 4294967295,
1613 0, 0, 0, 0, 0, 0,
1614 0, 0, 0, 0, 0, 0, 1, 1,
1615 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
1616 0, 0, 0, 0, 0, 0
1617 */
1618 else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
1619 {
1620 // lac, ci, arfcn
1621 if(cell_info.running) {
1622 int tmp_int;
1623 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001624 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001625 char* free_ptr = tmp_s;
1626 char *line = tmp_s;
1627 if (at_tok_start(&line) < 0)
1628 {
1629 goto EEMUMTSSVC_EXIT;
1630 }
1631 // Jump 12 integer.
1632 i = 0;
1633 while(i < 12) {
1634 if (at_tok_nextint(&line, &tmp_int) < 0)
1635 {
1636 goto EEMUMTSSVC_EXIT;
1637 }
1638 i++;
1639 }
1640 // mcc
1641 if (at_tok_nextint(&line, &tmp_int) < 0)
1642 {
1643 goto EEMUMTSSVC_EXIT;
1644 }
1645 cell_info.cell_list.cell[cell_info.cell_list.num].value4= (uint32)tmp_int;
1646 // mnc
1647 if (at_tok_nextint(&line, &tmp_int) < 0)
1648 {
1649 goto EEMUMTSSVC_EXIT;
1650 }
1651 cell_info.cell_list.cell[cell_info.cell_list.num].value5= (uint32)tmp_int;
1652 // lac
1653 if (at_tok_nextint(&line, &tmp_int) < 0)
1654 {
1655 goto EEMUMTSSVC_EXIT;
1656 }
1657 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1658 // ci
1659 if (at_tok_nextint(&line, &tmp_int) < 0)
1660 {
1661 goto EEMUMTSSVC_EXIT;
1662 }
1663 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1664
1665 if (at_tok_nextint(&line, &tmp_int) < 0)
1666 {
1667 goto EEMUMTSSVC_EXIT;
1668 }
1669 // cpi
1670 if (at_tok_nextint(&line, &tmp_int) < 0)
1671 {
1672 goto EEMUMTSSVC_EXIT;
1673 }
1674 cell_info.cell_list.cell[cell_info.cell_list.num].value6= (uint32)tmp_int;
1675 /*
1676 // Jump 2 integer.
1677 i = 0;
1678 while(i < 2) {
1679 if (at_tok_nextint(&line, &tmp_int) < 0)
1680 {
1681 goto EEMUMTSSVC_EXIT;
1682 }
1683 i++;
1684 }
1685 */
1686 // arfcn
1687 if (at_tok_nextint(&line, &tmp_int) < 0)
1688 {
1689 goto EEMUMTSSVC_EXIT;
1690 }
1691 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1692
1693 cell_info.cell_list.num++;
1694EEMUMTSSVC_EXIT:
1695 free(free_ptr);
1696 }
1697 }
1698 /*
1699 // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1700 +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1701 */
1702 else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
1703 {
1704 // lac, ci, arfcn
1705 if(cell_info.running) {
1706 int tmp_int;
1707 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001708 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001709 char* free_ptr = tmp_s;
1710 char *line = tmp_s;
1711 if (at_tok_start(&line) < 0)
1712 {
1713 goto EEMUMTSINTRA_EXIT;
1714 }
1715 // Jump 8 integer.
1716 i = 0;
1717 while(i < 8) {
1718 if (at_tok_nextint(&line, &tmp_int) < 0)
1719 {
1720 goto EEMUMTSINTRA_EXIT;
1721 }
1722 i++;
1723 }
1724
1725 // lac
1726 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1727 {
1728 goto EEMUMTSINTRA_EXIT;
1729 }
1730 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1731
1732 // ci
1733 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1734 {
1735 goto EEMUMTSINTRA_EXIT;
1736 }
1737 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1738
1739 // arfcn
1740 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1741 {
1742 goto EEMUMTSINTRA_EXIT;
1743 }
1744 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1745
1746 cell_info.cell_list.num++;
1747EEMUMTSINTRA_EXIT:
1748 free(free_ptr);
1749 }
1750 }
1751 /*
1752 // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1753 +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1754 */
1755 else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
1756 {
1757 // lac, ci, arfcn
1758 if(cell_info.running) {
1759 int tmp_int;
1760 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001761 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001762 char* free_ptr = tmp_s;
1763 char *line = tmp_s;
1764 if (at_tok_start(&line) < 0)
1765 {
1766 goto EEMUMTSINTERRAT_EXIT;
1767 }
1768 // Jump 7 integer.
1769 i = 0;
1770 while(i < 7) {
1771 if (at_tok_nextint(&line, &tmp_int) < 0)
1772 {
1773 goto EEMUMTSINTERRAT_EXIT;
1774 }
1775 i++;
1776 }
1777
1778 // lac
1779 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1780 {
1781 goto EEMUMTSINTERRAT_EXIT;
1782 }
1783 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1784
1785 // ci
1786 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1787 {
1788 goto EEMUMTSINTERRAT_EXIT;
1789 }
1790 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1791
1792 // arfcn
1793 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1794 {
1795 goto EEMUMTSINTERRAT_EXIT;
1796 }
1797 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1798
1799 cell_info.cell_list.num++;
1800EEMUMTSINTERRAT_EXIT:
1801 free(free_ptr);
1802 }
1803 }
1804 // GSM
1805 // +EEMGINFOBASIC: 2
1806 // Do nothing.
1807 else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
1808 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1809 {
1810 if(cell_info.running) {
1811
1812 }
1813 }
1814 /*
1815 // mcc, mnc_len, mnc, lac, ci, nom, nco,
1816 // bsic, C1, C2, TA, TxPwr,
1817 // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1818 // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1819 // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1820 // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1821 // gsmBand,channelMode
1822 +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
1823 63, 36, 146, 1, 7,
1824 46, 42, 42, 7, 0,
1825 53, 0, 8, 0, 1, 6, 53,
1826 2, 0, 146, 42, 54, 0, 1,
1827 1, 32, 0, 0, 0, 0,
1828 0, 0
1829 */
1830 else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
1831 {
1832 // lac, ci, arfcn, bsic
1833 LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
1834 if(cell_info.running) {
1835 int tmp_int;
1836 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001837 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001838 char* free_ptr = tmp_s;
1839 char *line = tmp_s;
1840 if (at_tok_start(&line) < 0)
1841 {
1842 goto EEMGINFOSVC_EXIT;
1843 }
1844
1845 // mcc
1846 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1847 {
1848 goto EEMGINFOSVC_EXIT;
1849 }
1850 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1851
1852 //mnc_len
1853 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1854 {
1855 goto EEMGINFOSVC_EXIT;
1856 }
1857 // mnc
1858 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
1859 {
1860 goto EEMGINFOSVC_EXIT;
1861 }
1862 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1863
1864 /*
1865 // Jump 3 integer.
1866 i = 0;
1867 while(i < 3) {
1868 if (at_tok_nextint(&line, &tmp_int) < 0)
1869 {
1870 goto EEMGINFOSVC_EXIT;
1871 }
1872 i++;
1873 }
1874 */
1875 // lac
1876 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1877 {
1878 goto EEMGINFOSVC_EXIT;
1879 }
1880 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1881
1882 // ci
1883 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1884 {
1885 goto EEMGINFOSVC_EXIT;
1886 }
1887 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
1888
1889 // Jump 2 integer.
1890 i = 0;
1891 while(i < 2) {
1892 if (at_tok_nextint(&line, &tmp_int) < 0)
1893 {
1894 goto EEMGINFOSVC_EXIT;
1895 }
1896 i++;
1897 }
1898
1899 // bsic
1900 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1901 {
1902 goto EEMGINFOSVC_EXIT;
1903 }
1904 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
1905
1906 // Jump 15 integer.
1907 i = 0;
1908 while(i < 15) {
1909 if (at_tok_nextint(&line, &tmp_int) < 0)
1910 {
1911 goto EEMGINFOSVC_EXIT;
1912 }
1913 i++;
1914 }
1915
1916 // arfcn
1917 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1918 {
1919 goto EEMGINFOSVC_EXIT;
1920 }
1921 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
1922
1923 cell_info.cell_list.num++;
1924EEMGINFOSVC_EXIT:
1925 free(free_ptr);
1926 }
1927 }
1928 /*
1929 // PS_attached, attach_type, service_type, tx_power, c_value,
1930 // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1931 // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1932 // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1933 +EEMGINFOPS: 1, 255, 0, 0, 0,
1934 0, 0, 268435501, 1, 0, 0,
1935 4, 0, 96, 0, 0, 0,
1936 0, 0, 0, 65535, 0, 13350
1937 */
1938 // Do nothing.
1939 else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
1940 {
1941 if(cell_info.running) {
1942
1943 }
1944 }
1945 else if(strStartsWith(s, "+EEMGINFONC:")) // cell
1946 {
1947 if(cell_info.running) {
1948 int tmp_int;
1949 int i = 0;
b.liufd87baf2024-11-15 15:30:38 +08001950 char* tmp_s = memdup(s,strlen(s) + 1);
b.liub4772072024-08-15 14:47:03 +08001951 char* free_ptr = tmp_s;
1952 char *line = tmp_s;
1953 if (at_tok_start(&line) < 0)
1954 {
1955 goto EEMGINFOPS_EXIT;
1956 }
1957
1958 // nc_num
1959 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1960 {
1961 LOG("cell_info.running 1= %d\n.",cell_info.running);
1962 goto EEMGINFOPS_EXIT;
1963 }
1964 // mcc
1965 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1966 {
1967 LOG("cell_info.running 2= %d\n.",cell_info.running);
1968 goto EEMGINFOPS_EXIT;
1969 }
1970 cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
1971
1972 // mnc
1973 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1974 {
1975 LOG("cell_info.running 3= %d\n.",cell_info.running);
1976 goto EEMGINFOPS_EXIT;
1977 }
1978 cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
1979
1980 // lac
1981 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1982 {
1983 LOG("cell_info.running 4= %d\n.",cell_info.running);
1984 goto EEMGINFOPS_EXIT;
1985 }
1986 cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
1987
1988 // rac
1989 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1990 {
1991 LOG("cell_info.running 5= %d\n.",cell_info.running);
1992 goto EEMGINFOPS_EXIT;
1993 }
1994
1995 // ci
1996 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
1997 {
1998 LOG("cell_info.running 6= %d\n.",cell_info.running);
1999 goto EEMGINFOPS_EXIT;
2000 }
2001 cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
2002
2003 // rx_lv
2004 if (at_tok_nextint(&line, &tmp_int) < 0)
2005 {
2006 LOG("cell_info.running 7= %d\n.",cell_info.running);
2007 goto EEMGINFOPS_EXIT;
2008 }
2009
2010 // bsic
2011 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
2012 {
2013 LOG("cell_info.running 8= %d\n.",cell_info.running);
2014 goto EEMGINFOPS_EXIT;
2015 }
2016 cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
2017
2018 // Jump 2 integer.
2019 i = 0;
2020 while(i < 2) {
2021 if (at_tok_nextint(&line, &tmp_int) < 0)
2022 {
2023 LOG("cell_info.running 9= %d\n.",cell_info.running);
2024 goto EEMGINFOPS_EXIT;
2025 }
2026 i++;
2027 }
2028
2029 // arfcn
2030 if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
2031 {
2032 LOG("cell_info.running 10 = %d\n.",cell_info.running);
2033 goto EEMGINFOPS_EXIT;
2034 }
2035 cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
2036
2037 cell_info.cell_list.num++;
2038EEMGINFOPS_EXIT:
2039 free(free_ptr);
2040 }
2041 } else {
2042 LOGW("Unknown CELL URC : %s", s);
2043 }
2044}
2045
b.liu87afc4c2024-08-14 17:33:45 +08002046
b.liu7ca612c2025-04-25 09:23:36 +08002047static void onUnsolicited(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
b.liu87afc4c2024-08-14 17:33:45 +08002048{
b.liufd87baf2024-11-15 15:30:38 +08002049 LOGV("URC : %s", s);
b.liu87afc4c2024-08-14 17:33:45 +08002050 // MBTK_AT_READY
b.liuaced4f92024-12-31 11:14:51 +08002051 // +CMT: ,23
2052 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
2053 // Get PDU data.
2054 if(cmt_found) {
2055 cmt_found = FALSE;
b.liu7ca612c2025-04-25 09:23:36 +08002056 urc_sms_state_change_process(sim_id, s, true);
b.liuaced4f92024-12-31 11:14:51 +08002057 } else if (strStartsWith(s, "MBTK_AT_READY")) { // AT ready.
b.liu87afc4c2024-08-14 17:33:45 +08002058
b.liubcf86c92024-08-19 19:48:28 +08002059 } else if(strStartsWith(s, "CONNECT") || strStartsWith(s, "+CGEV:")) {
b.liu7ca612c2025-04-25 09:23:36 +08002060 urc_pdp_state_change_process(sim_id, s, sms_pdu);
b.liubeb61cc2025-02-13 10:38:29 +08002061 } else if(strStartsWith(s, "+EEMNRSVC:") || strStartsWith(s, "+EEMNRINTER:")
2062 || strStartsWith(s, "+EEMNRINTERRAT:")
2063 || strStartsWith(s, "+EEMLTESVC:") || strStartsWith(s, "+EEMLTEINTER:")
b.liubcf86c92024-08-19 19:48:28 +08002064 || strStartsWith(s, "+EEMLTEINTRA:") || strStartsWith(s, "+EEMLTEINTERRAT:")
2065 || strStartsWith(s, "+EEMUMTSSVC:") || strStartsWith(s, "+EEMUMTSINTRA:")
2066 || strStartsWith(s, "+EEMUMTSINTERRAT:") || strStartsWith(s, "+EEMGINFOBASIC:")
2067 || strStartsWith(s, "+EEMGINFOSVC:") || strStartsWith(s, "+EEMGINFOPS:")
2068 || strStartsWith(s, "+EEMGINFONC:")) {
b.liu7ca612c2025-04-25 09:23:36 +08002069 urc_cell_info_process(sim_id, s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08002070 }
2071 else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
2072 {
2073 const char* ptr = s + strlen("*RADIOPOWER:");
2074 while(*ptr != '\0' && *ptr == ' ' )
2075 {
2076 ptr++;
2077 }
2078
b.liu15f456b2024-10-31 20:16:06 +08002079 mbtk_ril_radio_state_info_t state;
2080 memset(&state, 0, sizeof(mbtk_ril_radio_state_info_t));
b.liu7ca612c2025-04-25 09:23:36 +08002081 state.sim_id = sim_id;
b.liu87afc4c2024-08-14 17:33:45 +08002082 if(*ptr == '1') {
b.liu15f456b2024-10-31 20:16:06 +08002083 state.radio_state = MBTK_RADIO_STATE_FULL_FUNC;
b.liu87afc4c2024-08-14 17:33:45 +08002084 } else {
b.liu15f456b2024-10-31 20:16:06 +08002085 state.radio_state = MBTK_RADIO_STATE_MINI_FUNC;
b.liu87afc4c2024-08-14 17:33:45 +08002086 }
b.liu15f456b2024-10-31 20:16:06 +08002087 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 +08002088 }
2089 // +CREG: 1, "8010", "000060a5", 0, 2, 0
2090 // +CREG: 1, "8330", "06447347", 7, 2, 0
2091 // +CEREG: 1, "8330", "06447347", 7
2092 // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
2093 // $CREG: 1, "8010", "000060a7", 0,, 2, 0
2094 // +CGREG: 1
b.liubeb61cc2025-02-13 10:38:29 +08002095 // +C5GREG: 1,"00280386","07e920010",11,1,"01"
b.liu87afc4c2024-08-14 17:33:45 +08002096 else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
b.liu15f456b2024-10-31 20:16:06 +08002097 || strStartsWith(s, "+CEREG:") // LTE data registed.
b.liubeb61cc2025-02-13 10:38:29 +08002098 || strStartsWith(s, "+CREG:") // GMS/WCDMA/LTE CS registed.
2099 || strStartsWith(s, "+C5GREG:")) // NR data registed.
b.liu87afc4c2024-08-14 17:33:45 +08002100 {
b.liu7ca612c2025-04-25 09:23:36 +08002101 urc_net_reg_state_change_process(sim_id, s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08002102 }
b.liu15f456b2024-10-31 20:16:06 +08002103 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
2104 else if(strStartsWith(s, "+CLCC:")
2105 || strStartsWith(s, "+CPAS:")
2106 || strStartsWith(s, "+CALLDISCONNECT:"))
b.liu87afc4c2024-08-14 17:33:45 +08002107 {
b.liu7ca612c2025-04-25 09:23:36 +08002108 urc_call_state_change_process(sim_id, s, sms_pdu);
b.liu87afc4c2024-08-14 17:33:45 +08002109 }
b.liu15f456b2024-10-31 20:16:06 +08002110 else if(strStartsWith(s, "*SIMDETEC:")
2111 || strStartsWith(s, "*EUICC:")
2112 || strStartsWith(s, "+CPIN:"))
2113 {
b.liu7ca612c2025-04-25 09:23:36 +08002114 urc_sim_state_change_process(sim_id, s, sms_pdu);
b.liu15f456b2024-10-31 20:16:06 +08002115 }
2116 else if(strStartsWith(s, "+CMT:"))
2117 {
b.liuaced4f92024-12-31 11:14:51 +08002118 cmt_found = TRUE;
b.liu7ca612c2025-04-25 09:23:36 +08002119 urc_sms_state_change_process(sim_id, s, false);
b.liu15f456b2024-10-31 20:16:06 +08002120 }
b.liu29ead772025-05-26 17:51:20 +08002121 else if(strStartsWith(s, "*ECALLDATA:")
2122 || strStartsWith(s, "+ECALLDIALRETRY:"))
b.liu15f456b2024-10-31 20:16:06 +08002123 {
b.liu7ca612c2025-04-25 09:23:36 +08002124 urc_ecall_state_change_process(sim_id, s, sms_pdu);
b.liu15f456b2024-10-31 20:16:06 +08002125 }
2126#if 0
b.liu87afc4c2024-08-14 17:33:45 +08002127 // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
2128 else if(strStartsWith(s, "+CLCC:"))
2129 {
2130 mbtk_call_info_t reg;
2131 reg.call_wait = MBTK_CLCC;
2132 char* tmp_s = memdup(s,strlen(s));
2133 char* free_ptr = tmp_s;
2134 char *line = tmp_s;
2135 int tmp_int;
2136 char *tmp_str;
2137 int err;
2138
2139 err = at_tok_start(&line);
2140 if (err < 0)
2141 {
2142 goto CLCC_EXIT;
2143 }
2144 err = at_tok_nextint(&line, &tmp_int); // dir1
2145 if (err < 0)
2146 {
2147 goto CLCC_EXIT;
2148 }
2149 reg.dir1 = (uint8)tmp_int;
2150 err = at_tok_nextint(&line, &tmp_int);// dir
2151 if (err < 0)
2152 {
2153 goto CLCC_EXIT;
2154 }
2155 reg.dir = (uint8)tmp_int;
2156 err = at_tok_nextint(&line, &tmp_int);// state
2157 if (err < 0)
2158 {
2159 goto CLCC_EXIT;
2160 }
2161 reg.state = (uint8)tmp_int;
2162 err = at_tok_nextint(&line, &tmp_int);// mode
2163 if (err < 0)
2164 {
2165 goto CLCC_EXIT;
2166 }
2167 reg.mode = (uint8)tmp_int;
2168 err = at_tok_nextint(&line, &tmp_int);// mpty
2169 if (err < 0)
2170 {
2171 goto CLCC_EXIT;
2172 }
2173 reg.mpty = (uint8)tmp_int;
2174 err = at_tok_nextstr(&line, &tmp_str); // phone_number
2175 if (err < 0)
2176 {
2177 goto CLCC_EXIT;
2178 }
2179
2180 memset(reg.phone_number,0,sizeof(reg.phone_number));
2181 memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
2182 err = at_tok_nextint(&line, &tmp_int);// tpye
2183 if (err < 0)
2184 {
2185 goto CLCC_EXIT;
2186 }
2187 reg.type = (uint8)tmp_int;
2188 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
2189CLCC_EXIT:
2190 free(free_ptr);
2191 }
2192 // +CPAS: 4
2193 else if(strStartsWith(s, "+CPAS:"))
2194 {
2195 mbtk_call_info_t reg;
2196 reg.call_wait = 0;
2197 char* tmp_s = memdup(s,strlen(s));
2198 char* free_ptr = tmp_s;
2199 char *line = tmp_s;
2200 int tmp_int;
2201 int err;
2202
2203 memset(&reg,0,sizeof(reg));
2204
2205 err = at_tok_start(&line);
2206 if (err < 0)
2207 {
2208 goto CPAS_EXIT;
2209 }
2210 err = at_tok_nextint(&line, &tmp_int);
2211 if (err < 0)
2212 {
2213 goto CPAS_EXIT;
2214 }
2215 reg.pas = (uint8)tmp_int;
2216 reg.call_wait = MBTK_CPAS;
2217 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
2218CPAS_EXIT:
2219 free(free_ptr);
2220 }
2221 // +CALLDISCONNECT: 1
2222 else if(strStartsWith(s, "+CALLDISCONNECT:"))
2223 {
2224 mbtk_call_info_t reg;
2225 reg.call_wait = 0;
2226 char* tmp_s = memdup(s,strlen(s));
2227 char* free_ptr = tmp_s;
2228 char *line = tmp_s;
2229 int tmp_int;
2230 int err;
2231
2232 memset(&reg,0,sizeof(reg));
2233
2234 err = at_tok_start(&line);
2235 if (err < 0)
2236 {
2237 goto CALLDISCONNECTED_EXIT;
2238 }
2239 err = at_tok_nextint(&line, &tmp_int);
2240 if (err < 0)
2241 {
2242 goto CALLDISCONNECTED_EXIT;
2243 }
2244 reg.disconnected_id = tmp_int;
2245 reg.call_wait = MBTK_DISCONNECTED;
2246
2247 if(reg.call_wait == MBTK_DISCONNECTED)
2248 {
2249 //mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
2250 }
2251
2252 urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, &reg, sizeof(mbtk_call_info_t));
2253
2254CALLDISCONNECTED_EXIT:
2255 free(free_ptr);
2256 }
2257 // *SIMDETEC:1,SIM
2258 else if(strStartsWith(s, "*SIMDETEC:"))
2259 {
2260 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
2261 {
2262 net_info.sim_state = MBTK_SIM_ABSENT;
2263 }
2264
2265 sim_info_reg.sim = -1;
2266 if(strStartsWith(s, "*SIMDETEC:1,NOS"))
2267 sim_info_reg.sim = 0;
2268 else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
2269 sim_info_reg.sim = 1;
2270 if(sim_info_reg.sim == 0)
2271 {
2272 uint8 data_pdp;
2273 data_pdp = 11; //
2274 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
2275 }
2276 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
2277 }
2278 // *EUICC:1
2279/*0: SIM
22801: USIM
22812: TEST SIM
22823: TEST USIM
22834: UNKNOWN
2284Note: *EUICC:
2285*/
2286 else if(strStartsWith(s, "*EUICC:"))
2287 {
2288 sim_info_reg.sim_card_type = -1;
2289 if(strStartsWith(s, "*EUICC: 0"))
2290 sim_info_reg.sim_card_type = 1;
2291 else if(strStartsWith(s, "*EUICC: 1"))
2292 sim_info_reg.sim_card_type = 2;
2293 else if(strStartsWith(s, "*EUICC: 2"))
2294 sim_info_reg.sim_card_type = 1;
2295 else if(strStartsWith(s, "*EUICC: 3"))
2296 sim_info_reg.sim_card_type = 2;
2297 else if(strStartsWith(s, "*EUICC: 4"))
2298 sim_info_reg.sim_card_type = 0;
2299 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
2300 }
2301 // +CPIN: SIM PIN
2302 else if(strStartsWith(s, "+CPIN:"))
2303 {
2304 sim_info_reg.sim = -1;
2305 if(strStartsWith(s, "+CPIN: READY"))
2306 {
2307 sim_info_reg.sim = 1;
2308 net_info.sim_state = MBTK_SIM_READY;
2309 }
2310 else if(strStartsWith(s, "+CPIN: SIM PIN"))
2311 {
2312 sim_info_reg.sim = 2;
2313 net_info.sim_state = MBTK_SIM_PIN;
2314 }
2315 else if(strStartsWith(s, "+CPIN: SIM PUK"))
2316 {
2317 sim_info_reg.sim = 3;
2318 net_info.sim_state = MBTK_SIM_PUK;
2319 }
2320 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
2321 {
2322 sim_info_reg.sim = 4;
2323 net_info.sim_state = MBTK_SIM_ABSENT;
2324 }
2325 else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
2326 {
2327 sim_info_reg.sim = 5;
2328 net_info.sim_state = MBTK_SIM_ABSENT;
2329 }
2330 else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
2331 {
2332 sim_info_reg.sim = 6;
2333 net_info.sim_state = MBTK_SIM_ABSENT;
2334 }
2335 else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
2336 {
2337 sim_info_reg.sim = 7;
2338 net_info.sim_state = MBTK_SIM_ABSENT;
2339 }
2340 else if(strStartsWith(s, "+CPIN: SIM PIN2"))
2341 {
2342 sim_info_reg.sim = 8;
2343 net_info.sim_state = MBTK_SIM_ABSENT;
2344 }
2345 else if(strStartsWith(s, "+CPIN: SIM PUK2"))
2346 {
2347 sim_info_reg.sim = 9;
2348 net_info.sim_state = MBTK_SIM_ABSENT;
2349 }
2350 else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
2351 {
2352 sim_info_reg.sim = 10;
2353 net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
2354 }
2355 else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
2356 {
2357 sim_info_reg.sim = 11;
2358 net_info.sim_state = MBTK_SIM_ABSENT;
2359 }
2360 else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
2361 {
2362 sim_info_reg.sim = 12;
2363 net_info.sim_state = MBTK_SIM_ABSENT;
2364 }
2365 else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
2366 {
2367 sim_info_reg.sim = 13;
2368 net_info.sim_state = MBTK_SIM_ABSENT;
2369 }
2370 else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
2371 {
2372 sim_info_reg.sim = 14;
2373 net_info.sim_state = MBTK_SIM_ABSENT;
2374 }
2375 else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
2376 {
2377 sim_info_reg.sim = 15;
2378 net_info.sim_state = MBTK_SIM_ABSENT;
2379 }
2380 else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
2381 {
2382 sim_info_reg.sim = 16;
2383 net_info.sim_state = MBTK_SIM_ABSENT;
2384 }
2385 else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
2386 {
2387 sim_info_reg.sim = 17;
2388 net_info.sim_state = MBTK_SIM_ABSENT;
2389 }
2390 else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
2391 {
2392 sim_info_reg.sim = 18;
2393 net_info.sim_state = MBTK_SIM_ABSENT;
2394 }
2395 else
2396 sim_info_reg.sim = 20;
2397
2398 if(sim_info_reg.sim == 18)
2399 {
2400 uint8 data_pdp;
2401 data_pdp = 11; //
2402 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
2403 }
2404
2405 urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
2406 }
2407 // +CMT: ,23
2408 // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
2409 else if(strStartsWith(s, "+CMT:") || sms_cmt)
2410 {
2411 if(!sms_cmt){
2412 sms_cmt = true;
2413 }else{
2414 sms_cmt = false;
2415 }
2416 printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
2417 urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
2418 }
b.liub4772072024-08-15 14:47:03 +08002419#endif
b.liu87afc4c2024-08-14 17:33:45 +08002420 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"
2421 {
2422
2423 }
2424 else
2425 {
2426 LOGV("Unknown URC : %s", s);
2427 }
b.liu87afc4c2024-08-14 17:33:45 +08002428}
2429
b.liu7ca612c2025-04-25 09:23:36 +08002430static void onUnsolicited1(const char *s, const char *sms_pdu)
2431{
2432 onUnsolicited(MBTK_SIM_1, s, sms_pdu);
2433}
hong.liu7d2fa902025-07-23 04:41:53 -07002434#ifdef LYNQ_DSDS_SUPPORT
b.liu7ca612c2025-04-25 09:23:36 +08002435static void onUnsolicited2(const char *s, const char *sms_pdu)
2436{
2437 onUnsolicited(MBTK_SIM_2, s, sms_pdu);
2438}
hong.liu7d2fa902025-07-23 04:41:53 -07002439#endif
2440static int openSocket(const char* sockname, bool with_wait)
b.liu87afc4c2024-08-14 17:33:45 +08002441{
2442 int sock = socket(AF_UNIX, SOCK_STREAM, 0);
2443 if (sock < 0)
2444 {
2445 LOGE("Error create socket: %s\n", strerror(errno));
2446 return -1;
2447 }
2448 struct sockaddr_un addr;
2449 memset(&addr, 0, sizeof(addr));
2450 addr.sun_family = AF_UNIX;
2451 strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
hong.liu7d2fa902025-07-23 04:41:53 -07002452 if(with_wait) {
2453 while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
2454 {
2455 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
2456 sleep(1);
2457 }
2458 }
2459 else
b.liu87afc4c2024-08-14 17:33:45 +08002460 {
hong.liu7d2fa902025-07-23 04:41:53 -07002461 if (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
2462 {
2463 LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
2464 // sleep(1);
2465 }
b.liu87afc4c2024-08-14 17:33:45 +08002466 }
2467
2468#if 0
2469 int sk_flags = fcntl(sock, F_GETFL, 0);
2470 fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
2471#endif
2472
2473 return sock;
2474}
2475
b.liu571445f2025-02-13 10:22:55 +08002476static void ril_at_ready_process()
b.liu7ca612c2025-04-25 09:23:36 +08002477{
2478 // SIM1 radio state config.
2479 ril_info.radio_state[MBTK_SIM_1] = ril_radio_state_get(MBTK_SIM_1, ATPORTTYPE_0);
2480 if (ril_info.radio_state[MBTK_SIM_1] != MBTK_RADIO_STATE_FULL_FUNC)
b.liu571445f2025-02-13 10:22:55 +08002481 {
b.liu7ca612c2025-04-25 09:23:36 +08002482 ril_radio_state_set(MBTK_SIM_1, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);
b.liu87afc4c2024-08-14 17:33:45 +08002483 }
b.liu571445f2025-02-13 10:22:55 +08002484
b.liu7ca612c2025-04-25 09:23:36 +08002485 if(ril_info.radio_state[MBTK_SIM_1] == MBTK_RADIO_STATE_FULL_FUNC)
b.liu87afc4c2024-08-14 17:33:45 +08002486 {
b.liu7ca612c2025-04-25 09:23:36 +08002487 at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+CEREG=2", NULL);
2488 }
hong.liu7d2fa902025-07-23 04:41:53 -07002489#ifdef LYNQ_DSDS_SUPPORT
b.liu7ca612c2025-04-25 09:23:36 +08002490 // SIM2 radio state config.
2491 ril_info.radio_state[MBTK_SIM_2] = ril_radio_state_get(MBTK_SIM_2, ATPORTTYPE_0);
2492 if (ril_info.radio_state[MBTK_SIM_2] != MBTK_RADIO_STATE_FULL_FUNC)
b.liu571445f2025-02-13 10:22:55 +08002493 {
b.liu7ca612c2025-04-25 09:23:36 +08002494 ril_radio_state_set(MBTK_SIM_2, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);
2495 }
2496
2497 if(ril_info.radio_state[MBTK_SIM_2] == MBTK_RADIO_STATE_FULL_FUNC)
2498 {
2499 at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+CEREG=2", NULL);
2500 }
hong.liu7d2fa902025-07-23 04:41:53 -07002501#endif
b.liu7ca612c2025-04-25 09:23:36 +08002502 // SIM1 state config.
2503 ril_info.sim_state[MBTK_SIM_1] = ril_sim_state_get(MBTK_SIM_1, ATPORTTYPE_0);
2504 if(ril_info.sim_state[MBTK_SIM_1] == MBTK_SIM_STATE_READY)
2505 {
2506 LOGD("SIM1 READY!");
2507 at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+COPS=3", NULL);
b.liu87afc4c2024-08-14 17:33:45 +08002508
2509 // Set APN from prop.
b.liu7ca612c2025-04-25 09:23:36 +08002510 apn_auto_conf_from_prop(MBTK_SIM_1, ATPORTTYPE_0);
b.liu571445f2025-02-13 10:22:55 +08002511 }
2512 else
2513 {
b.liu7ca612c2025-04-25 09:23:36 +08002514 LOGE("SIM1 NOT READY!");
2515 }
hong.liu7d2fa902025-07-23 04:41:53 -07002516#ifdef LYNQ_DSDS_SUPPORT
b.liu7ca612c2025-04-25 09:23:36 +08002517 // SIM2 state config.
2518 ril_info.sim_state[MBTK_SIM_2] = ril_sim_state_get(MBTK_SIM_2, ATPORTTYPE_0);
2519 if(ril_info.sim_state[MBTK_SIM_2] == MBTK_SIM_STATE_READY)
2520 {
hong.liu7d2fa902025-07-23 04:41:53 -07002521 LOGD("SIM2 READY!");
b.liu7ca612c2025-04-25 09:23:36 +08002522 at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+COPS=3", NULL);
2523
2524 // Set APN from prop.
2525 apn_auto_conf_from_prop(MBTK_SIM_2, ATPORTTYPE_0);
2526 }
2527 else
2528 {
hong.liu7d2fa902025-07-23 04:41:53 -07002529 LOGE("SIM2 NOT READY!");
b.liu7ca612c2025-04-25 09:23:36 +08002530 }
hong.liu7d2fa902025-07-23 04:41:53 -07002531#endif
b.liu7ca612c2025-04-25 09:23:36 +08002532 if(req_dual_sim_get(ATPORTTYPE_0, &(ril_info.cur_sim_id), NULL)) {
2533 LOGE("req_dual_sim_get() fail, so set to SIM1.");
2534 ril_info.cur_sim_id = MBTK_SIM_1;
2535 } else {
2536 LOGD("Current SIM : %d", ril_info.cur_sim_id);
b.liu87afc4c2024-08-14 17:33:45 +08002537 }
2538}
2539
2540static void ind_regisger(sock_cli_info_t* cli_info, uint16 ind)
b.liu571445f2025-02-13 10:22:55 +08002541{
2542 uint32 i = 0;
2543 while(i < cli_info->ind_num)
2544 {
2545 if(cli_info->ind_register[i] == ind)
2546 break;
2547 i++;
2548 }
2549
2550 if(i == cli_info->ind_num) // No found IND
2551 {
2552 cli_info->ind_register[i] = ind;
2553 cli_info->ind_num++;
b.liu87afc4c2024-08-14 17:33:45 +08002554 LOGD("Register IND : %s", id2str(ind));
b.liu571445f2025-02-13 10:22:55 +08002555 }
2556 else
2557 {
b.liu87afc4c2024-08-14 17:33:45 +08002558 LOGW("IND had exist.");
b.liu571445f2025-02-13 10:22:55 +08002559 }
b.liu87afc4c2024-08-14 17:33:45 +08002560}
2561
b.liu571445f2025-02-13 10:22:55 +08002562// Process AT URC data
b.liu87afc4c2024-08-14 17:33:45 +08002563static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack)
b.liub171c9a2024-11-12 19:23:29 +08002564{
2565 if(cli_info) {
2566 if(ril_info.msg_queue[cli_info->port].count >= PACK_PROCESS_QUEUE_MAX)
2567 {
2568 LOGE("Packet process queue is full");
2569 return -1;
2570 }
2571 } else {
2572 if(ril_info.msg_queue[ATPORTTYPE_0].count >= PACK_PROCESS_QUEUE_MAX)
2573 {
2574 LOGE("Packet process queue is full");
2575 return -1;
2576 }
2577 }
b.liu571445f2025-02-13 10:22:55 +08002578
b.liu87afc4c2024-08-14 17:33:45 +08002579 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 +08002580 if(!item)
2581 {
b.liu87afc4c2024-08-14 17:33:45 +08002582 LOGE("malloc() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08002583 return -1;
2584 }
2585 item->cli_info = cli_info;
b.liub171c9a2024-11-12 19:23:29 +08002586 item->pack = pack;
2587
2588 if(cli_info) {
2589 mbtk_queue_put(&(ril_info.msg_queue[cli_info->port]), item);
2590
2591 // If thread is waitting,continue it.
2592 pthread_mutex_lock(&(ril_info.msg_mutex[cli_info->port]));
2593 pthread_cond_signal(&(ril_info.msg_cond[cli_info->port]));
2594 pthread_mutex_unlock(&(ril_info.msg_mutex[cli_info->port]));
2595 } else { // URC message, is null.
2596 mbtk_queue_put(&(ril_info.msg_queue[ATPORTTYPE_0]), item);
2597
2598 // If thread is waitting,continue it.
2599 pthread_mutex_lock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
2600 pthread_cond_signal(&(ril_info.msg_cond[ATPORTTYPE_0]));
2601 pthread_mutex_unlock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
2602 }
b.liu571445f2025-02-13 10:22:55 +08002603
2604 return 0;
b.liu87afc4c2024-08-14 17:33:45 +08002605}
2606
2607
2608static void pack_distribute(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
b.liu571445f2025-02-13 10:22:55 +08002609{
2610 // Register IND Message.
b.liu15f456b2024-10-31 20:16:06 +08002611 if(pack->msg_type == RIL_MSG_TYPE_REQ)
2612 {
2613 if(pack->msg_id > RIL_MSG_ID_IND_BEGIN
2614 && pack->msg_id < RIL_MSG_ID_IND_END) {
2615 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
2616 if(cli_info->ind_num >= IND_REGISTER_MAX)
2617 {
2618 LOGE("IND if full.");
2619 err = MBTK_RIL_ERR_IND_FULL;
2620 }
2621 else
2622 {
2623 ind_regisger(cli_info, pack->msg_id);
2624 }
2625
b.liu7ca612c2025-04-25 09:23:36 +08002626 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 +08002627
2628 ril_msg_pack_free(pack);
2629 } else {
b.liub171c9a2024-11-12 19:23:29 +08002630 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 +08002631 if(0 && pack->data_len > 0)
2632 {
2633 log_hex("DATA", pack->data, pack->data_len);
2634 }
2635
2636 // Send to REQ_process_thread process.
2637 send_pack_to_queue(cli_info, pack);
2638
2639 // For test.
2640 // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS);
2641 }
2642 } else {
2643 LOGE("Pack type error : %d", pack->msg_type);
2644 }
b.liu87afc4c2024-08-14 17:33:45 +08002645}
2646
b.liu571445f2025-02-13 10:22:55 +08002647// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
2648// Otherwise, do not call pack_error_send().
b.liu87afc4c2024-08-14 17:33:45 +08002649static 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 +08002650{
b.liu87afc4c2024-08-14 17:33:45 +08002651 if(pack->msg_id > RIL_MSG_ID_DEV_BEGIN && pack->msg_id < RIL_MSG_ID_DEV_END) {
2652 return dev_pack_req_process(cli_info, pack);
2653 } else if(pack->msg_id > RIL_MSG_ID_SIM_BEGIN && pack->msg_id < RIL_MSG_ID_SIM_END) {
2654 return sim_pack_req_process(cli_info, pack);
2655 } else if(pack->msg_id > RIL_MSG_ID_NET_BEGIN && pack->msg_id < RIL_MSG_ID_NET_END) {
2656 return net_pack_req_process(cli_info, pack);
b.liu15f456b2024-10-31 20:16:06 +08002657 } else if(pack->msg_id > RIL_MSG_ID_DATA_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_DATA_CALL_END) {
2658 return data_call_pack_req_process(cli_info, pack);
b.liu87afc4c2024-08-14 17:33:45 +08002659 } else if(pack->msg_id > RIL_MSG_ID_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_CALL_END) {
2660 return call_pack_req_process(cli_info, pack);
2661 } else if(pack->msg_id > RIL_MSG_ID_SMS_BEGIN && pack->msg_id < RIL_MSG_ID_SMS_END) {
2662 return sms_pack_req_process(cli_info, pack);
2663 } else if(pack->msg_id > RIL_MSG_ID_PB_BEGIN && pack->msg_id < RIL_MSG_ID_PB_END) {
2664 return pb_pack_req_process(cli_info, pack);
b.liu15f456b2024-10-31 20:16:06 +08002665 } else if(pack->msg_id > RIL_MSG_ID_ECALL_BEGIN && pack->msg_id < RIL_MSG_ID_ECALL_END) {
2666 return ecall_pack_req_process(cli_info, pack);
b.liu87afc4c2024-08-14 17:33:45 +08002667 } else {
2668 LOGW("Unknown msg id : %d", pack->msg_id);
2669 return MBTK_RIL_ERR_FORMAT;
2670 }
2671}
2672
2673static void urc_msg_process(ril_urc_msg_info_t *msg)
b.liu571445f2025-02-13 10:22:55 +08002674{
b.liu472cfaf2024-12-19 19:08:19 +08002675 // data can be NULL (For RIL_URC_MSG_BAND_SET)
b.liu15f456b2024-10-31 20:16:06 +08002676 if(!msg->data || msg->data_len <= 0) {
b.liu472cfaf2024-12-19 19:08:19 +08002677 LOGW("URC data is NULL.");
2678 // return;
b.liu15f456b2024-10-31 20:16:06 +08002679 }
2680
b.liu571445f2025-02-13 10:22:55 +08002681 switch(msg->msg) {
b.liu15f456b2024-10-31 20:16:06 +08002682 case RIL_MSG_ID_IND_RADIO_STATE_CHANGE:
2683 {
2684 mbtk_ril_radio_state_info_t *state = (mbtk_ril_radio_state_info_t*)msg->data;
2685 LOGD("Radio state : %d", state->radio_state);
b.liu571445f2025-02-13 10:22:55 +08002686 break;
b.liu15f456b2024-10-31 20:16:06 +08002687 }
b.liufd87baf2024-11-15 15:30:38 +08002688 case RIL_MSG_ID_IND_SIM_STATE_CHANGE:
2689 {
2690 mbtk_ril_sim_state_info_t *state = (mbtk_ril_sim_state_info_t*)msg->data;
2691 if(state->sim_state == MBTK_SIM_STATE_READY) {
2692 LOGD("SIM READY!");
2693 at_send_command(ATPORTTYPE_0, "AT+COPS=3", NULL);
2694
2695 // Set APN from prop.
b.liu7ca612c2025-04-25 09:23:36 +08002696 apn_auto_conf_from_prop(state->sim_id, ATPORTTYPE_0);
b.liufd87baf2024-11-15 15:30:38 +08002697 }
2698 }
b.liuafdf2c62024-11-12 11:10:44 +08002699 case RIL_MSG_ID_IND_NET_REG_STATE_CHANGE:
2700 {
2701 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 +08002702 data_call_retry(reg_state->sim_id, ATPORTTYPE_0, reg_state);
b.liuafdf2c62024-11-12 11:10:44 +08002703 break;
2704 }
b.liu472cfaf2024-12-19 19:08:19 +08002705 case RIL_URC_MSG_BAND_SET:
2706 {
2707 int cme_err = MBTK_RIL_ERR_CME_NON;
b.liu7ca612c2025-04-25 09:23:36 +08002708 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 +08002709 {
b.liu7ca612c2025-04-25 09:23:36 +08002710 LOGE("Set SIM1 band fail.");
b.liu472cfaf2024-12-19 19:08:19 +08002711 }
2712 else // Set band success.
2713 {
b.liu7ca612c2025-04-25 09:23:36 +08002714 LOGD("Set SIM1 band success.");
hong.liu7d2fa902025-07-23 04:41:53 -07002715 #ifdef LYNQ_DSDS_SUPPORT
b.liu7ca612c2025-04-25 09:23:36 +08002716 cme_err = MBTK_RIL_ERR_CME_NON;
2717 if(req_band_set(MBTK_SIM_2, ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2718 {
2719 LOGE("Set SIM2 band fail.");
b.liu472cfaf2024-12-19 19:08:19 +08002720 }
b.liu7ca612c2025-04-25 09:23:36 +08002721 else // Set band success.
2722 {
2723 LOGD("Set SIM2 band success.");
2724 // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));
hong.liu7d2fa902025-07-23 04:41:53 -07002725 #endif
b.liu7ca612c2025-04-25 09:23:36 +08002726 band_info.band_set_success = TRUE;
2727 if(band_info.band_area == MBTK_MODEM_BAND_AREA_CN) {
2728 property_set("persist.mbtk.band_config", "CN");
2729 } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_EU) {
2730 property_set("persist.mbtk.band_config", "EU");
2731 } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_SA) {
2732 property_set("persist.mbtk.band_config", "SA");
2733 } else {
2734 property_set("persist.mbtk.band_config", "ALL");
2735 }
hong.liu7d2fa902025-07-23 04:41:53 -07002736 #ifdef LYNQ_DSDS_SUPPORT
b.liu7ca612c2025-04-25 09:23:36 +08002737 }
hong.liu7d2fa902025-07-23 04:41:53 -07002738 #endif
b.liu472cfaf2024-12-19 19:08:19 +08002739 }
2740 break;
2741 }
b.liu571445f2025-02-13 10:22:55 +08002742 default:
2743 {
2744 LOGE("Unknown URC : %d", msg->msg);
2745 break;
2746 }
2747 }
b.liu87afc4c2024-08-14 17:33:45 +08002748}
2749
2750// Read client conn/msg and push into ril_info.msg_queue.
2751static void* ril_read_pthread(void* arg)
b.liu571445f2025-02-13 10:22:55 +08002752{
2753 UNUSED(arg);
b.liu87afc4c2024-08-14 17:33:45 +08002754 ril_info.epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1);
2755 if(ril_info.epoll_fd < 0)
b.liu571445f2025-02-13 10:22:55 +08002756 {
b.liu87afc4c2024-08-14 17:33:45 +08002757 LOGE("epoll_create() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08002758 return NULL;
2759 }
2760
2761 uint32 event = EPOLLIN | EPOLLET;
2762 struct epoll_event ev;
b.liu87afc4c2024-08-14 17:33:45 +08002763 ev.data.fd = ril_info.sock_listen_fd;
b.liu571445f2025-02-13 10:22:55 +08002764 ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
b.liu87afc4c2024-08-14 17:33:45 +08002765 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, ril_info.sock_listen_fd, &ev);
b.liu571445f2025-02-13 10:22:55 +08002766
2767 int nready = -1;
2768 struct epoll_event epoll_events[EPOLL_LISTEN_MAX];
2769 while(1)
2770 {
b.liu87afc4c2024-08-14 17:33:45 +08002771 nready = epoll_wait(ril_info.epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
b.liu571445f2025-02-13 10:22:55 +08002772 if(nready > 0)
2773 {
b.liu87afc4c2024-08-14 17:33:45 +08002774 sock_cli_info_t *cli_info = NULL;
b.liu571445f2025-02-13 10:22:55 +08002775 int i;
2776 for(i = 0; i < nready; i++)
2777 {
2778 LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events);
2779 if(epoll_events[i].events & EPOLLHUP) // Client Close.
2780 {
2781 if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL)
2782 {
2783 cli_close(cli_info);
2784 }
2785 else
2786 {
2787 LOG("Unknown client[fd = %d].", epoll_events[i].data.fd);
2788 }
2789 }
2790 else if(epoll_events[i].events & EPOLLIN)
2791 {
b.liu87afc4c2024-08-14 17:33:45 +08002792 if(epoll_events[i].data.fd == ril_info.sock_listen_fd) // New clients connected.
b.liu571445f2025-02-13 10:22:55 +08002793 {
2794 int client_fd = -1;
2795 while(1)
2796 {
2797 struct sockaddr_in cliaddr;
2798 socklen_t clilen = sizeof(cliaddr);
2799 client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen);
2800 if(client_fd < 0)
2801 {
2802 if(errno == EAGAIN)
2803 {
2804 LOG("All client connect get.");
2805 }
2806 else
2807 {
2808 LOG("accept() error[%d].", errno);
2809 }
2810 break;
2811 }
2812 // Set O_NONBLOCK
2813 int flags = fcntl(client_fd, F_GETFL, 0);
2814 if (flags > 0)
2815 {
2816 flags |= O_NONBLOCK;
2817 if (fcntl(client_fd, F_SETFL, flags) < 0)
2818 {
2819 LOG("Set flags error:%d", errno);
2820 }
2821 }
2822
2823 memset(&ev,0,sizeof(struct epoll_event));
2824 ev.data.fd = client_fd;
2825 ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET;
b.liu87afc4c2024-08-14 17:33:45 +08002826 epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, client_fd, &ev);
b.liu571445f2025-02-13 10:22:55 +08002827
b.liu87afc4c2024-08-14 17:33:45 +08002828 sock_cli_info_t *info = (sock_cli_info_t*)malloc(sizeof(sock_cli_info_t));
b.liu571445f2025-02-13 10:22:55 +08002829 if(info)
2830 {
b.liu87afc4c2024-08-14 17:33:45 +08002831 memset(info, 0, sizeof(sock_cli_info_t));
2832 info->fd = client_fd;
b.liub171c9a2024-11-12 19:23:29 +08002833
2834 // Default AT port.
2835 info->port = ATPORTTYPE_0;
b.liu7ca612c2025-04-25 09:23:36 +08002836 info->sim_id = MBTK_SIM_1;
b.liub171c9a2024-11-12 19:23:29 +08002837
b.liu87afc4c2024-08-14 17:33:45 +08002838 list_add(ril_info.sock_client_list, info);
2839 LOG("Add New Client FD Into List.");
2840
b.liu15f456b2024-10-31 20:16:06 +08002841 // Send msg RIL_MSG_ID_IND_SER_STATE_CHANGE to client.
2842 mbtk_ril_ser_state_enum state = MBTK_RIL_SER_STATE_READY;
b.liu7ca612c2025-04-25 09:23:36 +08002843 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 +08002844 }
2845 else
2846 {
2847 LOG("malloc() fail.");
2848 }
2849 }
2850 }
2851 else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive.
2852 {
2853 // Read and process every message.
b.liu87afc4c2024-08-14 17:33:45 +08002854 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
2855 ril_msg_pack_info_t** pack = ril_pack_recv(cli_info->fd, true, &err);
b.liub171c9a2024-11-12 19:23:29 +08002856
b.liu571445f2025-02-13 10:22:55 +08002857 // Parse packet error,send error response to client.
2858 if(pack == NULL)
2859 {
b.liu7ca612c2025-04-25 09:23:36 +08002860 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 +08002861 }
2862 else
2863 {
b.liu87afc4c2024-08-14 17:33:45 +08002864 ril_msg_pack_info_t** pack_ptr = pack;
b.liu571445f2025-02-13 10:22:55 +08002865 while(*pack_ptr)
b.liub171c9a2024-11-12 19:23:29 +08002866 {
2867 // Update AT port in the first.
2868 cli_info->port = (ATPortType_enum)((*pack_ptr)->at_port);
b.liu7ca612c2025-04-25 09:23:36 +08002869 cli_info->sim_id = (mbtk_sim_type_enum)((*pack_ptr)->sim_id);
hong.liu7d2fa902025-07-23 04:41:53 -07002870 #ifndef LYNQ_DSDS_SUPPORT
2871 if(cli_info->sim_id == MBTK_SIM_2)
2872 {
2873 ril_error_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd,(*pack_ptr)->msg_id , (*pack_ptr)->msg_index, MBTK_RIL_ERR_UNSUPPORTED);
b.liu7ca612c2025-04-25 09:23:36 +08002874 }
hong.liu7d2fa902025-07-23 04:41:53 -07002875 else
2876 #endif
2877 {
2878 if(cli_info->sim_id == MBTK_SIM_AUTO) {
2879 cli_info->sim_id = ril_info.cur_sim_id;
2880 LOGD("Auto sim => %d", cli_info->sim_id);
2881 }
b.liub171c9a2024-11-12 19:23:29 +08002882
hong.liu7d2fa902025-07-23 04:41:53 -07002883 pack_distribute(cli_info, *pack_ptr);
2884 // Not free,will free in pack_process() or packet process thread.
2885 //mbtk_info_pack_free(pack_ptr);
2886 }
b.liu571445f2025-02-13 10:22:55 +08002887 pack_ptr++;
2888 }
2889
2890 free(pack);
2891 }
2892 }
2893 else
2894 {
2895 LOG("Unknown socket : %d", epoll_events[i].data.fd);
2896 }
2897 }
2898 else
2899 {
2900 LOG("Unknown event : %x", epoll_events[i].events);
2901 }
2902 }
2903 }
2904 else
2905 {
2906 LOG("epoll_wait() fail[%d].", errno);
2907 }
2908 }
2909
2910 return NULL;
b.liu87afc4c2024-08-14 17:33:45 +08002911}
2912
b.liubeb61cc2025-02-13 10:38:29 +08002913static void band_support_init()
2914{
2915 mbtk_device_info_modem_t info_modem;
2916 memset(&band_info.band_support, 0, sizeof(mbtk_band_info_t));
2917 memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
b.liubeb61cc2025-02-13 10:38:29 +08002918 if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
2919 LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
2920 band_info.band_area = MBTK_MODEM_BAND_AREA_ALL;
2921#ifdef MBTK_5G_SUPPORT
2922 band_info.band_support.net_pref = MBTK_NET_PREF_LTE_NR_NR_PREF; // 19
2923 band_info.net_support = MBTK_NET_SUPPORT_4G | MBTK_NET_SUPPORT_5G;
2924
2925 band_info.band_support.gsm_band = 0;
2926 band_info.band_support.umts_band = 0;
2927 band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
2928 band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
2929 band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
2930
2931 band_info.band_support.nr_3_band = MBTK_BAND_ALL_NR_3_DEFAULT;
2932 band_info.band_support.nr_2_band = MBTK_BAND_ALL_NR_2_DEFAULT;
2933 band_info.band_support.nr_1_band = MBTK_BAND_ALL_NR_1_DEFAULT;
2934 band_info.band_support.nr_0_band = MBTK_BAND_ALL_NR_0_DEFAULT;
2935#else
2936 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
2937 band_info.net_support = MBTK_NET_SUPPORT_2G | MBTK_NET_SUPPORT_3G | MBTK_NET_SUPPORT_4G;
2938
2939 band_info.band_support.gsm_band = MBTK_BAND_ALL_GSM_DEFAULT;
2940 band_info.band_support.umts_band = MBTK_BAND_ALL_WCDMA_DEFAULT;
2941 band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
2942 band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
2943 band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
2944
2945 band_info.band_support.nr_3_band = 0;
2946 band_info.band_support.nr_2_band = 0;
2947 band_info.band_support.nr_1_band = 0;
2948 band_info.band_support.nr_0_band = 0;
2949#endif
2950 } else {
b.liub7530d22025-06-16 19:49:05 +08002951 if(info_modem.version == DEV_INFO_VERSION_V1) {
2952 band_info.band_area = info_modem.modem.v1.band_area;
2953 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
2954 band_info.band_support.gsm_band = info_modem.modem.v1.band_gsm;
2955 band_info.band_support.umts_band = info_modem.modem.v1.band_wcdma;
2956 band_info.band_support.tdlte_band = info_modem.modem.v1.band_tdlte;
2957 band_info.band_support.fddlte_band = info_modem.modem.v1.band_fddlte;
2958 band_info.band_support.lte_ext_band = info_modem.modem.v1.band_lte_ext;
b.liubeb61cc2025-02-13 10:38:29 +08002959 } else {
b.liub7530d22025-06-16 19:49:05 +08002960 band_info.band_area = info_modem.modem.v2.band_area;
2961 band_info.net_support = info_modem.modem.v2.net_support;
2962 if(info_modem.modem.v2.net_pref < MBTK_NET_PREF_MAX) {
2963 band_info.band_support.net_pref = info_modem.modem.v2.net_pref;
b.liubeb61cc2025-02-13 10:38:29 +08002964 } else {
b.liub7530d22025-06-16 19:49:05 +08002965 if(band_info.net_support & MBTK_NET_SUPPORT_5G) {
2966 band_info.band_support.net_pref = MBTK_NET_PREF_LTE_NR_NR_PREF; // 19
2967 } else {
2968 band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
2969 }
b.liubeb61cc2025-02-13 10:38:29 +08002970 }
b.liub7530d22025-06-16 19:49:05 +08002971 band_info.band_support.gsm_band = info_modem.modem.v2.band_gsm;
2972 band_info.band_support.umts_band = info_modem.modem.v2.band_wcdma;
2973 band_info.band_support.tdlte_band = info_modem.modem.v2.band_tdlte;
2974 band_info.band_support.fddlte_band = info_modem.modem.v2.band_fddlte;
2975 band_info.band_support.lte_ext_band = info_modem.modem.v2.band_lte_ext;
b.liubeb61cc2025-02-13 10:38:29 +08002976
b.liub7530d22025-06-16 19:49:05 +08002977 band_info.band_support.nr_3_band = info_modem.modem.v2.band_nr_3;
2978 band_info.band_support.nr_2_band = info_modem.modem.v2.band_nr_2;
2979 band_info.band_support.nr_1_band = info_modem.modem.v2.band_nr_1;
2980 band_info.band_support.nr_0_band = info_modem.modem.v2.band_nr_0;
2981 }
b.liubeb61cc2025-02-13 10:38:29 +08002982 }
b.liubeb61cc2025-02-13 10:38:29 +08002983}
2984
b.liu571445f2025-02-13 10:22:55 +08002985static void* ril_process_thread(void* arg)
2986{
2987 UNUSED(arg);
2988 ATPortType_enum *port = (ATPortType_enum*)arg;
2989 ril_msg_queue_info_t* item = NULL;
2990
2991 pthread_mutex_lock(&(ril_info.msg_mutex[*port]));
2992 while(TRUE)
2993 {
2994 if(mbtk_queue_empty(&(ril_info.msg_queue[*port])))
2995 {
2996 LOG("[Port-%d]Packet process wait...", *port);
2997 pthread_cond_wait(&(ril_info.msg_cond[*port]), &(ril_info.msg_mutex[*port]));
2998 LOG("[Port-%d]Packet process continue...", *port);
2999 }
3000 else
3001 {
3002 LOG("Packet process queue not empty,continue...");
3003 }
3004
3005 // Process all information request.
3006 mbtk_ril_err_enum err;
3007 while((item = (ril_msg_queue_info_t*)mbtk_queue_get(&(ril_info.msg_queue[*port]))) != NULL)
3008 {
3009 if(item->cli_info) { // REQ form client.
3010 ril_msg_pack_info_t *pack = (ril_msg_pack_info_t*)item->pack;
3011 LOGD("Process REQ %s.", id2str(pack->msg_id));
3012 ril_info.at_process[*port] = true;
3013 err = pack_req_process(item->cli_info, pack);
3014 if(err != MBTK_RIL_ERR_SUCCESS)
3015 {
b.liu7ca612c2025-04-25 09:23:36 +08003016 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 +08003017 }
3018 ril_info.at_process[*port] = false;
3019 ril_msg_pack_free(pack);
3020 free(item);
3021 } else { // REQ from myself.
3022 if(item->pack) {
3023 ril_urc_msg_info_t *urc = (ril_urc_msg_info_t*)item->pack;
3024 LOGD("Process URC %d.", urc->msg);
3025 urc_msg_process(urc);
3026 if(urc->data)
3027 free(urc->data);
3028 free(urc);
3029 }
3030 }
3031 }
3032 }
3033 pthread_mutex_unlock(&(ril_info.msg_mutex[*port]));
3034
3035 free(port);
3036
3037 return NULL;
3038}
3039
3040/*
3041AT*BAND=15,78,147,482,134742231
3042
3043OK
3044*/
3045static void* band_config_thread()
3046{
b.liu571445f2025-02-13 10:22:55 +08003047 band_info.band_set_success = FALSE;
b.liu62240ee2024-11-07 17:52:45 +08003048// bool is_first = TRUE;
b.liu87afc4c2024-08-14 17:33:45 +08003049 while(!band_info.band_set_success) {
3050 // Set band.
b.liu472cfaf2024-12-19 19:08:19 +08003051#if 1
3052 ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
3053 if(msg) {
3054 msg->msg = RIL_URC_MSG_BAND_SET;
3055 msg->data = NULL;//mbtk_memcpy(&band_info, sizeof(ril_band_info_t));
3056 msg->data_len = 0; //sizeof(ril_band_info_t);
b.liu87afc4c2024-08-14 17:33:45 +08003057#if 0
b.liu571445f2025-02-13 10:22:55 +08003058 if(msg->data == NULL) {
3059 LOGE("mbtk_memcpy() fail.");
3060 break;
3061 }
b.liu472cfaf2024-12-19 19:08:19 +08003062#endif
3063 send_pack_to_queue(NULL, msg);
3064
b.liu571445f2025-02-13 10:22:55 +08003065 sleep(5);
b.liu472cfaf2024-12-19 19:08:19 +08003066 } else {
3067 LOG("malloc() fail[%d].", errno);
3068 break;
b.liu87afc4c2024-08-14 17:33:45 +08003069 }
3070#else
3071 sleep(5);
3072#endif
b.liu571445f2025-02-13 10:22:55 +08003073 }
3074
3075 LOGD("Set Band thread exit.");
3076 return NULL;
3077}
b.liu87afc4c2024-08-14 17:33:45 +08003078
3079
3080int ril_server_start()
b.liu571445f2025-02-13 10:22:55 +08003081{
b.liu87afc4c2024-08-14 17:33:45 +08003082 signal(SIGPIPE, SIG_IGN);
3083
3084 memset(&ril_info, 0, sizeof(ril_info_t));
3085 memset(&band_info, 0, sizeof(ril_band_info_t));
3086 memset(&band_info.band_support, 0xFF, sizeof(mbtk_band_info_t));
b.liu571445f2025-02-13 10:22:55 +08003087
3088 //check cfun and sim card status
3089 ril_at_ready_process();
b.liubeb61cc2025-02-13 10:38:29 +08003090
3091 // Init support band.
3092 band_support_init();
b.liu571445f2025-02-13 10:22:55 +08003093
3094 //any AT instruction that is not sent through pack_process_thread needs to precede the thread
3095 //thread create
b.liu87afc4c2024-08-14 17:33:45 +08003096 if(ril_info.sock_listen_fd > 0)
b.liu571445f2025-02-13 10:22:55 +08003097 {
b.liu87afc4c2024-08-14 17:33:45 +08003098 LOGE("Information Server Has Started.");
b.liu571445f2025-02-13 10:22:55 +08003099 return -1;
3100 }
3101
3102 struct sockaddr_un server_addr;
b.liu87afc4c2024-08-14 17:33:45 +08003103 ril_info.sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
3104 if(ril_info.sock_listen_fd < 0)
b.liu571445f2025-02-13 10:22:55 +08003105 {
b.liu87afc4c2024-08-14 17:33:45 +08003106 LOGE("socket() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08003107 return -1;
3108 }
3109
3110 // Set O_NONBLOCK
b.liu87afc4c2024-08-14 17:33:45 +08003111 int flags = fcntl(ril_info.sock_listen_fd, F_GETFL, 0);
b.liu571445f2025-02-13 10:22:55 +08003112 if (flags < 0)
3113 {
b.liu87afc4c2024-08-14 17:33:45 +08003114 LOGE("Get flags error:%d", errno);
b.liu571445f2025-02-13 10:22:55 +08003115 goto error;
3116 }
3117 flags |= O_NONBLOCK;
b.liu87afc4c2024-08-14 17:33:45 +08003118 if (fcntl(ril_info.sock_listen_fd, F_SETFL, flags) < 0)
b.liu571445f2025-02-13 10:22:55 +08003119 {
b.liu87afc4c2024-08-14 17:33:45 +08003120 LOGE("Set flags error:%d", errno);
b.liu571445f2025-02-13 10:22:55 +08003121 goto error;
3122 }
3123
b.liu87afc4c2024-08-14 17:33:45 +08003124 unlink(RIL_SOCK_NAME);
b.liu571445f2025-02-13 10:22:55 +08003125 memset(&server_addr, 0, sizeof(struct sockaddr_un));
3126 server_addr.sun_family = AF_LOCAL;
b.liu87afc4c2024-08-14 17:33:45 +08003127 strcpy(server_addr.sun_path, RIL_SOCK_NAME);
3128 if(bind(ril_info.sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)))
b.liu571445f2025-02-13 10:22:55 +08003129 {
b.liu87afc4c2024-08-14 17:33:45 +08003130 LOGE("bind() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08003131 goto error;
3132 }
3133
b.liu87afc4c2024-08-14 17:33:45 +08003134 if(listen(ril_info.sock_listen_fd, SOCK_CLIENT_MAX))
b.liu571445f2025-02-13 10:22:55 +08003135 {
b.liu87afc4c2024-08-14 17:33:45 +08003136 LOGE("listen() fail[%d].", errno);
b.liu571445f2025-02-13 10:22:55 +08003137 goto error;
3138 }
3139
b.liu87afc4c2024-08-14 17:33:45 +08003140 ril_info.sock_client_list = list_create(sock_cli_free_func);
3141 if(ril_info.sock_client_list == NULL)
b.liu571445f2025-02-13 10:22:55 +08003142 {
b.liu87afc4c2024-08-14 17:33:45 +08003143 LOGE("list_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003144 goto error;
b.liu87afc4c2024-08-14 17:33:45 +08003145 }
3146
b.liub171c9a2024-11-12 19:23:29 +08003147 mbtk_queue_init(&(ril_info.msg_queue[ATPORTTYPE_0]));
3148 pthread_mutex_init(&(ril_info.msg_mutex[ATPORTTYPE_0]), NULL);
3149 pthread_cond_init(&(ril_info.msg_cond[ATPORTTYPE_0]), NULL);
b.liu571445f2025-02-13 10:22:55 +08003150
b.liu62240ee2024-11-07 17:52:45 +08003151 pthread_t info_pid, pack_pid/*, monitor_pid, urc_pid, bootconn_pid*/;
b.liu571445f2025-02-13 10:22:55 +08003152 pthread_attr_t thread_attr;
3153 pthread_attr_init(&thread_attr);
3154 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
3155 {
b.liu87afc4c2024-08-14 17:33:45 +08003156 LOGE("pthread_attr_setdetachstate() fail.");
b.liu571445f2025-02-13 10:22:55 +08003157 goto error;
3158 }
3159
b.liu87afc4c2024-08-14 17:33:45 +08003160 if(pthread_create(&info_pid, &thread_attr, ril_read_pthread, NULL))
b.liu571445f2025-02-13 10:22:55 +08003161 {
b.liu87afc4c2024-08-14 17:33:45 +08003162 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003163 goto error;
3164 }
b.liub171c9a2024-11-12 19:23:29 +08003165
3166 ATPortType_enum *port_0 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
b.liu7ca612c2025-04-25 09:23:36 +08003167 *port_0 = MBTK_AT_PORT_DEF;
b.liub171c9a2024-11-12 19:23:29 +08003168 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_0))
b.liu571445f2025-02-13 10:22:55 +08003169 {
b.liu87afc4c2024-08-14 17:33:45 +08003170 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003171 goto error;
b.liub171c9a2024-11-12 19:23:29 +08003172 }
3173
3174 ATPortType_enum *port_1 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
b.liu7ca612c2025-04-25 09:23:36 +08003175 *port_1 = MBTK_AT_PORT_VOICE;
b.liub171c9a2024-11-12 19:23:29 +08003176 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_1))
b.liu571445f2025-02-13 10:22:55 +08003177 {
b.liub171c9a2024-11-12 19:23:29 +08003178 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003179 goto error;
b.liub171c9a2024-11-12 19:23:29 +08003180 }
b.liufd87baf2024-11-15 15:30:38 +08003181
b.liu61eedc92024-11-13 16:07:00 +08003182 ATPortType_enum *port_2 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
b.liu7ca612c2025-04-25 09:23:36 +08003183 *port_2 = MBTK_AT_PORT_DATA;
b.liu61eedc92024-11-13 16:07:00 +08003184 if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_2))
b.liu571445f2025-02-13 10:22:55 +08003185 {
b.liu61eedc92024-11-13 16:07:00 +08003186 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003187 goto error;
b.liu61eedc92024-11-13 16:07:00 +08003188 }
b.liu571445f2025-02-13 10:22:55 +08003189
3190 // Set Band
3191 // AT*BAND=15,78,147,482,134742231
3192 char buff[10];
3193 memset(buff, 0, 10);
3194 property_get("persist.mbtk.band_config", buff, "");
3195 if(strlen(buff) == 0) {
3196 pthread_t band_pid;
3197 if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL))
3198 {
b.liu87afc4c2024-08-14 17:33:45 +08003199 LOGE("pthread_create() fail.");
b.liu571445f2025-02-13 10:22:55 +08003200 }
3201 }
3202
b.liufd87baf2024-11-15 15:30:38 +08003203 pthread_attr_destroy(&thread_attr);
3204
3205 if(asr_auto_data_call_enable()) {
3206 ril_cid_start = MBTK_RIL_CID_2;
3207
3208 char def_cid[10] = {0};
3209 char prop_data[100] = {0};
3210 int cid = -1;
3211 sprintf(def_cid, "%d", MBTK_RIL_CID_DEF); // Default route and DNS is CID 1.
3212 memset(prop_data, 0, sizeof(prop_data));
3213 if(property_get(MBTK_DEF_DNS_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
3214 cid = atoi(prop_data);
3215 }
3216
3217 if(cid == MBTK_RIL_CID_DEF) {
3218 if(file_link("/tmp/resolv.conf", "/etc/resolv.conf")) {
3219 LOGE("Create link file fail.");
3220 }
3221 }
3222 } else {
3223 ril_cid_start = MBTK_RIL_CID_DEF;
3224 }
b.liu571445f2025-02-13 10:22:55 +08003225
b.liufd87baf2024-11-15 15:30:38 +08003226 LOGD("MBTK Ril Server Start[CID start with : %d]...", ril_cid_start);
b.liu571445f2025-02-13 10:22:55 +08003227
3228 return 0;
b.liu87afc4c2024-08-14 17:33:45 +08003229error:
3230 if(ril_info.sock_client_list) {
3231 list_free(ril_info.sock_client_list);
3232 ril_info.sock_client_list = NULL;
3233 }
3234
3235 if(ril_info.sock_listen_fd > 0) {
3236 close(ril_info.sock_listen_fd);
3237 ril_info.sock_listen_fd = -1;
3238 }
b.liu571445f2025-02-13 10:22:55 +08003239 return -1;
b.liu87afc4c2024-08-14 17:33:45 +08003240}
3241
b.liu87afc4c2024-08-14 17:33:45 +08003242int main(int argc, char *argv[])
3243{
3244 mbtk_log_init("radio", "MBTK_RIL");
3245
b.liubcf86c92024-08-19 19:48:28 +08003246 MBTK_SOURCE_INFO_PRINT("mbtk_rild");
3247
b.liu87afc4c2024-08-14 17:33:45 +08003248#ifdef MBTK_DUMP_SUPPORT
3249 mbtk_debug_open(NULL, TRUE);
3250#endif
3251
3252// Using Killall,the file lock may be not release.
3253#if 0
3254 if(app_already_running(MBTK_RILD_PID_FILE)) {
3255 LOGW("daemon already running.");
3256 exit(1);
3257 }
3258#endif
3259
3260 LOGI("mbtk_rild start.");
3261
3262 if(InProduction_Mode()) {
3263 LOGI("Is Production Mode, will exit...");
3264 exit(0);
3265 }
3266
3267 ready_state_update();
3268
hong.liu7d2fa902025-07-23 04:41:53 -07003269 // Must wait for atcmdsrv ready.
3270 int at_sock = openSocket(MBTK_RILD_REQ_SLOT1_CHANNEL0, TRUE);
b.liu87afc4c2024-08-14 17:33:45 +08003271 if(at_sock < 0)
3272 {
3273 LOGE("Open AT Socket Fail[%d].", errno);
3274 return -1;
3275 }
hong.liu7d2fa902025-07-23 04:41:53 -07003276 int uart_sock = openSocket(MBTK_RILD_URC_SLOT1, FALSE);
b.liu87afc4c2024-08-14 17:33:45 +08003277 if(uart_sock < 0)
3278 {
3279 LOGE("Open Uart Socket Fail[%d].", errno);
3280 return -1;
3281 }
3282
hong.liu7d2fa902025-07-23 04:41:53 -07003283 int at_sock_1 = openSocket(MBTK_RILD_REQ_SLOT1_CHANNEL1, FALSE);
b.liub171c9a2024-11-12 19:23:29 +08003284 if(at_sock_1 < 0)
b.liu87afc4c2024-08-14 17:33:45 +08003285 {
b.liub171c9a2024-11-12 19:23:29 +08003286 LOGE("Open AT Socket Fail[%d].", errno);
b.liu87afc4c2024-08-14 17:33:45 +08003287 return -1;
3288 }
3289
hong.liu7d2fa902025-07-23 04:41:53 -07003290 int at_sock_2 = openSocket(MBTK_RILD_REQ_SLOT1_CHANNEL2, FALSE);
b.liu61eedc92024-11-13 16:07:00 +08003291 if(at_sock_2 < 0)
3292 {
3293 LOGE("Open AT Socket Fail[%d].", errno);
3294 return -1;
3295 }
hong.liu7d2fa902025-07-23 04:41:53 -07003296#ifdef LYNQ_DSDS_SUPPORT
3297 int uart_sock1 = openSocket(MBTK_RILD_URC_SLOT2, FALSE);
b.liu7ca612c2025-04-25 09:23:36 +08003298 if(uart_sock1 < 0)
3299 {
3300 LOGE("Open Uart Socket Fail[%d].", errno);
3301 return -1;
3302 }
3303
hong.liu7d2fa902025-07-23 04:41:53 -07003304 int at_sock1 = openSocket(MBTK_RILD_REQ_SLOT2_CHANNEL0, FALSE);
b.liu7ca612c2025-04-25 09:23:36 +08003305 if(at_sock1 < 0)
3306 {
3307 LOGE("Open AT Socket Fail[%d].", errno);
3308 return -1;
3309 }
3310
hong.liu7d2fa902025-07-23 04:41:53 -07003311 int at_sock1_1 = openSocket(MBTK_RILD_REQ_SLOT2_CHANNEL1, FALSE);
b.liu7ca612c2025-04-25 09:23:36 +08003312 if(at_sock1_1 < 0)
3313 {
3314 LOGE("Open AT Socket Fail[%d].", errno);
3315 return -1;
3316 }
3317
hong.liu7d2fa902025-07-23 04:41:53 -07003318 int at_sock1_2 = openSocket(MBTK_RILD_REQ_SLOT2_CHANNEL2, FALSE);
b.liu7ca612c2025-04-25 09:23:36 +08003319 if(at_sock1_2 < 0)
3320 {
3321 LOGE("Open AT Socket Fail[%d].", errno);
3322 return -1;
3323 }
hong.liu7d2fa902025-07-23 04:41:53 -07003324#endif
b.liub171c9a2024-11-12 19:23:29 +08003325 at_set_on_reader_closed(onATReaderClosed);
3326 at_set_on_timeout(onATTimeout);
3327
b.liu7ca612c2025-04-25 09:23:36 +08003328 if(at_open(ATPORTID_SIM1_0, at_sock, uart_sock, onUnsolicited1))
b.liub171c9a2024-11-12 19:23:29 +08003329 {
3330 LOGE("Start AT_0 thread fail.");
3331 return -1;
3332 }
3333
b.liu7ca612c2025-04-25 09:23:36 +08003334 if(at_open(ATPORTID_SIM1_1, at_sock_1, uart_sock, onUnsolicited1))
b.liub171c9a2024-11-12 19:23:29 +08003335 {
3336 LOGE("Start AT_1 thread fail.");
3337 return -1;
3338 }
3339
b.liu7ca612c2025-04-25 09:23:36 +08003340 if(at_open(ATPORTID_SIM1_2, at_sock_2, uart_sock, onUnsolicited1))
b.liu61eedc92024-11-13 16:07:00 +08003341 {
3342 LOGE("Start AT_1 thread fail.");
3343 return -1;
3344 }
3345
b.liu7ca612c2025-04-25 09:23:36 +08003346 if(at_handshake(ATPORTID_SIM1_0))
b.liu87afc4c2024-08-14 17:33:45 +08003347 {
b.liu7ca612c2025-04-25 09:23:36 +08003348 LOGE("SIM1 AT handshake fail.");
b.liu87afc4c2024-08-14 17:33:45 +08003349 return -1;
3350 }
3351
b.liu7ca612c2025-04-25 09:23:36 +08003352 LOGD("SIM1 AT OK.");
3353
hong.liu7d2fa902025-07-23 04:41:53 -07003354#ifdef LYNQ_DSDS_SUPPORT
b.liu7ca612c2025-04-25 09:23:36 +08003355 if(at_open(ATPORTID_SIM2_0, at_sock1, uart_sock1, onUnsolicited2))
3356 {
hong.liu7d2fa902025-07-23 04:41:53 -07003357 LOGE("Start ATPORTID_SIM2_0 thread fail.");
b.liu7ca612c2025-04-25 09:23:36 +08003358 return -1;
3359 }
3360
3361 if(at_open(ATPORTID_SIM2_1, at_sock1_1, uart_sock1, onUnsolicited2))
3362 {
hong.liu7d2fa902025-07-23 04:41:53 -07003363 LOGE("Start ATPORTID_SIM2_1 thread fail.");
b.liu7ca612c2025-04-25 09:23:36 +08003364 return -1;
3365 }
3366
3367 if(at_open(ATPORTID_SIM2_2, at_sock1_2, uart_sock1, onUnsolicited2))
3368 {
hong.liu7d2fa902025-07-23 04:41:53 -07003369 LOGE("Start ATPORTID_SIM2_2 thread fail.");
b.liu7ca612c2025-04-25 09:23:36 +08003370 return -1;
3371 }
3372
yq.wang3c5808d2025-05-08 17:39:19 +08003373 usleep(100 * 1000);
3374
b.liu7ca612c2025-04-25 09:23:36 +08003375 if(at_handshake(ATPORTID_SIM2_0))
3376 {
3377 LOGE("SIM2 AT handshake fail.");
3378 return -1;
3379 }
3380
3381 LOGD("SIM2 AT OK.");
hong.liu7d2fa902025-07-23 04:41:53 -07003382#endif
b.liu87afc4c2024-08-14 17:33:45 +08003383 if(ril_server_start())
3384 {
3385 LOGE("ril_server_start() fail.");
3386 return -1;
3387 }
3388
3389 mbtk_ril_ready();
3390
3391 while(1)
3392 {
3393 sleep(24 * 60 * 60);
3394 }
3395
3396 LOGD("!!!mbtk_ril exit!!!");
3397 return 0;
3398}