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