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