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