xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdint.h> |
| 3 | #include <sys/types.h> |
| 4 | #include <arpa/inet.h> |
| 5 | #include <string.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <unistd.h> |
| 8 | #include <log/log.h> |
| 9 | #include <libdata/lynq_data.h> |
| 10 | #include <liblog/lynq_deflog.h> |
| 11 | #include <pthread.h> |
| 12 | #include <libxml/tree.h> |
| 13 | #include <libxml/parser.h> |
| 14 | #include "lynq-qser-data.h" |
| 15 | |
| 16 | #define USER_LOG_TAG "LYNQ_QSER_DATA" |
| 17 | |
| 18 | #define RESULT_OK (0) |
| 19 | #define RESULT_ERROR (-1) |
| 20 | |
| 21 | static pthread_t s_cb_tid = -1; |
| 22 | static int s_qser_data_cb_thread_status = 0; |
| 23 | static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 24 | static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER; |
| 25 | |
| 26 | #define data_xml_path "/data/lynq_qser_data_apn.xml" |
| 27 | |
| 28 | static qser_data_call_evt_cb_t s_data_call_cb = NULL; |
| 29 | const int apndb_offset = 683; |
| 30 | |
| 31 | void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res) |
| 32 | { |
| 33 | inet_aton(libdata->addresses,&(data_res->v4.ip)); |
| 34 | inet_aton(libdata->gateways,&(data_res->v4.gateway)); |
| 35 | inet_aton(libdata->dnses,&(data_res->v4.pri_dns)); |
| 36 | inet_aton(libdata->dnses,&(data_res->v4.sec_dns)); |
| 37 | return ; |
| 38 | } |
| 39 | |
| 40 | void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res) |
| 41 | { |
| 42 | inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip)); |
| 43 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 44 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns)); |
| 45 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns)); |
| 46 | return ; |
| 47 | } |
| 48 | |
| 49 | void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res) |
| 50 | { |
| 51 | inet_aton(libdata->addresses,&(data_res->v4.addr.ip)); |
| 52 | inet_aton(libdata->gateways,&(data_res->v4.addr.gateway)); |
| 53 | inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns)); |
| 54 | inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns)); |
| 55 | data_res->v4.stats.pkts_tx = 0; |
| 56 | data_res->v4.stats.pkts_rx = 0; |
| 57 | data_res->v4.stats.bytes_tx = 0; |
| 58 | data_res->v4.stats.bytes_rx = 0; |
| 59 | data_res->v4.stats.pkts_dropped_tx = 0; |
| 60 | data_res->v4.stats.pkts_dropped_rx = 0; |
| 61 | return ; |
| 62 | } |
| 63 | |
| 64 | void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res) |
| 65 | { |
| 66 | inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip)); |
| 67 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway)); |
| 68 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns)); |
| 69 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns)); |
| 70 | data_res->v6.stats.pkts_tx = 0; |
| 71 | data_res->v6.stats.pkts_rx = 0; |
| 72 | data_res->v6.stats.bytes_tx = 0; |
| 73 | data_res->v6.stats.bytes_rx = 0; |
| 74 | data_res->v6.stats.pkts_dropped_tx = 0; |
| 75 | data_res->v6.stats.pkts_dropped_rx = 0; |
| 76 | return ; |
| 77 | } |
| 78 | |
| 79 | void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res) |
| 80 | { |
| 81 | if (state != 0) |
| 82 | { |
| 83 | data_res->v4.state = QSER_DATA_CALL_CONNECTED; |
| 84 | data_res->v4.reconnect = 1; |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | data_res->v4.state = QSER_DATA_CALL_DISCONNECTED; |
| 89 | data_res->v4.reconnect = 0; |
| 90 | } |
| 91 | return ; |
| 92 | } |
| 93 | |
| 94 | void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res) |
| 95 | { |
| 96 | if (state != 0) |
| 97 | { |
| 98 | data_res->v6.state = QSER_DATA_CALL_CONNECTED; |
| 99 | data_res->v6.reconnect = 1; |
| 100 | } |
| 101 | else |
| 102 | { |
| 103 | data_res->v6.state = QSER_DATA_CALL_DISCONNECTED; |
| 104 | data_res->v6.reconnect = 0; |
| 105 | } |
| 106 | return ; |
| 107 | } |
| 108 | |
| 109 | |
| 110 | int apn_xml_add(qser_apn_add_s *apn,unsigned char *apn_num) |
| 111 | { |
| 112 | int node_num = 0; |
| 113 | char temp_buff[12]; |
| 114 | xmlDocPtr pdoc = NULL; |
| 115 | xmlNodePtr node = NULL; |
| 116 | xmlNodePtr tmp_node = NULL; |
| 117 | xmlNodePtr sum_node = NULL; |
| 118 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 119 | if(NULL == pdoc) |
| 120 | { |
| 121 | LYERRLOG("open xml file error"); |
| 122 | goto FAILED; |
| 123 | } |
| 124 | |
| 125 | node = xmlDocGetRootElement(pdoc); |
| 126 | if (NULL == node) |
| 127 | { |
| 128 | LYERRLOG("xmlDocGetRootElement() error"); |
| 129 | goto FAILED; |
| 130 | } |
| 131 | sum_node = node->xmlChildrenNode; |
| 132 | sum_node = sum_node->next; |
| 133 | while (sum_node != NULL) |
| 134 | { |
| 135 | if (xmlGetProp(sum_node, "profile_idx") == NULL) //Null Node |
| 136 | { |
| 137 | sum_node = sum_node->next; |
| 138 | continue; |
| 139 | } |
| 140 | node_num++; |
| 141 | sum_node = sum_node->next; |
| 142 | } |
| 143 | tmp_node = xmlNewNode(NULL,BAD_CAST"apn"); |
| 144 | *apn_num = node_num; |
| 145 | LYERRLOG("apn_num%d ",node_num); |
| 146 | bzero(temp_buff,12); |
| 147 | snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num); |
| 148 | xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 149 | bzero(temp_buff,12); |
| 150 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type); |
| 151 | xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff); |
| 152 | bzero(temp_buff,12); |
| 153 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto); |
| 154 | xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff); |
| 155 | xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name); |
| 156 | xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username); |
| 157 | xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password); |
| 158 | xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type); |
| 159 | xmlAddChild(node,tmp_node); |
| 160 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 161 | xmlFreeDoc(pdoc); |
| 162 | return RESULT_OK; |
| 163 | |
| 164 | FAILED: |
| 165 | if (pdoc) |
| 166 | { |
| 167 | xmlFreeDoc(pdoc); |
| 168 | } |
| 169 | return RESULT_ERROR; |
| 170 | } |
| 171 | |
| 172 | int apn_xml_delete(unsigned char profile_idx) |
| 173 | { |
| 174 | int node_num = 0; |
| 175 | char temp_buff[12]; |
| 176 | xmlDocPtr pdoc = NULL; |
| 177 | xmlNodePtr node = NULL; |
| 178 | xmlNodePtr modify_node = NULL; |
| 179 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 180 | if(NULL == pdoc) |
| 181 | { |
| 182 | LYERRLOG("open xml file error"); |
| 183 | goto FAILED; |
| 184 | } |
| 185 | |
| 186 | node = xmlDocGetRootElement(pdoc); |
| 187 | if (NULL == node) |
| 188 | { |
| 189 | LYERRLOG("xmlDocGetRootElement() error"); |
| 190 | goto FAILED; |
| 191 | } |
| 192 | modify_node = node->xmlChildrenNode; |
| 193 | modify_node = modify_node->next; |
| 194 | for (node_num=0 ;node_num<(int)profile_idx ; node_num++) |
| 195 | { |
| 196 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 197 | { |
| 198 | modify_node = modify_node->next; |
| 199 | node_num--; |
| 200 | continue; |
| 201 | } |
| 202 | modify_node = modify_node->next; |
| 203 | } |
| 204 | xmlUnlinkNode(modify_node); |
| 205 | xmlFreeNode(modify_node); |
| 206 | modify_node = NULL; |
| 207 | node_num = 0; |
| 208 | modify_node = node->xmlChildrenNode; |
| 209 | modify_node = modify_node->next; |
| 210 | while (modify_node != NULL) |
| 211 | { |
| 212 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 213 | { |
| 214 | modify_node = modify_node->next; |
| 215 | continue; |
| 216 | } |
| 217 | bzero(temp_buff,12); |
| 218 | snprintf(temp_buff,sizeof(temp_buff),"%d",node_num); |
| 219 | xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 220 | modify_node = modify_node->next; |
| 221 | node_num++; |
| 222 | } |
| 223 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 224 | xmlFreeDoc(pdoc); |
| 225 | return RESULT_OK; |
| 226 | |
| 227 | FAILED: |
| 228 | if (pdoc) |
| 229 | { |
| 230 | xmlFreeDoc(pdoc); |
| 231 | } |
| 232 | return RESULT_ERROR; |
| 233 | } |
| 234 | |
| 235 | int apn_xml_modify(qser_apn_info_s *apn) |
| 236 | { |
| 237 | int node_num = 0; |
| 238 | char temp_buff[12]; |
| 239 | xmlDocPtr pdoc = NULL; |
| 240 | xmlNodePtr node = NULL; |
| 241 | xmlNodePtr modify_node = NULL; |
| 242 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 243 | if(NULL == pdoc) |
| 244 | { |
| 245 | LYERRLOG("open xml file error"); |
| 246 | goto FAILED; |
| 247 | } |
| 248 | |
| 249 | node = xmlDocGetRootElement(pdoc); |
| 250 | if (NULL == node) |
| 251 | { |
| 252 | LYERRLOG("xmlDocGetRootElement() error"); |
| 253 | goto FAILED; |
| 254 | } |
| 255 | modify_node = node->xmlChildrenNode; |
| 256 | modify_node = modify_node->next; |
| 257 | for (node_num=0; node_num<(int)apn->profile_idx;node_num++) |
| 258 | { |
| 259 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 260 | { |
| 261 | modify_node = modify_node->next; |
| 262 | node_num--; |
| 263 | continue; |
| 264 | } |
| 265 | modify_node = modify_node->next; |
| 266 | } |
| 267 | bzero(temp_buff,12); |
| 268 | snprintf(temp_buff,sizeof(temp_buff),"%d",node_num); |
| 269 | xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 270 | bzero(temp_buff,12); |
| 271 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type); |
| 272 | xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff); |
| 273 | bzero(temp_buff,12); |
| 274 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto); |
| 275 | xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff); |
| 276 | xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name); |
| 277 | xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username); |
| 278 | xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password); |
| 279 | xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type); |
| 280 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 281 | xmlFreeDoc(pdoc); |
| 282 | return RESULT_OK; |
| 283 | |
| 284 | FAILED: |
| 285 | if (pdoc) |
| 286 | { |
| 287 | xmlFreeDoc(pdoc); |
| 288 | } |
| 289 | return RESULT_ERROR; |
| 290 | } |
| 291 | |
| 292 | |
| 293 | int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn) |
| 294 | { |
| 295 | int node_num = 0; |
| 296 | xmlDocPtr pdoc = NULL; |
| 297 | xmlNodePtr node = NULL; |
| 298 | xmlNodePtr modify_node = NULL; |
| 299 | unsigned char temp = NULL; |
| 300 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 301 | if(NULL == pdoc) |
| 302 | { |
| 303 | LYERRLOG("open xml file error"); |
| 304 | goto FAILED; |
| 305 | } |
| 306 | |
| 307 | node = xmlDocGetRootElement(pdoc); |
| 308 | if (NULL == node) |
| 309 | { |
| 310 | LYERRLOG("xmlDocGetRootElement() error"); |
| 311 | goto FAILED; |
| 312 | } |
| 313 | modify_node = node->xmlChildrenNode; |
| 314 | modify_node = modify_node->next; |
| 315 | for (node_num = 0;node_num<(int)profile_idx;node_num++) |
| 316 | { |
| 317 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 318 | { |
| 319 | modify_node = modify_node->next; |
| 320 | node_num--; |
| 321 | continue; |
| 322 | } |
| 323 | modify_node = modify_node->next; |
| 324 | } |
| 325 | apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx")); |
| 326 | apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type")); |
| 327 | apn->auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto")); |
| 328 | strcpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name")); |
| 329 | strcpy(apn->username,(char *)xmlGetProp(modify_node, "username")); |
| 330 | strcpy(apn->password,(char *)xmlGetProp(modify_node, "password")); |
| 331 | strcpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type")); |
| 332 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 333 | xmlFreeDoc(pdoc); |
| 334 | return RESULT_OK; |
| 335 | |
| 336 | FAILED: |
| 337 | if (pdoc) |
| 338 | { |
| 339 | xmlFreeDoc(pdoc); |
| 340 | } |
| 341 | return RESULT_ERROR; |
| 342 | } |
| 343 | |
| 344 | int apn_xml_query_list(qser_apn_info_list_s *apn_list) |
| 345 | { |
| 346 | int node_num = 0; |
| 347 | xmlDocPtr pdoc = NULL; |
| 348 | xmlNodePtr node = NULL; |
| 349 | xmlNodePtr modify_node = NULL; |
| 350 | xmlChar *temp_char; |
| 351 | char temp[64]; |
| 352 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 353 | if(NULL == pdoc) |
| 354 | { |
| 355 | LYERRLOG("open xml file error"); |
| 356 | goto FAILED; |
| 357 | } |
| 358 | |
| 359 | node = xmlDocGetRootElement(pdoc); |
| 360 | if (NULL == node) |
| 361 | { |
| 362 | LYERRLOG("xmlDocGetRootElement() error"); |
| 363 | goto FAILED; |
| 364 | } |
| 365 | modify_node = node->xmlChildrenNode; |
| 366 | modify_node = modify_node->next; |
| 367 | while (modify_node != NULL) |
| 368 | { |
| 369 | temp_char = xmlGetProp(modify_node, "profile_idx"); |
| 370 | if (temp_char == NULL) |
| 371 | { |
| 372 | modify_node = modify_node->next; |
| 373 | continue; |
| 374 | } |
| 375 | sprintf(temp,"%s",temp_char); |
| 376 | apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp); |
| 377 | apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type")); |
| 378 | apn_list->apn[node_num].auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto")); |
| 379 | strcpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name")); |
| 380 | strcpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username")); |
| 381 | strcpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password")); |
| 382 | node_num ++; |
| 383 | modify_node = modify_node->next; |
| 384 | } |
| 385 | apn_list->cnt = node_num; |
| 386 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 387 | xmlFreeDoc(pdoc); |
| 388 | return RESULT_OK; |
| 389 | |
| 390 | FAILED: |
| 391 | if (pdoc) |
| 392 | { |
| 393 | xmlFreeDoc(pdoc); |
| 394 | } |
| 395 | return RESULT_ERROR; |
| 396 | } |
| 397 | |
| 398 | void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type) |
| 399 | { |
| 400 | switch (pdp_type) |
| 401 | { |
| 402 | case QSER_APN_PDP_TYPE_IPV4: |
| 403 | strcpy(out_pdp_type,"IPV4"); |
| 404 | break; |
| 405 | case QSER_APN_PDP_TYPE_PPP: |
| 406 | strcpy(out_pdp_type,"PPP"); |
| 407 | break; |
| 408 | case QSER_APN_PDP_TYPE_IPV6: |
| 409 | strcpy(out_pdp_type,"IPV6"); |
| 410 | break; |
| 411 | case QSER_APN_PDP_TYPE_IPV4V6: |
| 412 | strcpy(out_pdp_type,"IPV4V6"); |
| 413 | break; |
| 414 | default: |
| 415 | strcpy(out_pdp_type,"NULL"); |
| 416 | break; |
| 417 | } |
| 418 | return; |
| 419 | } |
| 420 | void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto) |
| 421 | { |
| 422 | switch (auth_proto) |
| 423 | { |
| 424 | case QSER_APN_AUTH_PROTO_DEFAULT: |
| 425 | strcpy(out_proto,"NULL;authType=0"); |
| 426 | break; |
| 427 | case QSER_APN_AUTH_PROTO_NONE: |
| 428 | strcpy(out_proto,"NULL;authType=1"); |
| 429 | break; |
| 430 | case QSER_APN_AUTH_PROTO_PAP: |
| 431 | strcpy(out_proto,"NULL;authType=2"); |
| 432 | break; |
| 433 | case QSER_APN_AUTH_PROTO_CHAP: |
| 434 | strcpy(out_proto,"NULL;authtype=3"); |
| 435 | break; |
| 436 | case QSER_APN_AUTH_PROTO_PAP_CHAP: |
| 437 | strcpy(out_proto,"NULL;authtype=4"); |
| 438 | break; |
| 439 | default: |
| 440 | strcpy(out_proto,"NULL;authType=NULL"); |
| 441 | break; |
| 442 | } |
| 443 | return ; |
| 444 | } |
| 445 | |
| 446 | int data_call_handle_get(const char profile_idx,int *handle) |
| 447 | { |
| 448 | int num = LYNQ_APN_CHANNEL_MAX; |
| 449 | int table_num = 0; |
| 450 | lynq_apn_info **apn_table = NULL; |
| 451 | qser_apn_info_s apn; |
| 452 | apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX); |
| 453 | if (NULL == apn_table) |
| 454 | { |
| 455 | LYERRLOG("malloc apn_table fail "); |
| 456 | return RESULT_ERROR; |
| 457 | } |
| 458 | for(int i =0;i<10;i++) |
| 459 | { |
| 460 | apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info)); |
| 461 | if (apn_table[i]==NULL) |
| 462 | { |
| 463 | for (int n=0;n<i;n++) |
| 464 | { |
| 465 | free(apn_table[n]); |
| 466 | } |
| 467 | return RESULT_ERROR; |
| 468 | } |
| 469 | memset(apn_table[i],0,sizeof(lynq_apn_info)); |
| 470 | } |
| 471 | lynq_get_apn_table(&table_num,apn_table); |
| 472 | memset(&apn,0,sizeof(qser_apn_info_s)); |
| 473 | apn_xml_query(profile_idx,&apn); |
| 474 | for (int j = 0;j < table_num;j++) |
| 475 | { |
| 476 | if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0) |
| 477 | { |
| 478 | *handle = apn_table[j]->index; |
| 479 | LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle); |
| 480 | break; |
| 481 | } |
| 482 | } |
| 483 | |
| 484 | for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++) |
| 485 | { |
| 486 | if (apn_table[i]!=NULL) |
| 487 | { |
| 488 | free(apn_table[i]); |
| 489 | apn_table[i]=NULL; |
| 490 | } |
| 491 | } |
| 492 | free(apn_table); |
| 493 | apn_table=NULL; |
| 494 | LYINFLOG("data_call_handle_get end"); |
| 495 | return RESULT_OK; |
| 496 | } |
| 497 | |
| 498 | void *thread_wait_cb_status(void) |
| 499 | { |
| 500 | int handle = -1; |
| 501 | lynq_data_call_response_v11_t data_urc_info; |
| 502 | qser_data_call_state_s data_cb_state; |
| 503 | while (s_qser_data_cb_thread_status) |
| 504 | { |
| 505 | lynq_wait_data_call_state_change(&handle); |
| 506 | lynq_get_data_call_list(&handle,&data_urc_info); |
| 507 | /*compare paramter*/ |
| 508 | data_cb_state.profile_idx = (char)handle; |
| 509 | |
| 510 | memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1); |
| 511 | if (!strcmp(data_urc_info.type,"IPV4")) |
| 512 | { |
| 513 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4; |
| 514 | } |
| 515 | else if (!strcmp(data_urc_info.type,"IPV6")) |
| 516 | { |
| 517 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6; |
| 518 | } |
| 519 | else if (strcmp(data_urc_info.type,"IPV4V6")) |
| 520 | { |
| 521 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | LYERRLOG("unknow data call type"); |
| 526 | continue; |
| 527 | } |
| 528 | |
| 529 | if (data_urc_info.status != 0) |
| 530 | { |
| 531 | data_cb_state.state = QSER_DATA_CALL_CONNECTED; |
| 532 | } |
| 533 | else |
| 534 | { |
| 535 | data_cb_state.state = QSER_DATA_CALL_DISCONNECTED; |
| 536 | } |
| 537 | if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4) |
| 538 | { |
| 539 | lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state); |
| 540 | } |
| 541 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6) |
| 542 | { |
| 543 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 544 | } |
| 545 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6) |
| 546 | { |
| 547 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 548 | } |
| 549 | else |
| 550 | { |
| 551 | LYERRLOG("unknow ip_family"); |
| 552 | continue; |
| 553 | } |
| 554 | if (s_data_call_cb != NULL) |
| 555 | { |
| 556 | s_data_call_cb(&data_cb_state); |
| 557 | } |
| 558 | } |
| 559 | return NULL; |
| 560 | } |
| 561 | |
| 562 | int qser_cb_pthread_create() |
| 563 | { |
| 564 | int ret; |
| 565 | s_qser_data_cb_thread_status = 1; |
| 566 | ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL); |
| 567 | if (ret < 0) |
| 568 | { |
| 569 | LYERRLOG("pthread create fail"); |
| 570 | s_qser_data_cb_thread_status = 0; |
| 571 | return RESULT_ERROR; |
| 572 | } |
| 573 | return RESULT_OK; |
| 574 | } |
| 575 | |
| 576 | void qser_cb_pthread_cancel() |
| 577 | { |
| 578 | int ret; |
| 579 | s_qser_data_cb_thread_status = 0; |
| 580 | if (s_cb_tid != -1) |
| 581 | { |
| 582 | ret = pthread_cancel(s_cb_tid); |
| 583 | LYDBGLOG("pthread cancel ret = %d",ret); |
| 584 | ret = pthread_join(s_cb_tid,NULL); |
| 585 | LYDBGLOG("pthread join ret = %d",ret); |
| 586 | s_cb_tid = -1; |
| 587 | } |
| 588 | return; |
| 589 | } |
| 590 | |
| 591 | int qser_data_call_init(qser_data_call_evt_cb_t evt_cb) |
| 592 | { |
| 593 | int ret = 0; |
| 594 | int utoken = 0; |
| 595 | if (NULL == evt_cb) |
| 596 | { |
| 597 | LYERRLOG("init incoming paramters error"); |
| 598 | return RESULT_ERROR; |
| 599 | } |
| 600 | s_data_call_cb = evt_cb; |
| 601 | qser_cb_pthread_create(); |
| 602 | ret = lynq_init_data(utoken); |
| 603 | if (ret != RESULT_OK) |
| 604 | { |
| 605 | qser_cb_pthread_cancel(); |
| 606 | s_data_call_cb = NULL; |
| 607 | return RESULT_ERROR; |
| 608 | } |
| 609 | return RESULT_OK; |
| 610 | } |
| 611 | |
| 612 | void qser_data_call_destroy(void) |
| 613 | { |
| 614 | qser_cb_pthread_cancel(); |
| 615 | lynq_deinit_data(); |
| 616 | s_data_call_cb = NULL; |
| 617 | return ; |
| 618 | } |
| 619 | |
| 620 | int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 621 | { |
| 622 | int ret = -1; |
| 623 | int handle = 0; |
| 624 | if (NULL == data_call || NULL == err) |
| 625 | { |
| 626 | LYERRLOG("call start incoming paramters error"); |
| 627 | return ret; |
| 628 | } |
| 629 | if (data_call->profile_idx == 0) |
| 630 | { |
| 631 | ret = lynq_setup_data_call(&handle); |
| 632 | } |
| 633 | else |
| 634 | { |
| 635 | char pdptype[16]; |
| 636 | qser_apn_info_s apn_info; |
| 637 | qser_apn_get(data_call->profile_idx,&apn_info); |
| 638 | judge_pdp_type(apn_info.pdp_type,pdptype); |
| 639 | ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype); |
| 640 | } |
| 641 | if (ret < 0) |
| 642 | { |
| 643 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 644 | } |
| 645 | return ret; |
| 646 | } |
| 647 | |
| 648 | int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err) |
| 649 | { |
| 650 | int ret = 0; |
| 651 | int handle = -1; |
| 652 | |
| 653 | if (NULL == err) |
| 654 | { |
| 655 | LYERRLOG("call stop incoming paramters error"); |
| 656 | return ret; |
| 657 | } |
| 658 | data_call_handle_get(profile_idx,&handle); |
| 659 | ret = lynq_deactive_data_call(&handle); |
| 660 | if (ret < 0) |
| 661 | { |
| 662 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 663 | } |
| 664 | return RESULT_OK; |
| 665 | } |
| 666 | int qser_data_call_info_get(char profile_idx,qser_data_call_ip_family_e ip_family,qser_data_call_info_s *info,qser_data_call_error_e *err) |
| 667 | { |
| 668 | int ret = 0; |
| 669 | int handle = -1; |
| 670 | lynq_data_call_response_v11_t data_call_info; |
| 671 | data_call_handle_get(profile_idx,&handle); |
| 672 | ret = lynq_get_data_call_list(&handle,&data_call_info); |
| 673 | if (ret == 0) |
| 674 | { |
| 675 | info->profile_idx = profile_idx; |
| 676 | info->ip_family = ip_family; |
| 677 | if (strcmp(data_call_info.type,"IPV4")) |
| 678 | { |
| 679 | strcpy(info->v4.name,data_call_info.ifname); |
| 680 | datacall_ipv4_status_judge(data_call_info.status,info); |
| 681 | LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 682 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
| 683 | } |
| 684 | else if (strcmp(data_call_info.type,"IPV6")) |
| 685 | { |
| 686 | strcpy(info->v6.name,data_call_info.ifname); |
| 687 | |
| 688 | datacall_ipv6_status_judge(data_call_info.status,info); |
| 689 | LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 690 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
| 691 | } |
| 692 | else if (strcmp(data_call_info.type,"IPV4V6")) |
| 693 | { |
| 694 | strcpy(info->v4.name,data_call_info.ifname); |
| 695 | datacall_ipv4_status_judge(data_call_info.status,info); |
| 696 | LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 697 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
| 698 | strcpy(info->v6.name,data_call_info.ifname); |
| 699 | datacall_ipv6_status_judge(data_call_info.status,info); |
| 700 | LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 701 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
| 702 | } |
| 703 | else |
| 704 | { |
| 705 | LYERRLOG("useless qser_data_call_ip_family_e"); |
| 706 | } |
| 707 | } |
| 708 | return ret; |
| 709 | } |
| 710 | int qser_apn_set(qser_apn_info_s *apn) |
| 711 | { |
| 712 | int ret = 0; |
| 713 | if (NULL == apn) |
| 714 | { |
| 715 | LYERRLOG("apn set incoming paramters error"); |
| 716 | return RESULT_ERROR; |
| 717 | } |
| 718 | ret = apn_xml_modify(apn); |
| 719 | if (ret < 0) |
| 720 | { |
| 721 | LYERRLOG("apn_xml_modify error"); |
| 722 | return ret; |
| 723 | } |
| 724 | int apn_id = 0; |
| 725 | char tmp_id[12]; |
| 726 | char *outinfo = NULL; |
| 727 | char normalprotocol[16]; |
| 728 | char authtype[32]; |
| 729 | outinfo = (char *)malloc(sizeof(char)*512); |
| 730 | bzero(tmp_id,12); |
| 731 | bzero(outinfo,512); |
| 732 | apn_id = apn->profile_idx + apndb_offset; |
| 733 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 734 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 735 | judge_authtype(apn->auth_proto,authtype); |
| 736 | lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 737 | LYINFLOG("[output]:%s",outinfo); |
| 738 | free(outinfo); |
| 739 | outinfo = NULL; |
| 740 | return RESULT_OK; |
| 741 | } |
| 742 | |
| 743 | int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn) |
| 744 | { |
| 745 | if (profile_idx < 0 || profile_idx > 24 || NULL == apn) |
| 746 | { |
| 747 | LYERRLOG("apn get incoming paramters error"); |
| 748 | return RESULT_ERROR; |
| 749 | } |
| 750 | int ret = 0; |
| 751 | ret = apn_xml_query(profile_idx,apn); |
| 752 | if (ret < 0) |
| 753 | { |
| 754 | LYERRLOG("apn_xml_query error"); |
| 755 | return ret; |
| 756 | } |
| 757 | return ret; |
| 758 | } |
| 759 | |
| 760 | int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx) |
| 761 | { |
| 762 | int ret = 0; |
| 763 | if (NULL == apn || NULL == profile_idx) |
| 764 | { |
| 765 | LYERRLOG("apn add incoming paramters error"); |
| 766 | return RESULT_ERROR; |
| 767 | } |
| 768 | ret = apn_xml_add(apn,profile_idx); |
| 769 | if (ret < 0) |
| 770 | { |
| 771 | LYERRLOG("apn_xml_add error"); |
| 772 | return ret; |
| 773 | } |
| 774 | int apn_id = 0; |
| 775 | char tmp_id[12]; |
| 776 | char *outinfo = NULL; |
| 777 | char normalprotocol[16]; |
| 778 | char authtype[32]; |
| 779 | outinfo = (char *)malloc(sizeof(char)*512); |
| 780 | bzero(tmp_id,12); |
| 781 | bzero(outinfo,512); |
| 782 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 783 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 784 | judge_authtype(apn->auth_proto,authtype); |
| 785 | lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 786 | LYINFLOG("[output]:%s",outinfo); |
| 787 | free(outinfo); |
| 788 | outinfo = NULL; |
| 789 | return RESULT_OK; |
| 790 | } |
| 791 | |
| 792 | int qser_apn_del(unsigned char profile_idx) |
| 793 | { |
| 794 | if (profile_idx < 0 || profile_idx > 24) |
| 795 | { |
| 796 | LYERRLOG("apn del incoming paramters error"); |
| 797 | return RESULT_OK; |
| 798 | } |
| 799 | int ret = 0; |
| 800 | ret = apn_xml_delete(profile_idx); |
| 801 | if (ret < 0) |
| 802 | { |
| 803 | LYERRLOG("apn_xml_delete error"); |
| 804 | return ret; |
| 805 | } |
| 806 | int apn_id = 0; |
| 807 | char tmp_id[12]; |
| 808 | char *outinfo = NULL; |
| 809 | outinfo = (char *)malloc(sizeof(char)*512); |
| 810 | bzero(tmp_id,12); |
| 811 | bzero(outinfo,512); |
| 812 | apn_id = profile_idx+apndb_offset; |
| 813 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 814 | lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo); |
| 815 | LYINFLOG("[output]:%s",outinfo); |
| 816 | free(outinfo); |
| 817 | outinfo = NULL; |
| 818 | return ret; |
| 819 | } |
| 820 | |
| 821 | int qser_apn_get_list(qser_apn_info_list_s *apn_list) |
| 822 | { |
| 823 | if (NULL == apn_list) |
| 824 | { |
| 825 | LYERRLOG("apn_list incoming paramters error"); |
| 826 | return RESULT_ERROR; |
| 827 | } |
| 828 | int ret = 0; |
| 829 | ret = apn_xml_query_list(apn_list); |
| 830 | if (ret < 0) |
| 831 | { |
| 832 | LYERRLOG("apn_xml_query_list error"); |
| 833 | return ret; |
| 834 | } |
| 835 | return ret; |
| 836 | } |