blob: 69c1b1dc43f56f34535d9166c0810aa1904cdcc8 [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 {
582 ret = MBTK_SIM_NOT_READY;
583 goto done;
584 }
585
586 switch (at_get_cme_error(p_response))
587 {
588 case CME_SUCCESS:
589 break;
590
591 case CME_SIM_NOT_INSERTED:
592 ret = MBTK_SIM_ABSENT;
593 goto done;
594
595 default:
596 ret = MBTK_SIM_NOT_READY;
597 goto done;
598 }
599
600 /* 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/*
1801AT+CPIN=1234
1802
1803OK
1804
1805*/
1806static int req_pin_verify(char *data, int *cme_err)
1807{
1808 ATResponse *response = NULL;
1809 char cmd[64]={0};
1810 sprintf(cmd, "AT+CPIN=%s", data);
1811 int err = at_send_command(cmd, &response);
1812 if (err < 0 || response->success == 0){
1813 if(cme_err) {
1814 *cme_err = at_get_cme_error(response);
1815 }
1816 goto exit;
1817 }
1818
1819exit:
1820 at_response_free(response);
1821 return err;
1822}
1823
1824/*
1825AT+CLCK=SC,2
1826+CLCK: 1
1827
1828OK
1829
1830AT+CLCK="SC",1,"1234"
1831+CLCK:1
1832
1833OK
1834
1835AT+CPWD="SC","1234","4321"
1836
1837OK
1838
1839*/
1840static int req_pin_change(mbtk_change_pin_info *data, int *cme_err)
1841{
1842 ATResponse *response = NULL;
1843 char cmd[64]={0};
1844
1845 int err = at_send_command_singleline("AT+CLCK=SC,2", "+CLCK:", &response);
1846 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1847 if(response) {
1848 *cme_err = at_get_cme_error(response);
1849 }
1850 LOGD("AT+CLCK fail.");
1851 goto exit;
1852 }
1853
1854 char *line = response->p_intermediates->line;
1855 if(line == NULL) {
1856 LOGD("line is NULL");
1857 goto exit;
1858 }
1859 err = at_tok_start(&line);
1860 if (err < 0)
1861 {
1862 goto exit;
1863 }
1864 int clck;
1865 err = at_tok_nextint(&line, &clck);
1866 if (err < 0)
1867 {
1868 goto exit;
1869 }
1870 at_response_free(response);
1871
1872 if(clck==0)
1873 {
1874 sprintf(cmd, "AT+CLCK=SC,1,%s", data->old_pin_value);
1875 err = at_send_command_singleline(cmd, "+CLCK:", &response);
1876 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1877 if(response) {
1878 *cme_err = at_get_cme_error(response);
1879 }
1880 LOGD("AT+CLCK fail.");
1881 goto exit;
1882 }
1883 line = response->p_intermediates->line;
1884 if(line == NULL) {
1885 LOGD("line is NULL");
1886 goto exit;
1887 }
1888 err = at_tok_start(&line);
1889 if (err < 0)
1890 {
1891 goto exit;
1892 }
1893 clck = -1;
1894 err = at_tok_nextint(&line, &clck);
1895 if (err < 0)
1896 {
1897 goto exit;
1898 }
1899 at_response_free(response);
1900 if(clck != 1)
1901 return err;
1902 }
1903 memset(cmd, 0, 64);
1904 sprintf(cmd, "AT+CPWD=SC,%s,%s", data->old_pin_value,data->new_pin_value);
1905 err = at_send_command(cmd, &response);
1906 if (err < 0 || response->success == 0){
1907 if(cme_err) {
1908 *cme_err = at_get_cme_error(response);
1909 }
1910 goto exit;
1911 }
1912
1913exit:
1914 at_response_free(response);
1915 return err;
1916}
1917
1918/*
1919AT+CPIN?
1920+CPIN:SIM PUK
1921
1922OK
1923
1924AT+CPIN="PUK","PIN"
1925+CPIN: READY
1926
1927OK
1928*/
1929static int req_puk_unlock_pin(mbtk_unlock_pin_info *data, int *cme_err)
1930{
1931 ATResponse *response = NULL;
1932 char cmd[64]={0};
1933#if 0
1934 int err = at_send_command_singleline("AT+CPIN?", "+CPIN:", &response);
1935 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1936 if(response) {
1937 *cme_err = at_get_cme_error(response);
1938 }
1939 LOGD("AT+CNUM? fail.");
1940 goto exit;
1941 }
1942
1943 char *line = response->p_intermediates->line;
1944 if(line == NULL) {
1945 LOGD("line is NULL");
1946 goto exit;
1947 }
1948 err = at_tok_start(&line);
1949 if (err < 0)
1950 {
1951 goto exit;
1952 }
1953 char *tmp_ptr = NULL;
1954 err = at_tok_nextstr(&line, &tmp_ptr);
1955 if (err < 0)
1956 {
1957 goto exit;
1958 }
1959 at_response_free(response);
1960
1961 if(!strstr(tmp_ptr,"SIM PUK"))
1962 {
1963 sprintf(cmd, "AT+CPIN=%s,%s", data->puk_value, data->pin_value);
1964 err = at_send_command_singleline(cmd, "+CPIN:", &response);
1965 if (err < 0 || response == NULL || response->success == 0 || !response->p_intermediates){
1966 if(response) {
1967 *cme_err = at_get_cme_error(response);
1968 }
1969 LOGD("AT+CNUM? fail.");
1970 goto exit;
1971 }
1972 line = response->p_intermediates->line;
1973 if(line == NULL) {
1974 LOGD("line is NULL");
1975 goto exit;
1976 }
1977 err = at_tok_start(&line);
1978 if (err < 0)
1979 {
1980 goto exit;
1981 }
1982 memset(tmp_ptr, 0, strlen(tmp_ptr));
1983 err = at_tok_nextstr(&line, &tmp_ptr);
1984 if (err < 0)
1985 {
1986 goto exit;
1987 }
1988 at_response_free(response);
1989 if(strstr(tmp_ptr, "READY"))
1990 return err;
1991 }
1992 else
1993 return err;
1994#else
1995 sprintf(cmd, "AT+CPIN=%s,%s", data->puk_value, data->pin_value);
r.xiao2ad43d12024-03-23 00:03:29 -07001996 int err = at_send_command(cmd, &response);
1997 if (err < 0 || response->success == 0){
1998 if(cme_err) {
liubin281ac462023-07-19 14:22:54 +08001999 *cme_err = at_get_cme_error(response);
2000 }
liubin281ac462023-07-19 14:22:54 +08002001 goto exit;
2002 }
r.xiao2ad43d12024-03-23 00:03:29 -07002003
liubin281ac462023-07-19 14:22:54 +08002004#endif
2005exit:
2006 at_response_free(response);
2007 return err;
2008}
2009
2010/*
2011AT+COPS=?
2012
2013+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)
2014
2015OK
2016
2017// Return [sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)]
2018*/
2019#if 0
2020static int req_available_net_get(mbtk_net_array_info_t *data_ptr)
2021{
2022 ATResponse *response = NULL;
2023 char *tmp_ptr = NULL;
2024 int tmp_int;
2025 int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response);
2026
2027 if (err < 0 || response->success == 0 || !response->p_intermediates)
2028 goto exit;
2029#if 1
2030 char *line_ptr = response->p_intermediates->line;
2031 if(line_ptr == NULL) {
2032 LOG("line is NULL");
2033 goto exit;
2034 }
2035 //LOG("Line:%s",line_ptr);
2036 line_ptr = strstr(line_ptr, "(");
2037 while(line_ptr) {
2038 line_ptr++;
2039 // Only for available/current net.
2040 if(*line_ptr == '1' || *line_ptr == '2') {
2041 //LOG("Temp:%s",line_ptr);
2042 //sleep(1);
2043 line_ptr = strstr(line_ptr, ",");
2044 if(line_ptr == NULL)
2045 goto exit;
2046 line_ptr++;
2047
2048 line_ptr = strstr(line_ptr, ",");
2049 if(line_ptr == NULL)
2050 goto exit;
2051 line_ptr++;
2052
2053 line_ptr = strstr(line_ptr, ",");
2054 if(line_ptr == NULL)
2055 goto exit;
2056
2057 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"'))
2058 line_ptr++;
2059
2060 mbtk_net_info_t *net = (mbtk_net_info_t*)malloc(sizeof(mbtk_net_info_t));
2061 if(net == NULL) {
2062 LOG("malloc() fail.");
2063 goto exit;
2064 }
2065 memset(net, 0, sizeof(mbtk_net_info_t));
2066
2067 // Point to "46000"
2068 //LOG("PLMN:%s",line_ptr);
2069 //sleep(1);
2070 net->plmn = (uint32)atoi(line_ptr);
2071
2072 line_ptr = strstr(line_ptr, ",");
2073 if(line_ptr == NULL)
2074 goto exit;
2075
2076 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' '))
2077 line_ptr++;
2078
2079 // Point to "7"
2080 if(*line_ptr == '\0') {
2081 free(net);
2082 goto exit;
2083 }
2084 //LOG("Type:%s",line_ptr);
2085 //sleep(1);
2086 net->net_type = (uint8)atoi(line_ptr);
2087 list_add(data_ptr->net_list, net);
2088 data_ptr->count++;
2089 }
2090
2091 line_ptr = strstr(line_ptr, "(");
2092 }
2093#endif
2094exit:
2095 at_response_free(response);
2096 return err;
2097}
2098#else
2099static int req_available_net_get(void* buff, int *cme_err)
2100{
2101 ATResponse *response = NULL;
2102 char *tmp_ptr = NULL;
2103 int tmp_int;
2104 int buff_size = 0;
2105 int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response);
2106
2107 if (err < 0 || response->success == 0 || !response->p_intermediates){
2108 *cme_err = at_get_cme_error(response);
2109 goto exit;
2110 }
2111 char *line_ptr = response->p_intermediates->line;
2112 if(line_ptr == NULL) {
2113 LOG("line is NULL");
2114 goto exit;
2115 }
2116 uint8* buff_ptr = (uint8*)buff;
2117 //LOG("Line:%s",line_ptr);
2118 line_ptr = strstr(line_ptr, "(");
2119 while(line_ptr) {
2120 line_ptr++;
2121 // Only for available/current net.
2122 if(*line_ptr == '1' || *line_ptr == '2' || *line_ptr == '3') {
2123 *(buff_ptr + 2) = (uint8)atoi(line_ptr); // net_state
2124
2125 line_ptr = strstr(line_ptr, ",");
2126 if(line_ptr == NULL)
2127 goto exit;
2128 line_ptr++;
2129
2130 line_ptr = strstr(line_ptr, ",");
2131 if(line_ptr == NULL)
2132 goto exit;
2133 line_ptr++;
2134
2135 line_ptr = strstr(line_ptr, ",");
2136 if(line_ptr == NULL)
2137 goto exit;
2138
2139 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"'))
2140 line_ptr++;
2141
2142 // set sel_mode to 0
2143 *buff_ptr = (uint8)0;
2144 // Point to "46000"
2145 //LOG("PLMN:%s",line_ptr);
2146 //sleep(1);
2147 uint32_2_byte((uint32)atoi(line_ptr), buff_ptr + 3, false); // plmn
2148
2149 line_ptr = strstr(line_ptr, ",");
2150 if(line_ptr == NULL)
2151 goto exit;
2152
2153 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' '))
2154 line_ptr++;
2155
2156 // Point to "7"
2157 if(*line_ptr == '\0') {
2158 goto exit;
2159 }
2160 //LOG("Type:%s",line_ptr);
2161 //sleep(1);
2162 *(buff_ptr + 1) = (uint8)atoi(line_ptr); // net_type
2163
2164 buff_size += sizeof(mbtk_net_info_t);
2165 buff_ptr += sizeof(mbtk_net_info_t);
2166 }
2167
2168 line_ptr = strstr(line_ptr, "(");
2169 }
2170exit:
2171 at_response_free(response);
2172 return buff_size;
2173}
2174#endif
2175
2176/*
2177AT+COPS?
2178+COPS: 1
2179
2180OK
2181
2182or
2183
2184AT+COPS?
2185+COPS: 0,2,"46001",7
2186
2187OK
2188
2189*/
2190static int req_net_sel_mode_get(mbtk_net_info_t *net, int *cme_err)
2191{
2192 //LOG("req_net_sel_mode_get() 0");
2193 //sleep(1);
2194 ATResponse *response = NULL;
2195 int tmp_int;
2196 char *tmp_ptr = NULL;
2197 int err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
2198 //LOG("req_net_sel_mode_get() 00");
2199 //sleep(1);
2200 if (err < 0 || response->success == 0 || !response->p_intermediates){
2201 if(cme_err != NULL)
2202 *cme_err = at_get_cme_error(response);
2203 err = -1;
2204 goto exit;
2205 }
2206 //LOG("req_net_sel_mode_get() 1");
2207 //sleep(1);
2208 char *line = response->p_intermediates->line;
2209 if(line == NULL) {
2210 LOG("line is NULL");
2211 goto exit;
2212 }
2213 //LOG("req_net_sel_mode_get() 2");
2214 //sleep(1);
2215 err = at_tok_start(&line);
2216 if (err < 0)
2217 {
2218 goto exit;
2219 }
2220 //LOG("req_net_sel_mode_get() 3");
2221 //sleep(1);
2222 err = at_tok_nextint(&line, &tmp_int);
2223 if (err < 0)
2224 {
2225 goto exit;
2226 }
2227 net->net_sel_mode = (uint8)tmp_int;
2228 //LOG("req_net_sel_mode_get() 4");
2229 //sleep(1);
2230 // +COPS: 1
2231 if(!at_tok_hasmore(&line)) {
2232 goto exit;
2233 }
2234 //LOG("req_net_sel_mode_get() 5");
2235 //sleep(1);
2236 err = at_tok_nextint(&line, &tmp_int);
2237 if (err < 0)
2238 {
2239 goto exit;
2240 }
2241 //LOG("req_net_sel_mode_get() 6");
2242 //sleep(1);
2243 err = at_tok_nextstr(&line, &tmp_ptr);
2244 if (err < 0)
2245 {
2246 goto exit;
2247 }
2248 // memcpy(net->plmn, tmp_ptr, strlen(tmp_ptr));
2249 net->plmn = (uint32)atoi(tmp_ptr);
2250 //LOG("req_net_sel_mode_get() 7");
2251 //sleep(1);
2252 err = at_tok_nextint(&line, &tmp_int);
2253 if (err < 0)
2254 {
2255 goto exit;
2256 }
2257 net->net_type = (uint8)tmp_int;
2258
2259 net->net_state = (uint8)MBTK_NET_AVIL_STATE_CURRENT;
2260
2261exit:
2262 //LOG("req_net_sel_mode_get() 8");
2263 //sleep(1);
2264 at_response_free(response);
2265 return err;
2266}
2267
2268/*
2269AT+COPS=0
2270or
2271AT+COPS=1,2,"46000",7
2272
2273OK
2274
2275*/
2276static int req_net_sel_mode_set(mbtk_net_info_t* net, int *cme_err)
2277{
2278 ATResponse *response = NULL;
2279 char cmd[50] = {0};
2280 char* cmp_ptr = cmd;
2281 if(net == NULL) {
2282 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
2283 } else {
2284 if(net->net_sel_mode == 0) {
2285 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
2286 } else if(net->net_type == 0xFF) {
2287 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\"",net->plmn);
2288 } else {
2289 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\",%d",net->plmn, net->net_type);
2290 }
2291 }
2292
2293 int err = at_send_command(cmd, &response);
2294
2295 if (err < 0 || response->success == 0) {
2296 *cme_err = at_get_cme_error(response);
2297 goto exit;
2298 }
2299
2300exit:
2301 at_response_free(response);
2302 return err;
2303}
2304
2305/*
2306AT+EEMOPT=1
2307OK
2308
2309// LTE
2310AT+EEMGINFO?
2311// <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
2312// <rsrp>,<rsrq>, <sinr>,
2313// errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
2314// cellId,subFrameAssignType,specialSubframePatterns,transMode
2315// mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
2316// tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
2317// dlBer, ulBer,
2318// diversitySinr, diversityRssi
2319+EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
23200, 0, 0,
23211, 10, 0, 1, 0, 1059, 78, 3959566565,
2322105149248, 2, 7, 7,
23230, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
23240, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
23250, 0,
23267, 44
2327
2328// index,phyCellId,euArfcn,rsrp,rsrq
2329+EEMLTEINTER: 0, 65535, 38950, 0, 0
2330
2331+EEMLTEINTER: 1, 0, 0, 0, 0
2332
2333+EEMLTEINTER: 2, 0, 4294967295, 255, 255
2334
2335+EEMLTEINTER: 3, 65535, 1300, 0, 0
2336
2337+EEMLTEINTER: 4, 0, 0, 0, 0
2338
2339+EEMLTEINTER: 5, 0, 4294967295, 247, 0
2340
2341+EEMLTEINTER: 6, 197, 41332, 24, 9
2342
2343+EEMLTEINTER: 7, 0, 0, 0, 0
2344
2345+EEMLTEINTER: 8, 0, 0, 0, 0
2346
2347+EEMLTEINTRA: 0, 429, 40936, 56, 12
2348
2349+EEMLTEINTERRAT: 0,0
2350
2351+EEMLTEINTERRAT: 1,0
2352
2353+EEMGINFO: 3, 2 // <state>:
2354 // 0: ME in Idle mode
2355 // 1: ME in Dedicated mode
2356 // 2: ME in PS PTM mode
2357 // 3: invalid state
2358 // <nw_type>:
2359 // 0: GSM 1: UMTS 2: LTE
2360
2361OK
2362
2363// WCDMA
2364AT+EEMGINFO?
2365// Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
2366
2367// if sCMeasPresent == 1
2368// cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
2369// endif
2370
2371// if sCParamPresent == 1
2372// rac, nom, mcc, mnc_len, mnc, lac, ci,
2373// uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
2374// csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
2375// endif
2376
2377// if ueOpStatusPresent == 1
2378// rrcState, numLinks, srncId, sRnti,
2379// algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
2380// HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
2381// MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
2382// serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
2383// endif
2384//
2385+EEMUMTSSVC: 3, 1, 1, 1,
2386-80, 27, -6, -18, -115, -32768,
23871, 1, 1120, 2, 1, 61697, 168432821,
238815, 24, 10763, 0, 0, 0, 0,
2389128, 128, 65535, 0, 0,
23902, 255, 65535, 4294967295,
23910, 0, 0, 0, 0, 0,
23920, 0, 0, 0, 0, 0, 1, 1,
239328672, 28672, 0, 0, 0, 0, 0, 0, 0,
23940, 0, 0, 0, 0, 0
2395
2396// index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
2397+EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
2398
2399+EEMUMTSINTRA: 1, -1, -32768, -18, -115, 0, 0, 65534, 2, 10763, 40, 32768
2400
2401+EEMUMTSINTRA: 2, -32768, -18, -115, 0, 0, 65534, 3, 10763, 278, 32768, 65535
2402
2403+EEMUMTSINTRA: 3, -18, -115, 0, 0, -2, 4, 10763, 28, 32768, 65535, 32768
2404
2405+EEMUMTSINTRA: 4, -115, 0, 0, -2, 5, 10763, 270, 32768, 65535, 32768, 65518
2406
2407+EEMUMTSINTRA: 5, 0, 0, -2, 6, 10763, 286, 32768, 65535, 32768, 65518, 65421
2408
2409+EEMUMTSINTRA: 6, 0, -2, 7, 10763, 80, 32768, 65535, 32768, 65518, 65421, 0
2410
2411+EEMUMTSINTRA: 7, -2, 8, 10763, 206, -32768, 65535, 32768, 65518, 65421, 0, 0
2412
2413+EEMUMTSINTRA: 8, 9, 10763, 11, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
2414
2415+EEMUMTSINTRA: 9, 10763, 19, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 11
2416
2417+EEMUMTSINTRA: 10, 232, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 12, 10763
2418
2419+EEMUMTSINTRA: 11, -32768, -1, -32768, -18, -115, 0, 0, 65534, 13, 10763, 66
2420
2421+EEMUMTSINTRA: 12, -1, -32768, -18, -115, 0, 0, 65534, 14, 10763, 216, 32768
2422
2423+EEMUMTSINTRA: 13, -32768, -18, -115, 0, 0, 65534, 15, 10763, 183, 32768, 65535
2424
2425+EEMUMTSINTRA: 14, -18, -115, 0, 0, -2, 16, 10763, 165, 32768, 65535, 32768
2426
2427+EEMUMTSINTRA: 15, -115, 0, 0, -2, 17, 10763, 151, 32768, 65535, 32768, 65518
2428
2429+EEMUMTSINTRA: 16, 0, 0, -2, 18, 10763, 43, 32768, 65535, 32768, 65518, 65421
2430
2431+EEMUMTSINTRA: 17, 0, -2, 19, 10763, 72, 32768, 65535, 32768, 65518, 65421, 0
2432
2433+EEMUMTSINTRA: 18, -2, 20, 10763, 157, -32768, 65535, 32768, 65518, 65421, 0, 0
2434
2435+EEMUMTSINTRA: 19, 21, 10763, 165, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
2436
2437+EEMUMTSINTRA: 20, 10763, 301, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 23
2438
2439+EEMUMTSINTRA: 21, 23, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 24, 10763
2440
2441+EEMUMTSINTRA: 22, -32768, -1, -32768, -18, -115, 0, 0, 65534, 25, 10763, 0
2442
2443+EEMUMTSINTRA: 23, -1, -32768, -18, -115, 0, 0, 65534, 26, 10763, 167, 32768
2444
2445+EEMUMTSINTRA: 24, -32768, -18, -115, 0, 0, 65534, 27, 10763, 34, 32768, 65535
2446
2447+EEMUMTSINTRA: 25, -18, -115, 0, 0, -2, 28, 10763, 313, 32768, 65535, 32768
2448
2449+EEMUMTSINTRA: 26, -115, 0, 0, -2, 29, 10763, 152, 32768, 65535, 32768, 65518
2450
2451+EEMUMTSINTRA: 27, 0, 0, -2, 30, 10763, 239, 0, 0, 0, 0, 0
2452
2453+EEMUMTSINTRA: 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
2454
2455+EEMUMTSINTRA: 29, 0, 0, 0, 0, -115, 0, 0, 65534, 30, 10763, 239
2456
2457// index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
2458+EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
2459
2460+EEMUMTSINTERRAT: 1, -107, -1, -1, 0, 0, 65534, 1, 72, 49, 0
2461
2462+EEMUMTSINTERRAT: 2, -1, -1, 0, 0, 65534, 2, 119, 15, 32768, 149
2463
2464+EEMUMTSINTERRAT: 3, -1, 0, 0, -2, 3, 121, 23, 0, 0, 0
2465
2466+EEMGINFO: 3, 1
2467
2468OK
2469
2470
2471// GSM
2472AT+EEMGINFO?
2473+EEMGINFOBASIC: 2
2474
2475// mcc, mnc_len, mnc, lac, ci, nom, nco,
2476// bsic, C1, C2, TA, TxPwr,
2477// RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
2478// ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
2479// bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
2480// ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
2481// gsmBand,channelMode
2482+EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
248363, 36, 146, 1, 7,
248446, 42, 42, 7, 0,
248553, 0, 8, 0, 1, 6, 53,
24862, 0, 146, 42, 54, 0, 1,
24871, 32, 0, 0, 0, 0,
24880, 0
2489
2490// PS_attached, attach_type, service_type, tx_power, c_value,
2491// ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
2492// gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
2493// pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
2494+EEMGINFOPS: 1, 255, 0, 0, 0,
24950, 0, 268435501, 1, 0, 0,
24964, 0, 96, 0, 0, 0,
24970, 0, 0, 65535, 0, 13350
2498
2499+EEMGINFO: 0, 0
2500
2501OK
2502
2503*/
2504static int req_cell_info_get(int *cme_err)
2505{
2506 ATResponse *response = NULL;
2507 int tmp_int;
2508 int buff_size = 0;
2509 // AT+EEMOPT=1 in the first.
2510 int err = at_send_command("AT+EEMOPT=1", &response);
2511 if (err < 0 || response->success == 0){
2512 *cme_err = at_get_cme_error(response);
2513 goto exit;
2514 }
2515
2516 // Reset buffer in the first.
2517 memset(&cell_info, 0xFF, sizeof(mbtK_cell_pack_info_t));
2518 cell_info.running = true;
2519 cell_info.cell_num = 0;
2520
2521 err = at_send_command_singleline("AT+EEMGINFO?", "+EEMGINFO:", &response);
2522 if (err < 0 || response->success == 0 || !response->p_intermediates){
2523 *cme_err = at_get_cme_error(response);
2524 goto exit;
2525 }
2526
2527 // Now, cell infomation has get from URC message.
2528
2529 char *line = response->p_intermediates->line;
2530 err = at_tok_start(&line);
2531 if (err < 0)
2532 {
2533 goto exit;
2534 }
2535 err = at_tok_nextint(&line, &tmp_int);
2536 if (err < 0)
2537 {
2538 goto exit;
2539 }
2540 err = at_tok_nextint(&line, &tmp_int);
2541 if (err < 0)
2542 {
2543 goto exit;
2544 }
2545
2546 cell_info.type = (uint8)tmp_int;
2547 cell_info.running = false;
2548
2549#if 0
2550 while(lines_ptr)
2551 {
2552 // LTE
2553 if(strStartsWith(line, "+EEMLTESVC:")) // LTE Server Cell
2554 {
2555
2556 }
b.liue0ab2442024-02-06 18:53:28 +08002557 else if(strStartsWith(line, "+EEMLTEINTER:")) // LTE
liubin281ac462023-07-19 14:22:54 +08002558 {
2559
2560 }
b.liue0ab2442024-02-06 18:53:28 +08002561 else if(strStartsWith(line, "+EEMLTEINTRA:")) // LTE
liubin281ac462023-07-19 14:22:54 +08002562 {
2563
2564 }
b.liue0ab2442024-02-06 18:53:28 +08002565 else if(strStartsWith(line, "+EEMLTEINTERRAT:")) // LTE
liubin281ac462023-07-19 14:22:54 +08002566 {
2567
2568 }
2569 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
2570 // <nw_type>: 0: GSM 1: UMTS 2: LTE
2571 {
2572
2573 }
2574 // WCDMA
2575 else if(strStartsWith(line, "+EEMUMTSSVC:")) // WCDMA Server Cell
2576 {
2577
2578 }
b.liue0ab2442024-02-06 18:53:28 +08002579 else if(strStartsWith(line, "+EEMUMTSINTRA:")) // WCDMA
liubin281ac462023-07-19 14:22:54 +08002580 {
2581
2582 }
b.liue0ab2442024-02-06 18:53:28 +08002583 else if(strStartsWith(line, "+EEMUMTSINTERRAT:")) // WCDMA
liubin281ac462023-07-19 14:22:54 +08002584 {
2585
2586 }
2587 // GSM
2588 else if(strStartsWith(line, "+EEMGINFOBASIC:")) // Basic information in GSM
2589 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
2590 {
2591
2592 }
2593 else if(strStartsWith(line, "+EEMGINFOSVC:")) // GSM Server Cell
2594 {
2595
2596 }
b.liue0ab2442024-02-06 18:53:28 +08002597 else if(strStartsWith(line, "+EEMGINFOPS:")) // PS
liubin281ac462023-07-19 14:22:54 +08002598 {
2599
2600 }
2601
2602
2603 lines_ptr = lines_ptr->p_next;
2604 }
2605#endif
2606
2607exit:
2608 at_response_free(response);
2609 return buff_size;
2610}
2611
2612static int req_cell_info_set(const char *cmgl, char *reg, int len, int *cme_err)
2613{
2614 printf("req_cmgl_set(2)-----------------start\n");
2615 printf("cmgl:%s\n", cmgl);
2616 ATResponse *response = NULL;
2617 char cmd[30] = {0};
2618 char data[218] = {0};
2619 int err = 0;
2620
2621 memcpy(data, cmgl, len);
2622
2623 sprintf(cmd, "at*cell=%s", data);
2624 printf("cmd:%s\n", cmd);
2625
2626 if(strlen(cmd) > 0)
2627 {
2628 err = at_send_command_multiline(cmd, "", &response);
2629 if (err < 0 || response->success == 0 || !response->p_intermediates){
2630 *cme_err = at_get_cme_error(response);
2631 // printf("at_send_command_multiline() is err-----------------\n");
2632 goto exit;
2633 }
2634
2635 ATLine* lines_ptr = response->p_intermediates;
2636 char *line = NULL;
2637 int reg_len = 0;
2638 bool flag = false;
2639 while(lines_ptr)
2640 {
2641 line = lines_ptr->line;
2642 if(line ==NULL)
2643 {
2644 printf("line is null----------------------\n");
2645 }
2646 printf("-----line:%s\n", line);
2647
2648 lines_ptr = lines_ptr->p_next;
2649 }
2650 }
2651 err = 0;
2652 memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss"));
2653exit:
2654 at_response_free(response);
2655 printf("req_cell_info_set()-----------------end\n");
2656 return err;
2657}
2658
2659
2660
2661/*
2662AT+CSQ
2663+CSQ: 31,99
2664
2665OK
2666
2667AT+CESQ
2668+CESQ: 60,99,255,255,20,61
2669
2670OK
2671
2672AT+COPS?
2673+COPS: 0,2,"46001",7
2674
2675OK
2676
2677*/
2678static int req_net_signal_get(mbtk_signal_info_t *signal, int *cme_err)
2679{
2680 ATResponse *response = NULL;
2681 int tmp_int;
2682 char *tmp_ptr = NULL;
2683 // AT+EEMOPT=1 in the first.
2684 int err = at_send_command_singleline("AT+CSQ", "+CSQ:", &response);
2685 if (err < 0 || response->success == 0 || !response->p_intermediates){
2686 if(cme_err != NULL)
2687 *cme_err = at_get_cme_error(response);
2688 err = -1;
2689 goto exit;
2690 }
2691
2692 char *line = response->p_intermediates->line;
2693 err = at_tok_start(&line);
2694 if (err < 0)
2695 {
2696 goto exit;
2697 }
2698 err = at_tok_nextint(&line, &tmp_int);
2699 if (err < 0)
2700 {
2701 goto exit;
2702 }
2703 signal->rssi = (uint8)tmp_int;
2704 at_response_free(response);
2705
2706 err = at_send_command_singleline("AT+CESQ", "+CESQ:", &response);
2707 if (err < 0 || response->success == 0 || !response->p_intermediates){
2708 if(cme_err != NULL)
2709 *cme_err = at_get_cme_error(response);
2710 err = -1;
2711 goto exit;
2712 }
2713
2714 line = response->p_intermediates->line;
2715 err = at_tok_start(&line);
2716 if (err < 0)
2717 {
2718 goto exit;
2719 }
2720 err = at_tok_nextint(&line, &tmp_int);
2721 if (err < 0)
2722 {
2723 goto exit;
2724 }
2725 signal->rxlev = (uint8)tmp_int;
2726
2727 err = at_tok_nextint(&line, &tmp_int);
2728 if (err < 0)
2729 {
2730 goto exit;
2731 }
2732 signal->ber = (uint8)tmp_int;
2733
2734 err = at_tok_nextint(&line, &tmp_int);
2735 if (err < 0)
2736 {
2737 goto exit;
2738 }
2739 signal->rscp = (uint8)tmp_int;
2740
2741 err = at_tok_nextint(&line, &tmp_int);
2742 if (err < 0)
2743 {
2744 goto exit;
2745 }
2746 signal->ecno = (uint8)tmp_int;
2747
2748 err = at_tok_nextint(&line, &tmp_int);
2749 if (err < 0)
2750 {
2751 goto exit;
2752 }
2753 signal->rsrq = (uint8)tmp_int;
2754
2755 err = at_tok_nextint(&line, &tmp_int);
2756 if (err < 0)
2757 {
2758 goto exit;
2759 }
2760 signal->rsrp = (uint8)tmp_int;
2761
2762 at_response_free(response);
2763 err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
2764 if (err < 0 || response->success == 0 || !response->p_intermediates){
2765 if(cme_err != NULL)
2766 *cme_err = at_get_cme_error(response);
2767 err = -1;
2768 goto exit;
2769 }
2770 line = response->p_intermediates->line;
2771 err = at_tok_start(&line);
2772 if (err < 0)
2773 {
2774 goto exit;
2775 }
2776 err = at_tok_nextint(&line, &tmp_int);
2777 if (err < 0)
2778 {
2779 goto exit;
2780 }
2781 if(!at_tok_hasmore(&line)) {
2782 goto exit;
2783 }
2784 err = at_tok_nextint(&line, &tmp_int);
2785 if (err < 0)
2786 {
2787 goto exit;
2788 }
2789 err = at_tok_nextstr(&line, &tmp_ptr);
2790 if (err < 0)
2791 {
2792 goto exit;
2793 }
2794 err = at_tok_nextint(&line, &tmp_int);
2795 if (err < 0)
2796 {
2797 goto exit;
2798 }
2799 signal->type = (uint8)tmp_int;
2800 net_info.net_type = signal->type;
2801
2802exit:
2803 at_response_free(response);
2804 return err;
2805}
2806
2807/*
2808AT+CREG=3
2809OK
2810
2811AT+CREG?
2812+CREG: 3,1,"8330","06447340",7
2813
2814OK
2815
2816AT+CREG?
2817+CREG: 3,0
2818
2819OK
2820
2821AT+CEREG?
2822+CEREG: 3,1,"8330","06447340",7
2823
2824OK
2825
2826
2827AT+CIREG?
2828+CIREG: 2,1,15
2829
2830OK
2831
2832AT+CIREG?
2833+CIREG: 0
2834
2835OK
2836
2837
2838*/
2839static int req_net_reg_get(mbtk_net_reg_info_t *reg, int *cme_err)
2840{
2841 ATResponse *response = NULL;
2842 int tmp_int;
2843 char *tmp_str = NULL;
2844 int err = at_send_command("AT+CREG=3", &response);
2845 if (err < 0 || response->success == 0){
2846 *cme_err = at_get_cme_error(response);
2847 goto exit;
2848 }
2849 at_response_free(response);
2850
2851 err = at_send_command_multiline("AT+CREG?", "+CREG:", &response);
2852 if (err < 0 || response->success == 0 || !response->p_intermediates){
2853 *cme_err = at_get_cme_error(response);
2854 goto exit;
2855 }
2856
2857 char *line = response->p_intermediates->line;
2858 err = at_tok_start(&line);
2859 if (err < 0)
2860 {
2861 goto exit;
2862 }
2863 err = at_tok_nextint(&line, &tmp_int); // n
2864 if (err < 0)
2865 {
2866 goto exit;
2867 }
2868 err = at_tok_nextint(&line, &tmp_int);// stat
2869 if (err < 0)
2870 {
2871 goto exit;
2872 }
2873 reg->call_state = (uint8)tmp_int;
2874
2875 if(at_tok_hasmore(&line)) {
2876 err = at_tok_nextstr(&line, &tmp_str); // lac
2877 if (err < 0)
2878 {
2879 goto exit;
2880 }
2881 reg->lac = strtol(tmp_str, NULL, 16);
2882
2883 err = at_tok_nextstr(&line, &tmp_str); // ci
2884 if (err < 0)
2885 {
2886 goto exit;
2887 }
2888 reg->ci = strtol(tmp_str, NULL, 16);
2889
2890 err = at_tok_nextint(&line, &tmp_int);// AcT
2891 if (err < 0)
2892 {
2893 goto exit;
2894 }
2895 reg->type = (uint8)tmp_int;
2896 }
2897 at_response_free(response);
2898
2899 err = at_send_command_multiline("AT+CEREG?", "+CEREG:", &response);
2900 if (err < 0 || response->success == 0 || !response->p_intermediates){
2901 *cme_err = at_get_cme_error(response);
2902 goto exit;
2903 }
2904
2905 line = response->p_intermediates->line;
2906 err = at_tok_start(&line);
2907 if (err < 0)
2908 {
2909 goto exit;
2910 }
2911 err = at_tok_nextint(&line, &tmp_int); // n
2912 if (err < 0)
2913 {
2914 goto exit;
2915 }
2916 err = at_tok_nextint(&line, &tmp_int);// stat
2917 if (err < 0)
2918 {
2919 goto exit;
2920 }
2921 reg->data_state = (uint8)tmp_int;
2922
2923 if(reg->lac == 0 && at_tok_hasmore(&line)) {
2924 err = at_tok_nextstr(&line, &tmp_str); // lac
2925 if (err < 0)
2926 {
2927 goto exit;
2928 }
2929 reg->lac = strtol(tmp_str, NULL, 16);
2930
2931 err = at_tok_nextstr(&line, &tmp_str); // ci
2932 if (err < 0)
2933 {
2934 goto exit;
2935 }
2936 reg->ci = strtol(tmp_str, NULL, 16);
2937
2938 err = at_tok_nextint(&line, &tmp_int);// AcT
2939 if (err < 0)
2940 {
2941 goto exit;
2942 }
2943 reg->type = (uint8)tmp_int;
2944 }
2945 at_response_free(response);
2946
2947 err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response);
2948 if (err < 0 || response->success == 0 || !response->p_intermediates){
2949 reg->ims_state = (uint8)0;
2950 err = 0;
2951 goto exit;
2952 }
2953 line = response->p_intermediates->line;
2954 err = at_tok_start(&line);
2955 if (err < 0)
2956 {
2957 goto exit;
2958 }
2959 err = at_tok_nextint(&line, &tmp_int); // n/stat
2960 if (err < 0)
2961 {
2962 goto exit;
2963 }
2964 if(at_tok_hasmore(&line)) {
2965 err = at_tok_nextint(&line, &tmp_int);// stat
2966 if (err < 0)
2967 {
2968 goto exit;
2969 }
2970 reg->ims_state = (uint8)tmp_int;
2971 } else {
2972 reg->ims_state = (uint8)tmp_int;
2973 }
2974
2975exit:
2976 at_response_free(response);
2977 return err;
2978}
2979
r.xiao06db9a12024-04-14 18:51:15 -07002980
2981static int net_ims_set(uint8 reg, int *cme_err)
2982{
2983 ATResponse *response = NULL;
2984 char cmd[30] = {0};
2985 int err = -1;
2986
b.liufdf03172024-06-07 15:01:29 +08002987 sprintf(cmd, "AT+ACONFIG=\"IMSD=%d\"", reg);
r.xiao06db9a12024-04-14 18:51:15 -07002988 err = at_send_command(cmd, &response);
2989 LOG("cmd : %s", cmd);
2990
2991 if (err < 0 || response->success == 0){
2992 *cme_err = at_get_cme_error(response);
2993 goto exit;
2994 }
2995
2996exit:
2997 at_response_free(response);
2998 return err;
2999}
3000
3001
3002static int net_ims_get(int *reg, int *cme_err)
3003{
3004 ATResponse *response = NULL;
b.liufdf03172024-06-07 15:01:29 +08003005 int tmp_int, tmp_reg = 0;
3006 int err;
3007 char *tmp_str = NULL;
3008
3009 err = at_send_command_singleline("AT+ACONFIG?", "", &response);
3010 if (err < 0 || response->success == 0 || !response->p_intermediates){
3011 tmp_reg = 0;
3012 err = 0;
3013 goto exit;
3014 }
3015 if(response->p_intermediates->line) {
3016 char *ptr = strstr(response->p_intermediates->line, "IMSD=");
3017 if(ptr) {
3018 tmp_reg = atoi(ptr + strlen("IMSD="));
3019 }
3020 }
3021
3022 LOG("net_ims_get reg : %u", tmp_reg);
3023
3024exit:
3025 at_response_free(response);
3026 *reg = tmp_reg;
3027 return err;
3028}
3029
3030static int net_ims_reg_state_get(int *reg, int *cme_err)
3031{
3032 ATResponse *response = NULL;
3033 int tmp_int, tmp_reg = -1;
r.xiao06db9a12024-04-14 18:51:15 -07003034 int err;
3035 char *tmp_str = NULL;
3036
3037 err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response);
3038 if (err < 0 || response->success == 0 || !response->p_intermediates){
3039 tmp_reg = 0;
3040 err = 0;
3041 goto exit;
3042 }
3043 char *line = response->p_intermediates->line;
3044 err = at_tok_start(&line);
3045 if (err < 0)
3046 {
3047 goto exit;
3048 }
3049 err = at_tok_nextint(&line, &tmp_int); // n/stat
3050 if (err < 0)
3051 {
3052 goto exit;
3053 }
liuyangc4ca9592024-06-06 15:43:50 +08003054
b.liufdf03172024-06-07 15:01:29 +08003055 if(at_tok_hasmore(&line)) {
3056 err = at_tok_nextint(&line, &tmp_int);// stat
3057 if (err < 0)
3058 {
3059 goto exit;
3060 }
3061 tmp_reg = tmp_int;
3062 } else {
3063 tmp_reg = tmp_int;
3064 }
r.xiao06db9a12024-04-14 18:51:15 -07003065
3066 LOG("net_ims_get reg : %u", tmp_reg);
3067
3068exit:
3069 at_response_free(response);
3070 *reg = tmp_reg;
3071 return err;
3072}
3073
3074
b.liufdf03172024-06-07 15:01:29 +08003075
liubin281ac462023-07-19 14:22:54 +08003076/*
3077AT+CGDCONT?
3078+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,,,,
3079
3080+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
3081
3082OK
3083
3084
3085*/
wangyouqianged88c722023-11-22 16:33:43 +08003086#ifdef MBTK_AF_SUPPORT
3087mbtk_ip_type_enum default_iptype = MBTK_IP_TYPE_IPV4V6;
3088#endif
3089
liubin281ac462023-07-19 14:22:54 +08003090static int req_apn_get(void *data, int *data_len, int *cme_err)
3091{
3092 ATResponse *response = NULL;
3093 int err = at_send_command_multiline("AT+CGDCONT?", "+CGDCONT:", &response);
3094
3095 if (err < 0 || response->success == 0 || !response->p_intermediates){
3096 *cme_err = at_get_cme_error(response);
3097 goto exit;
3098 }
3099
3100 ATLine* lines_ptr = response->p_intermediates;
3101 char *line = NULL;
3102 int tmp_int;
3103 char *tmp_str = NULL;
3104 /*
3105 <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>...
3106 <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
3107 */
3108 uint8* apn_num = (uint8*)data;
3109 uint8* data_ptr = (uint8*)(data + sizeof(uint8)); // Jump apn_num[1]
3110 mbtk_apn_info_t apn;
3111 while(lines_ptr)
3112 {
3113 line = lines_ptr->line;
3114 err = at_tok_start(&line);
3115 if (err < 0)
3116 {
3117 goto exit;
3118 }
3119
3120 err = at_tok_nextint(&line, &tmp_int); // cid
3121 if (err < 0)
3122 {
3123 goto exit;
3124 }
3125 // Only get CID 1-7
3126 if(tmp_int >= MBTK_APN_CID_MIN && tmp_int <= MBTK_APN_CID_MAX) {
3127 memset(&apn, 0x0, sizeof(mbtk_apn_info_t));
3128 apn.cid = tmp_int;
3129 *data_ptr++ = (uint8)tmp_int; // cid
3130
3131 err = at_tok_nextstr(&line, &tmp_str);// ip type
3132 if (err < 0)
3133 {
3134 goto exit;
3135 }
3136 if(!strcasecmp(tmp_str, "IP")) {
3137 *data_ptr++ = (uint8)MBTK_IP_TYPE_IP;
3138 apn.ip_type = MBTK_IP_TYPE_IP;
3139 } else if(!strcasecmp(tmp_str, "IPV6")) {
3140 *data_ptr++ = (uint8)MBTK_IP_TYPE_IPV6;
3141 apn.ip_type = MBTK_IP_TYPE_IPV6;
3142 } else if(!strcasecmp(tmp_str, "IPV4V6")) {
3143 *data_ptr++ = (uint8)MBTK_IP_TYPE_IPV4V6;
3144 apn.ip_type = MBTK_IP_TYPE_IPV4V6;
3145 } else {
3146 *data_ptr++ = (uint8)MBTK_IP_TYPE_PPP;
3147 apn.ip_type = MBTK_IP_TYPE_PPP;
3148 }
3149
wangyouqianged88c722023-11-22 16:33:43 +08003150#ifdef MBTK_AF_SUPPORT
3151 if(apn.cid == 1)
3152 {
3153 default_iptype = apn.ip_type;
3154 }
3155#endif
liubin281ac462023-07-19 14:22:54 +08003156 err = at_tok_nextstr(&line, &tmp_str); // apn
3157 if (err < 0)
3158 {
3159 goto exit;
3160 }
3161 if(str_empty(tmp_str)) {
3162 uint16_2_byte((uint16)0, data_ptr, false);
3163 data_ptr += sizeof(uint16);
3164 } else {
3165 uint16_2_byte((uint16)strlen(tmp_str), data_ptr, false);
3166 data_ptr += sizeof(uint16);
3167 memcpy(data_ptr, tmp_str, strlen(tmp_str));
3168 data_ptr += strlen(tmp_str);
3169 memcpy(apn.apn, tmp_str, strlen(tmp_str));
3170 }
3171
3172 if(apn_user_pass_set_by_cid(apn.cid, &apn)) {
3173 // user
3174 uint16_2_byte((uint16)0, data_ptr, false);
3175 data_ptr += sizeof(uint16);
3176
3177 // pass
3178 uint16_2_byte((uint16)0, data_ptr, false);
3179 data_ptr += sizeof(uint16);
3180
3181 // auth
3182 uint16_2_byte((uint16)0, data_ptr, false);
3183 data_ptr += sizeof(uint16);
3184 } else {
3185 // user
3186 if(str_empty(apn.user)) {
3187 uint16_2_byte((uint16)0, data_ptr, false);
3188 data_ptr += sizeof(uint16);
3189 } else {
3190 uint16_2_byte((uint16)strlen(apn.user), data_ptr, false);
3191 data_ptr += sizeof(uint16);
3192 memcpy(data_ptr, apn.user, strlen(apn.user));
3193 data_ptr += strlen(apn.user);
3194 }
3195
3196 // pass
3197 if(str_empty(apn.pass)) {
3198 uint16_2_byte((uint16)0, data_ptr, false);
3199 data_ptr += sizeof(uint16);
3200 } else {
3201 uint16_2_byte((uint16)strlen(apn.pass), data_ptr, false);
3202 data_ptr += sizeof(uint16);
3203 memcpy(data_ptr, apn.pass, strlen(apn.pass));
3204 data_ptr += strlen(apn.pass);
3205 }
3206
3207 // auth
3208 if(str_empty(apn.auth)) {
3209 uint16_2_byte((uint16)0, data_ptr, false);
3210 data_ptr += sizeof(uint16);
3211 } else {
3212 uint16_2_byte((uint16)strlen(apn.auth), data_ptr, false);
3213 data_ptr += sizeof(uint16);
3214 memcpy(data_ptr, apn.auth, strlen(apn.auth));
3215 data_ptr += strlen(apn.auth);
3216 }
3217 }
3218
3219 (*apn_num)++;
3220 }
3221
3222 lines_ptr = lines_ptr->p_next;
3223 }
3224
3225 *data_len = data_ptr - (uint8*)data;
3226
3227 goto exit;
3228exit:
3229 at_response_free(response);
3230 return err;
3231}
3232
3233#if 0
3234/*
3235LTE APN
3236AT+CFUN=4
3237AT*CGDFLT=1,IP,"private.vpdn",1,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,1
3238AT*CGDFAUTH=1,2,"noc@njcc.vpdn.js","123456"
3239AT+CFUN=1
3240AT+CEREG?
3241AT+CGDCONT?
3242
32432/3G APN
3244AT+CGREG?
3245AT+CGDCONT=6,IP,"private.vpdn"
3246AT*AUTHREQ=6,2,"noc@njcc.vpdn.js","123456"
3247AT+CGDATA="",6
3248AT+CGDCONT?
3249*/
3250static int req_apn_set_username(mbtk_apn_info_t *apn, int *cme_err)
3251{
3252 ATResponse *response = NULL;
3253 char cmd[400] = {0};
3254 int index = 0;
3255 int err = 0;
3256
3257 err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
3258 if (err < 0 || response->success == 0 || !response->p_intermediates){
3259 if(cme_err != NULL)
3260 *cme_err = at_get_cme_error(response);
3261 err = -1;
3262 goto apn_set;
3263 }
3264
3265 int tmp_int = 0;
3266 int state=0;
3267 char cmd_buf[64];
3268 char *line = response->p_intermediates->line;
3269 err = at_tok_start(&line);
3270 if (err < 0)
3271 {
3272 goto apn_set;
3273 }
3274 err = at_tok_nextint(&line, &tmp_int);
3275 if (err < 0)
3276 {
3277 goto apn_set;
3278 }
3279 err = at_tok_nextint(&line, &tmp_int);
3280 if (err < 0)
3281 {
3282 goto apn_set;
3283 }
3284 err = at_tok_nextstr(&line, &cmd_buf);
3285 if (err < 0)
3286 {
3287 goto apn_set;
3288 }
3289 err = at_tok_nextint(&line, &tmp_int);
3290 if (err < 0)
3291 {
3292 goto apn_set;
3293 }
3294 else
3295 state = tmp_int;
3296
3297apn_set:
3298 at_response_free(response);
3299 *cme_err = MBTK_INFO_ERR_CME_NON;
3300 //if(state == 7 && apn->cid == 1) //LTE && cid = 1
3301 if(0) //LTE && cid = 1
3302 {
3303 err = at_send_command("AT+CFUN=4", &response);
3304 if (err < 0 || response->success == 0){
3305 *cme_err = at_get_cme_error(response);
3306 goto exit;
3307 }
3308 at_response_free(response);
3309
3310 memset(cmd, 0, 400);
3311 index = 0;
3312 index += sprintf(cmd, "AT*CGDFLT=%d,", 1);
3313 switch(apn->ip_type) {
3314 case MBTK_IP_TYPE_IP: {
3315 index += sprintf(cmd + index,"\"IP\",");
3316 break;
3317 }
3318 case MBTK_IP_TYPE_IPV6: {
3319 index += sprintf(cmd + index,"\"IPV6\",");
3320 break;
3321 }
3322 case MBTK_IP_TYPE_IPV4V6: {
3323 index += sprintf(cmd + index,"\"IPV4V6\",");
3324 break;
3325 }
3326 default: {
3327 index += sprintf(cmd + index,"\"PPP\",");
3328 break;
3329 }
3330 }
3331
3332 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);
3333 err = at_send_command(cmd, &response);
3334 if (err < 0 || response->success == 0){
3335 *cme_err = at_get_cme_error(response);
3336 goto exit;
3337 }
3338 at_response_free(response);
3339
3340 memset(cmd, 0, 400);
3341 int cmd_auth=0;
3342 if(strstr(apn->auth,"NONE"))
3343 cmd_auth = 0;
3344 else if(strstr(apn->auth,"PAP"))
3345 cmd_auth = 1;
3346 else if(strstr(apn->auth,"CHAP"))
3347 cmd_auth = 2;
3348 else if(strstr(apn->auth,"PAP AND CHAP"))
3349 cmd_auth = 3;
3350 else
3351 goto exit;
3352
3353 sprintf(cmd,"AT*CGDFAUTH=1,%d,%s,%s",cmd_auth,apn->user,apn->pass);
3354
3355 err = at_send_command(cmd, &response);
3356 if (err < 0 || response->success == 0){
3357 *cme_err = at_get_cme_error(response);
3358 goto exit;
3359 }
3360 }
3361 else //2/3G
3362 {
3363 memset(cmd,0,400);
3364 index = 0;
3365 index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid);
3366 switch(apn->ip_type) {
3367 case MBTK_IP_TYPE_IP: {
3368 index += sprintf(cmd + index,"\"IP\",");
3369 break;
3370 }
3371 case MBTK_IP_TYPE_IPV6: {
3372 index += sprintf(cmd + index,"\"IPV6\",");
3373 break;
3374 }
3375 case MBTK_IP_TYPE_IPV4V6: {
3376 index += sprintf(cmd + index,"\"IPV4V6\",");
3377 break;
3378 }
3379 default: {
3380 index += sprintf(cmd + index,"\"PPP\",");
3381 break;
3382 }
3383 }
3384 index += sprintf(cmd + index, "\"%s\"", apn->apn);
3385
3386 err = at_send_command(cmd, &response);
3387 if (err < 0 || response->success == 0){
3388 *cme_err = at_get_cme_error(response);
3389 goto exit;
3390 }
3391 at_response_free(response);
3392
3393 memset(cmd,0,400);
3394 int cmd_auth=0;
3395 if(strstr(apn->auth,"NONE"))
3396 cmd_auth = 0;
3397 else if(strstr(apn->auth,"PAP"))
3398 cmd_auth = 1;
3399 else if(strstr(apn->auth,"CHAP"))
3400 cmd_auth = 2;
3401 else if(strstr(apn->auth,"PAP AND CHAP"))
3402 cmd_auth = 3;
3403 else
3404 goto exit;
3405
3406 sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass);
3407 err = at_send_command(cmd, &response);
3408 if (err < 0 || response->success == 0){
3409 *cme_err = at_get_cme_error(response);
3410 goto exit;
3411 }
3412 }
3413
3414exit:
3415 at_response_free(response);
3416 return err;
3417}
3418#endif
3419
3420/*
3421AT+CGDCONT=1,"IPV4V6","cmnet"
3422OK
3423
3424AT*CGDFLT=1,"IPv4v6","reliance.grevpdn.zj",,,,,,,,,,,,,,,,,,1
3425OK
3426
3427*/
3428static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err)
3429{
3430 ATResponse *response = NULL;
3431 char cmd[400] = {0};
3432 int index = 0;
3433 int err = 0;
3434
3435 index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid);
3436 switch(apn->ip_type) {
3437 case MBTK_IP_TYPE_IP: {
3438 index += sprintf(cmd + index,"\"IP\",");
3439 break;
3440 }
3441 case MBTK_IP_TYPE_IPV6: {
3442 index += sprintf(cmd + index,"\"IPV6\",");
3443 break;
3444 }
3445 case MBTK_IP_TYPE_IPV4V6: {
3446 index += sprintf(cmd + index,"\"IPV4V6\",");
3447 break;
3448 }
3449 default: {
3450 index += sprintf(cmd + index,"\"PPP\",");
3451 break;
3452 }
3453 }
3454 if(strlen(apn->apn) > 0) {
3455 index += sprintf(cmd + index,"\"%s\"", apn->apn);
b.liudfec1e12024-06-06 16:38:59 +08003456 }
liubin281ac462023-07-19 14:22:54 +08003457
3458 err = at_send_command(cmd, &response);
3459 if (err < 0 || response->success == 0){
3460 if(cme_err) {
3461 *cme_err = at_get_cme_error(response);
3462 }
3463 goto exit;
3464 }
3465
3466 if(!str_empty(apn->user) || !str_empty(apn->pass)) {
3467 at_response_free(response);
3468
3469 memset(cmd,0,400);
3470 int cmd_auth=0;
3471 if(strstr(apn->auth,"NONE"))
3472 cmd_auth = 0;
3473 else if(strstr(apn->auth,"PAP"))
3474 cmd_auth = 1;
3475 else if(strstr(apn->auth,"CHAP"))
3476 cmd_auth = 2;
3477#if 0
3478 else if(strstr(apn->auth,"PAP AND CHAP"))
3479 cmd_auth = 3;
3480#endif
3481 else
3482 goto exit;
3483
3484 sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass);
3485 err = at_send_command(cmd, &response);
3486 if (err < 0 || response->success == 0){
3487 *cme_err = at_get_cme_error(response);
3488 goto exit;
3489 }
3490 }
3491
3492exit:
3493 at_response_free(response);
3494 return err;
3495}
3496
liuyang1cefd852024-04-24 18:30:53 +08003497static int req_apn_del(int data, int *cme_err)
liuyang0e49d9a2024-04-23 21:04:54 +08003498{
3499 ATResponse *response = NULL;
3500 char cmd[64]={0};
liuyang1cefd852024-04-24 18:30:53 +08003501 sprintf(cmd, "AT+CGDCONT=%d", data);
liuyang0e49d9a2024-04-23 21:04:54 +08003502 int err = at_send_command(cmd, &response);
3503 if (err < 0 || response->success == 0){
3504 if(cme_err) {
3505 *cme_err = at_get_cme_error(response);
3506 }
3507 goto exit;
3508 }
3509
3510exit:
3511 at_response_free(response);
3512 return err;
3513}
3514
3515
liubin281ac462023-07-19 14:22:54 +08003516int wait_cgact_complete(int timeout)
3517{
3518 int count = timeout * 10; // timeout * 1000 / 100
3519 int i = 0;
3520
3521 while(cgact_wait.waitting && i < count) {
3522 i++;
3523 usleep(100000); // 100ms
3524 }
3525
3526 if(i == count) { // Timeout
3527 return -1;
3528 } else {
3529 return 0;
3530 }
3531}
3532
3533/*
3534AT+CGDATA="",6
3535CONNECT
3536
3537OK
3538
3539AT+CFUN=1
3540
3541OK
3542
3543*/
3544static int req_data_call_user_start(int cid, int *cme_err)
3545{
3546 ATResponse *response = NULL;
3547 char cmd[400] = {0};
3548 int index = 0;
3549 int err = 0;
3550
3551 err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
3552 if (err < 0 || response->success == 0 || !response->p_intermediates){
3553 if(cme_err != NULL)
3554 *cme_err = at_get_cme_error(response);
3555 err = -1;
3556 goto exit;
3557 }
3558
3559 int tmp_int;
3560 char cmd_buf[64];
3561 char *line = response->p_intermediates->line;
3562 err = at_tok_start(&line);
3563 if (err < 0)
3564 {
3565 goto exit;
3566 }
3567 err = at_tok_nextint(&line, &tmp_int);
3568 if (err < 0)
3569 {
3570 goto exit;
3571 }
3572 err = at_tok_nextint(&line, &tmp_int);
3573 if (err < 0)
3574 {
3575 goto exit;
3576 }
3577 err = at_tok_nextstr(&line, &cmd_buf);
3578 if (err < 0)
3579 {
3580 goto exit;
3581 }
3582 err = at_tok_nextint(&line, &tmp_int);
3583 if (err < 0)
3584 {
3585 goto exit;
3586 }
3587 at_response_free(response);
3588
3589 if(tmp_int == 7 && cid == 1) //LTE && cid = 1
3590 {
3591 ATResponse *response = NULL;
3592 char cmd[400] = {0};
3593 int err = 0;
3594
3595 err = at_send_command("AT+CFUN=1", &response);
3596 if (err < 0 || response->success == 0){
3597 if(cme_err) {
3598 *cme_err = at_get_cme_error(response);
3599 }
3600 goto exit;
3601 }
3602 }
3603 else
3604 {
3605 ATResponse *response = NULL;
3606 char cmd[400] = {0};
3607 int err = 0;
3608 sprintf(cmd, "AT+CGDATA=\"\",%d", cid);
3609 err = at_send_command(cmd, &response);
3610 if (err < 0 || response->success == 0){
3611 if(cme_err) {
3612 *cme_err = at_get_cme_error(response);
3613 }
3614 goto exit;
3615 }
3616 }
3617
3618exit:
3619 at_response_free(response);
3620 return err;
3621}
3622
3623/*
3624AT+CGACT?
3625+CGACT: 1,1
3626+CGACT: 8,1
3627OK
3628
3629AT+CGACT=1,<cid>
3630OK
3631
3632*/
3633static int req_data_call_start(int cid, int *cme_err)
3634{
3635 ATResponse *response = NULL;
3636 char cmd[400] = {0};
3637 int err = 0;
3638#if 0
3639 err = at_send_command_multiline("AT+CGACT?", "+CGACT:", &response);
3640 if (err < 0 || response->success == 0 || !response->p_intermediates){
3641 *cme_err = at_get_cme_error(response);
3642 goto exit;
3643 }
3644 ATLine* lines_ptr = response->p_intermediates;
3645 char *line = NULL;
3646 int tmp_int;
3647 while(lines_ptr)
3648 {
3649 line = lines_ptr->line;
3650 err = at_tok_start(&line);
3651 if (err < 0)
3652 {
3653 goto exit;
3654 }
3655
3656 err = at_tok_nextint(&line, &tmp_int); // cid
3657 if (err < 0)
3658 {
3659 goto exit;
3660 }
3661 if(tmp_int == cid) { // Found cid
3662 err = at_tok_nextint(&line, &tmp_int); // cid
3663 if (err < 0)
3664 {
3665 goto exit;
3666 }
3667 if(tmp_int == 1) { // This cid has active.
3668 goto net_config;
3669 } else {
3670 goto cid_active;
3671 }
3672 break;
3673 }
3674
3675 lines_ptr = lines_ptr->p_next;
3676 }
3677
3678 if(lines_ptr == NULL) { // No found this cid.
3679 LOGE("No found cid : %d", cid);
3680 goto exit;
3681 }
3682 at_response_free(response);
3683
3684 // Start active cid.
3685cid_active:
3686#endif
3687
3688 sprintf(cmd, "AT+CGACT=1,%d", cid);
3689 err = at_send_command(cmd, &response);
3690 if (err < 0 || response->success == 0){
3691 if(cme_err) {
3692 *cme_err = at_get_cme_error(response);
3693 }
3694 goto exit;
3695 }
3696
3697exit:
3698 at_response_free(response);
3699 return err;
3700}
3701
3702/*
3703AT+CGACT=0,<cid>
3704OK
3705
3706*/
3707static int req_data_call_stop(int cid, int *cme_err)
3708{
3709 ATResponse *response = NULL;
3710 char cmd[400] = {0};
3711 int err = 0;
3712#if 0
3713 err = at_send_command_multiline("AT+CGACT?", "+CGACT:", &response);
3714 if (err < 0 || response->success == 0 || !response->p_intermediates){
3715 *cme_err = at_get_cme_error(response);
3716 goto exit;
3717 }
3718 ATLine* lines_ptr = response->p_intermediates;
3719 char *line = NULL;
3720 int tmp_int;
3721 while(lines_ptr)
3722 {
3723 line = lines_ptr->line;
3724 err = at_tok_start(&line);
3725 if (err < 0)
3726 {
3727 goto exit;
3728 }
3729
3730 err = at_tok_nextint(&line, &tmp_int); // cid
3731 if (err < 0)
3732 {
3733 goto exit;
3734 }
3735 if(tmp_int == cid) { // Found cid
3736 err = at_tok_nextint(&line, &tmp_int); // cid
3737 if (err < 0)
3738 {
3739 goto exit;
3740 }
3741 if(tmp_int == 1) { // This cid has active.
3742 goto net_config;
3743 } else {
3744 goto cid_active;
3745 }
3746 break;
3747 }
3748
3749 lines_ptr = lines_ptr->p_next;
3750 }
3751
3752 if(lines_ptr == NULL) { // No found this cid.
3753 LOGE("No found cid : %d", cid);
3754 goto exit;
3755 }
3756 at_response_free(response);
3757
3758 // Start active cid.
3759cid_active:
3760#endif
3761
3762 sprintf(cmd, "AT+CGACT=0,%d", cid);
3763 err = at_send_command(cmd, &response);
3764 if (err < 0 || response->success == 0){
3765 *cme_err = at_get_cme_error(response);
3766 goto exit;
3767 }
3768
3769exit:
3770 at_response_free(response);
3771 return err;
3772}
3773
3774/*
3775IPv4 : 10.255.74.26
3776IPv6 : 254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239
3777*/
3778static bool is_ipv4(const char *ip)
3779{
3780 const char *ptr = ip;
3781 int count = 0;
3782 while(*ptr) {
3783 if(*ptr == '.')
3784 count++;
3785 ptr++;
3786 }
3787
3788 if(count == 3) {
3789 return true;
3790 } else {
3791 return false;
3792 }
3793}
3794
3795/*
3796AT+CGCONTRDP=1
3797+CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","10.255.74.26","","223.87.253.100","223.87.253.253","","",0,0
3798+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
3799
3800OK
3801
3802*/
3803static int req_data_call_state_get(int cid, mbtk_ipv4_info_t *ipv4, mbtk_ipv6_info_t *ipv6, int *cme_err)
3804{
3805 ATResponse *response = NULL;
3806 char cmd[50] = {0};
3807 int err = 0;
3808
3809 sprintf(cmd, "AT+CGCONTRDP=%d", cid);
3810
3811 err = at_send_command_multiline(cmd, "+CGCONTRDP:", &response);
3812 if (err < 0 || response->success == 0 || !response->p_intermediates){
3813 *cme_err = at_get_cme_error(response);
3814 goto exit;
3815 }
3816 ATLine* lines_ptr = response->p_intermediates;
3817 char *line = NULL;
3818 int tmp_int;
3819 char *tmp_ptr = NULL;
3820 while(lines_ptr)
3821 {
3822 line = lines_ptr->line;
3823 err = at_tok_start(&line);
3824 if (err < 0)
3825 {
3826 goto exit;
3827 }
3828
3829 err = at_tok_nextint(&line, &tmp_int); // cid
3830 if (err < 0)
3831 {
3832 goto exit;
3833 }
3834 err = at_tok_nextint(&line, &tmp_int); // bearer_id
3835 if (err < 0)
3836 {
3837 goto exit;
3838 }
3839 err = at_tok_nextstr(&line, &tmp_ptr); // APN
3840 if (err < 0)
3841 {
3842 goto exit;
3843 }
3844
3845 err = at_tok_nextstr(&line, &tmp_ptr); // IP
3846 if (err < 0 || str_empty(tmp_ptr))
3847 {
3848 goto exit;
3849 }
3850 if(is_ipv4(tmp_ptr)) {
3851 if(inet_pton(AF_INET, tmp_ptr, &(ipv4->IPAddr)) < 0) {
3852 LOGE("inet_pton() fail.");
3853 err = -1;
3854 goto exit;
3855 }
3856
3857 ipv4->valid = true;
3858 //log_hex("IPv4", &(ipv4->IPAddr), sizeof(struct in_addr));
3859 } else {
3860 if(str_2_ipv6(tmp_ptr, &(ipv6->IPV6Addr))) {
3861 LOGE("str_2_ipv6() fail.");
3862 err = -1;
3863 goto exit;
3864 }
3865
3866 ipv6->valid = true;
3867 //log_hex("IPv6", &(ipv6->IPV6Addr), 16);
3868 }
3869
3870 err = at_tok_nextstr(&line, &tmp_ptr); // Gateway
3871 if (err < 0)
3872 {
3873 goto exit;
3874 }
3875 if(!str_empty(tmp_ptr)) { // No found gateway
3876 if(is_ipv4(tmp_ptr)) {
3877 if(inet_pton(AF_INET, tmp_ptr, &(ipv4->GateWay)) < 0) {
3878 LOGE("inet_pton() fail.");
3879 err = -1;
3880 goto exit;
3881 }
3882
3883 //log_hex("IPv4", &(ipv4->GateWay), sizeof(struct in_addr));
3884 } else {
3885 if(str_2_ipv6(tmp_ptr, &(ipv6->GateWay))) {
3886 LOGE("str_2_ipv6() fail.");
3887 err = -1;
3888 goto exit;
3889 }
3890
3891 //log_hex("IPv6", &(ipv6->GateWay), 16);
3892 }
3893 }
3894
3895 err = at_tok_nextstr(&line, &tmp_ptr); // prim_DNS
3896 if (err < 0)
3897 {
3898 goto exit;
3899 }
3900 if(!str_empty(tmp_ptr)) { // No found Primary DNS
3901 if(is_ipv4(tmp_ptr)) {
3902 if(inet_pton(AF_INET, tmp_ptr, &(ipv4->PrimaryDNS)) < 0) {
3903 LOGE("inet_pton() fail.");
3904 err = -1;
3905 goto exit;
3906 }
3907
3908 //log_hex("IPv4", &(ipv4->PrimaryDNS), sizeof(struct in_addr));
3909 } else {
3910 if(str_2_ipv6(tmp_ptr, &(ipv6->PrimaryDNS))) {
3911 LOGE("str_2_ipv6() fail.");
3912 err = -1;
3913 goto exit;
3914 }
3915
3916 //log_hex("IPv6", &(ipv6->PrimaryDNS), 16);
3917 }
3918 }
3919
3920 err = at_tok_nextstr(&line, &tmp_ptr); // sec_DNS
3921 if (err < 0)
3922 {
3923 goto exit;
3924 }
3925 if(!str_empty(tmp_ptr)) { // No found Secondary DNS
3926 if(is_ipv4(tmp_ptr)) {
3927 if(inet_pton(AF_INET, tmp_ptr, &(ipv4->SecondaryDNS)) < 0) {
3928 LOGE("inet_pton() fail.");
3929 err = -1;
3930 goto exit;
3931 }
3932
3933 //log_hex("IPv4", &(ipv4->SecondaryDNS), sizeof(struct in_addr));
3934 } else {
3935 if(str_2_ipv6(tmp_ptr, &(ipv6->SecondaryDNS))) {
3936 LOGE("str_2_ipv6() fail.");
3937 err = -1;
3938 goto exit;
3939 }
3940
3941 //log_hex("IPv6", &(ipv6->SecondaryDNS), 16);
3942 }
3943 }
3944
3945 lines_ptr = lines_ptr->p_next;
3946 }
3947
3948exit:
3949 at_response_free(response);
3950 return err;
3951}
3952
3953/*
3954AT+CGCONTRDP
3955+CGCONTRDP: 1,5,"cmnet.MNC000.MCC460.GPRS","10.156.238.86","","223.87.253.100","223.87.253.253","","",0,0
3956+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
3957+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
3958OK
3959
3960*/
3961static int apn_state_get(list_node_t **apn_list)
3962{
3963 ATResponse *response = NULL;
3964 int err = 0;
3965 *apn_list = list_create(NULL);
3966 if(*apn_list == NULL)
3967 {
3968 LOG("list_create() fail.");
3969 return -1;
3970 }
3971
3972 err = at_send_command_multiline("AT+CGCONTRDP", "+CGCONTRDP:", &response);
3973 if (err < 0 || response->success == 0 || !response->p_intermediates){
3974 goto exit;
3975 }
3976 ATLine* lines_ptr = response->p_intermediates;
3977 char *line = NULL;
3978 int tmp_int;
3979 char *tmp_ptr = NULL;
3980 int cid_current = 0;
3981 info_apn_ip_t *apn = NULL;
3982 while(lines_ptr)
3983 {
3984 line = lines_ptr->line;
3985 err = at_tok_start(&line);
3986 if (err < 0)
3987 {
3988 goto exit;
3989 }
3990
3991 err = at_tok_nextint(&line, &tmp_int); // cid
3992 if (err < 0)
3993 {
3994 goto exit;
3995 }
3996
3997 if(tmp_int != 1 && tmp_int != 8) { // Not process cid 1 and 8.
3998 if(cid_current != tmp_int) { // New cid.
3999 apn = (info_apn_ip_t*)malloc(sizeof(info_apn_ip_t));
4000 if(apn == NULL) {
4001 goto exit;
4002 }
4003 memset(apn, 0, sizeof(info_apn_ip_t));
4004 apn->cid = tmp_int;
4005 cid_current = tmp_int;
4006
4007 list_add(*apn_list, apn);
4008 }
4009 err = at_tok_nextint(&line, &tmp_int); // bearer_id
4010 if (err < 0)
4011 {
4012 goto exit;
4013 }
4014 err = at_tok_nextstr(&line, &tmp_ptr); // APN
4015 if (err < 0)
4016 {
4017 goto exit;
4018 }
4019
4020 err = at_tok_nextstr(&line, &tmp_ptr); // IP
4021 if (err < 0 || str_empty(tmp_ptr))
4022 {
4023 goto exit;
4024 }
4025 if(is_ipv4(tmp_ptr)) {
4026 apn->ipv4_valid = true;
4027 memcpy(apn->ipv4, tmp_ptr, strlen(tmp_ptr));
4028 } else {
4029 apn->ipv6_valid = true;
4030 uint8 tmp_ipv6[16];
4031 if(str_2_ipv6(tmp_ptr, tmp_ipv6)) {
4032 LOGE("str_2_ipv6() fail.");
4033 err = -1;
4034 goto exit;
4035 }
4036
4037 if(inet_ntop(AF_INET6, tmp_ipv6, apn->ipv6, 50) == NULL) {
4038 err = -1;
4039 LOGE("inet_ntop ipv6 ip fail.");
4040 goto exit;
4041 }
4042 }
4043 }
4044
4045 lines_ptr = lines_ptr->p_next;
4046 }
4047
4048exit:
4049 at_response_free(response);
4050 return err;
4051}
4052
4053mbtk_info_err_enum call_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack);
4054mbtk_info_err_enum sms_pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack);
4055mbtk_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 -08004056
liubin281ac462023-07-19 14:22:54 +08004057//mbtk wyq for data_call_ex add start
4058void data_call_bootconn_save(int cid, int bootconn);
4059//mbtk wyq for data_call_ex add end
4060
4061//void net_list_free(void *data);
4062// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
4063// Otherwise, do not call pack_error_send().
4064static mbtk_info_err_enum pack_req_process(sock_client_info_t* cli_info, mbtk_info_pack_t* pack)
4065{
4066 if(pack->info_id > MBTK_INFO_ID_CALL_BEGIN && pack->info_id < MBTK_INFO_ID_CALL_END) {
4067 return call_pack_req_process(cli_info, pack);
4068 } else if(pack->info_id > MBTK_INFO_ID_SMS_BEGIN && pack->info_id < MBTK_INFO_ID_SMS_END) {
4069 return sms_pack_req_process(cli_info, pack);
4070 } else if(pack->info_id > MBTK_INFO_ID_PB_BEGIN && pack->info_id < MBTK_INFO_ID_PB_END) {
4071 return pb_pack_req_process(cli_info, pack);
4072 } else {
4073 mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
4074 int cme_err = MBTK_INFO_ERR_CME_NON;
4075 switch(pack->info_id)
4076 {
4077 case MBTK_INFO_ID_DEV_IMEI_REQ: // <string> IMEI
4078 {
4079 if(pack->data_len == 0 || pack->data == NULL) // Get IMEI
4080 {
4081 char imei[20] = {0};
4082 if(req_imei_get(imei, &cme_err) || strlen(imei) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4083 {
4084 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4085 err = MBTK_INFO_ERR_CME + cme_err;
4086 } else {
4087 err = MBTK_INFO_ERR_UNKNOWN;
4088 }
4089 LOG("Get IMEI fail.");
4090 }
4091 else
4092 {
4093 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_IMEI_RSP, imei, strlen(imei));
4094 }
4095 }
4096 else // Set IMEI(Unsupport).
4097 {
4098 err = MBTK_INFO_ERR_UNSUPPORTED;
4099 LOG("Unsupport set IMEI.");
4100 }
4101 break;
4102 }
4103 case MBTK_INFO_ID_DEV_SN_REQ: // <string> SN
4104 {
4105 if(pack->data_len == 0 || pack->data == NULL) // Get SN
4106 {
4107 char sn[20] = {0};
4108 if(req_sn_get(sn, &cme_err) || strlen(sn) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4109 {
4110 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4111 err = MBTK_INFO_ERR_CME + cme_err;
4112 } else {
4113 err = MBTK_INFO_ERR_UNKNOWN;
4114 }
4115 LOG("Get SN fail.");
4116 }
4117 else
4118 {
4119 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_SN_RSP, sn, strlen(sn));
4120 }
4121 }
4122 else // Set SN(Unsupport).
4123 {
4124 err = MBTK_INFO_ERR_UNSUPPORTED;
4125 LOG("Unsupport set SN.");
4126 }
4127 break;
4128 }
4129 case MBTK_INFO_ID_DEV_MEID_REQ: // <string> MEID (Only for CDMA)
4130 {
4131 if(pack->data_len == 0 || pack->data == NULL) // Get MEID
4132 {
4133 err = MBTK_INFO_ERR_UNSUPPORTED;
4134 LOG("Support only for CDMA.");
4135 }
4136 else // Set MEID(Unsupport).
4137 {
4138 err = MBTK_INFO_ERR_UNSUPPORTED;
4139 LOG("Unsupport set MEID.");
4140 }
4141 break;
4142 }
4143 case MBTK_INFO_ID_DEV_VERSION_REQ: // <string> VERSION
4144 {
4145 if(pack->data_len == 0 || pack->data == NULL) // Get VERSION
4146 {
4147 char version[50] = {0};
4148 if(req_version_get(version, &cme_err) || strlen(version) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4149 {
4150 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4151 err = MBTK_INFO_ERR_CME + cme_err;
4152 } else {
4153 err = MBTK_INFO_ERR_UNKNOWN;
4154 }
4155 LOG("Get Version fail.");
4156 }
4157 else
4158 {
4159 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VERSION_RSP, version, strlen(version));
4160 }
4161 }
4162 else // Set VERSION(Unsupport).
4163 {
4164 err = MBTK_INFO_ERR_UNSUPPORTED;
4165 LOG("Unsupport set VERSION.");
4166 }
4167 break;
4168 }
4169 case MBTK_INFO_ID_DEV_MODEL_REQ: //MODEL
4170 {
4171 if(pack->data_len == 0 || pack->data == NULL) // Get MODEL
4172 {
4173 char model[50] = {0};
4174 if(req_model_get(model, &cme_err) || strlen(model) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4175 {
4176 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4177 err = MBTK_INFO_ERR_CME + cme_err;
4178 } else {
4179 err = MBTK_INFO_ERR_UNKNOWN;
4180 }
4181 LOG("Get model fail.");
4182 }
4183 else
4184 {
4185 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VERSION_RSP, model, strlen(model));
4186 }
4187 }
4188 else // Set model(Unsupport).
4189 {
4190 err = MBTK_INFO_ERR_UNSUPPORTED;
4191 LOG("Unsupport set model.");
4192 }
4193 break;
4194 }
4195 case MBTK_INFO_ID_DEV_MODEM_REQ: //MODEM
4196 {
4197 if(pack->data_len == 0 || pack->data == NULL) // Get MODEM
4198 {
4199 int modem = -1;
4200 if(req_modem_get(&modem, &cme_err) || modem < 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4201 {
4202 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4203 err = MBTK_INFO_ERR_CME + cme_err;
4204 } else {
4205 err = MBTK_INFO_ERR_UNKNOWN;
4206 }
4207 LOG("Get modem fail.");
4208 }
4209 else
4210 {
4211 uint8 modem_type = (uint8)modem;
4212 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_MODEM_RSP, &modem_type, sizeof(uint8));
4213 }
4214 }
4215 else // Set modem
4216 {
4217 mbtk_modem_info_t *modem = (mbtk_modem_info_t *)pack->data;
4218 if(pack->data_len != sizeof(mbtk_modem_info_t))
4219 {
4220 err = MBTK_INFO_ERR_REQ_PARAMETER;
4221 LOG("Set modem error.");
4222 break;
4223 }
4224 if(req_modem_set(modem, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4225 {
4226 LOG("Set modem fail.");
4227 err = MBTK_INFO_ERR_FORMAT;
4228 } else {
4229 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_MODEM_RSP, NULL, 0);
4230 }
4231 }
4232 break;
4233 }
4234 case MBTK_INFO_ID_DEV_TIME_REQ: // <uint8><string> YYYY-MM-DD-HH:MM:SS
4235 {
4236 if(pack->data_len == 0 || pack->data == NULL) // Get Time
4237 {
4238 int type = -1;
4239 if(req_time_get(&type, &cme_err) || type < 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4240 {
4241 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4242 err = MBTK_INFO_ERR_CME + cme_err;
4243 } else {
4244 err = MBTK_INFO_ERR_UNKNOWN;
4245 }
4246 LOG("Get Time fail.");
4247 }
4248 else
4249 {
4250 uint8 time_type = (uint8)type;
4251 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, &time_type, sizeof(uint8));
4252 }
4253 }
4254 else // Set Time
4255 {
4256 if(pack->data_len == sizeof(uint8)) {
4257 if(req_time_set(*(pack->data), NULL, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4258 {
4259 LOG("Set Time fail.");
4260 err = MBTK_INFO_ERR_FORMAT;
4261 } else {
4262 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, NULL, 0);
4263 }
4264 } else {
4265 char time_ptr[100] = {0};
4266 memcpy(time_ptr, pack->data + sizeof(uint8), pack->data_len - sizeof(uint8));
4267 if(req_time_set(*(pack->data), time_ptr, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4268 {
4269 LOG("Set Time fail.");
4270 err = MBTK_INFO_ERR_FORMAT;
4271 } else {
4272 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TIME_RSP, NULL, 0);
4273 }
4274 }
4275 }
4276 break;
4277 }
b.liubaa41e12024-07-19 15:07:24 +08004278 case MBTK_INFO_ID_DEV_CELL_TIME_REQ: // <string> YYYY-MM-DD-HH:MM:SS
liubin281ac462023-07-19 14:22:54 +08004279 {
4280 if(pack->data_len == 0 || pack->data == NULL) // Get Time
4281 {
4282 char time[100];
4283 if(req_net_time_get(time, &cme_err) || strlen(time) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4284 {
4285 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4286 err = MBTK_INFO_ERR_CME + cme_err;
4287 } else {
4288 err = MBTK_INFO_ERR_UNKNOWN;
4289 }
4290 LOG("Get Time fail.");
4291 }
4292 else
4293 {
4294 char time_ser[100]={0};
4295 memcpy(time_ser,time,strlen(time));
b.liubaa41e12024-07-19 15:07:24 +08004296 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_CELL_TIME_RSP, time_ser, strlen(time_ser));
liubin281ac462023-07-19 14:22:54 +08004297 }
4298 }
4299 else // Set Time
4300 {
4301 err = MBTK_INFO_ERR_UNSUPPORTED;
4302 LOG("Unsupport set TIME.");
4303 }
4304 break;
4305 }
4306 case MBTK_INFO_ID_DEV_VOLTE_REQ: // <uint8> 0:Close 1:Open
4307 {
4308 if(pack->data_len == 0 || pack->data == NULL) // Get VoLTE state.
4309 {
4310 int state;
4311 if(req_volte_get(&state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4312 {
4313 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4314 err = MBTK_INFO_ERR_CME + cme_err;
4315 } else {
4316 err = MBTK_INFO_ERR_UNKNOWN;
4317 }
4318 LOG("Get VoLTE state fail.");
4319 }
4320 else
4321 {
4322 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VOLTE_RSP, &state, sizeof(uint8));
4323 }
4324 }
4325 else // Set VoLTE state.
4326 {
4327 uint8 on = *(pack->data);
4328 if(pack->data_len != sizeof(uint8) || (on != 0 && on != 1))
4329 {
4330 err = MBTK_INFO_ERR_REQ_PARAMETER;
4331 LOG("Set VOLTE parameter error.");
4332 break;
4333 }
4334
4335 if(req_volte_set(on, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4336 {
4337 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4338 err = MBTK_INFO_ERR_CME + cme_err;
4339 } else {
4340 err = MBTK_INFO_ERR_UNKNOWN;
4341 }
4342 LOG("Set VoLTE state fail.");
4343 }
4344 else
4345 {
4346 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_VOLTE_RSP, NULL, 0);
4347
4348 // Restart is required to take effect.
4349 LOG("Will reboot system...");
4350 }
4351 }
4352 break;
4353 }
4354 case MBTK_INFO_ID_DEV_TEMP_REQ: // <string> Temperature
4355 {
4356 if(pack->data_len == sizeof(uint8) && pack->data) {
r.xiao2102d762024-06-07 03:10:38 -07004357 mbtk_thermal_info_t temp;
4358 memset(&temp, 0, sizeof(mbtk_thermal_info_t));
liubin281ac462023-07-19 14:22:54 +08004359 if(req_temp_get(*(pack->data), &temp, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4360 {
4361 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4362 err = MBTK_INFO_ERR_CME + cme_err;
4363 } else {
4364 err = MBTK_INFO_ERR_UNKNOWN;
4365 }
4366 LOG("Get temperature fail.");
4367 }
4368 else
4369 {
r.xiao2102d762024-06-07 03:10:38 -07004370 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_DEV_TEMP_RSP, &temp, sizeof(mbtk_thermal_info_t));
liubin281ac462023-07-19 14:22:54 +08004371 }
4372 } else {
4373 err = MBTK_INFO_ERR_FORMAT;
4374 LOG("Unsupport get Temperature.");
4375 }
4376 break;
4377 }
4378 case MBTK_INFO_ID_SIM_PLMN_REQ: // plmn
4379 {
4380 if(pack->data_len == 0 || pack->data == NULL) // plmn
4381 {
4382 mbtk_plmn_info plmn;
4383 if(req_plmn_get(&plmn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4384 {
4385 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4386 err = MBTK_INFO_ERR_CME + cme_err;
4387 } else {
4388 err = MBTK_INFO_ERR_UNKNOWN;
4389 }
4390 LOG("Get PLMN fail.");
4391 }
4392 else
4393 {
4394 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PLMN_RSP, &plmn, sizeof(mbtk_plmn_info));
4395 }
4396 }
4397 else // Set
4398 {
4399 err = MBTK_INFO_ERR_UNSUPPORTED;
4400 LOG("Set sim state fail.");
4401 }
4402 break;
4403 }
4404 case MBTK_INFO_ID_SIM_STATE_REQ: // mbtk_sim_state_enum
4405 {
4406 if(pack->data_len == 0 || pack->data == NULL) // Get sim state.
4407 {
4408 uint8 sim_state = (uint8)getSIMStatus();
4409 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_STATE_RSP, &sim_state, sizeof(uint8));
4410 }
4411 else // Set
4412 {
4413 err = MBTK_INFO_ERR_UNSUPPORTED;
4414 LOG("Set sim state fail.");
4415 }
4416 break;
4417 }
4418 case MBTK_INFO_ID_SIM_STYPE_REQ: // mbtk_sim_card_type_enum
4419 {
4420 if(pack->data_len == 0 || pack->data == NULL) // Get sim card type
4421 {
4422 uint8 sim_card_type;
4423 if(req_sim_card_type_get(&sim_card_type, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4424 {
4425 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4426 err = MBTK_INFO_ERR_CME + cme_err;
4427 } else {
4428 err = MBTK_INFO_ERR_UNKNOWN;
4429 }
4430 LOG("Get IMSI fail.");
4431 }
4432 else
4433 {
4434 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_STYPE_RSP, &sim_card_type, sizeof(uint8));
4435 }
4436 }
4437 else // Set
4438 {
4439 err = MBTK_INFO_ERR_UNSUPPORTED;
4440 LOG("Set sim state fail.");
4441 }
4442 break;
4443 }
4444 case MBTK_INFO_ID_SIM_PINPUK_TIMES_REQ: // mbtk_pin_puk_last_times
4445 {
4446 if(pack->data_len == 0 || pack->data == NULL) // Get sim card type
4447 {
4448 mbtk_pin_puk_last_times pin_puk_last_times;
4449 if(req_pin_puk_last_times_get(&pin_puk_last_times, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4450 {
4451 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4452 err = MBTK_INFO_ERR_CME + cme_err;
4453 } else {
4454 err = MBTK_INFO_ERR_UNKNOWN;
4455 }
4456 LOG("Get IMSI fail.");
4457 }
4458 else
4459 {
4460 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PINPUK_TIMES_RSP, &pin_puk_last_times, sizeof(mbtk_pin_puk_last_times));
4461 }
4462 }
4463 else // Set
4464 {
4465 err = MBTK_INFO_ERR_UNSUPPORTED;
4466 LOG("Set sim state fail.");
4467 }
4468 break;
4469 }
4470 case MBTK_INFO_ID_SIM_ENABLE_PIN_REQ: // <string> PIN
4471 {
4472 if(pack->data_len == 0 || pack->data == NULL) // Enable PIN
4473 {
4474 err = MBTK_INFO_ERR_UNSUPPORTED;
4475 LOG("Unsupport GET PIN.");
4476 }
4477 else // Enable PIN
4478 {
4479 mbtk_enable_pin_info *pin = NULL;
4480 pin = (mbtk_enable_pin_info *)pack->data;
4481 if(req_pin_enable(pin, &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_ENABLE_PIN_RSP, NULL, 0);
4493 }
4494 }
4495 break;
4496 }
4497 case MBTK_INFO_ID_SIM_PIN_REQ: // <string> PIN
4498 {
4499 if(pack->data_len == 0 || pack->data == NULL) // PIN
4500 {
4501 err = MBTK_INFO_ERR_UNSUPPORTED;
4502 LOG("Unsupport GET PIN.");
4503 }
4504 else // Set PIN
4505 {
4506 char pin[16] = {0};
4507 memcpy(pin, pack->data, pack->data_len);
4508 if(req_pin_verify(pin, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4509 {
4510 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4511 err = MBTK_INFO_ERR_CME + cme_err;
4512 } else {
4513 err = MBTK_INFO_ERR_UNKNOWN;
4514 }
4515 LOG("Set PIN fail.");
4516 }
4517 else
4518 {
4519 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PIN_RSP, NULL, 0);
4520 }
4521 }
4522 break;
4523 }
4524 case MBTK_INFO_ID_SIM_PUK_REQ: // <string> PUK
4525 {
4526 if(pack->data_len == 0 || pack->data == NULL)
4527 {
4528 err = MBTK_INFO_ERR_UNSUPPORTED;
4529 LOG("Unsupport.");
4530 }
4531 else // change PIN
4532 {
4533 mbtk_unlock_pin_info *pin_info = NULL;
4534 pin_info = (mbtk_unlock_pin_info *)pack->data;
4535 if(req_puk_unlock_pin(pin_info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4536 {
4537 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4538 err = MBTK_INFO_ERR_CME + cme_err;
4539 } else {
4540 err = MBTK_INFO_ERR_UNKNOWN;
4541 }
4542 LOG("Get IMSI fail.");
4543 }
4544 else
4545 {
4546 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_CHANGE_PIN_RSP, NULL, 0);
4547 }
4548 }
4549 break;
4550 }
4551 case MBTK_INFO_ID_SIM_CHANGE_PIN_REQ: // <string> <string> old_PIN new_PIN
4552 {
4553 if(pack->data_len == 0 || pack->data == NULL)
4554 {
4555 err = MBTK_INFO_ERR_UNSUPPORTED;
4556 LOG("Unsupport.");
4557 }
4558 else // change PIN
4559 {
4560 mbtk_change_pin_info *pin_info = NULL;
4561 pin_info = (mbtk_change_pin_info *)pack->data;
4562 if(req_pin_change(pin_info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4563 {
4564 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4565 err = MBTK_INFO_ERR_CME + cme_err;
4566 } else {
4567 err = MBTK_INFO_ERR_UNKNOWN;
4568 }
4569 LOG("Get IMSI fail.");
4570 }
4571 else
4572 {
4573 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_CHANGE_PIN_RSP, NULL, 0);
4574 }
4575 }
4576 break;
4577 }
4578 case MBTK_INFO_ID_SIM_IMSI_REQ: // <string> IMSI
4579 {
4580 if(pack->data_len == 0 || pack->data == NULL) // Get IMSI
4581 {
4582 char imsi[20] = {0};
4583 if(req_imsi_get(imsi, &cme_err) || strlen(imsi) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4584 {
4585 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4586 err = MBTK_INFO_ERR_CME + cme_err;
4587 } else {
4588 err = MBTK_INFO_ERR_UNKNOWN;
4589 }
4590 LOG("Get IMSI fail.");
4591 }
4592 else
4593 {
4594 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_IMSI_RSP, imsi, strlen(imsi));
4595 }
4596 }
4597 else // Set IMSI(Unsupport).
4598 {
4599 err = MBTK_INFO_ERR_UNSUPPORTED;
4600 LOG("Unsupport set IMSI.");
4601 }
4602 break;
4603 }
4604 case MBTK_INFO_ID_SIM_ICCID_REQ: // <string> ICCID
4605 {
4606 if(pack->data_len == 0 || pack->data == NULL) // Get ICCID
4607 {
4608 //log_hex("pack", pack, sizeof(mbtk_info_pack_t));
4609 //sleep(1);
4610 char iccid[50] = {0};
4611 if(req_iccid_get(iccid, &cme_err) || strlen(iccid) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4612 {
4613 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4614 err = MBTK_INFO_ERR_CME + cme_err;
4615 } else {
4616 err = MBTK_INFO_ERR_UNKNOWN;
4617 }
4618 LOG("Get ICCID fail.");
4619 }
4620 else
4621 {
4622 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_ICCID_RSP, iccid, strlen(iccid));
4623 }
4624 }
4625 else // Set ICCID(Unsupport).
4626 {
4627 err = MBTK_INFO_ERR_UNSUPPORTED;
4628 LOG("Unsupport set ICCID.");
4629 }
4630 break;
4631 }
4632 case MBTK_INFO_ID_SIM_PN_REQ: // <string> Phone Number
4633 {
4634 if(pack->data_len == 0 || pack->data == NULL) // Get Phone Number
4635 {
4636 //log_hex("pack", pack, sizeof(mbtk_info_pack_t));
4637 //sleep(1);
4638 char phone_number[50] = {0};
4639 if(req_phone_number_get(phone_number, &cme_err) || strlen(phone_number) == 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4640 {
4641 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4642 err = MBTK_INFO_ERR_CME + cme_err;
4643 } else {
4644 err = MBTK_INFO_ERR_UNKNOWN;
4645 }
4646 LOG("Get Phone Number fail.");
4647 }
4648 else
4649 {
4650 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_SIM_PN_RSP, phone_number, strlen(phone_number));
4651 }
4652 }
4653 else // Set Phone Number(Unsupport).
4654 {
4655 err = MBTK_INFO_ERR_UNSUPPORTED;
4656 LOG("Unsupport set Phone Number.");
4657 }
4658 break;
4659 }
4660 case MBTK_INFO_ID_NET_SEL_MODE_REQ: // <mbtk_net_info_t> Operator
4661 {
4662 if(pack->data_len == 0 || pack->data == NULL) // Get
4663 {
4664 mbtk_net_info_t info;
4665 memset(&info, 0, sizeof(mbtk_net_info_t));
4666 if(req_net_sel_mode_get(&info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4667 {
4668 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4669 err = MBTK_INFO_ERR_CME + cme_err;
4670 } else {
4671 err = MBTK_INFO_ERR_UNKNOWN;
4672 }
4673 LOG("Get Net select mode fail.");
4674 }
4675 else
4676 {
4677 LOG("NET : %d, %d, %d, %d", info.net_sel_mode, info.net_type, info.net_state, info.plmn);
4678 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SEL_MODE_RSP, &info, sizeof(mbtk_net_info_t));
4679 }
4680 }
4681 else // Set
4682 {
4683 //LOG("1 pack-%p,data-%p,data_len-%d", pack, pack->data, pack->data_len);
4684 //log_hex("pack", pack, sizeof(mbtk_info_pack_t));
4685 //log_hex("data", pack->data, pack->data_len);
4686
4687 mbtk_net_info_t* info = (mbtk_net_info_t*)pack->data;//(mbtk_net_info_t*)mbtk_info_pack_data_get(pack, NULL);
4688 if(info == NULL) {
4689 err = MBTK_INFO_ERR_FORMAT;
4690 LOG("Get Net select mode fail.");
4691 } else {
4692 LOG("NET : %d, %d, %d", info->net_sel_mode, info->net_type, info->plmn);
4693 if(req_net_sel_mode_set(info, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON) {
4694 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4695 err = MBTK_INFO_ERR_CME + cme_err;
4696 } else {
4697 err = MBTK_INFO_ERR_UNKNOWN;
4698 }
4699 LOG("Get Net select mode fail.");
4700 } else {
4701 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SEL_MODE_RSP, NULL, 0);
4702 }
4703 }
4704 }
4705 break;
4706 }
4707 case MBTK_INFO_ID_NET_AVAILABLE_REQ:// sel_mode(uint8)type(uint8)plmn(uint32)...sel_mode(uint8)type(uint8)plmn(uint32)
4708 {
4709 if(pack->data_len == 0 || pack->data == NULL) // Get Available Net.
4710 {
4711 int buffer_size;
4712 uint8 buffer[SOCK_MSG_LEN_MAX];
4713 memset(buffer, 0, SOCK_MSG_LEN_MAX);
4714 if((buffer_size = req_available_net_get(buffer, &cme_err)) <= 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4715 {
4716 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4717 err = MBTK_INFO_ERR_CME + cme_err;
4718 } else {
4719 err = MBTK_INFO_ERR_UNKNOWN;
4720 }
4721 LOG("Get Available Net fail.");
4722 }
4723 else
4724 {
4725 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_AVAILABLE_RSP, buffer, buffer_size);
4726 }
4727 }
4728 else // Set Available Net(Unsupport).
4729 {
4730 err = MBTK_INFO_ERR_UNSUPPORTED;
4731 LOG("Unsupport set available net.");
4732 }
4733 break;
4734 }
4735 case MBTK_INFO_ID_NET_BAND_REQ:
4736 {
4737 if(pack->data_len == 0 || pack->data == NULL)
4738 {
4739 err = MBTK_INFO_ERR_REQ_PARAMETER;
4740 LOG("No data found.");
4741 }
4742 else // Get support/current bands.
4743 {
4744 if(pack->data_len == sizeof(uint8)) {
4745 if(*(pack->data)) { // Get current bands.
4746 mbtk_band_info_t band;
b.liu288093c2024-05-09 17:02:57 +08004747 memset(&band, 0x0, sizeof(mbtk_band_info_t));
liubin281ac462023-07-19 14:22:54 +08004748 if(req_band_get(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4749 {
4750 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4751 err = MBTK_INFO_ERR_CME + cme_err;
4752 } else {
4753 err = MBTK_INFO_ERR_UNKNOWN;
4754 }
4755 LOG("Get net band fail.");
4756 }
4757 else
4758 {
4759 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, &band, sizeof(mbtk_band_info_t));
4760 }
4761 } else { // Get support bands.
4762 band_support_get();
4763 if(band_support.net_pref != 0)
4764 {
4765 err = MBTK_INFO_ERR_UNKNOWN;
4766 LOG("Get support bands fail.");
4767 }
4768 else
4769 {
4770 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, &band_support, sizeof(mbtk_band_info_t));
4771 }
4772 }
4773 } else { // Set current bands.
4774 mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data;
4775 if(pack->data_len != sizeof(mbtk_band_info_t))
4776 {
4777 err = MBTK_INFO_ERR_REQ_PARAMETER;
4778 LOG("Set net band error.");
4779 break;
4780 }
4781
4782 if(req_band_set(band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4783 {
4784 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4785 err = MBTK_INFO_ERR_CME + cme_err;
4786 } else {
4787 err = MBTK_INFO_ERR_UNKNOWN;
4788 }
4789 LOG("Set net band fail.");
4790 }
4791 else
4792 {
4793 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_BAND_RSP, NULL, 0);
4794 }
4795 }
4796 }
4797 break;
4798 }
4799 case MBTK_INFO_ID_NET_CELL_REQ: // mbtk_cell_info_t[]
4800 {
4801 if(pack->data_len == 0 || pack->data == NULL) // Get net cell.
4802 {
4803 if(req_cell_info_get(&cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4804 {
4805 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4806 err = MBTK_INFO_ERR_CME + cme_err;
4807 } else {
4808 err = MBTK_INFO_ERR_UNKNOWN;
4809 }
4810 LOG("Get net cell fail.");
4811 }
4812 else
4813 {
4814 LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_num);
4815 //sleep(1);
4816 // mbtK_cell_pack_info_t
4817 if(cell_info.cell_num > 0 && cell_info.cell_num <= CELL_NUM_MAX && cell_info.type >= 0 && cell_info.type <= 2) {
4818 uint8 *data = (uint8*)malloc(sizeof(uint8) + sizeof(mbtk_cell_info_t) * cell_info.cell_num);
4819 if(data == NULL){
4820 err = MBTK_INFO_ERR_MEMORY;
4821 LOG("Get net cell fail.");
4822 } else {
4823 *data = cell_info.type; // Set network type.
4824 // Copy cell info item.
4825 #if 0
4826 int i = 0;
4827 while(i < cell_info.cell_num) {
4828 memcpy(data + sizeof(uint8) + sizeof(mbtk_cell_info_t) * i,
4829 &(cell_info.cell[i]),
4830 sizeof(mbtk_cell_info_t));
4831 i++;
4832 }
4833 #else
4834 memcpy(data + sizeof(uint8),
4835 &(cell_info.cell),
4836 sizeof(mbtk_cell_info_t) * cell_info.cell_num);
4837 #endif
4838 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_CELL_RSP, data, sizeof(uint8) + sizeof(mbtk_cell_info_t) * cell_info.cell_num);
4839 free(data);
4840 }
4841 } else {
4842 err = MBTK_INFO_ERR_UNKNOWN;
4843 LOG("Get net cell fail.");
4844 }
4845 }
4846 }
4847 else // Lock cell
4848 {
4849 char *mem = (char*)(pack->data);
4850 int len = pack->data_len;
4851 char reg[100] = {0};
4852 printf("mem:%s, len:%d", pack->data, pack->data_len);
4853
4854 if(req_cell_info_set(mem, reg, len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4855 {
4856 // printf("cpms_set fail\n");
4857 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4858 err = MBTK_INFO_ERR_CME + cme_err;
4859 } else {
4860 err = MBTK_INFO_ERR_UNKNOWN;
4861 }
4862 // LOG("Set req_cell_info_set fail.");
4863 }
4864 else
4865 {
4866
4867 printf("req_cell_info_set success, reg:%s\n", reg);
4868 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_CELL_RSP, reg, strlen(reg));
4869
4870 // Restart is required to take effect.
4871 LOG("Will reboot system...");
4872 }
4873 }
4874 break;
4875 }
4876 case MBTK_INFO_ID_NET_RADIO_REQ: // <uint8> 0:OFF 1:ON
4877 {
4878 if(pack->data_len == 0 || pack->data == NULL) // Get
4879 {
4880 uint8 radio_on = (uint8)isRadioOn();
4881 if(radio_on < 0)
4882 {
4883 err = MBTK_INFO_ERR_UNKNOWN;
4884 LOG("Get radio state fail.");
4885 }
4886 else
4887 {
4888 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_RADIO_RSP, &radio_on, sizeof(uint8));
4889 }
4890 }
4891 else // Set
4892 {
yq.wangd58f71e2024-08-21 23:45:31 -07004893 at_cfun_command = true;
liubin281ac462023-07-19 14:22:54 +08004894 uint8 radio_on = *(pack->data);
4895 if(radio_on != 0 && radio_on != 1)
4896 {
4897 err = MBTK_INFO_ERR_REQ_PARAMETER;
4898 LOG("Set radio state fail.");
4899 }
4900 else
4901 {
4902 setRadioPower(radio_on);
4903 if((radio_on && net_info.radio_state == MBTK_RADIO_STATE_ON)
4904 || (!radio_on && net_info.radio_state == MBTK_RADIO_STATE_OFF)) {
4905 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_RADIO_RSP, NULL, 0);
4906 } else {
4907 err = MBTK_INFO_ERR_UNKNOWN;
4908 LOG("Set radio state fail.");
4909 }
4910 }
yq.wangd58f71e2024-08-21 23:45:31 -07004911 at_cfun_command = false;
liubin281ac462023-07-19 14:22:54 +08004912 }
4913 break;
4914 }
4915 case MBTK_INFO_ID_NET_SIGNAL_REQ: // mbtk_signal_info_t
4916 {
4917 if(pack->data_len == 0 || pack->data == NULL) // Get net signal.
4918 {
4919 mbtk_signal_info_t signal;
4920 memset(&signal, 0, sizeof(mbtk_signal_info_t));
4921 if(req_net_signal_get(&signal, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4922 {
4923 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4924 err = MBTK_INFO_ERR_CME + cme_err;
4925 } else {
4926 err = MBTK_INFO_ERR_UNKNOWN;
4927 }
4928 LOG("Get net signal fail.");
4929 }
4930 else
4931 {
4932 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_SIGNAL_RSP, &signal, sizeof(mbtk_signal_info_t));
4933 }
4934 }
4935 else // Set
4936 {
4937 err = MBTK_INFO_ERR_UNSUPPORTED;
4938 LOG("Set net signal fail.");
4939 }
4940 break;
4941 }
4942 case MBTK_INFO_ID_NET_REG_REQ: // mbtk_net_reg_info_t
4943 {
4944 if(pack->data_len == 0 || pack->data == NULL) // Get net reg.
4945 {
4946 mbtk_net_reg_info_t reg;
4947 memset(&reg, 0, sizeof(mbtk_net_reg_info_t));
4948 if(req_net_reg_get(&reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
4949 {
4950 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4951 err = MBTK_INFO_ERR_CME + cme_err;
4952 } else {
4953 err = MBTK_INFO_ERR_UNKNOWN;
4954 }
4955 LOG("Get net reg fail.");
4956 }
4957 else
4958 {
4959 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_REG_RSP, &reg, sizeof(mbtk_net_reg_info_t));
4960 }
4961 }
4962 else // Set
4963 {
4964 err = MBTK_INFO_ERR_UNSUPPORTED;
4965 LOG("Set net reg fail.");
4966 }
4967 break;
4968 }
4969 case MBTK_INFO_ID_NET_APN_REQ: // mbtk_apn_info_t
4970 {
4971 if(pack->data_len == 0 || pack->data == NULL) // Get APN
4972 {
4973 uint8 buff[SOCK_MSG_LEN_MAX];
4974 memset(buff, 0, SOCK_MSG_LEN_MAX);
4975 int data_len = 0;
4976 if(req_apn_get(buff, &data_len, &cme_err) || data_len <= 0 || cme_err != MBTK_INFO_ERR_CME_NON)
4977 {
4978 if(cme_err != MBTK_INFO_ERR_CME_NON) {
4979 err = MBTK_INFO_ERR_CME + cme_err;
4980 } else {
4981 err = MBTK_INFO_ERR_UNKNOWN;
4982 }
4983 LOG("Get APN fail.");
4984 }
4985 else
4986 {
4987 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, buff, data_len);
4988 }
4989 }
4990 else // Set
4991 {
4992 // <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
4993 const uint8* ptr = pack->data;
4994 mbtk_apn_info_t apn;
4995 int len;
4996 memset(&apn, 0, sizeof(mbtk_apn_info_t));
4997 // cid
4998 apn.cid = *ptr++;
4999
5000 // ip_type
5001 apn.ip_type = (mbtk_ip_type_enum)(*ptr++);
5002
5003 // apn
5004 len = byte_2_uint16(ptr, false);
5005 ptr += sizeof(uint16);
5006 if(len > 0) {
5007 memcpy(apn.apn, ptr, len);
5008 ptr += len;
5009 }
5010
5011 // user
5012 len = byte_2_uint16(ptr, false);
5013 ptr += sizeof(uint16);
5014 if(len > 0) {
5015 memcpy(apn.user, ptr, len);
5016 ptr += len;
5017 }
5018
5019 // pass
5020 len = byte_2_uint16(ptr, false);
5021 ptr += sizeof(uint16);
5022 if(len > 0) {
5023 memcpy(apn.pass, ptr, len);
5024 ptr += len;
5025 }
5026
5027 // auth
5028 len = byte_2_uint16(ptr, false);
5029 ptr += sizeof(uint16);
5030 if(len > 0) {
5031 memcpy(apn.auth, ptr, len);
5032 ptr += len;
5033 }
5034
5035 LOGD("APN : %d, %d, %s, %s, %s, %s", apn.cid, apn.ip_type, str_empty(apn.apn) ? "NULL" : apn.apn,
5036 str_empty(apn.user) ? "NULL" : apn.user, str_empty(apn.pass) ? "NULL" : apn.pass, str_empty(apn.auth) ? "NULL" : apn.auth);
5037 if(req_apn_set(&apn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5038 {
5039 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5040 err = MBTK_INFO_ERR_CME + cme_err;
5041 } else {
5042 err = MBTK_INFO_ERR_UNKNOWN;
5043 }
5044 LOG("Set APN fail.");
5045 }
5046 else
5047 {
5048 // Save apn.
wangyouqianged88c722023-11-22 16:33:43 +08005049#ifdef MBTK_AF_SUPPORT
5050 if(apn.cid == 1)
5051 {
5052 default_iptype = apn.ip_type;
5053 }
5054#endif
liubin281ac462023-07-19 14:22:54 +08005055 apn_prop_set(&apn);
5056
5057 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, NULL, 0);
5058 }
5059 }
5060 break;
5061 }
wangyouqiang80487e42024-05-24 15:06:20 +08005062 case MBTK_INFO_ID_NET_QSER_APN_REQ:
5063 {
5064 if(pack->data_len == 0 || pack->data == NULL)
5065 {
5066 uint8 buff[SOCK_MSG_LEN_MAX];
5067 memset(buff, 0, SOCK_MSG_LEN_MAX);
5068 int data_len = 0;
5069 if(mbtk_qser_req_apn_get(buff, &data_len, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5070 {
5071 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5072 err = MBTK_INFO_ERR_CME + cme_err;
5073 } else {
5074 err = MBTK_INFO_ERR_UNKNOWN;
5075 }
5076 LOGE("Get APN fail.");
5077 }
5078 else
5079 {
5080 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_RSP, buff, data_len);
5081 }
5082 }
5083 else
5084 {
5085 const uint8* ptr = pack->data;
5086 mbtk_apn_info_t apn;
5087 mbtk_apn_req_type_enum req_type = MBTK_APN_REQ_TYPE_SET;
5088 uint8 apn_type[MBTK_QSER_APN_NAME_SIZE] = {0};
5089 int ret = mbtk_strdata_to_apn(pack->data, &apn, apn_type, &req_type);
5090 if(ret < 0)
5091 {
5092 LOGE("mbtk_strdata_to_apn fail. ret = [%d]", ret);
5093 err = MBTK_INFO_ERR_REQ_PARAMETER;
5094 }
5095 else
5096 {
5097 if(req_apn_set(&apn, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5098 {
5099 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5100 err = MBTK_INFO_ERR_CME + cme_err;
5101 } else {
5102 err = MBTK_INFO_ERR_UNKNOWN;
5103 }
5104 LOGE("Set APN fail.");
5105 }
5106 else
5107 {
5108 // Save apn.
5109 apn_prop_set(&apn);
5110 mbtk_qser_apn_save(apn, apn_type, true);
5111 if(req_type == MBTK_APN_REQ_TYPE_ADD)
5112 {
5113 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_QSER_APN_RSP, (void *)&apn.cid, 1);
5114 }
5115 else
5116 {
5117 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_QSER_APN_RSP, NULL, 0);
5118 }
5119 }
5120 }
5121 }
5122
5123 break;
5124 }
b.liu288093c2024-05-09 17:02:57 +08005125 case MBTK_INFO_ID_NET_APN_DEL_REQ:
liuyang0e49d9a2024-04-23 21:04:54 +08005126 {
b.liu288093c2024-05-09 17:02:57 +08005127 if(pack->data_len == 0 || pack->data == NULL)
liuyang0e49d9a2024-04-23 21:04:54 +08005128 {
5129 err = MBTK_INFO_ERR_UNSUPPORTED;
5130 LOG("Unsupported delete apn .");
5131 }
b.liu288093c2024-05-09 17:02:57 +08005132 else
liuyang0e49d9a2024-04-23 21:04:54 +08005133 {
liuyang1cefd852024-04-24 18:30:53 +08005134 int profile = pack->data[0];
wangyouqiang80487e42024-05-24 15:06:20 +08005135 if(cid_active[profile] == 1)
liuyang0e49d9a2024-04-23 21:04:54 +08005136 {
wangyouqiang80487e42024-05-24 15:06:20 +08005137 LOGD("cid pdp already open.");
5138 err = MBTK_INFO_ERR_CID_EXIST;
wangyouqiang13e98402024-05-24 16:07:43 +08005139 break;
wangyouqiang80487e42024-05-24 15:06:20 +08005140 }
5141 if(mbtk_qser_apn_del(profile) < 0)
5142 {
5143 LOGD("del error.");
5144 err = MBTK_INFO_ERR_REQ_PARAMETER;
liuyang0e49d9a2024-04-23 21:04:54 +08005145 }
5146 else
5147 {
wangyouqiang80487e42024-05-24 15:06:20 +08005148 if(req_apn_del(profile, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5149 {
5150 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5151 err = MBTK_INFO_ERR_CME + cme_err;
5152 } else {
5153 err = MBTK_INFO_ERR_UNKNOWN;
5154 }
5155 LOG("Delete apn fail.");
5156 }
5157 else
5158 {
5159 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_APN_DEL_RSP, NULL, 0);
5160 }
liuyang0e49d9a2024-04-23 21:04:54 +08005161 }
5162 }
5163 break;
5164 }
liubin281ac462023-07-19 14:22:54 +08005165 case MBTK_INFO_ID_NET_DATA_CALL_REQ:
5166 {
5167 if(pack->data_len == 0 || pack->data == NULL)
5168 {
5169 err = MBTK_INFO_ERR_UNSUPPORTED;
5170 }
5171 else
5172 {
5173 /* <call_type[1]><cid[1]><auto_conn_interval[1]><boot_conn[1]><timeout[1]>
5174 call_type : mbtk_data_call_type_enum
5175 cid : 2 - 7
5176 timeout : second
5177 */
5178 mbtk_data_call_type_enum call_type = (mbtk_data_call_type_enum)pack->data[0];
5179 int cid = pack->data[1];
5180 int reconn = 0;
5181
wangyouqiang80487e42024-05-24 15:06:20 +08005182#if 0
liubin281ac462023-07-19 14:22:54 +08005183 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) {
5184 err = MBTK_INFO_ERR_CID;
5185 break;
5186 }
wangyouqiang80487e42024-05-24 15:06:20 +08005187#endif
5188 if(mbtk_check_cid(cid) < 0)
5189 {
5190 err = MBTK_INFO_ERR_CID;
5191 break;
5192 }
liubin281ac462023-07-19 14:22:54 +08005193
5194 LOG("cid_active[%d] = %d", cid, cid_active[cid]);
5195 memset(&cgact_wait, 0, sizeof(info_cgact_wait_t));
5196 switch(call_type) {
5197 case MBTK_DATA_CALL_START: {
5198 //mbtk wyq for data_call_ex add start
5199 int auto_conn_interval = pack->data[2];
5200 int boot_conn = pack->data[3];
5201 int timeout = pack->data[4];
5202 data_call_bootconn_save(cid, boot_conn);
b.liufe320632024-01-17 20:38:08 +08005203
wangyouqiang13e98402024-05-24 16:07:43 +08005204 mbtk_signal_info_t signal;
5205 memset(&signal, 0xFF, sizeof(mbtk_signal_info_t));
5206 req_net_signal_get(&signal, NULL);
b.liufe320632024-01-17 20:38:08 +08005207
liubin281ac462023-07-19 14:22:54 +08005208 if(cid_active[cid] == 1)
5209 {
5210 err = MBTK_INFO_ERR_CID_EXIST;
5211 break;
5212 }
b.liufe320632024-01-17 20:38:08 +08005213
wangyouqiang80487e42024-05-24 15:06:20 +08005214 if(mbtk_check_default_pdp_state(cid))
5215 {
5216 err = MBTK_INFO_ERR_UNSUPPORTED;
5217 break;
5218 }
5219
liubin281ac462023-07-19 14:22:54 +08005220 data_call_reconn:
5221 //mbtk wyq for data_call_ex add end
5222 cgact_wait.waitting = true;
5223 cgact_wait.cid = cid;
5224 cgact_wait.act = true;
5225 if(req_data_call_start(cid, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5226 {
5227 //mbtk wyq for data_call_ex add start
5228 if(reconn < 5 && auto_conn_interval > 0)
5229 {
5230 sleep(auto_conn_interval);
5231 reconn++;
5232 cme_err = MBTK_INFO_ERR_CME_NON;
5233 LOG("data_call restart call.");
5234 goto data_call_reconn;
5235 }
5236 //mbtk wyq for data_call_ex add end
5237 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5238 err = MBTK_INFO_ERR_CME + cme_err;
5239 } else {
5240 err = MBTK_INFO_ERR_UNKNOWN;
5241 }
5242 LOG("%d active fail.", cid);
5243 }
5244 else
5245 {
5246 // Wait for "CONNECT" or "+CGEV:"
5247 if(wait_cgact_complete(timeout)) { // Timeout
5248 err = MBTK_INFO_ERR_TIMEOUT;
5249 break;
5250 }
5251
5252 // Get IP information.
5253 mbtk_ipv4_info_t ipv4;
5254 mbtk_ipv6_info_t ipv6;
5255 memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t));
5256 memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t));
5257 if(req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5258 {
5259 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5260 err = MBTK_INFO_ERR_CME + cme_err;
5261 } else {
5262 err = MBTK_INFO_ERR_UNKNOWN;
5263 }
5264 LOG("Get %d state fail.", cid);
5265 }
5266 else
5267 {
5268 // Config IPv4 address.
wangyouqianged88c722023-11-22 16:33:43 +08005269#ifdef MBTK_AF_SUPPORT
5270 if(cid == 1)
5271 {
5272 //uint8 pdp_data = cid;
5273 //pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_data, sizeof(uint8));
5274 ipv4.valid = false;
5275 ipv6.valid = false;
5276 if(default_iptype == MBTK_IP_TYPE_IP)
5277 {
5278 ipv4.valid = true;
5279 }
5280 else if(default_iptype == MBTK_IP_TYPE_IPV6)
5281 {
5282 ipv6.valid = true;
5283 }
5284 else
5285 {
5286 ipv4.valid = true;
5287 ipv6.valid = true;
5288 }
5289 }
5290#endif
liubin281ac462023-07-19 14:22:54 +08005291#if 1
5292 if(ipv4.valid) {
5293 char dev[20] = {0};
5294 sprintf(dev, "ccinet%d", cid - 1);
5295
5296 char ip[20] = {0};
5297 char gateway[20] = {0};
5298 char *gateway_ptr = NULL;
5299 char netmask[20] = {0};
5300 char *netmask_ptr = NULL;
5301 if(inet_ntop(AF_INET, &(ipv4.IPAddr), ip, 20) == NULL) {
5302 err = MBTK_INFO_ERR_UNKNOWN;
5303 LOGE("inet_ntop ipv4 ip fail.");
5304 log_hex("IPv4", &(ipv4.IPAddr), 4);
5305 break;
5306 }
5307
5308 if(ipv4.GateWay) {
5309 if(inet_ntop(AF_INET, &(ipv4.GateWay), gateway, 20) == NULL) {
5310 err = MBTK_INFO_ERR_UNKNOWN;
5311 LOGE("inet_ntop ipv4 gateway fail.");
5312 log_hex("IPv4", &(ipv4.IPAddr), 4);
5313 break;
5314 } else {
5315 gateway_ptr = gateway;
5316 }
5317 }
5318
5319 if(ipv4.NetMask) {
5320 if(inet_ntop(AF_INET, &(ipv4.NetMask), netmask, 20) == NULL) {
5321 err = MBTK_INFO_ERR_UNKNOWN;
5322 LOGE("inet_ntop ipv4 netmask fail.");
5323 log_hex("IPv4", &(ipv4.IPAddr), 4);
5324 break;
5325 } else {
5326 netmask_ptr = netmask;
5327 }
5328 }
5329
5330 if(netmask_ptr == NULL) {
5331 netmask_ptr = netmask;
5332 memcpy(netmask_ptr, "255.255.255.0", strlen("255.255.255.0"));
5333 }
5334
5335 if(mbtk_ifc_configure2(dev, ip, 0, gateway_ptr, netmask_ptr)) {
5336 LOGD("Config %s IPv4 %s fail.", dev, ip);
5337 } else {
5338 LOGD("Config %s IPv4 %s success.", dev, ip);
5339 }
5340
5341 }
5342#endif
5343 // Config IPv6 address.
5344 if(ipv6.valid) {
5345 char ip[50] = {0};
5346 char dev[20] = {0};
5347 sprintf(dev, "ccinet%d", cid - 1);
5348
5349 if(inet_ntop(AF_INET6, &(ipv6.IPV6Addr), ip, 50) == NULL) {
5350 err = MBTK_INFO_ERR_UNKNOWN;
5351 LOGE("inet_ntop ipv6 ip fail.");
5352 log_hex("IPv6", &(ipv6.IPV6Addr), 16);
5353 break;
5354 }
5355
5356 if(mbtk_ipv6_config(dev, ip, 64)) {
5357 LOGD("Config %s IPv6 %s fail.", dev, ip);
5358 } else {
5359 LOGD("Config %s IPv6 %s success.", dev, ip);
5360 }
5361 }
5362
5363 cid_active[cid] = 1;
wangyouqiang80487e42024-05-24 15:06:20 +08005364 mbtk_set_default_pdp_state(true, cid);
5365 mbtk_qser_route_config(cid, &ipv4, &ipv6);
liubin281ac462023-07-19 14:22:54 +08005366 if(cli_info->fd != DATA_CALL_BOOTCONN_FD)
5367 {
liuyange134d842024-06-27 17:34:02 +08005368 mbtk_net_led_set(MBTK_NET_LED_DATA_CONNECT);
liubin281ac462023-07-19 14:22:54 +08005369 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0);
5370 }
5371 else
5372 {
5373 free(pack->data);
5374 free(cli_info);
5375 LOG("data_call bootconn success.");
5376 }
5377 }
5378 }
5379 break;
5380 }
5381 case MBTK_DATA_CALL_STOP: {
5382 //mbtk wyq for data_call_ex add start
5383 if(cid_active[cid] == 0)
5384 {
5385 err = MBTK_INFO_ERR_CID_NO_EXIST;
5386 break;
5387 }
5388
5389 int timeout = pack->data[2];
5390 //mbtk wyq for data_call_ex add end
b.liuf37bd332024-03-18 13:51:24 +08005391#if (defined(MBTK_AF_SUPPORT) || defined(MBTK_ALL_CID_SUPPORT))
wangyouqianged88c722023-11-22 16:33:43 +08005392 if(cid == 1)
5393 {
5394 char dev[20] = {0};
5395 uint8 pdp_data = cid + 100;
5396 pack_rsp_send(cli_info->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, &pdp_data, sizeof(uint8));
b.liufe320632024-01-17 20:38:08 +08005397
wangyouqianged88c722023-11-22 16:33:43 +08005398 sprintf(dev, "ccinet%d", cid - 1);
5399
5400 // Config network.
5401 if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
5402 LOGD("Config %s IPv4 0 fail.", dev);
5403 } else {
5404 LOGD("Config %s IPv4 0 success.", dev);
5405 }
5406 cid_active[cid] = 0;
wangyouqiang80487e42024-05-24 15:06:20 +08005407 mbtk_set_default_pdp_state(false, cid);
liuyange134d842024-06-27 17:34:02 +08005408 mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
wangyouqianged88c722023-11-22 16:33:43 +08005409 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0);
5410 break;
5411 }
5412#endif
liubin281ac462023-07-19 14:22:54 +08005413 cgact_wait.waitting = true;
5414 cgact_wait.cid = cid;
5415 cgact_wait.act = false;
5416 if(req_data_call_stop(cid, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5417 {
5418 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5419 err = MBTK_INFO_ERR_CME + cme_err;
5420 } else {
5421 err = MBTK_INFO_ERR_UNKNOWN;
5422 }
5423 LOG("%d deactive fail.", cid);
5424 }
5425 else
5426 {
5427 // Wait for "CONNECT" or "+CGEV:"
5428 if(wait_cgact_complete(timeout)) { // Timeout
5429 err = MBTK_INFO_ERR_TIMEOUT;
5430 break;
5431 }
5432 char dev[20] = {0};
5433 sprintf(dev, "ccinet%d", cid - 1);
5434
5435 // Config network.
5436 if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
5437 LOGD("Config %s IPv4 0 fail.", dev);
5438 } else {
5439 LOGD("Config %s IPv4 0 success.", dev);
5440 }
5441
5442#if 0
5443 if(mbtk_ipv6_config(dev, NULL, 64)) {
5444 LOGD("Config %s IPv6 0 fail.", dev);
5445 } else {
5446 LOGD("Config %s IPv6 0 success.", dev);
5447 }
5448#endif
5449 cid_active[cid] = 0;
wangyouqiang80487e42024-05-24 15:06:20 +08005450 mbtk_set_default_pdp_state(false, cid);
liuyange134d842024-06-27 17:34:02 +08005451 mbtk_net_led_set(MBTK_NET_LED_NET_CONNECT);
liubin281ac462023-07-19 14:22:54 +08005452 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, NULL, 0);
5453 }
5454 break;
5455 }
5456 case MBTK_DATA_CALL_STATE: {
wangyouqianged88c722023-11-22 16:33:43 +08005457 if(cid_active[cid] == 0)
5458 {
5459 err = MBTK_INFO_ERR_CID_NO_EXIST;
5460 break;
5461 }
liubin281ac462023-07-19 14:22:54 +08005462 mbtk_ipv4_info_t ipv4;
5463 mbtk_ipv6_info_t ipv6;
5464 memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t));
5465 memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t));
5466 if(req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5467 {
5468 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5469 err = MBTK_INFO_ERR_CME + cme_err;
5470 } else {
5471 err = MBTK_INFO_ERR_UNKNOWN;
5472 }
5473 LOG("Get %d state fail.", cid);
5474 }
5475 else
5476 {
5477 uint8 buff[SOCK_MSG_LEN_MAX] = {0};
5478 int buff_len = 0;
wangyouqianged88c722023-11-22 16:33:43 +08005479#ifdef MBTK_AF_SUPPORT
5480 if(cid == 1)
5481 {
5482 ipv4.valid = false;
5483 ipv6.valid = false;
5484 if(default_iptype == MBTK_IP_TYPE_IP)
5485 {
5486 ipv4.valid = true;
5487 }
5488 else if(default_iptype == MBTK_IP_TYPE_IPV6)
5489 {
5490 ipv6.valid = true;
5491 }
5492 else
5493 {
5494 ipv4.valid = true;
5495 ipv6.valid = true;
5496 }
5497 }
5498#endif
liubin281ac462023-07-19 14:22:54 +08005499 if(ipv4.valid && ipv6.valid) {
5500 buff[0] = (uint8)2;
5501 buff_len++;
5502
5503 memcpy(buff + buff_len, &ipv4, sizeof(mbtk_ipv4_info_t));
5504 buff_len += sizeof(mbtk_ipv4_info_t);
5505 memcpy(buff + buff_len, &ipv6, sizeof(mbtk_ipv6_info_t));
5506 buff_len += sizeof(mbtk_ipv6_info_t);
5507 } else if(ipv4.valid) {
5508 buff[0] = (uint8)0;
5509 buff_len++;
5510
5511 memcpy(buff + buff_len, &ipv4, sizeof(mbtk_ipv4_info_t));
5512 buff_len += sizeof(mbtk_ipv4_info_t);
5513 } else if(ipv6.valid) {
5514 buff[0] = (uint8)1;
5515 buff_len++;
5516
5517 memcpy(buff + buff_len, &ipv6, sizeof(mbtk_ipv6_info_t));
5518 buff_len += sizeof(mbtk_ipv6_info_t);
5519 } else {
5520 LOGE("Get IPv4/IPv6 fail.");
5521 err = MBTK_INFO_ERR_UNKNOWN;
5522 break;
5523 }
5524 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_DATA_CALL_RSP, buff, buff_len);
5525 }
5526 break;
5527 }
5528 default: {
5529 err = MBTK_INFO_ERR_FORMAT;
5530 break;
5531 }
5532 }
5533 }
5534 break;
5535 }
r.xiao06db9a12024-04-14 18:51:15 -07005536 case MBTK_INFO_ID_NET_IMS_REQ:
5537 {
5538 if(pack->data_len == 0 || pack->data == NULL) //Get
5539 {
5540 int reg = -1;
5541 if(net_ims_get(&reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5542 {
5543 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5544 err = MBTK_INFO_ERR_CME + cme_err;
5545 } else {
5546 err = MBTK_INFO_ERR_UNKNOWN;
5547 }
5548 LOG("Get net ims fail.");
5549 }
5550 else
5551 {
5552 uint8 reg_type = (uint8)reg;
5553 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_RSP, &reg_type, sizeof(uint8));
5554 }
5555 }
5556 else
5557 {
5558 uint8 ims = *(pack->data);
5559
5560 if(net_ims_set(ims, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5561 {
5562 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5563 err = MBTK_INFO_ERR_CME + cme_err;
5564 } else {
5565 err = MBTK_INFO_ERR_UNKNOWN;
5566 }
5567 LOG("Set net ims fail.");
5568 }
5569 else
5570 {
5571 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_RSP, NULL, 0);
5572 }
5573 }
5574 break;
5575 }
b.liufdf03172024-06-07 15:01:29 +08005576 case MBTK_INFO_ID_NET_IMS_REG_STATE_REQ:
5577 {
5578 if(pack->data_len == 0 || pack->data == NULL) //Get
5579 {
5580 int reg = -1;
5581 if(net_ims_reg_state_get(&reg, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5582 {
5583 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5584 err = MBTK_INFO_ERR_CME + cme_err;
5585 } else {
5586 err = MBTK_INFO_ERR_UNKNOWN;
5587 }
5588 LOG("Get net ims fail.");
5589 }
5590 else
5591 {
5592 uint8 reg_type = (uint8)reg;
5593 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_NET_IMS_REG_STATE_RSP, &reg_type, sizeof(uint8));
5594 }
5595 }
5596 else
5597 {
5598 err = MBTK_INFO_ERR_UNSUPPORTED;
5599 }
5600 break;
5601 }
r.xiaoec113d12024-01-12 02:13:28 -08005602 case MBTK_INFO_ID_WAKEUP_STA_REQ:
5603 {
5604 if(pack->data_len == 0 || pack->data == NULL)
5605 {
5606 err = MBTK_INFO_ERR_UNSUPPORTED;
5607 LOG("Get POWERIND state UNSUPPORTED.");
5608 }
5609 else // Set powerind state.
5610 {
5611 uint32 state = *(pack->data);
5612 if(req_powerind_set(state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5613 {
5614 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5615 err = MBTK_INFO_ERR_CME + cme_err;
5616 } else {
5617 err = MBTK_INFO_ERR_UNKNOWN;
5618 }
5619 LOG("Set POWERIND state fail.");
5620 }
5621 else
5622 {
5623 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_WAKEUP_STA_RSP, NULL, 0);
5624 }
5625 }
5626 break;
5627 }
5628 case MBTK_INFO_ID_OOS_STA_REQ:
5629 {
5630 if(pack->data_len == 0 || pack->data == NULL)
5631 {
5632 mbtk_oos_info oos_t;
5633 if(req_oos_get(&oos_t, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5634 {
5635 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5636 err = MBTK_INFO_ERR_CME + cme_err;
5637 } else {
5638 err = MBTK_INFO_ERR_UNKNOWN;
5639 }
5640 LOG("Get SMS OOS fail.");
r.xiaoec113d12024-01-12 02:13:28 -08005641 }
5642 else
5643 {
r.xiaoec113d12024-01-12 02:13:28 -08005644 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_OOS_STA_RSP, &oos_t, sizeof(mbtk_oos_info));
5645 }
5646 }
b.liufe320632024-01-17 20:38:08 +08005647 else // Set OOS
r.xiaoec113d12024-01-12 02:13:28 -08005648 {
r.xiaocfd7c682024-01-22 03:59:46 -08005649 mbtk_oos_info *state = (mbtk_oos_info *)pack->data;
5650 if(pack->data_len != sizeof(mbtk_oos_info))
5651 {
5652 err = MBTK_INFO_ERR_REQ_PARAMETER;
5653 LOG("Set oos error.");
5654 break;
5655 }
5656
r.xiaoec113d12024-01-12 02:13:28 -08005657 if(req_oos_set(state, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
5658 {
5659 if(cme_err != MBTK_INFO_ERR_CME_NON) {
5660 err = MBTK_INFO_ERR_CME + cme_err;
5661 } else {
5662 err = MBTK_INFO_ERR_UNKNOWN;
5663 }
5664 LOG("Set OOS fail.");
5665 }
5666 else
5667 {
5668 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_OOS_STA_RSP, NULL, 0);
5669 }
5670 }
5671 break;
5672 }
wangyouqiang38e53362024-01-23 10:53:48 +08005673 case MBTK_INFO_ID_LED_REQ:
5674 {
5675 if(pack->data_len == 0 || pack->data == NULL)
5676 {
5677 err = MBTK_INFO_ERR_UNSUPPORTED;
5678 LOGE("led param is error.");
5679 }
5680 else
5681 {
5682 char type = pack->data[0];
5683 char status = pack->data[1];
5684 LOGE("[set_led] = [%d], [status_led] = [%d].", type, status);
r.xiaoec113d12024-01-12 02:13:28 -08005685
wangyouqiang38e53362024-01-23 10:53:48 +08005686 if(type == MBTK_LED_TYPE_NET)
5687 {
5688 if(status == MBTK_LED_STATUS_CLOSE)
5689 {
5690 mbtk_net_led_set(MBTK_NET_LED_CLOSE);
5691 }
5692 else
5693 {
5694 mbtk_net_led_set(MBTK_NET_LED_OPEN);
5695 }
5696 }
5697 else
5698 {
5699 if(status == MBTK_LED_STATUS_CLOSE)
5700 {
5701 status_led_set(MBTK_STATUS_LED_CLOSE);
5702 }
5703 else
5704 {
5705 status_led_set(MBTK_STATUS_LED_OPEN);
5706 }
5707 }
5708 pack_rsp_send(cli_info->fd, MBTK_INFO_ID_LED_RSP, NULL, 0);
5709 }
5710 break;
5711 }
liubin281ac462023-07-19 14:22:54 +08005712 default:
5713 {
5714 err = MBTK_INFO_ERR_REQ_UNKNOWN;
5715 LOG("Unknown request : %s", id2str(pack->info_id));
5716 break;
5717 }
5718 }
5719
5720 return err;
5721 }
5722}
5723
5724// Process AT URC data
5725static int send_pack_to_queue(sock_client_info_t* cli_info, void* pack)
5726{
5727 if(info_queue.count >= PACK_PROCESS_QUEUE_MAX)
5728 {
5729 LOG("Packet process queue is full");
5730 return -1;
5731 }
5732
5733 info_queue_item_t *item = (info_queue_item_t*)malloc(sizeof(info_queue_item_t));
5734 if(!item)
5735 {
5736 LOG("malloc() fail[%d].", errno);
5737 return -1;
5738 }
5739 item->cli_info = cli_info;
5740 item->pack = pack;
5741 mbtk_queue_put(&info_queue, item);
5742
5743 // If thread is waitting,continue it.
5744 if(1/*!is_running*/)
5745 {
5746 pthread_mutex_lock(&info_mutex);
5747 pthread_cond_signal(&info_cond);
5748 pthread_mutex_unlock(&info_mutex);
5749 }
5750 else
5751 {
5752 LOG("Packet process thread is process...");
5753 }
5754
5755 return 0;
5756}
5757
5758static void radio_state_change(void *data, int data_len)
5759{
5760 uint8 *data_ptr = (uint8*)data;
5761 if(data_ptr[0]) {
5762 net_info.radio_state = MBTK_RADIO_STATE_ON;
5763 } else {
5764 net_info.radio_state = MBTK_RADIO_STATE_OFF;
5765 }
5766
5767 sock_client_info_t *cli = NULL;
5768 list_first(sock_client_list);
5769 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5770 {
5771 if(cli->ind_num > 0) {
5772 int i;
5773 for(i = 0; i < IND_REGISTER_MAX; i++) {
5774 // Registe MBTK_INFO_ID_IND_RADIO_STATE_CHANGE
5775 if(cli->ind_register[i] == MBTK_INFO_ID_IND_RADIO_STATE_CHANGE) {
5776 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_RADIO_STATE_CHANGE, data, data_len);
5777 break;
5778 }
5779 }
5780 }
5781 }
5782}
5783
5784static void pdp_state_change(void *data, int data_len)
5785{
5786 sock_client_info_t *cli = NULL;
5787 list_first(sock_client_list);
5788 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5789 {
5790 if(cli->ind_num > 0) {
5791 int i;
5792 for(i = 0; i < IND_REGISTER_MAX; i++) {
5793 if(cli->ind_register[i] == MBTK_INFO_ID_IND_PDP_STATE_CHANGE) {
5794 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_PDP_STATE_CHANGE, data, data_len);
5795 break;
5796 }
5797 }
5798 }
5799 }
5800}
5801
5802static void net_state_change(void *data, int data_len)
5803{
5804 sock_client_info_t *cli = NULL;
5805 list_first(sock_client_list);
5806 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5807 {
5808 if(cli->ind_num > 0) {
5809 int i;
5810 for(i = 0; i < IND_REGISTER_MAX; i++) {
5811 // Registe MBTK_INFO_ID_IND_NET_STATE_CHANGE
5812 if(cli->ind_register[i] == MBTK_INFO_ID_IND_NET_STATE_CHANGE) {
5813 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_NET_STATE_CHANGE, data, data_len);
5814 break;
5815 }
5816 }
5817 }
5818 }
5819}
5820
5821static void call_state_change(void *data, int data_len)
5822{
5823 sock_client_info_t *cli = NULL;
5824 list_first(sock_client_list);
5825 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5826 {
5827 if(cli->ind_num > 0) {
5828 int i;
5829 for(i = 0; i < IND_REGISTER_MAX; i++) {
5830 // Registed MBTK_INFO_ID_IND_RADIO_STATE_CHANGE
5831 if(cli->ind_register[i] == MBTK_INFO_ID_IND_CALL_STATE_CHANGE) {
5832 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_CALL_STATE_CHANGE, data, data_len);
5833 break;
5834 }
5835 }
5836 }
5837 }
5838}
5839
5840static void sim_state_change(void *data, int data_len)
5841{
5842 sock_client_info_t *cli = NULL;
5843 list_first(sock_client_list);
5844 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5845 {
5846 if(cli->ind_num > 0) {
5847 int i;
5848 for(i = 0; i < IND_REGISTER_MAX; i++) {
5849 // Registed MBTK_INFO_ID_IND_RADIO_STATE_CHANGE
5850 if(cli->ind_register[i] == MBTK_INFO_ID_IND_SIM_STATE_CHANGE) {
5851 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SIM_STATE_CHANGE, data, data_len);
5852 break;
5853 }
5854 }
5855 }
5856 }
5857}
5858
5859static void sms_state_change(void *data, int data_len)
5860{
5861 sock_client_info_t *cli = NULL;
5862 list_first(sock_client_list);
5863 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5864 {
5865 if(cli->ind_num > 0) {
5866 int i;
5867 for(i = 0; i < IND_REGISTER_MAX; i++) {
5868 // Registed MBTK_INFO_ID_IND_SMS_STATE_CHANGE
5869 if(cli->ind_register[i] == MBTK_INFO_ID_IND_SMS_STATE_CHANGE) {
5870 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SMS_STATE_CHANGE, data, data_len);
5871 break;
5872 }
5873 }
5874 }
5875 }
5876}
5877
r.xiaofca7c472024-04-24 01:00:23 -07005878static void signal_state_change(void *data, int data_len)
5879{
5880 sock_client_info_t *cli = NULL;
5881 list_first(sock_client_list);
5882 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
5883 {
5884 if(cli->ind_num > 0) {
5885 int i;
5886 for(i = 0; i < IND_REGISTER_MAX; i++) {
5887 // Registe MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE
5888 if(cli->ind_register[i] == MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE) {
5889 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SIGNAL_STATE_CHANGE, data, data_len);
5890 break;
5891 }
5892 }
5893 }
5894 }
5895}
5896
5897
liubin281ac462023-07-19 14:22:54 +08005898int urc_msg_distribute(bool async_process, info_urc_msg_id_enum msg, void *data, int data_len)
5899{
5900#if 0
5901 if(urc_queue.count >= PACK_PROCESS_QUEUE_MAX)
5902 {
5903 LOG("Packet process queue is full");
5904 return -1;
5905 }
5906
5907 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
5908 if(!urc)
5909 {
5910 LOG("malloc() fail[%d].", errno);
5911 return -1;
5912 }
5913 urc->msg = msg;
5914 urc->data = memdup(data, data_len);
5915 urc->data_len = data_len;
5916
5917 mbtk_queue_put(&urc_queue, urc);
5918
5919 // If thread is waitting,continue it.
5920 if(1/*!is_running*/)
5921 {
5922 pthread_mutex_lock(&urc_mutex);
5923 pthread_cond_signal(&urc_cond);
5924 pthread_mutex_unlock(&urc_mutex);
5925 }
5926 else
5927 {
5928 LOG("Packet process thread is process...");
5929 }
5930
5931 return 0;
5932#else
5933 if(async_process) {
5934 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
5935 if(!urc)
5936 {
5937 LOG("malloc() fail[%d].", errno);
5938 return -1;
5939 }
5940 urc->msg = msg;
5941 if(data && data_len > 0) {
5942 urc->data = memdup(data, data_len);
5943 urc->data_len = data_len;
5944 } else {
5945 urc->data = NULL;
5946 urc->data_len = 0;
5947 }
5948 return send_pack_to_queue(NULL, urc);
5949 } else {
5950 switch(msg) {
5951 case INFO_URC_MSG_NET_CS_REG_STATE:
5952 {
5953 net_state_change(data, data_len);
5954 break;
5955 }
5956 case INFO_URC_MSG_CALL_STATE:
5957 {
5958 call_state_change(data, data_len);
5959 break;
5960 }
5961 case INFO_URC_MSG_SMS_STATE:
5962 {
5963 sms_state_change(data, data_len);
5964 break;
5965 }
5966 case INFO_URC_MSG_SIM_STATE:
5967 {
5968 sim_state_change(data, data_len);
5969 break;
5970 }
5971 case INFO_URC_MSG_PDP_STATE:
5972 {
5973 pdp_state_change(data, data_len);
5974 break;
5975 }
5976 default: {
5977 LOGE("Unknown msg : %d", msg);
5978 break;
5979 }
5980 }
5981
5982 return 0;
5983 }
5984#endif
5985}
5986
5987
5988static void ind_regisger(sock_client_info_t* cli_info, uint16 ind)
5989{
5990 uint32 i = 0;
5991 while(i < cli_info->ind_num)
5992 {
5993 if(cli_info->ind_register[i] == ind)
5994 break;
5995 i++;
5996 }
5997
5998 if(i == cli_info->ind_num) // No found IND
5999 {
6000 cli_info->ind_register[i] = ind;
6001 cli_info->ind_num++;
6002 LOG("Register IND : %s", id2str(ind));
6003 }
6004 else
6005 {
6006 LOG("IND had exist.");
6007 }
6008}
6009
6010static void pack_distribute(sock_client_info_t* cli_info, mbtk_info_pack_t* pack)
6011{
6012 // Register IND Message.
6013 if(mbtk_info_type_get(pack->info_id) == MBTK_INFO_TYPE_IND)
6014 {
6015 mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
6016 if(cli_info->ind_num >= IND_REGISTER_MAX)
6017 {
6018 LOG("IND if full.");
6019 err = MBTK_INFO_ERR_IND_FULL;
6020 }
6021 else
6022 {
6023 ind_regisger(cli_info, pack->info_id);
6024 }
6025
6026 pack_error_send(cli_info->fd, pack->info_id, err);
6027
6028 mbtk_info_pack_free(&pack);
6029 }
6030 else // Request Information.
6031 {
6032 LOG("Start process REQ(%s), Length : %d", id2str(pack->info_id), pack->data_len);
6033 if(0 && pack->data_len > 0)
6034 {
6035 log_hex("DATA", pack->data, pack->data_len);
6036 }
6037
6038 // Send to REQ_process_thread process.
6039 send_pack_to_queue(cli_info, pack);
6040
6041 // For test.
6042 // pack_error_send(cli_info->fd, pack->info_id + 1, MBTK_INFO_ERR_SUCCESS);
6043 }
6044}
6045
6046static sock_client_info_t* cli_find(int fd)
6047{
6048 sock_client_info_t *result = NULL;
6049 list_first(sock_client_list);
6050 while ((result = (sock_client_info_t*) list_next(sock_client_list)))
6051 {
6052 if (result->fd == fd)
6053 return result;
6054 }
6055
6056 return NULL;
6057}
6058
6059//mbtk wyq for server_ready_status add start
6060void server_ready_set(void)
6061{
6062 server_ready_status = 1;
6063}
6064
6065char server_ready_get(void)
6066{
6067 return server_ready_status;
6068}
6069
6070static void server_state_send(void)
6071{
6072 sock_client_info_t *cli = NULL;
6073 list_first(sock_client_list);
6074 while ((cli = (sock_client_info_t*) list_next(sock_client_list)))
6075 {
6076 if(cli->ind_num > 0) {
6077 if(cli->ind_register[0] == MBTK_INFO_ID_IND_SERVER_STATE_CHANGE) {
6078 cli->ind_num = 0;
6079 cli->ind_register[0] = 0;
6080 pack_rsp_send(cli->fd , MBTK_INFO_ID_IND_SERVER_STATE_CHANGE, "1", 1);
6081 break;
6082 }
6083 }
6084 else
6085 {
6086 break;
6087 }
6088 }
6089 LOG("handshake message send ok.");
6090}
6091
6092//mbtk wyq for server_ready_status add end
6093
6094//mbtk wyq for data_call_ex add start
6095//Save the cid that "DATA_CALL" needs to be automatically connected after startup
6096void data_call_bootconn_save(int cid, int bootconn)
6097{
6098 if(cid_bootconn[cid] == bootconn + '0')
6099 {
6100 return;
6101 }
6102 cid_bootconn[cid] = bootconn + '0';
6103
6104 LOG("data_call_bootconn_set cid_bootconn = %s", cid_bootconn);
6105 property_set("persist.mbtk.datacall.bootconn", cid_bootconn);
6106}
6107
6108static void* data_call_bootconn_pthread(void *arg)
6109{
6110 UNUSED(arg);
6111 LOG("data_call_bootconn_pthread enter.");
6112 int i = 0;
6113 int send_sum = 0;
6114 int bootconn = 0;
b.liufe320632024-01-17 20:38:08 +08006115
liubin281ac462023-07-19 14:22:54 +08006116 while(1)
6117 {
6118 if(server_ready_get() && send_sum == 0)
6119 {
6120 server_state_send();
6121 send_sum = 1;
6122 }
b.liufe320632024-01-17 20:38:08 +08006123
liubin281ac462023-07-19 14:22:54 +08006124 if(net_info.sim_state == MBTK_SIM_READY && net_info.net_type == MBTK_RADIO_TECH_E_UTRAN && bootconn == 0)
6125 {
6126 //data_call_bootconn_exec();
6127 property_get("persist.mbtk.datacall.bootconn", cid_bootconn, "00000000");
6128 LOG("data_call_bootconn_exec cid_bootconn = %s", cid_bootconn);
b.liufe320632024-01-17 20:38:08 +08006129
liubin281ac462023-07-19 14:22:54 +08006130 for(i = MBTK_APN_CID_MIN; i < MBTK_APN_CID_MAX + 1; i++)
6131 {
6132 if(cid_bootconn[i] == '1')
6133 {
6134 sock_client_info_t *info = (sock_client_info_t*)malloc(sizeof(sock_client_info_t));
6135 if(info == NULL)
6136 {
6137 LOG("clinent_info malloc() fail.");
6138 continue;
6139 }
6140 memset(info, 0, sizeof(sock_client_info_t));
6141 info->fd = DATA_CALL_BOOTCONN_FD;
b.liufe320632024-01-17 20:38:08 +08006142
liubin281ac462023-07-19 14:22:54 +08006143 mbtk_info_pack_t* pack = mbtk_info_pack_creat(MBTK_INFO_ID_NET_DATA_CALL_REQ);
6144 if(pack == NULL)
6145 {
6146 free(info);
6147 LOG("Packet malloc() fail.");
6148 continue;
6149 }
6150
6151 // "info_err"
6152 //pack->info_err = byte_2_uint16(ptr, false)
6153
6154 // "data_len"
6155 pack->data_len = 5;
6156
6157 char *p = (char *)malloc(5);
6158 p[0] = MBTK_DATA_CALL_START;
6159 p[1] = i;
6160 p[2] = 0;
6161 p[3] = 1;
6162 p[4] = 10;
6163 pack->data = p;
6164 send_pack_to_queue(info, pack);
6165 }
6166 }
6167
6168 bootconn = 1;
6169 }
6170
6171 if(bootconn == 1 && send_sum == 1)
6172 {
6173 break;
6174 }
6175 else
6176 {
6177 sleep(1);
6178 }
6179 }
6180
6181 LOG("data_call_bootconn_pthread exit.");
6182 return NULL;
6183}
6184
6185//mbtk wyq for data_call_ex add end
6186
6187static void* info_main_pthread(void* arg)
6188{
6189 UNUSED(arg);
6190 epoll_fd = epoll_create(SOCK_CLIENT_MAX + 1);
6191 if(epoll_fd < 0)
6192 {
6193 LOG("epoll_create() fail[%d].", errno);
6194 return NULL;
6195 }
6196
6197 uint32 event = EPOLLIN | EPOLLET;
6198 struct epoll_event ev;
6199 ev.data.fd = sock_listen_fd;
6200 ev.events = event; //EPOLLIN | EPOLLERR | EPOLLET;
6201 epoll_ctl(epoll_fd,EPOLL_CTL_ADD,sock_listen_fd,&ev);
6202
6203 int nready = -1;
6204 struct epoll_event epoll_events[EPOLL_LISTEN_MAX];
6205 while(1)
6206 {
6207 nready = epoll_wait(epoll_fd, epoll_events, EPOLL_LISTEN_MAX, -1);
6208 if(nready > 0)
6209 {
6210 sock_client_info_t *cli_info = NULL;
6211 int i;
6212 for(i = 0; i < nready; i++)
6213 {
6214 LOG("fd[%d] event = %x",epoll_events[i].data.fd, epoll_events[i].events);
6215 if(epoll_events[i].events & EPOLLHUP) // Client Close.
6216 {
6217 if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL)
6218 {
6219 cli_close(cli_info);
6220 }
6221 else
6222 {
6223 LOG("Unknown client[fd = %d].", epoll_events[i].data.fd);
6224 }
6225 }
6226 else if(epoll_events[i].events & EPOLLIN)
6227 {
6228 if(epoll_events[i].data.fd == sock_listen_fd) // New clients connected.
6229 {
6230 int client_fd = -1;
6231 while(1)
6232 {
6233 struct sockaddr_in cliaddr;
6234 socklen_t clilen = sizeof(cliaddr);
6235 client_fd = accept(epoll_events[i].data.fd, (struct sockaddr *) &cliaddr, &clilen);
6236 if(client_fd < 0)
6237 {
6238 if(errno == EAGAIN)
6239 {
6240 LOG("All client connect get.");
6241 }
6242 else
6243 {
6244 LOG("accept() error[%d].", errno);
6245 }
6246 break;
6247 }
6248 // Set O_NONBLOCK
6249 int flags = fcntl(client_fd, F_GETFL, 0);
6250 if (flags > 0)
6251 {
6252 flags |= O_NONBLOCK;
6253 if (fcntl(client_fd, F_SETFL, flags) < 0)
6254 {
6255 LOG("Set flags error:%d", errno);
6256 }
6257 }
6258
6259 memset(&ev,0,sizeof(struct epoll_event));
6260 ev.data.fd = client_fd;
6261 ev.events = event;//EPOLLIN | EPOLLERR | EPOLLET;
6262 epoll_ctl(epoll_fd, EPOLL_CTL_ADD, client_fd, &ev);
6263
6264 sock_client_info_t *info = (sock_client_info_t*)malloc(sizeof(sock_client_info_t));
6265 if(info)
6266 {
6267 memset(info, 0, sizeof(sock_client_info_t));
6268 info->fd = client_fd;
6269 if(server_ready_get() == 1)
6270 {
6271 info->ind_num = 0;
6272 pack_rsp_send(info->fd , MBTK_INFO_ID_IND_SERVER_STATE_CHANGE, "1", 1);
6273 LOG("server ready ok.");
6274 }
6275 else
6276 {
6277 info->ind_num = 1;
6278 info->ind_register[0] = MBTK_INFO_ID_IND_SERVER_STATE_CHANGE;
6279 LOG("server ready no.");
6280 }
6281 list_add(sock_client_list, info);
6282 LOG("Add New Client FD Into List.");
6283 }
6284 else
6285 {
6286 LOG("malloc() fail.");
6287 }
6288 }
6289 }
6290 else if((cli_info = cli_find(epoll_events[i].data.fd)) != NULL) // Client data arrive.
6291 {
6292 // Read and process every message.
6293 mbtk_info_err_enum err = MBTK_INFO_ERR_SUCCESS;
6294 mbtk_info_pack_t** pack = mbtk_info_pack_recv(cli_info->fd, true, &err);
6295
6296 // Parse packet error,send error response to client.
6297 if(pack == NULL)
6298 {
6299 if(err != MBTK_INFO_ERR_SUCCESS)
6300 {
6301 pack_error_send(cli_info->fd, MBTK_INFO_ID_REQ_UNKNOWN, err);
6302 }
6303 }
6304 else
6305 {
6306#if 0
6307 int i = 0;
6308 while(pack[i] != NULL)
6309 {
6310 pack_distribute(cli_info, pack[i]);
6311 // Not free,will free in pack_process() or packet process thread.
6312 //mbtk_info_pack_free(&(pack[i]));
6313 i++;
6314 }
6315 free(pack);
6316#else
6317 mbtk_info_pack_t** pack_ptr = pack;
6318 while(*pack_ptr)
6319 {
6320 pack_distribute(cli_info, *pack_ptr);
6321 // Not free,will free in pack_process() or packet process thread.
6322 //mbtk_info_pack_free(pack_ptr);
6323 pack_ptr++;
6324 }
6325
6326 free(pack);
6327#endif
6328 }
6329 }
6330 else
6331 {
6332 LOG("Unknown socket : %d", epoll_events[i].data.fd);
6333 }
6334 }
6335 else
6336 {
6337 LOG("Unknown event : %x", epoll_events[i].events);
6338 }
6339 }
6340 }
6341 else
6342 {
6343 LOG("epoll_wait() fail[%d].", errno);
6344 }
6345 }
6346
6347 return NULL;
6348}
6349
liubin281ac462023-07-19 14:22:54 +08006350/*
6351void mbtk_radio_ready_cb()
6352{
6353 pthread_t radio_pid;
6354 pthread_attr_t thread_attr;
6355 pthread_attr_init(&thread_attr);
6356 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
6357 {
6358 LOG("pthread_attr_setdetachstate() fail.");
6359 return;
6360 }
6361
6362 if(pthread_create(&radio_pid, &thread_attr, radio_ready_thread, NULL))
6363 {
6364 LOG("pthread_create() fail.");
6365 }
6366
6367 pthread_attr_destroy(&thread_attr);
6368}
6369*/
6370
6371static void net_ifc_state_change(bool act, int cid)
6372{
6373 if(cid < MBTK_APN_CID_MIN || cid > MBTK_APN_CID_MAX) { // No nothing for cid 1 and 8
6374 return;
6375 }
6376
yq.wanga9efa822024-07-03 04:33:48 -07006377#if 0
wangyouqiang65884152023-10-25 19:54:15 +08006378 if(act)
6379 {
6380 cid_active[cid] = 1;
wangyouqiang80487e42024-05-24 15:06:20 +08006381 mbtk_set_default_pdp_state(true, cid);
wangyouqiang65884152023-10-25 19:54:15 +08006382 }
6383 else
6384 {
6385 cid_active[cid] = 0;
wangyouqiang80487e42024-05-24 15:06:20 +08006386 mbtk_set_default_pdp_state(false, cid);
wangyouqiang65884152023-10-25 19:54:15 +08006387 }
yq.wanga9efa822024-07-03 04:33:48 -07006388#endif
liubin281ac462023-07-19 14:22:54 +08006389 char dev[20] = {0};
6390 sprintf(dev, "ccinet%d", cid - 1);
6391 if(act) { // Config IP.
6392 // Get IP information.
6393 mbtk_ipv4_info_t ipv4;
6394 mbtk_ipv6_info_t ipv6;
6395 memset(&ipv4, 0, sizeof(mbtk_ipv4_info_t));
6396 memset(&ipv6, 0, sizeof(mbtk_ipv6_info_t));
6397 int cme_err = MBTK_INFO_ERR_CME_NON;
6398 if(!req_data_call_state_get(cid, &ipv4, &ipv6, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON)
6399 {
wangyouqianged88c722023-11-22 16:33:43 +08006400#ifdef MBTK_AF_SUPPORT
6401 if(cid == 1)
6402 {
6403 ipv4.valid = false;
6404 ipv6.valid = false;
6405 if(default_iptype == MBTK_IP_TYPE_IP)
6406 {
6407 ipv4.valid = true;
6408 }
6409 else if(default_iptype == MBTK_IP_TYPE_IPV6)
6410 {
6411 ipv6.valid = true;
6412 }
6413 else
6414 {
6415 ipv4.valid = true;
6416 ipv6.valid = true;
6417 }
6418 }
6419#endif
liubin281ac462023-07-19 14:22:54 +08006420 // Config IPv4 address.
6421 if(ipv4.valid) {
6422 char ip[20] = {0};
6423 if(inet_ntop(AF_INET, &(ipv4.IPAddr), ip, 20) == NULL) {
6424 LOGE("inet_ntop ipv4 ip fail.");
6425 return;
6426 }
6427
6428 if(mbtk_ifc_configure2(dev, ip, 0, NULL, "255.255.255.0")) {
6429 LOGD("Config %s IPv4 %s fail.", dev, ip);
6430 } else {
6431 LOGD("Config %s IPv4 %s success.", dev, ip);
6432 }
6433 }
6434
6435 // Config IPv6 address.
6436 if(ipv6.valid) {
6437 char ip[50] = {0};
6438
6439 if(inet_ntop(AF_INET6, &(ipv6.IPV6Addr), ip, 50) == NULL) {
6440 LOGE("inet_ntop ipv6 ip fail.");
6441 return;
6442 }
6443
6444 if(mbtk_ipv6_config(dev, ip, 64)) {
6445 LOGD("Config %s IPv6 %s fail.", dev, ip);
6446 } else {
6447 LOGD("Config %s IPv6 %s success.", dev, ip);
6448 }
6449 }
yq.wanga9efa822024-07-03 04:33:48 -07006450
6451 mbtk_qser_route_config(cid, &ipv4, &ipv6);
liubin281ac462023-07-19 14:22:54 +08006452 }
6453 } else { // Del IP
6454 if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
6455 LOGD("Config %s IPv4 0 fail.", dev);
6456 } else {
6457 LOGD("Config %s IPv4 0 success.", dev);
6458 }
6459 }
6460}
6461
yq.wanga9efa822024-07-03 04:33:48 -07006462static void data_call_restart()
6463{
6464#if 0
6465 // Waitting for network ok.
6466 mbtk_net_info_t info;
6467 int cme_err;
6468 int i = 0;
6469 while(i < 15) { // 15s timeout
6470 cme_err = MBTK_INFO_ERR_CME_NON;
6471 memset(&info, 0, sizeof(mbtk_net_info_t));
6472 if(!req_net_sel_mode_get(&info, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON)
6473 {
6474 if(info.net_type >= 2) {
6475 break;
6476 }
6477 }
6478
6479 sleep(1);
6480 i++;
6481 }
6482#endif
6483 // +CGACT
6484 int cid;
wangyouqiang3947b302024-07-04 17:26:08 +08006485 uint8 data_pdp = 0;
yq.wanga9efa822024-07-03 04:33:48 -07006486 LOGD("Start active APN.");
6487 at_process = true;
6488 cgact_wait.act = true;
yq.wangd58f71e2024-08-21 23:45:31 -07006489 for(cid = MBTK_APN_CID_MIN; cid <= MBTK_APN_CID_MAX; cid++) {
6490 if(cid_active[cid])
6491 {
6492 LOG("Active cid : %d", cid);
6493 cgact_wait.waitting = true;
6494 cgact_wait.cid = cid;
6495 net_ifc_state_change(false, cid);
6496 data_pdp = cid + 100;
6497 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
6498 req_data_call_start(cid, NULL);
6499 wait_cgact_complete(10);
6500 net_ifc_state_change(true, cid);
6501 data_pdp = cid + 220;
6502 urc_msg_distribute(false, INFO_URC_MSG_PDP_STATE, &data_pdp, sizeof(uint8));
6503 }
yq.wanga9efa822024-07-03 04:33:48 -07006504 }
6505 at_process = false;
6506}
6507
liubin281ac462023-07-19 14:22:54 +08006508static void urc_msg_process(info_urc_msg_t *msg)
6509{
6510 uint8 *data = NULL;
6511 if(msg->data) {
6512 data = (uint8*)msg->data;
6513 }
6514 switch(msg->msg) {
6515 case INFO_URC_MSG_RADIO_STATE:
6516 {
6517 radio_state_change(msg->data, msg->data_len);
6518 // Reconfig APN while radio on.
6519 if(data[0]) {
6520 apn_prop_get();
6521 }
6522 break;
6523 }
6524 case INFO_URC_MSG_CGEV:
6525 {
6526 bool act = data[0];
6527 int cid = data[1];
6528 if(cid > 0) {
6529 net_ifc_state_change(act, cid);
6530 }
6531 break;
6532 }
6533 case INFO_URC_MSG_NET_PS_REG_STATE:
6534 {
b.liufe320632024-01-17 20:38:08 +08006535 uint8 net_data[4];
liubin281ac462023-07-19 14:22:54 +08006536 net_data[0] = (uint8)MBTK_NET_PS_STATE;
b.liufe320632024-01-17 20:38:08 +08006537 net_data[1] = data[0]; // act
6538 net_data[3] = data[1]; // 0 - GSM/WCDMA; 1 - LTE
liubin281ac462023-07-19 14:22:54 +08006539 mbtk_net_reg_state_enum state = (mbtk_net_reg_state_enum)data[0];
6540 if(state == MBTK_NET_REG_STATE_HOME
6541 || state == MBTK_NET_REG_STATE_ROAMING) { // Registered, home network or roaming.
6542 mbtk_net_info_t info;
6543 int cme_err = MBTK_INFO_ERR_CME_NON;
6544 memset(&info, 0, sizeof(mbtk_net_info_t));
6545 if(!req_net_sel_mode_get(&info, &cme_err) && cme_err == MBTK_INFO_ERR_CME_NON)
6546 {
6547 net_data[2] = info.net_type;
6548 net_state_change(net_data, sizeof(net_data));
6549
6550 if(info.net_type >= MBTK_RADIO_TECH_UTRAN) {
6551 data_call_restart();
6552 }
6553 } else {
6554 net_data[2] = (uint8)0xFF;
6555 net_state_change(net_data, sizeof(net_data));
6556 }
6557 } else {
6558 net_data[2] = (uint8)0xFF;
6559 net_state_change(net_data, sizeof(net_data));
6560 }
6561 break;
6562 }
b.liuf37bd332024-03-18 13:51:24 +08006563 case INFO_URC_MSG_SET_BAND:
6564 {
6565 mbtk_band_info_t band;
6566 int cme_err = MBTK_INFO_ERR_CME_NON;
6567
6568 band.net_pref = MBTK_NET_PREF_GSM_UMTS_LTE_LTE_PREF; // 15
b.liu288093c2024-05-09 17:02:57 +08006569 band.gsm_band = (uint16)band_set_info.band_gsm;
6570 band.umts_band = (uint16)band_set_info.band_wcdma;
b.liuf37bd332024-03-18 13:51:24 +08006571 band.tdlte_band = band_set_info.band_tdlte;
6572 band.fddlte_band = band_set_info.band_fddlte;
b.liu288093c2024-05-09 17:02:57 +08006573 band.lte_ext_band = band_set_info.band_lte_ext;
6574
b.liuf37bd332024-03-18 13:51:24 +08006575 if(req_band_set(&band, &cme_err) || cme_err != MBTK_INFO_ERR_CME_NON)
6576 {
6577 LOG("Set band fail.");
6578 }
6579 else // Set band success.
6580 {
b.liu45bfb532024-05-11 15:37:22 +08006581 // log_hex("BAND-2", &band_set_info, sizeof(band_set_info_t));
b.liu288093c2024-05-09 17:02:57 +08006582 band_set_success = TRUE;
6583 if(band_area == MBTK_MODEM_BAND_AREA_CN) {
b.liuf37bd332024-03-18 13:51:24 +08006584 property_set("persist.mbtk.band_config", "CN");
b.liu288093c2024-05-09 17:02:57 +08006585 } else if(band_area == MBTK_MODEM_BAND_AREA_EU) {
b.liuf37bd332024-03-18 13:51:24 +08006586 property_set("persist.mbtk.band_config", "EU");
b.liu288093c2024-05-09 17:02:57 +08006587 } else if(band_area == MBTK_MODEM_BAND_AREA_SA) {
b.liuf678f992024-05-08 15:23:10 +08006588 property_set("persist.mbtk.band_config", "SA");
b.liuf37bd332024-03-18 13:51:24 +08006589 } else {
6590 property_set("persist.mbtk.band_config", "ALL");
6591 }
6592 LOG("Set band success.");
6593 }
6594 break;
6595 }
wangyouqiangce45a102024-04-18 18:08:29 +08006596 case INFO_URC_MSG_GET_SIM_STATE:
6597 {
6598 net_info.sim_state = getSIMStatus();
6599 if(net_info.sim_state == MBTK_SIM_READY)
6600 {
6601 LOG("SIM READY!");
6602 }
6603 else
6604 {
6605 LOG("SIM NOT READY!");
6606 }
6607 break;
6608 }
liubin281ac462023-07-19 14:22:54 +08006609 case INFO_URC_MSG_NET_STATE_LOG:
6610 {
6611 // Get network state and signal.
6612 char buff[256] = {0};
r.xiaofca7c472024-04-24 01:00:23 -07006613 uint8 data_signal[7];
r.xiao9ad82632024-04-24 02:18:13 -07006614 mbtk_signal_info_t signal, tmp_signal;
liubin281ac462023-07-19 14:22:54 +08006615 memset(&signal, 0xFF, sizeof(mbtk_signal_info_t));
6616 if(!req_net_signal_get(&signal, NULL)) {
6617 char tmp[50] = {0};
6618 struct timeval log_time;
6619 gettimeofday(&log_time, NULL);
6620 struct tm* tm_t = localtime(&(log_time.tv_sec));
6621 strftime(tmp, 50, "%F %T", tm_t);
6622 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,
6623 signal.rsrq, signal.rsrp);
6624 mbtk_signal_log(buff);
r.xiao9ad82632024-04-24 02:18:13 -07006625 memset(&tmp_signal, 0xFF, sizeof(mbtk_signal_info_t));
6626 tmp_signal.type = signal.type;
6627 tmp_signal.rssi = signal.rssi;
6628 tmp_signal.rxlev = signal.rxlev;
6629 tmp_signal.ber = signal.ber;
6630 tmp_signal.rscp = signal.rscp;
6631 tmp_signal.ecno = signal.ecno;
6632 tmp_signal.rsrq = signal.rsrq;
6633 tmp_signal.rsrp = signal.rsrp;
r.xiaofca7c472024-04-24 01:00:23 -07006634
r.xiao9ad82632024-04-24 02:18:13 -07006635 if( (signal_globe.type != tmp_signal.type) || (signal_globe.rssi != tmp_signal.rssi) || (signal_globe.rxlev != tmp_signal.rxlev) ||
6636 (signal_globe.ber != tmp_signal.ber) || (signal_globe.rscp != tmp_signal.rscp) || (signal_globe.ecno != tmp_signal.ecno) ||
6637 (signal_globe.rsrq != tmp_signal.rsrq) || (signal_globe.rsrp != tmp_signal.rsrp) )
b.liu288093c2024-05-09 17:02:57 +08006638
r.xiaofca7c472024-04-24 01:00:23 -07006639 {
r.xiao9ad82632024-04-24 02:18:13 -07006640 signal_globe.type = signal.type;
6641 signal_globe.rssi = signal.rssi;
6642 signal_globe.rxlev = signal.rxlev;
6643 signal_globe.ber = signal.ber;
6644 signal_globe.rscp = signal.rscp;
6645 signal_globe.ecno = signal.ecno;
6646 signal_globe.rsrq = signal.rsrq;
6647 signal_globe.rsrp = signal.rsrp;
r.xiaofca7c472024-04-24 01:00:23 -07006648 //ADD SIGANLE CB
6649 data_signal[0] = signal.type;
6650 data_signal[1] = signal.rssi;
6651 data_signal[2] = signal.rxlev;
6652 data_signal[3] = signal.ber;
6653 data_signal[4] = signal.rscp;
6654 data_signal[5] = signal.ecno;
6655 data_signal[6] = signal.rsrq;
6656 data_signal[7] = signal.rsrp;
6657 /*
6658 LOGE("data[0]=%d data[1]=%d data[2]=%d data[3]=%d data[4]=%d data[5]=%d data[6]=%d data[7]=%d",
6659 data_signal[0],data_signal[1],data_signal[2],data_signal[3],data_signal[4],data_signal[5],data_signal[6],data_signal[7]);
6660 */
6661 signal_state_change(data_signal, sizeof(data_signal));
6662 }
liubin281ac462023-07-19 14:22:54 +08006663 }
liubin281ac462023-07-19 14:22:54 +08006664 break;
6665 }
6666 default:
6667 {
6668 LOGE("Unknown URC : %d", msg->msg);
6669 break;
6670 }
6671 }
6672}
6673
6674static void* pack_process_thread(void* arg)
6675{
6676 UNUSED(arg);
6677 info_queue_item_t* item = NULL;
6678 mbtk_queue_init(&info_queue);
6679 pthread_mutex_init(&info_mutex, NULL);
6680 pthread_cond_init(&info_cond, NULL);
6681
6682 memset(&band_support, 0xFF, sizeof(mbtk_band_info_t));
6683
6684 pthread_mutex_lock(&info_mutex);
6685 while(TRUE)
6686 {
6687 if(mbtk_queue_empty(&info_queue))
6688 {
6689 LOG("Packet process wait...");
6690 pthread_cond_wait(&info_cond, &info_mutex);
6691 LOG("Packet process continue...");
6692 }
6693 else
6694 {
6695 LOG("Packet process queue not empty,continue...");
6696 }
6697
6698 // Process all information request.
6699 mbtk_info_err_enum err;
6700 while((item = (info_queue_item_t*)mbtk_queue_get(&info_queue)) != NULL)
6701 {
6702 if(item->cli_info) { // REQ form client.
6703 mbtk_info_pack_t *pack = (mbtk_info_pack_t*)item->pack;
6704 LOG("Process REQ %s.", id2str(pack->info_id));
6705 at_process = true;
6706 err = pack_req_process(item->cli_info, pack);
6707 if(err != MBTK_INFO_ERR_SUCCESS)
6708 {
6709 if(item->cli_info->fd != DATA_CALL_BOOTCONN_FD)
6710 {
6711 pack_error_send(item->cli_info->fd, pack->info_id + 1, err);
6712 }
6713 else
6714 {
wangyouqiang80487e42024-05-24 15:06:20 +08006715 if(pack->data != NULL)
6716 {
6717 free(pack->data);
6718 }
6719 if(item->cli_info)
6720 {
6721 free(item->cli_info);
6722 }
liubin281ac462023-07-19 14:22:54 +08006723 }
6724 }
6725 at_process = false;
6726 mbtk_info_pack_free(&pack);
6727 free(item);
6728 } else { // REQ from myself.
6729 info_urc_msg_t *urc = (info_urc_msg_t*)item->pack;
6730 LOG("Process URC %d.", urc->msg);
6731 urc_msg_process(urc);
6732 if(!urc->data)
6733 free(urc->data);
6734 free(urc);
6735 }
6736 }
6737 }
6738 pthread_mutex_unlock(&info_mutex);
6739 return NULL;
6740}
6741
6742void apn_prop_get()
6743{
6744 char prop_name[20];
6745 char prop_data[300];
6746 // cid : 2 - 7
6747 int cid = MBTK_APN_CID_MIN;
6748 mbtk_apn_info_t apn;
6749 for(; cid <= MBTK_APN_CID_MAX; cid++) {
6750 memset(prop_name, 0, 20);
6751 memset(prop_data, 0, 300);
6752 memset(&apn, 0, sizeof(mbtk_apn_info_t));
6753 sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid);
6754 if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) {
6755 apn.cid = cid;
6756 char *ptr_1 = prop_data;
6757 apn.ip_type = (mbtk_ip_type_enum)atoi(ptr_1);
6758 ptr_1 = strstr(ptr_1, ",");
6759 if(!ptr_1) {
6760 continue;
6761 }
6762 ptr_1++; // Jump ',' to apn
6763
6764 char *ptr_2 = strstr(ptr_1, ",");
6765 if(!ptr_2) {
6766 continue;
6767 }
6768 memcpy(apn.apn, ptr_1, ptr_2 - ptr_1); // apn
6769
6770 ptr_2++; // Jump ',' to user
6771 ptr_1 = strstr(ptr_2, ",");
6772 if(!ptr_1) {
6773 continue;
6774 }
6775 if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
6776 memcpy(apn.user, ptr_2, ptr_1 - ptr_2); // user
6777 }
6778
6779 ptr_1++; // Jump ',' to pass
6780 ptr_2 = strstr(ptr_1, ",");
6781 if(!ptr_2) {
6782 continue;
6783 }
6784 if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
6785 memcpy(apn.pass, ptr_1, ptr_2 - ptr_1); // pass
6786 }
6787
6788 ptr_2++; // Jump ',' to auth (Is last item)
6789 if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
6790 memcpy(apn.auth, ptr_2, strlen(ptr_2)); // auth
6791 }
6792
6793 req_apn_set(&apn, NULL);
6794 }
6795 }
6796}
6797
6798/*
b.liue0ab2442024-02-06 18:53:28 +08006799root@OpenWrt:/usrdata# cat /proc/mtd
6800dev: size erasesize name
6801mtd0: 00040000 00020000 "bootloader"
6802mtd1: 00020000 00020000 "cp_reliabledata"
6803mtd2: 00020000 00020000 "ap_reliabledata"
6804mtd3: 00020000 00020000 "cp_reliabledata_backup"
6805mtd4: 00020000 00020000 "ap_reliabledata_backup"
6806mtd5: 00020000 00020000 "mep-ota"
6807mtd6: 00020000 00020000 "mep-ota_backup"
6808mtd7: 00040000 00020000 "dtim"
6809mtd8: 00f40000 00020000 "cpimage"
6810mtd9: 000c0000 00020000 "u-boot"
6811mtd10: 00500000 00020000 "kernel"
6812mtd11: 00100000 00020000 "asr_flag"
6813mtd12: 01400000 00020000 "rootfs"
6814mtd13: 01400000 00020000 "oem_data"
6815mtd14: 01e00000 00020000 "OTA"
6816mtd15: 01400000 00020000 "rootfs_data"
6817mtd16: 081a0000 00020000 "user_data"
6818mtd17: 00d20000 00020000 "MRVL_BBM"
6819*/
6820static int partition_name_2_dev(const char *name, char *dev) {
6821 if(name == NULL || dev == NULL) {
6822 LOGE("ARG error.");
6823 return -1;
6824 }
6825
6826 int fp = fopen("/proc/mtd", "r");
6827 if (fp == NULL) {
6828 LOGE("Open MTD failed!");
6829 return -1;
6830 }
6831
6832 char buf[1024];
6833 while (fgets(buf, 1024, fp) != NULL) {
6834 if(strstr(buf, name)) {
6835 int index = atoi(buf + 3);
6836 sprintf(dev, "/dev/mtdblock%d", index);
6837 LOGD("%s -> %s", name, dev);
6838 return 0;
6839 }
6840 }
6841
6842 return -1;
6843}
6844
6845static int custom_partition_read(const char *name, mbtk_cust_info_t *cust_info)
6846{
6847 int fd = 0, ret = 0;
6848 unsigned int step = 0, offset = 0, flaglen = 0;
6849 flaglen = sizeof(mbtk_cust_info_t);
6850
6851 char mtd_path[50] = {0};
6852 if(partition_name_2_dev(name, mtd_path)) {
6853 LOGE("partition_name_2_dev() failed!");
6854 return -1;
6855 }
6856
6857 fd = open(mtd_path, O_RDONLY);
6858 if (fd < 0) {
6859 LOGE("Fatal error: can't open cust info %s\n", mtd_path);
6860 return -1;
6861 }
6862
6863 if (read(fd, cust_info, flaglen) < 0)
6864 goto error;
6865 if (cust_info->header != CUST_INFO_HEADER) {
6866 LOGE("Cust info partition error.");
6867 goto error;
6868 } else {
6869 if(cust_info->band_type == 1) { // CN
6870 LOGD("Band : CN");
6871 } else if(cust_info->band_type == 2) { // EU
6872 LOGD("Band : EU");
6873 } else {
6874 LOGE("Unknown band type:%d", cust_info->band_type);
6875 goto error;
6876 }
6877 }
6878 close(fd);
6879 return 0;
6880error:
6881 close(fd);
6882 return -1;
6883}
6884
6885/*
liubin281ac462023-07-19 14:22:54 +08006886AT*BAND=15,78,147,482,134742231
6887
6888OK
6889*/
b.liubb5e7682024-02-28 20:13:04 +08006890static void* band_config_thread()
liubin281ac462023-07-19 14:22:54 +08006891{
b.liubb5e7682024-02-28 20:13:04 +08006892 mbtk_device_info_modem_t info_modem;
b.liuf37bd332024-03-18 13:51:24 +08006893 memset(&band_set_info, 0, sizeof(band_set_info_t));
b.liubb5e7682024-02-28 20:13:04 +08006894 memset(&info_modem, 0, sizeof(mbtk_device_info_modem_t));
b.liu288093c2024-05-09 17:02:57 +08006895 band_set_success = FALSE;
b.liuf37bd332024-03-18 13:51:24 +08006896 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 +08006897 LOGD("mbtk_dev_info_read(MODEM) fail, use default band.");
b.liu288093c2024-05-09 17:02:57 +08006898 band_area = MBTK_MODEM_BAND_AREA_ALL;
b.liuf37bd332024-03-18 13:51:24 +08006899 band_set_info.band_gsm = MBTK_BAND_ALL_GSM_DEFAULT;
6900 band_set_info.band_wcdma = MBTK_BAND_ALL_WCDMA_DEFAULT;
6901 band_set_info.band_tdlte = MBTK_BAND_ALL_TDLTE_DEFAULT;
6902 band_set_info.band_fddlte = MBTK_BAND_ALL_FDDLTE_DEFAULT;
b.liu288093c2024-05-09 17:02:57 +08006903 band_set_info.band_lte_ext = MBTK_BAND_ALL_EXT_LTE_DEFAULT;
b.liubb5e7682024-02-28 20:13:04 +08006904 } else {
b.liu288093c2024-05-09 17:02:57 +08006905 band_area = info_modem.band_area;
b.liuf37bd332024-03-18 13:51:24 +08006906 band_set_info.band_gsm = info_modem.band_gsm;
6907 band_set_info.band_wcdma = info_modem.band_wcdma;
6908 band_set_info.band_tdlte = info_modem.band_tdlte;
6909 band_set_info.band_fddlte = info_modem.band_fddlte;
b.liuf678f992024-05-08 15:23:10 +08006910 band_set_info.band_lte_ext = info_modem.band_lte_ext;
b.liuf37bd332024-03-18 13:51:24 +08006911 }
b.liubb5e7682024-02-28 20:13:04 +08006912
b.liuf37bd332024-03-18 13:51:24 +08006913 bool is_first = TRUE;
b.liu288093c2024-05-09 17:02:57 +08006914 while(!band_set_success) {
b.liuf37bd332024-03-18 13:51:24 +08006915 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
6916 if(!urc)
6917 {
6918 LOG("malloc() fail[%d].", errno);
6919 break;
b.liubb5e7682024-02-28 20:13:04 +08006920 } else {
b.liuf37bd332024-03-18 13:51:24 +08006921 urc->msg = INFO_URC_MSG_SET_BAND;
6922 urc->data = NULL;
6923 urc->data_len = 0;
6924 send_pack_to_queue(NULL, urc);
6925
6926 if(is_first) {
6927 is_first = FALSE;
6928 } else {
b.liu288093c2024-05-09 17:02:57 +08006929 LOGE("*BAND exec error, will retry in 5s.");
b.liuf37bd332024-03-18 13:51:24 +08006930 }
b.liu288093c2024-05-09 17:02:57 +08006931 sleep(5);
b.liubb5e7682024-02-28 20:13:04 +08006932 }
6933 }
6934
b.liuf37bd332024-03-18 13:51:24 +08006935 LOGD("Set Band thread exit.");
b.liubb5e7682024-02-28 20:13:04 +08006936 return NULL;
liubin281ac462023-07-19 14:22:54 +08006937}
6938
6939static void* net_monitor_thread(void* arg)
6940{
6941 UNUSED(arg);
6942 // Start network monitor
6943 int cid;
6944 while(1) {
6945#if 0
6946 // Config IP
6947 list_node_t* apn_list = NULL;
6948 if(!apn_state_get(&apn_list) && apn_list != NULL) {
6949 info_apn_ip_t *apn = NULL;
6950 for(cid = MBTK_APN_CID_MIN; cid <= MBTK_APN_CID_MAX && cid_active[cid]; cid++) {
6951 bool ip_found = false;
6952 list_first(apn_list);
6953 while ((apn = (info_apn_ip_t*) list_next(apn_list))) {
6954 if(cid == apn->cid) {
6955 ip_found = true;
6956 break;
6957 }
6958 }
6959
6960 char dev[20] = {0};
6961 sprintf(dev, "ccinet%d", cid - 1);
6962 if(ip_found) { // Ip ok,set IP.
6963 if(apn->ipv4_valid) {
6964 if(mbtk_ifc_configure2(dev, (char*)apn->ipv4, 0, NULL, "255.255.255.0")) {
6965 LOGD("Config %s IPv4 %s fail.", dev, apn->ipv4);
6966 } else {
6967 LOGD("Config %s IPv4 %s success.", dev, apn->ipv4);
6968 }
6969 }
6970
6971 if(apn->ipv6_valid) {
6972 if(mbtk_ipv6_config(dev, (char*)apn->ipv6, 64)) {
6973 LOGD("Config %s IPv6 %s fail.", dev, apn->ipv6);
6974 } else {
6975 LOGD("Config %s IPv6 %s success.", dev, apn->ipv6);
6976 }
6977 }
6978 } else { // No ip
6979 if(mbtk_ifc_configure2(dev, NULL, 0, NULL, NULL)) {
6980 LOGD("Config %s IPv4 0 fail.", dev);
6981 } else {
6982 LOGD("Config %s IPv4 0 success.", dev);
6983 }
6984 }
6985 }
6986
6987 list_free(apn_list);
6988 }
6989#endif
6990
6991 if(net_info.radio_state == MBTK_RADIO_STATE_ON && net_info.sim_state == MBTK_SIM_READY) {
6992#if 0
6993 urc_msg_distribute(true, INFO_URC_MSG_NET_CS_REG_STATE, NULL, 0);
6994#else
6995 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
6996 if(!urc)
6997 {
6998 LOG("malloc() fail[%d].", errno);
6999 } else {
7000 urc->msg = INFO_URC_MSG_NET_STATE_LOG;
7001 urc->data = NULL;
7002 urc->data_len = 0;
7003 send_pack_to_queue(NULL, urc);
7004 }
7005#endif
wangyouqiangce45a102024-04-18 18:08:29 +08007006 sleep(15);
liubin281ac462023-07-19 14:22:54 +08007007 }
wangyouqiangce45a102024-04-18 18:08:29 +08007008 else
7009 {
7010 info_urc_msg_t *urc = (info_urc_msg_t*)malloc(sizeof(info_urc_msg_t));
7011 if(!urc)
7012 {
7013 LOG("malloc() fail[%d].", errno);
7014 }
7015 else
7016 {
7017 urc->msg = INFO_URC_MSG_GET_SIM_STATE;
7018 urc->data = NULL;
7019 urc->data_len = 0;
7020 send_pack_to_queue(NULL, urc);
7021 }
7022 sleep(2);
7023 }
liubin281ac462023-07-19 14:22:54 +08007024 }
7025
7026 LOGD("monitor_thread exit.");
7027 return NULL;
7028}
7029
7030static void* urc_process_thread(void* arg)
7031{
7032 UNUSED(arg);
7033 info_urc_msg_t* item = NULL;
7034 mbtk_queue_init(&urc_queue);
7035 pthread_mutex_init(&urc_mutex, NULL);
7036 pthread_cond_init(&urc_cond, NULL);
7037
7038 pthread_mutex_lock(&urc_mutex);
7039 while(TRUE)
7040 {
7041 if(mbtk_queue_empty(&urc_queue))
7042 {
7043 LOG("URC process wait...");
7044 pthread_cond_wait(&urc_cond, &urc_mutex);
7045 LOG("URC process continue...");
7046 }
7047 else
7048 {
7049 LOG("URC process queue not empty,continue...");
7050 }
7051
7052 // Process all information request.
7053 while((item = (info_urc_msg_t*)mbtk_queue_get(&urc_queue)) != NULL)
7054 {
7055 LOG("Process URC %d.", item->msg);
7056 uint8 *data = (uint8*)item->data;
7057 switch(item->msg) {
7058 case INFO_URC_MSG_RADIO_STATE:
7059 {
7060 radio_state_change(item->data, item->data_len);
7061 break;
7062 }
7063 case INFO_URC_MSG_CGEV:
7064 {
7065 bool act = data[0];
7066 int cid = data[1];
7067 if(cid > 0) {
7068 net_ifc_state_change(act, cid);
7069 }
7070 break;
7071 }
7072 default:
7073 {
7074 LOGE("Unknown URC : %d", item->msg);
7075 break;
7076 }
7077 }
7078 if(!item->data)
7079 free(item->data);
7080 free(item);
7081 }
7082 }
7083 pthread_mutex_unlock(&urc_mutex);
7084
7085 return NULL;
7086}
7087
7088static void ril_at_ready_process()
7089{
7090 net_info.radio_state = (isRadioOn() == 1) ? MBTK_RADIO_STATE_ON : MBTK_RADIO_STATE_OFF;
7091#if 1
7092 if (net_info.radio_state != MBTK_RADIO_STATE_ON)
7093 {
7094 setRadioPower(1);
7095 } else { // Radio has ON
7096 apn_prop_get();
7097 }
7098
7099 if(net_info.radio_state == MBTK_RADIO_STATE_ON)
7100 {
7101 at_send_command("AT+CEREG=2", NULL);
7102 }
7103
7104 int count = 0;
7105#endif
7106 net_info.sim_state = getSIMStatus();
7107#if 0
7108 while (net_info.sim_state != MBTK_SIM_READY && count < 30)
7109 {
7110 if(net_info.radio_state != MBTK_RADIO_STATE_ON)
7111 {
7112 setRadioPower(1);
7113 }
7114 LOGD("Waitting for SIM READY...");
7115 sleep(1);
7116 net_info.sim_state = getSIMStatus();
7117 count++;
7118 }
7119#endif
7120 if(net_info.sim_state == MBTK_SIM_READY)
7121 {
7122 LOGD("SIM READY!");
r.xiao7c62bc62024-05-24 00:53:30 -07007123 at_send_command("AT+COPS=3", NULL);
liubin281ac462023-07-19 14:22:54 +08007124 }
7125 else
7126 {
7127 LOGE("SIM NOT READY!");
7128 }
liubin281ac462023-07-19 14:22:54 +08007129}
7130
wangyouqiang80487e42024-05-24 15:06:20 +08007131int mbtk_get_apn_send_pack(void)
7132{
7133 sock_client_info_t *info = (sock_client_info_t*)malloc(sizeof(sock_client_info_t));
7134 if(info == NULL)
7135 {
7136 LOG("clinent_info malloc() fail.");
7137 return -1;
7138 }
7139 memset(info, 0, sizeof(sock_client_info_t));
7140 info->fd = DATA_CALL_APN_GET_FD;
7141
7142 mbtk_info_pack_t* pack = mbtk_info_pack_creat(MBTK_INFO_ID_NET_QSER_APN_REQ);
7143 if(pack == NULL)
7144 {
7145 free(info);
7146 LOG("Packet malloc() fail.");
7147 return -1;
7148 }
7149
7150 send_pack_to_queue(info, pack);
7151 return 0;
7152}
7153
liubin281ac462023-07-19 14:22:54 +08007154int mbtk_info_server_start()
7155{
7156 signal(SIGPIPE, SIG_IGN);
7157
wangyouqiangce45a102024-04-18 18:08:29 +08007158 //check cfun and sim card status
7159 ril_at_ready_process();
7160
7161 //any AT instruction that is not sent through pack_process_thread needs to precede the thread
7162 //thread create
liubin281ac462023-07-19 14:22:54 +08007163 if(sock_listen_fd > 0)
7164 {
7165 LOG("Information Server Has Started.");
7166 return -1;
7167 }
7168
7169 struct sockaddr_un server_addr;
7170 sock_listen_fd = socket(AF_LOCAL, SOCK_STREAM, 0);
7171 if(sock_listen_fd < 0)
7172 {
7173 LOG("socket() fail[%d].", errno);
7174 return -1;
7175 }
7176
7177 // Set O_NONBLOCK
7178 int flags = fcntl(sock_listen_fd, F_GETFL, 0);
7179 if (flags < 0)
7180 {
7181 LOG("Get flags error:%d", errno);
7182 goto error;
7183 }
7184 flags |= O_NONBLOCK;
7185 if (fcntl(sock_listen_fd, F_SETFL, flags) < 0)
7186 {
7187 LOG("Set flags error:%d", errno);
7188 goto error;
7189 }
7190
7191 unlink(SOCK_INFO_PATH);
7192 memset(&server_addr, 0, sizeof(struct sockaddr_un));
7193 server_addr.sun_family = AF_LOCAL;
7194 strcpy(server_addr.sun_path, SOCK_INFO_PATH);
7195 if(bind(sock_listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)))
7196 {
7197 LOG("bind() fail[%d].", errno);
7198 goto error;
7199 }
7200
7201 if(listen(sock_listen_fd, SOCK_CLIENT_MAX))
7202 {
7203 LOG("listen() fail[%d].", errno);
7204 goto error;
7205 }
7206
7207 sock_client_list = list_create(sock_cli_free_func);
7208 if(sock_client_list == NULL)
7209 {
7210 LOG("list_create() fail.");
7211 goto error;
7212 }
7213
7214 pthread_t info_pid, pack_pid, monitor_pid, urc_pid, bootconn_pid;
7215 pthread_attr_t thread_attr;
7216 pthread_attr_init(&thread_attr);
7217 if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED))
7218 {
7219 LOG("pthread_attr_setdetachstate() fail.");
7220 goto error;
7221 }
7222
7223 if(pthread_create(&info_pid, &thread_attr, info_main_pthread, NULL))
7224 {
7225 LOG("pthread_create() fail.");
7226 goto error;
7227 }
7228
7229 if(pthread_create(&pack_pid, &thread_attr, pack_process_thread, NULL))
7230 {
7231 LOG("pthread_create() fail.");
7232 goto error;
7233 }
7234
7235#if 0
7236 if(pthread_create(&urc_pid, &thread_attr, urc_process_thread, NULL))
7237 {
7238 LOG("pthread_create() fail.");
7239 goto error;
7240 }
7241#endif
7242
b.liubb5e7682024-02-28 20:13:04 +08007243 // Set Band
7244 // AT*BAND=15,78,147,482,134742231
7245 char buff[10];
7246 memset(buff, 0, 10);
7247 property_get("persist.mbtk.band_config", buff, "");
7248 if(strlen(buff) == 0) {
7249 pthread_t band_pid;
7250 if(pthread_create(&band_pid, &thread_attr, band_config_thread, NULL))
7251 {
7252 LOG("pthread_create() fail.");
7253 }
7254 }
7255
b.liuf1ab8152024-05-23 13:16:07 +08007256#if 0
liubin281ac462023-07-19 14:22:54 +08007257 if(pthread_create(&monitor_pid, &thread_attr, net_monitor_thread, NULL))
7258 {
7259 LOG("pthread_create() fail.");
7260 }
b.liuf1ab8152024-05-23 13:16:07 +08007261#endif
liubin281ac462023-07-19 14:22:54 +08007262
7263 //mbtk wyq for data_call_ex add start
7264 if(pthread_create(&bootconn_pid, &thread_attr, data_call_bootconn_pthread, NULL))
7265 {
7266 LOG("pthread_create() fail.");
7267 }
7268 //mbtk wyq for data_call_ex add end
7269
7270 pthread_attr_destroy(&thread_attr);
7271
wangyouqiang80487e42024-05-24 15:06:20 +08007272 mbtk_qser_apn_init();
7273
liubin281ac462023-07-19 14:22:54 +08007274 LOG("MBTK Information Server Start...");
7275
7276 return 0;
7277
7278error:
7279 close(sock_listen_fd);
7280 sock_listen_fd = -1;
7281 return -1;
7282}
7283
7284#if 0
7285int main(int argc, char *argv[])
7286{
7287 if(mbtk_info_server_start())
7288 {
7289 return -1;
7290 }
7291
7292 while(1)
7293 {
7294 sleep(24 * 60 * 60);
7295 }
7296
7297 return 0;
7298}
7299#endif
7300
7301