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