blob: eebf913e4d7149e05fdd92540b5081dbc41cbfa4 [file] [log] [blame]
xf.li2fc84552023-06-23 05:26:47 -07001#include <stdio.h>
2#include <stdint.h>
3#include <sys/types.h>
4#include <arpa/inet.h>
5#include <string.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <log/log.h>
9#include <libdata/lynq_data.h>
10#include <liblog/lynq_deflog.h>
11#include <pthread.h>
12#include <libxml/tree.h>
13#include <libxml/parser.h>
14#include "lynq-qser-data.h"
15
16#define USER_LOG_TAG "LYNQ_QSER_DATA"
17
18#define RESULT_OK (0)
19#define RESULT_ERROR (-1)
20
xf.lib33d4862023-12-13 00:40:37 -080021typedef enum{
22 LYNQ_E_NO_INIT=9002
23}LYNQ_E;
24
25static int g_lynq_qser_data_init_flag = 0;
xf.li2fc84552023-06-23 05:26:47 -070026static pthread_t s_cb_tid = -1;
27static int s_qser_data_cb_thread_status = 0;
28static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
29static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER;
30
xf.li807fd132023-07-02 02:45:36 -070031#define data_xml_path "/mnt/userdata/lynq_qser_data_apn.xml"
xf.li7b0bfd02023-08-03 01:11:52 -070032#define COPY_XML_RETRY_TIMES 3
xf.li2fc84552023-06-23 05:26:47 -070033
34static qser_data_call_evt_cb_t s_data_call_cb = NULL;
xf.lie3f55f42023-12-01 22:47:33 -080035static xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -070036const int apndb_offset = 683;
37
38void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
39{
xf.li3c0a4752023-09-03 20:46:19 -070040#ifdef MOBILETEK_TARGET_PLATFORM_T106
41 char *tmp_char = NULL;
42 char *addresses = NULL;
43 char *dnses = NULL;
44 const char addresses_separator[2] = "/";
45 const char dnses_separator[2] = " ";
46
47 addresses = libdata->addresses;
48 dnses = libdata->dnses;
49 //get addresses
50 tmp_char = strsep(&addresses, addresses_separator);
51 if(tmp_char != NULL)
52 {
53 LYINFLOG("ipv4 addresses = %s", tmp_char);
54 inet_aton(tmp_char,&(data_res->v4.ip));
55 }
56
57 //get dnses
58 tmp_char = strsep(&dnses, dnses_separator);
59 if(tmp_char != NULL)
60 {
61 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
62 inet_aton(tmp_char,&(data_res->v4.pri_dns));
63 }
64 tmp_char = strsep(&dnses, dnses_separator);
65 if(tmp_char != NULL)
66 {
67 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
68 inet_aton(tmp_char, &(data_res->v4.sec_dns));
69 }
70 //get gateway
71 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
72
73#else
xf.li2fc84552023-06-23 05:26:47 -070074 inet_aton(libdata->addresses,&(data_res->v4.ip));
75 inet_aton(libdata->gateways,&(data_res->v4.gateway));
76 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
77 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -070078#endif
xf.li2fc84552023-06-23 05:26:47 -070079 return ;
80}
81
82void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
83{
xf.li3c0a4752023-09-03 20:46:19 -070084#ifdef MOBILETEK_TARGET_PLATFORM_T106
85 char *tmp_char = NULL;
86 char *addresses = NULL;
87 char *dnses = NULL;
88 const char addresses_separator[2] = "/";
89 const char dnses_separator[2] = " ";
90
91 addresses = libdata->addresses;
92 dnses = libdata->dnses;
93 //get addresses
94 tmp_char = strsep(&addresses, addresses_separator);
95 if(tmp_char != NULL)
96 {
97 LYINFLOG("ipv6 addresses = %s", tmp_char);
98 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
99 }
100 //get dnses
101 tmp_char = strsep(&dnses, dnses_separator);
102 if(tmp_char != NULL)
103 {
104 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
105 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
106 }
107 tmp_char = strsep(&dnses, dnses_separator);
108 if(tmp_char != NULL)
109 {
110 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
111 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
112 }
113 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
114#else
xf.li2fc84552023-06-23 05:26:47 -0700115 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
116 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
117 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
118 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700119#endif
120
121 return ;
122}
123
124void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
125{
126 char *tmp_char = NULL;
127 char *addresses = NULL;
128 char *dnses = NULL;
129 const char addresses_separator[2] = "/";
130 const char dnses_separator[2] = " ";
131
132 addresses = libdata->addresses;
133 dnses = libdata->dnses;
134 //get addresses
135 tmp_char = strsep(&addresses, addresses_separator);
136 if(tmp_char != NULL)
137 {
138 LYINFLOG("ipv4 addresses = %s", tmp_char);
139 inet_aton(tmp_char,&(data_res->v4.ip));
140 }
141 tmp_char = strsep(&addresses, addresses_separator);
142 if(tmp_char != NULL)
143 {
144 LYINFLOG("ipv6 addresses = %s", tmp_char);
145 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
146 }
147 //get dnses
148 tmp_char = strsep(&dnses, dnses_separator);
149 if(tmp_char != NULL)
150 {
151 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
152 inet_aton(tmp_char,&(data_res->v4.pri_dns));
153 }
154 tmp_char = strsep(&dnses, dnses_separator);
155 if(tmp_char != NULL)
156 {
157 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
158 inet_aton(tmp_char, &(data_res->v4.sec_dns));
159 }
160 tmp_char = strsep(&dnses, dnses_separator);
161 if(tmp_char != NULL)
162 {
163 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
164 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
165 }
166 tmp_char = strsep(&dnses, dnses_separator);
167 if(tmp_char != NULL)
168 {
169 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
170 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
171 }
172 //get gateway
173 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
174
xf.li2fc84552023-06-23 05:26:47 -0700175 return ;
176}
177
178void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
179{
xf.li3c0a4752023-09-03 20:46:19 -0700180#ifdef MOBILETEK_TARGET_PLATFORM_T106
181 char *tmp_char = NULL;
182 char *addresses = NULL;
183 char *dnses = NULL;
184 const char addresses_separator[2] = "/";
185 const char dnses_separator[2] = " ";
186
187 addresses = libdata->addresses;
188 dnses = libdata->dnses;
189 //get addresses
190 tmp_char = strsep(&addresses, addresses_separator);
191 if(tmp_char != NULL)
192 {
193 LYINFLOG("ipv4 addresses = %s", tmp_char);
194 inet_aton(tmp_char,&(data_res->v4.addr.ip));
195 }
196 //get dnses
197 tmp_char = strsep(&dnses, dnses_separator);
198 if(tmp_char != NULL)
199 {
200 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
201 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
202 }
203 tmp_char = strsep(&dnses, dnses_separator);
204 if(tmp_char != NULL)
205 {
206 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
207 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
208 }
209 //get gateway
210 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
211 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
212
213 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
214 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
215 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
216#else
xf.li2fc84552023-06-23 05:26:47 -0700217 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
218 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
219 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
220 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700221#endif
xf.li2fc84552023-06-23 05:26:47 -0700222 data_res->v4.stats.pkts_tx = 0;
223 data_res->v4.stats.pkts_rx = 0;
224 data_res->v4.stats.bytes_tx = 0;
225 data_res->v4.stats.bytes_rx = 0;
226 data_res->v4.stats.pkts_dropped_tx = 0;
227 data_res->v4.stats.pkts_dropped_rx = 0;
228 return ;
229}
230
231void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
232{
xf.li3c0a4752023-09-03 20:46:19 -0700233#ifdef MOBILETEK_TARGET_PLATFORM_T106
234 char *tmp_char = NULL;
235 char *addresses = NULL;
236 char *dnses = NULL;
237 const char addresses_separator[2] = "/";
238 const char dnses_separator[2] = " ";
239
240 addresses = libdata->addresses;
241 dnses = libdata->dnses;
242 //get addresses
243 tmp_char = strsep(&addresses, addresses_separator);
244 if(tmp_char != NULL)
245 {
246 LYINFLOG("ipv6 addresses = %s", tmp_char);
247 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
248 }
249 //get dnses
250 tmp_char = strsep(&dnses, dnses_separator);
251 if(tmp_char != NULL)
252 {
253 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
254 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
255 }
256 tmp_char = strsep(&dnses, dnses_separator);
257 if(tmp_char != NULL)
258 {
259 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
260 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
261 }
262 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
263#else
xf.li2fc84552023-06-23 05:26:47 -0700264 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
265 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
266 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
267 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700268#endif
269 data_res->v6.stats.pkts_tx = 0;
270 data_res->v6.stats.pkts_rx = 0;
271 data_res->v6.stats.bytes_tx = 0;
272 data_res->v6.stats.bytes_rx = 0;
273 data_res->v6.stats.pkts_dropped_tx = 0;
274 data_res->v6.stats.pkts_dropped_rx = 0;
275 return ;
276}
277void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
278{
279 char *tmp_char = NULL;
280 char *addresses = NULL;
281 char *dnses = NULL;
282 const char addresses_separator[2] = "/";
283 const char dnses_separator[2] = " ";
284
285 char buf_ip[64] = {0};
286 char buf_gateway[64] = {0};
287 char buf_pri_dns[64] = {0};
288 char buf_sec_dns[64] = {0};
289
290 addresses = libdata->addresses;
291 dnses = libdata->dnses;
292 //get addresses
293 tmp_char = strsep(&addresses, addresses_separator);
294 if(tmp_char != NULL)
295 {
296 LYINFLOG("ipv4 addresses = %s", tmp_char);
297 inet_aton(tmp_char,&(data_res->v4.addr.ip));
298 }
299 tmp_char = strsep(&addresses, addresses_separator);
300 if(tmp_char != NULL)
301 {
302 LYINFLOG("ipv6 addresses = %s", tmp_char);
303 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
304 }
305 //get dnses
306 tmp_char = strsep(&dnses, dnses_separator);
307 if(tmp_char != NULL)
308 {
309 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
310 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
311 }
312 tmp_char = strsep(&dnses, dnses_separator);
313 if(tmp_char != NULL)
314 {
315 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
316 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
317 }
318 tmp_char = strsep(&dnses, dnses_separator);
319 if(tmp_char != NULL)
320 {
321 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
322 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
323 }
324 tmp_char = strsep(&dnses, dnses_separator);
325 if(tmp_char != NULL)
326 {
327 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
328 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
329 }
330 //get gateway
331 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
332
333 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
334 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
335 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
336
337 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
338 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
339 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
340 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
341 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
342 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
343 data_res->v4.stats.pkts_tx = 0;
344 data_res->v4.stats.pkts_rx = 0;
345 data_res->v4.stats.bytes_tx = 0;
346 data_res->v4.stats.bytes_rx = 0;
347 data_res->v4.stats.pkts_dropped_tx = 0;
348 data_res->v4.stats.pkts_dropped_rx = 0;
349
xf.li2fc84552023-06-23 05:26:47 -0700350 data_res->v6.stats.pkts_tx = 0;
351 data_res->v6.stats.pkts_rx = 0;
352 data_res->v6.stats.bytes_tx = 0;
353 data_res->v6.stats.bytes_rx = 0;
354 data_res->v6.stats.pkts_dropped_tx = 0;
355 data_res->v6.stats.pkts_dropped_rx = 0;
356 return ;
357}
358
359void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
360{
xf.lib5dc0632023-11-30 18:20:35 -0800361 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700362 {
363 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
364 data_res->v4.reconnect = 1;
365 }
366 else
367 {
368 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
369 data_res->v4.reconnect = 0;
370 }
371 return ;
372}
373
374void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
375{
xf.lib5dc0632023-11-30 18:20:35 -0800376 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700377 {
378 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
379 data_res->v6.reconnect = 1;
380 }
381 else
382 {
383 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
384 data_res->v6.reconnect = 0;
385 }
386 return ;
387}
388
389
390int apn_xml_add(qser_apn_add_s *apn,unsigned char *apn_num)
391{
392 int node_num = 0;
393 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800394 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700395 xmlNodePtr node = NULL;
396 xmlNodePtr tmp_node = NULL;
397 xmlNodePtr sum_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800398
399// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
400 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700401 {
402 LYERRLOG("open xml file error");
403 goto FAILED;
404 }
405
xf.lie3f55f42023-12-01 22:47:33 -0800406 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700407 if (NULL == node)
408 {
409 LYERRLOG("xmlDocGetRootElement() error");
410 goto FAILED;
411 }
412 sum_node = node->xmlChildrenNode;
413 sum_node = sum_node->next;
414 while (sum_node != NULL)
415 {
416 if (xmlGetProp(sum_node, "profile_idx") == NULL) //Null Node
417 {
418 sum_node = sum_node->next;
419 continue;
420 }
xf.lif7c68e32023-10-10 23:18:42 -0700421 else if(strcmp((char *)xmlGetProp(sum_node, "apn_type"), apn->apn_type) == 0)
422 {
423 LYERRLOG("apntype already exists\n");
424 goto FAILED;
425 }
xf.li2fc84552023-06-23 05:26:47 -0700426 node_num++;
427 sum_node = sum_node->next;
428 }
xf.li3f891cb2023-08-23 23:11:24 -0700429 LYINFLOG("apn_num = %d ",node_num);
430 if(node_num >= QSER_APN_MAX_LIST)
431 {
432 LYERRLOG("apn num reached the max");
433 goto FAILED;
434 }
xf.li2fc84552023-06-23 05:26:47 -0700435 tmp_node = xmlNewNode(NULL,BAD_CAST"apn");
436 *apn_num = node_num;
xf.li2fc84552023-06-23 05:26:47 -0700437 bzero(temp_buff,12);
438 snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num);
439 xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
440 bzero(temp_buff,12);
441 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
442 xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
443 bzero(temp_buff,12);
444 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
445 xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
446 xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
447 xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username);
448 xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password);
449 xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
450 xmlAddChild(node,tmp_node);
xf.lie3f55f42023-12-01 22:47:33 -0800451 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
452
453// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700454 return RESULT_OK;
455
456 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800457 /* if (apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700458 {
xf.lie3f55f42023-12-01 22:47:33 -0800459 xmlFreeDoc(apn_table_xml_pdoc);
460 }*/
xf.li2fc84552023-06-23 05:26:47 -0700461 return RESULT_ERROR;
462}
463
464int apn_xml_delete(unsigned char profile_idx)
465{
466 int node_num = 0;
467 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800468 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700469 xmlNodePtr node = NULL;
470 xmlNodePtr modify_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800471 // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
472 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700473 {
474 LYERRLOG("open xml file error");
475 goto FAILED;
476 }
477
xf.lie3f55f42023-12-01 22:47:33 -0800478 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700479 if (NULL == node)
480 {
481 LYERRLOG("xmlDocGetRootElement() error");
482 goto FAILED;
483 }
484 modify_node = node->xmlChildrenNode;
xf.li029a9e72023-11-04 02:29:45 -0700485 if(modify_node != NULL)
486 {
487 modify_node = modify_node->next;
488 }
489 else
490 {
491 LYERRLOG("modify_node is null\n");
492 goto FAILED;
493 }
xf.li2fc84552023-06-23 05:26:47 -0700494 for (node_num=0 ;node_num<(int)profile_idx ; node_num++)
495 {
xf.li029a9e72023-11-04 02:29:45 -0700496 if(modify_node == NULL)
497 {
498 LYERRLOG("modify_node is null\n");
499 goto FAILED;
500 }
xf.li2fc84552023-06-23 05:26:47 -0700501 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
502 {
503 modify_node = modify_node->next;
504 node_num--;
505 continue;
506 }
507 modify_node = modify_node->next;
508 }
xf.li029a9e72023-11-04 02:29:45 -0700509 if(modify_node == NULL)
510 {
511 LYERRLOG("modify_node is null\n");
512 goto FAILED;
513 }
xf.li2fc84552023-06-23 05:26:47 -0700514 xmlUnlinkNode(modify_node);
515 xmlFreeNode(modify_node);
516 modify_node = NULL;
517 node_num = 0;
518 modify_node = node->xmlChildrenNode;
519 modify_node = modify_node->next;
520 while (modify_node != NULL)
521 {
522 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
523 {
524 modify_node = modify_node->next;
525 continue;
526 }
527 bzero(temp_buff,12);
528 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
529 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
530 modify_node = modify_node->next;
531 node_num++;
532 }
xf.lie3f55f42023-12-01 22:47:33 -0800533 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
534// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700535 return RESULT_OK;
536
537 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800538 // if (apn_table_xml_pdoc)
539 // {
540 // xmlFreeDoc(apn_table_xml_pdoc);
541 // }
xf.li2fc84552023-06-23 05:26:47 -0700542 return RESULT_ERROR;
543}
544
545int apn_xml_modify(qser_apn_info_s *apn)
546{
547 int node_num = 0;
548 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800549 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700550 xmlNodePtr node = NULL;
551 xmlNodePtr modify_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800552// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
553 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700554 {
555 LYERRLOG("open xml file error");
556 goto FAILED;
557 }
558
xf.lie3f55f42023-12-01 22:47:33 -0800559 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700560 if (NULL == node)
561 {
562 LYERRLOG("xmlDocGetRootElement() error");
563 goto FAILED;
564 }
565 modify_node = node->xmlChildrenNode;
566 modify_node = modify_node->next;
567 for (node_num=0; node_num<(int)apn->profile_idx;node_num++)
568 {
569 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
570 {
571 modify_node = modify_node->next;
572 node_num--;
573 continue;
574 }
575 modify_node = modify_node->next;
576 }
577 bzero(temp_buff,12);
578 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
579 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
580 bzero(temp_buff,12);
581 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
582 xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
583 bzero(temp_buff,12);
584 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
585 xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
586 xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
587 xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username);
588 xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password);
589 xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
xf.lie3f55f42023-12-01 22:47:33 -0800590 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
591// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700592 return RESULT_OK;
593
594 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800595 // if (apn_table_xml_pdoc)
596 // {
597 // xmlFreeDoc(apn_table_xml_pdoc);
598 // }
xf.li2fc84552023-06-23 05:26:47 -0700599 return RESULT_ERROR;
600}
601
602
603int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn)
604{
605 int node_num = 0;
xf.lie3f55f42023-12-01 22:47:33 -0800606 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700607 xmlNodePtr node = NULL;
608 xmlNodePtr modify_node = NULL;
609 unsigned char temp = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800610// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
611 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700612 {
613 LYERRLOG("open xml file error");
614 goto FAILED;
615 }
616
xf.lie3f55f42023-12-01 22:47:33 -0800617 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700618 if (NULL == node)
619 {
620 LYERRLOG("xmlDocGetRootElement() error");
621 goto FAILED;
622 }
623 modify_node = node->xmlChildrenNode;
xf.libf9df4c2023-07-02 02:42:35 -0700624 if(modify_node != NULL)
xf.li2fc84552023-06-23 05:26:47 -0700625 {
xf.libf9df4c2023-07-02 02:42:35 -0700626 modify_node = modify_node->next;
627 }
628 else
629 {
630 LYERRLOG("modify_node is null\n");
631 goto FAILED;
632 }
633 LYINFLOG("profile_idx is %d\n", (int)profile_idx);
634 for (node_num = 0;(node_num<(int)profile_idx);node_num++)
635 {
636 if(modify_node == NULL)
637 {
638 LYERRLOG("modify_node is null\n");
639 goto FAILED;
640 }
xf.li2fc84552023-06-23 05:26:47 -0700641 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
642 {
643 modify_node = modify_node->next;
644 node_num--;
645 continue;
646 }
647 modify_node = modify_node->next;
xf.li029a9e72023-11-04 02:29:45 -0700648 }
649 if(modify_node == NULL)
650 {
651 LYERRLOG("modify_node is null\n");
652 goto FAILED;
xf.li2fc84552023-06-23 05:26:47 -0700653 }
654 apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx"));
655 apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
656 apn->auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto"));
xf.li6c7e3972023-10-27 20:01:59 -0700657 strncpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
658 strncpy(apn->username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
659 strncpy(apn->password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
660 strncpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE);
xf.lie3f55f42023-12-01 22:47:33 -0800661// xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
662// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700663 return RESULT_OK;
664
665 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800666 // if (apn_table_xml_pdoc)
667 // {
668 // xmlFreeDoc(apn_table_xml_pdoc);
669 // }
xf.li2fc84552023-06-23 05:26:47 -0700670 return RESULT_ERROR;
671}
672
673int apn_xml_query_list(qser_apn_info_list_s *apn_list)
674{
675 int node_num = 0;
xf.lie3f55f42023-12-01 22:47:33 -0800676 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700677 xmlNodePtr node = NULL;
678 xmlNodePtr modify_node = NULL;
679 xmlChar *temp_char;
680 char temp[64];
xf.lie3f55f42023-12-01 22:47:33 -0800681// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
682 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700683 {
684 LYERRLOG("open xml file error");
685 goto FAILED;
686 }
687
xf.lie3f55f42023-12-01 22:47:33 -0800688 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700689 if (NULL == node)
690 {
691 LYERRLOG("xmlDocGetRootElement() error");
692 goto FAILED;
693 }
694 modify_node = node->xmlChildrenNode;
695 modify_node = modify_node->next;
696 while (modify_node != NULL)
697 {
698 temp_char = xmlGetProp(modify_node, "profile_idx");
699 if (temp_char == NULL)
700 {
701 modify_node = modify_node->next;
702 continue;
703 }
704 sprintf(temp,"%s",temp_char);
705 apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp);
706 apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
707 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 -0700708 strncpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
709 strncpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
710 strncpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
711 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 -0700712 node_num ++;
713 modify_node = modify_node->next;
714 }
715 apn_list->cnt = node_num;
xf.lie3f55f42023-12-01 22:47:33 -0800716// xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
717// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700718 return RESULT_OK;
719
720 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800721 // if (apn_table_xml_pdoc)
722 // {
723 // xmlFreeDoc(apn_table_xml_pdoc);
724 // }
xf.li2fc84552023-06-23 05:26:47 -0700725 return RESULT_ERROR;
726}
727
728void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
729{
730 switch (pdp_type)
731 {
732 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -0800733#ifdef MOBILETEK_TARGET_PLATFORM_T106
734 strcpy(out_pdp_type,"IP");
735#else
xf.li2fc84552023-06-23 05:26:47 -0700736 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -0800737#endif
xf.li2fc84552023-06-23 05:26:47 -0700738 break;
739 case QSER_APN_PDP_TYPE_PPP:
740 strcpy(out_pdp_type,"PPP");
741 break;
742 case QSER_APN_PDP_TYPE_IPV6:
743 strcpy(out_pdp_type,"IPV6");
744 break;
745 case QSER_APN_PDP_TYPE_IPV4V6:
746 strcpy(out_pdp_type,"IPV4V6");
747 break;
748 default:
749 strcpy(out_pdp_type,"NULL");
750 break;
751 }
752 return;
753}
754void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
755{
756 switch (auth_proto)
757 {
758 case QSER_APN_AUTH_PROTO_DEFAULT:
759 strcpy(out_proto,"NULL;authType=0");
760 break;
761 case QSER_APN_AUTH_PROTO_NONE:
762 strcpy(out_proto,"NULL;authType=1");
763 break;
764 case QSER_APN_AUTH_PROTO_PAP:
765 strcpy(out_proto,"NULL;authType=2");
766 break;
767 case QSER_APN_AUTH_PROTO_CHAP:
768 strcpy(out_proto,"NULL;authtype=3");
769 break;
770 case QSER_APN_AUTH_PROTO_PAP_CHAP:
771 strcpy(out_proto,"NULL;authtype=4");
772 break;
773 default:
774 strcpy(out_proto,"NULL;authType=NULL");
775 break;
776 }
777 return ;
778}
779
780int data_call_handle_get(const char profile_idx,int *handle)
781{
782 int num = LYNQ_APN_CHANNEL_MAX;
783 int table_num = 0;
784 lynq_apn_info **apn_table = NULL;
785 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -0700786 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700787 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
788 if (NULL == apn_table)
789 {
790 LYERRLOG("malloc apn_table fail ");
791 return RESULT_ERROR;
792 }
793 for(int i =0;i<10;i++)
794 {
795 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
796 if (apn_table[i]==NULL)
797 {
798 for (int n=0;n<i;n++)
799 {
800 free(apn_table[n]);
801 }
802 return RESULT_ERROR;
803 }
804 memset(apn_table[i],0,sizeof(lynq_apn_info));
805 }
806 lynq_get_apn_table(&table_num,apn_table);
807 memset(&apn,0,sizeof(qser_apn_info_s));
xf.li0fc26502023-09-16 02:10:17 -0700808 ret = apn_xml_query(profile_idx,&apn);
809 if (ret < 0)
810 {
811 LYERRLOG("apn_xml_query error");
812 return ret;
813 }
xf.li2fc84552023-06-23 05:26:47 -0700814 for (int j = 0;j < table_num;j++)
815 {
816 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
817 {
818 *handle = apn_table[j]->index;
819 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
820 break;
821 }
822 }
823
824 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
825 {
826 if (apn_table[i]!=NULL)
827 {
828 free(apn_table[i]);
829 apn_table[i]=NULL;
830 }
831 }
832 free(apn_table);
833 apn_table=NULL;
834 LYINFLOG("data_call_handle_get end");
835 return RESULT_OK;
836}
837
838void *thread_wait_cb_status(void)
839{
840 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -0700841 int ret = 0;
xf.li8535bc02023-12-12 23:28:35 -0800842 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -0700843 qser_data_call_state_s data_cb_state;
844 while (s_qser_data_cb_thread_status)
845 {
xf.li6b0d8502023-09-04 18:49:12 -0700846 ret = lynq_wait_data_call_state_change(&handle);
847 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
848 if(s_qser_data_cb_thread_status == 0)
849 {
850 return NULL;
851 }
852 else if(ret < 0)
853 {
854 continue;
855 }
xf.li8535bc02023-12-12 23:28:35 -0800856 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
857 memset(&data_urc_info, 0, sizeof(data_urc_info));
858 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -0700859 lynq_get_data_call_list(&handle,&data_urc_info);
860 /*compare paramter*/
861 data_cb_state.profile_idx = (char)handle;
xf.li8535bc02023-12-12 23:28:35 -0800862 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",
863 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
864 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
865 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -0700866 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -0800867 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -0700868 {
869 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
870 }
871 else if (!strcmp(data_urc_info.type,"IPV6"))
872 {
873 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
874 }
xf.li8535bc02023-12-12 23:28:35 -0800875 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -0700876 {
877 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
878 }
879 else
880 {
xf.li8535bc02023-12-12 23:28:35 -0800881 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -0700882 }
883
xf.li8535bc02023-12-12 23:28:35 -0800884 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -0700885 {
886 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
887 }
888 else
889 {
890 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
891 }
892 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
893 {
894 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
895 }
896 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
897 {
898 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
899 }
900 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
901 {
xf.li3c0a4752023-09-03 20:46:19 -0700902#ifdef MOBILETEK_TARGET_PLATFORM_T106
903 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
904#else
xf.li2fc84552023-06-23 05:26:47 -0700905 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -0700906#endif
xf.li2fc84552023-06-23 05:26:47 -0700907 }
908 else
909 {
910 LYERRLOG("unknow ip_family");
911 continue;
912 }
913 if (s_data_call_cb != NULL)
914 {
915 s_data_call_cb(&data_cb_state);
916 }
917 }
918 return NULL;
919}
920
921int qser_cb_pthread_create()
922{
923 int ret;
924 s_qser_data_cb_thread_status = 1;
925 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
926 if (ret < 0)
927 {
928 LYERRLOG("pthread create fail");
929 s_qser_data_cb_thread_status = 0;
930 return RESULT_ERROR;
931 }
932 return RESULT_OK;
933}
934
935void qser_cb_pthread_cancel()
936{
xf.li2fc84552023-06-23 05:26:47 -0700937 s_qser_data_cb_thread_status = 0;
938 if (s_cb_tid != -1)
939 {
xf.li6b0d8502023-09-04 18:49:12 -0700940 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -0700941 }
942 return;
943}
xf.li7b0bfd02023-08-03 01:11:52 -0700944int check_xml_file(const char *file)
945{
946 /* Check for existence */
947 if((access(file, F_OK)) == -1)
948 {
949 LYERRLOG("no such xml file.\n");
950 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
951 }
952
953 if((access(file, F_OK)) == -1)
954 {
955 LYERRLOG("error copy xml file.\n");
956 return -1;
957 }
958 return RESULT_OK;
959}
xf.li2fc84552023-06-23 05:26:47 -0700960
961int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
962{
963 int ret = 0;
964 int utoken = 0;
965 if (NULL == evt_cb)
966 {
967 LYERRLOG("init incoming paramters error");
968 return RESULT_ERROR;
969 }
xf.li7b0bfd02023-08-03 01:11:52 -0700970
971 ret = check_xml_file(data_xml_path);
972 if (ret != RESULT_OK)
973 {
974 LYERRLOG("check xml file error");
975 return RESULT_ERROR;
976 }
977
xf.li2fc84552023-06-23 05:26:47 -0700978 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -0700979
xf.li2fc84552023-06-23 05:26:47 -0700980 ret = lynq_init_data(utoken);
981 if (ret != RESULT_OK)
982 {
xf.li6b0d8502023-09-04 18:49:12 -0700983 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -0700984 s_data_call_cb = NULL;
985 return RESULT_ERROR;
986 }
xf.li6b0d8502023-09-04 18:49:12 -0700987 qser_cb_pthread_create();
xf.lie3f55f42023-12-01 22:47:33 -0800988 apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
989 if(NULL == apn_table_xml_pdoc)
990 {
991 LYERRLOG("open xml file error");
992 return RESULT_ERROR;
993 }
xf.lib33d4862023-12-13 00:40:37 -0800994 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -0700995 return RESULT_OK;
996}
997
998void qser_data_call_destroy(void)
999{
xf.li6b0d8502023-09-04 18:49:12 -07001000 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.lie3f55f42023-12-01 22:47:33 -08001001 if(apn_table_xml_pdoc)
1002 {
1003 xmlFreeDoc(apn_table_xml_pdoc);
1004 }
xf.li2fc84552023-06-23 05:26:47 -07001005 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001006 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001007 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001008 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001009 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001010 return ;
1011}
1012
1013int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1014{
1015 int ret = -1;
1016 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001017 if(g_lynq_qser_data_init_flag == 0)
1018 {
1019 if(err != NULL)
1020 {
1021 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1022 }
1023 return LYNQ_E_NO_INIT;
1024 }
xf.li2fc84552023-06-23 05:26:47 -07001025 if (NULL == data_call || NULL == err)
1026 {
1027 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001028 if(err != NULL)
1029 {
1030 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1031 }
xf.li2fc84552023-06-23 05:26:47 -07001032 return ret;
1033 }
1034 if (data_call->profile_idx == 0)
1035 {
1036 ret = lynq_setup_data_call(&handle);
1037 }
1038 else
1039 {
1040 char pdptype[16];
1041 qser_apn_info_s apn_info;
xf.li0fc26502023-09-16 02:10:17 -07001042 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1043 if (ret != 0)
1044 {
1045 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001046 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001047 return ret;
1048 }
xf.li2fc84552023-06-23 05:26:47 -07001049 judge_pdp_type(apn_info.pdp_type,pdptype);
1050 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1051 }
xf.lic12b3702023-11-22 22:39:01 -08001052 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001053 {
1054 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1055 }
1056 return ret;
1057}
1058
xf.li8535bc02023-12-12 23:28:35 -08001059int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1060{
1061 int ret = -1;
1062 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001063 if(g_lynq_qser_data_init_flag == 0)
1064 {
1065 if(err != NULL)
1066 {
1067 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1068 }
1069 return LYNQ_E_NO_INIT;
1070 }
xf.li8535bc02023-12-12 23:28:35 -08001071 if (NULL == data_call || NULL == err)
1072 {
1073 LYERRLOG("call start incoming paramters error");
1074 if(err != NULL)
1075 {
1076 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1077 }
1078 return ret;
1079 }
1080 if (data_call->profile_idx == 0)
1081 {
1082 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1083 }
1084 else
1085 {
1086 char pdptype[16];
1087 qser_apn_info_s apn_info;
1088 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1089 if (ret != 0)
1090 {
1091 LYERRLOG("qser_apn_get error");
1092 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1093 return ret;
1094 }
1095 judge_pdp_type(apn_info.pdp_type,pdptype);
1096 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);
1097 }
1098 if (ret != 0)
1099 {
1100 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1101 }
1102 return ret;
1103}
1104
xf.li2fc84552023-06-23 05:26:47 -07001105int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1106{
1107 int ret = 0;
1108 int handle = -1;
1109
xf.lib33d4862023-12-13 00:40:37 -08001110 if(g_lynq_qser_data_init_flag == 0)
1111 {
1112 if(err != NULL)
1113 {
1114 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1115 }
1116 return LYNQ_E_NO_INIT;
1117 }
xf.li2fc84552023-06-23 05:26:47 -07001118 if (NULL == err)
1119 {
1120 LYERRLOG("call stop incoming paramters error");
1121 return ret;
1122 }
xf.lic12b3702023-11-22 22:39:01 -08001123 ret = data_call_handle_get(profile_idx,&handle);
1124 if(ret != 0)
1125 {
1126 LYERRLOG("datacall handle get error");
1127 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1128 return ret;
1129 }
xf.li2fc84552023-06-23 05:26:47 -07001130 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001131 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001132 {
1133 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001134 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001135 }
xy.hee2daacc2023-09-18 00:57:51 -07001136 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001137}
1138int 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)
1139{
1140 int ret = 0;
1141 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001142 if(g_lynq_qser_data_init_flag == 0)
1143 {
1144 if(err != NULL)
1145 {
1146 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1147 }
1148 return LYNQ_E_NO_INIT;
1149 }
xf.li2fc84552023-06-23 05:26:47 -07001150 lynq_data_call_response_v11_t data_call_info;
1151 data_call_handle_get(profile_idx,&handle);
1152 ret = lynq_get_data_call_list(&handle,&data_call_info);
1153 if (ret == 0)
1154 {
1155 info->profile_idx = profile_idx;
1156 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001157 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 -07001158 {
1159 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001160 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001161 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1162 lynq_ipv4_aton_getinfo(&data_call_info,info);
1163 }
xf.li3c0a4752023-09-03 20:46:19 -07001164 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001165 {
1166 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001167 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001168 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1169 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1170 }
xf.li3c0a4752023-09-03 20:46:19 -07001171 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001172 {
1173 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001174 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001175 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 -07001176#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001177 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001178#endif
xf.li2fc84552023-06-23 05:26:47 -07001179 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001180 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001181 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 -07001182#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001183 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001184#endif
1185#ifdef MOBILETEK_TARGET_PLATFORM_T106
1186 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1187#endif
xf.li2fc84552023-06-23 05:26:47 -07001188 }
1189 else
1190 {
1191 LYERRLOG("useless qser_data_call_ip_family_e");
1192 }
1193 }
1194 return ret;
1195}
1196int qser_apn_set(qser_apn_info_s *apn)
1197{
1198 int ret = 0;
xf.lib33d4862023-12-13 00:40:37 -08001199 if(g_lynq_qser_data_init_flag == 0)
1200 {
1201 return LYNQ_E_NO_INIT;
1202 }
xf.li2fc84552023-06-23 05:26:47 -07001203 if (NULL == apn)
1204 {
1205 LYERRLOG("apn set incoming paramters error");
1206 return RESULT_ERROR;
1207 }
1208 ret = apn_xml_modify(apn);
1209 if (ret < 0)
1210 {
1211 LYERRLOG("apn_xml_modify error");
1212 return ret;
1213 }
xf.li6c7e3972023-10-27 20:01:59 -07001214#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001215 int apn_id = 0;
1216 char tmp_id[12];
1217 char *outinfo = NULL;
1218 char normalprotocol[16];
1219 char authtype[32];
1220 outinfo = (char *)malloc(sizeof(char)*512);
1221 bzero(tmp_id,12);
1222 bzero(outinfo,512);
1223 apn_id = apn->profile_idx + apndb_offset;
1224 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1225 judge_pdp_type(apn->pdp_type,normalprotocol);
1226 judge_authtype(apn->auth_proto,authtype);
1227 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1228 LYINFLOG("[output]:%s",outinfo);
1229 free(outinfo);
1230 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001231#endif
1232 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001233}
1234
1235int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1236{
xf.lib33d4862023-12-13 00:40:37 -08001237 if(g_lynq_qser_data_init_flag == 0)
1238 {
1239 return LYNQ_E_NO_INIT;
1240 }
xf.li2fc84552023-06-23 05:26:47 -07001241 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
1242 {
1243 LYERRLOG("apn get incoming paramters error");
1244 return RESULT_ERROR;
1245 }
1246 int ret = 0;
1247 ret = apn_xml_query(profile_idx,apn);
1248 if (ret < 0)
1249 {
1250 LYERRLOG("apn_xml_query error");
1251 return ret;
1252 }
1253 return ret;
1254}
1255
1256int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1257{
1258 int ret = 0;
xf.lib33d4862023-12-13 00:40:37 -08001259 if(g_lynq_qser_data_init_flag == 0)
1260 {
1261 return LYNQ_E_NO_INIT;
1262 }
xf.li2fc84552023-06-23 05:26:47 -07001263 if (NULL == apn || NULL == profile_idx)
1264 {
1265 LYERRLOG("apn add incoming paramters error");
1266 return RESULT_ERROR;
1267 }
1268 ret = apn_xml_add(apn,profile_idx);
1269 if (ret < 0)
1270 {
1271 LYERRLOG("apn_xml_add error");
1272 return ret;
1273 }
xf.li6c7e3972023-10-27 20:01:59 -07001274#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001275 int apn_id = 0;
1276 char tmp_id[12];
1277 char *outinfo = NULL;
1278 char normalprotocol[16];
1279 char authtype[32];
1280 outinfo = (char *)malloc(sizeof(char)*512);
1281 bzero(tmp_id,12);
1282 bzero(outinfo,512);
1283 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1284 judge_pdp_type(apn->pdp_type,normalprotocol);
1285 judge_authtype(apn->auth_proto,authtype);
1286 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1287 LYINFLOG("[output]:%s",outinfo);
1288 free(outinfo);
1289 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001290#endif
1291 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001292}
1293
1294int qser_apn_del(unsigned char profile_idx)
1295{
xf.lib33d4862023-12-13 00:40:37 -08001296 if(g_lynq_qser_data_init_flag == 0)
1297 {
1298 return LYNQ_E_NO_INIT;
1299 }
xf.li2fc84552023-06-23 05:26:47 -07001300 if (profile_idx < 0 || profile_idx > 24)
1301 {
1302 LYERRLOG("apn del incoming paramters error");
1303 return RESULT_OK;
1304 }
1305 int ret = 0;
1306 ret = apn_xml_delete(profile_idx);
1307 if (ret < 0)
1308 {
1309 LYERRLOG("apn_xml_delete error");
1310 return ret;
1311 }
xf.li6c7e3972023-10-27 20:01:59 -07001312#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001313 int apn_id = 0;
1314 char tmp_id[12];
1315 char *outinfo = NULL;
1316 outinfo = (char *)malloc(sizeof(char)*512);
1317 bzero(tmp_id,12);
1318 bzero(outinfo,512);
1319 apn_id = profile_idx+apndb_offset;
1320 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1321 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1322 LYINFLOG("[output]:%s",outinfo);
1323 free(outinfo);
1324 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001325#endif
xf.li2fc84552023-06-23 05:26:47 -07001326 return ret;
1327}
1328
1329int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1330{
xf.lib33d4862023-12-13 00:40:37 -08001331 if(g_lynq_qser_data_init_flag == 0)
1332 {
1333 return LYNQ_E_NO_INIT;
1334 }
xf.li2fc84552023-06-23 05:26:47 -07001335 if (NULL == apn_list)
1336 {
1337 LYERRLOG("apn_list incoming paramters error");
1338 return RESULT_ERROR;
1339 }
1340 int ret = 0;
1341 ret = apn_xml_query_list(apn_list);
1342 if (ret < 0)
1343 {
1344 LYERRLOG("apn_xml_query_list error");
1345 return ret;
1346 }
1347 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001348}
you.chen21c62b72023-09-08 09:41:11 +08001349
1350DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1351