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