blob: d582fb4c2a0da4cfcd5560b7b88b36ca2a01d206 [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <errno.h>
5#include <sys/socket.h>
6#include <sys/un.h>
7#include <netinet/in.h>
8#include <pthread.h>
9#include <sys/epoll.h>
10#include <fcntl.h>
11#include <signal.h>
12#include <cutils/properties.h>
13
14#include "mbtk_type.h"
15#include "mbtk_info.h"
16#include "mbtk_queue.h"
17#include "atchannel.h"
18#include "at_tok.h"
19#include "mbtk_utils.h"
20#include "mbtk_ifc.h"
21#include "info_data.h"
wangyouqiang38e53362024-01-23 10:53:48 +080022#include "mbtk_led.h"
b.liue0ab2442024-02-06 18:53:28 +080023#include "cust_info.h"
b.liubb5e7682024-02-28 20:13:04 +080024#include "mbtk_device.h"
wangyouqiang80487e42024-05-24 15:06:20 +080025#include "mbtk_data_call.h"
liubin281ac462023-07-19 14:22:54 +080026
b.liuf37bd332024-03-18 13:51:24 +080027typedef struct {
b.liuf37bd332024-03-18 13:51:24 +080028 uint32 band_gsm;
29 uint32 band_wcdma;
30 uint32 band_tdlte;
31 uint32 band_fddlte;
b.liuf678f992024-05-08 15:23:10 +080032 uint32 band_lte_ext;
b.liuf37bd332024-03-18 13:51:24 +080033} band_set_info_t;
34
liubin281ac462023-07-19 14:22:54 +080035static int sock_listen_fd = -1;
36static int epoll_fd = -1;
37static list_node_t *sock_client_list = NULL;
38static mbtk_queue_node_t info_queue;
39static pthread_cond_t info_cond;
40static pthread_mutex_t info_mutex;
41static mbtk_queue_node_t urc_queue;
42static pthread_cond_t urc_cond;
43static pthread_mutex_t urc_mutex;
b.liuf37bd332024-03-18 13:51:24 +080044static band_set_info_t band_set_info;
b.liu288093c2024-05-09 17:02:57 +080045static bool band_set_success = FALSE;
46static mbtk_modem_band_area_enum band_area;
liubin281ac462023-07-19 14:22:54 +080047
48static mbtk_band_info_t band_support;
49net_info_t net_info;
50mbtK_cell_pack_info_t cell_info;
51info_cgact_wait_t cgact_wait;
52static int cid_active[MBTK_APN_CID_MAX + 1] = {0};
53bool at_process = false;
yq.wangd58f71e2024-08-21 23:45:31 -070054bool at_cfun_command = false;
liubin281ac462023-07-19 14:22:54 +080055//mbtk wyq for data_call_ex add start
56// |2----7|
57//"00000000"+'\0'
58static char cid_bootconn[MBTK_APN_CID_MAX + 2] = {0};
59#define DATA_CALL_BOOTCONN_FD 0x5f6f7f8f
60//mbtk wyq for data_call_ex add end
61
62//mbtk wyq for server_ready_status add start
63static char server_ready_status = 0;
64//mbtk wyq for server_ready_status add end
65
r.xiaofca7c472024-04-24 01:00:23 -070066static mbtk_signal_info_t signal_globe;
67
r.xiaoec113d12024-01-12 02:13:28 -080068
69/*
70AT*POWERIND=0"
71or
72AT*POWERIND=1~31"
73
74OK
75
76AT*POWERIND=31,就相当于设置NETWORK、SIM、SMS、CS CALL、PS DATA变化时都不主动上报,
77其中PS DATA目前暂时不支持,只是保留了这个标志位,0 means resume all.
78
79AP power state: 1~31 means suspend,
80bitmap:
81bit0 - NETWORK;
82bit1 - SIM;
83bit2 - SMS;
84bit3 - CS CALL
85bit4 - PS DATA
86
87*/
88static int req_powerind_set(uint32 state, int *cme_err)
89{
90 ATResponse *response = NULL;
91 char cmd[100] = {0};
92
93 if (state >= 0 && state < 32)
94 {
95 sprintf(cmd, "AT*POWERIND=%d", state);
r.xiaocfd7c682024-01-22 03:59:46 -080096 LOG("Set the powerind command is = [%s]\n", cmd);
r.xiaoec113d12024-01-12 02:13:28 -080097 }
98 int err = at_send_command(cmd, &response);
99 if (err < 0 || response->success == 0){
100 *cme_err = at_get_cme_error(response);
101 goto exit;
102 }
103
104exit:
105 at_response_free(response);
106 return err;
107}
108
109/*
r.xiaocfd7c682024-01-22 03:59:46 -0800110AT+OOSPP=1
111or
112AT+OOSPP=0
113or
r.xiaoec113d12024-01-12 02:13:28 -0800114AT+OOSPP=1,20,30,40 //AtOospp()
115 param1:mode
116 param2:oosPhasePeriod[0] //5 times, 5s by default;
r.xiaocfd7c682024-01-22 03:59:46 -0800117 param3:oosPhasePeriod[1] //5 times, 10s by default;
118 param4:oosPhasePeriod[2] //unlimited, 20s by default;
r.xiaoec113d12024-01-12 02:13:28 -0800119
120
121BTW
1221, 如果只输入mode=1,其余参数不设置,相当于这个功能打开,时间间隔是这个功能的默认值。
1232, 如果当mode=1加上其余设置参数后,功能打开,时间间隔是本次设置的值;
r.xiaocfd7c682024-01-22 03:59:46 -08001243,如果再设置mode=0,相当于这个功能关闭,是走平台自己另一套的搜网设置。
125平台本身是有一套间隔搜网,也有历史频点优先处理的逻辑(不需要我们进行处理),
126提供给我们的AT+OOSPP指令是让我们可以自定义搜网间隔
r.xiaoec113d12024-01-12 02:13:28 -0800127*/
r.xiaocfd7c682024-01-22 03:59:46 -0800128static int req_oos_set(mbtk_oos_info* state, int *cme_err)
r.xiaoec113d12024-01-12 02:13:28 -0800129{
130 ATResponse *response = NULL;
131 char cmd[100] = {0};
r.xiaoec113d12024-01-12 02:13:28 -0800132
r.xiaocfd7c682024-01-22 03:59:46 -0800133 if ((state->mode == 1 && state->oosPhase[0] == 0 && state->oosPhase[1] == 0 && state->oosPhase[2] == 0) \
134 || state->mode == 0)
r.xiaoec113d12024-01-12 02:13:28 -0800135 {
r.xiaocfd7c682024-01-22 03:59:46 -0800136 sprintf(cmd, "AT+OOSPP=%d", state->mode);//只有一个值0/1
r.xiaoec113d12024-01-12 02:13:28 -0800137 }
138 else
139 {
r.xiaocfd7c682024-01-22 03:59:46 -0800140 if ((state->oosPhase[0] != 0) && (state->oosPhase[1] != 0) && (state->oosPhase[2] != 0))
141 {
142 sprintf(cmd, "AT+OOSPP=%d,%d,%d,%d", state->mode, state->oosPhase[0], state->oosPhase[1], state->oosPhase[2]);
143 }
144 else if ((state->oosPhase[0] != 0) && (state->oosPhase[1] != 0) && (state->oosPhase[2] == 0))
145 {
146 sprintf(cmd, "AT+OOSPP=%d,%d,%d", state->mode, state->oosPhase[0], state->oosPhase[1]);
147 }
148 else if ((state->oosPhase[0] != 0) && (state->oosPhase[1] == 0) && (state->oosPhase[2] == 0))
149 {
150 sprintf(cmd, "AT+OOSPP=%d,%d", state->mode, state->oosPhase[0]);
151 }
152 else
153 {
154 LOG("AT+OOSPP SET ERR");
155 goto exit;
156 }
r.xiaoec113d12024-01-12 02:13:28 -0800157 }
158
r.xiaocfd7c682024-01-22 03:59:46 -0800159 LOG("Set the oos command is = [%s]\n", cmd);
r.xiaoec113d12024-01-12 02:13:28 -0800160 int err = at_send_command(cmd, &response);
161 if (err < 0 || response->success == 0){
162 *cme_err = at_get_cme_error(response);
163 goto exit;
164 }
165
166exit:
167 at_response_free(response);
168 return err;
169}
170
171
172/*
173AT+OOSPP?
r.xiaocfd7c682024-01-22 03:59:46 -0800174开(默认值):
175+OOSPP:5,10,20
r.xiaoec113d12024-01-12 02:13:28 -0800176关:
177+OOSPP:0
178*/
179static int req_oos_get(mbtk_oos_info *req, int *cme_err)
180{
181 ATResponse *response = NULL;
182
r.xiaocfd7c682024-01-22 03:59:46 -0800183 int err = at_send_command_singleline("AT+OOSPP?", "+OOSPP:", &response);
r.xiaoec113d12024-01-12 02:13:28 -0800184
185 if (err < 0 || response->success == 0 || !response->p_intermediates){
186 *cme_err = at_get_cme_error(response);
187 goto exit;
188 }
189
190 char *line = response->p_intermediates->line;
191
192 char *tmp_str = NULL;
r.xiaocfd7c682024-01-22 03:59:46 -0800193 err = at_tok_start(&line);//+OOSPP:10,15,20,过滤+OOSPP:
194 if (err < 0)
195 {
196 goto exit;
197 }
198
199 //LOG("req_oos_get =[%s]",line);
200
r.xiaoec113d12024-01-12 02:13:28 -0800201 err = at_tok_nextstr(&line, &tmp_str);
202 if (err < 0)
203 {
204 goto exit;
205 }
206
r.xiaoec113d12024-01-12 02:13:28 -0800207 int mode = atoi(tmp_str);
208 if (mode == 0)//关闭状态
209 {
r.xiaocfd7c682024-01-22 03:59:46 -0800210 req->mode = mode;
r.xiaoec113d12024-01-12 02:13:28 -0800211 }
212 else//开状态
213 {
214 req->mode = 1;
r.xiaocfd7c682024-01-22 03:59:46 -0800215 //LOG("tmp_str =[%s]",tmp_str);
216 req->oosPhase[0] = atoi(tmp_str);
b.liufe320632024-01-17 20:38:08 +0800217
r.xiaoec113d12024-01-12 02:13:28 -0800218 err = at_tok_nextstr(&line, &tmp_str);
219 if (err < 0)
220 {
221 goto exit;
222 }
r.xiaocfd7c682024-01-22 03:59:46 -0800223 //LOG("tmp_str =[%s]",tmp_str);
224 req->oosPhase[1] = atoi(tmp_str);
r.xiaoec113d12024-01-12 02:13:28 -0800225
226 err = at_tok_nextstr(&line, &tmp_str);
227 if (err < 0)
228 {
229 goto exit;
230 }
r.xiaocfd7c682024-01-22 03:59:46 -0800231 //LOG("tmp_str =[%s]",tmp_str);
232 req->oosPhase[2] = atoi(tmp_str);
r.xiaoec113d12024-01-12 02:13:28 -0800233 }
234
r.xiaoec113d12024-01-12 02:13:28 -0800235exit:
236 at_response_free(response);
237 return err;
238}
239
liubin281ac462023-07-19 14:22:54 +0800240static void sock_cli_free_func(void *data)
241{
242 if (data)
243 {
244 sock_client_info_t *info = (sock_client_info_t*) data;
245 LOG("Free Socket client[fd = %d].", info->fd);
246 free(info);
247 }
248}
249
250static void cli_close(sock_client_info_t* client)
251{
252 struct epoll_event ev;
253 memset(&ev,0,sizeof(struct epoll_event));
254 ev.data.fd = client->fd;
255 ev.events = EPOLLIN | EPOLLERR | EPOLLET;
256 epoll_ctl(epoll_fd, EPOLL_CTL_DEL, client->fd, &ev);
257
258 close(client->fd);
259
260 if(list_remove(sock_client_list, client))
261 {
262 sock_cli_free_func(client);
263 }
264}
265
266static void pack_error_send(int fd, int info_id, int err)
267{
268 mbtk_info_pack_t* pack = mbtk_info_pack_creat(info_id);
269 if(pack)
270 {
271 pack->info_err = (uint16)err;
272 mbtk_info_pack_send(fd, pack);
273 mbtk_info_pack_free(&pack);
274 }
275 else
276 {
277 LOG("mbtk_info_pack_creat() fail.");
278 }
279}
280
281void pack_rsp_send(int fd, int info_id, const void* data, int data_len)
282{
283 mbtk_info_pack_t* pack = mbtk_info_pack_creat(info_id);
284 if(pack)
285 {
286 pack->info_err = (uint16)MBTK_INFO_ERR_SUCCESS;
287 if(data != NULL && data_len > 0)
288 {
289 //mbtk_info_pack_data_set(pack, data, data_len);
290 pack->data_len = (uint16)data_len;
291 pack->data = (const uint8*)data;
292 }
293 mbtk_info_pack_send(fd, pack);
294 mbtk_info_pack_free(&pack);
295 }
296 else
297 {
298 LOG("mbtk_info_pack_creat() fail.");
299 }
300}
301
302static int apn_prop_set(mbtk_apn_info_t *apn)
303{
304 char prop_name[20] = {0};
305 char prop_data[300] = {0};
306 sprintf(prop_name, "%s_%d",MBTK_APN_PROP,apn->cid);
307 snprintf(prop_data, 300, "%d,%s,%s,%s,%s", apn->ip_type, apn->apn,
308 str_empty(apn->user) ? "NULL" : apn->user,
309 str_empty(apn->pass) ? "NULL" : apn->pass,
310 str_empty(apn->auth) ? "NULL" : apn->auth);
311
312 return property_set(prop_name, prop_data);
313}
314
315/*
316AT*BAND=?
317*BAND:(0-18),79,147,482,524503
318
319
320OK
321
322AT*BAND=15,78,147,482,134742231
323
324
325*/
326static void band_support_get()
327{
328 // Support band has get.
329 if(band_support.net_pref != 0xFF) {
330 return;
331 }
332
333#if 1
334 // 79,147,482,524503
b.liu288093c2024-05-09 17:02:57 +0800335 band_support.gsm_band = (uint16)79; // GSM : B2/B3/B5/B8(GSM 850/PGSM 900/EGSM 900/DCS GSM 1800/PCS GSM 1900)
336 band_support.umts_band = (uint16)155; // WCDMA : B1/B2/B4/B5/B8
337 band_support.tdlte_band = (uint32)482; // TDD-LTE : B34/B38/B39/B40/B41
338 band_support.fddlte_band = (uint32)134742239; // FDD-LTE : B1/B2/B3/B4/B5/B7/B8/B20/B28
339 band_support.lte_ext_band = (uint32)2; // B66
liubin281ac462023-07-19 14:22:54 +0800340 band_support.net_pref = (uint8)0;
341#else
342 ATResponse *response = NULL;
343 int tmp_int;
344 char *tmp_str;
345 int err = at_send_command_singleline("AT*BAND=?", "*BAND:", &response);
346
347 if (err < 0 || response->success == 0 || !response->p_intermediates)
348 goto exit;
349
350 char *line = response->p_intermediates->line;
351 err = at_tok_start(&line);
352 if (err < 0)
353 {
354 goto exit;
355 }
356
357 err = at_tok_nextstr(&line, &tmp_str);
358 if (err < 0)
359 {
360 goto exit;
361 }
362
363 err = at_tok_nextint(&line, &tmp_int);
364 if (err < 0)
365 {
366 goto exit;
367 }
368 band_support.gsm_band = (uint16)tmp_int;
369
370 err = at_tok_nextint(&line, &tmp_int);
371 if (err < 0)
372 {
373 goto exit;
374 }
375 band_support.umts_band = (uint16)tmp_int;
376
377 err = at_tok_nextint(&line, &tmp_int);
378 if (err < 0)
379 {
380 goto exit;
381 }
382 band_support.tdlte_band = (uint32)tmp_int;
383
384 err = at_tok_nextint(&line, &tmp_int);
385 if (err < 0)
386 {
387 goto exit;
388 }
389 band_support.fddlte_band = (uint32)tmp_int;
390 band_support.net_pref = (uint8)0;
391exit:
392 at_response_free(response);
393#endif
394}
395
396static int parseRegistrationState(char *str, int *items, int **response)
397{
398 int err;
399 char *line = str, *p;
400 int *resp = NULL;
401 int skip;
402 int commas;
403
404 LOGD("parseRegistrationState. Parsing: %s",str);
405 err = at_tok_start(&line);
406 if (err < 0) goto error;
407
408 /* Ok you have to be careful here
409 * The solicited version of the CREG response is
410 * +CREG: n, stat, [lac, cid]
411 * and the unsolicited version is
412 * +CREG: stat, [lac, cid]
413 * The <n> parameter is basically "is unsolicited creg on?"
414 * which it should always be
415 *
416 * Now we should normally get the solicited version here,
417 * but the unsolicited version could have snuck in
418 * so we have to handle both
419 *
420 * Also since the LAC and CID are only reported when registered,
421 * we can have 1, 2, 3, or 4 arguments here
422 *
423 * finally, a +CGREG: answer may have a fifth value that corresponds
424 * to the network type, as in;
425 *
426 * +CGREG: n, stat [,lac, cid [,networkType]]
427 */
428
429 /* count number of commas */
430 commas = 0;
431 for (p = line ; *p != '\0' ; p++)
432 {
433 if (*p == ',') commas++;
434 }
435
436 resp = (int *)calloc(commas + 1, sizeof(int));
437 if (!resp) goto error;
438 switch (commas)
439 {
440 case 0: /* +CREG: <stat> */
441 err = at_tok_nextint(&line, &resp[0]);
442 if (err < 0) goto error;
443 //resp[1] = -1;
444 //resp[2] = -1;
445 break;
446
447 case 1: /* +CREG: <n>, <stat> */
448 err = at_tok_nextint(&line, &skip);
449 if (err < 0) goto error;
450 err = at_tok_nextint(&line, &resp[0]);
451 if (err < 0) goto error;
452 resp[1] = -1;
453 //resp[2] = -1;
454 if (err < 0) goto error;
455 break;
456
457 case 2: /* +CREG: <stat>, <lac>, <cid> */
458 err = at_tok_nextint(&line, &resp[0]);
459 if (err < 0) goto error;
460 err = at_tok_nexthexint(&line, &resp[1]);
461 if (err < 0) goto error;
462 err = at_tok_nexthexint(&line, &resp[2]);
463 if (err < 0) goto error;
464 break;
465 case 3: /* +CREG: <n>, <stat>, <lac>, <cid> */
466 /* +CEREG: 1,"8330","06447340",7 */
467#if 0
468 err = at_tok_nextint(&line, &skip);
469 if (err < 0) goto error;
470 err = at_tok_nextint(&line, &resp[0]);
471 if (err < 0) goto error;
472 err = at_tok_nexthexint(&line, &resp[1]);
473 if (err < 0) goto error;
474 err = at_tok_nexthexint(&line, &resp[2]);
475 if (err < 0) goto error;
476#else
477 err = at_tok_nextint(&line, &resp[0]);
478 if (err < 0) goto error;
479 err = at_tok_nextint(&line, &resp[1]);
480 if (err < 0) goto error;
481 err = at_tok_nexthexint(&line, &resp[2]);
482 if (err < 0) goto error;
483 err = at_tok_nextint(&line, &resp[3]);
484 if (err < 0) goto error;
485#endif
486 break;
487 /* special case for CGREG, there is a fourth parameter
488 * that is the network type (unknown/gprs/edge/umts)
489 */
490 case 4: /* +CGREG: <n>, <stat>, <lac>, <cid>, <networkType> */
491 /* +CEREG: 2,1,"8330","06447340",7 */
492 err = at_tok_nextint(&line, &skip);
493 if (err < 0) goto error;
494 err = at_tok_nextint(&line, &resp[0]);
495 if (err < 0) goto error;
496 err = at_tok_nexthexint(&line, &resp[1]);
497 if (err < 0) goto error;
498 err = at_tok_nexthexint(&line, &resp[2]);
499 if (err < 0) goto error;
500 err = at_tok_nexthexint(&line, &resp[3]);
501 if (err < 0) goto error;
502 break;
503 default:
504 goto error;
505 }
506 /*
507 if(commas > 1) {
508 s_lac = resp[1];
509 s_cid = resp[2];
510 }*/
511 if (response)
512 *response = resp;
513 if (items)
514 *items = commas + 1;
515 return 0;
516error:
517 free(resp);
518 return -1;
519}
520
521/*
5220: minimum functionality
5231: full functionality
5243: disable phone receive RF circuits.
5254: disable phone both transmit and receive RF circuits
5265: disable SIM
5276: turn off full secondary receive.
528-1: fail
529*/
530static int isRadioOn()
531{
532 ATResponse *p_response = NULL;
533 int err;
534 char *line;
535 int ret;
536
537 err = at_send_command_singleline("AT+CFUN?", "+CFUN:", &p_response);
538
539 if (err < 0 || p_response->success == 0 || !p_response->p_intermediates)
540 {
541 // assume radio is off
542 goto error;
543 }
544
545 line = p_response->p_intermediates->line;
546
547 err = at_tok_start(&line);
548 if (err < 0) goto error;
549
550 err = at_tok_nextint(&line, &ret);
551 if (err < 0) goto error;
552
553 at_response_free(p_response);
554
555 if(ret == 1) {
556 net_info.radio_state = MBTK_RADIO_STATE_ON;
557 } else {
558 net_info.radio_state = MBTK_RADIO_STATE_OFF;
559 }
560
561 return ret;
562
563error:
564
565 at_response_free(p_response);
566 return -1;
567}
568
569/** Returns SIM_NOT_READY on error */
570static mbtk_sim_state_enum getSIMStatus()
571{
572 ATResponse *p_response = NULL;
573 int err;
574 mbtk_sim_state_enum ret;
575 char *cpinLine;
576 char *cpinResult;
577
578 err = at_send_command_singleline("AT+CPIN?", "+CPIN:", &p_response);
579
580 if (err < 0 || p_response->success == 0 || !p_response->p_intermediates)
581 {
yq.wang586a0df2024-10-24 20:10:37 -0700582 switch (at_get_cme_error(p_response))
583 {
584 case CME_SUCCESS:
585 break;
586
587 case CME_SIM_NOT_INSERTED:
588 case 13: //sim fail,as "sim absent"
589 ret = MBTK_SIM_ABSENT;
590 goto done;
591
592 default:
593 ret = MBTK_SIM_NOT_READY;
594 goto done;
595 }
liubin281ac462023-07-19 14:22:54 +0800596 ret = MBTK_SIM_NOT_READY;
597 goto done;
598 }
yq.wang586a0df2024-10-24 20:10:37 -0700599
liubin281ac462023-07-19 14:22:54 +0800600 /* CPIN? has succeeded, now look at the result */
601
602 cpinLine = p_response->p_intermediates->line;
603 err = at_tok_start (&cpinLine);
604
605 if (err < 0)
606 {
607 ret = MBTK_SIM_NOT_READY;
608 goto done;
609 }
610
611 err = at_tok_nextstr(&cpinLine, &cpinResult);
612
613 if (err < 0)
614 {
615 ret = MBTK_SIM_NOT_READY;
616 goto done;
617 }
618
619 if (0 == strcmp (cpinResult, "SIM PIN"))
620 {
621 ret = MBTK_SIM_PIN;
622 goto done;
623 }
624 else if (0 == strcmp (cpinResult, "SIM PUK"))
625 {
626 ret = MBTK_SIM_PUK;
627 goto done;
628 }
629 else if (0 == strcmp (cpinResult, "PH-NET PIN"))
630 {
631 return MBTK_SIM_NETWORK_PERSONALIZATION;
632 }
633 else if (0 != strcmp (cpinResult, "READY"))
634 {
635 /* we're treating unsupported lock types as "sim absent" */
636 ret = MBTK_SIM_ABSENT;
637 goto done;
638 }
639
640 at_response_free(p_response);
641 p_response = NULL;
642 cpinResult = NULL;
643
644 // ret = net_info.radio_state == MBTK_RADIO_STATE_ON ? MBTK_SIM_READY : MBTK_SIM_NOT_READY;
645 net_info.sim_state = MBTK_SIM_READY;
646 return MBTK_SIM_READY;
647done:
648 at_response_free(p_response);
649 net_info.sim_state = ret;
650 return ret;
651}
652
653void setRadioPower(int isOn)
654{
655 int err;
656 ATResponse *p_response = NULL;
657
658 LOGI("RadioPower - %s", isOn == 0 ? "OFF" : "ON");
659
660 if(isOn == 0 && net_info.radio_state == MBTK_RADIO_STATE_ON)
661 {
662 err = at_send_command("AT+CFUN=0", &p_response);
663 if (err || !p_response->success)
664 goto error;
665
666 net_info.radio_state = MBTK_RADIO_STATE_OFF;
667 }
668 else if(isOn && net_info.radio_state != MBTK_RADIO_STATE_ON)
669 {
670 err = at_send_command("AT+CFUN=1", &p_response);
671 if (err || !p_response->success)
672 {
673 if(isRadioOn() == 1)
674 {
675 net_info.radio_state = MBTK_RADIO_STATE_ON;
676 }
677 goto error;
678 }
679
680 net_info.radio_state = MBTK_RADIO_STATE_ON;
681 }
682
683 at_response_free(p_response);
684 return;
685error:
686 at_response_free(p_response);
687}
688
689static int apn_user_pass_set_by_cid(int cid, mbtk_apn_info_t *apn)
690{
691 char prop_name[20] = {0};
692 char prop_data[300] = {0};
693 sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid);
694 if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) {
695 char apn_name[128] = {0};
696 char *ptr_1 = prop_data;
697 mbtk_ip_type_enum ip_type = (mbtk_ip_type_enum)atoi(ptr_1);
698 ptr_1 = strstr(ptr_1, ",");
699 if(!ptr_1) {
700 return -1;
701 }
702 ptr_1++; // Jump ',' to apn
703
704 char *ptr_2 = strstr(ptr_1, ",");
705 if(!ptr_2) {
706 return -1;
707 }
708 memcpy(apn_name, ptr_1, ptr_2 - ptr_1); // apn
709
710 // Check ip_type and apn_name
711 if(ip_type != apn->ip_type || strcmp(apn_name, apn->apn)) {
712 LOGD("APN Changed, not get user/pass/auth.");
713 return -1;
714 }
715
716 ptr_2++; // Jump ',' to user
717 ptr_1 = strstr(ptr_2, ",");
718 if(!ptr_1) {
719 return -1;
720 }
721 if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
722 memcpy(apn->user, ptr_2, ptr_1 - ptr_2); // user
723 }
724
725 ptr_1++; // Jump ',' to pass
726 ptr_2 = strstr(ptr_1, ",");
727 if(!ptr_2) {
728 return -1;
729 }
730 if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
731 memcpy(apn->pass, ptr_1, ptr_2 - ptr_1); // pass
732 }
733
734 ptr_2++; // Jump ',' to auth (Is last item)
735 if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
736 memcpy(apn->auth, ptr_2, strlen(ptr_2)); // auth
737 }
738
739 return 0;
740 }
741 return -1;
742}
743
744
745/*
746AT+CPOL?
747*EUICC: 1
748
749OK
750*/
751static int req_plmn_get(mbtk_plmn_info *type, int *cme_err)
752{
753 ATResponse *response = NULL;
754 char *tmp_ptr = NULL;
755 int err = at_send_command_multiline("AT+CPOL?", "+CPOL:", &response);
756
757 if (err < 0 || response->success == 0 || !response->p_intermediates){
758 *cme_err = at_get_cme_error(response);
759 goto exit;
760 }
761
762 int mccmnc_type = -1;
763 int count = -1;
764 char *mccmnc_name = NULL;
765 ATLine* lines_ptr = response->p_intermediates;
766 char *line = NULL;
767 while(lines_ptr)
768 {
769 line = lines_ptr->line;
770 //if(strStartsWith(line, "+CPOL:"))
771 {
772 err = at_tok_start(&line);
773 if (err < 0)
774 {
775 goto exit;
776 }
777 err = at_tok_nextint(&line, &count);
778 if (err < 0)
779 {
780 goto exit;
781 }
782 type->count = count;
783
784 err = at_tok_nextint(&line, &mccmnc_type);
785 if (err < 0)
786 {
787 goto exit;
788 }
789 type->mbtk_plmn_name[count-1].format = mccmnc_type;
790
791 err = at_tok_nextstr(&line, &mccmnc_name);
792 if (err < 0)
793 {
794 goto exit;
795 }
796 memcpy(type->mbtk_plmn_name[count-1].plmn_name, mccmnc_name, strlen(mccmnc_name));
797 mccmnc_name = NULL;
798 }
799 lines_ptr = lines_ptr->p_next;
800 }
801
802exit:
803 at_response_free(response);
804 return err;
805}
806
807
808/*
809AT*EUICC?
810*EUICC: 1
811
812OK
813*/
814static int req_sim_card_type_get(uint8 *type, int *cme_err)
815{
816 ATResponse *response = NULL;
817 char *tmp_ptr = NULL;
818 int err = at_send_command_singleline("AT*EUICC?", "*EUICC:", &response);
819
820 if (err < 0 || response->success == 0 || !response->p_intermediates){
821 *cme_err = at_get_cme_error(response);
822 goto exit;
823 }
824
825 char *line = response->p_intermediates->line;
826 err = at_tok_start(&line);
827 if (err < 0)
828 {
829 goto exit;
830 }
831 int sim_card_type = -1;
832 err = at_tok_nextint(&line, &sim_card_type);
833 if (err < 0)
834 {
835 goto exit;
836 }
837 if(sim_card_type != -1)
838 *type = sim_card_type;
839 goto exit;
840exit:
841 at_response_free(response);
842 return err;
843}
844
845/*
846AT+EPIN?
847+EPIN: 3,0,10,0
848
849OK
850*/
851static int req_pin_puk_last_times_get(mbtk_pin_puk_last_times *times, int *cme_err)
852{
853 ATResponse *response = NULL;
854 char *tmp_ptr = NULL;
855 int err = at_send_command_singleline("AT+EPIN?", "+EPIN:", &response);
856
857 if (err < 0 || response->success == 0 || !response->p_intermediates){
858 *cme_err = at_get_cme_error(response);
859 goto exit;
860 }
861
862 char *line = response->p_intermediates->line;
863 err = at_tok_start(&line);
864 if (err < 0)
865 {
866 goto exit;
867 }
868 mbtk_pin_puk_last_times last_times={0};
869 err = at_tok_nextint(&line, &(last_times.p1_retry));
870 if (err < 0)
871 {
872 goto exit;
873 }
874 times->p1_retry = last_times.p1_retry;
875 err = at_tok_nextint(&line, &(last_times.p2_retry));
876 if (err < 0)
877 {
878 goto exit;
879 }
880 times->p2_retry = last_times.p2_retry;
881 err = at_tok_nextint(&line, &(last_times.puk1_retry));
882 if (err < 0)
883 {
884 goto exit;
885 }
886 times->puk1_retry = last_times.puk1_retry;
887 err = at_tok_nextint(&line, &(last_times.puk2_retry));
888 if (err < 0)
889 {
890 goto exit;
891 }
892 times->puk2_retry = last_times.puk2_retry;
893
894exit:
895 at_response_free(response);
896 return err;
897}
898
899
900/*
901AT+CGSN
902864788050901201
903
904OK
905*/
906static int req_imei_get(void *data, int *cme_err)
907{
908 ATResponse *response = NULL;
909 int err = at_send_command_numeric("AT+CGSN", &response);
910
911 if (err < 0 || response->success == 0 || !response->p_intermediates) {
912 *cme_err = at_get_cme_error(response);
913 goto exit;
914 }
915
916 memcpy(data, response->p_intermediates->line, strlen(response->p_intermediates->line));
917exit:
918 at_response_free(response);
919 return err;
920}
921
922/*
923AT+MRD_SN=R
924+MRD_SN:0101,Thu Nov 12 00:00:00 2020,G4M32301020006
925
926OK
927
928*/
929static int req_sn_get(void *data, int *cme_err)
930{
931 ATResponse *response = NULL;
932 char *tmp_ptr = NULL;
933 int err = at_send_command_singleline("AT+MRD_SN=R", "+MRD_SN:", &response);
934
935 if (err < 0 || response->success == 0 || !response->p_intermediates){
936 *cme_err = at_get_cme_error(response);
937 goto exit;
938 }
939
940 char *line = response->p_intermediates->line;
941 err = at_tok_start(&line);
942 if (err < 0)
943 {
944 goto exit;
945 }
946
947 err = at_tok_nextstr(&line, &tmp_ptr);
948 if (err < 0)
949 {
950 goto exit;
951 }
952
953 err = at_tok_nextstr(&line, &tmp_ptr);
954 if (err < 0)
955 {
956 goto exit;
957 }
958
959 err = at_tok_nextstr(&line, &tmp_ptr);
960 if (err < 0)
961 {
962 goto exit;
963 }
964
965 memcpy(data, tmp_ptr, strlen(tmp_ptr));
966
967 goto exit;
968exit:
969 at_response_free(response);
970 return err;
971}
972
973/*
974AT+SYSTIME?
975+SYSTIME: 1
976
977OK
978
979*/
980static int req_time_get(int *data, int *cme_err)
981{
982 ATResponse *response = NULL;
983 int tmp_int;
984 int err = at_send_command_singleline("AT+SYSTIME?", "+SYSTIME:", &response);
985
986 if (err < 0 || response->success == 0 || !response->p_intermediates){
987 *cme_err = at_get_cme_error(response);
988 goto exit;
989 }
990
991 char *line = response->p_intermediates->line;
992 err = at_tok_start(&line);
993 if (err < 0)
994 {
995 goto exit;
996 }
997 err = at_tok_nextint(&line, &tmp_int);
998 if (err < 0)
999 {
1000 goto exit;
1001 }
1002 *data = tmp_int;
1003
1004exit:
1005 at_response_free(response);
1006 return err;
1007}
1008
1009/*
1010AT+CCLK?
1011+CCLK: "23/03/20,01:58:00+32"
1012
1013OK
1014
1015*/
1016static int req_net_time_get(char *data, int *cme_err)
1017{
1018 ATResponse *response = NULL;
1019 char *tmp_ptr = NULL;
1020 int err = at_send_command_singleline("AT+CCLK?", "+CCLK:", &response);
1021
1022 if (err < 0 || response->success == 0 || !response->p_intermediates){
1023 *cme_err = at_get_cme_error(response);
1024 goto exit;
1025 }
1026
1027 char *line = response->p_intermediates->line;
1028 err = at_tok_start(&line);
1029 if (err < 0)
1030 {
1031 goto exit;
1032 }
1033 err = at_tok_nextstr(&line, &tmp_ptr);
1034 if (err < 0)
1035 {
1036 goto exit;
1037 }
1038 memcpy(data, tmp_ptr, strlen(tmp_ptr));
1039
1040exit:
1041 at_response_free(response);
1042 return err;
1043}
1044
1045/*
1046AT+CFUN?
1047+CFUN: 1
1048OK
1049*/
1050static int req_modem_get(int *data, int *cme_err)
1051{
1052 ATResponse *response = NULL;
1053 int modem;
1054 int err = at_send_command_singleline("AT+CFUN?", "+CFUN:", &response);
1055
1056 if (err < 0 || response->success == 0 || !response->p_intermediates){
1057 *cme_err = at_get_cme_error(response);
1058 goto exit;
1059 }
1060
1061 char *line = response->p_intermediates->line;
1062 err = at_tok_start(&line);
1063 if (err < 0)
1064 {
1065 goto exit;
1066 }
1067 err = at_tok_nextint(&line, &modem);
1068 if (err < 0)
1069 {
1070 goto exit;
1071 }
1072 *data = modem;
1073
1074exit:
1075 at_response_free(response);
1076 return err;
1077}
1078
1079/*
1080AT+CFUN=<fun>[,<rst>]
1081OK
1082*/
1083static int req_modem_set(mbtk_modem_info_t* modem, int *cme_err)
1084{
1085 ATResponse *response = NULL;
1086 char cmd[30] = {0};
1087 int err = -1;
1088
1089 sprintf(cmd, "AT+CFUN=%d,%d", modem->fun, modem->rst);
1090 err = at_send_command(cmd, &response);
1091
1092 if (err < 0 || response->success == 0){
1093 *cme_err = at_get_cme_error(response);
1094 goto exit;
1095 }
1096/*
1097 ATResponse *response = NULL;
1098 int err = at_send_command_multiline(cmd, "", &response);
1099
1100 if (err < 0 || response->success == 0 || !response->p_intermediates){
1101 *cme_err = at_get_cme_error(response);
1102 goto exit;
1103 }
1104
1105 ATLine* lines_ptr = response->p_intermediates;
1106 char *line = NULL;
1107 while(lines_ptr)
1108 {
1109 line = lines_ptr->line;
1110 if(strStartsWith(line, "Revision"))
1111 {
1112 err = at_tok_start(&line);
1113 if (err < 0)
1114 {
1115 goto exit;
1116 }
1117 memcpy(data, line, strlen(line));
1118 break;
1119 }
1120 lines_ptr = lines_ptr->p_next;
1121 }
1122
1123 goto exit;
1124*/
1125exit:
1126 at_response_free(response);
1127 return err;
1128}
1129
1130
1131/*
1132AT+SYSTIME=0,"2022-01-25-11:15:30"
1133OK
1134
1135AT+SYSTIME=1
1136OK
1137*/
1138static int req_time_set(int type, char *time, int *cme_err)
1139{
1140 ATResponse *response = NULL;
1141 int tmp_int;
1142 char cmd[200] = {0};
1143 if(str_empty(time)){
1144 sprintf(cmd, "AT+SYSTIME=%d", type);
1145 } else {
1146 sprintf(cmd, "AT+SYSTIME=%d,\"%s\"", type, time);
1147 }
1148 int err = at_send_command(cmd, &response);
1149
1150 if (err < 0 || response->success == 0){
1151 *cme_err = at_get_cme_error(response);
1152 goto exit;
1153 }
1154
1155exit:
1156 at_response_free(response);
1157 return err;
1158}
1159
1160
1161/*
1162ATI
1163Manufacturer:"LYNQ"
1164Model:"LYNQ_L508TLC"
1165Revision:L508TLCv02.01b01.00
1166IMEI:864788050901201
1167
1168OK
1169
1170*/
1171static int req_version_get(void *data, int *cme_err)
1172{
1173 ATResponse *response = NULL;
1174 int err = at_send_command_multiline("ATI", "", &response);
1175
1176 if (err < 0 || response->success == 0 || !response->p_intermediates){
1177 *cme_err = at_get_cme_error(response);
1178 goto exit;
1179 }
1180
1181 ATLine* lines_ptr = response->p_intermediates;
1182 char *line = NULL;
1183 while(lines_ptr)
1184 {
1185 line = lines_ptr->line;
1186 if(strStartsWith(line, "Revision"))
1187 {
1188 err = at_tok_start(&line);
1189 if (err < 0)
1190 {
1191 goto exit;
1192 }
1193 memcpy(data, line, strlen(line));
1194 break;
1195 }
1196 lines_ptr = lines_ptr->p_next;
1197 }
1198
1199 goto exit;
1200exit:
1201 at_response_free(response);
1202 return err;
1203}
1204
1205/*
1206ATI
1207Manufacturer:"LYNQ"
1208Model:"LYNQ_L508TLC"
1209Revision:L508TLCv02.01b01.00
1210IMEI:864788050901201
1211
1212OK
1213
1214*/
1215static int req_model_get(void *data, int *cme_err)
1216{
1217 ATResponse *response = NULL;
1218 int err = at_send_command_multiline("ATI", "", &response);
1219
1220 if (err < 0 || response->success == 0 || !response->p_intermediates){
1221 *cme_err = at_get_cme_error(response);
1222 goto exit;
1223 }
1224
1225 ATLine* lines_ptr = response->p_intermediates;
1226 char *line = NULL;
1227 while(lines_ptr)
1228 {
1229 line = lines_ptr->line;
1230 if(strStartsWith(line, "Model"))
1231 {
1232 err = at_tok_start(&line);
1233 if (err < 0)
1234 {
1235 goto exit;
1236 }
1237 memcpy(data, line, strlen(line));
1238 break;
1239 }
1240 lines_ptr = lines_ptr->p_next;
1241 }
1242
1243 goto exit;
1244exit:
1245 at_response_free(response);
1246 return err;
1247}
1248
1249/*
1250AT+ACONFIG="IMSD=1"
1251or
1252AT+ACONFIG="IMSD=0"
1253
1254OK
1255*/
1256static int req_volte_set(int state, int *cme_err)
1257{
1258 ATResponse *response = NULL;
1259 char cmd[30] = {0};
1260 if(state)
1261 {
1262 strcpy(cmd, "AT+ACONFIG=\"IMSD=1\"");
1263 }
1264 else
1265 {
1266 strcpy(cmd, "AT+ACONFIG=\"IMSD=0\"");
1267 }
1268 int err = at_send_command(cmd, &response);
1269
1270 if (err < 0 || response->success == 0) {
1271 *cme_err = at_get_cme_error(response);
1272 goto exit;
1273 }
1274
1275 err = 0;
1276exit:
1277 at_response_free(response);
1278 return err;
1279}
1280
1281/*
1282AT+ACONFIG?
1283PID=0,VID=0,IMSD=1,PIPE=0,FAST=0,RDUP=1,NOCP=0,GEFL=-1237040617
1284
1285OK
1286*/
1287static int req_volte_get(int *state, int *cme_err)
1288{
1289 ATResponse *response = NULL;
1290 char *tmp_ptr = NULL;
1291 int err = at_send_command_singleline("AT+ACONFIG?", "", &response);
1292
1293 if (err < 0 || response->success == 0 || !response->p_intermediates){
1294 *cme_err = at_get_cme_error(response);
1295 goto exit;
1296 }
1297
1298 char *line = response->p_intermediates->line;
1299 char* ptr = strstr(line, "IMSD=");
1300 if(ptr)
1301 {
1302 *state = atoi(ptr + strlen("IMSD="));
1303 }
1304 else
1305 {
1306 err = -1;
1307 }
1308exit:
1309 at_response_free(response);
1310 return err;
1311}
1312
1313
1314/*
1315* Get system temperature.
1316*
1317* type[IN]:
1318* 0: Soc temperature.
1319* 1: RF temperature.
1320* temp[OUT]:
1321* temperature in celsius.
1322*
1323
1324AT*RFTEMP
1325*RFTEMP:0,28
1326OK
1327
1328AT*SOCTEMP
1329*SOCTEMP:24000
1330OK
1331
1332*/
r.xiao2102d762024-06-07 03:10:38 -07001333static int req_temp_get(int type, mbtk_thermal_info_t *temp, int *cme_err)
liubin281ac462023-07-19 14:22:54 +08001334{
1335 ATResponse *response = NULL;
1336 int err = -1;
1337 int tmp_int;
1338 if(type == 0) { // Soc
1339 err = at_send_command_singleline("AT*SOCTEMP", "*SOCTEMP:", &response);
1340 } else { // RF
1341 err = at_send_command_singleline("AT*RFTEMP", "*RFTEMP:", &response);
1342 }
1343
1344 if (err < 0 || response->success == 0 || !response->p_intermediates){
1345 *cme_err = at_get_cme_error(response);
1346 goto exit;
1347 }
1348
1349 char *line = response->p_intermediates->line;
1350 err = at_tok_start(&line);
1351 if (err < 0)
1352 {
1353 goto exit;
1354 }
1355 err = at_tok_nextint(&line, &tmp_int);
1356 if (err < 0)
1357 {
1358 goto exit;
1359 }
1360
1361 if(type == 1) { // RF
1362 err = at_tok_nextint(&line, &tmp_int);
1363 if (err < 0)
1364 {
1365 goto exit;
1366 }
r.xiao2102d762024-06-07 03:10:38 -07001367 temp->ther = tmp_int;
liubin281ac462023-07-19 14:22:54 +08001368 } else {
r.xiao2102d762024-06-07 03:10:38 -07001369 tmp_int = tmp_int / 1000;
1370 temp->ther = tmp_int;
1371 //LOG(" >>>temp =%d",temp->ther);
liubin281ac462023-07-19 14:22:54 +08001372 }
1373
1374exit:
1375 at_response_free(response);
1376 return err;
1377}
1378
1379/*
1380AT*BAND=15
1381OK
1382
1383*/
1384static int req_band_set(mbtk_band_info_t* band, int *cme_err)
1385{
1386 ATResponse *response = NULL;
b.liudfec1e12024-06-06 16:38:59 +08001387 char cmd[100] = {0};
liubin281ac462023-07-19 14:22:54 +08001388 int err = -1;
1389
1390 if(band->gsm_band == 0 && band->umts_band == 0
1391 && band->tdlte_band == 0 && band->fddlte_band == 0) {
1392 sprintf(cmd, "AT*BAND=%d", band->net_pref);
1393 } else {
1394 band_support_get();
1395
1396 log_hex("BAND_SUPPORT", &band_support, sizeof(mbtk_band_info_t));
1397 log_hex("BAND", band, sizeof(mbtk_band_info_t));
1398
1399 if(band->gsm_band == 0) {
1400 band->gsm_band = band_support.gsm_band;
1401 }
1402 if(band->umts_band == 0) {
1403 band->umts_band = band_support.umts_band;
1404 }
1405 if(band->tdlte_band == 0) {
1406 band->tdlte_band = band_support.tdlte_band;
1407 }
1408 if(band->fddlte_band == 0) {
1409 band->fddlte_band = band_support.fddlte_band;
1410 }
1411
1412 if((band->gsm_band & band_support.gsm_band) != band->gsm_band) {
1413 LOG("GSM band error.");
1414 goto exit;
1415 }
1416
1417 if((band->umts_band & band_support.umts_band) != band->umts_band) {
1418 LOG("UMTS band error.");
1419 goto exit;
1420 }
1421
1422 if((band->tdlte_band & band_support.tdlte_band) != band->tdlte_band) {
1423 LOG("TDLTE band error.");
1424 goto exit;
1425 }
1426
1427 if((band->fddlte_band & band_support.fddlte_band) != band->fddlte_band) {
1428 LOG("FDDLTE band error.");
1429 goto exit;
1430 }
1431
b.liu288093c2024-05-09 17:02:57 +08001432 if((band->lte_ext_band & band_support.lte_ext_band) != band->lte_ext_band) {
1433 LOG("EXT_LTE band error.");
1434 goto exit;
1435 }
1436
liubin281ac462023-07-19 14:22:54 +08001437 if(band->net_pref == 0xFF) { // No change net_pref.
1438 int tmp_int;
1439 err = at_send_command_singleline("AT*BAND?", "*BAND:", &response);
1440 if (err < 0 || response->success == 0 || !response->p_intermediates){
1441 *cme_err = at_get_cme_error(response);
1442 goto exit;
1443 }
1444
1445 char *line = response->p_intermediates->line;
1446 err = at_tok_start(&line);
1447 if (err < 0)
1448 {
1449 goto exit;
1450 }
1451
1452 err = at_tok_nextint(&line, &tmp_int);
1453 if (err < 0)
1454 {
1455 goto exit;
1456 }
1457 band->net_pref = (uint8)tmp_int; // Set to current net_pref.
1458
1459 at_response_free(response);
1460 }
1461
b.liu288093c2024-05-09 17:02:57 +08001462 if(band->lte_ext_band > 0) {
1463 sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d,,,,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band, band->lte_ext_band);
1464 } else {
1465 sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
1466 }
liubin281ac462023-07-19 14:22:54 +08001467 }
1468 err = at_send_command(cmd, &response);
1469
1470 if (err < 0 || response->success == 0){
1471 *cme_err = at_get_cme_error(response);
1472 goto exit;
1473 }
1474
1475 err = 0;
1476exit:
1477 at_response_free(response);
1478 return err;
1479}
1480
1481/*
1482// ???????
1483AT*BAND=?
1484*BAND:(0-18),79,147,482,524503
1485
1486OK
1487
1488// ???????????
1489AT*BAND?
1490*BAND: 15, 78, 147, 482, 524503, 0, 2, 2, 0, 0
1491
1492OK
1493
1494// ?????????
1495AT*BAND=5,79,147,128,1
1496OK
1497
1498net_prefferred??
1499 0 : GSM only
1500 1 : UMTS only
1501 2 : GSM/UMTS(auto)
1502 3 : GSM/UMTS(GSM preferred)
1503 4 : GSM/UMTS(UMTS preferred)
1504 5 : LTE only
1505 6 : GSM/LTE(auto)
1506 7 : GSM/LTE(GSM preferred)
1507 8 : GSM/LTE(LTE preferred)
1508 9 : UMTS/LTE(auto)
1509 10 : UMTS/LTE(UMTS preferred)
1510 11 : UMTS/LTE(LTE preferred)
1511 12 : GSM/UMTS/LTE(auto)
1512 13 : GSM/UMTS/LTE(GSM preferred)
1513 14 : GSM/UMTS/LTE(UMTS preferred)
1514 15 : GSM/UMTS/LTE(LTE preferred)
1515GSM band??
1516 1 ?C PGSM 900 (standard or primary)
1517 2 ?C DCS GSM 1800
1518 4 ?C PCS GSM 1900
1519 8 ?C EGSM 900 (extended)
1520 16 ?C GSM 450
1521 32 ?C GSM 480
1522 64 ?C GSM 850
1523 512 - BAND_LOCK_BIT // used for GSM band setting
1524UMTS band??
1525 1 ?C UMTS_BAND_1
1526 2 ?C UMTS_BAND_2
1527 4 ?C UMTS_BAND_3
1528 8 ?C UMTS_BAND_4
1529 16 ?C UMTS_BAND_5
1530 32 ?C UMTS_BAND_6
1531 64 ?C UMTS_BAND_7
1532 128 ?C UMTS_BAND_8
1533 256 ?C UMTS_BAND_9
1534LTEbandH(TDD-LTE band)
1535 32 ?C TDLTE_BAND_38
1536 64 ?C TDLTE_BAND_39
1537 128 ?C TDLTE_BAND_40
1538 256 ?C TDLTE_BAND_41
1539LTEbandL(FDD-LTE band)
1540 1 ?C FDDLTE_BAND_1
1541 4 ?C FDDLTE _BAND_3
1542 8 ?C FDDLTE _BAND_4
1543 64 ?C FDDLTE _BAND_7
1544 65536 ?C FDDLTE _BAND_17
1545 524288 ?C FDDLTE _BAND_20
1546*/
1547static int req_band_get(mbtk_band_info_t *band, int *cme_err)
1548{
1549 ATResponse *response = NULL;
1550 int tmp_int;
1551
1552 band_support_get();
1553
1554 log_hex("BAND_SUPPORT", &band_support, sizeof(mbtk_band_info_t));
1555 int err = at_send_command_singleline("AT*BAND?", "*BAND:", &response);
1556 if (err < 0 || response->success == 0 || !response->p_intermediates){
1557 *cme_err = at_get_cme_error(response);
1558 goto exit;
1559 }
1560
1561 char *line = response->p_intermediates->line;
1562 err = at_tok_start(&line);
1563 if (err < 0)
1564 {
1565 goto exit;
1566 }
1567
1568 err = at_tok_nextint(&line, &tmp_int);
1569 if (err < 0)
1570 {
1571 goto exit;
1572 }
1573 band->net_pref = (uint8)tmp_int;
1574
1575 err = at_tok_nextint(&line, &tmp_int);
1576 if (err < 0)
1577 {
1578 goto exit;
1579 }
1580 band->gsm_band = (uint16)tmp_int;
1581
1582 err = at_tok_nextint(&line, &tmp_int);
1583 if (err < 0)
1584 {
1585 goto exit;
1586 }
1587 band->umts_band = (uint16)tmp_int;
1588
1589 err = at_tok_nextint(&line, &tmp_int);
1590 if (err < 0)
1591 {
1592 goto exit;
1593 }
1594 band->tdlte_band = (uint32)tmp_int;
1595
1596 err = at_tok_nextint(&line, &tmp_int);
1597 if (err < 0)
1598 {
1599 goto exit;
1600 }
1601 band->fddlte_band = (uint32)tmp_int;
1602
b.liu288093c2024-05-09 17:02:57 +08001603 // roamingConfig
1604 err = at_tok_nextint(&line, &tmp_int);
1605 if (err < 0)
1606 {
1607 goto exit;
1608 }
1609
1610 // srvDomain
1611 err = at_tok_nextint(&line, &tmp_int);
1612 if (err < 0)
1613 {
1614 goto exit;
1615 }
1616
1617 // bandPriorityFlag
1618 err = at_tok_nextint(&line, &tmp_int);
1619 if (err < 0)
1620 {
1621 goto exit;
1622 }
1623
1624 //
1625 err = at_tok_nextint(&line, &tmp_int);
1626 if (err < 0)
1627 {
1628 goto exit;
1629 }
1630
1631 // ltebandExt
1632 err = at_tok_nextint(&line, &tmp_int);
1633 if (err < 0)
1634 {
1635 goto exit;
1636 }
1637 band->lte_ext_band = (uint32)tmp_int;
1638
liubin281ac462023-07-19 14:22:54 +08001639 log_hex("BAND", band, sizeof(mbtk_band_info_t));
1640
1641exit:
1642 at_response_free(response);
1643 return err;
1644}
1645
1646/*
1647AT+ICCID
1648+ICCID: 89860621330065648041
1649
1650OK
1651*/
1652static int req_iccid_get(void *data, int *cme_err)
1653{
1654 ATResponse *response = NULL;
1655 char *tmp_ptr = NULL;
1656 int err = at_send_command_singleline("AT+ICCID", "+ICCID:", &response);
1657
1658 if (err < 0 || response->success == 0 || !response->p_intermediates){
1659 *cme_err = at_get_cme_error(response);
1660 goto exit;
1661 }
1662
1663 char *line = response->p_intermediates->line;
1664 err = at_tok_start(&line);
1665 if (err < 0)
1666 {
1667 goto exit;
1668 }
1669
1670 err = at_tok_nextstr(&line, &tmp_ptr);
1671 if (err < 0)
1672 {
1673 goto exit;
1674 }
1675
1676 memcpy(data, tmp_ptr, strlen(tmp_ptr));
1677exit:
1678 at_response_free(response);
1679 return err;
1680}
1681
1682/*
1683AT+CNUM?
1684+CNUM: "","13980414101",129
1685
1686OK
1687
1688*/
1689static int req_phone_number_get(void *data, int *cme_err)
1690{
1691 ATResponse *response = NULL;
1692 char *tmp_ptr = NULL;
1693 int err = at_send_command_singleline("AT+CNUM?", "+CNUM:", &response);
1694 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1695 if(response) {
1696 *cme_err = at_get_cme_error(response);
1697 }
1698 LOGD("AT+CNUM? fail.");
1699 goto exit;
1700 }
1701
1702 char *line = response->p_intermediates->line;
1703 if(line == NULL) {
1704 LOGD("line is NULL");
1705 goto exit;
1706 }
1707 err = at_tok_start(&line);
1708 if (err < 0)
1709 {
1710 goto exit;
1711 }
1712
1713 err = at_tok_nextstr(&line, &tmp_ptr);
1714 if (err < 0)
1715 {
1716 goto exit;
1717 }
1718
1719 err = at_tok_nextstr(&line, &tmp_ptr);
1720 if (err < 0)
1721 {
1722 goto exit;
1723 }
1724
1725 memcpy(data, tmp_ptr, strlen(tmp_ptr));
1726exit:
1727 at_response_free(response);
1728 return err;
1729}
1730
1731
1732/*
1733AT+CIMI
1734460068103383304
1735
1736OK
1737
1738*/
1739static int req_imsi_get(void *data, int *cme_err)
1740{
1741 ATResponse *response = NULL;
1742 int err = at_send_command_numeric("AT+CIMI", &response);
1743
1744 if (err < 0 || response->success == 0 || !response->p_intermediates){
1745 *cme_err = at_get_cme_error(response);
1746 goto exit;
1747 }
1748
1749 memcpy(data, response->p_intermediates->line, strlen(response->p_intermediates->line));
1750exit:
1751 at_response_free(response);
1752 return err;
1753}
1754
1755
1756/*
1757AT+CLCK=SC,1/0,1234
1758+CLCK:1/0
1759
1760OK
1761
1762*/
1763static int req_pin_enable(mbtk_enable_pin_info *data, int *cme_err)
1764{
1765 ATResponse *response = NULL;
1766 char cmd[64]={0};
1767 sprintf(cmd, "AT+CLCK=SC,%d,%s", data->enable, data->pin_value);
1768
1769 int err = at_send_command_singleline(cmd, "+CLCK:", &response);
1770 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1771 if(response) {
1772 *cme_err = at_get_cme_error(response);
1773 }
1774 LOGD("AT+CLCK? fail.");
1775 goto exit;
1776 }
1777
1778 char *line = response->p_intermediates->line;
1779 if(line == NULL) {
1780 LOGD("line is NULL");
1781 goto exit;
1782 }
1783 err = at_tok_start(&line);
1784 if (err < 0)
1785 {
1786 goto exit;
1787 }
1788 int clck;
1789 err = at_tok_nextint(&line, &clck);
1790 if (err < 0)
1791 {
1792 goto exit;
1793 }
1794
1795exit:
1796 at_response_free(response);
1797 return err;
1798}
1799
1800/*
yq.wang586a0df2024-10-24 20:10:37 -07001801AT+CLCK=SC,2
1802+CLCK: 1
1803
1804OK
1805*/
1806static int req_get_pin_state(mbtk_enable_pin_info *state, int *cme_err)
1807{
1808 ATResponse *response = NULL;
1809 char cmd[64]={0};
1810
1811 int err = at_send_command_singleline("AT+CLCK=SC,2", "+CLCK:", &response);
1812 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates)
1813 {
1814 if(response)
1815 {
1816 *cme_err = at_get_cme_error(response);
1817 }
1818 LOGE("[req_get_pin_state] AT+CLCK fail.");
1819 goto exit;
1820 }
1821
1822 char *line = response->p_intermediates->line;
1823 if(line == NULL)
1824 {
1825 LOGE("[req_get_pin_state] line is NULL");
1826 goto exit;
1827 }
1828 err = at_tok_start(&line);
1829 if (err < 0)
1830 {
1831 LOGE("[req_get_pin_state] at_tok_start fail.[%d]", err);
1832 goto exit;
1833 }
1834
1835 int clck;
1836 err = at_tok_nextint(&line, &clck);
1837 if (err < 0)
1838 {
1839 LOGE("[req_get_pin_state] at_tok_nextint fail.[%d]", err);
1840 goto exit;
1841 }
1842
1843 if(clck == 1)
1844 {
1845 state = MBTK_PIN_ENABLE;
1846 }
1847 else
1848 {
1849 state = MBTK_PIN_DISABLE;
1850 }
1851exit:
1852 at_response_free(response);
1853 response = NULL;
1854 return err;
1855}
1856
1857
1858/*
liubin281ac462023-07-19 14:22:54 +08001859AT+CPIN=1234
1860
1861OK
1862
1863*/
1864static int req_pin_verify(char *data, int *cme_err)
1865{
1866 ATResponse *response = NULL;
1867 char cmd[64]={0};
1868 sprintf(cmd, "AT+CPIN=%s", data);
1869 int err = at_send_command(cmd, &response);
1870 if (err < 0 || response->success == 0){
1871 if(cme_err) {
1872 *cme_err = at_get_cme_error(response);
1873 }
1874 goto exit;
1875 }
1876
1877exit:
1878 at_response_free(response);
1879 return err;
1880}
1881
1882/*
1883AT+CLCK=SC,2
1884+CLCK: 1
1885
1886OK
1887
1888AT+CLCK="SC",1,"1234"
1889+CLCK:1
1890
1891OK
1892
1893AT+CPWD="SC","1234","4321"
1894
1895OK
1896
1897*/
1898static int req_pin_change(mbtk_change_pin_info *data, int *cme_err)
1899{
1900 ATResponse *response = NULL;
1901 char cmd[64]={0};
1902
1903 int err = at_send_command_singleline("AT+CLCK=SC,2", "+CLCK:", &response);
1904 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1905 if(response) {
1906 *cme_err = at_get_cme_error(response);
1907 }
1908 LOGD("AT+CLCK fail.");
1909 goto exit;
1910 }
1911
1912 char *line = response->p_intermediates->line;
1913 if(line == NULL) {
1914 LOGD("line is NULL");
1915 goto exit;
1916 }
1917 err = at_tok_start(&line);
1918 if (err < 0)
1919 {
1920 goto exit;
1921 }
1922 int clck;
1923 err = at_tok_nextint(&line, &clck);
1924 if (err < 0)
1925 {
1926 goto exit;
1927 }
1928 at_response_free(response);
1929
1930 if(clck==0)
1931 {
1932 sprintf(cmd, "AT+CLCK=SC,1,%s", data->old_pin_value);
1933 err = at_send_command_singleline(cmd, "+CLCK:", &response);
1934 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1935 if(response) {
1936 *cme_err = at_get_cme_error(response);
1937 }
1938 LOGD("AT+CLCK fail.");
1939 goto exit;
1940 }
1941 line = response->p_intermediates->line;
1942 if(line == NULL) {
1943 LOGD("line is NULL");
1944 goto exit;
1945 }
1946 err = at_tok_start(&line);
1947 if (err < 0)
1948 {
1949 goto exit;
1950 }
1951 clck = -1;
1952 err = at_tok_nextint(&line, &clck);
1953 if (err < 0)
1954 {
1955 goto exit;
1956 }
1957 at_response_free(response);
1958 if(clck != 1)
1959 return err;
1960 }
1961 memset(cmd, 0, 64);
1962 sprintf(cmd, "AT+CPWD=SC,%s,%s", data->old_pin_value,data->new_pin_value);
1963 err = at_send_command(cmd, &response);
1964 if (err < 0 || response->success == 0){
1965 if(cme_err) {
1966 *cme_err = at_get_cme_error(response);
1967 }
1968 goto exit;
1969 }
1970
1971exit:
1972 at_response_free(response);
1973 return err;
1974}
1975
1976/*
1977AT+CPIN?
1978+CPIN:SIM PUK
1979
1980OK
1981
1982AT+CPIN="PUK","PIN"
1983+CPIN: READY
1984
1985OK
1986*/
1987static int req_puk_unlock_pin(mbtk_unlock_pin_info *data, int *cme_err)
1988{
1989 ATResponse *response = NULL;
1990 char cmd[64]={0};
1991#if 0
1992 int err = at_send_command_singleline("AT+CPIN?", "+CPIN:", &response);
1993 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1994 if(response) {
1995 *cme_err = at_get_cme_error(response);
1996 }
1997 LOGD("AT+CNUM? fail.");
1998 goto exit;
1999 }
2000
2001 char *line = response->p_intermediates->line;
2002 if(line == NULL) {
2003 LOGD("line is NULL");
2004 goto exit;
2005 }
2006 err = at_tok_start(&line);
2007 if (err < 0)
2008 {
2009 goto exit;
2010 }
2011 char *tmp_ptr = NULL;
2012 err = at_tok_nextstr(&line, &tmp_ptr);
2013 if (err < 0)
2014 {
2015 goto exit;
2016 }
2017 at_response_free(response);
2018
2019 if(!strstr(tmp_ptr,"SIM PUK"))
2020 {
2021 sprintf(cmd, "AT+CPIN=%s,%s", data->puk_value, data->pin_value);
2022 err = at_send_command_singleline(cmd, "+CPIN:", &response);
2023 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
2024 if(response) {
2025 *cme_err = at_get_cme_error(response);
2026 }
2027 LOGD("AT+CNUM? fail.");
2028 goto exit;
2029 }
2030 line = response->p_intermediates->line;
2031 if(line == NULL) {
2032 LOGD("line is NULL");
2033 goto exit;
2034 }
2035 err = at_tok_start(&line);
2036 if (err < 0)
2037 {
2038 goto exit;
2039 }
2040 memset(tmp_ptr, 0, strlen(tmp_ptr));
2041 err = at_tok_nextstr(&line, &tmp_ptr);
2042 if (err < 0)
2043 {
2044 goto exit;
2045 }
2046 at_response_free(response);
2047 if(strstr(tmp_ptr, "READY"))
2048 return err;
2049 }
2050 else
2051 return err;
2052#else
2053 sprintf(cmd, "AT+CPIN=%s,%s", data->puk_value, data->pin_value);
r.xiao2ad43d12024-03-23 00:03:29 -07002054 int err = at_send_command(cmd, &response);
2055 if (err < 0 || response->success == 0){
2056 if(cme_err) {
liubin281ac462023-07-19 14:22:54 +08002057 *cme_err = at_get_cme_error(response);
2058 }
liubin281ac462023-07-19 14:22:54 +08002059 goto exit;
2060 }
r.xiao2ad43d12024-03-23 00:03:29 -07002061
liubin281ac462023-07-19 14:22:54 +08002062#endif
2063exit:
2064 at_response_free(response);
2065 return err;
2066}
2067
2068/*
2069AT+COPS=?
2070
2071+COPS: (2, "CHINA MOBILE", "CMCC", "46000", 7),(3, "CHN-CT", "CT", "46011", 7),(3, "CHN-UNICOM", "UNICOM", "46001", 7),(1, "460 15", "460 15", "46015", 7),,(0,1,2,3,4),(0,1,2)
2072
2073OK
2074
2075// Return [sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)]
2076*/
2077#if 0
2078static int req_available_net_get(mbtk_net_array_info_t *data_ptr)
2079{
2080 ATResponse *response = NULL;
2081 char *tmp_ptr = NULL;
2082 int tmp_int;
2083 int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response);
2084
2085 if (err < 0 || response->success == 0 || !response->p_intermediates)
2086 goto exit;
2087#if 1
2088 char *line_ptr = response->p_intermediates->line;
2089 if(line_ptr == NULL) {
2090 LOG("line is NULL");
2091 goto exit;
2092 }
2093 //LOG("Line:%s",line_ptr);
2094 line_ptr = strstr(line_ptr, "(");
2095 while(line_ptr) {
2096 line_ptr++;
2097 // Only for available/current net.
2098 if(*line_ptr == '1' || *line_ptr == '2') {
2099 //LOG("Temp:%s",line_ptr);
2100 //sleep(1);
2101 line_ptr = strstr(line_ptr, ",");
2102 if(line_ptr == NULL)
2103 goto exit;
2104 line_ptr++;
2105
2106 line_ptr = strstr(line_ptr, ",");
2107 if(line_ptr == NULL)
2108 goto exit;
2109 line_ptr++;
2110
2111 line_ptr = strstr(line_ptr, ",");
2112 if(line_ptr == NULL)
2113 goto exit;
2114
2115 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"'))
2116 line_ptr++;
2117
2118 mbtk_net_info_t *net = (mbtk_net_info_t*)malloc(sizeof(mbtk_net_info_t));
2119 if(net == NULL) {
2120 LOG("malloc() fail.");
2121 goto exit;
2122 }
2123 memset(net, 0, sizeof(mbtk_net_info_t));
2124
2125 // Point to "46000"
2126 //LOG("PLMN:%s",line_ptr);
2127 //sleep(1);
2128 net->plmn = (uint32)atoi(line_ptr);
2129
2130 line_ptr = strstr(line_ptr, ",");
2131 if(line_ptr == NULL)
2132 goto exit;
2133
2134 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' '))
2135 line_ptr++;
2136
2137 // Point to "7"
2138 if(*line_ptr == '\0') {
2139 free(net);
2140 goto exit;
2141 }
2142 //LOG("Type:%s",line_ptr);
2143 //sleep(1);
2144 net->net_type = (uint8)atoi(line_ptr);
2145 list_add(data_ptr->net_list, net);
2146 data_ptr->count++;
2147 }
2148
2149 line_ptr = strstr(line_ptr, "(");
2150 }
2151#endif
2152exit:
2153 at_response_free(response);
2154 return err;
2155}
2156#else
2157static int req_available_net_get(void* buff, int *cme_err)
2158{
2159 ATResponse *response = NULL;
2160 char *tmp_ptr = NULL;
2161 int tmp_int;
2162 int buff_size = 0;
2163 int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response);
2164
2165 if (err < 0 || response->success == 0 || !response->p_intermediates){
2166 *cme_err = at_get_cme_error(response);
2167 goto exit;
2168 }
2169 char *line_ptr = response->p_intermediates->line;
2170 if(line_ptr == NULL) {
2171 LOG("line is NULL");
2172 goto exit;
2173 }
2174 uint8* buff_ptr = (uint8*)buff;
2175 //LOG("Line:%s",line_ptr);
2176 line_ptr = strstr(line_ptr, "(");
2177 while(line_ptr) {
2178 line_ptr++;
2179 // Only for available/current net.
2180 if(*line_ptr == '1' || *line_ptr == '2' || *line_ptr == '3') {
2181 *(buff_ptr + 2) = (uint8)atoi(line_ptr); // net_state
2182
2183 line_ptr = strstr(line_ptr, ",");
2184 if(line_ptr == NULL)
2185 goto exit;
2186 line_ptr++;
2187
2188 line_ptr = strstr(line_ptr, ",");
2189 if(line_ptr == NULL)
2190 goto exit;
2191 line_ptr++;
2192
2193 line_ptr = strstr(line_ptr, ",");
2194 if(line_ptr == NULL)
2195 goto exit;
2196
2197 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"'))
2198 line_ptr++;
2199
2200 // set sel_mode to 0
2201 *buff_ptr = (uint8)0;
2202 // Point to "46000"
2203 //LOG("PLMN:%s",line_ptr);
2204 //sleep(1);
2205 uint32_2_byte((uint32)atoi(line_ptr), buff_ptr + 3, false); // plmn
2206
2207 line_ptr = strstr(line_ptr, ",");
2208 if(line_ptr == NULL)
2209 goto exit;
2210
2211 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' '))
2212 line_ptr++;
2213
2214 // Point to "7"
2215 if(*line_ptr == '\0') {
2216 goto exit;
2217 }
2218 //LOG("Type:%s",line_ptr);
2219 //sleep(1);
2220 *(buff_ptr + 1) = (uint8)atoi(line_ptr); // net_type
2221
2222 buff_size += sizeof(mbtk_net_info_t);
2223 buff_ptr += sizeof(mbtk_net_info_t);
2224 }
2225
2226 line_ptr = strstr(line_ptr, "(");
2227 }
2228exit:
2229 at_response_free(response);
2230 return buff_size;
2231}
2232#endif
2233
2234/*
2235AT+COPS?
2236+COPS: 1
2237
2238OK
2239
2240or
2241
2242AT+COPS?
2243+COPS: 0,2,"46001",7
2244
2245OK
2246
2247*/
2248static int req_net_sel_mode_get(mbtk_net_info_t *net, int *cme_err)
2249{
2250 //LOG("req_net_sel_mode_get() 0");
2251 //sleep(1);
2252 ATResponse *response = NULL;
2253 int tmp_int;
2254 char *tmp_ptr = NULL;
2255 int err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
2256 //LOG("req_net_sel_mode_get() 00");
2257 //sleep(1);
2258 if (err < 0 || response->success == 0 || !response->p_intermediates){
2259 if(cme_err != NULL)
2260 *cme_err = at_get_cme_error(response);
2261 err = -1;
2262 goto exit;
2263 }
2264 //LOG("req_net_sel_mode_get() 1");
2265 //sleep(1);
2266 char *line = response->p_intermediates->line;
2267 if(line == NULL) {
2268 LOG("line is NULL");
2269 goto exit;
2270 }
2271 //LOG("req_net_sel_mode_get() 2");
2272 //sleep(1);
2273 err = at_tok_start(&line);
2274 if (err < 0)
2275 {
2276 goto exit;
2277 }
2278 //LOG("req_net_sel_mode_get() 3");
2279 //sleep(1);
2280 err = at_tok_nextint(&line, &tmp_int);
2281 if (err < 0)
2282 {
2283 goto exit;
2284 }
2285 net->net_sel_mode = (uint8)tmp_int;
2286 //LOG("req_net_sel_mode_get() 4");
2287 //sleep(1);
2288 // +COPS: 1
2289 if(!at_tok_hasmore(&line)) {
2290 goto exit;
2291 }
2292 //LOG("req_net_sel_mode_get() 5");
2293 //sleep(1);
2294 err = at_tok_nextint(&line, &tmp_int);
2295 if (err < 0)
2296 {
2297 goto exit;
2298 }
2299 //LOG("req_net_sel_mode_get() 6");
2300 //sleep(1);
2301 err = at_tok_nextstr(&line, &tmp_ptr);
2302 if (err < 0)
2303 {
2304 goto exit;
2305 }
2306 // memcpy(net->plmn, tmp_ptr, strlen(tmp_ptr));
2307 net->plmn = (uint32)atoi(tmp_ptr);
2308 //LOG("req_net_sel_mode_get() 7");
2309 //sleep(1);
2310 err = at_tok_nextint(&line, &tmp_int);
2311 if (err < 0)
2312 {
2313 goto exit;
2314 }
2315 net->net_type = (uint8)tmp_int;
2316
2317 net->net_state = (uint8)MBTK_NET_AVIL_STATE_CURRENT;
2318
2319exit:
2320 //LOG("req_net_sel_mode_get() 8");
2321 //sleep(1);
2322 at_response_free(response);
2323 return err;
2324}
2325
2326/*
2327AT+COPS=0
2328or
2329AT+COPS=1,2,"46000",7
2330
2331OK
2332
2333*/
2334static int req_net_sel_mode_set(mbtk_net_info_t* net, int *cme_err)
2335{
2336 ATResponse *response = NULL;
2337 char cmd[50] = {0};
2338 char* cmp_ptr = cmd;
2339 if(net == NULL) {
2340 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
2341 } else {
2342 if(net->net_sel_mode == 0) {
2343 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
2344 } else if(net->net_type == 0xFF) {
2345 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\"",net->plmn);
2346 } else {
2347 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\",%d",net->plmn, net->net_type);
2348 }
2349 }
2350
2351 int err = at_send_command(cmd, &response);
2352
2353 if (err < 0 || response->success == 0) {
2354 *cme_err = at_get_cme_error(response);
2355 goto exit;
2356 }
2357
2358exit:
2359 at_response_free(response);
2360 return err;
2361}
2362
2363/*
2364AT+EEMOPT=1
2365OK
2366
2367// LTE
2368AT+EEMGINFO?
2369// <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
2370// <rsrp>,<rsrq>, <sinr>,
2371// errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
2372// cellId,subFrameAssignType,specialSubframePatterns,transMode
2373// mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
2374// tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
2375// dlBer, ulBer,
2376// diversitySinr, diversityRssi
2377+EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
23780, 0, 0,
23791, 10, 0, 1, 0, 1059, 78, 3959566565,
2380105149248, 2, 7, 7,
23810, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
23820, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
23830, 0,
23847, 44
2385
2386// index,phyCellId,euArfcn,rsrp,rsrq
2387+EEMLTEINTER: 0, 65535, 38950, 0, 0
2388
2389+EEMLTEINTER: 1, 0, 0, 0, 0
2390
2391+EEMLTEINTER: 2, 0, 4294967295, 255, 255
2392
2393+EEMLTEINTER: 3, 65535, 1300, 0, 0
2394
2395+EEMLTEINTER: 4, 0, 0, 0, 0
2396
2397+EEMLTEINTER: 5, 0, 4294967295, 247, 0
2398
2399+EEMLTEINTER: 6, 197, 41332, 24, 9
2400
2401+EEMLTEINTER: 7, 0, 0, 0, 0
2402
2403+EEMLTEINTER: 8, 0, 0, 0, 0
2404
2405+EEMLTEINTRA: 0, 429, 40936, 56, 12
2406
2407+EEMLTEINTERRAT: 0,0
2408
2409+EEMLTEINTERRAT: 1,0
2410
2411+EEMGINFO: 3, 2 // <state>:
2412 // 0: ME in Idle mode
2413 // 1: ME in Dedicated mode
2414 // 2: ME in PS PTM mode
2415 // 3: invalid state
2416 // <nw_type>:
2417 // 0: GSM 1: UMTS 2: LTE
2418
2419OK
2420
2421// WCDMA
2422AT+EEMGINFO?
2423// Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
2424
2425// if sCMeasPresent == 1
2426// cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
2427// endif
2428
2429// if sCParamPresent == 1
2430// rac, nom, mcc, mnc_len, mnc, lac, ci,
2431// uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
2432// csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
2433// endif
2434
2435// if ueOpStatusPresent == 1
2436// rrcState, numLinks, srncId, sRnti,
2437// algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
2438// HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
2439// MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
2440// serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
2441// endif
2442//
2443+EEMUMTSSVC: 3, 1, 1, 1,
2444-80, 27, -6, -18, -115, -32768,
24451, 1, 1120, 2, 1, 61697, 168432821,
244615, 24, 10763, 0, 0, 0, 0,
2447128, 128, 65535, 0, 0,
24482, 255, 65535, 4294967295,
24490, 0, 0, 0, 0, 0,
24500, 0, 0, 0, 0, 0, 1, 1,
245128672, 28672, 0, 0, 0, 0, 0, 0, 0,
24520, 0, 0, 0, 0, 0
2453
2454// index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
2455+EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
2456
2457+EEMUMTSINTRA: 1, -1, -32768, -18, -115, 0, 0, 65534, 2, 10763, 40, 32768
2458
2459+EEMUMTSINTRA: 2, -32768, -18, -115, 0, 0, 65534, 3, 10763, 278, 32768, 65535
2460
2461+EEMUMTSINTRA: 3, -18, -115, 0, 0, -2, 4, 10763, 28, 32768, 65535, 32768
2462
2463+EEMUMTSINTRA: 4, -115, 0, 0, -2, 5, 10763, 270, 32768, 65535, 32768, 65518
2464
2465+EEMUMTSINTRA: 5, 0, 0, -2, 6, 10763, 286, 32768, 65535, 32768, 65518, 65421
2466
2467+EEMUMTSINTRA: 6, 0, -2, 7, 10763, 80, 32768, 65535, 32768, 65518, 65421, 0
2468
2469+EEMUMTSINTRA: 7, -2, 8, 10763, 206, -32768, 65535, 32768, 65518, 65421, 0, 0
2470
2471+EEMUMTSINTRA: 8, 9, 10763, 11, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
2472
2473+EEMUMTSINTRA: 9, 10763, 19, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 11
2474
2475+EEMUMTSINTRA: 10, 232, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 12, 10763
2476
2477+EEMUMTSINTRA: 11, -32768, -1, -32768, -18, -115, 0, 0, 65534, 13, 10763, 66
2478
2479+EEMUMTSINTRA: 12, -1, -32768, -18, -115, 0, 0, 65534, 14, 10763, 216, 32768
2480
2481+EEMUMTSINTRA: 13, -32768, -18, -115, 0, 0, 65534, 15, 10763, 183, 32768, 65535
2482
2483+EEMUMTSINTRA: 14, -18, -115, 0, 0, -2, 16, 10763, 165, 32768, 65535, 32768
2484
2485+EEMUMTSINTRA: 15, -115, 0, 0, -2, 17, 10763, 151, 32768, 65535, 32768, 65518
2486
2487+EEMUMTSINTRA: 16, 0, 0, -2, 18, 10763, 43, 32768, 65535, 32768, 65518, 65421
2488
2489+EEMUMTSINTRA: 17, 0, -2, 19, 10763, 72, 32768, 65535, 32768, 65518, 65421, 0
2490
2491+EEMUMTSINTRA: 18, -2, 20, 10763, 157, -32768, 65535, 32768, 65518, 65421, 0, 0
2492
2493+EEMUMTSINTRA: 19, 21, 10763, 165, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
2494
2495+EEMUMTSINTRA: 20, 10763, 301, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 23
2496
2497+EEMUMTSINTRA: 21, 23, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 24, 10763
2498
2499+EEMUMTSINTRA: 22, -32768, -1, -32768, -18, -115, 0, 0, 65534, 25, 10763, 0
2500
2501+EEMUMTSINTRA: 23, -1, -32768, -18, -115, 0, 0, 65534, 26, 10763, 167, 32768
2502
2503+EEMUMTSINTRA: 24, -32768, -18, -115, 0, 0, 65534, 27, 10763, 34, 32768, 65535
2504
2505+EEMUMTSINTRA: 25, -18, -115, 0, 0, -2, 28, 10763, 313, 32768, 65535, 32768
2506
2507+EEMUMTSINTRA: 26, -115, 0, 0, -2, 29, 10763, 152, 32768, 65535, 32768, 65518
2508
2509+EEMUMTSINTRA: 27, 0, 0, -2, 30, 10763, 239, 0, 0, 0, 0, 0
2510
2511+EEMUMTSINTRA: 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
2512
2513+EEMUMTSINTRA: 29, 0, 0, 0, 0, -115, 0, 0, 65534, 30, 10763, 239
2514
2515// index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
2516+EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
2517
2518+EEMUMTSINTERRAT: 1, -107, -1, -1, 0, 0, 65534, 1, 72, 49, 0
2519
2520+EEMUMTSINTERRAT: 2, -1, -1, 0, 0, 65534, 2, 119, 15, 32768, 149
2521
2522+EEMUMTSINTERRAT: 3, -1, 0, 0, -2, 3, 121, 23, 0, 0, 0
2523
2524+EEMGINFO: 3, 1
2525
2526OK
2527
2528
2529// GSM
2530AT+EEMGINFO?
2531+EEMGINFOBASIC: 2
2532
2533// mcc, mnc_len, mnc, lac, ci, nom, nco,
2534// bsic, C1, C2, TA, TxPwr,
2535// RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
2536// ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
2537// bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
2538// ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
2539// gsmBand,channelMode
2540+EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
254163, 36, 146, 1, 7,
254246, 42, 42, 7, 0,
254353, 0, 8, 0, 1, 6, 53,
25442, 0, 146, 42, 54, 0, 1,
25451, 32, 0, 0, 0, 0,
25460, 0
2547
2548// PS_attached, attach_type, service_type, tx_power, c_value,
2549// ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
2550// gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
2551// pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
2552+EEMGINFOPS: 1, 255, 0, 0, 0,
25530, 0, 268435501, 1, 0, 0,
25544, 0, 96, 0, 0, 0,
25550, 0, 0, 65535, 0, 13350
2556
2557+EEMGINFO: 0, 0
2558
2559OK
2560
2561*/
2562static int req_cell_info_get(int *cme_err)
2563{
2564 ATResponse *response = NULL;
2565 int tmp_int;
2566 int buff_size = 0;
2567 // AT+EEMOPT=1 in the first.
2568 int err = at_send_command("AT+EEMOPT=1", &response);
2569 if (err < 0 || response->success == 0){
2570 *cme_err = at_get_cme_error(response);
2571 goto exit;
2572 }
2573
2574 // Reset buffer in the first.
2575 memset(&cell_info, 0xFF, sizeof(mbtK_cell_pack_info_t));
2576 cell_info.running = true;
2577 cell_info.cell_num = 0;
2578
2579 err = at_send_command_singleline("AT+EEMGINFO?", "+EEMGINFO:", &response);
2580 if (err < 0 || response->success == 0 || !response->p_intermediates){
2581 *cme_err = at_get_cme_error(response);
2582 goto exit;
2583 }
2584
2585 // Now, cell infomation has get from URC message.
2586
2587 char *line = response->p_intermediates->line;
2588 err = at_tok_start(&line);
2589 if (err < 0)
2590 {
2591 goto exit;
2592 }
2593 err = at_tok_nextint(&line, &tmp_int);
2594 if (err < 0)
2595 {
2596 goto exit;
2597 }
2598 err = at_tok_nextint(&line, &tmp_int);
2599 if (err < 0)
2600 {
2601 goto exit;
2602 }
2603
2604 cell_info.type = (uint8)tmp_int;
2605 cell_info.running = false;
2606
2607#if 0
2608 while(lines_ptr)
2609 {
2610 // LTE
2611 if(strStartsWith(line, "+EEMLTESVC:")) // LTE Server Cell
2612 {
2613
2614 }
b.liue0ab2442024-02-06 18:53:28 +08002615 else if(strStartsWith(line, "+EEMLTEINTER:")) // LTE
liubin281ac462023-07-19 14:22:54 +08002616 {
2617
2618 }
b.liue0ab2442024-02-06 18:53:28 +08002619 else if(strStartsWith(line, "+EEMLTEINTRA:")) // LTE
liubin281ac462023-07-19 14:22:54 +08002620 {
2621
2622 }
b.liue0ab2442024-02-06 18:53:28 +08002623 else if(strStartsWith(line, "+EEMLTEINTERRAT:")) // LTE
liubin281ac462023-07-19 14:22:54 +08002624 {
2625
2626 }
2627 else if(strStartsWith(line, "+EEMGINFO:")) // <state>: 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode 3: invalid state
2628 // <nw_type>: 0: GSM 1: UMTS 2: LTE
2629 {
2630
2631 }
2632 // WCDMA
2633 else if(strStartsWith(line, "+EEMUMTSSVC:")) // WCDMA Server Cell
2634 {
2635
2636 }
b.liue0ab2442024-02-06 18:53:28 +08002637 else if(strStartsWith(line, "+EEMUMTSINTRA:")) // WCDMA
liubin281ac462023-07-19 14:22:54 +08002638 {
2639
2640 }
b.liue0ab2442024-02-06 18:53:28 +08002641 else if(strStartsWith(line, "+EEMUMTSINTERRAT:")) // WCDMA
liubin281ac462023-07-19 14:22:54 +08002642 {
2643
2644 }
2645 // GSM
2646 else if(strStartsWith(line, "+EEMGINFOBASIC:")) // Basic information in GSM
2647 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
2648 {
2649
2650 }
2651 else if(strStartsWith(line, "+EEMGINFOSVC:")) // GSM Server Cell
2652 {
2653
2654 }
b.liue0ab2442024-02-06 18:53:28 +08002655 else if(strStartsWith(line, "+EEMGINFOPS:")) // PS
liubin281ac462023-07-19 14:22:54 +08002656 {
2657
2658 }
2659
2660
2661 lines_ptr = lines_ptr->p_next;
2662 }
2663#endif
2664
2665exit:
2666 at_response_free(response);
2667 return buff_size;
2668}
2669
2670static int req_cell_info_set(const char *cmgl, char *reg, int len, int *cme_err)
2671{
2672 printf("req_cmgl_set(2)-----------------start\n");
2673 printf("cmgl:%s\n", cmgl);
2674 ATResponse *response = NULL;
2675 char cmd[30] = {0};
2676 char data[218] = {0};
2677 int err = 0;
2678
2679 memcpy(data, cmgl, len);
2680
2681 sprintf(cmd, "at*cell=%s", data);
2682 printf("cmd:%s\n", cmd);
2683
2684 if(strlen(cmd) > 0)
2685 {
2686 err = at_send_command_multiline(cmd, "", &response);
2687 if (err < 0 || response->success == 0 || !response->p_intermediates){
2688 *cme_err = at_get_cme_error(response);
2689 // printf("at_send_command_multiline() is err-----------------\n");
2690 goto exit;
2691 }
2692
2693 ATLine* lines_ptr = response->p_intermediates;
2694 char *line = NULL;
2695 int reg_len = 0;
2696 bool flag = false;
2697 while(lines_ptr)
2698 {
2699 line = lines_ptr->line;
2700 if(line ==NULL)
2701 {
2702 printf("line is null----------------------\n");
2703 }
2704 printf("-----line:%s\n", line);
2705
2706 lines_ptr = lines_ptr->p_next;
2707 }
2708 }
2709 err = 0;
2710 memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss"));
2711exit:
2712 at_response_free(response);
2713 printf("req_cell_info_set()-----------------end\n");
2714 return err;
2715}
2716
2717
2718
2719/*
2720AT+CSQ
2721+CSQ: 31,99
2722
2723OK
2724
2725AT+CESQ
2726+CESQ: 60,99,255,255,20,61
2727
2728OK
2729
2730AT+COPS?
2731+COPS: 0,2,"46001",7
2732
2733OK
2734
2735*/
2736static int req_net_signal_get(mbtk_signal_info_t *signal, int *cme_err)
2737{
2738 ATResponse *response = NULL;
2739 int tmp_int;
2740 char *tmp_ptr = NULL;
2741 // AT+EEMOPT=1 in the first.
2742 int err = at_send_command_singleline("AT+CSQ", "+CSQ:", &response);
2743 if (err < 0 || response->success == 0 || !response->p_intermediates){
2744 if(cme_err != NULL)
2745 *cme_err = at_get_cme_error(response);
2746 err = -1;
2747 goto exit;
2748 }
2749
2750 char *line = response->p_intermediates->line;
2751 err = at_tok_start(&line);
2752 if (err < 0)
2753 {
2754 goto exit;
2755 }
2756 err = at_tok_nextint(&line, &tmp_int);
2757 if (err < 0)
2758 {
2759 goto exit;
2760 }
2761 signal->rssi = (uint8)tmp_int;
2762 at_response_free(response);
2763
2764 err = at_send_command_singleline("AT+CESQ", "+CESQ:", &response);
2765 if (err < 0 || response->success == 0 || !response->p_intermediates){
2766 if(cme_err != NULL)
2767 *cme_err = at_get_cme_error(response);
2768 err = -1;
2769 goto exit;
2770 }
2771
2772 line = response->p_intermediates->line;
2773 err = at_tok_start(&line);
2774 if (err < 0)
2775 {
2776 goto exit;
2777 }
2778 err = at_tok_nextint(&line, &tmp_int);
2779 if (err < 0)
2780 {
2781 goto exit;
2782 }
2783 signal->rxlev = (uint8)tmp_int;
2784
2785 err = at_tok_nextint(&line, &tmp_int);
2786 if (err < 0)
2787 {
2788 goto exit;
2789 }
2790 signal->ber = (uint8)tmp_int;
2791
2792 err = at_tok_nextint(&line, &tmp_int);
2793 if (err < 0)
2794 {
2795 goto exit;
2796 }
2797 signal->rscp = (uint8)tmp_int;
2798
2799 err = at_tok_nextint(&line, &tmp_int);
2800 if (err < 0)
2801 {
2802 goto exit;
2803 }
2804 signal->ecno = (uint8)tmp_int;
2805
2806 err = at_tok_nextint(&line, &tmp_int);
2807 if (err < 0)
2808 {
2809 goto exit;
2810 }
2811 signal->rsrq = (uint8)tmp_int;
2812
2813 err = at_tok_nextint(&line, &tmp_int);
2814 if (err < 0)
2815 {
2816 goto exit;
2817 }
2818 signal->rsrp = (uint8)tmp_int;
2819
2820 at_response_free(response);
2821 err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
2822 if (err < 0 || response->success == 0 || !response->p_intermediates){
2823 if(cme_err != NULL)
2824 *cme_err = at_get_cme_error(response);
2825 err = -1;
2826 goto exit;
2827 }
2828 line = response->p_intermediates->line;
2829 err = at_tok_start(&line);
2830 if (err < 0)
2831 {
2832 goto exit;
2833 }
2834 err = at_tok_nextint(&line, &tmp_int);
2835 if (err < 0)
2836 {
2837 goto exit;
2838 }
2839 if(!at_tok_hasmore(&line)) {
2840 goto exit;
2841 }
2842 err = at_tok_nextint(&line, &tmp_int);
2843 if (err < 0)
2844 {
2845 goto exit;
2846 }
2847 err = at_tok_nextstr(&line, &tmp_ptr);
2848 if (err < 0)
2849 {
2850 goto exit;
2851 }
2852 err = at_tok_nextint(&line, &tmp_int);
2853 if (err < 0)
2854 {
2855 goto exit;
2856 }
2857 signal->type = (uint8)tmp_int;
2858 net_info.net_type = signal->type;
2859
2860exit:
2861 at_response_free(response);
2862 return err;
2863}
2864
2865/*
2866AT+CREG=3
2867OK
2868
2869AT+CREG?
2870+CREG: 3,1,"8330","06447340",7
2871
2872OK
2873
2874AT+CREG?
2875+CREG: 3,0
2876
2877OK
2878
2879AT+CEREG?
2880+CEREG: 3,1,"8330","06447340",7
2881
2882OK
2883
2884
2885AT+CIREG?
2886+CIREG: 2,1,15
2887
2888OK
2889
2890AT+CIREG?
2891+CIREG: 0
2892
2893OK
2894
2895
2896*/
2897static int req_net_reg_get(mbtk_net_reg_info_t *reg, int *cme_err)
2898{
2899 ATResponse *response = NULL;
2900 int tmp_int;
2901 char *tmp_str = NULL;
2902 int err = at_send_command("AT+CREG=3", &response);
2903 if (err < 0 || response->success == 0){
2904 *cme_err = at_get_cme_error(response);
2905 goto exit;
2906 }
2907 at_response_free(response);
2908
2909 err = at_send_command_multiline("AT+CREG?", "+CREG:", &response);
2910 if (err < 0 || response->success == 0 || !response->p_intermediates){
2911 *cme_err = at_get_cme_error(response);
2912 goto exit;
2913 }
2914
2915 char *line = response->p_intermediates->line;
2916 err = at_tok_start(&line);
2917 if (err < 0)
2918 {
2919 goto exit;
2920 }
2921 err = at_tok_nextint(&line, &tmp_int); // n
2922 if (err < 0)
2923 {
2924 goto exit;
2925 }
2926 err = at_tok_nextint(&line, &tmp_int);// stat
2927 if (err < 0)
2928 {
2929 goto exit;
2930 }
2931 reg->call_state = (uint8)tmp_int;
2932
2933 if(at_tok_hasmore(&line)) {
2934 err = at_tok_nextstr(&line, &tmp_str); // lac
2935 if (err < 0)
2936 {
2937 goto exit;
2938 }
2939 reg->lac = strtol(tmp_str, NULL, 16);
2940
2941 err = at_tok_nextstr(&line, &tmp_str); // ci
2942 if (err < 0)
2943 {
2944 goto exit;
2945 }
2946 reg->ci = strtol(tmp_str, NULL, 16);
2947
2948 err = at_tok_nextint(&line, &tmp_int);// AcT
2949 if (err < 0)
2950 {
2951 goto exit;
2952 }
2953 reg->type = (uint8)tmp_int;
2954 }
2955 at_response_free(response);
2956
2957 err = at_send_command_multiline("AT+CEREG?", "+CEREG:", &response);
2958 if (err < 0 || response->success == 0 || !response->p_intermediates){
2959 *cme_err = at_get_cme_error(response);
2960 goto exit;
2961 }
2962
2963 line = response->p_intermediates->line;
2964 err = at_tok_start(&line);
2965 if (err < 0)
2966 {
2967 goto exit;
2968 }
2969 err = at_tok_nextint(&line, &tmp_int); // n
2970 if (err < 0)
2971 {
2972 goto exit;
2973 }
2974 err = at_tok_nextint(&line, &tmp_int);// stat
2975 if (err < 0)
2976 {
2977 goto exit;
2978 }
2979 reg->data_state = (uint8)tmp_int;
2980
2981 if(reg->lac == 0 && at_tok_hasmore(&line)) {
2982 err = at_tok_nextstr(&line, &tmp_str); // lac
2983 if (err < 0)
2984 {
2985 goto exit;
2986 }
2987 reg->lac = strtol(tmp_str, NULL, 16);
2988
2989 err = at_tok_nextstr(&line, &tmp_str); // ci
2990 if (err < 0)
2991 {
2992 goto exit;
2993 }
2994 reg->ci = strtol(tmp_str, NULL, 16);
2995
2996 err = at_tok_nextint(&line, &tmp_int);// AcT
2997 if (err < 0)
2998 {
2999 goto exit;
3000 }
3001 reg->type = (uint8)tmp_int;
3002 }
3003 at_response_free(response);
3004
3005 err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response);
3006 if (err < 0 || response->success == 0 || !response->p_intermediates){
3007 reg->ims_state = (uint8)0;
3008 err = 0;
3009 goto exit;
3010 }
3011 line = response->p_intermediates->line;
3012 err = at_tok_start(&line);
3013 if (err < 0)
3014 {
3015 goto exit;
3016 }
3017 err = at_tok_nextint(&line, &tmp_int); // n/stat
3018 if (err < 0)
3019 {
3020 goto exit;
3021 }
3022 if(at_tok_hasmore(&line)) {
3023 err = at_tok_nextint(&line, &tmp_int);// stat
3024 if (err < 0)
3025 {
3026 goto exit;
3027 }
3028 reg->ims_state = (uint8)tmp_int;
3029 } else {
3030 reg->ims_state = (uint8)tmp_int;
3031 }
3032
3033exit:
3034 at_response_free(response);
3035 return err;
3036}
3037
r.xiao06db9a12024-04-14 18:51:15 -07003038
3039static int net_ims_set(uint8 reg, int *cme_err)
3040{
3041 ATResponse *response = NULL;
3042 char cmd[30] = {0};
3043 int err = -1;
3044
b.liufdf03172024-06-07 15:01:29 +08003045 sprintf(cmd, "AT+ACONFIG=\"IMSD=%d\"", reg);
r.xiao06db9a12024-04-14 18:51:15 -07003046 err = at_send_command(cmd, &response);
3047 LOG("cmd : %s", cmd);
3048
3049 if (err < 0 || response->success == 0){
3050 *cme_err = at_get_cme_error(response);
3051 goto exit;
3052 }
3053
3054exit:
3055 at_response_free(response);
3056 return err;
3057}
3058
3059
3060static int net_ims_get(int *reg, int *cme_err)
3061{
3062 ATResponse *response = NULL;
b.liufdf03172024-06-07 15:01:29 +08003063 int tmp_int, tmp_reg = 0;
3064 int err;
3065 char *tmp_str = NULL;
3066
3067 err = at_send_command_singleline("AT+ACONFIG?", "", &response);
3068 if (err < 0 || response->success == 0 || !response->p_intermediates){
3069 tmp_reg = 0;
3070 err = 0;
3071 goto exit;
3072 }
3073 if(response->p_intermediates->line) {
3074 char *ptr = strstr(response->p_intermediates->line, "IMSD=");
3075 if(ptr) {
3076 tmp_reg = atoi(ptr + strlen("IMSD="));
3077 }
3078 }
3079
3080 LOG("net_ims_get reg : %u", tmp_reg);
3081
3082exit:
3083 at_response_free(response);
3084 *reg = tmp_reg;
3085 return err;
3086}
3087
3088static int net_ims_reg_state_get(int *reg, int *cme_err)
3089{
3090 ATResponse *response = NULL;
3091 int tmp_int, tmp_reg = -1;
r.xiao06db9a12024-04-14 18:51:15 -07003092 int err;
3093 char *tmp_str = NULL;
3094
3095 err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response);
3096 if (err < 0 || response->success == 0 || !response->p_intermediates){
3097 tmp_reg = 0;
3098 err = 0;
3099 goto exit;
3100 }
3101 char *line = response->p_intermediates->line;
3102 err = at_tok_start(&line);
3103 if (err < 0)
3104 {
3105 goto exit;
3106 }
3107 err = at_tok_nextint(&line, &tmp_int); // n/stat
3108 if (err < 0)
3109 {
3110 goto exit;
3111 }
liuyangc4ca9592024-06-06 15:43:50 +08003112
b.liufdf03172024-06-07 15:01:29 +08003113 if(at_tok_hasmore(&line)) {
3114 err = at_tok_nextint(&line, &tmp_int);// stat
3115 if (err < 0)
3116 {
3117 goto exit;
3118 }
3119 tmp_reg = tmp_int;
3120 } else {
3121 tmp_reg = tmp_int;
3122 }
r.xiao06db9a12024-04-14 18:51:15 -07003123
3124 LOG("net_ims_get reg : %u", tmp_reg);
3125
3126exit:
3127 at_response_free(response);
3128 *reg = tmp_reg;
3129 return err;
3130}
3131
3132
b.liufdf03172024-06-07 15:01:29 +08003133
liubin281ac462023-07-19 14:22:54 +08003134/*
3135AT+CGDCONT?
3136+CGDCONT: 1,"IPV4V6","cmnet.MNC000.MCC460.GPRS","10.131.67.146 254.128.0.0.0.0.0.0.0.1.0.2.200.2.158.0",0,0,,,,
3137
3138+CGDCONT: 8,"IPV4V6","IMS","254.128.0.0.0.0.0.0.0.1.0.2.200.2.160.160",0,0,0,2,1,1
3139
3140OK
3141
3142
3143*/
wangyouqianged88c722023-11-22 16:33:43 +08003144#ifdef MBTK_AF_SUPPORT
3145mbtk_ip_type_enum default_iptype = MBTK_IP_TYPE_IPV4V6;
3146#endif
3147
liubin281ac462023-07-19 14:22:54 +08003148static int req_apn_get(void *data, int *data_len, int *cme_err)
3149{
3150 ATResponse *response = NULL;
3151 int err = at_send_command_multiline("AT+CGDCONT?", "+CGDCONT:", &response);
3152
3153 if (err < 0 || response->success == 0 || !response->p_intermediates){
3154 *cme_err = at_get_cme_error(response);
3155 goto exit;
3156 }
3157
3158 ATLine* lines_ptr = response->p_intermediates;
3159 char *line = NULL;
3160 int tmp_int;
3161 char *tmp_str = NULL;
3162 /*
3163 <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>...
3164 <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
3165 */
3166 uint8* apn_num = (uint8*)data;
3167 uint8* data_ptr = (uint8*)(data + sizeof(uint8)); // Jump apn_num[1]
3168 mbtk_apn_info_t apn;
3169 while(lines_ptr)
3170 {
3171 line = lines_ptr->line;
3172 err = at_tok_start(&line);
3173 if (err < 0)
3174 {
3175 goto exit;
3176 }
3177
3178 err = at_tok_nextint(&line, &tmp_int); // cid
3179 if (err < 0)
3180 {
3181 goto exit;
3182 }
3183 // Only get CID 1-7
3184 if(tmp_int >= MBTK_APN_CID_MIN && tmp_int <= MBTK_APN_CID_MAX) {
3185 memset(&apn, 0x0, sizeof(mbtk_apn_info_t));
3186 apn.cid = tmp_int;
3187 *data_ptr++ = (uint8)tmp_int; // cid
3188
3189 err = at_tok_nextstr(&line, &tmp_str);// ip type
3190 if (err < 0)
3191 {
3192 goto exit;
3193 }
3194 if(!strcasecmp(tmp_str, "IP")) {
3195 *data_ptr++ = (uint8)MBTK_IP_TYPE_IP;
3196 apn.ip_type = MBTK_IP_TYPE_IP;
3197 } else if(!strcasecmp(tmp_str, "IPV6")) {
3198 *data_ptr++ = (uint8)MBTK_IP_TYPE_IPV6;
3199 apn.ip_type = MBTK_IP_TYPE_IPV6;
3200 } else if(!strcasecmp(tmp_str, "IPV4V6")) {
3201 *data_ptr++ = (uint8)MBTK_IP_TYPE_IPV4V6;
3202 apn.ip_type = MBTK_IP_TYPE_IPV4V6;
3203 } else {
3204 *data_ptr++ = (uint8)MBTK_IP_TYPE_PPP;
3205 apn.ip_type = MBTK_IP_TYPE_PPP;
3206 }
3207
wangyouqianged88c722023-11-22 16:33:43 +08003208#ifdef MBTK_AF_SUPPORT
3209 if(apn.cid == 1)
3210 {
3211 default_iptype = apn.ip_type;
3212 }
3213#endif
liubin281ac462023-07-19 14:22:54 +08003214 err = at_tok_nextstr(&line, &tmp_str); // apn
3215 if (err < 0)
3216 {
3217 goto exit;
3218 }
3219 if(str_empty(tmp_str)) {
3220 uint16_2_byte((uint16)0, data_ptr, false);
3221 data_ptr += sizeof(uint16);
3222 } else {
3223 uint16_2_byte((uint16)strlen(tmp_str), data_ptr, false);
3224 data_ptr += sizeof(uint16);
3225 memcpy(data_ptr, tmp_str, strlen(tmp_str));
3226 data_ptr += strlen(tmp_str);
3227 memcpy(apn.apn, tmp_str, strlen(tmp_str));
3228 }
3229
3230 if(apn_user_pass_set_by_cid(apn.cid, &apn)) {
3231 // user
3232 uint16_2_byte((uint16)0, data_ptr, false);
3233 data_ptr += sizeof(uint16);
3234
3235 // pass
3236 uint16_2_byte((uint16)0, data_ptr, false);
3237 data_ptr += sizeof(uint16);
3238
3239 // auth
3240 uint16_2_byte((uint16)0, data_ptr, false);
3241 data_ptr += sizeof(uint16);
3242 } else {
3243 // user
3244 if(str_empty(apn.user)) {
3245 uint16_2_byte((uint16)0, data_ptr, false);
3246 data_ptr += sizeof(uint16);
3247 } else {
3248 uint16_2_byte((uint16)strlen(apn.user), data_ptr, false);
3249 data_ptr += sizeof(uint16);
3250 memcpy(data_ptr, apn.user, strlen(apn.user));
3251 data_ptr += strlen(apn.user);
3252 }
3253
3254 // pass
3255 if(str_empty(apn.pass)) {
3256 uint16_2_byte((uint16)0, data_ptr, false);
3257 data_ptr += sizeof(uint16);
3258 } else {
3259 uint16_2_byte((uint16)strlen(apn.pass), data_ptr, false);
3260 data_ptr += sizeof(uint16);
3261 memcpy(data_ptr, apn.pass, strlen(apn.pass));
3262 data_ptr += strlen(apn.pass);
3263 }
3264
3265 // auth
3266 if(str_empty(apn.auth)) {
3267 uint16_2_byte((uint16)0, data_ptr, false);
3268 data_ptr += sizeof(uint16);
3269 } else {
3270 uint16_2_byte((uint16)strlen(apn.auth), data_ptr, false);
3271 data_ptr += sizeof(uint16);
3272 memcpy(data_ptr, apn.auth, strlen(apn.auth));
3273 data_ptr += strlen(apn.auth);
3274 }
3275 }
3276
3277 (*apn_num)++;
3278 }
3279
3280 lines_ptr = lines_ptr->p_next;
3281 }
3282
3283 *data_len = data_ptr - (uint8*)data;
3284
3285 goto exit;
3286exit:
3287 at_response_free(response);
3288 return err;
3289}
3290
3291#if 0
3292/*
3293LTE APN
3294AT+CFUN=4
3295AT*CGDFLT=1,IP,"private.vpdn",1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1
3296AT*CGDFAUTH=1,2,"noc@njcc.vpdn.js","123456"
3297AT+CFUN=1
3298AT+CEREG?
3299AT+CGDCONT?
3300
33012/3G APN
3302AT+CGREG?
3303AT+CGDCONT=6,IP,"private.vpdn"
3304AT*AUTHREQ=6,2,"noc@njcc.vpdn.js","123456"
3305AT+CGDATA="",6
3306AT+CGDCONT?
3307*/
3308static int req_apn_set_username(mbtk_apn_info_t *apn, int *cme_err)
3309{
3310 ATResponse *response = NULL;
3311 char cmd[400] = {0};
3312 int index = 0;
3313 int err = 0;
3314
3315 err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
3316 if (err < 0 || response->success == 0 || !response->p_intermediates){
3317 if(cme_err != NULL)
3318 *cme_err = at_get_cme_error(response);
3319 err = -1;
3320 goto apn_set;
3321 }
3322
3323 int tmp_int = 0;
3324 int state=0;
3325 char cmd_buf[64];
3326 char *line = response->p_intermediates->line;
3327 err = at_tok_start(&line);
3328 if (err < 0)
3329 {
3330 goto apn_set;
3331 }
3332 err = at_tok_nextint(&line, &tmp_int);
3333 if (err < 0)
3334 {
3335 goto apn_set;
3336 }
3337 err = at_tok_nextint(&line, &tmp_int);
3338 if (err < 0)
3339 {
3340 goto apn_set;
3341 }
3342 err = at_tok_nextstr(&line, &cmd_buf);
3343 if (err < 0)
3344 {
3345 goto apn_set;
3346 }
3347 err = at_tok_nextint(&line, &tmp_int);
3348 if (err < 0)
3349 {
3350 goto apn_set;
3351 }
3352 else
3353 state = tmp_int;
3354
3355apn_set:
3356 at_response_free(response);
3357 *cme_err = MBTK_INFO_ERR_CME_NON;
3358 //if(state == 7 && apn->cid == 1) //LTE && cid = 1
3359 if(0) //LTE && cid = 1
3360 {
3361 err = at_send_command("AT+CFUN=4", &response);
3362 if (err < 0 || response->success == 0){
3363 *cme_err = at_get_cme_error(response);
3364 goto exit;
3365 }
3366 at_response_free(response);
3367
3368 memset(cmd, 0, 400);
3369 index = 0;
3370 index += sprintf(cmd, "AT*CGDFLT=%d,", 1);
3371 switch(apn->ip_type) {
3372 case MBTK_IP_TYPE_IP: {
3373 index += sprintf(cmd + index,"\"IP\",");
3374 break;
3375 }
3376 case MBTK_IP_TYPE_IPV6: {
3377 index += sprintf(cmd + index,"\"IPV6\",");
3378 break;
3379 }
3380 case MBTK_IP_TYPE_IPV4V6: {
3381 index += sprintf(cmd + index,"\"IPV4V6\",");
3382 break;
3383 }
3384 default: {
3385 index += sprintf(cmd + index,"\"PPP\",");
3386 break;
3387 }
3388 }
3389
3390 index += sprintf(cmd + index,"\"%s\",1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1",apn->apn);
3391 err = at_send_command(cmd, &response);
3392 if (err < 0 || response->success == 0){
3393 *cme_err = at_get_cme_error(response);
3394 goto exit;
3395 }
3396 at_response_free(response);
3397
3398 memset(cmd, 0, 400);
3399 int cmd_auth=0;
3400 if(strstr(apn->auth,"NONE"))
3401 cmd_auth = 0;
3402 else if(strstr(apn->auth,"PAP"))
3403 cmd_auth = 1;
3404 else if(strstr(apn->auth,"CHAP"))
3405 cmd_auth = 2;
3406 else if(strstr(apn->auth,"PAP AND CHAP"))
3407 cmd_auth = 3;
3408 else
3409 goto exit;
3410
3411 sprintf(cmd,"AT*CGDFAUTH=1,%d,%s,%s",cmd_auth,apn->user,apn->pass);
3412
3413 err = at_send_command(cmd, &response);
3414 if (err < 0 || response->success == 0){
3415 *cme_err = at_get_cme_error(response);
3416 goto exit;
3417 }
3418 }
3419 else //2/3G
3420 {
3421 memset(cmd,0,400);
3422 index = 0;
3423 index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid);
3424 switch(apn->ip_type) {
3425 case MBTK_IP_TYPE_IP: {
3426 index += sprintf(cmd + index,"\"IP\",");
3427 break;
3428 }
3429 case MBTK_IP_TYPE_IPV6: {
3430 index += sprintf(cmd + index,"\"IPV6\",");
3431 break;
3432 }
3433 case MBTK_IP_TYPE_IPV4V6: {
3434 index += sprintf(cmd + index,"\"IPV4V6\",");
3435 break;
3436 }
3437 default: {
3438 index += sprintf(cmd + index,"\"PPP\",");
3439 break;
3440 }
3441 }
3442 index += sprintf(cmd + index, "\"%s\"", apn->apn);
3443
3444 err = at_send_command(cmd, &response);
3445 if (err < 0 || response->success == 0){
3446 *cme_err = at_get_cme_error(response);
3447 goto exit;
3448 }
3449 at_response_free(response);
3450
3451 memset(cmd,0,400);
3452 int cmd_auth=0;
3453 if(strstr(apn->auth,"NONE"))
3454 cmd_auth = 0;
3455 else if(strstr(apn->auth,"PAP"))
3456 cmd_auth = 1;
3457 else if(strstr(apn->auth,"CHAP"))
3458 cmd_auth = 2;
3459 else if(strstr(apn->auth,"PAP AND CHAP"))
3460 cmd_auth = 3;
3461 else
3462 goto exit;
3463
3464 sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass);
3465 err = at_send_command(cmd, &response);
3466 if (err < 0 || response->success == 0){
3467 *cme_err = at_get_cme_error(response);
3468 goto exit;
3469 }
3470 }
3471
3472exit:
3473 at_response_free(response);
3474 return err;
3475}
3476#endif
3477
3478/*
3479AT+CGDCONT=1,"IPV4V6","cmnet"
3480OK
3481
3482AT*CGDFLT=1,"IPv4v6","reliance.grevpdn.zj",,,,,,,,,,,,,,,,,,1
3483OK
3484
3485*/
3486static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err)
3487{
3488 ATResponse *response = NULL;
3489 char cmd[400] = {0};
3490 int index = 0;
3491 int err = 0;
3492
3493 index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid);
3494 switch(apn->ip_type) {
3495 case MBTK_IP_TYPE_IP: {
3496 index += sprintf(cmd + index,"\"IP\",");
3497 break;
3498 }
3499 case MBTK_IP_TYPE_IPV6: {
3500 index += sprintf(cmd + index,"\"IPV6\",");
3501 break;
3502 }
3503 case MBTK_IP_TYPE_IPV4V6: {
3504 index += sprintf(cmd + index,"\"IPV4V6\",");
3505 break;
3506 }
3507 default: {
3508 index += sprintf(cmd + index,"\"PPP\",");
3509 break;
3510 }
3511 }
3512 if(strlen(apn->apn) > 0) {
3513 index += sprintf(cmd + index,"\"%s\"", apn->apn);
b.liudfec1e12024-06-06 16:38:59 +08003514 }
liubin281ac462023-07-19 14:22:54 +08003515
3516 err = at_send_command(cmd, &response);
3517 if (err < 0 || response->success == 0){
3518 if(cme_err) {
3519 *cme_err = at_get_cme_error(response);
3520 }
3521 goto exit;
3522 }
3523
3524 if(!str_empty(apn->user) || !str_empty(apn->pass)) {
3525 at_response_free(response);
3526
3527 memset(cmd,0,400);
3528 int cmd_auth=0;
3529 if(strstr(apn->auth,"NONE"))
3530 cmd_auth = 0;
3531 else if(strstr(apn->auth,"PAP"))
3532 cmd_auth = 1;
3533 else if(strstr(apn->auth,"CHAP"))
3534 cmd_auth = 2;
3535#if 0
3536 else if(strstr(apn->auth,"PAP AND CHAP"))
3537 cmd_auth = 3;
3538#endif
3539 else
3540 goto exit;
3541
3542 sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass);
3543 err = at_send_command(cmd, &response);
3544 if (err < 0 || response->success == 0){
3545 *cme_err = at_get_cme_error(response);
3546 goto exit;
3547 }
3548 }
3549
3550exit:
3551 at_response_free(response);
3552 return err;
3553}
3554
liuyang1cefd852024-04-24 18:30:53 +08003555static int req_apn_del(int data, int *cme_err)
liuyang0e49d9a2024-04-23 21:04:54 +08003556{
3557 ATResponse *response = NULL;
3558 char cmd[64]={0};
liuyang1cefd852024-04-24 18:30:53 +08003559 sprintf(cmd, "AT+CGDCONT=%d", data);
liuyang0e49d9a2024-04-23 21:04:54 +08003560 int err = at_send_command(cmd, &response);
3561 if (err < 0 || response->success == 0){
3562 if(cme_err) {
3563 *cme_err = at_get_cme_error(response);
3564 }
3565 goto exit;
3566 }
3567
3568exit:
3569 at_response_free(response);
3570 return err;
3571}
3572
3573
liubin281ac462023-07-19 14:22:54 +08003574int wait_cgact_complete(int timeout)
3575{
3576 int count = timeout * 10; // timeout * 1000 / 100
3577 int i = 0;
3578
3579 while(cgact_wait.waitting && i < count) {
3580 i++;
3581 usleep(100000); // 100ms
3582 }
3583
3584 if(i == count) { // Timeout
3585 return -1;
3586 } else {
3587 return 0;
3588 }
3589}
3590
3591/*
3592AT+CGDATA="",6
3593CONNECT
3594
3595OK
3596
3597AT+CFUN=1
3598
3599OK
3600
3601*/
3602static int req_data_call_user_start(int cid, int *cme_err)
3603{
3604 ATResponse *response = NULL;
3605 char cmd[400] = {0};
3606 int index = 0;
3607 int err = 0;
3608
3609 err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
3610 if (err < 0 || response->success == 0 || !response->p_intermediates){
3611 if(cme_err != NULL)
3612 *cme_err = at_get_cme_error(response);
3613 err = -1;
3614 goto exit;
3615 }
3616
3617 int tmp_int;
3618 char cmd_buf[64];
3619 char *line = response->p_intermediates->line;
3620 err = at_tok_start(&line);
3621 if (err < 0)
3622 {
3623 goto exit;
3624 }
3625 err = at_tok_nextint(&line, &tmp_int);
3626 if (err < 0)
3627 {
3628 goto exit;
3629 }
3630 err = at_tok_nextint(&line, &tmp_int);
3631 if (err < 0)
3632 {
3633 goto exit;
3634 }
3635 err = at_tok_nextstr(&line, &cmd_buf);
3636 if (err < 0)
3637 {
3638 goto exit;
3639 }
3640 err = at_tok_nextint(&line, &tmp_int);
3641 if (err < 0)
3642 {
3643 goto exit;
3644 }
3645 at_response_free(response);
3646
3647 if(tmp_int == 7 && cid == 1) //LTE && cid = 1
3648 {
3649 ATResponse *response = NULL;
3650 char cmd[400] = {0};
3651 int err = 0;
3652
3653 err = at_send_command("AT+CFUN=1", &response);
3654 if (err < 0 || response->success == 0){
3655 if(cme_err) {
3656 *cme_err = at_get_cme_error(response);
3657 }
3658 goto exit;
3659 }
3660 }
3661 else
3662 {
3663 ATResponse *response = NULL;
3664 char cmd[400] = {0};
3665 int err = 0;
3666 sprintf(cmd, "AT+CGDATA=\"\",%d", cid);
3667 err = at_send_command(cmd, &response);
3668 if (err < 0 || response->success == 0){
3669 if(cme_err) {
3670 *cme_err = at_get_cme_error(response);
3671 }
3672 goto exit;
3673 }
3674 }
3675
3676exit:
3677 at_response_free(response);
3678 return err;
3679}
3680
3681/*
3682AT+CGACT?
3683+CGACT: 1,1
3684+CGACT: 8,1
3685OK
3686
3687AT+CGACT=1,<cid>
3688OK
3689
3690*/
3691static int req_data_call_start(int cid, int *cme_err)
3692{
3693 ATResponse *response = NULL;
3694 char cmd[400] = {0};
3695 int err = 0;
3696#if 0
3697 err = at_send_command_multiline("AT+CGACT?", "+CGACT:", &response);
3698 if (err < 0 || response->success == 0 || !response->p_intermediates){
3699 *cme_err = at_get_cme_error(response);
3700 goto exit;
3701 }
3702 ATLine* lines_ptr = response->p_intermediates;
3703 char *line = NULL;
3704 int tmp_int;
3705 while(lines_ptr)
3706 {
3707 line = lines_ptr->line;
3708 err = at_tok_start(&line);
3709 if (err < 0)
3710 {
3711 goto exit;
3712 }
3713
3714 err = at_tok_nextint(&line, &tmp_int); // cid
3715 if (err < 0)
3716 {
3717 goto exit;
3718 }
3719 if(tmp_int == cid) { // Found cid
3720 err = at_tok_nextint(&line, &tmp_int); // cid
3721 if (err < 0)
3722 {
3723 goto exit;
3724 }
3725 if(tmp_int == 1) { // This cid has active.
3726 goto net_config;
3727 } else {
3728 goto cid_active;
3729 }
3730 break;
3731 }
3732
3733 lines_ptr = lines_ptr->p_next;
3734 }
3735
3736 if(lines_ptr == NULL) { // No found this cid.
3737 LOGE("No found cid : %d", cid);
3738 goto exit;
3739 }
3740 at_response_free(response);
3741
3742 // Start active cid.
3743cid_active:
3744#endif
3745
3746 sprintf(cmd, "AT+CGACT=1,%d", cid);
3747 err = at_send_command(cmd, &response);
3748 if (err < 0 || response->success == 0){
3749 if(cme_err) {
3750 *cme_err = at_get_cme_error(response);
3751 }
3752 goto exit;
3753 }
3754
3755exit:
3756 at_response_free(response);
3757 return err;
3758}
3759
3760/*
3761AT+CGACT=0,<cid>
3762OK
3763
3764*/
3765static int req_data_call_stop(int cid, int *cme_err)
3766{
3767 ATResponse *response = NULL;
3768 char cmd[400] = {0};
3769 int err = 0;
3770#if 0
3771 err = at_send_command_multiline("AT+CGACT?", "+CGACT:", &response);
3772 if (err < 0 || response->success == 0 || !response->p_intermediates){
3773 *cme_err = at_get_cme_error(response);
3774 goto exit;
3775 }
3776 ATLine* lines_ptr = response->p_intermediates;
3777 char *line = NULL;
3778 int tmp_int;
3779 while(lines_ptr)
3780 {
3781 line = lines_ptr->line;
3782 err = at_tok_start(&line);
3783 if (err < 0)
3784 {
3785 goto exit;
3786 }
3787
3788 err = at_tok_nextint(&line, &tmp_int); // cid
3789 if (err < 0)
3790 {
3791 goto exit;
3792 }
3793 if(tmp_int == cid) { // Found cid
3794 err = at_tok_nextint(&line, &tmp_int); // cid
3795 if (err < 0)
3796 {
3797 goto exit;
3798 }
3799 if(tmp_int == 1) { // This cid has active.
3800 goto net_config;
3801 } else {
3802 goto cid_active;
3803 }
3804 break;
3805 }
3806
3807 lines_ptr = lines_ptr->p_next;
3808 }
3809
3810 if(lines_ptr == NULL) { // No found this cid.
3811 LOGE("No found cid : %d", cid);
3812 goto exit;
3813 }
3814 at_response_free(response);
3815
3816 // Start active cid.
3817cid_active:
3818#endif
3819
3820 sprintf(cmd, "AT+CGACT=0,%d", cid);
3821 err = at_send_command(cmd, &response);
3822 if (err < 0 || response->success == 0){
3823 *cme_err = at_get_cme_error(response);
3824 goto exit;
3825 }
3826
3827exit:
3828 at_response_free(response);
3829 return err;
3830}
3831
3832/*
3833IPv4 : 10.255.74.26
3834IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239
3835*/
3836static bool is_ipv4(const char *ip)
3837{
3838 const char *ptr = ip;
3839 int count = 0;
3840 while(*ptr) {
3841 if(*ptr == '.')
3842 count++;
3843 ptr++;
3844 }
3845
3846 if(count == 3) {
3847 return true;
3848 } else {
3849 return false;
3850 }
3851}
3852
3853/*
3854AT+CGCONTRDP=1
3855+CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","10.255.74.26","","223.87.253.100","223.87.253.253","","",0,0
3856+CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239","","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.1","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.2","","",0,0
3857
3858OK
3859
3860*/
3861static int req_data_call_state_get(int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6, int *cme_err)
3862{
3863 ATResponse *response = NULL;
3864 char cmd[50] = {0};
3865 int err = 0;
3866
3867 sprintf(cmd, "AT+CGCONTRDP=%d", cid);
3868
3869 err = at_send_command_multiline(cmd, "+CGCONTRDP:", &response);
3870 if (err < 0 || response->success == 0 || !response->p_intermediates){
3871 *cme_err = at_get_cme_error(response);
3872 goto exit;
3873 }
3874 ATLine* lines_ptr = response->p_intermediates;
3875 char *line = NULL;
3876 int tmp_int;
3877 char *tmp_ptr = NULL;
3878 while(lines_ptr)
3879 {
3880 line = lines_ptr->line;
3881 err = at_tok_start(&line);
3882 if (err < 0)
3883 {
3884 goto exit;
3885 }
3886
3887 err = at_tok_nextint(&line, &tmp_int); // cid
3888 if (err < 0)
3889 {
3890 goto exit;
3891 }
3892 err = at_tok_nextint(&line, &tmp_int); // bearer_id
3893 if (err < 0)
3894 {
3895 goto exit;
3896 }
3897 err = at_tok_nextstr(&line, &tmp_ptr); // APN
3898 if (err < 0)
3899 {
3900 goto exit;
3901 }
3902
3903 err = at_tok_nextstr(&line, &tmp_ptr); // IP
3904 if (err < 0 || str_empty(tmp_ptr))
3905 {
3906 goto exit;
3907 }
3908 if(is_ipv4(tmp_ptr)) {
3909 if(inet_pton(AF_INET, tmp_ptr, &(ipv4->IPAddr)) < 0) {
3910 LOGE("inet_pton() fail.");
3911 err = -1;
3912 goto exit;
3913 }
3914
3915 ipv4->valid = true;
3916 //log_hex("IPv4", &(ipv4->IPAddr), sizeof(struct in_addr));
3917 } else {
3918 if(str_2_ipv6(tmp_ptr, &(ipv6->IPV6Addr))) {
3919 LOGE("str_2_ipv6() fail.");
3920 err = -1;
3921 goto exit;
3922 }
3923
3924 ipv6->valid = true;
3925 //log_hex("IPv6", &(ipv6->IPV6Addr), 16);
3926 }
3927
3928 err = at_tok_nextstr(&line, &tmp_ptr); // Gateway
3929 if (err < 0)
3930 {
3931 goto exit;
3932 }
3933 if(!str_empty(tmp_ptr)) { // No found gateway
3934 if(is_ipv4(tmp_ptr)) {
3935 if(inet_pton(AF_INET, tmp_ptr, &(ipv4->GateWay)) < 0) {
3936 LOGE("inet_pton() fail.");
3937 err = -1;
3938 goto exit;
3939 }
3940
3941 //log_hex("IPv4", &(ipv4->GateWay), sizeof(struct in_addr));
3942 } else {
3943 if(str_2_ipv6(tmp_ptr, &(ipv6->GateWay))) {
3944 LOGE("str_2_ipv6() fail.");
3945 err = -1;
3946 goto exit;
3947 }
3948
3949 //log_hex("IPv6", &(ipv6->GateWay), 16);
3950 }
3951 }
3952
3953 err = at_tok_nextstr(&line, &tmp_ptr); // prim_DNS
3954 if (err < 0)
3955 {
3956 goto exit;
3957 }
3958 if(!str_empty(tmp_ptr)) { // No found Primary DNS
3959 if(is_ipv4(tmp_ptr)) {
3960 if(inet_pton(AF_INET, tmp_ptr, &(ipv4->PrimaryDNS)) < 0) {
3961 LOGE("inet_pton() fail.");
3962 err = -1;
3963 goto exit;
3964 }
3965
3966 //log_hex("IPv4", &(ipv4->PrimaryDNS), sizeof(struct in_addr));
3967 } else {
3968 if(str_2_ipv6(tmp_ptr, &(ipv6->PrimaryDNS))) {
3969 LOGE("str_2_ipv6() fail.");
3970 err = -1;
3971 goto exit;
3972 }
3973
3974 //log_hex("IPv6", &(ipv6->PrimaryDNS), 16);
3975 }
3976 }
3977
3978 err = at_tok_nextstr(&line, &tmp_ptr); // sec_DNS
3979 if (err < 0)
3980 {
3981 goto exit;
3982 }
3983 if(!str_empty(tmp_ptr)) { // No found Secondary DNS
3984 if(is_ipv4(tmp_ptr)) {
3985 if(inet_pton(AF_INET, tmp_ptr, &(ipv4->SecondaryDNS)) < 0) {
3986 LOGE("inet_pton() fail.");
3987 err = -1;
3988 goto exit;
3989 }
3990
3991 //log_hex("IPv4", &(ipv4->SecondaryDNS), sizeof(struct in_addr));
3992 } else {
3993 if(str_2_ipv6(tmp_ptr, &(ipv6->SecondaryDNS))) {
3994 LOGE("str_2_ipv6() fail.");
3995 err = -1;
3996 goto exit;
3997 }
3998
3999 //log_hex("IPv6", &(ipv6->SecondaryDNS), 16);
4000 }
4001 }
4002
4003 lines_ptr = lines_ptr->p_next;
4004 }
4005
4006exit:
4007 at_response_free(response);
4008 return err;
4009}
4010
4011/*
4012AT+CGCONTRDP
4013+CGCONTRDP: 1,5,"cmnet.MNC000.MCC460.GPRS","10.156.238.86","","223.87.253.100","223.87.253.253","","",0,0
4014+CGCONTRDP: 1,5,"cmnet.MNC000.MCC460.GPRS","254.128.0.0.0.0.0.0.0.1.0.1.181.5.77.221","","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.1","36.9.128.98.32.0.0.2.0,0,0
4015+CGCONTRDP: 8,6,"IMS.MNC000.MCC460.GPRS","254.128.0.0.0.0.0.0.0.1.0.1.181.5.79.116","","","","36.9.128.98.80.2.0.87.0.0.0.0.0.3.31.1","36.9.128.98.80.2,1,0
4016OK
4017
4018*/
4019static int apn_state_get(list_node_t **apn_list)
4020{
4021 ATResponse *response = NULL;
4022 int err = 0;
4023 *apn_list = list_create(NULL);
4024 if(*apn_list == NULL)
4025 {
4026 LOG("list_create() fail.");
4027 return -1;
4028 }
4029
4030 err = at_send_command_multiline("AT+CGCONTRDP", "+CGCONTRDP:", &response);
4031 if (err < 0 || response->success == 0 || !response->p_intermediates){
4032 goto exit;
4033 }
4034 ATLine* lines_ptr = response->p_intermediates;
4035 char *line = NULL;
4036 int tmp_int;
4037 char *tmp_ptr = NULL;
4038 int cid_current = 0;
4039 info_apn_ip_t *apn = NULL;
4040 while(lines_ptr)
4041 {
4042 line = lines_ptr->line;
4043 err = at_tok_start(&line);
4044 if (err < 0)
4045 {
4046 goto exit;
4047 }
4048
4049 err = at_tok_nextint(&line, &tmp_int); // cid
4050 if (err < 0)
4051 {
4052 goto exit;
4053 }
4054
4055 if(tmp_int != 1 && tmp_int != 8) { // Not process cid 1 and 8.
4056 if(cid_current != tmp_int) { // New cid.
4057 apn = (info_apn_ip_t*)malloc(sizeof(info_apn_ip_t));
4058 if(apn == NULL) {
4059 goto exit;
4060 }
4061 memset(apn, 0, sizeof(info_apn_ip_t));
4062 apn->cid = tmp_int;
4063 cid_current = tmp_int;
4064
4065 list_add(*apn_list, apn);
4066 }
4067 err = at_tok_nextint(&line, &tmp_int); // bearer_id
4068 if (err < 0)
4069 {
4070 goto exit;
4071 }
4072 err = at_tok_nextstr(&line, &tmp_ptr); // APN
4073 if (err < 0)
4074 {
4075 goto exit;
4076 }
4077
4078 err = at_tok_nextstr(&line, &tmp_ptr); // IP
4079 if (err < 0 || str_empty(tmp_ptr))
4080 {
4081 goto exit;
4082 }
4083 if(is_ipv4(tmp_ptr)) {
4084 apn->ipv4_valid = true;
4085 memcpy(apn->ipv4, tmp_ptr, strlen(tmp_ptr));
4086 } else {
4087 apn->ipv6_valid = true;
4088 uint8 tmp_ipv6[16];
4089 if(str_2_ipv6(tmp_ptr, tmp_ipv6)) {
4090 LOGE("str_2_ipv6() fail.");
4091 err = -1;
4092 goto exit;
4093 }
4094
4095 if(inet_ntop(AF_INET6, tmp_ipv6, apn->ipv6, 50) == NULL) {
4096 err = -1;
4097 LOGE("inet_ntop ipv6 ip fail.");
4098 goto exit;
4099 }
4100 }
4101 }
4102
4103 lines_ptr = lines_ptr->p_next;
4104 }
4105
4106exit:
4107 at_response_free(response);
4108 return err;
4109}
4110
4111mbtk_info_err_enum call_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack);
4112mbtk_info_err_enum sms_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack);
4113mbtk_info_err_enum pb_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack);
r.xiaoec113d12024-01-12 02:13:28 -08004114
liubin281ac462023-07-19 14:22:54 +08004115//mbtk wyq for data_call_ex add start
4116void data_call_bootconn_save(int cid, int bootconn);
4117//mbtk wyq for data_call_ex add end
4118
4119//void net_list_free(void *data);
4120// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
4121// Otherwise, do not call pack_error_send().
4122static mbtk_info_err_enum pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack)
4123{
4124 if(pack->info_id > MBTK_INFO_ID_CALL_BEGIN && pack->info_id < MBTK_INFO_ID_CALL_END) {
4125 return call_pack_req_process(cli_info, pack);
4126 } else if(pack->info_id > MBTK_INFO_ID_SMS_BEGIN && pack->info_id < MBTK_INFO_ID_SMS_END) {
4127 return sms_pack_req_process(cli_info, pack);
4128 } else if(pack->info_id > MBTK_INFO_ID_PB_BEGIN && pack->info_id < MBTK_INFO_ID_PB_END) {
4129 return pb_pack_req_process(cli_info, pack);
4130 } else {
4131 mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
4132 int cme_err = MBTK_INFO_ERR_CME_NON;
4133 switch(pack->info_id)
4134 {
4135 case MBTK_INFO_ID_DEV_IMEI_REQ: // <string> IMEI
4136 {
4137 if(pack->data_len == 0 || pack->data == NULL) // Get IMEI
4138 {
4139 char imei[20] = {0};
4140 if(req_imei_get(imei, &cme_err) || strlen(imei) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4141 {
4142 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4143 err = MBTK_INFO_ERR_CME + cme_err;
4144 } else {
4145 err = MBTK_INFO_ERR_UNKNOWN;
4146 }
4147 LOG("Get IMEI fail.");
4148 }
4149 else
4150 {
4151 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_IMEI_RSP, imei, strlen(imei));
4152 }
4153 }
4154 else // Set IMEI(Unsupport).
4155 {
4156 err = MBTK_INFO_ERR_UNSUPPORTED;
4157 LOG("Unsupport set IMEI.");
4158 }
4159 break;
4160 }
4161 case MBTK_INFO_ID_DEV_SN_REQ: // <string> SN
4162 {
4163 if(pack->data_len == 0 || pack->data == NULL) // Get SN
4164 {
4165 char sn[20] = {0};
4166 if(req_sn_get(sn, &cme_err) || strlen(sn) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4167 {
4168 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4169 err = MBTK_INFO_ERR_CME + cme_err;
4170 } else {
4171 err = MBTK_INFO_ERR_UNKNOWN;
4172 }
4173 LOG("Get SN fail.");
4174 }
4175 else
4176 {
4177 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_SN_RSP, sn, strlen(sn));
4178 }
4179 }
4180 else // Set SN(Unsupport).
4181 {
4182 err = MBTK_INFO_ERR_UNSUPPORTED;
4183 LOG("Unsupport set SN.");
4184 }
4185 break;
4186 }
4187 case MBTK_INFO_ID_DEV_MEID_REQ: // <string> MEID (Only for CDMA)
4188 {
4189 if(pack->data_len == 0 || pack->data == NULL) // Get MEID
4190 {
4191 err = MBTK_INFO_ERR_UNSUPPORTED;
4192 LOG("Support only for CDMA.");
4193 }
4194 else // Set MEID(Unsupport).
4195 {
4196 err = MBTK_INFO_ERR_UNSUPPORTED;
4197 LOG("Unsupport set MEID.");
4198 }
4199 break;
4200 }
4201 case MBTK_INFO_ID_DEV_VERSION_REQ: // <string> VERSION
4202 {
4203 if(pack->data_len == 0 || pack->data == NULL) // Get VERSION
4204 {
4205 char version[50] = {0};
4206 if(req_version_get(version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4207 {
4208 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4209 err = MBTK_INFO_ERR_CME + cme_err;
4210 } else {
4211 err = MBTK_INFO_ERR_UNKNOWN;
4212 }
4213 LOG("Get Version fail.");
4214 }
4215 else
4216 {
4217 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VERSION_RSP, version, strlen(version));
4218 }
4219 }
4220 else // Set VERSION(Unsupport).
4221 {
4222 err = MBTK_INFO_ERR_UNSUPPORTED;
4223 LOG("Unsupport set VERSION.");
4224 }
4225 break;
4226 }
4227 case MBTK_INFO_ID_DEV_MODEL_REQ: //MODEL
4228 {
4229 if(pack->data_len == 0 || pack->data == NULL) // Get MODEL
4230 {
4231 char model[50] = {0};
4232 if(req_model_get(model, &cme_err) || strlen(model) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4233 {
4234 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4235 err = MBTK_INFO_ERR_CME + cme_err;
4236 } else {
4237 err = MBTK_INFO_ERR_UNKNOWN;
4238 }
4239 LOG("Get model fail.");
4240 }
4241 else
4242 {
4243 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VERSION_RSP, model, strlen(model));
4244 }
4245 }
4246 else // Set model(Unsupport).
4247 {
4248 err = MBTK_INFO_ERR_UNSUPPORTED;
4249 LOG("Unsupport set model.");
4250 }
4251 break;
4252 }
4253 case MBTK_INFO_ID_DEV_MODEM_REQ: //MODEM
4254 {
4255 if(pack->data_len == 0 || pack->data == NULL) // Get MODEM
4256 {
4257 int modem = -1;
4258 if(req_modem_get(&modem, &cme_err) || modem < 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4259 {
4260 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4261 err = MBTK_INFO_ERR_CME + cme_err;
4262 } else {
4263 err = MBTK_INFO_ERR_UNKNOWN;
4264 }
4265 LOG("Get modem fail.");
4266 }
4267 else
4268 {
4269 uint8 modem_type = (uint8)modem;
4270 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_MODEM_RSP, &modem_type, sizeof(uint8));
4271 }
4272 }
4273 else // Set modem
4274 {
4275 mbtk_modem_info_t *modem = (mbtk_modem_info_t *)pack->data;
4276 if(pack->data_len != sizeof(mbtk_modem_info_t))
4277 {
4278 err = MBTK_INFO_ERR_REQ_PARAMETER;
4279 LOG("Set modem error.");
4280 break;
4281 }
4282 if(req_modem_set(modem, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4283 {
4284 LOG("Set modem fail.");
4285 err = MBTK_INFO_ERR_FORMAT;
4286 } else {
4287 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_MODEM_RSP, NULL, 0);
4288 }
4289 }
4290 break;
4291 }
4292 case MBTK_INFO_ID_DEV_TIME_REQ: // <uint8><string> YYYY-MM-DD-HH:MM:SS
4293 {
4294 if(pack->data_len == 0 || pack->data == NULL) // Get Time
4295 {
4296 int type = -1;
4297 if(req_time_get(&type, &cme_err) || type < 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4298 {
4299 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4300 err = MBTK_INFO_ERR_CME + cme_err;
4301 } else {
4302 err = MBTK_INFO_ERR_UNKNOWN;
4303 }
4304 LOG("Get Time fail.");
4305 }
4306 else
4307 {
4308 uint8 time_type = (uint8)type;
4309 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, &time_type, sizeof(uint8));
4310 }
4311 }
4312 else // Set Time
4313 {
4314 if(pack->data_len == sizeof(uint8)) {
4315 if(req_time_set(*(pack->data), NULL, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4316 {
4317 LOG("Set Time fail.");
4318 err = MBTK_INFO_ERR_FORMAT;
4319 } else {
4320 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, NULL, 0);
4321 }
4322 } else {
4323 char time_ptr[100] = {0};
4324 memcpy(time_ptr, pack->data + sizeof(uint8), pack->data_len - sizeof(uint8));
4325 if(req_time_set(*(pack->data), time_ptr, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4326 {
4327 LOG("Set Time fail.");
4328 err = MBTK_INFO_ERR_FORMAT;
4329 } else {
4330 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, NULL, 0);
4331 }
4332 }
4333 }
4334 break;
4335 }
b.liubaa41e12024-07-19 15:07:24 +08004336 case MBTK_INFO_ID_DEV_CELL_TIME_REQ: // <string> YYYY-MM-DD-HH:MM:SS
liubin281ac462023-07-19 14:22:54 +08004337 {
4338 if(pack->data_len == 0 || pack->data == NULL) // Get Time
4339 {
4340 char time[100];
4341 if(req_net_time_get(time, &cme_err) || strlen(time) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4342 {
4343 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4344 err = MBTK_INFO_ERR_CME + cme_err;
4345 } else {
4346 err = MBTK_INFO_ERR_UNKNOWN;
4347 }
4348 LOG("Get Time fail.");
4349 }
4350 else
4351 {
4352 char time_ser[100]={0};
4353 memcpy(time_ser,time,strlen(time));
b.liubaa41e12024-07-19 15:07:24 +08004354 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_CELL_TIME_RSP, time_ser, strlen(time_ser));
liubin281ac462023-07-19 14:22:54 +08004355 }
4356 }
4357 else // Set Time
4358 {
4359 err = MBTK_INFO_ERR_UNSUPPORTED;
4360 LOG("Unsupport set TIME.");
4361 }
4362 break;
4363 }
4364 case MBTK_INFO_ID_DEV_VOLTE_REQ: // <uint8> 0:Close 1:Open
4365 {
4366 if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state.
4367 {
4368 int state;
4369 if(req_volte_get(&state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4370 {
4371 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4372 err = MBTK_INFO_ERR_CME + cme_err;
4373 } else {
4374 err = MBTK_INFO_ERR_UNKNOWN;
4375 }
4376 LOG("Get VoLTE state fail.");
4377 }
4378 else
4379 {
4380 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VOLTE_RSP, &state, sizeof(uint8));
4381 }
4382 }
4383 else // Set VoLTE state.
4384 {
4385 uint8 on = *(pack->data);
4386 if(pack->data_len != sizeof(uint8) || (on != 0 && on != 1))
4387 {
4388 err = MBTK_INFO_ERR_REQ_PARAMETER;
4389 LOG("Set VOLTE parameter error.");
4390 break;
4391 }
4392
4393 if(req_volte_set(on, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4394 {
4395 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4396 err = MBTK_INFO_ERR_CME + cme_err;
4397 } else {
4398 err = MBTK_INFO_ERR_UNKNOWN;
4399 }
4400 LOG("Set VoLTE state fail.");
4401 }
4402 else
4403 {
4404 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VOLTE_RSP, NULL, 0);
4405
4406 // Restart is required to take effect.
4407 LOG("Will reboot system...");
4408 }
4409 }
4410 break;
4411 }
4412 case MBTK_INFO_ID_DEV_TEMP_REQ: // <string> Temperature
4413 {
4414 if(pack->data_len == sizeof(uint8) && pack->data) {
r.xiao2102d762024-06-07 03:10:38 -07004415 mbtk_thermal_info_t temp;
4416 memset(&temp, 0, sizeof(mbtk_thermal_info_t));
liubin281ac462023-07-19 14:22:54 +08004417 if(req_temp_get(*(pack->data), &temp, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4418 {
4419 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4420 err = MBTK_INFO_ERR_CME + cme_err;
4421 } else {
4422 err = MBTK_INFO_ERR_UNKNOWN;
4423 }
4424 LOG("Get temperature fail.");
4425 }
4426 else
4427 {
r.xiao2102d762024-06-07 03:10:38 -07004428 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TEMP_RSP, &temp, sizeof(mbtk_thermal_info_t));
liubin281ac462023-07-19 14:22:54 +08004429 }
4430 } else {
4431 err = MBTK_INFO_ERR_FORMAT;
4432 LOG("Unsupport get Temperature.");
4433 }
4434 break;
4435 }
4436 case MBTK_INFO_ID_SIM_PLMN_REQ: // plmn
4437 {
4438 if(pack->data_len == 0 || pack->data == NULL) // plmn
4439 {
4440 mbtk_plmn_info plmn;
4441 if(req_plmn_get(&plmn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4442 {
4443 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4444 err = MBTK_INFO_ERR_CME + cme_err;
4445 } else {
4446 err = MBTK_INFO_ERR_UNKNOWN;
4447 }
4448 LOG("Get PLMN fail.");
4449 }
4450 else
4451 {
4452 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PLMN_RSP, &plmn, sizeof(mbtk_plmn_info));
4453 }
4454 }
4455 else // Set
4456 {
4457 err = MBTK_INFO_ERR_UNSUPPORTED;
4458 LOG("Set sim state fail.");
4459 }
4460 break;
4461 }
4462 case MBTK_INFO_ID_SIM_STATE_REQ: // mbtk_sim_state_enum
4463 {
4464 if(pack->data_len == 0 || pack->data == NULL) // Get sim state.
4465 {
4466 uint8 sim_state = (uint8)getSIMStatus();
4467 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_STATE_RSP, &sim_state, sizeof(uint8));
4468 }
4469 else // Set
4470 {
4471 err = MBTK_INFO_ERR_UNSUPPORTED;
4472 LOG("Set sim state fail.");
4473 }
4474 break;
4475 }
4476 case MBTK_INFO_ID_SIM_STYPE_REQ: // mbtk_sim_card_type_enum
4477 {
4478 if(pack->data_len == 0 || pack->data == NULL) // Get sim card type
4479 {
4480 uint8 sim_card_type;
4481 if(req_sim_card_type_get(&sim_card_type, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4482 {
4483 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4484 err = MBTK_INFO_ERR_CME + cme_err;
4485 } else {
4486 err = MBTK_INFO_ERR_UNKNOWN;
4487 }
4488 LOG("Get IMSI fail.");
4489 }
4490 else
4491 {
4492 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_STYPE_RSP, &sim_card_type, sizeof(uint8));
4493 }
4494 }
4495 else // Set
4496 {
4497 err = MBTK_INFO_ERR_UNSUPPORTED;
4498 LOG("Set sim state fail.");
4499 }
4500 break;
4501 }
4502 case MBTK_INFO_ID_SIM_PINPUK_TIMES_REQ: // mbtk_pin_puk_last_times
4503 {
4504 if(pack->data_len == 0 || pack->data == NULL) // Get sim card type
4505 {
4506 mbtk_pin_puk_last_times pin_puk_last_times;
4507 if(req_pin_puk_last_times_get(&pin_puk_last_times, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4508 {
4509 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4510 err = MBTK_INFO_ERR_CME + cme_err;
4511 } else {
4512 err = MBTK_INFO_ERR_UNKNOWN;
4513 }
4514 LOG("Get IMSI fail.");
4515 }
4516 else
4517 {
4518 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PINPUK_TIMES_RSP, &pin_puk_last_times, sizeof(mbtk_pin_puk_last_times));
4519 }
4520 }
4521 else // Set
4522 {
4523 err = MBTK_INFO_ERR_UNSUPPORTED;
4524 LOG("Set sim state fail.");
4525 }
4526 break;
4527 }
4528 case MBTK_INFO_ID_SIM_ENABLE_PIN_REQ: // <string> PIN
4529 {
4530 if(pack->data_len == 0 || pack->data == NULL) // Enable PIN
4531 {
yq.wang586a0df2024-10-24 20:10:37 -07004532 mbtk_pin_state_enum pin_state = MBTK_PIN_DISABLE;
4533 if(req_get_pin_state(&pin_state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4534 {
4535 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4536 err = MBTK_INFO_ERR_CME + cme_err;
4537 } else {
4538 err = MBTK_INFO_ERR_UNKNOWN;
4539 }
4540 LOGE("Get pin state fail.");
4541 }
4542 else
4543 {
4544 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_ENABLE_PIN_RSP, &pin_state, sizeof(mbtk_pin_state_enum));
4545 }
liubin281ac462023-07-19 14:22:54 +08004546 }
4547 else // Enable PIN
4548 {
4549 mbtk_enable_pin_info *pin = NULL;
4550 pin = (mbtk_enable_pin_info *)pack->data;
4551 if(req_pin_enable(pin, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4552 {
4553 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4554 err = MBTK_INFO_ERR_CME + cme_err;
4555 } else {
4556 err = MBTK_INFO_ERR_UNKNOWN;
4557 }
4558 LOG("Get IMSI fail.");
4559 }
4560 else
4561 {
4562 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_ENABLE_PIN_RSP, NULL, 0);
4563 }
4564 }
4565 break;
4566 }
4567 case MBTK_INFO_ID_SIM_PIN_REQ: // <string> PIN
4568 {
4569 if(pack->data_len == 0 || pack->data == NULL) // PIN
4570 {
4571 err = MBTK_INFO_ERR_UNSUPPORTED;
4572 LOG("Unsupport GET PIN.");
4573 }
4574 else // Set PIN
4575 {
4576 char pin[16] = {0};
4577 memcpy(pin, pack->data, pack->data_len);
4578 if(req_pin_verify(pin, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4579 {
4580 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4581 err = MBTK_INFO_ERR_CME + cme_err;
4582 } else {
4583 err = MBTK_INFO_ERR_UNKNOWN;
4584 }
4585 LOG("Set PIN fail.");
4586 }
4587 else
4588 {
4589 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PIN_RSP, NULL, 0);
4590 }
4591 }
4592 break;
4593 }
4594 case MBTK_INFO_ID_SIM_PUK_REQ: // <string> PUK
4595 {
4596 if(pack->data_len == 0 || pack->data == NULL)
4597 {
4598 err = MBTK_INFO_ERR_UNSUPPORTED;
4599 LOG("Unsupport.");
4600 }
4601 else // change PIN
4602 {
4603 mbtk_unlock_pin_info *pin_info = NULL;
4604 pin_info = (mbtk_unlock_pin_info *)pack->data;
4605 if(req_puk_unlock_pin(pin_info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4606 {
4607 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4608 err = MBTK_INFO_ERR_CME + cme_err;
4609 } else {
4610 err = MBTK_INFO_ERR_UNKNOWN;
4611 }
4612 LOG("Get IMSI fail.");
4613 }
4614 else
4615 {
4616 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_CHANGE_PIN_RSP, NULL, 0);
4617 }
4618 }
4619 break;
4620 }
4621 case MBTK_INFO_ID_SIM_CHANGE_PIN_REQ: // <string> <string> old_PIN new_PIN
4622 {
4623 if(pack->data_len == 0 || pack->data == NULL)
4624 {
4625 err = MBTK_INFO_ERR_UNSUPPORTED;
4626 LOG("Unsupport.");
4627 }
4628 else // change PIN
4629 {
4630 mbtk_change_pin_info *pin_info = NULL;
4631 pin_info = (mbtk_change_pin_info *)pack->data;
4632 if(req_pin_change(pin_info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4633 {
4634 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4635 err = MBTK_INFO_ERR_CME + cme_err;
4636 } else {
4637 err = MBTK_INFO_ERR_UNKNOWN;
4638 }
4639 LOG("Get IMSI fail.");
4640 }
4641 else
4642 {
4643 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_CHANGE_PIN_RSP, NULL, 0);
4644 }
4645 }
4646 break;
4647 }
4648 case MBTK_INFO_ID_SIM_IMSI_REQ: // <string> IMSI
4649 {
4650 if(pack->data_len == 0 || pack->data == NULL) // Get IMSI
4651 {
4652 char imsi[20] = {0};
4653 if(req_imsi_get(imsi, &cme_err) || strlen(imsi) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4654 {
4655 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4656 err = MBTK_INFO_ERR_CME + cme_err;
4657 } else {
4658 err = MBTK_INFO_ERR_UNKNOWN;
4659 }
4660 LOG("Get IMSI fail.");
4661 }
4662 else
4663 {
4664 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_IMSI_RSP, imsi, strlen(imsi));
4665 }
4666 }
4667 else // Set IMSI(Unsupport).
4668 {
4669 err = MBTK_INFO_ERR_UNSUPPORTED;
4670 LOG("Unsupport set IMSI.");
4671 }
4672 break;
4673 }
4674 case MBTK_INFO_ID_SIM_ICCID_REQ: // <string> ICCID
4675 {
4676 if(pack->data_len == 0 || pack->data == NULL) // Get ICCID
4677 {
4678 //log_hex("pack", pack, sizeof(mbtk_info_pack_t));
4679 //sleep(1);
4680 char iccid[50] = {0};
4681 if(req_iccid_get(iccid, &cme_err) || strlen(iccid) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4682 {
4683 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4684 err = MBTK_INFO_ERR_CME + cme_err;
4685 } else {
4686 err = MBTK_INFO_ERR_UNKNOWN;
4687 }
4688 LOG("Get ICCID fail.");
4689 }
4690 else
4691 {
4692 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_ICCID_RSP, iccid, strlen(iccid));
4693 }
4694 }
4695 else // Set ICCID(Unsupport).
4696 {
4697 err = MBTK_INFO_ERR_UNSUPPORTED;
4698 LOG("Unsupport set ICCID.");
4699 }
4700 break;
4701 }
4702 case MBTK_INFO_ID_SIM_PN_REQ: // <string> Phone Number
4703 {
4704 if(pack->data_len == 0 || pack->data == NULL) // Get Phone Number
4705 {
4706 //log_hex("pack", pack, sizeof(mbtk_info_pack_t));
4707 //sleep(1);
4708 char phone_number[50] = {0};
4709 if(req_phone_number_get(phone_number, &cme_err) || strlen(phone_number) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4710 {
4711 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4712 err = MBTK_INFO_ERR_CME + cme_err;
4713 } else {
4714 err = MBTK_INFO_ERR_UNKNOWN;
4715 }
4716 LOG("Get Phone Number fail.");
4717 }
4718 else
4719 {
4720 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PN_RSP, phone_number, strlen(phone_number));
4721 }
4722 }
4723 else // Set Phone Number(Unsupport).
4724 {
4725 err = MBTK_INFO_ERR_UNSUPPORTED;
4726 LOG("Unsupport set Phone Number.");
4727 }
4728 break;
4729 }
4730 case MBTK_INFO_ID_NET_SEL_MODE_REQ: // <mbtk_net_info_t> Operator
4731 {
4732 if(pack->data_len == 0 || pack->data == NULL) // Get
4733 {
4734 mbtk_net_info_t info;
4735 memset(&info, 0, sizeof(mbtk_net_info_t));
4736 if(req_net_sel_mode_get(&info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4737 {
4738 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4739 err = MBTK_INFO_ERR_CME + cme_err;
4740 } else {
4741 err = MBTK_INFO_ERR_UNKNOWN;
4742 }
4743 LOG("Get Net select mode fail.");
4744 }
4745 else
4746 {
4747 LOG("NET : %d, %d, %d, %d", info.net_sel_mode, info.net_type, info.net_state, info.plmn);
4748 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SEL_MODE_RSP, &info, sizeof(mbtk_net_info_t));
4749 }
4750 }
4751 else // Set
4752 {
4753 //LOG("1 pack-%p,data-%p,data_len-%d", pack, pack->data, pack->data_len);
4754 //log_hex("pack", pack, sizeof(mbtk_info_pack_t));
4755 //log_hex("data", pack->data, pack->data_len);
4756
4757 mbtk_net_info_t* info = (mbtk_net_info_t*)pack->data;//(mbtk_net_info_t*)mbtk_info_pack_data_get(pack, NULL);
4758 if(info == NULL) {
4759 err = MBTK_INFO_ERR_FORMAT;
4760 LOG("Get Net select mode fail.");
4761 } else {
4762 LOG("NET : %d, %d, %d", info->net_sel_mode, info->net_type, info->plmn);
4763 if(req_net_sel_mode_set(info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) {
4764 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4765 err = MBTK_INFO_ERR_CME + cme_err;
4766 } else {
4767 err = MBTK_INFO_ERR_UNKNOWN;
4768 }
4769 LOG("Get Net select mode fail.");
4770 } else {
4771 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SEL_MODE_RSP, NULL, 0);
4772 }
4773 }
4774 }
4775 break;
4776 }
4777 case MBTK_INFO_ID_NET_AVAILABLE_REQ:// sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)
4778 {
4779 if(pack->data_len == 0 || pack->data == NULL) // Get Available Net.
4780 {
4781 int buffer_size;
4782 uint8 buffer[SOCK_MSG_LEN_MAX];
4783 memset(buffer, 0, SOCK_MSG_LEN_MAX);
4784 if((buffer_size = req_available_net_get(buffer, &cme_err)) <= 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4785 {
4786 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4787 err = MBTK_INFO_ERR_CME + cme_err;
4788 } else {
4789 err = MBTK_INFO_ERR_UNKNOWN;
4790 }
4791 LOG("Get Available Net fail.");
4792 }
4793 else
4794 {
4795 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_AVAILABLE_RSP, buffer, buffer_size);
4796 }
4797 }
4798 else // Set Available Net(Unsupport).
4799 {
4800 err = MBTK_INFO_ERR_UNSUPPORTED;
4801 LOG("Unsupport set available net.");
4802 }
4803 break;
4804 }
4805 case MBTK_INFO_ID_NET_BAND_REQ:
4806 {
4807 if(pack->data_len == 0 || pack->data == NULL)
4808 {
4809 err = MBTK_INFO_ERR_REQ_PARAMETER;
4810 LOG("No data found.");
4811 }
4812 else // Get support/current bands.
4813 {
4814 if(pack->data_len == sizeof(uint8)) {
4815 if(*(pack->data)) { // Get current bands.
4816 mbtk_band_info_t band;
b.liu288093c2024-05-09 17:02:57 +08004817 memset(&band, 0x0, sizeof(mbtk_band_info_t));
liubin281ac462023-07-19 14:22:54 +08004818 if(req_band_get(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4819 {
4820 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4821 err = MBTK_INFO_ERR_CME + cme_err;
4822 } else {
4823 err = MBTK_INFO_ERR_UNKNOWN;
4824 }
4825 LOG("Get net band fail.");
4826 }
4827 else
4828 {
4829 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, &band, sizeof(mbtk_band_info_t));
4830 }
4831 } else { // Get support bands.
4832 band_support_get();
4833 if(band_support.net_pref != 0)
4834 {
4835 err = MBTK_INFO_ERR_UNKNOWN;
4836 LOG("Get support bands fail.");
4837 }
4838 else
4839 {
4840 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, &band_support, sizeof(mbtk_band_info_t));
4841 }
4842 }
4843 } else { // Set current bands.
4844 mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data;
4845 if(pack->data_len != sizeof(mbtk_band_info_t))
4846 {
4847 err = MBTK_INFO_ERR_REQ_PARAMETER;
4848 LOG("Set net band error.");
4849 break;
4850 }
4851
4852 if(req_band_set(band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4853 {
4854 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4855 err = MBTK_INFO_ERR_CME + cme_err;
4856 } else {
4857 err = MBTK_INFO_ERR_UNKNOWN;
4858 }
4859 LOG("Set net band fail.");
4860 }
4861 else
4862 {
4863 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, NULL, 0);
4864 }
4865 }
4866 }
4867 break;
4868 }
4869 case MBTK_INFO_ID_NET_CELL_REQ: // mbtk_cell_info_t[]
4870 {
4871 if(pack->data_len == 0 || pack->data == NULL) // Get net cell.
4872 {
4873 if(req_cell_info_get(&cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4874 {
4875 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4876 err = MBTK_INFO_ERR_CME + cme_err;
4877 } else {
4878 err = MBTK_INFO_ERR_UNKNOWN;
4879 }
4880 LOG("Get net cell fail.");
4881 }
4882 else
4883 {
4884 LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_num);
4885 //sleep(1);
4886 // mbtK_cell_pack_info_t
4887 if(cell_info.cell_num > 0 && cell_info.cell_num <= CELL_NUM_MAX && cell_info.type >= 0 && cell_info.type <= 2) {
4888 uint8 *data = (uint8*)malloc(sizeof(uint8) + sizeof(mbtk_cell_info_t) * cell_info.cell_num);
4889 if(data == NULL){
4890 err = MBTK_INFO_ERR_MEMORY;
4891 LOG("Get net cell fail.");
4892 } else {
4893 *data = cell_info.type; // Set network type.
4894 // Copy cell info item.
4895 #if 0
4896 int i = 0;
4897 while(i < cell_info.cell_num) {
4898 memcpy(data + sizeof(uint8) + sizeof(mbtk_cell_info_t) * i,
4899 &(cell_info.cell[i]),
4900 sizeof(mbtk_cell_info_t));
4901 i++;
4902 }
4903 #else
4904 memcpy(data + sizeof(uint8),
4905 &(cell_info.cell),
4906 sizeof(mbtk_cell_info_t) * cell_info.cell_num);
4907 #endif
4908 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_CELL_RSP, data, sizeof(uint8) + sizeof(mbtk_cell_info_t) * cell_info.cell_num);
4909 free(data);
4910 }
4911 } else {
4912 err = MBTK_INFO_ERR_UNKNOWN;
4913 LOG("Get net cell fail.");
4914 }
4915 }
4916 }
4917 else // Lock cell
4918 {
4919 char *mem = (char*)(pack->data);
4920 int len = pack->data_len;
4921 char reg[100] = {0};
4922 printf("mem:%s, len:%d", pack->data, pack->data_len);
4923
4924 if(req_cell_info_set(mem, reg, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4925 {
4926 // printf("cpms_set fail\n");
4927 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4928 err = MBTK_INFO_ERR_CME + cme_err;
4929 } else {
4930 err = MBTK_INFO_ERR_UNKNOWN;
4931 }
4932 // LOG("Set req_cell_info_set fail.");
4933 }
4934 else
4935 {
4936
4937 printf("req_cell_info_set success, reg:%s\n", reg);
4938 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_CELL_RSP, reg, strlen(reg));
4939
4940 // Restart is required to take effect.
4941 LOG("Will reboot system...");
4942 }
4943 }
4944 break;
4945 }
4946 case MBTK_INFO_ID_NET_RADIO_REQ: // <uint8> 0:OFF 1:ON
4947 {
4948 if(pack->data_len == 0 || pack->data == NULL) // Get
4949 {
4950 uint8 radio_on = (uint8)isRadioOn();
4951 if(radio_on < 0)
4952 {
4953 err = MBTK_INFO_ERR_UNKNOWN;
4954 LOG("Get radio state fail.");
4955 }
4956 else
4957 {
4958 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_RADIO_RSP, &radio_on, sizeof(uint8));
4959 }
4960 }
4961 else // Set
4962 {
yq.wangd58f71e2024-08-21 23:45:31 -07004963 at_cfun_command = true;
liubin281ac462023-07-19 14:22:54 +08004964 uint8 radio_on = *(pack->data);
4965 if(radio_on != 0 && radio_on != 1)
4966 {
4967 err = MBTK_INFO_ERR_REQ_PARAMETER;
4968 LOG("Set radio state fail.");
4969 }
4970 else
4971 {
4972 setRadioPower(radio_on);
4973 if((radio_on && net_info.radio_state == MBTK_RADIO_STATE_ON)
4974 || (!radio_on && net_info.radio_state == MBTK_RADIO_STATE_OFF)) {
4975 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_RADIO_RSP, NULL, 0);
4976 } else {
4977 err = MBTK_INFO_ERR_UNKNOWN;
4978 LOG("Set radio state fail.");
4979 }
4980 }
yq.wangd58f71e2024-08-21 23:45:31 -07004981 at_cfun_command = false;
liubin281ac462023-07-19 14:22:54 +08004982 }
4983 break;
4984 }
4985 case MBTK_INFO_ID_NET_SIGNAL_REQ: // mbtk_signal_info_t
4986 {
4987 if(pack->data_len == 0 || pack->data == NULL) // Get net signal.
4988 {
4989 mbtk_signal_info_t signal;
4990 memset(&signal, 0, sizeof(mbtk_signal_info_t));
4991 if(req_net_signal_get(&signal, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4992 {
4993 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4994 err = MBTK_INFO_ERR_CME + cme_err;
4995 } else {
4996 err = MBTK_INFO_ERR_UNKNOWN;
4997 }
4998 LOG("Get net signal fail.");
4999 }
5000 else
5001 {
5002 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SIGNAL_RSP, &signal, sizeof(mbtk_signal_info_t));
5003 }
5004 }
5005 else // Set
5006 {
5007 err = MBTK_INFO_ERR_UNSUPPORTED;
5008 LOG("Set net signal fail.");
5009 }
5010 break;
5011 }
5012 case MBTK_INFO_ID_NET_REG_REQ: // mbtk_net_reg_info_t
5013 {
5014 if(pack->data_len == 0 || pack->data == NULL) // Get net reg.
5015 {
5016 mbtk_net_reg_info_t reg;
5017 memset(&reg, 0, sizeof(mbtk_net_reg_info_t));
5018 if(req_net_reg_get(&reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5019 {
5020 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5021 err = MBTK_INFO_ERR_CME + cme_err;
5022 } else {
5023 err = MBTK_INFO_ERR_UNKNOWN;
5024 }
5025 LOG("Get net reg fail.");
5026 }
5027 else
5028 {
5029 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_REG_RSP, &reg, sizeof(mbtk_net_reg_info_t));
5030 }
5031 }
5032 else // Set
5033 {
5034 err = MBTK_INFO_ERR_UNSUPPORTED;
5035 LOG("Set net reg fail.");
5036 }
5037 break;
5038 }
5039 case MBTK_INFO_ID_NET_APN_REQ: // mbtk_apn_info_t
5040 {
5041 if(pack->data_len == 0 || pack->data == NULL) // Get APN
5042 {
5043 uint8 buff[SOCK_MSG_LEN_MAX];
5044 memset(buff, 0, SOCK_MSG_LEN_MAX);
5045 int data_len = 0;
5046 if(req_apn_get(buff, &data_len, &cme_err) || data_len <= 0 || cme_err != MBTK_INFO_ERR_CME_NON)
5047 {
5048 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5049 err = MBTK_INFO_ERR_CME + cme_err;
5050 } else {
5051 err = MBTK_INFO_ERR_UNKNOWN;
5052 }
5053 LOG("Get APN fail.");
5054 }
5055 else
5056 {
5057 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, buff, data_len);
5058 }
5059 }
5060 else // Set
5061 {
5062 // <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
5063 const uint8* ptr = pack->data;
5064 mbtk_apn_info_t apn;
5065 int len;
5066 memset(&apn, 0, sizeof(mbtk_apn_info_t));
5067 // cid
5068 apn.cid = *ptr++;
5069
5070 // ip_type
5071 apn.ip_type = (mbtk_ip_type_enum)(*ptr++);
5072
5073 // apn
5074 len = byte_2_uint16(ptr, false);
5075 ptr += sizeof(uint16);
5076 if(len > 0) {
5077 memcpy(apn.apn, ptr, len);
5078 ptr += len;
5079 }
5080
5081 // user
5082 len = byte_2_uint16(ptr, false);
5083 ptr += sizeof(uint16);
5084 if(len > 0) {
5085 memcpy(apn.user, ptr, len);
5086 ptr += len;
5087 }
5088
5089 // pass
5090 len = byte_2_uint16(ptr, false);
5091 ptr += sizeof(uint16);
5092 if(len > 0) {
5093 memcpy(apn.pass, ptr, len);
5094 ptr += len;
5095 }
5096
5097 // auth
5098 len = byte_2_uint16(ptr, false);
5099 ptr += sizeof(uint16);
5100 if(len > 0) {
5101 memcpy(apn.auth, ptr, len);
5102 ptr += len;
5103 }
5104
5105 LOGD("APN : %d, %d, %s, %s, %s, %s", apn.cid, apn.ip_type, str_empty(apn.apn) ? "NULL" : apn.apn,
5106 str_empty(apn.user) ? "NULL" : apn.user, str_empty(apn.pass) ? "NULL" : apn.pass, str_empty(apn.auth) ? "NULL" : apn.auth);
5107 if(req_apn_set(&apn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5108 {
5109 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5110 err = MBTK_INFO_ERR_CME + cme_err;
5111 } else {
5112 err = MBTK_INFO_ERR_UNKNOWN;
5113 }
5114 LOG("Set APN fail.");
5115 }
5116 else
5117 {
5118 // Save apn.
wangyouqianged88c722023-11-22 16:33:43 +08005119#ifdef MBTK_AF_SUPPORT
5120 if(apn.cid == 1)
5121 {
5122 default_iptype = apn.ip_type;
5123 }
5124#endif
liubin281ac462023-07-19 14:22:54 +08005125 apn_prop_set(&apn);
5126
5127 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, NULL, 0);
5128 }
5129 }
5130 break;
5131 }
wangyouqiang80487e42024-05-24 15:06:20 +08005132 case MBTK_INFO_ID_NET_QSER_APN_REQ:
5133 {
5134 if(pack->data_len == 0 || pack->data == NULL)
5135 {
5136 uint8 buff[SOCK_MSG_LEN_MAX];
5137 memset(buff, 0, SOCK_MSG_LEN_MAX);
5138 int data_len = 0;
5139 if(mbtk_qser_req_apn_get(buff, &data_len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5140 {
5141 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5142 err = MBTK_INFO_ERR_CME + cme_err;
5143 } else {
5144 err = MBTK_INFO_ERR_UNKNOWN;
5145 }
5146 LOGE("Get APN fail.");
5147 }
5148 else
5149 {
5150 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, buff, data_len);
5151 }
5152 }
5153 else
5154 {
5155 const uint8* ptr = pack->data;
5156 mbtk_apn_info_t apn;
5157 mbtk_apn_req_type_enum req_type = MBTK_APN_REQ_TYPE_SET;
5158 uint8 apn_type[MBTK_QSER_APN_NAME_SIZE] = {0};
5159 int ret = mbtk_strdata_to_apn(pack->data, &apn, apn_type, &req_type);
5160 if(ret < 0)
5161 {
5162 LOGE("mbtk_strdata_to_apn fail. ret = [%d]", ret);
5163 err = MBTK_INFO_ERR_REQ_PARAMETER;
5164 }
5165 else
5166 {
5167 if(req_apn_set(&apn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5168 {
5169 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5170 err = MBTK_INFO_ERR_CME + cme_err;
5171 } else {
5172 err = MBTK_INFO_ERR_UNKNOWN;
5173 }
5174 LOGE("Set APN fail.");
5175 }
5176 else
5177 {
5178 // Save apn.
5179 apn_prop_set(&apn);
5180 mbtk_qser_apn_save(apn, apn_type, true);
5181 if(req_type == MBTK_APN_REQ_TYPE_ADD)
5182 {
5183 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_QSER_APN_RSP, (void *)&apn.cid, 1);
5184 }
5185 else
5186 {
5187 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_QSER_APN_RSP, NULL, 0);
5188 }
5189 }
5190 }
5191 }
5192
5193 break;
5194 }
b.liu288093c2024-05-09 17:02:57 +08005195 case MBTK_INFO_ID_NET_APN_DEL_REQ:
liuyang0e49d9a2024-04-23 21:04:54 +08005196 {
b.liu288093c2024-05-09 17:02:57 +08005197 if(pack->data_len == 0 || pack->data == NULL)
liuyang0e49d9a2024-04-23 21:04:54 +08005198 {
5199 err = MBTK_INFO_ERR_UNSUPPORTED;
5200 LOG("Unsupported delete apn .");
5201 }
b.liu288093c2024-05-09 17:02:57 +08005202 else
liuyang0e49d9a2024-04-23 21:04:54 +08005203 {
liuyang1cefd852024-04-24 18:30:53 +08005204 int profile = pack->data[0];
wangyouqiang80487e42024-05-24 15:06:20 +08005205 if(cid_active[profile] == 1)
liuyang0e49d9a2024-04-23 21:04:54 +08005206 {
wangyouqiang80487e42024-05-24 15:06:20 +08005207 LOGD("cid pdp already open.");
5208 err = MBTK_INFO_ERR_CID_EXIST;
wangyouqiang13e98402024-05-24 16:07:43 +08005209 break;
wangyouqiang80487e42024-05-24 15:06:20 +08005210 }
5211 if(mbtk_qser_apn_del(profile) < 0)
5212 {
5213 LOGD("del error.");
5214 err = MBTK_INFO_ERR_REQ_PARAMETER;
liuyang0e49d9a2024-04-23 21:04:54 +08005215 }
5216 else
5217 {
wangyouqiang80487e42024-05-24 15:06:20 +08005218 if(req_apn_del(profile, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5219 {
5220 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5221 err = MBTK_INFO_ERR_CME + cme_err;
5222 } else {
5223 err = MBTK_INFO_ERR_UNKNOWN;
5224 }
5225 LOG("Delete apn fail.");
5226 }
5227 else
5228 {
5229 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_DEL_RSP, NULL, 0);
5230 }
liuyang0e49d9a2024-04-23 21:04:54 +08005231 }
5232 }
5233 break;
5234 }
liubin281ac462023-07-19 14:22:54 +08005235 case MBTK_INFO_ID_NET_DATA_CALL_REQ:
5236 {
5237 if(pack->data_len == 0 || pack->data == NULL)
5238 {
5239 err = MBTK_INFO_ERR_UNSUPPORTED;
5240 }
5241 else
5242 {
5243 /* <call_type[1]><cid[1]><auto_conn_interval[1]><boot_conn[1]><timeout[1]>
5244 call_type : mbtk_data_call_type_enum
5245 cid : 2 - 7
5246 timeout : second
5247 */
5248 mbtk_data_call_type_enum call_type = (mbtk_data_call_type_enum)pack->data[0];
5249 int cid = pack->data[1];
5250 int reconn = 0;
5251
wangyouqiang80487e42024-05-24 15:06:20 +08005252#if 0
liubin281ac462023-07-19 14:22:54 +08005253 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
5254 err = MBTK_INFO_ERR_CID;
5255 break;
5256 }
wangyouqiang80487e42024-05-24 15:06:20 +08005257#endif
5258 if(mbtk_check_cid(cid) < 0)
5259 {
5260 err = MBTK_INFO_ERR_CID;
5261 break;
5262 }
liubin281ac462023-07-19 14:22:54 +08005263
5264 LOG("cid_active[%d] = %d", cid, cid_active[cid]);
5265 memset(&cgact_wait, 0, sizeof(info_cgact_wait_t));
5266 switch(call_type) {
5267 case MBTK_DATA_CALL_START: {
5268 //mbtk wyq for data_call_ex add start
5269 int auto_conn_interval = pack->data[2];
5270 int boot_conn = pack->data[3];
5271 int timeout = pack->data[4];
5272 data_call_bootconn_save(cid, boot_conn);
b.liufe320632024-01-17 20:38:08 +08005273
wangyouqiang13e98402024-05-24 16:07:43 +08005274 mbtk_signal_info_t signal;
5275 memset(&signal, 0xFF, sizeof(mbtk_signal_info_t));
5276 req_net_signal_get(&signal, NULL);
b.liufe320632024-01-17 20:38:08 +08005277
liubin281ac462023-07-19 14:22:54 +08005278 if(cid_active[cid] == 1)
5279 {
5280 err = MBTK_INFO_ERR_CID_EXIST;
5281 break;
5282 }
b.liufe320632024-01-17 20:38:08 +08005283
wangyouqiang80487e42024-05-24 15:06:20 +08005284 if(mbtk_check_default_pdp_state(cid))
5285 {
5286 err = MBTK_INFO_ERR_UNSUPPORTED;
5287 break;
5288 }
5289
liubin281ac462023-07-19 14:22:54 +08005290 data_call_reconn:
5291 //mbtk wyq for data_call_ex add end
5292 cgact_wait.waitting = true;
5293 cgact_wait.cid = cid;
5294 cgact_wait.act = true;
5295 if(req_data_call_start(cid, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5296 {
5297 //mbtk wyq for data_call_ex add start
5298 if(reconn < 5 && auto_conn_interval > 0)
5299 {
5300 sleep(auto_conn_interval);
5301 reconn++;
5302 cme_err = MBTK_INFO_ERR_CME_NON;
5303 LOG("data_call restart call.");
5304 goto data_call_reconn;
5305 }
5306 //mbtk wyq for data_call_ex add end
5307 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5308 err = MBTK_INFO_ERR_CME + cme_err;
5309 } else {
5310 err = MBTK_INFO_ERR_UNKNOWN;
5311 }
5312 LOG("%d active fail.", cid);
5313 }
5314 else
5315 {
5316 // Wait for "CONNECT" or "+CGEV:"
5317 if(wait_cgact_complete(timeout)) { // Timeout
5318 err = MBTK_INFO_ERR_TIMEOUT;
5319 break;
5320 }
5321
5322 // Get IP information.
5323 mbtk_ipv4_info_t ipv4;
5324 mbtk_ipv6_info_t ipv6;
5325 memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t));
5326 memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t));
5327 if(req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5328 {
5329 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5330 err = MBTK_INFO_ERR_CME + cme_err;
5331 } else {
5332 err = MBTK_INFO_ERR_UNKNOWN;
5333 }
5334 LOG("Get %d state fail.", cid);
5335 }
5336 else
5337 {
5338 // Config IPv4 address.
wangyouqianged88c722023-11-22 16:33:43 +08005339#ifdef MBTK_AF_SUPPORT
5340 if(cid == 1)
5341 {
5342 //uint8 pdp_data = cid;
5343 //pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_data, sizeof(uint8));
5344 ipv4.valid = false;
5345 ipv6.valid = false;
5346 if(default_iptype == MBTK_IP_TYPE_IP)
5347 {
5348 ipv4.valid = true;
5349 }
5350 else if(default_iptype == MBTK_IP_TYPE_IPV6)
5351 {
5352 ipv6.valid = true;
5353 }
5354 else
5355 {
5356 ipv4.valid = true;
5357 ipv6.valid = true;
5358 }
5359 }
5360#endif
liubin281ac462023-07-19 14:22:54 +08005361#if 1
5362 if(ipv4.valid) {
5363 char dev[20] = {0};
5364 sprintf(dev, "ccinet%d", cid - 1);
5365
5366 char ip[20] = {0};
5367 char gateway[20] = {0};
5368 char *gateway_ptr = NULL;
5369 char netmask[20] = {0};
5370 char *netmask_ptr = NULL;
5371 if(inet_ntop(AF_INET, &(ipv4.IPAddr), ip, 20) == NULL) {
5372 err = MBTK_INFO_ERR_UNKNOWN;
5373 LOGE("inet_ntop ipv4 ip fail.");
5374 log_hex("IPv4", &(ipv4.IPAddr), 4);
5375 break;
5376 }
5377
5378 if(ipv4.GateWay) {
5379 if(inet_ntop(AF_INET, &(ipv4.GateWay), gateway, 20) == NULL) {
5380 err = MBTK_INFO_ERR_UNKNOWN;
5381 LOGE("inet_ntop ipv4 gateway fail.");
5382 log_hex("IPv4", &(ipv4.IPAddr), 4);
5383 break;
5384 } else {
5385 gateway_ptr = gateway;
5386 }
5387 }
5388
5389 if(ipv4.NetMask) {
5390 if(inet_ntop(AF_INET, &(ipv4.NetMask), netmask, 20) == NULL) {
5391 err = MBTK_INFO_ERR_UNKNOWN;
5392 LOGE("inet_ntop ipv4 netmask fail.");
5393 log_hex("IPv4", &(ipv4.IPAddr), 4);
5394 break;
5395 } else {
5396 netmask_ptr = netmask;
5397 }
5398 }
5399
5400 if(netmask_ptr == NULL) {
5401 netmask_ptr = netmask;
5402 memcpy(netmask_ptr, "255.255.255.0", strlen("255.255.255.0"));
5403 }
5404
5405 if(mbtk_ifc_configure2(dev, ip, 0, gateway_ptr, netmask_ptr)) {
5406 LOGD("Config %s IPv4 %s fail.", dev, ip);
5407 } else {
5408 LOGD("Config %s IPv4 %s success.", dev, ip);
5409 }
5410
5411 }
5412#endif
5413 // Config IPv6 address.
5414 if(ipv6.valid) {
5415 char ip[50] = {0};
5416 char dev[20] = {0};
5417 sprintf(dev, "ccinet%d", cid - 1);
5418
5419 if(inet_ntop(AF_INET6, &(ipv6.IPV6Addr), ip, 50) == NULL) {
5420 err = MBTK_INFO_ERR_UNKNOWN;
5421 LOGE("inet_ntop ipv6 ip fail.");
5422 log_hex("IPv6", &(ipv6.IPV6Addr), 16);
5423 break;
5424 }
5425
5426 if(mbtk_ipv6_config(dev, ip, 64)) {
5427 LOGD("Config %s IPv6 %s fail.", dev, ip);
5428 } else {
5429 LOGD("Config %s IPv6 %s success.", dev, ip);
5430 }
5431 }
5432
5433 cid_active[cid] = 1;
wangyouqiang80487e42024-05-24 15:06:20 +08005434 mbtk_set_default_pdp_state(true, cid);
5435 mbtk_qser_route_config(cid, &ipv4, &ipv6);
liubin281ac462023-07-19 14:22:54 +08005436 if(cli_info->fd != DATA_CALL_BOOTCONN_FD)
5437 {
liuyange134d842024-06-27 17:34:02 +08005438 mbtk_net_led_set(MBTK_NET_LED_DATA_CONNECT);
liubin281ac462023-07-19 14:22:54 +08005439 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0);
5440 }
5441 else
5442 {
5443 free(pack->data);
5444 free(cli_info);
5445 LOG("data_call bootconn success.");
5446 }
5447 }
5448 }
5449 break;
5450 }
5451 case MBTK_DATA_CALL_STOP: {
5452 //mbtk wyq for data_call_ex add start
5453 if(cid_active[cid] == 0)
5454 {
5455 err = MBTK_INFO_ERR_CID_NO_EXIST;
5456 break;
5457 }
5458
5459 int timeout = pack->data[2];
5460 //mbtk wyq for data_call_ex add end
b.liuf37bd332024-03-18 13:51:24 +08005461#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
wangyouqianged88c722023-11-22 16:33:43 +08005462 if(cid == 1)
5463 {
5464 char dev[20] = {0};
5465 uint8 pdp_data = cid + 100;
5466 pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_data, sizeof(uint8));
b.liufe320632024-01-17 20:38:08 +08005467
wangyouqianged88c722023-11-22 16:33:43 +08005468 sprintf(dev, "ccinet%d", cid - 1);
5469
5470 // Config network.
5471 if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
5472 LOGD("Config %s IPv4 0 fail.", dev);
5473 } else {
5474 LOGD("Config %s IPv4 0 success.", dev);
5475 }
5476 cid_active[cid] = 0;
wangyouqiang80487e42024-05-24 15:06:20 +08005477 mbtk_set_default_pdp_state(false, cid);
liuyange134d842024-06-27 17:34:02 +08005478 mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
wangyouqianged88c722023-11-22 16:33:43 +08005479 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0);
5480 break;
5481 }
5482#endif
liubin281ac462023-07-19 14:22:54 +08005483 cgact_wait.waitting = true;
5484 cgact_wait.cid = cid;
5485 cgact_wait.act = false;
5486 if(req_data_call_stop(cid, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5487 {
5488 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5489 err = MBTK_INFO_ERR_CME + cme_err;
5490 } else {
5491 err = MBTK_INFO_ERR_UNKNOWN;
5492 }
5493 LOG("%d deactive fail.", cid);
5494 }
5495 else
5496 {
5497 // Wait for "CONNECT" or "+CGEV:"
5498 if(wait_cgact_complete(timeout)) { // Timeout
5499 err = MBTK_INFO_ERR_TIMEOUT;
5500 break;
5501 }
5502 char dev[20] = {0};
5503 sprintf(dev, "ccinet%d", cid - 1);
5504
5505 // Config network.
5506 if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
5507 LOGD("Config %s IPv4 0 fail.", dev);
5508 } else {
5509 LOGD("Config %s IPv4 0 success.", dev);
5510 }
5511
5512#if 0
5513 if(mbtk_ipv6_config(dev, NULL, 64)) {
5514 LOGD("Config %s IPv6 0 fail.", dev);
5515 } else {
5516 LOGD("Config %s IPv6 0 success.", dev);
5517 }
5518#endif
5519 cid_active[cid] = 0;
wangyouqiang80487e42024-05-24 15:06:20 +08005520 mbtk_set_default_pdp_state(false, cid);
liuyange134d842024-06-27 17:34:02 +08005521 mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
liubin281ac462023-07-19 14:22:54 +08005522 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0);
5523 }
5524 break;
5525 }
5526 case MBTK_DATA_CALL_STATE: {
wangyouqianged88c722023-11-22 16:33:43 +08005527 if(cid_active[cid] == 0)
5528 {
5529 err = MBTK_INFO_ERR_CID_NO_EXIST;
5530 break;
5531 }
liubin281ac462023-07-19 14:22:54 +08005532 mbtk_ipv4_info_t ipv4;
5533 mbtk_ipv6_info_t ipv6;
5534 memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t));
5535 memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t));
5536 if(req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5537 {
5538 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5539 err = MBTK_INFO_ERR_CME + cme_err;
5540 } else {
5541 err = MBTK_INFO_ERR_UNKNOWN;
5542 }
5543 LOG("Get %d state fail.", cid);
5544 }
5545 else
5546 {
5547 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
5548 int buff_len = 0;
wangyouqianged88c722023-11-22 16:33:43 +08005549#ifdef MBTK_AF_SUPPORT
5550 if(cid == 1)
5551 {
5552 ipv4.valid = false;
5553 ipv6.valid = false;
5554 if(default_iptype == MBTK_IP_TYPE_IP)
5555 {
5556 ipv4.valid = true;
5557 }
5558 else if(default_iptype == MBTK_IP_TYPE_IPV6)
5559 {
5560 ipv6.valid = true;
5561 }
5562 else
5563 {
5564 ipv4.valid = true;
5565 ipv6.valid = true;
5566 }
5567 }
5568#endif
liubin281ac462023-07-19 14:22:54 +08005569 if(ipv4.valid && ipv6.valid) {
5570 buff[0] = (uint8)2;
5571 buff_len++;
5572
5573 memcpy(buff + buff_len, &ipv4, sizeof(mbtk_ipv4_info_t));
5574 buff_len += sizeof(mbtk_ipv4_info_t);
5575 memcpy(buff + buff_len, &ipv6, sizeof(mbtk_ipv6_info_t));
5576 buff_len += sizeof(mbtk_ipv6_info_t);
5577 } else if(ipv4.valid) {
5578 buff[0] = (uint8)0;
5579 buff_len++;
5580
5581 memcpy(buff + buff_len, &ipv4, sizeof(mbtk_ipv4_info_t));
5582 buff_len += sizeof(mbtk_ipv4_info_t);
5583 } else if(ipv6.valid) {
5584 buff[0] = (uint8)1;
5585 buff_len++;
5586
5587 memcpy(buff + buff_len, &ipv6, sizeof(mbtk_ipv6_info_t));
5588 buff_len += sizeof(mbtk_ipv6_info_t);
5589 } else {
5590 LOGE("Get IPv4/IPv6 fail.");
5591 err = MBTK_INFO_ERR_UNKNOWN;
5592 break;
5593 }
5594 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, buff, buff_len);
5595 }
5596 break;
5597 }
5598 default: {
5599 err = MBTK_INFO_ERR_FORMAT;
5600 break;
5601 }
5602 }
5603 }
5604 break;
5605 }
r.xiao06db9a12024-04-14 18:51:15 -07005606 case MBTK_INFO_ID_NET_IMS_REQ:
5607 {
5608 if(pack->data_len == 0 || pack->data == NULL) //Get
5609 {
5610 int reg = -1;
5611 if(net_ims_get(&reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5612 {
5613 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5614 err = MBTK_INFO_ERR_CME + cme_err;
5615 } else {
5616 err = MBTK_INFO_ERR_UNKNOWN;
5617 }
5618 LOG("Get net ims fail.");
5619 }
5620 else
5621 {
5622 uint8 reg_type = (uint8)reg;
5623 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_RSP, &reg_type, sizeof(uint8));
5624 }
5625 }
5626 else
5627 {
5628 uint8 ims = *(pack->data);
5629
5630 if(net_ims_set(ims, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5631 {
5632 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5633 err = MBTK_INFO_ERR_CME + cme_err;
5634 } else {
5635 err = MBTK_INFO_ERR_UNKNOWN;
5636 }
5637 LOG("Set net ims fail.");
5638 }
5639 else
5640 {
5641 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_RSP, NULL, 0);
5642 }
5643 }
5644 break;
5645 }
b.liufdf03172024-06-07 15:01:29 +08005646 case MBTK_INFO_ID_NET_IMS_REG_STATE_REQ:
5647 {
5648 if(pack->data_len == 0 || pack->data == NULL) //Get
5649 {
5650 int reg = -1;
5651 if(net_ims_reg_state_get(&reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5652 {
5653 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5654 err = MBTK_INFO_ERR_CME + cme_err;
5655 } else {
5656 err = MBTK_INFO_ERR_UNKNOWN;
5657 }
5658 LOG("Get net ims fail.");
5659 }
5660 else
5661 {
5662 uint8 reg_type = (uint8)reg;
5663 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_REG_STATE_RSP, &reg_type, sizeof(uint8));
5664 }
5665 }
5666 else
5667 {
5668 err = MBTK_INFO_ERR_UNSUPPORTED;
5669 }
5670 break;
5671 }
r.xiaoec113d12024-01-12 02:13:28 -08005672 case MBTK_INFO_ID_WAKEUP_STA_REQ:
5673 {
5674 if(pack->data_len == 0 || pack->data == NULL)
5675 {
5676 err = MBTK_INFO_ERR_UNSUPPORTED;
5677 LOG("Get POWERIND state UNSUPPORTED.");
5678 }
5679 else // Set powerind state.
5680 {
5681 uint32 state = *(pack->data);
5682 if(req_powerind_set(state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5683 {
5684 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5685 err = MBTK_INFO_ERR_CME + cme_err;
5686 } else {
5687 err = MBTK_INFO_ERR_UNKNOWN;
5688 }
5689 LOG("Set POWERIND state fail.");
5690 }
5691 else
5692 {
5693 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_WAKEUP_STA_RSP, NULL, 0);
5694 }
5695 }
5696 break;
5697 }
5698 case MBTK_INFO_ID_OOS_STA_REQ:
5699 {
5700 if(pack->data_len == 0 || pack->data == NULL)
5701 {
5702 mbtk_oos_info oos_t;
5703 if(req_oos_get(&oos_t, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5704 {
5705 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5706 err = MBTK_INFO_ERR_CME + cme_err;
5707 } else {
5708 err = MBTK_INFO_ERR_UNKNOWN;
5709 }
5710 LOG("Get SMS OOS fail.");
r.xiaoec113d12024-01-12 02:13:28 -08005711 }
5712 else
5713 {
r.xiaoec113d12024-01-12 02:13:28 -08005714 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_OOS_STA_RSP, &oos_t, sizeof(mbtk_oos_info));
5715 }
5716 }
b.liufe320632024-01-17 20:38:08 +08005717 else // Set OOS
r.xiaoec113d12024-01-12 02:13:28 -08005718 {
r.xiaocfd7c682024-01-22 03:59:46 -08005719 mbtk_oos_info *state = (mbtk_oos_info *)pack->data;
5720 if(pack->data_len != sizeof(mbtk_oos_info))
5721 {
5722 err = MBTK_INFO_ERR_REQ_PARAMETER;
5723 LOG("Set oos error.");
5724 break;
5725 }
5726
r.xiaoec113d12024-01-12 02:13:28 -08005727 if(req_oos_set(state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5728 {
5729 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5730 err = MBTK_INFO_ERR_CME + cme_err;
5731 } else {
5732 err = MBTK_INFO_ERR_UNKNOWN;
5733 }
5734 LOG("Set OOS fail.");
5735 }
5736 else
5737 {
5738 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_OOS_STA_RSP, NULL, 0);
5739 }
5740 }
5741 break;
5742 }
wangyouqiang38e53362024-01-23 10:53:48 +08005743 case MBTK_INFO_ID_LED_REQ:
5744 {
5745 if(pack->data_len == 0 || pack->data == NULL)
5746 {
5747 err = MBTK_INFO_ERR_UNSUPPORTED;
5748 LOGE("led param is error.");
5749 }
5750 else
5751 {
5752 char type = pack->data[0];
5753 char status = pack->data[1];
5754 LOGE("[set_led] = [%d], [status_led] = [%d].", type, status);
r.xiaoec113d12024-01-12 02:13:28 -08005755
wangyouqiang38e53362024-01-23 10:53:48 +08005756 if(type == MBTK_LED_TYPE_NET)
5757 {
5758 if(status == MBTK_LED_STATUS_CLOSE)
5759 {
5760 mbtk_net_led_set(MBTK_NET_LED_CLOSE);
5761 }
5762 else
5763 {
5764 mbtk_net_led_set(MBTK_NET_LED_OPEN);
5765 }
5766 }
5767 else
5768 {
5769 if(status == MBTK_LED_STATUS_CLOSE)
5770 {
5771 status_led_set(MBTK_STATUS_LED_CLOSE);
5772 }
5773 else
5774 {
5775 status_led_set(MBTK_STATUS_LED_OPEN);
5776 }
5777 }
5778 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_LED_RSP, NULL, 0);
5779 }
5780 break;
5781 }
liubin281ac462023-07-19 14:22:54 +08005782 default:
5783 {
5784 err = MBTK_INFO_ERR_REQ_UNKNOWN;
5785 LOG("Unknown request : %s", id2str(pack->info_id));
5786 break;
5787 }
5788 }
5789
5790 return err;
5791 }
5792}
5793
5794// Process AT URC data
5795static int send_pack_to_queue(sock_client_info_t* cli_info, void* pack)
5796{
5797 if(info_queue.count >= PACK_PROCESS_QUEUE_MAX)
5798 {
5799 LOG("Packet process queue is full");
5800 return -1;
5801 }
5802
5803 info_queue_item_t *item = (info_queue_item_t*)malloc(sizeof(info_queue_item_t));
5804 if(!item)
5805 {
5806 LOG("malloc() fail[%d].", errno);
5807 return -1;
5808 }
5809 item->cli_info = cli_info;
5810 item->pack = pack;
5811 mbtk_queue_put(&info_queue, item);
5812
5813 // If thread is waitting,continue it.
5814 if(1/*!is_running*/)
5815 {
5816 pthread_mutex_lock(&info_mutex);
5817 pthread_cond_signal(&info_cond);
5818 pthread_mutex_unlock(&info_mutex);
5819 }
5820 else
5821 {
5822 LOG("Packet process thread is process...");
5823 }
5824
5825 return 0;
5826}
5827
5828static void radio_state_change(void *data, int data_len)
5829{
5830 uint8 *data_ptr = (uint8*)data;
5831 if(data_ptr[0]) {
5832 net_info.radio_state = MBTK_RADIO_STATE_ON;
5833 } else {
5834 net_info.radio_state = MBTK_RADIO_STATE_OFF;
5835 }
5836
5837 sock_client_info_t *cli = NULL;
5838 list_first(sock_client_list);
5839 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5840 {
5841 if(cli->ind_num > 0) {
5842 int i;
5843 for(i = 0; i < IND_REGISTER_MAX; i++) {
5844 // Registe MBTK_INFO_ID_IND_RADIO_STATE_CHANGE
5845 if(cli->ind_register[i] == MBTK_INFO_ID_IND_RADIO_STATE_CHANGE) {
5846 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_RADIO_STATE_CHANGE, data, data_len);
5847 break;
5848 }
5849 }
5850 }
5851 }
5852}
5853
5854static void pdp_state_change(void *data, int data_len)
5855{
5856 sock_client_info_t *cli = NULL;
5857 list_first(sock_client_list);
5858 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5859 {
5860 if(cli->ind_num > 0) {
5861 int i;
5862 for(i = 0; i < IND_REGISTER_MAX; i++) {
5863 if(cli->ind_register[i] == MBTK_INFO_ID_IND_PDP_STATE_CHANGE) {
5864 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, data, data_len);
5865 break;
5866 }
5867 }
5868 }
5869 }
5870}
5871
5872static void net_state_change(void *data, int data_len)
5873{
5874 sock_client_info_t *cli = NULL;
5875 list_first(sock_client_list);
5876 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5877 {
5878 if(cli->ind_num > 0) {
5879 int i;
5880 for(i = 0; i < IND_REGISTER_MAX; i++) {
5881 // Registe MBTK_INFO_ID_IND_NET_STATE_CHANGE
5882 if(cli->ind_register[i] == MBTK_INFO_ID_IND_NET_STATE_CHANGE) {
5883 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_NET_STATE_CHANGE, data, data_len);
5884 break;
5885 }
5886 }
5887 }
5888 }
5889}
5890
5891static void call_state_change(void *data, int data_len)
5892{
5893 sock_client_info_t *cli = NULL;
5894 list_first(sock_client_list);
5895 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5896 {
5897 if(cli->ind_num > 0) {
5898 int i;
5899 for(i = 0; i < IND_REGISTER_MAX; i++) {
5900 // Registed MBTK_INFO_ID_IND_RADIO_STATE_CHANGE
5901 if(cli->ind_register[i] == MBTK_INFO_ID_IND_CALL_STATE_CHANGE) {
5902 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_CALL_STATE_CHANGE, data, data_len);
5903 break;
5904 }
5905 }
5906 }
5907 }
5908}
5909
5910static void sim_state_change(void *data, int data_len)
5911{
5912 sock_client_info_t *cli = NULL;
5913 list_first(sock_client_list);
5914 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5915 {
5916 if(cli->ind_num > 0) {
5917 int i;
5918 for(i = 0; i < IND_REGISTER_MAX; i++) {
5919 // Registed MBTK_INFO_ID_IND_RADIO_STATE_CHANGE
5920 if(cli->ind_register[i] == MBTK_INFO_ID_IND_SIM_STATE_CHANGE) {
5921 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SIM_STATE_CHANGE, data, data_len);
5922 break;
5923 }
5924 }
5925 }
5926 }
5927}
5928
5929static void sms_state_change(void *data, int data_len)
5930{
5931 sock_client_info_t *cli = NULL;
5932 list_first(sock_client_list);
5933 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5934 {
5935 if(cli->ind_num > 0) {
5936 int i;
5937 for(i = 0; i < IND_REGISTER_MAX; i++) {
5938 // Registed MBTK_INFO_ID_IND_SMS_STATE_CHANGE
5939 if(cli->ind_register[i] == MBTK_INFO_ID_IND_SMS_STATE_CHANGE) {
5940 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SMS_STATE_CHANGE, data, data_len);
5941 break;
5942 }
5943 }
5944 }
5945 }
5946}
5947
r.xiaofca7c472024-04-24 01:00:23 -07005948static void signal_state_change(void *data, int data_len)
5949{
5950 sock_client_info_t *cli = NULL;
5951 list_first(sock_client_list);
5952 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5953 {
5954 if(cli->ind_num > 0) {
5955 int i;
5956 for(i = 0; i < IND_REGISTER_MAX; i++) {
5957 // Registe MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE
5958 if(cli->ind_register[i] == MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE) {
5959 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE, data, data_len);
5960 break;
5961 }
5962 }
5963 }
5964 }
5965}
5966
5967
liubin281ac462023-07-19 14:22:54 +08005968int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len)
5969{
5970#if 0
5971 if(urc_queue.count >= PACK_PROCESS_QUEUE_MAX)
5972 {
5973 LOG("Packet process queue is full");
5974 return -1;
5975 }
5976
5977 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
5978 if(!urc)
5979 {
5980 LOG("malloc() fail[%d].", errno);
5981 return -1;
5982 }
5983 urc->msg = msg;
5984 urc->data = memdup(data, data_len);
5985 urc->data_len = data_len;
5986
5987 mbtk_queue_put(&urc_queue, urc);
5988
5989 // If thread is waitting,continue it.
5990 if(1/*!is_running*/)
5991 {
5992 pthread_mutex_lock(&urc_mutex);
5993 pthread_cond_signal(&urc_cond);
5994 pthread_mutex_unlock(&urc_mutex);
5995 }
5996 else
5997 {
5998 LOG("Packet process thread is process...");
5999 }
6000
6001 return 0;
6002#else
6003 if(async_process) {
6004 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
6005 if(!urc)
6006 {
6007 LOG("malloc() fail[%d].", errno);
6008 return -1;
6009 }
6010 urc->msg = msg;
6011 if(data && data_len > 0) {
6012 urc->data = memdup(data, data_len);
6013 urc->data_len = data_len;
6014 } else {
6015 urc->data = NULL;
6016 urc->data_len = 0;
6017 }
6018 return send_pack_to_queue(NULL, urc);
6019 } else {
6020 switch(msg) {
6021 case INFO_URC_MSG_NET_CS_REG_STATE:
6022 {
6023 net_state_change(data, data_len);
6024 break;
6025 }
6026 case INFO_URC_MSG_CALL_STATE:
6027 {
6028 call_state_change(data, data_len);
6029 break;
6030 }
6031 case INFO_URC_MSG_SMS_STATE:
6032 {
6033 sms_state_change(data, data_len);
6034 break;
6035 }
6036 case INFO_URC_MSG_SIM_STATE:
6037 {
6038 sim_state_change(data, data_len);
6039 break;
6040 }
6041 case INFO_URC_MSG_PDP_STATE:
6042 {
6043 pdp_state_change(data, data_len);
6044 break;
6045 }
6046 default: {
6047 LOGE("Unknown msg : %d", msg);
6048 break;
6049 }
6050 }
6051
6052 return 0;
6053 }
6054#endif
6055}
6056
6057
6058static void ind_regisger(sock_client_info_t* cli_info, uint16 ind)
6059{
6060 uint32 i = 0;
6061 while(i < cli_info->ind_num)
6062 {
6063 if(cli_info->ind_register[i] == ind)
6064 break;
6065 i++;
6066 }
6067
6068 if(i == cli_info->ind_num) // No found IND
6069 {
6070 cli_info->ind_register[i] = ind;
6071 cli_info->ind_num++;
6072 LOG("Register IND : %s", id2str(ind));
6073 }
6074 else
6075 {
6076 LOG("IND had exist.");
6077 }
6078}
6079
6080static void pack_distribute(sock_client_info_t* cli_info, mbtk_info_pack_t* pack)
6081{
6082 // Register IND Message.
6083 if(mbtk_info_type_get(pack->info_id) == MBTK_INFO_TYPE_IND)
6084 {
6085 mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
6086 if(cli_info->ind_num >= IND_REGISTER_MAX)
6087 {
6088 LOG("IND if full.");
6089 err = MBTK_INFO_ERR_IND_FULL;
6090 }
6091 else
6092 {
6093 ind_regisger(cli_info, pack->info_id);
6094 }
6095
6096 pack_error_send(cli_info->fd, pack->info_id, err);
6097
6098 mbtk_info_pack_free(&pack);
6099 }
6100 else // Request Information.
6101 {
6102 LOG("Start process REQ(%s), Length : %d", id2str(pack->info_id), pack->data_len);
6103 if(0 && pack->data_len > 0)
6104 {
6105 log_hex("DATA", pack->data, pack->data_len);
6106 }
6107
6108 // Send to REQ_process_thread process.
6109 send_pack_to_queue(cli_info, pack);
6110
6111 // For test.
6112 // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS);
6113 }
6114}
6115
6116static sock_client_info_t* cli_find(int fd)
6117{
6118 sock_client_info_t *result = NULL;
6119 list_first(sock_client_list);
6120 while ((result = (sock_client_info_t*) list_next(sock_client_list)))
6121 {
6122 if (result->fd == fd)
6123 return result;
6124 }
6125
6126 return NULL;
6127}
6128
6129//mbtk wyq for server_ready_status add start
6130void server_ready_set(void)
6131{
6132 server_ready_status = 1;
6133}
6134
6135char server_ready_get(void)
6136{
6137 return server_ready_status;
6138}
6139
6140static void server_state_send(void)
6141{
6142 sock_client_info_t *cli = NULL;
6143 list_first(sock_client_list);
6144 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
6145 {
6146 if(cli->ind_num > 0) {
6147 if(cli->ind_register[0] == MBTK_INFO_ID_IND_SERVER_STATE_CHANGE) {
6148 cli->ind_num = 0;
6149 cli->ind_register[0] = 0;
6150 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SERVER_STATE_CHANGE, "1", 1);
6151 break;
6152 }
6153 }
6154 else
6155 {
6156 break;
6157 }
6158 }
6159 LOG("handshake message send ok.");
6160}
6161
6162//mbtk wyq for server_ready_status add end
6163
6164//mbtk wyq for data_call_ex add start
6165//Save the cid that "DATA_CALL" needs to be automatically connected after startup
6166void data_call_bootconn_save(int cid, int bootconn)
6167{
6168 if(cid_bootconn[cid] == bootconn + '0')
6169 {
6170 return;
6171 }
6172 cid_bootconn[cid] = bootconn + '0';
6173
6174 LOG("data_call_bootconn_set cid_bootconn = %s", cid_bootconn);
6175 property_set("persist.mbtk.datacall.bootconn", cid_bootconn);
6176}
6177
6178static void* data_call_bootconn_pthread(void *arg)
6179{
6180 UNUSED(arg);
6181 LOG("data_call_bootconn_pthread enter.");
6182 int i = 0;
6183 int send_sum = 0;
6184 int bootconn = 0;
b.liufe320632024-01-17 20:38:08 +08006185
liubin281ac462023-07-19 14:22:54 +08006186 while(1)
6187 {
6188 if(server_ready_get() && send_sum == 0)
6189 {
6190 server_state_send();
6191 send_sum = 1;
6192 }
b.liufe320632024-01-17 20:38:08 +08006193
liubin281ac462023-07-19 14:22:54 +08006194 if(net_info.sim_state == MBTK_SIM_READY && net_info.net_type == MBTK_RADIO_TECH_E_UTRAN && bootconn == 0)
6195 {
6196 //data_call_bootconn_exec();
6197 property_get("persist.mbtk.datacall.bootconn", cid_bootconn, "00000000");
6198 LOG("data_call_bootconn_exec cid_bootconn = %s", cid_bootconn);
b.liufe320632024-01-17 20:38:08 +08006199
liubin281ac462023-07-19 14:22:54 +08006200 for(i = MBTK_APN_CID_MIN; i < MBTK_APN_CID_MAX + 1; i++)
6201 {
6202 if(cid_bootconn[i] == '1')
6203 {
6204 sock_client_info_t *info = (sock_client_info_t*)malloc(sizeof(sock_client_info_t));
6205 if(info == NULL)
6206 {
6207 LOG("clinent_info malloc() fail.");
6208 continue;
6209 }
6210 memset(info, 0, sizeof(sock_client_info_t));
6211 info->fd = DATA_CALL_BOOTCONN_FD;
b.liufe320632024-01-17 20:38:08 +08006212
liubin281ac462023-07-19 14:22:54 +08006213 mbtk_info_pack_t* pack = mbtk_info_pack_creat(MBTK_INFO_ID_NET_DATA_CALL_REQ);
6214 if(pack == NULL)
6215 {
6216 free(info);
6217 LOG("Packet malloc() fail.");
6218 continue;
6219 }
6220
6221 // "info_err"
6222 //pack->info_err = byte_2_uint16(ptr, false)
6223
6224 // "data_len"
6225 pack->data_len = 5;
6226
6227 char *p = (char *)malloc(5);
6228 p[0] = MBTK_DATA_CALL_START;
6229 p[1] = i;
6230 p[2] = 0;
6231 p[3] = 1;
6232 p[4] = 10;
6233 pack->data = p;
6234 send_pack_to_queue(info, pack);
6235 }
6236 }
6237
6238 bootconn = 1;
6239 }
6240
6241 if(bootconn == 1 && send_sum == 1)
6242 {
6243 break;
6244 }
6245 else
6246 {
6247 sleep(1);
6248 }
6249 }
6250
6251 LOG("data_call_bootconn_pthread exit.");
6252 return NULL;
6253}
6254
6255//mbtk wyq for data_call_ex add end
6256
6257static void* info_main_pthread(void* arg)
6258{
6259 UNUSED(arg);
6260 epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1);
6261 if(epoll_fd < 0)
6262 {
6263 LOG("epoll_create() fail[%d].", errno);
6264 return NULL;
6265 }
6266
6267 uint32 event = EPOLLIN | EPOLLET;
6268 struct epoll_event ev;
6269 ev.data.fd = sock_listen_fd;
6270 ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
6271 epoll_ctl(epoll_fd,EPOLL_CTL_ADD,sock_listen_fd,&ev);
6272
6273 int nready = -1;
6274 struct epoll_event epoll_events[EPOLL_LISTEN_MAX];
6275 while(1)
6276 {
6277 nready = epoll_wait(epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
6278 if(nready > 0)
6279 {
6280 sock_client_info_t *cli_info = NULL;
6281 int i;
6282 for(i = 0; i < nready; i++)
6283 {
6284 LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events);
6285 if(epoll_events[i].events & EPOLLHUP) // Client Close.
6286 {
6287 if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL)
6288 {
6289 cli_close(cli_info);
6290 }
6291 else
6292 {
6293 LOG("Unknown client[fd = %d].", epoll_events[i].data.fd);
6294 }
6295 }
6296 else if(epoll_events[i].events & EPOLLIN)
6297 {
6298 if(epoll_events[i].data.fd == sock_listen_fd) // New clients connected.
6299 {
6300 int client_fd = -1;
6301 while(1)
6302 {
6303 struct sockaddr_in cliaddr;
6304 socklen_t clilen = sizeof(cliaddr);
6305 client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen);
6306 if(client_fd < 0)
6307 {
6308 if(errno == EAGAIN)
6309 {
6310 LOG("All client connect get.");
6311 }
6312 else
6313 {
6314 LOG("accept() error[%d].", errno);
6315 }
6316 break;
6317 }
6318 // Set O_NONBLOCK
6319 int flags = fcntl(client_fd, F_GETFL, 0);
6320 if (flags > 0)
6321 {
6322 flags |= O_NONBLOCK;
6323 if (fcntl(client_fd, F_SETFL, flags) < 0)
6324 {
6325 LOG("Set flags error:%d", errno);
6326 }
6327 }
6328
6329 memset(&ev,0,sizeof(struct epoll_event));
6330 ev.data.fd = client_fd;
6331 ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET;
6332 epoll_ctl(epoll_fd, EPOLL_CTL_ADD, client_fd, &ev);
6333
6334 sock_client_info_t *info = (sock_client_info_t*)malloc(sizeof(sock_client_info_t));
6335 if(info)
6336 {
6337 memset(info, 0, sizeof(sock_client_info_t));
6338 info->fd = client_fd;
6339 if(server_ready_get() == 1)
6340 {
6341 info->ind_num = 0;
6342 pack_rsp_send(info->fd , MBTK_INFO_ID_IND_SERVER_STATE_CHANGE, "1", 1);
6343 LOG("server ready ok.");
6344 }
6345 else
6346 {
6347 info->ind_num = 1;
6348 info->ind_register[0] = MBTK_INFO_ID_IND_SERVER_STATE_CHANGE;
6349 LOG("server ready no.");
6350 }
6351 list_add(sock_client_list, info);
6352 LOG("Add New Client FD Into List.");
6353 }
6354 else
6355 {
6356 LOG("malloc() fail.");
6357 }
6358 }
6359 }
6360 else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive.
6361 {
6362 // Read and process every message.
6363 mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
6364 mbtk_info_pack_t** pack = mbtk_info_pack_recv(cli_info->fd, true, &err);
6365
6366 // Parse packet error,send error response to client.
6367 if(pack == NULL)
6368 {
6369 if(err != MBTK_INFO_ERR_SUCCESS)
6370 {
6371 pack_error_send(cli_info->fd, MBTK_INFO_ID_REQ_UNKNOWN, err);
6372 }
6373 }
6374 else
6375 {
6376#if 0
6377 int i = 0;
6378 while(pack[i] != NULL)
6379 {
6380 pack_distribute(cli_info, pack[i]);
6381 // Not free,will free in pack_process() or packet process thread.
6382 //mbtk_info_pack_free(&(pack[i]));
6383 i++;
6384 }
6385 free(pack);
6386#else
6387 mbtk_info_pack_t** pack_ptr = pack;
6388 while(*pack_ptr)
6389 {
6390 pack_distribute(cli_info, *pack_ptr);
6391 // Not free,will free in pack_process() or packet process thread.
6392 //mbtk_info_pack_free(pack_ptr);
6393 pack_ptr++;
6394 }
6395
6396 free(pack);
6397#endif
6398 }
6399 }
6400 else
6401 {
6402 LOG("Unknown socket : %d", epoll_events[i].data.fd);
6403 }
6404 }
6405 else
6406 {
6407 LOG("Unknown event : %x", epoll_events[i].events);
6408 }
6409 }
6410 }
6411 else
6412 {
6413 LOG("epoll_wait() fail[%d].", errno);
6414 }
6415 }
6416
6417 return NULL;
6418}
6419
liubin281ac462023-07-19 14:22:54 +08006420/*
6421void mbtk_radio_ready_cb()
6422{
6423 pthread_t radio_pid;
6424 pthread_attr_t thread_attr;
6425 pthread_attr_init(&thread_attr);
6426 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
6427 {
6428 LOG("pthread_attr_setdetachstate() fail.");
6429 return;
6430 }
6431
6432 if(pthread_create(&radio_pid, &thread_attr, radio_ready_thread, NULL))
6433 {
6434 LOG("pthread_create() fail.");
6435 }
6436
6437 pthread_attr_destroy(&thread_attr);
6438}
6439*/
6440
6441static void net_ifc_state_change(bool act, int cid)
6442{
6443 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) { // No nothing for cid 1 and 8
6444 return;
6445 }
6446
yq.wanga9efa822024-07-03 04:33:48 -07006447#if 0
wangyouqiang65884152023-10-25 19:54:15 +08006448 if(act)
6449 {
6450 cid_active[cid] = 1;
wangyouqiang80487e42024-05-24 15:06:20 +08006451 mbtk_set_default_pdp_state(true, cid);
wangyouqiang65884152023-10-25 19:54:15 +08006452 }
6453 else
6454 {
6455 cid_active[cid] = 0;
wangyouqiang80487e42024-05-24 15:06:20 +08006456 mbtk_set_default_pdp_state(false, cid);
wangyouqiang65884152023-10-25 19:54:15 +08006457 }
yq.wanga9efa822024-07-03 04:33:48 -07006458#endif
liubin281ac462023-07-19 14:22:54 +08006459 char dev[20] = {0};
6460 sprintf(dev, "ccinet%d", cid - 1);
6461 if(act) { // Config IP.
6462 // Get IP information.
6463 mbtk_ipv4_info_t ipv4;
6464 mbtk_ipv6_info_t ipv6;
6465 memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t));
6466 memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t));
6467 int cme_err = MBTK_INFO_ERR_CME_NON;
6468 if(!req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON)
6469 {
wangyouqianged88c722023-11-22 16:33:43 +08006470#ifdef MBTK_AF_SUPPORT
6471 if(cid == 1)
6472 {
6473 ipv4.valid = false;
6474 ipv6.valid = false;
6475 if(default_iptype == MBTK_IP_TYPE_IP)
6476 {
6477 ipv4.valid = true;
6478 }
6479 else if(default_iptype == MBTK_IP_TYPE_IPV6)
6480 {
6481 ipv6.valid = true;
6482 }
6483 else
6484 {
6485 ipv4.valid = true;
6486 ipv6.valid = true;
6487 }
6488 }
6489#endif
liubin281ac462023-07-19 14:22:54 +08006490 // Config IPv4 address.
6491 if(ipv4.valid) {
6492 char ip[20] = {0};
6493 if(inet_ntop(AF_INET, &(ipv4.IPAddr), ip, 20) == NULL) {
6494 LOGE("inet_ntop ipv4 ip fail.");
6495 return;
6496 }
6497
6498 if(mbtk_ifc_configure2(dev, ip, 0, NULL, "255.255.255.0")) {
6499 LOGD("Config %s IPv4 %s fail.", dev, ip);
6500 } else {
6501 LOGD("Config %s IPv4 %s success.", dev, ip);
6502 }
6503 }
6504
6505 // Config IPv6 address.
6506 if(ipv6.valid) {
6507 char ip[50] = {0};
6508
6509 if(inet_ntop(AF_INET6, &(ipv6.IPV6Addr), ip, 50) == NULL) {
6510 LOGE("inet_ntop ipv6 ip fail.");
6511 return;
6512 }
6513
6514 if(mbtk_ipv6_config(dev, ip, 64)) {
6515 LOGD("Config %s IPv6 %s fail.", dev, ip);
6516 } else {
6517 LOGD("Config %s IPv6 %s success.", dev, ip);
6518 }
6519 }
yq.wanga9efa822024-07-03 04:33:48 -07006520
6521 mbtk_qser_route_config(cid, &ipv4, &ipv6);
liubin281ac462023-07-19 14:22:54 +08006522 }
6523 } else { // Del IP
6524 if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
6525 LOGD("Config %s IPv4 0 fail.", dev);
6526 } else {
6527 LOGD("Config %s IPv4 0 success.", dev);
6528 }
6529 }
6530}
6531
yq.wanga9efa822024-07-03 04:33:48 -07006532static void data_call_restart()
6533{
6534#if 0
6535 // Waitting for network ok.
6536 mbtk_net_info_t info;
6537 int cme_err;
6538 int i = 0;
6539 while(i < 15) { // 15s timeout
6540 cme_err = MBTK_INFO_ERR_CME_NON;
6541 memset(&info, 0, sizeof(mbtk_net_info_t));
6542 if(!req_net_sel_mode_get(&info, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON)
6543 {
6544 if(info.net_type >= 2) {
6545 break;
6546 }
6547 }
6548
6549 sleep(1);
6550 i++;
6551 }
6552#endif
6553 // +CGACT
6554 int cid;
wangyouqiang3947b302024-07-04 17:26:08 +08006555 uint8 data_pdp = 0;
yq.wanga9efa822024-07-03 04:33:48 -07006556 LOGD("Start active APN.");
6557 at_process = true;
6558 cgact_wait.act = true;
yq.wangd58f71e2024-08-21 23:45:31 -07006559 for(cid = MBTK_APN_CID_MIN; cid <= MBTK_APN_CID_MAX; cid++) {
6560 if(cid_active[cid])
6561 {
6562 LOG("Active cid : %d", cid);
6563 cgact_wait.waitting = true;
6564 cgact_wait.cid = cid;
6565 net_ifc_state_change(false, cid);
6566 data_pdp = cid + 100;
6567 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
6568 req_data_call_start(cid, NULL);
6569 wait_cgact_complete(10);
6570 net_ifc_state_change(true, cid);
6571 data_pdp = cid + 220;
6572 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
6573 }
yq.wanga9efa822024-07-03 04:33:48 -07006574 }
6575 at_process = false;
6576}
6577
liubin281ac462023-07-19 14:22:54 +08006578static void urc_msg_process(info_urc_msg_t *msg)
6579{
6580 uint8 *data = NULL;
6581 if(msg->data) {
6582 data = (uint8*)msg->data;
6583 }
6584 switch(msg->msg) {
6585 case INFO_URC_MSG_RADIO_STATE:
6586 {
6587 radio_state_change(msg->data, msg->data_len);
6588 // Reconfig APN while radio on.
6589 if(data[0]) {
6590 apn_prop_get();
6591 }
6592 break;
6593 }
6594 case INFO_URC_MSG_CGEV:
6595 {
6596 bool act = data[0];
6597 int cid = data[1];
6598 if(cid > 0) {
6599 net_ifc_state_change(act, cid);
6600 }
6601 break;
6602 }
6603 case INFO_URC_MSG_NET_PS_REG_STATE:
6604 {
b.liufe320632024-01-17 20:38:08 +08006605 uint8 net_data[4];
liubin281ac462023-07-19 14:22:54 +08006606 net_data[0] = (uint8)MBTK_NET_PS_STATE;
b.liufe320632024-01-17 20:38:08 +08006607 net_data[1] = data[0]; // act
6608 net_data[3] = data[1]; // 0 - GSM/WCDMA; 1 - LTE
liubin281ac462023-07-19 14:22:54 +08006609 mbtk_net_reg_state_enum state = (mbtk_net_reg_state_enum)data[0];
6610 if(state == MBTK_NET_REG_STATE_HOME
6611 || state == MBTK_NET_REG_STATE_ROAMING) { // Registered, home network or roaming.
6612 mbtk_net_info_t info;
6613 int cme_err = MBTK_INFO_ERR_CME_NON;
6614 memset(&info, 0, sizeof(mbtk_net_info_t));
6615 if(!req_net_sel_mode_get(&info, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON)
6616 {
6617 net_data[2] = info.net_type;
6618 net_state_change(net_data, sizeof(net_data));
6619
6620 if(info.net_type >= MBTK_RADIO_TECH_UTRAN) {
6621 data_call_restart();
6622 }
6623 } else {
6624 net_data[2] = (uint8)0xFF;
6625 net_state_change(net_data, sizeof(net_data));
6626 }
6627 } else {
6628 net_data[2] = (uint8)0xFF;
6629 net_state_change(net_data, sizeof(net_data));
6630 }
6631 break;
6632 }
b.liuf37bd332024-03-18 13:51:24 +08006633 case INFO_URC_MSG_SET_BAND:
6634 {
6635 mbtk_band_info_t band;
6636 int cme_err = MBTK_INFO_ERR_CME_NON;
6637
6638 band.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
b.liu288093c2024-05-09 17:02:57 +08006639 band.gsm_band = (uint16)band_set_info.band_gsm;
6640 band.umts_band = (uint16)band_set_info.band_wcdma;
b.liuf37bd332024-03-18 13:51:24 +08006641 band.tdlte_band = band_set_info.band_tdlte;
6642 band.fddlte_band = band_set_info.band_fddlte;
b.liu288093c2024-05-09 17:02:57 +08006643 band.lte_ext_band = band_set_info.band_lte_ext;
6644
b.liuf37bd332024-03-18 13:51:24 +08006645 if(req_band_set(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
6646 {
6647 LOG("Set band fail.");
6648 }
6649 else // Set band success.
6650 {
b.liu45bfb532024-05-11 15:37:22 +08006651 // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));
b.liu288093c2024-05-09 17:02:57 +08006652 band_set_success = TRUE;
6653 if(band_area == MBTK_MODEM_BAND_AREA_CN) {
b.liuf37bd332024-03-18 13:51:24 +08006654 property_set("persist.mbtk.band_config", "CN");
b.liu288093c2024-05-09 17:02:57 +08006655 } else if(band_area == MBTK_MODEM_BAND_AREA_EU) {
b.liuf37bd332024-03-18 13:51:24 +08006656 property_set("persist.mbtk.band_config", "EU");
b.liu288093c2024-05-09 17:02:57 +08006657 } else if(band_area == MBTK_MODEM_BAND_AREA_SA) {
b.liuf678f992024-05-08 15:23:10 +08006658 property_set("persist.mbtk.band_config", "SA");
b.liuf37bd332024-03-18 13:51:24 +08006659 } else {
6660 property_set("persist.mbtk.band_config", "ALL");
6661 }
6662 LOG("Set band success.");
6663 }
6664 break;
6665 }
wangyouqiangce45a102024-04-18 18:08:29 +08006666 case INFO_URC_MSG_GET_SIM_STATE:
6667 {
6668 net_info.sim_state = getSIMStatus();
6669 if(net_info.sim_state == MBTK_SIM_READY)
6670 {
6671 LOG("SIM READY!");
6672 }
6673 else
6674 {
6675 LOG("SIM NOT READY!");
6676 }
6677 break;
6678 }
liubin281ac462023-07-19 14:22:54 +08006679 case INFO_URC_MSG_NET_STATE_LOG:
6680 {
6681 // Get network state and signal.
6682 char buff[256] = {0};
yq.wangf1fc31e2024-10-12 03:21:03 -07006683 uint8 data_signal[8];
6684 mbtk_signal_info_t signal;
liubin281ac462023-07-19 14:22:54 +08006685 memset(&signal, 0xFF, sizeof(mbtk_signal_info_t));
6686 if(!req_net_signal_get(&signal, NULL)) {
6687 char tmp[50] = {0};
6688 struct timeval log_time;
6689 gettimeofday(&log_time, NULL);
6690 struct tm* tm_t = localtime(&(log_time.tv_sec));
6691 strftime(tmp, 50, "%F %T", tm_t);
6692 snprintf(buff, sizeof(buff), "%s:%d,%d,%d,%d,%d,%d,%d,%d", tmp, signal.type, signal.rssi, signal.rxlev, signal.ber, signal.rscp, signal.ecno,
6693 signal.rsrq, signal.rsrp);
yq.wangf1fc31e2024-10-12 03:21:03 -07006694 mbtk_signal_log(buff);
6695 }
r.xiaofca7c472024-04-24 01:00:23 -07006696
yq.wangf1fc31e2024-10-12 03:21:03 -07006697 if(signal_globe.type != signal.type)
6698 {
6699 data_signal[0] = signal.type;
6700 data_signal[1] = signal.rssi;
6701 data_signal[2] = signal.rxlev;
6702 data_signal[3] = signal.ber;
6703 data_signal[4] = signal.rscp;
6704 data_signal[5] = signal.ecno;
6705 data_signal[6] = signal.rsrq;
6706 data_signal[7] = signal.rsrp;
6707 signal_globe.type = signal.type;
6708 signal_state_change(data_signal, sizeof(data_signal));
liubin281ac462023-07-19 14:22:54 +08006709 }
liubin281ac462023-07-19 14:22:54 +08006710 break;
6711 }
6712 default:
6713 {
6714 LOGE("Unknown URC : %d", msg->msg);
6715 break;
6716 }
6717 }
6718}
6719
6720static void* pack_process_thread(void* arg)
6721{
6722 UNUSED(arg);
6723 info_queue_item_t* item = NULL;
6724 mbtk_queue_init(&info_queue);
6725 pthread_mutex_init(&info_mutex, NULL);
6726 pthread_cond_init(&info_cond, NULL);
6727
6728 memset(&band_support, 0xFF, sizeof(mbtk_band_info_t));
6729
6730 pthread_mutex_lock(&info_mutex);
6731 while(TRUE)
6732 {
6733 if(mbtk_queue_empty(&info_queue))
6734 {
6735 LOG("Packet process wait...");
6736 pthread_cond_wait(&info_cond, &info_mutex);
6737 LOG("Packet process continue...");
6738 }
6739 else
6740 {
6741 LOG("Packet process queue not empty,continue...");
6742 }
6743
6744 // Process all information request.
6745 mbtk_info_err_enum err;
6746 while((item = (info_queue_item_t*)mbtk_queue_get(&info_queue)) != NULL)
6747 {
6748 if(item->cli_info) { // REQ form client.
6749 mbtk_info_pack_t *pack = (mbtk_info_pack_t*)item->pack;
6750 LOG("Process REQ %s.", id2str(pack->info_id));
6751 at_process = true;
6752 err = pack_req_process(item->cli_info, pack);
6753 if(err != MBTK_INFO_ERR_SUCCESS)
6754 {
6755 if(item->cli_info->fd != DATA_CALL_BOOTCONN_FD)
6756 {
6757 pack_error_send(item->cli_info->fd, pack->info_id + 1, err);
6758 }
6759 else
6760 {
wangyouqiang80487e42024-05-24 15:06:20 +08006761 if(pack->data != NULL)
6762 {
6763 free(pack->data);
6764 }
6765 if(item->cli_info)
6766 {
6767 free(item->cli_info);
6768 }
liubin281ac462023-07-19 14:22:54 +08006769 }
6770 }
6771 at_process = false;
6772 mbtk_info_pack_free(&pack);
6773 free(item);
6774 } else { // REQ from myself.
6775 info_urc_msg_t *urc = (info_urc_msg_t*)item->pack;
6776 LOG("Process URC %d.", urc->msg);
6777 urc_msg_process(urc);
6778 if(!urc->data)
6779 free(urc->data);
6780 free(urc);
6781 }
6782 }
6783 }
6784 pthread_mutex_unlock(&info_mutex);
6785 return NULL;
6786}
6787
6788void apn_prop_get()
6789{
6790 char prop_name[20];
6791 char prop_data[300];
6792 // cid : 2 - 7
6793 int cid = MBTK_APN_CID_MIN;
6794 mbtk_apn_info_t apn;
6795 for(; cid <= MBTK_APN_CID_MAX; cid++) {
6796 memset(prop_name, 0, 20);
6797 memset(prop_data, 0, 300);
6798 memset(&apn, 0, sizeof(mbtk_apn_info_t));
6799 sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid);
6800 if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) {
6801 apn.cid = cid;
6802 char *ptr_1 = prop_data;
6803 apn.ip_type = (mbtk_ip_type_enum)atoi(ptr_1);
6804 ptr_1 = strstr(ptr_1, ",");
6805 if(!ptr_1) {
6806 continue;
6807 }
6808 ptr_1++; // Jump ',' to apn
6809
6810 char *ptr_2 = strstr(ptr_1, ",");
6811 if(!ptr_2) {
6812 continue;
6813 }
6814 memcpy(apn.apn, ptr_1, ptr_2 - ptr_1); // apn
6815
6816 ptr_2++; // Jump ',' to user
6817 ptr_1 = strstr(ptr_2, ",");
6818 if(!ptr_1) {
6819 continue;
6820 }
6821 if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
6822 memcpy(apn.user, ptr_2, ptr_1 - ptr_2); // user
6823 }
6824
6825 ptr_1++; // Jump ',' to pass
6826 ptr_2 = strstr(ptr_1, ",");
6827 if(!ptr_2) {
6828 continue;
6829 }
6830 if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
6831 memcpy(apn.pass, ptr_1, ptr_2 - ptr_1); // pass
6832 }
6833
6834 ptr_2++; // Jump ',' to auth (Is last item)
6835 if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
6836 memcpy(apn.auth, ptr_2, strlen(ptr_2)); // auth
6837 }
6838
6839 req_apn_set(&apn, NULL);
6840 }
6841 }
6842}
6843
6844/*
b.liue0ab2442024-02-06 18:53:28 +08006845root@OpenWrt:/usrdata# cat /proc/mtd
6846dev: size erasesize name
6847mtd0: 00040000 00020000 "bootloader"
6848mtd1: 00020000 00020000 "cp_reliabledata"
6849mtd2: 00020000 00020000 "ap_reliabledata"
6850mtd3: 00020000 00020000 "cp_reliabledata_backup"
6851mtd4: 00020000 00020000 "ap_reliabledata_backup"
6852mtd5: 00020000 00020000 "mep-ota"
6853mtd6: 00020000 00020000 "mep-ota_backup"
6854mtd7: 00040000 00020000 "dtim"
6855mtd8: 00f40000 00020000 "cpimage"
6856mtd9: 000c0000 00020000 "u-boot"
6857mtd10: 00500000 00020000 "kernel"
6858mtd11: 00100000 00020000 "asr_flag"
6859mtd12: 01400000 00020000 "rootfs"
6860mtd13: 01400000 00020000 "oem_data"
6861mtd14: 01e00000 00020000 "OTA"
6862mtd15: 01400000 00020000 "rootfs_data"
6863mtd16: 081a0000 00020000 "user_data"
6864mtd17: 00d20000 00020000 "MRVL_BBM"
6865*/
6866static int partition_name_2_dev(const char *name, char *dev) {
6867 if(name == NULL || dev == NULL) {
6868 LOGE("ARG error.");
6869 return -1;
6870 }
6871
6872 int fp = fopen("/proc/mtd", "r");
6873 if (fp == NULL) {
6874 LOGE("Open MTD failed!");
6875 return -1;
6876 }
6877
6878 char buf[1024];
6879 while (fgets(buf, 1024, fp) != NULL) {
6880 if(strstr(buf, name)) {
6881 int index = atoi(buf + 3);
6882 sprintf(dev, "/dev/mtdblock%d", index);
6883 LOGD("%s -> %s", name, dev);
6884 return 0;
6885 }
6886 }
6887
6888 return -1;
6889}
6890
6891static int custom_partition_read(const char *name, mbtk_cust_info_t *cust_info)
6892{
6893 int fd = 0, ret = 0;
6894 unsigned int step = 0, offset = 0, flaglen = 0;
6895 flaglen = sizeof(mbtk_cust_info_t);
6896
6897 char mtd_path[50] = {0};
6898 if(partition_name_2_dev(name, mtd_path)) {
6899 LOGE("partition_name_2_dev() failed!");
6900 return -1;
6901 }
6902
6903 fd = open(mtd_path, O_RDONLY);
6904 if (fd < 0) {
6905 LOGE("Fatal error: can't open cust info %s\n", mtd_path);
6906 return -1;
6907 }
6908
6909 if (read(fd, cust_info, flaglen) < 0)
6910 goto error;
6911 if (cust_info->header != CUST_INFO_HEADER) {
6912 LOGE("Cust info partition error.");
6913 goto error;
6914 } else {
6915 if(cust_info->band_type == 1) { // CN
6916 LOGD("Band : CN");
6917 } else if(cust_info->band_type == 2) { // EU
6918 LOGD("Band : EU");
6919 } else {
6920 LOGE("Unknown band type:%d", cust_info->band_type);
6921 goto error;
6922 }
6923 }
6924 close(fd);
6925 return 0;
6926error:
6927 close(fd);
6928 return -1;
6929}
6930
6931/*
liubin281ac462023-07-19 14:22:54 +08006932AT*BAND=15,78,147,482,134742231
6933
6934OK
6935*/
b.liubb5e7682024-02-28 20:13:04 +08006936static void* band_config_thread()
liubin281ac462023-07-19 14:22:54 +08006937{
b.liubb5e7682024-02-28 20:13:04 +08006938 mbtk_device_info_modem_t info_modem;
b.liuf37bd332024-03-18 13:51:24 +08006939 memset(&band_set_info, 0, sizeof(band_set_info_t));
b.liubb5e7682024-02-28 20:13:04 +08006940 memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
b.liu288093c2024-05-09 17:02:57 +08006941 band_set_success = FALSE;
b.liuf37bd332024-03-18 13:51:24 +08006942 if(mbtk_dev_info_read(MBTK_DEVICE_INFO_ITEM_MODEM, &(info_modem), sizeof(mbtk_device_info_modem_t))) {
b.liubb5e7682024-02-28 20:13:04 +08006943 LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
b.liu288093c2024-05-09 17:02:57 +08006944 band_area = MBTK_MODEM_BAND_AREA_ALL;
b.liuf37bd332024-03-18 13:51:24 +08006945 band_set_info.band_gsm = MBTK_BAND_ALL_GSM_DEFAULT;
6946 band_set_info.band_wcdma = MBTK_BAND_ALL_WCDMA_DEFAULT;
6947 band_set_info.band_tdlte = MBTK_BAND_ALL_TDLTE_DEFAULT;
6948 band_set_info.band_fddlte = MBTK_BAND_ALL_FDDLTE_DEFAULT;
b.liu288093c2024-05-09 17:02:57 +08006949 band_set_info.band_lte_ext = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
b.liubb5e7682024-02-28 20:13:04 +08006950 } else {
b.liu288093c2024-05-09 17:02:57 +08006951 band_area = info_modem.band_area;
b.liuf37bd332024-03-18 13:51:24 +08006952 band_set_info.band_gsm = info_modem.band_gsm;
6953 band_set_info.band_wcdma = info_modem.band_wcdma;
6954 band_set_info.band_tdlte = info_modem.band_tdlte;
6955 band_set_info.band_fddlte = info_modem.band_fddlte;
b.liuf678f992024-05-08 15:23:10 +08006956 band_set_info.band_lte_ext = info_modem.band_lte_ext;
b.liuf37bd332024-03-18 13:51:24 +08006957 }
b.liubb5e7682024-02-28 20:13:04 +08006958
b.liuf37bd332024-03-18 13:51:24 +08006959 bool is_first = TRUE;
b.liu288093c2024-05-09 17:02:57 +08006960 while(!band_set_success) {
b.liuf37bd332024-03-18 13:51:24 +08006961 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
6962 if(!urc)
6963 {
6964 LOG("malloc() fail[%d].", errno);
6965 break;
b.liubb5e7682024-02-28 20:13:04 +08006966 } else {
b.liuf37bd332024-03-18 13:51:24 +08006967 urc->msg = INFO_URC_MSG_SET_BAND;
6968 urc->data = NULL;
6969 urc->data_len = 0;
6970 send_pack_to_queue(NULL, urc);
6971
6972 if(is_first) {
6973 is_first = FALSE;
6974 } else {
b.liu288093c2024-05-09 17:02:57 +08006975 LOGE("*BAND exec error, will retry in 5s.");
b.liuf37bd332024-03-18 13:51:24 +08006976 }
b.liu288093c2024-05-09 17:02:57 +08006977 sleep(5);
b.liubb5e7682024-02-28 20:13:04 +08006978 }
6979 }
6980
b.liuf37bd332024-03-18 13:51:24 +08006981 LOGD("Set Band thread exit.");
b.liubb5e7682024-02-28 20:13:04 +08006982 return NULL;
liubin281ac462023-07-19 14:22:54 +08006983}
6984
6985static void* net_monitor_thread(void* arg)
6986{
6987 UNUSED(arg);
6988 // Start network monitor
6989 int cid;
6990 while(1) {
6991#if 0
6992 // Config IP
6993 list_node_t* apn_list = NULL;
6994 if(!apn_state_get(&apn_list) && apn_list != NULL) {
6995 info_apn_ip_t *apn = NULL;
6996 for(cid = MBTK_APN_CID_MIN; cid <= MBTK_APN_CID_MAX && cid_active[cid]; cid++) {
6997 bool ip_found = false;
6998 list_first(apn_list);
6999 while ((apn = (info_apn_ip_t*) list_next(apn_list))) {
7000 if(cid == apn->cid) {
7001 ip_found = true;
7002 break;
7003 }
7004 }
7005
7006 char dev[20] = {0};
7007 sprintf(dev, "ccinet%d", cid - 1);
7008 if(ip_found) { // Ip ok,set IP.
7009 if(apn->ipv4_valid) {
7010 if(mbtk_ifc_configure2(dev, (char*)apn->ipv4, 0, NULL, "255.255.255.0")) {
7011 LOGD("Config %s IPv4 %s fail.", dev, apn->ipv4);
7012 } else {
7013 LOGD("Config %s IPv4 %s success.", dev, apn->ipv4);
7014 }
7015 }
7016
7017 if(apn->ipv6_valid) {
7018 if(mbtk_ipv6_config(dev, (char*)apn->ipv6, 64)) {
7019 LOGD("Config %s IPv6 %s fail.", dev, apn->ipv6);
7020 } else {
7021 LOGD("Config %s IPv6 %s success.", dev, apn->ipv6);
7022 }
7023 }
7024 } else { // No ip
7025 if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
7026 LOGD("Config %s IPv4 0 fail.", dev);
7027 } else {
7028 LOGD("Config %s IPv4 0 success.", dev);
7029 }
7030 }
7031 }
7032
7033 list_free(apn_list);
7034 }
7035#endif
7036
7037 if(net_info.radio_state == MBTK_RADIO_STATE_ON && net_info.sim_state == MBTK_SIM_READY) {
7038#if 0
7039 urc_msg_distribute(true, INFO_URC_MSG_NET_CS_REG_STATE, NULL, 0);
7040#else
7041 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
7042 if(!urc)
7043 {
7044 LOG("malloc() fail[%d].", errno);
7045 } else {
7046 urc->msg = INFO_URC_MSG_NET_STATE_LOG;
7047 urc->data = NULL;
7048 urc->data_len = 0;
7049 send_pack_to_queue(NULL, urc);
7050 }
7051#endif
wangyouqiangce45a102024-04-18 18:08:29 +08007052 sleep(15);
liubin281ac462023-07-19 14:22:54 +08007053 }
wangyouqiangce45a102024-04-18 18:08:29 +08007054 else
7055 {
7056 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
7057 if(!urc)
7058 {
7059 LOG("malloc() fail[%d].", errno);
7060 }
7061 else
7062 {
7063 urc->msg = INFO_URC_MSG_GET_SIM_STATE;
7064 urc->data = NULL;
7065 urc->data_len = 0;
7066 send_pack_to_queue(NULL, urc);
7067 }
7068 sleep(2);
7069 }
liubin281ac462023-07-19 14:22:54 +08007070 }
7071
7072 LOGD("monitor_thread exit.");
7073 return NULL;
7074}
7075
7076static void* urc_process_thread(void* arg)
7077{
7078 UNUSED(arg);
7079 info_urc_msg_t* item = NULL;
7080 mbtk_queue_init(&urc_queue);
7081 pthread_mutex_init(&urc_mutex, NULL);
7082 pthread_cond_init(&urc_cond, NULL);
7083
7084 pthread_mutex_lock(&urc_mutex);
7085 while(TRUE)
7086 {
7087 if(mbtk_queue_empty(&urc_queue))
7088 {
7089 LOG("URC process wait...");
7090 pthread_cond_wait(&urc_cond, &urc_mutex);
7091 LOG("URC process continue...");
7092 }
7093 else
7094 {
7095 LOG("URC process queue not empty,continue...");
7096 }
7097
7098 // Process all information request.
7099 while((item = (info_urc_msg_t*)mbtk_queue_get(&urc_queue)) != NULL)
7100 {
7101 LOG("Process URC %d.", item->msg);
7102 uint8 *data = (uint8*)item->data;
7103 switch(item->msg) {
7104 case INFO_URC_MSG_RADIO_STATE:
7105 {
7106 radio_state_change(item->data, item->data_len);
7107 break;
7108 }
7109 case INFO_URC_MSG_CGEV:
7110 {
7111 bool act = data[0];
7112 int cid = data[1];
7113 if(cid > 0) {
7114 net_ifc_state_change(act, cid);
7115 }
7116 break;
7117 }
7118 default:
7119 {
7120 LOGE("Unknown URC : %d", item->msg);
7121 break;
7122 }
7123 }
7124 if(!item->data)
7125 free(item->data);
7126 free(item);
7127 }
7128 }
7129 pthread_mutex_unlock(&urc_mutex);
7130
7131 return NULL;
7132}
7133
7134static void ril_at_ready_process()
7135{
7136 net_info.radio_state = (isRadioOn() == 1) ? MBTK_RADIO_STATE_ON : MBTK_RADIO_STATE_OFF;
7137#if 1
7138 if (net_info.radio_state != MBTK_RADIO_STATE_ON)
7139 {
7140 setRadioPower(1);
7141 } else { // Radio has ON
7142 apn_prop_get();
7143 }
7144
7145 if(net_info.radio_state == MBTK_RADIO_STATE_ON)
7146 {
7147 at_send_command("AT+CEREG=2", NULL);
7148 }
7149
7150 int count = 0;
7151#endif
7152 net_info.sim_state = getSIMStatus();
7153#if 0
7154 while (net_info.sim_state != MBTK_SIM_READY && count < 30)
7155 {
7156 if(net_info.radio_state != MBTK_RADIO_STATE_ON)
7157 {
7158 setRadioPower(1);
7159 }
7160 LOGD("Waitting for SIM READY...");
7161 sleep(1);
7162 net_info.sim_state = getSIMStatus();
7163 count++;
7164 }
7165#endif
7166 if(net_info.sim_state == MBTK_SIM_READY)
7167 {
7168 LOGD("SIM READY!");
r.xiao7c62bc62024-05-24 00:53:30 -07007169 at_send_command("AT+COPS=3", NULL);
liubin281ac462023-07-19 14:22:54 +08007170 }
7171 else
7172 {
7173 LOGE("SIM NOT READY!");
7174 }
liubin281ac462023-07-19 14:22:54 +08007175}
7176
wangyouqiang80487e42024-05-24 15:06:20 +08007177int mbtk_get_apn_send_pack(void)
7178{
7179 sock_client_info_t *info = (sock_client_info_t*)malloc(sizeof(sock_client_info_t));
7180 if(info == NULL)
7181 {
7182 LOG("clinent_info malloc() fail.");
7183 return -1;
7184 }
7185 memset(info, 0, sizeof(sock_client_info_t));
7186 info->fd = DATA_CALL_APN_GET_FD;
7187
7188 mbtk_info_pack_t* pack = mbtk_info_pack_creat(MBTK_INFO_ID_NET_QSER_APN_REQ);
7189 if(pack == NULL)
7190 {
7191 free(info);
7192 LOG("Packet malloc() fail.");
7193 return -1;
7194 }
7195
7196 send_pack_to_queue(info, pack);
7197 return 0;
7198}
7199
liubin281ac462023-07-19 14:22:54 +08007200int mbtk_info_server_start()
7201{
7202 signal(SIGPIPE, SIG_IGN);
7203
wangyouqiangce45a102024-04-18 18:08:29 +08007204 //check cfun and sim card status
7205 ril_at_ready_process();
7206
7207 //any AT instruction that is not sent through pack_process_thread needs to precede the thread
7208 //thread create
liubin281ac462023-07-19 14:22:54 +08007209 if(sock_listen_fd > 0)
7210 {
7211 LOG("Information Server Has Started.");
7212 return -1;
7213 }
7214
7215 struct sockaddr_un server_addr;
7216 sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
7217 if(sock_listen_fd < 0)
7218 {
7219 LOG("socket() fail[%d].", errno);
7220 return -1;
7221 }
7222
7223 // Set O_NONBLOCK
7224 int flags = fcntl(sock_listen_fd, F_GETFL, 0);
7225 if (flags < 0)
7226 {
7227 LOG("Get flags error:%d", errno);
7228 goto error;
7229 }
7230 flags |= O_NONBLOCK;
7231 if (fcntl(sock_listen_fd, F_SETFL, flags) < 0)
7232 {
7233 LOG("Set flags error:%d", errno);
7234 goto error;
7235 }
7236
7237 unlink(SOCK_INFO_PATH);
7238 memset(&server_addr, 0, sizeof(struct sockaddr_un));
7239 server_addr.sun_family = AF_LOCAL;
7240 strcpy(server_addr.sun_path, SOCK_INFO_PATH);
7241 if(bind(sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)))
7242 {
7243 LOG("bind() fail[%d].", errno);
7244 goto error;
7245 }
7246
7247 if(listen(sock_listen_fd, SOCK_CLIENT_MAX))
7248 {
7249 LOG("listen() fail[%d].", errno);
7250 goto error;
7251 }
7252
7253 sock_client_list = list_create(sock_cli_free_func);
7254 if(sock_client_list == NULL)
7255 {
7256 LOG("list_create() fail.");
7257 goto error;
7258 }
7259
7260 pthread_t info_pid, pack_pid, monitor_pid, urc_pid, bootconn_pid;
7261 pthread_attr_t thread_attr;
7262 pthread_attr_init(&thread_attr);
7263 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
7264 {
7265 LOG("pthread_attr_setdetachstate() fail.");
7266 goto error;
7267 }
7268
7269 if(pthread_create(&info_pid, &thread_attr, info_main_pthread, NULL))
7270 {
7271 LOG("pthread_create() fail.");
7272 goto error;
7273 }
7274
7275 if(pthread_create(&pack_pid, &thread_attr, pack_process_thread, NULL))
7276 {
7277 LOG("pthread_create() fail.");
7278 goto error;
7279 }
7280
7281#if 0
7282 if(pthread_create(&urc_pid, &thread_attr, urc_process_thread, NULL))
7283 {
7284 LOG("pthread_create() fail.");
7285 goto error;
7286 }
7287#endif
7288
b.liubb5e7682024-02-28 20:13:04 +08007289 // Set Band
7290 // AT*BAND=15,78,147,482,134742231
7291 char buff[10];
7292 memset(buff, 0, 10);
7293 property_get("persist.mbtk.band_config", buff, "");
7294 if(strlen(buff) == 0) {
7295 pthread_t band_pid;
7296 if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL))
7297 {
7298 LOG("pthread_create() fail.");
7299 }
7300 }
7301
b.liuf1ab8152024-05-23 13:16:07 +08007302#if 0
liubin281ac462023-07-19 14:22:54 +08007303 if(pthread_create(&monitor_pid, &thread_attr, net_monitor_thread, NULL))
7304 {
7305 LOG("pthread_create() fail.");
7306 }
b.liuf1ab8152024-05-23 13:16:07 +08007307#endif
liubin281ac462023-07-19 14:22:54 +08007308
7309 //mbtk wyq for data_call_ex add start
7310 if(pthread_create(&bootconn_pid, &thread_attr, data_call_bootconn_pthread, NULL))
7311 {
7312 LOG("pthread_create() fail.");
7313 }
7314 //mbtk wyq for data_call_ex add end
7315
7316 pthread_attr_destroy(&thread_attr);
7317
wangyouqiang80487e42024-05-24 15:06:20 +08007318 mbtk_qser_apn_init();
7319
liubin281ac462023-07-19 14:22:54 +08007320 LOG("MBTK Information Server Start...");
7321
7322 return 0;
7323
7324error:
7325 close(sock_listen_fd);
7326 sock_listen_fd = -1;
7327 return -1;
7328}
7329
7330#if 0
7331int main(int argc, char *argv[])
7332{
7333 if(mbtk_info_server_start())
7334 {
7335 return -1;
7336 }
7337
7338 while(1)
7339 {
7340 sleep(24 * 60 * 60);
7341 }
7342
7343 return 0;
7344}
7345#endif
7346
7347