blob: 2848bf9e8c52744526a169ae6c2be2831c982d3b [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;
b.liub171c9a2024-11-12 19:23:29 +080026void ril_rsp_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
b.liu87afc4c2024-08-14 17:33:45 +080027
28/*
29AT+COPS=?
30
31+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)
32
33OK
34*/
b.liub171c9a2024-11-12 19:23:29 +080035static int req_available_net_get(ATPortType_enum port, mbtk_net_info_array_t* nets, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +080036{
37 ATResponse *response = NULL;
b.liub171c9a2024-11-12 19:23:29 +080038 int err = at_send_command_singleline(port, "AT+COPS=?", "+COPS:", &response);
b.liu87afc4c2024-08-14 17:33:45 +080039
40 if (err < 0 || response->success == 0 || !response->p_intermediates){
41 if(cme_err) {
42 *cme_err = at_get_cme_error(response);
43 }
44 goto exit;
45 }
46 char *line_ptr = response->p_intermediates->line;
47 if(line_ptr == NULL) {
48 LOG("line is NULL");
49 err = -1;
50 goto exit;
51 }
52 //LOG("Line:%s",line_ptr);
53 line_ptr = strstr(line_ptr, "(");
54 while(line_ptr) {
55 line_ptr++;
56 // Only for available/current net.
57 if(*line_ptr == '1' || *line_ptr == '2' || *line_ptr == '3') {
58 nets->net_info[nets->num].net_state = (uint8)atoi(line_ptr); // net_state
59
60 line_ptr = strstr(line_ptr, ",");
61 if(line_ptr == NULL) {
62 err = -1;
63 goto exit;
64 }
65 line_ptr++;
66
67 line_ptr = strstr(line_ptr, ",");
68 if(line_ptr == NULL) {
69 err = -1;
70 goto exit;
71 }
72 line_ptr++;
73
74 line_ptr = strstr(line_ptr, ",");
75 if(line_ptr == NULL) {
76 err = -1;
77 goto exit;
78 }
79
80 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"'))
81 line_ptr++;
82
83 // set sel_mode to 0
84 nets->net_info[nets->num].net_sel_mode = (uint8)0;
85 // Point to "46000"
86 //LOG("PLMN:%s",line_ptr);
87 //sleep(1);
88 //uint32_2_byte((uint32)atoi(line_ptr), buff_ptr + 3, false); // plmn
89 nets->net_info[nets->num].plmn = (uint32)atoi(line_ptr);
90
91 line_ptr = strstr(line_ptr, ",");
92 if(line_ptr == NULL) {
93 err = -1;
94 goto exit;
95 }
96
97 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' '))
98 line_ptr++;
99
100 // Point to "7"
101 if(*line_ptr == '\0') {
102 err = -1;
103 goto exit;
104 }
105 //LOG("Type:%s",line_ptr);
106 //sleep(1);
107 nets->net_info[nets->num].net_type = (uint8)atoi(line_ptr); // net_type
108
109 nets->num++;
110 }
111
112 line_ptr = strstr(line_ptr, "(");
113 }
114exit:
115 at_response_free(response);
116 return err;
117}
118
119/*
120AT+COPS?
121+COPS: 1
122
123OK
124
125or
126
127AT+COPS?
128+COPS: 0,2,"46001",7
129
130OK
131
132*/
b.liub171c9a2024-11-12 19:23:29 +0800133static int req_net_sel_mode_get(ATPortType_enum port, mbtk_net_info_t *net, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800134{
135 //LOG("req_net_sel_mode_get() 0");
136 //sleep(1);
137 ATResponse *response = NULL;
138 int tmp_int;
139 char *tmp_ptr = NULL;
b.liub171c9a2024-11-12 19:23:29 +0800140 int err = at_send_command_singleline(port, "AT+COPS?", "+COPS:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800141 //LOG("req_net_sel_mode_get() 00");
142 //sleep(1);
143 if (err < 0 || response->success == 0 || !response->p_intermediates){
144 if(cme_err != NULL)
145 *cme_err = at_get_cme_error(response);
146 err = -1;
147 goto exit;
148 }
149 //LOG("req_net_sel_mode_get() 1");
150 //sleep(1);
151 char *line = response->p_intermediates->line;
152 if(line == NULL) {
153 LOG("line is NULL");
154 goto exit;
155 }
156 //LOG("req_net_sel_mode_get() 2");
157 //sleep(1);
158 err = at_tok_start(&line);
159 if (err < 0)
160 {
161 goto exit;
162 }
163 //LOG("req_net_sel_mode_get() 3");
164 //sleep(1);
165 err = at_tok_nextint(&line, &tmp_int);
166 if (err < 0)
167 {
168 goto exit;
169 }
170 net->net_sel_mode = (uint8)tmp_int;
171 //LOG("req_net_sel_mode_get() 4");
172 //sleep(1);
173 // +COPS: 1
174 if(!at_tok_hasmore(&line)) {
175 goto exit;
176 }
177 //LOG("req_net_sel_mode_get() 5");
178 //sleep(1);
179 err = at_tok_nextint(&line, &tmp_int);
180 if (err < 0)
181 {
182 goto exit;
183 }
184 //LOG("req_net_sel_mode_get() 6");
185 //sleep(1);
186 err = at_tok_nextstr(&line, &tmp_ptr);
187 if (err < 0)
188 {
189 goto exit;
190 }
191 // memcpy(net->plmn, tmp_ptr, strlen(tmp_ptr));
192 net->plmn = (uint32)atoi(tmp_ptr);
193 //LOG("req_net_sel_mode_get() 7");
194 //sleep(1);
195 err = at_tok_nextint(&line, &tmp_int);
196 if (err < 0)
197 {
198 goto exit;
199 }
200 net->net_type = (uint8)tmp_int;
201
202 net->net_state = (uint8)MBTK_NET_AVIL_STATE_CURRENT;
203
204exit:
205 //LOG("req_net_sel_mode_get() 8");
206 //sleep(1);
207 at_response_free(response);
208 return err;
209}
210
211/*
212AT+COPS=0
213or
214AT+COPS=1,2,"46000",7
215
216OK
217
218*/
b.liub171c9a2024-11-12 19:23:29 +0800219static int req_net_sel_mode_set(ATPortType_enum port, mbtk_net_info_t* net, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800220{
221 ATResponse *response = NULL;
222 char cmd[50] = {0};
223 char* cmp_ptr = cmd;
224 if(net == NULL) {
225 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
226 } else {
227 if(net->net_sel_mode == 0) {
228 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
229 } else if(net->net_type == 0xFF) {
230 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\"",net->plmn);
231 } else {
232 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\",%d",net->plmn, net->net_type);
233 }
234 }
235
b.liub171c9a2024-11-12 19:23:29 +0800236 int err = at_send_command(port, cmd, &response);
b.liu87afc4c2024-08-14 17:33:45 +0800237
238 if (err < 0 || response->success == 0) {
239 if(cme_err) {
240 *cme_err = at_get_cme_error(response);
241 }
242 goto exit;
243 }
244
245exit:
246 at_response_free(response);
247 return err;
248}
249
250/*
251AT*BAND=15
252OK
253
254*/
b.liu472cfaf2024-12-19 19:08:19 +0800255int req_band_set(ATPortType_enum port, mbtk_band_info_t* band, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800256{
257 ATResponse *response = NULL;
258 char cmd[100] = {0};
259 int err = -1;
260
261 if(band->gsm_band == 0 && band->umts_band == 0
b.liu61ad9172025-01-09 14:33:55 +0800262 && band->tdlte_band == 0 && band->fddlte_band == 0 && band->lte_ext_band == 0
263 && band->nr_3_band == 0 && band->nr_2_band == 0
264 && band->nr_1_band == 0 && band->nr_0_band == 0) {
b.liu87afc4c2024-08-14 17:33:45 +0800265 sprintf(cmd, "AT*BAND=%d", band->net_pref);
266 } else {
267 log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t));
268 log_hex("BAND", band, sizeof(mbtk_band_info_t));
269
270 if(band->gsm_band == 0) {
271 band->gsm_band = band_info.band_support.gsm_band;
272 }
273 if(band->umts_band == 0) {
274 band->umts_band = band_info.band_support.umts_band;
275 }
276 if(band->tdlte_band == 0) {
277 band->tdlte_band = band_info.band_support.tdlte_band;
278 }
279 if(band->fddlte_band == 0) {
280 band->fddlte_band = band_info.band_support.fddlte_band;
281 }
b.liu61ad9172025-01-09 14:33:55 +0800282 if(band->lte_ext_band == 0) {
283 band->lte_ext_band = band_info.band_support.lte_ext_band;
284 }
285 if(band->nr_3_band == 0) {
286 band->nr_3_band = band_info.band_support.nr_3_band;
287 }
288 if(band->nr_2_band == 0) {
289 band->nr_2_band = band_info.band_support.nr_2_band;
290 }
291 if(band->nr_1_band == 0) {
292 band->nr_1_band = band_info.band_support.nr_1_band;
293 }
294 if(band->nr_0_band == 0) {
295 band->nr_0_band = band_info.band_support.nr_0_band;
296 }
b.liu87afc4c2024-08-14 17:33:45 +0800297
298 if((band->gsm_band & band_info.band_support.gsm_band) != band->gsm_band) {
299 LOG("GSM band error.");
300 goto exit;
301 }
302
303 if((band->umts_band & band_info.band_support.umts_band) != band->umts_band) {
304 LOG("UMTS band error.");
305 goto exit;
306 }
307
308 if((band->tdlte_band & band_info.band_support.tdlte_band) != band->tdlte_band) {
309 LOG("TDLTE band error.");
310 goto exit;
311 }
312
313 if((band->fddlte_band & band_info.band_support.fddlte_band) != band->fddlte_band) {
314 LOG("FDDLTE band error.");
315 goto exit;
316 }
317
318 if((band->lte_ext_band & band_info.band_support.lte_ext_band) != band->lte_ext_band) {
319 LOG("EXT_LTE band error.");
320 goto exit;
321 }
322
b.liu61ad9172025-01-09 14:33:55 +0800323 if((band->nr_3_band & band_info.band_support.nr_3_band) != band->nr_3_band) {
324 LOG("nr_3_band band error.");
325 goto exit;
326 }
327
328 if((band->nr_2_band & band_info.band_support.nr_2_band) != band->nr_2_band) {
329 LOG("nr_2_band band error.");
330 goto exit;
331 }
332
333 if((band->nr_1_band & band_info.band_support.nr_1_band) != band->nr_1_band) {
334 LOG("nr_1_band band error.");
335 goto exit;
336 }
337
338 if((band->nr_0_band & band_info.band_support.nr_0_band) != band->nr_0_band) {
339 LOG("nr_0_band band error.");
340 goto exit;
341 }
342
b.liu87afc4c2024-08-14 17:33:45 +0800343 if(band->net_pref == 0xFF) { // No change net_pref.
344 int tmp_int;
b.liub171c9a2024-11-12 19:23:29 +0800345 err = at_send_command_singleline(port, "AT*BAND?", "*BAND:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800346 if (err < 0 || response->success == 0 || !response->p_intermediates){
347 if(cme_err) {
348 *cme_err = at_get_cme_error(response);
349 }
350 goto exit;
351 }
352
353 char *line = response->p_intermediates->line;
354 err = at_tok_start(&line);
355 if (err < 0)
356 {
357 goto exit;
358 }
359
360 err = at_tok_nextint(&line, &tmp_int);
361 if (err < 0)
362 {
363 goto exit;
364 }
365 band->net_pref = (uint8)tmp_int; // Set to current net_pref.
366
367 at_response_free(response);
368 }
b.liuf2ea8bf2025-01-09 15:07:34 +0800369#ifdef MBTK_DEV_INFO_VERSION_2
b.liu61ad9172025-01-09 14:33:55 +0800370 // Only support 4G/5G
371 if(band_info.net_support & MBTK_NET_SUPPORT_5G) {
372 // AT*band=19,0,0,482,134742231,0,24576,256,134217877,0
373 if(band->lte_ext_band > 0) {
374 sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d,%d,%d,%d,%d,0,,,,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band,
375 band->nr_3_band, band->nr_2_band, band->nr_1_band, band->nr_0_band, band->lte_ext_band);
376 } else {
377 sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d,%d,%d,%d,%d,0", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band,
378 band->nr_3_band, band->nr_2_band, band->nr_1_band, band->nr_0_band);
379 }
b.liu87afc4c2024-08-14 17:33:45 +0800380 } else {
b.liu61ad9172025-01-09 14:33:55 +0800381 if(band->lte_ext_band > 0) {
382 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);
383 } else {
384 sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
385 }
b.liu87afc4c2024-08-14 17:33:45 +0800386 }
b.liuf2ea8bf2025-01-09 15:07:34 +0800387#else
388 if(band->lte_ext_band > 0) {
389 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);
390 } else {
391 sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
392 }
393#endif
b.liu87afc4c2024-08-14 17:33:45 +0800394 }
b.liub171c9a2024-11-12 19:23:29 +0800395 err = at_send_command(port, cmd, &response);
b.liu87afc4c2024-08-14 17:33:45 +0800396
397 if (err < 0 || response->success == 0){
398 if(cme_err) {
399 *cme_err = at_get_cme_error(response);
400 }
401 goto exit;
402 }
403
404 err = 0;
405exit:
406 at_response_free(response);
407 return err;
408}
409
410/*
411// ???????
412AT*BAND=?
413*BAND:(0-18),79,147,482,524503
414
415OK
416
417// ???????????
418AT*BAND?
419*BAND: 15, 78, 147, 482, 524503, 0, 2, 2, 0, 0
420
421OK
422
b.liu61ad9172025-01-09 14:33:55 +08004235G :
424*BAND: 19, 0, 0, 482, 149,0, 24576, 256, 134217877, 0, 0, 2, 2, 0
425
426
b.liu87afc4c2024-08-14 17:33:45 +0800427// ?????????
428AT*BAND=5,79,147,128,1
429OK
430
431net_prefferred??
432 0 : GSM only
433 1 : UMTS only
434 2 : GSM/UMTS(auto)
435 3 : GSM/UMTS(GSM preferred)
436 4 : GSM/UMTS(UMTS preferred)
437 5 : LTE only
438 6 : GSM/LTE(auto)
439 7 : GSM/LTE(GSM preferred)
440 8 : GSM/LTE(LTE preferred)
441 9 : UMTS/LTE(auto)
442 10 : UMTS/LTE(UMTS preferred)
443 11 : UMTS/LTE(LTE preferred)
444 12 : GSM/UMTS/LTE(auto)
445 13 : GSM/UMTS/LTE(GSM preferred)
446 14 : GSM/UMTS/LTE(UMTS preferred)
447 15 : GSM/UMTS/LTE(LTE preferred)
448GSM band??
449 1 ?C PGSM 900 (standard or primary)
450 2 ?C DCS GSM 1800
451 4 ?C PCS GSM 1900
452 8 ?C EGSM 900 (extended)
453 16 ?C GSM 450
454 32 ?C GSM 480
455 64 ?C GSM 850
456 512 - BAND_LOCK_BIT // used for GSM band setting
457UMTS band??
458 1 ?C UMTS_BAND_1
459 2 ?C UMTS_BAND_2
460 4 ?C UMTS_BAND_3
461 8 ?C UMTS_BAND_4
462 16 ?C UMTS_BAND_5
463 32 ?C UMTS_BAND_6
464 64 ?C UMTS_BAND_7
465 128 ?C UMTS_BAND_8
466 256 ?C UMTS_BAND_9
467LTEbandH(TDD-LTE band)
468 32 ?C TDLTE_BAND_38
469 64 ?C TDLTE_BAND_39
470 128 ?C TDLTE_BAND_40
471 256 ?C TDLTE_BAND_41
472LTEbandL(FDD-LTE band)
473 1 ?C FDDLTE_BAND_1
474 4 ?C FDDLTE _BAND_3
475 8 ?C FDDLTE _BAND_4
476 64 ?C FDDLTE _BAND_7
477 65536 ?C FDDLTE _BAND_17
478 524288 ?C FDDLTE _BAND_20
479*/
b.liub171c9a2024-11-12 19:23:29 +0800480static int req_band_get(ATPortType_enum port, mbtk_band_info_t *band, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800481{
482 ATResponse *response = NULL;
483 int tmp_int;
484
485 log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t));
b.liub171c9a2024-11-12 19:23:29 +0800486 int err = at_send_command_singleline(port, "AT*BAND?", "*BAND:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800487 if (err < 0 || response->success == 0 || !response->p_intermediates){
488 if(cme_err) {
489 *cme_err = at_get_cme_error(response);
490 }
491 goto exit;
492 }
493
494 char *line = response->p_intermediates->line;
495 err = at_tok_start(&line);
496 if (err < 0)
497 {
498 goto exit;
499 }
500
501 err = at_tok_nextint(&line, &tmp_int);
502 if (err < 0)
503 {
504 goto exit;
505 }
506 band->net_pref = (uint8)tmp_int;
507
508 err = at_tok_nextint(&line, &tmp_int);
509 if (err < 0)
510 {
511 goto exit;
512 }
513 band->gsm_band = (uint16)tmp_int;
514
515 err = at_tok_nextint(&line, &tmp_int);
516 if (err < 0)
517 {
518 goto exit;
519 }
520 band->umts_band = (uint16)tmp_int;
521
522 err = at_tok_nextint(&line, &tmp_int);
523 if (err < 0)
524 {
525 goto exit;
526 }
527 band->tdlte_band = (uint32)tmp_int;
528
529 err = at_tok_nextint(&line, &tmp_int);
530 if (err < 0)
531 {
532 goto exit;
533 }
534 band->fddlte_band = (uint32)tmp_int;
535
b.liuf2ea8bf2025-01-09 15:07:34 +0800536#ifdef MBTK_DEV_INFO_VERSION_2
537 if(band_info.net_support & MBTK_NET_SUPPORT_5G)
538 {
b.liu61ad9172025-01-09 14:33:55 +0800539 err = at_tok_nextint(&line, &tmp_int);
540 if (err < 0)
541 {
542 goto exit;
543 }
544 band->nr_3_band = (uint32)tmp_int;
545
546 err = at_tok_nextint(&line, &tmp_int);
547 if (err < 0)
548 {
549 goto exit;
550 }
551 band->nr_2_band = (uint32)tmp_int;
552
553 err = at_tok_nextint(&line, &tmp_int);
554 if (err < 0)
555 {
556 goto exit;
557 }
558 band->nr_1_band = (uint32)tmp_int;
559
560 err = at_tok_nextint(&line, &tmp_int);
561 if (err < 0)
562 {
563 goto exit;
564 }
565 band->nr_0_band = (uint32)tmp_int;
566 }
b.liuf2ea8bf2025-01-09 15:07:34 +0800567#endif
b.liu61ad9172025-01-09 14:33:55 +0800568
b.liu87afc4c2024-08-14 17:33:45 +0800569 // roamingConfig
570 err = at_tok_nextint(&line, &tmp_int);
571 if (err < 0)
572 {
573 goto exit;
574 }
575
576 // srvDomain
577 err = at_tok_nextint(&line, &tmp_int);
578 if (err < 0)
579 {
580 goto exit;
581 }
582
583 // bandPriorityFlag
584 err = at_tok_nextint(&line, &tmp_int);
585 if (err < 0)
586 {
587 goto exit;
588 }
589
590 //
591 err = at_tok_nextint(&line, &tmp_int);
592 if (err < 0)
593 {
594 goto exit;
595 }
596
597 // ltebandExt
598 err = at_tok_nextint(&line, &tmp_int);
599 if (err < 0)
600 {
601 goto exit;
602 }
603 band->lte_ext_band = (uint32)tmp_int;
604
605 log_hex("BAND", band, sizeof(mbtk_band_info_t));
606
607exit:
608 at_response_free(response);
609 return err;
610}
611
612/*
613AT+CSQ
614+CSQ: 31,99
615
616OK
617
618AT+CESQ
619+CESQ: 60,99,255,255,20,61
620
621OK
622
623AT+COPS?
624+COPS: 0,2,"46001",7
625
626OK
627
628*/
b.liub171c9a2024-11-12 19:23:29 +0800629static int req_net_signal_get(ATPortType_enum port, mbtk_signal_info_t *signal, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800630{
631 ATResponse *response = NULL;
632 int tmp_int;
633 char *tmp_ptr = NULL;
634 // AT+EEMOPT=1 in the first.
b.liub171c9a2024-11-12 19:23:29 +0800635 int err = at_send_command_singleline(port, "AT+CSQ", "+CSQ:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800636 if (err < 0 || response->success == 0 || !response->p_intermediates){
637 if(cme_err != NULL)
638 *cme_err = at_get_cme_error(response);
639 err = -1;
640 goto exit;
641 }
642
643 char *line = response->p_intermediates->line;
644 err = at_tok_start(&line);
645 if (err < 0)
646 {
647 goto exit;
648 }
649 err = at_tok_nextint(&line, &tmp_int);
650 if (err < 0)
651 {
652 goto exit;
653 }
654 signal->rssi = (uint8)tmp_int;
655 at_response_free(response);
656
b.liub171c9a2024-11-12 19:23:29 +0800657 err = at_send_command_singleline(port, "AT+CESQ", "+CESQ:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800658 if (err < 0 || response->success == 0 || !response->p_intermediates){
659 if(cme_err != NULL)
660 *cme_err = at_get_cme_error(response);
661 err = -1;
662 goto exit;
663 }
664
665 line = response->p_intermediates->line;
666 err = at_tok_start(&line);
667 if (err < 0)
668 {
669 goto exit;
670 }
671 err = at_tok_nextint(&line, &tmp_int);
672 if (err < 0)
673 {
674 goto exit;
675 }
676 signal->rxlev = (uint8)tmp_int;
677
678 err = at_tok_nextint(&line, &tmp_int);
679 if (err < 0)
680 {
681 goto exit;
682 }
683 signal->ber = (uint8)tmp_int;
684
685 err = at_tok_nextint(&line, &tmp_int);
686 if (err < 0)
687 {
688 goto exit;
689 }
690 signal->rscp = (uint8)tmp_int;
691
692 err = at_tok_nextint(&line, &tmp_int);
693 if (err < 0)
694 {
695 goto exit;
696 }
697 signal->ecno = (uint8)tmp_int;
698
699 err = at_tok_nextint(&line, &tmp_int);
700 if (err < 0)
701 {
702 goto exit;
703 }
704 signal->rsrq = (uint8)tmp_int;
705
706 err = at_tok_nextint(&line, &tmp_int);
707 if (err < 0)
708 {
709 goto exit;
710 }
711 signal->rsrp = (uint8)tmp_int;
712
713 at_response_free(response);
b.liub171c9a2024-11-12 19:23:29 +0800714 err = at_send_command_singleline(port, "AT+COPS?", "+COPS:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800715 if (err < 0 || response->success == 0 || !response->p_intermediates){
716 if(cme_err != NULL)
717 *cme_err = at_get_cme_error(response);
718 err = -1;
719 goto exit;
720 }
721 line = response->p_intermediates->line;
722 err = at_tok_start(&line);
723 if (err < 0)
724 {
725 goto exit;
726 }
727 err = at_tok_nextint(&line, &tmp_int);
728 if (err < 0)
729 {
730 goto exit;
731 }
732 if(!at_tok_hasmore(&line)) {
733 goto exit;
734 }
735 err = at_tok_nextint(&line, &tmp_int);
736 if (err < 0)
737 {
738 goto exit;
739 }
740 err = at_tok_nextstr(&line, &tmp_ptr);
741 if (err < 0)
742 {
743 goto exit;
744 }
745 err = at_tok_nextint(&line, &tmp_int);
746 if (err < 0)
747 {
748 goto exit;
749 }
750 signal->type = (uint8)tmp_int;
751
752exit:
753 at_response_free(response);
754 return err;
755}
756
757/*
758AT+CREG=3
759OK
760
761AT+CREG?
762+CREG: 3,1,"8330","06447340",7
763
764OK
765
766AT+CREG?
767+CREG: 3,0
768
769OK
770
771AT+CEREG?
772+CEREG: 3,1,"8330","06447340",7
773
774OK
775
776
777AT+CIREG?
778+CIREG: 2,1,15
779
780OK
781
782AT+CIREG?
783+CIREG: 0
784
785OK
786
787
788*/
b.liub171c9a2024-11-12 19:23:29 +0800789static int req_net_reg_get(ATPortType_enum port, mbtk_net_reg_info_t *reg, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800790{
791 ATResponse *response = NULL;
792 int tmp_int;
793 char *tmp_str = NULL;
b.liub171c9a2024-11-12 19:23:29 +0800794 int err = at_send_command(port, "AT+CREG=3", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800795 if (err < 0 || response->success == 0){
796 if(cme_err) {
797 *cme_err = at_get_cme_error(response);
798 }
799 goto exit;
800 }
801 at_response_free(response);
802
b.liub171c9a2024-11-12 19:23:29 +0800803 err = at_send_command_multiline(port, "AT+CREG?", "+CREG:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800804 if (err < 0 || response->success == 0 || !response->p_intermediates){
805 if(cme_err) {
806 *cme_err = at_get_cme_error(response);
807 }
808 goto exit;
809 }
810
811 char *line = response->p_intermediates->line;
812 err = at_tok_start(&line);
813 if (err < 0)
814 {
815 goto exit;
816 }
817 err = at_tok_nextint(&line, &tmp_int); // n
818 if (err < 0)
819 {
820 goto exit;
821 }
822 err = at_tok_nextint(&line, &tmp_int);// stat
823 if (err < 0)
824 {
825 goto exit;
826 }
827 reg->call_state = (uint8)tmp_int;
828
829 if(at_tok_hasmore(&line)) {
830 err = at_tok_nextstr(&line, &tmp_str); // lac
831 if (err < 0)
832 {
833 goto exit;
834 }
835 reg->lac = strtol(tmp_str, NULL, 16);
836
837 err = at_tok_nextstr(&line, &tmp_str); // ci
838 if (err < 0)
839 {
840 goto exit;
841 }
842 reg->ci = strtol(tmp_str, NULL, 16);
843
844 err = at_tok_nextint(&line, &tmp_int);// AcT
845 if (err < 0)
846 {
847 goto exit;
848 }
849 reg->type = (uint8)tmp_int;
850 }
851 at_response_free(response);
852
b.liub171c9a2024-11-12 19:23:29 +0800853 err = at_send_command_multiline(port, "AT+CEREG?", "+CEREG:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800854 if (err < 0 || response->success == 0 || !response->p_intermediates){
855 if(cme_err) {
856 *cme_err = at_get_cme_error(response);
857 }
858 goto exit;
859 }
860
861 line = response->p_intermediates->line;
862 err = at_tok_start(&line);
863 if (err < 0)
864 {
865 goto exit;
866 }
867 err = at_tok_nextint(&line, &tmp_int); // n
868 if (err < 0)
869 {
870 goto exit;
871 }
872 err = at_tok_nextint(&line, &tmp_int);// stat
873 if (err < 0)
874 {
875 goto exit;
876 }
877 reg->data_state = (uint8)tmp_int;
878
879 if(reg->lac == 0 && at_tok_hasmore(&line)) {
880 err = at_tok_nextstr(&line, &tmp_str); // lac
881 if (err < 0)
882 {
883 goto exit;
884 }
885 reg->lac = strtol(tmp_str, NULL, 16);
886
887 err = at_tok_nextstr(&line, &tmp_str); // ci
888 if (err < 0)
889 {
890 goto exit;
891 }
892 reg->ci = strtol(tmp_str, NULL, 16);
893
894 err = at_tok_nextint(&line, &tmp_int);// AcT
895 if (err < 0)
896 {
897 goto exit;
898 }
899 reg->type = (uint8)tmp_int;
900 }
901 at_response_free(response);
902
b.liub171c9a2024-11-12 19:23:29 +0800903 err = at_send_command_multiline(port, "AT+CIREG?", "+CIREG:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800904 if (err < 0 || response->success == 0 || !response->p_intermediates){
905 reg->ims_state = (uint8)0;
906 err = 0;
907 goto exit;
908 }
909 line = response->p_intermediates->line;
910 err = at_tok_start(&line);
911 if (err < 0)
912 {
913 goto exit;
914 }
915 err = at_tok_nextint(&line, &tmp_int); // n/stat
916 if (err < 0)
917 {
918 goto exit;
919 }
920 if(at_tok_hasmore(&line)) {
921 err = at_tok_nextint(&line, &tmp_int);// stat
922 if (err < 0)
923 {
924 goto exit;
925 }
926 reg->ims_state = (uint8)tmp_int;
927 } else {
928 reg->ims_state = (uint8)tmp_int;
929 }
930
931exit:
932 at_response_free(response);
933 return err;
934}
935
936/*
b.liub4772072024-08-15 14:47:03 +0800937AT+EEMOPT=1
938OK
939
940// LTE
941AT+EEMGINFO?
942// <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
943// <rsrp>,<rsrq>, <sinr>,
944// errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
945// cellId,subFrameAssignType,specialSubframePatterns,transMode
946// mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
947// tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
948// dlBer, ulBer,
949// diversitySinr, diversityRssi
950+EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
9510, 0, 0,
9521, 10, 0, 1, 0, 1059, 78, 3959566565,
953105149248, 2, 7, 7,
9540, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
9550, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
9560, 0,
9577, 44
958
959// index,phyCellId,euArfcn,rsrp,rsrq
960+EEMLTEINTER: 0, 65535, 38950, 0, 0
961
962+EEMLTEINTER: 1, 0, 0, 0, 0
963
964+EEMLTEINTER: 2, 0, 4294967295, 255, 255
965
966+EEMLTEINTER: 3, 65535, 1300, 0, 0
967
968+EEMLTEINTER: 4, 0, 0, 0, 0
969
970+EEMLTEINTER: 5, 0, 4294967295, 247, 0
971
972+EEMLTEINTER: 6, 197, 41332, 24, 9
973
974+EEMLTEINTER: 7, 0, 0, 0, 0
975
976+EEMLTEINTER: 8, 0, 0, 0, 0
977
978+EEMLTEINTRA: 0, 429, 40936, 56, 12
979
980+EEMLTEINTERRAT: 0,0
981
982+EEMLTEINTERRAT: 1,0
983
984+EEMGINFO: 3, 2 // <state>:
985 // 0: ME in Idle mode
986 // 1: ME in Dedicated mode
987 // 2: ME in PS PTM mode
988 // 3: invalid state
989 // <nw_type>:
990 // 0: GSM 1: UMTS 2: LTE
991
992OK
993
994// WCDMA
995AT+EEMGINFO?
996// Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
997
998// if sCMeasPresent == 1
999// cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1000// endif
1001
1002// if sCParamPresent == 1
1003// rac, nom, mcc, mnc_len, mnc, lac, ci,
1004// uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1005// csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1006// endif
1007
1008// if ueOpStatusPresent == 1
1009// rrcState, numLinks, srncId, sRnti,
1010// algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1011// HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1012// MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1013// serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1014// endif
1015//
1016+EEMUMTSSVC: 3, 1, 1, 1,
1017-80, 27, -6, -18, -115, -32768,
10181, 1, 1120, 2, 1, 61697, 168432821,
101915, 24, 10763, 0, 0, 0, 0,
1020128, 128, 65535, 0, 0,
10212, 255, 65535, 4294967295,
10220, 0, 0, 0, 0, 0,
10230, 0, 0, 0, 0, 0, 1, 1,
102428672, 28672, 0, 0, 0, 0, 0, 0, 0,
10250, 0, 0, 0, 0, 0
1026
1027// index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1028+EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1029
1030+EEMUMTSINTRA: 1, -1, -32768, -18, -115, 0, 0, 65534, 2, 10763, 40, 32768
1031
1032+EEMUMTSINTRA: 2, -32768, -18, -115, 0, 0, 65534, 3, 10763, 278, 32768, 65535
1033
1034+EEMUMTSINTRA: 3, -18, -115, 0, 0, -2, 4, 10763, 28, 32768, 65535, 32768
1035
1036+EEMUMTSINTRA: 4, -115, 0, 0, -2, 5, 10763, 270, 32768, 65535, 32768, 65518
1037
1038+EEMUMTSINTRA: 5, 0, 0, -2, 6, 10763, 286, 32768, 65535, 32768, 65518, 65421
1039
1040+EEMUMTSINTRA: 6, 0, -2, 7, 10763, 80, 32768, 65535, 32768, 65518, 65421, 0
1041
1042+EEMUMTSINTRA: 7, -2, 8, 10763, 206, -32768, 65535, 32768, 65518, 65421, 0, 0
1043
1044+EEMUMTSINTRA: 8, 9, 10763, 11, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
1045
1046+EEMUMTSINTRA: 9, 10763, 19, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 11
1047
1048+EEMUMTSINTRA: 10, 232, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 12, 10763
1049
1050+EEMUMTSINTRA: 11, -32768, -1, -32768, -18, -115, 0, 0, 65534, 13, 10763, 66
1051
1052+EEMUMTSINTRA: 12, -1, -32768, -18, -115, 0, 0, 65534, 14, 10763, 216, 32768
1053
1054+EEMUMTSINTRA: 13, -32768, -18, -115, 0, 0, 65534, 15, 10763, 183, 32768, 65535
1055
1056+EEMUMTSINTRA: 14, -18, -115, 0, 0, -2, 16, 10763, 165, 32768, 65535, 32768
1057
1058+EEMUMTSINTRA: 15, -115, 0, 0, -2, 17, 10763, 151, 32768, 65535, 32768, 65518
1059
1060+EEMUMTSINTRA: 16, 0, 0, -2, 18, 10763, 43, 32768, 65535, 32768, 65518, 65421
1061
1062+EEMUMTSINTRA: 17, 0, -2, 19, 10763, 72, 32768, 65535, 32768, 65518, 65421, 0
1063
1064+EEMUMTSINTRA: 18, -2, 20, 10763, 157, -32768, 65535, 32768, 65518, 65421, 0, 0
1065
1066+EEMUMTSINTRA: 19, 21, 10763, 165, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
1067
1068+EEMUMTSINTRA: 20, 10763, 301, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 23
1069
1070+EEMUMTSINTRA: 21, 23, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 24, 10763
1071
1072+EEMUMTSINTRA: 22, -32768, -1, -32768, -18, -115, 0, 0, 65534, 25, 10763, 0
1073
1074+EEMUMTSINTRA: 23, -1, -32768, -18, -115, 0, 0, 65534, 26, 10763, 167, 32768
1075
1076+EEMUMTSINTRA: 24, -32768, -18, -115, 0, 0, 65534, 27, 10763, 34, 32768, 65535
1077
1078+EEMUMTSINTRA: 25, -18, -115, 0, 0, -2, 28, 10763, 313, 32768, 65535, 32768
1079
1080+EEMUMTSINTRA: 26, -115, 0, 0, -2, 29, 10763, 152, 32768, 65535, 32768, 65518
1081
1082+EEMUMTSINTRA: 27, 0, 0, -2, 30, 10763, 239, 0, 0, 0, 0, 0
1083
1084+EEMUMTSINTRA: 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1085
1086+EEMUMTSINTRA: 29, 0, 0, 0, 0, -115, 0, 0, 65534, 30, 10763, 239
1087
1088// index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1089+EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1090
1091+EEMUMTSINTERRAT: 1, -107, -1, -1, 0, 0, 65534, 1, 72, 49, 0
1092
1093+EEMUMTSINTERRAT: 2, -1, -1, 0, 0, 65534, 2, 119, 15, 32768, 149
1094
1095+EEMUMTSINTERRAT: 3, -1, 0, 0, -2, 3, 121, 23, 0, 0, 0
1096
1097+EEMGINFO: 3, 1
1098
1099OK
1100
1101
1102// GSM
1103AT+EEMGINFO?
1104+EEMGINFOBASIC: 2
1105
1106// mcc, mnc_len, mnc, lac, ci, nom, nco,
1107// bsic, C1, C2, TA, TxPwr,
1108// RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1109// ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1110// bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1111// ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1112// gsmBand,channelMode
1113+EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
111463, 36, 146, 1, 7,
111546, 42, 42, 7, 0,
111653, 0, 8, 0, 1, 6, 53,
11172, 0, 146, 42, 54, 0, 1,
11181, 32, 0, 0, 0, 0,
11190, 0
1120
1121// PS_attached, attach_type, service_type, tx_power, c_value,
1122// ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1123// gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1124// pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1125+EEMGINFOPS: 1, 255, 0, 0, 0,
11260, 0, 268435501, 1, 0, 0,
11274, 0, 96, 0, 0, 0,
11280, 0, 0, 65535, 0, 13350
1129
1130+EEMGINFO: 0, 0
1131
1132OK
1133
1134*/
b.liub171c9a2024-11-12 19:23:29 +08001135static int req_cell_info_get(ATPortType_enum port, int *cme_err)
b.liub4772072024-08-15 14:47:03 +08001136{
1137 ATResponse *response = NULL;
1138 int tmp_int;
1139 int buff_size = 0;
1140 // AT+EEMOPT=1 in the first.
b.liub171c9a2024-11-12 19:23:29 +08001141 int err = at_send_command(port, "AT+EEMOPT=1", &response);
b.liub4772072024-08-15 14:47:03 +08001142 if (err < 0 || response->success == 0){
1143 *cme_err = at_get_cme_error(response);
1144 goto exit;
1145 }
1146
1147 // Reset buffer in the first.
1148 memset(&cell_info, 0xFF, sizeof(mbtK_cell_pack_info_t));
1149 cell_info.running = true;
1150 cell_info.cell_list.num = 0;
1151
b.liub171c9a2024-11-12 19:23:29 +08001152 err = at_send_command_singleline(port, "AT+EEMGINFO?", "+EEMGINFO:", &response);
b.liub4772072024-08-15 14:47:03 +08001153 if (err < 0 || response->success == 0 || !response->p_intermediates){
1154 *cme_err = at_get_cme_error(response);
1155 goto exit;
1156 }
1157
1158 // Now, cell infomation has get from URC message.
1159
1160 char *line = response->p_intermediates->line;
1161 err = at_tok_start(&line);
1162 if (err < 0)
1163 {
1164 goto exit;
1165 }
1166 err = at_tok_nextint(&line, &tmp_int);
1167 if (err < 0)
1168 {
1169 goto exit;
1170 }
1171 err = at_tok_nextint(&line, &tmp_int);
1172 if (err < 0)
1173 {
1174 goto exit;
1175 }
1176
1177 cell_info.cell_list.type = (uint8)tmp_int;
1178 cell_info.running = false;
1179
1180#if 0
1181 while(lines_ptr)
1182 {
1183 // LTE
1184 if(strStartsWith(line, "+EEMLTESVC:")) // LTE Server Cell
1185 {
1186
1187 }
1188 else if(strStartsWith(line, "+EEMLTEINTER:")) // LTE
1189 {
1190
1191 }
1192 else if(strStartsWith(line, "+EEMLTEINTRA:")) // LTE
1193 {
1194
1195 }
1196 else if(strStartsWith(line, "+EEMLTEINTERRAT:")) // LTE
1197 {
1198
1199 }
1200 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
1201 // <nw_type>: 0: GSM 1: UMTS 2: LTE
1202 {
1203
1204 }
1205 // WCDMA
1206 else if(strStartsWith(line, "+EEMUMTSSVC:")) // WCDMA Server Cell
1207 {
1208
1209 }
1210 else if(strStartsWith(line, "+EEMUMTSINTRA:")) // WCDMA
1211 {
1212
1213 }
1214 else if(strStartsWith(line, "+EEMUMTSINTERRAT:")) // WCDMA
1215 {
1216
1217 }
1218 // GSM
1219 else if(strStartsWith(line, "+EEMGINFOBASIC:")) // Basic information in GSM
1220 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1221 {
1222
1223 }
1224 else if(strStartsWith(line, "+EEMGINFOSVC:")) // GSM Server Cell
1225 {
1226
1227 }
1228 else if(strStartsWith(line, "+EEMGINFOPS:")) // PS
1229 {
1230
1231 }
1232
1233
1234 lines_ptr = lines_ptr->p_next;
1235 }
1236#endif
1237
1238exit:
1239 at_response_free(response);
1240 return buff_size;
1241}
1242
b.liub171c9a2024-11-12 19:23:29 +08001243static int req_cell_info_set(ATPortType_enum port, const char *cmgl, char *reg, int len, int *cme_err)
b.liub4772072024-08-15 14:47:03 +08001244{
1245 ATResponse *response = NULL;
b.liu62240ee2024-11-07 17:52:45 +08001246 char cmd[500] = {0};
b.liub4772072024-08-15 14:47:03 +08001247 char data[218] = {0};
1248 int err = 0;
1249
1250 memcpy(data, cmgl, len);
1251
1252 sprintf(cmd, "AT*CELL=%s", data);
1253
1254 if(strlen(cmd) > 0)
1255 {
b.liub171c9a2024-11-12 19:23:29 +08001256 err = at_send_command_multiline(port, cmd, "", &response);
b.liub4772072024-08-15 14:47:03 +08001257 if (err < 0 || response->success == 0 || !response->p_intermediates){
1258 *cme_err = at_get_cme_error(response);
1259 goto exit;
1260 }
1261
1262 ATLine* lines_ptr = response->p_intermediates;
1263 char *line = NULL;
b.liu62240ee2024-11-07 17:52:45 +08001264// int reg_len = 0;
1265// bool flag = false;
b.liub4772072024-08-15 14:47:03 +08001266 while(lines_ptr)
1267 {
1268 line = lines_ptr->line;
1269 if(line ==NULL)
1270 {
1271 LOGD("line is null----------------------");
1272 }
1273 lines_ptr = lines_ptr->p_next;
1274 }
1275 }
1276 err = 0;
1277 memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss"));
1278exit:
1279 at_response_free(response);
1280 return err;
1281}
1282
b.liu557c81d2024-11-19 16:52:45 +08001283/*
1284AT+OOSPP=1
1285or
1286AT+OOSPP=0
1287or
1288AT+OOSPP=1,20,30,40 //AtOospp()
1289 param1£ºmode
1290 param2£ºoosPhasePeriod[0] //5 times, 5s by default;
1291 param3£ºoosPhasePeriod[1] //5 times, 10s by default;
1292 param4£ºoosPhasePeriod[2] //unlimited, 20s by default;
1293
1294
1295BTW
12961, Èç¹ûÖ»ÊäÈëmode=1£¬ÆäÓà²ÎÊý²»ÉèÖã¬Ï൱ÓÚÕâ¸ö¹¦ÄÜ´ò¿ª£¬Ê±¼ä¼ä¸ôÊÇÕâ¸ö¹¦ÄܵÄĬÈÏÖµ¡£
12972, Èç¹ûµ±mode=1¼ÓÉÏÆäÓàÉèÖòÎÊýºó£¬¹¦ÄÜ´ò¿ª£¬Ê±¼ä¼ä¸ôÊDZ¾´ÎÉèÖõÄÖµ£»
12983£¬Èç¹ûÔÙÉèÖÃmode=0£¬Ï൱ÓÚÕâ¸ö¹¦Äܹرգ¬ÊÇ×߯½Ì¨×Ô¼ºÁíÒ»Ì×µÄËÑÍøÉèÖá£
1299ƽ̨±¾ÉíÊÇÓÐÒ»Ì×¼ä¸ôËÑÍø£¬Ò²ÓÐÀúʷƵµãÓÅÏÈ´¦ÀíµÄÂß¼­£¨²»ÐèÒªÎÒÃǽøÐд¦Àí£©£¬
1300Ìṩ¸øÎÒÃǵÄAT+OOSPPÖ¸ÁîÊÇÈÃÎÒÃÇ¿ÉÒÔ×Ô¶¨ÒåËÑÍø¼ä¸ô
1301*/
1302static int req_oos_set(ATPortType_enum port, const mbtk_ril_oos_info_t* oos_info, int *cme_err)
1303{
1304 ATResponse *response = NULL;
1305 char cmd[100] = {0};
1306 int err = 0;
1307
1308 if ((oos_info->state == 1 && oos_info->oosPhase[0] == 0 && oos_info->oosPhase[1] == 0 && oos_info->oosPhase[2] == 0) \
1309 || oos_info->state == 0)
1310 {
1311 sprintf(cmd, "AT+OOSPP=%d", oos_info->state);//Ö»ÓÐÒ»¸öÖµ0/1
1312 }
1313 else
1314 {
1315 if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] != 0) && (oos_info->oosPhase[2] != 0))
1316 {
1317 sprintf(cmd, "AT+OOSPP=%d,%d,%d,%d", oos_info->state, oos_info->oosPhase[0], oos_info->oosPhase[1], oos_info->oosPhase[2]);
1318 }
1319 else if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] != 0) && (oos_info->oosPhase[2] == 0))
1320 {
1321 sprintf(cmd, "AT+OOSPP=%d,%d,%d", oos_info->state, oos_info->oosPhase[0], oos_info->oosPhase[1]);
1322 }
1323 else if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] == 0) && (oos_info->oosPhase[2] == 0))
1324 {
1325 sprintf(cmd, "AT+OOSPP=%d,%d", oos_info->state, oos_info->oosPhase[0]);
1326 }
1327 else
1328 {
1329 LOGE("AT+OOSPP SET ERR");
1330 goto exit;
1331 }
1332 }
1333
1334 LOGI("Set the oos command is = [%s]\n", cmd);
1335 err = at_send_command(port, cmd, &response);
1336 if (err < 0 || response->success == 0){
1337 *cme_err = at_get_cme_error(response);
1338 goto exit;
1339 }
1340
1341exit:
1342 at_response_free(response);
1343 return err;
1344}
1345
1346/*
1347AT+OOSPP?
1348¿ª(ĬÈÏÖµ)£º
1349+OOSPP:5,10,20
1350¹Ø£º
1351+OOSPP:0
1352*/
1353static int req_oos_get(ATPortType_enum port, mbtk_ril_oos_info_t *oos_info, int *cme_err)
1354{
1355 ATResponse *response = NULL;
1356
1357 int err = at_send_command_singleline(port, "AT+OOSPP?", "+OOSPP:", &response);
1358
1359 if (err < 0 || response->success == 0 || !response->p_intermediates){
1360 *cme_err = at_get_cme_error(response);
1361 goto exit;
1362 }
1363
1364 char *line = response->p_intermediates->line;
1365
1366 char *tmp_str = NULL;
1367 err = at_tok_start(&line);//+OOSPP:10,15,20,¹ýÂË+OOSPP:
1368 if (err < 0)
1369 {
1370 goto exit;
1371 }
1372
1373 //LOG("req_oos_get =[%s]",line);
1374
1375 err = at_tok_nextstr(&line, &tmp_str);
1376 if (err < 0)
1377 {
1378 goto exit;
1379 }
1380
1381 int mode = atoi(tmp_str);
1382 if (mode == 0)//¹Ø±Õ״̬
1383 {
1384 oos_info->state = mode;
1385 }
1386 else//¿ª×´Ì¬
1387 {
1388 oos_info->state = 1;
1389 //LOG("tmp_str =[%s]",tmp_str);
1390 oos_info->oosPhase[0] = atoi(tmp_str);
1391
1392 err = at_tok_nextstr(&line, &tmp_str);
1393 if (err < 0)
1394 {
1395 goto exit;
1396 }
1397 //LOG("tmp_str =[%s]",tmp_str);
1398 oos_info->oosPhase[1] = atoi(tmp_str);
1399
1400 err = at_tok_nextstr(&line, &tmp_str);
1401 if (err < 0)
1402 {
1403 goto exit;
1404 }
1405 //LOG("tmp_str =[%s]",tmp_str);
1406 oos_info->oosPhase[2] = atoi(tmp_str);
1407 }
1408
1409exit:
1410 at_response_free(response);
1411 return err;
1412}
1413
b.liu87afc4c2024-08-14 17:33:45 +08001414//void net_list_free(void *data);
1415// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
1416// Otherwise, do not call pack_error_send().
1417mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
1418{
1419 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
1420 int cme_err = MBTK_RIL_ERR_CME_NON;
1421 switch(pack->msg_id)
1422 {
1423 case RIL_MSG_ID_NET_AVAILABLE:
1424 {
1425 if(pack->data_len == 0 || pack->data == NULL)
1426 {
1427 mbtk_net_info_array_t net_array;
1428 memset(&net_array, 0, sizeof(mbtk_net_info_array_t));
b.liub171c9a2024-11-12 19:23:29 +08001429 if(req_available_net_get(cli_info->port, &net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001430 {
1431 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1432 err = MBTK_RIL_ERR_CME + cme_err;
1433 } else {
1434 err = MBTK_RIL_ERR_UNKNOWN;
1435 }
1436 LOGD("Get Available Net fail.");
1437 }
1438 else
1439 {
b.liub171c9a2024-11-12 19:23:29 +08001440 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t));
b.liu87afc4c2024-08-14 17:33:45 +08001441 }
1442 }
1443 else // Set
1444 {
1445 err = MBTK_RIL_ERR_UNSUPPORTED;
1446 LOGW("Unsupport set available net.");
1447 }
1448 break;
1449 }
1450 case RIL_MSG_ID_NET_SEL_MODE:
1451 {
1452 if(pack->data_len == 0 || pack->data == NULL)
1453 {
1454 mbtk_net_info_t info;
1455 memset(&info, 0, sizeof(mbtk_net_info_t));
b.liub171c9a2024-11-12 19:23:29 +08001456 if(req_net_sel_mode_get(cli_info->port, &info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001457 {
1458 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1459 err = MBTK_RIL_ERR_CME + cme_err;
1460 } else {
1461 err = MBTK_RIL_ERR_UNKNOWN;
1462 }
1463 LOGD("Get Net sel mode fail.");
1464 }
1465 else
1466 {
b.liub171c9a2024-11-12 19:23:29 +08001467 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t));
b.liu87afc4c2024-08-14 17:33:45 +08001468 }
1469 }
1470 else // Set
1471 {
1472 mbtk_net_info_t *info = (mbtk_net_info_t*)pack->data;
b.liub171c9a2024-11-12 19:23:29 +08001473 if(req_net_sel_mode_set(cli_info->port, info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001474 {
1475 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1476 err = MBTK_RIL_ERR_CME + cme_err;
1477 } else {
1478 err = MBTK_RIL_ERR_UNKNOWN;
1479 }
1480 LOGD("Set Net sel mode fail.");
1481 }
1482 else
1483 {
b.liub171c9a2024-11-12 19:23:29 +08001484 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +08001485 }
1486 }
1487 break;
1488 }
1489 case RIL_MSG_ID_NET_BAND:
1490 {
1491 if(pack->data_len == 0 || pack->data == NULL)
1492 {
1493 err = MBTK_RIL_ERR_REQ_PARAMETER;
1494 LOG("No data found.");
1495 }
1496 else // Set
1497 {
1498 if(pack->data_len == sizeof(uint8)) {
1499 if(*(pack->data)) { // Get current bands.
1500 mbtk_band_info_t band;
1501 memset(&band, 0x0, sizeof(mbtk_band_info_t));
b.liub171c9a2024-11-12 19:23:29 +08001502 if(req_band_get(cli_info->port, &band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001503 {
1504 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1505 err = MBTK_RIL_ERR_CME + cme_err;
1506 } else {
1507 err = MBTK_RIL_ERR_UNKNOWN;
1508 }
1509 LOG("Get net band fail.");
1510 }
1511 else
1512 {
b.liub171c9a2024-11-12 19:23:29 +08001513 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t));
b.liu87afc4c2024-08-14 17:33:45 +08001514 }
1515 } else { // Get support bands.
b.liub171c9a2024-11-12 19:23:29 +08001516 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band_info.band_support , sizeof(mbtk_band_info_t));
b.liu87afc4c2024-08-14 17:33:45 +08001517 }
1518 } else { // Set current bands.
1519 mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data;
1520 if(pack->data_len != sizeof(mbtk_band_info_t))
1521 {
1522 err = MBTK_RIL_ERR_REQ_PARAMETER;
1523 LOG("Set net band error.");
1524 break;
1525 }
1526
b.liub171c9a2024-11-12 19:23:29 +08001527 if(req_band_set(cli_info->port, band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001528 {
1529 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1530 err = MBTK_RIL_ERR_CME + cme_err;
1531 } else {
1532 err = MBTK_RIL_ERR_UNKNOWN;
1533 }
1534 LOG("Set net band fail.");
1535 }
1536 else
1537 {
b.liub171c9a2024-11-12 19:23:29 +08001538 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +08001539 }
1540 }
1541 }
1542 break;
1543 }
1544 case RIL_MSG_ID_NET_SIGNAL:
1545 {
1546 if(pack->data_len == 0 || pack->data == NULL)
1547 {
1548 mbtk_signal_info_t signal;
1549 memset(&signal, 0, sizeof(mbtk_signal_info_t));
b.liub171c9a2024-11-12 19:23:29 +08001550 if(req_net_signal_get(cli_info->port, &signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001551 {
1552 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1553 err = MBTK_RIL_ERR_CME + cme_err;
1554 } else {
1555 err = MBTK_RIL_ERR_UNKNOWN;
1556 }
1557 LOGD("Get net signal fail.");
1558 }
1559 else
1560 {
b.liub171c9a2024-11-12 19:23:29 +08001561 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t));
b.liu87afc4c2024-08-14 17:33:45 +08001562 }
1563 }
1564 else // Set
1565 {
1566 err = MBTK_RIL_ERR_UNSUPPORTED;
1567 LOGW("Unsupport set net signal.");
1568 }
1569 break;
1570 }
1571 case RIL_MSG_ID_NET_REG:
1572 {
1573 if(pack->data_len == 0 || pack->data == NULL)
1574 {
1575 mbtk_net_reg_info_t net_reg;
1576 memset(&net_reg, 0, sizeof(mbtk_net_reg_info_t));
b.liub171c9a2024-11-12 19:23:29 +08001577 if(req_net_reg_get(cli_info->port, &net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001578 {
1579 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1580 err = MBTK_RIL_ERR_CME + cme_err;
1581 } else {
1582 err = MBTK_RIL_ERR_UNKNOWN;
1583 }
1584 LOGD("Get Net reg info fail.");
1585 }
1586 else
1587 {
b.liub171c9a2024-11-12 19:23:29 +08001588 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &net_reg, sizeof(mbtk_net_reg_info_t));
b.liu87afc4c2024-08-14 17:33:45 +08001589 }
1590 }
1591 else // Set
1592 {
1593 err = MBTK_RIL_ERR_UNSUPPORTED;
1594 LOGW("Unsupport set net reg info.");
1595 }
1596 break;
1597 }
1598 case RIL_MSG_ID_NET_CELL:
1599 {
b.liub4772072024-08-15 14:47:03 +08001600 if(pack->data_len == 0 || pack->data == NULL) // Get net cell.
b.liu87afc4c2024-08-14 17:33:45 +08001601 {
b.liub171c9a2024-11-12 19:23:29 +08001602 if(req_cell_info_get(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001603 {
1604 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1605 err = MBTK_RIL_ERR_CME + cme_err;
1606 } else {
1607 err = MBTK_RIL_ERR_UNKNOWN;
1608 }
b.liub4772072024-08-15 14:47:03 +08001609 LOG("Get net cell fail.");
b.liu87afc4c2024-08-14 17:33:45 +08001610 }
1611 else
1612 {
b.liub4772072024-08-15 14:47:03 +08001613 LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_list.num);
b.liub171c9a2024-11-12 19:23:29 +08001614 ril_rsp_pack_send(cli_info->port, 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 +08001615 }
1616 }
b.liub4772072024-08-15 14:47:03 +08001617 else // Lock cell
b.liu87afc4c2024-08-14 17:33:45 +08001618 {
b.liub4772072024-08-15 14:47:03 +08001619 char *mem = (char*)(pack->data);
1620 int len = pack->data_len;
1621 char reg[100] = {0};
b.liub171c9a2024-11-12 19:23:29 +08001622 if(req_cell_info_set(cli_info->port, mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liub4772072024-08-15 14:47:03 +08001623 {
1624 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1625 err = MBTK_RIL_ERR_CME + cme_err;
1626 } else {
1627 err = MBTK_RIL_ERR_UNKNOWN;
1628 }
1629 }
1630 else
1631 {
b.liub171c9a2024-11-12 19:23:29 +08001632 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
b.liub4772072024-08-15 14:47:03 +08001633 }
b.liu87afc4c2024-08-14 17:33:45 +08001634 }
1635 break;
1636 }
b.liu557c81d2024-11-19 16:52:45 +08001637 case RIL_MSG_ID_NET_OOS:
1638 {
1639 if(pack->data_len == 0 || pack->data == NULL) // Get net oos.
1640 {
1641 mbtk_ril_oos_info_t oos_info;
1642 memset(&oos_info, 0, sizeof(mbtk_ril_oos_info_t));
1643 if(req_oos_get(cli_info->port, &oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1644 {
1645 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1646 err = MBTK_RIL_ERR_CME + cme_err;
1647 } else {
1648 err = MBTK_RIL_ERR_UNKNOWN;
1649 }
1650 LOG("Get net oos fail.");
1651 }
1652 else
1653 {
1654 LOG("req_oos_get() success,cell number: %d", oos_info.state);
1655 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &oos_info, sizeof(mbtk_ril_oos_info_t));
1656 }
1657 }
1658 else // Set net oos.
1659 {
1660 mbtk_ril_oos_info_t *oos_info = (mbtk_ril_oos_info_t*)(pack->data);
1661 if(req_oos_set(cli_info->port, oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
1662 {
1663 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1664 err = MBTK_RIL_ERR_CME + cme_err;
1665 } else {
1666 err = MBTK_RIL_ERR_UNKNOWN;
1667 }
1668 }
1669 else
1670 {
1671 ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
1672 }
1673 }
1674 break;
1675 }
b.liu87afc4c2024-08-14 17:33:45 +08001676 default:
1677 {
1678 err = MBTK_RIL_ERR_REQ_UNKNOWN;
1679 LOG("Unknown request : %s", id2str(pack->msg_id));
1680 break;
1681 }
1682 }
1683
1684 return err;
1685}
1686