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