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