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