blob: 427c535675ee86d9715f8eb953c1b9a51b84a98c [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.liu7ca612c2025-04-25 09:23:36 +080026void ril_rsp_pack_send(mbtk_sim_type_enum sim_id, ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len);
27ATPortId_enum portType_2_portId(mbtk_sim_type_enum sim_id, ATPortType_enum port);
28
b.liu87afc4c2024-08-14 17:33:45 +080029
b.liubeb61cc2025-02-13 10:38:29 +080030static bool net_support_check(uint32 net_type, uint32 net_flag)
31{
b.liubeb61cc2025-02-13 10:38:29 +080032 return (net_type & net_flag);
b.liubeb61cc2025-02-13 10:38:29 +080033}
34
b.liu87afc4c2024-08-14 17:33:45 +080035/*
36AT+COPS=?
37
38+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)
39
40OK
41*/
b.liu7ca612c2025-04-25 09:23:36 +080042static int req_available_net_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_net_info_array_t* nets, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +080043{
44 ATResponse *response = NULL;
b.liu7ca612c2025-04-25 09:23:36 +080045 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+COPS=?", "+COPS:", &response);
b.liu87afc4c2024-08-14 17:33:45 +080046
47 if (err < 0 || response->success == 0 || !response->p_intermediates){
48 if(cme_err) {
49 *cme_err = at_get_cme_error(response);
50 }
51 goto exit;
52 }
53 char *line_ptr = response->p_intermediates->line;
54 if(line_ptr == NULL) {
55 LOG("line is NULL");
56 err = -1;
57 goto exit;
58 }
59 //LOG("Line:%s",line_ptr);
60 line_ptr = strstr(line_ptr, "(");
61 while(line_ptr) {
62 line_ptr++;
63 // Only for available/current net.
64 if(*line_ptr == '1' || *line_ptr == '2' || *line_ptr == '3') {
65 nets->net_info[nets->num].net_state = (uint8)atoi(line_ptr); // net_state
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 line_ptr++;
80
81 line_ptr = strstr(line_ptr, ",");
82 if(line_ptr == NULL) {
83 err = -1;
84 goto exit;
85 }
86
87 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"'))
88 line_ptr++;
89
90 // set sel_mode to 0
91 nets->net_info[nets->num].net_sel_mode = (uint8)0;
92 // Point to "46000"
93 //LOG("PLMN:%s",line_ptr);
94 //sleep(1);
95 //uint32_2_byte((uint32)atoi(line_ptr), buff_ptr + 3, false); // plmn
96 nets->net_info[nets->num].plmn = (uint32)atoi(line_ptr);
97
98 line_ptr = strstr(line_ptr, ",");
99 if(line_ptr == NULL) {
100 err = -1;
101 goto exit;
102 }
103
104 while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' '))
105 line_ptr++;
106
107 // Point to "7"
108 if(*line_ptr == '\0') {
109 err = -1;
110 goto exit;
111 }
112 //LOG("Type:%s",line_ptr);
113 //sleep(1);
114 nets->net_info[nets->num].net_type = (uint8)atoi(line_ptr); // net_type
115
116 nets->num++;
117 }
118
119 line_ptr = strstr(line_ptr, "(");
120 }
121exit:
122 at_response_free(response);
123 return err;
124}
125
126/*
127AT+COPS?
128+COPS: 1
129
130OK
131
132or
133
134AT+COPS?
135+COPS: 0,2,"46001",7
136
137OK
138
139*/
b.liu7ca612c2025-04-25 09:23:36 +0800140static int req_net_sel_mode_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_net_info_t *net, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800141{
142 //LOG("req_net_sel_mode_get() 0");
143 //sleep(1);
144 ATResponse *response = NULL;
145 int tmp_int;
146 char *tmp_ptr = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800147 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+COPS?", "+COPS:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800148 //LOG("req_net_sel_mode_get() 00");
149 //sleep(1);
150 if (err < 0 || response->success == 0 || !response->p_intermediates){
151 if(cme_err != NULL)
152 *cme_err = at_get_cme_error(response);
153 err = -1;
154 goto exit;
155 }
156 //LOG("req_net_sel_mode_get() 1");
157 //sleep(1);
158 char *line = response->p_intermediates->line;
159 if(line == NULL) {
160 LOG("line is NULL");
161 goto exit;
162 }
163 //LOG("req_net_sel_mode_get() 2");
164 //sleep(1);
165 err = at_tok_start(&line);
166 if (err < 0)
167 {
168 goto exit;
169 }
170 //LOG("req_net_sel_mode_get() 3");
171 //sleep(1);
172 err = at_tok_nextint(&line, &tmp_int);
173 if (err < 0)
174 {
175 goto exit;
176 }
177 net->net_sel_mode = (uint8)tmp_int;
178 //LOG("req_net_sel_mode_get() 4");
179 //sleep(1);
180 // +COPS: 1
181 if(!at_tok_hasmore(&line)) {
182 goto exit;
183 }
184 //LOG("req_net_sel_mode_get() 5");
185 //sleep(1);
186 err = at_tok_nextint(&line, &tmp_int);
187 if (err < 0)
188 {
189 goto exit;
190 }
191 //LOG("req_net_sel_mode_get() 6");
192 //sleep(1);
193 err = at_tok_nextstr(&line, &tmp_ptr);
194 if (err < 0)
195 {
196 goto exit;
197 }
198 // memcpy(net->plmn, tmp_ptr, strlen(tmp_ptr));
199 net->plmn = (uint32)atoi(tmp_ptr);
200 //LOG("req_net_sel_mode_get() 7");
201 //sleep(1);
202 err = at_tok_nextint(&line, &tmp_int);
203 if (err < 0)
204 {
205 goto exit;
206 }
207 net->net_type = (uint8)tmp_int;
208
209 net->net_state = (uint8)MBTK_NET_AVIL_STATE_CURRENT;
210
211exit:
212 //LOG("req_net_sel_mode_get() 8");
213 //sleep(1);
214 at_response_free(response);
215 return err;
216}
217
218/*
219AT+COPS=0
220or
221AT+COPS=1,2,"46000",7
222
223OK
224
225*/
b.liu7ca612c2025-04-25 09:23:36 +0800226static int req_net_sel_mode_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_net_info_t* net, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800227{
228 ATResponse *response = NULL;
229 char cmd[50] = {0};
230 char* cmp_ptr = cmd;
231 if(net == NULL) {
232 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
233 } else {
234 if(net->net_sel_mode == 0) {
235 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0");
236 } else if(net->net_type == 0xFF) {
237 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\"",net->plmn);
238 } else {
239 cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\",%d",net->plmn, net->net_type);
240 }
241 }
242
b.liu7ca612c2025-04-25 09:23:36 +0800243 int err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu87afc4c2024-08-14 17:33:45 +0800244
245 if (err < 0 || response->success == 0) {
246 if(cme_err) {
247 *cme_err = at_get_cme_error(response);
248 }
249 goto exit;
250 }
251
252exit:
253 at_response_free(response);
254 return err;
255}
256
257/*
258AT*BAND=15
259OK
260
261*/
b.liu7ca612c2025-04-25 09:23:36 +0800262int req_band_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t* band, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800263{
264 ATResponse *response = NULL;
265 char cmd[100] = {0};
266 int err = -1;
267
268 if(band->gsm_band == 0 && band->umts_band == 0
b.liu61ad9172025-01-09 14:33:55 +0800269 && band->tdlte_band == 0 && band->fddlte_band == 0 && band->lte_ext_band == 0
270 && band->nr_3_band == 0 && band->nr_2_band == 0
b.liubea31eb2025-01-09 15:17:12 +0800271 && band->nr_1_band == 0 && band->nr_0_band == 0
b.liubea31eb2025-01-09 15:17:12 +0800272 ) {
b.liu87afc4c2024-08-14 17:33:45 +0800273 sprintf(cmd, "AT*BAND=%d", band->net_pref);
274 } else {
275 log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t));
276 log_hex("BAND", band, sizeof(mbtk_band_info_t));
277
b.liubeb61cc2025-02-13 10:38:29 +0800278 if(band->gsm_band == 0 && net_support_check(band_info.net_support, MBTK_NET_SUPPORT_2G)) {
b.liu87afc4c2024-08-14 17:33:45 +0800279 band->gsm_band = band_info.band_support.gsm_band;
280 }
b.liubeb61cc2025-02-13 10:38:29 +0800281 if(band->umts_band == 0 && net_support_check(band_info.net_support, MBTK_NET_SUPPORT_3G)) {
b.liu87afc4c2024-08-14 17:33:45 +0800282 band->umts_band = band_info.band_support.umts_band;
283 }
b.liubeb61cc2025-02-13 10:38:29 +0800284
285 if(net_support_check(band_info.net_support, MBTK_NET_SUPPORT_4G)) {
286 if(band->tdlte_band == 0) {
287 band->tdlte_band = band_info.band_support.tdlte_band;
288 }
289 if(band->fddlte_band == 0) {
290 band->fddlte_band = band_info.band_support.fddlte_band;
291 }
292 if(band->lte_ext_band == 0) {
293 band->lte_ext_band = band_info.band_support.lte_ext_band;
294 }
b.liu87afc4c2024-08-14 17:33:45 +0800295 }
b.liubeb61cc2025-02-13 10:38:29 +0800296
297 if(net_support_check(band_info.net_support, MBTK_NET_SUPPORT_5G)) {
298 if(band->nr_3_band == 0) {
299 band->nr_3_band = band_info.band_support.nr_3_band;
300 }
301 if(band->nr_2_band == 0) {
302 band->nr_2_band = band_info.band_support.nr_2_band;
303 }
304 if(band->nr_1_band == 0) {
305 band->nr_1_band = band_info.band_support.nr_1_band;
306 }
307 if(band->nr_0_band == 0) {
308 band->nr_0_band = band_info.band_support.nr_0_band;
309 }
b.liu87afc4c2024-08-14 17:33:45 +0800310 }
b.liubeb61cc2025-02-13 10:38:29 +0800311
b.liu87afc4c2024-08-14 17:33:45 +0800312 if((band->gsm_band & band_info.band_support.gsm_band) != band->gsm_band) {
313 LOG("GSM band error.");
314 goto exit;
315 }
316
317 if((band->umts_band & band_info.band_support.umts_band) != band->umts_band) {
318 LOG("UMTS band error.");
319 goto exit;
320 }
321
322 if((band->tdlte_band & band_info.band_support.tdlte_band) != band->tdlte_band) {
323 LOG("TDLTE band error.");
324 goto exit;
325 }
326
327 if((band->fddlte_band & band_info.band_support.fddlte_band) != band->fddlte_band) {
328 LOG("FDDLTE band error.");
329 goto exit;
330 }
331
332 if((band->lte_ext_band & band_info.band_support.lte_ext_band) != band->lte_ext_band) {
333 LOG("EXT_LTE band error.");
334 goto exit;
335 }
b.liu61ad9172025-01-09 14:33:55 +0800336 if((band->nr_3_band & band_info.band_support.nr_3_band) != band->nr_3_band) {
337 LOG("nr_3_band band error.");
338 goto exit;
339 }
340
341 if((band->nr_2_band & band_info.band_support.nr_2_band) != band->nr_2_band) {
342 LOG("nr_2_band band error.");
343 goto exit;
344 }
345
346 if((band->nr_1_band & band_info.band_support.nr_1_band) != band->nr_1_band) {
347 LOG("nr_1_band band error.");
348 goto exit;
349 }
350
351 if((band->nr_0_band & band_info.band_support.nr_0_band) != band->nr_0_band) {
352 LOG("nr_0_band band error.");
353 goto exit;
354 }
b.liu87afc4c2024-08-14 17:33:45 +0800355 if(band->net_pref == 0xFF) { // No change net_pref.
356 int tmp_int;
b.liu7ca612c2025-04-25 09:23:36 +0800357 err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*BAND?", "*BAND:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800358 if (err < 0 || response->success == 0 || !response->p_intermediates){
359 if(cme_err) {
360 *cme_err = at_get_cme_error(response);
361 }
362 goto exit;
363 }
364
365 char *line = response->p_intermediates->line;
366 err = at_tok_start(&line);
367 if (err < 0)
368 {
369 goto exit;
370 }
371
372 err = at_tok_nextint(&line, &tmp_int);
373 if (err < 0)
374 {
375 goto exit;
376 }
377 band->net_pref = (uint8)tmp_int; // Set to current net_pref.
378
379 at_response_free(response);
380 }
b.liu61ad9172025-01-09 14:33:55 +0800381 // Only support 4G/5G
382 if(band_info.net_support & MBTK_NET_SUPPORT_5G) {
383 // AT*band=19,0,0,482,134742231,0,24576,256,134217877,0
384 if(band->lte_ext_band > 0) {
385 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,
386 band->nr_3_band, band->nr_2_band, band->nr_1_band, band->nr_0_band, band->lte_ext_band);
387 } else {
388 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,
389 band->nr_3_band, band->nr_2_band, band->nr_1_band, band->nr_0_band);
390 }
b.liu87afc4c2024-08-14 17:33:45 +0800391 } else {
b.liu61ad9172025-01-09 14:33:55 +0800392 if(band->lte_ext_band > 0) {
393 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);
394 } else {
395 sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band);
396 }
b.liu87afc4c2024-08-14 17:33:45 +0800397 }
398 }
b.liu7ca612c2025-04-25 09:23:36 +0800399 err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu87afc4c2024-08-14 17:33:45 +0800400
401 if (err < 0 || response->success == 0){
402 if(cme_err) {
403 *cme_err = at_get_cme_error(response);
404 }
405 goto exit;
406 }
407
408 err = 0;
409exit:
410 at_response_free(response);
411 return err;
412}
413
414/*
415// ???????
416AT*BAND=?
417*BAND:(0-18),79,147,482,524503
418
419OK
420
421// ???????????
422AT*BAND?
423*BAND: 15, 78, 147, 482, 524503, 0, 2, 2, 0, 0
424
425OK
426
b.liu61ad9172025-01-09 14:33:55 +08004275G :
428*BAND: 19, 0, 0, 482, 149,0, 24576, 256, 134217877, 0, 0, 2, 2, 0
429
430
b.liu87afc4c2024-08-14 17:33:45 +0800431// ?????????
432AT*BAND=5,79,147,128,1
433OK
434
435net_prefferred??
436 0 : GSM only
437 1 : UMTS only
438 2 : GSM/UMTS(auto)
439 3 : GSM/UMTS(GSM preferred)
440 4 : GSM/UMTS(UMTS preferred)
441 5 : LTE only
442 6 : GSM/LTE(auto)
443 7 : GSM/LTE(GSM preferred)
444 8 : GSM/LTE(LTE preferred)
445 9 : UMTS/LTE(auto)
446 10 : UMTS/LTE(UMTS preferred)
447 11 : UMTS/LTE(LTE preferred)
448 12 : GSM/UMTS/LTE(auto)
449 13 : GSM/UMTS/LTE(GSM preferred)
450 14 : GSM/UMTS/LTE(UMTS preferred)
451 15 : GSM/UMTS/LTE(LTE preferred)
452GSM band??
453 1 ?C PGSM 900 (standard or primary)
454 2 ?C DCS GSM 1800
455 4 ?C PCS GSM 1900
456 8 ?C EGSM 900 (extended)
457 16 ?C GSM 450
458 32 ?C GSM 480
459 64 ?C GSM 850
460 512 - BAND_LOCK_BIT // used for GSM band setting
461UMTS band??
462 1 ?C UMTS_BAND_1
463 2 ?C UMTS_BAND_2
464 4 ?C UMTS_BAND_3
465 8 ?C UMTS_BAND_4
466 16 ?C UMTS_BAND_5
467 32 ?C UMTS_BAND_6
468 64 ?C UMTS_BAND_7
469 128 ?C UMTS_BAND_8
470 256 ?C UMTS_BAND_9
471LTEbandH(TDD-LTE band)
472 32 ?C TDLTE_BAND_38
473 64 ?C TDLTE_BAND_39
474 128 ?C TDLTE_BAND_40
475 256 ?C TDLTE_BAND_41
476LTEbandL(FDD-LTE band)
477 1 ?C FDDLTE_BAND_1
478 4 ?C FDDLTE _BAND_3
479 8 ?C FDDLTE _BAND_4
480 64 ?C FDDLTE _BAND_7
481 65536 ?C FDDLTE _BAND_17
482 524288 ?C FDDLTE _BAND_20
483*/
b.liu7ca612c2025-04-25 09:23:36 +0800484static int req_band_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_band_info_t *band, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800485{
486 ATResponse *response = NULL;
487 int tmp_int;
488
489 log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t));
b.liu7ca612c2025-04-25 09:23:36 +0800490 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT*BAND?", "*BAND:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800491 if (err < 0 || response->success == 0 || !response->p_intermediates){
492 if(cme_err) {
493 *cme_err = at_get_cme_error(response);
494 }
495 goto exit;
496 }
497
498 char *line = response->p_intermediates->line;
499 err = at_tok_start(&line);
500 if (err < 0)
501 {
502 goto exit;
503 }
504
505 err = at_tok_nextint(&line, &tmp_int);
506 if (err < 0)
507 {
508 goto exit;
509 }
510 band->net_pref = (uint8)tmp_int;
511
512 err = at_tok_nextint(&line, &tmp_int);
513 if (err < 0)
514 {
515 goto exit;
516 }
517 band->gsm_band = (uint16)tmp_int;
518
519 err = at_tok_nextint(&line, &tmp_int);
520 if (err < 0)
521 {
522 goto exit;
523 }
524 band->umts_band = (uint16)tmp_int;
525
526 err = at_tok_nextint(&line, &tmp_int);
527 if (err < 0)
528 {
529 goto exit;
530 }
531 band->tdlte_band = (uint32)tmp_int;
532
533 err = at_tok_nextint(&line, &tmp_int);
534 if (err < 0)
535 {
536 goto exit;
537 }
538 band->fddlte_band = (uint32)tmp_int;
539
b.liuf2ea8bf2025-01-09 15:07:34 +0800540 if(band_info.net_support & MBTK_NET_SUPPORT_5G)
541 {
b.liu61ad9172025-01-09 14:33:55 +0800542 err = at_tok_nextint(&line, &tmp_int);
543 if (err < 0)
544 {
545 goto exit;
546 }
547 band->nr_3_band = (uint32)tmp_int;
548
549 err = at_tok_nextint(&line, &tmp_int);
550 if (err < 0)
551 {
552 goto exit;
553 }
554 band->nr_2_band = (uint32)tmp_int;
555
556 err = at_tok_nextint(&line, &tmp_int);
557 if (err < 0)
558 {
559 goto exit;
560 }
561 band->nr_1_band = (uint32)tmp_int;
562
563 err = at_tok_nextint(&line, &tmp_int);
564 if (err < 0)
565 {
566 goto exit;
567 }
568 band->nr_0_band = (uint32)tmp_int;
569 }
570
b.liu87afc4c2024-08-14 17:33:45 +0800571 // roamingConfig
572 err = at_tok_nextint(&line, &tmp_int);
573 if (err < 0)
574 {
575 goto exit;
576 }
577
578 // srvDomain
579 err = at_tok_nextint(&line, &tmp_int);
580 if (err < 0)
581 {
582 goto exit;
583 }
584
585 // bandPriorityFlag
586 err = at_tok_nextint(&line, &tmp_int);
587 if (err < 0)
588 {
589 goto exit;
590 }
591
592 //
593 err = at_tok_nextint(&line, &tmp_int);
594 if (err < 0)
595 {
596 goto exit;
597 }
598
599 // ltebandExt
600 err = at_tok_nextint(&line, &tmp_int);
601 if (err < 0)
602 {
603 goto exit;
604 }
605 band->lte_ext_band = (uint32)tmp_int;
606
607 log_hex("BAND", band, sizeof(mbtk_band_info_t));
608
609exit:
610 at_response_free(response);
611 return err;
612}
613
614/*
615AT+CSQ
616+CSQ: 31,99
617
618OK
619
620AT+CESQ
621+CESQ: 60,99,255,255,20,61
622
623OK
624
625AT+COPS?
626+COPS: 0,2,"46001",7
627
628OK
629
630*/
b.liu7ca612c2025-04-25 09:23:36 +0800631static int req_net_signal_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_signal_info_t *signal, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800632{
633 ATResponse *response = NULL;
634 int tmp_int;
635 char *tmp_ptr = NULL;
636 // AT+EEMOPT=1 in the first.
b.liu7ca612c2025-04-25 09:23:36 +0800637 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CSQ", "+CSQ:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800638 if (err < 0 || response->success == 0 || !response->p_intermediates){
639 if(cme_err != NULL)
640 *cme_err = at_get_cme_error(response);
641 err = -1;
642 goto exit;
643 }
644
645 char *line = response->p_intermediates->line;
646 err = at_tok_start(&line);
647 if (err < 0)
648 {
649 goto exit;
650 }
651 err = at_tok_nextint(&line, &tmp_int);
652 if (err < 0)
653 {
654 goto exit;
655 }
656 signal->rssi = (uint8)tmp_int;
657 at_response_free(response);
658
b.liu7ca612c2025-04-25 09:23:36 +0800659 err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+CESQ", "+CESQ:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800660 if (err < 0 || response->success == 0 || !response->p_intermediates){
661 if(cme_err != NULL)
662 *cme_err = at_get_cme_error(response);
663 err = -1;
664 goto exit;
665 }
666
667 line = response->p_intermediates->line;
668 err = at_tok_start(&line);
669 if (err < 0)
670 {
671 goto exit;
672 }
673 err = at_tok_nextint(&line, &tmp_int);
674 if (err < 0)
675 {
676 goto exit;
677 }
678 signal->rxlev = (uint8)tmp_int;
679
680 err = at_tok_nextint(&line, &tmp_int);
681 if (err < 0)
682 {
683 goto exit;
684 }
685 signal->ber = (uint8)tmp_int;
686
687 err = at_tok_nextint(&line, &tmp_int);
688 if (err < 0)
689 {
690 goto exit;
691 }
692 signal->rscp = (uint8)tmp_int;
693
694 err = at_tok_nextint(&line, &tmp_int);
695 if (err < 0)
696 {
697 goto exit;
698 }
699 signal->ecno = (uint8)tmp_int;
700
701 err = at_tok_nextint(&line, &tmp_int);
702 if (err < 0)
703 {
704 goto exit;
705 }
706 signal->rsrq = (uint8)tmp_int;
707
708 err = at_tok_nextint(&line, &tmp_int);
709 if (err < 0)
710 {
711 goto exit;
712 }
713 signal->rsrp = (uint8)tmp_int;
714
b.liubeb61cc2025-02-13 10:38:29 +0800715 if(at_tok_hasmore(&line)) {
716 err = at_tok_nextint(&line, &tmp_int);
717 if (err < 0)
718 {
719 goto exit;
720 }
721 signal->ss_rsrq = (uint8)tmp_int;
722 }
723 if(at_tok_hasmore(&line)) {
724 err = at_tok_nextint(&line, &tmp_int);
725 if (err < 0)
726 {
727 goto exit;
728 }
729 signal->ss_rsrp = (uint8)tmp_int;
730 }
731 if(at_tok_hasmore(&line)) {
732 err = at_tok_nextint(&line, &tmp_int);
733 if (err < 0)
734 {
735 goto exit;
736 }
737 signal->ss_sinr = (uint8)tmp_int;
738 }
739
b.liu87afc4c2024-08-14 17:33:45 +0800740 at_response_free(response);
b.liu7ca612c2025-04-25 09:23:36 +0800741 err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+COPS?", "+COPS:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800742 if (err < 0 || response->success == 0 || !response->p_intermediates){
743 if(cme_err != NULL)
744 *cme_err = at_get_cme_error(response);
745 err = -1;
746 goto exit;
747 }
748 line = response->p_intermediates->line;
749 err = at_tok_start(&line);
750 if (err < 0)
751 {
752 goto exit;
753 }
754 err = at_tok_nextint(&line, &tmp_int);
755 if (err < 0)
756 {
757 goto exit;
758 }
759 if(!at_tok_hasmore(&line)) {
760 goto exit;
761 }
762 err = at_tok_nextint(&line, &tmp_int);
763 if (err < 0)
764 {
765 goto exit;
766 }
767 err = at_tok_nextstr(&line, &tmp_ptr);
768 if (err < 0)
769 {
770 goto exit;
771 }
772 err = at_tok_nextint(&line, &tmp_int);
773 if (err < 0)
774 {
775 goto exit;
776 }
777 signal->type = (uint8)tmp_int;
778
779exit:
780 at_response_free(response);
781 return err;
782}
783
784/*
785AT+CREG=3
786OK
787
788AT+CREG?
789+CREG: 3,1,"8330","06447340",7
790
791OK
792
793AT+CREG?
794+CREG: 3,0
795
796OK
797
798AT+CEREG?
799+CEREG: 3,1,"8330","06447340",7
800
801OK
802
803
804AT+CIREG?
805+CIREG: 2,1,15
806
807OK
808
809AT+CIREG?
810+CIREG: 0
811
812OK
813
814
815*/
b.liu7ca612c2025-04-25 09:23:36 +0800816static int req_net_reg_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_net_reg_info_t *reg, int *cme_err)
b.liu87afc4c2024-08-14 17:33:45 +0800817{
818 ATResponse *response = NULL;
819 int tmp_int;
820 char *tmp_str = NULL;
b.liu7ca612c2025-04-25 09:23:36 +0800821 int err = at_send_command(portType_2_portId(sim_id, port), "AT+CREG=3", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800822 if (err < 0 || response->success == 0){
823 if(cme_err) {
824 *cme_err = at_get_cme_error(response);
825 }
826 goto exit;
827 }
828 at_response_free(response);
829
b.liu7ca612c2025-04-25 09:23:36 +0800830 err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CREG?", "+CREG:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800831 if (err < 0 || response->success == 0 || !response->p_intermediates){
832 if(cme_err) {
833 *cme_err = at_get_cme_error(response);
834 }
835 goto exit;
836 }
837
838 char *line = response->p_intermediates->line;
839 err = at_tok_start(&line);
840 if (err < 0)
841 {
842 goto exit;
843 }
844 err = at_tok_nextint(&line, &tmp_int); // n
845 if (err < 0)
846 {
847 goto exit;
848 }
849 err = at_tok_nextint(&line, &tmp_int);// stat
850 if (err < 0)
851 {
852 goto exit;
853 }
854 reg->call_state = (uint8)tmp_int;
855
856 if(at_tok_hasmore(&line)) {
857 err = at_tok_nextstr(&line, &tmp_str); // lac
858 if (err < 0)
859 {
860 goto exit;
861 }
862 reg->lac = strtol(tmp_str, NULL, 16);
863
864 err = at_tok_nextstr(&line, &tmp_str); // ci
865 if (err < 0)
866 {
867 goto exit;
868 }
869 reg->ci = strtol(tmp_str, NULL, 16);
870
871 err = at_tok_nextint(&line, &tmp_int);// AcT
872 if (err < 0)
873 {
874 goto exit;
875 }
876 reg->type = (uint8)tmp_int;
877 }
878 at_response_free(response);
879
b.liu7ca612c2025-04-25 09:23:36 +0800880 err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CEREG?", "+CEREG:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800881 if (err < 0 || response->success == 0 || !response->p_intermediates){
882 if(cme_err) {
883 *cme_err = at_get_cme_error(response);
884 }
885 goto exit;
886 }
887
888 line = response->p_intermediates->line;
889 err = at_tok_start(&line);
890 if (err < 0)
891 {
892 goto exit;
893 }
894 err = at_tok_nextint(&line, &tmp_int); // n
895 if (err < 0)
896 {
897 goto exit;
898 }
899 err = at_tok_nextint(&line, &tmp_int);// stat
900 if (err < 0)
901 {
902 goto exit;
903 }
904 reg->data_state = (uint8)tmp_int;
905
906 if(reg->lac == 0 && at_tok_hasmore(&line)) {
907 err = at_tok_nextstr(&line, &tmp_str); // lac
908 if (err < 0)
909 {
910 goto exit;
911 }
912 reg->lac = strtol(tmp_str, NULL, 16);
913
914 err = at_tok_nextstr(&line, &tmp_str); // ci
915 if (err < 0)
916 {
917 goto exit;
918 }
919 reg->ci = strtol(tmp_str, NULL, 16);
920
921 err = at_tok_nextint(&line, &tmp_int);// AcT
922 if (err < 0)
923 {
924 goto exit;
925 }
926 reg->type = (uint8)tmp_int;
b.liubeb61cc2025-02-13 10:38:29 +0800927 } else if(reg->data_state == 0 && (band_info.net_support & MBTK_NET_SUPPORT_5G)) {
928 at_response_free(response);
b.liu7ca612c2025-04-25 09:23:36 +0800929 err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+C5GREG?", "+C5GREG:", &response);
b.liubeb61cc2025-02-13 10:38:29 +0800930 if (err < 0 || response->success == 0 || !response->p_intermediates){
931 if(cme_err) {
932 *cme_err = at_get_cme_error(response);
933 }
934 goto exit;
935 }
936
937 line = response->p_intermediates->line;
938 err = at_tok_start(&line);
939 if (err < 0)
940 {
941 goto exit;
942 }
943 err = at_tok_nextint(&line, &tmp_int); // n
944 if (err < 0)
945 {
946 goto exit;
947 }
948 err = at_tok_nextint(&line, &tmp_int);// stat
949 if (err < 0)
950 {
951 goto exit;
952 }
953 reg->data_state = (uint8)tmp_int;
954
955 if(/*reg->lac == 0 && */at_tok_hasmore(&line)) {
956 err = at_tok_nextstr(&line, &tmp_str); // lac
957 if (err < 0)
958 {
959 goto exit;
960 }
961 reg->lac = strtol(tmp_str, NULL, 16);
962
963 err = at_tok_nextstr(&line, &tmp_str); // ci
964 if (err < 0)
965 {
966 goto exit;
967 }
968 reg->ci = strtol(tmp_str, NULL, 16);
969
970 err = at_tok_nextint(&line, &tmp_int);// AcT
971 if (err < 0)
972 {
973 goto exit;
974 }
975 reg->type = (uint8)tmp_int;
976 }
b.liu87afc4c2024-08-14 17:33:45 +0800977 }
978 at_response_free(response);
979
b.liu7ca612c2025-04-25 09:23:36 +0800980 err = at_send_command_multiline(portType_2_portId(sim_id, port), "AT+CIREG?", "+CIREG:", &response);
b.liu87afc4c2024-08-14 17:33:45 +0800981 if (err < 0 || response->success == 0 || !response->p_intermediates){
982 reg->ims_state = (uint8)0;
983 err = 0;
984 goto exit;
985 }
986 line = response->p_intermediates->line;
987 err = at_tok_start(&line);
988 if (err < 0)
989 {
990 goto exit;
991 }
992 err = at_tok_nextint(&line, &tmp_int); // n/stat
993 if (err < 0)
994 {
995 goto exit;
996 }
997 if(at_tok_hasmore(&line)) {
998 err = at_tok_nextint(&line, &tmp_int);// stat
999 if (err < 0)
1000 {
1001 goto exit;
1002 }
1003 reg->ims_state = (uint8)tmp_int;
1004 } else {
1005 reg->ims_state = (uint8)tmp_int;
1006 }
1007
1008exit:
1009 at_response_free(response);
1010 return err;
1011}
1012
1013/*
b.liub4772072024-08-15 14:47:03 +08001014AT+EEMOPT=1
1015OK
1016
1017// LTE
1018AT+EEMGINFO?
1019// <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>,
1020// <rsrp>,<rsrq>, <sinr>,
1021// errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi,
1022// cellId,subFrameAssignType,specialSubframePatterns,transMode
1023// mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt,
1024// tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB,
1025// dlBer, ulBer,
1026// diversitySinr, diversityRssi
1027+EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20,
10280, 0, 0,
10291, 10, 0, 1, 0, 1059, 78, 3959566565,
1030105149248, 2, 7, 7,
10310, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777,
10320, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0,
10330, 0,
10347, 44
1035
1036// index,phyCellId,euArfcn,rsrp,rsrq
1037+EEMLTEINTER: 0, 65535, 38950, 0, 0
1038
1039+EEMLTEINTER: 1, 0, 0, 0, 0
1040
1041+EEMLTEINTER: 2, 0, 4294967295, 255, 255
1042
1043+EEMLTEINTER: 3, 65535, 1300, 0, 0
1044
1045+EEMLTEINTER: 4, 0, 0, 0, 0
1046
1047+EEMLTEINTER: 5, 0, 4294967295, 247, 0
1048
1049+EEMLTEINTER: 6, 197, 41332, 24, 9
1050
1051+EEMLTEINTER: 7, 0, 0, 0, 0
1052
1053+EEMLTEINTER: 8, 0, 0, 0, 0
1054
1055+EEMLTEINTRA: 0, 429, 40936, 56, 12
1056
1057+EEMLTEINTERRAT: 0,0
1058
1059+EEMLTEINTERRAT: 1,0
1060
1061+EEMGINFO: 3, 2 // <state>:
1062 // 0: ME in Idle mode
1063 // 1: ME in Dedicated mode
1064 // 2: ME in PS PTM mode
1065 // 3: invalid state
1066 // <nw_type>:
1067 // 0: GSM 1: UMTS 2: LTE
1068
1069OK
1070
1071// WCDMA
1072AT+EEMGINFO?
1073// Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent,
1074
1075// if sCMeasPresent == 1
1076// cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower,
1077// endif
1078
1079// if sCParamPresent == 1
1080// rac, nom, mcc, mnc_len, mnc, lac, ci,
1081// uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed,
1082// csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport,
1083// endif
1084
1085// if ueOpStatusPresent == 1
1086// rrcState, numLinks, srncId, sRnti,
1087// algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn,
1088// HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause,
1089// MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput,
1090// serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count
1091// endif
1092//
1093+EEMUMTSSVC: 3, 1, 1, 1,
1094-80, 27, -6, -18, -115, -32768,
10951, 1, 1120, 2, 1, 61697, 168432821,
109615, 24, 10763, 0, 0, 0, 0,
1097128, 128, 65535, 0, 0,
10982, 255, 65535, 4294967295,
10990, 0, 0, 0, 0, 0,
11000, 0, 0, 0, 0, 0, 1, 1,
110128672, 28672, 0, 0, 0, 0, 0, 0, 0,
11020, 0, 0, 0, 0, 0
1103
1104// index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc
1105+EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32
1106
1107+EEMUMTSINTRA: 1, -1, -32768, -18, -115, 0, 0, 65534, 2, 10763, 40, 32768
1108
1109+EEMUMTSINTRA: 2, -32768, -18, -115, 0, 0, 65534, 3, 10763, 278, 32768, 65535
1110
1111+EEMUMTSINTRA: 3, -18, -115, 0, 0, -2, 4, 10763, 28, 32768, 65535, 32768
1112
1113+EEMUMTSINTRA: 4, -115, 0, 0, -2, 5, 10763, 270, 32768, 65535, 32768, 65518
1114
1115+EEMUMTSINTRA: 5, 0, 0, -2, 6, 10763, 286, 32768, 65535, 32768, 65518, 65421
1116
1117+EEMUMTSINTRA: 6, 0, -2, 7, 10763, 80, 32768, 65535, 32768, 65518, 65421, 0
1118
1119+EEMUMTSINTRA: 7, -2, 8, 10763, 206, -32768, 65535, 32768, 65518, 65421, 0, 0
1120
1121+EEMUMTSINTRA: 8, 9, 10763, 11, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
1122
1123+EEMUMTSINTRA: 9, 10763, 19, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 11
1124
1125+EEMUMTSINTRA: 10, 232, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 12, 10763
1126
1127+EEMUMTSINTRA: 11, -32768, -1, -32768, -18, -115, 0, 0, 65534, 13, 10763, 66
1128
1129+EEMUMTSINTRA: 12, -1, -32768, -18, -115, 0, 0, 65534, 14, 10763, 216, 32768
1130
1131+EEMUMTSINTRA: 13, -32768, -18, -115, 0, 0, 65534, 15, 10763, 183, 32768, 65535
1132
1133+EEMUMTSINTRA: 14, -18, -115, 0, 0, -2, 16, 10763, 165, 32768, 65535, 32768
1134
1135+EEMUMTSINTRA: 15, -115, 0, 0, -2, 17, 10763, 151, 32768, 65535, 32768, 65518
1136
1137+EEMUMTSINTRA: 16, 0, 0, -2, 18, 10763, 43, 32768, 65535, 32768, 65518, 65421
1138
1139+EEMUMTSINTRA: 17, 0, -2, 19, 10763, 72, 32768, 65535, 32768, 65518, 65421, 0
1140
1141+EEMUMTSINTRA: 18, -2, 20, 10763, 157, -32768, 65535, 32768, 65518, 65421, 0, 0
1142
1143+EEMUMTSINTRA: 19, 21, 10763, 165, -32768, -1, 32768, 65518, 65421, 0, 0, 65534
1144
1145+EEMUMTSINTRA: 20, 10763, 301, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 23
1146
1147+EEMUMTSINTRA: 21, 23, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 24, 10763
1148
1149+EEMUMTSINTRA: 22, -32768, -1, -32768, -18, -115, 0, 0, 65534, 25, 10763, 0
1150
1151+EEMUMTSINTRA: 23, -1, -32768, -18, -115, 0, 0, 65534, 26, 10763, 167, 32768
1152
1153+EEMUMTSINTRA: 24, -32768, -18, -115, 0, 0, 65534, 27, 10763, 34, 32768, 65535
1154
1155+EEMUMTSINTRA: 25, -18, -115, 0, 0, -2, 28, 10763, 313, 32768, 65535, 32768
1156
1157+EEMUMTSINTRA: 26, -115, 0, 0, -2, 29, 10763, 152, 32768, 65535, 32768, 65518
1158
1159+EEMUMTSINTRA: 27, 0, 0, -2, 30, 10763, 239, 0, 0, 0, 0, 0
1160
1161+EEMUMTSINTRA: 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1162
1163+EEMUMTSINTRA: 29, 0, 0, 0, 0, -115, 0, 0, 65534, 30, 10763, 239
1164
1165// index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic
1166+EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36
1167
1168+EEMUMTSINTERRAT: 1, -107, -1, -1, 0, 0, 65534, 1, 72, 49, 0
1169
1170+EEMUMTSINTERRAT: 2, -1, -1, 0, 0, 65534, 2, 119, 15, 32768, 149
1171
1172+EEMUMTSINTERRAT: 3, -1, 0, 0, -2, 3, 121, 23, 0, 0, 0
1173
1174+EEMGINFO: 3, 1
1175
1176OK
1177
1178
1179// GSM
1180AT+EEMGINFO?
1181+EEMGINFOBASIC: 2
1182
1183// mcc, mnc_len, mnc, lac, ci, nom, nco,
1184// bsic, C1, C2, TA, TxPwr,
1185// RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub,
1186// ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn,
1187// bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support,
1188// ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count,
1189// gsmBand,channelMode
1190+EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0,
119163, 36, 146, 1, 7,
119246, 42, 42, 7, 0,
119353, 0, 8, 0, 1, 6, 53,
11942, 0, 146, 42, 54, 0, 1,
11951, 32, 0, 0, 0, 0,
11960, 0
1197
1198// PS_attached, attach_type, service_type, tx_power, c_value,
1199// ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation,
1200// gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause
1201// pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status
1202+EEMGINFOPS: 1, 255, 0, 0, 0,
12030, 0, 268435501, 1, 0, 0,
12044, 0, 96, 0, 0, 0,
12050, 0, 0, 65535, 0, 13350
1206
1207+EEMGINFO: 0, 0
1208
1209OK
1210
1211*/
b.liu7ca612c2025-04-25 09:23:36 +08001212static int req_cell_info_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, int *cme_err)
b.liub4772072024-08-15 14:47:03 +08001213{
1214 ATResponse *response = NULL;
1215 int tmp_int;
1216 int buff_size = 0;
1217 // AT+EEMOPT=1 in the first.
b.liu7ca612c2025-04-25 09:23:36 +08001218 int err = at_send_command(portType_2_portId(sim_id, port), "AT+EEMOPT=1", &response);
b.liub4772072024-08-15 14:47:03 +08001219 if (err < 0 || response->success == 0){
1220 *cme_err = at_get_cme_error(response);
1221 goto exit;
1222 }
1223
1224 // Reset buffer in the first.
1225 memset(&cell_info, 0xFF, sizeof(mbtK_cell_pack_info_t));
1226 cell_info.running = true;
1227 cell_info.cell_list.num = 0;
1228
b.liu7ca612c2025-04-25 09:23:36 +08001229 err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+EEMGINFO?", "+EEMGINFO:", &response);
b.liub4772072024-08-15 14:47:03 +08001230 if (err < 0 || response->success == 0 || !response->p_intermediates){
1231 *cme_err = at_get_cme_error(response);
1232 goto exit;
1233 }
1234
1235 // Now, cell infomation has get from URC message.
1236
1237 char *line = response->p_intermediates->line;
1238 err = at_tok_start(&line);
1239 if (err < 0)
1240 {
1241 goto exit;
1242 }
1243 err = at_tok_nextint(&line, &tmp_int);
1244 if (err < 0)
1245 {
1246 goto exit;
1247 }
1248 err = at_tok_nextint(&line, &tmp_int);
1249 if (err < 0)
1250 {
1251 goto exit;
1252 }
1253
1254 cell_info.cell_list.type = (uint8)tmp_int;
1255 cell_info.running = false;
1256
1257#if 0
1258 while(lines_ptr)
1259 {
1260 // LTE
1261 if(strStartsWith(line, "+EEMLTESVC:")) // LTE Server Cell
1262 {
1263
1264 }
1265 else if(strStartsWith(line, "+EEMLTEINTER:")) // LTE
1266 {
1267
1268 }
1269 else if(strStartsWith(line, "+EEMLTEINTRA:")) // LTE
1270 {
1271
1272 }
1273 else if(strStartsWith(line, "+EEMLTEINTERRAT:")) // LTE
1274 {
1275
1276 }
1277 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
1278 // <nw_type>: 0: GSM 1: UMTS 2: LTE
1279 {
1280
1281 }
1282 // WCDMA
1283 else if(strStartsWith(line, "+EEMUMTSSVC:")) // WCDMA Server Cell
1284 {
1285
1286 }
1287 else if(strStartsWith(line, "+EEMUMTSINTRA:")) // WCDMA
1288 {
1289
1290 }
1291 else if(strStartsWith(line, "+EEMUMTSINTERRAT:")) // WCDMA
1292 {
1293
1294 }
1295 // GSM
1296 else if(strStartsWith(line, "+EEMGINFOBASIC:")) // Basic information in GSM
1297 // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode
1298 {
1299
1300 }
1301 else if(strStartsWith(line, "+EEMGINFOSVC:")) // GSM Server Cell
1302 {
1303
1304 }
1305 else if(strStartsWith(line, "+EEMGINFOPS:")) // PS
1306 {
1307
1308 }
1309
1310
1311 lines_ptr = lines_ptr->p_next;
1312 }
1313#endif
1314
1315exit:
1316 at_response_free(response);
1317 return buff_size;
1318}
1319
b.liu7ca612c2025-04-25 09:23:36 +08001320static int req_cell_info_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const char *cmgl, char *reg, int len, int *cme_err)
b.liub4772072024-08-15 14:47:03 +08001321{
1322 ATResponse *response = NULL;
b.liu62240ee2024-11-07 17:52:45 +08001323 char cmd[500] = {0};
b.liub4772072024-08-15 14:47:03 +08001324 char data[218] = {0};
1325 int err = 0;
1326
1327 memcpy(data, cmgl, len);
1328
1329 sprintf(cmd, "AT*CELL=%s", data);
1330
1331 if(strlen(cmd) > 0)
1332 {
b.liu7ca612c2025-04-25 09:23:36 +08001333 err = at_send_command_multiline(portType_2_portId(sim_id, port), cmd, "", &response);
b.liub4772072024-08-15 14:47:03 +08001334 if (err < 0 || response->success == 0 || !response->p_intermediates){
1335 *cme_err = at_get_cme_error(response);
1336 goto exit;
1337 }
1338
1339 ATLine* lines_ptr = response->p_intermediates;
1340 char *line = NULL;
b.liu62240ee2024-11-07 17:52:45 +08001341// int reg_len = 0;
1342// bool flag = false;
b.liub4772072024-08-15 14:47:03 +08001343 while(lines_ptr)
1344 {
1345 line = lines_ptr->line;
1346 if(line ==NULL)
1347 {
1348 LOGD("line is null----------------------");
1349 }
1350 lines_ptr = lines_ptr->p_next;
1351 }
1352 }
1353 err = 0;
1354 memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss"));
1355exit:
1356 at_response_free(response);
1357 return err;
1358}
1359
b.liu557c81d2024-11-19 16:52:45 +08001360/*
1361AT+OOSPP=1
1362or
1363AT+OOSPP=0
1364or
1365AT+OOSPP=1,20,30,40 //AtOospp()
1366 param1£ºmode
1367 param2£ºoosPhasePeriod[0] //5 times, 5s by default;
1368 param3£ºoosPhasePeriod[1] //5 times, 10s by default;
1369 param4£ºoosPhasePeriod[2] //unlimited, 20s by default;
1370
1371
1372BTW
13731, Èç¹ûÖ»ÊäÈëmode=1£¬ÆäÓà²ÎÊý²»ÉèÖã¬Ï൱ÓÚÕâ¸ö¹¦ÄÜ´ò¿ª£¬Ê±¼ä¼ä¸ôÊÇÕâ¸ö¹¦ÄܵÄĬÈÏÖµ¡£
13742, Èç¹ûµ±mode=1¼ÓÉÏÆäÓàÉèÖòÎÊýºó£¬¹¦ÄÜ´ò¿ª£¬Ê±¼ä¼ä¸ôÊDZ¾´ÎÉèÖõÄÖµ£»
13753£¬Èç¹ûÔÙÉèÖÃmode=0£¬Ï൱ÓÚÕâ¸ö¹¦Äܹرգ¬ÊÇ×߯½Ì¨×Ô¼ºÁíÒ»Ì×µÄËÑÍøÉèÖá£
1376ƽ̨±¾ÉíÊÇÓÐÒ»Ì×¼ä¸ôËÑÍø£¬Ò²ÓÐÀúʷƵµãÓÅÏÈ´¦ÀíµÄÂß¼­£¨²»ÐèÒªÎÒÃǽøÐд¦Àí£©£¬
1377Ìṩ¸øÎÒÃǵÄAT+OOSPPÖ¸ÁîÊÇÈÃÎÒÃÇ¿ÉÒÔ×Ô¶¨ÒåËÑÍø¼ä¸ô
1378*/
b.liu7ca612c2025-04-25 09:23:36 +08001379static int req_oos_set(mbtk_sim_type_enum sim_id, ATPortType_enum port, const mbtk_ril_oos_info_t* oos_info, int *cme_err)
b.liu557c81d2024-11-19 16:52:45 +08001380{
1381 ATResponse *response = NULL;
1382 char cmd[100] = {0};
1383 int err = 0;
1384
1385 if ((oos_info->state == 1 && oos_info->oosPhase[0] == 0 && oos_info->oosPhase[1] == 0 && oos_info->oosPhase[2] == 0) \
1386 || oos_info->state == 0)
1387 {
1388 sprintf(cmd, "AT+OOSPP=%d", oos_info->state);//Ö»ÓÐÒ»¸öÖµ0/1
1389 }
1390 else
1391 {
1392 if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] != 0) && (oos_info->oosPhase[2] != 0))
1393 {
1394 sprintf(cmd, "AT+OOSPP=%d,%d,%d,%d", oos_info->state, oos_info->oosPhase[0], oos_info->oosPhase[1], oos_info->oosPhase[2]);
1395 }
1396 else if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] != 0) && (oos_info->oosPhase[2] == 0))
1397 {
1398 sprintf(cmd, "AT+OOSPP=%d,%d,%d", oos_info->state, oos_info->oosPhase[0], oos_info->oosPhase[1]);
1399 }
1400 else if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] == 0) && (oos_info->oosPhase[2] == 0))
1401 {
1402 sprintf(cmd, "AT+OOSPP=%d,%d", oos_info->state, oos_info->oosPhase[0]);
1403 }
1404 else
1405 {
1406 LOGE("AT+OOSPP SET ERR");
1407 goto exit;
1408 }
1409 }
1410
1411 LOGI("Set the oos command is = [%s]\n", cmd);
b.liu7ca612c2025-04-25 09:23:36 +08001412 err = at_send_command(portType_2_portId(sim_id, port), cmd, &response);
b.liu557c81d2024-11-19 16:52:45 +08001413 if (err < 0 || response->success == 0){
1414 *cme_err = at_get_cme_error(response);
1415 goto exit;
1416 }
1417
1418exit:
1419 at_response_free(response);
1420 return err;
1421}
1422
1423/*
1424AT+OOSPP?
1425¿ª(ĬÈÏÖµ)£º
1426+OOSPP:5,10,20
1427¹Ø£º
1428+OOSPP:0
1429*/
b.liu7ca612c2025-04-25 09:23:36 +08001430static int req_oos_get(mbtk_sim_type_enum sim_id, ATPortType_enum port, mbtk_ril_oos_info_t *oos_info, int *cme_err)
b.liu557c81d2024-11-19 16:52:45 +08001431{
1432 ATResponse *response = NULL;
1433
b.liu7ca612c2025-04-25 09:23:36 +08001434 int err = at_send_command_singleline(portType_2_portId(sim_id, port), "AT+OOSPP?", "+OOSPP:", &response);
b.liu557c81d2024-11-19 16:52:45 +08001435
1436 if (err < 0 || response->success == 0 || !response->p_intermediates){
1437 *cme_err = at_get_cme_error(response);
1438 goto exit;
1439 }
1440
1441 char *line = response->p_intermediates->line;
1442
1443 char *tmp_str = NULL;
1444 err = at_tok_start(&line);//+OOSPP:10,15,20,¹ýÂË+OOSPP:
1445 if (err < 0)
1446 {
1447 goto exit;
1448 }
1449
1450 //LOG("req_oos_get =[%s]",line);
1451
1452 err = at_tok_nextstr(&line, &tmp_str);
1453 if (err < 0)
1454 {
1455 goto exit;
1456 }
1457
1458 int mode = atoi(tmp_str);
1459 if (mode == 0)//¹Ø±Õ״̬
1460 {
1461 oos_info->state = mode;
1462 }
1463 else//¿ª×´Ì¬
1464 {
1465 oos_info->state = 1;
1466 //LOG("tmp_str =[%s]",tmp_str);
1467 oos_info->oosPhase[0] = atoi(tmp_str);
1468
1469 err = at_tok_nextstr(&line, &tmp_str);
1470 if (err < 0)
1471 {
1472 goto exit;
1473 }
1474 //LOG("tmp_str =[%s]",tmp_str);
1475 oos_info->oosPhase[1] = atoi(tmp_str);
1476
1477 err = at_tok_nextstr(&line, &tmp_str);
1478 if (err < 0)
1479 {
1480 goto exit;
1481 }
1482 //LOG("tmp_str =[%s]",tmp_str);
1483 oos_info->oosPhase[2] = atoi(tmp_str);
1484 }
1485
1486exit:
1487 at_response_free(response);
1488 return err;
1489}
1490
b.liu87afc4c2024-08-14 17:33:45 +08001491//void net_list_free(void *data);
1492// Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP.
1493// Otherwise, do not call pack_error_send().
1494mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack)
1495{
1496 mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS;
1497 int cme_err = MBTK_RIL_ERR_CME_NON;
1498 switch(pack->msg_id)
1499 {
1500 case RIL_MSG_ID_NET_AVAILABLE:
1501 {
1502 if(pack->data_len == 0 || pack->data == NULL)
1503 {
1504 mbtk_net_info_array_t net_array;
1505 memset(&net_array, 0, sizeof(mbtk_net_info_array_t));
b.liu7ca612c2025-04-25 09:23:36 +08001506 if(req_available_net_get(cli_info->sim_id, cli_info->port, &net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001507 {
1508 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1509 err = MBTK_RIL_ERR_CME + cme_err;
1510 } else {
1511 err = MBTK_RIL_ERR_UNKNOWN;
1512 }
1513 LOGD("Get Available Net fail.");
1514 }
1515 else
1516 {
b.liu7ca612c2025-04-25 09:23:36 +08001517 ril_rsp_pack_send(cli_info->sim_id, 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 +08001518 }
1519 }
1520 else // Set
1521 {
1522 err = MBTK_RIL_ERR_UNSUPPORTED;
1523 LOGW("Unsupport set available net.");
1524 }
1525 break;
1526 }
1527 case RIL_MSG_ID_NET_SEL_MODE:
1528 {
1529 if(pack->data_len == 0 || pack->data == NULL)
1530 {
1531 mbtk_net_info_t info;
1532 memset(&info, 0, sizeof(mbtk_net_info_t));
b.liu7ca612c2025-04-25 09:23:36 +08001533 if(req_net_sel_mode_get(cli_info->sim_id, cli_info->port, &info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001534 {
1535 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1536 err = MBTK_RIL_ERR_CME + cme_err;
1537 } else {
1538 err = MBTK_RIL_ERR_UNKNOWN;
1539 }
1540 LOGD("Get Net sel mode fail.");
1541 }
1542 else
1543 {
b.liu7ca612c2025-04-25 09:23:36 +08001544 ril_rsp_pack_send(cli_info->sim_id, 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 +08001545 }
1546 }
1547 else // Set
1548 {
1549 mbtk_net_info_t *info = (mbtk_net_info_t*)pack->data;
b.liu7ca612c2025-04-25 09:23:36 +08001550 if(req_net_sel_mode_set(cli_info->sim_id, cli_info->port, info, &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("Set Net sel mode fail.");
1558 }
1559 else
1560 {
b.liu7ca612c2025-04-25 09:23:36 +08001561 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +08001562 }
1563 }
1564 break;
1565 }
1566 case RIL_MSG_ID_NET_BAND:
1567 {
1568 if(pack->data_len == 0 || pack->data == NULL)
1569 {
1570 err = MBTK_RIL_ERR_REQ_PARAMETER;
1571 LOG("No data found.");
1572 }
1573 else // Set
1574 {
1575 if(pack->data_len == sizeof(uint8)) {
1576 if(*(pack->data)) { // Get current bands.
1577 mbtk_band_info_t band;
1578 memset(&band, 0x0, sizeof(mbtk_band_info_t));
b.liu7ca612c2025-04-25 09:23:36 +08001579 if(req_band_get(cli_info->sim_id, cli_info->port, &band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001580 {
1581 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1582 err = MBTK_RIL_ERR_CME + cme_err;
1583 } else {
1584 err = MBTK_RIL_ERR_UNKNOWN;
1585 }
1586 LOG("Get net band fail.");
1587 }
1588 else
1589 {
b.liu7ca612c2025-04-25 09:23:36 +08001590 ril_rsp_pack_send(cli_info->sim_id, 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 +08001591 }
1592 } else { // Get support bands.
b.liu7ca612c2025-04-25 09:23:36 +08001593 ril_rsp_pack_send(cli_info->sim_id, 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 +08001594 }
1595 } else { // Set current bands.
1596 mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data;
1597 if(pack->data_len != sizeof(mbtk_band_info_t))
1598 {
1599 err = MBTK_RIL_ERR_REQ_PARAMETER;
1600 LOG("Set net band error.");
1601 break;
1602 }
1603
b.liu7ca612c2025-04-25 09:23:36 +08001604 if(req_band_set(cli_info->sim_id, cli_info->port, band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001605 {
1606 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1607 err = MBTK_RIL_ERR_CME + cme_err;
1608 } else {
1609 err = MBTK_RIL_ERR_UNKNOWN;
1610 }
1611 LOG("Set net band fail.");
1612 }
1613 else
1614 {
b.liu7ca612c2025-04-25 09:23:36 +08001615 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu87afc4c2024-08-14 17:33:45 +08001616 }
1617 }
1618 }
1619 break;
1620 }
1621 case RIL_MSG_ID_NET_SIGNAL:
1622 {
1623 if(pack->data_len == 0 || pack->data == NULL)
1624 {
1625 mbtk_signal_info_t signal;
1626 memset(&signal, 0, sizeof(mbtk_signal_info_t));
b.liu7ca612c2025-04-25 09:23:36 +08001627 if(req_net_signal_get(cli_info->sim_id, cli_info->port, &signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001628 {
1629 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1630 err = MBTK_RIL_ERR_CME + cme_err;
1631 } else {
1632 err = MBTK_RIL_ERR_UNKNOWN;
1633 }
1634 LOGD("Get net signal fail.");
1635 }
1636 else
1637 {
b.liu7ca612c2025-04-25 09:23:36 +08001638 ril_rsp_pack_send(cli_info->sim_id, 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 +08001639 }
1640 }
1641 else // Set
1642 {
1643 err = MBTK_RIL_ERR_UNSUPPORTED;
1644 LOGW("Unsupport set net signal.");
1645 }
1646 break;
1647 }
1648 case RIL_MSG_ID_NET_REG:
1649 {
1650 if(pack->data_len == 0 || pack->data == NULL)
1651 {
1652 mbtk_net_reg_info_t net_reg;
1653 memset(&net_reg, 0, sizeof(mbtk_net_reg_info_t));
b.liu7ca612c2025-04-25 09:23:36 +08001654 if(req_net_reg_get(cli_info->sim_id, cli_info->port, &net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001655 {
1656 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1657 err = MBTK_RIL_ERR_CME + cme_err;
1658 } else {
1659 err = MBTK_RIL_ERR_UNKNOWN;
1660 }
1661 LOGD("Get Net reg info fail.");
1662 }
1663 else
1664 {
b.liu7ca612c2025-04-25 09:23:36 +08001665 ril_rsp_pack_send(cli_info->sim_id, 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 +08001666 }
1667 }
1668 else // Set
1669 {
1670 err = MBTK_RIL_ERR_UNSUPPORTED;
1671 LOGW("Unsupport set net reg info.");
1672 }
1673 break;
1674 }
1675 case RIL_MSG_ID_NET_CELL:
1676 {
q.huangfd4b1d82025-08-26 18:57:31 +08001677 if(pack->data_len == 1 || pack->data == NULL) // Get net cell. // data_len == 1 is wrote by hq at 2025/08/26 for bug 2187
b.liu87afc4c2024-08-14 17:33:45 +08001678 {
b.liu7ca612c2025-04-25 09:23:36 +08001679 if(req_cell_info_get(cli_info->sim_id, cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu87afc4c2024-08-14 17:33:45 +08001680 {
1681 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1682 err = MBTK_RIL_ERR_CME + cme_err;
1683 } else {
1684 err = MBTK_RIL_ERR_UNKNOWN;
1685 }
b.liub4772072024-08-15 14:47:03 +08001686 LOG("Get net cell fail.");
b.liu87afc4c2024-08-14 17:33:45 +08001687 }
1688 else
1689 {
b.liub4772072024-08-15 14:47:03 +08001690 LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_list.num);
b.liubeb61cc2025-02-13 10:38:29 +08001691 LOGD("data_len = %d", sizeof(mbtk_cell_info_array_t));
b.liu7ca612c2025-04-25 09:23:36 +08001692 ril_rsp_pack_send(cli_info->sim_id, 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 +08001693 }
1694 }
b.liub4772072024-08-15 14:47:03 +08001695 else // Lock cell
b.liu87afc4c2024-08-14 17:33:45 +08001696 {
b.liub4772072024-08-15 14:47:03 +08001697 char *mem = (char*)(pack->data);
1698 int len = pack->data_len;
1699 char reg[100] = {0};
b.liu7ca612c2025-04-25 09:23:36 +08001700 if(req_cell_info_set(cli_info->sim_id, cli_info->port, mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liub4772072024-08-15 14:47:03 +08001701 {
1702 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1703 err = MBTK_RIL_ERR_CME + cme_err;
1704 } else {
1705 err = MBTK_RIL_ERR_UNKNOWN;
1706 }
1707 }
1708 else
1709 {
b.liu7ca612c2025-04-25 09:23:36 +08001710 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg));
b.liub4772072024-08-15 14:47:03 +08001711 }
b.liu87afc4c2024-08-14 17:33:45 +08001712 }
1713 break;
1714 }
b.liu557c81d2024-11-19 16:52:45 +08001715 case RIL_MSG_ID_NET_OOS:
1716 {
1717 if(pack->data_len == 0 || pack->data == NULL) // Get net oos.
1718 {
1719 mbtk_ril_oos_info_t oos_info;
1720 memset(&oos_info, 0, sizeof(mbtk_ril_oos_info_t));
b.liu7ca612c2025-04-25 09:23:36 +08001721 if(req_oos_get(cli_info->sim_id, cli_info->port, &oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu557c81d2024-11-19 16:52:45 +08001722 {
1723 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1724 err = MBTK_RIL_ERR_CME + cme_err;
1725 } else {
1726 err = MBTK_RIL_ERR_UNKNOWN;
1727 }
1728 LOG("Get net oos fail.");
1729 }
1730 else
1731 {
1732 LOG("req_oos_get() success,cell number: %d", oos_info.state);
b.liu7ca612c2025-04-25 09:23:36 +08001733 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &oos_info, sizeof(mbtk_ril_oos_info_t));
b.liu557c81d2024-11-19 16:52:45 +08001734 }
1735 }
1736 else // Set net oos.
1737 {
1738 mbtk_ril_oos_info_t *oos_info = (mbtk_ril_oos_info_t*)(pack->data);
b.liu7ca612c2025-04-25 09:23:36 +08001739 if(req_oos_set(cli_info->sim_id, cli_info->port, oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON)
b.liu557c81d2024-11-19 16:52:45 +08001740 {
1741 if(cme_err != MBTK_RIL_ERR_CME_NON) {
1742 err = MBTK_RIL_ERR_CME + cme_err;
1743 } else {
1744 err = MBTK_RIL_ERR_UNKNOWN;
1745 }
1746 }
1747 else
1748 {
b.liu7ca612c2025-04-25 09:23:36 +08001749 ril_rsp_pack_send(cli_info->sim_id, cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0);
b.liu557c81d2024-11-19 16:52:45 +08001750 }
1751 }
1752 break;
1753 }
b.liu87afc4c2024-08-14 17:33:45 +08001754 default:
1755 {
1756 err = MBTK_RIL_ERR_REQ_UNKNOWN;
1757 LOG("Unknown request : %s", id2str(pack->msg_id));
1758 break;
1759 }
1760 }
1761
1762 return err;
1763}
1764