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