blob: 5e4aea4b334ac285fda5ed145e862ace1fc60800 [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{
xf.li3c0a4752023-09-03 20:46:19 -070034#ifdef MOBILETEK_TARGET_PLATFORM_T106
35 char *tmp_char = NULL;
36 char *addresses = NULL;
37 char *dnses = NULL;
38 const char addresses_separator[2] = "/";
39 const char dnses_separator[2] = " ";
40
41 addresses = libdata->addresses;
42 dnses = libdata->dnses;
43 //get addresses
44 tmp_char = strsep(&addresses, addresses_separator);
45 if(tmp_char != NULL)
46 {
47 LYINFLOG("ipv4 addresses = %s", tmp_char);
48 inet_aton(tmp_char,&(data_res->v4.ip));
49 }
50
51 //get dnses
52 tmp_char = strsep(&dnses, dnses_separator);
53 if(tmp_char != NULL)
54 {
55 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
56 inet_aton(tmp_char,&(data_res->v4.pri_dns));
57 }
58 tmp_char = strsep(&dnses, dnses_separator);
59 if(tmp_char != NULL)
60 {
61 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
62 inet_aton(tmp_char, &(data_res->v4.sec_dns));
63 }
64 //get gateway
65 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
66
67#else
xf.li2fc84552023-06-23 05:26:47 -070068 inet_aton(libdata->addresses,&(data_res->v4.ip));
69 inet_aton(libdata->gateways,&(data_res->v4.gateway));
70 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
71 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -070072#endif
xf.li2fc84552023-06-23 05:26:47 -070073 return ;
74}
75
76void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
77{
xf.li3c0a4752023-09-03 20:46:19 -070078#ifdef MOBILETEK_TARGET_PLATFORM_T106
79 char *tmp_char = NULL;
80 char *addresses = NULL;
81 char *dnses = NULL;
82 const char addresses_separator[2] = "/";
83 const char dnses_separator[2] = " ";
84
85 addresses = libdata->addresses;
86 dnses = libdata->dnses;
87 //get addresses
88 tmp_char = strsep(&addresses, addresses_separator);
89 if(tmp_char != NULL)
90 {
91 LYINFLOG("ipv6 addresses = %s", tmp_char);
92 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
93 }
94 //get dnses
95 tmp_char = strsep(&dnses, dnses_separator);
96 if(tmp_char != NULL)
97 {
98 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
99 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
100 }
101 tmp_char = strsep(&dnses, dnses_separator);
102 if(tmp_char != NULL)
103 {
104 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
105 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
106 }
107 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
108#else
xf.li2fc84552023-06-23 05:26:47 -0700109 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
110 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
111 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
112 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700113#endif
114
115 return ;
116}
117
118void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
119{
120 char *tmp_char = NULL;
121 char *addresses = NULL;
122 char *dnses = NULL;
123 const char addresses_separator[2] = "/";
124 const char dnses_separator[2] = " ";
125
126 addresses = libdata->addresses;
127 dnses = libdata->dnses;
128 //get addresses
129 tmp_char = strsep(&addresses, addresses_separator);
130 if(tmp_char != NULL)
131 {
132 LYINFLOG("ipv4 addresses = %s", tmp_char);
133 inet_aton(tmp_char,&(data_res->v4.ip));
134 }
135 tmp_char = strsep(&addresses, addresses_separator);
136 if(tmp_char != NULL)
137 {
138 LYINFLOG("ipv6 addresses = %s", tmp_char);
139 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
140 }
141 //get dnses
142 tmp_char = strsep(&dnses, dnses_separator);
143 if(tmp_char != NULL)
144 {
145 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
146 inet_aton(tmp_char,&(data_res->v4.pri_dns));
147 }
148 tmp_char = strsep(&dnses, dnses_separator);
149 if(tmp_char != NULL)
150 {
151 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
152 inet_aton(tmp_char, &(data_res->v4.sec_dns));
153 }
154 tmp_char = strsep(&dnses, dnses_separator);
155 if(tmp_char != NULL)
156 {
157 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
158 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
159 }
160 tmp_char = strsep(&dnses, dnses_separator);
161 if(tmp_char != NULL)
162 {
163 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
164 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
165 }
166 //get gateway
167 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
168
xf.li2fc84552023-06-23 05:26:47 -0700169 return ;
170}
171
172void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
173{
xf.li3c0a4752023-09-03 20:46:19 -0700174#ifdef MOBILETEK_TARGET_PLATFORM_T106
175 char *tmp_char = NULL;
176 char *addresses = NULL;
177 char *dnses = NULL;
178 const char addresses_separator[2] = "/";
179 const char dnses_separator[2] = " ";
180
181 addresses = libdata->addresses;
182 dnses = libdata->dnses;
183 //get addresses
184 tmp_char = strsep(&addresses, addresses_separator);
185 if(tmp_char != NULL)
186 {
187 LYINFLOG("ipv4 addresses = %s", tmp_char);
188 inet_aton(tmp_char,&(data_res->v4.addr.ip));
189 }
190 //get dnses
191 tmp_char = strsep(&dnses, dnses_separator);
192 if(tmp_char != NULL)
193 {
194 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
195 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
196 }
197 tmp_char = strsep(&dnses, dnses_separator);
198 if(tmp_char != NULL)
199 {
200 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
201 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
202 }
203 //get gateway
204 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
205 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
206
207 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
208 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
209 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
210#else
xf.li2fc84552023-06-23 05:26:47 -0700211 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
212 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
213 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
214 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700215#endif
xf.li2fc84552023-06-23 05:26:47 -0700216 data_res->v4.stats.pkts_tx = 0;
217 data_res->v4.stats.pkts_rx = 0;
218 data_res->v4.stats.bytes_tx = 0;
219 data_res->v4.stats.bytes_rx = 0;
220 data_res->v4.stats.pkts_dropped_tx = 0;
221 data_res->v4.stats.pkts_dropped_rx = 0;
222 return ;
223}
224
225void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
226{
xf.li3c0a4752023-09-03 20:46:19 -0700227#ifdef MOBILETEK_TARGET_PLATFORM_T106
228 char *tmp_char = NULL;
229 char *addresses = NULL;
230 char *dnses = NULL;
231 const char addresses_separator[2] = "/";
232 const char dnses_separator[2] = " ";
233
234 addresses = libdata->addresses;
235 dnses = libdata->dnses;
236 //get addresses
237 tmp_char = strsep(&addresses, addresses_separator);
238 if(tmp_char != NULL)
239 {
240 LYINFLOG("ipv6 addresses = %s", tmp_char);
241 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
242 }
243 //get dnses
244 tmp_char = strsep(&dnses, dnses_separator);
245 if(tmp_char != NULL)
246 {
247 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
248 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
249 }
250 tmp_char = strsep(&dnses, dnses_separator);
251 if(tmp_char != NULL)
252 {
253 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
254 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
255 }
256 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
257#else
xf.li2fc84552023-06-23 05:26:47 -0700258 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
259 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
260 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
261 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700262#endif
263 data_res->v6.stats.pkts_tx = 0;
264 data_res->v6.stats.pkts_rx = 0;
265 data_res->v6.stats.bytes_tx = 0;
266 data_res->v6.stats.bytes_rx = 0;
267 data_res->v6.stats.pkts_dropped_tx = 0;
268 data_res->v6.stats.pkts_dropped_rx = 0;
269 return ;
270}
271void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
272{
273 char *tmp_char = NULL;
274 char *addresses = NULL;
275 char *dnses = NULL;
276 const char addresses_separator[2] = "/";
277 const char dnses_separator[2] = " ";
278
279 char buf_ip[64] = {0};
280 char buf_gateway[64] = {0};
281 char buf_pri_dns[64] = {0};
282 char buf_sec_dns[64] = {0};
283
284 addresses = libdata->addresses;
285 dnses = libdata->dnses;
286 //get addresses
287 tmp_char = strsep(&addresses, addresses_separator);
288 if(tmp_char != NULL)
289 {
290 LYINFLOG("ipv4 addresses = %s", tmp_char);
291 inet_aton(tmp_char,&(data_res->v4.addr.ip));
292 }
293 tmp_char = strsep(&addresses, addresses_separator);
294 if(tmp_char != NULL)
295 {
296 LYINFLOG("ipv6 addresses = %s", tmp_char);
297 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
298 }
299 //get dnses
300 tmp_char = strsep(&dnses, dnses_separator);
301 if(tmp_char != NULL)
302 {
303 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
304 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
305 }
306 tmp_char = strsep(&dnses, dnses_separator);
307 if(tmp_char != NULL)
308 {
309 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
310 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
311 }
312 tmp_char = strsep(&dnses, dnses_separator);
313 if(tmp_char != NULL)
314 {
315 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
316 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
317 }
318 tmp_char = strsep(&dnses, dnses_separator);
319 if(tmp_char != NULL)
320 {
321 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
322 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
323 }
324 //get gateway
325 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
326
327 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
328 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
329 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
330
331 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
332 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
333 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
334 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
335 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
336 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
337 data_res->v4.stats.pkts_tx = 0;
338 data_res->v4.stats.pkts_rx = 0;
339 data_res->v4.stats.bytes_tx = 0;
340 data_res->v4.stats.bytes_rx = 0;
341 data_res->v4.stats.pkts_dropped_tx = 0;
342 data_res->v4.stats.pkts_dropped_rx = 0;
343
xf.li2fc84552023-06-23 05:26:47 -0700344 data_res->v6.stats.pkts_tx = 0;
345 data_res->v6.stats.pkts_rx = 0;
346 data_res->v6.stats.bytes_tx = 0;
347 data_res->v6.stats.bytes_rx = 0;
348 data_res->v6.stats.pkts_dropped_tx = 0;
349 data_res->v6.stats.pkts_dropped_rx = 0;
350 return ;
351}
352
353void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
354{
355 if (state != 0)
356 {
357 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
358 data_res->v4.reconnect = 1;
359 }
360 else
361 {
362 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
363 data_res->v4.reconnect = 0;
364 }
365 return ;
366}
367
368void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
369{
370 if (state != 0)
371 {
372 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
373 data_res->v6.reconnect = 1;
374 }
375 else
376 {
377 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
378 data_res->v6.reconnect = 0;
379 }
380 return ;
381}
382
383
384int apn_xml_add(qser_apn_add_s *apn,unsigned char *apn_num)
385{
386 int node_num = 0;
387 char temp_buff[12];
388 xmlDocPtr pdoc = NULL;
389 xmlNodePtr node = NULL;
390 xmlNodePtr tmp_node = NULL;
391 xmlNodePtr sum_node = NULL;
392 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
393 if(NULL == pdoc)
394 {
395 LYERRLOG("open xml file error");
396 goto FAILED;
397 }
398
399 node = xmlDocGetRootElement(pdoc);
400 if (NULL == node)
401 {
402 LYERRLOG("xmlDocGetRootElement() error");
403 goto FAILED;
404 }
405 sum_node = node->xmlChildrenNode;
406 sum_node = sum_node->next;
407 while (sum_node != NULL)
408 {
409 if (xmlGetProp(sum_node, "profile_idx") == NULL) //Null Node
410 {
411 sum_node = sum_node->next;
412 continue;
413 }
xf.lif7c68e32023-10-10 23:18:42 -0700414 else if(strcmp((char *)xmlGetProp(sum_node, "apn_type"), apn->apn_type) == 0)
415 {
416 LYERRLOG("apntype already exists\n");
417 goto FAILED;
418 }
xf.li2fc84552023-06-23 05:26:47 -0700419 node_num++;
420 sum_node = sum_node->next;
421 }
xf.li3f891cb2023-08-23 23:11:24 -0700422 LYINFLOG("apn_num = %d ",node_num);
423 if(node_num >= QSER_APN_MAX_LIST)
424 {
425 LYERRLOG("apn num reached the max");
426 goto FAILED;
427 }
xf.li2fc84552023-06-23 05:26:47 -0700428 tmp_node = xmlNewNode(NULL,BAD_CAST"apn");
429 *apn_num = node_num;
xf.li2fc84552023-06-23 05:26:47 -0700430 bzero(temp_buff,12);
431 snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num);
432 xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
433 bzero(temp_buff,12);
434 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
435 xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
436 bzero(temp_buff,12);
437 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
438 xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
439 xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
440 xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username);
441 xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password);
442 xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
443 xmlAddChild(node,tmp_node);
444 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
445 xmlFreeDoc(pdoc);
446 return RESULT_OK;
447
448 FAILED:
449 if (pdoc)
450 {
451 xmlFreeDoc(pdoc);
452 }
453 return RESULT_ERROR;
454}
455
456int apn_xml_delete(unsigned char profile_idx)
457{
458 int node_num = 0;
459 char temp_buff[12];
460 xmlDocPtr pdoc = NULL;
461 xmlNodePtr node = NULL;
462 xmlNodePtr modify_node = NULL;
463 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
464 if(NULL == pdoc)
465 {
466 LYERRLOG("open xml file error");
467 goto FAILED;
468 }
469
470 node = xmlDocGetRootElement(pdoc);
471 if (NULL == node)
472 {
473 LYERRLOG("xmlDocGetRootElement() error");
474 goto FAILED;
475 }
476 modify_node = node->xmlChildrenNode;
xf.li029a9e72023-11-04 02:29:45 -0700477 if(modify_node != NULL)
478 {
479 modify_node = modify_node->next;
480 }
481 else
482 {
483 LYERRLOG("modify_node is null\n");
484 goto FAILED;
485 }
xf.li2fc84552023-06-23 05:26:47 -0700486 for (node_num=0 ;node_num<(int)profile_idx ; node_num++)
487 {
xf.li029a9e72023-11-04 02:29:45 -0700488 if(modify_node == NULL)
489 {
490 LYERRLOG("modify_node is null\n");
491 goto FAILED;
492 }
xf.li2fc84552023-06-23 05:26:47 -0700493 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
494 {
495 modify_node = modify_node->next;
496 node_num--;
497 continue;
498 }
499 modify_node = modify_node->next;
500 }
xf.li029a9e72023-11-04 02:29:45 -0700501 if(modify_node == NULL)
502 {
503 LYERRLOG("modify_node is null\n");
504 goto FAILED;
505 }
xf.li2fc84552023-06-23 05:26:47 -0700506 xmlUnlinkNode(modify_node);
507 xmlFreeNode(modify_node);
508 modify_node = NULL;
509 node_num = 0;
510 modify_node = node->xmlChildrenNode;
511 modify_node = modify_node->next;
512 while (modify_node != NULL)
513 {
514 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
515 {
516 modify_node = modify_node->next;
517 continue;
518 }
519 bzero(temp_buff,12);
520 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
521 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
522 modify_node = modify_node->next;
523 node_num++;
524 }
525 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
526 xmlFreeDoc(pdoc);
527 return RESULT_OK;
528
529 FAILED:
530 if (pdoc)
531 {
532 xmlFreeDoc(pdoc);
533 }
534 return RESULT_ERROR;
535}
536
537int apn_xml_modify(qser_apn_info_s *apn)
538{
539 int node_num = 0;
540 char temp_buff[12];
541 xmlDocPtr pdoc = NULL;
542 xmlNodePtr node = NULL;
543 xmlNodePtr modify_node = NULL;
544 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
545 if(NULL == pdoc)
546 {
547 LYERRLOG("open xml file error");
548 goto FAILED;
549 }
550
551 node = xmlDocGetRootElement(pdoc);
552 if (NULL == node)
553 {
554 LYERRLOG("xmlDocGetRootElement() error");
555 goto FAILED;
556 }
557 modify_node = node->xmlChildrenNode;
558 modify_node = modify_node->next;
559 for (node_num=0; node_num<(int)apn->profile_idx;node_num++)
560 {
561 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
562 {
563 modify_node = modify_node->next;
564 node_num--;
565 continue;
566 }
567 modify_node = modify_node->next;
568 }
569 bzero(temp_buff,12);
570 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
571 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
572 bzero(temp_buff,12);
573 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
574 xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
575 bzero(temp_buff,12);
576 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
577 xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
578 xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
579 xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username);
580 xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password);
581 xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
582 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
583 xmlFreeDoc(pdoc);
584 return RESULT_OK;
585
586 FAILED:
587 if (pdoc)
588 {
589 xmlFreeDoc(pdoc);
590 }
591 return RESULT_ERROR;
592}
593
594
595int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn)
596{
597 int node_num = 0;
598 xmlDocPtr pdoc = NULL;
599 xmlNodePtr node = NULL;
600 xmlNodePtr modify_node = NULL;
601 unsigned char temp = NULL;
602 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
603 if(NULL == pdoc)
604 {
605 LYERRLOG("open xml file error");
606 goto FAILED;
607 }
608
609 node = xmlDocGetRootElement(pdoc);
610 if (NULL == node)
611 {
612 LYERRLOG("xmlDocGetRootElement() error");
613 goto FAILED;
614 }
615 modify_node = node->xmlChildrenNode;
xf.libf9df4c2023-07-02 02:42:35 -0700616 if(modify_node != NULL)
xf.li2fc84552023-06-23 05:26:47 -0700617 {
xf.libf9df4c2023-07-02 02:42:35 -0700618 modify_node = modify_node->next;
619 }
620 else
621 {
622 LYERRLOG("modify_node is null\n");
623 goto FAILED;
624 }
625 LYINFLOG("profile_idx is %d\n", (int)profile_idx);
626 for (node_num = 0;(node_num<(int)profile_idx);node_num++)
627 {
628 if(modify_node == NULL)
629 {
630 LYERRLOG("modify_node is null\n");
631 goto FAILED;
632 }
xf.li2fc84552023-06-23 05:26:47 -0700633 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
634 {
635 modify_node = modify_node->next;
636 node_num--;
637 continue;
638 }
639 modify_node = modify_node->next;
xf.li029a9e72023-11-04 02:29:45 -0700640 }
641 if(modify_node == NULL)
642 {
643 LYERRLOG("modify_node is null\n");
644 goto FAILED;
xf.li2fc84552023-06-23 05:26:47 -0700645 }
646 apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx"));
647 apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
648 apn->auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto"));
xf.li6c7e3972023-10-27 20:01:59 -0700649 strncpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
650 strncpy(apn->username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
651 strncpy(apn->password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
652 strncpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE);
xf.li2fc84552023-06-23 05:26:47 -0700653 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
654 xmlFreeDoc(pdoc);
655 return RESULT_OK;
656
657 FAILED:
658 if (pdoc)
659 {
660 xmlFreeDoc(pdoc);
661 }
662 return RESULT_ERROR;
663}
664
665int apn_xml_query_list(qser_apn_info_list_s *apn_list)
666{
667 int node_num = 0;
668 xmlDocPtr pdoc = NULL;
669 xmlNodePtr node = NULL;
670 xmlNodePtr modify_node = NULL;
671 xmlChar *temp_char;
672 char temp[64];
673 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
674 if(NULL == pdoc)
675 {
676 LYERRLOG("open xml file error");
677 goto FAILED;
678 }
679
680 node = xmlDocGetRootElement(pdoc);
681 if (NULL == node)
682 {
683 LYERRLOG("xmlDocGetRootElement() error");
684 goto FAILED;
685 }
686 modify_node = node->xmlChildrenNode;
687 modify_node = modify_node->next;
688 while (modify_node != NULL)
689 {
690 temp_char = xmlGetProp(modify_node, "profile_idx");
691 if (temp_char == NULL)
692 {
693 modify_node = modify_node->next;
694 continue;
695 }
696 sprintf(temp,"%s",temp_char);
697 apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp);
698 apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
699 apn_list->apn[node_num].auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto"));
xf.li6c7e3972023-10-27 20:01:59 -0700700 strncpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
701 strncpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
702 strncpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
703 strncpy(apn_list->apn[node_num].apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE);
xf.li2fc84552023-06-23 05:26:47 -0700704 node_num ++;
705 modify_node = modify_node->next;
706 }
707 apn_list->cnt = node_num;
708 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
709 xmlFreeDoc(pdoc);
710 return RESULT_OK;
711
712 FAILED:
713 if (pdoc)
714 {
715 xmlFreeDoc(pdoc);
716 }
717 return RESULT_ERROR;
718}
719
720void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
721{
722 switch (pdp_type)
723 {
724 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -0800725#ifdef MOBILETEK_TARGET_PLATFORM_T106
726 strcpy(out_pdp_type,"IP");
727#else
xf.li2fc84552023-06-23 05:26:47 -0700728 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -0800729#endif
xf.li2fc84552023-06-23 05:26:47 -0700730 break;
731 case QSER_APN_PDP_TYPE_PPP:
732 strcpy(out_pdp_type,"PPP");
733 break;
734 case QSER_APN_PDP_TYPE_IPV6:
735 strcpy(out_pdp_type,"IPV6");
736 break;
737 case QSER_APN_PDP_TYPE_IPV4V6:
738 strcpy(out_pdp_type,"IPV4V6");
739 break;
740 default:
741 strcpy(out_pdp_type,"NULL");
742 break;
743 }
744 return;
745}
746void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
747{
748 switch (auth_proto)
749 {
750 case QSER_APN_AUTH_PROTO_DEFAULT:
751 strcpy(out_proto,"NULL;authType=0");
752 break;
753 case QSER_APN_AUTH_PROTO_NONE:
754 strcpy(out_proto,"NULL;authType=1");
755 break;
756 case QSER_APN_AUTH_PROTO_PAP:
757 strcpy(out_proto,"NULL;authType=2");
758 break;
759 case QSER_APN_AUTH_PROTO_CHAP:
760 strcpy(out_proto,"NULL;authtype=3");
761 break;
762 case QSER_APN_AUTH_PROTO_PAP_CHAP:
763 strcpy(out_proto,"NULL;authtype=4");
764 break;
765 default:
766 strcpy(out_proto,"NULL;authType=NULL");
767 break;
768 }
769 return ;
770}
771
772int data_call_handle_get(const char profile_idx,int *handle)
773{
774 int num = LYNQ_APN_CHANNEL_MAX;
775 int table_num = 0;
776 lynq_apn_info **apn_table = NULL;
777 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -0700778 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700779 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
780 if (NULL == apn_table)
781 {
782 LYERRLOG("malloc apn_table fail ");
783 return RESULT_ERROR;
784 }
785 for(int i =0;i<10;i++)
786 {
787 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
788 if (apn_table[i]==NULL)
789 {
790 for (int n=0;n<i;n++)
791 {
792 free(apn_table[n]);
793 }
794 return RESULT_ERROR;
795 }
796 memset(apn_table[i],0,sizeof(lynq_apn_info));
797 }
798 lynq_get_apn_table(&table_num,apn_table);
799 memset(&apn,0,sizeof(qser_apn_info_s));
xf.li0fc26502023-09-16 02:10:17 -0700800 ret = apn_xml_query(profile_idx,&apn);
801 if (ret < 0)
802 {
803 LYERRLOG("apn_xml_query error");
804 return ret;
805 }
xf.li2fc84552023-06-23 05:26:47 -0700806 for (int j = 0;j < table_num;j++)
807 {
808 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
809 {
810 *handle = apn_table[j]->index;
811 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
812 break;
813 }
814 }
815
816 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
817 {
818 if (apn_table[i]!=NULL)
819 {
820 free(apn_table[i]);
821 apn_table[i]=NULL;
822 }
823 }
824 free(apn_table);
825 apn_table=NULL;
826 LYINFLOG("data_call_handle_get end");
827 return RESULT_OK;
828}
829
830void *thread_wait_cb_status(void)
831{
832 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -0700833 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700834 lynq_data_call_response_v11_t data_urc_info;
835 qser_data_call_state_s data_cb_state;
836 while (s_qser_data_cb_thread_status)
837 {
xf.li6b0d8502023-09-04 18:49:12 -0700838 ret = lynq_wait_data_call_state_change(&handle);
839 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
840 if(s_qser_data_cb_thread_status == 0)
841 {
842 return NULL;
843 }
844 else if(ret < 0)
845 {
846 continue;
847 }
848
xf.li2fc84552023-06-23 05:26:47 -0700849 lynq_get_data_call_list(&handle,&data_urc_info);
850 /*compare paramter*/
851 data_cb_state.profile_idx = (char)handle;
852
853 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -0800854 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -0700855 {
856 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
857 }
858 else if (!strcmp(data_urc_info.type,"IPV6"))
859 {
860 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
861 }
862 else if (strcmp(data_urc_info.type,"IPV4V6"))
863 {
864 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
865 }
866 else
867 {
868 LYERRLOG("unknow data call type");
869 continue;
870 }
871
872 if (data_urc_info.status != 0)
873 {
874 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
875 }
876 else
877 {
878 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
879 }
880 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
881 {
882 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
883 }
884 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
885 {
886 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
887 }
888 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
889 {
xf.li3c0a4752023-09-03 20:46:19 -0700890#ifdef MOBILETEK_TARGET_PLATFORM_T106
891 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
892#else
xf.li2fc84552023-06-23 05:26:47 -0700893 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -0700894#endif
xf.li2fc84552023-06-23 05:26:47 -0700895 }
896 else
897 {
898 LYERRLOG("unknow ip_family");
899 continue;
900 }
901 if (s_data_call_cb != NULL)
902 {
903 s_data_call_cb(&data_cb_state);
904 }
905 }
906 return NULL;
907}
908
909int qser_cb_pthread_create()
910{
911 int ret;
912 s_qser_data_cb_thread_status = 1;
913 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
914 if (ret < 0)
915 {
916 LYERRLOG("pthread create fail");
917 s_qser_data_cb_thread_status = 0;
918 return RESULT_ERROR;
919 }
920 return RESULT_OK;
921}
922
923void qser_cb_pthread_cancel()
924{
xf.li2fc84552023-06-23 05:26:47 -0700925 s_qser_data_cb_thread_status = 0;
926 if (s_cb_tid != -1)
927 {
xf.li6b0d8502023-09-04 18:49:12 -0700928 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -0700929 }
930 return;
931}
xf.li7b0bfd02023-08-03 01:11:52 -0700932int check_xml_file(const char *file)
933{
934 /* Check for existence */
935 if((access(file, F_OK)) == -1)
936 {
937 LYERRLOG("no such xml file.\n");
938 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
939 }
940
941 if((access(file, F_OK)) == -1)
942 {
943 LYERRLOG("error copy xml file.\n");
944 return -1;
945 }
946 return RESULT_OK;
947}
xf.li2fc84552023-06-23 05:26:47 -0700948
949int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
950{
951 int ret = 0;
952 int utoken = 0;
953 if (NULL == evt_cb)
954 {
955 LYERRLOG("init incoming paramters error");
956 return RESULT_ERROR;
957 }
xf.li7b0bfd02023-08-03 01:11:52 -0700958
959 ret = check_xml_file(data_xml_path);
960 if (ret != RESULT_OK)
961 {
962 LYERRLOG("check xml file error");
963 return RESULT_ERROR;
964 }
965
xf.li2fc84552023-06-23 05:26:47 -0700966 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -0700967
xf.li2fc84552023-06-23 05:26:47 -0700968 ret = lynq_init_data(utoken);
969 if (ret != RESULT_OK)
970 {
xf.li6b0d8502023-09-04 18:49:12 -0700971 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700972 s_data_call_cb = NULL;
973 return RESULT_ERROR;
974 }
xf.li6b0d8502023-09-04 18:49:12 -0700975 qser_cb_pthread_create();
xf.li2fc84552023-06-23 05:26:47 -0700976 return RESULT_OK;
977}
978
979void qser_data_call_destroy(void)
980{
xf.li6b0d8502023-09-04 18:49:12 -0700981 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
982
xf.li2fc84552023-06-23 05:26:47 -0700983 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -0700984 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700985 s_data_call_cb = NULL;
xf.li6b0d8502023-09-04 18:49:12 -0700986 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -0700987 return ;
988}
989
990int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
991{
992 int ret = -1;
993 int handle = 0;
994 if (NULL == data_call || NULL == err)
995 {
996 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -0800997 if(err != NULL)
998 {
999 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1000 }
xf.li2fc84552023-06-23 05:26:47 -07001001 return ret;
1002 }
1003 if (data_call->profile_idx == 0)
1004 {
1005 ret = lynq_setup_data_call(&handle);
1006 }
1007 else
1008 {
1009 char pdptype[16];
1010 qser_apn_info_s apn_info;
xf.li0fc26502023-09-16 02:10:17 -07001011 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1012 if (ret != 0)
1013 {
1014 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001015 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001016 return ret;
1017 }
xf.li2fc84552023-06-23 05:26:47 -07001018 judge_pdp_type(apn_info.pdp_type,pdptype);
1019 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1020 }
xf.lic12b3702023-11-22 22:39:01 -08001021 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001022 {
1023 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1024 }
1025 return ret;
1026}
1027
1028int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1029{
1030 int ret = 0;
1031 int handle = -1;
1032
1033 if (NULL == err)
1034 {
1035 LYERRLOG("call stop incoming paramters error");
1036 return ret;
1037 }
xf.lic12b3702023-11-22 22:39:01 -08001038 ret = data_call_handle_get(profile_idx,&handle);
1039 if(ret != 0)
1040 {
1041 LYERRLOG("datacall handle get error");
1042 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1043 return ret;
1044 }
xf.li2fc84552023-06-23 05:26:47 -07001045 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001046 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001047 {
1048 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001049 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001050 }
xy.hee2daacc2023-09-18 00:57:51 -07001051 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001052}
1053int 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)
1054{
1055 int ret = 0;
1056 int handle = -1;
1057 lynq_data_call_response_v11_t data_call_info;
1058 data_call_handle_get(profile_idx,&handle);
1059 ret = lynq_get_data_call_list(&handle,&data_call_info);
1060 if (ret == 0)
1061 {
1062 info->profile_idx = profile_idx;
1063 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001064 if ((strncmp(data_call_info.type,"IPV4", strlen("IPV4") + 1) == 0) || (strncmp(data_call_info.type,"IP", strlen("IP") + 1) == 0))
xf.li2fc84552023-06-23 05:26:47 -07001065 {
1066 strcpy(info->v4.name,data_call_info.ifname);
1067 datacall_ipv4_status_judge(data_call_info.status,info);
1068 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1069 lynq_ipv4_aton_getinfo(&data_call_info,info);
1070 }
xf.li3c0a4752023-09-03 20:46:19 -07001071 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001072 {
1073 strcpy(info->v6.name,data_call_info.ifname);
1074
1075 datacall_ipv6_status_judge(data_call_info.status,info);
1076 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1077 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1078 }
xf.li3c0a4752023-09-03 20:46:19 -07001079 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001080 {
1081 strcpy(info->v4.name,data_call_info.ifname);
1082 datacall_ipv4_status_judge(data_call_info.status,info);
1083 LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
xf.li3c0a4752023-09-03 20:46:19 -07001084#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001085 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001086#endif
xf.li2fc84552023-06-23 05:26:47 -07001087 strcpy(info->v6.name,data_call_info.ifname);
1088 datacall_ipv6_status_judge(data_call_info.status,info);
1089 LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
xf.li3c0a4752023-09-03 20:46:19 -07001090#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001091 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001092#endif
1093#ifdef MOBILETEK_TARGET_PLATFORM_T106
1094 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1095#endif
xf.li2fc84552023-06-23 05:26:47 -07001096 }
1097 else
1098 {
1099 LYERRLOG("useless qser_data_call_ip_family_e");
1100 }
1101 }
1102 return ret;
1103}
1104int qser_apn_set(qser_apn_info_s *apn)
1105{
1106 int ret = 0;
1107 if (NULL == apn)
1108 {
1109 LYERRLOG("apn set incoming paramters error");
1110 return RESULT_ERROR;
1111 }
1112 ret = apn_xml_modify(apn);
1113 if (ret < 0)
1114 {
1115 LYERRLOG("apn_xml_modify error");
1116 return ret;
1117 }
xf.li6c7e3972023-10-27 20:01:59 -07001118#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001119 int apn_id = 0;
1120 char tmp_id[12];
1121 char *outinfo = NULL;
1122 char normalprotocol[16];
1123 char authtype[32];
1124 outinfo = (char *)malloc(sizeof(char)*512);
1125 bzero(tmp_id,12);
1126 bzero(outinfo,512);
1127 apn_id = apn->profile_idx + apndb_offset;
1128 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1129 judge_pdp_type(apn->pdp_type,normalprotocol);
1130 judge_authtype(apn->auth_proto,authtype);
1131 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1132 LYINFLOG("[output]:%s",outinfo);
1133 free(outinfo);
1134 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001135#endif
1136 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001137}
1138
1139int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1140{
1141 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
1142 {
1143 LYERRLOG("apn get incoming paramters error");
1144 return RESULT_ERROR;
1145 }
1146 int ret = 0;
1147 ret = apn_xml_query(profile_idx,apn);
1148 if (ret < 0)
1149 {
1150 LYERRLOG("apn_xml_query error");
1151 return ret;
1152 }
1153 return ret;
1154}
1155
1156int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1157{
1158 int ret = 0;
1159 if (NULL == apn || NULL == profile_idx)
1160 {
1161 LYERRLOG("apn add incoming paramters error");
1162 return RESULT_ERROR;
1163 }
1164 ret = apn_xml_add(apn,profile_idx);
1165 if (ret < 0)
1166 {
1167 LYERRLOG("apn_xml_add error");
1168 return ret;
1169 }
xf.li6c7e3972023-10-27 20:01:59 -07001170#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001171 int apn_id = 0;
1172 char tmp_id[12];
1173 char *outinfo = NULL;
1174 char normalprotocol[16];
1175 char authtype[32];
1176 outinfo = (char *)malloc(sizeof(char)*512);
1177 bzero(tmp_id,12);
1178 bzero(outinfo,512);
1179 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1180 judge_pdp_type(apn->pdp_type,normalprotocol);
1181 judge_authtype(apn->auth_proto,authtype);
1182 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1183 LYINFLOG("[output]:%s",outinfo);
1184 free(outinfo);
1185 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001186#endif
1187 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001188}
1189
1190int qser_apn_del(unsigned char profile_idx)
1191{
1192 if (profile_idx < 0 || profile_idx > 24)
1193 {
1194 LYERRLOG("apn del incoming paramters error");
1195 return RESULT_OK;
1196 }
1197 int ret = 0;
1198 ret = apn_xml_delete(profile_idx);
1199 if (ret < 0)
1200 {
1201 LYERRLOG("apn_xml_delete error");
1202 return ret;
1203 }
xf.li6c7e3972023-10-27 20:01:59 -07001204#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001205 int apn_id = 0;
1206 char tmp_id[12];
1207 char *outinfo = NULL;
1208 outinfo = (char *)malloc(sizeof(char)*512);
1209 bzero(tmp_id,12);
1210 bzero(outinfo,512);
1211 apn_id = profile_idx+apndb_offset;
1212 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1213 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1214 LYINFLOG("[output]:%s",outinfo);
1215 free(outinfo);
1216 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001217#endif
xf.li2fc84552023-06-23 05:26:47 -07001218 return ret;
1219}
1220
1221int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1222{
1223 if (NULL == apn_list)
1224 {
1225 LYERRLOG("apn_list incoming paramters error");
1226 return RESULT_ERROR;
1227 }
1228 int ret = 0;
1229 ret = apn_xml_query_list(apn_list);
1230 if (ret < 0)
1231 {
1232 LYERRLOG("apn_xml_query_list error");
1233 return ret;
1234 }
1235 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001236}
you.chen21c62b72023-09-08 09:41:11 +08001237
1238DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1239