blob: 0d1d63d7c85db9eef0c05e7e91b44775a14d0a0c [file] [log] [blame]
xf.li2fc84552023-06-23 05:26:47 -07001#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
21static pthread_t s_cb_tid = -1;
22static int s_qser_data_cb_thread_status = 0;
23static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
24static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER;
25
xf.li807fd132023-07-02 02:45:36 -070026#define data_xml_path "/mnt/userdata/lynq_qser_data_apn.xml"
xf.li7b0bfd02023-08-03 01:11:52 -070027#define COPY_XML_RETRY_TIMES 3
xf.li2fc84552023-06-23 05:26:47 -070028
29static qser_data_call_evt_cb_t s_data_call_cb = NULL;
30const int apndb_offset = 683;
31
32void 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
41void 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
50void 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
65void 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
80void 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
95void 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
111int 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
173int 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
236int 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
294int 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.libf9df4c2023-07-02 02:42:35 -0700315 if(modify_node != NULL)
xf.li2fc84552023-06-23 05:26:47 -0700316 {
xf.libf9df4c2023-07-02 02:42:35 -0700317 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.li2fc84552023-06-23 05:26:47 -0700332 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
359int 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"));
397 node_num ++;
398 modify_node = modify_node->next;
399 }
400 apn_list->cnt = node_num;
401 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
402 xmlFreeDoc(pdoc);
403 return RESULT_OK;
404
405 FAILED:
406 if (pdoc)
407 {
408 xmlFreeDoc(pdoc);
409 }
410 return RESULT_ERROR;
411}
412
413void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
414{
415 switch (pdp_type)
416 {
417 case QSER_APN_PDP_TYPE_IPV4:
418 strcpy(out_pdp_type,"IPV4");
419 break;
420 case QSER_APN_PDP_TYPE_PPP:
421 strcpy(out_pdp_type,"PPP");
422 break;
423 case QSER_APN_PDP_TYPE_IPV6:
424 strcpy(out_pdp_type,"IPV6");
425 break;
426 case QSER_APN_PDP_TYPE_IPV4V6:
427 strcpy(out_pdp_type,"IPV4V6");
428 break;
429 default:
430 strcpy(out_pdp_type,"NULL");
431 break;
432 }
433 return;
434}
435void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
436{
437 switch (auth_proto)
438 {
439 case QSER_APN_AUTH_PROTO_DEFAULT:
440 strcpy(out_proto,"NULL;authType=0");
441 break;
442 case QSER_APN_AUTH_PROTO_NONE:
443 strcpy(out_proto,"NULL;authType=1");
444 break;
445 case QSER_APN_AUTH_PROTO_PAP:
446 strcpy(out_proto,"NULL;authType=2");
447 break;
448 case QSER_APN_AUTH_PROTO_CHAP:
449 strcpy(out_proto,"NULL;authtype=3");
450 break;
451 case QSER_APN_AUTH_PROTO_PAP_CHAP:
452 strcpy(out_proto,"NULL;authtype=4");
453 break;
454 default:
455 strcpy(out_proto,"NULL;authType=NULL");
456 break;
457 }
458 return ;
459}
460
461int data_call_handle_get(const char profile_idx,int *handle)
462{
463 int num = LYNQ_APN_CHANNEL_MAX;
464 int table_num = 0;
465 lynq_apn_info **apn_table = NULL;
466 qser_apn_info_s apn;
467 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
468 if (NULL == apn_table)
469 {
470 LYERRLOG("malloc apn_table fail ");
471 return RESULT_ERROR;
472 }
473 for(int i =0;i<10;i++)
474 {
475 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
476 if (apn_table[i]==NULL)
477 {
478 for (int n=0;n<i;n++)
479 {
480 free(apn_table[n]);
481 }
482 return RESULT_ERROR;
483 }
484 memset(apn_table[i],0,sizeof(lynq_apn_info));
485 }
486 lynq_get_apn_table(&table_num,apn_table);
487 memset(&apn,0,sizeof(qser_apn_info_s));
488 apn_xml_query(profile_idx,&apn);
489 for (int j = 0;j < table_num;j++)
490 {
491 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
492 {
493 *handle = apn_table[j]->index;
494 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
495 break;
496 }
497 }
498
499 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
500 {
501 if (apn_table[i]!=NULL)
502 {
503 free(apn_table[i]);
504 apn_table[i]=NULL;
505 }
506 }
507 free(apn_table);
508 apn_table=NULL;
509 LYINFLOG("data_call_handle_get end");
510 return RESULT_OK;
511}
512
513void *thread_wait_cb_status(void)
514{
515 int handle = -1;
516 lynq_data_call_response_v11_t data_urc_info;
517 qser_data_call_state_s data_cb_state;
518 while (s_qser_data_cb_thread_status)
519 {
520 lynq_wait_data_call_state_change(&handle);
521 lynq_get_data_call_list(&handle,&data_urc_info);
522 /*compare paramter*/
523 data_cb_state.profile_idx = (char)handle;
524
525 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
526 if (!strcmp(data_urc_info.type,"IPV4"))
527 {
528 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
529 }
530 else if (!strcmp(data_urc_info.type,"IPV6"))
531 {
532 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
533 }
534 else if (strcmp(data_urc_info.type,"IPV4V6"))
535 {
536 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
537 }
538 else
539 {
540 LYERRLOG("unknow data call type");
541 continue;
542 }
543
544 if (data_urc_info.status != 0)
545 {
546 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
547 }
548 else
549 {
550 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
551 }
552 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
553 {
554 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
555 }
556 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
557 {
558 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
559 }
560 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
561 {
562 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
563 }
564 else
565 {
566 LYERRLOG("unknow ip_family");
567 continue;
568 }
569 if (s_data_call_cb != NULL)
570 {
571 s_data_call_cb(&data_cb_state);
572 }
573 }
574 return NULL;
575}
576
577int qser_cb_pthread_create()
578{
579 int ret;
580 s_qser_data_cb_thread_status = 1;
581 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
582 if (ret < 0)
583 {
584 LYERRLOG("pthread create fail");
585 s_qser_data_cb_thread_status = 0;
586 return RESULT_ERROR;
587 }
588 return RESULT_OK;
589}
590
591void qser_cb_pthread_cancel()
592{
593 int ret;
594 s_qser_data_cb_thread_status = 0;
595 if (s_cb_tid != -1)
596 {
597 ret = pthread_cancel(s_cb_tid);
598 LYDBGLOG("pthread cancel ret = %d",ret);
599 ret = pthread_join(s_cb_tid,NULL);
600 LYDBGLOG("pthread join ret = %d",ret);
601 s_cb_tid = -1;
602 }
603 return;
604}
xf.li7b0bfd02023-08-03 01:11:52 -0700605int check_xml_file(const char *file)
606{
607 /* Check for existence */
608 if((access(file, F_OK)) == -1)
609 {
610 LYERRLOG("no such xml file.\n");
611 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
612 }
613
614 if((access(file, F_OK)) == -1)
615 {
616 LYERRLOG("error copy xml file.\n");
617 return -1;
618 }
619 return RESULT_OK;
620}
xf.li2fc84552023-06-23 05:26:47 -0700621
622int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
623{
624 int ret = 0;
625 int utoken = 0;
626 if (NULL == evt_cb)
627 {
628 LYERRLOG("init incoming paramters error");
629 return RESULT_ERROR;
630 }
xf.li7b0bfd02023-08-03 01:11:52 -0700631
632 ret = check_xml_file(data_xml_path);
633 if (ret != RESULT_OK)
634 {
635 LYERRLOG("check xml file error");
636 return RESULT_ERROR;
637 }
638
xf.li2fc84552023-06-23 05:26:47 -0700639 s_data_call_cb = evt_cb;
640 qser_cb_pthread_create();
641 ret = lynq_init_data(utoken);
642 if (ret != RESULT_OK)
643 {
644 qser_cb_pthread_cancel();
645 s_data_call_cb = NULL;
646 return RESULT_ERROR;
647 }
648 return RESULT_OK;
649}
650
651void qser_data_call_destroy(void)
652{
653 qser_cb_pthread_cancel();
654 lynq_deinit_data();
655 s_data_call_cb = NULL;
656 return ;
657}
658
659int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
660{
661 int ret = -1;
662 int handle = 0;
663 if (NULL == data_call || NULL == err)
664 {
665 LYERRLOG("call start incoming paramters error");
666 return ret;
667 }
668 if (data_call->profile_idx == 0)
669 {
670 ret = lynq_setup_data_call(&handle);
671 }
672 else
673 {
674 char pdptype[16];
675 qser_apn_info_s apn_info;
676 qser_apn_get(data_call->profile_idx,&apn_info);
677 judge_pdp_type(apn_info.pdp_type,pdptype);
678 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
679 }
680 if (ret < 0)
681 {
682 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
683 }
684 return ret;
685}
686
687int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
688{
689 int ret = 0;
690 int handle = -1;
691
692 if (NULL == err)
693 {
694 LYERRLOG("call stop incoming paramters error");
695 return ret;
696 }
697 data_call_handle_get(profile_idx,&handle);
698 ret = lynq_deactive_data_call(&handle);
699 if (ret < 0)
700 {
701 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
702 }
703 return RESULT_OK;
704}
705int 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)
706{
707 int ret = 0;
708 int handle = -1;
709 lynq_data_call_response_v11_t data_call_info;
710 data_call_handle_get(profile_idx,&handle);
711 ret = lynq_get_data_call_list(&handle,&data_call_info);
712 if (ret == 0)
713 {
714 info->profile_idx = profile_idx;
715 info->ip_family = ip_family;
716 if (strcmp(data_call_info.type,"IPV4"))
717 {
718 strcpy(info->v4.name,data_call_info.ifname);
719 datacall_ipv4_status_judge(data_call_info.status,info);
720 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
721 lynq_ipv4_aton_getinfo(&data_call_info,info);
722 }
723 else if (strcmp(data_call_info.type,"IPV6"))
724 {
725 strcpy(info->v6.name,data_call_info.ifname);
726
727 datacall_ipv6_status_judge(data_call_info.status,info);
728 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
729 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
730 }
731 else if (strcmp(data_call_info.type,"IPV4V6"))
732 {
733 strcpy(info->v4.name,data_call_info.ifname);
734 datacall_ipv4_status_judge(data_call_info.status,info);
735 LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
736 lynq_ipv4_aton_getinfo(&data_call_info,info);
737 strcpy(info->v6.name,data_call_info.ifname);
738 datacall_ipv6_status_judge(data_call_info.status,info);
739 LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
740 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
741 }
742 else
743 {
744 LYERRLOG("useless qser_data_call_ip_family_e");
745 }
746 }
747 return ret;
748}
749int qser_apn_set(qser_apn_info_s *apn)
750{
751 int ret = 0;
752 if (NULL == apn)
753 {
754 LYERRLOG("apn set incoming paramters error");
755 return RESULT_ERROR;
756 }
757 ret = apn_xml_modify(apn);
758 if (ret < 0)
759 {
760 LYERRLOG("apn_xml_modify error");
761 return ret;
762 }
763 int apn_id = 0;
764 char tmp_id[12];
765 char *outinfo = NULL;
766 char normalprotocol[16];
767 char authtype[32];
768 outinfo = (char *)malloc(sizeof(char)*512);
769 bzero(tmp_id,12);
770 bzero(outinfo,512);
771 apn_id = apn->profile_idx + apndb_offset;
772 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
773 judge_pdp_type(apn->pdp_type,normalprotocol);
774 judge_authtype(apn->auth_proto,authtype);
775 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
776 LYINFLOG("[output]:%s",outinfo);
777 free(outinfo);
778 outinfo = NULL;
779 return RESULT_OK;
780}
781
782int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
783{
784 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
785 {
786 LYERRLOG("apn get incoming paramters error");
787 return RESULT_ERROR;
788 }
789 int ret = 0;
790 ret = apn_xml_query(profile_idx,apn);
791 if (ret < 0)
792 {
793 LYERRLOG("apn_xml_query error");
794 return ret;
795 }
796 return ret;
797}
798
799int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
800{
801 int ret = 0;
802 if (NULL == apn || NULL == profile_idx)
803 {
804 LYERRLOG("apn add incoming paramters error");
805 return RESULT_ERROR;
806 }
807 ret = apn_xml_add(apn,profile_idx);
808 if (ret < 0)
809 {
810 LYERRLOG("apn_xml_add error");
811 return ret;
812 }
813 int apn_id = 0;
814 char tmp_id[12];
815 char *outinfo = NULL;
816 char normalprotocol[16];
817 char authtype[32];
818 outinfo = (char *)malloc(sizeof(char)*512);
819 bzero(tmp_id,12);
820 bzero(outinfo,512);
821 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
822 judge_pdp_type(apn->pdp_type,normalprotocol);
823 judge_authtype(apn->auth_proto,authtype);
824 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
825 LYINFLOG("[output]:%s",outinfo);
826 free(outinfo);
827 outinfo = NULL;
828 return RESULT_OK;
829}
830
831int qser_apn_del(unsigned char profile_idx)
832{
833 if (profile_idx < 0 || profile_idx > 24)
834 {
835 LYERRLOG("apn del incoming paramters error");
836 return RESULT_OK;
837 }
838 int ret = 0;
839 ret = apn_xml_delete(profile_idx);
840 if (ret < 0)
841 {
842 LYERRLOG("apn_xml_delete error");
843 return ret;
844 }
845 int apn_id = 0;
846 char tmp_id[12];
847 char *outinfo = NULL;
848 outinfo = (char *)malloc(sizeof(char)*512);
849 bzero(tmp_id,12);
850 bzero(outinfo,512);
851 apn_id = profile_idx+apndb_offset;
852 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
853 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
854 LYINFLOG("[output]:%s",outinfo);
855 free(outinfo);
856 outinfo = NULL;
857 return ret;
858}
859
860int qser_apn_get_list(qser_apn_info_list_s *apn_list)
861{
862 if (NULL == apn_list)
863 {
864 LYERRLOG("apn_list incoming paramters error");
865 return RESULT_ERROR;
866 }
867 int ret = 0;
868 ret = apn_xml_query_list(apn_list);
869 if (ret < 0)
870 {
871 LYERRLOG("apn_xml_query_list error");
872 return ret;
873 }
874 return ret;
875}