b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1 | #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.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 23 | mbtk_cell_pack_info_t cell_info; |
| 24 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 25 | extern ril_band_info_t band_info; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 26 | void ril_rsp_pack_send(ATPortType_enum port, int fd, int ril_id, int msg_index, const void* data, int data_len); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 27 | |
| 28 | /* |
| 29 | AT+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 | |
| 33 | OK |
| 34 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 35 | static int req_available_net_get(ATPortType_enum port, mbtk_net_info_array_t* nets, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 36 | { |
| 37 | ATResponse *response = NULL; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 38 | int err = at_send_command_singleline(port, "AT+COPS=?", "+COPS:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 39 | |
| 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 | } |
| 114 | exit: |
| 115 | at_response_free(response); |
| 116 | return err; |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | AT+COPS? |
| 121 | +COPS: 1 |
| 122 | |
| 123 | OK |
| 124 | |
| 125 | or |
| 126 | |
| 127 | AT+COPS? |
| 128 | +COPS: 0,2,"46001",7 |
| 129 | |
| 130 | OK |
| 131 | |
| 132 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 133 | static int req_net_sel_mode_get(ATPortType_enum port, mbtk_net_info_t *net, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 134 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 140 | int err = at_send_command_singleline(port, "AT+COPS?", "+COPS:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 141 | //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 | |
| 204 | exit: |
| 205 | //LOG("req_net_sel_mode_get() 8"); |
| 206 | //sleep(1); |
| 207 | at_response_free(response); |
| 208 | return err; |
| 209 | } |
| 210 | |
| 211 | /* |
| 212 | AT+COPS=0 |
| 213 | or |
| 214 | AT+COPS=1,2,"46000",7 |
| 215 | |
| 216 | OK |
| 217 | |
| 218 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 219 | static int req_net_sel_mode_set(ATPortType_enum port, mbtk_net_info_t* net, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 220 | { |
| 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.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 236 | int err = at_send_command(port, cmd, &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 237 | |
| 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 | |
| 245 | exit: |
| 246 | at_response_free(response); |
| 247 | return err; |
| 248 | } |
| 249 | |
| 250 | /* |
| 251 | AT*BAND=15 |
| 252 | OK |
| 253 | |
| 254 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 255 | static int req_band_set(ATPortType_enum port, mbtk_band_info_t* band, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 256 | { |
| 257 | ATResponse *response = NULL; |
| 258 | char cmd[100] = {0}; |
| 259 | int err = -1; |
| 260 | |
| 261 | if(band->gsm_band == 0 && band->umts_band == 0 |
| 262 | && band->tdlte_band == 0 && band->fddlte_band == 0) { |
| 263 | sprintf(cmd, "AT*BAND=%d", band->net_pref); |
| 264 | } else { |
| 265 | log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t)); |
| 266 | log_hex("BAND", band, sizeof(mbtk_band_info_t)); |
| 267 | |
| 268 | if(band->gsm_band == 0) { |
| 269 | band->gsm_band = band_info.band_support.gsm_band; |
| 270 | } |
| 271 | if(band->umts_band == 0) { |
| 272 | band->umts_band = band_info.band_support.umts_band; |
| 273 | } |
| 274 | if(band->tdlte_band == 0) { |
| 275 | band->tdlte_band = band_info.band_support.tdlte_band; |
| 276 | } |
| 277 | if(band->fddlte_band == 0) { |
| 278 | band->fddlte_band = band_info.band_support.fddlte_band; |
| 279 | } |
| 280 | |
| 281 | if((band->gsm_band & band_info.band_support.gsm_band) != band->gsm_band) { |
| 282 | LOG("GSM band error."); |
| 283 | goto exit; |
| 284 | } |
| 285 | |
| 286 | if((band->umts_band & band_info.band_support.umts_band) != band->umts_band) { |
| 287 | LOG("UMTS band error."); |
| 288 | goto exit; |
| 289 | } |
| 290 | |
| 291 | if((band->tdlte_band & band_info.band_support.tdlte_band) != band->tdlte_band) { |
| 292 | LOG("TDLTE band error."); |
| 293 | goto exit; |
| 294 | } |
| 295 | |
| 296 | if((band->fddlte_band & band_info.band_support.fddlte_band) != band->fddlte_band) { |
| 297 | LOG("FDDLTE band error."); |
| 298 | goto exit; |
| 299 | } |
| 300 | |
| 301 | if((band->lte_ext_band & band_info.band_support.lte_ext_band) != band->lte_ext_band) { |
| 302 | LOG("EXT_LTE band error."); |
| 303 | goto exit; |
| 304 | } |
| 305 | |
| 306 | if(band->net_pref == 0xFF) { // No change net_pref. |
| 307 | int tmp_int; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 308 | err = at_send_command_singleline(port, "AT*BAND?", "*BAND:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 309 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 310 | if(cme_err) { |
| 311 | *cme_err = at_get_cme_error(response); |
| 312 | } |
| 313 | goto exit; |
| 314 | } |
| 315 | |
| 316 | char *line = response->p_intermediates->line; |
| 317 | err = at_tok_start(&line); |
| 318 | if (err < 0) |
| 319 | { |
| 320 | goto exit; |
| 321 | } |
| 322 | |
| 323 | err = at_tok_nextint(&line, &tmp_int); |
| 324 | if (err < 0) |
| 325 | { |
| 326 | goto exit; |
| 327 | } |
| 328 | band->net_pref = (uint8)tmp_int; // Set to current net_pref. |
| 329 | |
| 330 | at_response_free(response); |
| 331 | } |
| 332 | |
| 333 | if(band->lte_ext_band > 0) { |
| 334 | 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); |
| 335 | } else { |
| 336 | sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band); |
| 337 | } |
| 338 | } |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 339 | err = at_send_command(port, cmd, &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 340 | |
| 341 | if (err < 0 || response->success == 0){ |
| 342 | if(cme_err) { |
| 343 | *cme_err = at_get_cme_error(response); |
| 344 | } |
| 345 | goto exit; |
| 346 | } |
| 347 | |
| 348 | err = 0; |
| 349 | exit: |
| 350 | at_response_free(response); |
| 351 | return err; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | // ??????? |
| 356 | AT*BAND=? |
| 357 | *BAND:(0-18),79,147,482,524503 |
| 358 | |
| 359 | OK |
| 360 | |
| 361 | // ??????????? |
| 362 | AT*BAND? |
| 363 | *BAND: 15, 78, 147, 482, 524503, 0, 2, 2, 0, 0 |
| 364 | |
| 365 | OK |
| 366 | |
| 367 | // ????????? |
| 368 | AT*BAND=5,79,147,128,1 |
| 369 | OK |
| 370 | |
| 371 | net_prefferred?? |
| 372 | 0 : GSM only |
| 373 | 1 : UMTS only |
| 374 | 2 : GSM/UMTS(auto) |
| 375 | 3 : GSM/UMTS(GSM preferred) |
| 376 | 4 : GSM/UMTS(UMTS preferred) |
| 377 | 5 : LTE only |
| 378 | 6 : GSM/LTE(auto) |
| 379 | 7 : GSM/LTE(GSM preferred) |
| 380 | 8 : GSM/LTE(LTE preferred) |
| 381 | 9 : UMTS/LTE(auto) |
| 382 | 10 : UMTS/LTE(UMTS preferred) |
| 383 | 11 : UMTS/LTE(LTE preferred) |
| 384 | 12 : GSM/UMTS/LTE(auto) |
| 385 | 13 : GSM/UMTS/LTE(GSM preferred) |
| 386 | 14 : GSM/UMTS/LTE(UMTS preferred) |
| 387 | 15 : GSM/UMTS/LTE(LTE preferred) |
| 388 | GSM band?? |
| 389 | 1 ?C PGSM 900 (standard or primary) |
| 390 | 2 ?C DCS GSM 1800 |
| 391 | 4 ?C PCS GSM 1900 |
| 392 | 8 ?C EGSM 900 (extended) |
| 393 | 16 ?C GSM 450 |
| 394 | 32 ?C GSM 480 |
| 395 | 64 ?C GSM 850 |
| 396 | 512 - BAND_LOCK_BIT // used for GSM band setting |
| 397 | UMTS band?? |
| 398 | 1 ?C UMTS_BAND_1 |
| 399 | 2 ?C UMTS_BAND_2 |
| 400 | 4 ?C UMTS_BAND_3 |
| 401 | 8 ?C UMTS_BAND_4 |
| 402 | 16 ?C UMTS_BAND_5 |
| 403 | 32 ?C UMTS_BAND_6 |
| 404 | 64 ?C UMTS_BAND_7 |
| 405 | 128 ?C UMTS_BAND_8 |
| 406 | 256 ?C UMTS_BAND_9 |
| 407 | LTEbandH(TDD-LTE band) |
| 408 | 32 ?C TDLTE_BAND_38 |
| 409 | 64 ?C TDLTE_BAND_39 |
| 410 | 128 ?C TDLTE_BAND_40 |
| 411 | 256 ?C TDLTE_BAND_41 |
| 412 | LTEbandL(FDD-LTE band) |
| 413 | 1 ?C FDDLTE_BAND_1 |
| 414 | 4 ?C FDDLTE _BAND_3 |
| 415 | 8 ?C FDDLTE _BAND_4 |
| 416 | 64 ?C FDDLTE _BAND_7 |
| 417 | 65536 ?C FDDLTE _BAND_17 |
| 418 | 524288 ?C FDDLTE _BAND_20 |
| 419 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 420 | static int req_band_get(ATPortType_enum port, mbtk_band_info_t *band, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 421 | { |
| 422 | ATResponse *response = NULL; |
| 423 | int tmp_int; |
| 424 | |
| 425 | log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t)); |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 426 | int err = at_send_command_singleline(port, "AT*BAND?", "*BAND:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 427 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 428 | if(cme_err) { |
| 429 | *cme_err = at_get_cme_error(response); |
| 430 | } |
| 431 | goto exit; |
| 432 | } |
| 433 | |
| 434 | char *line = response->p_intermediates->line; |
| 435 | err = at_tok_start(&line); |
| 436 | if (err < 0) |
| 437 | { |
| 438 | goto exit; |
| 439 | } |
| 440 | |
| 441 | err = at_tok_nextint(&line, &tmp_int); |
| 442 | if (err < 0) |
| 443 | { |
| 444 | goto exit; |
| 445 | } |
| 446 | band->net_pref = (uint8)tmp_int; |
| 447 | |
| 448 | err = at_tok_nextint(&line, &tmp_int); |
| 449 | if (err < 0) |
| 450 | { |
| 451 | goto exit; |
| 452 | } |
| 453 | band->gsm_band = (uint16)tmp_int; |
| 454 | |
| 455 | err = at_tok_nextint(&line, &tmp_int); |
| 456 | if (err < 0) |
| 457 | { |
| 458 | goto exit; |
| 459 | } |
| 460 | band->umts_band = (uint16)tmp_int; |
| 461 | |
| 462 | err = at_tok_nextint(&line, &tmp_int); |
| 463 | if (err < 0) |
| 464 | { |
| 465 | goto exit; |
| 466 | } |
| 467 | band->tdlte_band = (uint32)tmp_int; |
| 468 | |
| 469 | err = at_tok_nextint(&line, &tmp_int); |
| 470 | if (err < 0) |
| 471 | { |
| 472 | goto exit; |
| 473 | } |
| 474 | band->fddlte_band = (uint32)tmp_int; |
| 475 | |
| 476 | // roamingConfig |
| 477 | err = at_tok_nextint(&line, &tmp_int); |
| 478 | if (err < 0) |
| 479 | { |
| 480 | goto exit; |
| 481 | } |
| 482 | |
| 483 | // srvDomain |
| 484 | err = at_tok_nextint(&line, &tmp_int); |
| 485 | if (err < 0) |
| 486 | { |
| 487 | goto exit; |
| 488 | } |
| 489 | |
| 490 | // bandPriorityFlag |
| 491 | err = at_tok_nextint(&line, &tmp_int); |
| 492 | if (err < 0) |
| 493 | { |
| 494 | goto exit; |
| 495 | } |
| 496 | |
| 497 | // |
| 498 | err = at_tok_nextint(&line, &tmp_int); |
| 499 | if (err < 0) |
| 500 | { |
| 501 | goto exit; |
| 502 | } |
| 503 | |
| 504 | // ltebandExt |
| 505 | err = at_tok_nextint(&line, &tmp_int); |
| 506 | if (err < 0) |
| 507 | { |
| 508 | goto exit; |
| 509 | } |
| 510 | band->lte_ext_band = (uint32)tmp_int; |
| 511 | |
| 512 | log_hex("BAND", band, sizeof(mbtk_band_info_t)); |
| 513 | |
| 514 | exit: |
| 515 | at_response_free(response); |
| 516 | return err; |
| 517 | } |
| 518 | |
| 519 | /* |
| 520 | AT+CSQ |
| 521 | +CSQ: 31,99 |
| 522 | |
| 523 | OK |
| 524 | |
| 525 | AT+CESQ |
| 526 | +CESQ: 60,99,255,255,20,61 |
| 527 | |
| 528 | OK |
| 529 | |
| 530 | AT+COPS? |
| 531 | +COPS: 0,2,"46001",7 |
| 532 | |
| 533 | OK |
| 534 | |
| 535 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 536 | static int req_net_signal_get(ATPortType_enum port, mbtk_signal_info_t *signal, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 537 | { |
| 538 | ATResponse *response = NULL; |
| 539 | int tmp_int; |
| 540 | char *tmp_ptr = NULL; |
| 541 | // AT+EEMOPT=1 in the first. |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 542 | int err = at_send_command_singleline(port, "AT+CSQ", "+CSQ:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 543 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 544 | if(cme_err != NULL) |
| 545 | *cme_err = at_get_cme_error(response); |
| 546 | err = -1; |
| 547 | goto exit; |
| 548 | } |
| 549 | |
| 550 | char *line = response->p_intermediates->line; |
| 551 | err = at_tok_start(&line); |
| 552 | if (err < 0) |
| 553 | { |
| 554 | goto exit; |
| 555 | } |
| 556 | err = at_tok_nextint(&line, &tmp_int); |
| 557 | if (err < 0) |
| 558 | { |
| 559 | goto exit; |
| 560 | } |
| 561 | signal->rssi = (uint8)tmp_int; |
| 562 | at_response_free(response); |
| 563 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 564 | err = at_send_command_singleline(port, "AT+CESQ", "+CESQ:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 565 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 566 | if(cme_err != NULL) |
| 567 | *cme_err = at_get_cme_error(response); |
| 568 | err = -1; |
| 569 | goto exit; |
| 570 | } |
| 571 | |
| 572 | line = response->p_intermediates->line; |
| 573 | err = at_tok_start(&line); |
| 574 | if (err < 0) |
| 575 | { |
| 576 | goto exit; |
| 577 | } |
| 578 | err = at_tok_nextint(&line, &tmp_int); |
| 579 | if (err < 0) |
| 580 | { |
| 581 | goto exit; |
| 582 | } |
| 583 | signal->rxlev = (uint8)tmp_int; |
| 584 | |
| 585 | err = at_tok_nextint(&line, &tmp_int); |
| 586 | if (err < 0) |
| 587 | { |
| 588 | goto exit; |
| 589 | } |
| 590 | signal->ber = (uint8)tmp_int; |
| 591 | |
| 592 | err = at_tok_nextint(&line, &tmp_int); |
| 593 | if (err < 0) |
| 594 | { |
| 595 | goto exit; |
| 596 | } |
| 597 | signal->rscp = (uint8)tmp_int; |
| 598 | |
| 599 | err = at_tok_nextint(&line, &tmp_int); |
| 600 | if (err < 0) |
| 601 | { |
| 602 | goto exit; |
| 603 | } |
| 604 | signal->ecno = (uint8)tmp_int; |
| 605 | |
| 606 | err = at_tok_nextint(&line, &tmp_int); |
| 607 | if (err < 0) |
| 608 | { |
| 609 | goto exit; |
| 610 | } |
| 611 | signal->rsrq = (uint8)tmp_int; |
| 612 | |
| 613 | err = at_tok_nextint(&line, &tmp_int); |
| 614 | if (err < 0) |
| 615 | { |
| 616 | goto exit; |
| 617 | } |
| 618 | signal->rsrp = (uint8)tmp_int; |
| 619 | |
| 620 | at_response_free(response); |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 621 | err = at_send_command_singleline(port, "AT+COPS?", "+COPS:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 622 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 623 | if(cme_err != NULL) |
| 624 | *cme_err = at_get_cme_error(response); |
| 625 | err = -1; |
| 626 | goto exit; |
| 627 | } |
| 628 | line = response->p_intermediates->line; |
| 629 | err = at_tok_start(&line); |
| 630 | if (err < 0) |
| 631 | { |
| 632 | goto exit; |
| 633 | } |
| 634 | err = at_tok_nextint(&line, &tmp_int); |
| 635 | if (err < 0) |
| 636 | { |
| 637 | goto exit; |
| 638 | } |
| 639 | if(!at_tok_hasmore(&line)) { |
| 640 | goto exit; |
| 641 | } |
| 642 | err = at_tok_nextint(&line, &tmp_int); |
| 643 | if (err < 0) |
| 644 | { |
| 645 | goto exit; |
| 646 | } |
| 647 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 648 | if (err < 0) |
| 649 | { |
| 650 | goto exit; |
| 651 | } |
| 652 | err = at_tok_nextint(&line, &tmp_int); |
| 653 | if (err < 0) |
| 654 | { |
| 655 | goto exit; |
| 656 | } |
| 657 | signal->type = (uint8)tmp_int; |
| 658 | |
| 659 | exit: |
| 660 | at_response_free(response); |
| 661 | return err; |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | AT+CREG=3 |
| 666 | OK |
| 667 | |
| 668 | AT+CREG? |
| 669 | +CREG: 3,1,"8330","06447340",7 |
| 670 | |
| 671 | OK |
| 672 | |
| 673 | AT+CREG? |
| 674 | +CREG: 3,0 |
| 675 | |
| 676 | OK |
| 677 | |
| 678 | AT+CEREG? |
| 679 | +CEREG: 3,1,"8330","06447340",7 |
| 680 | |
| 681 | OK |
| 682 | |
| 683 | |
| 684 | AT+CIREG? |
| 685 | +CIREG: 2,1,15 |
| 686 | |
| 687 | OK |
| 688 | |
| 689 | AT+CIREG? |
| 690 | +CIREG: 0 |
| 691 | |
| 692 | OK |
| 693 | |
| 694 | |
| 695 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 696 | static int req_net_reg_get(ATPortType_enum port, mbtk_net_reg_info_t *reg, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 697 | { |
| 698 | ATResponse *response = NULL; |
| 699 | int tmp_int; |
| 700 | char *tmp_str = NULL; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 701 | int err = at_send_command(port, "AT+CREG=3", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 702 | if (err < 0 || response->success == 0){ |
| 703 | if(cme_err) { |
| 704 | *cme_err = at_get_cme_error(response); |
| 705 | } |
| 706 | goto exit; |
| 707 | } |
| 708 | at_response_free(response); |
| 709 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 710 | err = at_send_command_multiline(port, "AT+CREG?", "+CREG:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 711 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 712 | if(cme_err) { |
| 713 | *cme_err = at_get_cme_error(response); |
| 714 | } |
| 715 | goto exit; |
| 716 | } |
| 717 | |
| 718 | char *line = response->p_intermediates->line; |
| 719 | err = at_tok_start(&line); |
| 720 | if (err < 0) |
| 721 | { |
| 722 | goto exit; |
| 723 | } |
| 724 | err = at_tok_nextint(&line, &tmp_int); // n |
| 725 | if (err < 0) |
| 726 | { |
| 727 | goto exit; |
| 728 | } |
| 729 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 730 | if (err < 0) |
| 731 | { |
| 732 | goto exit; |
| 733 | } |
| 734 | reg->call_state = (uint8)tmp_int; |
| 735 | |
| 736 | if(at_tok_hasmore(&line)) { |
| 737 | err = at_tok_nextstr(&line, &tmp_str); // lac |
| 738 | if (err < 0) |
| 739 | { |
| 740 | goto exit; |
| 741 | } |
| 742 | reg->lac = strtol(tmp_str, NULL, 16); |
| 743 | |
| 744 | err = at_tok_nextstr(&line, &tmp_str); // ci |
| 745 | if (err < 0) |
| 746 | { |
| 747 | goto exit; |
| 748 | } |
| 749 | reg->ci = strtol(tmp_str, NULL, 16); |
| 750 | |
| 751 | err = at_tok_nextint(&line, &tmp_int);// AcT |
| 752 | if (err < 0) |
| 753 | { |
| 754 | goto exit; |
| 755 | } |
| 756 | reg->type = (uint8)tmp_int; |
| 757 | } |
| 758 | at_response_free(response); |
| 759 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 760 | err = at_send_command_multiline(port, "AT+CEREG?", "+CEREG:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 761 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 762 | if(cme_err) { |
| 763 | *cme_err = at_get_cme_error(response); |
| 764 | } |
| 765 | goto exit; |
| 766 | } |
| 767 | |
| 768 | line = response->p_intermediates->line; |
| 769 | err = at_tok_start(&line); |
| 770 | if (err < 0) |
| 771 | { |
| 772 | goto exit; |
| 773 | } |
| 774 | err = at_tok_nextint(&line, &tmp_int); // n |
| 775 | if (err < 0) |
| 776 | { |
| 777 | goto exit; |
| 778 | } |
| 779 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 780 | if (err < 0) |
| 781 | { |
| 782 | goto exit; |
| 783 | } |
| 784 | reg->data_state = (uint8)tmp_int; |
| 785 | |
| 786 | if(reg->lac == 0 && at_tok_hasmore(&line)) { |
| 787 | err = at_tok_nextstr(&line, &tmp_str); // lac |
| 788 | if (err < 0) |
| 789 | { |
| 790 | goto exit; |
| 791 | } |
| 792 | reg->lac = strtol(tmp_str, NULL, 16); |
| 793 | |
| 794 | err = at_tok_nextstr(&line, &tmp_str); // ci |
| 795 | if (err < 0) |
| 796 | { |
| 797 | goto exit; |
| 798 | } |
| 799 | reg->ci = strtol(tmp_str, NULL, 16); |
| 800 | |
| 801 | err = at_tok_nextint(&line, &tmp_int);// AcT |
| 802 | if (err < 0) |
| 803 | { |
| 804 | goto exit; |
| 805 | } |
| 806 | reg->type = (uint8)tmp_int; |
| 807 | } |
| 808 | at_response_free(response); |
| 809 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 810 | err = at_send_command_multiline(port, "AT+CIREG?", "+CIREG:", &response); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 811 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 812 | reg->ims_state = (uint8)0; |
| 813 | err = 0; |
| 814 | goto exit; |
| 815 | } |
| 816 | line = response->p_intermediates->line; |
| 817 | err = at_tok_start(&line); |
| 818 | if (err < 0) |
| 819 | { |
| 820 | goto exit; |
| 821 | } |
| 822 | err = at_tok_nextint(&line, &tmp_int); // n/stat |
| 823 | if (err < 0) |
| 824 | { |
| 825 | goto exit; |
| 826 | } |
| 827 | if(at_tok_hasmore(&line)) { |
| 828 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 829 | if (err < 0) |
| 830 | { |
| 831 | goto exit; |
| 832 | } |
| 833 | reg->ims_state = (uint8)tmp_int; |
| 834 | } else { |
| 835 | reg->ims_state = (uint8)tmp_int; |
| 836 | } |
| 837 | |
| 838 | exit: |
| 839 | at_response_free(response); |
| 840 | return err; |
| 841 | } |
| 842 | |
| 843 | /* |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 844 | AT+EEMOPT=1 |
| 845 | OK |
| 846 | |
| 847 | // LTE |
| 848 | AT+EEMGINFO? |
| 849 | // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>, |
| 850 | // <rsrp>,<rsrq>, <sinr>, |
| 851 | // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi, |
| 852 | // cellId,subFrameAssignType,specialSubframePatterns,transMode |
| 853 | // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt, |
| 854 | // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB, |
| 855 | // dlBer, ulBer, |
| 856 | // diversitySinr, diversityRssi |
| 857 | +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20, |
| 858 | 0, 0, 0, |
| 859 | 1, 10, 0, 1, 0, 1059, 78, 3959566565, |
| 860 | 105149248, 2, 7, 7, |
| 861 | 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777, |
| 862 | 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0, |
| 863 | 0, 0, |
| 864 | 7, 44 |
| 865 | |
| 866 | // index,phyCellId,euArfcn,rsrp,rsrq |
| 867 | +EEMLTEINTER: 0, 65535, 38950, 0, 0 |
| 868 | |
| 869 | +EEMLTEINTER: 1, 0, 0, 0, 0 |
| 870 | |
| 871 | +EEMLTEINTER: 2, 0, 4294967295, 255, 255 |
| 872 | |
| 873 | +EEMLTEINTER: 3, 65535, 1300, 0, 0 |
| 874 | |
| 875 | +EEMLTEINTER: 4, 0, 0, 0, 0 |
| 876 | |
| 877 | +EEMLTEINTER: 5, 0, 4294967295, 247, 0 |
| 878 | |
| 879 | +EEMLTEINTER: 6, 197, 41332, 24, 9 |
| 880 | |
| 881 | +EEMLTEINTER: 7, 0, 0, 0, 0 |
| 882 | |
| 883 | +EEMLTEINTER: 8, 0, 0, 0, 0 |
| 884 | |
| 885 | +EEMLTEINTRA: 0, 429, 40936, 56, 12 |
| 886 | |
| 887 | +EEMLTEINTERRAT: 0,0 |
| 888 | |
| 889 | +EEMLTEINTERRAT: 1,0 |
| 890 | |
| 891 | +EEMGINFO: 3, 2 // <state>: |
| 892 | // 0: ME in Idle mode |
| 893 | // 1: ME in Dedicated mode |
| 894 | // 2: ME in PS PTM mode |
| 895 | // 3: invalid state |
| 896 | // <nw_type>: |
| 897 | // 0: GSM 1: UMTS 2: LTE |
| 898 | |
| 899 | OK |
| 900 | |
| 901 | // WCDMA |
| 902 | AT+EEMGINFO? |
| 903 | // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent, |
| 904 | |
| 905 | // if sCMeasPresent == 1 |
| 906 | // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower, |
| 907 | // endif |
| 908 | |
| 909 | // if sCParamPresent == 1 |
| 910 | // rac, nom, mcc, mnc_len, mnc, lac, ci, |
| 911 | // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed, |
| 912 | // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport, |
| 913 | // endif |
| 914 | |
| 915 | // if ueOpStatusPresent == 1 |
| 916 | // rrcState, numLinks, srncId, sRnti, |
| 917 | // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn, |
| 918 | // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause, |
| 919 | // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput, |
| 920 | // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count |
| 921 | // endif |
| 922 | // |
| 923 | +EEMUMTSSVC: 3, 1, 1, 1, |
| 924 | -80, 27, -6, -18, -115, -32768, |
| 925 | 1, 1, 1120, 2, 1, 61697, 168432821, |
| 926 | 15, 24, 10763, 0, 0, 0, 0, |
| 927 | 128, 128, 65535, 0, 0, |
| 928 | 2, 255, 65535, 4294967295, |
| 929 | 0, 0, 0, 0, 0, 0, |
| 930 | 0, 0, 0, 0, 0, 0, 1, 1, |
| 931 | 28672, 28672, 0, 0, 0, 0, 0, 0, 0, |
| 932 | 0, 0, 0, 0, 0, 0 |
| 933 | |
| 934 | // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc |
| 935 | +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32 |
| 936 | |
| 937 | +EEMUMTSINTRA: 1, -1, -32768, -18, -115, 0, 0, 65534, 2, 10763, 40, 32768 |
| 938 | |
| 939 | +EEMUMTSINTRA: 2, -32768, -18, -115, 0, 0, 65534, 3, 10763, 278, 32768, 65535 |
| 940 | |
| 941 | +EEMUMTSINTRA: 3, -18, -115, 0, 0, -2, 4, 10763, 28, 32768, 65535, 32768 |
| 942 | |
| 943 | +EEMUMTSINTRA: 4, -115, 0, 0, -2, 5, 10763, 270, 32768, 65535, 32768, 65518 |
| 944 | |
| 945 | +EEMUMTSINTRA: 5, 0, 0, -2, 6, 10763, 286, 32768, 65535, 32768, 65518, 65421 |
| 946 | |
| 947 | +EEMUMTSINTRA: 6, 0, -2, 7, 10763, 80, 32768, 65535, 32768, 65518, 65421, 0 |
| 948 | |
| 949 | +EEMUMTSINTRA: 7, -2, 8, 10763, 206, -32768, 65535, 32768, 65518, 65421, 0, 0 |
| 950 | |
| 951 | +EEMUMTSINTRA: 8, 9, 10763, 11, -32768, -1, 32768, 65518, 65421, 0, 0, 65534 |
| 952 | |
| 953 | +EEMUMTSINTRA: 9, 10763, 19, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 11 |
| 954 | |
| 955 | +EEMUMTSINTRA: 10, 232, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 12, 10763 |
| 956 | |
| 957 | +EEMUMTSINTRA: 11, -32768, -1, -32768, -18, -115, 0, 0, 65534, 13, 10763, 66 |
| 958 | |
| 959 | +EEMUMTSINTRA: 12, -1, -32768, -18, -115, 0, 0, 65534, 14, 10763, 216, 32768 |
| 960 | |
| 961 | +EEMUMTSINTRA: 13, -32768, -18, -115, 0, 0, 65534, 15, 10763, 183, 32768, 65535 |
| 962 | |
| 963 | +EEMUMTSINTRA: 14, -18, -115, 0, 0, -2, 16, 10763, 165, 32768, 65535, 32768 |
| 964 | |
| 965 | +EEMUMTSINTRA: 15, -115, 0, 0, -2, 17, 10763, 151, 32768, 65535, 32768, 65518 |
| 966 | |
| 967 | +EEMUMTSINTRA: 16, 0, 0, -2, 18, 10763, 43, 32768, 65535, 32768, 65518, 65421 |
| 968 | |
| 969 | +EEMUMTSINTRA: 17, 0, -2, 19, 10763, 72, 32768, 65535, 32768, 65518, 65421, 0 |
| 970 | |
| 971 | +EEMUMTSINTRA: 18, -2, 20, 10763, 157, -32768, 65535, 32768, 65518, 65421, 0, 0 |
| 972 | |
| 973 | +EEMUMTSINTRA: 19, 21, 10763, 165, -32768, -1, 32768, 65518, 65421, 0, 0, 65534 |
| 974 | |
| 975 | +EEMUMTSINTRA: 20, 10763, 301, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 23 |
| 976 | |
| 977 | +EEMUMTSINTRA: 21, 23, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 24, 10763 |
| 978 | |
| 979 | +EEMUMTSINTRA: 22, -32768, -1, -32768, -18, -115, 0, 0, 65534, 25, 10763, 0 |
| 980 | |
| 981 | +EEMUMTSINTRA: 23, -1, -32768, -18, -115, 0, 0, 65534, 26, 10763, 167, 32768 |
| 982 | |
| 983 | +EEMUMTSINTRA: 24, -32768, -18, -115, 0, 0, 65534, 27, 10763, 34, 32768, 65535 |
| 984 | |
| 985 | +EEMUMTSINTRA: 25, -18, -115, 0, 0, -2, 28, 10763, 313, 32768, 65535, 32768 |
| 986 | |
| 987 | +EEMUMTSINTRA: 26, -115, 0, 0, -2, 29, 10763, 152, 32768, 65535, 32768, 65518 |
| 988 | |
| 989 | +EEMUMTSINTRA: 27, 0, 0, -2, 30, 10763, 239, 0, 0, 0, 0, 0 |
| 990 | |
| 991 | +EEMUMTSINTRA: 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 992 | |
| 993 | +EEMUMTSINTRA: 29, 0, 0, 0, 0, -115, 0, 0, 65534, 30, 10763, 239 |
| 994 | |
| 995 | // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic |
| 996 | +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36 |
| 997 | |
| 998 | +EEMUMTSINTERRAT: 1, -107, -1, -1, 0, 0, 65534, 1, 72, 49, 0 |
| 999 | |
| 1000 | +EEMUMTSINTERRAT: 2, -1, -1, 0, 0, 65534, 2, 119, 15, 32768, 149 |
| 1001 | |
| 1002 | +EEMUMTSINTERRAT: 3, -1, 0, 0, -2, 3, 121, 23, 0, 0, 0 |
| 1003 | |
| 1004 | +EEMGINFO: 3, 1 |
| 1005 | |
| 1006 | OK |
| 1007 | |
| 1008 | |
| 1009 | // GSM |
| 1010 | AT+EEMGINFO? |
| 1011 | +EEMGINFOBASIC: 2 |
| 1012 | |
| 1013 | // mcc, mnc_len, mnc, lac, ci, nom, nco, |
| 1014 | // bsic, C1, C2, TA, TxPwr, |
| 1015 | // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub, |
| 1016 | // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn, |
| 1017 | // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support, |
| 1018 | // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count, |
| 1019 | // gsmBand,channelMode |
| 1020 | +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0, |
| 1021 | 63, 36, 146, 1, 7, |
| 1022 | 46, 42, 42, 7, 0, |
| 1023 | 53, 0, 8, 0, 1, 6, 53, |
| 1024 | 2, 0, 146, 42, 54, 0, 1, |
| 1025 | 1, 32, 0, 0, 0, 0, |
| 1026 | 0, 0 |
| 1027 | |
| 1028 | // PS_attached, attach_type, service_type, tx_power, c_value, |
| 1029 | // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation, |
| 1030 | // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause |
| 1031 | // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status |
| 1032 | +EEMGINFOPS: 1, 255, 0, 0, 0, |
| 1033 | 0, 0, 268435501, 1, 0, 0, |
| 1034 | 4, 0, 96, 0, 0, 0, |
| 1035 | 0, 0, 0, 65535, 0, 13350 |
| 1036 | |
| 1037 | +EEMGINFO: 0, 0 |
| 1038 | |
| 1039 | OK |
| 1040 | |
| 1041 | */ |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1042 | static int req_cell_info_get(ATPortType_enum port, int *cme_err) |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1043 | { |
| 1044 | ATResponse *response = NULL; |
| 1045 | int tmp_int; |
| 1046 | int buff_size = 0; |
| 1047 | // AT+EEMOPT=1 in the first. |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1048 | int err = at_send_command(port, "AT+EEMOPT=1", &response); |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1049 | if (err < 0 || response->success == 0){ |
| 1050 | *cme_err = at_get_cme_error(response); |
| 1051 | goto exit; |
| 1052 | } |
| 1053 | |
| 1054 | // Reset buffer in the first. |
| 1055 | memset(&cell_info, 0xFF, sizeof(mbtK_cell_pack_info_t)); |
| 1056 | cell_info.running = true; |
| 1057 | cell_info.cell_list.num = 0; |
| 1058 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1059 | err = at_send_command_singleline(port, "AT+EEMGINFO?", "+EEMGINFO:", &response); |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1060 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1061 | *cme_err = at_get_cme_error(response); |
| 1062 | goto exit; |
| 1063 | } |
| 1064 | |
| 1065 | // Now, cell infomation has get from URC message. |
| 1066 | |
| 1067 | char *line = response->p_intermediates->line; |
| 1068 | err = at_tok_start(&line); |
| 1069 | if (err < 0) |
| 1070 | { |
| 1071 | goto exit; |
| 1072 | } |
| 1073 | err = at_tok_nextint(&line, &tmp_int); |
| 1074 | if (err < 0) |
| 1075 | { |
| 1076 | goto exit; |
| 1077 | } |
| 1078 | err = at_tok_nextint(&line, &tmp_int); |
| 1079 | if (err < 0) |
| 1080 | { |
| 1081 | goto exit; |
| 1082 | } |
| 1083 | |
| 1084 | cell_info.cell_list.type = (uint8)tmp_int; |
| 1085 | cell_info.running = false; |
| 1086 | |
| 1087 | #if 0 |
| 1088 | while(lines_ptr) |
| 1089 | { |
| 1090 | // LTE |
| 1091 | if(strStartsWith(line, "+EEMLTESVC:")) // LTE Server Cell |
| 1092 | { |
| 1093 | |
| 1094 | } |
| 1095 | else if(strStartsWith(line, "+EEMLTEINTER:")) // LTE |
| 1096 | { |
| 1097 | |
| 1098 | } |
| 1099 | else if(strStartsWith(line, "+EEMLTEINTRA:")) // LTE |
| 1100 | { |
| 1101 | |
| 1102 | } |
| 1103 | else if(strStartsWith(line, "+EEMLTEINTERRAT:")) // LTE |
| 1104 | { |
| 1105 | |
| 1106 | } |
| 1107 | 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 |
| 1108 | // <nw_type>: 0: GSM 1: UMTS 2: LTE |
| 1109 | { |
| 1110 | |
| 1111 | } |
| 1112 | // WCDMA |
| 1113 | else if(strStartsWith(line, "+EEMUMTSSVC:")) // WCDMA Server Cell |
| 1114 | { |
| 1115 | |
| 1116 | } |
| 1117 | else if(strStartsWith(line, "+EEMUMTSINTRA:")) // WCDMA |
| 1118 | { |
| 1119 | |
| 1120 | } |
| 1121 | else if(strStartsWith(line, "+EEMUMTSINTERRAT:")) // WCDMA |
| 1122 | { |
| 1123 | |
| 1124 | } |
| 1125 | // GSM |
| 1126 | else if(strStartsWith(line, "+EEMGINFOBASIC:")) // Basic information in GSM |
| 1127 | // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode |
| 1128 | { |
| 1129 | |
| 1130 | } |
| 1131 | else if(strStartsWith(line, "+EEMGINFOSVC:")) // GSM Server Cell |
| 1132 | { |
| 1133 | |
| 1134 | } |
| 1135 | else if(strStartsWith(line, "+EEMGINFOPS:")) // PS |
| 1136 | { |
| 1137 | |
| 1138 | } |
| 1139 | |
| 1140 | |
| 1141 | lines_ptr = lines_ptr->p_next; |
| 1142 | } |
| 1143 | #endif |
| 1144 | |
| 1145 | exit: |
| 1146 | at_response_free(response); |
| 1147 | return buff_size; |
| 1148 | } |
| 1149 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1150 | static int req_cell_info_set(ATPortType_enum port, const char *cmgl, char *reg, int len, int *cme_err) |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1151 | { |
| 1152 | ATResponse *response = NULL; |
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 1153 | char cmd[500] = {0}; |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1154 | char data[218] = {0}; |
| 1155 | int err = 0; |
| 1156 | |
| 1157 | memcpy(data, cmgl, len); |
| 1158 | |
| 1159 | sprintf(cmd, "AT*CELL=%s", data); |
| 1160 | |
| 1161 | if(strlen(cmd) > 0) |
| 1162 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1163 | err = at_send_command_multiline(port, cmd, "", &response); |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1164 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1165 | *cme_err = at_get_cme_error(response); |
| 1166 | goto exit; |
| 1167 | } |
| 1168 | |
| 1169 | ATLine* lines_ptr = response->p_intermediates; |
| 1170 | char *line = NULL; |
b.liu | 62240ee | 2024-11-07 17:52:45 +0800 | [diff] [blame] | 1171 | // int reg_len = 0; |
| 1172 | // bool flag = false; |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1173 | while(lines_ptr) |
| 1174 | { |
| 1175 | line = lines_ptr->line; |
| 1176 | if(line ==NULL) |
| 1177 | { |
| 1178 | LOGD("line is null----------------------"); |
| 1179 | } |
| 1180 | lines_ptr = lines_ptr->p_next; |
| 1181 | } |
| 1182 | } |
| 1183 | err = 0; |
| 1184 | memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss")); |
| 1185 | exit: |
| 1186 | at_response_free(response); |
| 1187 | return err; |
| 1188 | } |
| 1189 | |
b.liu | 557c81d | 2024-11-19 16:52:45 +0800 | [diff] [blame^] | 1190 | /* |
| 1191 | AT+OOSPP=1 |
| 1192 | or |
| 1193 | AT+OOSPP=0 |
| 1194 | or |
| 1195 | AT+OOSPP=1,20,30,40 //AtOospp() |
| 1196 | param1£ºmode |
| 1197 | param2£ºoosPhasePeriod[0] //5 times, 5s by default; |
| 1198 | param3£ºoosPhasePeriod[1] //5 times, 10s by default; |
| 1199 | param4£ºoosPhasePeriod[2] //unlimited, 20s by default; |
| 1200 | |
| 1201 | |
| 1202 | BTW |
| 1203 | 1, Èç¹ûÖ»ÊäÈëmode=1£¬ÆäÓà²ÎÊý²»ÉèÖã¬Ï൱ÓÚÕâ¸ö¹¦ÄÜ´ò¿ª£¬Ê±¼ä¼ä¸ôÊÇÕâ¸ö¹¦ÄܵÄĬÈÏÖµ¡£ |
| 1204 | 2, Èç¹ûµ±mode=1¼ÓÉÏÆäÓàÉèÖòÎÊýºó£¬¹¦ÄÜ´ò¿ª£¬Ê±¼ä¼ä¸ôÊDZ¾´ÎÉèÖõÄÖµ£» |
| 1205 | 3£¬Èç¹ûÔÙÉèÖÃmode=0£¬Ï൱ÓÚÕâ¸ö¹¦Äܹرգ¬ÊÇ×߯½Ì¨×Ô¼ºÁíÒ»Ì×µÄËÑÍøÉèÖᣠ|
| 1206 | ƽ̨±¾ÉíÊÇÓÐÒ»Ì×¼ä¸ôËÑÍø£¬Ò²ÓÐÀúʷƵµãÓÅÏÈ´¦ÀíµÄÂß¼£¨²»ÐèÒªÎÒÃǽøÐд¦Àí£©£¬ |
| 1207 | Ìṩ¸øÎÒÃǵÄAT+OOSPPÖ¸ÁîÊÇÈÃÎÒÃÇ¿ÉÒÔ×Ô¶¨ÒåËÑÍø¼ä¸ô |
| 1208 | */ |
| 1209 | static int req_oos_set(ATPortType_enum port, const mbtk_ril_oos_info_t* oos_info, int *cme_err) |
| 1210 | { |
| 1211 | ATResponse *response = NULL; |
| 1212 | char cmd[100] = {0}; |
| 1213 | int err = 0; |
| 1214 | |
| 1215 | if ((oos_info->state == 1 && oos_info->oosPhase[0] == 0 && oos_info->oosPhase[1] == 0 && oos_info->oosPhase[2] == 0) \ |
| 1216 | || oos_info->state == 0) |
| 1217 | { |
| 1218 | sprintf(cmd, "AT+OOSPP=%d", oos_info->state);//Ö»ÓÐÒ»¸öÖµ0/1 |
| 1219 | } |
| 1220 | else |
| 1221 | { |
| 1222 | if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] != 0) && (oos_info->oosPhase[2] != 0)) |
| 1223 | { |
| 1224 | sprintf(cmd, "AT+OOSPP=%d,%d,%d,%d", oos_info->state, oos_info->oosPhase[0], oos_info->oosPhase[1], oos_info->oosPhase[2]); |
| 1225 | } |
| 1226 | else if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] != 0) && (oos_info->oosPhase[2] == 0)) |
| 1227 | { |
| 1228 | sprintf(cmd, "AT+OOSPP=%d,%d,%d", oos_info->state, oos_info->oosPhase[0], oos_info->oosPhase[1]); |
| 1229 | } |
| 1230 | else if ((oos_info->oosPhase[0] != 0) && (oos_info->oosPhase[1] == 0) && (oos_info->oosPhase[2] == 0)) |
| 1231 | { |
| 1232 | sprintf(cmd, "AT+OOSPP=%d,%d", oos_info->state, oos_info->oosPhase[0]); |
| 1233 | } |
| 1234 | else |
| 1235 | { |
| 1236 | LOGE("AT+OOSPP SET ERR"); |
| 1237 | goto exit; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | LOGI("Set the oos command is = [%s]\n", cmd); |
| 1242 | err = at_send_command(port, cmd, &response); |
| 1243 | if (err < 0 || response->success == 0){ |
| 1244 | *cme_err = at_get_cme_error(response); |
| 1245 | goto exit; |
| 1246 | } |
| 1247 | |
| 1248 | exit: |
| 1249 | at_response_free(response); |
| 1250 | return err; |
| 1251 | } |
| 1252 | |
| 1253 | /* |
| 1254 | AT+OOSPP? |
| 1255 | ¿ª(ĬÈÏÖµ)£º |
| 1256 | +OOSPP:5,10,20 |
| 1257 | ¹Ø£º |
| 1258 | +OOSPP:0 |
| 1259 | */ |
| 1260 | static int req_oos_get(ATPortType_enum port, mbtk_ril_oos_info_t *oos_info, int *cme_err) |
| 1261 | { |
| 1262 | ATResponse *response = NULL; |
| 1263 | |
| 1264 | int err = at_send_command_singleline(port, "AT+OOSPP?", "+OOSPP:", &response); |
| 1265 | |
| 1266 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1267 | *cme_err = at_get_cme_error(response); |
| 1268 | goto exit; |
| 1269 | } |
| 1270 | |
| 1271 | char *line = response->p_intermediates->line; |
| 1272 | |
| 1273 | char *tmp_str = NULL; |
| 1274 | err = at_tok_start(&line);//+OOSPP:10,15,20,¹ýÂË+OOSPP: |
| 1275 | if (err < 0) |
| 1276 | { |
| 1277 | goto exit; |
| 1278 | } |
| 1279 | |
| 1280 | //LOG("req_oos_get =[%s]",line); |
| 1281 | |
| 1282 | err = at_tok_nextstr(&line, &tmp_str); |
| 1283 | if (err < 0) |
| 1284 | { |
| 1285 | goto exit; |
| 1286 | } |
| 1287 | |
| 1288 | int mode = atoi(tmp_str); |
| 1289 | if (mode == 0)//¹Ø±Õ״̬ |
| 1290 | { |
| 1291 | oos_info->state = mode; |
| 1292 | } |
| 1293 | else//¿ª×´Ì¬ |
| 1294 | { |
| 1295 | oos_info->state = 1; |
| 1296 | //LOG("tmp_str =[%s]",tmp_str); |
| 1297 | oos_info->oosPhase[0] = atoi(tmp_str); |
| 1298 | |
| 1299 | err = at_tok_nextstr(&line, &tmp_str); |
| 1300 | if (err < 0) |
| 1301 | { |
| 1302 | goto exit; |
| 1303 | } |
| 1304 | //LOG("tmp_str =[%s]",tmp_str); |
| 1305 | oos_info->oosPhase[1] = atoi(tmp_str); |
| 1306 | |
| 1307 | err = at_tok_nextstr(&line, &tmp_str); |
| 1308 | if (err < 0) |
| 1309 | { |
| 1310 | goto exit; |
| 1311 | } |
| 1312 | //LOG("tmp_str =[%s]",tmp_str); |
| 1313 | oos_info->oosPhase[2] = atoi(tmp_str); |
| 1314 | } |
| 1315 | |
| 1316 | exit: |
| 1317 | at_response_free(response); |
| 1318 | return err; |
| 1319 | } |
| 1320 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1321 | //void net_list_free(void *data); |
| 1322 | // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP. |
| 1323 | // Otherwise, do not call pack_error_send(). |
| 1324 | mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack) |
| 1325 | { |
| 1326 | mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS; |
| 1327 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 1328 | switch(pack->msg_id) |
| 1329 | { |
| 1330 | case RIL_MSG_ID_NET_AVAILABLE: |
| 1331 | { |
| 1332 | if(pack->data_len == 0 || pack->data == NULL) |
| 1333 | { |
| 1334 | mbtk_net_info_array_t net_array; |
| 1335 | memset(&net_array, 0, sizeof(mbtk_net_info_array_t)); |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1336 | if(req_available_net_get(cli_info->port, &net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1337 | { |
| 1338 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1339 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1340 | } else { |
| 1341 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1342 | } |
| 1343 | LOGD("Get Available Net fail."); |
| 1344 | } |
| 1345 | else |
| 1346 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1347 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1348 | } |
| 1349 | } |
| 1350 | else // Set |
| 1351 | { |
| 1352 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1353 | LOGW("Unsupport set available net."); |
| 1354 | } |
| 1355 | break; |
| 1356 | } |
| 1357 | case RIL_MSG_ID_NET_SEL_MODE: |
| 1358 | { |
| 1359 | if(pack->data_len == 0 || pack->data == NULL) |
| 1360 | { |
| 1361 | mbtk_net_info_t info; |
| 1362 | memset(&info, 0, sizeof(mbtk_net_info_t)); |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1363 | if(req_net_sel_mode_get(cli_info->port, &info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1364 | { |
| 1365 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1366 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1367 | } else { |
| 1368 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1369 | } |
| 1370 | LOGD("Get Net sel mode fail."); |
| 1371 | } |
| 1372 | else |
| 1373 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1374 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1375 | } |
| 1376 | } |
| 1377 | else // Set |
| 1378 | { |
| 1379 | mbtk_net_info_t *info = (mbtk_net_info_t*)pack->data; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1380 | if(req_net_sel_mode_set(cli_info->port, info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1381 | { |
| 1382 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1383 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1384 | } else { |
| 1385 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1386 | } |
| 1387 | LOGD("Set Net sel mode fail."); |
| 1388 | } |
| 1389 | else |
| 1390 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1391 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1392 | } |
| 1393 | } |
| 1394 | break; |
| 1395 | } |
| 1396 | case RIL_MSG_ID_NET_BAND: |
| 1397 | { |
| 1398 | if(pack->data_len == 0 || pack->data == NULL) |
| 1399 | { |
| 1400 | err = MBTK_RIL_ERR_REQ_PARAMETER; |
| 1401 | LOG("No data found."); |
| 1402 | } |
| 1403 | else // Set |
| 1404 | { |
| 1405 | if(pack->data_len == sizeof(uint8)) { |
| 1406 | if(*(pack->data)) { // Get current bands. |
| 1407 | mbtk_band_info_t band; |
| 1408 | memset(&band, 0x0, sizeof(mbtk_band_info_t)); |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1409 | if(req_band_get(cli_info->port, &band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1410 | { |
| 1411 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1412 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1413 | } else { |
| 1414 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1415 | } |
| 1416 | LOG("Get net band fail."); |
| 1417 | } |
| 1418 | else |
| 1419 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1420 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1421 | } |
| 1422 | } else { // Get support bands. |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1423 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1424 | } |
| 1425 | } else { // Set current bands. |
| 1426 | mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data; |
| 1427 | if(pack->data_len != sizeof(mbtk_band_info_t)) |
| 1428 | { |
| 1429 | err = MBTK_RIL_ERR_REQ_PARAMETER; |
| 1430 | LOG("Set net band error."); |
| 1431 | break; |
| 1432 | } |
| 1433 | |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1434 | if(req_band_set(cli_info->port, band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1435 | { |
| 1436 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1437 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1438 | } else { |
| 1439 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1440 | } |
| 1441 | LOG("Set net band fail."); |
| 1442 | } |
| 1443 | else |
| 1444 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1445 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | } |
| 1449 | break; |
| 1450 | } |
| 1451 | case RIL_MSG_ID_NET_SIGNAL: |
| 1452 | { |
| 1453 | if(pack->data_len == 0 || pack->data == NULL) |
| 1454 | { |
| 1455 | mbtk_signal_info_t signal; |
| 1456 | memset(&signal, 0, sizeof(mbtk_signal_info_t)); |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1457 | if(req_net_signal_get(cli_info->port, &signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1458 | { |
| 1459 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1460 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1461 | } else { |
| 1462 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1463 | } |
| 1464 | LOGD("Get net signal fail."); |
| 1465 | } |
| 1466 | else |
| 1467 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1468 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t)); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1469 | } |
| 1470 | } |
| 1471 | else // Set |
| 1472 | { |
| 1473 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1474 | LOGW("Unsupport set net signal."); |
| 1475 | } |
| 1476 | break; |
| 1477 | } |
| 1478 | case RIL_MSG_ID_NET_REG: |
| 1479 | { |
| 1480 | if(pack->data_len == 0 || pack->data == NULL) |
| 1481 | { |
| 1482 | mbtk_net_reg_info_t net_reg; |
| 1483 | memset(&net_reg, 0, sizeof(mbtk_net_reg_info_t)); |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1484 | if(req_net_reg_get(cli_info->port, &net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1485 | { |
| 1486 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1487 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1488 | } else { |
| 1489 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1490 | } |
| 1491 | LOGD("Get Net reg info fail."); |
| 1492 | } |
| 1493 | else |
| 1494 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1495 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | else // Set |
| 1499 | { |
| 1500 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1501 | LOGW("Unsupport set net reg info."); |
| 1502 | } |
| 1503 | break; |
| 1504 | } |
| 1505 | case RIL_MSG_ID_NET_CELL: |
| 1506 | { |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1507 | if(pack->data_len == 0 || pack->data == NULL) // Get net cell. |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1508 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1509 | if(req_cell_info_get(cli_info->port, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1510 | { |
| 1511 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1512 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1513 | } else { |
| 1514 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1515 | } |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1516 | LOG("Get net cell fail."); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1517 | } |
| 1518 | else |
| 1519 | { |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1520 | LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_list.num); |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1521 | 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.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1522 | } |
| 1523 | } |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1524 | else // Lock cell |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1525 | { |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1526 | char *mem = (char*)(pack->data); |
| 1527 | int len = pack->data_len; |
| 1528 | char reg[100] = {0}; |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1529 | if(req_cell_info_set(cli_info->port, mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1530 | { |
| 1531 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1532 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1533 | } else { |
| 1534 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1535 | } |
| 1536 | } |
| 1537 | else |
| 1538 | { |
b.liu | b171c9a | 2024-11-12 19:23:29 +0800 | [diff] [blame] | 1539 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg)); |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1540 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1541 | } |
| 1542 | break; |
| 1543 | } |
b.liu | 557c81d | 2024-11-19 16:52:45 +0800 | [diff] [blame^] | 1544 | case RIL_MSG_ID_NET_OOS: |
| 1545 | { |
| 1546 | if(pack->data_len == 0 || pack->data == NULL) // Get net oos. |
| 1547 | { |
| 1548 | mbtk_ril_oos_info_t oos_info; |
| 1549 | memset(&oos_info, 0, sizeof(mbtk_ril_oos_info_t)); |
| 1550 | if(req_oos_get(cli_info->port, &oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1551 | { |
| 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 | LOG("Get net oos fail."); |
| 1558 | } |
| 1559 | else |
| 1560 | { |
| 1561 | LOG("req_oos_get() success,cell number: %d", oos_info.state); |
| 1562 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, &oos_info, sizeof(mbtk_ril_oos_info_t)); |
| 1563 | } |
| 1564 | } |
| 1565 | else // Set net oos. |
| 1566 | { |
| 1567 | mbtk_ril_oos_info_t *oos_info = (mbtk_ril_oos_info_t*)(pack->data); |
| 1568 | if(req_oos_set(cli_info->port, oos_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1569 | { |
| 1570 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1571 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1572 | } else { |
| 1573 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1574 | } |
| 1575 | } |
| 1576 | else |
| 1577 | { |
| 1578 | ril_rsp_pack_send(cli_info->port, cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 1579 | } |
| 1580 | } |
| 1581 | break; |
| 1582 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1583 | default: |
| 1584 | { |
| 1585 | err = MBTK_RIL_ERR_REQ_UNKNOWN; |
| 1586 | LOG("Unknown request : %s", id2str(pack->msg_id)); |
| 1587 | break; |
| 1588 | } |
| 1589 | } |
| 1590 | |
| 1591 | return err; |
| 1592 | } |
| 1593 | |