b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1 | /*
|
| 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 | -------- -------- -------------------------------------------------------
|
| 20 | 2024/08/13 LiuBin Initial version
|
b.liu | 60c2f1f | 2024-12-31 12:54:45 +0800 | [diff] [blame] | 21 | 2024/12/31 LiuBin Add new sms urc process(+CMT)
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 22 |
|
| 23 | ******************************************************************************/
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 24 | #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.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 57 | #include "mbtk_file.h"
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 58 |
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 59 | #ifndef TEMP_FAILURE_RETRY
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 60 | #define TEMP_FAILURE_RETRY(exp) ({ \
|
| 61 | typeof (exp) _rc; \
|
| 62 | do { \
|
| 63 | _rc = (exp); \
|
| 64 | } while (_rc == -1 && errno == EINTR); \
|
| 65 | _rc; })
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 66 | #endif
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 67 |
|
| 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.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 75 | #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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 85 | #define RIL_CALL_NUM_MAX 10
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 86 |
|
| 87 | static bool ril_net_ready = FALSE; // Only one time.
|
| 88 | static bool ril_server_ready = FALSE; // Only one time.
|
| 89 | ril_band_info_t band_info;
|
| 90 | ril_info_t ril_info;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 91 | static mbtk_ril_call_state_info_t call_list[RIL_CALL_NUM_MAX];
|
b.liu | aced4f9 | 2024-12-31 11:14:51 +0800 | [diff] [blame] | 92 | static bool cmt_found = FALSE;
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 93 | //#define LYNQ_DSDS_SUPPORT 1
|
b.liu | aced4f9 | 2024-12-31 11:14:51 +0800 | [diff] [blame] | 94 |
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 95 | extern mbtk_cell_pack_info_t cell_info;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 96 | extern ril_cgact_wait_t cgact_wait;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 97 | extern int ril_cid_start;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 98 |
|
| 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);
|
| 101 | int InProduction_Mode(void);
|
| 102 | mbtk_ril_err_enum dev_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 103 | mbtk_ril_err_enum call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 104 | mbtk_ril_err_enum sim_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 105 | mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 106 | mbtk_ril_err_enum data_call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 107 | mbtk_ril_err_enum pb_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 108 | mbtk_ril_err_enum sms_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 109 | mbtk_ril_err_enum ecall_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 110 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 111 | void data_call_retry(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_net_reg_state_info_t *reg_state);
|
b.liu | afdf2c6 | 2024-11-12 11:10:44 +0800 | [diff] [blame] | 112 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 113 | void data_call_state_change_cb(mbtk_sim_type_enum sim_id, int cid, bool action, bool auto_change, int reason);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 114 | static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack);
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 115 | int req_band_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t* band, int *cme_err);
|
| 116 | int req_dual_sim_get(ATPortType_enum port, mbtk_sim_type_enum *sim_id, int *cme_err);
|
| 117 |
|
| 118 | ATPortId_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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 122 |
|
| 123 | /* Called on command thread */
|
| 124 | static void onATTimeout()
|
| 125 | {
|
| 126 | LOGI("AT channel timeout; closing\n");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 127 | at_close(ATPORTID_SIM1_0);
|
| 128 | at_close(ATPORTID_SIM1_1);
|
| 129 | at_close(ATPORTID_SIM1_2);
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 130 | #ifdef LYNQ_DSDS_SUPPORT
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 131 | at_close(ATPORTID_SIM2_0);
|
| 132 | at_close(ATPORTID_SIM2_1);
|
| 133 | at_close(ATPORTID_SIM2_2);
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 134 | #endif
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 135 | }
|
| 136 |
|
| 137 | /* Called on command or reader thread */
|
| 138 | static void onATReaderClosed()
|
| 139 | {
|
| 140 | LOGI("AT channel closed\n");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 141 | at_close(ATPORTID_SIM1_0);
|
| 142 | at_close(ATPORTID_SIM1_1);
|
| 143 | at_close(ATPORTID_SIM1_2);
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 144 | #ifdef LYNQ_DSDS_SUPPORT
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 145 | at_close(ATPORTID_SIM2_0);
|
| 146 | at_close(ATPORTID_SIM2_1);
|
| 147 | at_close(ATPORTID_SIM2_2);
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 148 | #endif
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 149 | }
|
| 150 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 151 | static void sock_cli_free_func(void *data) |
| 152 | { |
| 153 | if (data) |
| 154 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 155 | sock_cli_info_t *info = (sock_cli_info_t*) data;
|
| 156 | LOGD("Free Socket client[fd = %d].", info->fd);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 157 | free(info); |
| 158 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 159 | }
|
| 160 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 161 | bool 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 178 | /*
|
| 179 | * Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
|
| 180 | */
|
| 181 | static 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 | */
|
| 201 | static 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 | */
|
| 221 | static 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 |
|
| 253 | static 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.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 259 | mbtk_system(MBTK_BOOT_NET_READY);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 260 | } 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 |
|
| 269 | static 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.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 275 | mbtk_system(MBTK_BOOT_SERVER_READY);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 276 | } 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 |
|
| 285 | static sock_cli_info_t* cli_find(int fd)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 286 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 287 | 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.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 290 | { |
| 291 | if (result->fd == fd) |
| 292 | return result; |
| 293 | } |
| 294 | |
| 295 | return NULL; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 296 | }
|
| 297 |
|
| 298 | static void cli_close(sock_cli_info_t* client)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 299 | { |
| 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 304 | epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_DEL, client->fd, &ev);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 305 | |
| 306 | close(client->fd); |
| 307 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 308 | if(list_remove(ril_info.sock_client_list, client))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 309 | { |
| 310 | sock_cli_free_func(client); |
| 311 | } |
| 312 | } |
| 313 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 314 | static 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.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 315 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 316 | ril_msg_pack_info_t* pack = ril_msg_pack_creat(sim_id, port, RIL_MSG_TYPE_RSP, ril_id, msg_index, NULL, 0);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 317 | if(pack) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 318 | {
|
| 319 | pack->err = (uint16)err;
|
| 320 | ril_pack_send(fd, pack);
|
| 321 | ril_msg_pack_free(pack);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 322 | } |
| 323 | else |
| 324 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 325 | LOGW("ril_msg_pack_creat() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 329 | void 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.liu | 10a3410 | 2024-08-20 20:36:24 +0800 | [diff] [blame] | 330 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 331 | 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.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 332 | if(pack) |
| 333 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 334 | pack->err = (uint16)MBTK_RIL_ERR_SUCCESS;
|
| 335 | #if 0
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 336 | if(data != NULL && data_len > 0) |
| 337 | { |
| 338 | pack->data_len = (uint16)data_len; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 339 | pack->data = (uint8*)mbtk_memcpy(data, data_len);
|
| 340 | }
|
| 341 | #endif
|
| 342 | ril_pack_send(fd, pack);
|
| 343 | ril_msg_pack_free(pack);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 344 | } |
| 345 | else |
| 346 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 347 | LOGW("ril_msg_pack_creat() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 348 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 349 | }
|
| 350 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 351 | void ril_ind_pack_send(mbtk_sim_type_enum sim_id, int fd, int msg_id, const void* data, int data_len)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 352 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 353 | 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.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 354 | if(pack) |
| 355 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 356 | pack->err = (uint16)0;
|
| 357 | #if 0
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 358 | if(data != NULL && data_len > 0) |
| 359 | { |
| 360 | pack->data_len = (uint16)data_len; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 361 | pack->data = (uint8*)mbtk_memcpy(data, data_len);
|
| 362 | }
|
| 363 | #endif
|
| 364 | ril_pack_send(fd, pack);
|
| 365 | ril_msg_pack_free(pack);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 366 | } |
| 367 | else |
| 368 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 369 | LOGW("ril_msg_pack_creat() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 370 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 371 | }
|
| 372 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 373 | void ril_state_change(ril_msg_id_enum msg_id, const void *data, int data_len)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 374 | { |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 375 | 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.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 378 | { |
| 379 | if(cli->ind_num > 0) { |
| 380 | int i; |
| 381 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 382 | if(cli->ind_register[i] == msg_id) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 383 | ril_ind_pack_send(MBTK_SIM_1, cli->fd, msg_id, data, data_len);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 384 | break; |
| 385 | } |
| 386 | } |
| 387 | } |
| 388 | } |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 389 | }
|
| 390 |
|
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 391 | static int urc_msg_distribute(bool async_process, ril_msg_id_enum msg_id, const void *data, int data_len)
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 392 | {
|
| 393 | // Send urc msg to client.
|
| 394 | if(msg_id > RIL_MSG_ID_IND_BEGIN && msg_id < RIL_MSG_ID_IND_END) {
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 395 | 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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 405 | }
|
| 406 |
|
| 407 | // Async process urc msg.
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 408 | if(async_process) { |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 409 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 432 | static void urc_sim_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 433 | {
|
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 437 | state.sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 438 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 439 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 440 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 460 | state.sim_type = ril_info.sim_type[sim_id];
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 461 | state.sim_state = MBTK_SIM_STATE_ABSENT;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 462 | ril_info.sim_state[sim_id] = MBTK_SIM_STATE_ABSENT;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 463 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 465 | state.sim_type = ril_info.sim_type[sim_id];
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 466 | state.sim_state = MBTK_SIM_STATE_NOT_READY;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 467 | ril_info.sim_state[sim_id] = MBTK_SIM_STATE_NOT_READY;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 468 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 545 | state.sim_type = ril_info.sim_type[sim_id];
|
| 546 | ril_info.sim_state[sim_id] = state.sim_state;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 547 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 548 | urc_msg_distribute(true, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 549 | } 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 558 | ril_info.sim_type[sim_id] = (mbtk_sim_card_type_enum)tmp_int;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 559 | } else {
|
| 560 | LOGW("Unknown URC.");
|
| 561 | }
|
| 562 |
|
| 563 | SIM_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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 570 | static void urc_call_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 571 | {
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 572 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 573 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 605 | call_list[i].sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 606 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 667 | call_list[i].sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 668 |
|
| 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 |
|
| 679 | CALL_STATE_EXIT:
|
| 680 | free(tmp_s);
|
| 681 | }
|
| 682 |
|
| 683 | // *ECALLDATA: <urc_id>[,<urc_data>]
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 684 | static void urc_ecall_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 685 | {
|
| 686 | mbtk_ril_ecall_state_info_t ecall_state;
|
| 687 | memset(&ecall_state, 0, sizeof(mbtk_ril_ecall_state_info_t));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 688 | ecall_state.sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 689 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 690 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 691 | 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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 702 |
|
b.liu | 29ead77 | 2025-05-26 17:51:20 +0800 | [diff] [blame] | 703 | 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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 715 | }
|
| 716 |
|
| 717 | urc_msg_distribute(false, RIL_MSG_ID_IND_ECALL_STATE_CHANGE, &ecall_state, sizeof(mbtk_ril_ecall_state_info_t));
|
| 718 | ECALLDATA_EXIT:
|
| 719 | free(tmp_s);
|
| 720 | }
|
| 721 |
|
| 722 | // +CMT: ,23
|
| 723 | // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 724 | static void urc_sms_state_change_process(mbtk_sim_type_enum sim_id, const char *s, bool is_pdu)
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 725 | {
|
b.liu | 0bb1c8e | 2024-12-31 14:44:40 +0800 | [diff] [blame] | 726 | static mbtk_ril_sms_state_info_t sms_info;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 727 | memset(&sms_info, 0, sizeof(mbtk_ril_sms_state_info_t));
|
| 728 | sms_info.sim_id = sim_id;
|
| 729 |
|
b.liu | 0bb1c8e | 2024-12-31 14:44:40 +0800 | [diff] [blame] | 730 | if(!is_pdu) {
|
b.liu | 60c2f1f | 2024-12-31 12:54:45 +0800 | [diff] [blame] | 731 | 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.liu | 60c2f1f | 2024-12-31 12:54:45 +0800 | [diff] [blame] | 747 | CMT_EXIT:
|
| 748 | free(tmp_s);
|
b.liu | 0bb1c8e | 2024-12-31 14:44:40 +0800 | [diff] [blame] | 749 | } 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.liu | 60c2f1f | 2024-12-31 12:54:45 +0800 | [diff] [blame] | 753 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 754 | }
|
| 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.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 762 | // +C5GREG: 1,"00280386","07e920010",11,1,"01"
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 763 | static void urc_net_reg_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 764 | {
|
| 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 768 | state.sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 769 |
|
| 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.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 775 | } else if(strStartsWith(s, "+C5GREG:")) {
|
| 776 | state.type = MBTK_NET_REG_TYPE_DATA_NR;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 777 | } else {
|
| 778 | state.type = MBTK_NET_REG_TYPE_DATA_LTE;
|
| 779 | }
|
| 780 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 781 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 782 | 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.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 794 | if (state.reg_state && at_tok_hasmore(&line)) // Reg
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 795 | {
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 796 | if (at_tok_nextstr(&line, &tmp_str) < 0) // tac
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 797 | {
|
| 798 | goto CGREG_EXIT;
|
| 799 | }
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 800 | state.tac = (uint64)strtoull(tmp_str, NULL, 16);
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 801 |
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 802 | if (at_tok_nextstr(&line, &tmp_str) < 0) // ci
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 803 | {
|
| 804 | goto CGREG_EXIT;
|
| 805 | }
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 806 | state.ci = (uint64)strtoull(tmp_str, NULL, 16);
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 807 |
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 808 | 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.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 815 | 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.liu | afdf2c6 | 2024-11-12 11:10:44 +0800 | [diff] [blame] | 820 | // 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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 822 | CGREG_EXIT:
|
| 823 | free(tmp_s);
|
| 824 | }
|
| 825 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 826 | static void urc_pdp_state_change_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 827 | {
|
| 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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 889 | mbtk_ril_pdp_state_info_t cgev_info;
|
| 890 | memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 891 | cgev_info.sim_id = sim_id;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 892 | int cid, reason = 0;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 893 | if (sscanf(s, "+CGEV: NW PDN DEACT %d", &cid) == 1) {
|
| 894 | cgev_info.cid = (uint16)cid;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 895 | cgev_info.action = FALSE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 896 | } else if (sscanf(s, "+CGEV: ME PDN DEACT %d", &cid) == 1) {
|
| 897 | cgev_info.cid = (uint16)cid;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 898 | cgev_info.action = FALSE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 899 | } 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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 903 | cgev_info.action = TRUE;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 904 | } else if (!strcmp(s, "+CGEV: ME DETACH")) {
|
| 905 | if(cgact_wait.waitting) {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 906 | cgev_info.cid = cgact_wait.cid;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 907 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 908 | cgev_info.action = FALSE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 909 | } 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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 912 | cgev_info.action = TRUE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 913 | } else if(sscanf(s, "+CGEV: EPS PDN ACT %d", &cid) == 1) {
|
| 914 | cgev_info.cid = (uint16)cid;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 915 | cgev_info.action = TRUE;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 916 | } else {
|
| 917 | LOGD(">>>>>>>>>No process +CGEV <<<<<<<<<");
|
| 918 | return;
|
| 919 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 920 | cgev_info.auto_change = !cgact_wait.waitting;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 921 |
|
| 922 | if(cgact_wait.act) {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 923 | if(cgact_wait.waitting && cgev_info.action && cgact_wait.cid == cgev_info.cid) {
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 924 | cgact_wait.waitting = false;
|
| 925 | }
|
| 926 | } else {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 927 | if(cgact_wait.waitting && !cgev_info.action && cgact_wait.cid == cgev_info.cid) {
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 928 | cgact_wait.waitting = false;
|
| 929 | }
|
| 930 | }
|
| 931 |
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 932 | 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.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 934 | if(cgev_info.cid >= MBTK_APN_CID_MIN && cgev_info.cid <= MBTK_APN_CID_MAX) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 935 | data_call_state_change_cb(sim_id, cgev_info.cid, cgev_info.action, cgev_info.auto_change, cgev_info.reason);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 936 | urc_msg_distribute(false, RIL_MSG_ID_IND_PDP_STATE_CHANGE, &cgev_info, sizeof(mbtk_ril_pdp_state_info_t));
|
| 937 | }
|
| 938 |
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 939 | #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;
|
| 965 | at_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;
|
| 1084 | PDP_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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 1131 | static void urc_cell_info_process(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1132 | {
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 1133 | // +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 |
|
| 1275 | EEMNRSVC_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++;
|
| 1324 | EEMNRINTER_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 | }
|
| 1409 | EEMNRINTERRAT_EXIT:
|
| 1410 | free(free_ptr);
|
| 1411 | }
|
| 1412 | }
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1413 | /*
|
| 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.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 1431 | else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1432 | {
|
| 1433 | // tac, PCI, dlEuarfcn, ulEuarfcn, band
|
| 1434 | if(cell_info.running) {
|
| 1435 | int tmp_int;
|
| 1436 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1437 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1438 | 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
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1485 | if (at_tok_nextint(&line, &tmp_int) < 0) //ul arfcn
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1486 | {
|
| 1487 | goto EEMLTESVC_EXIT;
|
| 1488 | }
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1489 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1490 | {
|
| 1491 | goto EEMLTESVC_EXIT;
|
| 1492 | }
|
| 1493 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int; //band
|
| 1494 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1495 | {
|
| 1496 | goto EEMLTESVC_EXIT;
|
| 1497 | }
|
| 1498 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1499 | {
|
| 1500 | goto EEMLTESVC_EXIT;
|
| 1501 | }
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1502 | cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int; //rsrp
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1503 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1504 | {
|
| 1505 | goto EEMLTESVC_EXIT;
|
| 1506 | }
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1507 | cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int; //rsrq
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1508 |
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1509 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1510 | {
|
| 1511 | goto EEMLTESVC_EXIT;
|
| 1512 | }
|
| 1513 |
|
| 1514 | cell_info.cell_list.cell[cell_info.cell_list.num].value11 = (uint32)tmp_int; //sinr
|
| 1515 |
|
| 1516 | for(i =0; i < 9; i++)
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1517 | {
|
| 1518 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1519 | {
|
| 1520 | goto EEMLTESVC_EXIT;
|
| 1521 | }
|
| 1522 | }
|
| 1523 | cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int; //cell identiy
|
| 1524 |
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1525 |
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1526 | cell_info.cell_list.num++;
|
| 1527 |
|
| 1528 | EEMLTESVC_EXIT:
|
| 1529 | free(free_ptr);
|
| 1530 | }
|
| 1531 | }
|
| 1532 | /*
|
| 1533 | // index,phyCellId,euArfcn,rsrp,rsrq
|
| 1534 | +EEMLTEINTER: 0, 65535, 38950, 0, 0
|
| 1535 | */
|
| 1536 | else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
|
| 1537 | {
|
| 1538 | // phyCellId,euArfcn,rsrp,rsrq
|
| 1539 | if(cell_info.running) {
|
| 1540 | int tmp_int;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1541 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1542 | char* free_ptr = tmp_s;
|
| 1543 | char *line = tmp_s;
|
| 1544 | if (at_tok_start(&line) < 0)
|
| 1545 | {
|
| 1546 | goto EEMLTEINTER_EXIT;
|
| 1547 | }
|
| 1548 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1549 | {
|
| 1550 | goto EEMLTEINTER_EXIT;
|
| 1551 | }
|
| 1552 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
|
| 1553 | {
|
| 1554 | goto EEMLTEINTER_EXIT;
|
| 1555 | }
|
| 1556 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1557 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1558 | {
|
| 1559 | goto EEMLTEINTER_EXIT;
|
| 1560 | }
|
| 1561 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1562 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1563 | {
|
| 1564 | goto EEMLTEINTER_EXIT;
|
| 1565 | }
|
| 1566 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1567 | LOG("cell line : %s", line);
|
| 1568 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1569 | {
|
| 1570 | goto EEMLTEINTER_EXIT;
|
| 1571 | }
|
| 1572 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 1573 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1574 | {
|
| 1575 | LOG("cell tmp_int : %d", tmp_int);
|
| 1576 | goto EEMLTEINTER_EXIT;
|
| 1577 | }
|
| 1578 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
|
| 1579 | LOG("cell value5 : %d", cell_info.cell_list.cell[cell_info.cell_list.num].value5);
|
| 1580 | cell_info.cell_list.num++;
|
| 1581 | EEMLTEINTER_EXIT:
|
| 1582 | free(free_ptr);
|
| 1583 | }
|
| 1584 | }
|
| 1585 | // Do nothing
|
| 1586 | else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
|
| 1587 | {
|
| 1588 | if(cell_info.running) {
|
| 1589 |
|
| 1590 | }
|
| 1591 | }
|
| 1592 | // WCDMA
|
| 1593 | /*
|
| 1594 | // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
|
| 1595 |
|
| 1596 | // if sCMeasPresent == 1
|
| 1597 | // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
|
| 1598 | // endif
|
| 1599 |
|
| 1600 | // if sCParamPresent == 1
|
| 1601 | // rac, nom, mcc, mnc_len, mnc, lac, ci,
|
| 1602 | // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
|
| 1603 | // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
|
| 1604 | // endif
|
| 1605 |
|
| 1606 | // if ueOpStatusPresent == 1
|
| 1607 | // rrcState, numLinks, srncId, sRnti,
|
| 1608 | // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
|
| 1609 | // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
|
| 1610 | // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
|
| 1611 | // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
|
| 1612 | // endif
|
| 1613 | //
|
| 1614 | +EEMUMTSSVC: 3, 1, 1, 1,
|
| 1615 | -80, 27, -6, -18, -115, -32768,
|
| 1616 | 1, 1, 1120, 2, 1, 61697, 168432821,
|
| 1617 | 15, 24, 10763, 0, 0, 0, 0,
|
| 1618 | 128, 128, 65535, 0, 0,
|
| 1619 | 2, 255, 65535, 4294967295,
|
| 1620 | 0, 0, 0, 0, 0, 0,
|
| 1621 | 0, 0, 0, 0, 0, 0, 1, 1,
|
| 1622 | 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
|
| 1623 | 0, 0, 0, 0, 0, 0
|
| 1624 | */
|
| 1625 | else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
|
| 1626 | {
|
| 1627 | // lac, ci, arfcn
|
| 1628 | if(cell_info.running) {
|
| 1629 | int tmp_int;
|
| 1630 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1631 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1632 | char* free_ptr = tmp_s;
|
| 1633 | char *line = tmp_s;
|
| 1634 | if (at_tok_start(&line) < 0)
|
| 1635 | {
|
| 1636 | goto EEMUMTSSVC_EXIT;
|
| 1637 | }
|
| 1638 | // Jump 12 integer.
|
| 1639 | i = 0;
|
| 1640 | while(i < 12) {
|
| 1641 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1642 | {
|
| 1643 | goto EEMUMTSSVC_EXIT;
|
| 1644 | }
|
| 1645 | i++;
|
| 1646 | }
|
| 1647 | // mcc
|
| 1648 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1649 | {
|
| 1650 | goto EEMUMTSSVC_EXIT;
|
| 1651 | }
|
| 1652 | cell_info.cell_list.cell[cell_info.cell_list.num].value4= (uint32)tmp_int;
|
| 1653 | // mnc
|
| 1654 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1655 | {
|
| 1656 | goto EEMUMTSSVC_EXIT;
|
| 1657 | }
|
| 1658 | cell_info.cell_list.cell[cell_info.cell_list.num].value5= (uint32)tmp_int;
|
| 1659 | // lac
|
| 1660 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1661 | {
|
| 1662 | goto EEMUMTSSVC_EXIT;
|
| 1663 | }
|
| 1664 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1665 | // ci
|
| 1666 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1667 | {
|
| 1668 | goto EEMUMTSSVC_EXIT;
|
| 1669 | }
|
| 1670 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1671 |
|
| 1672 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1673 | {
|
| 1674 | goto EEMUMTSSVC_EXIT;
|
| 1675 | }
|
| 1676 | // cpi
|
| 1677 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1678 | {
|
| 1679 | goto EEMUMTSSVC_EXIT;
|
| 1680 | }
|
| 1681 | cell_info.cell_list.cell[cell_info.cell_list.num].value6= (uint32)tmp_int;
|
| 1682 | /*
|
| 1683 | // Jump 2 integer.
|
| 1684 | i = 0;
|
| 1685 | while(i < 2) {
|
| 1686 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1687 | {
|
| 1688 | goto EEMUMTSSVC_EXIT;
|
| 1689 | }
|
| 1690 | i++;
|
| 1691 | }
|
| 1692 | */
|
| 1693 | // arfcn
|
| 1694 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1695 | {
|
| 1696 | goto EEMUMTSSVC_EXIT;
|
| 1697 | }
|
| 1698 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1699 |
|
| 1700 | cell_info.cell_list.num++;
|
| 1701 | EEMUMTSSVC_EXIT:
|
| 1702 | free(free_ptr);
|
| 1703 | }
|
| 1704 | }
|
| 1705 | /*
|
| 1706 | // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
|
| 1707 | +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
|
| 1708 | */
|
| 1709 | else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
|
| 1710 | {
|
| 1711 | // lac, ci, arfcn
|
| 1712 | if(cell_info.running) {
|
| 1713 | int tmp_int;
|
| 1714 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1715 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1716 | char* free_ptr = tmp_s;
|
| 1717 | char *line = tmp_s;
|
| 1718 | if (at_tok_start(&line) < 0)
|
| 1719 | {
|
| 1720 | goto EEMUMTSINTRA_EXIT;
|
| 1721 | }
|
| 1722 | // Jump 8 integer.
|
| 1723 | i = 0;
|
| 1724 | while(i < 8) {
|
| 1725 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1726 | {
|
| 1727 | goto EEMUMTSINTRA_EXIT;
|
| 1728 | }
|
| 1729 | i++;
|
| 1730 | }
|
| 1731 |
|
| 1732 | // lac
|
| 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].value1 = (uint32)tmp_int;
|
| 1738 |
|
| 1739 | // ci
|
| 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].value2 = (uint32)tmp_int;
|
| 1745 |
|
| 1746 | // arfcn
|
| 1747 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1748 | {
|
| 1749 | goto EEMUMTSINTRA_EXIT;
|
| 1750 | }
|
| 1751 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1752 |
|
| 1753 | cell_info.cell_list.num++;
|
| 1754 | EEMUMTSINTRA_EXIT:
|
| 1755 | free(free_ptr);
|
| 1756 | }
|
| 1757 | }
|
| 1758 | /*
|
| 1759 | // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
|
| 1760 | +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
|
| 1761 | */
|
| 1762 | else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
|
| 1763 | {
|
| 1764 | // lac, ci, arfcn
|
| 1765 | if(cell_info.running) {
|
| 1766 | int tmp_int;
|
| 1767 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1768 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1769 | char* free_ptr = tmp_s;
|
| 1770 | char *line = tmp_s;
|
| 1771 | if (at_tok_start(&line) < 0)
|
| 1772 | {
|
| 1773 | goto EEMUMTSINTERRAT_EXIT;
|
| 1774 | }
|
| 1775 | // Jump 7 integer.
|
| 1776 | i = 0;
|
| 1777 | while(i < 7) {
|
| 1778 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1779 | {
|
| 1780 | goto EEMUMTSINTERRAT_EXIT;
|
| 1781 | }
|
| 1782 | i++;
|
| 1783 | }
|
| 1784 |
|
| 1785 | // lac
|
| 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].value1 = (uint32)tmp_int;
|
| 1791 |
|
| 1792 | // ci
|
| 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].value2 = (uint32)tmp_int;
|
| 1798 |
|
| 1799 | // arfcn
|
| 1800 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1801 | {
|
| 1802 | goto EEMUMTSINTERRAT_EXIT;
|
| 1803 | }
|
| 1804 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1805 |
|
| 1806 | cell_info.cell_list.num++;
|
| 1807 | EEMUMTSINTERRAT_EXIT:
|
| 1808 | free(free_ptr);
|
| 1809 | }
|
| 1810 | }
|
| 1811 | // GSM
|
| 1812 | // +EEMGINFOBASIC: 2
|
| 1813 | // Do nothing.
|
| 1814 | else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
|
| 1815 | // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
|
| 1816 | {
|
| 1817 | if(cell_info.running) {
|
| 1818 |
|
| 1819 | }
|
| 1820 | }
|
| 1821 | /*
|
| 1822 | // mcc, mnc_len, mnc, lac, ci, nom, nco,
|
| 1823 | // bsic, C1, C2, TA, TxPwr,
|
| 1824 | // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
|
| 1825 | // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
|
| 1826 | // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
|
| 1827 | // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
|
| 1828 | // gsmBand,channelMode
|
| 1829 | +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
|
| 1830 | 63, 36, 146, 1, 7,
|
| 1831 | 46, 42, 42, 7, 0,
|
| 1832 | 53, 0, 8, 0, 1, 6, 53,
|
| 1833 | 2, 0, 146, 42, 54, 0, 1,
|
| 1834 | 1, 32, 0, 0, 0, 0,
|
| 1835 | 0, 0
|
| 1836 | */
|
| 1837 | else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
|
| 1838 | {
|
| 1839 | // lac, ci, arfcn, bsic
|
| 1840 | LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
|
| 1841 | if(cell_info.running) {
|
| 1842 | int tmp_int;
|
| 1843 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1844 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1845 | char* free_ptr = tmp_s;
|
| 1846 | char *line = tmp_s;
|
| 1847 | if (at_tok_start(&line) < 0)
|
| 1848 | {
|
| 1849 | goto EEMGINFOSVC_EXIT;
|
| 1850 | }
|
| 1851 |
|
| 1852 | // mcc
|
| 1853 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1854 | {
|
| 1855 | goto EEMGINFOSVC_EXIT;
|
| 1856 | }
|
| 1857 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
|
| 1858 |
|
| 1859 | //mnc_len
|
| 1860 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1861 | {
|
| 1862 | goto EEMGINFOSVC_EXIT;
|
| 1863 | }
|
| 1864 | // mnc
|
| 1865 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1866 | {
|
| 1867 | goto EEMGINFOSVC_EXIT;
|
| 1868 | }
|
| 1869 | cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1870 | // lac
|
| 1871 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1872 | {
|
| 1873 | goto EEMGINFOSVC_EXIT;
|
| 1874 | }
|
| 1875 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1876 |
|
| 1877 | // ci
|
| 1878 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1879 | {
|
| 1880 | goto EEMGINFOSVC_EXIT;
|
| 1881 | }
|
| 1882 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1883 |
|
| 1884 | // Jump 2 integer.
|
| 1885 | i = 0;
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1886 | while(i < 3) {
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1887 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1888 | {
|
| 1889 | goto EEMGINFOSVC_EXIT;
|
| 1890 | }
|
| 1891 | i++;
|
| 1892 | }
|
| 1893 |
|
| 1894 | // bsic
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1895 | if ( tmp_int < 0 || tmp_int >= 65536)
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1896 | {
|
| 1897 | goto EEMGINFOSVC_EXIT;
|
| 1898 | }
|
| 1899 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 1900 |
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1901 | // Jump 4 integer, get 5rd number
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1902 | i = 0;
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1903 | while(i < 5) {
|
| 1904 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1905 | {
|
| 1906 | goto EEMGINFOSVC_EXIT;
|
| 1907 | }
|
| 1908 | i++;
|
| 1909 | }
|
| 1910 |
|
| 1911 | cell_info.cell_list.cell[cell_info.cell_list.num].value7=tmp_int; //rxlev
|
| 1912 |
|
| 1913 | // Jump 10 integer, get 11rd number
|
| 1914 | i = 0;
|
| 1915 | while(i < 11) {
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1916 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1917 | {
|
| 1918 | goto EEMGINFOSVC_EXIT;
|
| 1919 | }
|
| 1920 | i++;
|
| 1921 | }
|
| 1922 |
|
| 1923 | // arfcn
|
q.huang | d58823b | 2025-08-15 18:28:59 +0800 | [diff] [blame] | 1924 | if (tmp_int < 0 || tmp_int >= 65536)
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1925 | {
|
| 1926 | goto EEMGINFOSVC_EXIT;
|
| 1927 | }
|
| 1928 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1929 |
|
| 1930 | cell_info.cell_list.num++;
|
| 1931 | EEMGINFOSVC_EXIT:
|
| 1932 | free(free_ptr);
|
| 1933 | }
|
| 1934 | }
|
| 1935 | /*
|
| 1936 | // PS_attached, attach_type, service_type, tx_power, c_value,
|
| 1937 | // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
|
| 1938 | // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
|
| 1939 | // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
|
| 1940 | +EEMGINFOPS: 1, 255, 0, 0, 0,
|
| 1941 | 0, 0, 268435501, 1, 0, 0,
|
| 1942 | 4, 0, 96, 0, 0, 0,
|
| 1943 | 0, 0, 0, 65535, 0, 13350
|
| 1944 | */
|
| 1945 | // Do nothing.
|
| 1946 | else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
|
| 1947 | {
|
| 1948 | if(cell_info.running) {
|
| 1949 |
|
| 1950 | }
|
| 1951 | }
|
| 1952 | else if(strStartsWith(s, "+EEMGINFONC:")) // cell
|
| 1953 | {
|
| 1954 | if(cell_info.running) {
|
| 1955 | int tmp_int;
|
| 1956 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1957 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1958 | char* free_ptr = tmp_s;
|
| 1959 | char *line = tmp_s;
|
| 1960 | if (at_tok_start(&line) < 0)
|
| 1961 | {
|
| 1962 | goto EEMGINFOPS_EXIT;
|
| 1963 | }
|
| 1964 |
|
| 1965 | // nc_num
|
| 1966 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1967 | {
|
| 1968 | LOG("cell_info.running 1= %d\n.",cell_info.running);
|
| 1969 | goto EEMGINFOPS_EXIT;
|
| 1970 | }
|
| 1971 | // mcc
|
| 1972 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1973 | {
|
| 1974 | LOG("cell_info.running 2= %d\n.",cell_info.running);
|
| 1975 | goto EEMGINFOPS_EXIT;
|
| 1976 | }
|
| 1977 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
|
| 1978 |
|
| 1979 | // mnc
|
| 1980 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1981 | {
|
| 1982 | LOG("cell_info.running 3= %d\n.",cell_info.running);
|
| 1983 | goto EEMGINFOPS_EXIT;
|
| 1984 | }
|
| 1985 | cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
|
| 1986 |
|
| 1987 | // lac
|
| 1988 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1989 | {
|
| 1990 | LOG("cell_info.running 4= %d\n.",cell_info.running);
|
| 1991 | goto EEMGINFOPS_EXIT;
|
| 1992 | }
|
| 1993 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1994 |
|
| 1995 | // rac
|
| 1996 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1997 | {
|
| 1998 | LOG("cell_info.running 5= %d\n.",cell_info.running);
|
| 1999 | goto EEMGINFOPS_EXIT;
|
| 2000 | }
|
| 2001 |
|
| 2002 | // ci
|
| 2003 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 2004 | {
|
| 2005 | LOG("cell_info.running 6= %d\n.",cell_info.running);
|
| 2006 | goto EEMGINFOPS_EXIT;
|
| 2007 | }
|
| 2008 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 2009 |
|
| 2010 | // rx_lv
|
| 2011 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 2012 | {
|
| 2013 | LOG("cell_info.running 7= %d\n.",cell_info.running);
|
| 2014 | goto EEMGINFOPS_EXIT;
|
| 2015 | }
|
| 2016 |
|
| 2017 | // bsic
|
| 2018 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 2019 | {
|
| 2020 | LOG("cell_info.running 8= %d\n.",cell_info.running);
|
| 2021 | goto EEMGINFOPS_EXIT;
|
| 2022 | }
|
| 2023 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 2024 |
|
| 2025 | // Jump 2 integer.
|
| 2026 | i = 0;
|
| 2027 | while(i < 2) {
|
| 2028 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 2029 | {
|
| 2030 | LOG("cell_info.running 9= %d\n.",cell_info.running);
|
| 2031 | goto EEMGINFOPS_EXIT;
|
| 2032 | }
|
| 2033 | i++;
|
| 2034 | }
|
| 2035 |
|
| 2036 | // arfcn
|
| 2037 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 2038 | {
|
| 2039 | LOG("cell_info.running 10 = %d\n.",cell_info.running);
|
| 2040 | goto EEMGINFOPS_EXIT;
|
| 2041 | }
|
| 2042 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 2043 |
|
| 2044 | cell_info.cell_list.num++;
|
| 2045 | EEMGINFOPS_EXIT:
|
| 2046 | free(free_ptr);
|
| 2047 | }
|
| 2048 | } else {
|
| 2049 | LOGW("Unknown CELL URC : %s", s);
|
| 2050 | }
|
| 2051 | }
|
| 2052 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2053 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2054 | static void onUnsolicited(mbtk_sim_type_enum sim_id, const char *s, const char *sms_pdu)
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2055 | {
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 2056 | LOGV("URC : %s", s);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2057 | // MBTK_AT_READY
|
b.liu | aced4f9 | 2024-12-31 11:14:51 +0800 | [diff] [blame] | 2058 | // +CMT: ,23
|
| 2059 | // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
|
| 2060 | // Get PDU data.
|
| 2061 | if(cmt_found) {
|
| 2062 | cmt_found = FALSE;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2063 | urc_sms_state_change_process(sim_id, s, true);
|
b.liu | aced4f9 | 2024-12-31 11:14:51 +0800 | [diff] [blame] | 2064 | } else if (strStartsWith(s, "MBTK_AT_READY")) { // AT ready.
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2065 |
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 2066 | } else if(strStartsWith(s, "CONNECT") || strStartsWith(s, "+CGEV:")) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2067 | urc_pdp_state_change_process(sim_id, s, sms_pdu);
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2068 | } else if(strStartsWith(s, "+EEMNRSVC:") || strStartsWith(s, "+EEMNRINTER:")
|
| 2069 | || strStartsWith(s, "+EEMNRINTERRAT:")
|
| 2070 | || strStartsWith(s, "+EEMLTESVC:") || strStartsWith(s, "+EEMLTEINTER:")
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 2071 | || strStartsWith(s, "+EEMLTEINTRA:") || strStartsWith(s, "+EEMLTEINTERRAT:")
|
| 2072 | || strStartsWith(s, "+EEMUMTSSVC:") || strStartsWith(s, "+EEMUMTSINTRA:")
|
| 2073 | || strStartsWith(s, "+EEMUMTSINTERRAT:") || strStartsWith(s, "+EEMGINFOBASIC:")
|
| 2074 | || strStartsWith(s, "+EEMGINFOSVC:") || strStartsWith(s, "+EEMGINFOPS:")
|
| 2075 | || strStartsWith(s, "+EEMGINFONC:")) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2076 | urc_cell_info_process(sim_id, s, sms_pdu);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2077 | }
|
| 2078 | else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
|
| 2079 | {
|
| 2080 | const char* ptr = s + strlen("*RADIOPOWER:");
|
| 2081 | while(*ptr != '\0' && *ptr == ' ' )
|
| 2082 | {
|
| 2083 | ptr++;
|
| 2084 | }
|
| 2085 |
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2086 | mbtk_ril_radio_state_info_t state;
|
| 2087 | memset(&state, 0, sizeof(mbtk_ril_radio_state_info_t));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2088 | state.sim_id = sim_id;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2089 | if(*ptr == '1') {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2090 | state.radio_state = MBTK_RADIO_STATE_FULL_FUNC;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2091 | } else {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2092 | state.radio_state = MBTK_RADIO_STATE_MINI_FUNC;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2093 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2094 | urc_msg_distribute(true, RIL_MSG_ID_IND_RADIO_STATE_CHANGE, &state, sizeof(mbtk_ril_radio_state_info_t));
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2095 | }
|
| 2096 | // +CREG: 1, "8010", "000060a5", 0, 2, 0
|
| 2097 | // +CREG: 1, "8330", "06447347", 7, 2, 0
|
| 2098 | // +CEREG: 1, "8330", "06447347", 7
|
| 2099 | // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
|
| 2100 | // $CREG: 1, "8010", "000060a7", 0,, 2, 0
|
| 2101 | // +CGREG: 1
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2102 | // +C5GREG: 1,"00280386","07e920010",11,1,"01"
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2103 | else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2104 | || strStartsWith(s, "+CEREG:") // LTE data registed.
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2105 | || strStartsWith(s, "+CREG:") // GMS/WCDMA/LTE CS registed.
|
| 2106 | || strStartsWith(s, "+C5GREG:")) // NR data registed.
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2107 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2108 | urc_net_reg_state_change_process(sim_id, s, sms_pdu);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2109 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2110 | // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
|
| 2111 | else if(strStartsWith(s, "+CLCC:")
|
| 2112 | || strStartsWith(s, "+CPAS:")
|
| 2113 | || strStartsWith(s, "+CALLDISCONNECT:"))
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2114 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2115 | urc_call_state_change_process(sim_id, s, sms_pdu);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2116 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2117 | else if(strStartsWith(s, "*SIMDETEC:")
|
| 2118 | || strStartsWith(s, "*EUICC:")
|
| 2119 | || strStartsWith(s, "+CPIN:"))
|
| 2120 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2121 | urc_sim_state_change_process(sim_id, s, sms_pdu);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2122 | }
|
| 2123 | else if(strStartsWith(s, "+CMT:"))
|
| 2124 | {
|
b.liu | aced4f9 | 2024-12-31 11:14:51 +0800 | [diff] [blame] | 2125 | cmt_found = TRUE;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2126 | urc_sms_state_change_process(sim_id, s, false);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2127 | }
|
b.liu | 29ead77 | 2025-05-26 17:51:20 +0800 | [diff] [blame] | 2128 | else if(strStartsWith(s, "*ECALLDATA:")
|
| 2129 | || strStartsWith(s, "+ECALLDIALRETRY:"))
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2130 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2131 | urc_ecall_state_change_process(sim_id, s, sms_pdu);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2132 | }
|
| 2133 | #if 0
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2134 | // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
|
| 2135 | else if(strStartsWith(s, "+CLCC:"))
|
| 2136 | {
|
| 2137 | mbtk_call_info_t reg;
|
| 2138 | reg.call_wait = MBTK_CLCC;
|
| 2139 | char* tmp_s = memdup(s,strlen(s));
|
| 2140 | char* free_ptr = tmp_s;
|
| 2141 | char *line = tmp_s;
|
| 2142 | int tmp_int;
|
| 2143 | char *tmp_str;
|
| 2144 | int err;
|
| 2145 |
|
| 2146 | err = at_tok_start(&line);
|
| 2147 | if (err < 0)
|
| 2148 | {
|
| 2149 | goto CLCC_EXIT;
|
| 2150 | }
|
| 2151 | err = at_tok_nextint(&line, &tmp_int); // dir1
|
| 2152 | if (err < 0)
|
| 2153 | {
|
| 2154 | goto CLCC_EXIT;
|
| 2155 | }
|
| 2156 | reg.dir1 = (uint8)tmp_int;
|
| 2157 | err = at_tok_nextint(&line, &tmp_int);// dir
|
| 2158 | if (err < 0)
|
| 2159 | {
|
| 2160 | goto CLCC_EXIT;
|
| 2161 | }
|
| 2162 | reg.dir = (uint8)tmp_int;
|
| 2163 | err = at_tok_nextint(&line, &tmp_int);// state
|
| 2164 | if (err < 0)
|
| 2165 | {
|
| 2166 | goto CLCC_EXIT;
|
| 2167 | }
|
| 2168 | reg.state = (uint8)tmp_int;
|
| 2169 | err = at_tok_nextint(&line, &tmp_int);// mode
|
| 2170 | if (err < 0)
|
| 2171 | {
|
| 2172 | goto CLCC_EXIT;
|
| 2173 | }
|
| 2174 | reg.mode = (uint8)tmp_int;
|
| 2175 | err = at_tok_nextint(&line, &tmp_int);// mpty
|
| 2176 | if (err < 0)
|
| 2177 | {
|
| 2178 | goto CLCC_EXIT;
|
| 2179 | }
|
| 2180 | reg.mpty = (uint8)tmp_int;
|
| 2181 | err = at_tok_nextstr(&line, &tmp_str); // phone_number
|
| 2182 | if (err < 0)
|
| 2183 | {
|
| 2184 | goto CLCC_EXIT;
|
| 2185 | }
|
| 2186 |
|
| 2187 | memset(reg.phone_number,0,sizeof(reg.phone_number));
|
| 2188 | memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
|
| 2189 | err = at_tok_nextint(&line, &tmp_int);// tpye
|
| 2190 | if (err < 0)
|
| 2191 | {
|
| 2192 | goto CLCC_EXIT;
|
| 2193 | }
|
| 2194 | reg.type = (uint8)tmp_int;
|
| 2195 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 2196 | CLCC_EXIT:
|
| 2197 | free(free_ptr);
|
| 2198 | }
|
| 2199 | // +CPAS: 4
|
| 2200 | else if(strStartsWith(s, "+CPAS:"))
|
| 2201 | {
|
| 2202 | mbtk_call_info_t reg;
|
| 2203 | reg.call_wait = 0;
|
| 2204 | char* tmp_s = memdup(s,strlen(s));
|
| 2205 | char* free_ptr = tmp_s;
|
| 2206 | char *line = tmp_s;
|
| 2207 | int tmp_int;
|
| 2208 | int err;
|
| 2209 |
|
| 2210 | memset(®,0,sizeof(reg));
|
| 2211 |
|
| 2212 | err = at_tok_start(&line);
|
| 2213 | if (err < 0)
|
| 2214 | {
|
| 2215 | goto CPAS_EXIT;
|
| 2216 | }
|
| 2217 | err = at_tok_nextint(&line, &tmp_int);
|
| 2218 | if (err < 0)
|
| 2219 | {
|
| 2220 | goto CPAS_EXIT;
|
| 2221 | }
|
| 2222 | reg.pas = (uint8)tmp_int;
|
| 2223 | reg.call_wait = MBTK_CPAS;
|
| 2224 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 2225 | CPAS_EXIT:
|
| 2226 | free(free_ptr);
|
| 2227 | }
|
| 2228 | // +CALLDISCONNECT: 1
|
| 2229 | else if(strStartsWith(s, "+CALLDISCONNECT:"))
|
| 2230 | {
|
| 2231 | mbtk_call_info_t reg;
|
| 2232 | reg.call_wait = 0;
|
| 2233 | char* tmp_s = memdup(s,strlen(s));
|
| 2234 | char* free_ptr = tmp_s;
|
| 2235 | char *line = tmp_s;
|
| 2236 | int tmp_int;
|
| 2237 | int err;
|
| 2238 |
|
| 2239 | memset(®,0,sizeof(reg));
|
| 2240 |
|
| 2241 | err = at_tok_start(&line);
|
| 2242 | if (err < 0)
|
| 2243 | {
|
| 2244 | goto CALLDISCONNECTED_EXIT;
|
| 2245 | }
|
| 2246 | err = at_tok_nextint(&line, &tmp_int);
|
| 2247 | if (err < 0)
|
| 2248 | {
|
| 2249 | goto CALLDISCONNECTED_EXIT;
|
| 2250 | }
|
| 2251 | reg.disconnected_id = tmp_int;
|
| 2252 | reg.call_wait = MBTK_DISCONNECTED;
|
| 2253 |
|
| 2254 | if(reg.call_wait == MBTK_DISCONNECTED)
|
| 2255 | {
|
| 2256 | //mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
|
| 2257 | }
|
| 2258 |
|
| 2259 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 2260 |
|
| 2261 | CALLDISCONNECTED_EXIT:
|
| 2262 | free(free_ptr);
|
| 2263 | }
|
| 2264 | // *SIMDETEC:1,SIM
|
| 2265 | else if(strStartsWith(s, "*SIMDETEC:"))
|
| 2266 | {
|
| 2267 | if(strStartsWith(s, "*SIMDETEC:1,NOS"))
|
| 2268 | {
|
| 2269 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2270 | }
|
| 2271 |
|
| 2272 | sim_info_reg.sim = -1;
|
| 2273 | if(strStartsWith(s, "*SIMDETEC:1,NOS"))
|
| 2274 | sim_info_reg.sim = 0;
|
| 2275 | else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
|
| 2276 | sim_info_reg.sim = 1;
|
| 2277 | if(sim_info_reg.sim == 0)
|
| 2278 | {
|
| 2279 | uint8 data_pdp;
|
| 2280 | data_pdp = 11; //
|
| 2281 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 2282 | }
|
| 2283 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 2284 | }
|
| 2285 | // *EUICC:1
|
| 2286 | /*0: SIM
|
| 2287 | 1: USIM
|
| 2288 | 2: TEST SIM
|
| 2289 | 3: TEST USIM
|
| 2290 | 4: UNKNOWN
|
| 2291 | Note: *EUICC:
|
| 2292 | */
|
| 2293 | else if(strStartsWith(s, "*EUICC:"))
|
| 2294 | {
|
| 2295 | sim_info_reg.sim_card_type = -1;
|
| 2296 | if(strStartsWith(s, "*EUICC: 0"))
|
| 2297 | sim_info_reg.sim_card_type = 1;
|
| 2298 | else if(strStartsWith(s, "*EUICC: 1"))
|
| 2299 | sim_info_reg.sim_card_type = 2;
|
| 2300 | else if(strStartsWith(s, "*EUICC: 2"))
|
| 2301 | sim_info_reg.sim_card_type = 1;
|
| 2302 | else if(strStartsWith(s, "*EUICC: 3"))
|
| 2303 | sim_info_reg.sim_card_type = 2;
|
| 2304 | else if(strStartsWith(s, "*EUICC: 4"))
|
| 2305 | sim_info_reg.sim_card_type = 0;
|
| 2306 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 2307 | }
|
| 2308 | // +CPIN: SIM PIN
|
| 2309 | else if(strStartsWith(s, "+CPIN:"))
|
| 2310 | {
|
| 2311 | sim_info_reg.sim = -1;
|
| 2312 | if(strStartsWith(s, "+CPIN: READY"))
|
| 2313 | {
|
| 2314 | sim_info_reg.sim = 1;
|
| 2315 | net_info.sim_state = MBTK_SIM_READY;
|
| 2316 | }
|
| 2317 | else if(strStartsWith(s, "+CPIN: SIM PIN"))
|
| 2318 | {
|
| 2319 | sim_info_reg.sim = 2;
|
| 2320 | net_info.sim_state = MBTK_SIM_PIN;
|
| 2321 | }
|
| 2322 | else if(strStartsWith(s, "+CPIN: SIM PUK"))
|
| 2323 | {
|
| 2324 | sim_info_reg.sim = 3;
|
| 2325 | net_info.sim_state = MBTK_SIM_PUK;
|
| 2326 | }
|
| 2327 | else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
|
| 2328 | {
|
| 2329 | sim_info_reg.sim = 4;
|
| 2330 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2331 | }
|
| 2332 | else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
|
| 2333 | {
|
| 2334 | sim_info_reg.sim = 5;
|
| 2335 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2336 | }
|
| 2337 | else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
|
| 2338 | {
|
| 2339 | sim_info_reg.sim = 6;
|
| 2340 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2341 | }
|
| 2342 | else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
|
| 2343 | {
|
| 2344 | sim_info_reg.sim = 7;
|
| 2345 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2346 | }
|
| 2347 | else if(strStartsWith(s, "+CPIN: SIM PIN2"))
|
| 2348 | {
|
| 2349 | sim_info_reg.sim = 8;
|
| 2350 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2351 | }
|
| 2352 | else if(strStartsWith(s, "+CPIN: SIM PUK2"))
|
| 2353 | {
|
| 2354 | sim_info_reg.sim = 9;
|
| 2355 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2356 | }
|
| 2357 | else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
|
| 2358 | {
|
| 2359 | sim_info_reg.sim = 10;
|
| 2360 | net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
|
| 2361 | }
|
| 2362 | else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
|
| 2363 | {
|
| 2364 | sim_info_reg.sim = 11;
|
| 2365 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2366 | }
|
| 2367 | else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
|
| 2368 | {
|
| 2369 | sim_info_reg.sim = 12;
|
| 2370 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2371 | }
|
| 2372 | else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
|
| 2373 | {
|
| 2374 | sim_info_reg.sim = 13;
|
| 2375 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2376 | }
|
| 2377 | else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
|
| 2378 | {
|
| 2379 | sim_info_reg.sim = 14;
|
| 2380 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2381 | }
|
| 2382 | else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
|
| 2383 | {
|
| 2384 | sim_info_reg.sim = 15;
|
| 2385 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2386 | }
|
| 2387 | else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
|
| 2388 | {
|
| 2389 | sim_info_reg.sim = 16;
|
| 2390 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2391 | }
|
| 2392 | else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
|
| 2393 | {
|
| 2394 | sim_info_reg.sim = 17;
|
| 2395 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2396 | }
|
| 2397 | else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
|
| 2398 | {
|
| 2399 | sim_info_reg.sim = 18;
|
| 2400 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2401 | }
|
| 2402 | else
|
| 2403 | sim_info_reg.sim = 20;
|
| 2404 |
|
| 2405 | if(sim_info_reg.sim == 18)
|
| 2406 | {
|
| 2407 | uint8 data_pdp;
|
| 2408 | data_pdp = 11; //
|
| 2409 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 2410 | }
|
| 2411 |
|
| 2412 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 2413 | }
|
| 2414 | // +CMT: ,23
|
| 2415 | // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
|
| 2416 | else if(strStartsWith(s, "+CMT:") || sms_cmt)
|
| 2417 | {
|
| 2418 | if(!sms_cmt){
|
| 2419 | sms_cmt = true;
|
| 2420 | }else{
|
| 2421 | sms_cmt = false;
|
| 2422 | }
|
| 2423 | printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
|
| 2424 | urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
|
| 2425 | }
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 2426 | #endif
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2427 | 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"
|
| 2428 | {
|
| 2429 |
|
| 2430 | }
|
| 2431 | else
|
| 2432 | {
|
| 2433 | LOGV("Unknown URC : %s", s);
|
| 2434 | }
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2435 | }
|
| 2436 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2437 | static void onUnsolicited1(const char *s, const char *sms_pdu)
|
| 2438 | {
|
| 2439 | onUnsolicited(MBTK_SIM_1, s, sms_pdu);
|
| 2440 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2441 | #ifdef LYNQ_DSDS_SUPPORT
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2442 | static void onUnsolicited2(const char *s, const char *sms_pdu)
|
| 2443 | {
|
| 2444 | onUnsolicited(MBTK_SIM_2, s, sms_pdu);
|
| 2445 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2446 | #endif
|
| 2447 | static int openSocket(const char* sockname, bool with_wait)
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2448 | {
|
| 2449 | int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
| 2450 | if (sock < 0)
|
| 2451 | {
|
| 2452 | LOGE("Error create socket: %s\n", strerror(errno));
|
| 2453 | return -1;
|
| 2454 | }
|
| 2455 | struct sockaddr_un addr;
|
| 2456 | memset(&addr, 0, sizeof(addr));
|
| 2457 | addr.sun_family = AF_UNIX;
|
| 2458 | strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2459 | if(with_wait) {
|
| 2460 | while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
|
| 2461 | {
|
| 2462 | LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
|
| 2463 | sleep(1);
|
| 2464 | }
|
| 2465 | }
|
| 2466 | else
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2467 | {
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2468 | if (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
|
| 2469 | {
|
| 2470 | LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
|
| 2471 | // sleep(1);
|
| 2472 | }
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2473 | }
|
| 2474 |
|
| 2475 | #if 0
|
| 2476 | int sk_flags = fcntl(sock, F_GETFL, 0);
|
| 2477 | fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
|
| 2478 | #endif
|
| 2479 |
|
| 2480 | return sock;
|
| 2481 | }
|
| 2482 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2483 | static void ril_at_ready_process() |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2484 | {
|
| 2485 | // SIM1 radio state config.
|
| 2486 | ril_info.radio_state[MBTK_SIM_1] = ril_radio_state_get(MBTK_SIM_1, ATPORTTYPE_0);
|
| 2487 | if (ril_info.radio_state[MBTK_SIM_1] != MBTK_RADIO_STATE_FULL_FUNC)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2488 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2489 | ril_radio_state_set(MBTK_SIM_1, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2490 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2491 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2492 | if(ril_info.radio_state[MBTK_SIM_1] == MBTK_RADIO_STATE_FULL_FUNC)
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2493 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2494 | at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+CEREG=2", NULL);
|
| 2495 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2496 | #ifdef LYNQ_DSDS_SUPPORT
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2497 | // SIM2 radio state config.
|
| 2498 | ril_info.radio_state[MBTK_SIM_2] = ril_radio_state_get(MBTK_SIM_2, ATPORTTYPE_0);
|
| 2499 | if (ril_info.radio_state[MBTK_SIM_2] != MBTK_RADIO_STATE_FULL_FUNC)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2500 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2501 | ril_radio_state_set(MBTK_SIM_2, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);
|
| 2502 | }
|
| 2503 | |
| 2504 | if(ril_info.radio_state[MBTK_SIM_2] == MBTK_RADIO_STATE_FULL_FUNC)
|
| 2505 | {
|
| 2506 | at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+CEREG=2", NULL);
|
| 2507 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2508 | #endif
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2509 | // SIM1 state config.
|
| 2510 | ril_info.sim_state[MBTK_SIM_1] = ril_sim_state_get(MBTK_SIM_1, ATPORTTYPE_0);
|
| 2511 | if(ril_info.sim_state[MBTK_SIM_1] == MBTK_SIM_STATE_READY)
|
| 2512 | { |
| 2513 | LOGD("SIM1 READY!");
|
| 2514 | at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+COPS=3", NULL);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2515 |
|
| 2516 | // Set APN from prop.
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2517 | apn_auto_conf_from_prop(MBTK_SIM_1, ATPORTTYPE_0);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2518 | } |
| 2519 | else |
| 2520 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2521 | LOGE("SIM1 NOT READY!");
|
| 2522 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2523 | #ifdef LYNQ_DSDS_SUPPORT
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2524 | // SIM2 state config.
|
| 2525 | ril_info.sim_state[MBTK_SIM_2] = ril_sim_state_get(MBTK_SIM_2, ATPORTTYPE_0);
|
| 2526 | if(ril_info.sim_state[MBTK_SIM_2] == MBTK_SIM_STATE_READY)
|
| 2527 | { |
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2528 | LOGD("SIM2 READY!");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2529 | at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+COPS=3", NULL);
|
| 2530 |
|
| 2531 | // Set APN from prop.
|
| 2532 | apn_auto_conf_from_prop(MBTK_SIM_2, ATPORTTYPE_0);
|
| 2533 | } |
| 2534 | else |
| 2535 | { |
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2536 | LOGE("SIM2 NOT READY!");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2537 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2538 | #endif
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2539 | if(req_dual_sim_get(ATPORTTYPE_0, &(ril_info.cur_sim_id), NULL)) {
|
| 2540 | LOGE("req_dual_sim_get() fail, so set to SIM1.");
|
| 2541 | ril_info.cur_sim_id = MBTK_SIM_1;
|
| 2542 | } else {
|
| 2543 | LOGD("Current SIM : %d", ril_info.cur_sim_id);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2544 | }
|
| 2545 | }
|
| 2546 |
|
| 2547 | static void ind_regisger(sock_cli_info_t* cli_info, uint16 ind)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2548 | { |
| 2549 | uint32 i = 0; |
| 2550 | while(i < cli_info->ind_num) |
| 2551 | { |
| 2552 | if(cli_info->ind_register[i] == ind) |
| 2553 | break; |
| 2554 | i++; |
| 2555 | } |
| 2556 | |
| 2557 | if(i == cli_info->ind_num) // No found IND |
| 2558 | { |
| 2559 | cli_info->ind_register[i] = ind; |
| 2560 | cli_info->ind_num++; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2561 | LOGD("Register IND : %s", id2str(ind));
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2562 | } |
| 2563 | else |
| 2564 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2565 | LOGW("IND had exist.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2566 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2567 | }
|
| 2568 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2569 | // Process AT URC data |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2570 | static int send_pack_to_queue(sock_cli_info_t* cli_info, void* pack)
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2571 | {
|
| 2572 | if(cli_info) {
|
| 2573 | if(ril_info.msg_queue[cli_info->port].count >= PACK_PROCESS_QUEUE_MAX)
|
| 2574 | {
|
| 2575 | LOGE("Packet process queue is full");
|
| 2576 | return -1;
|
| 2577 | }
|
| 2578 | } else {
|
| 2579 | if(ril_info.msg_queue[ATPORTTYPE_0].count >= PACK_PROCESS_QUEUE_MAX)
|
| 2580 | {
|
| 2581 | LOGE("Packet process queue is full");
|
| 2582 | return -1;
|
| 2583 | }
|
| 2584 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2585 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2586 | ril_msg_queue_info_t *item = (ril_msg_queue_info_t*)malloc(sizeof(ril_msg_queue_info_t));
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2587 | if(!item) |
| 2588 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2589 | LOGE("malloc() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2590 | return -1; |
| 2591 | } |
| 2592 | item->cli_info = cli_info; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2593 | item->pack = pack;
|
| 2594 |
|
| 2595 | if(cli_info) {
|
| 2596 | mbtk_queue_put(&(ril_info.msg_queue[cli_info->port]), item);
|
| 2597 |
|
| 2598 | // If thread is waitting,continue it.
|
| 2599 | pthread_mutex_lock(&(ril_info.msg_mutex[cli_info->port]));
|
| 2600 | pthread_cond_signal(&(ril_info.msg_cond[cli_info->port]));
|
| 2601 | pthread_mutex_unlock(&(ril_info.msg_mutex[cli_info->port]));
|
| 2602 | } else { // URC message, is null.
|
| 2603 | mbtk_queue_put(&(ril_info.msg_queue[ATPORTTYPE_0]), item);
|
| 2604 |
|
| 2605 | // If thread is waitting,continue it.
|
| 2606 | pthread_mutex_lock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
|
| 2607 | pthread_cond_signal(&(ril_info.msg_cond[ATPORTTYPE_0]));
|
| 2608 | pthread_mutex_unlock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
|
| 2609 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2610 | |
| 2611 | return 0; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2612 | }
|
| 2613 |
|
| 2614 |
|
| 2615 | static void pack_distribute(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2616 | { |
| 2617 | // Register IND Message. |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2618 | if(pack->msg_type == RIL_MSG_TYPE_REQ)
|
| 2619 | {
|
| 2620 | if(pack->msg_id > RIL_MSG_ID_IND_BEGIN
|
| 2621 | && pack->msg_id < RIL_MSG_ID_IND_END) {
|
| 2622 | mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
|
| 2623 | if(cli_info->ind_num >= IND_REGISTER_MAX)
|
| 2624 | {
|
| 2625 | LOGE("IND if full.");
|
| 2626 | err = MBTK_RIL_ERR_IND_FULL;
|
| 2627 | }
|
| 2628 | else
|
| 2629 | {
|
| 2630 | ind_regisger(cli_info, pack->msg_id);
|
| 2631 | }
|
| 2632 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2633 | ril_error_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, err);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2634 |
|
| 2635 | ril_msg_pack_free(pack);
|
| 2636 | } else {
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2637 | LOGD("Start process REQ(%s, Port : %d), Length : %d", id2str(pack->msg_id), cli_info->port, pack->data_len);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2638 | if(0 && pack->data_len > 0)
|
| 2639 | {
|
| 2640 | log_hex("DATA", pack->data, pack->data_len);
|
| 2641 | }
|
| 2642 |
|
| 2643 | // Send to REQ_process_thread process.
|
| 2644 | send_pack_to_queue(cli_info, pack);
|
| 2645 |
|
| 2646 | // For test.
|
| 2647 | // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS);
|
| 2648 | }
|
| 2649 | } else {
|
| 2650 | LOGE("Pack type error : %d", pack->msg_type);
|
| 2651 | }
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2652 | }
|
| 2653 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2654 | // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP. |
| 2655 | // Otherwise, do not call pack_error_send(). |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2656 | static mbtk_ril_err_enum pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2657 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2658 | if(pack->msg_id > RIL_MSG_ID_DEV_BEGIN && pack->msg_id < RIL_MSG_ID_DEV_END) {
|
| 2659 | return dev_pack_req_process(cli_info, pack);
|
| 2660 | } else if(pack->msg_id > RIL_MSG_ID_SIM_BEGIN && pack->msg_id < RIL_MSG_ID_SIM_END) {
|
| 2661 | return sim_pack_req_process(cli_info, pack);
|
| 2662 | } else if(pack->msg_id > RIL_MSG_ID_NET_BEGIN && pack->msg_id < RIL_MSG_ID_NET_END) {
|
| 2663 | return net_pack_req_process(cli_info, pack);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2664 | } else if(pack->msg_id > RIL_MSG_ID_DATA_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_DATA_CALL_END) {
|
| 2665 | return data_call_pack_req_process(cli_info, pack);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2666 | } else if(pack->msg_id > RIL_MSG_ID_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_CALL_END) {
|
| 2667 | return call_pack_req_process(cli_info, pack);
|
| 2668 | } else if(pack->msg_id > RIL_MSG_ID_SMS_BEGIN && pack->msg_id < RIL_MSG_ID_SMS_END) {
|
| 2669 | return sms_pack_req_process(cli_info, pack);
|
| 2670 | } else if(pack->msg_id > RIL_MSG_ID_PB_BEGIN && pack->msg_id < RIL_MSG_ID_PB_END) {
|
| 2671 | return pb_pack_req_process(cli_info, pack);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2672 | } else if(pack->msg_id > RIL_MSG_ID_ECALL_BEGIN && pack->msg_id < RIL_MSG_ID_ECALL_END) {
|
| 2673 | return ecall_pack_req_process(cli_info, pack);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2674 | } else {
|
| 2675 | LOGW("Unknown msg id : %d", pack->msg_id);
|
| 2676 | return MBTK_RIL_ERR_FORMAT;
|
| 2677 | }
|
| 2678 | }
|
| 2679 |
|
| 2680 | static void urc_msg_process(ril_urc_msg_info_t *msg)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2681 | { |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2682 | // data can be NULL (For RIL_URC_MSG_BAND_SET)
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2683 | if(!msg->data || msg->data_len <= 0) {
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2684 | LOGW("URC data is NULL.");
|
| 2685 | // return;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2686 | }
|
| 2687 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2688 | switch(msg->msg) { |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2689 | case RIL_MSG_ID_IND_RADIO_STATE_CHANGE:
|
| 2690 | {
|
| 2691 | mbtk_ril_radio_state_info_t *state = (mbtk_ril_radio_state_info_t*)msg->data;
|
| 2692 | LOGD("Radio state : %d", state->radio_state);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2693 | break; |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2694 | }
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 2695 | case RIL_MSG_ID_IND_SIM_STATE_CHANGE:
|
| 2696 | {
|
| 2697 | mbtk_ril_sim_state_info_t *state = (mbtk_ril_sim_state_info_t*)msg->data;
|
| 2698 | if(state->sim_state == MBTK_SIM_STATE_READY) {
|
| 2699 | LOGD("SIM READY!");
|
| 2700 | at_send_command(ATPORTTYPE_0, "AT+COPS=3", NULL);
|
| 2701 |
|
| 2702 | // Set APN from prop.
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2703 | apn_auto_conf_from_prop(state->sim_id, ATPORTTYPE_0);
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 2704 | }
|
| 2705 | }
|
b.liu | afdf2c6 | 2024-11-12 11:10:44 +0800 | [diff] [blame] | 2706 | case RIL_MSG_ID_IND_NET_REG_STATE_CHANGE:
|
| 2707 | {
|
| 2708 | mbtk_ril_net_reg_state_info_t *reg_state = (mbtk_ril_net_reg_state_info_t*)msg->data;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2709 | data_call_retry(reg_state->sim_id, ATPORTTYPE_0, reg_state);
|
b.liu | afdf2c6 | 2024-11-12 11:10:44 +0800 | [diff] [blame] | 2710 | break;
|
| 2711 | }
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2712 | case RIL_URC_MSG_BAND_SET:
|
| 2713 | {
|
| 2714 | int cme_err = MBTK_RIL_ERR_CME_NON;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2715 | if(req_band_set(MBTK_SIM_1, ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2716 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2717 | LOGE("Set SIM1 band fail.");
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2718 | }
|
| 2719 | else // Set band success.
|
| 2720 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2721 | LOGD("Set SIM1 band success.");
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2722 | #ifdef LYNQ_DSDS_SUPPORT
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2723 | cme_err = MBTK_RIL_ERR_CME_NON;
|
| 2724 | if(req_band_set(MBTK_SIM_2, ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
|
| 2725 | {
|
| 2726 | LOGE("Set SIM2 band fail.");
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2727 | }
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2728 | else // Set band success.
|
| 2729 | {
|
| 2730 | LOGD("Set SIM2 band success.");
|
| 2731 | // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2732 | #endif
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2733 | band_info.band_set_success = TRUE;
|
| 2734 | if(band_info.band_area == MBTK_MODEM_BAND_AREA_CN) {
|
| 2735 | property_set("persist.mbtk.band_config", "CN");
|
| 2736 | } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_EU) {
|
| 2737 | property_set("persist.mbtk.band_config", "EU");
|
| 2738 | } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_SA) {
|
| 2739 | property_set("persist.mbtk.band_config", "SA");
|
| 2740 | } else {
|
| 2741 | property_set("persist.mbtk.band_config", "ALL");
|
| 2742 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2743 | #ifdef LYNQ_DSDS_SUPPORT
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2744 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2745 | #endif
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2746 | }
|
| 2747 | break;
|
| 2748 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2749 | default: |
| 2750 | { |
| 2751 | LOGE("Unknown URC : %d", msg->msg); |
| 2752 | break; |
| 2753 | } |
| 2754 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2755 | }
|
| 2756 |
|
| 2757 | // Read client conn/msg and push into ril_info.msg_queue.
|
| 2758 | static void* ril_read_pthread(void* arg)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2759 | { |
| 2760 | UNUSED(arg); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2761 | ril_info.epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1);
|
| 2762 | if(ril_info.epoll_fd < 0)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2763 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2764 | LOGE("epoll_create() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2765 | return NULL; |
| 2766 | } |
| 2767 | |
| 2768 | uint32 event = EPOLLIN | EPOLLET; |
| 2769 | struct epoll_event ev; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2770 | ev.data.fd = ril_info.sock_listen_fd;
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2771 | ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2772 | epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, ril_info.sock_listen_fd, &ev);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2773 | |
| 2774 | int nready = -1; |
| 2775 | struct epoll_event epoll_events[EPOLL_LISTEN_MAX]; |
| 2776 | while(1) |
| 2777 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2778 | nready = epoll_wait(ril_info.epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2779 | if(nready > 0) |
| 2780 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2781 | sock_cli_info_t *cli_info = NULL;
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2782 | int i; |
| 2783 | for(i = 0; i < nready; i++) |
| 2784 | { |
| 2785 | LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events); |
| 2786 | if(epoll_events[i].events & EPOLLHUP) // Client Close. |
| 2787 | { |
| 2788 | if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) |
| 2789 | { |
| 2790 | cli_close(cli_info); |
| 2791 | } |
| 2792 | else |
| 2793 | { |
| 2794 | LOG("Unknown client[fd = %d].", epoll_events[i].data.fd); |
| 2795 | } |
| 2796 | } |
| 2797 | else if(epoll_events[i].events & EPOLLIN) |
| 2798 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2799 | if(epoll_events[i].data.fd == ril_info.sock_listen_fd) // New clients connected.
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2800 | { |
| 2801 | int client_fd = -1; |
| 2802 | while(1) |
| 2803 | { |
| 2804 | struct sockaddr_in cliaddr; |
| 2805 | socklen_t clilen = sizeof(cliaddr); |
| 2806 | client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen); |
| 2807 | if(client_fd < 0) |
| 2808 | { |
| 2809 | if(errno == EAGAIN) |
| 2810 | { |
| 2811 | LOG("All client connect get."); |
| 2812 | } |
| 2813 | else |
| 2814 | { |
| 2815 | LOG("accept() error[%d].", errno); |
| 2816 | } |
| 2817 | break; |
| 2818 | } |
| 2819 | // Set O_NONBLOCK |
| 2820 | int flags = fcntl(client_fd, F_GETFL, 0); |
| 2821 | if (flags > 0) |
| 2822 | { |
| 2823 | flags |= O_NONBLOCK; |
| 2824 | if (fcntl(client_fd, F_SETFL, flags) < 0) |
| 2825 | { |
| 2826 | LOG("Set flags error:%d", errno); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | memset(&ev,0,sizeof(struct epoll_event)); |
| 2831 | ev.data.fd = client_fd; |
| 2832 | ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2833 | epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, client_fd, &ev);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2834 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2835 | sock_cli_info_t *info = (sock_cli_info_t*)malloc(sizeof(sock_cli_info_t));
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2836 | if(info) |
| 2837 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2838 | memset(info, 0, sizeof(sock_cli_info_t));
|
| 2839 | info->fd = client_fd;
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2840 |
|
| 2841 | // Default AT port.
|
| 2842 | info->port = ATPORTTYPE_0;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2843 | info->sim_id = MBTK_SIM_1;
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2844 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2845 | list_add(ril_info.sock_client_list, info);
|
| 2846 | LOG("Add New Client FD Into List.");
|
| 2847 |
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2848 | // Send msg RIL_MSG_ID_IND_SER_STATE_CHANGE to client.
|
| 2849 | mbtk_ril_ser_state_enum state = MBTK_RIL_SER_STATE_READY;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2850 | ril_ind_pack_send(MBTK_SIM_1, client_fd, RIL_MSG_ID_IND_SER_STATE_CHANGE, &state, 1);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2851 | } |
| 2852 | else |
| 2853 | { |
| 2854 | LOG("malloc() fail."); |
| 2855 | } |
| 2856 | } |
| 2857 | } |
| 2858 | else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive. |
| 2859 | { |
| 2860 | // Read and process every message. |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2861 | mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
|
| 2862 | ril_msg_pack_info_t** pack = ril_pack_recv(cli_info->fd, true, &err);
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2863 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2864 | // Parse packet error,send error response to client. |
| 2865 | if(pack == NULL) |
| 2866 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2867 | ril_error_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, RIL_MSG_ID_UNKNOWN, RIL_MSG_INDEX_INVALID, err);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2868 | } |
| 2869 | else |
| 2870 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2871 | ril_msg_pack_info_t** pack_ptr = pack;
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2872 | while(*pack_ptr) |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2873 | {
|
| 2874 | // Update AT port in the first.
|
| 2875 | cli_info->port = (ATPortType_enum)((*pack_ptr)->at_port);
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2876 | cli_info->sim_id = (mbtk_sim_type_enum)((*pack_ptr)->sim_id);
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2877 | #ifndef LYNQ_DSDS_SUPPORT
|
| 2878 | if(cli_info->sim_id == MBTK_SIM_2)
|
| 2879 | {
|
| 2880 | 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.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 2881 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2882 | else
|
| 2883 | #endif
|
| 2884 | {
|
| 2885 | if(cli_info->sim_id == MBTK_SIM_AUTO) {
|
| 2886 | cli_info->sim_id = ril_info.cur_sim_id;
|
| 2887 | LOGD("Auto sim => %d", cli_info->sim_id);
|
| 2888 | }
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2889 |
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 2890 | pack_distribute(cli_info, *pack_ptr); |
| 2891 | // Not free,will free in pack_process() or packet process thread. |
| 2892 | //mbtk_info_pack_free(pack_ptr); |
| 2893 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2894 | pack_ptr++; |
| 2895 | } |
| 2896 | |
| 2897 | free(pack); |
| 2898 | } |
| 2899 | } |
| 2900 | else |
| 2901 | { |
| 2902 | LOG("Unknown socket : %d", epoll_events[i].data.fd); |
| 2903 | } |
| 2904 | } |
| 2905 | else |
| 2906 | { |
| 2907 | LOG("Unknown event : %x", epoll_events[i].events); |
| 2908 | } |
| 2909 | } |
| 2910 | } |
| 2911 | else |
| 2912 | { |
| 2913 | LOG("epoll_wait() fail[%d].", errno); |
| 2914 | } |
| 2915 | } |
| 2916 | |
| 2917 | return NULL; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2918 | }
|
| 2919 |
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2920 | static void band_support_init()
|
| 2921 | {
|
| 2922 | mbtk_device_info_modem_t info_modem;
|
| 2923 | memset(&band_info.band_support, 0, sizeof(mbtk_band_info_t));
|
| 2924 | memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2925 | if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
|
| 2926 | LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
|
| 2927 | band_info.band_area = MBTK_MODEM_BAND_AREA_ALL;
|
| 2928 | #ifdef MBTK_5G_SUPPORT
|
| 2929 | band_info.band_support.net_pref = MBTK_NET_PREF_LTE_NR_NR_PREF; // 19
|
| 2930 | band_info.net_support = MBTK_NET_SUPPORT_4G | MBTK_NET_SUPPORT_5G;
|
| 2931 |
|
| 2932 | band_info.band_support.gsm_band = 0;
|
| 2933 | band_info.band_support.umts_band = 0;
|
| 2934 | band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
|
| 2935 | band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
|
| 2936 | band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
|
| 2937 |
|
| 2938 | band_info.band_support.nr_3_band = MBTK_BAND_ALL_NR_3_DEFAULT;
|
| 2939 | band_info.band_support.nr_2_band = MBTK_BAND_ALL_NR_2_DEFAULT;
|
| 2940 | band_info.band_support.nr_1_band = MBTK_BAND_ALL_NR_1_DEFAULT;
|
| 2941 | band_info.band_support.nr_0_band = MBTK_BAND_ALL_NR_0_DEFAULT;
|
| 2942 | #else
|
| 2943 | band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
|
| 2944 | band_info.net_support = MBTK_NET_SUPPORT_2G | MBTK_NET_SUPPORT_3G | MBTK_NET_SUPPORT_4G;
|
| 2945 |
|
| 2946 | band_info.band_support.gsm_band = MBTK_BAND_ALL_GSM_DEFAULT;
|
| 2947 | band_info.band_support.umts_band = MBTK_BAND_ALL_WCDMA_DEFAULT;
|
| 2948 | band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
|
| 2949 | band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
|
| 2950 | band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
|
| 2951 |
|
| 2952 | band_info.band_support.nr_3_band = 0;
|
| 2953 | band_info.band_support.nr_2_band = 0;
|
| 2954 | band_info.band_support.nr_1_band = 0;
|
| 2955 | band_info.band_support.nr_0_band = 0;
|
| 2956 | #endif
|
| 2957 | } else {
|
b.liu | b7530d2 | 2025-06-16 19:49:05 +0800 | [diff] [blame] | 2958 | if(info_modem.version == DEV_INFO_VERSION_V1) {
|
| 2959 | band_info.band_area = info_modem.modem.v1.band_area;
|
| 2960 | band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
|
| 2961 | band_info.band_support.gsm_band = info_modem.modem.v1.band_gsm;
|
| 2962 | band_info.band_support.umts_band = info_modem.modem.v1.band_wcdma;
|
| 2963 | band_info.band_support.tdlte_band = info_modem.modem.v1.band_tdlte;
|
| 2964 | band_info.band_support.fddlte_band = info_modem.modem.v1.band_fddlte;
|
| 2965 | band_info.band_support.lte_ext_band = info_modem.modem.v1.band_lte_ext;
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2966 | } else {
|
b.liu | b7530d2 | 2025-06-16 19:49:05 +0800 | [diff] [blame] | 2967 | band_info.band_area = info_modem.modem.v2.band_area;
|
| 2968 | band_info.net_support = info_modem.modem.v2.net_support;
|
| 2969 | if(info_modem.modem.v2.net_pref < MBTK_NET_PREF_MAX) {
|
| 2970 | band_info.band_support.net_pref = info_modem.modem.v2.net_pref;
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2971 | } else {
|
b.liu | b7530d2 | 2025-06-16 19:49:05 +0800 | [diff] [blame] | 2972 | if(band_info.net_support & MBTK_NET_SUPPORT_5G) {
|
| 2973 | band_info.band_support.net_pref = MBTK_NET_PREF_LTE_NR_NR_PREF; // 19
|
| 2974 | } else {
|
| 2975 | band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
|
| 2976 | }
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2977 | }
|
b.liu | b7530d2 | 2025-06-16 19:49:05 +0800 | [diff] [blame] | 2978 | band_info.band_support.gsm_band = info_modem.modem.v2.band_gsm;
|
| 2979 | band_info.band_support.umts_band = info_modem.modem.v2.band_wcdma;
|
| 2980 | band_info.band_support.tdlte_band = info_modem.modem.v2.band_tdlte;
|
| 2981 | band_info.band_support.fddlte_band = info_modem.modem.v2.band_fddlte;
|
| 2982 | band_info.band_support.lte_ext_band = info_modem.modem.v2.band_lte_ext;
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2983 |
|
b.liu | b7530d2 | 2025-06-16 19:49:05 +0800 | [diff] [blame] | 2984 | band_info.band_support.nr_3_band = info_modem.modem.v2.band_nr_3;
|
| 2985 | band_info.band_support.nr_2_band = info_modem.modem.v2.band_nr_2;
|
| 2986 | band_info.band_support.nr_1_band = info_modem.modem.v2.band_nr_1;
|
| 2987 | band_info.band_support.nr_0_band = info_modem.modem.v2.band_nr_0;
|
| 2988 | }
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2989 | }
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2990 | }
|
| 2991 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2992 | static void* ril_process_thread(void* arg)
|
| 2993 | { |
| 2994 | UNUSED(arg);
|
| 2995 | ATPortType_enum *port = (ATPortType_enum*)arg;
|
| 2996 | ril_msg_queue_info_t* item = NULL;
|
| 2997 | |
| 2998 | pthread_mutex_lock(&(ril_info.msg_mutex[*port]));
|
| 2999 | while(TRUE) |
| 3000 | { |
| 3001 | if(mbtk_queue_empty(&(ril_info.msg_queue[*port])))
|
| 3002 | { |
| 3003 | LOG("[Port-%d]Packet process wait...", *port);
|
| 3004 | pthread_cond_wait(&(ril_info.msg_cond[*port]), &(ril_info.msg_mutex[*port]));
|
| 3005 | LOG("[Port-%d]Packet process continue...", *port);
|
| 3006 | } |
| 3007 | else |
| 3008 | { |
| 3009 | LOG("Packet process queue not empty,continue..."); |
| 3010 | } |
| 3011 | |
| 3012 | // Process all information request. |
| 3013 | mbtk_ril_err_enum err;
|
| 3014 | while((item = (ril_msg_queue_info_t*)mbtk_queue_get(&(ril_info.msg_queue[*port]))) != NULL)
|
| 3015 | { |
| 3016 | if(item->cli_info) { // REQ form client. |
| 3017 | ril_msg_pack_info_t *pack = (ril_msg_pack_info_t*)item->pack;
|
| 3018 | LOGD("Process REQ %s.", id2str(pack->msg_id));
|
| 3019 | ril_info.at_process[*port] = true;
|
| 3020 | err = pack_req_process(item->cli_info, pack); |
| 3021 | if(err != MBTK_RIL_ERR_SUCCESS)
|
| 3022 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3023 | 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.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3024 | } |
| 3025 | ril_info.at_process[*port] = false;
|
| 3026 | ril_msg_pack_free(pack);
|
| 3027 | free(item); |
| 3028 | } else { // REQ from myself.
|
| 3029 | if(item->pack) {
|
| 3030 | ril_urc_msg_info_t *urc = (ril_urc_msg_info_t*)item->pack;
|
| 3031 | LOGD("Process URC %d.", urc->msg);
|
| 3032 | urc_msg_process(urc);
|
| 3033 | if(urc->data)
|
| 3034 | free(urc->data);
|
| 3035 | free(urc);
|
| 3036 | }
|
| 3037 | } |
| 3038 | } |
| 3039 | } |
| 3040 | pthread_mutex_unlock(&(ril_info.msg_mutex[*port]));
|
| 3041 |
|
| 3042 | free(port);
|
| 3043 |
|
| 3044 | return NULL; |
| 3045 | }
|
| 3046 |
|
| 3047 | /* |
| 3048 | AT*BAND=15,78,147,482,134742231 |
| 3049 | |
| 3050 | OK |
| 3051 | */ |
| 3052 | static void* band_config_thread() |
| 3053 | { |
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3054 | band_info.band_set_success = FALSE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 3055 | // bool is_first = TRUE;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3056 | while(!band_info.band_set_success) {
|
| 3057 | // Set band.
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 3058 | #if 1
|
| 3059 | ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
|
| 3060 | if(msg) {
|
| 3061 | msg->msg = RIL_URC_MSG_BAND_SET;
|
| 3062 | msg->data = NULL;//mbtk_memcpy(&band_info, sizeof(ril_band_info_t));
|
| 3063 | msg->data_len = 0; //sizeof(ril_band_info_t);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3064 | #if 0
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3065 | if(msg->data == NULL) { |
| 3066 | LOGE("mbtk_memcpy() fail."); |
| 3067 | break; |
| 3068 | } |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 3069 | #endif
|
| 3070 | send_pack_to_queue(NULL, msg);
|
| 3071 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3072 | sleep(5); |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 3073 | } else {
|
| 3074 | LOG("malloc() fail[%d].", errno);
|
| 3075 | break;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3076 | }
|
| 3077 | #else
|
| 3078 | sleep(5);
|
| 3079 | #endif
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | LOGD("Set Band thread exit."); |
| 3083 | return NULL; |
| 3084 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3085 |
|
| 3086 |
|
| 3087 | int ril_server_start()
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3088 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3089 | signal(SIGPIPE, SIG_IGN);
|
| 3090 |
|
| 3091 | memset(&ril_info, 0, sizeof(ril_info_t));
|
| 3092 | memset(&band_info, 0, sizeof(ril_band_info_t));
|
| 3093 | memset(&band_info.band_support, 0xFF, sizeof(mbtk_band_info_t));
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3094 | |
| 3095 | //check cfun and sim card status |
| 3096 | ril_at_ready_process(); |
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 3097 |
|
| 3098 | // Init support band.
|
| 3099 | band_support_init();
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3100 | |
| 3101 | //any AT instruction that is not sent through pack_process_thread needs to precede the thread |
| 3102 | //thread create |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3103 | if(ril_info.sock_listen_fd > 0)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3104 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3105 | LOGE("Information Server Has Started.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3106 | return -1; |
| 3107 | } |
| 3108 | |
| 3109 | struct sockaddr_un server_addr; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3110 | ril_info.sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
| 3111 | if(ril_info.sock_listen_fd < 0)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3112 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3113 | LOGE("socket() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3114 | return -1; |
| 3115 | } |
| 3116 | |
| 3117 | // Set O_NONBLOCK |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3118 | int flags = fcntl(ril_info.sock_listen_fd, F_GETFL, 0);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3119 | if (flags < 0) |
| 3120 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3121 | LOGE("Get flags error:%d", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3122 | goto error; |
| 3123 | } |
| 3124 | flags |= O_NONBLOCK; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3125 | if (fcntl(ril_info.sock_listen_fd, F_SETFL, flags) < 0)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3126 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3127 | LOGE("Set flags error:%d", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3128 | goto error; |
| 3129 | } |
| 3130 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3131 | unlink(RIL_SOCK_NAME);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3132 | memset(&server_addr, 0, sizeof(struct sockaddr_un)); |
| 3133 | server_addr.sun_family = AF_LOCAL; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3134 | strcpy(server_addr.sun_path, RIL_SOCK_NAME);
|
| 3135 | if(bind(ril_info.sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3136 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3137 | LOGE("bind() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3138 | goto error; |
| 3139 | } |
| 3140 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3141 | if(listen(ril_info.sock_listen_fd, SOCK_CLIENT_MAX))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3142 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3143 | LOGE("listen() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3144 | goto error; |
| 3145 | } |
| 3146 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3147 | ril_info.sock_client_list = list_create(sock_cli_free_func);
|
| 3148 | if(ril_info.sock_client_list == NULL)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3149 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3150 | LOGE("list_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3151 | goto error; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3152 | }
|
| 3153 |
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3154 | mbtk_queue_init(&(ril_info.msg_queue[ATPORTTYPE_0]));
|
| 3155 | pthread_mutex_init(&(ril_info.msg_mutex[ATPORTTYPE_0]), NULL);
|
| 3156 | pthread_cond_init(&(ril_info.msg_cond[ATPORTTYPE_0]), NULL);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3157 | |
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 3158 | pthread_t info_pid, pack_pid/*, monitor_pid, urc_pid, bootconn_pid*/;
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3159 | pthread_attr_t thread_attr; |
| 3160 | pthread_attr_init(&thread_attr); |
| 3161 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 3162 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3163 | LOGE("pthread_attr_setdetachstate() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3164 | goto error; |
| 3165 | } |
| 3166 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3167 | if(pthread_create(&info_pid, &thread_attr, ril_read_pthread, NULL))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3168 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3169 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3170 | goto error; |
| 3171 | } |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3172 |
|
| 3173 | ATPortType_enum *port_0 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3174 | *port_0 = MBTK_AT_PORT_DEF;
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3175 | if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_0))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3176 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3177 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3178 | goto error; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3179 | }
|
| 3180 |
|
| 3181 | ATPortType_enum *port_1 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3182 | *port_1 = MBTK_AT_PORT_VOICE;
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3183 | if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_1))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3184 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3185 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3186 | goto error; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3187 | }
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 3188 |
|
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3189 | ATPortType_enum *port_2 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3190 | *port_2 = MBTK_AT_PORT_DATA;
|
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3191 | if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_2))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3192 | { |
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3193 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3194 | goto error; |
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3195 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3196 | |
| 3197 | // Set Band |
| 3198 | // AT*BAND=15,78,147,482,134742231 |
| 3199 | char buff[10]; |
| 3200 | memset(buff, 0, 10); |
| 3201 | property_get("persist.mbtk.band_config", buff, ""); |
| 3202 | if(strlen(buff) == 0) { |
| 3203 | pthread_t band_pid; |
| 3204 | if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL)) |
| 3205 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3206 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3207 | } |
| 3208 | } |
| 3209 | |
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 3210 | pthread_attr_destroy(&thread_attr);
|
| 3211 |
|
| 3212 | if(asr_auto_data_call_enable()) {
|
| 3213 | ril_cid_start = MBTK_RIL_CID_2;
|
| 3214 |
|
| 3215 | char def_cid[10] = {0};
|
| 3216 | char prop_data[100] = {0};
|
| 3217 | int cid = -1;
|
| 3218 | sprintf(def_cid, "%d", MBTK_RIL_CID_DEF); // Default route and DNS is CID 1.
|
| 3219 | memset(prop_data, 0, sizeof(prop_data));
|
| 3220 | if(property_get(MBTK_DEF_DNS_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
|
| 3221 | cid = atoi(prop_data);
|
| 3222 | }
|
| 3223 |
|
| 3224 | if(cid == MBTK_RIL_CID_DEF) {
|
| 3225 | if(file_link("/tmp/resolv.conf", "/etc/resolv.conf")) {
|
| 3226 | LOGE("Create link file fail.");
|
| 3227 | }
|
| 3228 | }
|
| 3229 | } else {
|
| 3230 | ril_cid_start = MBTK_RIL_CID_DEF;
|
| 3231 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3232 | |
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 3233 | LOGD("MBTK Ril Server Start[CID start with : %d]...", ril_cid_start);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3234 | |
| 3235 | return 0; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3236 | error:
|
| 3237 | if(ril_info.sock_client_list) {
|
| 3238 | list_free(ril_info.sock_client_list);
|
| 3239 | ril_info.sock_client_list = NULL;
|
| 3240 | }
|
| 3241 |
|
| 3242 | if(ril_info.sock_listen_fd > 0) {
|
| 3243 | close(ril_info.sock_listen_fd);
|
| 3244 | ril_info.sock_listen_fd = -1;
|
| 3245 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3246 | return -1; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3247 | }
|
| 3248 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3249 | int main(int argc, char *argv[])
|
| 3250 | {
|
| 3251 | mbtk_log_init("radio", "MBTK_RIL");
|
| 3252 |
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 3253 | MBTK_SOURCE_INFO_PRINT("mbtk_rild");
|
| 3254 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3255 | #ifdef MBTK_DUMP_SUPPORT
|
| 3256 | mbtk_debug_open(NULL, TRUE);
|
| 3257 | #endif
|
| 3258 |
|
| 3259 | // Using Killall,the file lock may be not release.
|
| 3260 | #if 0
|
| 3261 | if(app_already_running(MBTK_RILD_PID_FILE)) {
|
| 3262 | LOGW("daemon already running.");
|
| 3263 | exit(1);
|
| 3264 | }
|
| 3265 | #endif
|
| 3266 |
|
| 3267 | LOGI("mbtk_rild start.");
|
| 3268 |
|
| 3269 | if(InProduction_Mode()) {
|
| 3270 | LOGI("Is Production Mode, will exit...");
|
| 3271 | exit(0);
|
| 3272 | }
|
| 3273 |
|
| 3274 | ready_state_update();
|
| 3275 |
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3276 | // Must wait for atcmdsrv ready.
|
| 3277 | int at_sock = openSocket(MBTK_RILD_REQ_SLOT1_CHANNEL0, TRUE);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3278 | if(at_sock < 0)
|
| 3279 | {
|
| 3280 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3281 | return -1;
|
| 3282 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3283 | int uart_sock = openSocket(MBTK_RILD_URC_SLOT1, FALSE);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3284 | if(uart_sock < 0)
|
| 3285 | {
|
| 3286 | LOGE("Open Uart Socket Fail[%d].", errno);
|
| 3287 | return -1;
|
| 3288 | }
|
| 3289 |
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3290 | int at_sock_1 = openSocket(MBTK_RILD_REQ_SLOT1_CHANNEL1, FALSE);
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3291 | if(at_sock_1 < 0)
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3292 | {
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3293 | LOGE("Open AT Socket Fail[%d].", errno);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3294 | return -1;
|
| 3295 | }
|
| 3296 |
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3297 | int at_sock_2 = openSocket(MBTK_RILD_REQ_SLOT1_CHANNEL2, FALSE);
|
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3298 | if(at_sock_2 < 0)
|
| 3299 | {
|
| 3300 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3301 | return -1;
|
| 3302 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3303 | #ifdef LYNQ_DSDS_SUPPORT
|
| 3304 | int uart_sock1 = openSocket(MBTK_RILD_URC_SLOT2, FALSE);
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3305 | if(uart_sock1 < 0)
|
| 3306 | {
|
| 3307 | LOGE("Open Uart Socket Fail[%d].", errno);
|
| 3308 | return -1;
|
| 3309 | }
|
| 3310 |
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3311 | int at_sock1 = openSocket(MBTK_RILD_REQ_SLOT2_CHANNEL0, FALSE);
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3312 | if(at_sock1 < 0)
|
| 3313 | {
|
| 3314 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3315 | return -1;
|
| 3316 | }
|
| 3317 |
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3318 | int at_sock1_1 = openSocket(MBTK_RILD_REQ_SLOT2_CHANNEL1, FALSE);
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3319 | if(at_sock1_1 < 0)
|
| 3320 | {
|
| 3321 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3322 | return -1;
|
| 3323 | }
|
| 3324 |
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3325 | int at_sock1_2 = openSocket(MBTK_RILD_REQ_SLOT2_CHANNEL2, FALSE);
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3326 | if(at_sock1_2 < 0)
|
| 3327 | {
|
| 3328 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3329 | return -1;
|
| 3330 | }
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3331 | #endif
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3332 | at_set_on_reader_closed(onATReaderClosed);
|
| 3333 | at_set_on_timeout(onATTimeout);
|
| 3334 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3335 | if(at_open(ATPORTID_SIM1_0, at_sock, uart_sock, onUnsolicited1))
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3336 | {
|
| 3337 | LOGE("Start AT_0 thread fail.");
|
| 3338 | return -1;
|
| 3339 | }
|
| 3340 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3341 | if(at_open(ATPORTID_SIM1_1, at_sock_1, uart_sock, onUnsolicited1))
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3342 | {
|
| 3343 | LOGE("Start AT_1 thread fail.");
|
| 3344 | return -1;
|
| 3345 | }
|
| 3346 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3347 | if(at_open(ATPORTID_SIM1_2, at_sock_2, uart_sock, onUnsolicited1))
|
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3348 | {
|
| 3349 | LOGE("Start AT_1 thread fail.");
|
| 3350 | return -1;
|
| 3351 | }
|
| 3352 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3353 | if(at_handshake(ATPORTID_SIM1_0))
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3354 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3355 | LOGE("SIM1 AT handshake fail.");
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3356 | return -1;
|
| 3357 | }
|
| 3358 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3359 | LOGD("SIM1 AT OK.");
|
| 3360 |
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3361 | #ifdef LYNQ_DSDS_SUPPORT
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3362 | if(at_open(ATPORTID_SIM2_0, at_sock1, uart_sock1, onUnsolicited2))
|
| 3363 | {
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3364 | LOGE("Start ATPORTID_SIM2_0 thread fail.");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3365 | return -1;
|
| 3366 | }
|
| 3367 |
|
| 3368 | if(at_open(ATPORTID_SIM2_1, at_sock1_1, uart_sock1, onUnsolicited2))
|
| 3369 | {
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3370 | LOGE("Start ATPORTID_SIM2_1 thread fail.");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3371 | return -1;
|
| 3372 | }
|
| 3373 |
|
| 3374 | if(at_open(ATPORTID_SIM2_2, at_sock1_2, uart_sock1, onUnsolicited2))
|
| 3375 | {
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3376 | LOGE("Start ATPORTID_SIM2_2 thread fail.");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3377 | return -1;
|
| 3378 | }
|
| 3379 |
|
yq.wang | 3c5808d | 2025-05-08 17:39:19 +0800 | [diff] [blame] | 3380 | usleep(100 * 1000);
|
| 3381 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame] | 3382 | if(at_handshake(ATPORTID_SIM2_0))
|
| 3383 | {
|
| 3384 | LOGE("SIM2 AT handshake fail.");
|
| 3385 | return -1;
|
| 3386 | }
|
| 3387 |
|
| 3388 | LOGD("SIM2 AT OK.");
|
hong.liu | 7d2fa90 | 2025-07-23 04:41:53 -0700 | [diff] [blame] | 3389 | #endif
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3390 | if(ril_server_start())
|
| 3391 | {
|
| 3392 | LOGE("ril_server_start() fail.");
|
| 3393 | return -1;
|
| 3394 | }
|
| 3395 |
|
| 3396 | mbtk_ril_ready();
|
| 3397 |
|
| 3398 | while(1)
|
| 3399 | {
|
| 3400 | sleep(24 * 60 * 60);
|
| 3401 | }
|
| 3402 |
|
| 3403 | LOGD("!!!mbtk_ril exit!!!");
|
| 3404 | return 0;
|
| 3405 | }
|