blob: 6e0cd8c5113efb6ef82cf296b4cef3824fe95a8d [file] [log] [blame]
b.liu87afc4c2024-08-14 17:33:45 +08001#include <stdio.h>
2#include <stdlib.h>
3#include <unistd.h>
4#include <errno.h>
5#include <sys/socket.h>
6#include <sys/un.h>
7#include <netinet/in.h>
8#include <pthread.h>
9#include <sys/epoll.h>
10#include <fcntl.h>
11#include <signal.h>
12#include <cutils/properties.h>
13#include <arpa/inet.h>
14
15#include "mbtk_type.h"
16#include "mbtk_ril.h"
17#include "atchannel.h"
18#include "at_tok.h"
19#include "mbtk_utils.h"
20#include "ril_info.h"
21#include "mbtk_str.h"
22
b.liub4772072024-08-15 14:47:03 +080023mbtk_cell_pack_info_t cell_info;
24
b.liu87afc4c2024-08-14 17:33:45 +080025extern ril_band_info_t band_info;
26void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len);
27static int req_apn_get(mbtk_apn_info_array_t *apns, int *cme_err);
28static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err);
29static void apn_prop_get(ril_apn_info_array_t *apns);
30
31void apn_auto_conf_from_prop()
32{
33 ril_apn_info_array_t apns;
34 int i = 0;
35 memset(&apns, 0, sizeof(ril_apn_info_array_t));
36 apn_prop_get(&apns);
37 while(i < apns.num) {
38 int cme_err = MBTK_RIL_ERR_CME_NON;
39 if(req_apn_set(&(apns.apns[i]), &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
40 {
41 LOGD("Set APN fail.");
42 }
43 else
44 {
45 LOGD("Set APN - %d success.", apns.apns[i].cid);
46 }
47 i++;
48 }
49}
50
51static bool apn_conf_support(mbtk_ril_cid_enum cid)
52{
53 if(cid == MBTK_RIL_CID_DEF) {
54 /*
55 uci show wan_default.default.enable
56 wan_default.default.enable='1'
57
58 uci get wan_default.default.enable
59 1
60 */
61 char buff[128] = {0};
62 if(mbtk_cmd_line("uci get wan_default.default.enable", buff, sizeof(buff)) && strlen(buff) > 0) {
63 return buff[0] == '1' ? FALSE : TRUE;
64 }
65 }
66 return TRUE;
67}
68
69static int apn_cid_reset(mbtk_apn_info_t *apn)
70{
71 // Delete apn
72 if(str_empty(apn->apn)) {
73 if(apn->cid == MBTK_RIL_CID_NUL)
74 return -1;
75
76 if(!apn_conf_support(MBTK_RIL_CID_DEF) && apn->cid == MBTK_RIL_CID_DEF)
77 return -1;
78
79 mbtk_apn_info_array_t apns;
80 int cme_err = MBTK_RIL_ERR_CME_NON;
81 memset(&apns, 0, sizeof(mbtk_apn_info_array_t));
82 if(req_apn_get(&apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
83 {
84 LOGW("Get APN fail.");
85 return 0;
86 }
87 else
88 {
89 int index = 0;
90 while(index < apns.num) {
91 if(apns.apns[index].cid == apn->cid)
92 return 0;
93 index++;
94 }
95 return -1;
96 }
97 } else {
98 if(apn->cid == MBTK_RIL_CID_NUL) {
99 int start_cid;
100 bool asr_auto_call_open = !apn_conf_support(MBTK_RIL_CID_DEF);
101 mbtk_apn_info_array_t apns;
102 int cme_err = MBTK_RIL_ERR_CME_NON;
103 if(asr_auto_call_open) {
104 start_cid = MBTK_RIL_CID_2;
105 } else {
106 start_cid = MBTK_APN_CID_MIN;
107 }
108 memset(&apns, 0, sizeof(mbtk_apn_info_array_t));
109 if(req_apn_get(&apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
110 {
111 LOGW("Get APN fail.");
112 apn->cid = start_cid;
113 }
114 else
115 {
116 for(; start_cid <= MBTK_APN_CID_MAX; start_cid++) {
117 int index = 0;
118 while(index < apns.num) {
119 if(apns.apns[index].cid == start_cid)
120 break;
121 index++;
122 }
123
124 if(index == apns.num) { // Found not used cid : start_cid.
125 LOGD("Change CID : %d -> %d", apn->cid, start_cid);
126 apn->cid = start_cid;
127 return 0;
128 }
129 }
130
131 if(start_cid > MBTK_APN_CID_MAX) {
132 LOGE("APN full.");
133 return -1;
134 }
135 }
136 }
137 }
138 return 0;
139}
140
141static void apn_prop_get(ril_apn_info_array_t *apns)
142{
143 char prop_name[20] = {0};
144 char prop_data[300] = {0};
145 int cid;
146 memset(apns, 0, sizeof(ril_apn_info_array_t));
147 bool asr_auto_call_open = !apn_conf_support(MBTK_RIL_CID_DEF);
148
149 // If auto data call is open,the default route is CID 1.
150 if(asr_auto_call_open) {
151 apns->cid_for_def_route = MBTK_RIL_CID_DEF;
152 cid = MBTK_RIL_CID_2;
153 } else {
154 if(property_get(MBTK_DEF_ROUTE_CID, prop_data, "") > 0 && !str_empty(prop_data)) {
155 apns->cid_for_def_route = (mbtk_ril_cid_enum)atoi(prop_data);
156 }
157 cid = MBTK_APN_CID_MIN;
158 }
159 for(; cid <= MBTK_APN_CID_MAX; cid++) {
160 memset(prop_name, 0, 20);
161 memset(prop_data, 0, 300);
162
163 sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid);
164 // ip_type,auth,auto_data_call,apn,user,pass
165 if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) {
166 apns->apns[apns->num].cid = (mbtk_ril_cid_enum)cid;
167 char *ptr_1 = prop_data;
168 apns->apns[apns->num].ip_type = (mbtk_ip_type_enum)atoi(ptr_1);
169 ptr_1 = strstr(ptr_1, ",");
170 if(!ptr_1) {
171 continue;
172 }
173 ptr_1++; // Jump ',' to auth
174
175 apns->apns[apns->num].auth = (mbtk_apn_auth_type_enum)atoi(ptr_1);
176 ptr_1 = strstr(ptr_1, ",");
177 if(!ptr_1) {
178 continue;
179 }
180 ptr_1++; // Jump ',' to auto_data_call
181
182 apns->apns[apns->num].auto_boot_call = (uint8)atoi(ptr_1);
183 ptr_1 = strstr(ptr_1, ",");
184 if(!ptr_1) {
185 continue;
186 }
187 ptr_1++; // Jump ',' to apn
188
189 char *ptr_2 = strstr(ptr_1, ",");
190 if(!ptr_2) {
191 continue;
192 }
193 if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
194 memcpy(apns->apns[apns->num].apn, ptr_1, ptr_2 - ptr_1); // apn
195 }
196
197 ptr_2++; // Jump ',' to user
198 ptr_1 = strstr(ptr_2, ",");
199 if(!ptr_1) {
200 continue;
201 }
202 if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
203 memcpy(apns->apns[apns->num].user, ptr_2, ptr_1 - ptr_2); // user
204 }
205
206 ptr_1++; // Jump ',' to pass
207 if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
208 memcpy(apns->apns[apns->num].pass, ptr_1, strlen(ptr_1)); // pass
209 }
210
211 apns->num++;
212 }
213 }
214}
215
216static int apn_prop_get_by_cid(mbtk_ril_cid_enum cid, mbtk_apn_info_t *apn)
217{
218 char prop_name[20] = {0};
219 char prop_data[300] = {0};
220 memset(apn, 0, sizeof(mbtk_apn_info_t));
221
222 sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid);
223 // ip_type,auth,auto_data_call,apn,user,pass
224 if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) {
225 apn->cid = cid;
226 apn->auto_save = (uint8)1;
227 char *ptr_1 = prop_data;
228 apn->ip_type = (mbtk_ip_type_enum)atoi(ptr_1);
229 ptr_1 = strstr(ptr_1, ",");
230 if(!ptr_1) {
231 return -1;
232 }
233 ptr_1++; // Jump ',' to auth
234
235 apn->auth = (mbtk_apn_auth_type_enum)atoi(ptr_1);
236 ptr_1 = strstr(ptr_1, ",");
237 if(!ptr_1) {
238 return -1;
239 }
240 ptr_1++; // Jump ',' to auto_data_call
241
242 apn->auto_boot_call = (uint8)atoi(ptr_1);
243 ptr_1 = strstr(ptr_1, ",");
244 if(!ptr_1) {
245 return -1;
246 }
247 ptr_1++; // Jump ',' to apn
248
249 char *ptr_2 = strstr(ptr_1, ",");
250 if(!ptr_2) {
251 return -1;
252 }
253 if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
254 memcpy(apn->apn, ptr_1, ptr_2 - ptr_1); // apn
255 }
256
257 ptr_2++; // Jump ',' to user
258 ptr_1 = strstr(ptr_2, ",");
259 if(!ptr_1) {
260 return -1;
261 }
262 if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL"
263 memcpy(apn->user, ptr_2, ptr_1 - ptr_2); // user
264 }
265
266 ptr_1++; // Jump ',' to pass
267 if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL"
268 memcpy(apn->pass, ptr_1, strlen(ptr_1)); // pass
269 }
270 return 0;
271 }
272 return -1;
273}
274
275static int apn_prop_set(mbtk_apn_info_t *apn)
276{
277 char prop_name[20] = {0};
278 char prop_data[300] = {0};
279 int ret = -1;
280 if(apn->auto_save) {
281 sprintf(prop_name, "%s_%d", MBTK_APN_PROP, apn->cid);
282 // Delete apn
283 if(!str_empty(apn->apn)) {
284 snprintf(prop_data, 300, "%d,%d,%d,%s,%s,%s", apn->ip_type, apn->auth, apn->auto_boot_call,
285 apn->apn,
286 str_empty(apn->user) ? "NULL" : apn->user,
287 str_empty(apn->pass) ? "NULL" : apn->pass);
288 }
289
290 ret = property_set(prop_name, prop_data);
291 }
292
293 if(apn->def_route) {
294 memset(prop_data, 0, sizeof(prop_data));
295 prop_data[0] = '0' + apn->cid;
296 ret = property_set(MBTK_DEF_ROUTE_CID, prop_data);
297 }
298 return ret;
299}
300
301static int apn_prop_reset(mbtk_data_call_info_t *data_info)
302{
303 mbtk_apn_info_t apn;
304 if(apn_prop_get_by_cid(data_info->cid, &apn)) {
305 return -1;
306 } else {
307 apn.auto_boot_call = data_info->auto_boot_call;
308 apn.def_route = data_info->def_route;
309 return apn_prop_set(&apn);
310 }
311}
312
313
314/*
315AT+COPS=?
316
317+COPS: (2, "CHN-CT", "CT", "46011", 7),(3, "CHN-UNICOM", "UNICOM", "46001", 7),(3, "CHINA MOBILE", "CMCC", "46000", 0),(3, "CHINA MOBILE", "CMCC", "46000", 7),(3, "China Broadnet", "CBN", "46015", 7),,(0,1,2,3,4),(0,1,2)
318
319OK
320*/
321static int req_available_net_get(mbtk_net_info_array_t* nets, int *cme_err)
322{
323 ATResponse *response = NULL;
324 int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response);
325
326 if (err < 0 || response->success == 0 || !response->p_intermediates){
327 if(cme_err) {
328 *cme_err = at_get_cme_error(response);
329 }
330 goto exit;
331 }
332 char *line_ptr = response->p_intermediates->line;
333 if(line_ptr == NULL) {
334 LOG("line is NULL");
335 err = -1;
336 goto exit;
337 }
338 //LOG("Line:%s",line_ptr);
339 line_ptr = strstr(line_ptr, "(");
340 while(line_ptr) {
341 line_ptr++;
342 // Only for available/current net.
343 if(*line_ptr == '1' || *line_ptr == '2' || *line_ptr == '3') {
344 nets->net_info[nets->num].net_state = (uint8)atoi(line_ptr); // net_state
345
346 line_ptr = strstr(line_ptr, ",");
347 if(line_ptr == NULL) {
348 err = -1;
349 goto exit;
350 }
351 line_ptr++;
352
353 line_ptr = strstr(line_ptr, ",");
354 if(line_ptr == NULL) {
355 err = -1;
356 goto exit;
357 }
358 line_ptr++;
359
360 line_ptr = strstr(line_ptr, ",");
361 if(line_ptr == NULL) {
362 err = -1;
363 goto exit;
364 }
365
366 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"'))
367 line_ptr++;
368
369 // set sel_mode to 0
370 nets->net_info[nets->num].net_sel_mode = (uint8)0;
371 // Point to "46000"
372 //LOG("PLMN:%s",line_ptr);
373 //sleep(1);
374 //uint32_2_byte((uint32)atoi(line_ptr), buff_ptr + 3, false); // plmn
375 nets->net_info[nets->num].plmn = (uint32)atoi(line_ptr);
376
377 line_ptr = strstr(line_ptr, ",");
378 if(line_ptr == NULL) {
379 err = -1;
380 goto exit;
381 }
382
383 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' '))
384 line_ptr++;
385
386 // Point to "7"
387 if(*line_ptr == '\0') {
388 err = -1;
389 goto exit;
390 }
391 //LOG("Type:%s",line_ptr);
392 //sleep(1);
393 nets->net_info[nets->num].net_type = (uint8)atoi(line_ptr); // net_type
394
395 nets->num++;
396 }
397
398 line_ptr = strstr(line_ptr, "(");
399 }
400exit:
401 at_response_free(response);
402 return err;
403}
404
405/*
406AT+COPS?
407+COPS: 1
408
409OK
410
411or
412
413AT+COPS?
414+COPS: 0,2,"46001",7
415
416OK
417
418*/
419static int req_net_sel_mode_get(mbtk_net_info_t *net, int *cme_err)
420{
421 //LOG("req_net_sel_mode_get() 0");
422 //sleep(1);
423 ATResponse *response = NULL;
424 int tmp_int;
425 char *tmp_ptr = NULL;
426 int err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
427 //LOG("req_net_sel_mode_get() 00");
428 //sleep(1);
429 if (err < 0 || response->success == 0 || !response->p_intermediates){
430 if(cme_err != NULL)
431 *cme_err = at_get_cme_error(response);
432 err = -1;
433 goto exit;
434 }
435 //LOG("req_net_sel_mode_get() 1");
436 //sleep(1);
437 char *line = response->p_intermediates->line;
438 if(line == NULL) {
439 LOG("line is NULL");
440 goto exit;
441 }
442 //LOG("req_net_sel_mode_get() 2");
443 //sleep(1);
444 err = at_tok_start(&line);
445 if (err < 0)
446 {
447 goto exit;
448 }
449 //LOG("req_net_sel_mode_get() 3");
450 //sleep(1);
451 err = at_tok_nextint(&line, &tmp_int);
452 if (err < 0)
453 {
454 goto exit;
455 }
456 net->net_sel_mode = (uint8)tmp_int;
457 //LOG("req_net_sel_mode_get() 4");
458 //sleep(1);
459 // +COPS: 1
460 if(!at_tok_hasmore(&line)) {
461 goto exit;
462 }
463 //LOG("req_net_sel_mode_get() 5");
464 //sleep(1);
465 err = at_tok_nextint(&line, &tmp_int);
466 if (err < 0)
467 {
468 goto exit;
469 }
470 //LOG("req_net_sel_mode_get() 6");
471 //sleep(1);
472 err = at_tok_nextstr(&line, &tmp_ptr);
473 if (err < 0)
474 {
475 goto exit;
476 }
477 // memcpy(net->plmn, tmp_ptr, strlen(tmp_ptr));
478 net->plmn = (uint32)atoi(tmp_ptr);
479 //LOG("req_net_sel_mode_get() 7");
480 //sleep(1);
481 err = at_tok_nextint(&line, &tmp_int);
482 if (err < 0)
483 {
484 goto exit;
485 }
486 net->net_type = (uint8)tmp_int;
487
488 net->net_state = (uint8)MBTK_NET_AVIL_STATE_CURRENT;
489
490exit:
491 //LOG("req_net_sel_mode_get() 8");
492 //sleep(1);
493 at_response_free(response);
494 return err;
495}
496
497/*
498AT+COPS=0
499or
500AT+COPS=1,2,"46000",7
501
502OK
503
504*/
505static int req_net_sel_mode_set(mbtk_net_info_t* net, int *cme_err)
506{
507 ATResponse *response = NULL;
508 char cmd[50] = {0};
509 char* cmp_ptr = cmd;
510 if(net == NULL) {
511 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
512 } else {
513 if(net->net_sel_mode == 0) {
514 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
515 } else if(net->net_type == 0xFF) {
516 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\"",net->plmn);
517 } else {
518 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\",%d",net->plmn, net->net_type);
519 }
520 }
521
522 int err = at_send_command(cmd, &response);
523
524 if (err < 0 || response->success == 0) {
525 if(cme_err) {
526 *cme_err = at_get_cme_error(response);
527 }
528 goto exit;
529 }
530
531exit:
532 at_response_free(response);
533 return err;
534}
535
536/*
537AT*BAND=15
538OK
539
540*/
541static int req_band_set(mbtk_band_info_t* band, int *cme_err)
542{
543 ATResponse *response = NULL;
544 char cmd[100] = {0};
545 int err = -1;
546
547 if(band->gsm_band == 0 && band->umts_band == 0
548 && band->tdlte_band == 0 && band->fddlte_band == 0) {
549 sprintf(cmd, "AT*BAND=%d", band->net_pref);
550 } else {
551 log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t));
552 log_hex("BAND", band, sizeof(mbtk_band_info_t));
553
554 if(band->gsm_band == 0) {
555 band->gsm_band = band_info.band_support.gsm_band;
556 }
557 if(band->umts_band == 0) {
558 band->umts_band = band_info.band_support.umts_band;
559 }
560 if(band->tdlte_band == 0) {
561 band->tdlte_band = band_info.band_support.tdlte_band;
562 }
563 if(band->fddlte_band == 0) {
564 band->fddlte_band = band_info.band_support.fddlte_band;
565 }
566
567 if((band->gsm_band & band_info.band_support.gsm_band) != band->gsm_band) {
568 LOG("GSM band error.");
569 goto exit;
570 }
571
572 if((band->umts_band & band_info.band_support.umts_band) != band->umts_band) {
573 LOG("UMTS band error.");
574 goto exit;
575 }
576
577 if((band->tdlte_band & band_info.band_support.tdlte_band) != band->tdlte_band) {
578 LOG("TDLTE band error.");
579 goto exit;
580 }
581
582 if((band->fddlte_band & band_info.band_support.fddlte_band) != band->fddlte_band) {
583 LOG("FDDLTE band error.");
584 goto exit;
585 }
586
587 if((band->lte_ext_band & band_info.band_support.lte_ext_band) != band->lte_ext_band) {
588 LOG("EXT_LTE band error.");
589 goto exit;
590 }
591
592 if(band->net_pref == 0xFF) { // No change net_pref.
593 int tmp_int;
594 err = at_send_command_singleline("AT*BAND?", "*BAND:", &response);
595 if (err < 0 || response->success == 0 || !response->p_intermediates){
596 if(cme_err) {
597 *cme_err = at_get_cme_error(response);
598 }
599 goto exit;
600 }
601
602 char *line = response->p_intermediates->line;
603 err = at_tok_start(&line);
604 if (err < 0)
605 {
606 goto exit;
607 }
608
609 err = at_tok_nextint(&line, &tmp_int);
610 if (err < 0)
611 {
612 goto exit;
613 }
614 band->net_pref = (uint8)tmp_int; // Set to current net_pref.
615
616 at_response_free(response);
617 }
618
619 if(band->lte_ext_band > 0) {
620 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);
621 } else {
622 sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
623 }
624 }
625 err = at_send_command(cmd, &response);
626
627 if (err < 0 || response->success == 0){
628 if(cme_err) {
629 *cme_err = at_get_cme_error(response);
630 }
631 goto exit;
632 }
633
634 err = 0;
635exit:
636 at_response_free(response);
637 return err;
638}
639
640/*
641// ???????
642AT*BAND=?
643*BAND:(0-18),79,147,482,524503
644
645OK
646
647// ???????????
648AT*BAND?
649*BAND: 15, 78, 147, 482, 524503, 0, 2, 2, 0, 0
650
651OK
652
653// ?????????
654AT*BAND=5,79,147,128,1
655OK
656
657net_prefferred??
658 0 : GSM only
659 1 : UMTS only
660 2 : GSM/UMTS(auto)
661 3 : GSM/UMTS(GSM preferred)
662 4 : GSM/UMTS(UMTS preferred)
663 5 : LTE only
664 6 : GSM/LTE(auto)
665 7 : GSM/LTE(GSM preferred)
666 8 : GSM/LTE(LTE preferred)
667 9 : UMTS/LTE(auto)
668 10 : UMTS/LTE(UMTS preferred)
669 11 : UMTS/LTE(LTE preferred)
670 12 : GSM/UMTS/LTE(auto)
671 13 : GSM/UMTS/LTE(GSM preferred)
672 14 : GSM/UMTS/LTE(UMTS preferred)
673 15 : GSM/UMTS/LTE(LTE preferred)
674GSM band??
675 1 ?C PGSM 900 (standard or primary)
676 2 ?C DCS GSM 1800
677 4 ?C PCS GSM 1900
678 8 ?C EGSM 900 (extended)
679 16 ?C GSM 450
680 32 ?C GSM 480
681 64 ?C GSM 850
682 512 - BAND_LOCK_BIT // used for GSM band setting
683UMTS band??
684 1 ?C UMTS_BAND_1
685 2 ?C UMTS_BAND_2
686 4 ?C UMTS_BAND_3
687 8 ?C UMTS_BAND_4
688 16 ?C UMTS_BAND_5
689 32 ?C UMTS_BAND_6
690 64 ?C UMTS_BAND_7
691 128 ?C UMTS_BAND_8
692 256 ?C UMTS_BAND_9
693LTEbandH(TDD-LTE band)
694 32 ?C TDLTE_BAND_38
695 64 ?C TDLTE_BAND_39
696 128 ?C TDLTE_BAND_40
697 256 ?C TDLTE_BAND_41
698LTEbandL(FDD-LTE band)
699 1 ?C FDDLTE_BAND_1
700 4 ?C FDDLTE _BAND_3
701 8 ?C FDDLTE _BAND_4
702 64 ?C FDDLTE _BAND_7
703 65536 ?C FDDLTE _BAND_17
704 524288 ?C FDDLTE _BAND_20
705*/
706static int req_band_get(mbtk_band_info_t *band, int *cme_err)
707{
708 ATResponse *response = NULL;
709 int tmp_int;
710
711 log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t));
712 int err = at_send_command_singleline("AT*BAND?", "*BAND:", &response);
713 if (err < 0 || response->success == 0 || !response->p_intermediates){
714 if(cme_err) {
715 *cme_err = at_get_cme_error(response);
716 }
717 goto exit;
718 }
719
720 char *line = response->p_intermediates->line;
721 err = at_tok_start(&line);
722 if (err < 0)
723 {
724 goto exit;
725 }
726
727 err = at_tok_nextint(&line, &tmp_int);
728 if (err < 0)
729 {
730 goto exit;
731 }
732 band->net_pref = (uint8)tmp_int;
733
734 err = at_tok_nextint(&line, &tmp_int);
735 if (err < 0)
736 {
737 goto exit;
738 }
739 band->gsm_band = (uint16)tmp_int;
740
741 err = at_tok_nextint(&line, &tmp_int);
742 if (err < 0)
743 {
744 goto exit;
745 }
746 band->umts_band = (uint16)tmp_int;
747
748 err = at_tok_nextint(&line, &tmp_int);
749 if (err < 0)
750 {
751 goto exit;
752 }
753 band->tdlte_band = (uint32)tmp_int;
754
755 err = at_tok_nextint(&line, &tmp_int);
756 if (err < 0)
757 {
758 goto exit;
759 }
760 band->fddlte_band = (uint32)tmp_int;
761
762 // roamingConfig
763 err = at_tok_nextint(&line, &tmp_int);
764 if (err < 0)
765 {
766 goto exit;
767 }
768
769 // srvDomain
770 err = at_tok_nextint(&line, &tmp_int);
771 if (err < 0)
772 {
773 goto exit;
774 }
775
776 // bandPriorityFlag
777 err = at_tok_nextint(&line, &tmp_int);
778 if (err < 0)
779 {
780 goto exit;
781 }
782
783 //
784 err = at_tok_nextint(&line, &tmp_int);
785 if (err < 0)
786 {
787 goto exit;
788 }
789
790 // ltebandExt
791 err = at_tok_nextint(&line, &tmp_int);
792 if (err < 0)
793 {
794 goto exit;
795 }
796 band->lte_ext_band = (uint32)tmp_int;
797
798 log_hex("BAND", band, sizeof(mbtk_band_info_t));
799
800exit:
801 at_response_free(response);
802 return err;
803}
804
805/*
806AT+CSQ
807+CSQ: 31,99
808
809OK
810
811AT+CESQ
812+CESQ: 60,99,255,255,20,61
813
814OK
815
816AT+COPS?
817+COPS: 0,2,"46001",7
818
819OK
820
821*/
822static int req_net_signal_get(mbtk_signal_info_t *signal, int *cme_err)
823{
824 ATResponse *response = NULL;
825 int tmp_int;
826 char *tmp_ptr = NULL;
827 // AT+EEMOPT=1 in the first.
828 int err = at_send_command_singleline("AT+CSQ", "+CSQ:", &response);
829 if (err < 0 || response->success == 0 || !response->p_intermediates){
830 if(cme_err != NULL)
831 *cme_err = at_get_cme_error(response);
832 err = -1;
833 goto exit;
834 }
835
836 char *line = response->p_intermediates->line;
837 err = at_tok_start(&line);
838 if (err < 0)
839 {
840 goto exit;
841 }
842 err = at_tok_nextint(&line, &tmp_int);
843 if (err < 0)
844 {
845 goto exit;
846 }
847 signal->rssi = (uint8)tmp_int;
848 at_response_free(response);
849
850 err = at_send_command_singleline("AT+CESQ", "+CESQ:", &response);
851 if (err < 0 || response->success == 0 || !response->p_intermediates){
852 if(cme_err != NULL)
853 *cme_err = at_get_cme_error(response);
854 err = -1;
855 goto exit;
856 }
857
858 line = response->p_intermediates->line;
859 err = at_tok_start(&line);
860 if (err < 0)
861 {
862 goto exit;
863 }
864 err = at_tok_nextint(&line, &tmp_int);
865 if (err < 0)
866 {
867 goto exit;
868 }
869 signal->rxlev = (uint8)tmp_int;
870
871 err = at_tok_nextint(&line, &tmp_int);
872 if (err < 0)
873 {
874 goto exit;
875 }
876 signal->ber = (uint8)tmp_int;
877
878 err = at_tok_nextint(&line, &tmp_int);
879 if (err < 0)
880 {
881 goto exit;
882 }
883 signal->rscp = (uint8)tmp_int;
884
885 err = at_tok_nextint(&line, &tmp_int);
886 if (err < 0)
887 {
888 goto exit;
889 }
890 signal->ecno = (uint8)tmp_int;
891
892 err = at_tok_nextint(&line, &tmp_int);
893 if (err < 0)
894 {
895 goto exit;
896 }
897 signal->rsrq = (uint8)tmp_int;
898
899 err = at_tok_nextint(&line, &tmp_int);
900 if (err < 0)
901 {
902 goto exit;
903 }
904 signal->rsrp = (uint8)tmp_int;
905
906 at_response_free(response);
907 err = at_send_command_singleline("AT+COPS?", "+COPS:", &response);
908 if (err < 0 || response->success == 0 || !response->p_intermediates){
909 if(cme_err != NULL)
910 *cme_err = at_get_cme_error(response);
911 err = -1;
912 goto exit;
913 }
914 line = response->p_intermediates->line;
915 err = at_tok_start(&line);
916 if (err < 0)
917 {
918 goto exit;
919 }
920 err = at_tok_nextint(&line, &tmp_int);
921 if (err < 0)
922 {
923 goto exit;
924 }
925 if(!at_tok_hasmore(&line)) {
926 goto exit;
927 }
928 err = at_tok_nextint(&line, &tmp_int);
929 if (err < 0)
930 {
931 goto exit;
932 }
933 err = at_tok_nextstr(&line, &tmp_ptr);
934 if (err < 0)
935 {
936 goto exit;
937 }
938 err = at_tok_nextint(&line, &tmp_int);
939 if (err < 0)
940 {
941 goto exit;
942 }
943 signal->type = (uint8)tmp_int;
944
945exit:
946 at_response_free(response);
947 return err;
948}
949
950/*
951AT+CREG=3
952OK
953
954AT+CREG?
955+CREG: 3,1,"8330","06447340",7
956
957OK
958
959AT+CREG?
960+CREG: 3,0
961
962OK
963
964AT+CEREG?
965+CEREG: 3,1,"8330","06447340",7
966
967OK
968
969
970AT+CIREG?
971+CIREG: 2,1,15
972
973OK
974
975AT+CIREG?
976+CIREG: 0
977
978OK
979
980
981*/
982static int req_net_reg_get(mbtk_net_reg_info_t *reg, int *cme_err)
983{
984 ATResponse *response = NULL;
985 int tmp_int;
986 char *tmp_str = NULL;
987 int err = at_send_command("AT+CREG=3", &response);
988 if (err < 0 || response->success == 0){
989 if(cme_err) {
990 *cme_err = at_get_cme_error(response);
991 }
992 goto exit;
993 }
994 at_response_free(response);
995
996 err = at_send_command_multiline("AT+CREG?", "+CREG:", &response);
997 if (err < 0 || response->success == 0 || !response->p_intermediates){
998 if(cme_err) {
999 *cme_err = at_get_cme_error(response);
1000 }
1001 goto exit;
1002 }
1003
1004 char *line = response->p_intermediates->line;
1005 err = at_tok_start(&line);
1006 if (err < 0)
1007 {
1008 goto exit;
1009 }
1010 err = at_tok_nextint(&line, &tmp_int); // n
1011 if (err < 0)
1012 {
1013 goto exit;
1014 }
1015 err = at_tok_nextint(&line, &tmp_int);// stat
1016 if (err < 0)
1017 {
1018 goto exit;
1019 }
1020 reg->call_state = (uint8)tmp_int;
1021
1022 if(at_tok_hasmore(&line)) {
1023 err = at_tok_nextstr(&line, &tmp_str); // lac
1024 if (err < 0)
1025 {
1026 goto exit;
1027 }
1028 reg->lac = strtol(tmp_str, NULL, 16);
1029
1030 err = at_tok_nextstr(&line, &tmp_str); // ci
1031 if (err < 0)
1032 {
1033 goto exit;
1034 }
1035 reg->ci = strtol(tmp_str, NULL, 16);
1036
1037 err = at_tok_nextint(&line, &tmp_int);// AcT
1038 if (err < 0)
1039 {
1040 goto exit;
1041 }
1042 reg->type = (uint8)tmp_int;
1043 }
1044 at_response_free(response);
1045
1046 err = at_send_command_multiline("AT+CEREG?", "+CEREG:", &response);
1047 if (err < 0 || response->success == 0 || !response->p_intermediates){
1048 if(cme_err) {
1049 *cme_err = at_get_cme_error(response);
1050 }
1051 goto exit;
1052 }
1053
1054 line = response->p_intermediates->line;
1055 err = at_tok_start(&line);
1056 if (err < 0)
1057 {
1058 goto exit;
1059 }
1060 err = at_tok_nextint(&line, &tmp_int); // n
1061 if (err < 0)
1062 {
1063 goto exit;
1064 }
1065 err = at_tok_nextint(&line, &tmp_int);// stat
1066 if (err < 0)
1067 {
1068 goto exit;
1069 }
1070 reg->data_state = (uint8)tmp_int;
1071
1072 if(reg->lac == 0 && at_tok_hasmore(&line)) {
1073 err = at_tok_nextstr(&line, &tmp_str); // lac
1074 if (err < 0)
1075 {
1076 goto exit;
1077 }
1078 reg->lac = strtol(tmp_str, NULL, 16);
1079
1080 err = at_tok_nextstr(&line, &tmp_str); // ci
1081 if (err < 0)
1082 {
1083 goto exit;
1084 }
1085 reg->ci = strtol(tmp_str, NULL, 16);
1086
1087 err = at_tok_nextint(&line, &tmp_int);// AcT
1088 if (err < 0)
1089 {
1090 goto exit;
1091 }
1092 reg->type = (uint8)tmp_int;
1093 }
1094 at_response_free(response);
1095
1096 err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response);
1097 if (err < 0 || response->success == 0 || !response->p_intermediates){
1098 reg->ims_state = (uint8)0;
1099 err = 0;
1100 goto exit;
1101 }
1102 line = response->p_intermediates->line;
1103 err = at_tok_start(&line);
1104 if (err < 0)
1105 {
1106 goto exit;
1107 }
1108 err = at_tok_nextint(&line, &tmp_int); // n/stat
1109 if (err < 0)
1110 {
1111 goto exit;
1112 }
1113 if(at_tok_hasmore(&line)) {
1114 err = at_tok_nextint(&line, &tmp_int);// stat
1115 if (err < 0)
1116 {
1117 goto exit;
1118 }
1119 reg->ims_state = (uint8)tmp_int;
1120 } else {
1121 reg->ims_state = (uint8)tmp_int;
1122 }
1123
1124exit:
1125 at_response_free(response);
1126 return err;
1127}
1128
1129/*
b.liub4772072024-08-15 14:47:03 +08001130AT+EEMOPT=1
1131OK
1132
1133// LTE
1134AT+EEMGINFO?
1135// <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
1136// <rsrp>,<rsrq>, <sinr>,
1137// errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
1138// cellId,subFrameAssignType,specialSubframePatterns,transMode
1139// mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
1140// tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
1141// dlBer, ulBer,
1142// diversitySinr, diversityRssi
1143+EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
11440, 0, 0,
11451, 10, 0, 1, 0, 1059, 78, 3959566565,
1146105149248, 2, 7, 7,
11470, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
11480, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
11490, 0,
11507, 44
1151
1152// index,phyCellId,euArfcn,rsrp,rsrq
1153+EEMLTEINTER: 0, 65535, 38950, 0, 0
1154
1155+EEMLTEINTER: 1, 0, 0, 0, 0
1156
1157+EEMLTEINTER: 2, 0, 4294967295, 255, 255
1158
1159+EEMLTEINTER: 3, 65535, 1300, 0, 0
1160
1161+EEMLTEINTER: 4, 0, 0, 0, 0
1162
1163+EEMLTEINTER: 5, 0, 4294967295, 247, 0
1164
1165+EEMLTEINTER: 6, 197, 41332, 24, 9
1166
1167+EEMLTEINTER: 7, 0, 0, 0, 0
1168
1169+EEMLTEINTER: 8, 0, 0, 0, 0
1170
1171+EEMLTEINTRA: 0, 429, 40936, 56, 12
1172
1173+EEMLTEINTERRAT: 0,0
1174
1175+EEMLTEINTERRAT: 1,0
1176
1177+EEMGINFO: 3, 2 // <state>:
1178 // 0: ME in Idle mode
1179 // 1: ME in Dedicated mode
1180 // 2: ME in PS PTM mode
1181 // 3: invalid state
1182 // <nw_type>:
1183 // 0: GSM 1: UMTS 2: LTE
1184
1185OK
1186
1187// WCDMA
1188AT+EEMGINFO?
1189// Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1190
1191// if sCMeasPresent == 1
1192// cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1193// endif
1194
1195// if sCParamPresent == 1
1196// rac, nom, mcc, mnc_len, mnc, lac, ci,
1197// uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1198// csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1199// endif
1200
1201// if ueOpStatusPresent == 1
1202// rrcState, numLinks, srncId, sRnti,
1203// algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1204// HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1205// MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1206// serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1207// endif
1208//
1209+EEMUMTSSVC: 3, 1, 1, 1,
1210-80, 27, -6, -18, -115, -32768,
12111, 1, 1120, 2, 1, 61697, 168432821,
121215, 24, 10763, 0, 0, 0, 0,
1213128, 128, 65535, 0, 0,
12142, 255, 65535, 4294967295,
12150, 0, 0, 0, 0, 0,
12160, 0, 0, 0, 0, 0, 1, 1,
121728672, 28672, 0, 0, 0, 0, 0, 0, 0,
12180, 0, 0, 0, 0, 0
1219
1220// index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1221+EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1222
1223+EEMUMTSINTRA: 1, -1, -32768, -18, -115, 0, 0, 65534, 2, 10763, 40, 32768
1224
1225+EEMUMTSINTRA: 2, -32768, -18, -115, 0, 0, 65534, 3, 10763, 278, 32768, 65535
1226
1227+EEMUMTSINTRA: 3, -18, -115, 0, 0, -2, 4, 10763, 28, 32768, 65535, 32768
1228
1229+EEMUMTSINTRA: 4, -115, 0, 0, -2, 5, 10763, 270, 32768, 65535, 32768, 65518
1230
1231+EEMUMTSINTRA: 5, 0, 0, -2, 6, 10763, 286, 32768, 65535, 32768, 65518, 65421
1232
1233+EEMUMTSINTRA: 6, 0, -2, 7, 10763, 80, 32768, 65535, 32768, 65518, 65421, 0
1234
1235+EEMUMTSINTRA: 7, -2, 8, 10763, 206, -32768, 65535, 32768, 65518, 65421, 0, 0
1236
1237+EEMUMTSINTRA: 8, 9, 10763, 11, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
1238
1239+EEMUMTSINTRA: 9, 10763, 19, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 11
1240
1241+EEMUMTSINTRA: 10, 232, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 12, 10763
1242
1243+EEMUMTSINTRA: 11, -32768, -1, -32768, -18, -115, 0, 0, 65534, 13, 10763, 66
1244
1245+EEMUMTSINTRA: 12, -1, -32768, -18, -115, 0, 0, 65534, 14, 10763, 216, 32768
1246
1247+EEMUMTSINTRA: 13, -32768, -18, -115, 0, 0, 65534, 15, 10763, 183, 32768, 65535
1248
1249+EEMUMTSINTRA: 14, -18, -115, 0, 0, -2, 16, 10763, 165, 32768, 65535, 32768
1250
1251+EEMUMTSINTRA: 15, -115, 0, 0, -2, 17, 10763, 151, 32768, 65535, 32768, 65518
1252
1253+EEMUMTSINTRA: 16, 0, 0, -2, 18, 10763, 43, 32768, 65535, 32768, 65518, 65421
1254
1255+EEMUMTSINTRA: 17, 0, -2, 19, 10763, 72, 32768, 65535, 32768, 65518, 65421, 0
1256
1257+EEMUMTSINTRA: 18, -2, 20, 10763, 157, -32768, 65535, 32768, 65518, 65421, 0, 0
1258
1259+EEMUMTSINTRA: 19, 21, 10763, 165, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
1260
1261+EEMUMTSINTRA: 20, 10763, 301, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 23
1262
1263+EEMUMTSINTRA: 21, 23, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 24, 10763
1264
1265+EEMUMTSINTRA: 22, -32768, -1, -32768, -18, -115, 0, 0, 65534, 25, 10763, 0
1266
1267+EEMUMTSINTRA: 23, -1, -32768, -18, -115, 0, 0, 65534, 26, 10763, 167, 32768
1268
1269+EEMUMTSINTRA: 24, -32768, -18, -115, 0, 0, 65534, 27, 10763, 34, 32768, 65535
1270
1271+EEMUMTSINTRA: 25, -18, -115, 0, 0, -2, 28, 10763, 313, 32768, 65535, 32768
1272
1273+EEMUMTSINTRA: 26, -115, 0, 0, -2, 29, 10763, 152, 32768, 65535, 32768, 65518
1274
1275+EEMUMTSINTRA: 27, 0, 0, -2, 30, 10763, 239, 0, 0, 0, 0, 0
1276
1277+EEMUMTSINTRA: 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1278
1279+EEMUMTSINTRA: 29, 0, 0, 0, 0, -115, 0, 0, 65534, 30, 10763, 239
1280
1281// index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1282+EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1283
1284+EEMUMTSINTERRAT: 1, -107, -1, -1, 0, 0, 65534, 1, 72, 49, 0
1285
1286+EEMUMTSINTERRAT: 2, -1, -1, 0, 0, 65534, 2, 119, 15, 32768, 149
1287
1288+EEMUMTSINTERRAT: 3, -1, 0, 0, -2, 3, 121, 23, 0, 0, 0
1289
1290+EEMGINFO: 3, 1
1291
1292OK
1293
1294
1295// GSM
1296AT+EEMGINFO?
1297+EEMGINFOBASIC: 2
1298
1299// mcc, mnc_len, mnc, lac, ci, nom, nco,
1300// bsic, C1, C2, TA, TxPwr,
1301// RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1302// ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1303// bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1304// ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1305// gsmBand,channelMode
1306+EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
130763, 36, 146, 1, 7,
130846, 42, 42, 7, 0,
130953, 0, 8, 0, 1, 6, 53,
13102, 0, 146, 42, 54, 0, 1,
13111, 32, 0, 0, 0, 0,
13120, 0
1313
1314// PS_attached, attach_type, service_type, tx_power, c_value,
1315// ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1316// gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1317// pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1318+EEMGINFOPS: 1, 255, 0, 0, 0,
13190, 0, 268435501, 1, 0, 0,
13204, 0, 96, 0, 0, 0,
13210, 0, 0, 65535, 0, 13350
1322
1323+EEMGINFO: 0, 0
1324
1325OK
1326
1327*/
1328static int req_cell_info_get(int *cme_err)
1329{
1330 ATResponse *response = NULL;
1331 int tmp_int;
1332 int buff_size = 0;
1333 // AT+EEMOPT=1 in the first.
1334 int err = at_send_command("AT+EEMOPT=1", &response);
1335 if (err < 0 || response->success == 0){
1336 *cme_err = at_get_cme_error(response);
1337 goto exit;
1338 }
1339
1340 // Reset buffer in the first.
1341 memset(&cell_info, 0xFF, sizeof(mbtK_cell_pack_info_t));
1342 cell_info.running = true;
1343 cell_info.cell_list.num = 0;
1344
1345 err = at_send_command_singleline("AT+EEMGINFO?", "+EEMGINFO:", &response);
1346 if (err < 0 || response->success == 0 || !response->p_intermediates){
1347 *cme_err = at_get_cme_error(response);
1348 goto exit;
1349 }
1350
1351 // Now, cell infomation has get from URC message.
1352
1353 char *line = response->p_intermediates->line;
1354 err = at_tok_start(&line);
1355 if (err < 0)
1356 {
1357 goto exit;
1358 }
1359 err = at_tok_nextint(&line, &tmp_int);
1360 if (err < 0)
1361 {
1362 goto exit;
1363 }
1364 err = at_tok_nextint(&line, &tmp_int);
1365 if (err < 0)
1366 {
1367 goto exit;
1368 }
1369
1370 cell_info.cell_list.type = (uint8)tmp_int;
1371 cell_info.running = false;
1372
1373#if 0
1374 while(lines_ptr)
1375 {
1376 // LTE
1377 if(strStartsWith(line, "+EEMLTESVC:")) // LTE Server Cell
1378 {
1379
1380 }
1381 else if(strStartsWith(line, "+EEMLTEINTER:")) // LTE
1382 {
1383
1384 }
1385 else if(strStartsWith(line, "+EEMLTEINTRA:")) // LTE
1386 {
1387
1388 }
1389 else if(strStartsWith(line, "+EEMLTEINTERRAT:")) // LTE
1390 {
1391
1392 }
1393 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
1394 // <nw_type>: 0: GSM 1: UMTS 2: LTE
1395 {
1396
1397 }
1398 // WCDMA
1399 else if(strStartsWith(line, "+EEMUMTSSVC:")) // WCDMA Server Cell
1400 {
1401
1402 }
1403 else if(strStartsWith(line, "+EEMUMTSINTRA:")) // WCDMA
1404 {
1405
1406 }
1407 else if(strStartsWith(line, "+EEMUMTSINTERRAT:")) // WCDMA
1408 {
1409
1410 }
1411 // GSM
1412 else if(strStartsWith(line, "+EEMGINFOBASIC:")) // Basic information in GSM
1413 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1414 {
1415
1416 }
1417 else if(strStartsWith(line, "+EEMGINFOSVC:")) // GSM Server Cell
1418 {
1419
1420 }
1421 else if(strStartsWith(line, "+EEMGINFOPS:")) // PS
1422 {
1423
1424 }
1425
1426
1427 lines_ptr = lines_ptr->p_next;
1428 }
1429#endif
1430
1431exit:
1432 at_response_free(response);
1433 return buff_size;
1434}
1435
1436static int req_cell_info_set(const char *cmgl, char *reg, int len, int *cme_err)
1437{
1438 ATResponse *response = NULL;
1439 char cmd[30] = {0};
1440 char data[218] = {0};
1441 int err = 0;
1442
1443 memcpy(data, cmgl, len);
1444
1445 sprintf(cmd, "AT*CELL=%s", data);
1446
1447 if(strlen(cmd) > 0)
1448 {
1449 err = at_send_command_multiline(cmd, "", &response);
1450 if (err < 0 || response->success == 0 || !response->p_intermediates){
1451 *cme_err = at_get_cme_error(response);
1452 goto exit;
1453 }
1454
1455 ATLine* lines_ptr = response->p_intermediates;
1456 char *line = NULL;
1457 int reg_len = 0;
1458 bool flag = false;
1459 while(lines_ptr)
1460 {
1461 line = lines_ptr->line;
1462 if(line ==NULL)
1463 {
1464 LOGD("line is null----------------------");
1465 }
1466 lines_ptr = lines_ptr->p_next;
1467 }
1468 }
1469 err = 0;
1470 memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss"));
1471exit:
1472 at_response_free(response);
1473 return err;
1474}
1475
1476
1477/*
b.liu87afc4c2024-08-14 17:33:45 +08001478AT+CGDCONT?
1479
1480+CGDCONT: 1,"IPV4V6","ctnet","10.142.64.116 254.128.0.0.0.0.0.0.0.0.0.0.0.0.0.1",0,0,0,2,0,0
1481
1482+CGDCONT: 8,"IPV4V6","IMS","254.128.0.0.0.0.0.0.0.0.0.0.0.0.0.1",0,0,0,2,1,1
1483
1484OK
1485
1486*/
1487static int req_apn_get(mbtk_apn_info_array_t *apns, int *cme_err)
1488{
1489 ATResponse *response = NULL;
1490 int err = at_send_command_multiline("AT+CGDCONT?", "+CGDCONT:", &response);
1491
1492 if (err < 0 || response->success == 0 || !response->p_intermediates){
1493 if(cme_err) {
1494 *cme_err = at_get_cme_error(response);
1495 }
1496 goto exit;
1497 }
1498
1499 ATLine* lines_ptr = response->p_intermediates;
1500 char *line = NULL;
1501 int tmp_int;
1502 char *tmp_str = NULL;
1503 /*
1504 <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>...
1505 <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>
1506 */
1507 while(lines_ptr)
1508 {
1509 line = lines_ptr->line;
1510 err = at_tok_start(&line);
1511 if (err < 0)
1512 {
1513 goto exit;
1514 }
1515
1516 err = at_tok_nextint(&line, &tmp_int); // cid
1517 if (err < 0)
1518 {
1519 goto exit;
1520 }
1521 // Only get CID 1-7
1522 if(tmp_int >= MBTK_APN_CID_MIN && tmp_int <= MBTK_APN_CID_MAX) {
1523 apns->apns[apns->num].cid = (mbtk_ril_cid_enum)tmp_int;
1524
1525 err = at_tok_nextstr(&line, &tmp_str);// ip type
1526 if (err < 0)
1527 {
1528 goto exit;
1529 }
1530 if(!strcasecmp(tmp_str, "IP")) {
1531 apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IP;
1532 } else if(!strcasecmp(tmp_str, "IPV6")) {
1533 apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IPV6;
1534 } else if(!strcasecmp(tmp_str, "IPV4V6")) {
1535 apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IPV4V6;
1536 } else {
1537 apns->apns[apns->num].ip_type = MBTK_IP_TYPE_PPP;
1538 }
1539
1540 err = at_tok_nextstr(&line, &tmp_str); // apn
1541 if (err < 0)
1542 {
1543 goto exit;
1544 }
1545 if(!str_empty(tmp_str)) {
1546 memcpy(apns->apns[apns->num].apn, tmp_str, strlen(tmp_str));
1547 }
1548
1549 apns->num++;
1550 }
1551
1552 lines_ptr = lines_ptr->p_next;
1553 }
1554
1555 goto exit;
1556exit:
1557 at_response_free(response);
1558 return err;
1559}
1560
1561/*
1562AT+CGDCONT=1,"IPV4V6","cmnet"
1563OK
1564
1565AT*AUTHReq=1,1,marvell,123456
1566OK
1567
1568*/
1569static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err)
1570{
1571 ATResponse *response = NULL;
1572 char cmd[400] = {0};
1573 int index = 0;
1574 int err = 0;
1575
1576 // Delete apn
1577 if(str_empty(apn->apn)) {
1578 sprintf(cmd, "AT+CGDCONT=%d", apn->cid);
1579 err = at_send_command(cmd, &response);
1580 if (err < 0 || response->success == 0){
1581 if(cme_err) {
1582 *cme_err = at_get_cme_error(response);
1583 }
1584 goto exit;
1585 }
1586 } else {
1587 index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid);
1588 switch(apn->ip_type) {
1589 case MBTK_IP_TYPE_IP: {
1590 index += sprintf(cmd + index,"\"IP\",");
1591 break;
1592 }
1593 case MBTK_IP_TYPE_IPV6: {
1594 index += sprintf(cmd + index,"\"IPV6\",");
1595 break;
1596 }
1597 case MBTK_IP_TYPE_IPV4V6: {
1598 index += sprintf(cmd + index,"\"IPV4V6\",");
1599 break;
1600 }
1601 default: {
1602 index += sprintf(cmd + index,"\"PPP\",");
1603 break;
1604 }
1605 }
1606 if(strlen(apn->apn) > 0) {
1607 index += sprintf(cmd + index,"\"%s\"", apn->apn);
1608 }
1609
1610 err = at_send_command(cmd, &response);
1611 if (err < 0 || response->success == 0){
1612 if(cme_err) {
1613 *cme_err = at_get_cme_error(response);
1614 }
1615 goto exit;
1616 }
1617
1618 if(!str_empty(apn->user) || !str_empty(apn->pass)) {
1619 at_response_free(response);
1620
1621 memset(cmd,0,400);
1622 int cmd_auth=0;
1623 if(apn->auth == MBTK_APN_AUTH_PROTO_NONE)
1624 cmd_auth = 0;
1625 else if(apn->auth == MBTK_APN_AUTH_PROTO_PAP)
1626 cmd_auth = 1;
1627 else if(apn->auth == MBTK_APN_AUTH_PROTO_CHAP)
1628 cmd_auth = 2;
1629 else
1630 goto exit;
1631
1632 sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass);
1633 err = at_send_command(cmd, &response);
1634 if (err < 0 || response->success == 0){
1635 if(cme_err) {
1636 *cme_err = at_get_cme_error(response);
1637 }
1638 goto exit;
1639 }
1640 }
1641 }
1642
1643exit:
1644 at_response_free(response);
1645 return err;
1646}
1647
1648/*
1649AT+CGACT?
1650+CGACT: 1,1
1651+CGACT: 8,1
1652OK
1653
1654AT+CGACT=1,<cid>
1655OK
1656
1657*/
1658static int req_data_call_start(mbtk_ril_cid_enum cid, bool def_route,
1659 int retry_interval, int timeout, mbtk_ip_info_t *ip_info, int *cme_err)
1660{
1661 ATResponse *response = NULL;
1662 char cmd[400] = {0};
1663 int err = 0;
1664
1665 sprintf(cmd, "AT+CGACT=1,%d", cid);
1666 err = at_send_command(cmd, &response);
1667 if (err < 0 || response->success == 0){
1668 if(cme_err) {
1669 *cme_err = at_get_cme_error(response);
1670 }
1671 goto exit;
1672 }
1673
1674exit:
1675 at_response_free(response);
1676 return err;
1677}
1678
1679/*
1680AT+CGACT=0,<cid>
1681OK
1682
1683*/
1684static int req_data_call_stop(mbtk_ril_cid_enum cid, int timeout, int *cme_err)
1685{
1686 ATResponse *response = NULL;
1687 char cmd[400] = {0};
1688 int err = 0;
1689
1690 sprintf(cmd, "AT+CGACT=0,%d", cid);
1691 err = at_send_command(cmd, &response);
1692 if (err < 0 || response->success == 0){
1693 if(cme_err) {
1694 *cme_err = at_get_cme_error(response);
1695 }
1696 goto exit;
1697 }
1698
1699exit:
1700 at_response_free(response);
1701 return err;
1702}
1703
1704/*
1705AT+CGCONTRDP=1
1706+CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","10.255.74.26","","223.87.253.100","223.87.253.253","","",0,0
1707+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
1708
1709OK
1710
1711*/
1712static int req_data_call_state_get(mbtk_ril_cid_enum cid, mbtk_ip_info_t *ip_info, int *cme_err)
1713{
1714 ATResponse *response = NULL;
1715 char cmd[50] = {0};
1716 int err = 0;
1717
1718 sprintf(cmd, "AT+CGCONTRDP=%d", cid);
1719
1720 err = at_send_command_multiline(cmd, "+CGCONTRDP:", &response);
1721 if (err < 0 || response->success == 0 || !response->p_intermediates){
1722 *cme_err = at_get_cme_error(response);
1723 goto exit;
1724 }
1725 ATLine* lines_ptr = response->p_intermediates;
1726 char *line = NULL;
1727 int tmp_int;
1728 char *tmp_ptr = NULL;
1729 while(lines_ptr)
1730 {
1731 line = lines_ptr->line;
1732 err = at_tok_start(&line);
1733 if (err < 0)
1734 {
1735 goto exit;
1736 }
1737
1738 err = at_tok_nextint(&line, &tmp_int); // cid
1739 if (err < 0)
1740 {
1741 goto exit;
1742 }
1743 err = at_tok_nextint(&line, &tmp_int); // bearer_id
1744 if (err < 0)
1745 {
1746 goto exit;
1747 }
1748 err = at_tok_nextstr(&line, &tmp_ptr); // APN
1749 if (err < 0)
1750 {
1751 goto exit;
1752 }
1753
1754 err = at_tok_nextstr(&line, &tmp_ptr); // IP
1755 if (err < 0 || str_empty(tmp_ptr))
1756 {
1757 goto exit;
1758 }
1759 if(is_ipv4(tmp_ptr)) {
1760 if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.IPAddr)) < 0) {
1761 LOGE("inet_pton() fail.");
1762 err = -1;
1763 goto exit;
1764 }
1765
1766 ip_info->ipv4.valid = true;
1767 //log_hex("IPv4", &(ipv4->IPAddr), sizeof(struct in_addr));
1768 } else {
1769 if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.IPV6Addr))) {
1770 LOGE("str_2_ipv6() fail.");
1771 err = -1;
1772 goto exit;
1773 }
1774
1775 ip_info->ipv6.valid = true;
1776 //log_hex("IPv6", &(ipv6->IPV6Addr), 16);
1777 }
1778
1779 err = at_tok_nextstr(&line, &tmp_ptr); // Gateway
1780 if (err < 0)
1781 {
1782 goto exit;
1783 }
1784 if(!str_empty(tmp_ptr)) { // No found gateway
1785 if(is_ipv4(tmp_ptr)) {
1786 if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.GateWay)) < 0) {
1787 LOGE("inet_pton() fail.");
1788 err = -1;
1789 goto exit;
1790 }
1791
1792 //log_hex("IPv4", &(ipv4->GateWay), sizeof(struct in_addr));
1793 } else {
1794 if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.GateWay))) {
1795 LOGE("str_2_ipv6() fail.");
1796 err = -1;
1797 goto exit;
1798 }
1799
1800 //log_hex("IPv6", &(ipv6->GateWay), 16);
1801 }
1802 }
1803
1804 err = at_tok_nextstr(&line, &tmp_ptr); // prim_DNS
1805 if (err < 0)
1806 {
1807 goto exit;
1808 }
1809 if(!str_empty(tmp_ptr)) { // No found Primary DNS
1810 if(is_ipv4(tmp_ptr)) {
1811 if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.PrimaryDNS)) < 0) {
1812 LOGE("inet_pton() fail.");
1813 err = -1;
1814 goto exit;
1815 }
1816
1817 //log_hex("IPv4", &(ipv4->PrimaryDNS), sizeof(struct in_addr));
1818 } else {
1819 if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.PrimaryDNS))) {
1820 LOGE("str_2_ipv6() fail.");
1821 err = -1;
1822 goto exit;
1823 }
1824
1825 //log_hex("IPv6", &(ipv6->PrimaryDNS), 16);
1826 }
1827 }
1828
1829 err = at_tok_nextstr(&line, &tmp_ptr); // sec_DNS
1830 if (err < 0)
1831 {
1832 goto exit;
1833 }
1834 if(!str_empty(tmp_ptr)) { // No found Secondary DNS
1835 if(is_ipv4(tmp_ptr)) {
1836 if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.SecondaryDNS)) < 0) {
1837 LOGE("inet_pton() fail.");
1838 err = -1;
1839 goto exit;
1840 }
1841
1842 //log_hex("IPv4", &(ipv4->SecondaryDNS), sizeof(struct in_addr));
1843 } else {
1844 if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.SecondaryDNS))) {
1845 LOGE("str_2_ipv6() fail.");
1846 err = -1;
1847 goto exit;
1848 }
1849
1850 //log_hex("IPv6", &(ipv6->SecondaryDNS), 16);
1851 }
1852 }
1853
1854 lines_ptr = lines_ptr->p_next;
1855 }
1856
1857exit:
1858 at_response_free(response);
1859 return err;
1860}
1861
1862
1863//void net_list_free(void *data);
1864// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
1865// Otherwise, do not call pack_error_send().
1866mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
1867{
1868 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
1869 int cme_err = MBTK_RIL_ERR_CME_NON;
1870 switch(pack->msg_id)
1871 {
1872 case RIL_MSG_ID_NET_AVAILABLE:
1873 {
1874 if(pack->data_len == 0 || pack->data == NULL)
1875 {
1876 mbtk_net_info_array_t net_array;
1877 memset(&net_array, 0, sizeof(mbtk_net_info_array_t));
1878 if(req_available_net_get(&net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1879 {
1880 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1881 err = MBTK_RIL_ERR_CME + cme_err;
1882 } else {
1883 err = MBTK_RIL_ERR_UNKNOWN;
1884 }
1885 LOGD("Get Available Net fail.");
1886 }
1887 else
1888 {
1889 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t));
1890 }
1891 }
1892 else // Set
1893 {
1894 err = MBTK_RIL_ERR_UNSUPPORTED;
1895 LOGW("Unsupport set available net.");
1896 }
1897 break;
1898 }
1899 case RIL_MSG_ID_NET_SEL_MODE:
1900 {
1901 if(pack->data_len == 0 || pack->data == NULL)
1902 {
1903 mbtk_net_info_t info;
1904 memset(&info, 0, sizeof(mbtk_net_info_t));
1905 if(req_net_sel_mode_get(&info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1906 {
1907 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1908 err = MBTK_RIL_ERR_CME + cme_err;
1909 } else {
1910 err = MBTK_RIL_ERR_UNKNOWN;
1911 }
1912 LOGD("Get Net sel mode fail.");
1913 }
1914 else
1915 {
1916 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t));
1917 }
1918 }
1919 else // Set
1920 {
1921 mbtk_net_info_t *info = (mbtk_net_info_t*)pack->data;
1922 if(req_net_sel_mode_set(info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1923 {
1924 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1925 err = MBTK_RIL_ERR_CME + cme_err;
1926 } else {
1927 err = MBTK_RIL_ERR_UNKNOWN;
1928 }
1929 LOGD("Set Net sel mode fail.");
1930 }
1931 else
1932 {
1933 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
1934 }
1935 }
1936 break;
1937 }
1938 case RIL_MSG_ID_NET_BAND:
1939 {
1940 if(pack->data_len == 0 || pack->data == NULL)
1941 {
1942 err = MBTK_RIL_ERR_REQ_PARAMETER;
1943 LOG("No data found.");
1944 }
1945 else // Set
1946 {
1947 if(pack->data_len == sizeof(uint8)) {
1948 if(*(pack->data)) { // Get current bands.
1949 mbtk_band_info_t band;
1950 memset(&band, 0x0, sizeof(mbtk_band_info_t));
1951 if(req_band_get(&band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1952 {
1953 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1954 err = MBTK_RIL_ERR_CME + cme_err;
1955 } else {
1956 err = MBTK_RIL_ERR_UNKNOWN;
1957 }
1958 LOG("Get net band fail.");
1959 }
1960 else
1961 {
1962 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t));
1963 }
1964 } else { // Get support bands.
1965 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &band_info.band_support , sizeof(mbtk_band_info_t));
1966 }
1967 } else { // Set current bands.
1968 mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data;
1969 if(pack->data_len != sizeof(mbtk_band_info_t))
1970 {
1971 err = MBTK_RIL_ERR_REQ_PARAMETER;
1972 LOG("Set net band error.");
1973 break;
1974 }
1975
1976 if(req_band_set(band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1977 {
1978 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1979 err = MBTK_RIL_ERR_CME + cme_err;
1980 } else {
1981 err = MBTK_RIL_ERR_UNKNOWN;
1982 }
1983 LOG("Set net band fail.");
1984 }
1985 else
1986 {
1987 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
1988 }
1989 }
1990 }
1991 break;
1992 }
1993 case RIL_MSG_ID_NET_SIGNAL:
1994 {
1995 if(pack->data_len == 0 || pack->data == NULL)
1996 {
1997 mbtk_signal_info_t signal;
1998 memset(&signal, 0, sizeof(mbtk_signal_info_t));
1999 if(req_net_signal_get(&signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2000 {
2001 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2002 err = MBTK_RIL_ERR_CME + cme_err;
2003 } else {
2004 err = MBTK_RIL_ERR_UNKNOWN;
2005 }
2006 LOGD("Get net signal fail.");
2007 }
2008 else
2009 {
2010 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t));
2011 }
2012 }
2013 else // Set
2014 {
2015 err = MBTK_RIL_ERR_UNSUPPORTED;
2016 LOGW("Unsupport set net signal.");
2017 }
2018 break;
2019 }
2020 case RIL_MSG_ID_NET_REG:
2021 {
2022 if(pack->data_len == 0 || pack->data == NULL)
2023 {
2024 mbtk_net_reg_info_t net_reg;
2025 memset(&net_reg, 0, sizeof(mbtk_net_reg_info_t));
2026 if(req_net_reg_get(&net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2027 {
2028 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2029 err = MBTK_RIL_ERR_CME + cme_err;
2030 } else {
2031 err = MBTK_RIL_ERR_UNKNOWN;
2032 }
2033 LOGD("Get Net reg info fail.");
2034 }
2035 else
2036 {
2037 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_reg, sizeof(mbtk_net_reg_info_t));
2038 }
2039 }
2040 else // Set
2041 {
2042 err = MBTK_RIL_ERR_UNSUPPORTED;
2043 LOGW("Unsupport set net reg info.");
2044 }
2045 break;
2046 }
2047 case RIL_MSG_ID_NET_CELL:
2048 {
b.liub4772072024-08-15 14:47:03 +08002049 if(pack->data_len == 0 || pack->data == NULL) // Get net cell.
b.liu87afc4c2024-08-14 17:33:45 +08002050 {
b.liub4772072024-08-15 14:47:03 +08002051 if(req_cell_info_get(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08002052 {
2053 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2054 err = MBTK_RIL_ERR_CME + cme_err;
2055 } else {
2056 err = MBTK_RIL_ERR_UNKNOWN;
2057 }
b.liub4772072024-08-15 14:47:03 +08002058 LOG("Get net cell fail.");
b.liu87afc4c2024-08-14 17:33:45 +08002059 }
2060 else
2061 {
b.liub4772072024-08-15 14:47:03 +08002062 LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_list.num);
2063 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &cell_info.cell_list, sizeof(mbtk_cell_info_array_t));
b.liu87afc4c2024-08-14 17:33:45 +08002064 }
2065 }
b.liub4772072024-08-15 14:47:03 +08002066 else // Lock cell
b.liu87afc4c2024-08-14 17:33:45 +08002067 {
b.liub4772072024-08-15 14:47:03 +08002068 char *mem = (char*)(pack->data);
2069 int len = pack->data_len;
2070 char reg[100] = {0};
2071 if(req_cell_info_set(mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2072 {
2073 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2074 err = MBTK_RIL_ERR_CME + cme_err;
2075 } else {
2076 err = MBTK_RIL_ERR_UNKNOWN;
2077 }
2078 }
2079 else
2080 {
2081 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
2082 }
b.liu87afc4c2024-08-14 17:33:45 +08002083 }
2084 break;
2085 }
2086 case RIL_MSG_ID_NET_APN:
2087 {
2088 if(pack->data_len == 0 || pack->data == NULL)
2089 {
2090 mbtk_apn_info_array_t apns;
2091 memset(&apns, 0, sizeof(mbtk_apn_info_array_t));
2092 if(req_apn_get(&apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2093 {
2094 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2095 err = MBTK_RIL_ERR_CME + cme_err;
2096 } else {
2097 err = MBTK_RIL_ERR_UNKNOWN;
2098 }
2099 LOGD("Get APN fail.");
2100 }
2101 else
2102 {
2103 LOGD("size - %d", sizeof(mbtk_apn_info_array_t));
2104 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &apns, sizeof(mbtk_apn_info_array_t));
2105 }
2106 }
2107 else // Set
2108 {
2109 mbtk_apn_info_t *apn = (mbtk_apn_info_t*)pack->data;
2110 if(apn_cid_reset(apn)) {
2111 err = MBTK_RIL_ERR_CID;
2112 } else {
2113 if(apn_conf_support(apn->cid)) {
2114 if(req_apn_set(apn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2115 {
2116 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2117 err = MBTK_RIL_ERR_CME + cme_err;
2118 } else {
2119 err = MBTK_RIL_ERR_UNKNOWN;
2120 }
2121 LOGD("Set APN fail.");
2122 }
2123 else
2124 {
2125 if(apn_prop_set(apn)) {
2126 LOGE("Save APN fail.");
2127 }
2128 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
2129 }
2130 } else {
2131 err = MBTK_RIL_ERR_UNSUPPORTED;
2132 LOGD("Can not set APN for CID : %d", apn->cid);
2133 }
2134 }
2135 }
2136 break;
2137 }
2138 case RIL_MSG_ID_NET_DATA_CALL:
2139 {
2140 if(pack->data_len == 0 || pack->data == NULL)
2141 {
2142 err = MBTK_RIL_ERR_UNSUPPORTED;
2143 }
2144 else // Set
2145 {
2146 mbtk_data_call_info_t *call_info = (mbtk_data_call_info_t*)pack->data;
2147 if(call_info->type == MBTK_DATA_CALL_START) {
2148 mbtk_ip_info_t ip_info;
2149 memset(&ip_info, 0, sizeof(ip_info));
2150 if(apn_prop_reset(call_info)) {
2151 err = MBTK_RIL_ERR_REQ_UNKNOWN;
2152 LOG("apn_prop_reset() fail.");
2153 } else {
2154 if(req_data_call_start(call_info->cid, call_info->def_route,
2155 call_info->retry_interval, call_info->timeout, &ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2156 {
2157 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2158 err = MBTK_RIL_ERR_CME + cme_err;
2159 } else {
2160 err = MBTK_RIL_ERR_UNKNOWN;
2161 }
2162 LOGD("Start data call fail.");
2163 }
2164 else
2165 {
2166 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t));
2167 }
2168 }
2169 } else if(call_info->type == MBTK_DATA_CALL_STOP) {
2170 if(req_data_call_stop(call_info->cid, call_info->timeout, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2171 {
2172 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2173 err = MBTK_RIL_ERR_CME + cme_err;
2174 } else {
2175 err = MBTK_RIL_ERR_UNKNOWN;
2176 }
2177 LOGD("Stop data call fail.");
2178 }
2179 else
2180 {
2181 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
2182 }
2183 } else {
2184 mbtk_ip_info_t ip_info;
2185 memset(&ip_info, 0, sizeof(ip_info));
2186 if(req_data_call_state_get(call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
2187 {
2188 if(cme_err != MBTK_RIL_ERR_CME_NON) {
2189 err = MBTK_RIL_ERR_CME + cme_err;
2190 } else {
2191 err = MBTK_RIL_ERR_UNKNOWN;
2192 }
2193 LOGD("Get data call state fail.");
2194 }
2195 else
2196 {
2197 ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t));
2198 }
2199 }
2200 }
2201 break;
2202 }
2203 default:
2204 {
2205 err = MBTK_RIL_ERR_REQ_UNKNOWN;
2206 LOG("Unknown request : %s", id2str(pack->msg_id));
2207 break;
2208 }
2209 }
2210
2211 return err;
2212}
2213
2214
2215
2216
2217
2218