blob: 2af1aac0c37c8324d39c2358a80baff8ec36a7fc [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;
xf.li6b0d8502023-09-04 18:49:12 -0700522 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700523 lynq_data_call_response_v11_t data_urc_info;
524 qser_data_call_state_s data_cb_state;
525 while (s_qser_data_cb_thread_status)
526 {
xf.li6b0d8502023-09-04 18:49:12 -0700527 ret = lynq_wait_data_call_state_change(&handle);
528 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
529 if(s_qser_data_cb_thread_status == 0)
530 {
531 return NULL;
532 }
533 else if(ret < 0)
534 {
535 continue;
536 }
537
xf.li2fc84552023-06-23 05:26:47 -0700538 lynq_get_data_call_list(&handle,&data_urc_info);
539 /*compare paramter*/
540 data_cb_state.profile_idx = (char)handle;
541
542 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
543 if (!strcmp(data_urc_info.type,"IPV4"))
544 {
545 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
546 }
547 else if (!strcmp(data_urc_info.type,"IPV6"))
548 {
549 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
550 }
551 else if (strcmp(data_urc_info.type,"IPV4V6"))
552 {
553 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
554 }
555 else
556 {
557 LYERRLOG("unknow data call type");
558 continue;
559 }
560
561 if (data_urc_info.status != 0)
562 {
563 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
564 }
565 else
566 {
567 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
568 }
569 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
570 {
571 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
572 }
573 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
574 {
575 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
576 }
577 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
578 {
579 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
580 }
581 else
582 {
583 LYERRLOG("unknow ip_family");
584 continue;
585 }
586 if (s_data_call_cb != NULL)
587 {
588 s_data_call_cb(&data_cb_state);
589 }
590 }
591 return NULL;
592}
593
594int qser_cb_pthread_create()
595{
596 int ret;
597 s_qser_data_cb_thread_status = 1;
598 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
599 if (ret < 0)
600 {
601 LYERRLOG("pthread create fail");
602 s_qser_data_cb_thread_status = 0;
603 return RESULT_ERROR;
604 }
605 return RESULT_OK;
606}
607
608void qser_cb_pthread_cancel()
609{
xf.li2fc84552023-06-23 05:26:47 -0700610 s_qser_data_cb_thread_status = 0;
611 if (s_cb_tid != -1)
612 {
xf.li6b0d8502023-09-04 18:49:12 -0700613 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -0700614 }
615 return;
616}
xf.li7b0bfd02023-08-03 01:11:52 -0700617int check_xml_file(const char *file)
618{
619 /* Check for existence */
620 if((access(file, F_OK)) == -1)
621 {
622 LYERRLOG("no such xml file.\n");
623 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
624 }
625
626 if((access(file, F_OK)) == -1)
627 {
628 LYERRLOG("error copy xml file.\n");
629 return -1;
630 }
631 return RESULT_OK;
632}
xf.li2fc84552023-06-23 05:26:47 -0700633
634int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
635{
636 int ret = 0;
637 int utoken = 0;
638 if (NULL == evt_cb)
639 {
640 LYERRLOG("init incoming paramters error");
641 return RESULT_ERROR;
642 }
xf.li7b0bfd02023-08-03 01:11:52 -0700643
644 ret = check_xml_file(data_xml_path);
645 if (ret != RESULT_OK)
646 {
647 LYERRLOG("check xml file error");
648 return RESULT_ERROR;
649 }
650
xf.li2fc84552023-06-23 05:26:47 -0700651 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -0700652
xf.li2fc84552023-06-23 05:26:47 -0700653 ret = lynq_init_data(utoken);
654 if (ret != RESULT_OK)
655 {
xf.li6b0d8502023-09-04 18:49:12 -0700656 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700657 s_data_call_cb = NULL;
658 return RESULT_ERROR;
659 }
xf.li6b0d8502023-09-04 18:49:12 -0700660 qser_cb_pthread_create();
xf.li2fc84552023-06-23 05:26:47 -0700661 return RESULT_OK;
662}
663
664void qser_data_call_destroy(void)
665{
xf.li6b0d8502023-09-04 18:49:12 -0700666 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
667
xf.li2fc84552023-06-23 05:26:47 -0700668 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -0700669 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700670 s_data_call_cb = NULL;
xf.li6b0d8502023-09-04 18:49:12 -0700671 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -0700672 return ;
673}
674
675int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
676{
677 int ret = -1;
678 int handle = 0;
679 if (NULL == data_call || NULL == err)
680 {
681 LYERRLOG("call start incoming paramters error");
682 return ret;
683 }
684 if (data_call->profile_idx == 0)
685 {
686 ret = lynq_setup_data_call(&handle);
687 }
688 else
689 {
690 char pdptype[16];
691 qser_apn_info_s apn_info;
692 qser_apn_get(data_call->profile_idx,&apn_info);
693 judge_pdp_type(apn_info.pdp_type,pdptype);
694 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
695 }
696 if (ret < 0)
697 {
698 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
699 }
700 return ret;
701}
702
703int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
704{
705 int ret = 0;
706 int handle = -1;
707
708 if (NULL == err)
709 {
710 LYERRLOG("call stop incoming paramters error");
711 return ret;
712 }
713 data_call_handle_get(profile_idx,&handle);
714 ret = lynq_deactive_data_call(&handle);
715 if (ret < 0)
716 {
717 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
718 }
719 return RESULT_OK;
720}
721int 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)
722{
723 int ret = 0;
724 int handle = -1;
725 lynq_data_call_response_v11_t data_call_info;
726 data_call_handle_get(profile_idx,&handle);
727 ret = lynq_get_data_call_list(&handle,&data_call_info);
728 if (ret == 0)
729 {
730 info->profile_idx = profile_idx;
731 info->ip_family = ip_family;
732 if (strcmp(data_call_info.type,"IPV4"))
733 {
734 strcpy(info->v4.name,data_call_info.ifname);
735 datacall_ipv4_status_judge(data_call_info.status,info);
736 LYINFLOG("[IPV4]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 }
739 else if (strcmp(data_call_info.type,"IPV6"))
740 {
741 strcpy(info->v6.name,data_call_info.ifname);
742
743 datacall_ipv6_status_judge(data_call_info.status,info);
744 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
745 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
746 }
747 else if (strcmp(data_call_info.type,"IPV4V6"))
748 {
749 strcpy(info->v4.name,data_call_info.ifname);
750 datacall_ipv4_status_judge(data_call_info.status,info);
751 LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
752 lynq_ipv4_aton_getinfo(&data_call_info,info);
753 strcpy(info->v6.name,data_call_info.ifname);
754 datacall_ipv6_status_judge(data_call_info.status,info);
755 LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
756 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
757 }
758 else
759 {
760 LYERRLOG("useless qser_data_call_ip_family_e");
761 }
762 }
763 return ret;
764}
765int qser_apn_set(qser_apn_info_s *apn)
766{
767 int ret = 0;
768 if (NULL == apn)
769 {
770 LYERRLOG("apn set incoming paramters error");
771 return RESULT_ERROR;
772 }
773 ret = apn_xml_modify(apn);
774 if (ret < 0)
775 {
776 LYERRLOG("apn_xml_modify error");
777 return ret;
778 }
779 int apn_id = 0;
780 char tmp_id[12];
781 char *outinfo = NULL;
782 char normalprotocol[16];
783 char authtype[32];
784 outinfo = (char *)malloc(sizeof(char)*512);
785 bzero(tmp_id,12);
786 bzero(outinfo,512);
787 apn_id = apn->profile_idx + apndb_offset;
788 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
789 judge_pdp_type(apn->pdp_type,normalprotocol);
790 judge_authtype(apn->auth_proto,authtype);
791 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
792 LYINFLOG("[output]:%s",outinfo);
793 free(outinfo);
794 outinfo = NULL;
795 return RESULT_OK;
796}
797
798int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
799{
800 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
801 {
802 LYERRLOG("apn get incoming paramters error");
803 return RESULT_ERROR;
804 }
805 int ret = 0;
806 ret = apn_xml_query(profile_idx,apn);
807 if (ret < 0)
808 {
809 LYERRLOG("apn_xml_query error");
810 return ret;
811 }
812 return ret;
813}
814
815int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
816{
817 int ret = 0;
818 if (NULL == apn || NULL == profile_idx)
819 {
820 LYERRLOG("apn add incoming paramters error");
821 return RESULT_ERROR;
822 }
823 ret = apn_xml_add(apn,profile_idx);
824 if (ret < 0)
825 {
826 LYERRLOG("apn_xml_add error");
827 return ret;
828 }
829 int apn_id = 0;
830 char tmp_id[12];
831 char *outinfo = NULL;
832 char normalprotocol[16];
833 char authtype[32];
834 outinfo = (char *)malloc(sizeof(char)*512);
835 bzero(tmp_id,12);
836 bzero(outinfo,512);
837 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
838 judge_pdp_type(apn->pdp_type,normalprotocol);
839 judge_authtype(apn->auth_proto,authtype);
840 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
841 LYINFLOG("[output]:%s",outinfo);
842 free(outinfo);
843 outinfo = NULL;
844 return RESULT_OK;
845}
846
847int qser_apn_del(unsigned char profile_idx)
848{
849 if (profile_idx < 0 || profile_idx > 24)
850 {
851 LYERRLOG("apn del incoming paramters error");
852 return RESULT_OK;
853 }
854 int ret = 0;
855 ret = apn_xml_delete(profile_idx);
856 if (ret < 0)
857 {
858 LYERRLOG("apn_xml_delete error");
859 return ret;
860 }
861 int apn_id = 0;
862 char tmp_id[12];
863 char *outinfo = NULL;
864 outinfo = (char *)malloc(sizeof(char)*512);
865 bzero(tmp_id,12);
866 bzero(outinfo,512);
867 apn_id = profile_idx+apndb_offset;
868 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
869 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
870 LYINFLOG("[output]:%s",outinfo);
871 free(outinfo);
872 outinfo = NULL;
873 return ret;
874}
875
876int qser_apn_get_list(qser_apn_info_list_s *apn_list)
877{
878 if (NULL == apn_list)
879 {
880 LYERRLOG("apn_list incoming paramters error");
881 return RESULT_ERROR;
882 }
883 int ret = 0;
884 ret = apn_xml_query_list(apn_list);
885 if (ret < 0)
886 {
887 LYERRLOG("apn_xml_query_list error");
888 return ret;
889 }
890 return ret;
xf.li3f891cb2023-08-23 23:11:24 -0700891}