blob: 138514db354192d207a8045f41f710d725057364 [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;
xf.lie3f55f42023-12-01 22:47:33 -080030static xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -070031const int apndb_offset = 683;
32
33void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
34{
xf.li3c0a4752023-09-03 20:46:19 -070035#ifdef MOBILETEK_TARGET_PLATFORM_T106
36 char *tmp_char = NULL;
37 char *addresses = NULL;
38 char *dnses = NULL;
39 const char addresses_separator[2] = "/";
40 const char dnses_separator[2] = " ";
41
42 addresses = libdata->addresses;
43 dnses = libdata->dnses;
44 //get addresses
45 tmp_char = strsep(&addresses, addresses_separator);
46 if(tmp_char != NULL)
47 {
48 LYINFLOG("ipv4 addresses = %s", tmp_char);
49 inet_aton(tmp_char,&(data_res->v4.ip));
50 }
51
52 //get dnses
53 tmp_char = strsep(&dnses, dnses_separator);
54 if(tmp_char != NULL)
55 {
56 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
57 inet_aton(tmp_char,&(data_res->v4.pri_dns));
58 }
59 tmp_char = strsep(&dnses, dnses_separator);
60 if(tmp_char != NULL)
61 {
62 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
63 inet_aton(tmp_char, &(data_res->v4.sec_dns));
64 }
65 //get gateway
66 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
67
68#else
xf.li2fc84552023-06-23 05:26:47 -070069 inet_aton(libdata->addresses,&(data_res->v4.ip));
70 inet_aton(libdata->gateways,&(data_res->v4.gateway));
71 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
72 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -070073#endif
xf.li2fc84552023-06-23 05:26:47 -070074 return ;
75}
76
77void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
78{
xf.li3c0a4752023-09-03 20:46:19 -070079#ifdef MOBILETEK_TARGET_PLATFORM_T106
80 char *tmp_char = NULL;
81 char *addresses = NULL;
82 char *dnses = NULL;
83 const char addresses_separator[2] = "/";
84 const char dnses_separator[2] = " ";
85
86 addresses = libdata->addresses;
87 dnses = libdata->dnses;
88 //get addresses
89 tmp_char = strsep(&addresses, addresses_separator);
90 if(tmp_char != NULL)
91 {
92 LYINFLOG("ipv6 addresses = %s", tmp_char);
93 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
94 }
95 //get dnses
96 tmp_char = strsep(&dnses, dnses_separator);
97 if(tmp_char != NULL)
98 {
99 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
100 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
101 }
102 tmp_char = strsep(&dnses, dnses_separator);
103 if(tmp_char != NULL)
104 {
105 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
106 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
107 }
108 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
109#else
xf.li2fc84552023-06-23 05:26:47 -0700110 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
111 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
112 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
113 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700114#endif
115
116 return ;
117}
118
119void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
120{
121 char *tmp_char = NULL;
122 char *addresses = NULL;
123 char *dnses = NULL;
124 const char addresses_separator[2] = "/";
125 const char dnses_separator[2] = " ";
126
127 addresses = libdata->addresses;
128 dnses = libdata->dnses;
129 //get addresses
130 tmp_char = strsep(&addresses, addresses_separator);
131 if(tmp_char != NULL)
132 {
133 LYINFLOG("ipv4 addresses = %s", tmp_char);
134 inet_aton(tmp_char,&(data_res->v4.ip));
135 }
136 tmp_char = strsep(&addresses, addresses_separator);
137 if(tmp_char != NULL)
138 {
139 LYINFLOG("ipv6 addresses = %s", tmp_char);
140 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
141 }
142 //get dnses
143 tmp_char = strsep(&dnses, dnses_separator);
144 if(tmp_char != NULL)
145 {
146 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
147 inet_aton(tmp_char,&(data_res->v4.pri_dns));
148 }
149 tmp_char = strsep(&dnses, dnses_separator);
150 if(tmp_char != NULL)
151 {
152 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
153 inet_aton(tmp_char, &(data_res->v4.sec_dns));
154 }
155 tmp_char = strsep(&dnses, dnses_separator);
156 if(tmp_char != NULL)
157 {
158 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
159 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
160 }
161 tmp_char = strsep(&dnses, dnses_separator);
162 if(tmp_char != NULL)
163 {
164 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
165 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
166 }
167 //get gateway
168 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
169
xf.li2fc84552023-06-23 05:26:47 -0700170 return ;
171}
172
173void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
174{
xf.li3c0a4752023-09-03 20:46:19 -0700175#ifdef MOBILETEK_TARGET_PLATFORM_T106
176 char *tmp_char = NULL;
177 char *addresses = NULL;
178 char *dnses = NULL;
179 const char addresses_separator[2] = "/";
180 const char dnses_separator[2] = " ";
181
182 addresses = libdata->addresses;
183 dnses = libdata->dnses;
184 //get addresses
185 tmp_char = strsep(&addresses, addresses_separator);
186 if(tmp_char != NULL)
187 {
188 LYINFLOG("ipv4 addresses = %s", tmp_char);
189 inet_aton(tmp_char,&(data_res->v4.addr.ip));
190 }
191 //get dnses
192 tmp_char = strsep(&dnses, dnses_separator);
193 if(tmp_char != NULL)
194 {
195 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
196 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
197 }
198 tmp_char = strsep(&dnses, dnses_separator);
199 if(tmp_char != NULL)
200 {
201 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
202 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
203 }
204 //get gateway
205 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
206 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
207
208 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
209 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
210 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
211#else
xf.li2fc84552023-06-23 05:26:47 -0700212 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
213 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
214 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
215 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700216#endif
xf.li2fc84552023-06-23 05:26:47 -0700217 data_res->v4.stats.pkts_tx = 0;
218 data_res->v4.stats.pkts_rx = 0;
219 data_res->v4.stats.bytes_tx = 0;
220 data_res->v4.stats.bytes_rx = 0;
221 data_res->v4.stats.pkts_dropped_tx = 0;
222 data_res->v4.stats.pkts_dropped_rx = 0;
223 return ;
224}
225
226void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
227{
xf.li3c0a4752023-09-03 20:46:19 -0700228#ifdef MOBILETEK_TARGET_PLATFORM_T106
229 char *tmp_char = NULL;
230 char *addresses = NULL;
231 char *dnses = NULL;
232 const char addresses_separator[2] = "/";
233 const char dnses_separator[2] = " ";
234
235 addresses = libdata->addresses;
236 dnses = libdata->dnses;
237 //get addresses
238 tmp_char = strsep(&addresses, addresses_separator);
239 if(tmp_char != NULL)
240 {
241 LYINFLOG("ipv6 addresses = %s", tmp_char);
242 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
243 }
244 //get dnses
245 tmp_char = strsep(&dnses, dnses_separator);
246 if(tmp_char != NULL)
247 {
248 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
249 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
250 }
251 tmp_char = strsep(&dnses, dnses_separator);
252 if(tmp_char != NULL)
253 {
254 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
255 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
256 }
257 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
258#else
xf.li2fc84552023-06-23 05:26:47 -0700259 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
260 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
261 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
262 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700263#endif
264 data_res->v6.stats.pkts_tx = 0;
265 data_res->v6.stats.pkts_rx = 0;
266 data_res->v6.stats.bytes_tx = 0;
267 data_res->v6.stats.bytes_rx = 0;
268 data_res->v6.stats.pkts_dropped_tx = 0;
269 data_res->v6.stats.pkts_dropped_rx = 0;
270 return ;
271}
272void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
273{
274 char *tmp_char = NULL;
275 char *addresses = NULL;
276 char *dnses = NULL;
277 const char addresses_separator[2] = "/";
278 const char dnses_separator[2] = " ";
279
280 char buf_ip[64] = {0};
281 char buf_gateway[64] = {0};
282 char buf_pri_dns[64] = {0};
283 char buf_sec_dns[64] = {0};
284
285 addresses = libdata->addresses;
286 dnses = libdata->dnses;
287 //get addresses
288 tmp_char = strsep(&addresses, addresses_separator);
289 if(tmp_char != NULL)
290 {
291 LYINFLOG("ipv4 addresses = %s", tmp_char);
292 inet_aton(tmp_char,&(data_res->v4.addr.ip));
293 }
294 tmp_char = strsep(&addresses, addresses_separator);
295 if(tmp_char != NULL)
296 {
297 LYINFLOG("ipv6 addresses = %s", tmp_char);
298 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
299 }
300 //get dnses
301 tmp_char = strsep(&dnses, dnses_separator);
302 if(tmp_char != NULL)
303 {
304 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
305 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
306 }
307 tmp_char = strsep(&dnses, dnses_separator);
308 if(tmp_char != NULL)
309 {
310 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
311 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
312 }
313 tmp_char = strsep(&dnses, dnses_separator);
314 if(tmp_char != NULL)
315 {
316 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
317 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
318 }
319 tmp_char = strsep(&dnses, dnses_separator);
320 if(tmp_char != NULL)
321 {
322 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
323 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
324 }
325 //get gateway
326 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
327
328 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
329 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
330 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
331
332 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
333 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
334 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
335 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
336 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
337 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
338 data_res->v4.stats.pkts_tx = 0;
339 data_res->v4.stats.pkts_rx = 0;
340 data_res->v4.stats.bytes_tx = 0;
341 data_res->v4.stats.bytes_rx = 0;
342 data_res->v4.stats.pkts_dropped_tx = 0;
343 data_res->v4.stats.pkts_dropped_rx = 0;
344
xf.li2fc84552023-06-23 05:26:47 -0700345 data_res->v6.stats.pkts_tx = 0;
346 data_res->v6.stats.pkts_rx = 0;
347 data_res->v6.stats.bytes_tx = 0;
348 data_res->v6.stats.bytes_rx = 0;
349 data_res->v6.stats.pkts_dropped_tx = 0;
350 data_res->v6.stats.pkts_dropped_rx = 0;
351 return ;
352}
353
354void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
355{
xf.lib5dc0632023-11-30 18:20:35 -0800356 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700357 {
358 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
359 data_res->v4.reconnect = 1;
360 }
361 else
362 {
363 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
364 data_res->v4.reconnect = 0;
365 }
366 return ;
367}
368
369void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
370{
xf.lib5dc0632023-11-30 18:20:35 -0800371 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700372 {
373 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
374 data_res->v6.reconnect = 1;
375 }
376 else
377 {
378 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
379 data_res->v6.reconnect = 0;
380 }
381 return ;
382}
383
384
385int apn_xml_add(qser_apn_add_s *apn,unsigned char *apn_num)
386{
387 int node_num = 0;
388 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800389 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700390 xmlNodePtr node = NULL;
391 xmlNodePtr tmp_node = NULL;
392 xmlNodePtr sum_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800393
394// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
395 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700396 {
397 LYERRLOG("open xml file error");
398 goto FAILED;
399 }
400
xf.lie3f55f42023-12-01 22:47:33 -0800401 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700402 if (NULL == node)
403 {
404 LYERRLOG("xmlDocGetRootElement() error");
405 goto FAILED;
406 }
407 sum_node = node->xmlChildrenNode;
408 sum_node = sum_node->next;
409 while (sum_node != NULL)
410 {
411 if (xmlGetProp(sum_node, "profile_idx") == NULL) //Null Node
412 {
413 sum_node = sum_node->next;
414 continue;
415 }
xf.lif7c68e32023-10-10 23:18:42 -0700416 else if(strcmp((char *)xmlGetProp(sum_node, "apn_type"), apn->apn_type) == 0)
417 {
418 LYERRLOG("apntype already exists\n");
419 goto FAILED;
420 }
xf.li2fc84552023-06-23 05:26:47 -0700421 node_num++;
422 sum_node = sum_node->next;
423 }
xf.li3f891cb2023-08-23 23:11:24 -0700424 LYINFLOG("apn_num = %d ",node_num);
425 if(node_num >= QSER_APN_MAX_LIST)
426 {
427 LYERRLOG("apn num reached the max");
428 goto FAILED;
429 }
xf.li2fc84552023-06-23 05:26:47 -0700430 tmp_node = xmlNewNode(NULL,BAD_CAST"apn");
431 *apn_num = node_num;
xf.li2fc84552023-06-23 05:26:47 -0700432 bzero(temp_buff,12);
433 snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num);
434 xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
435 bzero(temp_buff,12);
436 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
437 xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
438 bzero(temp_buff,12);
439 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
440 xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
441 xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
442 xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username);
443 xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password);
444 xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
445 xmlAddChild(node,tmp_node);
xf.lie3f55f42023-12-01 22:47:33 -0800446 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
447
448// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700449 return RESULT_OK;
450
451 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800452 /* if (apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700453 {
xf.lie3f55f42023-12-01 22:47:33 -0800454 xmlFreeDoc(apn_table_xml_pdoc);
455 }*/
xf.li2fc84552023-06-23 05:26:47 -0700456 return RESULT_ERROR;
457}
458
459int apn_xml_delete(unsigned char profile_idx)
460{
461 int node_num = 0;
462 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800463 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700464 xmlNodePtr node = NULL;
465 xmlNodePtr modify_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800466 // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
467 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700468 {
469 LYERRLOG("open xml file error");
470 goto FAILED;
471 }
472
xf.lie3f55f42023-12-01 22:47:33 -0800473 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700474 if (NULL == node)
475 {
476 LYERRLOG("xmlDocGetRootElement() error");
477 goto FAILED;
478 }
479 modify_node = node->xmlChildrenNode;
xf.li029a9e72023-11-04 02:29:45 -0700480 if(modify_node != NULL)
481 {
482 modify_node = modify_node->next;
483 }
484 else
485 {
486 LYERRLOG("modify_node is null\n");
487 goto FAILED;
488 }
xf.li2fc84552023-06-23 05:26:47 -0700489 for (node_num=0 ;node_num<(int)profile_idx ; node_num++)
490 {
xf.li029a9e72023-11-04 02:29:45 -0700491 if(modify_node == NULL)
492 {
493 LYERRLOG("modify_node is null\n");
494 goto FAILED;
495 }
xf.li2fc84552023-06-23 05:26:47 -0700496 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
497 {
498 modify_node = modify_node->next;
499 node_num--;
500 continue;
501 }
502 modify_node = modify_node->next;
503 }
xf.li029a9e72023-11-04 02:29:45 -0700504 if(modify_node == NULL)
505 {
506 LYERRLOG("modify_node is null\n");
507 goto FAILED;
508 }
xf.li2fc84552023-06-23 05:26:47 -0700509 xmlUnlinkNode(modify_node);
510 xmlFreeNode(modify_node);
511 modify_node = NULL;
512 node_num = 0;
513 modify_node = node->xmlChildrenNode;
514 modify_node = modify_node->next;
515 while (modify_node != NULL)
516 {
517 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
518 {
519 modify_node = modify_node->next;
520 continue;
521 }
522 bzero(temp_buff,12);
523 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
524 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
525 modify_node = modify_node->next;
526 node_num++;
527 }
xf.lie3f55f42023-12-01 22:47:33 -0800528 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
529// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700530 return RESULT_OK;
531
532 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800533 // if (apn_table_xml_pdoc)
534 // {
535 // xmlFreeDoc(apn_table_xml_pdoc);
536 // }
xf.li2fc84552023-06-23 05:26:47 -0700537 return RESULT_ERROR;
538}
539
540int apn_xml_modify(qser_apn_info_s *apn)
541{
542 int node_num = 0;
543 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800544 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700545 xmlNodePtr node = NULL;
546 xmlNodePtr modify_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800547// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
548 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700549 {
550 LYERRLOG("open xml file error");
551 goto FAILED;
552 }
553
xf.lie3f55f42023-12-01 22:47:33 -0800554 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700555 if (NULL == node)
556 {
557 LYERRLOG("xmlDocGetRootElement() error");
558 goto FAILED;
559 }
560 modify_node = node->xmlChildrenNode;
561 modify_node = modify_node->next;
562 for (node_num=0; node_num<(int)apn->profile_idx;node_num++)
563 {
564 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
565 {
566 modify_node = modify_node->next;
567 node_num--;
568 continue;
569 }
570 modify_node = modify_node->next;
571 }
572 bzero(temp_buff,12);
573 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
574 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
575 bzero(temp_buff,12);
576 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
577 xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
578 bzero(temp_buff,12);
579 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
580 xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
581 xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
582 xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username);
583 xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password);
584 xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
xf.lie3f55f42023-12-01 22:47:33 -0800585 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
586// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700587 return RESULT_OK;
588
589 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800590 // if (apn_table_xml_pdoc)
591 // {
592 // xmlFreeDoc(apn_table_xml_pdoc);
593 // }
xf.li2fc84552023-06-23 05:26:47 -0700594 return RESULT_ERROR;
595}
596
597
598int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn)
599{
600 int node_num = 0;
xf.lie3f55f42023-12-01 22:47:33 -0800601 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700602 xmlNodePtr node = NULL;
603 xmlNodePtr modify_node = NULL;
604 unsigned char temp = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800605// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
606 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700607 {
608 LYERRLOG("open xml file error");
609 goto FAILED;
610 }
611
xf.lie3f55f42023-12-01 22:47:33 -0800612 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700613 if (NULL == node)
614 {
615 LYERRLOG("xmlDocGetRootElement() error");
616 goto FAILED;
617 }
618 modify_node = node->xmlChildrenNode;
xf.libf9df4c2023-07-02 02:42:35 -0700619 if(modify_node != NULL)
xf.li2fc84552023-06-23 05:26:47 -0700620 {
xf.libf9df4c2023-07-02 02:42:35 -0700621 modify_node = modify_node->next;
622 }
623 else
624 {
625 LYERRLOG("modify_node is null\n");
626 goto FAILED;
627 }
628 LYINFLOG("profile_idx is %d\n", (int)profile_idx);
629 for (node_num = 0;(node_num<(int)profile_idx);node_num++)
630 {
631 if(modify_node == NULL)
632 {
633 LYERRLOG("modify_node is null\n");
634 goto FAILED;
635 }
xf.li2fc84552023-06-23 05:26:47 -0700636 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
637 {
638 modify_node = modify_node->next;
639 node_num--;
640 continue;
641 }
642 modify_node = modify_node->next;
xf.li029a9e72023-11-04 02:29:45 -0700643 }
644 if(modify_node == NULL)
645 {
646 LYERRLOG("modify_node is null\n");
647 goto FAILED;
xf.li2fc84552023-06-23 05:26:47 -0700648 }
649 apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx"));
650 apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
651 apn->auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto"));
xf.li6c7e3972023-10-27 20:01:59 -0700652 strncpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
653 strncpy(apn->username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
654 strncpy(apn->password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
655 strncpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE);
xf.lie3f55f42023-12-01 22:47:33 -0800656// xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
657// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700658 return RESULT_OK;
659
660 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800661 // if (apn_table_xml_pdoc)
662 // {
663 // xmlFreeDoc(apn_table_xml_pdoc);
664 // }
xf.li2fc84552023-06-23 05:26:47 -0700665 return RESULT_ERROR;
666}
667
668int apn_xml_query_list(qser_apn_info_list_s *apn_list)
669{
670 int node_num = 0;
xf.lie3f55f42023-12-01 22:47:33 -0800671 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700672 xmlNodePtr node = NULL;
673 xmlNodePtr modify_node = NULL;
674 xmlChar *temp_char;
675 char temp[64];
xf.lie3f55f42023-12-01 22:47:33 -0800676// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
677 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700678 {
679 LYERRLOG("open xml file error");
680 goto FAILED;
681 }
682
xf.lie3f55f42023-12-01 22:47:33 -0800683 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700684 if (NULL == node)
685 {
686 LYERRLOG("xmlDocGetRootElement() error");
687 goto FAILED;
688 }
689 modify_node = node->xmlChildrenNode;
690 modify_node = modify_node->next;
691 while (modify_node != NULL)
692 {
693 temp_char = xmlGetProp(modify_node, "profile_idx");
694 if (temp_char == NULL)
695 {
696 modify_node = modify_node->next;
697 continue;
698 }
699 sprintf(temp,"%s",temp_char);
700 apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp);
701 apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
702 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 -0700703 strncpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
704 strncpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
705 strncpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
706 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 -0700707 node_num ++;
708 modify_node = modify_node->next;
709 }
710 apn_list->cnt = node_num;
xf.lie3f55f42023-12-01 22:47:33 -0800711// xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
712// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700713 return RESULT_OK;
714
715 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800716 // if (apn_table_xml_pdoc)
717 // {
718 // xmlFreeDoc(apn_table_xml_pdoc);
719 // }
xf.li2fc84552023-06-23 05:26:47 -0700720 return RESULT_ERROR;
721}
722
723void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
724{
725 switch (pdp_type)
726 {
727 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -0800728#ifdef MOBILETEK_TARGET_PLATFORM_T106
729 strcpy(out_pdp_type,"IP");
730#else
xf.li2fc84552023-06-23 05:26:47 -0700731 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -0800732#endif
xf.li2fc84552023-06-23 05:26:47 -0700733 break;
734 case QSER_APN_PDP_TYPE_PPP:
735 strcpy(out_pdp_type,"PPP");
736 break;
737 case QSER_APN_PDP_TYPE_IPV6:
738 strcpy(out_pdp_type,"IPV6");
739 break;
740 case QSER_APN_PDP_TYPE_IPV4V6:
741 strcpy(out_pdp_type,"IPV4V6");
742 break;
743 default:
744 strcpy(out_pdp_type,"NULL");
745 break;
746 }
747 return;
748}
749void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
750{
751 switch (auth_proto)
752 {
753 case QSER_APN_AUTH_PROTO_DEFAULT:
754 strcpy(out_proto,"NULL;authType=0");
755 break;
756 case QSER_APN_AUTH_PROTO_NONE:
757 strcpy(out_proto,"NULL;authType=1");
758 break;
759 case QSER_APN_AUTH_PROTO_PAP:
760 strcpy(out_proto,"NULL;authType=2");
761 break;
762 case QSER_APN_AUTH_PROTO_CHAP:
763 strcpy(out_proto,"NULL;authtype=3");
764 break;
765 case QSER_APN_AUTH_PROTO_PAP_CHAP:
766 strcpy(out_proto,"NULL;authtype=4");
767 break;
768 default:
769 strcpy(out_proto,"NULL;authType=NULL");
770 break;
771 }
772 return ;
773}
774
775int data_call_handle_get(const char profile_idx,int *handle)
776{
777 int num = LYNQ_APN_CHANNEL_MAX;
778 int table_num = 0;
779 lynq_apn_info **apn_table = NULL;
780 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -0700781 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700782 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
783 if (NULL == apn_table)
784 {
785 LYERRLOG("malloc apn_table fail ");
786 return RESULT_ERROR;
787 }
788 for(int i =0;i<10;i++)
789 {
790 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
791 if (apn_table[i]==NULL)
792 {
793 for (int n=0;n<i;n++)
794 {
795 free(apn_table[n]);
796 }
797 return RESULT_ERROR;
798 }
799 memset(apn_table[i],0,sizeof(lynq_apn_info));
800 }
801 lynq_get_apn_table(&table_num,apn_table);
802 memset(&apn,0,sizeof(qser_apn_info_s));
xf.li0fc26502023-09-16 02:10:17 -0700803 ret = apn_xml_query(profile_idx,&apn);
804 if (ret < 0)
805 {
806 LYERRLOG("apn_xml_query error");
807 return ret;
808 }
xf.li2fc84552023-06-23 05:26:47 -0700809 for (int j = 0;j < table_num;j++)
810 {
811 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
812 {
813 *handle = apn_table[j]->index;
814 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
815 break;
816 }
817 }
818
819 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
820 {
821 if (apn_table[i]!=NULL)
822 {
823 free(apn_table[i]);
824 apn_table[i]=NULL;
825 }
826 }
827 free(apn_table);
828 apn_table=NULL;
829 LYINFLOG("data_call_handle_get end");
830 return RESULT_OK;
831}
832
833void *thread_wait_cb_status(void)
834{
835 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -0700836 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700837 lynq_data_call_response_v11_t data_urc_info;
838 qser_data_call_state_s data_cb_state;
839 while (s_qser_data_cb_thread_status)
840 {
xf.li6b0d8502023-09-04 18:49:12 -0700841 ret = lynq_wait_data_call_state_change(&handle);
842 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
843 if(s_qser_data_cb_thread_status == 0)
844 {
845 return NULL;
846 }
847 else if(ret < 0)
848 {
849 continue;
850 }
851
xf.li2fc84552023-06-23 05:26:47 -0700852 lynq_get_data_call_list(&handle,&data_urc_info);
853 /*compare paramter*/
854 data_cb_state.profile_idx = (char)handle;
855
856 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -0800857 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -0700858 {
859 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
860 }
861 else if (!strcmp(data_urc_info.type,"IPV6"))
862 {
863 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
864 }
865 else if (strcmp(data_urc_info.type,"IPV4V6"))
866 {
867 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
868 }
869 else
870 {
871 LYERRLOG("unknow data call type");
872 continue;
873 }
874
875 if (data_urc_info.status != 0)
876 {
877 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
878 }
879 else
880 {
881 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
882 }
883 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
884 {
885 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
886 }
887 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
888 {
889 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
890 }
891 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
892 {
xf.li3c0a4752023-09-03 20:46:19 -0700893#ifdef MOBILETEK_TARGET_PLATFORM_T106
894 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
895#else
xf.li2fc84552023-06-23 05:26:47 -0700896 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -0700897#endif
xf.li2fc84552023-06-23 05:26:47 -0700898 }
899 else
900 {
901 LYERRLOG("unknow ip_family");
902 continue;
903 }
904 if (s_data_call_cb != NULL)
905 {
906 s_data_call_cb(&data_cb_state);
907 }
908 }
909 return NULL;
910}
911
912int qser_cb_pthread_create()
913{
914 int ret;
915 s_qser_data_cb_thread_status = 1;
916 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
917 if (ret < 0)
918 {
919 LYERRLOG("pthread create fail");
920 s_qser_data_cb_thread_status = 0;
921 return RESULT_ERROR;
922 }
923 return RESULT_OK;
924}
925
926void qser_cb_pthread_cancel()
927{
xf.li2fc84552023-06-23 05:26:47 -0700928 s_qser_data_cb_thread_status = 0;
929 if (s_cb_tid != -1)
930 {
xf.li6b0d8502023-09-04 18:49:12 -0700931 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -0700932 }
933 return;
934}
xf.li7b0bfd02023-08-03 01:11:52 -0700935int check_xml_file(const char *file)
936{
937 /* Check for existence */
938 if((access(file, F_OK)) == -1)
939 {
940 LYERRLOG("no such xml file.\n");
941 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
942 }
943
944 if((access(file, F_OK)) == -1)
945 {
946 LYERRLOG("error copy xml file.\n");
947 return -1;
948 }
949 return RESULT_OK;
950}
xf.li2fc84552023-06-23 05:26:47 -0700951
952int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
953{
954 int ret = 0;
955 int utoken = 0;
956 if (NULL == evt_cb)
957 {
958 LYERRLOG("init incoming paramters error");
959 return RESULT_ERROR;
960 }
xf.li7b0bfd02023-08-03 01:11:52 -0700961
962 ret = check_xml_file(data_xml_path);
963 if (ret != RESULT_OK)
964 {
965 LYERRLOG("check xml file error");
966 return RESULT_ERROR;
967 }
968
xf.li2fc84552023-06-23 05:26:47 -0700969 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -0700970
xf.li2fc84552023-06-23 05:26:47 -0700971 ret = lynq_init_data(utoken);
972 if (ret != RESULT_OK)
973 {
xf.li6b0d8502023-09-04 18:49:12 -0700974 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700975 s_data_call_cb = NULL;
976 return RESULT_ERROR;
977 }
xf.li6b0d8502023-09-04 18:49:12 -0700978 qser_cb_pthread_create();
xf.lie3f55f42023-12-01 22:47:33 -0800979 apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
980 if(NULL == apn_table_xml_pdoc)
981 {
982 LYERRLOG("open xml file error");
983 return RESULT_ERROR;
984 }
xf.li2fc84552023-06-23 05:26:47 -0700985 return RESULT_OK;
986}
987
988void qser_data_call_destroy(void)
989{
xf.li6b0d8502023-09-04 18:49:12 -0700990 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.lie3f55f42023-12-01 22:47:33 -0800991 if(apn_table_xml_pdoc)
992 {
993 xmlFreeDoc(apn_table_xml_pdoc);
994 }
xf.li2fc84552023-06-23 05:26:47 -0700995 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -0700996 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700997 s_data_call_cb = NULL;
xf.li6b0d8502023-09-04 18:49:12 -0700998 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -0700999 return ;
1000}
1001
1002int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1003{
1004 int ret = -1;
1005 int handle = 0;
1006 if (NULL == data_call || NULL == err)
1007 {
1008 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001009 if(err != NULL)
1010 {
1011 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1012 }
xf.li2fc84552023-06-23 05:26:47 -07001013 return ret;
1014 }
1015 if (data_call->profile_idx == 0)
1016 {
1017 ret = lynq_setup_data_call(&handle);
1018 }
1019 else
1020 {
1021 char pdptype[16];
1022 qser_apn_info_s apn_info;
xf.li0fc26502023-09-16 02:10:17 -07001023 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1024 if (ret != 0)
1025 {
1026 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001027 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001028 return ret;
1029 }
xf.li2fc84552023-06-23 05:26:47 -07001030 judge_pdp_type(apn_info.pdp_type,pdptype);
1031 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1032 }
xf.lic12b3702023-11-22 22:39:01 -08001033 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001034 {
1035 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1036 }
1037 return ret;
1038}
1039
1040int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1041{
1042 int ret = 0;
1043 int handle = -1;
1044
1045 if (NULL == err)
1046 {
1047 LYERRLOG("call stop incoming paramters error");
1048 return ret;
1049 }
xf.lic12b3702023-11-22 22:39:01 -08001050 ret = data_call_handle_get(profile_idx,&handle);
1051 if(ret != 0)
1052 {
1053 LYERRLOG("datacall handle get error");
1054 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1055 return ret;
1056 }
xf.li2fc84552023-06-23 05:26:47 -07001057 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001058 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001059 {
1060 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001061 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001062 }
xy.hee2daacc2023-09-18 00:57:51 -07001063 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001064}
1065int 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)
1066{
1067 int ret = 0;
1068 int handle = -1;
1069 lynq_data_call_response_v11_t data_call_info;
1070 data_call_handle_get(profile_idx,&handle);
1071 ret = lynq_get_data_call_list(&handle,&data_call_info);
1072 if (ret == 0)
1073 {
1074 info->profile_idx = profile_idx;
1075 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001076 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 -07001077 {
1078 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001079 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001080 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1081 lynq_ipv4_aton_getinfo(&data_call_info,info);
1082 }
xf.li3c0a4752023-09-03 20:46:19 -07001083 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001084 {
1085 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001086 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001087 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1088 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1089 }
xf.li3c0a4752023-09-03 20:46:19 -07001090 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001091 {
1092 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001093 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001094 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 -07001095#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001096 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001097#endif
xf.li2fc84552023-06-23 05:26:47 -07001098 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001099 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001100 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 -07001101#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001102 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001103#endif
1104#ifdef MOBILETEK_TARGET_PLATFORM_T106
1105 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1106#endif
xf.li2fc84552023-06-23 05:26:47 -07001107 }
1108 else
1109 {
1110 LYERRLOG("useless qser_data_call_ip_family_e");
1111 }
1112 }
1113 return ret;
1114}
1115int qser_apn_set(qser_apn_info_s *apn)
1116{
1117 int ret = 0;
1118 if (NULL == apn)
1119 {
1120 LYERRLOG("apn set incoming paramters error");
1121 return RESULT_ERROR;
1122 }
1123 ret = apn_xml_modify(apn);
1124 if (ret < 0)
1125 {
1126 LYERRLOG("apn_xml_modify error");
1127 return ret;
1128 }
xf.li6c7e3972023-10-27 20:01:59 -07001129#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001130 int apn_id = 0;
1131 char tmp_id[12];
1132 char *outinfo = NULL;
1133 char normalprotocol[16];
1134 char authtype[32];
1135 outinfo = (char *)malloc(sizeof(char)*512);
1136 bzero(tmp_id,12);
1137 bzero(outinfo,512);
1138 apn_id = apn->profile_idx + apndb_offset;
1139 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1140 judge_pdp_type(apn->pdp_type,normalprotocol);
1141 judge_authtype(apn->auth_proto,authtype);
1142 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1143 LYINFLOG("[output]:%s",outinfo);
1144 free(outinfo);
1145 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001146#endif
1147 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001148}
1149
1150int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1151{
1152 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
1153 {
1154 LYERRLOG("apn get incoming paramters error");
1155 return RESULT_ERROR;
1156 }
1157 int ret = 0;
1158 ret = apn_xml_query(profile_idx,apn);
1159 if (ret < 0)
1160 {
1161 LYERRLOG("apn_xml_query error");
1162 return ret;
1163 }
1164 return ret;
1165}
1166
1167int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1168{
1169 int ret = 0;
1170 if (NULL == apn || NULL == profile_idx)
1171 {
1172 LYERRLOG("apn add incoming paramters error");
1173 return RESULT_ERROR;
1174 }
1175 ret = apn_xml_add(apn,profile_idx);
1176 if (ret < 0)
1177 {
1178 LYERRLOG("apn_xml_add error");
1179 return ret;
1180 }
xf.li6c7e3972023-10-27 20:01:59 -07001181#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001182 int apn_id = 0;
1183 char tmp_id[12];
1184 char *outinfo = NULL;
1185 char normalprotocol[16];
1186 char authtype[32];
1187 outinfo = (char *)malloc(sizeof(char)*512);
1188 bzero(tmp_id,12);
1189 bzero(outinfo,512);
1190 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1191 judge_pdp_type(apn->pdp_type,normalprotocol);
1192 judge_authtype(apn->auth_proto,authtype);
1193 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1194 LYINFLOG("[output]:%s",outinfo);
1195 free(outinfo);
1196 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001197#endif
1198 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001199}
1200
1201int qser_apn_del(unsigned char profile_idx)
1202{
1203 if (profile_idx < 0 || profile_idx > 24)
1204 {
1205 LYERRLOG("apn del incoming paramters error");
1206 return RESULT_OK;
1207 }
1208 int ret = 0;
1209 ret = apn_xml_delete(profile_idx);
1210 if (ret < 0)
1211 {
1212 LYERRLOG("apn_xml_delete error");
1213 return ret;
1214 }
xf.li6c7e3972023-10-27 20:01:59 -07001215#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001216 int apn_id = 0;
1217 char tmp_id[12];
1218 char *outinfo = NULL;
1219 outinfo = (char *)malloc(sizeof(char)*512);
1220 bzero(tmp_id,12);
1221 bzero(outinfo,512);
1222 apn_id = profile_idx+apndb_offset;
1223 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1224 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1225 LYINFLOG("[output]:%s",outinfo);
1226 free(outinfo);
1227 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001228#endif
xf.li2fc84552023-06-23 05:26:47 -07001229 return ret;
1230}
1231
1232int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1233{
1234 if (NULL == apn_list)
1235 {
1236 LYERRLOG("apn_list incoming paramters error");
1237 return RESULT_ERROR;
1238 }
1239 int ret = 0;
1240 ret = apn_xml_query_list(apn_list);
1241 if (ret < 0)
1242 {
1243 LYERRLOG("apn_xml_query_list error");
1244 return ret;
1245 }
1246 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001247}
you.chen21c62b72023-09-08 09:41:11 +08001248
1249DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1250