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; |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 24 | ril_cgact_wait_t cgact_wait; |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 25 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 26 | extern ril_band_info_t band_info; |
| 27 | void ril_rsp_pack_send(int fd, int ril_id, int msg_index, const void* data, int data_len); |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 28 | static int req_apn_get(bool get_def_cid, mbtk_apn_info_array_t *apns, int *cme_err); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 29 | static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err); |
| 30 | static void apn_prop_get(ril_apn_info_array_t *apns); |
| 31 | |
| 32 | void apn_auto_conf_from_prop() |
| 33 | { |
| 34 | ril_apn_info_array_t apns; |
| 35 | int i = 0; |
| 36 | memset(&apns, 0, sizeof(ril_apn_info_array_t)); |
| 37 | apn_prop_get(&apns); |
| 38 | while(i < apns.num) { |
| 39 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 40 | if(req_apn_set(&(apns.apns[i]), &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 41 | { |
| 42 | LOGD("Set APN fail."); |
| 43 | } |
| 44 | else |
| 45 | { |
| 46 | LOGD("Set APN - %d success.", apns.apns[i].cid); |
| 47 | } |
| 48 | i++; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | static bool apn_conf_support(mbtk_ril_cid_enum cid) |
| 53 | { |
| 54 | if(cid == MBTK_RIL_CID_DEF) { |
| 55 | /* |
| 56 | uci show wan_default.default.enable |
| 57 | wan_default.default.enable='1' |
| 58 | |
| 59 | uci get wan_default.default.enable |
| 60 | 1 |
| 61 | */ |
| 62 | char buff[128] = {0}; |
| 63 | if(mbtk_cmd_line("uci get wan_default.default.enable", buff, sizeof(buff)) && strlen(buff) > 0) { |
| 64 | return buff[0] == '1' ? FALSE : TRUE; |
| 65 | } |
| 66 | } |
| 67 | return TRUE; |
| 68 | } |
| 69 | |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 70 | static int apn_check_and_cid_reset(mbtk_apn_info_t *apn) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 71 | { |
| 72 | // Delete apn |
| 73 | if(str_empty(apn->apn)) { |
| 74 | if(apn->cid == MBTK_RIL_CID_NUL) |
| 75 | return -1; |
| 76 | |
| 77 | if(!apn_conf_support(MBTK_RIL_CID_DEF) && apn->cid == MBTK_RIL_CID_DEF) |
| 78 | return -1; |
| 79 | |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 80 | // The cid no use,so can not delete. |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 81 | mbtk_apn_info_array_t apns; |
| 82 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 83 | memset(&apns, 0, sizeof(mbtk_apn_info_array_t)); |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 84 | if(req_apn_get(FALSE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 85 | { |
| 86 | LOGW("Get APN fail."); |
| 87 | return 0; |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | int index = 0; |
| 92 | while(index < apns.num) { |
| 93 | if(apns.apns[index].cid == apn->cid) |
| 94 | return 0; |
| 95 | index++; |
| 96 | } |
| 97 | return -1; |
| 98 | } |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 99 | } else { // Add or change APN. |
| 100 | int start_cid; |
| 101 | bool asr_auto_call_open = !apn_conf_support(MBTK_RIL_CID_DEF); |
| 102 | mbtk_apn_info_array_t apns; |
| 103 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 104 | |
| 105 | if(asr_auto_call_open) { |
| 106 | start_cid = MBTK_RIL_CID_2; |
| 107 | } else { |
| 108 | start_cid = MBTK_APN_CID_MIN; |
| 109 | } |
| 110 | memset(&apns, 0, sizeof(mbtk_apn_info_array_t)); |
| 111 | if(req_apn_get(TRUE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 112 | { |
| 113 | LOGW("Get APN fail."); |
| 114 | if(apn->cid == MBTK_RIL_CID_NUL) { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 115 | apn->cid = start_cid; |
| 116 | } |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 117 | } |
| 118 | else |
| 119 | { |
| 120 | int index = 0; |
| 121 | bool is_change = FALSE; // Is add APN default. |
| 122 | |
| 123 | if(apn->cid == MBTK_RIL_CID_NUL) { // Is add (auto set cid). |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 124 | for(; start_cid <= MBTK_APN_CID_MAX; start_cid++) { |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 125 | index = 0; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 126 | while(index < apns.num) { |
| 127 | if(apns.apns[index].cid == start_cid) |
| 128 | break; |
| 129 | index++; |
| 130 | } |
| 131 | |
| 132 | if(index == apns.num) { // Found not used cid : start_cid. |
| 133 | LOGD("Change CID : %d -> %d", apn->cid, start_cid); |
| 134 | apn->cid = start_cid; |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 135 | // return 0; |
| 136 | break; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
| 140 | if(start_cid > MBTK_APN_CID_MAX) { |
| 141 | LOGE("APN full."); |
| 142 | return -1; |
| 143 | } |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 144 | is_change = FALSE; |
| 145 | } else { |
| 146 | index = 0; |
| 147 | while(index < apns.num) { |
| 148 | if(apns.apns[index].cid == apn->cid) { |
| 149 | is_change = TRUE; |
| 150 | break; |
| 151 | } |
| 152 | index++; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | // Is add,the APN can't same. |
| 157 | if(!is_change) { |
| 158 | index = 0; |
| 159 | while(index < apns.num) { |
| 160 | if(strcmp(apns.apns[index].apn,apn->apn) == 0) { |
| 161 | LOGW("APN : %s exist.", apn->apn); |
| 162 | return -1; |
| 163 | } |
| 164 | index++; |
| 165 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | } |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static void apn_prop_get(ril_apn_info_array_t *apns) |
| 173 | { |
| 174 | char prop_name[20] = {0}; |
| 175 | char prop_data[300] = {0}; |
| 176 | int cid; |
| 177 | memset(apns, 0, sizeof(ril_apn_info_array_t)); |
| 178 | bool asr_auto_call_open = !apn_conf_support(MBTK_RIL_CID_DEF); |
| 179 | |
| 180 | // If auto data call is open,the default route is CID 1. |
| 181 | if(asr_auto_call_open) { |
| 182 | apns->cid_for_def_route = MBTK_RIL_CID_DEF; |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 183 | apns->cid_for_dns = MBTK_RIL_CID_DEF; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 184 | cid = MBTK_RIL_CID_2; |
| 185 | } else { |
| 186 | if(property_get(MBTK_DEF_ROUTE_CID, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 187 | apns->cid_for_def_route = (mbtk_ril_cid_enum)atoi(prop_data); |
| 188 | } |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 189 | memset(prop_data, 0, sizeof(prop_data)); |
| 190 | if(property_get(MBTK_DEF_DNS_CID, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 191 | apns->cid_for_dns = (mbtk_ril_cid_enum)atoi(prop_data); |
| 192 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 193 | cid = MBTK_APN_CID_MIN; |
| 194 | } |
| 195 | for(; cid <= MBTK_APN_CID_MAX; cid++) { |
| 196 | memset(prop_name, 0, 20); |
| 197 | memset(prop_data, 0, 300); |
| 198 | |
| 199 | sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid); |
| 200 | // ip_type,auth,auto_data_call,apn,user,pass |
| 201 | if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 202 | apns->apns[apns->num].cid = (mbtk_ril_cid_enum)cid; |
| 203 | char *ptr_1 = prop_data; |
| 204 | apns->apns[apns->num].ip_type = (mbtk_ip_type_enum)atoi(ptr_1); |
| 205 | ptr_1 = strstr(ptr_1, ","); |
| 206 | if(!ptr_1) { |
| 207 | continue; |
| 208 | } |
| 209 | ptr_1++; // Jump ',' to auth |
| 210 | |
| 211 | apns->apns[apns->num].auth = (mbtk_apn_auth_type_enum)atoi(ptr_1); |
| 212 | ptr_1 = strstr(ptr_1, ","); |
| 213 | if(!ptr_1) { |
| 214 | continue; |
| 215 | } |
| 216 | ptr_1++; // Jump ',' to auto_data_call |
| 217 | |
| 218 | apns->apns[apns->num].auto_boot_call = (uint8)atoi(ptr_1); |
| 219 | ptr_1 = strstr(ptr_1, ","); |
| 220 | if(!ptr_1) { |
| 221 | continue; |
| 222 | } |
| 223 | ptr_1++; // Jump ',' to apn |
| 224 | |
| 225 | char *ptr_2 = strstr(ptr_1, ","); |
| 226 | if(!ptr_2) { |
| 227 | continue; |
| 228 | } |
| 229 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 230 | memcpy(apns->apns[apns->num].apn, ptr_1, ptr_2 - ptr_1); // apn |
| 231 | } |
| 232 | |
| 233 | ptr_2++; // Jump ',' to user |
| 234 | ptr_1 = strstr(ptr_2, ","); |
| 235 | if(!ptr_1) { |
| 236 | continue; |
| 237 | } |
| 238 | if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL" |
| 239 | memcpy(apns->apns[apns->num].user, ptr_2, ptr_1 - ptr_2); // user |
| 240 | } |
| 241 | |
| 242 | ptr_1++; // Jump ',' to pass |
| 243 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 244 | memcpy(apns->apns[apns->num].pass, ptr_1, strlen(ptr_1)); // pass |
| 245 | } |
| 246 | |
| 247 | apns->num++; |
| 248 | } |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | static int apn_prop_get_by_cid(mbtk_ril_cid_enum cid, mbtk_apn_info_t *apn) |
| 253 | { |
| 254 | char prop_name[20] = {0}; |
| 255 | char prop_data[300] = {0}; |
| 256 | memset(apn, 0, sizeof(mbtk_apn_info_t)); |
| 257 | |
| 258 | sprintf(prop_name, "%s_%d",MBTK_APN_PROP,cid); |
| 259 | // ip_type,auth,auto_data_call,apn,user,pass |
| 260 | if(property_get(prop_name, prop_data, "") > 0 && !str_empty(prop_data)) { |
| 261 | apn->cid = cid; |
| 262 | apn->auto_save = (uint8)1; |
| 263 | char *ptr_1 = prop_data; |
| 264 | apn->ip_type = (mbtk_ip_type_enum)atoi(ptr_1); |
| 265 | ptr_1 = strstr(ptr_1, ","); |
| 266 | if(!ptr_1) { |
| 267 | return -1; |
| 268 | } |
| 269 | ptr_1++; // Jump ',' to auth |
| 270 | |
| 271 | apn->auth = (mbtk_apn_auth_type_enum)atoi(ptr_1); |
| 272 | ptr_1 = strstr(ptr_1, ","); |
| 273 | if(!ptr_1) { |
| 274 | return -1; |
| 275 | } |
| 276 | ptr_1++; // Jump ',' to auto_data_call |
| 277 | |
| 278 | apn->auto_boot_call = (uint8)atoi(ptr_1); |
| 279 | ptr_1 = strstr(ptr_1, ","); |
| 280 | if(!ptr_1) { |
| 281 | return -1; |
| 282 | } |
| 283 | ptr_1++; // Jump ',' to apn |
| 284 | |
| 285 | char *ptr_2 = strstr(ptr_1, ","); |
| 286 | if(!ptr_2) { |
| 287 | return -1; |
| 288 | } |
| 289 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 290 | memcpy(apn->apn, ptr_1, ptr_2 - ptr_1); // apn |
| 291 | } |
| 292 | |
| 293 | ptr_2++; // Jump ',' to user |
| 294 | ptr_1 = strstr(ptr_2, ","); |
| 295 | if(!ptr_1) { |
| 296 | return -1; |
| 297 | } |
| 298 | if(memcmp(ptr_2, "NULL", 4)) { // Not "NULL" |
| 299 | memcpy(apn->user, ptr_2, ptr_1 - ptr_2); // user |
| 300 | } |
| 301 | |
| 302 | ptr_1++; // Jump ',' to pass |
| 303 | if(memcmp(ptr_1, "NULL", 4)) { // Not "NULL" |
| 304 | memcpy(apn->pass, ptr_1, strlen(ptr_1)); // pass |
| 305 | } |
| 306 | return 0; |
| 307 | } |
| 308 | return -1; |
| 309 | } |
| 310 | |
| 311 | static int apn_prop_set(mbtk_apn_info_t *apn) |
| 312 | { |
| 313 | char prop_name[20] = {0}; |
| 314 | char prop_data[300] = {0}; |
| 315 | int ret = -1; |
| 316 | if(apn->auto_save) { |
| 317 | sprintf(prop_name, "%s_%d", MBTK_APN_PROP, apn->cid); |
| 318 | // Delete apn |
| 319 | if(!str_empty(apn->apn)) { |
| 320 | snprintf(prop_data, 300, "%d,%d,%d,%s,%s,%s", apn->ip_type, apn->auth, apn->auto_boot_call, |
| 321 | apn->apn, |
| 322 | str_empty(apn->user) ? "NULL" : apn->user, |
| 323 | str_empty(apn->pass) ? "NULL" : apn->pass); |
| 324 | } |
| 325 | |
| 326 | ret = property_set(prop_name, prop_data); |
| 327 | } |
| 328 | |
| 329 | if(apn->def_route) { |
| 330 | memset(prop_data, 0, sizeof(prop_data)); |
| 331 | prop_data[0] = '0' + apn->cid; |
| 332 | ret = property_set(MBTK_DEF_ROUTE_CID, prop_data); |
| 333 | } |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 334 | if(apn->as_dns) { |
| 335 | memset(prop_data, 0, sizeof(prop_data)); |
| 336 | prop_data[0] = '0' + apn->cid; |
| 337 | ret = property_set(MBTK_DEF_DNS_CID, prop_data); |
| 338 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 339 | return ret; |
| 340 | } |
| 341 | |
| 342 | static int apn_prop_reset(mbtk_data_call_info_t *data_info) |
| 343 | { |
| 344 | mbtk_apn_info_t apn; |
| 345 | if(apn_prop_get_by_cid(data_info->cid, &apn)) { |
| 346 | return -1; |
| 347 | } else { |
| 348 | apn.auto_boot_call = data_info->auto_boot_call; |
| 349 | apn.def_route = data_info->def_route; |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 350 | apn.as_dns = data_info->as_dns; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 351 | return apn_prop_set(&apn); |
| 352 | } |
| 353 | } |
| 354 | |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 355 | static int wait_cgact_complete(int timeout) |
| 356 | { |
| 357 | int count = timeout * 10; // timeout * 1000 / 100 |
| 358 | int i = 0; |
| 359 | |
| 360 | while(cgact_wait.waitting && i < count) { |
| 361 | i++; |
| 362 | usleep(100000); // 100ms |
| 363 | } |
| 364 | |
| 365 | memset(&cgact_wait, 0, sizeof(ril_cgact_wait_t)); |
| 366 | if(i == count) { // Timeout |
| 367 | return -1; |
| 368 | } else { |
| 369 | return 0; |
| 370 | } |
| 371 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 372 | |
| 373 | /* |
| 374 | AT+COPS=? |
| 375 | |
| 376 | +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) |
| 377 | |
| 378 | OK |
| 379 | */ |
| 380 | static int req_available_net_get(mbtk_net_info_array_t* nets, int *cme_err) |
| 381 | { |
| 382 | ATResponse *response = NULL; |
| 383 | int err = at_send_command_singleline("AT+COPS=?", "+COPS:", &response); |
| 384 | |
| 385 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 386 | if(cme_err) { |
| 387 | *cme_err = at_get_cme_error(response); |
| 388 | } |
| 389 | goto exit; |
| 390 | } |
| 391 | char *line_ptr = response->p_intermediates->line; |
| 392 | if(line_ptr == NULL) { |
| 393 | LOG("line is NULL"); |
| 394 | err = -1; |
| 395 | goto exit; |
| 396 | } |
| 397 | //LOG("Line:%s",line_ptr); |
| 398 | line_ptr = strstr(line_ptr, "("); |
| 399 | while(line_ptr) { |
| 400 | line_ptr++; |
| 401 | // Only for available/current net. |
| 402 | if(*line_ptr == '1' || *line_ptr == '2' || *line_ptr == '3') { |
| 403 | nets->net_info[nets->num].net_state = (uint8)atoi(line_ptr); // net_state |
| 404 | |
| 405 | line_ptr = strstr(line_ptr, ","); |
| 406 | if(line_ptr == NULL) { |
| 407 | err = -1; |
| 408 | goto exit; |
| 409 | } |
| 410 | line_ptr++; |
| 411 | |
| 412 | line_ptr = strstr(line_ptr, ","); |
| 413 | if(line_ptr == NULL) { |
| 414 | err = -1; |
| 415 | goto exit; |
| 416 | } |
| 417 | line_ptr++; |
| 418 | |
| 419 | line_ptr = strstr(line_ptr, ","); |
| 420 | if(line_ptr == NULL) { |
| 421 | err = -1; |
| 422 | goto exit; |
| 423 | } |
| 424 | |
| 425 | while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ' || *line_ptr == '"')) |
| 426 | line_ptr++; |
| 427 | |
| 428 | // set sel_mode to 0 |
| 429 | nets->net_info[nets->num].net_sel_mode = (uint8)0; |
| 430 | // Point to "46000" |
| 431 | //LOG("PLMN:%s",line_ptr); |
| 432 | //sleep(1); |
| 433 | //uint32_2_byte((uint32)atoi(line_ptr), buff_ptr + 3, false); // plmn |
| 434 | nets->net_info[nets->num].plmn = (uint32)atoi(line_ptr); |
| 435 | |
| 436 | line_ptr = strstr(line_ptr, ","); |
| 437 | if(line_ptr == NULL) { |
| 438 | err = -1; |
| 439 | goto exit; |
| 440 | } |
| 441 | |
| 442 | while(*line_ptr != '\0' && (*line_ptr == ',' || *line_ptr == ' ')) |
| 443 | line_ptr++; |
| 444 | |
| 445 | // Point to "7" |
| 446 | if(*line_ptr == '\0') { |
| 447 | err = -1; |
| 448 | goto exit; |
| 449 | } |
| 450 | //LOG("Type:%s",line_ptr); |
| 451 | //sleep(1); |
| 452 | nets->net_info[nets->num].net_type = (uint8)atoi(line_ptr); // net_type |
| 453 | |
| 454 | nets->num++; |
| 455 | } |
| 456 | |
| 457 | line_ptr = strstr(line_ptr, "("); |
| 458 | } |
| 459 | exit: |
| 460 | at_response_free(response); |
| 461 | return err; |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | AT+COPS? |
| 466 | +COPS: 1 |
| 467 | |
| 468 | OK |
| 469 | |
| 470 | or |
| 471 | |
| 472 | AT+COPS? |
| 473 | +COPS: 0,2,"46001",7 |
| 474 | |
| 475 | OK |
| 476 | |
| 477 | */ |
| 478 | static int req_net_sel_mode_get(mbtk_net_info_t *net, int *cme_err) |
| 479 | { |
| 480 | //LOG("req_net_sel_mode_get() 0"); |
| 481 | //sleep(1); |
| 482 | ATResponse *response = NULL; |
| 483 | int tmp_int; |
| 484 | char *tmp_ptr = NULL; |
| 485 | int err = at_send_command_singleline("AT+COPS?", "+COPS:", &response); |
| 486 | //LOG("req_net_sel_mode_get() 00"); |
| 487 | //sleep(1); |
| 488 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 489 | if(cme_err != NULL) |
| 490 | *cme_err = at_get_cme_error(response); |
| 491 | err = -1; |
| 492 | goto exit; |
| 493 | } |
| 494 | //LOG("req_net_sel_mode_get() 1"); |
| 495 | //sleep(1); |
| 496 | char *line = response->p_intermediates->line; |
| 497 | if(line == NULL) { |
| 498 | LOG("line is NULL"); |
| 499 | goto exit; |
| 500 | } |
| 501 | //LOG("req_net_sel_mode_get() 2"); |
| 502 | //sleep(1); |
| 503 | err = at_tok_start(&line); |
| 504 | if (err < 0) |
| 505 | { |
| 506 | goto exit; |
| 507 | } |
| 508 | //LOG("req_net_sel_mode_get() 3"); |
| 509 | //sleep(1); |
| 510 | err = at_tok_nextint(&line, &tmp_int); |
| 511 | if (err < 0) |
| 512 | { |
| 513 | goto exit; |
| 514 | } |
| 515 | net->net_sel_mode = (uint8)tmp_int; |
| 516 | //LOG("req_net_sel_mode_get() 4"); |
| 517 | //sleep(1); |
| 518 | // +COPS: 1 |
| 519 | if(!at_tok_hasmore(&line)) { |
| 520 | goto exit; |
| 521 | } |
| 522 | //LOG("req_net_sel_mode_get() 5"); |
| 523 | //sleep(1); |
| 524 | err = at_tok_nextint(&line, &tmp_int); |
| 525 | if (err < 0) |
| 526 | { |
| 527 | goto exit; |
| 528 | } |
| 529 | //LOG("req_net_sel_mode_get() 6"); |
| 530 | //sleep(1); |
| 531 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 532 | if (err < 0) |
| 533 | { |
| 534 | goto exit; |
| 535 | } |
| 536 | // memcpy(net->plmn, tmp_ptr, strlen(tmp_ptr)); |
| 537 | net->plmn = (uint32)atoi(tmp_ptr); |
| 538 | //LOG("req_net_sel_mode_get() 7"); |
| 539 | //sleep(1); |
| 540 | err = at_tok_nextint(&line, &tmp_int); |
| 541 | if (err < 0) |
| 542 | { |
| 543 | goto exit; |
| 544 | } |
| 545 | net->net_type = (uint8)tmp_int; |
| 546 | |
| 547 | net->net_state = (uint8)MBTK_NET_AVIL_STATE_CURRENT; |
| 548 | |
| 549 | exit: |
| 550 | //LOG("req_net_sel_mode_get() 8"); |
| 551 | //sleep(1); |
| 552 | at_response_free(response); |
| 553 | return err; |
| 554 | } |
| 555 | |
| 556 | /* |
| 557 | AT+COPS=0 |
| 558 | or |
| 559 | AT+COPS=1,2,"46000",7 |
| 560 | |
| 561 | OK |
| 562 | |
| 563 | */ |
| 564 | static int req_net_sel_mode_set(mbtk_net_info_t* net, int *cme_err) |
| 565 | { |
| 566 | ATResponse *response = NULL; |
| 567 | char cmd[50] = {0}; |
| 568 | char* cmp_ptr = cmd; |
| 569 | if(net == NULL) { |
| 570 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0"); |
| 571 | } else { |
| 572 | if(net->net_sel_mode == 0) { |
| 573 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=0"); |
| 574 | } else if(net->net_type == 0xFF) { |
| 575 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\"",net->plmn); |
| 576 | } else { |
| 577 | cmp_ptr += sprintf(cmp_ptr, "AT+COPS=1,2,\"%d\",%d",net->plmn, net->net_type); |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | int err = at_send_command(cmd, &response); |
| 582 | |
| 583 | if (err < 0 || response->success == 0) { |
| 584 | if(cme_err) { |
| 585 | *cme_err = at_get_cme_error(response); |
| 586 | } |
| 587 | goto exit; |
| 588 | } |
| 589 | |
| 590 | exit: |
| 591 | at_response_free(response); |
| 592 | return err; |
| 593 | } |
| 594 | |
| 595 | /* |
| 596 | AT*BAND=15 |
| 597 | OK |
| 598 | |
| 599 | */ |
| 600 | static int req_band_set(mbtk_band_info_t* band, int *cme_err) |
| 601 | { |
| 602 | ATResponse *response = NULL; |
| 603 | char cmd[100] = {0}; |
| 604 | int err = -1; |
| 605 | |
| 606 | if(band->gsm_band == 0 && band->umts_band == 0 |
| 607 | && band->tdlte_band == 0 && band->fddlte_band == 0) { |
| 608 | sprintf(cmd, "AT*BAND=%d", band->net_pref); |
| 609 | } else { |
| 610 | log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t)); |
| 611 | log_hex("BAND", band, sizeof(mbtk_band_info_t)); |
| 612 | |
| 613 | if(band->gsm_band == 0) { |
| 614 | band->gsm_band = band_info.band_support.gsm_band; |
| 615 | } |
| 616 | if(band->umts_band == 0) { |
| 617 | band->umts_band = band_info.band_support.umts_band; |
| 618 | } |
| 619 | if(band->tdlte_band == 0) { |
| 620 | band->tdlte_band = band_info.band_support.tdlte_band; |
| 621 | } |
| 622 | if(band->fddlte_band == 0) { |
| 623 | band->fddlte_band = band_info.band_support.fddlte_band; |
| 624 | } |
| 625 | |
| 626 | if((band->gsm_band & band_info.band_support.gsm_band) != band->gsm_band) { |
| 627 | LOG("GSM band error."); |
| 628 | goto exit; |
| 629 | } |
| 630 | |
| 631 | if((band->umts_band & band_info.band_support.umts_band) != band->umts_band) { |
| 632 | LOG("UMTS band error."); |
| 633 | goto exit; |
| 634 | } |
| 635 | |
| 636 | if((band->tdlte_band & band_info.band_support.tdlte_band) != band->tdlte_band) { |
| 637 | LOG("TDLTE band error."); |
| 638 | goto exit; |
| 639 | } |
| 640 | |
| 641 | if((band->fddlte_band & band_info.band_support.fddlte_band) != band->fddlte_band) { |
| 642 | LOG("FDDLTE band error."); |
| 643 | goto exit; |
| 644 | } |
| 645 | |
| 646 | if((band->lte_ext_band & band_info.band_support.lte_ext_band) != band->lte_ext_band) { |
| 647 | LOG("EXT_LTE band error."); |
| 648 | goto exit; |
| 649 | } |
| 650 | |
| 651 | if(band->net_pref == 0xFF) { // No change net_pref. |
| 652 | int tmp_int; |
| 653 | err = at_send_command_singleline("AT*BAND?", "*BAND:", &response); |
| 654 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 655 | if(cme_err) { |
| 656 | *cme_err = at_get_cme_error(response); |
| 657 | } |
| 658 | goto exit; |
| 659 | } |
| 660 | |
| 661 | char *line = response->p_intermediates->line; |
| 662 | err = at_tok_start(&line); |
| 663 | if (err < 0) |
| 664 | { |
| 665 | goto exit; |
| 666 | } |
| 667 | |
| 668 | err = at_tok_nextint(&line, &tmp_int); |
| 669 | if (err < 0) |
| 670 | { |
| 671 | goto exit; |
| 672 | } |
| 673 | band->net_pref = (uint8)tmp_int; // Set to current net_pref. |
| 674 | |
| 675 | at_response_free(response); |
| 676 | } |
| 677 | |
| 678 | if(band->lte_ext_band > 0) { |
| 679 | 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); |
| 680 | } else { |
| 681 | sprintf(cmd, "AT*BAND=%d,%d,%d,%d,%d", band->net_pref, band->gsm_band, band->umts_band, band->tdlte_band, band->fddlte_band); |
| 682 | } |
| 683 | } |
| 684 | err = at_send_command(cmd, &response); |
| 685 | |
| 686 | if (err < 0 || response->success == 0){ |
| 687 | if(cme_err) { |
| 688 | *cme_err = at_get_cme_error(response); |
| 689 | } |
| 690 | goto exit; |
| 691 | } |
| 692 | |
| 693 | err = 0; |
| 694 | exit: |
| 695 | at_response_free(response); |
| 696 | return err; |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | // ??????? |
| 701 | AT*BAND=? |
| 702 | *BAND:(0-18),79,147,482,524503 |
| 703 | |
| 704 | OK |
| 705 | |
| 706 | // ??????????? |
| 707 | AT*BAND? |
| 708 | *BAND: 15, 78, 147, 482, 524503, 0, 2, 2, 0, 0 |
| 709 | |
| 710 | OK |
| 711 | |
| 712 | // ????????? |
| 713 | AT*BAND=5,79,147,128,1 |
| 714 | OK |
| 715 | |
| 716 | net_prefferred?? |
| 717 | 0 : GSM only |
| 718 | 1 : UMTS only |
| 719 | 2 : GSM/UMTS(auto) |
| 720 | 3 : GSM/UMTS(GSM preferred) |
| 721 | 4 : GSM/UMTS(UMTS preferred) |
| 722 | 5 : LTE only |
| 723 | 6 : GSM/LTE(auto) |
| 724 | 7 : GSM/LTE(GSM preferred) |
| 725 | 8 : GSM/LTE(LTE preferred) |
| 726 | 9 : UMTS/LTE(auto) |
| 727 | 10 : UMTS/LTE(UMTS preferred) |
| 728 | 11 : UMTS/LTE(LTE preferred) |
| 729 | 12 : GSM/UMTS/LTE(auto) |
| 730 | 13 : GSM/UMTS/LTE(GSM preferred) |
| 731 | 14 : GSM/UMTS/LTE(UMTS preferred) |
| 732 | 15 : GSM/UMTS/LTE(LTE preferred) |
| 733 | GSM band?? |
| 734 | 1 ?C PGSM 900 (standard or primary) |
| 735 | 2 ?C DCS GSM 1800 |
| 736 | 4 ?C PCS GSM 1900 |
| 737 | 8 ?C EGSM 900 (extended) |
| 738 | 16 ?C GSM 450 |
| 739 | 32 ?C GSM 480 |
| 740 | 64 ?C GSM 850 |
| 741 | 512 - BAND_LOCK_BIT // used for GSM band setting |
| 742 | UMTS band?? |
| 743 | 1 ?C UMTS_BAND_1 |
| 744 | 2 ?C UMTS_BAND_2 |
| 745 | 4 ?C UMTS_BAND_3 |
| 746 | 8 ?C UMTS_BAND_4 |
| 747 | 16 ?C UMTS_BAND_5 |
| 748 | 32 ?C UMTS_BAND_6 |
| 749 | 64 ?C UMTS_BAND_7 |
| 750 | 128 ?C UMTS_BAND_8 |
| 751 | 256 ?C UMTS_BAND_9 |
| 752 | LTEbandH(TDD-LTE band) |
| 753 | 32 ?C TDLTE_BAND_38 |
| 754 | 64 ?C TDLTE_BAND_39 |
| 755 | 128 ?C TDLTE_BAND_40 |
| 756 | 256 ?C TDLTE_BAND_41 |
| 757 | LTEbandL(FDD-LTE band) |
| 758 | 1 ?C FDDLTE_BAND_1 |
| 759 | 4 ?C FDDLTE _BAND_3 |
| 760 | 8 ?C FDDLTE _BAND_4 |
| 761 | 64 ?C FDDLTE _BAND_7 |
| 762 | 65536 ?C FDDLTE _BAND_17 |
| 763 | 524288 ?C FDDLTE _BAND_20 |
| 764 | */ |
| 765 | static int req_band_get(mbtk_band_info_t *band, int *cme_err) |
| 766 | { |
| 767 | ATResponse *response = NULL; |
| 768 | int tmp_int; |
| 769 | |
| 770 | log_hex("BAND_SUPPORT", &band_info.band_support, sizeof(mbtk_band_info_t)); |
| 771 | int err = at_send_command_singleline("AT*BAND?", "*BAND:", &response); |
| 772 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 773 | if(cme_err) { |
| 774 | *cme_err = at_get_cme_error(response); |
| 775 | } |
| 776 | goto exit; |
| 777 | } |
| 778 | |
| 779 | char *line = response->p_intermediates->line; |
| 780 | err = at_tok_start(&line); |
| 781 | if (err < 0) |
| 782 | { |
| 783 | goto exit; |
| 784 | } |
| 785 | |
| 786 | err = at_tok_nextint(&line, &tmp_int); |
| 787 | if (err < 0) |
| 788 | { |
| 789 | goto exit; |
| 790 | } |
| 791 | band->net_pref = (uint8)tmp_int; |
| 792 | |
| 793 | err = at_tok_nextint(&line, &tmp_int); |
| 794 | if (err < 0) |
| 795 | { |
| 796 | goto exit; |
| 797 | } |
| 798 | band->gsm_band = (uint16)tmp_int; |
| 799 | |
| 800 | err = at_tok_nextint(&line, &tmp_int); |
| 801 | if (err < 0) |
| 802 | { |
| 803 | goto exit; |
| 804 | } |
| 805 | band->umts_band = (uint16)tmp_int; |
| 806 | |
| 807 | err = at_tok_nextint(&line, &tmp_int); |
| 808 | if (err < 0) |
| 809 | { |
| 810 | goto exit; |
| 811 | } |
| 812 | band->tdlte_band = (uint32)tmp_int; |
| 813 | |
| 814 | err = at_tok_nextint(&line, &tmp_int); |
| 815 | if (err < 0) |
| 816 | { |
| 817 | goto exit; |
| 818 | } |
| 819 | band->fddlte_band = (uint32)tmp_int; |
| 820 | |
| 821 | // roamingConfig |
| 822 | err = at_tok_nextint(&line, &tmp_int); |
| 823 | if (err < 0) |
| 824 | { |
| 825 | goto exit; |
| 826 | } |
| 827 | |
| 828 | // srvDomain |
| 829 | err = at_tok_nextint(&line, &tmp_int); |
| 830 | if (err < 0) |
| 831 | { |
| 832 | goto exit; |
| 833 | } |
| 834 | |
| 835 | // bandPriorityFlag |
| 836 | err = at_tok_nextint(&line, &tmp_int); |
| 837 | if (err < 0) |
| 838 | { |
| 839 | goto exit; |
| 840 | } |
| 841 | |
| 842 | // |
| 843 | err = at_tok_nextint(&line, &tmp_int); |
| 844 | if (err < 0) |
| 845 | { |
| 846 | goto exit; |
| 847 | } |
| 848 | |
| 849 | // ltebandExt |
| 850 | err = at_tok_nextint(&line, &tmp_int); |
| 851 | if (err < 0) |
| 852 | { |
| 853 | goto exit; |
| 854 | } |
| 855 | band->lte_ext_band = (uint32)tmp_int; |
| 856 | |
| 857 | log_hex("BAND", band, sizeof(mbtk_band_info_t)); |
| 858 | |
| 859 | exit: |
| 860 | at_response_free(response); |
| 861 | return err; |
| 862 | } |
| 863 | |
| 864 | /* |
| 865 | AT+CSQ |
| 866 | +CSQ: 31,99 |
| 867 | |
| 868 | OK |
| 869 | |
| 870 | AT+CESQ |
| 871 | +CESQ: 60,99,255,255,20,61 |
| 872 | |
| 873 | OK |
| 874 | |
| 875 | AT+COPS? |
| 876 | +COPS: 0,2,"46001",7 |
| 877 | |
| 878 | OK |
| 879 | |
| 880 | */ |
| 881 | static int req_net_signal_get(mbtk_signal_info_t *signal, int *cme_err) |
| 882 | { |
| 883 | ATResponse *response = NULL; |
| 884 | int tmp_int; |
| 885 | char *tmp_ptr = NULL; |
| 886 | // AT+EEMOPT=1 in the first. |
| 887 | int err = at_send_command_singleline("AT+CSQ", "+CSQ:", &response); |
| 888 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 889 | if(cme_err != NULL) |
| 890 | *cme_err = at_get_cme_error(response); |
| 891 | err = -1; |
| 892 | goto exit; |
| 893 | } |
| 894 | |
| 895 | char *line = response->p_intermediates->line; |
| 896 | err = at_tok_start(&line); |
| 897 | if (err < 0) |
| 898 | { |
| 899 | goto exit; |
| 900 | } |
| 901 | err = at_tok_nextint(&line, &tmp_int); |
| 902 | if (err < 0) |
| 903 | { |
| 904 | goto exit; |
| 905 | } |
| 906 | signal->rssi = (uint8)tmp_int; |
| 907 | at_response_free(response); |
| 908 | |
| 909 | err = at_send_command_singleline("AT+CESQ", "+CESQ:", &response); |
| 910 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 911 | if(cme_err != NULL) |
| 912 | *cme_err = at_get_cme_error(response); |
| 913 | err = -1; |
| 914 | goto exit; |
| 915 | } |
| 916 | |
| 917 | line = response->p_intermediates->line; |
| 918 | err = at_tok_start(&line); |
| 919 | if (err < 0) |
| 920 | { |
| 921 | goto exit; |
| 922 | } |
| 923 | err = at_tok_nextint(&line, &tmp_int); |
| 924 | if (err < 0) |
| 925 | { |
| 926 | goto exit; |
| 927 | } |
| 928 | signal->rxlev = (uint8)tmp_int; |
| 929 | |
| 930 | err = at_tok_nextint(&line, &tmp_int); |
| 931 | if (err < 0) |
| 932 | { |
| 933 | goto exit; |
| 934 | } |
| 935 | signal->ber = (uint8)tmp_int; |
| 936 | |
| 937 | err = at_tok_nextint(&line, &tmp_int); |
| 938 | if (err < 0) |
| 939 | { |
| 940 | goto exit; |
| 941 | } |
| 942 | signal->rscp = (uint8)tmp_int; |
| 943 | |
| 944 | err = at_tok_nextint(&line, &tmp_int); |
| 945 | if (err < 0) |
| 946 | { |
| 947 | goto exit; |
| 948 | } |
| 949 | signal->ecno = (uint8)tmp_int; |
| 950 | |
| 951 | err = at_tok_nextint(&line, &tmp_int); |
| 952 | if (err < 0) |
| 953 | { |
| 954 | goto exit; |
| 955 | } |
| 956 | signal->rsrq = (uint8)tmp_int; |
| 957 | |
| 958 | err = at_tok_nextint(&line, &tmp_int); |
| 959 | if (err < 0) |
| 960 | { |
| 961 | goto exit; |
| 962 | } |
| 963 | signal->rsrp = (uint8)tmp_int; |
| 964 | |
| 965 | at_response_free(response); |
| 966 | err = at_send_command_singleline("AT+COPS?", "+COPS:", &response); |
| 967 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 968 | if(cme_err != NULL) |
| 969 | *cme_err = at_get_cme_error(response); |
| 970 | err = -1; |
| 971 | goto exit; |
| 972 | } |
| 973 | line = response->p_intermediates->line; |
| 974 | err = at_tok_start(&line); |
| 975 | if (err < 0) |
| 976 | { |
| 977 | goto exit; |
| 978 | } |
| 979 | err = at_tok_nextint(&line, &tmp_int); |
| 980 | if (err < 0) |
| 981 | { |
| 982 | goto exit; |
| 983 | } |
| 984 | if(!at_tok_hasmore(&line)) { |
| 985 | goto exit; |
| 986 | } |
| 987 | err = at_tok_nextint(&line, &tmp_int); |
| 988 | if (err < 0) |
| 989 | { |
| 990 | goto exit; |
| 991 | } |
| 992 | err = at_tok_nextstr(&line, &tmp_ptr); |
| 993 | if (err < 0) |
| 994 | { |
| 995 | goto exit; |
| 996 | } |
| 997 | err = at_tok_nextint(&line, &tmp_int); |
| 998 | if (err < 0) |
| 999 | { |
| 1000 | goto exit; |
| 1001 | } |
| 1002 | signal->type = (uint8)tmp_int; |
| 1003 | |
| 1004 | exit: |
| 1005 | at_response_free(response); |
| 1006 | return err; |
| 1007 | } |
| 1008 | |
| 1009 | /* |
| 1010 | AT+CREG=3 |
| 1011 | OK |
| 1012 | |
| 1013 | AT+CREG? |
| 1014 | +CREG: 3,1,"8330","06447340",7 |
| 1015 | |
| 1016 | OK |
| 1017 | |
| 1018 | AT+CREG? |
| 1019 | +CREG: 3,0 |
| 1020 | |
| 1021 | OK |
| 1022 | |
| 1023 | AT+CEREG? |
| 1024 | +CEREG: 3,1,"8330","06447340",7 |
| 1025 | |
| 1026 | OK |
| 1027 | |
| 1028 | |
| 1029 | AT+CIREG? |
| 1030 | +CIREG: 2,1,15 |
| 1031 | |
| 1032 | OK |
| 1033 | |
| 1034 | AT+CIREG? |
| 1035 | +CIREG: 0 |
| 1036 | |
| 1037 | OK |
| 1038 | |
| 1039 | |
| 1040 | */ |
| 1041 | static int req_net_reg_get(mbtk_net_reg_info_t *reg, int *cme_err) |
| 1042 | { |
| 1043 | ATResponse *response = NULL; |
| 1044 | int tmp_int; |
| 1045 | char *tmp_str = NULL; |
| 1046 | int err = at_send_command("AT+CREG=3", &response); |
| 1047 | if (err < 0 || response->success == 0){ |
| 1048 | if(cme_err) { |
| 1049 | *cme_err = at_get_cme_error(response); |
| 1050 | } |
| 1051 | goto exit; |
| 1052 | } |
| 1053 | at_response_free(response); |
| 1054 | |
| 1055 | err = at_send_command_multiline("AT+CREG?", "+CREG:", &response); |
| 1056 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1057 | if(cme_err) { |
| 1058 | *cme_err = at_get_cme_error(response); |
| 1059 | } |
| 1060 | goto exit; |
| 1061 | } |
| 1062 | |
| 1063 | char *line = response->p_intermediates->line; |
| 1064 | err = at_tok_start(&line); |
| 1065 | if (err < 0) |
| 1066 | { |
| 1067 | goto exit; |
| 1068 | } |
| 1069 | err = at_tok_nextint(&line, &tmp_int); // n |
| 1070 | if (err < 0) |
| 1071 | { |
| 1072 | goto exit; |
| 1073 | } |
| 1074 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 1075 | if (err < 0) |
| 1076 | { |
| 1077 | goto exit; |
| 1078 | } |
| 1079 | reg->call_state = (uint8)tmp_int; |
| 1080 | |
| 1081 | if(at_tok_hasmore(&line)) { |
| 1082 | err = at_tok_nextstr(&line, &tmp_str); // lac |
| 1083 | if (err < 0) |
| 1084 | { |
| 1085 | goto exit; |
| 1086 | } |
| 1087 | reg->lac = strtol(tmp_str, NULL, 16); |
| 1088 | |
| 1089 | err = at_tok_nextstr(&line, &tmp_str); // ci |
| 1090 | if (err < 0) |
| 1091 | { |
| 1092 | goto exit; |
| 1093 | } |
| 1094 | reg->ci = strtol(tmp_str, NULL, 16); |
| 1095 | |
| 1096 | err = at_tok_nextint(&line, &tmp_int);// AcT |
| 1097 | if (err < 0) |
| 1098 | { |
| 1099 | goto exit; |
| 1100 | } |
| 1101 | reg->type = (uint8)tmp_int; |
| 1102 | } |
| 1103 | at_response_free(response); |
| 1104 | |
| 1105 | err = at_send_command_multiline("AT+CEREG?", "+CEREG:", &response); |
| 1106 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1107 | if(cme_err) { |
| 1108 | *cme_err = at_get_cme_error(response); |
| 1109 | } |
| 1110 | goto exit; |
| 1111 | } |
| 1112 | |
| 1113 | line = response->p_intermediates->line; |
| 1114 | err = at_tok_start(&line); |
| 1115 | if (err < 0) |
| 1116 | { |
| 1117 | goto exit; |
| 1118 | } |
| 1119 | err = at_tok_nextint(&line, &tmp_int); // n |
| 1120 | if (err < 0) |
| 1121 | { |
| 1122 | goto exit; |
| 1123 | } |
| 1124 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 1125 | if (err < 0) |
| 1126 | { |
| 1127 | goto exit; |
| 1128 | } |
| 1129 | reg->data_state = (uint8)tmp_int; |
| 1130 | |
| 1131 | if(reg->lac == 0 && at_tok_hasmore(&line)) { |
| 1132 | err = at_tok_nextstr(&line, &tmp_str); // lac |
| 1133 | if (err < 0) |
| 1134 | { |
| 1135 | goto exit; |
| 1136 | } |
| 1137 | reg->lac = strtol(tmp_str, NULL, 16); |
| 1138 | |
| 1139 | err = at_tok_nextstr(&line, &tmp_str); // ci |
| 1140 | if (err < 0) |
| 1141 | { |
| 1142 | goto exit; |
| 1143 | } |
| 1144 | reg->ci = strtol(tmp_str, NULL, 16); |
| 1145 | |
| 1146 | err = at_tok_nextint(&line, &tmp_int);// AcT |
| 1147 | if (err < 0) |
| 1148 | { |
| 1149 | goto exit; |
| 1150 | } |
| 1151 | reg->type = (uint8)tmp_int; |
| 1152 | } |
| 1153 | at_response_free(response); |
| 1154 | |
| 1155 | err = at_send_command_multiline("AT+CIREG?", "+CIREG:", &response); |
| 1156 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1157 | reg->ims_state = (uint8)0; |
| 1158 | err = 0; |
| 1159 | goto exit; |
| 1160 | } |
| 1161 | line = response->p_intermediates->line; |
| 1162 | err = at_tok_start(&line); |
| 1163 | if (err < 0) |
| 1164 | { |
| 1165 | goto exit; |
| 1166 | } |
| 1167 | err = at_tok_nextint(&line, &tmp_int); // n/stat |
| 1168 | if (err < 0) |
| 1169 | { |
| 1170 | goto exit; |
| 1171 | } |
| 1172 | if(at_tok_hasmore(&line)) { |
| 1173 | err = at_tok_nextint(&line, &tmp_int);// stat |
| 1174 | if (err < 0) |
| 1175 | { |
| 1176 | goto exit; |
| 1177 | } |
| 1178 | reg->ims_state = (uint8)tmp_int; |
| 1179 | } else { |
| 1180 | reg->ims_state = (uint8)tmp_int; |
| 1181 | } |
| 1182 | |
| 1183 | exit: |
| 1184 | at_response_free(response); |
| 1185 | return err; |
| 1186 | } |
| 1187 | |
| 1188 | /* |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 1189 | AT+EEMOPT=1 |
| 1190 | OK |
| 1191 | |
| 1192 | // LTE |
| 1193 | AT+EEMGINFO? |
| 1194 | // <mcc>, <length of mnc>, <mnc>, <tac>, <PCI>, <dlEuarfcn>, < ulEuarfcn >, <band>, <dlBandwidth>, |
| 1195 | // <rsrp>,<rsrq>, <sinr>, |
| 1196 | // errcModeState,emmState,serviceState,IsSingleEmmRejectCause,EMMRejectCause,mmeGroupId,mmeCode,mTmsi, |
| 1197 | // cellId,subFrameAssignType,specialSubframePatterns,transMode |
| 1198 | // mainRsrp,diversityRsrp,mainRsrq,diversityRsrq,rssi,cqi,pathLoss,tb0DlTpt,tb1DlTpt,tb0DlPeakTpt,tb1DlPeakTpt,tb0UlPeakTpt, |
| 1199 | // tb1UlPeakTpt,dlThroughPut,dlPeakThroughPut,averDlPRB,averCQITb0,averCQITb1,rankIndex,grantTotal,ulThroughPut,ulPeakThroughPut,currPuschTxPower,averUlPRB, |
| 1200 | // dlBer, ulBer, |
| 1201 | // diversitySinr, diversityRssi |
| 1202 | +EEMLTESVC: 1120, 2, 0, 33584, 430, 40936, 40936, 41, 20, |
| 1203 | 0, 0, 0, |
| 1204 | 1, 10, 0, 1, 0, 1059, 78, 3959566565, |
| 1205 | 105149248, 2, 7, 7, |
| 1206 | 0, 0, 0, 0, 0, 0, 0, 1190919, 0, 0, 0, 16779777, |
| 1207 | 0, 5112867, 3959566565, 2, 0, 0, 0, 0, 0, 0, 0, 0, |
| 1208 | 0, 0, |
| 1209 | 7, 44 |
| 1210 | |
| 1211 | // index,phyCellId,euArfcn,rsrp,rsrq |
| 1212 | +EEMLTEINTER: 0, 65535, 38950, 0, 0 |
| 1213 | |
| 1214 | +EEMLTEINTER: 1, 0, 0, 0, 0 |
| 1215 | |
| 1216 | +EEMLTEINTER: 2, 0, 4294967295, 255, 255 |
| 1217 | |
| 1218 | +EEMLTEINTER: 3, 65535, 1300, 0, 0 |
| 1219 | |
| 1220 | +EEMLTEINTER: 4, 0, 0, 0, 0 |
| 1221 | |
| 1222 | +EEMLTEINTER: 5, 0, 4294967295, 247, 0 |
| 1223 | |
| 1224 | +EEMLTEINTER: 6, 197, 41332, 24, 9 |
| 1225 | |
| 1226 | +EEMLTEINTER: 7, 0, 0, 0, 0 |
| 1227 | |
| 1228 | +EEMLTEINTER: 8, 0, 0, 0, 0 |
| 1229 | |
| 1230 | +EEMLTEINTRA: 0, 429, 40936, 56, 12 |
| 1231 | |
| 1232 | +EEMLTEINTERRAT: 0,0 |
| 1233 | |
| 1234 | +EEMLTEINTERRAT: 1,0 |
| 1235 | |
| 1236 | +EEMGINFO: 3, 2 // <state>: |
| 1237 | // 0: ME in Idle mode |
| 1238 | // 1: ME in Dedicated mode |
| 1239 | // 2: ME in PS PTM mode |
| 1240 | // 3: invalid state |
| 1241 | // <nw_type>: |
| 1242 | // 0: GSM 1: UMTS 2: LTE |
| 1243 | |
| 1244 | OK |
| 1245 | |
| 1246 | // WCDMA |
| 1247 | AT+EEMGINFO? |
| 1248 | // Mode, sCMeasPresent, sCParamPresent, ueOpStatusPresent, |
| 1249 | |
| 1250 | // if sCMeasPresent == 1 |
| 1251 | // cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev, txPower, |
| 1252 | // endif |
| 1253 | |
| 1254 | // if sCParamPresent == 1 |
| 1255 | // rac, nom, mcc, mnc_len, mnc, lac, ci, |
| 1256 | // uraId, psc, arfcn, t3212, t3312, hcsUsed, attDetAllowed, |
| 1257 | // csDrxCycleLen, psDrxCycleLen, utranDrxCycleLen, HSDPASupport, HSUPASupport, |
| 1258 | // endif |
| 1259 | |
| 1260 | // if ueOpStatusPresent == 1 |
| 1261 | // rrcState, numLinks, srncId, sRnti, |
| 1262 | // algPresent, cipherAlg, cipherOn, algPresent, cipherAlg, cipherOn, |
| 1263 | // HSDPAActive, HSUPAActive, MccLastRegisteredNetwork, MncLastRegisteredNetwork, TMSI, PTMSI, IsSingleMmRejectCause, IsSingleGmmRejectCause, |
| 1264 | // MMRejectCause, GMMRejectCause, mmState, gmmState, gprsReadyState, readyTimerValueInSecs, NumActivePDPContext, ULThroughput, DLThroughput, |
| 1265 | // serviceStatus, pmmState, LAU_status, LAU_count, RAU_status, RAU_count |
| 1266 | // endif |
| 1267 | // |
| 1268 | +EEMUMTSSVC: 3, 1, 1, 1, |
| 1269 | -80, 27, -6, -18, -115, -32768, |
| 1270 | 1, 1, 1120, 2, 1, 61697, 168432821, |
| 1271 | 15, 24, 10763, 0, 0, 0, 0, |
| 1272 | 128, 128, 65535, 0, 0, |
| 1273 | 2, 255, 65535, 4294967295, |
| 1274 | 0, 0, 0, 0, 0, 0, |
| 1275 | 0, 0, 0, 0, 0, 0, 1, 1, |
| 1276 | 28672, 28672, 0, 0, 0, 0, 0, 0, 0, |
| 1277 | 0, 0, 0, 0, 0, 0 |
| 1278 | |
| 1279 | // index, cpichRSCP, utraRssi, cpichEcN0, sQual, sRxLev ,mcc, mnc, lac, ci, arfcn, psc |
| 1280 | +EEMUMTSINTRA: 0, -32768, -1, -32768, -18, -115, 0, 0, 65534, 1, 10763, 32 |
| 1281 | |
| 1282 | +EEMUMTSINTRA: 1, -1, -32768, -18, -115, 0, 0, 65534, 2, 10763, 40, 32768 |
| 1283 | |
| 1284 | +EEMUMTSINTRA: 2, -32768, -18, -115, 0, 0, 65534, 3, 10763, 278, 32768, 65535 |
| 1285 | |
| 1286 | +EEMUMTSINTRA: 3, -18, -115, 0, 0, -2, 4, 10763, 28, 32768, 65535, 32768 |
| 1287 | |
| 1288 | +EEMUMTSINTRA: 4, -115, 0, 0, -2, 5, 10763, 270, 32768, 65535, 32768, 65518 |
| 1289 | |
| 1290 | +EEMUMTSINTRA: 5, 0, 0, -2, 6, 10763, 286, 32768, 65535, 32768, 65518, 65421 |
| 1291 | |
| 1292 | +EEMUMTSINTRA: 6, 0, -2, 7, 10763, 80, 32768, 65535, 32768, 65518, 65421, 0 |
| 1293 | |
| 1294 | +EEMUMTSINTRA: 7, -2, 8, 10763, 206, -32768, 65535, 32768, 65518, 65421, 0, 0 |
| 1295 | |
| 1296 | +EEMUMTSINTRA: 8, 9, 10763, 11, -32768, -1, 32768, 65518, 65421, 0, 0, 65534 |
| 1297 | |
| 1298 | +EEMUMTSINTRA: 9, 10763, 19, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 11 |
| 1299 | |
| 1300 | +EEMUMTSINTRA: 10, 232, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 12, 10763 |
| 1301 | |
| 1302 | +EEMUMTSINTRA: 11, -32768, -1, -32768, -18, -115, 0, 0, 65534, 13, 10763, 66 |
| 1303 | |
| 1304 | +EEMUMTSINTRA: 12, -1, -32768, -18, -115, 0, 0, 65534, 14, 10763, 216, 32768 |
| 1305 | |
| 1306 | +EEMUMTSINTRA: 13, -32768, -18, -115, 0, 0, 65534, 15, 10763, 183, 32768, 65535 |
| 1307 | |
| 1308 | +EEMUMTSINTRA: 14, -18, -115, 0, 0, -2, 16, 10763, 165, 32768, 65535, 32768 |
| 1309 | |
| 1310 | +EEMUMTSINTRA: 15, -115, 0, 0, -2, 17, 10763, 151, 32768, 65535, 32768, 65518 |
| 1311 | |
| 1312 | +EEMUMTSINTRA: 16, 0, 0, -2, 18, 10763, 43, 32768, 65535, 32768, 65518, 65421 |
| 1313 | |
| 1314 | +EEMUMTSINTRA: 17, 0, -2, 19, 10763, 72, 32768, 65535, 32768, 65518, 65421, 0 |
| 1315 | |
| 1316 | +EEMUMTSINTRA: 18, -2, 20, 10763, 157, -32768, 65535, 32768, 65518, 65421, 0, 0 |
| 1317 | |
| 1318 | +EEMUMTSINTRA: 19, 21, 10763, 165, -32768, -1, 32768, 65518, 65421, 0, 0, 65534 |
| 1319 | |
| 1320 | +EEMUMTSINTRA: 20, 10763, 301, -32768, -1, -32768, 65518, 65421, 0, 0, 65534, 23 |
| 1321 | |
| 1322 | +EEMUMTSINTRA: 21, 23, -32768, -1, -32768, -18, 65421, 0, 0, 65534, 24, 10763 |
| 1323 | |
| 1324 | +EEMUMTSINTRA: 22, -32768, -1, -32768, -18, -115, 0, 0, 65534, 25, 10763, 0 |
| 1325 | |
| 1326 | +EEMUMTSINTRA: 23, -1, -32768, -18, -115, 0, 0, 65534, 26, 10763, 167, 32768 |
| 1327 | |
| 1328 | +EEMUMTSINTRA: 24, -32768, -18, -115, 0, 0, 65534, 27, 10763, 34, 32768, 65535 |
| 1329 | |
| 1330 | +EEMUMTSINTRA: 25, -18, -115, 0, 0, -2, 28, 10763, 313, 32768, 65535, 32768 |
| 1331 | |
| 1332 | +EEMUMTSINTRA: 26, -115, 0, 0, -2, 29, 10763, 152, 32768, 65535, 32768, 65518 |
| 1333 | |
| 1334 | +EEMUMTSINTRA: 27, 0, 0, -2, 30, 10763, 239, 0, 0, 0, 0, 0 |
| 1335 | |
| 1336 | +EEMUMTSINTRA: 28, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
| 1337 | |
| 1338 | +EEMUMTSINTRA: 29, 0, 0, 0, 0, -115, 0, 0, 65534, 30, 10763, 239 |
| 1339 | |
| 1340 | // index,gsmRssi,rxLev,C1,C2,mcc,mnc,lac,ci,arfcn,bsic |
| 1341 | +EEMUMTSINTERRAT: 0, -32768, -107, -1, -1, 0, 0, 65534, 0, 117, 36 |
| 1342 | |
| 1343 | +EEMUMTSINTERRAT: 1, -107, -1, -1, 0, 0, 65534, 1, 72, 49, 0 |
| 1344 | |
| 1345 | +EEMUMTSINTERRAT: 2, -1, -1, 0, 0, 65534, 2, 119, 15, 32768, 149 |
| 1346 | |
| 1347 | +EEMUMTSINTERRAT: 3, -1, 0, 0, -2, 3, 121, 23, 0, 0, 0 |
| 1348 | |
| 1349 | +EEMGINFO: 3, 1 |
| 1350 | |
| 1351 | OK |
| 1352 | |
| 1353 | |
| 1354 | // GSM |
| 1355 | AT+EEMGINFO? |
| 1356 | +EEMGINFOBASIC: 2 |
| 1357 | |
| 1358 | // mcc, mnc_len, mnc, lac, ci, nom, nco, |
| 1359 | // bsic, C1, C2, TA, TxPwr, |
| 1360 | // RxSig, RxSigFull, RxSigSub, RxQualFull, RxQualSub, |
| 1361 | // ARFCB_tch, hopping_chnl, chnl_type, TS, PacketIdle, rac, arfcn, |
| 1362 | // bs_pa_mfrms, C31, C32, t3212, t3312, pbcch_support, EDGE_support, |
| 1363 | // ncc_permitted, rl_timeout, ho_count, ho_succ, chnl_access_count, chnl_access_succ_count, |
| 1364 | // gsmBand,channelMode |
| 1365 | +EEMGINFOSVC: 1120, 2, 0, 32784, 24741, 2, 0, |
| 1366 | 63, 36, 146, 1, 7, |
| 1367 | 46, 42, 42, 7, 0, |
| 1368 | 53, 0, 8, 0, 1, 6, 53, |
| 1369 | 2, 0, 146, 42, 54, 0, 1, |
| 1370 | 1, 32, 0, 0, 0, 0, |
| 1371 | 0, 0 |
| 1372 | |
| 1373 | // PS_attached, attach_type, service_type, tx_power, c_value, |
| 1374 | // ul_ts, dl_ts, ul_cs, dl_cs, ul_modulation, dl_modulation, |
| 1375 | // gmsk_cv_bep, 8psk_cv_bep, gmsk_mean_bep, 8psk_mean_bep, EDGE_bep_period, single_gmm_rej_cause |
| 1376 | // pdp_active_num, mac_mode, network_control, network_mode, EDGE_slq_measurement_mode, edge_status |
| 1377 | +EEMGINFOPS: 1, 255, 0, 0, 0, |
| 1378 | 0, 0, 268435501, 1, 0, 0, |
| 1379 | 4, 0, 96, 0, 0, 0, |
| 1380 | 0, 0, 0, 65535, 0, 13350 |
| 1381 | |
| 1382 | +EEMGINFO: 0, 0 |
| 1383 | |
| 1384 | OK |
| 1385 | |
| 1386 | */ |
| 1387 | static int req_cell_info_get(int *cme_err) |
| 1388 | { |
| 1389 | ATResponse *response = NULL; |
| 1390 | int tmp_int; |
| 1391 | int buff_size = 0; |
| 1392 | // AT+EEMOPT=1 in the first. |
| 1393 | int err = at_send_command("AT+EEMOPT=1", &response); |
| 1394 | if (err < 0 || response->success == 0){ |
| 1395 | *cme_err = at_get_cme_error(response); |
| 1396 | goto exit; |
| 1397 | } |
| 1398 | |
| 1399 | // Reset buffer in the first. |
| 1400 | memset(&cell_info, 0xFF, sizeof(mbtK_cell_pack_info_t)); |
| 1401 | cell_info.running = true; |
| 1402 | cell_info.cell_list.num = 0; |
| 1403 | |
| 1404 | err = at_send_command_singleline("AT+EEMGINFO?", "+EEMGINFO:", &response); |
| 1405 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1406 | *cme_err = at_get_cme_error(response); |
| 1407 | goto exit; |
| 1408 | } |
| 1409 | |
| 1410 | // Now, cell infomation has get from URC message. |
| 1411 | |
| 1412 | char *line = response->p_intermediates->line; |
| 1413 | err = at_tok_start(&line); |
| 1414 | if (err < 0) |
| 1415 | { |
| 1416 | goto exit; |
| 1417 | } |
| 1418 | err = at_tok_nextint(&line, &tmp_int); |
| 1419 | if (err < 0) |
| 1420 | { |
| 1421 | goto exit; |
| 1422 | } |
| 1423 | err = at_tok_nextint(&line, &tmp_int); |
| 1424 | if (err < 0) |
| 1425 | { |
| 1426 | goto exit; |
| 1427 | } |
| 1428 | |
| 1429 | cell_info.cell_list.type = (uint8)tmp_int; |
| 1430 | cell_info.running = false; |
| 1431 | |
| 1432 | #if 0 |
| 1433 | while(lines_ptr) |
| 1434 | { |
| 1435 | // LTE |
| 1436 | if(strStartsWith(line, "+EEMLTESVC:")) // LTE Server Cell |
| 1437 | { |
| 1438 | |
| 1439 | } |
| 1440 | else if(strStartsWith(line, "+EEMLTEINTER:")) // LTE |
| 1441 | { |
| 1442 | |
| 1443 | } |
| 1444 | else if(strStartsWith(line, "+EEMLTEINTRA:")) // LTE |
| 1445 | { |
| 1446 | |
| 1447 | } |
| 1448 | else if(strStartsWith(line, "+EEMLTEINTERRAT:")) // LTE |
| 1449 | { |
| 1450 | |
| 1451 | } |
| 1452 | 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 |
| 1453 | // <nw_type>: 0: GSM 1: UMTS 2: LTE |
| 1454 | { |
| 1455 | |
| 1456 | } |
| 1457 | // WCDMA |
| 1458 | else if(strStartsWith(line, "+EEMUMTSSVC:")) // WCDMA Server Cell |
| 1459 | { |
| 1460 | |
| 1461 | } |
| 1462 | else if(strStartsWith(line, "+EEMUMTSINTRA:")) // WCDMA |
| 1463 | { |
| 1464 | |
| 1465 | } |
| 1466 | else if(strStartsWith(line, "+EEMUMTSINTERRAT:")) // WCDMA |
| 1467 | { |
| 1468 | |
| 1469 | } |
| 1470 | // GSM |
| 1471 | else if(strStartsWith(line, "+EEMGINFOBASIC:")) // Basic information in GSM |
| 1472 | // 0: ME in Idle mode 1: ME in Dedicated mode 2: ME in PS PTM mode |
| 1473 | { |
| 1474 | |
| 1475 | } |
| 1476 | else if(strStartsWith(line, "+EEMGINFOSVC:")) // GSM Server Cell |
| 1477 | { |
| 1478 | |
| 1479 | } |
| 1480 | else if(strStartsWith(line, "+EEMGINFOPS:")) // PS |
| 1481 | { |
| 1482 | |
| 1483 | } |
| 1484 | |
| 1485 | |
| 1486 | lines_ptr = lines_ptr->p_next; |
| 1487 | } |
| 1488 | #endif |
| 1489 | |
| 1490 | exit: |
| 1491 | at_response_free(response); |
| 1492 | return buff_size; |
| 1493 | } |
| 1494 | |
| 1495 | static int req_cell_info_set(const char *cmgl, char *reg, int len, int *cme_err) |
| 1496 | { |
| 1497 | ATResponse *response = NULL; |
| 1498 | char cmd[30] = {0}; |
| 1499 | char data[218] = {0}; |
| 1500 | int err = 0; |
| 1501 | |
| 1502 | memcpy(data, cmgl, len); |
| 1503 | |
| 1504 | sprintf(cmd, "AT*CELL=%s", data); |
| 1505 | |
| 1506 | if(strlen(cmd) > 0) |
| 1507 | { |
| 1508 | err = at_send_command_multiline(cmd, "", &response); |
| 1509 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1510 | *cme_err = at_get_cme_error(response); |
| 1511 | goto exit; |
| 1512 | } |
| 1513 | |
| 1514 | ATLine* lines_ptr = response->p_intermediates; |
| 1515 | char *line = NULL; |
| 1516 | int reg_len = 0; |
| 1517 | bool flag = false; |
| 1518 | while(lines_ptr) |
| 1519 | { |
| 1520 | line = lines_ptr->line; |
| 1521 | if(line ==NULL) |
| 1522 | { |
| 1523 | LOGD("line is null----------------------"); |
| 1524 | } |
| 1525 | lines_ptr = lines_ptr->p_next; |
| 1526 | } |
| 1527 | } |
| 1528 | err = 0; |
| 1529 | memcpy(reg, "req_cell_info_set succss", strlen("req_cell_info_set succss")); |
| 1530 | exit: |
| 1531 | at_response_free(response); |
| 1532 | return err; |
| 1533 | } |
| 1534 | |
| 1535 | |
| 1536 | /* |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1537 | AT+CGDCONT? |
| 1538 | |
| 1539 | +CGDCONT: 1,"IPV4V6","ctnet","10.142.64.116 254.128.0.0.0.0.0.0.0.0.0.0.0.0.0.1",0,0,0,2,0,0 |
| 1540 | |
| 1541 | +CGDCONT: 8,"IPV4V6","IMS","254.128.0.0.0.0.0.0.0.0.0.0.0.0.0.1",0,0,0,2,1,1 |
| 1542 | |
| 1543 | OK |
| 1544 | |
| 1545 | */ |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 1546 | static int req_apn_get(bool get_def_cid, mbtk_apn_info_array_t *apns, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1547 | { |
| 1548 | ATResponse *response = NULL; |
| 1549 | int err = at_send_command_multiline("AT+CGDCONT?", "+CGDCONT:", &response); |
| 1550 | |
| 1551 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1552 | if(cme_err) { |
| 1553 | *cme_err = at_get_cme_error(response); |
| 1554 | } |
| 1555 | goto exit; |
| 1556 | } |
| 1557 | |
| 1558 | ATLine* lines_ptr = response->p_intermediates; |
| 1559 | char *line = NULL; |
| 1560 | int tmp_int; |
| 1561 | char *tmp_str = NULL; |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 1562 | int cid_start; |
| 1563 | if(apn_conf_support(MBTK_RIL_CID_DEF)) { |
| 1564 | cid_start = MBTK_RIL_CID_DEF; |
| 1565 | } else { |
| 1566 | if(get_def_cid) { |
| 1567 | cid_start = MBTK_RIL_CID_DEF; |
| 1568 | } else { |
| 1569 | cid_start = MBTK_RIL_CID_2; |
| 1570 | } |
| 1571 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1572 | /* |
| 1573 | <apn_num[1]><cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth>... |
| 1574 | <cid[1]><ip_type[1]><apn_len[2]><apn><user_len[2]><user><pass_len[2]><pass><auth_len[2]><auth> |
| 1575 | */ |
| 1576 | while(lines_ptr) |
| 1577 | { |
| 1578 | line = lines_ptr->line; |
| 1579 | err = at_tok_start(&line); |
| 1580 | if (err < 0) |
| 1581 | { |
| 1582 | goto exit; |
| 1583 | } |
| 1584 | |
| 1585 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 1586 | if (err < 0) |
| 1587 | { |
| 1588 | goto exit; |
| 1589 | } |
| 1590 | // Only get CID 1-7 |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 1591 | if(tmp_int >= cid_start && tmp_int <= MBTK_APN_CID_MAX) { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1592 | apns->apns[apns->num].cid = (mbtk_ril_cid_enum)tmp_int; |
| 1593 | |
| 1594 | err = at_tok_nextstr(&line, &tmp_str);// ip type |
| 1595 | if (err < 0) |
| 1596 | { |
| 1597 | goto exit; |
| 1598 | } |
| 1599 | if(!strcasecmp(tmp_str, "IP")) { |
| 1600 | apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IP; |
| 1601 | } else if(!strcasecmp(tmp_str, "IPV6")) { |
| 1602 | apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IPV6; |
| 1603 | } else if(!strcasecmp(tmp_str, "IPV4V6")) { |
| 1604 | apns->apns[apns->num].ip_type = MBTK_IP_TYPE_IPV4V6; |
| 1605 | } else { |
| 1606 | apns->apns[apns->num].ip_type = MBTK_IP_TYPE_PPP; |
| 1607 | } |
| 1608 | |
| 1609 | err = at_tok_nextstr(&line, &tmp_str); // apn |
| 1610 | if (err < 0) |
| 1611 | { |
| 1612 | goto exit; |
| 1613 | } |
| 1614 | if(!str_empty(tmp_str)) { |
| 1615 | memcpy(apns->apns[apns->num].apn, tmp_str, strlen(tmp_str)); |
| 1616 | } |
| 1617 | |
| 1618 | apns->num++; |
| 1619 | } |
| 1620 | |
| 1621 | lines_ptr = lines_ptr->p_next; |
| 1622 | } |
| 1623 | |
| 1624 | goto exit; |
| 1625 | exit: |
| 1626 | at_response_free(response); |
| 1627 | return err; |
| 1628 | } |
| 1629 | |
| 1630 | /* |
| 1631 | AT+CGDCONT=1,"IPV4V6","cmnet" |
| 1632 | OK |
| 1633 | |
| 1634 | AT*AUTHReq=1,1,marvell,123456 |
| 1635 | OK |
| 1636 | |
| 1637 | */ |
| 1638 | static int req_apn_set(mbtk_apn_info_t *apn, int *cme_err) |
| 1639 | { |
| 1640 | ATResponse *response = NULL; |
| 1641 | char cmd[400] = {0}; |
| 1642 | int index = 0; |
| 1643 | int err = 0; |
| 1644 | |
| 1645 | // Delete apn |
| 1646 | if(str_empty(apn->apn)) { |
| 1647 | sprintf(cmd, "AT+CGDCONT=%d", apn->cid); |
| 1648 | err = at_send_command(cmd, &response); |
| 1649 | if (err < 0 || response->success == 0){ |
| 1650 | if(cme_err) { |
| 1651 | *cme_err = at_get_cme_error(response); |
| 1652 | } |
| 1653 | goto exit; |
| 1654 | } |
| 1655 | } else { |
| 1656 | index += sprintf(cmd, "AT+CGDCONT=%d,", apn->cid); |
| 1657 | switch(apn->ip_type) { |
| 1658 | case MBTK_IP_TYPE_IP: { |
| 1659 | index += sprintf(cmd + index,"\"IP\","); |
| 1660 | break; |
| 1661 | } |
| 1662 | case MBTK_IP_TYPE_IPV6: { |
| 1663 | index += sprintf(cmd + index,"\"IPV6\","); |
| 1664 | break; |
| 1665 | } |
| 1666 | case MBTK_IP_TYPE_IPV4V6: { |
| 1667 | index += sprintf(cmd + index,"\"IPV4V6\","); |
| 1668 | break; |
| 1669 | } |
| 1670 | default: { |
| 1671 | index += sprintf(cmd + index,"\"PPP\","); |
| 1672 | break; |
| 1673 | } |
| 1674 | } |
| 1675 | if(strlen(apn->apn) > 0) { |
| 1676 | index += sprintf(cmd + index,"\"%s\"", apn->apn); |
| 1677 | } |
| 1678 | |
| 1679 | err = at_send_command(cmd, &response); |
| 1680 | if (err < 0 || response->success == 0){ |
| 1681 | if(cme_err) { |
| 1682 | *cme_err = at_get_cme_error(response); |
| 1683 | } |
| 1684 | goto exit; |
| 1685 | } |
| 1686 | |
| 1687 | if(!str_empty(apn->user) || !str_empty(apn->pass)) { |
| 1688 | at_response_free(response); |
| 1689 | |
| 1690 | memset(cmd,0,400); |
| 1691 | int cmd_auth=0; |
| 1692 | if(apn->auth == MBTK_APN_AUTH_PROTO_NONE) |
| 1693 | cmd_auth = 0; |
| 1694 | else if(apn->auth == MBTK_APN_AUTH_PROTO_PAP) |
| 1695 | cmd_auth = 1; |
| 1696 | else if(apn->auth == MBTK_APN_AUTH_PROTO_CHAP) |
| 1697 | cmd_auth = 2; |
| 1698 | else |
| 1699 | goto exit; |
| 1700 | |
| 1701 | sprintf(cmd, "AT*AUTHREQ=%d,%d,%s,%s",apn->cid,cmd_auth,apn->user,apn->pass); |
| 1702 | err = at_send_command(cmd, &response); |
| 1703 | if (err < 0 || response->success == 0){ |
| 1704 | if(cme_err) { |
| 1705 | *cme_err = at_get_cme_error(response); |
| 1706 | } |
| 1707 | goto exit; |
| 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | exit: |
| 1713 | at_response_free(response); |
| 1714 | return err; |
| 1715 | } |
| 1716 | |
| 1717 | /* |
| 1718 | AT+CGACT? |
| 1719 | +CGACT: 1,1 |
| 1720 | +CGACT: 8,1 |
| 1721 | OK |
| 1722 | |
| 1723 | AT+CGACT=1,<cid> |
| 1724 | OK |
| 1725 | |
| 1726 | */ |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 1727 | static int req_data_call_start(mbtk_ril_cid_enum cid, bool def_route, bool as_dns, |
| 1728 | int retry_interval, int timeout, int *cme_err) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1729 | { |
| 1730 | ATResponse *response = NULL; |
| 1731 | char cmd[400] = {0}; |
| 1732 | int err = 0; |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 1733 | memset(&cgact_wait, 0, sizeof(ril_cgact_wait_t)); |
| 1734 | cgact_wait.waitting = true; |
| 1735 | cgact_wait.cid = cid; |
| 1736 | cgact_wait.act = true; |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1737 | |
| 1738 | sprintf(cmd, "AT+CGACT=1,%d", cid); |
| 1739 | err = at_send_command(cmd, &response); |
| 1740 | if (err < 0 || response->success == 0){ |
| 1741 | if(cme_err) { |
| 1742 | *cme_err = at_get_cme_error(response); |
| 1743 | } |
| 1744 | goto exit; |
| 1745 | } |
| 1746 | |
| 1747 | exit: |
| 1748 | at_response_free(response); |
| 1749 | return err; |
| 1750 | } |
| 1751 | |
| 1752 | /* |
| 1753 | AT+CGACT=0,<cid> |
| 1754 | OK |
| 1755 | |
| 1756 | */ |
| 1757 | static int req_data_call_stop(mbtk_ril_cid_enum cid, int timeout, int *cme_err) |
| 1758 | { |
| 1759 | ATResponse *response = NULL; |
| 1760 | char cmd[400] = {0}; |
| 1761 | int err = 0; |
| 1762 | |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 1763 | memset(&cgact_wait, 0, sizeof(ril_cgact_wait_t)); |
| 1764 | cgact_wait.waitting = true; |
| 1765 | cgact_wait.cid = cid; |
| 1766 | cgact_wait.act = false; |
| 1767 | |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 1768 | sprintf(cmd, "AT+CGACT=0,%d", cid); |
| 1769 | err = at_send_command(cmd, &response); |
| 1770 | if (err < 0 || response->success == 0){ |
| 1771 | if(cme_err) { |
| 1772 | *cme_err = at_get_cme_error(response); |
| 1773 | } |
| 1774 | goto exit; |
| 1775 | } |
| 1776 | |
| 1777 | exit: |
| 1778 | at_response_free(response); |
| 1779 | return err; |
| 1780 | } |
| 1781 | |
| 1782 | /* |
| 1783 | AT+CGCONTRDP=1 |
| 1784 | +CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","10.255.74.26","","223.87.253.100","223.87.253.253","","",0,0 |
| 1785 | +CGCONTRDP: 1,7,"cmnet-2.MNC000.MCC460.GPRS","254.128.0.0.0.0.0.0.0.1.0.2.144.5.212.239","","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.1","36.9.128.98.32.0.0.2.0.0.0.0.0.0.0.2","","",0,0 |
| 1786 | |
| 1787 | OK |
| 1788 | |
| 1789 | */ |
| 1790 | static int req_data_call_state_get(mbtk_ril_cid_enum cid, mbtk_ip_info_t *ip_info, int *cme_err) |
| 1791 | { |
| 1792 | ATResponse *response = NULL; |
| 1793 | char cmd[50] = {0}; |
| 1794 | int err = 0; |
| 1795 | |
| 1796 | sprintf(cmd, "AT+CGCONTRDP=%d", cid); |
| 1797 | |
| 1798 | err = at_send_command_multiline(cmd, "+CGCONTRDP:", &response); |
| 1799 | if (err < 0 || response->success == 0 || !response->p_intermediates){ |
| 1800 | *cme_err = at_get_cme_error(response); |
| 1801 | goto exit; |
| 1802 | } |
| 1803 | ATLine* lines_ptr = response->p_intermediates; |
| 1804 | char *line = NULL; |
| 1805 | int tmp_int; |
| 1806 | char *tmp_ptr = NULL; |
| 1807 | while(lines_ptr) |
| 1808 | { |
| 1809 | line = lines_ptr->line; |
| 1810 | err = at_tok_start(&line); |
| 1811 | if (err < 0) |
| 1812 | { |
| 1813 | goto exit; |
| 1814 | } |
| 1815 | |
| 1816 | err = at_tok_nextint(&line, &tmp_int); // cid |
| 1817 | if (err < 0) |
| 1818 | { |
| 1819 | goto exit; |
| 1820 | } |
| 1821 | err = at_tok_nextint(&line, &tmp_int); // bearer_id |
| 1822 | if (err < 0) |
| 1823 | { |
| 1824 | goto exit; |
| 1825 | } |
| 1826 | err = at_tok_nextstr(&line, &tmp_ptr); // APN |
| 1827 | if (err < 0) |
| 1828 | { |
| 1829 | goto exit; |
| 1830 | } |
| 1831 | |
| 1832 | err = at_tok_nextstr(&line, &tmp_ptr); // IP |
| 1833 | if (err < 0 || str_empty(tmp_ptr)) |
| 1834 | { |
| 1835 | goto exit; |
| 1836 | } |
| 1837 | if(is_ipv4(tmp_ptr)) { |
| 1838 | if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.IPAddr)) < 0) { |
| 1839 | LOGE("inet_pton() fail."); |
| 1840 | err = -1; |
| 1841 | goto exit; |
| 1842 | } |
| 1843 | |
| 1844 | ip_info->ipv4.valid = true; |
| 1845 | //log_hex("IPv4", &(ipv4->IPAddr), sizeof(struct in_addr)); |
| 1846 | } else { |
| 1847 | if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.IPV6Addr))) { |
| 1848 | LOGE("str_2_ipv6() fail."); |
| 1849 | err = -1; |
| 1850 | goto exit; |
| 1851 | } |
| 1852 | |
| 1853 | ip_info->ipv6.valid = true; |
| 1854 | //log_hex("IPv6", &(ipv6->IPV6Addr), 16); |
| 1855 | } |
| 1856 | |
| 1857 | err = at_tok_nextstr(&line, &tmp_ptr); // Gateway |
| 1858 | if (err < 0) |
| 1859 | { |
| 1860 | goto exit; |
| 1861 | } |
| 1862 | if(!str_empty(tmp_ptr)) { // No found gateway |
| 1863 | if(is_ipv4(tmp_ptr)) { |
| 1864 | if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.GateWay)) < 0) { |
| 1865 | LOGE("inet_pton() fail."); |
| 1866 | err = -1; |
| 1867 | goto exit; |
| 1868 | } |
| 1869 | |
| 1870 | //log_hex("IPv4", &(ipv4->GateWay), sizeof(struct in_addr)); |
| 1871 | } else { |
| 1872 | if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.GateWay))) { |
| 1873 | LOGE("str_2_ipv6() fail."); |
| 1874 | err = -1; |
| 1875 | goto exit; |
| 1876 | } |
| 1877 | |
| 1878 | //log_hex("IPv6", &(ipv6->GateWay), 16); |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | err = at_tok_nextstr(&line, &tmp_ptr); // prim_DNS |
| 1883 | if (err < 0) |
| 1884 | { |
| 1885 | goto exit; |
| 1886 | } |
| 1887 | if(!str_empty(tmp_ptr)) { // No found Primary DNS |
| 1888 | if(is_ipv4(tmp_ptr)) { |
| 1889 | if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.PrimaryDNS)) < 0) { |
| 1890 | LOGE("inet_pton() fail."); |
| 1891 | err = -1; |
| 1892 | goto exit; |
| 1893 | } |
| 1894 | |
| 1895 | //log_hex("IPv4", &(ipv4->PrimaryDNS), sizeof(struct in_addr)); |
| 1896 | } else { |
| 1897 | if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.PrimaryDNS))) { |
| 1898 | LOGE("str_2_ipv6() fail."); |
| 1899 | err = -1; |
| 1900 | goto exit; |
| 1901 | } |
| 1902 | |
| 1903 | //log_hex("IPv6", &(ipv6->PrimaryDNS), 16); |
| 1904 | } |
| 1905 | } |
| 1906 | |
| 1907 | err = at_tok_nextstr(&line, &tmp_ptr); // sec_DNS |
| 1908 | if (err < 0) |
| 1909 | { |
| 1910 | goto exit; |
| 1911 | } |
| 1912 | if(!str_empty(tmp_ptr)) { // No found Secondary DNS |
| 1913 | if(is_ipv4(tmp_ptr)) { |
| 1914 | if(inet_pton(AF_INET, tmp_ptr, &(ip_info->ipv4.SecondaryDNS)) < 0) { |
| 1915 | LOGE("inet_pton() fail."); |
| 1916 | err = -1; |
| 1917 | goto exit; |
| 1918 | } |
| 1919 | |
| 1920 | //log_hex("IPv4", &(ipv4->SecondaryDNS), sizeof(struct in_addr)); |
| 1921 | } else { |
| 1922 | if(str_2_ipv6(tmp_ptr, &(ip_info->ipv6.SecondaryDNS))) { |
| 1923 | LOGE("str_2_ipv6() fail."); |
| 1924 | err = -1; |
| 1925 | goto exit; |
| 1926 | } |
| 1927 | |
| 1928 | //log_hex("IPv6", &(ipv6->SecondaryDNS), 16); |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | lines_ptr = lines_ptr->p_next; |
| 1933 | } |
| 1934 | |
| 1935 | exit: |
| 1936 | at_response_free(response); |
| 1937 | return err; |
| 1938 | } |
| 1939 | |
| 1940 | |
| 1941 | //void net_list_free(void *data); |
| 1942 | // Return MBTK_INFO_ERR_SUCCESS,will call pack_error_send() to send RSP. |
| 1943 | // Otherwise, do not call pack_error_send(). |
| 1944 | mbtk_ril_err_enum net_pack_req_process(sock_cli_info_t* cli_info, ril_msg_pack_info_t* pack) |
| 1945 | { |
| 1946 | mbtk_ril_err_enum err = MBTK_RIL_ERR_SUCCESS; |
| 1947 | int cme_err = MBTK_RIL_ERR_CME_NON; |
| 1948 | switch(pack->msg_id) |
| 1949 | { |
| 1950 | case RIL_MSG_ID_NET_AVAILABLE: |
| 1951 | { |
| 1952 | if(pack->data_len == 0 || pack->data == NULL) |
| 1953 | { |
| 1954 | mbtk_net_info_array_t net_array; |
| 1955 | memset(&net_array, 0, sizeof(mbtk_net_info_array_t)); |
| 1956 | if(req_available_net_get(&net_array, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1957 | { |
| 1958 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1959 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1960 | } else { |
| 1961 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1962 | } |
| 1963 | LOGD("Get Available Net fail."); |
| 1964 | } |
| 1965 | else |
| 1966 | { |
| 1967 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_array, sizeof(mbtk_net_info_array_t)); |
| 1968 | } |
| 1969 | } |
| 1970 | else // Set |
| 1971 | { |
| 1972 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 1973 | LOGW("Unsupport set available net."); |
| 1974 | } |
| 1975 | break; |
| 1976 | } |
| 1977 | case RIL_MSG_ID_NET_SEL_MODE: |
| 1978 | { |
| 1979 | if(pack->data_len == 0 || pack->data == NULL) |
| 1980 | { |
| 1981 | mbtk_net_info_t info; |
| 1982 | memset(&info, 0, sizeof(mbtk_net_info_t)); |
| 1983 | if(req_net_sel_mode_get(&info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 1984 | { |
| 1985 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 1986 | err = MBTK_RIL_ERR_CME + cme_err; |
| 1987 | } else { |
| 1988 | err = MBTK_RIL_ERR_UNKNOWN; |
| 1989 | } |
| 1990 | LOGD("Get Net sel mode fail."); |
| 1991 | } |
| 1992 | else |
| 1993 | { |
| 1994 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &info, sizeof(mbtk_net_info_t)); |
| 1995 | } |
| 1996 | } |
| 1997 | else // Set |
| 1998 | { |
| 1999 | mbtk_net_info_t *info = (mbtk_net_info_t*)pack->data; |
| 2000 | if(req_net_sel_mode_set(info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2001 | { |
| 2002 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2003 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2004 | } else { |
| 2005 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2006 | } |
| 2007 | LOGD("Set Net sel mode fail."); |
| 2008 | } |
| 2009 | else |
| 2010 | { |
| 2011 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 2012 | } |
| 2013 | } |
| 2014 | break; |
| 2015 | } |
| 2016 | case RIL_MSG_ID_NET_BAND: |
| 2017 | { |
| 2018 | if(pack->data_len == 0 || pack->data == NULL) |
| 2019 | { |
| 2020 | err = MBTK_RIL_ERR_REQ_PARAMETER; |
| 2021 | LOG("No data found."); |
| 2022 | } |
| 2023 | else // Set |
| 2024 | { |
| 2025 | if(pack->data_len == sizeof(uint8)) { |
| 2026 | if(*(pack->data)) { // Get current bands. |
| 2027 | mbtk_band_info_t band; |
| 2028 | memset(&band, 0x0, sizeof(mbtk_band_info_t)); |
| 2029 | if(req_band_get(&band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2030 | { |
| 2031 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2032 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2033 | } else { |
| 2034 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2035 | } |
| 2036 | LOG("Get net band fail."); |
| 2037 | } |
| 2038 | else |
| 2039 | { |
| 2040 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &band, sizeof(mbtk_band_info_t)); |
| 2041 | } |
| 2042 | } else { // Get support bands. |
| 2043 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &band_info.band_support , sizeof(mbtk_band_info_t)); |
| 2044 | } |
| 2045 | } else { // Set current bands. |
| 2046 | mbtk_band_info_t* band = (mbtk_band_info_t*)pack->data; |
| 2047 | if(pack->data_len != sizeof(mbtk_band_info_t)) |
| 2048 | { |
| 2049 | err = MBTK_RIL_ERR_REQ_PARAMETER; |
| 2050 | LOG("Set net band error."); |
| 2051 | break; |
| 2052 | } |
| 2053 | |
| 2054 | if(req_band_set(band, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2055 | { |
| 2056 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2057 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2058 | } else { |
| 2059 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2060 | } |
| 2061 | LOG("Set net band fail."); |
| 2062 | } |
| 2063 | else |
| 2064 | { |
| 2065 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 2066 | } |
| 2067 | } |
| 2068 | } |
| 2069 | break; |
| 2070 | } |
| 2071 | case RIL_MSG_ID_NET_SIGNAL: |
| 2072 | { |
| 2073 | if(pack->data_len == 0 || pack->data == NULL) |
| 2074 | { |
| 2075 | mbtk_signal_info_t signal; |
| 2076 | memset(&signal, 0, sizeof(mbtk_signal_info_t)); |
| 2077 | if(req_net_signal_get(&signal, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2078 | { |
| 2079 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2080 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2081 | } else { |
| 2082 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2083 | } |
| 2084 | LOGD("Get net signal fail."); |
| 2085 | } |
| 2086 | else |
| 2087 | { |
| 2088 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &signal, sizeof(mbtk_signal_info_t)); |
| 2089 | } |
| 2090 | } |
| 2091 | else // Set |
| 2092 | { |
| 2093 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 2094 | LOGW("Unsupport set net signal."); |
| 2095 | } |
| 2096 | break; |
| 2097 | } |
| 2098 | case RIL_MSG_ID_NET_REG: |
| 2099 | { |
| 2100 | if(pack->data_len == 0 || pack->data == NULL) |
| 2101 | { |
| 2102 | mbtk_net_reg_info_t net_reg; |
| 2103 | memset(&net_reg, 0, sizeof(mbtk_net_reg_info_t)); |
| 2104 | if(req_net_reg_get(&net_reg, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2105 | { |
| 2106 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2107 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2108 | } else { |
| 2109 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2110 | } |
| 2111 | LOGD("Get Net reg info fail."); |
| 2112 | } |
| 2113 | else |
| 2114 | { |
| 2115 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &net_reg, sizeof(mbtk_net_reg_info_t)); |
| 2116 | } |
| 2117 | } |
| 2118 | else // Set |
| 2119 | { |
| 2120 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 2121 | LOGW("Unsupport set net reg info."); |
| 2122 | } |
| 2123 | break; |
| 2124 | } |
| 2125 | case RIL_MSG_ID_NET_CELL: |
| 2126 | { |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 2127 | if(pack->data_len == 0 || pack->data == NULL) // Get net cell. |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2128 | { |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 2129 | if(req_cell_info_get(&cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2130 | { |
| 2131 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2132 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2133 | } else { |
| 2134 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2135 | } |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 2136 | LOG("Get net cell fail."); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2137 | } |
| 2138 | else |
| 2139 | { |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 2140 | LOG("req_cell_info_get() success,cell number: %d", cell_info.cell_list.num); |
| 2141 | ril_rsp_pack_send(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] | 2142 | } |
| 2143 | } |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 2144 | else // Lock cell |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2145 | { |
b.liu | b477207 | 2024-08-15 14:47:03 +0800 | [diff] [blame] | 2146 | char *mem = (char*)(pack->data); |
| 2147 | int len = pack->data_len; |
| 2148 | char reg[100] = {0}; |
| 2149 | if(req_cell_info_set(mem, reg, len, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2150 | { |
| 2151 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2152 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2153 | } else { |
| 2154 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2155 | } |
| 2156 | } |
| 2157 | else |
| 2158 | { |
| 2159 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, reg, strlen(reg)); |
| 2160 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2161 | } |
| 2162 | break; |
| 2163 | } |
| 2164 | case RIL_MSG_ID_NET_APN: |
| 2165 | { |
| 2166 | if(pack->data_len == 0 || pack->data == NULL) |
| 2167 | { |
| 2168 | mbtk_apn_info_array_t apns; |
| 2169 | memset(&apns, 0, sizeof(mbtk_apn_info_array_t)); |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 2170 | if(req_apn_get(FALSE, &apns, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2171 | { |
| 2172 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2173 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2174 | } else { |
| 2175 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2176 | } |
| 2177 | LOGD("Get APN fail."); |
| 2178 | } |
| 2179 | else |
| 2180 | { |
| 2181 | LOGD("size - %d", sizeof(mbtk_apn_info_array_t)); |
| 2182 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &apns, sizeof(mbtk_apn_info_array_t)); |
| 2183 | } |
| 2184 | } |
| 2185 | else // Set |
| 2186 | { |
| 2187 | mbtk_apn_info_t *apn = (mbtk_apn_info_t*)pack->data; |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 2188 | if(apn_check_and_cid_reset(apn)) { |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2189 | err = MBTK_RIL_ERR_CID; |
| 2190 | } else { |
| 2191 | if(apn_conf_support(apn->cid)) { |
| 2192 | if(req_apn_set(apn, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2193 | { |
| 2194 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2195 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2196 | } else { |
| 2197 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2198 | } |
| 2199 | LOGD("Set APN fail."); |
| 2200 | } |
| 2201 | else |
| 2202 | { |
| 2203 | if(apn_prop_set(apn)) { |
| 2204 | LOGE("Save APN fail."); |
| 2205 | } |
| 2206 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 2207 | } |
| 2208 | } else { |
| 2209 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 2210 | LOGD("Can not set APN for CID : %d", apn->cid); |
| 2211 | } |
| 2212 | } |
| 2213 | } |
| 2214 | break; |
| 2215 | } |
| 2216 | case RIL_MSG_ID_NET_DATA_CALL: |
| 2217 | { |
| 2218 | if(pack->data_len == 0 || pack->data == NULL) |
| 2219 | { |
| 2220 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 2221 | } |
| 2222 | else // Set |
| 2223 | { |
| 2224 | mbtk_data_call_info_t *call_info = (mbtk_data_call_info_t*)pack->data; |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 2225 | if(!apn_conf_support(call_info->cid)) { |
| 2226 | err = MBTK_RIL_ERR_UNSUPPORTED; |
| 2227 | LOGD("Can not data call for CID : %d", call_info->cid); |
| 2228 | } else { |
| 2229 | if(call_info->type == MBTK_DATA_CALL_START) { |
| 2230 | mbtk_ip_info_t ip_info; |
| 2231 | memset(&ip_info, 0, sizeof(ip_info)); |
| 2232 | #if 0 |
| 2233 | if(apn_prop_reset(call_info)) { |
| 2234 | err = MBTK_RIL_ERR_REQ_UNKNOWN; |
| 2235 | LOG("apn_prop_reset() fail."); |
| 2236 | } else |
| 2237 | #else |
| 2238 | if(apn_prop_reset(call_info)) { |
| 2239 | LOG("apn_prop_reset() fail."); |
| 2240 | } |
| 2241 | #endif |
| 2242 | { |
| 2243 | if(req_data_call_start(call_info->cid, call_info->def_route, call_info->as_dns, |
| 2244 | call_info->retry_interval, call_info->timeout, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2245 | { |
| 2246 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2247 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2248 | } else { |
| 2249 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2250 | } |
| 2251 | LOGD("Start data call fail."); |
| 2252 | } |
| 2253 | else |
| 2254 | { |
| 2255 | // Wait for "CONNECT" or "+CGEV:" |
| 2256 | if(wait_cgact_complete(call_info->timeout)) { // Timeout |
| 2257 | err = MBTK_RIL_ERR_TIMEOUT; |
| 2258 | break; |
| 2259 | } |
| 2260 | |
| 2261 | // Get Ip informations. |
| 2262 | cme_err = MBTK_RIL_ERR_CME_NON; |
| 2263 | if(req_data_call_state_get(call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2264 | { |
| 2265 | LOGD("Get net informations fail."); |
| 2266 | err = MBTK_RIL_ERR_NET_CONF; |
| 2267 | } |
| 2268 | else |
| 2269 | { |
| 2270 | // Config network informations. |
| 2271 | if(net_ifc_reconfig(call_info->cid, call_info->def_route, call_info->as_dns, &ip_info)) { |
| 2272 | err = MBTK_RIL_ERR_NET_CONF; |
| 2273 | break; |
| 2274 | } |
| 2275 | |
| 2276 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t)); |
| 2277 | } |
| 2278 | } |
| 2279 | } |
| 2280 | } else if(call_info->type == MBTK_DATA_CALL_STOP) { |
| 2281 | if(req_data_call_stop(call_info->cid, call_info->timeout, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2282 | { |
| 2283 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2284 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2285 | } else { |
| 2286 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2287 | } |
b.liu | bcf86c9 | 2024-08-19 19:48:28 +0800 | [diff] [blame^] | 2288 | LOGD("Stop data call fail."); |
| 2289 | } |
| 2290 | else |
| 2291 | { |
| 2292 | // Wait for "CONNECT" or "+CGEV:" |
| 2293 | if(wait_cgact_complete(call_info->timeout)) { // Timeout |
| 2294 | err = MBTK_RIL_ERR_TIMEOUT; |
| 2295 | break; |
| 2296 | } |
| 2297 | |
| 2298 | // Clean network config. |
| 2299 | if(net_ifc_config(call_info->cid, FALSE, FALSE, NULL)) { |
| 2300 | err = MBTK_RIL_ERR_NET_CONF; |
| 2301 | break; |
| 2302 | } |
| 2303 | |
| 2304 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, NULL, 0); |
| 2305 | } |
| 2306 | } else { |
| 2307 | mbtk_ip_info_t ip_info; |
| 2308 | memset(&ip_info, 0, sizeof(ip_info)); |
| 2309 | if(req_data_call_state_get(call_info->cid ,&ip_info, &cme_err) || cme_err != MBTK_RIL_ERR_CME_NON) |
| 2310 | { |
| 2311 | if(cme_err != MBTK_RIL_ERR_CME_NON) { |
| 2312 | err = MBTK_RIL_ERR_CME + cme_err; |
| 2313 | } else { |
| 2314 | err = MBTK_RIL_ERR_UNKNOWN; |
| 2315 | } |
| 2316 | LOGD("Get data call state fail."); |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2317 | } |
| 2318 | else |
| 2319 | { |
| 2320 | ril_rsp_pack_send(cli_info->fd, pack->msg_id, pack->msg_index, &ip_info, sizeof(mbtk_ip_info_t)); |
| 2321 | } |
| 2322 | } |
b.liu | 87afc4c | 2024-08-14 17:33:45 +0800 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | break; |
| 2326 | } |
| 2327 | default: |
| 2328 | { |
| 2329 | err = MBTK_RIL_ERR_REQ_UNKNOWN; |
| 2330 | LOG("Unknown request : %s", id2str(pack->msg_id)); |
| 2331 | break; |
| 2332 | } |
| 2333 | } |
| 2334 | |
| 2335 | return err; |
| 2336 | } |
| 2337 | |