b.liu | 68a94c9 | 2025-05-24 12:53:41 +0800 | [diff] [blame^] | 1 | #include "lynq-qser-data.h" |
| 2 | #include "mbtk_type.h" |
| 3 | #include "mbtk_info_api.h" |
| 4 | |
| 5 | #include <pthread.h> |
| 6 | #include <cutils/properties.h> |
| 7 | #include <string.h> |
| 8 | #include <unistd.h> |
| 9 | #include <sys/types.h> |
| 10 | #include <sys/stat.h> |
| 11 | #include <fcntl.h> |
| 12 | //#include <sys/scoket.h> |
| 13 | #include <netinet/in.h> |
| 14 | #include <arpa/inet.h> |
| 15 | |
| 16 | /****************************DEFINE***************************************/ |
| 17 | #define QSER_RESULT_SUCCESS 0 |
| 18 | #define QSER_RESULT_FAIL -1 |
| 19 | |
| 20 | #define MBTK_INFO_ERR_CID_EXIST 311 |
| 21 | #define MBTK_INFO_ERR_CID_NO_EXIST 312 |
| 22 | #define MBTK_INFO_ERR_NO_APN 500 |
| 23 | |
| 24 | #define QSER_APN_NUM 8 |
| 25 | |
| 26 | #define QSER_APN_NAME_MAX_LEN 64 |
| 27 | #define QSER_APN_USER_MAX_LEN 32 |
| 28 | #define QSER_APN_PAWD_MAX_LEN 32 |
| 29 | #define QSER_APN_TYPE_MAX_LEN 16 |
| 30 | |
| 31 | //default range: 0 - 7 |
| 32 | //AT+CGACT range: 1 - 8 |
| 33 | //1 default IDX, 8 IMS IDX |
| 34 | #define QSER_PROFILE_IDX_MIN 1 |
| 35 | #define QSER_PROFILE_IDX_MAX 6 |
| 36 | |
| 37 | /****************************DEFINE***************************************/ |
| 38 | |
| 39 | /****************************VARIABLE***************************************/ |
| 40 | mbtk_info_handle_t* qser_info_handle = NULL; |
| 41 | int qser_info_handle_num = 0; |
| 42 | static bool inited = FALSE; |
| 43 | static qser_data_call_evt_cb_t qser_net_status_cb = NULL; |
| 44 | /****************************VARIABLE***************************************/ |
| 45 | |
| 46 | /******************************FUNC*****************************************/ |
| 47 | static int qser_apn_info_param_convert(int profile_idx, qser_apn_info_s *new_apn, mbtk_qser_apn_info_s *old_apn) |
| 48 | { |
| 49 | if(new_apn == NULL || old_apn == NULL) |
| 50 | { |
| 51 | LOGE("[qser_data] qser_apn_info_param_convert apn param is NULL."); |
| 52 | return QSER_RESULT_FAIL; |
| 53 | } |
| 54 | |
| 55 | memset(new_apn, 0x0, sizeof(qser_apn_info_s)); |
| 56 | new_apn->profile_idx = old_apn->cid - 1; |
| 57 | //get ip type |
| 58 | if(old_apn->ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6 |
| 59 | { |
| 60 | new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4V6; |
| 61 | } |
| 62 | else if(old_apn->ip_type == MBTK_IP_TYPE_IP) // IPV4 |
| 63 | { |
| 64 | new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV4; |
| 65 | } |
| 66 | else if(old_apn->ip_type == MBTK_IP_TYPE_IPV6) // IPV6 |
| 67 | { |
| 68 | new_apn->pdp_type = QSER_APN_PDP_TYPE_IPV6; |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | new_apn->pdp_type = QSER_APN_PDP_TYPE_PPP; |
| 73 | } |
| 74 | |
| 75 | //get apn name |
| 76 | if(strlen((char *)old_apn->apn_name) > QSER_APN_NAME_SIZE) |
| 77 | { |
| 78 | LOGE("[qser_data] apn_nmea length verylong."); |
| 79 | return QSER_RESULT_FAIL; |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | if(strlen((char *)old_apn->apn_name) > 0) |
| 84 | { |
| 85 | memcpy(new_apn->apn_name, old_apn->apn_name,strlen((char *)old_apn->apn_name)); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | //get apn user |
| 90 | if(strlen((char *)old_apn->user_name) > QSER_APN_USERNAME_SIZE) |
| 91 | { |
| 92 | LOGE("[qser_data] apn_user length verylong."); |
| 93 | return QSER_RESULT_FAIL; |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | if(strlen((char *)old_apn->user_name) > 0) |
| 98 | { |
| 99 | memcpy(new_apn->username, old_apn->user_name, strlen((char *)old_apn->user_name)); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | //get apn password |
| 104 | if(strlen((char *)old_apn->user_pass) > QSER_APN_PASSWORD_SIZE) |
| 105 | { |
| 106 | LOGE("[qser_data] apn_password length verylong."); |
| 107 | return QSER_RESULT_FAIL; |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | if(strlen((char *)old_apn->user_pass) > 0) |
| 112 | { |
| 113 | memcpy(new_apn->password, old_apn->user_pass, strlen((char *)old_apn->user_pass)); |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | //get apn proto |
| 118 | new_apn->auth_proto = (qser_apn_auth_proto_e)old_apn->auth_proto; |
| 119 | |
| 120 | //get apn type |
| 121 | if(strlen((char *)old_apn->apn_type) > QSER_APN_PASSWORD_SIZE) |
| 122 | { |
| 123 | LOGE("[qser_data] apn_type length verylong."); |
| 124 | return QSER_RESULT_FAIL; |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | if(strlen((char *)old_apn->apn_type) > 0) |
| 129 | { |
| 130 | memcpy(new_apn->apn_type, old_apn->apn_type, strlen((char *)old_apn->apn_type)); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | return QSER_RESULT_SUCCESS; |
| 135 | } |
| 136 | |
| 137 | static void qser_state_init(qser_data_call_state_s *state) |
| 138 | { |
| 139 | if(state != NULL) |
| 140 | { |
| 141 | state->profile_idx = 0; |
| 142 | memset(state->name, 0x0, 16); |
| 143 | state->ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 144 | state->state = QSER_DATA_CALL_DISCONNECTED; |
| 145 | state->err = QSER_DATA_CALL_ERROR_NONE; |
| 146 | inet_aton("0.0.0.0", &(state->v4.ip)); |
| 147 | inet_aton("0.0.0.0", &(state->v4.gateway)); |
| 148 | inet_aton("0.0.0.0", &(state->v4.pri_dns)); |
| 149 | inet_aton("0.0.0.0", &(state->v4.sec_dns)); |
| 150 | inet_pton(AF_INET6, "::", &(state->v6.ip)); |
| 151 | inet_pton(AF_INET6, "::", &(state->v6.gateway)); |
| 152 | inet_pton(AF_INET6, "::", &(state->v6.pri_dns)); |
| 153 | inet_pton(AF_INET6, "::", &(state->v6.sec_dns)); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | void qser_wan_net_state_change_cb(const void* data, int data_len) |
| 158 | { |
| 159 | if(data == NULL || data_len == 0) |
| 160 | { |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | uint8 *net_data = NULL; |
| 165 | net_data = (uint8 *)data; |
| 166 | |
| 167 | if(*net_data > 100 && *net_data < 200) |
| 168 | { |
| 169 | int idx = *net_data - 101; |
| 170 | if(idx <= QSER_PROFILE_IDX_MAX) |
| 171 | { |
| 172 | qser_data_call_state_s state = {0}; |
| 173 | qser_state_init(&state); |
| 174 | state.profile_idx = idx; |
| 175 | state.state = QSER_DATA_CALL_DISCONNECTED; |
| 176 | if(qser_net_status_cb != NULL) |
| 177 | { |
| 178 | qser_net_status_cb(&state); |
| 179 | } |
| 180 | } |
| 181 | else |
| 182 | { |
| 183 | LOGE("[qser_data] cb fail,idx is %d.", idx); |
| 184 | } |
| 185 | |
| 186 | } |
| 187 | else if(*net_data > 200 && *net_data < 220) |
| 188 | { |
| 189 | LOGE("[qser_data] cid[%d] is open.", *net_data - 201); |
| 190 | } |
| 191 | else if(*net_data > 220) |
| 192 | { |
| 193 | LOGE("[qser_data] cid[%d] is reopen.", *net_data - 221); |
| 194 | int idx = *net_data - 221; |
| 195 | if(idx <= QSER_PROFILE_IDX_MAX) |
| 196 | { |
| 197 | qser_data_call_state_s state = {0}; |
| 198 | qser_state_init(&state); |
| 199 | state.profile_idx = idx; |
| 200 | state.state = QSER_DATA_CALL_CONNECTED; |
| 201 | snprintf(state.name, 16, "ccinet%d", idx); |
| 202 | if(qser_net_status_cb != NULL) |
| 203 | { |
| 204 | qser_net_status_cb(&state); |
| 205 | } |
| 206 | } |
| 207 | } |
| 208 | else if(*net_data == 1) |
| 209 | { |
| 210 | LOGE("[qser_data] pdp is open."); |
| 211 | } |
| 212 | else |
| 213 | { |
| 214 | LOGE("[qser_data] unkonwn param [%d].", *net_data); |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | static void* data_call_async_thread(void* arg) |
| 219 | { |
| 220 | LOGE("[qser_data] entry data_call_async_thread."); |
| 221 | qser_data_call_error_e err = QSER_DATA_CALL_ERROR_NONE; |
| 222 | |
| 223 | qser_data_call_s qser_data_backup = {0}; |
| 224 | qser_data_call_info_s info = {0}; |
| 225 | if(arg != NULL) |
| 226 | { |
| 227 | memcpy(&qser_data_backup, (qser_data_call_s *)arg, sizeof(qser_data_call_s)); |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | LOGE("[qser_data] arg is NULL."); |
| 232 | } |
| 233 | |
| 234 | qser_data_call_state_s state = {0}; |
| 235 | qser_state_init(&state); |
| 236 | state.profile_idx = qser_data_backup.profile_idx; |
| 237 | snprintf(state.name, 16, "ccinet%d", qser_data_backup.profile_idx); |
| 238 | state.ip_family = qser_data_backup.ip_family; |
| 239 | |
| 240 | int ret = qser_data_call_start(&qser_data_backup, &err); |
| 241 | if(ret != QSER_RESULT_SUCCESS) |
| 242 | { |
| 243 | LOGE("[qser_data] qser_data_call_start() fail."); |
| 244 | state.err = err; |
| 245 | } |
| 246 | else |
| 247 | { |
| 248 | state.state = QSER_DATA_CALL_CONNECTED; |
| 249 | ret = qser_data_call_info_get(qser_data_backup.profile_idx, qser_data_backup.ip_family, &info, &err); |
| 250 | if(ret != QSER_RESULT_SUCCESS) |
| 251 | { |
| 252 | LOGE("[qser_data] qser_data_call_info_get() fail."); |
| 253 | state.err = err; |
| 254 | } |
| 255 | else |
| 256 | { |
| 257 | memcpy(&(state.v4), &(info.v4.addr), sizeof(struct v4_address_status)); |
| 258 | memcpy(&(state.v6), &(info.v6.addr), sizeof(struct v6_address_status)); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | if(qser_net_status_cb != NULL) |
| 263 | { |
| 264 | qser_net_status_cb(&state); |
| 265 | } |
| 266 | return NULL; |
| 267 | } |
| 268 | |
| 269 | /******************************FUNC*****************************************/ |
| 270 | |
| 271 | /****************************API***************************************/ |
| 272 | int qser_data_call_init(qser_data_call_evt_cb_t evt_cb) |
| 273 | { |
| 274 | //UNUSED(evt_cb); |
| 275 | if(!inited && qser_info_handle == NULL) |
| 276 | { |
| 277 | qser_info_handle = mbtk_info_handle_get(); |
| 278 | if(qser_info_handle) |
| 279 | { |
| 280 | qser_info_handle_num++; |
| 281 | inited = TRUE; |
| 282 | mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb); |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | LOGE("[qser_data] mbtk_info_handle_get() fail."); |
| 287 | return QSER_RESULT_FAIL; |
| 288 | } |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | if(!inited) |
| 293 | { |
| 294 | qser_info_handle_num++; |
| 295 | inited = TRUE; |
| 296 | mbtk_pdp_state_change_cb_reg(qser_info_handle, qser_wan_net_state_change_cb); |
| 297 | } |
| 298 | } |
| 299 | qser_net_status_cb = evt_cb; |
| 300 | |
| 301 | LOGE("[qser_data] mbtk_info_handle_get() success."); |
| 302 | return QSER_RESULT_SUCCESS; |
| 303 | } |
| 304 | |
| 305 | void qser_data_call_destroy(void) |
| 306 | { |
| 307 | if(qser_info_handle) |
| 308 | { |
| 309 | LOGE("[qser_data] qser_info_handle_num = %d", qser_info_handle_num); |
| 310 | if(qser_info_handle_num == 1) |
| 311 | { // 最后一个引用,可释放。 |
| 312 | int ret = mbtk_info_handle_free(&qser_info_handle); |
| 313 | if(ret) |
| 314 | { |
| 315 | LOGE("[qser_data] mbtk_info_handle_free() fail."); |
| 316 | } |
| 317 | else |
| 318 | { |
| 319 | qser_info_handle_num = 0; |
| 320 | qser_info_handle = NULL; |
| 321 | qser_net_status_cb = NULL; |
| 322 | inited = FALSE; |
| 323 | } |
| 324 | } |
| 325 | else |
| 326 | { |
| 327 | qser_info_handle_num--; |
| 328 | qser_net_status_cb = NULL; |
| 329 | } |
| 330 | } |
| 331 | else |
| 332 | { |
| 333 | LOGE("[qser_data] handle not inited."); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 338 | { |
| 339 | //UNUSED(data_call); |
| 340 | //UNUSED(err); |
| 341 | if(data_call == NULL || err == NULL) |
| 342 | { |
| 343 | LOGE("[qser_data] data_call or err is NULL."); |
| 344 | if(err != NULL) |
| 345 | { |
| 346 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 347 | } |
| 348 | return QSER_RESULT_FAIL; |
| 349 | } |
| 350 | |
| 351 | if(qser_info_handle == NULL) |
| 352 | { |
| 353 | LOGE("[qser_data] handle is NULL."); |
| 354 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 355 | return QSER_RESULT_FAIL; |
| 356 | } |
| 357 | |
| 358 | int ret = -1; |
| 359 | ret = mbtk_data_call_start(qser_info_handle, data_call->profile_idx + 1, 0, FALSE, 0); |
| 360 | if(ret != 0) |
| 361 | { |
| 362 | LOGE("[qser_data] mbtk_data_call_start fail.[ret = %d]", ret); |
| 363 | if(ret == MBTK_INFO_ERR_CID_EXIST) |
| 364 | { |
| 365 | *err = QSER_DATA_CALL_ERROR_PDP_ACTIVATE; |
| 366 | } |
| 367 | else |
| 368 | { |
| 369 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
| 370 | } |
| 371 | return QSER_RESULT_FAIL; |
| 372 | } |
| 373 | else |
| 374 | { |
| 375 | *err = QSER_DATA_CALL_ERROR_NONE; |
| 376 | } |
| 377 | |
| 378 | return QSER_RESULT_SUCCESS; |
| 379 | } |
| 380 | |
| 381 | int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 382 | { |
| 383 | //UNUSED(data_call); |
| 384 | UNUSED(err); |
| 385 | if(data_call == NULL || err == NULL) |
| 386 | { |
| 387 | LOGE("[qser_data] data_call or err is NULL."); |
| 388 | if(err != NULL) |
| 389 | { |
| 390 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 391 | } |
| 392 | return QSER_RESULT_FAIL; |
| 393 | } |
| 394 | |
| 395 | if(qser_info_handle == NULL) |
| 396 | { |
| 397 | LOGE("[qser_data] handle is NULL."); |
| 398 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 399 | return QSER_RESULT_FAIL; |
| 400 | } |
| 401 | |
| 402 | pthread_attr_t thread_attr; |
| 403 | pthread_t data_call_thread_id; |
| 404 | pthread_attr_init(&thread_attr); |
| 405 | if(pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED)) |
| 406 | { |
| 407 | LOGE("[qser_data] pthread_attr_setdetachstate() fail."); |
| 408 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
| 409 | return QSER_RESULT_FAIL; |
| 410 | } |
| 411 | |
| 412 | //memcpy(&qser_data_backup, data_call, sizeof(qser_data_call_s)); |
| 413 | if(pthread_create(&data_call_thread_id, &thread_attr, data_call_async_thread, (void *) data_call)) |
| 414 | { |
| 415 | LOGE("[qser_data] pthread_create() fail."); |
| 416 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
| 417 | return QSER_RESULT_FAIL; |
| 418 | } |
| 419 | pthread_attr_destroy(&thread_attr); |
| 420 | |
| 421 | return QSER_RESULT_SUCCESS; |
| 422 | } |
| 423 | |
| 424 | int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err) |
| 425 | { |
| 426 | //UNUSED(profile_idx); |
| 427 | UNUSED(ip_family); |
| 428 | //UNUSED(err); |
| 429 | if(err == NULL) |
| 430 | { |
| 431 | LOGE("[qser_data] err is NULL."); |
| 432 | return QSER_RESULT_FAIL; |
| 433 | } |
| 434 | |
| 435 | if(qser_info_handle == NULL) |
| 436 | { |
| 437 | LOGE("[qser_data] handle is NULL."); |
| 438 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 439 | return QSER_RESULT_FAIL; |
| 440 | } |
| 441 | |
| 442 | int ret = -1; |
| 443 | ret = mbtk_data_call_stop(qser_info_handle, profile_idx + 1, 15); |
| 444 | if(ret != 0) |
| 445 | { |
| 446 | LOGE("[qser_data] mbtk_data_call_stop fail.[ret = %d]", ret); |
| 447 | if(ret == MBTK_INFO_ERR_CID_NO_EXIST) |
| 448 | { |
| 449 | *err = QSER_DATA_CALL_ERROR_PDP_NO_ACTIVATE; |
| 450 | } |
| 451 | else |
| 452 | { |
| 453 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
| 454 | } |
| 455 | return QSER_RESULT_FAIL; |
| 456 | } |
| 457 | else |
| 458 | { |
| 459 | *err = QSER_DATA_CALL_ERROR_NONE; |
| 460 | } |
| 461 | |
| 462 | return QSER_RESULT_SUCCESS; |
| 463 | } |
| 464 | |
| 465 | int qser_data_call_info_get(char profile_idx,qser_data_call_ip_family_e ip_family, |
| 466 | qser_data_call_info_s *info, qser_data_call_error_e *err) |
| 467 | { |
| 468 | //UNUSED(profile_idx); |
| 469 | UNUSED(ip_family); |
| 470 | //UNUSED(info); |
| 471 | //UNUSED(err); |
| 472 | |
| 473 | if(info == NULL || err == NULL) |
| 474 | { |
| 475 | LOGE("[qser_data] info or err is NULL."); |
| 476 | if(err != NULL) |
| 477 | { |
| 478 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 479 | } |
| 480 | return QSER_RESULT_FAIL; |
| 481 | } |
| 482 | |
| 483 | if(qser_info_handle == NULL) |
| 484 | { |
| 485 | LOGE("[qser_data] handle is NULL."); |
| 486 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 487 | return QSER_RESULT_FAIL; |
| 488 | } |
| 489 | |
| 490 | int ret = -1; |
| 491 | mbtk_ipv4_info_t ipv4; |
| 492 | mbtk_ipv6_info_t ipv6; |
| 493 | #ifdef QSER_TEST |
| 494 | char v4_buff[32] = {0}; |
| 495 | char v6_buff[128] = {0}; |
| 496 | #endif |
| 497 | memset(info, 0, sizeof(qser_data_call_info_s)); |
| 498 | ret = mbtk_data_call_state_get(qser_info_handle, profile_idx + 1, &ipv4, &ipv6); |
| 499 | if(ret != 0) |
| 500 | { |
| 501 | LOGE("[qser_data] mbtk_data_call_state_get fail.[ret = %d]", ret); |
| 502 | if(ret == MBTK_INFO_ERR_CID_NO_EXIST) |
| 503 | { |
| 504 | *err = QSER_DATA_CALL_ERROR_PDP_NO_ACTIVATE; |
| 505 | } |
| 506 | else |
| 507 | { |
| 508 | *err = QSER_DATA_CALL_ERROR_UNKNOWN; |
| 509 | } |
| 510 | return QSER_RESULT_FAIL; |
| 511 | } |
| 512 | else |
| 513 | { |
| 514 | info->profile_idx = profile_idx; |
| 515 | if(ipv4.valid) |
| 516 | { |
| 517 | info->ip_family = QSER_DATA_CALL_TYPE_IPV4; |
| 518 | info->v4.state = QSER_DATA_CALL_CONNECTED; |
| 519 | sprintf(info->v4.name, "ccinet%d", profile_idx); |
| 520 | info->v4.addr.ip.s_addr = ipv4.IPAddr; |
| 521 | info->v4.addr.pri_dns.s_addr = ipv4.PrimaryDNS; |
| 522 | info->v4.addr.sec_dns.s_addr = ipv4.SecondaryDNS; |
| 523 | info->v4.reconnect = 1; |
| 524 | |
| 525 | #ifdef QSER_TEST |
| 526 | //LOGE("[qser_data] IP: %x pri_DNS: %x sec_DNS: %x.", ipv4.IPAddr, ipv4.PrimaryDNS, ipv4.SecondaryDNS); |
| 527 | if(inet_ntop(AF_INET, &(info->v4.addr.ip), v4_buff, 32) == NULL) { |
| 528 | LOGE("[qser_data] IP error."); |
| 529 | } else { |
| 530 | LOGE("[qser_data] IP : %s", v4_buff); |
| 531 | } |
| 532 | if(inet_ntop(AF_INET, &(info->v4.addr.pri_dns), v4_buff, 32) == NULL) { |
| 533 | LOGE("[qser_data] PrimaryDNS error."); |
| 534 | } else { |
| 535 | LOGE("[qser_data] PrimaryDNS : %s", v4_buff); |
| 536 | } |
| 537 | if(inet_ntop(AF_INET, &(info->v4.addr.sec_dns), v4_buff, 32) == NULL) { |
| 538 | LOGE("[qser_data] SecondaryDNS error."); |
| 539 | } else { |
| 540 | LOGE("[qser_data] SecondaryDNS : %s", v4_buff); |
| 541 | } |
| 542 | #endif |
| 543 | } |
| 544 | |
| 545 | if(ipv6.valid) |
| 546 | { |
| 547 | info->ip_family = QSER_DATA_CALL_TYPE_IPV6; |
| 548 | info->v6.state = QSER_DATA_CALL_CONNECTED; |
| 549 | sprintf(info->v6.name, "ccinet%d", profile_idx); |
| 550 | memcpy(&(info->v6.addr.ip), &(ipv6.IPV6Addr), sizeof(ipv6.IPV6Addr)); |
| 551 | memcpy(&(info->v6.addr.pri_dns), &(ipv6.PrimaryDNS), sizeof(ipv6.PrimaryDNS)); |
| 552 | memcpy(&(info->v6.addr.sec_dns), &(ipv6.SecondaryDNS), sizeof(ipv6.SecondaryDNS)); |
| 553 | info->v6.reconnect = 1; |
| 554 | |
| 555 | #ifdef QSER_TEST |
| 556 | if(ipv6_2_str(&(info->v6.addr.ip), v6_buff)) |
| 557 | { |
| 558 | LOGE("[qser_data] IP error."); |
| 559 | } else { |
| 560 | LOGE("[qser_data] IP : %s", v6_buff); |
| 561 | } |
| 562 | if(ipv6_2_str(&(info->v6.addr.pri_dns), v6_buff)) |
| 563 | { |
| 564 | LOGE("[qser_data] PrimaryDNS error."); |
| 565 | } else { |
| 566 | LOGE("[qser_data] PrimaryDNS : %s", v6_buff); |
| 567 | } |
| 568 | if(ipv6_2_str(&(info->v6.addr.sec_dns), v6_buff)) |
| 569 | { |
| 570 | LOGE("[qser_data] SecondaryDNS error."); |
| 571 | } else { |
| 572 | LOGE("[qser_data] SecondaryDNS : %s", v6_buff); |
| 573 | } |
| 574 | #endif |
| 575 | } |
| 576 | |
| 577 | if(ipv4.valid && ipv6.valid) |
| 578 | { |
| 579 | info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 580 | } |
| 581 | |
| 582 | if(!ipv4.valid && !ipv6.valid) |
| 583 | { |
| 584 | info->v4.state = QSER_DATA_CALL_DISCONNECTED; |
| 585 | info->v6.state = QSER_DATA_CALL_DISCONNECTED; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | *err = QSER_DATA_CALL_ERROR_NONE; |
| 590 | return QSER_RESULT_SUCCESS; |
| 591 | } |
| 592 | |
| 593 | int qser_apn_set(qser_apn_info_s *apn) |
| 594 | { |
| 595 | //UNUSED(apn); |
| 596 | if(qser_info_handle == NULL) |
| 597 | { |
| 598 | LOGE("[qser_data] handle is NULL."); |
| 599 | return QSER_RESULT_FAIL; |
| 600 | } |
| 601 | |
| 602 | if(apn == NULL) |
| 603 | { |
| 604 | LOGE("[qser_data] apn param is NULL."); |
| 605 | return QSER_RESULT_FAIL; |
| 606 | } |
| 607 | |
| 608 | if(strlen(apn->apn_name) > QSER_APN_NAME_MAX_LEN || strlen(apn->username) > QSER_APN_USER_MAX_LEN |
| 609 | || strlen(apn->password) > QSER_APN_PAWD_MAX_LEN || strlen(apn->apn_type) > QSER_APN_TYPE_MAX_LEN) |
| 610 | { |
| 611 | LOGE("[qser_data] apn length out of range."); |
| 612 | return QSER_RESULT_FAIL; |
| 613 | } |
| 614 | |
| 615 | int ret = 0; |
| 616 | mbtk_qser_apn_info_s apninfo; |
| 617 | memset(&apninfo, 0x0, sizeof(mbtk_qser_apn_info_s)); |
| 618 | apninfo.cid = apn->profile_idx + 1; |
| 619 | |
| 620 | if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4) |
| 621 | { |
| 622 | apninfo.ip_type = MBTK_IP_TYPE_IP; |
| 623 | } |
| 624 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV6) |
| 625 | { |
| 626 | apninfo.ip_type = MBTK_IP_TYPE_IPV6; |
| 627 | } |
| 628 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6) |
| 629 | { |
| 630 | apninfo.ip_type = MBTK_IP_TYPE_IPV4V6; |
| 631 | } |
| 632 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_PPP) |
| 633 | { |
| 634 | apninfo.ip_type = MBTK_IP_TYPE_PPP; |
| 635 | } |
| 636 | else |
| 637 | { |
| 638 | LOGE("[qser_data] pdp_type error."); |
| 639 | return QSER_RESULT_FAIL; |
| 640 | } |
| 641 | |
| 642 | |
| 643 | apninfo.req_type = MBTK_APN_REQ_TYPE_SET; |
| 644 | apninfo.auth_proto = (mbtk_apn_auth_proto_enum)apn->auth_proto; |
| 645 | if(strlen(apn->apn_name)) |
| 646 | { |
| 647 | memcpy(apninfo.apn_name, apn->apn_name, strlen(apn->apn_name)); |
| 648 | } |
| 649 | else |
| 650 | { |
| 651 | LOGE("[qser_data] apn_name is NULL."); |
| 652 | return QSER_RESULT_FAIL; |
| 653 | } |
| 654 | if(strlen(apn->username)) |
| 655 | { |
| 656 | memcpy(apninfo.user_name, apn->username, strlen(apn->username)); |
| 657 | } |
| 658 | if(strlen(apn->password)) |
| 659 | { |
| 660 | memcpy(apninfo.user_pass, apn->password, strlen(apn->password)); |
| 661 | } |
| 662 | if(strlen(apn->apn_type)) |
| 663 | { |
| 664 | memcpy(apninfo.apn_type, apn->apn_type, strlen(apn->apn_type)); |
| 665 | } |
| 666 | ret = mbtk_qser_apn_set(qser_info_handle, &apninfo, NULL); |
| 667 | if(ret != 0) |
| 668 | { |
| 669 | LOGE("[qser_data] mbtk_qser_apn_set fail."); |
| 670 | return QSER_RESULT_FAIL; |
| 671 | } |
| 672 | |
| 673 | return QSER_RESULT_SUCCESS; |
| 674 | } |
| 675 | |
| 676 | int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn) |
| 677 | { |
| 678 | //UNUSED(profile_idx); |
| 679 | //UNUSED(apn); |
| 680 | if(qser_info_handle == NULL) |
| 681 | { |
| 682 | LOGE("[qser_data] handle is NULL."); |
| 683 | return QSER_RESULT_FAIL; |
| 684 | } |
| 685 | |
| 686 | if(apn == NULL) |
| 687 | { |
| 688 | LOGE("[qser_data] apn param is NULL."); |
| 689 | return QSER_RESULT_FAIL; |
| 690 | } |
| 691 | |
| 692 | //get apn info |
| 693 | mbtk_qser_apn_info_s apns[10] = {0}; |
| 694 | int apn_num = 10; |
| 695 | int ret = mbtk_qser_apn_get(qser_info_handle, &apn_num, apns); |
| 696 | if(ret != 0) |
| 697 | { |
| 698 | LOGE("[qser_data] mbtk_apn_get fail. [ret = %d]",ret); |
| 699 | return QSER_RESULT_FAIL; |
| 700 | } |
| 701 | else |
| 702 | { |
| 703 | int i = 0; |
| 704 | for(i = 0; i < apn_num; i++) |
| 705 | { |
| 706 | if(apns[i].cid == profile_idx + 1) |
| 707 | { |
| 708 | LOGE("[qser_data] find IDX."); |
| 709 | break; |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | if(i == apn_num) |
| 714 | { |
| 715 | LOGE("[qser_data] not find IDX.[apn_num = %d]", apn_num); |
| 716 | return QSER_RESULT_FAIL; |
| 717 | } |
| 718 | |
| 719 | if(qser_apn_info_param_convert(profile_idx, apn, &apns[i]) != 0) |
| 720 | { |
| 721 | LOGE("[qser_data] qser_apn_info_param_convert fail"); |
| 722 | return QSER_RESULT_FAIL; |
| 723 | } |
| 724 | } |
| 725 | return QSER_RESULT_SUCCESS; |
| 726 | } |
| 727 | |
| 728 | int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx) |
| 729 | { |
| 730 | //UNUSED(apn); |
| 731 | //UNUSED(profile_idx); |
| 732 | if(qser_info_handle == NULL) |
| 733 | { |
| 734 | LOGE("[qser_data] handle is NULL."); |
| 735 | return QSER_RESULT_FAIL; |
| 736 | } |
| 737 | |
| 738 | if(apn == NULL || profile_idx == NULL) |
| 739 | { |
| 740 | LOGE("[qser_data] apn param is NULL."); |
| 741 | return QSER_RESULT_FAIL; |
| 742 | } |
| 743 | |
| 744 | if(strlen(apn->apn_name) > QSER_APN_NAME_MAX_LEN || strlen(apn->username) > QSER_APN_USER_MAX_LEN |
| 745 | || strlen(apn->password) > QSER_APN_PAWD_MAX_LEN || strlen(apn->apn_type) > QSER_APN_TYPE_MAX_LEN) |
| 746 | { |
| 747 | LOGE("[qser_data] apn length out of range."); |
| 748 | return QSER_RESULT_FAIL; |
| 749 | } |
| 750 | |
| 751 | int ret = 0; |
| 752 | unsigned char idx[2] = {0}; |
| 753 | mbtk_qser_apn_info_s apninfo; |
| 754 | memset(&apninfo, 0x0, sizeof(mbtk_qser_apn_info_s)); |
| 755 | apninfo.cid = 0; |
| 756 | |
| 757 | if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4) |
| 758 | { |
| 759 | apninfo.ip_type = MBTK_IP_TYPE_IP; |
| 760 | } |
| 761 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV6) |
| 762 | { |
| 763 | apninfo.ip_type = MBTK_IP_TYPE_IPV6; |
| 764 | } |
| 765 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_IPV4V6) |
| 766 | { |
| 767 | apninfo.ip_type = MBTK_IP_TYPE_IPV4V6; |
| 768 | } |
| 769 | else if(apn->pdp_type == QSER_APN_PDP_TYPE_PPP) |
| 770 | { |
| 771 | apninfo.ip_type = MBTK_IP_TYPE_PPP; |
| 772 | } |
| 773 | else |
| 774 | { |
| 775 | LOGE("[qser_data] pdp_type error."); |
| 776 | return QSER_RESULT_FAIL; |
| 777 | } |
| 778 | |
| 779 | apninfo.req_type = MBTK_APN_REQ_TYPE_ADD; |
| 780 | apninfo.auth_proto = (mbtk_apn_auth_proto_enum)apn->auth_proto; |
| 781 | if(strlen(apn->apn_name)) |
| 782 | { |
| 783 | memcpy(apninfo.apn_name, apn->apn_name, strlen(apn->apn_name)); |
| 784 | } |
| 785 | |
| 786 | if(strlen(apn->username)) |
| 787 | { |
| 788 | memcpy(apninfo.user_name, apn->username, strlen(apn->username)); |
| 789 | } |
| 790 | if(strlen(apn->password)) |
| 791 | { |
| 792 | memcpy(apninfo.user_pass, apn->password, strlen(apn->password)); |
| 793 | } |
| 794 | if(strlen(apn->apn_type)) |
| 795 | { |
| 796 | memcpy(apninfo.apn_type, apn->apn_type, strlen(apn->apn_type)); |
| 797 | } |
| 798 | ret = mbtk_qser_apn_set(qser_info_handle, &apninfo, idx); |
| 799 | if(ret != 0) |
| 800 | { |
| 801 | LOGE("[qser_data] mbtk_qser_apn_set fail."); |
| 802 | return QSER_RESULT_FAIL; |
| 803 | } |
| 804 | *profile_idx = idx[0] - 1; |
| 805 | return QSER_RESULT_SUCCESS; |
| 806 | } |
| 807 | |
| 808 | int qser_apn_del(unsigned char profile_idx) |
| 809 | { |
| 810 | int ret = 0; |
| 811 | qser_apn_info_s qser_apn = {0}; |
| 812 | |
| 813 | //UNUSED(profile_idx); |
| 814 | if(qser_info_handle == NULL) |
| 815 | { |
| 816 | LOGE("[qser_data] handle is NULL."); |
| 817 | return QSER_RESULT_FAIL; |
| 818 | } |
| 819 | |
| 820 | ret = qser_apn_get(profile_idx, &qser_apn); |
| 821 | if (ret < 0) |
| 822 | { |
| 823 | LOGE("[qser_data] mbtk_apn_del idx no find!"); |
| 824 | return QSER_RESULT_FAIL; |
| 825 | } |
| 826 | |
| 827 | ret = mbtk_apn_del(qser_info_handle, profile_idx); |
| 828 | if(ret < 0) |
| 829 | { |
| 830 | LOGE("[qser_data] mbtk_apn_del fail!"); |
| 831 | return QSER_RESULT_FAIL; |
| 832 | } |
| 833 | return QSER_RESULT_SUCCESS; |
| 834 | } |
| 835 | |
| 836 | int qser_apn_get_list(qser_apn_info_list_s *apn_list) |
| 837 | { |
| 838 | //UNUSED(apn_list); |
| 839 | |
| 840 | if(qser_info_handle == NULL) |
| 841 | { |
| 842 | LOGE("[qser_data] handle is NULL."); |
| 843 | return QSER_RESULT_FAIL; |
| 844 | } |
| 845 | |
| 846 | if(apn_list == NULL) |
| 847 | { |
| 848 | LOGE("[qser_data] apn_list param is NULL."); |
| 849 | return QSER_RESULT_FAIL; |
| 850 | } |
| 851 | |
| 852 | mbtk_qser_apn_info_s apns[10] = {0}; |
| 853 | int apn_num = 10; |
| 854 | int ret = mbtk_qser_apn_get(qser_info_handle, &apn_num, apns); |
| 855 | if(ret != 0) |
| 856 | { |
| 857 | if(ret == MBTK_INFO_ERR_NO_APN) |
| 858 | { |
| 859 | apn_list->cnt = 0; |
| 860 | return QSER_RESULT_SUCCESS; |
| 861 | } |
| 862 | LOGE("[qser_data] mbtk_apn_get fail. [ret = %d]",ret); |
| 863 | return QSER_RESULT_FAIL; |
| 864 | } |
| 865 | else |
| 866 | { |
| 867 | if(apn_num > 0 && apn_num <= QSER_APN_MAX_LIST) |
| 868 | { |
| 869 | int i = 0; |
| 870 | apn_list->cnt = 0; |
| 871 | for(i = 0; i < apn_num; i++) |
| 872 | { |
| 873 | if(qser_apn_info_param_convert(apns[i].cid - 1, &apn_list->apn[apn_list->cnt], &apns[i]) != 0) |
| 874 | { |
| 875 | LOGE("[qser_data] qser_apn_info_param_convert fail"); |
| 876 | return QSER_RESULT_FAIL; |
| 877 | } |
| 878 | apn_list->cnt++; |
| 879 | } |
| 880 | } |
| 881 | else if(apn_num > QSER_APN_MAX_LIST) |
| 882 | { |
| 883 | LOGE("[qser_data] apn_num overlong"); |
| 884 | return QSER_RESULT_FAIL; |
| 885 | } |
| 886 | else |
| 887 | { |
| 888 | apn_list->cnt = 0; |
| 889 | } |
| 890 | } |
| 891 | return QSER_RESULT_SUCCESS; |
| 892 | } |
| 893 | /****************************API***************************************/ |
| 894 | |