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