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