blob: 538584bac964a87ccfc42322929d503a883f8837 [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
xf.lib33d4862023-12-13 00:40:37 -080021typedef enum{
22 LYNQ_E_NO_INIT=9002
23}LYNQ_E;
24
25static int g_lynq_qser_data_init_flag = 0;
xf.li2fc84552023-06-23 05:26:47 -070026static pthread_t s_cb_tid = -1;
27static int s_qser_data_cb_thread_status = 0;
28static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
29static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER;
30
xf.li807fd132023-07-02 02:45:36 -070031#define data_xml_path "/mnt/userdata/lynq_qser_data_apn.xml"
xf.li7b0bfd02023-08-03 01:11:52 -070032#define COPY_XML_RETRY_TIMES 3
xf.li2fc84552023-06-23 05:26:47 -070033
34static qser_data_call_evt_cb_t s_data_call_cb = NULL;
xf.lie3f55f42023-12-01 22:47:33 -080035static xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -070036const int apndb_offset = 683;
37
38void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
39{
xf.li3c0a4752023-09-03 20:46:19 -070040#ifdef MOBILETEK_TARGET_PLATFORM_T106
41 char *tmp_char = NULL;
42 char *addresses = NULL;
43 char *dnses = NULL;
44 const char addresses_separator[2] = "/";
45 const char dnses_separator[2] = " ";
46
47 addresses = libdata->addresses;
48 dnses = libdata->dnses;
49 //get addresses
50 tmp_char = strsep(&addresses, addresses_separator);
51 if(tmp_char != NULL)
52 {
53 LYINFLOG("ipv4 addresses = %s", tmp_char);
54 inet_aton(tmp_char,&(data_res->v4.ip));
55 }
56
57 //get dnses
58 tmp_char = strsep(&dnses, dnses_separator);
59 if(tmp_char != NULL)
60 {
61 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
62 inet_aton(tmp_char,&(data_res->v4.pri_dns));
63 }
64 tmp_char = strsep(&dnses, dnses_separator);
65 if(tmp_char != NULL)
66 {
67 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
68 inet_aton(tmp_char, &(data_res->v4.sec_dns));
69 }
70 //get gateway
71 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
72
73#else
xf.li2fc84552023-06-23 05:26:47 -070074 inet_aton(libdata->addresses,&(data_res->v4.ip));
75 inet_aton(libdata->gateways,&(data_res->v4.gateway));
76 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
77 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -070078#endif
xf.li2fc84552023-06-23 05:26:47 -070079 return ;
80}
81
82void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
83{
xf.li3c0a4752023-09-03 20:46:19 -070084#ifdef MOBILETEK_TARGET_PLATFORM_T106
85 char *tmp_char = NULL;
86 char *addresses = NULL;
87 char *dnses = NULL;
88 const char addresses_separator[2] = "/";
89 const char dnses_separator[2] = " ";
90
91 addresses = libdata->addresses;
92 dnses = libdata->dnses;
93 //get addresses
94 tmp_char = strsep(&addresses, addresses_separator);
95 if(tmp_char != NULL)
96 {
97 LYINFLOG("ipv6 addresses = %s", tmp_char);
98 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
99 }
100 //get dnses
101 tmp_char = strsep(&dnses, dnses_separator);
102 if(tmp_char != NULL)
103 {
104 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
105 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
106 }
107 tmp_char = strsep(&dnses, dnses_separator);
108 if(tmp_char != NULL)
109 {
110 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
111 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
112 }
113 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
114#else
xf.li2fc84552023-06-23 05:26:47 -0700115 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
116 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
117 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
118 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700119#endif
120
121 return ;
122}
123
124void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
125{
126 char *tmp_char = NULL;
127 char *addresses = NULL;
128 char *dnses = NULL;
129 const char addresses_separator[2] = "/";
130 const char dnses_separator[2] = " ";
131
132 addresses = libdata->addresses;
133 dnses = libdata->dnses;
134 //get addresses
135 tmp_char = strsep(&addresses, addresses_separator);
136 if(tmp_char != NULL)
137 {
138 LYINFLOG("ipv4 addresses = %s", tmp_char);
139 inet_aton(tmp_char,&(data_res->v4.ip));
140 }
141 tmp_char = strsep(&addresses, addresses_separator);
142 if(tmp_char != NULL)
143 {
144 LYINFLOG("ipv6 addresses = %s", tmp_char);
145 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
146 }
147 //get dnses
148 tmp_char = strsep(&dnses, dnses_separator);
149 if(tmp_char != NULL)
150 {
151 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
152 inet_aton(tmp_char,&(data_res->v4.pri_dns));
153 }
154 tmp_char = strsep(&dnses, dnses_separator);
155 if(tmp_char != NULL)
156 {
157 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
158 inet_aton(tmp_char, &(data_res->v4.sec_dns));
159 }
160 tmp_char = strsep(&dnses, dnses_separator);
161 if(tmp_char != NULL)
162 {
163 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
164 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
165 }
166 tmp_char = strsep(&dnses, dnses_separator);
167 if(tmp_char != NULL)
168 {
169 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
170 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
171 }
172 //get gateway
173 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
174
xf.li2fc84552023-06-23 05:26:47 -0700175 return ;
176}
177
178void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
179{
xf.li3c0a4752023-09-03 20:46:19 -0700180#ifdef MOBILETEK_TARGET_PLATFORM_T106
181 char *tmp_char = NULL;
182 char *addresses = NULL;
183 char *dnses = NULL;
184 const char addresses_separator[2] = "/";
185 const char dnses_separator[2] = " ";
186
187 addresses = libdata->addresses;
188 dnses = libdata->dnses;
189 //get addresses
190 tmp_char = strsep(&addresses, addresses_separator);
191 if(tmp_char != NULL)
192 {
193 LYINFLOG("ipv4 addresses = %s", tmp_char);
194 inet_aton(tmp_char,&(data_res->v4.addr.ip));
195 }
196 //get dnses
197 tmp_char = strsep(&dnses, dnses_separator);
198 if(tmp_char != NULL)
199 {
200 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
201 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
202 }
203 tmp_char = strsep(&dnses, dnses_separator);
204 if(tmp_char != NULL)
205 {
206 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
207 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
208 }
209 //get gateway
210 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
211 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
212
213 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
214 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
215 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
216#else
xf.li2fc84552023-06-23 05:26:47 -0700217 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
218 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
219 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
220 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700221#endif
xf.li2fc84552023-06-23 05:26:47 -0700222 data_res->v4.stats.pkts_tx = 0;
223 data_res->v4.stats.pkts_rx = 0;
224 data_res->v4.stats.bytes_tx = 0;
225 data_res->v4.stats.bytes_rx = 0;
226 data_res->v4.stats.pkts_dropped_tx = 0;
227 data_res->v4.stats.pkts_dropped_rx = 0;
228 return ;
229}
230
231void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
232{
xf.li3c0a4752023-09-03 20:46:19 -0700233#ifdef MOBILETEK_TARGET_PLATFORM_T106
234 char *tmp_char = NULL;
235 char *addresses = NULL;
236 char *dnses = NULL;
237 const char addresses_separator[2] = "/";
238 const char dnses_separator[2] = " ";
239
240 addresses = libdata->addresses;
241 dnses = libdata->dnses;
242 //get addresses
243 tmp_char = strsep(&addresses, addresses_separator);
244 if(tmp_char != NULL)
245 {
246 LYINFLOG("ipv6 addresses = %s", tmp_char);
247 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
248 }
249 //get dnses
250 tmp_char = strsep(&dnses, dnses_separator);
251 if(tmp_char != NULL)
252 {
253 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
254 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
255 }
256 tmp_char = strsep(&dnses, dnses_separator);
257 if(tmp_char != NULL)
258 {
259 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
260 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
261 }
262 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
263#else
xf.li2fc84552023-06-23 05:26:47 -0700264 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
265 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
266 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
267 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700268#endif
269 data_res->v6.stats.pkts_tx = 0;
270 data_res->v6.stats.pkts_rx = 0;
271 data_res->v6.stats.bytes_tx = 0;
272 data_res->v6.stats.bytes_rx = 0;
273 data_res->v6.stats.pkts_dropped_tx = 0;
274 data_res->v6.stats.pkts_dropped_rx = 0;
275 return ;
276}
277void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
278{
279 char *tmp_char = NULL;
280 char *addresses = NULL;
281 char *dnses = NULL;
282 const char addresses_separator[2] = "/";
283 const char dnses_separator[2] = " ";
284
285 char buf_ip[64] = {0};
286 char buf_gateway[64] = {0};
287 char buf_pri_dns[64] = {0};
288 char buf_sec_dns[64] = {0};
289
290 addresses = libdata->addresses;
291 dnses = libdata->dnses;
292 //get addresses
293 tmp_char = strsep(&addresses, addresses_separator);
294 if(tmp_char != NULL)
295 {
296 LYINFLOG("ipv4 addresses = %s", tmp_char);
297 inet_aton(tmp_char,&(data_res->v4.addr.ip));
298 }
299 tmp_char = strsep(&addresses, addresses_separator);
300 if(tmp_char != NULL)
301 {
302 LYINFLOG("ipv6 addresses = %s", tmp_char);
303 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
304 }
305 //get dnses
306 tmp_char = strsep(&dnses, dnses_separator);
307 if(tmp_char != NULL)
308 {
309 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
310 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
311 }
312 tmp_char = strsep(&dnses, dnses_separator);
313 if(tmp_char != NULL)
314 {
315 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
316 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
317 }
318 tmp_char = strsep(&dnses, dnses_separator);
319 if(tmp_char != NULL)
320 {
321 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
322 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
323 }
324 tmp_char = strsep(&dnses, dnses_separator);
325 if(tmp_char != NULL)
326 {
327 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
328 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
329 }
330 //get gateway
331 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
332
333 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
334 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
335 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
336
337 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
338 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
339 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
340 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
341 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
342 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
343 data_res->v4.stats.pkts_tx = 0;
344 data_res->v4.stats.pkts_rx = 0;
345 data_res->v4.stats.bytes_tx = 0;
346 data_res->v4.stats.bytes_rx = 0;
347 data_res->v4.stats.pkts_dropped_tx = 0;
348 data_res->v4.stats.pkts_dropped_rx = 0;
349
xf.li2fc84552023-06-23 05:26:47 -0700350 data_res->v6.stats.pkts_tx = 0;
351 data_res->v6.stats.pkts_rx = 0;
352 data_res->v6.stats.bytes_tx = 0;
353 data_res->v6.stats.bytes_rx = 0;
354 data_res->v6.stats.pkts_dropped_tx = 0;
355 data_res->v6.stats.pkts_dropped_rx = 0;
356 return ;
357}
358
359void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
360{
xf.lib5dc0632023-11-30 18:20:35 -0800361 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700362 {
363 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
364 data_res->v4.reconnect = 1;
365 }
366 else
367 {
368 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
369 data_res->v4.reconnect = 0;
370 }
371 return ;
372}
373
374void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
375{
xf.lib5dc0632023-11-30 18:20:35 -0800376 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700377 {
378 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
379 data_res->v6.reconnect = 1;
380 }
381 else
382 {
383 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
384 data_res->v6.reconnect = 0;
385 }
386 return ;
387}
388
xf.li0fd6acf2023-12-20 18:16:34 -0800389int apn_xml_handle_get_profile(int handle, unsigned char *profile_idx)
390{
391 //xmlDocPtr apn_table_xml_pdoc = NULL;
392 xmlNodePtr node = NULL;
393 xmlNodePtr modify_node = NULL;
394 unsigned char temp = NULL;
395 //apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
396 if(NULL == apn_table_xml_pdoc)
397 {
398 LYERRLOG("open xml file error");
399 goto FAILED;
400 }
401
402 node = xmlDocGetRootElement(apn_table_xml_pdoc);
403 if (NULL == node)
404 {
405 LYERRLOG("xmlDocGetRootElement() error");
406 goto FAILED;
407 }
408 modify_node = node->xmlChildrenNode;
409 if(modify_node != NULL)
410 {
411 modify_node = modify_node->next;
412 }
413 else
414 {
415 LYERRLOG("modify_node is null\n");
416 goto FAILED;
417 }
418 for (;;)
419 {
420 if(modify_node == NULL)
421 {
422 LYERRLOG("modify_node is null\n");
423 goto FAILED;
424 }
425 if (xmlGetProp(modify_node, "handle") == NULL) //Null Node
426 {
427 modify_node = modify_node->next;
428 continue;
429 }
430 else if((int)atoi(xmlGetProp(modify_node, "handle")) == handle)
431 {
432 break;
433 }
434 modify_node = modify_node->next;
435 }
436 if(modify_node == NULL)
437 {
438 LYERRLOG("modify_node is null\n");
439 goto FAILED;
440 }
441 *profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx"));
442 //xmlFreeDoc(apn_table_xml_pdoc);
443 return RESULT_OK;
444
445 FAILED:
446 // if (apn_table_xml_pdoc)
447 // {
448 // xmlFreeDoc(apn_table_xml_pdoc);
449 // }
450 return RESULT_ERROR;
451}
452int apn_xml_handle_set(unsigned char profile_idx, int handle)
453{
454 int node_num = 0;
455 char temp_buff[12];
456 //xmlDocPtr apn_table_xml_pdoc = NULL;
457 xmlNodePtr node = NULL;
458 xmlNodePtr modify_node = NULL;
459 xmlNodePtr check_node = NULL;
460 //apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
461 if(NULL == apn_table_xml_pdoc)
462 {
463 LYERRLOG("open xml file error");
464 goto FAILED;
465 }
466 node = xmlDocGetRootElement(apn_table_xml_pdoc);
467 if (NULL == node)
468 {
469 LYERRLOG("xmlDocGetRootElement() error");
470 goto FAILED;
471 }
472 modify_node = node->xmlChildrenNode;
473 if(modify_node != NULL)
474 {
475 modify_node = modify_node->next;
476 }
477 else
478 {
479 LYERRLOG("modify_node is null\n");
480 goto FAILED;
481 }
482 for (;;)
483 {
484 if(modify_node == NULL)
485 {
486 LYERRLOG("modify_node is null\n");
487 goto FAILED;
488 }
489 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
490 {
491 modify_node = modify_node->next;
492 node_num--;
493 continue;
494 }
495 else if((int)atoi(xmlGetProp(modify_node, "profile_idx")) == (int)profile_idx)
496 {
497 break;
498 }
499 modify_node = modify_node->next;
500 }
501 if(modify_node == NULL)
502 {
503 LYERRLOG("modify_node is null\n");
504 goto FAILED;
505 }
506 bzero(temp_buff,12);
507 snprintf(temp_buff,sizeof(temp_buff),"%d",handle);
508 xmlSetProp(modify_node,BAD_CAST"handle",(xmlChar *)temp_buff);
509 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
510 //xmlFreeDoc(apn_table_xml_pdoc);
511 return RESULT_OK;
512
513 FAILED:
514 // if (apn_table_xml_pdoc)
515 // {
516 // xmlFreeDoc(apn_table_xml_pdoc);
517 // }
518 return RESULT_ERROR;
519}
520int apn_xml_handle_get(unsigned char profile_idx, int *handle)
521{
522 int node_num = 0;
523 //xmlDocPtr apn_table_xml_pdoc = NULL;
524 xmlNodePtr node = NULL;
525 xmlNodePtr modify_node = NULL;
526 unsigned char temp = NULL;
527 //apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
528 if(NULL == apn_table_xml_pdoc)
529 {
530 LYERRLOG("open xml file error");
531 goto FAILED;
532 }
533
534 node = xmlDocGetRootElement(apn_table_xml_pdoc);
535 if (NULL == node)
536 {
537 LYERRLOG("xmlDocGetRootElement() error");
538 goto FAILED;
539 }
540 modify_node = node->xmlChildrenNode;
541 if(modify_node != NULL)
542 {
543 modify_node = modify_node->next;
544 }
545 else
546 {
547 LYERRLOG("modify_node is null\n");
548 goto FAILED;
549 }
550 LYINFLOG("profile_idx is %d\n", (int)profile_idx);
551 for (;;)
552 {
553 if(modify_node == NULL)
554 {
555 LYERRLOG("modify_node is null\n");
556 goto FAILED;
557 }
558 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
559 {
560 modify_node = modify_node->next;
561 node_num--;
562 continue;
563 }
564 else if((int)atoi(xmlGetProp(modify_node, "profile_idx")) == (int)profile_idx)
565 {
566 break;
567 }
568 modify_node = modify_node->next;
569 }
570 if(modify_node == NULL)
571 {
572 LYERRLOG("modify_node is null\n");
573 goto FAILED;
574 }
575 *handle = (int)atoi(xmlGetProp(modify_node, "handle"));
576 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
577 //xmlFreeDoc(apn_table_xml_pdoc);
578 return RESULT_OK;
579
580 FAILED:
581 // if (apn_table_xml_pdoc)
582 // {
583 // xmlFreeDoc(apn_table_xml_pdoc);
584 // }
585 return RESULT_ERROR;
586}
xf.li2fc84552023-06-23 05:26:47 -0700587
588int apn_xml_add(qser_apn_add_s *apn,unsigned char *apn_num)
589{
590 int node_num = 0;
591 char temp_buff[12];
xf.li0fd6acf2023-12-20 18:16:34 -0800592 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.lie3f55f42023-12-01 22:47:33 -0800593 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700594 xmlNodePtr node = NULL;
595 xmlNodePtr tmp_node = NULL;
596 xmlNodePtr sum_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800597
598// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
599 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700600 {
601 LYERRLOG("open xml file error");
602 goto FAILED;
603 }
604
xf.lie3f55f42023-12-01 22:47:33 -0800605 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700606 if (NULL == node)
607 {
608 LYERRLOG("xmlDocGetRootElement() error");
609 goto FAILED;
610 }
611 sum_node = node->xmlChildrenNode;
612 sum_node = sum_node->next;
613 while (sum_node != NULL)
614 {
615 if (xmlGetProp(sum_node, "profile_idx") == NULL) //Null Node
616 {
617 sum_node = sum_node->next;
618 continue;
619 }
xf.lif7c68e32023-10-10 23:18:42 -0700620 else if(strcmp((char *)xmlGetProp(sum_node, "apn_type"), apn->apn_type) == 0)
621 {
622 LYERRLOG("apntype already exists\n");
623 goto FAILED;
624 }
xf.li2fc84552023-06-23 05:26:47 -0700625 node_num++;
626 sum_node = sum_node->next;
627 }
xf.li3f891cb2023-08-23 23:11:24 -0700628 LYINFLOG("apn_num = %d ",node_num);
629 if(node_num >= QSER_APN_MAX_LIST)
630 {
631 LYERRLOG("apn num reached the max");
632 goto FAILED;
633 }
xf.li2fc84552023-06-23 05:26:47 -0700634 tmp_node = xmlNewNode(NULL,BAD_CAST"apn");
635 *apn_num = node_num;
xf.li2fc84552023-06-23 05:26:47 -0700636 bzero(temp_buff,12);
637 snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num);
638 xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
639 bzero(temp_buff,12);
640 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
641 xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
642 bzero(temp_buff,12);
643 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
644 xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
645 xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
646 xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username);
647 xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password);
648 xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
xf.li0fd6acf2023-12-20 18:16:34 -0800649 bzero(temp_buff,12);
650 snprintf(temp_buff,sizeof(temp_buff),"%d",default_handle);
651 xmlNewProp(tmp_node,BAD_CAST"handle",(xmlChar *)temp_buff);
xf.li2fc84552023-06-23 05:26:47 -0700652 xmlAddChild(node,tmp_node);
xf.lie3f55f42023-12-01 22:47:33 -0800653 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
654
655// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700656 return RESULT_OK;
657
658 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800659 /* if (apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700660 {
xf.lie3f55f42023-12-01 22:47:33 -0800661 xmlFreeDoc(apn_table_xml_pdoc);
662 }*/
xf.li2fc84552023-06-23 05:26:47 -0700663 return RESULT_ERROR;
664}
665
666int apn_xml_delete(unsigned char profile_idx)
667{
668 int node_num = 0;
669 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800670 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700671 xmlNodePtr node = NULL;
672 xmlNodePtr modify_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800673 // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
674 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700675 {
676 LYERRLOG("open xml file error");
677 goto FAILED;
678 }
679
xf.lie3f55f42023-12-01 22:47:33 -0800680 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700681 if (NULL == node)
682 {
683 LYERRLOG("xmlDocGetRootElement() error");
684 goto FAILED;
685 }
686 modify_node = node->xmlChildrenNode;
xf.li029a9e72023-11-04 02:29:45 -0700687 if(modify_node != NULL)
688 {
689 modify_node = modify_node->next;
690 }
691 else
692 {
693 LYERRLOG("modify_node is null\n");
694 goto FAILED;
695 }
xf.li2fc84552023-06-23 05:26:47 -0700696 for (node_num=0 ;node_num<(int)profile_idx ; node_num++)
697 {
xf.li029a9e72023-11-04 02:29:45 -0700698 if(modify_node == NULL)
699 {
700 LYERRLOG("modify_node is null\n");
701 goto FAILED;
702 }
xf.li2fc84552023-06-23 05:26:47 -0700703 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
704 {
705 modify_node = modify_node->next;
706 node_num--;
707 continue;
708 }
709 modify_node = modify_node->next;
710 }
xf.li029a9e72023-11-04 02:29:45 -0700711 if(modify_node == NULL)
712 {
713 LYERRLOG("modify_node is null\n");
714 goto FAILED;
715 }
xf.li2fc84552023-06-23 05:26:47 -0700716 xmlUnlinkNode(modify_node);
717 xmlFreeNode(modify_node);
718 modify_node = NULL;
719 node_num = 0;
720 modify_node = node->xmlChildrenNode;
721 modify_node = modify_node->next;
722 while (modify_node != NULL)
723 {
724 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
725 {
726 modify_node = modify_node->next;
727 continue;
728 }
729 bzero(temp_buff,12);
730 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
731 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
732 modify_node = modify_node->next;
733 node_num++;
734 }
xf.lie3f55f42023-12-01 22:47:33 -0800735 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
736// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700737 return RESULT_OK;
738
739 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800740 // if (apn_table_xml_pdoc)
741 // {
742 // xmlFreeDoc(apn_table_xml_pdoc);
743 // }
xf.li2fc84552023-06-23 05:26:47 -0700744 return RESULT_ERROR;
745}
746
747int apn_xml_modify(qser_apn_info_s *apn)
748{
749 int node_num = 0;
750 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800751 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700752 xmlNodePtr node = NULL;
753 xmlNodePtr modify_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800754// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
755 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700756 {
757 LYERRLOG("open xml file error");
758 goto FAILED;
759 }
760
xf.lie3f55f42023-12-01 22:47:33 -0800761 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700762 if (NULL == node)
763 {
764 LYERRLOG("xmlDocGetRootElement() error");
765 goto FAILED;
766 }
767 modify_node = node->xmlChildrenNode;
xf.lifb8bf042023-12-13 18:09:49 -0800768 if(modify_node != NULL)
769 {
770 modify_node = modify_node->next;
771 }
772 else
773 {
774 LYERRLOG("modify_node is null\n");
775 goto FAILED;
776 }
xf.li2fc84552023-06-23 05:26:47 -0700777 for (node_num=0; node_num<(int)apn->profile_idx;node_num++)
778 {
xf.lifb8bf042023-12-13 18:09:49 -0800779 if(modify_node == NULL)
780 {
781 LYERRLOG("modify_node is null\n");
782 goto FAILED;
783 }
xf.li2fc84552023-06-23 05:26:47 -0700784 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
785 {
786 modify_node = modify_node->next;
787 node_num--;
788 continue;
789 }
790 modify_node = modify_node->next;
791 }
xf.lifb8bf042023-12-13 18:09:49 -0800792 if(modify_node == NULL)
793 {
794 LYERRLOG("modify_node is null\n");
795 goto FAILED;
796 }
xf.li2fc84552023-06-23 05:26:47 -0700797 bzero(temp_buff,12);
798 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
799 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
800 bzero(temp_buff,12);
801 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
802 xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
803 bzero(temp_buff,12);
804 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
805 xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
806 xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
807 xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username);
808 xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password);
809 xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
xf.lie3f55f42023-12-01 22:47:33 -0800810 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
811// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700812 return RESULT_OK;
813
814 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800815 // if (apn_table_xml_pdoc)
816 // {
817 // xmlFreeDoc(apn_table_xml_pdoc);
818 // }
xf.li2fc84552023-06-23 05:26:47 -0700819 return RESULT_ERROR;
820}
821
822
823int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn)
824{
825 int node_num = 0;
xf.lie3f55f42023-12-01 22:47:33 -0800826 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700827 xmlNodePtr node = NULL;
828 xmlNodePtr modify_node = NULL;
829 unsigned char temp = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800830// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
831 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700832 {
833 LYERRLOG("open xml file error");
834 goto FAILED;
835 }
836
xf.lie3f55f42023-12-01 22:47:33 -0800837 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700838 if (NULL == node)
839 {
840 LYERRLOG("xmlDocGetRootElement() error");
841 goto FAILED;
842 }
843 modify_node = node->xmlChildrenNode;
xf.libf9df4c2023-07-02 02:42:35 -0700844 if(modify_node != NULL)
xf.li2fc84552023-06-23 05:26:47 -0700845 {
xf.libf9df4c2023-07-02 02:42:35 -0700846 modify_node = modify_node->next;
847 }
848 else
849 {
850 LYERRLOG("modify_node is null\n");
851 goto FAILED;
852 }
853 LYINFLOG("profile_idx is %d\n", (int)profile_idx);
854 for (node_num = 0;(node_num<(int)profile_idx);node_num++)
855 {
856 if(modify_node == NULL)
857 {
858 LYERRLOG("modify_node is null\n");
859 goto FAILED;
860 }
xf.li2fc84552023-06-23 05:26:47 -0700861 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
862 {
863 modify_node = modify_node->next;
864 node_num--;
865 continue;
866 }
867 modify_node = modify_node->next;
xf.li029a9e72023-11-04 02:29:45 -0700868 }
869 if(modify_node == NULL)
870 {
871 LYERRLOG("modify_node is null\n");
872 goto FAILED;
xf.li2fc84552023-06-23 05:26:47 -0700873 }
874 apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx"));
875 apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
876 apn->auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto"));
xf.li6c7e3972023-10-27 20:01:59 -0700877 strncpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
878 strncpy(apn->username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
879 strncpy(apn->password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
880 strncpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE);
xf.lie3f55f42023-12-01 22:47:33 -0800881// xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
882// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700883 return RESULT_OK;
884
885 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800886 // if (apn_table_xml_pdoc)
887 // {
888 // xmlFreeDoc(apn_table_xml_pdoc);
889 // }
xf.li2fc84552023-06-23 05:26:47 -0700890 return RESULT_ERROR;
891}
892
893int apn_xml_query_list(qser_apn_info_list_s *apn_list)
894{
895 int node_num = 0;
xf.lie3f55f42023-12-01 22:47:33 -0800896 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700897 xmlNodePtr node = NULL;
898 xmlNodePtr modify_node = NULL;
899 xmlChar *temp_char;
900 char temp[64];
xf.lie3f55f42023-12-01 22:47:33 -0800901// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
902 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700903 {
904 LYERRLOG("open xml file error");
905 goto FAILED;
906 }
907
xf.lie3f55f42023-12-01 22:47:33 -0800908 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700909 if (NULL == node)
910 {
911 LYERRLOG("xmlDocGetRootElement() error");
912 goto FAILED;
913 }
914 modify_node = node->xmlChildrenNode;
915 modify_node = modify_node->next;
916 while (modify_node != NULL)
917 {
918 temp_char = xmlGetProp(modify_node, "profile_idx");
919 if (temp_char == NULL)
920 {
921 modify_node = modify_node->next;
922 continue;
923 }
924 sprintf(temp,"%s",temp_char);
925 apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp);
926 apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
927 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 -0700928 strncpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
929 strncpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
930 strncpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
931 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 -0700932 node_num ++;
933 modify_node = modify_node->next;
934 }
935 apn_list->cnt = node_num;
xf.lie3f55f42023-12-01 22:47:33 -0800936// xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
937// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700938 return RESULT_OK;
939
940 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800941 // if (apn_table_xml_pdoc)
942 // {
943 // xmlFreeDoc(apn_table_xml_pdoc);
944 // }
xf.li2fc84552023-06-23 05:26:47 -0700945 return RESULT_ERROR;
946}
947
948void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
949{
950 switch (pdp_type)
951 {
952 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -0800953#ifdef MOBILETEK_TARGET_PLATFORM_T106
954 strcpy(out_pdp_type,"IP");
955#else
xf.li2fc84552023-06-23 05:26:47 -0700956 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -0800957#endif
xf.li2fc84552023-06-23 05:26:47 -0700958 break;
959 case QSER_APN_PDP_TYPE_PPP:
960 strcpy(out_pdp_type,"PPP");
961 break;
962 case QSER_APN_PDP_TYPE_IPV6:
963 strcpy(out_pdp_type,"IPV6");
964 break;
965 case QSER_APN_PDP_TYPE_IPV4V6:
966 strcpy(out_pdp_type,"IPV4V6");
967 break;
968 default:
969 strcpy(out_pdp_type,"NULL");
970 break;
971 }
972 return;
973}
974void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
975{
976 switch (auth_proto)
977 {
978 case QSER_APN_AUTH_PROTO_DEFAULT:
979 strcpy(out_proto,"NULL;authType=0");
980 break;
981 case QSER_APN_AUTH_PROTO_NONE:
982 strcpy(out_proto,"NULL;authType=1");
983 break;
984 case QSER_APN_AUTH_PROTO_PAP:
985 strcpy(out_proto,"NULL;authType=2");
986 break;
987 case QSER_APN_AUTH_PROTO_CHAP:
988 strcpy(out_proto,"NULL;authtype=3");
989 break;
990 case QSER_APN_AUTH_PROTO_PAP_CHAP:
991 strcpy(out_proto,"NULL;authtype=4");
992 break;
993 default:
994 strcpy(out_proto,"NULL;authType=NULL");
995 break;
996 }
997 return ;
998}
999
1000int data_call_handle_get(const char profile_idx,int *handle)
1001{
1002 int num = LYNQ_APN_CHANNEL_MAX;
1003 int table_num = 0;
1004 lynq_apn_info **apn_table = NULL;
1005 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001006 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001007 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1008 if (NULL == apn_table)
1009 {
1010 LYERRLOG("malloc apn_table fail ");
1011 return RESULT_ERROR;
1012 }
1013 for(int i =0;i<10;i++)
1014 {
1015 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1016 if (apn_table[i]==NULL)
1017 {
1018 for (int n=0;n<i;n++)
1019 {
1020 free(apn_table[n]);
1021 }
1022 return RESULT_ERROR;
1023 }
1024 memset(apn_table[i],0,sizeof(lynq_apn_info));
1025 }
1026 lynq_get_apn_table(&table_num,apn_table);
1027 memset(&apn,0,sizeof(qser_apn_info_s));
xf.li0fc26502023-09-16 02:10:17 -07001028 ret = apn_xml_query(profile_idx,&apn);
1029 if (ret < 0)
1030 {
1031 LYERRLOG("apn_xml_query error");
1032 return ret;
1033 }
xf.li2fc84552023-06-23 05:26:47 -07001034 for (int j = 0;j < table_num;j++)
1035 {
1036 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1037 {
1038 *handle = apn_table[j]->index;
1039 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1040 break;
1041 }
1042 }
1043
1044 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1045 {
1046 if (apn_table[i]!=NULL)
1047 {
1048 free(apn_table[i]);
1049 apn_table[i]=NULL;
1050 }
1051 }
1052 free(apn_table);
1053 apn_table=NULL;
1054 LYINFLOG("data_call_handle_get end");
1055 return RESULT_OK;
1056}
1057
1058void *thread_wait_cb_status(void)
1059{
1060 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001061 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001062 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001063 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001064 qser_data_call_state_s data_cb_state;
1065 while (s_qser_data_cb_thread_status)
1066 {
xf.li6b0d8502023-09-04 18:49:12 -07001067 ret = lynq_wait_data_call_state_change(&handle);
1068 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
1069 if(s_qser_data_cb_thread_status == 0)
1070 {
1071 return NULL;
1072 }
1073 else if(ret < 0)
1074 {
1075 continue;
1076 }
xf.li8535bc02023-12-12 23:28:35 -08001077 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
1078 memset(&data_urc_info, 0, sizeof(data_urc_info));
1079 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001080 lynq_get_data_call_list(&handle,&data_urc_info);
1081 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001082 //data_cb_state.profile_idx = (char)handle;
1083 apn_xml_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li8535bc02023-12-12 23:28:35 -08001084 LYINFLOG("[thread_wait_cb_status]: status=%d, suggestedRetryTime=%d, cid=%d, active=%d, type=%s, ifname=%s, addresses=%s, dnses=%s, gateways=%s, pcscf=%s, mtu=%d\n",
1085 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
1086 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
1087 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -07001088 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001089 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001090 {
1091 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1092 }
1093 else if (!strcmp(data_urc_info.type,"IPV6"))
1094 {
1095 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1096 }
xf.li8535bc02023-12-12 23:28:35 -08001097 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001098 {
1099 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1100 }
1101 else
1102 {
xf.li8535bc02023-12-12 23:28:35 -08001103 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001104 }
1105
xf.li8535bc02023-12-12 23:28:35 -08001106 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001107 {
1108 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1109 }
1110 else
1111 {
1112 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.li0fd6acf2023-12-20 18:16:34 -08001113 ret = apn_xml_handle_set(data_cb_state.profile_idx, default_handle);
1114 if(ret != 0)
1115 {
1116 LYERRLOG("handle set error");
1117 }
xf.li2fc84552023-06-23 05:26:47 -07001118 }
1119 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1120 {
1121 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1122 }
1123 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1124 {
1125 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1126 }
1127 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1128 {
xf.li3c0a4752023-09-03 20:46:19 -07001129#ifdef MOBILETEK_TARGET_PLATFORM_T106
1130 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1131#else
xf.li2fc84552023-06-23 05:26:47 -07001132 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001133#endif
xf.li2fc84552023-06-23 05:26:47 -07001134 }
1135 else
1136 {
1137 LYERRLOG("unknow ip_family");
1138 continue;
1139 }
1140 if (s_data_call_cb != NULL)
1141 {
1142 s_data_call_cb(&data_cb_state);
1143 }
1144 }
1145 return NULL;
1146}
1147
1148int qser_cb_pthread_create()
1149{
1150 int ret;
1151 s_qser_data_cb_thread_status = 1;
1152 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
1153 if (ret < 0)
1154 {
1155 LYERRLOG("pthread create fail");
1156 s_qser_data_cb_thread_status = 0;
1157 return RESULT_ERROR;
1158 }
1159 return RESULT_OK;
1160}
1161
1162void qser_cb_pthread_cancel()
1163{
xf.li2fc84552023-06-23 05:26:47 -07001164 s_qser_data_cb_thread_status = 0;
1165 if (s_cb_tid != -1)
1166 {
xf.li6b0d8502023-09-04 18:49:12 -07001167 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001168 }
1169 return;
1170}
xf.li7b0bfd02023-08-03 01:11:52 -07001171int check_xml_file(const char *file)
1172{
1173 /* Check for existence */
1174 if((access(file, F_OK)) == -1)
1175 {
1176 LYERRLOG("no such xml file.\n");
1177 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
1178 }
1179
1180 if((access(file, F_OK)) == -1)
1181 {
1182 LYERRLOG("error copy xml file.\n");
1183 return -1;
1184 }
1185 return RESULT_OK;
1186}
xf.li2fc84552023-06-23 05:26:47 -07001187
1188int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1189{
1190 int ret = 0;
1191 int utoken = 0;
1192 if (NULL == evt_cb)
1193 {
1194 LYERRLOG("init incoming paramters error");
1195 return RESULT_ERROR;
1196 }
xf.li7b0bfd02023-08-03 01:11:52 -07001197
1198 ret = check_xml_file(data_xml_path);
1199 if (ret != RESULT_OK)
1200 {
1201 LYERRLOG("check xml file error");
1202 return RESULT_ERROR;
1203 }
1204
xf.li2fc84552023-06-23 05:26:47 -07001205 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -07001206
xf.li2fc84552023-06-23 05:26:47 -07001207 ret = lynq_init_data(utoken);
1208 if (ret != RESULT_OK)
1209 {
xf.li6b0d8502023-09-04 18:49:12 -07001210 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001211 s_data_call_cb = NULL;
1212 return RESULT_ERROR;
1213 }
xf.li6b0d8502023-09-04 18:49:12 -07001214 qser_cb_pthread_create();
xf.lie3f55f42023-12-01 22:47:33 -08001215 apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
1216 if(NULL == apn_table_xml_pdoc)
1217 {
1218 LYERRLOG("open xml file error");
1219 return RESULT_ERROR;
1220 }
xf.lib33d4862023-12-13 00:40:37 -08001221 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001222 return RESULT_OK;
1223}
1224
1225void qser_data_call_destroy(void)
1226{
xf.li6b0d8502023-09-04 18:49:12 -07001227 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.lie3f55f42023-12-01 22:47:33 -08001228 if(apn_table_xml_pdoc)
1229 {
1230 xmlFreeDoc(apn_table_xml_pdoc);
1231 }
xf.li2fc84552023-06-23 05:26:47 -07001232 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001233 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001234 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001235 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001236 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001237 return ;
1238}
1239
1240int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1241{
1242 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001243 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001244 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001245 if(g_lynq_qser_data_init_flag == 0)
1246 {
1247 if(err != NULL)
1248 {
1249 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1250 }
1251 return LYNQ_E_NO_INIT;
1252 }
xf.li2fc84552023-06-23 05:26:47 -07001253 if (NULL == data_call || NULL == err)
1254 {
1255 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001256 if(err != NULL)
1257 {
1258 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1259 }
xf.li2fc84552023-06-23 05:26:47 -07001260 return ret;
1261 }
1262 if (data_call->profile_idx == 0)
1263 {
1264 ret = lynq_setup_data_call(&handle);
1265 }
1266 else
1267 {
1268 char pdptype[16];
1269 qser_apn_info_s apn_info;
xf.li0fc26502023-09-16 02:10:17 -07001270 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1271 if (ret != 0)
1272 {
1273 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001274 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001275 return ret;
1276 }
xf.li2fc84552023-06-23 05:26:47 -07001277 judge_pdp_type(apn_info.pdp_type,pdptype);
1278 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1279 }
xf.lic12b3702023-11-22 22:39:01 -08001280 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001281 {
1282 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1283 }
xf.li0fd6acf2023-12-20 18:16:34 -08001284 else
1285 {
1286 error = apn_xml_handle_set(data_call->profile_idx, handle);
1287 if(error != 0)
1288 {
1289 LYERRLOG("handle set error");
1290 }
1291 }
xf.li2fc84552023-06-23 05:26:47 -07001292 return ret;
1293}
1294
xf.li8535bc02023-12-12 23:28:35 -08001295int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1296{
1297 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001298 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001299 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001300 if(g_lynq_qser_data_init_flag == 0)
1301 {
1302 if(err != NULL)
1303 {
1304 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1305 }
1306 return LYNQ_E_NO_INIT;
1307 }
xf.li8535bc02023-12-12 23:28:35 -08001308 if (NULL == data_call || NULL == err)
1309 {
1310 LYERRLOG("call start incoming paramters error");
1311 if(err != NULL)
1312 {
1313 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1314 }
1315 return ret;
1316 }
1317 if (data_call->profile_idx == 0)
1318 {
1319 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1320 }
1321 else
1322 {
1323 char pdptype[16];
1324 qser_apn_info_s apn_info;
1325 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1326 if (ret != 0)
1327 {
1328 LYERRLOG("qser_apn_get error");
1329 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1330 return ret;
1331 }
1332 judge_pdp_type(apn_info.pdp_type,pdptype);
1333 ret = lynq_setup_data_call_sp_t106_async(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1334 }
1335 if (ret != 0)
1336 {
1337 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1338 }
xf.li0fd6acf2023-12-20 18:16:34 -08001339 else
1340 {
1341 error = apn_xml_handle_set(data_call->profile_idx, handle);
1342 if(error != 0)
1343 {
1344 LYERRLOG("handle set error");
1345 }
1346 }
xf.li8535bc02023-12-12 23:28:35 -08001347 return ret;
1348}
1349
xf.li2fc84552023-06-23 05:26:47 -07001350int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1351{
1352 int ret = 0;
1353 int handle = -1;
1354
xf.lib33d4862023-12-13 00:40:37 -08001355 if(g_lynq_qser_data_init_flag == 0)
1356 {
1357 if(err != NULL)
1358 {
1359 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1360 }
1361 return LYNQ_E_NO_INIT;
1362 }
xf.li2fc84552023-06-23 05:26:47 -07001363 if (NULL == err)
1364 {
1365 LYERRLOG("call stop incoming paramters error");
1366 return ret;
1367 }
xf.lic12b3702023-11-22 22:39:01 -08001368 ret = data_call_handle_get(profile_idx,&handle);
1369 if(ret != 0)
1370 {
1371 LYERRLOG("datacall handle get error");
1372 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1373 return ret;
1374 }
xf.li2fc84552023-06-23 05:26:47 -07001375 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001376 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001377 {
1378 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001379 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001380 }
xy.hee2daacc2023-09-18 00:57:51 -07001381 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001382}
1383int 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)
1384{
1385 int ret = 0;
1386 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001387 if(g_lynq_qser_data_init_flag == 0)
1388 {
1389 if(err != NULL)
1390 {
1391 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1392 }
1393 return LYNQ_E_NO_INIT;
1394 }
xf.li2fc84552023-06-23 05:26:47 -07001395 lynq_data_call_response_v11_t data_call_info;
1396 data_call_handle_get(profile_idx,&handle);
1397 ret = lynq_get_data_call_list(&handle,&data_call_info);
1398 if (ret == 0)
1399 {
1400 info->profile_idx = profile_idx;
1401 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001402 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 -07001403 {
1404 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001405 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001406 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1407 lynq_ipv4_aton_getinfo(&data_call_info,info);
1408 }
xf.li3c0a4752023-09-03 20:46:19 -07001409 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001410 {
1411 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001412 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001413 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1414 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1415 }
xf.li3c0a4752023-09-03 20:46:19 -07001416 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001417 {
1418 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001419 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001420 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 -07001421#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001422 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001423#endif
xf.li2fc84552023-06-23 05:26:47 -07001424 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001425 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001426 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 -07001427#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001428 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001429#endif
1430#ifdef MOBILETEK_TARGET_PLATFORM_T106
1431 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1432#endif
xf.li2fc84552023-06-23 05:26:47 -07001433 }
1434 else
1435 {
1436 LYERRLOG("useless qser_data_call_ip_family_e");
1437 }
1438 }
1439 return ret;
1440}
1441int qser_apn_set(qser_apn_info_s *apn)
1442{
1443 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001444 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001445 if(g_lynq_qser_data_init_flag == 0)
1446 {
1447 return LYNQ_E_NO_INIT;
1448 }
xf.li2fc84552023-06-23 05:26:47 -07001449 if (NULL == apn)
1450 {
1451 LYERRLOG("apn set incoming paramters error");
1452 return RESULT_ERROR;
1453 }
xf.li0fd6acf2023-12-20 18:16:34 -08001454 ret = apn_xml_handle_get(apn->profile_idx, &handle);
1455 if(ret != 0)
1456 {
1457 LYERRLOG("handle set error");
1458 }
1459 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1460 {
1461 LYERRLOG("It has setup datacall");
1462 return RESULT_ERROR;
1463 }
xf.li2fc84552023-06-23 05:26:47 -07001464 ret = apn_xml_modify(apn);
1465 if (ret < 0)
1466 {
1467 LYERRLOG("apn_xml_modify error");
1468 return ret;
1469 }
xf.li6c7e3972023-10-27 20:01:59 -07001470#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001471 int apn_id = 0;
1472 char tmp_id[12];
1473 char *outinfo = NULL;
1474 char normalprotocol[16];
1475 char authtype[32];
1476 outinfo = (char *)malloc(sizeof(char)*512);
1477 bzero(tmp_id,12);
1478 bzero(outinfo,512);
1479 apn_id = apn->profile_idx + apndb_offset;
1480 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1481 judge_pdp_type(apn->pdp_type,normalprotocol);
1482 judge_authtype(apn->auth_proto,authtype);
1483 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1484 LYINFLOG("[output]:%s",outinfo);
1485 free(outinfo);
1486 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001487#endif
1488 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001489}
1490
1491int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1492{
xf.lib33d4862023-12-13 00:40:37 -08001493 if(g_lynq_qser_data_init_flag == 0)
1494 {
1495 return LYNQ_E_NO_INIT;
1496 }
xf.li2fc84552023-06-23 05:26:47 -07001497 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
1498 {
1499 LYERRLOG("apn get incoming paramters error");
1500 return RESULT_ERROR;
1501 }
1502 int ret = 0;
1503 ret = apn_xml_query(profile_idx,apn);
1504 if (ret < 0)
1505 {
1506 LYERRLOG("apn_xml_query error");
1507 return ret;
1508 }
1509 return ret;
1510}
1511
1512int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1513{
1514 int ret = 0;
xf.lib33d4862023-12-13 00:40:37 -08001515 if(g_lynq_qser_data_init_flag == 0)
1516 {
1517 return LYNQ_E_NO_INIT;
1518 }
xf.li2fc84552023-06-23 05:26:47 -07001519 if (NULL == apn || NULL == profile_idx)
1520 {
1521 LYERRLOG("apn add incoming paramters error");
1522 return RESULT_ERROR;
1523 }
1524 ret = apn_xml_add(apn,profile_idx);
1525 if (ret < 0)
1526 {
1527 LYERRLOG("apn_xml_add error");
1528 return ret;
1529 }
xf.li6c7e3972023-10-27 20:01:59 -07001530#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001531 int apn_id = 0;
1532 char tmp_id[12];
1533 char *outinfo = NULL;
1534 char normalprotocol[16];
1535 char authtype[32];
1536 outinfo = (char *)malloc(sizeof(char)*512);
1537 bzero(tmp_id,12);
1538 bzero(outinfo,512);
1539 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1540 judge_pdp_type(apn->pdp_type,normalprotocol);
1541 judge_authtype(apn->auth_proto,authtype);
1542 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1543 LYINFLOG("[output]:%s",outinfo);
1544 free(outinfo);
1545 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001546#endif
1547 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001548}
1549
1550int qser_apn_del(unsigned char profile_idx)
1551{
xf.lib33d4862023-12-13 00:40:37 -08001552 if(g_lynq_qser_data_init_flag == 0)
1553 {
1554 return LYNQ_E_NO_INIT;
1555 }
xf.li2fc84552023-06-23 05:26:47 -07001556 if (profile_idx < 0 || profile_idx > 24)
1557 {
1558 LYERRLOG("apn del incoming paramters error");
1559 return RESULT_OK;
1560 }
1561 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001562 int handle = -1;
1563 ret = apn_xml_handle_get(profile_idx, &handle);
1564 if(ret != 0)
1565 {
1566 LYERRLOG("handle set error");
1567 }
1568 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1569 {
1570 LYERRLOG("It has setup datacall");
1571 return RESULT_ERROR;
1572 }
xf.li2fc84552023-06-23 05:26:47 -07001573 ret = apn_xml_delete(profile_idx);
1574 if (ret < 0)
1575 {
1576 LYERRLOG("apn_xml_delete error");
1577 return ret;
1578 }
xf.li6c7e3972023-10-27 20:01:59 -07001579#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001580 int apn_id = 0;
1581 char tmp_id[12];
1582 char *outinfo = NULL;
1583 outinfo = (char *)malloc(sizeof(char)*512);
1584 bzero(tmp_id,12);
1585 bzero(outinfo,512);
1586 apn_id = profile_idx+apndb_offset;
1587 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1588 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1589 LYINFLOG("[output]:%s",outinfo);
1590 free(outinfo);
1591 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001592#endif
xf.li2fc84552023-06-23 05:26:47 -07001593 return ret;
1594}
1595
1596int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1597{
xf.lib33d4862023-12-13 00:40:37 -08001598 if(g_lynq_qser_data_init_flag == 0)
1599 {
1600 return LYNQ_E_NO_INIT;
1601 }
xf.li2fc84552023-06-23 05:26:47 -07001602 if (NULL == apn_list)
1603 {
1604 LYERRLOG("apn_list incoming paramters error");
1605 return RESULT_ERROR;
1606 }
1607 int ret = 0;
1608 ret = apn_xml_query_list(apn_list);
1609 if (ret < 0)
1610 {
1611 LYERRLOG("apn_xml_query_list error");
1612 return ret;
1613 }
1614 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001615}
you.chen21c62b72023-09-08 09:41:11 +08001616
1617DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1618