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