blob: d1114fcce36644510ae9389e1f07d26cce37c2fb [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 }
414 node_num++;
415 sum_node = sum_node->next;
416 }
xf.li3f891cb2023-08-23 23:11:24 -0700417 LYINFLOG("apn_num = %d ",node_num);
418 if(node_num >= QSER_APN_MAX_LIST)
419 {
420 LYERRLOG("apn num reached the max");
421 goto FAILED;
422 }
xf.li2fc84552023-06-23 05:26:47 -0700423 tmp_node = xmlNewNode(NULL,BAD_CAST"apn");
424 *apn_num = node_num;
xf.li2fc84552023-06-23 05:26:47 -0700425 bzero(temp_buff,12);
426 snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num);
427 xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
428 bzero(temp_buff,12);
429 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
430 xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
431 bzero(temp_buff,12);
432 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
433 xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
434 xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
435 xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username);
436 xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password);
437 xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
438 xmlAddChild(node,tmp_node);
439 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
440 xmlFreeDoc(pdoc);
441 return RESULT_OK;
442
443 FAILED:
444 if (pdoc)
445 {
446 xmlFreeDoc(pdoc);
447 }
448 return RESULT_ERROR;
449}
450
451int apn_xml_delete(unsigned char profile_idx)
452{
453 int node_num = 0;
454 char temp_buff[12];
455 xmlDocPtr pdoc = NULL;
456 xmlNodePtr node = NULL;
457 xmlNodePtr modify_node = NULL;
458 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
459 if(NULL == pdoc)
460 {
461 LYERRLOG("open xml file error");
462 goto FAILED;
463 }
464
465 node = xmlDocGetRootElement(pdoc);
466 if (NULL == node)
467 {
468 LYERRLOG("xmlDocGetRootElement() error");
469 goto FAILED;
470 }
471 modify_node = node->xmlChildrenNode;
472 modify_node = modify_node->next;
473 for (node_num=0 ;node_num<(int)profile_idx ; node_num++)
474 {
475 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
476 {
477 modify_node = modify_node->next;
478 node_num--;
479 continue;
480 }
481 modify_node = modify_node->next;
482 }
483 xmlUnlinkNode(modify_node);
484 xmlFreeNode(modify_node);
485 modify_node = NULL;
486 node_num = 0;
487 modify_node = node->xmlChildrenNode;
488 modify_node = modify_node->next;
489 while (modify_node != NULL)
490 {
491 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
492 {
493 modify_node = modify_node->next;
494 continue;
495 }
496 bzero(temp_buff,12);
497 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
498 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
499 modify_node = modify_node->next;
500 node_num++;
501 }
502 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
503 xmlFreeDoc(pdoc);
504 return RESULT_OK;
505
506 FAILED:
507 if (pdoc)
508 {
509 xmlFreeDoc(pdoc);
510 }
511 return RESULT_ERROR;
512}
513
514int apn_xml_modify(qser_apn_info_s *apn)
515{
516 int node_num = 0;
517 char temp_buff[12];
518 xmlDocPtr pdoc = NULL;
519 xmlNodePtr node = NULL;
520 xmlNodePtr modify_node = NULL;
521 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
522 if(NULL == pdoc)
523 {
524 LYERRLOG("open xml file error");
525 goto FAILED;
526 }
527
528 node = xmlDocGetRootElement(pdoc);
529 if (NULL == node)
530 {
531 LYERRLOG("xmlDocGetRootElement() error");
532 goto FAILED;
533 }
534 modify_node = node->xmlChildrenNode;
535 modify_node = modify_node->next;
536 for (node_num=0; node_num<(int)apn->profile_idx;node_num++)
537 {
538 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
539 {
540 modify_node = modify_node->next;
541 node_num--;
542 continue;
543 }
544 modify_node = modify_node->next;
545 }
546 bzero(temp_buff,12);
547 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
548 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
549 bzero(temp_buff,12);
550 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
551 xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
552 bzero(temp_buff,12);
553 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
554 xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
555 xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
556 xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username);
557 xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password);
558 xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
559 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
560 xmlFreeDoc(pdoc);
561 return RESULT_OK;
562
563 FAILED:
564 if (pdoc)
565 {
566 xmlFreeDoc(pdoc);
567 }
568 return RESULT_ERROR;
569}
570
571
572int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn)
573{
574 int node_num = 0;
575 xmlDocPtr pdoc = NULL;
576 xmlNodePtr node = NULL;
577 xmlNodePtr modify_node = NULL;
578 unsigned char temp = NULL;
579 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
580 if(NULL == pdoc)
581 {
582 LYERRLOG("open xml file error");
583 goto FAILED;
584 }
585
586 node = xmlDocGetRootElement(pdoc);
587 if (NULL == node)
588 {
589 LYERRLOG("xmlDocGetRootElement() error");
590 goto FAILED;
591 }
592 modify_node = node->xmlChildrenNode;
xf.libf9df4c2023-07-02 02:42:35 -0700593 if(modify_node != NULL)
xf.li2fc84552023-06-23 05:26:47 -0700594 {
xf.libf9df4c2023-07-02 02:42:35 -0700595 modify_node = modify_node->next;
596 }
597 else
598 {
599 LYERRLOG("modify_node is null\n");
600 goto FAILED;
601 }
602 LYINFLOG("profile_idx is %d\n", (int)profile_idx);
603 for (node_num = 0;(node_num<(int)profile_idx);node_num++)
604 {
605 if(modify_node == NULL)
606 {
607 LYERRLOG("modify_node is null\n");
608 goto FAILED;
609 }
xf.li2fc84552023-06-23 05:26:47 -0700610 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
611 {
612 modify_node = modify_node->next;
613 node_num--;
614 continue;
615 }
616 modify_node = modify_node->next;
xf.li0fc26502023-09-16 02:10:17 -0700617 if(modify_node == NULL)
618 {
619 LYERRLOG("modify_node is null\n");
620 goto FAILED;
621 }
xf.li2fc84552023-06-23 05:26:47 -0700622 }
623 apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx"));
624 apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
625 apn->auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto"));
626 strcpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name"));
627 strcpy(apn->username,(char *)xmlGetProp(modify_node, "username"));
628 strcpy(apn->password,(char *)xmlGetProp(modify_node, "password"));
629 strcpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"));
630 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
631 xmlFreeDoc(pdoc);
632 return RESULT_OK;
633
634 FAILED:
635 if (pdoc)
636 {
637 xmlFreeDoc(pdoc);
638 }
639 return RESULT_ERROR;
640}
641
642int apn_xml_query_list(qser_apn_info_list_s *apn_list)
643{
644 int node_num = 0;
645 xmlDocPtr pdoc = NULL;
646 xmlNodePtr node = NULL;
647 xmlNodePtr modify_node = NULL;
648 xmlChar *temp_char;
649 char temp[64];
650 pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
651 if(NULL == pdoc)
652 {
653 LYERRLOG("open xml file error");
654 goto FAILED;
655 }
656
657 node = xmlDocGetRootElement(pdoc);
658 if (NULL == node)
659 {
660 LYERRLOG("xmlDocGetRootElement() error");
661 goto FAILED;
662 }
663 modify_node = node->xmlChildrenNode;
664 modify_node = modify_node->next;
665 while (modify_node != NULL)
666 {
667 temp_char = xmlGetProp(modify_node, "profile_idx");
668 if (temp_char == NULL)
669 {
670 modify_node = modify_node->next;
671 continue;
672 }
673 sprintf(temp,"%s",temp_char);
674 apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp);
675 apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
676 apn_list->apn[node_num].auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto"));
677 strcpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name"));
678 strcpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username"));
679 strcpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password"));
xf.li177e8672023-08-10 03:07:14 -0700680 strcpy(apn_list->apn[node_num].apn_type,(char *)xmlGetProp(modify_node, "apn_type"));
xf.li2fc84552023-06-23 05:26:47 -0700681 node_num ++;
682 modify_node = modify_node->next;
683 }
684 apn_list->cnt = node_num;
685 xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1);
686 xmlFreeDoc(pdoc);
687 return RESULT_OK;
688
689 FAILED:
690 if (pdoc)
691 {
692 xmlFreeDoc(pdoc);
693 }
694 return RESULT_ERROR;
695}
696
697void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
698{
699 switch (pdp_type)
700 {
701 case QSER_APN_PDP_TYPE_IPV4:
702 strcpy(out_pdp_type,"IPV4");
703 break;
704 case QSER_APN_PDP_TYPE_PPP:
705 strcpy(out_pdp_type,"PPP");
706 break;
707 case QSER_APN_PDP_TYPE_IPV6:
708 strcpy(out_pdp_type,"IPV6");
709 break;
710 case QSER_APN_PDP_TYPE_IPV4V6:
711 strcpy(out_pdp_type,"IPV4V6");
712 break;
713 default:
714 strcpy(out_pdp_type,"NULL");
715 break;
716 }
717 return;
718}
719void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
720{
721 switch (auth_proto)
722 {
723 case QSER_APN_AUTH_PROTO_DEFAULT:
724 strcpy(out_proto,"NULL;authType=0");
725 break;
726 case QSER_APN_AUTH_PROTO_NONE:
727 strcpy(out_proto,"NULL;authType=1");
728 break;
729 case QSER_APN_AUTH_PROTO_PAP:
730 strcpy(out_proto,"NULL;authType=2");
731 break;
732 case QSER_APN_AUTH_PROTO_CHAP:
733 strcpy(out_proto,"NULL;authtype=3");
734 break;
735 case QSER_APN_AUTH_PROTO_PAP_CHAP:
736 strcpy(out_proto,"NULL;authtype=4");
737 break;
738 default:
739 strcpy(out_proto,"NULL;authType=NULL");
740 break;
741 }
742 return ;
743}
744
745int data_call_handle_get(const char profile_idx,int *handle)
746{
747 int num = LYNQ_APN_CHANNEL_MAX;
748 int table_num = 0;
749 lynq_apn_info **apn_table = NULL;
750 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -0700751 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700752 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
753 if (NULL == apn_table)
754 {
755 LYERRLOG("malloc apn_table fail ");
756 return RESULT_ERROR;
757 }
758 for(int i =0;i<10;i++)
759 {
760 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
761 if (apn_table[i]==NULL)
762 {
763 for (int n=0;n<i;n++)
764 {
765 free(apn_table[n]);
766 }
767 return RESULT_ERROR;
768 }
769 memset(apn_table[i],0,sizeof(lynq_apn_info));
770 }
771 lynq_get_apn_table(&table_num,apn_table);
772 memset(&apn,0,sizeof(qser_apn_info_s));
xf.li0fc26502023-09-16 02:10:17 -0700773 ret = apn_xml_query(profile_idx,&apn);
774 if (ret < 0)
775 {
776 LYERRLOG("apn_xml_query error");
777 return ret;
778 }
xf.li2fc84552023-06-23 05:26:47 -0700779 for (int j = 0;j < table_num;j++)
780 {
781 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
782 {
783 *handle = apn_table[j]->index;
784 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
785 break;
786 }
787 }
788
789 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
790 {
791 if (apn_table[i]!=NULL)
792 {
793 free(apn_table[i]);
794 apn_table[i]=NULL;
795 }
796 }
797 free(apn_table);
798 apn_table=NULL;
799 LYINFLOG("data_call_handle_get end");
800 return RESULT_OK;
801}
802
803void *thread_wait_cb_status(void)
804{
805 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -0700806 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700807 lynq_data_call_response_v11_t data_urc_info;
808 qser_data_call_state_s data_cb_state;
809 while (s_qser_data_cb_thread_status)
810 {
xf.li6b0d8502023-09-04 18:49:12 -0700811 ret = lynq_wait_data_call_state_change(&handle);
812 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
813 if(s_qser_data_cb_thread_status == 0)
814 {
815 return NULL;
816 }
817 else if(ret < 0)
818 {
819 continue;
820 }
821
xf.li2fc84552023-06-23 05:26:47 -0700822 lynq_get_data_call_list(&handle,&data_urc_info);
823 /*compare paramter*/
824 data_cb_state.profile_idx = (char)handle;
825
826 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
827 if (!strcmp(data_urc_info.type,"IPV4"))
828 {
829 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
830 }
831 else if (!strcmp(data_urc_info.type,"IPV6"))
832 {
833 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
834 }
835 else if (strcmp(data_urc_info.type,"IPV4V6"))
836 {
837 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
838 }
839 else
840 {
841 LYERRLOG("unknow data call type");
842 continue;
843 }
844
845 if (data_urc_info.status != 0)
846 {
847 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
848 }
849 else
850 {
851 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
852 }
853 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
854 {
855 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
856 }
857 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
858 {
859 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
860 }
861 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
862 {
xf.li3c0a4752023-09-03 20:46:19 -0700863#ifdef MOBILETEK_TARGET_PLATFORM_T106
864 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
865#else
xf.li2fc84552023-06-23 05:26:47 -0700866 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -0700867#endif
xf.li2fc84552023-06-23 05:26:47 -0700868 }
869 else
870 {
871 LYERRLOG("unknow ip_family");
872 continue;
873 }
874 if (s_data_call_cb != NULL)
875 {
876 s_data_call_cb(&data_cb_state);
877 }
878 }
879 return NULL;
880}
881
882int qser_cb_pthread_create()
883{
884 int ret;
885 s_qser_data_cb_thread_status = 1;
886 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
887 if (ret < 0)
888 {
889 LYERRLOG("pthread create fail");
890 s_qser_data_cb_thread_status = 0;
891 return RESULT_ERROR;
892 }
893 return RESULT_OK;
894}
895
896void qser_cb_pthread_cancel()
897{
xf.li2fc84552023-06-23 05:26:47 -0700898 s_qser_data_cb_thread_status = 0;
899 if (s_cb_tid != -1)
900 {
xf.li6b0d8502023-09-04 18:49:12 -0700901 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -0700902 }
903 return;
904}
xf.li7b0bfd02023-08-03 01:11:52 -0700905int check_xml_file(const char *file)
906{
907 /* Check for existence */
908 if((access(file, F_OK)) == -1)
909 {
910 LYERRLOG("no such xml file.\n");
911 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
912 }
913
914 if((access(file, F_OK)) == -1)
915 {
916 LYERRLOG("error copy xml file.\n");
917 return -1;
918 }
919 return RESULT_OK;
920}
xf.li2fc84552023-06-23 05:26:47 -0700921
922int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
923{
924 int ret = 0;
925 int utoken = 0;
926 if (NULL == evt_cb)
927 {
928 LYERRLOG("init incoming paramters error");
929 return RESULT_ERROR;
930 }
xf.li7b0bfd02023-08-03 01:11:52 -0700931
932 ret = check_xml_file(data_xml_path);
933 if (ret != RESULT_OK)
934 {
935 LYERRLOG("check xml file error");
936 return RESULT_ERROR;
937 }
938
xf.li2fc84552023-06-23 05:26:47 -0700939 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -0700940
xf.li2fc84552023-06-23 05:26:47 -0700941 ret = lynq_init_data(utoken);
942 if (ret != RESULT_OK)
943 {
xf.li6b0d8502023-09-04 18:49:12 -0700944 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700945 s_data_call_cb = NULL;
946 return RESULT_ERROR;
947 }
xf.li6b0d8502023-09-04 18:49:12 -0700948 qser_cb_pthread_create();
xf.li2fc84552023-06-23 05:26:47 -0700949 return RESULT_OK;
950}
951
952void qser_data_call_destroy(void)
953{
xf.li6b0d8502023-09-04 18:49:12 -0700954 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
955
xf.li2fc84552023-06-23 05:26:47 -0700956 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -0700957 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700958 s_data_call_cb = NULL;
xf.li6b0d8502023-09-04 18:49:12 -0700959 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -0700960 return ;
961}
962
963int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
964{
965 int ret = -1;
966 int handle = 0;
967 if (NULL == data_call || NULL == err)
968 {
969 LYERRLOG("call start incoming paramters error");
970 return ret;
971 }
972 if (data_call->profile_idx == 0)
973 {
974 ret = lynq_setup_data_call(&handle);
975 }
976 else
977 {
978 char pdptype[16];
979 qser_apn_info_s apn_info;
xf.li0fc26502023-09-16 02:10:17 -0700980 ret = qser_apn_get(data_call->profile_idx,&apn_info);
981 if (ret != 0)
982 {
983 LYERRLOG("qser_apn_get error");
984 return ret;
985 }
xf.li2fc84552023-06-23 05:26:47 -0700986 judge_pdp_type(apn_info.pdp_type,pdptype);
987 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
988 }
989 if (ret < 0)
990 {
991 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
992 }
993 return ret;
994}
995
996int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
997{
998 int ret = 0;
999 int handle = -1;
1000
1001 if (NULL == err)
1002 {
1003 LYERRLOG("call stop incoming paramters error");
1004 return ret;
1005 }
1006 data_call_handle_get(profile_idx,&handle);
1007 ret = lynq_deactive_data_call(&handle);
1008 if (ret < 0)
1009 {
1010 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1011 }
1012 return RESULT_OK;
1013}
1014int 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)
1015{
1016 int ret = 0;
1017 int handle = -1;
1018 lynq_data_call_response_v11_t data_call_info;
1019 data_call_handle_get(profile_idx,&handle);
1020 ret = lynq_get_data_call_list(&handle,&data_call_info);
1021 if (ret == 0)
1022 {
1023 info->profile_idx = profile_idx;
1024 info->ip_family = ip_family;
xf.li3c0a4752023-09-03 20:46:19 -07001025 if (strncmp(data_call_info.type,"IPV4", strlen("IPV4") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001026 {
1027 strcpy(info->v4.name,data_call_info.ifname);
1028 datacall_ipv4_status_judge(data_call_info.status,info);
1029 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1030 lynq_ipv4_aton_getinfo(&data_call_info,info);
1031 }
xf.li3c0a4752023-09-03 20:46:19 -07001032 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001033 {
1034 strcpy(info->v6.name,data_call_info.ifname);
1035
1036 datacall_ipv6_status_judge(data_call_info.status,info);
1037 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1038 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1039 }
xf.li3c0a4752023-09-03 20:46:19 -07001040 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001041 {
1042 strcpy(info->v4.name,data_call_info.ifname);
1043 datacall_ipv4_status_judge(data_call_info.status,info);
1044 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 -07001045#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001046 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001047#endif
xf.li2fc84552023-06-23 05:26:47 -07001048 strcpy(info->v6.name,data_call_info.ifname);
1049 datacall_ipv6_status_judge(data_call_info.status,info);
1050 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 -07001051#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001052 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001053#endif
1054#ifdef MOBILETEK_TARGET_PLATFORM_T106
1055 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1056#endif
xf.li2fc84552023-06-23 05:26:47 -07001057 }
1058 else
1059 {
1060 LYERRLOG("useless qser_data_call_ip_family_e");
1061 }
1062 }
1063 return ret;
1064}
1065int qser_apn_set(qser_apn_info_s *apn)
1066{
1067 int ret = 0;
1068 if (NULL == apn)
1069 {
1070 LYERRLOG("apn set incoming paramters error");
1071 return RESULT_ERROR;
1072 }
1073 ret = apn_xml_modify(apn);
1074 if (ret < 0)
1075 {
1076 LYERRLOG("apn_xml_modify error");
1077 return ret;
1078 }
1079 int apn_id = 0;
1080 char tmp_id[12];
1081 char *outinfo = NULL;
1082 char normalprotocol[16];
1083 char authtype[32];
1084 outinfo = (char *)malloc(sizeof(char)*512);
1085 bzero(tmp_id,12);
1086 bzero(outinfo,512);
1087 apn_id = apn->profile_idx + apndb_offset;
1088 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1089 judge_pdp_type(apn->pdp_type,normalprotocol);
1090 judge_authtype(apn->auth_proto,authtype);
1091 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1092 LYINFLOG("[output]:%s",outinfo);
1093 free(outinfo);
1094 outinfo = NULL;
1095 return RESULT_OK;
1096}
1097
1098int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1099{
1100 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
1101 {
1102 LYERRLOG("apn get incoming paramters error");
1103 return RESULT_ERROR;
1104 }
1105 int ret = 0;
1106 ret = apn_xml_query(profile_idx,apn);
1107 if (ret < 0)
1108 {
1109 LYERRLOG("apn_xml_query error");
1110 return ret;
1111 }
1112 return ret;
1113}
1114
1115int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1116{
1117 int ret = 0;
1118 if (NULL == apn || NULL == profile_idx)
1119 {
1120 LYERRLOG("apn add incoming paramters error");
1121 return RESULT_ERROR;
1122 }
1123 ret = apn_xml_add(apn,profile_idx);
1124 if (ret < 0)
1125 {
1126 LYERRLOG("apn_xml_add error");
1127 return ret;
1128 }
1129 int apn_id = 0;
1130 char tmp_id[12];
1131 char *outinfo = NULL;
1132 char normalprotocol[16];
1133 char authtype[32];
1134 outinfo = (char *)malloc(sizeof(char)*512);
1135 bzero(tmp_id,12);
1136 bzero(outinfo,512);
1137 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1138 judge_pdp_type(apn->pdp_type,normalprotocol);
1139 judge_authtype(apn->auth_proto,authtype);
1140 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1141 LYINFLOG("[output]:%s",outinfo);
1142 free(outinfo);
1143 outinfo = NULL;
1144 return RESULT_OK;
1145}
1146
1147int qser_apn_del(unsigned char profile_idx)
1148{
1149 if (profile_idx < 0 || profile_idx > 24)
1150 {
1151 LYERRLOG("apn del incoming paramters error");
1152 return RESULT_OK;
1153 }
1154 int ret = 0;
1155 ret = apn_xml_delete(profile_idx);
1156 if (ret < 0)
1157 {
1158 LYERRLOG("apn_xml_delete error");
1159 return ret;
1160 }
1161 int apn_id = 0;
1162 char tmp_id[12];
1163 char *outinfo = NULL;
1164 outinfo = (char *)malloc(sizeof(char)*512);
1165 bzero(tmp_id,12);
1166 bzero(outinfo,512);
1167 apn_id = profile_idx+apndb_offset;
1168 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1169 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1170 LYINFLOG("[output]:%s",outinfo);
1171 free(outinfo);
1172 outinfo = NULL;
1173 return ret;
1174}
1175
1176int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1177{
1178 if (NULL == apn_list)
1179 {
1180 LYERRLOG("apn_list incoming paramters error");
1181 return RESULT_ERROR;
1182 }
1183 int ret = 0;
1184 ret = apn_xml_query_list(apn_list);
1185 if (ret < 0)
1186 {
1187 LYERRLOG("apn_xml_query_list error");
1188 return ret;
1189 }
1190 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001191}
you.chen21c62b72023-09-08 09:41:11 +08001192
1193DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1194