blob: cae5273ecd6b649fd62e9b77c3d4024b31ae40ad [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.li8535bc02023-12-12 23:28:35 -0800837 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -0700838 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 }
xf.li8535bc02023-12-12 23:28:35 -0800851 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
852 memset(&data_urc_info, 0, sizeof(data_urc_info));
853 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -0700854 lynq_get_data_call_list(&handle,&data_urc_info);
855 /*compare paramter*/
856 data_cb_state.profile_idx = (char)handle;
xf.li8535bc02023-12-12 23:28:35 -0800857 LYINFLOG("[thread_wait_cb_status]: status=%d, suggestedRetryTime=%d, cid=%d, active=%d, type=%s, ifname=%s, addresses=%s, dnses=%s, gateways=%s, pcscf=%s, mtu=%d\n",
858 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
859 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
860 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -0700861 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -0800862 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -0700863 {
864 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
865 }
866 else if (!strcmp(data_urc_info.type,"IPV6"))
867 {
868 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
869 }
xf.li8535bc02023-12-12 23:28:35 -0800870 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -0700871 {
872 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
873 }
874 else
875 {
xf.li8535bc02023-12-12 23:28:35 -0800876 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -0700877 }
878
xf.li8535bc02023-12-12 23:28:35 -0800879 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -0700880 {
881 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
882 }
883 else
884 {
885 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
886 }
887 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
888 {
889 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
890 }
891 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
892 {
893 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
894 }
895 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
896 {
xf.li3c0a4752023-09-03 20:46:19 -0700897#ifdef MOBILETEK_TARGET_PLATFORM_T106
898 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
899#else
xf.li2fc84552023-06-23 05:26:47 -0700900 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -0700901#endif
xf.li2fc84552023-06-23 05:26:47 -0700902 }
903 else
904 {
905 LYERRLOG("unknow ip_family");
906 continue;
907 }
908 if (s_data_call_cb != NULL)
909 {
910 s_data_call_cb(&data_cb_state);
911 }
912 }
913 return NULL;
914}
915
916int qser_cb_pthread_create()
917{
918 int ret;
919 s_qser_data_cb_thread_status = 1;
920 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
921 if (ret < 0)
922 {
923 LYERRLOG("pthread create fail");
924 s_qser_data_cb_thread_status = 0;
925 return RESULT_ERROR;
926 }
927 return RESULT_OK;
928}
929
930void qser_cb_pthread_cancel()
931{
xf.li2fc84552023-06-23 05:26:47 -0700932 s_qser_data_cb_thread_status = 0;
933 if (s_cb_tid != -1)
934 {
xf.li6b0d8502023-09-04 18:49:12 -0700935 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -0700936 }
937 return;
938}
xf.li7b0bfd02023-08-03 01:11:52 -0700939int check_xml_file(const char *file)
940{
941 /* Check for existence */
942 if((access(file, F_OK)) == -1)
943 {
944 LYERRLOG("no such xml file.\n");
945 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
946 }
947
948 if((access(file, F_OK)) == -1)
949 {
950 LYERRLOG("error copy xml file.\n");
951 return -1;
952 }
953 return RESULT_OK;
954}
xf.li2fc84552023-06-23 05:26:47 -0700955
956int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
957{
958 int ret = 0;
959 int utoken = 0;
960 if (NULL == evt_cb)
961 {
962 LYERRLOG("init incoming paramters error");
963 return RESULT_ERROR;
964 }
xf.li7b0bfd02023-08-03 01:11:52 -0700965
966 ret = check_xml_file(data_xml_path);
967 if (ret != RESULT_OK)
968 {
969 LYERRLOG("check xml file error");
970 return RESULT_ERROR;
971 }
972
xf.li2fc84552023-06-23 05:26:47 -0700973 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -0700974
xf.li2fc84552023-06-23 05:26:47 -0700975 ret = lynq_init_data(utoken);
976 if (ret != RESULT_OK)
977 {
xf.li6b0d8502023-09-04 18:49:12 -0700978 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700979 s_data_call_cb = NULL;
980 return RESULT_ERROR;
981 }
xf.li6b0d8502023-09-04 18:49:12 -0700982 qser_cb_pthread_create();
xf.lie3f55f42023-12-01 22:47:33 -0800983 apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
984 if(NULL == apn_table_xml_pdoc)
985 {
986 LYERRLOG("open xml file error");
987 return RESULT_ERROR;
988 }
xf.li2fc84552023-06-23 05:26:47 -0700989 return RESULT_OK;
990}
991
992void qser_data_call_destroy(void)
993{
xf.li6b0d8502023-09-04 18:49:12 -0700994 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.lie3f55f42023-12-01 22:47:33 -0800995 if(apn_table_xml_pdoc)
996 {
997 xmlFreeDoc(apn_table_xml_pdoc);
998 }
xf.li2fc84552023-06-23 05:26:47 -0700999 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001000 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001001 s_data_call_cb = NULL;
xf.li6b0d8502023-09-04 18:49:12 -07001002 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001003 return ;
1004}
1005
1006int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1007{
1008 int ret = -1;
1009 int handle = 0;
1010 if (NULL == data_call || NULL == err)
1011 {
1012 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001013 if(err != NULL)
1014 {
1015 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1016 }
xf.li2fc84552023-06-23 05:26:47 -07001017 return ret;
1018 }
1019 if (data_call->profile_idx == 0)
1020 {
1021 ret = lynq_setup_data_call(&handle);
1022 }
1023 else
1024 {
1025 char pdptype[16];
1026 qser_apn_info_s apn_info;
xf.li0fc26502023-09-16 02:10:17 -07001027 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1028 if (ret != 0)
1029 {
1030 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001031 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001032 return ret;
1033 }
xf.li2fc84552023-06-23 05:26:47 -07001034 judge_pdp_type(apn_info.pdp_type,pdptype);
1035 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1036 }
xf.lic12b3702023-11-22 22:39:01 -08001037 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001038 {
1039 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1040 }
1041 return ret;
1042}
1043
xf.li8535bc02023-12-12 23:28:35 -08001044int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1045{
1046 int ret = -1;
1047 int handle = 0;
1048 if (NULL == data_call || NULL == err)
1049 {
1050 LYERRLOG("call start incoming paramters error");
1051 if(err != NULL)
1052 {
1053 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1054 }
1055 return ret;
1056 }
1057 if (data_call->profile_idx == 0)
1058 {
1059 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1060 }
1061 else
1062 {
1063 char pdptype[16];
1064 qser_apn_info_s apn_info;
1065 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1066 if (ret != 0)
1067 {
1068 LYERRLOG("qser_apn_get error");
1069 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1070 return ret;
1071 }
1072 judge_pdp_type(apn_info.pdp_type,pdptype);
1073 ret = lynq_setup_data_call_sp_t106_async(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1074 }
1075 if (ret != 0)
1076 {
1077 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1078 }
1079 return ret;
1080}
1081
xf.li2fc84552023-06-23 05:26:47 -07001082int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1083{
1084 int ret = 0;
1085 int handle = -1;
1086
1087 if (NULL == err)
1088 {
1089 LYERRLOG("call stop incoming paramters error");
1090 return ret;
1091 }
xf.lic12b3702023-11-22 22:39:01 -08001092 ret = data_call_handle_get(profile_idx,&handle);
1093 if(ret != 0)
1094 {
1095 LYERRLOG("datacall handle get error");
1096 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1097 return ret;
1098 }
xf.li2fc84552023-06-23 05:26:47 -07001099 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001100 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001101 {
1102 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001103 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001104 }
xy.hee2daacc2023-09-18 00:57:51 -07001105 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001106}
1107int 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)
1108{
1109 int ret = 0;
1110 int handle = -1;
1111 lynq_data_call_response_v11_t data_call_info;
1112 data_call_handle_get(profile_idx,&handle);
1113 ret = lynq_get_data_call_list(&handle,&data_call_info);
1114 if (ret == 0)
1115 {
1116 info->profile_idx = profile_idx;
1117 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001118 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 -07001119 {
1120 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001121 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001122 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1123 lynq_ipv4_aton_getinfo(&data_call_info,info);
1124 }
xf.li3c0a4752023-09-03 20:46:19 -07001125 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001126 {
1127 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001128 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001129 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1130 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1131 }
xf.li3c0a4752023-09-03 20:46:19 -07001132 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001133 {
1134 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001135 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001136 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 -07001137#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001138 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001139#endif
xf.li2fc84552023-06-23 05:26:47 -07001140 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001141 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001142 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 -07001143#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001144 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001145#endif
1146#ifdef MOBILETEK_TARGET_PLATFORM_T106
1147 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1148#endif
xf.li2fc84552023-06-23 05:26:47 -07001149 }
1150 else
1151 {
1152 LYERRLOG("useless qser_data_call_ip_family_e");
1153 }
1154 }
1155 return ret;
1156}
1157int qser_apn_set(qser_apn_info_s *apn)
1158{
1159 int ret = 0;
1160 if (NULL == apn)
1161 {
1162 LYERRLOG("apn set incoming paramters error");
1163 return RESULT_ERROR;
1164 }
1165 ret = apn_xml_modify(apn);
1166 if (ret < 0)
1167 {
1168 LYERRLOG("apn_xml_modify error");
1169 return ret;
1170 }
xf.li6c7e3972023-10-27 20:01:59 -07001171#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001172 int apn_id = 0;
1173 char tmp_id[12];
1174 char *outinfo = NULL;
1175 char normalprotocol[16];
1176 char authtype[32];
1177 outinfo = (char *)malloc(sizeof(char)*512);
1178 bzero(tmp_id,12);
1179 bzero(outinfo,512);
1180 apn_id = apn->profile_idx + apndb_offset;
1181 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1182 judge_pdp_type(apn->pdp_type,normalprotocol);
1183 judge_authtype(apn->auth_proto,authtype);
1184 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1185 LYINFLOG("[output]:%s",outinfo);
1186 free(outinfo);
1187 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001188#endif
1189 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001190}
1191
1192int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1193{
1194 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
1195 {
1196 LYERRLOG("apn get incoming paramters error");
1197 return RESULT_ERROR;
1198 }
1199 int ret = 0;
1200 ret = apn_xml_query(profile_idx,apn);
1201 if (ret < 0)
1202 {
1203 LYERRLOG("apn_xml_query error");
1204 return ret;
1205 }
1206 return ret;
1207}
1208
1209int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1210{
1211 int ret = 0;
1212 if (NULL == apn || NULL == profile_idx)
1213 {
1214 LYERRLOG("apn add incoming paramters error");
1215 return RESULT_ERROR;
1216 }
1217 ret = apn_xml_add(apn,profile_idx);
1218 if (ret < 0)
1219 {
1220 LYERRLOG("apn_xml_add error");
1221 return ret;
1222 }
xf.li6c7e3972023-10-27 20:01:59 -07001223#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001224 int apn_id = 0;
1225 char tmp_id[12];
1226 char *outinfo = NULL;
1227 char normalprotocol[16];
1228 char authtype[32];
1229 outinfo = (char *)malloc(sizeof(char)*512);
1230 bzero(tmp_id,12);
1231 bzero(outinfo,512);
1232 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1233 judge_pdp_type(apn->pdp_type,normalprotocol);
1234 judge_authtype(apn->auth_proto,authtype);
1235 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1236 LYINFLOG("[output]:%s",outinfo);
1237 free(outinfo);
1238 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001239#endif
1240 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001241}
1242
1243int qser_apn_del(unsigned char profile_idx)
1244{
1245 if (profile_idx < 0 || profile_idx > 24)
1246 {
1247 LYERRLOG("apn del incoming paramters error");
1248 return RESULT_OK;
1249 }
1250 int ret = 0;
1251 ret = apn_xml_delete(profile_idx);
1252 if (ret < 0)
1253 {
1254 LYERRLOG("apn_xml_delete error");
1255 return ret;
1256 }
xf.li6c7e3972023-10-27 20:01:59 -07001257#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001258 int apn_id = 0;
1259 char tmp_id[12];
1260 char *outinfo = NULL;
1261 outinfo = (char *)malloc(sizeof(char)*512);
1262 bzero(tmp_id,12);
1263 bzero(outinfo,512);
1264 apn_id = profile_idx+apndb_offset;
1265 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1266 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1267 LYINFLOG("[output]:%s",outinfo);
1268 free(outinfo);
1269 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001270#endif
xf.li2fc84552023-06-23 05:26:47 -07001271 return ret;
1272}
1273
1274int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1275{
1276 if (NULL == apn_list)
1277 {
1278 LYERRLOG("apn_list incoming paramters error");
1279 return RESULT_ERROR;
1280 }
1281 int ret = 0;
1282 ret = apn_xml_query_list(apn_list);
1283 if (ret < 0)
1284 {
1285 LYERRLOG("apn_xml_query_list error");
1286 return ret;
1287 }
1288 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001289}
you.chen21c62b72023-09-08 09:41:11 +08001290
1291DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1292