liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 1 | #include "ql/DSI_ConnectManager.h" |
| 2 | #include "mbtk_info_api.h" |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 3 | #include <fcntl.h> |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 4 | |
| 5 | extern mbtk_info_handle_t* ql_info_handle; |
| 6 | extern int ql_info_handle_num; |
| 7 | static bool inited = FALSE; |
| 8 | |
| 9 | typedef struct |
| 10 | { |
| 11 | bool active; |
| 12 | uint8 cid; |
| 13 | int ip_type; |
| 14 | char user[128]; |
| 15 | char pass[128]; |
| 16 | QL_DSI_AUTH_PREF_T auth; |
| 17 | } apn_info; |
| 18 | |
| 19 | // 2 - 7 |
| 20 | static apn_info ql_apn_info[9]={0}; |
| 21 | static int mbtk_interval_sec = 0; |
| 22 | static nw_status_cb ql_net_status_cb = NULL; |
| 23 | static ex_conn_status_cb ql_net_ex_status_cb = NULL; |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 24 | static int now_cid = 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 25 | |
| 26 | void ql_wan_net_state_change_cb(const void* data, int data_len) |
| 27 | { |
| 28 | uint8 *net_data = NULL; |
| 29 | net_data = (uint8 *)data; |
| 30 | |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 31 | if(*net_data > 100 && *net_data < 200) |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 32 | { |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 33 | int cid; |
| 34 | cid = *net_data; |
| 35 | cid = cid - 100; |
| 36 | ql_apn_info[cid].active = FALSE;//close |
| 37 | if(ql_net_ex_status_cb != NULL) |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 38 | { |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 39 | ql_net_ex_status_cb(cid, ql_apn_info[cid].ip_type, CONNECT_DISCON, 0); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 40 | } |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 41 | } |
| 42 | else if(*net_data > 200) |
| 43 | { |
| 44 | int cid; |
| 45 | cid = *net_data; |
| 46 | cid = cid - 200; |
| 47 | ql_apn_info[cid].active = TRUE;//open |
| 48 | } |
| 49 | else |
| 50 | { |
| 51 | if(ql_net_status_cb != NULL) |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 52 | { |
| 53 | ql_net_status_cb(*net_data); |
| 54 | |
| 55 | if(*net_data == 25 || *net_data == 26 || *net_data == 27) |
| 56 | { |
| 57 | ql_net_status_cb(CONNECT_CONSUCCESS); |
| 58 | } |
| 59 | } |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 60 | |
| 61 | if(ql_net_ex_status_cb != NULL) |
| 62 | { |
| 63 | if(*net_data == 1) |
| 64 | { |
| 65 | ql_net_ex_status_cb(now_cid, ql_apn_info[now_cid].ip_type, CONNECT_CONSUCCESS, 0); |
| 66 | } |
| 67 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 68 | } |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 69 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | int ql_wan_init(void) |
| 73 | { |
| 74 | if(!inited && ql_info_handle == NULL) |
| 75 | { |
| 76 | ql_info_handle = mbtk_info_handle_get(); |
| 77 | if(ql_info_handle) |
| 78 | { |
| 79 | ql_info_handle_num++; |
| 80 | inited = TRUE; |
| 81 | mbtk_pdp_state_change_cb_reg(ql_info_handle, ql_wan_net_state_change_cb); |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 82 | |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 83 | //return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 84 | } else { |
| 85 | LOGE("mbtk_info_handle_get() fail."); |
| 86 | return -1; |
| 87 | } |
| 88 | } else { |
| 89 | if(!inited) { |
| 90 | ql_info_handle_num++; |
| 91 | inited = TRUE; |
| 92 | mbtk_pdp_state_change_cb_reg(ql_info_handle, ql_wan_net_state_change_cb); |
| 93 | } |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 94 | //return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 95 | } |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 96 | |
| 97 | mbtk_apn_info_t apns[10] = {0}; |
| 98 | int apn_num = MBTK_APN_CID_MAX; |
| 99 | int ret = mbtk_apn_get(ql_info_handle, &apn_num, apns); |
| 100 | if(ret != 0) |
| 101 | { |
| 102 | LOGD("mbtk_apn_get ret = %d",ret); |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | int i; |
| 107 | int profile_idx; |
| 108 | for(i=0;i<MBTK_APN_CID_MAX;i++) |
| 109 | { |
| 110 | if(apns[i].cid > 0 && apns[i].cid <= MBTK_APN_CID_MAX) |
| 111 | { |
| 112 | profile_idx = apns[i].cid; |
| 113 | if(apns[i].ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6 |
| 114 | ql_apn_info[profile_idx].ip_type = 0; |
| 115 | else if(apns[i].ip_type == MBTK_IP_TYPE_IP) // IPV4 |
| 116 | ql_apn_info[profile_idx].ip_type = 1; |
| 117 | else if(apns[i].ip_type == MBTK_IP_TYPE_IPV6) // IPV6 |
| 118 | ql_apn_info[profile_idx].ip_type = 2; |
| 119 | else |
| 120 | ql_apn_info[profile_idx].ip_type = 0; |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | return 0; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | int ql_wan_release(void) |
| 128 | { |
| 129 | if(ql_info_handle) |
| 130 | { |
| 131 | LOGD("ql_info_handle_num = %d", ql_info_handle_num); |
| 132 | if(ql_info_handle_num == 1) { // 最后一个引用,可释放。 |
| 133 | int ret = mbtk_info_handle_free(&ql_info_handle); |
| 134 | if(ret) { |
| 135 | LOGE("mbtk_info_handle_free() fail."); |
| 136 | return -1; |
| 137 | } |
| 138 | else |
| 139 | { |
| 140 | ql_info_handle_num = 0; |
| 141 | ql_info_handle = NULL; |
| 142 | return 0; |
| 143 | } |
| 144 | } else { |
| 145 | ql_info_handle_num--; |
| 146 | return 0; |
| 147 | } |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | LOGE("DATA handle not inited."); |
| 152 | return -1; |
| 153 | } |
| 154 | } |
| 155 | /* |
| 156 | *Set data call over time. |
| 157 | */ |
| 158 | int ql_wan_set_autoconnect(int auto_status, int interval_sec) |
| 159 | { |
| 160 | if(auto_status == 0) //不开启失败重连 |
| 161 | mbtk_interval_sec = 0; |
| 162 | else //开启失败重连等待时间 |
| 163 | { |
| 164 | if(interval_sec <= 0) |
| 165 | mbtk_interval_sec = interval_sec; |
| 166 | else |
| 167 | mbtk_interval_sec = 5; // 默认为5s |
| 168 | } |
| 169 | return 0; |
| 170 | } |
| 171 | |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 172 | #ifdef MBTK_AF_SUPPORT |
| 173 | int mbtk_route_config(int profile_idx) |
| 174 | { |
| 175 | char buf[1024] = {0}; |
| 176 | char dns[128] = {0}; |
| 177 | int offset = 0; |
| 178 | int fd = -1; |
| 179 | mbtk_ipv4_info_t ipv4; |
| 180 | mbtk_ipv6_info_t ipv6; |
| 181 | sprintf(buf, "route add default dev ccinet%d", profile_idx -1); |
| 182 | system(buf); |
| 183 | |
| 184 | int ret = mbtk_data_call_state_get(ql_info_handle, profile_idx, &ipv4, &ipv6); |
| 185 | if(ret != 0) |
| 186 | return -1; |
| 187 | else |
| 188 | { |
| 189 | memset(buf, 0x0, 1024); |
| 190 | memset(dns, 0x0, 128); |
| 191 | offset = sprintf(buf, "search lan\n"); |
| 192 | if(ipv4.valid) |
| 193 | { |
| 194 | if(inet_ntop(AF_INET, &(ipv4.PrimaryDNS), dns, 32) == NULL) { |
| 195 | LOGD("PrimaryDNS error."); |
| 196 | } else { |
| 197 | LOGD("PrimaryDNS : %s", dns); |
| 198 | } |
| 199 | offset += sprintf(buf + offset, "nameserver %s\n", dns); |
| 200 | memset(dns, 0x0, 128); |
| 201 | if(inet_ntop(AF_INET, &(ipv4.SecondaryDNS), dns, 32) == NULL) { |
| 202 | LOGD("SecondaryDNS error."); |
| 203 | } else { |
| 204 | LOGD("SecondaryDNS : %s", dns); |
| 205 | } |
| 206 | offset += sprintf(buf + offset, "nameserver %s\n", dns); |
| 207 | } |
| 208 | if(ipv6.valid) |
| 209 | { |
| 210 | memset(dns, 0x0, 128); |
| 211 | if(ipv6_2_str(&(ipv6.PrimaryDNS), dns)) |
| 212 | { |
| 213 | LOGD("PrimaryDNS error."); |
| 214 | } else { |
| 215 | LOGD("PrimaryDNS : %s", dns); |
| 216 | } |
| 217 | offset += sprintf(buf + offset, "nameserver %s\n", dns); |
| 218 | memset(dns, 0x0, 128); |
| 219 | if(ipv6_2_str(&(ipv6.SecondaryDNS), dns)) |
| 220 | { |
| 221 | LOGD("SecondaryDNS error."); |
| 222 | } else { |
| 223 | LOGD("SecondaryDNS : %s", dns); |
| 224 | } |
| 225 | offset += sprintf(buf + offset, "nameserver %s\n", dns); |
| 226 | } |
| 227 | |
| 228 | if(offset > 0) |
| 229 | { |
| 230 | fd = open("/tmp/resolv.conf", O_WRONLY | O_TRUNC); |
| 231 | if(fd < 0) |
| 232 | { |
| 233 | LOGD("mbtk_route_config : open fail."); |
| 234 | return -1; |
| 235 | } |
| 236 | |
| 237 | ret = write(fd, buf, offset); |
| 238 | if(ret < 0) |
| 239 | { |
| 240 | LOGD("mbtk_route_config : write fail."); |
| 241 | } |
| 242 | |
| 243 | close(fd); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | #endif |
| 250 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 251 | int ql_wan_start_ex(int profile_idx, int op, ex_conn_status_cb nw_cb) |
| 252 | { |
| 253 | int ret = -1; |
| 254 | int count = 0; |
| 255 | if(ql_info_handle == NULL) |
| 256 | { |
| 257 | return -1; |
| 258 | } |
| 259 | |
| 260 | ql_net_ex_status_cb = nw_cb; |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 261 | ql_net_status_cb = NULL; |
| 262 | now_cid = profile_idx; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 263 | if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX) |
| 264 | { |
| 265 | LOGD("ql_wan_start_ex() cid out of range."); |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 266 | #if 0 |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 267 | if(ql_net_ex_status_cb) |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 268 | ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type ,PDP_CID_EXIST_FAIL, 0); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 269 | #endif |
| 270 | return -1; |
| 271 | } |
| 272 | |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 273 | //ql_netw_status_cb(ql_apn_info[profile_idx].cid); |
| 274 | if(op == 0) |
| 275 | { |
| 276 | ret = ql_wan_stop(profile_idx); |
| 277 | goto exit; |
| 278 | } |
| 279 | |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 280 | #if 0 |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 281 | if(ql_apn_info[profile_idx].active) |
| 282 | { |
| 283 | if(ql_net_ex_status_cb) |
| 284 | ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, PDP_CID_EXIST_FAIL, 0); |
| 285 | return -1; |
| 286 | } |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 287 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 288 | |
| 289 | if(ql_net_ex_status_cb) { |
| 290 | ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, CONNECT_DIAL_IMMEDIATELY, 0); |
| 291 | ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, CONNECT_CONNING, 0); |
| 292 | } |
| 293 | |
| 294 | data_call_continue: |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 295 | ret = mbtk_data_call_start(ql_info_handle, profile_idx, 0, op == 3 ? TRUE : FALSE, 0); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 296 | if(ret != 0) |
| 297 | { |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 298 | if(mbtk_interval_sec <= 0) |
| 299 | { |
| 300 | if(ql_net_ex_status_cb) |
| 301 | ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, CONNECT_DISCON, 0); |
| 302 | return ret; |
| 303 | } |
| 304 | else |
| 305 | { |
| 306 | if(count >= 5) |
| 307 | goto exit; |
| 308 | sleep(mbtk_interval_sec); |
| 309 | count++; |
| 310 | if(ql_net_ex_status_cb) |
| 311 | ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type, CONNECT_REDIAL, 0); |
| 312 | goto data_call_continue; |
| 313 | } |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 314 | LOGD("mbtk_data_call_start() fail."); |
| 315 | } |
| 316 | else |
| 317 | { |
| 318 | //ql_apn_info[8].cid=profile_idx; |
| 319 | //ql_netw_status_cb(CONNECT_CONSUCCESS); |
wangyouqiang | ed88c72 | 2023-11-22 16:33:43 +0800 | [diff] [blame] | 320 | #ifdef MBTK_AF_SUPPORT |
| 321 | if(profile_idx == 1) |
| 322 | { |
| 323 | mbtk_route_config(profile_idx); |
| 324 | |
| 325 | } |
| 326 | #endif |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 327 | LOGD("mbtk_data_call_start() success."); |
| 328 | } |
| 329 | exit: |
| 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | |
| 334 | /* |
| 335 | * Start data call. |
| 336 | */ |
| 337 | int ql_wan_start(int profile_idx, int op, nw_status_cb nw_cb) |
| 338 | { |
| 339 | int ret = -1; |
| 340 | int count = 0; |
| 341 | if(ql_info_handle == NULL) |
| 342 | { |
| 343 | return -1; |
| 344 | } |
| 345 | |
| 346 | ql_net_status_cb = nw_cb; |
wangyouqiang | 6588415 | 2023-10-25 19:54:15 +0800 | [diff] [blame] | 347 | ql_net_ex_status_cb = NULL; |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 348 | if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX) |
| 349 | { |
| 350 | ql_net_status_cb(PDP_ERROR_UNSPECIFIED); |
| 351 | return -1; |
| 352 | } |
| 353 | |
| 354 | //ql_netw_status_cb(ql_apn_info[profile_idx].cid); |
| 355 | if(op == 0) |
| 356 | { |
| 357 | ret = ql_wan_stop(profile_idx); |
| 358 | goto exit; |
| 359 | } |
| 360 | |
| 361 | if(ql_apn_info[profile_idx].active) |
| 362 | { |
| 363 | ql_net_status_cb(PDP_CID_EXIST_FAIL); |
| 364 | return -1; |
| 365 | } |
| 366 | |
| 367 | ql_net_status_cb(CONNECT_DIAL_IMMEDIATELY); |
| 368 | ql_net_status_cb(CONNECT_CONNING); |
| 369 | data_call_continue: |
wangyouqiang | f2c7291 | 2023-11-02 19:33:44 +0800 | [diff] [blame] | 370 | ret = mbtk_data_call_start(ql_info_handle, profile_idx, 0, op == 3 ? TRUE : FALSE, 0); |
liubin | 281ac46 | 2023-07-19 14:22:54 +0800 | [diff] [blame] | 371 | if(ret != 0) |
| 372 | { |
| 373 | if(mbtk_interval_sec <= 0) |
| 374 | { |
| 375 | ql_net_status_cb(CONNECT_DISCON); |
| 376 | return ret; |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | if(count >= 5) |
| 381 | goto exit; |
| 382 | sleep(mbtk_interval_sec); |
| 383 | count++; |
| 384 | ql_net_status_cb(CONNECT_REDIAL); |
| 385 | goto data_call_continue; |
| 386 | } |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | //ql_apn_info[8].cid=profile_idx; |
| 391 | //ql_netw_status_cb(CONNECT_CONSUCCESS); |
| 392 | LOGD("mbtk_data_call_start() success."); |
| 393 | } |
| 394 | exit: |
| 395 | return ret; |
| 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Stop data call. |
| 400 | */ |
| 401 | int ql_wan_stop(int profile_idx) |
| 402 | { |
| 403 | int err; |
| 404 | if(ql_info_handle == NULL) |
| 405 | { |
| 406 | return -1; |
| 407 | } |
| 408 | if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX) |
| 409 | { |
| 410 | LOGE("CID error."); |
| 411 | return -1; |
| 412 | } |
| 413 | |
| 414 | #if 0 //mbtk wyq for data_call add "if 0" |
| 415 | if(!ql_apn_info[profile_idx].active) |
| 416 | { |
| 417 | if(ql_net_ex_status_cb) |
| 418 | ql_net_ex_status_cb(profile_idx, ql_apn_info[profile_idx].ip_type ,PDP_CID_EXIST_FAIL, 0); |
| 419 | if(ql_net_status_cb) |
| 420 | ql_net_status_cb(PDP_CID_EXIST_FAIL); |
| 421 | return -1; |
| 422 | } |
| 423 | #endif |
| 424 | err = mbtk_data_call_stop(ql_info_handle, profile_idx, 15); |
| 425 | |
| 426 | return err; |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * Query data call state. |
| 431 | */ |
| 432 | int ql_get_data_call_info(int profile_idx, ql_data_call_info *info) |
| 433 | { |
| 434 | if(ql_info_handle == NULL || info == NULL) |
| 435 | { |
| 436 | return -1; |
| 437 | } |
| 438 | if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX) |
| 439 | { |
| 440 | LOGE("CID error."); |
| 441 | return -1; |
| 442 | } |
| 443 | mbtk_ipv4_info_t ipv4; |
| 444 | mbtk_ipv6_info_t ipv6; |
| 445 | memset(info, 0, sizeof(ql_data_call_info)); |
| 446 | int ret = mbtk_data_call_state_get(ql_info_handle, profile_idx, &ipv4, &ipv6); |
| 447 | if(ret != 0) |
| 448 | return -1; |
| 449 | else |
| 450 | { |
| 451 | info->profile_idx = profile_idx; |
| 452 | if(ipv4.valid) |
| 453 | { |
| 454 | info->ip_type = 1; // IPV4 |
| 455 | info->v4.state = 1; |
| 456 | sprintf(info->v4.addr.name, "ccinet%d", profile_idx - 1); |
| 457 | if(inet_ntop(AF_INET, &(ipv4.IPAddr), info->v4.addr.ip, 32) == NULL) { |
| 458 | LOGD("IP error."); |
| 459 | } else { |
| 460 | LOGD("IP : %s", info->v4.addr.ip); |
| 461 | } |
| 462 | if(inet_ntop(AF_INET, &(ipv4.PrimaryDNS), info->v4.addr.pri_dns, 32) == NULL) { |
| 463 | LOGD("PrimaryDNS error."); |
| 464 | } else { |
| 465 | LOGD("PrimaryDNS : %s", info->v4.addr.pri_dns); |
| 466 | } |
| 467 | if(inet_ntop(AF_INET, &(ipv4.SecondaryDNS), info->v4.addr.sec_dns, 32) == NULL) { |
| 468 | LOGD("SecondaryDNS error."); |
| 469 | } else { |
| 470 | LOGD("SecondaryDNS : %s", info->v4.addr.sec_dns); |
| 471 | } |
| 472 | } |
| 473 | if(ipv6.valid) |
| 474 | { |
| 475 | info->ip_type = 2; // IPV6 |
| 476 | info->v6.state = 1; |
| 477 | sprintf(info->v6.addr.name, "ccinet%d", profile_idx - 1); |
| 478 | if(ipv6_2_str(&(ipv6.IPV6Addr), info->v6.addr.ip)) |
| 479 | { |
| 480 | LOGD("IP error."); |
| 481 | } else { |
| 482 | LOGD("IP : %s", info->v6.addr.ip); |
| 483 | } |
| 484 | if(ipv6_2_str(&(ipv6.PrimaryDNS), info->v6.addr.pri_dns)) |
| 485 | { |
| 486 | LOGD("PrimaryDNS error."); |
| 487 | } else { |
| 488 | LOGD("PrimaryDNS : %s", info->v6.addr.pri_dns); |
| 489 | } |
| 490 | if(ipv6_2_str(&(ipv6.SecondaryDNS), info->v6.addr.sec_dns)) |
| 491 | { |
| 492 | LOGD("SecondaryDNS error."); |
| 493 | } else { |
| 494 | LOGD("SecondaryDNS : %s", info->v6.addr.sec_dns); |
| 495 | } |
| 496 | } |
| 497 | if(ipv4.valid && ipv6.valid) |
| 498 | info->ip_type = 0; // IPV4V6 |
| 499 | if(!ipv4.valid && !ipv6.valid) |
| 500 | { |
| 501 | info->v4.state = 0; |
| 502 | info->v6.state = 0; |
| 503 | } |
| 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | } |
| 508 | |
| 509 | /* |
| 510 | * Set specific APN informations. |
| 511 | * |
| 512 | * cid : 2-7 |
| 513 | */ |
| 514 | int ql_wan_setapn(int profile_idx, int ip_type, const char *apn, const char *userName, |
| 515 | const char *password, QL_DSI_AUTH_PREF_T auth) |
| 516 | { |
| 517 | if(ql_info_handle == NULL) |
| 518 | { |
| 519 | return -1; |
| 520 | } |
| 521 | if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX) |
| 522 | { |
| 523 | LOGE("CID error."); |
| 524 | return -1; |
| 525 | } |
| 526 | /* |
| 527 | QL_DSI_AUTH_PREF_NULL = 0, //无认证 |
| 528 | QL_DSI_AUTH_PREF_ONLY_PAP, //PAP 认证 |
| 529 | QL_DSI_AUTH_PREF_ONLY_CHAP, //CHAP 认证 |
| 530 | QL_DSI_AUTH_PREF_BOTH_PAP_CHAP //PAP 和 CHAP 认证 |
| 531 | */ |
| 532 | char mbtk_auth[64]={0}; |
| 533 | if(auth == QL_DSI_AUTH_PREF_NULL) |
| 534 | memcpy(mbtk_auth,"NONE",strlen("NONE")+1); |
| 535 | else if(auth == QL_DSI_AUTH_PREF_ONLY_PAP) |
| 536 | memcpy(mbtk_auth,"PAP",strlen("PAP")+1); |
| 537 | else if(auth == QL_DSI_AUTH_PREF_ONLY_CHAP) |
| 538 | memcpy(mbtk_auth,"CHAP",strlen("CHAP")+1); |
| 539 | else |
| 540 | { |
| 541 | LOGD("auth input error!"); |
| 542 | return -1; |
| 543 | } |
| 544 | |
| 545 | memset(&(ql_apn_info[profile_idx]), 0, sizeof(apn_info)); |
| 546 | ql_apn_info[profile_idx].cid = profile_idx; |
| 547 | ql_apn_info[profile_idx].ip_type = ip_type; |
| 548 | if(!str_empty(userName) && !str_empty(password)) { |
| 549 | memcpy(ql_apn_info[profile_idx].user, userName, strlen(userName)); |
| 550 | memcpy(ql_apn_info[profile_idx].pass, password, strlen(password)); |
| 551 | ql_apn_info[profile_idx].auth = auth; |
| 552 | LOGD("ql_wan_setapn: %d, %d, %s, %s, %s, %s",profile_idx, ip_type, apn, userName, password, mbtk_auth); |
| 553 | } else { |
| 554 | LOGD("ql_wan_setapn: %d, %d, %s, NULL, NULL, %s",profile_idx, ip_type, apn, mbtk_auth); |
| 555 | } |
| 556 | |
| 557 | /* |
| 558 | if(ip_type < 0 || ip_type > 3) |
| 559 | ql_netw_status_cb(PDP_UNKNOWN_PDP_ADDRESS_TYPE); |
| 560 | */ |
| 561 | if(ip_type == 0) // IPV4V6 |
| 562 | ip_type = MBTK_IP_TYPE_IPV4V6; |
| 563 | else if(ip_type == 1) // IPV4 |
| 564 | ip_type = MBTK_IP_TYPE_IP; |
| 565 | else if(ip_type == 2) // IPV6 |
| 566 | ip_type = MBTK_IP_TYPE_IPV6; |
| 567 | |
| 568 | return mbtk_apn_set(ql_info_handle, profile_idx, ip_type, apn, userName, password, mbtk_auth); |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | * Get current all APN informations. |
| 573 | */ |
| 574 | int __ql_wan_getapn(int profile_idx, int *ip_type, char *apn, int apnLen, char *userName, int userLen, char *password, int pwdLen,int* auth) |
| 575 | { |
| 576 | if(ql_info_handle == NULL || apn == NULL) |
| 577 | { |
| 578 | return -1; |
| 579 | } |
| 580 | if(profile_idx < MBTK_APN_CID_MIN || profile_idx > MBTK_APN_CID_MAX) |
| 581 | { |
| 582 | LOGE("CID error."); |
| 583 | return -1; |
| 584 | } |
| 585 | mbtk_apn_info_t apns[10]; |
| 586 | int apn_num = MBTK_APN_CID_MAX; |
| 587 | int ret = mbtk_apn_get(ql_info_handle, &apn_num, apns); |
| 588 | if(ret != 0) |
| 589 | { |
| 590 | LOGD("mbtk_apn_get ret = %d",ret); |
| 591 | return -1; |
| 592 | } |
| 593 | else |
| 594 | { |
| 595 | int i; |
| 596 | for(i=0;i<MBTK_APN_CID_MAX;i++) |
| 597 | { |
| 598 | if(apns[i].cid == profile_idx) |
| 599 | break; |
| 600 | } |
| 601 | if(i == MBTK_APN_CID_MAX) |
| 602 | return -1; |
| 603 | LOGD("cid = %d",i); |
| 604 | if(apns[i].ip_type == MBTK_IP_TYPE_IPV4V6) // IPV4V6 |
| 605 | *ip_type = 0; |
| 606 | else if(apns[i].ip_type == MBTK_IP_TYPE_IP) // IPV4 |
| 607 | *ip_type = 1; |
| 608 | else if(apns[i].ip_type == MBTK_IP_TYPE_IPV6) // IPV6 |
| 609 | *ip_type = 2; |
| 610 | else |
| 611 | *ip_type = 0; |
| 612 | |
| 613 | if(strlen(apns[i].apn)+1 > apnLen) |
| 614 | return -1; |
| 615 | else |
| 616 | memcpy(apn, apns[i].apn,strlen(apns[i].apn)+1); |
| 617 | |
| 618 | if(strlen(apns[i].user)+1 > userLen) |
| 619 | return -1; |
| 620 | else |
| 621 | { |
| 622 | if(strlen(apns[i].user) > 0) |
| 623 | memcpy(userName, apns[i].user, strlen(apns[i].user)+1); |
| 624 | else |
| 625 | memcpy(userName, ql_apn_info[profile_idx].user, strlen(ql_apn_info[profile_idx].user)+1); |
| 626 | } |
| 627 | |
| 628 | if(strlen(apns[i].pass)+1 > pwdLen) |
| 629 | return -1; |
| 630 | else |
| 631 | { |
| 632 | if(strlen(apns[i].pass) > 0) |
| 633 | memcpy(password, apns[i].pass, strlen(apns[i].pass)+1); |
| 634 | else |
| 635 | memcpy(password, ql_apn_info[profile_idx].pass, strlen(ql_apn_info[profile_idx].pass)+1); |
| 636 | } |
| 637 | |
| 638 | if(strlen(apns[i].auth) > 0) { |
| 639 | if(strcmp(apns[i].auth, "NONE") == 0) |
| 640 | *auth = QL_DSI_AUTH_PREF_NULL; |
| 641 | else if(strcmp(apns[i].auth, "PAP") == 0) |
| 642 | *auth = QL_DSI_AUTH_PREF_ONLY_PAP; |
| 643 | else if(strcmp(apns[i].auth, "CHAP") == 0) |
| 644 | *auth = QL_DSI_AUTH_PREF_ONLY_CHAP; |
| 645 | else |
| 646 | { |
| 647 | LOGD("auth error!"); |
| 648 | return -1; |
| 649 | } |
| 650 | } else { |
| 651 | *auth = ql_apn_info[profile_idx].auth; |
| 652 | } |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | |