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"
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 75 | #define RIL_CALL_NUM_MAX 10
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 76 |
|
| 77 | static bool ril_net_ready = FALSE; // Only one time.
|
| 78 | static bool ril_server_ready = FALSE; // Only one time.
|
| 79 | ril_band_info_t band_info;
|
| 80 | ril_info_t ril_info;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 81 | 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] | 82 | static bool cmt_found = FALSE;
|
| 83 |
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 84 | extern mbtk_cell_pack_info_t cell_info;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 85 | extern ril_cgact_wait_t cgact_wait;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 86 | extern int ril_cid_start;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 87 |
|
| 88 | // int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len);
|
| 89 | // int mbtk_signal_log(char *data);
|
| 90 | int InProduction_Mode(void);
|
| 91 | mbtk_ril_err_enum dev_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 92 | mbtk_ril_err_enum call_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 93 | mbtk_ril_err_enum sim_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 94 | 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] | 95 | 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] | 96 | mbtk_ril_err_enum pb_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 97 | 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] | 98 | mbtk_ril_err_enum ecall_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack);
|
| 99 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 100 | 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] | 101 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 102 | 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] | 103 | 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^] | 104 | int req_band_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t* band, int *cme_err);
|
| 105 | int req_dual_sim_get(ATPortType_enum port, mbtk_sim_type_enum *sim_id, int *cme_err);
|
| 106 |
|
| 107 | ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port)
|
| 108 | {
|
| 109 | return (ATPortId_enum)(sim_id * ATPORTTYPE_NUM + port);
|
| 110 | }
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 111 |
|
| 112 | /* Called on command thread */
|
| 113 | static void onATTimeout()
|
| 114 | {
|
| 115 | LOGI("AT channel timeout; closing\n");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 116 | at_close(ATPORTID_SIM1_0);
|
| 117 | at_close(ATPORTID_SIM1_1);
|
| 118 | at_close(ATPORTID_SIM1_2);
|
| 119 | at_close(ATPORTID_SIM2_0);
|
| 120 | at_close(ATPORTID_SIM2_1);
|
| 121 | at_close(ATPORTID_SIM2_2);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 122 | }
|
| 123 |
|
| 124 | /* Called on command or reader thread */
|
| 125 | static void onATReaderClosed()
|
| 126 | {
|
| 127 | LOGI("AT channel closed\n");
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 128 | at_close(ATPORTID_SIM1_0);
|
| 129 | at_close(ATPORTID_SIM1_1);
|
| 130 | at_close(ATPORTID_SIM1_2);
|
| 131 | at_close(ATPORTID_SIM2_0);
|
| 132 | at_close(ATPORTID_SIM2_1);
|
| 133 | at_close(ATPORTID_SIM2_2);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 134 | }
|
| 135 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 136 | static void sock_cli_free_func(void *data) |
| 137 | { |
| 138 | if (data) |
| 139 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 140 | sock_cli_info_t *info = (sock_cli_info_t*) data;
|
| 141 | LOGD("Free Socket client[fd = %d].", info->fd);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 142 | free(info); |
| 143 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 144 | }
|
| 145 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 146 | bool asr_auto_data_call_enable()
|
| 147 | {
|
| 148 | /*
|
| 149 | uci show wan_default.default.enable
|
| 150 | wan_default.default.enable='1'
|
| 151 |
|
| 152 | uci get wan_default.default.enable
|
| 153 | 1
|
| 154 | */
|
| 155 | char buff[128] = {0};
|
| 156 | if(mbtk_cmd_line("uci get wan_default.default.enable", buff, sizeof(buff)) && strlen(buff) > 0) {
|
| 157 | return buff[0] == '1' ? TRUE : FALSE;
|
| 158 | } else {
|
| 159 | return FALSE;
|
| 160 | }
|
| 161 | }
|
| 162 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 163 | /*
|
| 164 | * Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
|
| 165 | */
|
| 166 | static int net_ready_set()
|
| 167 | {
|
| 168 | int ret = -1;
|
| 169 | int fd = open(MBTK_RILD_FILE_NET_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
| 170 | if(fd > 0) {
|
| 171 | if(write(fd, "1", 1) == 1) {
|
| 172 | ret = 0;
|
| 173 | ril_net_ready = TRUE;
|
| 174 | }
|
| 175 | close(fd);
|
| 176 | } else {
|
| 177 | LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
|
| 178 | }
|
| 179 |
|
| 180 | return ret;
|
| 181 | }
|
| 182 |
|
| 183 | /*
|
| 184 | * Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
|
| 185 | */
|
| 186 | static int ser_ready_set()
|
| 187 | {
|
| 188 | int ret = -1;
|
| 189 | int fd = open(MBTK_RILD_FILE_SER_READY, O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
| 190 | if(fd > 0) {
|
| 191 | if(write(fd, "1", 1) == 1) {
|
| 192 | ret = 0;
|
| 193 | ril_server_ready = TRUE;
|
| 194 | }
|
| 195 | close(fd);
|
| 196 | } else {
|
| 197 | LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
|
| 198 | }
|
| 199 |
|
| 200 | return ret;
|
| 201 | }
|
| 202 |
|
| 203 | /*
|
| 204 | * Will exec mbtk_boot_server_ready and mbtk_boot_net_ready if is_first_boot is true.
|
| 205 | */
|
| 206 | static void ready_state_update()
|
| 207 | {
|
| 208 | int fd = open(MBTK_RILD_FILE_NET_READY, O_RDONLY, 0644);
|
| 209 | char buff[10];
|
| 210 | if(fd > 0) {
|
| 211 | if(read(fd, buff, sizeof(buff)) > 0) {
|
| 212 | ril_net_ready = TRUE;
|
| 213 | } else {
|
| 214 | ril_net_ready = FALSE;
|
| 215 | }
|
| 216 |
|
| 217 | close(fd);
|
| 218 | } else {
|
| 219 | ril_net_ready = FALSE;
|
| 220 | LOGE("Open %s fail:%d", MBTK_RILD_FILE_NET_READY, errno);
|
| 221 | }
|
| 222 |
|
| 223 | fd = open(MBTK_RILD_FILE_SER_READY, O_RDONLY, 0644);
|
| 224 | if(fd > 0) {
|
| 225 | if(read(fd, buff, sizeof(buff)) > 0) {
|
| 226 | ril_server_ready = TRUE;
|
| 227 | } else {
|
| 228 | ril_server_ready = FALSE;
|
| 229 | }
|
| 230 |
|
| 231 | close(fd);
|
| 232 | } else {
|
| 233 | ril_server_ready = FALSE;
|
| 234 | LOGE("Open %s fail:%d", MBTK_RILD_FILE_SER_READY, errno);
|
| 235 | }
|
| 236 | }
|
| 237 |
|
| 238 | static void mbtk_net_ready()
|
| 239 | {
|
| 240 | // /etc/init.d/mbtk_boot_net_ready
|
| 241 | if(!ril_net_ready) {
|
| 242 | if(access(MBTK_BOOT_NET_READY , X_OK) == 0) {
|
| 243 | LOGD("Exec : %s", MBTK_BOOT_NET_READY);
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 244 | mbtk_system(MBTK_BOOT_NET_READY);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 245 | } else {
|
| 246 | LOGE("%s can not exec.", MBTK_BOOT_NET_READY);
|
| 247 | }
|
| 248 | net_ready_set();
|
| 249 | } else {
|
| 250 | LOGD("No exec : %s", MBTK_BOOT_NET_READY);
|
| 251 | }
|
| 252 | }
|
| 253 |
|
| 254 | static void mbtk_ril_ready()
|
| 255 | {
|
| 256 | // /etc/init.d/mbtk_boot_server_ready
|
| 257 | if(!ril_server_ready) {
|
| 258 | if(access(MBTK_BOOT_SERVER_READY , X_OK) == 0) {
|
| 259 | LOGD("Exec : %s", MBTK_BOOT_SERVER_READY);
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 260 | mbtk_system(MBTK_BOOT_SERVER_READY);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 261 | } else {
|
| 262 | LOGE("%s can not exec.", MBTK_BOOT_SERVER_READY);
|
| 263 | }
|
| 264 | ser_ready_set();
|
| 265 | } else {
|
| 266 | LOGD("No exec : %s", MBTK_BOOT_SERVER_READY);
|
| 267 | }
|
| 268 | }
|
| 269 |
|
| 270 | static sock_cli_info_t* cli_find(int fd)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 271 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 272 | sock_cli_info_t *result = NULL;
|
| 273 | list_first(ril_info.sock_client_list);
|
| 274 | while ((result = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 275 | { |
| 276 | if (result->fd == fd) |
| 277 | return result; |
| 278 | } |
| 279 | |
| 280 | return NULL; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 281 | }
|
| 282 |
|
| 283 | static void cli_close(sock_cli_info_t* client)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 284 | { |
| 285 | struct epoll_event ev; |
| 286 | memset(&ev,0,sizeof(struct epoll_event)); |
| 287 | ev.data.fd = client->fd; |
| 288 | ev.events = EPOLLIN | EPOLLERR | EPOLLET; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 289 | epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_DEL, client->fd, &ev);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 290 | |
| 291 | close(client->fd); |
| 292 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 293 | if(list_remove(ril_info.sock_client_list, client))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 294 | { |
| 295 | sock_cli_free_func(client); |
| 296 | } |
| 297 | } |
| 298 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 299 | 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] | 300 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 301 | 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] | 302 | if(pack) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 303 | {
|
| 304 | pack->err = (uint16)err;
|
| 305 | ril_pack_send(fd, pack);
|
| 306 | ril_msg_pack_free(pack);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 307 | } |
| 308 | else |
| 309 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 310 | LOGW("ril_msg_pack_creat() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 314 | 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] | 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, data, data_len);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 317 | if(pack) |
| 318 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 319 | pack->err = (uint16)MBTK_RIL_ERR_SUCCESS;
|
| 320 | #if 0
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 321 | if(data != NULL && data_len > 0) |
| 322 | { |
| 323 | pack->data_len = (uint16)data_len; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 324 | pack->data = (uint8*)mbtk_memcpy(data, data_len);
|
| 325 | }
|
| 326 | #endif
|
| 327 | ril_pack_send(fd, pack);
|
| 328 | ril_msg_pack_free(pack);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 329 | } |
| 330 | else |
| 331 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 332 | LOGW("ril_msg_pack_creat() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 333 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 334 | }
|
| 335 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 336 | 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] | 337 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 338 | 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] | 339 | if(pack) |
| 340 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 341 | pack->err = (uint16)0;
|
| 342 | #if 0
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 343 | if(data != NULL && data_len > 0) |
| 344 | { |
| 345 | pack->data_len = (uint16)data_len; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 346 | pack->data = (uint8*)mbtk_memcpy(data, data_len);
|
| 347 | }
|
| 348 | #endif
|
| 349 | ril_pack_send(fd, pack);
|
| 350 | ril_msg_pack_free(pack);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 351 | } |
| 352 | else |
| 353 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 354 | LOGW("ril_msg_pack_creat() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 355 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 356 | }
|
| 357 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 358 | 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] | 359 | { |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 360 | sock_cli_info_t *cli = NULL;
|
| 361 | list_first(ril_info.sock_client_list);
|
| 362 | while ((cli = (sock_cli_info_t*) list_next(ril_info.sock_client_list)))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 363 | { |
| 364 | if(cli->ind_num > 0) { |
| 365 | int i; |
| 366 | for(i = 0; i < IND_REGISTER_MAX; i++) { |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 367 | if(cli->ind_register[i] == msg_id) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 368 | 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] | 369 | break; |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | } |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 374 | }
|
| 375 |
|
b.liu | 9e8584b | 2024-11-06 19:21:28 +0800 | [diff] [blame] | 376 | 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] | 377 | {
|
| 378 | // Send urc msg to client.
|
| 379 | 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] | 380 | if(msg_id == RIL_MSG_ID_IND_PDP_STATE_CHANGE) {
|
| 381 | mbtk_ril_pdp_state_info_t *info = (mbtk_ril_pdp_state_info_t*)data;
|
| 382 | if(info->action && !info->ip_info_valid) {
|
| 383 | LOGD("PDP action but no IP information, not send.");
|
| 384 | } else {
|
| 385 | ril_state_change(msg_id, data, data_len);
|
| 386 | }
|
| 387 | } else {
|
| 388 | ril_state_change(msg_id, data, data_len);
|
| 389 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 390 | }
|
| 391 |
|
| 392 | // Async process urc msg.
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 393 | if(async_process) { |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 394 | ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
|
| 395 | if(msg) {
|
| 396 | msg->msg = msg_id;
|
| 397 | msg->data = mbtk_memcpy(data, data_len);
|
| 398 | msg->data_len = data_len;
|
| 399 | if(msg->data == NULL) {
|
| 400 | LOGE("mbtk_memcpy() fail.");
|
| 401 | return -1;
|
| 402 | }
|
| 403 |
|
| 404 | return send_pack_to_queue(NULL, msg);
|
| 405 | } else {
|
| 406 | LOGE("malloc() fail.");
|
| 407 | return -1;
|
| 408 | }
|
| 409 | }
|
| 410 |
|
| 411 | return 0;
|
| 412 | }
|
| 413 |
|
| 414 | // *SIMDETEC:1,SIM
|
| 415 | // *EUICC:1
|
| 416 | // +CPIN: SIM PIN
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 417 | 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] | 418 | {
|
| 419 | mbtk_ril_sim_state_info_t state;
|
| 420 | memset(&state, 0, sizeof(mbtk_ril_sim_state_info_t));
|
| 421 | state.sim_type = MBTK_UNKNOWN;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 422 | state.sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 423 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 424 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 425 | char *line = tmp_s;
|
| 426 | int tmp_int;
|
| 427 | char *tmp_str;
|
| 428 |
|
| 429 | if(strStartsWith(s, "*SIMDETEC:")) {
|
| 430 | if (at_tok_start(&line) < 0)
|
| 431 | {
|
| 432 | goto SIM_STATE_EXIT;
|
| 433 | }
|
| 434 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 435 | {
|
| 436 | goto SIM_STATE_EXIT;
|
| 437 | }
|
| 438 | if (at_tok_nextstr(&line, &tmp_str) < 0)
|
| 439 | {
|
| 440 | goto SIM_STATE_EXIT;
|
| 441 | }
|
| 442 |
|
| 443 | if(tmp_str) {
|
| 444 | if(strcmp(tmp_str, "NOS") == 0) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 445 | state.sim_type = ril_info.sim_type[sim_id];
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 446 | state.sim_state = MBTK_SIM_STATE_ABSENT;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 447 | ril_info.sim_state[sim_id] = MBTK_SIM_STATE_ABSENT;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 448 | urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
|
| 449 | } else if(strcmp(tmp_str, "SIM") == 0) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 450 | state.sim_type = ril_info.sim_type[sim_id];
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 451 | state.sim_state = MBTK_SIM_STATE_NOT_READY;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 452 | ril_info.sim_state[sim_id] = MBTK_SIM_STATE_NOT_READY;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 453 | urc_msg_distribute(false, RIL_MSG_ID_IND_SIM_STATE_CHANGE, &state, sizeof(mbtk_ril_sim_state_info_t));
|
| 454 | }
|
| 455 | }
|
| 456 | } else if(strStartsWith(s, "+CPIN:")){
|
| 457 | if(strStartsWith(s, "+CPIN: READY"))
|
| 458 | {
|
| 459 | state.sim_state = MBTK_SIM_STATE_READY;
|
| 460 | }
|
| 461 | else if(strStartsWith(s, "+CPIN: SIM PIN"))
|
| 462 | {
|
| 463 | state.sim_state = MBTK_SIM_STATE_SIM_PIN;
|
| 464 | }
|
| 465 | else if(strStartsWith(s, "+CPIN: SIM PUK"))
|
| 466 | {
|
| 467 | state.sim_state = MBTK_SIM_STATE_SIM_PUK;
|
| 468 | }
|
| 469 | else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
|
| 470 | {
|
| 471 | state.sim_state = MBTK_SIM_STATE_PH_SIMLOCK_PIN;
|
| 472 | }
|
| 473 | else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
|
| 474 | {
|
| 475 | state.sim_state = MBTK_SIM_STATE_PH_SIMLOCK_PUK;
|
| 476 | }
|
| 477 | else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
|
| 478 | {
|
| 479 | state.sim_state = MBTK_SIM_STATE_PH_FSIM_PIN;
|
| 480 | }
|
| 481 | else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
|
| 482 | {
|
| 483 | state.sim_state = MBTK_SIM_STATE_PH_FSIM_PUK;
|
| 484 | }
|
| 485 | else if(strStartsWith(s, "+CPIN: SIM PIN2"))
|
| 486 | {
|
| 487 | state.sim_state = MBTK_SIM_STATE_SIM_PIN2;
|
| 488 | }
|
| 489 | else if(strStartsWith(s, "+CPIN: SIM PUK2"))
|
| 490 | {
|
| 491 | state.sim_state = MBTK_SIM_STATE_SIM_PUK2;
|
| 492 | }
|
| 493 | else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
|
| 494 | {
|
| 495 | state.sim_state = MBTK_SIM_STATE_PH_NET_PIN;
|
| 496 | }
|
| 497 | else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
|
| 498 | {
|
| 499 | state.sim_state = MBTK_SIM_STATE_PH_NET_PUK;
|
| 500 | }
|
| 501 | else if(strStartsWith(s, "+CPIN: PH-NETSUB PIN"))
|
| 502 | {
|
| 503 | state.sim_state = MBTK_SIM_STATE_PH_NETSUB_PIN;
|
| 504 | }
|
| 505 | else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
|
| 506 | {
|
| 507 | state.sim_state = MBTK_SIM_STATE_PH_NETSUB_PUK;
|
| 508 | }
|
| 509 | else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
|
| 510 | {
|
| 511 | state.sim_state = MBTK_SIM_STATE_PH_SP_PIN;
|
| 512 | }
|
| 513 | else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
|
| 514 | {
|
| 515 | state.sim_state = MBTK_SIM_STATE_PH_SP_PUK;
|
| 516 | }
|
| 517 | else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
|
| 518 | {
|
| 519 | state.sim_state = MBTK_SIM_STATE_PH_CORP_PIN;
|
| 520 | }
|
| 521 | else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
|
| 522 | {
|
| 523 | state.sim_state = MBTK_SIM_STATE_PH_CORP_PUK;
|
| 524 | }
|
| 525 | else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
|
| 526 | {
|
| 527 | state.sim_state = MBTK_SIM_STATE_ABSENT;
|
| 528 | }
|
| 529 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 530 | state.sim_type = ril_info.sim_type[sim_id];
|
| 531 | ril_info.sim_state[sim_id] = state.sim_state;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 532 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 533 | 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] | 534 | } else if(strStartsWith(s, "*EUICC:")){
|
| 535 | if (at_tok_start(&line) < 0)
|
| 536 | {
|
| 537 | goto SIM_STATE_EXIT;
|
| 538 | }
|
| 539 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 540 | {
|
| 541 | goto SIM_STATE_EXIT;
|
| 542 | }
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 543 | 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] | 544 | } else {
|
| 545 | LOGW("Unknown URC.");
|
| 546 | }
|
| 547 |
|
| 548 | SIM_STATE_EXIT:
|
| 549 | free(tmp_s);
|
| 550 | }
|
| 551 |
|
| 552 | // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
|
| 553 | // +CALLDISCONNECT: 1
|
| 554 | // +CPAS: 4
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 555 | 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] | 556 | {
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 557 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 558 | char *line = tmp_s;
|
| 559 | int tmp_int;
|
| 560 | char *tmp_str;
|
| 561 |
|
| 562 | if(strStartsWith(s, "+CLCC:")) {
|
| 563 | if (at_tok_start(&line) < 0)
|
| 564 | {
|
| 565 | goto CALL_STATE_EXIT;
|
| 566 | }
|
| 567 | if (at_tok_nextint(&line, &tmp_int) < 0) // call id
|
| 568 | {
|
| 569 | goto CALL_STATE_EXIT;
|
| 570 | }
|
| 571 |
|
| 572 | int i = 0;
|
| 573 | while(i < RIL_CALL_NUM_MAX) {
|
| 574 | if(call_list[i].call_id == tmp_int)
|
| 575 | break;
|
| 576 | i++;
|
| 577 | }
|
| 578 | if(i == RIL_CALL_NUM_MAX) { // No found this call id.
|
| 579 | i = 0;
|
| 580 | while(i < RIL_CALL_NUM_MAX) { // Find next empty call item.
|
| 581 | if(call_list[i].call_id == 0)
|
| 582 | break;
|
| 583 | i++;
|
| 584 | }
|
| 585 | call_list[i].call_id = tmp_int;
|
| 586 | }
|
| 587 |
|
| 588 | LOGD("Found call id : %d", call_list[i].call_id);
|
| 589 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 590 | call_list[i].sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 591 | if (at_tok_nextint(&line, &tmp_int) < 0) // dir
|
| 592 | {
|
| 593 | goto CALL_STATE_EXIT;
|
| 594 | }
|
| 595 | call_list[i].dir = (mbtk_ril_call_dir_enum)tmp_int;
|
| 596 |
|
| 597 | if (at_tok_nextint(&line, &tmp_int) < 0) // state
|
| 598 | {
|
| 599 | goto CALL_STATE_EXIT;
|
| 600 | }
|
| 601 | call_list[i].state = (mbtk_ril_call_state_enum)tmp_int;
|
| 602 |
|
| 603 | if (at_tok_nextint(&line, &tmp_int) < 0) // mode
|
| 604 | {
|
| 605 | goto CALL_STATE_EXIT;
|
| 606 | }
|
| 607 |
|
| 608 | if (at_tok_nextint(&line, &tmp_int) < 0) // mpty
|
| 609 | {
|
| 610 | goto CALL_STATE_EXIT;
|
| 611 | }
|
| 612 |
|
| 613 | if (at_tok_nextstr(&line, &tmp_str) < 0) // number
|
| 614 | {
|
| 615 | goto CALL_STATE_EXIT;
|
| 616 | }
|
| 617 | memset(call_list[i].call_number, 0, sizeof(call_list[i].call_number));
|
| 618 | if(tmp_str && strlen(tmp_str) > 0) {
|
| 619 | memcpy(call_list[i].call_number, tmp_str, strlen(tmp_str));
|
| 620 | }
|
| 621 |
|
| 622 | if (at_tok_nextint(&line, &tmp_int) < 0) // type
|
| 623 | {
|
| 624 | goto CALL_STATE_EXIT;
|
| 625 | }
|
| 626 | call_list[i].num_type = (mbtk_ril_call_num_type_enum)tmp_int;
|
| 627 |
|
| 628 | urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));
|
| 629 | } else if(strStartsWith(s, "+CALLDISCONNECT:")){
|
| 630 | if (at_tok_start(&line) < 0)
|
| 631 | {
|
| 632 | goto CALL_STATE_EXIT;
|
| 633 | }
|
| 634 | if (at_tok_nextint(&line, &tmp_int) < 0) // call id
|
| 635 | {
|
| 636 | goto CALL_STATE_EXIT;
|
| 637 | }
|
| 638 |
|
| 639 | int i = 0;
|
| 640 | while(i < RIL_CALL_NUM_MAX) {
|
| 641 | if(call_list[i].call_id == tmp_int)
|
| 642 | break;
|
| 643 | i++;
|
| 644 | }
|
| 645 |
|
| 646 | if(i == RIL_CALL_NUM_MAX) { // No found this call id.
|
| 647 | LOGE("No found this call id : %d", tmp_int);
|
| 648 | goto CALL_STATE_EXIT;
|
| 649 | }
|
| 650 |
|
| 651 | call_list[i].state = MBTK_RIL_CALL_STATE_DISCONNECT;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 652 | call_list[i].sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 653 |
|
| 654 | urc_msg_distribute(false, RIL_MSG_ID_IND_CALL_STATE_CHANGE, &(call_list[i]), sizeof(mbtk_ril_call_state_info_t));
|
| 655 |
|
| 656 | // Reset after call disconnect.
|
| 657 | memset(&(call_list[i]), 0, sizeof(mbtk_ril_call_state_info_t));
|
| 658 | } else if(strStartsWith(s, "+CPAS:")){
|
| 659 |
|
| 660 | } else {
|
| 661 | LOGW("Unknown URC.");
|
| 662 | }
|
| 663 |
|
| 664 | CALL_STATE_EXIT:
|
| 665 | free(tmp_s);
|
| 666 | }
|
| 667 |
|
| 668 | // *ECALLDATA: <urc_id>[,<urc_data>]
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 669 | 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] | 670 | {
|
| 671 | mbtk_ril_ecall_state_info_t ecall_state;
|
| 672 | memset(&ecall_state, 0, sizeof(mbtk_ril_ecall_state_info_t));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 673 | ecall_state.sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 674 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 675 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 676 | char *line = tmp_s;
|
| 677 | int tmp_int;
|
| 678 | char *tmp_str;
|
| 679 | if (at_tok_start(&line) < 0)
|
| 680 | {
|
| 681 | goto ECALLDATA_EXIT;
|
| 682 | }
|
| 683 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 684 | {
|
| 685 | goto ECALLDATA_EXIT;
|
| 686 | }
|
| 687 | ecall_state.urc_id = (uint8)tmp_int; // urc_id
|
| 688 | if (at_tok_nextstr(&line, &tmp_str) < 0)
|
| 689 | {
|
| 690 | goto ECALLDATA_EXIT;
|
| 691 | }
|
| 692 |
|
| 693 | if(tmp_str && strlen(tmp_str) > 0) {
|
| 694 | memcpy(ecall_state.urc_data, tmp_str, strlen(tmp_str));
|
| 695 | }
|
| 696 |
|
| 697 | urc_msg_distribute(false, RIL_MSG_ID_IND_ECALL_STATE_CHANGE, &ecall_state, sizeof(mbtk_ril_ecall_state_info_t));
|
| 698 | ECALLDATA_EXIT:
|
| 699 | free(tmp_s);
|
| 700 | }
|
| 701 |
|
| 702 | // +CMT: ,23
|
| 703 | // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 704 | 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] | 705 | {
|
b.liu | 0bb1c8e | 2024-12-31 14:44:40 +0800 | [diff] [blame] | 706 | static mbtk_ril_sms_state_info_t sms_info;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 707 | memset(&sms_info, 0, sizeof(mbtk_ril_sms_state_info_t));
|
| 708 | sms_info.sim_id = sim_id;
|
| 709 |
|
b.liu | 0bb1c8e | 2024-12-31 14:44:40 +0800 | [diff] [blame] | 710 | if(!is_pdu) {
|
b.liu | 60c2f1f | 2024-12-31 12:54:45 +0800 | [diff] [blame] | 711 | char* tmp_s = memdup(s,strlen(s) + 1);
|
| 712 | char *line = tmp_s;
|
| 713 | char *tmp_str;
|
| 714 | if (at_tok_start(&line) < 0)
|
| 715 | {
|
| 716 | goto CMT_EXIT;
|
| 717 | }
|
| 718 | if (at_tok_nextstr(&line, &tmp_str) < 0)
|
| 719 | {
|
| 720 | goto CMT_EXIT;
|
| 721 | }
|
| 722 | if (at_tok_nextstr(&line, &tmp_str) < 0)
|
| 723 | {
|
| 724 | goto CMT_EXIT;
|
| 725 | }
|
| 726 | sms_info.pdu_len = (uint16)atoi(tmp_str);
|
b.liu | 60c2f1f | 2024-12-31 12:54:45 +0800 | [diff] [blame] | 727 | CMT_EXIT:
|
| 728 | free(tmp_s);
|
b.liu | 0bb1c8e | 2024-12-31 14:44:40 +0800 | [diff] [blame] | 729 | } else {
|
| 730 | LOGD("PDU : %s", s);
|
| 731 | memcpy(sms_info.pdu, s, strlen(s));
|
| 732 | 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] | 733 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 734 | }
|
| 735 |
|
| 736 | // +CREG: 1, "8010", "000060a5", 0, 2, 0
|
| 737 | // +CREG: 1, "8330", "06447347", 7, 2, 0
|
| 738 | // +CEREG: 1, "8330", "06447347", 7
|
| 739 | // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
|
| 740 | // $CREG: 1, "8010", "000060a7", 0,, 2, 0
|
| 741 | // +CGREG: 1
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 742 | // +C5GREG: 1,"00280386","07e920010",11,1,"01"
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 743 | 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] | 744 | {
|
| 745 | mbtk_ril_net_reg_state_info_t state;
|
| 746 | memset(&state, 0, sizeof(mbtk_ril_net_reg_state_info_t));
|
| 747 | state.tech = MBTK_RADIO_TECH_UNKNOWN;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 748 | state.sim_id = sim_id;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 749 |
|
| 750 | if(strStartsWith(s, "+CREG:"))
|
| 751 | {
|
| 752 | state.type = MBTK_NET_REG_TYPE_CALL;
|
| 753 | } else if(strStartsWith(s, "+CGREG:")) {
|
| 754 | state.type = MBTK_NET_REG_TYPE_DATA_GSM_WCDMA;
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 755 | } else if(strStartsWith(s, "+C5GREG:")) {
|
| 756 | state.type = MBTK_NET_REG_TYPE_DATA_NR;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 757 | } else {
|
| 758 | state.type = MBTK_NET_REG_TYPE_DATA_LTE;
|
| 759 | }
|
| 760 |
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 761 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 762 | char *line = tmp_s;
|
| 763 | int tmp_int;
|
| 764 | char *tmp_str;
|
| 765 | if (at_tok_start(&line) < 0)
|
| 766 | {
|
| 767 | goto CGREG_EXIT;
|
| 768 | }
|
| 769 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 770 | {
|
| 771 | goto CGREG_EXIT;
|
| 772 | }
|
| 773 | state.reg_state = (mbtk_net_reg_state_enum)tmp_int; // Reg State.
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 774 | if (state.reg_state && at_tok_hasmore(&line)) // Reg
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 775 | {
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 776 | if (at_tok_nextstr(&line, &tmp_str) < 0) // tac
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 777 | {
|
| 778 | goto CGREG_EXIT;
|
| 779 | }
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 780 | state.tac = (uint64)strtoull(tmp_str, NULL, 16);
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 781 |
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 782 | if (at_tok_nextstr(&line, &tmp_str) < 0) // ci
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 783 | {
|
| 784 | goto CGREG_EXIT;
|
| 785 | }
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 786 | state.ci = (uint64)strtoull(tmp_str, NULL, 16);
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 787 |
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 788 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 789 | {
|
| 790 | goto CGREG_EXIT;
|
| 791 | }
|
| 792 | state.tech = (mbtk_radio_technology_enum)tmp_int; // AcT
|
| 793 | }
|
| 794 |
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 795 | if(state.reg_state == MBTK_NET_REG_STATE_HOME
|
| 796 | || state.reg_state == MBTK_NET_REG_STATE_ROAMING) {
|
| 797 | mbtk_net_ready();
|
| 798 | }
|
| 799 |
|
b.liu | afdf2c6 | 2024-11-12 11:10:44 +0800 | [diff] [blame] | 800 | // Should restart data call if necessary.
|
| 801 | 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] | 802 | CGREG_EXIT:
|
| 803 | free(tmp_s);
|
| 804 | }
|
| 805 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 806 | 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] | 807 | {
|
| 808 | // "CONNECT"
|
| 809 | if(strStartsWith(s, "CONNECT"))
|
| 810 | {
|
| 811 | #if 1
|
| 812 | if(cgact_wait.waitting && cgact_wait.act) {
|
| 813 | cgact_wait.waitting = false;
|
| 814 | }
|
| 815 | #endif
|
| 816 | }
|
| 817 | // +CGEV:
|
| 818 | // +CGEV: NW DEACT <cid>,<cid>
|
| 819 | // +CGEV: ME DEACT <cid>,<cid>
|
| 820 | // +CGEV: NW PDN DEACT <cid>
|
| 821 | // +CGEV: ME PDN DEACT <cid>
|
| 822 | // +CGEV: NW DETACH
|
| 823 | // +CGEV: ME DETACH
|
| 824 | //
|
| 825 | // +CGEV: NW ACT <cid>,<cid>
|
| 826 | // +CGEV: ME ACT <cid>,<cid>
|
| 827 | // +CGEV: EPS PDN ACT <cid>
|
| 828 | // +CGEV: ME PDN ACT <cid>,<reason>,<cid>
|
| 829 | // +CGEV: ME PDN ACT <cid>,<reason>
|
| 830 | // +CGEV: NW PDN ACT <cid>
|
| 831 | // +CGEV: EPS ACT <cid>
|
| 832 | // +CGEV: NW MODIFY <cid>,<reason>
|
| 833 | // +CGEV: NW REATTACH
|
| 834 |
|
| 835 | /*
|
| 836 | +CGEV: NW DETACH
|
| 837 | +CGEV: ME DETACH
|
| 838 | +CGEV: NW CLASS <class>
|
| 839 | +CGEV: ME CLASS <class>
|
| 840 | +CGEV: NW PDN ACT <cid>
|
| 841 | +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
|
| 842 | +CGEV: NW ACT <p_cid>, <cid>, <event_type>
|
| 843 | +CGEV: ME ACT <p_cid>, <cid>, <event_type>
|
| 844 | +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
|
| 845 | +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
|
| 846 | +CGEV: NW PDN DEACT <cid>
|
| 847 | +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
|
| 848 | +CGEV: ME PDN DEACT <cid>
|
| 849 | +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
|
| 850 | +CGEV: NW DEACT <p_cid>, <cid>, <event_type>
|
| 851 | +CGEV: NW DEACT <PDP_type>, <PDP_addr>, [<cid>]
|
| 852 | +CGEV: ME DEACT <p_cid>, <cid>, <event_type>
|
| 853 | +CGEV: ME DEACT <PDP_type>, <PDP_addr>, [<cid>]
|
| 854 | +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
|
| 855 | +CGEV: ME MODIFY <cid>, <change_reason>, <event_type>
|
| 856 | +CGEV: REJECT <PDP_type>, <PDP_addr>
|
| 857 | +CGEV: NW REACT <PDP_type>, <PDP_addr>, [<cid>]
|
| 858 | */
|
| 859 | else if(strStartsWith(s, "+CGEV:"))
|
| 860 | {
|
| 861 | #if 1
|
| 862 | // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>[,<reason>[,<cid_other>]]
|
| 863 | // "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY <cid>, <change_reason>, <event_type>
|
| 864 | // "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
|
| 865 | // "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
|
| 866 | // "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
|
| 867 | // "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
|
| 868 | // "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 869 | mbtk_ril_pdp_state_info_t cgev_info;
|
| 870 | memset(&cgev_info, 0, sizeof(mbtk_ril_pdp_state_info_t));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 871 | cgev_info.sim_id = sim_id;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 872 | int cid, reason = 0;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 873 | if (sscanf(s, "+CGEV: NW PDN DEACT %d", &cid) == 1) {
|
| 874 | cgev_info.cid = (uint16)cid;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 875 | cgev_info.action = FALSE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 876 | } else if (sscanf(s, "+CGEV: ME PDN DEACT %d", &cid) == 1) {
|
| 877 | cgev_info.cid = (uint16)cid;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 878 | cgev_info.action = FALSE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 879 | } else if(sscanf(s, "+CGEV: ME PDN ACT %d,%d", &cid, &reason) == 2
|
| 880 | || sscanf(s, "+CGEV: ME PDN ACT %d", &cid) == 1) {
|
| 881 | cgev_info.cid = (uint16)cid;
|
| 882 | cgev_info.reason = (uint16)reason;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 883 | cgev_info.action = TRUE;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 884 | } else if (!strcmp(s, "+CGEV: ME DETACH")) {
|
| 885 | if(cgact_wait.waitting) {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 886 | cgev_info.cid = cgact_wait.cid;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 887 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 888 | cgev_info.action = FALSE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 889 | } else if (sscanf(s, "+CGEV: NW MODIFY %d,%d", &cid, &reason) == 2) {
|
| 890 | cgev_info.cid = (uint16)cid;
|
| 891 | cgev_info.reason = (uint16)reason;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 892 | cgev_info.action = TRUE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 893 | } else if(sscanf(s, "+CGEV: EPS PDN ACT %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 = TRUE;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 896 | } else {
|
| 897 | LOGD(">>>>>>>>>No process +CGEV <<<<<<<<<");
|
| 898 | return;
|
| 899 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 900 | cgev_info.auto_change = !cgact_wait.waitting;
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 901 |
|
| 902 | if(cgact_wait.act) {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 903 | 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] | 904 | cgact_wait.waitting = false;
|
| 905 | }
|
| 906 | } else {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 907 | 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] | 908 | cgact_wait.waitting = false;
|
| 909 | }
|
| 910 | }
|
| 911 |
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 912 | LOGD("+CGEV:cid - %d, act - %d, auto_change - %d, reason - %d", cgev_info.cid, cgev_info.action,
|
| 913 | cgev_info.auto_change, cgev_info.reason);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 914 | 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^] | 915 | 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] | 916 | urc_msg_distribute(false, RIL_MSG_ID_IND_PDP_STATE_CHANGE, &cgev_info, sizeof(mbtk_ril_pdp_state_info_t));
|
| 917 | }
|
| 918 |
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 919 | #else
|
| 920 | if(at_process) {
|
| 921 | if(cgact_wait.act) {
|
| 922 | if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT 15,4
|
| 923 | if(cgact_wait.cid == atoi(s + 18)) {
|
| 924 | cgact_wait.waitting = false;
|
| 925 | }
|
| 926 |
|
| 927 | uint8 data_pdp;
|
| 928 | char* tmp_s = memdup(s + 18,strlen(s + 18));
|
| 929 | char* free_ptr = tmp_s;
|
| 930 | char *line = tmp_s;
|
| 931 | int tmp_int;
|
| 932 | if (at_tok_start(&line) < 0)
|
| 933 | {
|
| 934 | goto at_PDP_CREG_EXIT;
|
| 935 | }
|
| 936 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 937 | {
|
| 938 | goto at_PDP_CREG_EXIT;
|
| 939 | }
|
| 940 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 941 | {
|
| 942 | goto at_PDP_CREG_EXIT;
|
| 943 | }
|
| 944 | data_pdp = tmp_int;
|
| 945 | at_PDP_CREG_EXIT:
|
| 946 | free(free_ptr);
|
| 947 |
|
| 948 | //data_pdp = (uint8)atoi(s + 20); //reason
|
| 949 | if(cgact_wait.cid >= 1 && cgact_wait.cid < 8)
|
| 950 | {
|
| 951 | if(data_pdp == 0)
|
| 952 | {
|
| 953 | data_pdp = 25;
|
| 954 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 955 | //data_pdp = cgact_wait.cid + 200;
|
| 956 | }
|
| 957 | else if(data_pdp == 1)
|
| 958 | {
|
| 959 | data_pdp = 26;
|
| 960 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 961 | }
|
| 962 | else if(data_pdp == 2)
|
| 963 | {
|
| 964 | data_pdp = 27;
|
| 965 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 966 | }
|
| 967 | else if(data_pdp == 3)
|
| 968 | {
|
| 969 | data_pdp = 27;
|
| 970 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 971 | }
|
| 972 | else
|
| 973 | {
|
| 974 |
|
| 975 | }
|
| 976 | if(cgact_wait.cid != 0)
|
| 977 | {
|
| 978 | data_pdp = cgact_wait.cid + 200;
|
| 979 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 980 | }
|
| 981 | }
|
| 982 | } else if(strStartsWith(s, "+CGEV: NW MODIFY ")) { // +CGEV: NW MODIFY 1,4
|
| 983 | if(cgact_wait.cid == atoi(s + 17)) {
|
| 984 | cgact_wait.waitting = false;
|
| 985 | }
|
| 986 | }
|
| 987 | } else {
|
| 988 | if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: ME PDN DEACT 1
|
| 989 | if(cgact_wait.cid == atoi(s + 20)) {
|
| 990 | cgact_wait.waitting = false;
|
| 991 | }
|
| 992 | uint8 data_pdp;
|
| 993 | data_pdp = 0; //
|
| 994 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 995 | if(cgact_wait.cid != 0)
|
| 996 | {
|
| 997 | data_pdp = cgact_wait.cid + 100;
|
| 998 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 999 | }
|
| 1000 | }
|
| 1001 | }
|
| 1002 | } else {
|
| 1003 | // apn_state_set
|
| 1004 |
|
| 1005 | // +CGEV: NW PDN DEACT <cid>
|
| 1006 |
|
| 1007 | // +CGEV: EPS PDN ACT 1
|
| 1008 | // +CGEV: ME PDN ACT 8,1
|
| 1009 |
|
| 1010 | // +CGEV: ME PDN ACT 2,4
|
| 1011 | uint8 data[2] = {0xFF};
|
| 1012 | if(strStartsWith(s, "+CGEV: NW PDN DEACT ")) { // +CGEV: NW PDN DEACT <cid>
|
| 1013 | //apn_state_set(atoi(s + 20), false);
|
| 1014 | data[0] = (uint8)0;
|
| 1015 | data[1] = (uint8)atoi(s + 20);
|
| 1016 |
|
| 1017 | uint8 data_pdp;
|
| 1018 | data_pdp = 0; //
|
| 1019 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1020 | data_pdp = data[1] + 100;
|
| 1021 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1022 | } else if(strStartsWith(s, "+CGEV: EPS PDN ACT ")) { // +CGEV: EPS PDN ACT <cid>
|
| 1023 | //apn_state_set(atoi(s + 19), true);
|
| 1024 | #if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
|
| 1025 | //data[0] = (uint8)1;
|
| 1026 | //data[1] = (uint8)atoi(s + 19);
|
| 1027 | #else
|
| 1028 | data[0] = (uint8)1;
|
| 1029 | data[1] = (uint8)atoi(s + 19);
|
| 1030 | #endif
|
| 1031 | } else if(strStartsWith(s, "+CGEV: ME PDN DEACT ")) { // +CGEV: EPS PDN DEACT <cid>
|
| 1032 | //apn_state_set(atoi(s + 19), true);
|
| 1033 | data[0] = (uint8)0;
|
| 1034 | data[1] = (uint8)atoi(s + 20);
|
| 1035 |
|
| 1036 | uint8 data_pdp;
|
| 1037 | data_pdp = 0; //
|
| 1038 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1039 | data_pdp = data[1] + 100;
|
| 1040 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1041 | } else if(strStartsWith(s, "+CGEV: ME PDN ACT ")) { // +CGEV: ME PDN ACT <cid>,1
|
| 1042 | //apn_state_set(atoi(s + 18), true);
|
| 1043 | data[0] = (uint8)1;
|
| 1044 | data[1] = (uint8)atoi(s + 18);
|
| 1045 |
|
| 1046 | uint8 data_pdp;
|
| 1047 | char* tmp_s = memdup(s + 18,strlen(s + 18));
|
| 1048 | char* free_ptr = tmp_s;
|
| 1049 | char *line = tmp_s;
|
| 1050 | int tmp_int;
|
| 1051 | if (at_tok_start(&line) < 0)
|
| 1052 | {
|
| 1053 | goto PDP_CREG_EXIT;
|
| 1054 | }
|
| 1055 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1056 | {
|
| 1057 | goto PDP_CREG_EXIT;
|
| 1058 | }
|
| 1059 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1060 | {
|
| 1061 | goto PDP_CREG_EXIT;
|
| 1062 | }
|
| 1063 | data_pdp = tmp_int;
|
| 1064 | PDP_CREG_EXIT:
|
| 1065 | free(free_ptr);
|
| 1066 | //data_pdp = (uint8)atoi(s + 20); //reason
|
| 1067 | if(data[1] >= 1 && data[1] < 8)
|
| 1068 | {
|
| 1069 | if(data_pdp == 0)
|
| 1070 | {
|
| 1071 | data_pdp = 25;
|
| 1072 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1073 | }
|
| 1074 | else if(data_pdp == 1)
|
| 1075 | {
|
| 1076 | data_pdp = 26;
|
| 1077 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1078 | }
|
| 1079 | else if(data_pdp == 2)
|
| 1080 | {
|
| 1081 | data_pdp = 27;
|
| 1082 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1083 | }
|
| 1084 | else if(data_pdp == 3)
|
| 1085 | {
|
| 1086 | data_pdp = 27;
|
| 1087 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1088 | }
|
| 1089 | else
|
| 1090 | {
|
| 1091 |
|
| 1092 | }
|
| 1093 |
|
| 1094 | data_pdp = data[1] + 200;
|
| 1095 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 1096 | data[1] = 0;
|
| 1097 | }
|
| 1098 | } else {
|
| 1099 | LOGI("No process : %s", s);
|
| 1100 | }
|
| 1101 |
|
| 1102 | urc_msg_distribute(true, INFO_URC_MSG_CGEV, data, sizeof(uint8) * 2);
|
| 1103 | }
|
| 1104 | #endif
|
| 1105 | } else {
|
| 1106 | LOGW("Unknown PDP URC : %s", s);
|
| 1107 | }
|
| 1108 | }
|
| 1109 |
|
| 1110 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 1111 | 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] | 1112 | {
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 1113 | // +EEMNRSVC: <mcc>,<lenOfMnc>,<mnc>,<tac>,<phyCellId>,<dlNrArfcn>,<dlScs>,<ulNrArfcn>,<ulScs>,<sulNrArfcn>,<sulScs>,<band>,<dlBandwidth>,<cellId>,<IsRedCapCell>,<longDRXCyclePresent>,<shortDRXCyclePresent>,<longDRXCycle>,<shortDRXCycle>,<pagingCycle>,
|
| 1114 | // <rsrp>,<rsrq>,<sinr>,<rssi>,<qRxLevMin>,<qQualMin>,<srxlev>,
|
| 1115 | // <pathLoss>,
|
| 1116 | // <dlBler>,<averDlPRB>,<averDlMcs>,<averDlPortNum>,<averCQI>,<averLi>,<averRi>,<dlThroughPut>,<dlPeakThroughPut>,
|
| 1117 | // <ulBler>,<averUlPRB>,<averUlMcs>,<averUlPortNum>,<currPuschTxPower>,<currPucchTxPower>,<grantTotal>,<ulThroughPut>,<ulPeakThroughPut>,
|
| 1118 | // <nrrcModeState>,<nmmState>,<serviceState>,<IsSingleNmmRejectCause>,<NMMRejectCause>,<amfRegionId>,<amfSetId>,<amfPointer>,<nrTmsi>,
|
| 1119 | // <ulBandwidth>,<dlInitialBwpFreq>,<ulInitialBwpFreq>
|
| 1120 | /*
|
| 1121 | +EEMNRSVC: 1120, 2, 0, 2622342, 137, 158650, 0, 146678, 0, 0, 255, 28, 79, 620598788208, 0, 0, 0, 0, 0, 64,
|
| 1122 | 86, 65, 86, 51, 20, 0, 49,
|
| 1123 | 0,
|
| 1124 | 0, 0, 0, 0, 38, 0, 8, 0, 0,
|
| 1125 | 0, 256, 24, 16, 13, 20, 2, 2, 0,
|
| 1126 | 1, 10, 0, 1, 0, 9, 128, 5, 2358781729,
|
| 1127 | 79, 788390, 733390
|
| 1128 | */
|
| 1129 | if(strStartsWith(s, "+EEMNRSVC:")) {
|
| 1130 | // mcc,lenOfMnc,mnc,tac,PCI,dlNrArfcn,ulNrArfcn,band,rsrp,rsrq,sinr,rssi
|
| 1131 | // cellID
|
| 1132 | if(cell_info.running) {
|
| 1133 | int tmp_int;
|
| 1134 | int i = 0;
|
| 1135 | char* tmp_s = memdup(s,strlen(s) + 1);
|
| 1136 | char* free_ptr = tmp_s;
|
| 1137 | char *line = tmp_s;
|
| 1138 | char *tmp_str;
|
| 1139 | if (at_tok_start(&line) < 0)
|
| 1140 | {
|
| 1141 | goto EEMNRSVC_EXIT;
|
| 1142 | }
|
| 1143 |
|
| 1144 | if (at_tok_nextint(&line, &tmp_int) < 0) // mcc
|
| 1145 | {
|
| 1146 | goto EEMNRSVC_EXIT;
|
| 1147 | }
|
| 1148 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1149 |
|
| 1150 | if (at_tok_nextint(&line, &tmp_int) < 0) // lenOfMnc
|
| 1151 | {
|
| 1152 | goto EEMNRSVC_EXIT;
|
| 1153 | }
|
| 1154 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1155 | if (at_tok_nextint(&line, &tmp_int) < 0) // mnc
|
| 1156 | {
|
| 1157 | goto EEMNRSVC_EXIT;
|
| 1158 | }
|
| 1159 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1160 |
|
| 1161 | if (at_tok_nextint(&line, &tmp_int) < 0) // tac
|
| 1162 | {
|
| 1163 | goto EEMNRSVC_EXIT;
|
| 1164 | }
|
| 1165 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 1166 |
|
| 1167 | if (at_tok_nextint(&line, &tmp_int) < 0) // pci
|
| 1168 | {
|
| 1169 | goto EEMNRSVC_EXIT;
|
| 1170 | }
|
| 1171 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
|
| 1172 |
|
| 1173 | if (at_tok_nextint(&line, &tmp_int) < 0) // dlNrArfcn
|
| 1174 | {
|
| 1175 | goto EEMNRSVC_EXIT;
|
| 1176 | }
|
| 1177 | cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
|
| 1178 |
|
| 1179 | if (at_tok_nextint(&line, &tmp_int) < 0) // dlScs
|
| 1180 | {
|
| 1181 | goto EEMNRSVC_EXIT;
|
| 1182 | }
|
| 1183 |
|
| 1184 | if (at_tok_nextint(&line, &tmp_int) < 0) // ulNrArfcn
|
| 1185 | {
|
| 1186 | goto EEMNRSVC_EXIT;
|
| 1187 | }
|
| 1188 | cell_info.cell_list.cell[cell_info.cell_list.num].value7 = (uint32)tmp_int;
|
| 1189 |
|
| 1190 | // <ulScs>,<sulNrArfcn>,<sulScs>
|
| 1191 | for(i =0; i < 3; i++)
|
| 1192 | {
|
| 1193 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1194 | {
|
| 1195 | goto EEMNRSVC_EXIT;
|
| 1196 | }
|
| 1197 | }
|
| 1198 |
|
| 1199 | if (at_tok_nextint(&line, &tmp_int) < 0) // band
|
| 1200 | {
|
| 1201 | goto EEMNRSVC_EXIT;
|
| 1202 | }
|
| 1203 | cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int;
|
| 1204 |
|
| 1205 |
|
| 1206 | if (at_tok_nextint(&line, &tmp_int) < 0) // dlBandwidth
|
| 1207 | {
|
| 1208 | goto EEMNRSVC_EXIT;
|
| 1209 | }
|
| 1210 |
|
| 1211 |
|
| 1212 | if (at_tok_nextstr(&line, &tmp_str) < 0) // cellId
|
| 1213 | {
|
| 1214 | goto EEMNRSVC_EXIT;
|
| 1215 | }
|
| 1216 | // LOGD("cellID-str : %s", tmp_str);
|
| 1217 | cell_info.cell_list.cell[cell_info.cell_list.num].value64_1 = (uint64)strtoull(tmp_str, NULL, 10);
|
| 1218 | // LOGD("cellID : %llu", cell_info.cell_list.cell[cell_info.cell_list.num].value64_1);
|
| 1219 |
|
| 1220 | // <IsRedCapCell>,<longDRXCyclePresent>,<shortDRXCyclePresent>,<longDRXCycle>,<shortDRXCycle>,<pagingCycle>
|
| 1221 | for(i =0; i < 6; i++)
|
| 1222 | {
|
| 1223 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1224 | {
|
| 1225 | goto EEMNRSVC_EXIT;
|
| 1226 | }
|
| 1227 | }
|
| 1228 |
|
| 1229 | if (at_tok_nextint(&line, &tmp_int) < 0) // <rsrp>
|
| 1230 | {
|
| 1231 | goto EEMNRSVC_EXIT;
|
| 1232 | }
|
| 1233 | cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int;
|
| 1234 |
|
| 1235 | if (at_tok_nextint(&line, &tmp_int) < 0) // <rsrq>
|
| 1236 | {
|
| 1237 | goto EEMNRSVC_EXIT;
|
| 1238 | }
|
| 1239 | cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int;
|
| 1240 |
|
| 1241 | if (at_tok_nextint(&line, &tmp_int) < 0) // <sinr>
|
| 1242 | {
|
| 1243 | goto EEMNRSVC_EXIT;
|
| 1244 | }
|
| 1245 | cell_info.cell_list.cell[cell_info.cell_list.num].value11 = (uint32)tmp_int;
|
| 1246 |
|
| 1247 | if (at_tok_nextint(&line, &tmp_int) < 0) // <rssi>
|
| 1248 | {
|
| 1249 | goto EEMNRSVC_EXIT;
|
| 1250 | }
|
| 1251 | cell_info.cell_list.cell[cell_info.cell_list.num].value12 = (uint32)tmp_int;
|
| 1252 |
|
| 1253 | cell_info.cell_list.num++;
|
| 1254 |
|
| 1255 | EEMNRSVC_EXIT:
|
| 1256 | free(free_ptr);
|
| 1257 | }
|
| 1258 | }
|
| 1259 | // +EEMNRINTER: <index>,<phyCellId>,<nrArfcn>,<dlScs>,<rsrp>,<rsrq>,<sinr>,<srxlev>,<mcc>,<lenOfMnc>,<mnc>,<tac>,<cellId>
|
| 1260 | /* +EEMNRINTER: 0, 508, 723360, 0, 39, 64, -8, 1, 0, 0, 0, 0, 4294967295 */
|
| 1261 | /* +EEMNRINTER: 1, 254, 723360, 0, 45, 72, 1, 7, 0, 0, 0, 0, 4294967295 */
|
| 1262 | /* +EEMNRINTER: 2, 595, 723360, 0, 40, 65, -5, 3, 0, 0, 0, 0, 4294967295 */
|
| 1263 | else if(strStartsWith(s, "+EEMNRINTER:")) {
|
| 1264 | // phyCellId,nrArfcn,rsrp,rsrq
|
| 1265 | if(cell_info.running) {
|
| 1266 | int tmp_int;
|
| 1267 | char* tmp_s = memdup(s,strlen(s) + 1);
|
| 1268 | char* free_ptr = tmp_s;
|
| 1269 | char *line = tmp_s;
|
| 1270 | if (at_tok_start(&line) < 0)
|
| 1271 | {
|
| 1272 | goto EEMNRINTER_EXIT;
|
| 1273 | }
|
| 1274 | if (at_tok_nextint(&line, &tmp_int) < 0) // index
|
| 1275 | {
|
| 1276 | goto EEMNRINTER_EXIT;
|
| 1277 | }
|
| 1278 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int > 1007) // phyCellId (0 - 1007)
|
| 1279 | {
|
| 1280 | goto EEMNRINTER_EXIT;
|
| 1281 | }
|
| 1282 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1283 | if (at_tok_nextint(&line, &tmp_int) < 0) // nrArfcn
|
| 1284 | {
|
| 1285 | goto EEMNRINTER_EXIT;
|
| 1286 | }
|
| 1287 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1288 | if (at_tok_nextint(&line, &tmp_int) < 0) // dlScs
|
| 1289 | {
|
| 1290 | goto EEMNRINTER_EXIT;
|
| 1291 | }
|
| 1292 | if (at_tok_nextint(&line, &tmp_int) < 0) // rsrp
|
| 1293 | {
|
| 1294 | goto EEMNRINTER_EXIT;
|
| 1295 | }
|
| 1296 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1297 | if (at_tok_nextint(&line, &tmp_int) < 0) // rsrq
|
| 1298 | {
|
| 1299 | goto EEMNRINTER_EXIT;
|
| 1300 | }
|
| 1301 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 1302 |
|
| 1303 | cell_info.cell_list.num++;
|
| 1304 | EEMNRINTER_EXIT:
|
| 1305 | free(free_ptr);
|
| 1306 | }
|
| 1307 | }
|
| 1308 | // +EEMNRINTERRAT:<net_type>,<numInterRATEutra>,
|
| 1309 | // <earfcn>,<physCellId>,<rsrp>,<rsrq>,<sinr>,<mcc>,<lenOfMnc>,<mnc>,<tac>
|
| 1310 | // ......
|
| 1311 | // <earfcn>,<physCellId>,<rsrp>,<rsrq>,<sinr>,<mcc>,<lenOfMnc>,<mnc>,<tac>
|
| 1312 | /*
|
| 1313 | +EEMNRINTERRAT: 2, 6, // LTE
|
| 1314 | 1300, 423, 0, 0, 0, 0, 0, 0, 0,
|
| 1315 | 1300, 137, 0, 0, 0, 0, 0, 0, 0,
|
| 1316 | 1300, 149, 0, 0, 0, 0, 0, 0, 0,
|
| 1317 | 1300, 494, 0, 0, 0, 0, 0, 0, 0,
|
| 1318 | 1300, 337, 0, 0, 0, 0, 0, 0, 0,
|
| 1319 | 1300, 288, 0, 0, 0, 0, 0, 0, 0
|
| 1320 | */
|
| 1321 | /*
|
| 1322 | +EEMNRINTERRAT: 1, 0 // UMTS
|
| 1323 | */
|
| 1324 | else if(strStartsWith(s, "+EEMNRINTERRAT:")) {
|
| 1325 | // phyCellId,nrArfcn,rsrp,rsrq
|
| 1326 | if(cell_info.running) {
|
| 1327 | int tmp_int;
|
| 1328 | char* tmp_s = memdup(s,strlen(s) + 1);
|
| 1329 | char* free_ptr = tmp_s;
|
| 1330 | char *line = tmp_s;
|
| 1331 | if (at_tok_start(&line) < 0)
|
| 1332 | {
|
| 1333 | goto EEMNRINTERRAT_EXIT;
|
| 1334 | }
|
| 1335 | if (at_tok_nextint(&line, &tmp_int) < 0) // net_type
|
| 1336 | {
|
| 1337 | goto EEMNRINTERRAT_EXIT;
|
| 1338 | }
|
| 1339 |
|
| 1340 | #define CI_DEV_EM_NETWORK_LTE 2
|
| 1341 |
|
| 1342 | // Only support LTE.
|
| 1343 | if(tmp_int == CI_DEV_EM_NETWORK_LTE) { // LTE
|
| 1344 | int num;
|
| 1345 | int i, j;
|
| 1346 | if (at_tok_nextint(&line, &num) < 0) // numInterRATEutra
|
| 1347 | {
|
| 1348 | goto EEMNRINTERRAT_EXIT;
|
| 1349 | }
|
| 1350 | LOGD("LTE-RAT num : %d", num);
|
| 1351 | for(i = 0; i < num; i++) {
|
| 1352 | if (at_tok_nextint(&line, &tmp_int) < 0) // earfcn
|
| 1353 | {
|
| 1354 | goto EEMNRINTERRAT_EXIT;
|
| 1355 | }
|
| 1356 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1357 |
|
| 1358 | if (at_tok_nextint(&line, &tmp_int) < 0) // physCellId
|
| 1359 | {
|
| 1360 | goto EEMNRINTERRAT_EXIT;
|
| 1361 | }
|
| 1362 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1363 |
|
| 1364 | if (at_tok_nextint(&line, &tmp_int) < 0) // rsrp
|
| 1365 | {
|
| 1366 | goto EEMNRINTERRAT_EXIT;
|
| 1367 | }
|
| 1368 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1369 |
|
| 1370 | if (at_tok_nextint(&line, &tmp_int) < 0) // rsrq
|
| 1371 | {
|
| 1372 | goto EEMNRINTERRAT_EXIT;
|
| 1373 | }
|
| 1374 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 1375 |
|
| 1376 | // Jump 5 items.
|
| 1377 | j = 0;
|
| 1378 | while(j < 5) {
|
| 1379 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1380 | {
|
| 1381 | goto EEMNRINTERRAT_EXIT;
|
| 1382 | }
|
| 1383 | j++;
|
| 1384 | }
|
| 1385 |
|
| 1386 | cell_info.cell_list.num++;
|
| 1387 | }
|
| 1388 | }
|
| 1389 | EEMNRINTERRAT_EXIT:
|
| 1390 | free(free_ptr);
|
| 1391 | }
|
| 1392 | }
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1393 | /*
|
| 1394 | // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
|
| 1395 | // <rsrp>,<rsrq>, <sinr>,
|
| 1396 | // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
|
| 1397 | // cellId,subFrameAssignType,specialSubframePatterns,transMode
|
| 1398 | // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
|
| 1399 | // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
|
| 1400 | // dlBer, ulBer,
|
| 1401 | // diversitySinr, diversityRssi
|
| 1402 | +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
|
| 1403 | 0, 0, 0,
|
| 1404 | 1, 10, 0, 1, 0, 1059, 78, 3959566565,
|
| 1405 | 105149248, 2, 7, 7,
|
| 1406 | 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
|
| 1407 | 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
|
| 1408 | 0, 0,
|
| 1409 | 7, 44
|
| 1410 | */
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 1411 | else if(strStartsWith(s, "+EEMLTESVC:")) // LTE Server Cell
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1412 | {
|
| 1413 | // tac, PCI, dlEuarfcn, ulEuarfcn, band
|
| 1414 | if(cell_info.running) {
|
| 1415 | int tmp_int;
|
| 1416 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1417 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1418 | char* free_ptr = tmp_s;
|
| 1419 | char *line = tmp_s;
|
| 1420 | if (at_tok_start(&line) < 0)
|
| 1421 | {
|
| 1422 | goto EEMLTESVC_EXIT;
|
| 1423 | }
|
| 1424 |
|
| 1425 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1426 | {
|
| 1427 | goto EEMLTESVC_EXIT;
|
| 1428 | }
|
| 1429 | cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int; //mcc
|
| 1430 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1431 | {
|
| 1432 | goto EEMLTESVC_EXIT;
|
| 1433 | }
|
| 1434 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1435 | {
|
| 1436 | goto EEMLTESVC_EXIT;
|
| 1437 | }
|
| 1438 | cell_info.cell_list.cell[cell_info.cell_list.num].value7 = (uint32)tmp_int; //mnc
|
| 1439 | /*
|
| 1440 | // Jump 2 integer.
|
| 1441 | i = 0;
|
| 1442 | while(i < 2) {
|
| 1443 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1444 | {
|
| 1445 | goto EEMLTESVC_EXIT;
|
| 1446 | }
|
| 1447 | i++;
|
| 1448 | }
|
| 1449 | */
|
| 1450 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1451 | {
|
| 1452 | goto EEMLTESVC_EXIT;
|
| 1453 | }
|
| 1454 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int; //tac
|
| 1455 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1456 | {
|
| 1457 | goto EEMLTESVC_EXIT;
|
| 1458 | }
|
| 1459 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int; //pci
|
| 1460 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1461 | {
|
| 1462 | goto EEMLTESVC_EXIT;
|
| 1463 | }
|
| 1464 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int; //dl arfcn
|
| 1465 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1466 | {
|
| 1467 | goto EEMLTESVC_EXIT;
|
| 1468 | }
|
| 1469 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int; //ul arfcn
|
| 1470 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1471 | {
|
| 1472 | goto EEMLTESVC_EXIT;
|
| 1473 | }
|
| 1474 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int; //band
|
| 1475 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1476 | {
|
| 1477 | goto EEMLTESVC_EXIT;
|
| 1478 | }
|
| 1479 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1480 | {
|
| 1481 | goto EEMLTESVC_EXIT;
|
| 1482 | }
|
| 1483 | cell_info.cell_list.cell[cell_info.cell_list.num].value8 = (uint32)tmp_int; //cid
|
| 1484 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1485 | {
|
| 1486 | goto EEMLTESVC_EXIT;
|
| 1487 | }
|
| 1488 | cell_info.cell_list.cell[cell_info.cell_list.num].value9 = (uint32)tmp_int; //rsrp
|
| 1489 |
|
| 1490 | for(i =0; i < 10; i++)
|
| 1491 | {
|
| 1492 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1493 | {
|
| 1494 | goto EEMLTESVC_EXIT;
|
| 1495 | }
|
| 1496 | }
|
| 1497 | cell_info.cell_list.cell[cell_info.cell_list.num].value10 = (uint32)tmp_int; //cell identiy
|
| 1498 |
|
| 1499 | cell_info.cell_list.num++;
|
| 1500 |
|
| 1501 | EEMLTESVC_EXIT:
|
| 1502 | free(free_ptr);
|
| 1503 | }
|
| 1504 | }
|
| 1505 | /*
|
| 1506 | // index,phyCellId,euArfcn,rsrp,rsrq
|
| 1507 | +EEMLTEINTER: 0, 65535, 38950, 0, 0
|
| 1508 | */
|
| 1509 | else if(strStartsWith(s, "+EEMLTEINTER:") || strStartsWith(s, "+EEMLTEINTRA:")) // LTE ÒìÆµ/Í¬ÆµÐ¡Çø
|
| 1510 | {
|
| 1511 | // phyCellId,euArfcn,rsrp,rsrq
|
| 1512 | if(cell_info.running) {
|
| 1513 | int tmp_int;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1514 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1515 | char* free_ptr = tmp_s;
|
| 1516 | char *line = tmp_s;
|
| 1517 | if (at_tok_start(&line) < 0)
|
| 1518 | {
|
| 1519 | goto EEMLTEINTER_EXIT;
|
| 1520 | }
|
| 1521 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1522 | {
|
| 1523 | goto EEMLTEINTER_EXIT;
|
| 1524 | }
|
| 1525 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int > 503)
|
| 1526 | {
|
| 1527 | goto EEMLTEINTER_EXIT;
|
| 1528 | }
|
| 1529 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1530 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1531 | {
|
| 1532 | goto EEMLTEINTER_EXIT;
|
| 1533 | }
|
| 1534 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1535 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1536 | {
|
| 1537 | goto EEMLTEINTER_EXIT;
|
| 1538 | }
|
| 1539 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1540 | LOG("cell line : %s", line);
|
| 1541 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1542 | {
|
| 1543 | goto EEMLTEINTER_EXIT;
|
| 1544 | }
|
| 1545 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 1546 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1547 | {
|
| 1548 | LOG("cell tmp_int : %d", tmp_int);
|
| 1549 | goto EEMLTEINTER_EXIT;
|
| 1550 | }
|
| 1551 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
|
| 1552 | LOG("cell value5 : %d", cell_info.cell_list.cell[cell_info.cell_list.num].value5);
|
| 1553 | cell_info.cell_list.num++;
|
| 1554 | EEMLTEINTER_EXIT:
|
| 1555 | free(free_ptr);
|
| 1556 | }
|
| 1557 | }
|
| 1558 | // Do nothing
|
| 1559 | else if(strStartsWith(s, "+EEMLTEINTERRAT:")) // LTE RATÐ¡ÇøÐÅÏ¢
|
| 1560 | {
|
| 1561 | if(cell_info.running) {
|
| 1562 |
|
| 1563 | }
|
| 1564 | }
|
| 1565 | // WCDMA
|
| 1566 | /*
|
| 1567 | // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
|
| 1568 |
|
| 1569 | // if sCMeasPresent == 1
|
| 1570 | // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
|
| 1571 | // endif
|
| 1572 |
|
| 1573 | // if sCParamPresent == 1
|
| 1574 | // rac, nom, mcc, mnc_len, mnc, lac, ci,
|
| 1575 | // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
|
| 1576 | // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
|
| 1577 | // endif
|
| 1578 |
|
| 1579 | // if ueOpStatusPresent == 1
|
| 1580 | // rrcState, numLinks, srncId, sRnti,
|
| 1581 | // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
|
| 1582 | // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
|
| 1583 | // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
|
| 1584 | // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
|
| 1585 | // endif
|
| 1586 | //
|
| 1587 | +EEMUMTSSVC: 3, 1, 1, 1,
|
| 1588 | -80, 27, -6, -18, -115, -32768,
|
| 1589 | 1, 1, 1120, 2, 1, 61697, 168432821,
|
| 1590 | 15, 24, 10763, 0, 0, 0, 0,
|
| 1591 | 128, 128, 65535, 0, 0,
|
| 1592 | 2, 255, 65535, 4294967295,
|
| 1593 | 0, 0, 0, 0, 0, 0,
|
| 1594 | 0, 0, 0, 0, 0, 0, 1, 1,
|
| 1595 | 28672, 28672, 0, 0, 0, 0, 0, 0, 0,
|
| 1596 | 0, 0, 0, 0, 0, 0
|
| 1597 | */
|
| 1598 | else if(strStartsWith(s, "+EEMUMTSSVC:")) // WCDMA Server Cell
|
| 1599 | {
|
| 1600 | // lac, ci, arfcn
|
| 1601 | if(cell_info.running) {
|
| 1602 | int tmp_int;
|
| 1603 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1604 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1605 | char* free_ptr = tmp_s;
|
| 1606 | char *line = tmp_s;
|
| 1607 | if (at_tok_start(&line) < 0)
|
| 1608 | {
|
| 1609 | goto EEMUMTSSVC_EXIT;
|
| 1610 | }
|
| 1611 | // Jump 12 integer.
|
| 1612 | i = 0;
|
| 1613 | while(i < 12) {
|
| 1614 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1615 | {
|
| 1616 | goto EEMUMTSSVC_EXIT;
|
| 1617 | }
|
| 1618 | i++;
|
| 1619 | }
|
| 1620 | // mcc
|
| 1621 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1622 | {
|
| 1623 | goto EEMUMTSSVC_EXIT;
|
| 1624 | }
|
| 1625 | cell_info.cell_list.cell[cell_info.cell_list.num].value4= (uint32)tmp_int;
|
| 1626 | // mnc
|
| 1627 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1628 | {
|
| 1629 | goto EEMUMTSSVC_EXIT;
|
| 1630 | }
|
| 1631 | cell_info.cell_list.cell[cell_info.cell_list.num].value5= (uint32)tmp_int;
|
| 1632 | // lac
|
| 1633 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1634 | {
|
| 1635 | goto EEMUMTSSVC_EXIT;
|
| 1636 | }
|
| 1637 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1638 | // ci
|
| 1639 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1640 | {
|
| 1641 | goto EEMUMTSSVC_EXIT;
|
| 1642 | }
|
| 1643 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1644 |
|
| 1645 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1646 | {
|
| 1647 | goto EEMUMTSSVC_EXIT;
|
| 1648 | }
|
| 1649 | // cpi
|
| 1650 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1651 | {
|
| 1652 | goto EEMUMTSSVC_EXIT;
|
| 1653 | }
|
| 1654 | cell_info.cell_list.cell[cell_info.cell_list.num].value6= (uint32)tmp_int;
|
| 1655 | /*
|
| 1656 | // Jump 2 integer.
|
| 1657 | i = 0;
|
| 1658 | while(i < 2) {
|
| 1659 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1660 | {
|
| 1661 | goto EEMUMTSSVC_EXIT;
|
| 1662 | }
|
| 1663 | i++;
|
| 1664 | }
|
| 1665 | */
|
| 1666 | // arfcn
|
| 1667 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1668 | {
|
| 1669 | goto EEMUMTSSVC_EXIT;
|
| 1670 | }
|
| 1671 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1672 |
|
| 1673 | cell_info.cell_list.num++;
|
| 1674 | EEMUMTSSVC_EXIT:
|
| 1675 | free(free_ptr);
|
| 1676 | }
|
| 1677 | }
|
| 1678 | /*
|
| 1679 | // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
|
| 1680 | +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
|
| 1681 | */
|
| 1682 | else if(strStartsWith(s, "+EEMUMTSINTRA:")) // WCDMAÁÙ½üÐ¡Çø
|
| 1683 | {
|
| 1684 | // lac, ci, arfcn
|
| 1685 | if(cell_info.running) {
|
| 1686 | int tmp_int;
|
| 1687 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1688 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1689 | char* free_ptr = tmp_s;
|
| 1690 | char *line = tmp_s;
|
| 1691 | if (at_tok_start(&line) < 0)
|
| 1692 | {
|
| 1693 | goto EEMUMTSINTRA_EXIT;
|
| 1694 | }
|
| 1695 | // Jump 8 integer.
|
| 1696 | i = 0;
|
| 1697 | while(i < 8) {
|
| 1698 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1699 | {
|
| 1700 | goto EEMUMTSINTRA_EXIT;
|
| 1701 | }
|
| 1702 | i++;
|
| 1703 | }
|
| 1704 |
|
| 1705 | // lac
|
| 1706 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1707 | {
|
| 1708 | goto EEMUMTSINTRA_EXIT;
|
| 1709 | }
|
| 1710 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1711 |
|
| 1712 | // ci
|
| 1713 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1714 | {
|
| 1715 | goto EEMUMTSINTRA_EXIT;
|
| 1716 | }
|
| 1717 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1718 |
|
| 1719 | // arfcn
|
| 1720 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1721 | {
|
| 1722 | goto EEMUMTSINTRA_EXIT;
|
| 1723 | }
|
| 1724 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1725 |
|
| 1726 | cell_info.cell_list.num++;
|
| 1727 | EEMUMTSINTRA_EXIT:
|
| 1728 | free(free_ptr);
|
| 1729 | }
|
| 1730 | }
|
| 1731 | /*
|
| 1732 | // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
|
| 1733 | +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
|
| 1734 | */
|
| 1735 | else if(strStartsWith(s, "+EEMUMTSINTERRAT:")) // WCDMA RATÐ¡ÇøÐÅÏ¢
|
| 1736 | {
|
| 1737 | // lac, ci, arfcn
|
| 1738 | if(cell_info.running) {
|
| 1739 | int tmp_int;
|
| 1740 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1741 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1742 | char* free_ptr = tmp_s;
|
| 1743 | char *line = tmp_s;
|
| 1744 | if (at_tok_start(&line) < 0)
|
| 1745 | {
|
| 1746 | goto EEMUMTSINTERRAT_EXIT;
|
| 1747 | }
|
| 1748 | // Jump 7 integer.
|
| 1749 | i = 0;
|
| 1750 | while(i < 7) {
|
| 1751 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1752 | {
|
| 1753 | goto EEMUMTSINTERRAT_EXIT;
|
| 1754 | }
|
| 1755 | i++;
|
| 1756 | }
|
| 1757 |
|
| 1758 | // lac
|
| 1759 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1760 | {
|
| 1761 | goto EEMUMTSINTERRAT_EXIT;
|
| 1762 | }
|
| 1763 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1764 |
|
| 1765 | // ci
|
| 1766 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1767 | {
|
| 1768 | goto EEMUMTSINTERRAT_EXIT;
|
| 1769 | }
|
| 1770 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1771 |
|
| 1772 | // arfcn
|
| 1773 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1774 | {
|
| 1775 | goto EEMUMTSINTERRAT_EXIT;
|
| 1776 | }
|
| 1777 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1778 |
|
| 1779 | cell_info.cell_list.num++;
|
| 1780 | EEMUMTSINTERRAT_EXIT:
|
| 1781 | free(free_ptr);
|
| 1782 | }
|
| 1783 | }
|
| 1784 | // GSM
|
| 1785 | // +EEMGINFOBASIC: 2
|
| 1786 | // Do nothing.
|
| 1787 | else if(strStartsWith(s, "+EEMGINFOBASIC:")) // Basic information in GSM
|
| 1788 | // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
|
| 1789 | {
|
| 1790 | if(cell_info.running) {
|
| 1791 |
|
| 1792 | }
|
| 1793 | }
|
| 1794 | /*
|
| 1795 | // mcc, mnc_len, mnc, lac, ci, nom, nco,
|
| 1796 | // bsic, C1, C2, TA, TxPwr,
|
| 1797 | // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
|
| 1798 | // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
|
| 1799 | // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
|
| 1800 | // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
|
| 1801 | // gsmBand,channelMode
|
| 1802 | +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
|
| 1803 | 63, 36, 146, 1, 7,
|
| 1804 | 46, 42, 42, 7, 0,
|
| 1805 | 53, 0, 8, 0, 1, 6, 53,
|
| 1806 | 2, 0, 146, 42, 54, 0, 1,
|
| 1807 | 1, 32, 0, 0, 0, 0,
|
| 1808 | 0, 0
|
| 1809 | */
|
| 1810 | else if(strStartsWith(s, "+EEMGINFOSVC:")) // GSM Server Cell
|
| 1811 | {
|
| 1812 | // lac, ci, arfcn, bsic
|
| 1813 | LOG("+EEMGINFOSVC: 1= %d\n.",cell_info.running);
|
| 1814 | if(cell_info.running) {
|
| 1815 | int tmp_int;
|
| 1816 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1817 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1818 | char* free_ptr = tmp_s;
|
| 1819 | char *line = tmp_s;
|
| 1820 | if (at_tok_start(&line) < 0)
|
| 1821 | {
|
| 1822 | goto EEMGINFOSVC_EXIT;
|
| 1823 | }
|
| 1824 |
|
| 1825 | // mcc
|
| 1826 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1827 | {
|
| 1828 | goto EEMGINFOSVC_EXIT;
|
| 1829 | }
|
| 1830 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
|
| 1831 |
|
| 1832 | //mnc_len
|
| 1833 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1834 | {
|
| 1835 | goto EEMGINFOSVC_EXIT;
|
| 1836 | }
|
| 1837 | // mnc
|
| 1838 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int <= 0 || tmp_int >= 65536)
|
| 1839 | {
|
| 1840 | goto EEMGINFOSVC_EXIT;
|
| 1841 | }
|
| 1842 | cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
|
| 1843 |
|
| 1844 | /*
|
| 1845 | // Jump 3 integer.
|
| 1846 | i = 0;
|
| 1847 | while(i < 3) {
|
| 1848 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1849 | {
|
| 1850 | goto EEMGINFOSVC_EXIT;
|
| 1851 | }
|
| 1852 | i++;
|
| 1853 | }
|
| 1854 | */
|
| 1855 | // lac
|
| 1856 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1857 | {
|
| 1858 | goto EEMGINFOSVC_EXIT;
|
| 1859 | }
|
| 1860 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1861 |
|
| 1862 | // ci
|
| 1863 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1864 | {
|
| 1865 | goto EEMGINFOSVC_EXIT;
|
| 1866 | }
|
| 1867 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1868 |
|
| 1869 | // Jump 2 integer.
|
| 1870 | i = 0;
|
| 1871 | while(i < 2) {
|
| 1872 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1873 | {
|
| 1874 | goto EEMGINFOSVC_EXIT;
|
| 1875 | }
|
| 1876 | i++;
|
| 1877 | }
|
| 1878 |
|
| 1879 | // bsic
|
| 1880 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1881 | {
|
| 1882 | goto EEMGINFOSVC_EXIT;
|
| 1883 | }
|
| 1884 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 1885 |
|
| 1886 | // Jump 15 integer.
|
| 1887 | i = 0;
|
| 1888 | while(i < 15) {
|
| 1889 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1890 | {
|
| 1891 | goto EEMGINFOSVC_EXIT;
|
| 1892 | }
|
| 1893 | i++;
|
| 1894 | }
|
| 1895 |
|
| 1896 | // arfcn
|
| 1897 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1898 | {
|
| 1899 | goto EEMGINFOSVC_EXIT;
|
| 1900 | }
|
| 1901 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 1902 |
|
| 1903 | cell_info.cell_list.num++;
|
| 1904 | EEMGINFOSVC_EXIT:
|
| 1905 | free(free_ptr);
|
| 1906 | }
|
| 1907 | }
|
| 1908 | /*
|
| 1909 | // PS_attached, attach_type, service_type, tx_power, c_value,
|
| 1910 | // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
|
| 1911 | // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
|
| 1912 | // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
|
| 1913 | +EEMGINFOPS: 1, 255, 0, 0, 0,
|
| 1914 | 0, 0, 268435501, 1, 0, 0,
|
| 1915 | 4, 0, 96, 0, 0, 0,
|
| 1916 | 0, 0, 0, 65535, 0, 13350
|
| 1917 | */
|
| 1918 | // Do nothing.
|
| 1919 | else if(strStartsWith(s, "+EEMGINFOPS:")) // PSÐÅÏ¢
|
| 1920 | {
|
| 1921 | if(cell_info.running) {
|
| 1922 |
|
| 1923 | }
|
| 1924 | }
|
| 1925 | else if(strStartsWith(s, "+EEMGINFONC:")) // cell
|
| 1926 | {
|
| 1927 | if(cell_info.running) {
|
| 1928 | int tmp_int;
|
| 1929 | int i = 0;
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 1930 | char* tmp_s = memdup(s,strlen(s) + 1);
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1931 | char* free_ptr = tmp_s;
|
| 1932 | char *line = tmp_s;
|
| 1933 | if (at_tok_start(&line) < 0)
|
| 1934 | {
|
| 1935 | goto EEMGINFOPS_EXIT;
|
| 1936 | }
|
| 1937 |
|
| 1938 | // nc_num
|
| 1939 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1940 | {
|
| 1941 | LOG("cell_info.running 1= %d\n.",cell_info.running);
|
| 1942 | goto EEMGINFOPS_EXIT;
|
| 1943 | }
|
| 1944 | // mcc
|
| 1945 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1946 | {
|
| 1947 | LOG("cell_info.running 2= %d\n.",cell_info.running);
|
| 1948 | goto EEMGINFOPS_EXIT;
|
| 1949 | }
|
| 1950 | cell_info.cell_list.cell[cell_info.cell_list.num].value5 = (uint32)tmp_int;
|
| 1951 |
|
| 1952 | // mnc
|
| 1953 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1954 | {
|
| 1955 | LOG("cell_info.running 3= %d\n.",cell_info.running);
|
| 1956 | goto EEMGINFOPS_EXIT;
|
| 1957 | }
|
| 1958 | cell_info.cell_list.cell[cell_info.cell_list.num].value6 = (uint32)tmp_int;
|
| 1959 |
|
| 1960 | // lac
|
| 1961 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1962 | {
|
| 1963 | LOG("cell_info.running 4= %d\n.",cell_info.running);
|
| 1964 | goto EEMGINFOPS_EXIT;
|
| 1965 | }
|
| 1966 | cell_info.cell_list.cell[cell_info.cell_list.num].value1 = (uint32)tmp_int;
|
| 1967 |
|
| 1968 | // rac
|
| 1969 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1970 | {
|
| 1971 | LOG("cell_info.running 5= %d\n.",cell_info.running);
|
| 1972 | goto EEMGINFOPS_EXIT;
|
| 1973 | }
|
| 1974 |
|
| 1975 | // ci
|
| 1976 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1977 | {
|
| 1978 | LOG("cell_info.running 6= %d\n.",cell_info.running);
|
| 1979 | goto EEMGINFOPS_EXIT;
|
| 1980 | }
|
| 1981 | cell_info.cell_list.cell[cell_info.cell_list.num].value2 = (uint32)tmp_int;
|
| 1982 |
|
| 1983 | // rx_lv
|
| 1984 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 1985 | {
|
| 1986 | LOG("cell_info.running 7= %d\n.",cell_info.running);
|
| 1987 | goto EEMGINFOPS_EXIT;
|
| 1988 | }
|
| 1989 |
|
| 1990 | // bsic
|
| 1991 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 1992 | {
|
| 1993 | LOG("cell_info.running 8= %d\n.",cell_info.running);
|
| 1994 | goto EEMGINFOPS_EXIT;
|
| 1995 | }
|
| 1996 | cell_info.cell_list.cell[cell_info.cell_list.num].value4 = (uint32)tmp_int;
|
| 1997 |
|
| 1998 | // Jump 2 integer.
|
| 1999 | i = 0;
|
| 2000 | while(i < 2) {
|
| 2001 | if (at_tok_nextint(&line, &tmp_int) < 0)
|
| 2002 | {
|
| 2003 | LOG("cell_info.running 9= %d\n.",cell_info.running);
|
| 2004 | goto EEMGINFOPS_EXIT;
|
| 2005 | }
|
| 2006 | i++;
|
| 2007 | }
|
| 2008 |
|
| 2009 | // arfcn
|
| 2010 | if (at_tok_nextint(&line, &tmp_int) < 0 || tmp_int < 0 || tmp_int >= 65536)
|
| 2011 | {
|
| 2012 | LOG("cell_info.running 10 = %d\n.",cell_info.running);
|
| 2013 | goto EEMGINFOPS_EXIT;
|
| 2014 | }
|
| 2015 | cell_info.cell_list.cell[cell_info.cell_list.num].value3 = (uint32)tmp_int;
|
| 2016 |
|
| 2017 | cell_info.cell_list.num++;
|
| 2018 | EEMGINFOPS_EXIT:
|
| 2019 | free(free_ptr);
|
| 2020 | }
|
| 2021 | } else {
|
| 2022 | LOGW("Unknown CELL URC : %s", s);
|
| 2023 | }
|
| 2024 | }
|
| 2025 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2026 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2027 | 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] | 2028 | {
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 2029 | LOGV("URC : %s", s);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2030 | // MBTK_AT_READY
|
b.liu | aced4f9 | 2024-12-31 11:14:51 +0800 | [diff] [blame] | 2031 | // +CMT: ,23
|
| 2032 | // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
|
| 2033 | // Get PDU data.
|
| 2034 | if(cmt_found) {
|
| 2035 | cmt_found = FALSE;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2036 | urc_sms_state_change_process(sim_id, s, true);
|
b.liu | aced4f9 | 2024-12-31 11:14:51 +0800 | [diff] [blame] | 2037 | } else if (strStartsWith(s, "MBTK_AT_READY")) { // AT ready.
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2038 |
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 2039 | } else if(strStartsWith(s, "CONNECT") || strStartsWith(s, "+CGEV:")) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2040 | urc_pdp_state_change_process(sim_id, s, sms_pdu);
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2041 | } else if(strStartsWith(s, "+EEMNRSVC:") || strStartsWith(s, "+EEMNRINTER:")
|
| 2042 | || strStartsWith(s, "+EEMNRINTERRAT:")
|
| 2043 | || strStartsWith(s, "+EEMLTESVC:") || strStartsWith(s, "+EEMLTEINTER:")
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 2044 | || strStartsWith(s, "+EEMLTEINTRA:") || strStartsWith(s, "+EEMLTEINTERRAT:")
|
| 2045 | || strStartsWith(s, "+EEMUMTSSVC:") || strStartsWith(s, "+EEMUMTSINTRA:")
|
| 2046 | || strStartsWith(s, "+EEMUMTSINTERRAT:") || strStartsWith(s, "+EEMGINFOBASIC:")
|
| 2047 | || strStartsWith(s, "+EEMGINFOSVC:") || strStartsWith(s, "+EEMGINFOPS:")
|
| 2048 | || strStartsWith(s, "+EEMGINFONC:")) {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2049 | urc_cell_info_process(sim_id, s, sms_pdu);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2050 | }
|
| 2051 | else if(strStartsWith(s, "*RADIOPOWER:")) // "*RADIOPOWER: 1"
|
| 2052 | {
|
| 2053 | const char* ptr = s + strlen("*RADIOPOWER:");
|
| 2054 | while(*ptr != '\0' && *ptr == ' ' )
|
| 2055 | {
|
| 2056 | ptr++;
|
| 2057 | }
|
| 2058 |
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2059 | mbtk_ril_radio_state_info_t state;
|
| 2060 | memset(&state, 0, sizeof(mbtk_ril_radio_state_info_t));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2061 | state.sim_id = sim_id;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2062 | if(*ptr == '1') {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2063 | state.radio_state = MBTK_RADIO_STATE_FULL_FUNC;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2064 | } else {
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2065 | state.radio_state = MBTK_RADIO_STATE_MINI_FUNC;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2066 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2067 | 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] | 2068 | }
|
| 2069 | // +CREG: 1, "8010", "000060a5", 0, 2, 0
|
| 2070 | // +CREG: 1, "8330", "06447347", 7, 2, 0
|
| 2071 | // +CEREG: 1, "8330", "06447347", 7
|
| 2072 | // $CREG: 1, "8330", "06447347", 7,"0d4", 2, 0
|
| 2073 | // $CREG: 1, "8010", "000060a7", 0,, 2, 0
|
| 2074 | // +CGREG: 1
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2075 | // +C5GREG: 1,"00280386","07e920010",11,1,"01"
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2076 | else if(strStartsWith(s, "+CGREG:") // GMS/WCDMA data registed.
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2077 | || strStartsWith(s, "+CEREG:") // LTE data registed.
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2078 | || strStartsWith(s, "+CREG:") // GMS/WCDMA/LTE CS registed.
|
| 2079 | || strStartsWith(s, "+C5GREG:")) // NR data registed.
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2080 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2081 | urc_net_reg_state_change_process(sim_id, s, sms_pdu);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2082 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2083 | // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
|
| 2084 | else if(strStartsWith(s, "+CLCC:")
|
| 2085 | || strStartsWith(s, "+CPAS:")
|
| 2086 | || strStartsWith(s, "+CALLDISCONNECT:"))
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2087 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2088 | urc_call_state_change_process(sim_id, s, sms_pdu);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2089 | }
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2090 | else if(strStartsWith(s, "*SIMDETEC:")
|
| 2091 | || strStartsWith(s, "*EUICC:")
|
| 2092 | || strStartsWith(s, "+CPIN:"))
|
| 2093 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2094 | urc_sim_state_change_process(sim_id, s, sms_pdu);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2095 | }
|
| 2096 | else if(strStartsWith(s, "+CMT:"))
|
| 2097 | {
|
b.liu | aced4f9 | 2024-12-31 11:14:51 +0800 | [diff] [blame] | 2098 | cmt_found = TRUE;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2099 | urc_sms_state_change_process(sim_id, s, false);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2100 | }
|
| 2101 | else if(strStartsWith(s, "*ECALLDATA:"))
|
| 2102 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2103 | urc_ecall_state_change_process(sim_id, s, sms_pdu);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2104 | }
|
| 2105 | #if 0
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2106 | // +CLCC: 1, 1, 6, 0, 0, "18981911691", 129, "",, 0
|
| 2107 | else if(strStartsWith(s, "+CLCC:"))
|
| 2108 | {
|
| 2109 | mbtk_call_info_t reg;
|
| 2110 | reg.call_wait = MBTK_CLCC;
|
| 2111 | char* tmp_s = memdup(s,strlen(s));
|
| 2112 | char* free_ptr = tmp_s;
|
| 2113 | char *line = tmp_s;
|
| 2114 | int tmp_int;
|
| 2115 | char *tmp_str;
|
| 2116 | int err;
|
| 2117 |
|
| 2118 | err = at_tok_start(&line);
|
| 2119 | if (err < 0)
|
| 2120 | {
|
| 2121 | goto CLCC_EXIT;
|
| 2122 | }
|
| 2123 | err = at_tok_nextint(&line, &tmp_int); // dir1
|
| 2124 | if (err < 0)
|
| 2125 | {
|
| 2126 | goto CLCC_EXIT;
|
| 2127 | }
|
| 2128 | reg.dir1 = (uint8)tmp_int;
|
| 2129 | err = at_tok_nextint(&line, &tmp_int);// dir
|
| 2130 | if (err < 0)
|
| 2131 | {
|
| 2132 | goto CLCC_EXIT;
|
| 2133 | }
|
| 2134 | reg.dir = (uint8)tmp_int;
|
| 2135 | err = at_tok_nextint(&line, &tmp_int);// state
|
| 2136 | if (err < 0)
|
| 2137 | {
|
| 2138 | goto CLCC_EXIT;
|
| 2139 | }
|
| 2140 | reg.state = (uint8)tmp_int;
|
| 2141 | err = at_tok_nextint(&line, &tmp_int);// mode
|
| 2142 | if (err < 0)
|
| 2143 | {
|
| 2144 | goto CLCC_EXIT;
|
| 2145 | }
|
| 2146 | reg.mode = (uint8)tmp_int;
|
| 2147 | err = at_tok_nextint(&line, &tmp_int);// mpty
|
| 2148 | if (err < 0)
|
| 2149 | {
|
| 2150 | goto CLCC_EXIT;
|
| 2151 | }
|
| 2152 | reg.mpty = (uint8)tmp_int;
|
| 2153 | err = at_tok_nextstr(&line, &tmp_str); // phone_number
|
| 2154 | if (err < 0)
|
| 2155 | {
|
| 2156 | goto CLCC_EXIT;
|
| 2157 | }
|
| 2158 |
|
| 2159 | memset(reg.phone_number,0,sizeof(reg.phone_number));
|
| 2160 | memcpy(reg.phone_number, tmp_str, strlen(tmp_str));
|
| 2161 | err = at_tok_nextint(&line, &tmp_int);// tpye
|
| 2162 | if (err < 0)
|
| 2163 | {
|
| 2164 | goto CLCC_EXIT;
|
| 2165 | }
|
| 2166 | reg.type = (uint8)tmp_int;
|
| 2167 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 2168 | CLCC_EXIT:
|
| 2169 | free(free_ptr);
|
| 2170 | }
|
| 2171 | // +CPAS: 4
|
| 2172 | else if(strStartsWith(s, "+CPAS:"))
|
| 2173 | {
|
| 2174 | mbtk_call_info_t reg;
|
| 2175 | reg.call_wait = 0;
|
| 2176 | char* tmp_s = memdup(s,strlen(s));
|
| 2177 | char* free_ptr = tmp_s;
|
| 2178 | char *line = tmp_s;
|
| 2179 | int tmp_int;
|
| 2180 | int err;
|
| 2181 |
|
| 2182 | memset(®,0,sizeof(reg));
|
| 2183 |
|
| 2184 | err = at_tok_start(&line);
|
| 2185 | if (err < 0)
|
| 2186 | {
|
| 2187 | goto CPAS_EXIT;
|
| 2188 | }
|
| 2189 | err = at_tok_nextint(&line, &tmp_int);
|
| 2190 | if (err < 0)
|
| 2191 | {
|
| 2192 | goto CPAS_EXIT;
|
| 2193 | }
|
| 2194 | reg.pas = (uint8)tmp_int;
|
| 2195 | reg.call_wait = MBTK_CPAS;
|
| 2196 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 2197 | CPAS_EXIT:
|
| 2198 | free(free_ptr);
|
| 2199 | }
|
| 2200 | // +CALLDISCONNECT: 1
|
| 2201 | else if(strStartsWith(s, "+CALLDISCONNECT:"))
|
| 2202 | {
|
| 2203 | mbtk_call_info_t reg;
|
| 2204 | reg.call_wait = 0;
|
| 2205 | char* tmp_s = memdup(s,strlen(s));
|
| 2206 | char* free_ptr = tmp_s;
|
| 2207 | char *line = tmp_s;
|
| 2208 | int tmp_int;
|
| 2209 | int err;
|
| 2210 |
|
| 2211 | memset(®,0,sizeof(reg));
|
| 2212 |
|
| 2213 | err = at_tok_start(&line);
|
| 2214 | if (err < 0)
|
| 2215 | {
|
| 2216 | goto CALLDISCONNECTED_EXIT;
|
| 2217 | }
|
| 2218 | err = at_tok_nextint(&line, &tmp_int);
|
| 2219 | if (err < 0)
|
| 2220 | {
|
| 2221 | goto CALLDISCONNECTED_EXIT;
|
| 2222 | }
|
| 2223 | reg.disconnected_id = tmp_int;
|
| 2224 | reg.call_wait = MBTK_DISCONNECTED;
|
| 2225 |
|
| 2226 | if(reg.call_wait == MBTK_DISCONNECTED)
|
| 2227 | {
|
| 2228 | //mbtk_net_led_set(MBTK_NET_LED_CALL_DISCONNECT);
|
| 2229 | }
|
| 2230 |
|
| 2231 | urc_msg_distribute(false, INFO_URC_MSG_CALL_STATE, ®, sizeof(mbtk_call_info_t));
|
| 2232 |
|
| 2233 | CALLDISCONNECTED_EXIT:
|
| 2234 | free(free_ptr);
|
| 2235 | }
|
| 2236 | // *SIMDETEC:1,SIM
|
| 2237 | else if(strStartsWith(s, "*SIMDETEC:"))
|
| 2238 | {
|
| 2239 | if(strStartsWith(s, "*SIMDETEC:1,NOS"))
|
| 2240 | {
|
| 2241 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2242 | }
|
| 2243 |
|
| 2244 | sim_info_reg.sim = -1;
|
| 2245 | if(strStartsWith(s, "*SIMDETEC:1,NOS"))
|
| 2246 | sim_info_reg.sim = 0;
|
| 2247 | else if(strStartsWith(s, "*SIMDETEC:1,SIM"))
|
| 2248 | sim_info_reg.sim = 1;
|
| 2249 | if(sim_info_reg.sim == 0)
|
| 2250 | {
|
| 2251 | uint8 data_pdp;
|
| 2252 | data_pdp = 11; //
|
| 2253 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 2254 | }
|
| 2255 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 2256 | }
|
| 2257 | // *EUICC:1
|
| 2258 | /*0: SIM
|
| 2259 | 1: USIM
|
| 2260 | 2: TEST SIM
|
| 2261 | 3: TEST USIM
|
| 2262 | 4: UNKNOWN
|
| 2263 | Note: *EUICC:
|
| 2264 | */
|
| 2265 | else if(strStartsWith(s, "*EUICC:"))
|
| 2266 | {
|
| 2267 | sim_info_reg.sim_card_type = -1;
|
| 2268 | if(strStartsWith(s, "*EUICC: 0"))
|
| 2269 | sim_info_reg.sim_card_type = 1;
|
| 2270 | else if(strStartsWith(s, "*EUICC: 1"))
|
| 2271 | sim_info_reg.sim_card_type = 2;
|
| 2272 | else if(strStartsWith(s, "*EUICC: 2"))
|
| 2273 | sim_info_reg.sim_card_type = 1;
|
| 2274 | else if(strStartsWith(s, "*EUICC: 3"))
|
| 2275 | sim_info_reg.sim_card_type = 2;
|
| 2276 | else if(strStartsWith(s, "*EUICC: 4"))
|
| 2277 | sim_info_reg.sim_card_type = 0;
|
| 2278 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 2279 | }
|
| 2280 | // +CPIN: SIM PIN
|
| 2281 | else if(strStartsWith(s, "+CPIN:"))
|
| 2282 | {
|
| 2283 | sim_info_reg.sim = -1;
|
| 2284 | if(strStartsWith(s, "+CPIN: READY"))
|
| 2285 | {
|
| 2286 | sim_info_reg.sim = 1;
|
| 2287 | net_info.sim_state = MBTK_SIM_READY;
|
| 2288 | }
|
| 2289 | else if(strStartsWith(s, "+CPIN: SIM PIN"))
|
| 2290 | {
|
| 2291 | sim_info_reg.sim = 2;
|
| 2292 | net_info.sim_state = MBTK_SIM_PIN;
|
| 2293 | }
|
| 2294 | else if(strStartsWith(s, "+CPIN: SIM PUK"))
|
| 2295 | {
|
| 2296 | sim_info_reg.sim = 3;
|
| 2297 | net_info.sim_state = MBTK_SIM_PUK;
|
| 2298 | }
|
| 2299 | else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PIN"))
|
| 2300 | {
|
| 2301 | sim_info_reg.sim = 4;
|
| 2302 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2303 | }
|
| 2304 | else if(strStartsWith(s, "+CPIN: PH-SIMLOCK PUK"))
|
| 2305 | {
|
| 2306 | sim_info_reg.sim = 5;
|
| 2307 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2308 | }
|
| 2309 | else if(strStartsWith(s, "+CPIN: PH-FSIM PIN"))
|
| 2310 | {
|
| 2311 | sim_info_reg.sim = 6;
|
| 2312 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2313 | }
|
| 2314 | else if(strStartsWith(s, "+CPIN: PH-FSIM PUK"))
|
| 2315 | {
|
| 2316 | sim_info_reg.sim = 7;
|
| 2317 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2318 | }
|
| 2319 | else if(strStartsWith(s, "+CPIN: SIM PIN2"))
|
| 2320 | {
|
| 2321 | sim_info_reg.sim = 8;
|
| 2322 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2323 | }
|
| 2324 | else if(strStartsWith(s, "+CPIN: SIM PUK2"))
|
| 2325 | {
|
| 2326 | sim_info_reg.sim = 9;
|
| 2327 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2328 | }
|
| 2329 | else if(strStartsWith(s, "+CPIN: PH-NET PIN"))
|
| 2330 | {
|
| 2331 | sim_info_reg.sim = 10;
|
| 2332 | net_info.sim_state = MBTK_SIM_NETWORK_PERSONALIZATION;
|
| 2333 | }
|
| 2334 | else if(strStartsWith(s, "+CPIN: PH-NET PUK"))
|
| 2335 | {
|
| 2336 | sim_info_reg.sim = 11;
|
| 2337 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2338 | }
|
| 2339 | else if(strStartsWith(s, "+CPIN: PH-NETSUB PINMT"))
|
| 2340 | {
|
| 2341 | sim_info_reg.sim = 12;
|
| 2342 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2343 | }
|
| 2344 | else if(strStartsWith(s, "+CPIN: PH-NETSUB PUK"))
|
| 2345 | {
|
| 2346 | sim_info_reg.sim = 13;
|
| 2347 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2348 | }
|
| 2349 | else if(strStartsWith(s, "+CPIN: PH-SP PIN"))
|
| 2350 | {
|
| 2351 | sim_info_reg.sim = 14;
|
| 2352 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2353 | }
|
| 2354 | else if(strStartsWith(s, "+CPIN: PH-SP PUK"))
|
| 2355 | {
|
| 2356 | sim_info_reg.sim = 15;
|
| 2357 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2358 | }
|
| 2359 | else if(strStartsWith(s, "+CPIN: PH-CORP PIN"))
|
| 2360 | {
|
| 2361 | sim_info_reg.sim = 16;
|
| 2362 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2363 | }
|
| 2364 | else if(strStartsWith(s, "+CPIN: PH-CORP PUK"))
|
| 2365 | {
|
| 2366 | sim_info_reg.sim = 17;
|
| 2367 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2368 | }
|
| 2369 | else if(strStartsWith(s, "+CPIN: SIM REMOVED"))
|
| 2370 | {
|
| 2371 | sim_info_reg.sim = 18;
|
| 2372 | net_info.sim_state = MBTK_SIM_ABSENT;
|
| 2373 | }
|
| 2374 | else
|
| 2375 | sim_info_reg.sim = 20;
|
| 2376 |
|
| 2377 | if(sim_info_reg.sim == 18)
|
| 2378 | {
|
| 2379 | uint8 data_pdp;
|
| 2380 | data_pdp = 11; //
|
| 2381 | urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
|
| 2382 | }
|
| 2383 |
|
| 2384 | urc_msg_distribute(false, INFO_URC_MSG_SIM_STATE, &sim_info_reg, sizeof(mbtk_sim_card_info));
|
| 2385 | }
|
| 2386 | // +CMT: ,23
|
| 2387 | // 0891683108200855F6240D91688189911196F10000221130717445230331D90C
|
| 2388 | else if(strStartsWith(s, "+CMT:") || sms_cmt)
|
| 2389 | {
|
| 2390 | if(!sms_cmt){
|
| 2391 | sms_cmt = true;
|
| 2392 | }else{
|
| 2393 | sms_cmt = false;
|
| 2394 | }
|
| 2395 | printf("+CMT() sms_cmt:%d, s:%s, len:%d\n",sms_cmt, s, strlen(s));
|
| 2396 | urc_msg_distribute(false, INFO_URC_MSG_SMS_STATE, s, strlen(s));
|
| 2397 | }
|
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 2398 | #endif
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2399 | 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"
|
| 2400 | {
|
| 2401 |
|
| 2402 | }
|
| 2403 | else
|
| 2404 | {
|
| 2405 | LOGV("Unknown URC : %s", s);
|
| 2406 | }
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2407 | }
|
| 2408 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2409 | static void onUnsolicited1(const char *s, const char *sms_pdu)
|
| 2410 | {
|
| 2411 | onUnsolicited(MBTK_SIM_1, s, sms_pdu);
|
| 2412 | }
|
| 2413 |
|
| 2414 | static void onUnsolicited2(const char *s, const char *sms_pdu)
|
| 2415 | {
|
| 2416 | onUnsolicited(MBTK_SIM_2, s, sms_pdu);
|
| 2417 | }
|
| 2418 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2419 | static int openSocket(const char* sockname)
|
| 2420 | {
|
| 2421 | int sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
| 2422 | if (sock < 0)
|
| 2423 | {
|
| 2424 | LOGE("Error create socket: %s\n", strerror(errno));
|
| 2425 | return -1;
|
| 2426 | }
|
| 2427 | struct sockaddr_un addr;
|
| 2428 | memset(&addr, 0, sizeof(addr));
|
| 2429 | addr.sun_family = AF_UNIX;
|
| 2430 | strncpy(addr.sun_path, sockname, sizeof(addr.sun_path));
|
| 2431 | while (TEMP_FAILURE_RETRY(connect(sock,(const struct sockaddr*)&addr, sizeof(addr))) != 0)
|
| 2432 | {
|
| 2433 | LOGE("Error connect to socket %s: %s, try again", sockname, strerror(errno));
|
| 2434 | sleep(1);
|
| 2435 | }
|
| 2436 |
|
| 2437 | #if 0
|
| 2438 | int sk_flags = fcntl(sock, F_GETFL, 0);
|
| 2439 | fcntl(sock, F_SETFL, sk_flags | O_NONBLOCK);
|
| 2440 | #endif
|
| 2441 |
|
| 2442 | return sock;
|
| 2443 | }
|
| 2444 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2445 | static void ril_at_ready_process() |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2446 | {
|
| 2447 | // SIM1 radio state config.
|
| 2448 | ril_info.radio_state[MBTK_SIM_1] = ril_radio_state_get(MBTK_SIM_1, ATPORTTYPE_0);
|
| 2449 | 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] | 2450 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2451 | 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] | 2452 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2453 | |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2454 | 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] | 2455 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2456 | at_send_command(portType_2_portId(MBTK_SIM_1, ATPORTTYPE_0), "AT+CEREG=2", NULL);
|
| 2457 | }
|
| 2458 |
|
| 2459 | // SIM2 radio state config.
|
| 2460 | ril_info.radio_state[MBTK_SIM_2] = ril_radio_state_get(MBTK_SIM_2, ATPORTTYPE_0);
|
| 2461 | 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] | 2462 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2463 | ril_radio_state_set(MBTK_SIM_2, ATPORTTYPE_0, MBTK_RADIO_STATE_FULL_FUNC, FALSE);
|
| 2464 | }
|
| 2465 | |
| 2466 | if(ril_info.radio_state[MBTK_SIM_2] == MBTK_RADIO_STATE_FULL_FUNC)
|
| 2467 | {
|
| 2468 | at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+CEREG=2", NULL);
|
| 2469 | }
|
| 2470 |
|
| 2471 | // SIM1 state config.
|
| 2472 | ril_info.sim_state[MBTK_SIM_1] = ril_sim_state_get(MBTK_SIM_1, ATPORTTYPE_0);
|
| 2473 | if(ril_info.sim_state[MBTK_SIM_1] == MBTK_SIM_STATE_READY)
|
| 2474 | { |
| 2475 | LOGD("SIM1 READY!");
|
| 2476 | 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] | 2477 |
|
| 2478 | // Set APN from prop.
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2479 | apn_auto_conf_from_prop(MBTK_SIM_1, ATPORTTYPE_0);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2480 | } |
| 2481 | else |
| 2482 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2483 | LOGE("SIM1 NOT READY!");
|
| 2484 | }
|
| 2485 |
|
| 2486 | // SIM2 state config.
|
| 2487 | ril_info.sim_state[MBTK_SIM_2] = ril_sim_state_get(MBTK_SIM_2, ATPORTTYPE_0);
|
| 2488 | if(ril_info.sim_state[MBTK_SIM_2] == MBTK_SIM_STATE_READY)
|
| 2489 | { |
| 2490 | LOGD("SIM1 READY!");
|
| 2491 | at_send_command(portType_2_portId(MBTK_SIM_2, ATPORTTYPE_0), "AT+COPS=3", NULL);
|
| 2492 |
|
| 2493 | // Set APN from prop.
|
| 2494 | apn_auto_conf_from_prop(MBTK_SIM_2, ATPORTTYPE_0);
|
| 2495 | } |
| 2496 | else |
| 2497 | { |
| 2498 | LOGE("SIM1 NOT READY!");
|
| 2499 | }
|
| 2500 |
|
| 2501 | if(req_dual_sim_get(ATPORTTYPE_0, &(ril_info.cur_sim_id), NULL)) {
|
| 2502 | LOGE("req_dual_sim_get() fail, so set to SIM1.");
|
| 2503 | ril_info.cur_sim_id = MBTK_SIM_1;
|
| 2504 | } else {
|
| 2505 | LOGD("Current SIM : %d", ril_info.cur_sim_id);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2506 | }
|
| 2507 | }
|
| 2508 |
|
| 2509 | static void ind_regisger(sock_cli_info_t* cli_info, uint16 ind)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2510 | { |
| 2511 | uint32 i = 0; |
| 2512 | while(i < cli_info->ind_num) |
| 2513 | { |
| 2514 | if(cli_info->ind_register[i] == ind) |
| 2515 | break; |
| 2516 | i++; |
| 2517 | } |
| 2518 | |
| 2519 | if(i == cli_info->ind_num) // No found IND |
| 2520 | { |
| 2521 | cli_info->ind_register[i] = ind; |
| 2522 | cli_info->ind_num++; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2523 | LOGD("Register IND : %s", id2str(ind));
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2524 | } |
| 2525 | else |
| 2526 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2527 | LOGW("IND had exist.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2528 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2529 | }
|
| 2530 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2531 | // Process AT URC data |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2532 | 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] | 2533 | {
|
| 2534 | if(cli_info) {
|
| 2535 | if(ril_info.msg_queue[cli_info->port].count >= PACK_PROCESS_QUEUE_MAX)
|
| 2536 | {
|
| 2537 | LOGE("Packet process queue is full");
|
| 2538 | return -1;
|
| 2539 | }
|
| 2540 | } else {
|
| 2541 | if(ril_info.msg_queue[ATPORTTYPE_0].count >= PACK_PROCESS_QUEUE_MAX)
|
| 2542 | {
|
| 2543 | LOGE("Packet process queue is full");
|
| 2544 | return -1;
|
| 2545 | }
|
| 2546 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2547 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2548 | 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] | 2549 | if(!item) |
| 2550 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2551 | LOGE("malloc() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2552 | return -1; |
| 2553 | } |
| 2554 | item->cli_info = cli_info; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2555 | item->pack = pack;
|
| 2556 |
|
| 2557 | if(cli_info) {
|
| 2558 | mbtk_queue_put(&(ril_info.msg_queue[cli_info->port]), item);
|
| 2559 |
|
| 2560 | // If thread is waitting,continue it.
|
| 2561 | pthread_mutex_lock(&(ril_info.msg_mutex[cli_info->port]));
|
| 2562 | pthread_cond_signal(&(ril_info.msg_cond[cli_info->port]));
|
| 2563 | pthread_mutex_unlock(&(ril_info.msg_mutex[cli_info->port]));
|
| 2564 | } else { // URC message, is null.
|
| 2565 | mbtk_queue_put(&(ril_info.msg_queue[ATPORTTYPE_0]), item);
|
| 2566 |
|
| 2567 | // If thread is waitting,continue it.
|
| 2568 | pthread_mutex_lock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
|
| 2569 | pthread_cond_signal(&(ril_info.msg_cond[ATPORTTYPE_0]));
|
| 2570 | pthread_mutex_unlock(&(ril_info.msg_mutex[ATPORTTYPE_0]));
|
| 2571 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2572 | |
| 2573 | return 0; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2574 | }
|
| 2575 |
|
| 2576 |
|
| 2577 | 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] | 2578 | { |
| 2579 | // Register IND Message. |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2580 | if(pack->msg_type == RIL_MSG_TYPE_REQ)
|
| 2581 | {
|
| 2582 | if(pack->msg_id > RIL_MSG_ID_IND_BEGIN
|
| 2583 | && pack->msg_id < RIL_MSG_ID_IND_END) {
|
| 2584 | mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
|
| 2585 | if(cli_info->ind_num >= IND_REGISTER_MAX)
|
| 2586 | {
|
| 2587 | LOGE("IND if full.");
|
| 2588 | err = MBTK_RIL_ERR_IND_FULL;
|
| 2589 | }
|
| 2590 | else
|
| 2591 | {
|
| 2592 | ind_regisger(cli_info, pack->msg_id);
|
| 2593 | }
|
| 2594 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2595 | 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] | 2596 |
|
| 2597 | ril_msg_pack_free(pack);
|
| 2598 | } else {
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2599 | 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] | 2600 | if(0 && pack->data_len > 0)
|
| 2601 | {
|
| 2602 | log_hex("DATA", pack->data, pack->data_len);
|
| 2603 | }
|
| 2604 |
|
| 2605 | // Send to REQ_process_thread process.
|
| 2606 | send_pack_to_queue(cli_info, pack);
|
| 2607 |
|
| 2608 | // For test.
|
| 2609 | // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS);
|
| 2610 | }
|
| 2611 | } else {
|
| 2612 | LOGE("Pack type error : %d", pack->msg_type);
|
| 2613 | }
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2614 | }
|
| 2615 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2616 | // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP. |
| 2617 | // Otherwise, do not call pack_error_send(). |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2618 | 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] | 2619 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2620 | if(pack->msg_id > RIL_MSG_ID_DEV_BEGIN && pack->msg_id < RIL_MSG_ID_DEV_END) {
|
| 2621 | return dev_pack_req_process(cli_info, pack);
|
| 2622 | } else if(pack->msg_id > RIL_MSG_ID_SIM_BEGIN && pack->msg_id < RIL_MSG_ID_SIM_END) {
|
| 2623 | return sim_pack_req_process(cli_info, pack);
|
| 2624 | } else if(pack->msg_id > RIL_MSG_ID_NET_BEGIN && pack->msg_id < RIL_MSG_ID_NET_END) {
|
| 2625 | return net_pack_req_process(cli_info, pack);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2626 | } else if(pack->msg_id > RIL_MSG_ID_DATA_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_DATA_CALL_END) {
|
| 2627 | return data_call_pack_req_process(cli_info, pack);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2628 | } else if(pack->msg_id > RIL_MSG_ID_CALL_BEGIN && pack->msg_id < RIL_MSG_ID_CALL_END) {
|
| 2629 | return call_pack_req_process(cli_info, pack);
|
| 2630 | } else if(pack->msg_id > RIL_MSG_ID_SMS_BEGIN && pack->msg_id < RIL_MSG_ID_SMS_END) {
|
| 2631 | return sms_pack_req_process(cli_info, pack);
|
| 2632 | } else if(pack->msg_id > RIL_MSG_ID_PB_BEGIN && pack->msg_id < RIL_MSG_ID_PB_END) {
|
| 2633 | return pb_pack_req_process(cli_info, pack);
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2634 | } else if(pack->msg_id > RIL_MSG_ID_ECALL_BEGIN && pack->msg_id < RIL_MSG_ID_ECALL_END) {
|
| 2635 | return ecall_pack_req_process(cli_info, pack);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2636 | } else {
|
| 2637 | LOGW("Unknown msg id : %d", pack->msg_id);
|
| 2638 | return MBTK_RIL_ERR_FORMAT;
|
| 2639 | }
|
| 2640 | }
|
| 2641 |
|
| 2642 | static void urc_msg_process(ril_urc_msg_info_t *msg)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2643 | { |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2644 | // data can be NULL (For RIL_URC_MSG_BAND_SET)
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2645 | if(!msg->data || msg->data_len <= 0) {
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2646 | LOGW("URC data is NULL.");
|
| 2647 | // return;
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2648 | }
|
| 2649 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2650 | switch(msg->msg) { |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2651 | case RIL_MSG_ID_IND_RADIO_STATE_CHANGE:
|
| 2652 | {
|
| 2653 | mbtk_ril_radio_state_info_t *state = (mbtk_ril_radio_state_info_t*)msg->data;
|
| 2654 | LOGD("Radio state : %d", state->radio_state);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2655 | break; |
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2656 | }
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 2657 | case RIL_MSG_ID_IND_SIM_STATE_CHANGE:
|
| 2658 | {
|
| 2659 | mbtk_ril_sim_state_info_t *state = (mbtk_ril_sim_state_info_t*)msg->data;
|
| 2660 | if(state->sim_state == MBTK_SIM_STATE_READY) {
|
| 2661 | LOGD("SIM READY!");
|
| 2662 | at_send_command(ATPORTTYPE_0, "AT+COPS=3", NULL);
|
| 2663 |
|
| 2664 | // Set APN from prop.
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2665 | apn_auto_conf_from_prop(state->sim_id, ATPORTTYPE_0);
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 2666 | }
|
| 2667 | }
|
b.liu | afdf2c6 | 2024-11-12 11:10:44 +0800 | [diff] [blame] | 2668 | case RIL_MSG_ID_IND_NET_REG_STATE_CHANGE:
|
| 2669 | {
|
| 2670 | 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^] | 2671 | data_call_retry(reg_state->sim_id, ATPORTTYPE_0, reg_state);
|
b.liu | afdf2c6 | 2024-11-12 11:10:44 +0800 | [diff] [blame] | 2672 | break;
|
| 2673 | }
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2674 | case RIL_URC_MSG_BAND_SET:
|
| 2675 | {
|
| 2676 | int cme_err = MBTK_RIL_ERR_CME_NON;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2677 | 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] | 2678 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2679 | LOGE("Set SIM1 band fail.");
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2680 | }
|
| 2681 | else // Set band success.
|
| 2682 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2683 | LOGD("Set SIM1 band success.");
|
| 2684 | cme_err = MBTK_RIL_ERR_CME_NON;
|
| 2685 | if(req_band_set(MBTK_SIM_2, ATPORTTYPE_0, &band_info.band_support, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
|
| 2686 | {
|
| 2687 | LOGE("Set SIM2 band fail.");
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2688 | }
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2689 | else // Set band success.
|
| 2690 | {
|
| 2691 | LOGD("Set SIM2 band success.");
|
| 2692 | // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));
|
| 2693 | band_info.band_set_success = TRUE;
|
| 2694 | if(band_info.band_area == MBTK_MODEM_BAND_AREA_CN) {
|
| 2695 | property_set("persist.mbtk.band_config", "CN");
|
| 2696 | } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_EU) {
|
| 2697 | property_set("persist.mbtk.band_config", "EU");
|
| 2698 | } else if(band_info.band_area == MBTK_MODEM_BAND_AREA_SA) {
|
| 2699 | property_set("persist.mbtk.band_config", "SA");
|
| 2700 | } else {
|
| 2701 | property_set("persist.mbtk.band_config", "ALL");
|
| 2702 | }
|
| 2703 | }
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2704 | }
|
| 2705 | break;
|
| 2706 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2707 | default: |
| 2708 | { |
| 2709 | LOGE("Unknown URC : %d", msg->msg); |
| 2710 | break; |
| 2711 | } |
| 2712 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2713 | }
|
| 2714 |
|
| 2715 | // Read client conn/msg and push into ril_info.msg_queue.
|
| 2716 | static void* ril_read_pthread(void* arg)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2717 | { |
| 2718 | UNUSED(arg); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2719 | ril_info.epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1);
|
| 2720 | if(ril_info.epoll_fd < 0)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2721 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2722 | LOGE("epoll_create() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2723 | return NULL; |
| 2724 | } |
| 2725 | |
| 2726 | uint32 event = EPOLLIN | EPOLLET; |
| 2727 | struct epoll_event ev; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2728 | ev.data.fd = ril_info.sock_listen_fd;
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2729 | ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2730 | 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] | 2731 | |
| 2732 | int nready = -1; |
| 2733 | struct epoll_event epoll_events[EPOLL_LISTEN_MAX]; |
| 2734 | while(1) |
| 2735 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2736 | 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] | 2737 | if(nready > 0) |
| 2738 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2739 | sock_cli_info_t *cli_info = NULL;
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2740 | int i; |
| 2741 | for(i = 0; i < nready; i++) |
| 2742 | { |
| 2743 | LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events); |
| 2744 | if(epoll_events[i].events & EPOLLHUP) // Client Close. |
| 2745 | { |
| 2746 | if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) |
| 2747 | { |
| 2748 | cli_close(cli_info); |
| 2749 | } |
| 2750 | else |
| 2751 | { |
| 2752 | LOG("Unknown client[fd = %d].", epoll_events[i].data.fd); |
| 2753 | } |
| 2754 | } |
| 2755 | else if(epoll_events[i].events & EPOLLIN) |
| 2756 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2757 | 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] | 2758 | { |
| 2759 | int client_fd = -1; |
| 2760 | while(1) |
| 2761 | { |
| 2762 | struct sockaddr_in cliaddr; |
| 2763 | socklen_t clilen = sizeof(cliaddr); |
| 2764 | client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen); |
| 2765 | if(client_fd < 0) |
| 2766 | { |
| 2767 | if(errno == EAGAIN) |
| 2768 | { |
| 2769 | LOG("All client connect get."); |
| 2770 | } |
| 2771 | else |
| 2772 | { |
| 2773 | LOG("accept() error[%d].", errno); |
| 2774 | } |
| 2775 | break; |
| 2776 | } |
| 2777 | // Set O_NONBLOCK |
| 2778 | int flags = fcntl(client_fd, F_GETFL, 0); |
| 2779 | if (flags > 0) |
| 2780 | { |
| 2781 | flags |= O_NONBLOCK; |
| 2782 | if (fcntl(client_fd, F_SETFL, flags) < 0) |
| 2783 | { |
| 2784 | LOG("Set flags error:%d", errno); |
| 2785 | } |
| 2786 | } |
| 2787 | |
| 2788 | memset(&ev,0,sizeof(struct epoll_event)); |
| 2789 | ev.data.fd = client_fd; |
| 2790 | ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2791 | epoll_ctl(ril_info.epoll_fd, EPOLL_CTL_ADD, client_fd, &ev);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2792 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2793 | 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] | 2794 | if(info) |
| 2795 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2796 | memset(info, 0, sizeof(sock_cli_info_t));
|
| 2797 | info->fd = client_fd;
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2798 |
|
| 2799 | // Default AT port.
|
| 2800 | info->port = ATPORTTYPE_0;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2801 | info->sim_id = MBTK_SIM_1;
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2802 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2803 | list_add(ril_info.sock_client_list, info);
|
| 2804 | LOG("Add New Client FD Into List.");
|
| 2805 |
|
b.liu | 15f456b | 2024-10-31 20:16:06 +0800 | [diff] [blame] | 2806 | // Send msg RIL_MSG_ID_IND_SER_STATE_CHANGE to client.
|
| 2807 | mbtk_ril_ser_state_enum state = MBTK_RIL_SER_STATE_READY;
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2808 | 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] | 2809 | } |
| 2810 | else |
| 2811 | { |
| 2812 | LOG("malloc() fail."); |
| 2813 | } |
| 2814 | } |
| 2815 | } |
| 2816 | else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive. |
| 2817 | { |
| 2818 | // Read and process every message. |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2819 | mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
|
| 2820 | 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] | 2821 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2822 | // Parse packet error,send error response to client. |
| 2823 | if(pack == NULL) |
| 2824 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2825 | 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] | 2826 | } |
| 2827 | else |
| 2828 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2829 | ril_msg_pack_info_t** pack_ptr = pack;
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2830 | while(*pack_ptr) |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2831 | {
|
| 2832 | // Update AT port in the first.
|
| 2833 | cli_info->port = (ATPortType_enum)((*pack_ptr)->at_port);
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2834 | cli_info->sim_id = (mbtk_sim_type_enum)((*pack_ptr)->sim_id);
|
| 2835 | if(cli_info->sim_id == MBTK_SIM_AUTO) {
|
| 2836 | cli_info->sim_id = ril_info.cur_sim_id;
|
| 2837 | LOGD("Auto sim => %d", cli_info->sim_id);
|
| 2838 | }
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 2839 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2840 | pack_distribute(cli_info, *pack_ptr); |
| 2841 | // Not free,will free in pack_process() or packet process thread. |
| 2842 | //mbtk_info_pack_free(pack_ptr); |
| 2843 | pack_ptr++; |
| 2844 | } |
| 2845 | |
| 2846 | free(pack); |
| 2847 | } |
| 2848 | } |
| 2849 | else |
| 2850 | { |
| 2851 | LOG("Unknown socket : %d", epoll_events[i].data.fd); |
| 2852 | } |
| 2853 | } |
| 2854 | else |
| 2855 | { |
| 2856 | LOG("Unknown event : %x", epoll_events[i].events); |
| 2857 | } |
| 2858 | } |
| 2859 | } |
| 2860 | else |
| 2861 | { |
| 2862 | LOG("epoll_wait() fail[%d].", errno); |
| 2863 | } |
| 2864 | } |
| 2865 | |
| 2866 | return NULL; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2867 | }
|
| 2868 |
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2869 | static void band_support_init()
|
| 2870 | {
|
| 2871 | mbtk_device_info_modem_t info_modem;
|
| 2872 | memset(&band_info.band_support, 0, sizeof(mbtk_band_info_t));
|
| 2873 | memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2874 | if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
|
| 2875 | LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
|
| 2876 | band_info.band_area = MBTK_MODEM_BAND_AREA_ALL;
|
| 2877 | #ifdef MBTK_5G_SUPPORT
|
| 2878 | band_info.band_support.net_pref = MBTK_NET_PREF_LTE_NR_NR_PREF; // 19
|
| 2879 | band_info.net_support = MBTK_NET_SUPPORT_4G | MBTK_NET_SUPPORT_5G;
|
| 2880 |
|
| 2881 | band_info.band_support.gsm_band = 0;
|
| 2882 | band_info.band_support.umts_band = 0;
|
| 2883 | band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
|
| 2884 | band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
|
| 2885 | band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
|
| 2886 |
|
| 2887 | band_info.band_support.nr_3_band = MBTK_BAND_ALL_NR_3_DEFAULT;
|
| 2888 | band_info.band_support.nr_2_band = MBTK_BAND_ALL_NR_2_DEFAULT;
|
| 2889 | band_info.band_support.nr_1_band = MBTK_BAND_ALL_NR_1_DEFAULT;
|
| 2890 | band_info.band_support.nr_0_band = MBTK_BAND_ALL_NR_0_DEFAULT;
|
| 2891 | #else
|
| 2892 | band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
|
| 2893 | band_info.net_support = MBTK_NET_SUPPORT_2G | MBTK_NET_SUPPORT_3G | MBTK_NET_SUPPORT_4G;
|
| 2894 |
|
| 2895 | band_info.band_support.gsm_band = MBTK_BAND_ALL_GSM_DEFAULT;
|
| 2896 | band_info.band_support.umts_band = MBTK_BAND_ALL_WCDMA_DEFAULT;
|
| 2897 | band_info.band_support.tdlte_band = MBTK_BAND_ALL_TDLTE_DEFAULT;
|
| 2898 | band_info.band_support.fddlte_band = MBTK_BAND_ALL_FDDLTE_DEFAULT;
|
| 2899 | band_info.band_support.lte_ext_band = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
|
| 2900 |
|
| 2901 | band_info.band_support.nr_3_band = 0;
|
| 2902 | band_info.band_support.nr_2_band = 0;
|
| 2903 | band_info.band_support.nr_1_band = 0;
|
| 2904 | band_info.band_support.nr_0_band = 0;
|
| 2905 | #endif
|
| 2906 | } else {
|
| 2907 | band_info.band_area = info_modem.band_area;
|
| 2908 | band_info.net_support = info_modem.net_support;
|
| 2909 | if(info_modem.net_pref < MBTK_NET_PREF_MAX) {
|
| 2910 | band_info.band_support.net_pref = info_modem.net_pref;
|
| 2911 | } else {
|
| 2912 | if(band_info.net_support & MBTK_NET_SUPPORT_5G) {
|
| 2913 | band_info.band_support.net_pref = MBTK_NET_PREF_LTE_NR_NR_PREF; // 19
|
| 2914 | } else {
|
| 2915 | band_info.band_support.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
|
| 2916 | }
|
| 2917 | }
|
| 2918 | band_info.band_support.gsm_band = info_modem.band_gsm;
|
| 2919 | band_info.band_support.umts_band = info_modem.band_wcdma;
|
| 2920 | band_info.band_support.tdlte_band = info_modem.band_tdlte;
|
| 2921 | band_info.band_support.fddlte_band = info_modem.band_fddlte;
|
| 2922 | band_info.band_support.lte_ext_band = info_modem.band_lte_ext;
|
| 2923 |
|
| 2924 | band_info.band_support.nr_3_band = info_modem.band_nr_3;
|
| 2925 | band_info.band_support.nr_2_band = info_modem.band_nr_2;
|
| 2926 | band_info.band_support.nr_1_band = info_modem.band_nr_1;
|
| 2927 | band_info.band_support.nr_0_band = info_modem.band_nr_0;
|
| 2928 | }
|
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 2929 | }
|
| 2930 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2931 | static void* ril_process_thread(void* arg)
|
| 2932 | { |
| 2933 | UNUSED(arg);
|
| 2934 | ATPortType_enum *port = (ATPortType_enum*)arg;
|
| 2935 | ril_msg_queue_info_t* item = NULL;
|
| 2936 | |
| 2937 | pthread_mutex_lock(&(ril_info.msg_mutex[*port]));
|
| 2938 | while(TRUE) |
| 2939 | { |
| 2940 | if(mbtk_queue_empty(&(ril_info.msg_queue[*port])))
|
| 2941 | { |
| 2942 | LOG("[Port-%d]Packet process wait...", *port);
|
| 2943 | pthread_cond_wait(&(ril_info.msg_cond[*port]), &(ril_info.msg_mutex[*port]));
|
| 2944 | LOG("[Port-%d]Packet process continue...", *port);
|
| 2945 | } |
| 2946 | else |
| 2947 | { |
| 2948 | LOG("Packet process queue not empty,continue..."); |
| 2949 | } |
| 2950 | |
| 2951 | // Process all information request. |
| 2952 | mbtk_ril_err_enum err;
|
| 2953 | while((item = (ril_msg_queue_info_t*)mbtk_queue_get(&(ril_info.msg_queue[*port]))) != NULL)
|
| 2954 | { |
| 2955 | if(item->cli_info) { // REQ form client. |
| 2956 | ril_msg_pack_info_t *pack = (ril_msg_pack_info_t*)item->pack;
|
| 2957 | LOGD("Process REQ %s.", id2str(pack->msg_id));
|
| 2958 | ril_info.at_process[*port] = true;
|
| 2959 | err = pack_req_process(item->cli_info, pack); |
| 2960 | if(err != MBTK_RIL_ERR_SUCCESS)
|
| 2961 | { |
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 2962 | 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] | 2963 | } |
| 2964 | ril_info.at_process[*port] = false;
|
| 2965 | ril_msg_pack_free(pack);
|
| 2966 | free(item); |
| 2967 | } else { // REQ from myself.
|
| 2968 | if(item->pack) {
|
| 2969 | ril_urc_msg_info_t *urc = (ril_urc_msg_info_t*)item->pack;
|
| 2970 | LOGD("Process URC %d.", urc->msg);
|
| 2971 | urc_msg_process(urc);
|
| 2972 | if(urc->data)
|
| 2973 | free(urc->data);
|
| 2974 | free(urc);
|
| 2975 | }
|
| 2976 | } |
| 2977 | } |
| 2978 | } |
| 2979 | pthread_mutex_unlock(&(ril_info.msg_mutex[*port]));
|
| 2980 |
|
| 2981 | free(port);
|
| 2982 |
|
| 2983 | return NULL; |
| 2984 | }
|
| 2985 |
|
| 2986 | /* |
| 2987 | AT*BAND=15,78,147,482,134742231 |
| 2988 | |
| 2989 | OK |
| 2990 | */ |
| 2991 | static void* band_config_thread() |
| 2992 | { |
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 2993 | band_info.band_set_success = FALSE;
|
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 2994 | // bool is_first = TRUE;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2995 | while(!band_info.band_set_success) {
|
| 2996 | // Set band.
|
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 2997 | #if 1
|
| 2998 | ril_urc_msg_info_t *msg = (ril_urc_msg_info_t*)malloc(sizeof(ril_urc_msg_info_t));
|
| 2999 | if(msg) {
|
| 3000 | msg->msg = RIL_URC_MSG_BAND_SET;
|
| 3001 | msg->data = NULL;//mbtk_memcpy(&band_info, sizeof(ril_band_info_t));
|
| 3002 | msg->data_len = 0; //sizeof(ril_band_info_t);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3003 | #if 0
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3004 | if(msg->data == NULL) { |
| 3005 | LOGE("mbtk_memcpy() fail."); |
| 3006 | break; |
| 3007 | } |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 3008 | #endif
|
| 3009 | send_pack_to_queue(NULL, msg);
|
| 3010 |
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3011 | sleep(5); |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 3012 | } else {
|
| 3013 | LOG("malloc() fail[%d].", errno);
|
| 3014 | break;
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3015 | }
|
| 3016 | #else
|
| 3017 | sleep(5);
|
| 3018 | #endif
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | LOGD("Set Band thread exit."); |
| 3022 | return NULL; |
| 3023 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3024 |
|
| 3025 |
|
| 3026 | int ril_server_start()
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3027 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3028 | signal(SIGPIPE, SIG_IGN);
|
| 3029 |
|
| 3030 | memset(&ril_info, 0, sizeof(ril_info_t));
|
| 3031 | memset(&band_info, 0, sizeof(ril_band_info_t));
|
| 3032 | memset(&band_info.band_support, 0xFF, sizeof(mbtk_band_info_t));
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3033 | |
| 3034 | //check cfun and sim card status |
| 3035 | ril_at_ready_process(); |
b.liu | beb61cc | 2025-02-13 10:38:29 +0800 | [diff] [blame] | 3036 |
|
| 3037 | // Init support band.
|
| 3038 | band_support_init();
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3039 | |
| 3040 | //any AT instruction that is not sent through pack_process_thread needs to precede the thread |
| 3041 | //thread create |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3042 | if(ril_info.sock_listen_fd > 0)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3043 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3044 | LOGE("Information Server Has Started.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3045 | return -1; |
| 3046 | } |
| 3047 | |
| 3048 | struct sockaddr_un server_addr; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3049 | ril_info.sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
|
| 3050 | if(ril_info.sock_listen_fd < 0)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3051 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3052 | LOGE("socket() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3053 | return -1; |
| 3054 | } |
| 3055 | |
| 3056 | // Set O_NONBLOCK |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3057 | int flags = fcntl(ril_info.sock_listen_fd, F_GETFL, 0);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3058 | if (flags < 0) |
| 3059 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3060 | LOGE("Get flags error:%d", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3061 | goto error; |
| 3062 | } |
| 3063 | flags |= O_NONBLOCK; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3064 | if (fcntl(ril_info.sock_listen_fd, F_SETFL, flags) < 0)
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3065 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3066 | LOGE("Set flags error:%d", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3067 | goto error; |
| 3068 | } |
| 3069 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3070 | unlink(RIL_SOCK_NAME);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3071 | memset(&server_addr, 0, sizeof(struct sockaddr_un)); |
| 3072 | server_addr.sun_family = AF_LOCAL; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3073 | strcpy(server_addr.sun_path, RIL_SOCK_NAME);
|
| 3074 | 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] | 3075 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3076 | LOGE("bind() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3077 | goto error; |
| 3078 | } |
| 3079 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3080 | if(listen(ril_info.sock_listen_fd, SOCK_CLIENT_MAX))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3081 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3082 | LOGE("listen() fail[%d].", errno);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3083 | goto error; |
| 3084 | } |
| 3085 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3086 | ril_info.sock_client_list = list_create(sock_cli_free_func);
|
| 3087 | if(ril_info.sock_client_list == NULL)
|
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 | LOGE("list_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3090 | goto error; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3091 | }
|
| 3092 |
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3093 | mbtk_queue_init(&(ril_info.msg_queue[ATPORTTYPE_0]));
|
| 3094 | pthread_mutex_init(&(ril_info.msg_mutex[ATPORTTYPE_0]), NULL);
|
| 3095 | pthread_cond_init(&(ril_info.msg_cond[ATPORTTYPE_0]), NULL);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3096 | |
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 3097 | pthread_t info_pid, pack_pid/*, monitor_pid, urc_pid, bootconn_pid*/;
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3098 | pthread_attr_t thread_attr; |
| 3099 | pthread_attr_init(&thread_attr); |
| 3100 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 3101 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3102 | LOGE("pthread_attr_setdetachstate() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3103 | goto error; |
| 3104 | } |
| 3105 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3106 | if(pthread_create(&info_pid, &thread_attr, ril_read_pthread, NULL))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3107 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3108 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3109 | goto error; |
| 3110 | } |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3111 |
|
| 3112 | ATPortType_enum *port_0 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3113 | *port_0 = MBTK_AT_PORT_DEF;
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3114 | if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_0))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3115 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3116 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3117 | goto error; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3118 | }
|
| 3119 |
|
| 3120 | ATPortType_enum *port_1 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3121 | *port_1 = MBTK_AT_PORT_VOICE;
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3122 | if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_1))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3123 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3124 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3125 | goto error; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3126 | }
|
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 3127 |
|
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3128 | ATPortType_enum *port_2 = (ATPortType_enum*)malloc(sizeof(ATPortType_enum));
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3129 | *port_2 = MBTK_AT_PORT_DATA;
|
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3130 | if(pthread_create(&pack_pid, &thread_attr, ril_process_thread, port_2))
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3131 | { |
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3132 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3133 | goto error; |
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3134 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3135 | |
| 3136 | // Set Band |
| 3137 | // AT*BAND=15,78,147,482,134742231 |
| 3138 | char buff[10]; |
| 3139 | memset(buff, 0, 10); |
| 3140 | property_get("persist.mbtk.band_config", buff, ""); |
| 3141 | if(strlen(buff) == 0) { |
| 3142 | pthread_t band_pid; |
| 3143 | if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL)) |
| 3144 | { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3145 | LOGE("pthread_create() fail.");
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3146 | } |
| 3147 | } |
| 3148 | |
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 3149 | pthread_attr_destroy(&thread_attr);
|
| 3150 |
|
| 3151 | if(asr_auto_data_call_enable()) {
|
| 3152 | ril_cid_start = MBTK_RIL_CID_2;
|
| 3153 |
|
| 3154 | char def_cid[10] = {0};
|
| 3155 | char prop_data[100] = {0};
|
| 3156 | int cid = -1;
|
| 3157 | sprintf(def_cid, "%d", MBTK_RIL_CID_DEF); // Default route and DNS is CID 1.
|
| 3158 | memset(prop_data, 0, sizeof(prop_data));
|
| 3159 | if(property_get(MBTK_DEF_DNS_CID, prop_data, def_cid) > 0 && !str_empty(prop_data)) {
|
| 3160 | cid = atoi(prop_data);
|
| 3161 | }
|
| 3162 |
|
| 3163 | if(cid == MBTK_RIL_CID_DEF) {
|
| 3164 | if(file_link("/tmp/resolv.conf", "/etc/resolv.conf")) {
|
| 3165 | LOGE("Create link file fail.");
|
| 3166 | }
|
| 3167 | }
|
| 3168 | } else {
|
| 3169 | ril_cid_start = MBTK_RIL_CID_DEF;
|
| 3170 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3171 | |
b.liu | fd87baf | 2024-11-15 15:30:38 +0800 | [diff] [blame] | 3172 | LOGD("MBTK Ril Server Start[CID start with : %d]...", ril_cid_start);
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3173 | |
| 3174 | return 0; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3175 | error:
|
| 3176 | if(ril_info.sock_client_list) {
|
| 3177 | list_free(ril_info.sock_client_list);
|
| 3178 | ril_info.sock_client_list = NULL;
|
| 3179 | }
|
| 3180 |
|
| 3181 | if(ril_info.sock_listen_fd > 0) {
|
| 3182 | close(ril_info.sock_listen_fd);
|
| 3183 | ril_info.sock_listen_fd = -1;
|
| 3184 | }
|
b.liu | 571445f | 2025-02-13 10:22:55 +0800 | [diff] [blame] | 3185 | return -1; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3186 | }
|
| 3187 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3188 | int main(int argc, char *argv[])
|
| 3189 | {
|
| 3190 | mbtk_log_init("radio", "MBTK_RIL");
|
| 3191 |
|
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame] | 3192 | MBTK_SOURCE_INFO_PRINT("mbtk_rild");
|
| 3193 |
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3194 | #ifdef MBTK_DUMP_SUPPORT
|
| 3195 | mbtk_debug_open(NULL, TRUE);
|
| 3196 | #endif
|
| 3197 |
|
| 3198 | // Using Killall,the file lock may be not release.
|
| 3199 | #if 0
|
| 3200 | if(app_already_running(MBTK_RILD_PID_FILE)) {
|
| 3201 | LOGW("daemon already running.");
|
| 3202 | exit(1);
|
| 3203 | }
|
| 3204 | #endif
|
| 3205 |
|
| 3206 | LOGI("mbtk_rild start.");
|
| 3207 |
|
| 3208 | if(InProduction_Mode()) {
|
| 3209 | LOGI("Is Production Mode, will exit...");
|
| 3210 | exit(0);
|
| 3211 | }
|
| 3212 |
|
| 3213 | ready_state_update();
|
| 3214 |
|
| 3215 | int at_sock = openSocket("/tmp/atcmd_at");
|
| 3216 | if(at_sock < 0)
|
| 3217 | {
|
| 3218 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3219 | return -1;
|
| 3220 | }
|
| 3221 | int uart_sock = openSocket("/tmp/atcmd_urc");
|
| 3222 | if(uart_sock < 0)
|
| 3223 | {
|
| 3224 | LOGE("Open Uart Socket Fail[%d].", errno);
|
| 3225 | return -1;
|
| 3226 | }
|
| 3227 |
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3228 | int at_sock_1 = openSocket("/tmp/atcmd_at_1");
|
| 3229 | if(at_sock_1 < 0)
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3230 | {
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3231 | LOGE("Open AT Socket Fail[%d].", errno);
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3232 | return -1;
|
| 3233 | }
|
| 3234 |
|
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3235 | int at_sock_2 = openSocket("/tmp/atcmd_at_2");
|
| 3236 | if(at_sock_2 < 0)
|
| 3237 | {
|
| 3238 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3239 | return -1;
|
| 3240 | }
|
| 3241 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3242 | int uart_sock1 = openSocket("/tmp/atcmd_urc1");
|
| 3243 | if(uart_sock1 < 0)
|
| 3244 | {
|
| 3245 | LOGE("Open Uart Socket Fail[%d].", errno);
|
| 3246 | return -1;
|
| 3247 | }
|
| 3248 |
|
| 3249 | int at_sock1 = openSocket("/tmp/atcmd_at1");
|
| 3250 | if(at_sock1 < 0)
|
| 3251 | {
|
| 3252 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3253 | return -1;
|
| 3254 | }
|
| 3255 |
|
| 3256 | int at_sock1_1 = openSocket("/tmp/atcmd_at1_1");
|
| 3257 | if(at_sock1_1 < 0)
|
| 3258 | {
|
| 3259 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3260 | return -1;
|
| 3261 | }
|
| 3262 |
|
| 3263 | int at_sock1_2 = openSocket("/tmp/atcmd_at1_2");
|
| 3264 | if(at_sock1_2 < 0)
|
| 3265 | {
|
| 3266 | LOGE("Open AT Socket Fail[%d].", errno);
|
| 3267 | return -1;
|
| 3268 | }
|
| 3269 |
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3270 | at_set_on_reader_closed(onATReaderClosed);
|
| 3271 | at_set_on_timeout(onATTimeout);
|
| 3272 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3273 | if(at_open(ATPORTID_SIM1_0, at_sock, uart_sock, onUnsolicited1))
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3274 | {
|
| 3275 | LOGE("Start AT_0 thread fail.");
|
| 3276 | return -1;
|
| 3277 | }
|
| 3278 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3279 | if(at_open(ATPORTID_SIM1_1, at_sock_1, uart_sock, onUnsolicited1))
|
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 3280 | {
|
| 3281 | LOGE("Start AT_1 thread fail.");
|
| 3282 | return -1;
|
| 3283 | }
|
| 3284 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3285 | if(at_open(ATPORTID_SIM1_2, at_sock_2, uart_sock, onUnsolicited1))
|
b.liu | 61eedc9 | 2024-11-13 16:07:00 +0800 | [diff] [blame] | 3286 | {
|
| 3287 | LOGE("Start AT_1 thread fail.");
|
| 3288 | return -1;
|
| 3289 | }
|
| 3290 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3291 | if(at_handshake(ATPORTID_SIM1_0))
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3292 | {
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3293 | LOGE("SIM1 AT handshake fail.");
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3294 | return -1;
|
| 3295 | }
|
| 3296 |
|
b.liu | 7ca612c | 2025-04-25 09:23:36 +0800 | [diff] [blame^] | 3297 | LOGD("SIM1 AT OK.");
|
| 3298 |
|
| 3299 | if(at_open(ATPORTID_SIM2_0, at_sock1, uart_sock1, onUnsolicited2))
|
| 3300 | {
|
| 3301 | LOGE("Start AT_0 thread fail.");
|
| 3302 | return -1;
|
| 3303 | }
|
| 3304 |
|
| 3305 | if(at_open(ATPORTID_SIM2_1, at_sock1_1, uart_sock1, onUnsolicited2))
|
| 3306 | {
|
| 3307 | LOGE("Start AT_1 thread fail.");
|
| 3308 | return -1;
|
| 3309 | }
|
| 3310 |
|
| 3311 | if(at_open(ATPORTID_SIM2_2, at_sock1_2, uart_sock1, onUnsolicited2))
|
| 3312 | {
|
| 3313 | LOGE("Start AT_1 thread fail.");
|
| 3314 | return -1;
|
| 3315 | }
|
| 3316 |
|
| 3317 | if(at_handshake(ATPORTID_SIM2_0))
|
| 3318 | {
|
| 3319 | LOGE("SIM2 AT handshake fail.");
|
| 3320 | return -1;
|
| 3321 | }
|
| 3322 |
|
| 3323 | LOGD("SIM2 AT OK.");
|
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 3324 |
|
| 3325 | if(ril_server_start())
|
| 3326 | {
|
| 3327 | LOGE("ril_server_start() fail.");
|
| 3328 | return -1;
|
| 3329 | }
|
| 3330 |
|
| 3331 | mbtk_ril_ready();
|
| 3332 |
|
| 3333 | while(1)
|
| 3334 | {
|
| 3335 | sleep(24 * 60 * 60);
|
| 3336 | }
|
| 3337 |
|
| 3338 | LOGD("!!!mbtk_ril exit!!!");
|
| 3339 | return 0;
|
| 3340 | }
|