blob: c22a7bb6ac02ffb4c0f716c133efe9178d25ae07 [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
xf.li03baf1f2023-12-19 21:30:38 -0800132 char buf_ip[64] = {0};
133 char buf_gateway[64] = {0};
134 char buf_pri_dns[64] = {0};
135 char buf_sec_dns[64] = {0};
136
xf.li3c0a4752023-09-03 20:46:19 -0700137 addresses = libdata->addresses;
138 dnses = libdata->dnses;
139 //get addresses
140 tmp_char = strsep(&addresses, addresses_separator);
141 if(tmp_char != NULL)
142 {
143 LYINFLOG("ipv4 addresses = %s", tmp_char);
144 inet_aton(tmp_char,&(data_res->v4.ip));
145 }
146 tmp_char = strsep(&addresses, addresses_separator);
147 if(tmp_char != NULL)
148 {
149 LYINFLOG("ipv6 addresses = %s", tmp_char);
150 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
151 }
152 //get dnses
153 tmp_char = strsep(&dnses, dnses_separator);
154 if(tmp_char != NULL)
155 {
156 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
157 inet_aton(tmp_char,&(data_res->v4.pri_dns));
158 }
159 tmp_char = strsep(&dnses, dnses_separator);
160 if(tmp_char != NULL)
161 {
162 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
163 inet_aton(tmp_char, &(data_res->v4.sec_dns));
164 }
165 tmp_char = strsep(&dnses, dnses_separator);
166 if(tmp_char != NULL)
167 {
168 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
169 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
170 }
171 tmp_char = strsep(&dnses, dnses_separator);
172 if(tmp_char != NULL)
173 {
174 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
175 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
176 }
177 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800178 inet_aton(libdata->gateways,&(data_res->v4.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700179 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
180
xf.li03baf1f2023-12-19 21:30:38 -0800181 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip));
182 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns));
183 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns));
184
185 inet_ntop(AF_INET6, &(data_res->v6.ip), buf_ip, sizeof(buf_ip));
186 inet_ntop(AF_INET6, &(data_res->v6.gateway), buf_gateway, sizeof(buf_gateway));
187 inet_ntop(AF_INET6, &(data_res->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
188 inet_ntop(AF_INET6, &(data_res->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
189 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
190 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
xf.li2fc84552023-06-23 05:26:47 -0700191 return ;
192}
193
194void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
195{
xf.li3c0a4752023-09-03 20:46:19 -0700196#ifdef MOBILETEK_TARGET_PLATFORM_T106
197 char *tmp_char = NULL;
198 char *addresses = NULL;
199 char *dnses = NULL;
200 const char addresses_separator[2] = "/";
201 const char dnses_separator[2] = " ";
202
203 addresses = libdata->addresses;
204 dnses = libdata->dnses;
205 //get addresses
206 tmp_char = strsep(&addresses, addresses_separator);
207 if(tmp_char != NULL)
208 {
209 LYINFLOG("ipv4 addresses = %s", tmp_char);
210 inet_aton(tmp_char,&(data_res->v4.addr.ip));
211 }
212 //get dnses
213 tmp_char = strsep(&dnses, dnses_separator);
214 if(tmp_char != NULL)
215 {
216 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
217 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
218 }
219 tmp_char = strsep(&dnses, dnses_separator);
220 if(tmp_char != NULL)
221 {
222 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
223 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
224 }
225 //get gateway
226 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
227 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
228
229 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
230 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
231 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
232#else
xf.li2fc84552023-06-23 05:26:47 -0700233 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
234 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
235 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
236 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700237#endif
xf.li2fc84552023-06-23 05:26:47 -0700238 data_res->v4.stats.pkts_tx = 0;
239 data_res->v4.stats.pkts_rx = 0;
240 data_res->v4.stats.bytes_tx = 0;
241 data_res->v4.stats.bytes_rx = 0;
242 data_res->v4.stats.pkts_dropped_tx = 0;
243 data_res->v4.stats.pkts_dropped_rx = 0;
244 return ;
245}
246
247void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
248{
xf.li3c0a4752023-09-03 20:46:19 -0700249#ifdef MOBILETEK_TARGET_PLATFORM_T106
250 char *tmp_char = NULL;
251 char *addresses = NULL;
252 char *dnses = NULL;
253 const char addresses_separator[2] = "/";
254 const char dnses_separator[2] = " ";
255
256 addresses = libdata->addresses;
257 dnses = libdata->dnses;
258 //get addresses
259 tmp_char = strsep(&addresses, addresses_separator);
260 if(tmp_char != NULL)
261 {
262 LYINFLOG("ipv6 addresses = %s", tmp_char);
263 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
264 }
265 //get dnses
266 tmp_char = strsep(&dnses, dnses_separator);
267 if(tmp_char != NULL)
268 {
269 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
270 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
271 }
272 tmp_char = strsep(&dnses, dnses_separator);
273 if(tmp_char != NULL)
274 {
275 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
276 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
277 }
278 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
279#else
xf.li2fc84552023-06-23 05:26:47 -0700280 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
281 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
282 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
283 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700284#endif
285 data_res->v6.stats.pkts_tx = 0;
286 data_res->v6.stats.pkts_rx = 0;
287 data_res->v6.stats.bytes_tx = 0;
288 data_res->v6.stats.bytes_rx = 0;
289 data_res->v6.stats.pkts_dropped_tx = 0;
290 data_res->v6.stats.pkts_dropped_rx = 0;
291 return ;
292}
293void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
294{
295 char *tmp_char = NULL;
296 char *addresses = NULL;
297 char *dnses = NULL;
298 const char addresses_separator[2] = "/";
299 const char dnses_separator[2] = " ";
300
301 char buf_ip[64] = {0};
302 char buf_gateway[64] = {0};
303 char buf_pri_dns[64] = {0};
304 char buf_sec_dns[64] = {0};
305
306 addresses = libdata->addresses;
307 dnses = libdata->dnses;
308 //get addresses
309 tmp_char = strsep(&addresses, addresses_separator);
310 if(tmp_char != NULL)
311 {
312 LYINFLOG("ipv4 addresses = %s", tmp_char);
313 inet_aton(tmp_char,&(data_res->v4.addr.ip));
314 }
315 tmp_char = strsep(&addresses, addresses_separator);
316 if(tmp_char != NULL)
317 {
318 LYINFLOG("ipv6 addresses = %s", tmp_char);
319 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
320 }
321 //get dnses
322 tmp_char = strsep(&dnses, dnses_separator);
323 if(tmp_char != NULL)
324 {
325 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
326 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
327 }
328 tmp_char = strsep(&dnses, dnses_separator);
329 if(tmp_char != NULL)
330 {
331 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
332 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
333 }
334 tmp_char = strsep(&dnses, dnses_separator);
335 if(tmp_char != NULL)
336 {
337 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
338 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
339 }
340 tmp_char = strsep(&dnses, dnses_separator);
341 if(tmp_char != NULL)
342 {
343 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
344 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
345 }
346 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800347 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700348 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
349
350 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
xf.li03baf1f2023-12-19 21:30:38 -0800351 LYINFLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700352 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
353 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
354
355 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
356 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
357 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
358 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
359 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
360 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
361 data_res->v4.stats.pkts_tx = 0;
362 data_res->v4.stats.pkts_rx = 0;
363 data_res->v4.stats.bytes_tx = 0;
364 data_res->v4.stats.bytes_rx = 0;
365 data_res->v4.stats.pkts_dropped_tx = 0;
366 data_res->v4.stats.pkts_dropped_rx = 0;
367
xf.li2fc84552023-06-23 05:26:47 -0700368 data_res->v6.stats.pkts_tx = 0;
369 data_res->v6.stats.pkts_rx = 0;
370 data_res->v6.stats.bytes_tx = 0;
371 data_res->v6.stats.bytes_rx = 0;
372 data_res->v6.stats.pkts_dropped_tx = 0;
373 data_res->v6.stats.pkts_dropped_rx = 0;
374 return ;
375}
376
377void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
378{
xf.lib5dc0632023-11-30 18:20:35 -0800379 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700380 {
381 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
382 data_res->v4.reconnect = 1;
383 }
384 else
385 {
386 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
387 data_res->v4.reconnect = 0;
388 }
389 return ;
390}
391
392void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
393{
xf.lib5dc0632023-11-30 18:20:35 -0800394 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700395 {
396 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
397 data_res->v6.reconnect = 1;
398 }
399 else
400 {
401 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
402 data_res->v6.reconnect = 0;
403 }
404 return ;
405}
406
407
408int apn_xml_add(qser_apn_add_s *apn,unsigned char *apn_num)
409{
410 int node_num = 0;
411 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800412 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700413 xmlNodePtr node = NULL;
414 xmlNodePtr tmp_node = NULL;
415 xmlNodePtr sum_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800416
417// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
418 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700419 {
420 LYERRLOG("open xml file error");
421 goto FAILED;
422 }
423
xf.lie3f55f42023-12-01 22:47:33 -0800424 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700425 if (NULL == node)
426 {
427 LYERRLOG("xmlDocGetRootElement() error");
428 goto FAILED;
429 }
430 sum_node = node->xmlChildrenNode;
431 sum_node = sum_node->next;
432 while (sum_node != NULL)
433 {
434 if (xmlGetProp(sum_node, "profile_idx") == NULL) //Null Node
435 {
436 sum_node = sum_node->next;
437 continue;
438 }
xf.lif7c68e32023-10-10 23:18:42 -0700439 else if(strcmp((char *)xmlGetProp(sum_node, "apn_type"), apn->apn_type) == 0)
440 {
441 LYERRLOG("apntype already exists\n");
442 goto FAILED;
443 }
xf.li2fc84552023-06-23 05:26:47 -0700444 node_num++;
445 sum_node = sum_node->next;
446 }
xf.li3f891cb2023-08-23 23:11:24 -0700447 LYINFLOG("apn_num = %d ",node_num);
448 if(node_num >= QSER_APN_MAX_LIST)
449 {
450 LYERRLOG("apn num reached the max");
451 goto FAILED;
452 }
xf.li2fc84552023-06-23 05:26:47 -0700453 tmp_node = xmlNewNode(NULL,BAD_CAST"apn");
454 *apn_num = node_num;
xf.li2fc84552023-06-23 05:26:47 -0700455 bzero(temp_buff,12);
456 snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num);
457 xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
458 bzero(temp_buff,12);
459 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
460 xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
461 bzero(temp_buff,12);
462 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
463 xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
464 xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
465 xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username);
466 xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password);
467 xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
468 xmlAddChild(node,tmp_node);
xf.lie3f55f42023-12-01 22:47:33 -0800469 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
470
471// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700472 return RESULT_OK;
473
474 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800475 /* if (apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700476 {
xf.lie3f55f42023-12-01 22:47:33 -0800477 xmlFreeDoc(apn_table_xml_pdoc);
478 }*/
xf.li2fc84552023-06-23 05:26:47 -0700479 return RESULT_ERROR;
480}
481
482int apn_xml_delete(unsigned char profile_idx)
483{
484 int node_num = 0;
485 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800486 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700487 xmlNodePtr node = NULL;
488 xmlNodePtr modify_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800489 // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
490 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700491 {
492 LYERRLOG("open xml file error");
493 goto FAILED;
494 }
495
xf.lie3f55f42023-12-01 22:47:33 -0800496 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700497 if (NULL == node)
498 {
499 LYERRLOG("xmlDocGetRootElement() error");
500 goto FAILED;
501 }
502 modify_node = node->xmlChildrenNode;
xf.li029a9e72023-11-04 02:29:45 -0700503 if(modify_node != NULL)
504 {
505 modify_node = modify_node->next;
506 }
507 else
508 {
509 LYERRLOG("modify_node is null\n");
510 goto FAILED;
511 }
xf.li2fc84552023-06-23 05:26:47 -0700512 for (node_num=0 ;node_num<(int)profile_idx ; node_num++)
513 {
xf.li029a9e72023-11-04 02:29:45 -0700514 if(modify_node == NULL)
515 {
516 LYERRLOG("modify_node is null\n");
517 goto FAILED;
518 }
xf.li2fc84552023-06-23 05:26:47 -0700519 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
520 {
521 modify_node = modify_node->next;
522 node_num--;
523 continue;
524 }
525 modify_node = modify_node->next;
526 }
xf.li029a9e72023-11-04 02:29:45 -0700527 if(modify_node == NULL)
528 {
529 LYERRLOG("modify_node is null\n");
530 goto FAILED;
531 }
xf.li2fc84552023-06-23 05:26:47 -0700532 xmlUnlinkNode(modify_node);
533 xmlFreeNode(modify_node);
534 modify_node = NULL;
535 node_num = 0;
536 modify_node = node->xmlChildrenNode;
537 modify_node = modify_node->next;
538 while (modify_node != NULL)
539 {
540 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
541 {
542 modify_node = modify_node->next;
543 continue;
544 }
545 bzero(temp_buff,12);
546 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
547 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
548 modify_node = modify_node->next;
549 node_num++;
550 }
xf.lie3f55f42023-12-01 22:47:33 -0800551 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
552// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700553 return RESULT_OK;
554
555 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800556 // if (apn_table_xml_pdoc)
557 // {
558 // xmlFreeDoc(apn_table_xml_pdoc);
559 // }
xf.li2fc84552023-06-23 05:26:47 -0700560 return RESULT_ERROR;
561}
562
563int apn_xml_modify(qser_apn_info_s *apn)
564{
565 int node_num = 0;
566 char temp_buff[12];
xf.lie3f55f42023-12-01 22:47:33 -0800567 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700568 xmlNodePtr node = NULL;
569 xmlNodePtr modify_node = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800570// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
571 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700572 {
573 LYERRLOG("open xml file error");
574 goto FAILED;
575 }
576
xf.lie3f55f42023-12-01 22:47:33 -0800577 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700578 if (NULL == node)
579 {
580 LYERRLOG("xmlDocGetRootElement() error");
581 goto FAILED;
582 }
583 modify_node = node->xmlChildrenNode;
xf.lifb8bf042023-12-13 18:09:49 -0800584 if(modify_node != NULL)
585 {
586 modify_node = modify_node->next;
587 }
588 else
589 {
590 LYERRLOG("modify_node is null\n");
591 goto FAILED;
592 }
xf.li2fc84552023-06-23 05:26:47 -0700593 for (node_num=0; node_num<(int)apn->profile_idx;node_num++)
594 {
xf.lifb8bf042023-12-13 18:09:49 -0800595 if(modify_node == NULL)
596 {
597 LYERRLOG("modify_node is null\n");
598 goto FAILED;
599 }
xf.li2fc84552023-06-23 05:26:47 -0700600 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
601 {
602 modify_node = modify_node->next;
603 node_num--;
604 continue;
605 }
606 modify_node = modify_node->next;
607 }
xf.lifb8bf042023-12-13 18:09:49 -0800608 if(modify_node == NULL)
609 {
610 LYERRLOG("modify_node is null\n");
611 goto FAILED;
612 }
xf.li2fc84552023-06-23 05:26:47 -0700613 bzero(temp_buff,12);
614 snprintf(temp_buff,sizeof(temp_buff),"%d",node_num);
615 xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff);
616 bzero(temp_buff,12);
617 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type);
618 xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff);
619 bzero(temp_buff,12);
620 snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto);
621 xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff);
622 xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name);
623 xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username);
624 xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password);
625 xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type);
xf.lie3f55f42023-12-01 22:47:33 -0800626 xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
627// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700628 return RESULT_OK;
629
630 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800631 // if (apn_table_xml_pdoc)
632 // {
633 // xmlFreeDoc(apn_table_xml_pdoc);
634 // }
xf.li2fc84552023-06-23 05:26:47 -0700635 return RESULT_ERROR;
636}
637
638
639int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn)
640{
641 int node_num = 0;
xf.lie3f55f42023-12-01 22:47:33 -0800642 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700643 xmlNodePtr node = NULL;
644 xmlNodePtr modify_node = NULL;
645 unsigned char temp = NULL;
xf.lie3f55f42023-12-01 22:47:33 -0800646// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
647 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700648 {
649 LYERRLOG("open xml file error");
650 goto FAILED;
651 }
652
xf.lie3f55f42023-12-01 22:47:33 -0800653 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700654 if (NULL == node)
655 {
656 LYERRLOG("xmlDocGetRootElement() error");
657 goto FAILED;
658 }
659 modify_node = node->xmlChildrenNode;
xf.libf9df4c2023-07-02 02:42:35 -0700660 if(modify_node != NULL)
xf.li2fc84552023-06-23 05:26:47 -0700661 {
xf.libf9df4c2023-07-02 02:42:35 -0700662 modify_node = modify_node->next;
663 }
664 else
665 {
666 LYERRLOG("modify_node is null\n");
667 goto FAILED;
668 }
669 LYINFLOG("profile_idx is %d\n", (int)profile_idx);
670 for (node_num = 0;(node_num<(int)profile_idx);node_num++)
671 {
672 if(modify_node == NULL)
673 {
674 LYERRLOG("modify_node is null\n");
675 goto FAILED;
676 }
xf.li2fc84552023-06-23 05:26:47 -0700677 if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node
678 {
679 modify_node = modify_node->next;
680 node_num--;
681 continue;
682 }
683 modify_node = modify_node->next;
xf.li029a9e72023-11-04 02:29:45 -0700684 }
685 if(modify_node == NULL)
686 {
687 LYERRLOG("modify_node is null\n");
688 goto FAILED;
xf.li2fc84552023-06-23 05:26:47 -0700689 }
690 apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx"));
691 apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
692 apn->auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto"));
xf.li6c7e3972023-10-27 20:01:59 -0700693 strncpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
694 strncpy(apn->username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
695 strncpy(apn->password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
696 strncpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE);
xf.lie3f55f42023-12-01 22:47:33 -0800697// xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
698// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700699 return RESULT_OK;
700
701 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800702 // if (apn_table_xml_pdoc)
703 // {
704 // xmlFreeDoc(apn_table_xml_pdoc);
705 // }
xf.li2fc84552023-06-23 05:26:47 -0700706 return RESULT_ERROR;
707}
708
709int apn_xml_query_list(qser_apn_info_list_s *apn_list)
710{
711 int node_num = 0;
xf.lie3f55f42023-12-01 22:47:33 -0800712 //xmlDocPtr apn_table_xml_pdoc = NULL;
xf.li2fc84552023-06-23 05:26:47 -0700713 xmlNodePtr node = NULL;
714 xmlNodePtr modify_node = NULL;
715 xmlChar *temp_char;
716 char temp[64];
xf.lie3f55f42023-12-01 22:47:33 -0800717// apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
718 if(NULL == apn_table_xml_pdoc)
xf.li2fc84552023-06-23 05:26:47 -0700719 {
720 LYERRLOG("open xml file error");
721 goto FAILED;
722 }
723
xf.lie3f55f42023-12-01 22:47:33 -0800724 node = xmlDocGetRootElement(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700725 if (NULL == node)
726 {
727 LYERRLOG("xmlDocGetRootElement() error");
728 goto FAILED;
729 }
730 modify_node = node->xmlChildrenNode;
731 modify_node = modify_node->next;
732 while (modify_node != NULL)
733 {
734 temp_char = xmlGetProp(modify_node, "profile_idx");
735 if (temp_char == NULL)
736 {
737 modify_node = modify_node->next;
738 continue;
739 }
740 sprintf(temp,"%s",temp_char);
741 apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp);
742 apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type"));
743 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 -0700744 strncpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE);
745 strncpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE);
746 strncpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE);
747 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 -0700748 node_num ++;
749 modify_node = modify_node->next;
750 }
751 apn_list->cnt = node_num;
xf.lie3f55f42023-12-01 22:47:33 -0800752// xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1);
753// xmlFreeDoc(apn_table_xml_pdoc);
xf.li2fc84552023-06-23 05:26:47 -0700754 return RESULT_OK;
755
756 FAILED:
xf.lie3f55f42023-12-01 22:47:33 -0800757 // if (apn_table_xml_pdoc)
758 // {
759 // xmlFreeDoc(apn_table_xml_pdoc);
760 // }
xf.li2fc84552023-06-23 05:26:47 -0700761 return RESULT_ERROR;
762}
763
764void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
765{
766 switch (pdp_type)
767 {
768 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -0800769#ifdef MOBILETEK_TARGET_PLATFORM_T106
770 strcpy(out_pdp_type,"IP");
771#else
xf.li2fc84552023-06-23 05:26:47 -0700772 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -0800773#endif
xf.li2fc84552023-06-23 05:26:47 -0700774 break;
775 case QSER_APN_PDP_TYPE_PPP:
776 strcpy(out_pdp_type,"PPP");
777 break;
778 case QSER_APN_PDP_TYPE_IPV6:
779 strcpy(out_pdp_type,"IPV6");
780 break;
781 case QSER_APN_PDP_TYPE_IPV4V6:
782 strcpy(out_pdp_type,"IPV4V6");
783 break;
784 default:
785 strcpy(out_pdp_type,"NULL");
786 break;
787 }
788 return;
789}
790void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
791{
792 switch (auth_proto)
793 {
794 case QSER_APN_AUTH_PROTO_DEFAULT:
795 strcpy(out_proto,"NULL;authType=0");
796 break;
797 case QSER_APN_AUTH_PROTO_NONE:
798 strcpy(out_proto,"NULL;authType=1");
799 break;
800 case QSER_APN_AUTH_PROTO_PAP:
801 strcpy(out_proto,"NULL;authType=2");
802 break;
803 case QSER_APN_AUTH_PROTO_CHAP:
804 strcpy(out_proto,"NULL;authtype=3");
805 break;
806 case QSER_APN_AUTH_PROTO_PAP_CHAP:
807 strcpy(out_proto,"NULL;authtype=4");
808 break;
809 default:
810 strcpy(out_proto,"NULL;authType=NULL");
811 break;
812 }
813 return ;
814}
815
816int data_call_handle_get(const char profile_idx,int *handle)
817{
818 int num = LYNQ_APN_CHANNEL_MAX;
819 int table_num = 0;
820 lynq_apn_info **apn_table = NULL;
821 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -0700822 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -0700823 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
824 if (NULL == apn_table)
825 {
826 LYERRLOG("malloc apn_table fail ");
827 return RESULT_ERROR;
828 }
829 for(int i =0;i<10;i++)
830 {
831 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
832 if (apn_table[i]==NULL)
833 {
834 for (int n=0;n<i;n++)
835 {
836 free(apn_table[n]);
837 }
838 return RESULT_ERROR;
839 }
840 memset(apn_table[i],0,sizeof(lynq_apn_info));
841 }
842 lynq_get_apn_table(&table_num,apn_table);
843 memset(&apn,0,sizeof(qser_apn_info_s));
xf.li0fc26502023-09-16 02:10:17 -0700844 ret = apn_xml_query(profile_idx,&apn);
845 if (ret < 0)
846 {
847 LYERRLOG("apn_xml_query error");
848 return ret;
849 }
xf.li2fc84552023-06-23 05:26:47 -0700850 for (int j = 0;j < table_num;j++)
851 {
852 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
853 {
854 *handle = apn_table[j]->index;
855 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
856 break;
857 }
858 }
859
860 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
861 {
862 if (apn_table[i]!=NULL)
863 {
864 free(apn_table[i]);
865 apn_table[i]=NULL;
866 }
867 }
868 free(apn_table);
869 apn_table=NULL;
870 LYINFLOG("data_call_handle_get end");
871 return RESULT_OK;
872}
873
874void *thread_wait_cb_status(void)
875{
876 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -0700877 int ret = 0;
xf.li8535bc02023-12-12 23:28:35 -0800878 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -0700879 qser_data_call_state_s data_cb_state;
880 while (s_qser_data_cb_thread_status)
881 {
xf.li6b0d8502023-09-04 18:49:12 -0700882 ret = lynq_wait_data_call_state_change(&handle);
883 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
884 if(s_qser_data_cb_thread_status == 0)
885 {
886 return NULL;
887 }
888 else if(ret < 0)
889 {
890 continue;
891 }
xf.li8535bc02023-12-12 23:28:35 -0800892 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
893 memset(&data_urc_info, 0, sizeof(data_urc_info));
894 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -0700895 lynq_get_data_call_list(&handle,&data_urc_info);
896 /*compare paramter*/
897 data_cb_state.profile_idx = (char)handle;
xf.li8535bc02023-12-12 23:28:35 -0800898 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",
899 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
900 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
901 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -0700902 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -0800903 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -0700904 {
905 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
906 }
907 else if (!strcmp(data_urc_info.type,"IPV6"))
908 {
909 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
910 }
xf.li8535bc02023-12-12 23:28:35 -0800911 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -0700912 {
913 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
914 }
915 else
916 {
xf.li8535bc02023-12-12 23:28:35 -0800917 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -0700918 }
919
xf.li8535bc02023-12-12 23:28:35 -0800920 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -0700921 {
922 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
923 }
924 else
925 {
926 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
927 }
928 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
929 {
930 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
931 }
932 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
933 {
934 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
935 }
936 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
937 {
xf.li3c0a4752023-09-03 20:46:19 -0700938#ifdef MOBILETEK_TARGET_PLATFORM_T106
939 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
940#else
xf.li2fc84552023-06-23 05:26:47 -0700941 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -0700942#endif
xf.li2fc84552023-06-23 05:26:47 -0700943 }
944 else
945 {
946 LYERRLOG("unknow ip_family");
947 continue;
948 }
949 if (s_data_call_cb != NULL)
950 {
951 s_data_call_cb(&data_cb_state);
952 }
953 }
954 return NULL;
955}
956
957int qser_cb_pthread_create()
958{
959 int ret;
960 s_qser_data_cb_thread_status = 1;
961 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
962 if (ret < 0)
963 {
964 LYERRLOG("pthread create fail");
965 s_qser_data_cb_thread_status = 0;
966 return RESULT_ERROR;
967 }
968 return RESULT_OK;
969}
970
971void qser_cb_pthread_cancel()
972{
xf.li2fc84552023-06-23 05:26:47 -0700973 s_qser_data_cb_thread_status = 0;
974 if (s_cb_tid != -1)
975 {
xf.li6b0d8502023-09-04 18:49:12 -0700976 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -0700977 }
978 return;
979}
xf.li7b0bfd02023-08-03 01:11:52 -0700980int check_xml_file(const char *file)
981{
982 /* Check for existence */
983 if((access(file, F_OK)) == -1)
984 {
985 LYERRLOG("no such xml file.\n");
986 system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/");
987 }
988
989 if((access(file, F_OK)) == -1)
990 {
991 LYERRLOG("error copy xml file.\n");
992 return -1;
993 }
994 return RESULT_OK;
995}
xf.li2fc84552023-06-23 05:26:47 -0700996
997int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
998{
999 int ret = 0;
1000 int utoken = 0;
1001 if (NULL == evt_cb)
1002 {
1003 LYERRLOG("init incoming paramters error");
1004 return RESULT_ERROR;
1005 }
xf.li7b0bfd02023-08-03 01:11:52 -07001006
1007 ret = check_xml_file(data_xml_path);
1008 if (ret != RESULT_OK)
1009 {
1010 LYERRLOG("check xml file error");
1011 return RESULT_ERROR;
1012 }
1013
xf.li2fc84552023-06-23 05:26:47 -07001014 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -07001015
xf.li2fc84552023-06-23 05:26:47 -07001016 ret = lynq_init_data(utoken);
1017 if (ret != RESULT_OK)
1018 {
xf.li6b0d8502023-09-04 18:49:12 -07001019 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001020 s_data_call_cb = NULL;
1021 return RESULT_ERROR;
1022 }
xf.li6b0d8502023-09-04 18:49:12 -07001023 qser_cb_pthread_create();
xf.lie3f55f42023-12-01 22:47:33 -08001024 apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER);
1025 if(NULL == apn_table_xml_pdoc)
1026 {
1027 LYERRLOG("open xml file error");
1028 return RESULT_ERROR;
1029 }
xf.lib33d4862023-12-13 00:40:37 -08001030 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001031 return RESULT_OK;
1032}
1033
1034void qser_data_call_destroy(void)
1035{
xf.li6b0d8502023-09-04 18:49:12 -07001036 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.lie3f55f42023-12-01 22:47:33 -08001037 if(apn_table_xml_pdoc)
1038 {
1039 xmlFreeDoc(apn_table_xml_pdoc);
1040 }
xf.li2fc84552023-06-23 05:26:47 -07001041 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001042 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001043 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001044 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001045 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001046 return ;
1047}
1048
1049int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1050{
1051 int ret = -1;
1052 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001053 if(g_lynq_qser_data_init_flag == 0)
1054 {
1055 if(err != NULL)
1056 {
1057 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1058 }
1059 return LYNQ_E_NO_INIT;
1060 }
xf.li2fc84552023-06-23 05:26:47 -07001061 if (NULL == data_call || NULL == err)
1062 {
1063 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001064 if(err != NULL)
1065 {
1066 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1067 }
xf.li2fc84552023-06-23 05:26:47 -07001068 return ret;
1069 }
1070 if (data_call->profile_idx == 0)
1071 {
1072 ret = lynq_setup_data_call(&handle);
1073 }
1074 else
1075 {
1076 char pdptype[16];
1077 qser_apn_info_s apn_info;
xf.li0fc26502023-09-16 02:10:17 -07001078 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1079 if (ret != 0)
1080 {
1081 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001082 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001083 return ret;
1084 }
xf.li2fc84552023-06-23 05:26:47 -07001085 judge_pdp_type(apn_info.pdp_type,pdptype);
1086 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1087 }
xf.lic12b3702023-11-22 22:39:01 -08001088 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001089 {
1090 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1091 }
1092 return ret;
1093}
1094
xf.li8535bc02023-12-12 23:28:35 -08001095int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1096{
1097 int ret = -1;
1098 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001099 if(g_lynq_qser_data_init_flag == 0)
1100 {
1101 if(err != NULL)
1102 {
1103 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1104 }
1105 return LYNQ_E_NO_INIT;
1106 }
xf.li8535bc02023-12-12 23:28:35 -08001107 if (NULL == data_call || NULL == err)
1108 {
1109 LYERRLOG("call start incoming paramters error");
1110 if(err != NULL)
1111 {
1112 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1113 }
1114 return ret;
1115 }
1116 if (data_call->profile_idx == 0)
1117 {
1118 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1119 }
1120 else
1121 {
1122 char pdptype[16];
1123 qser_apn_info_s apn_info;
1124 ret = qser_apn_get(data_call->profile_idx,&apn_info);
1125 if (ret != 0)
1126 {
1127 LYERRLOG("qser_apn_get error");
1128 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1129 return ret;
1130 }
1131 judge_pdp_type(apn_info.pdp_type,pdptype);
1132 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);
1133 }
1134 if (ret != 0)
1135 {
1136 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1137 }
1138 return ret;
1139}
1140
xf.li2fc84552023-06-23 05:26:47 -07001141int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1142{
1143 int ret = 0;
1144 int handle = -1;
1145
xf.lib33d4862023-12-13 00:40:37 -08001146 if(g_lynq_qser_data_init_flag == 0)
1147 {
1148 if(err != NULL)
1149 {
1150 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1151 }
1152 return LYNQ_E_NO_INIT;
1153 }
xf.li2fc84552023-06-23 05:26:47 -07001154 if (NULL == err)
1155 {
1156 LYERRLOG("call stop incoming paramters error");
1157 return ret;
1158 }
xf.lic12b3702023-11-22 22:39:01 -08001159 ret = data_call_handle_get(profile_idx,&handle);
1160 if(ret != 0)
1161 {
1162 LYERRLOG("datacall handle get error");
1163 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1164 return ret;
1165 }
xf.li2fc84552023-06-23 05:26:47 -07001166 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001167 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001168 {
1169 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001170 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001171 }
xy.hee2daacc2023-09-18 00:57:51 -07001172 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001173}
1174int 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)
1175{
1176 int ret = 0;
1177 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001178 if(g_lynq_qser_data_init_flag == 0)
1179 {
1180 if(err != NULL)
1181 {
1182 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1183 }
1184 return LYNQ_E_NO_INIT;
1185 }
xf.li2fc84552023-06-23 05:26:47 -07001186 lynq_data_call_response_v11_t data_call_info;
1187 data_call_handle_get(profile_idx,&handle);
1188 ret = lynq_get_data_call_list(&handle,&data_call_info);
1189 if (ret == 0)
1190 {
1191 info->profile_idx = profile_idx;
1192 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001193 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 -07001194 {
1195 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001196 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001197 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1198 lynq_ipv4_aton_getinfo(&data_call_info,info);
1199 }
xf.li3c0a4752023-09-03 20:46:19 -07001200 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001201 {
1202 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001203 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001204 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1205 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1206 }
xf.li3c0a4752023-09-03 20:46:19 -07001207 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001208 {
1209 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001210 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001211 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 -07001212#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001213 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001214#endif
xf.li2fc84552023-06-23 05:26:47 -07001215 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001216 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001217 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 -07001218#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001219 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001220#endif
1221#ifdef MOBILETEK_TARGET_PLATFORM_T106
1222 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1223#endif
xf.li2fc84552023-06-23 05:26:47 -07001224 }
1225 else
1226 {
1227 LYERRLOG("useless qser_data_call_ip_family_e");
1228 }
1229 }
1230 return ret;
1231}
1232int qser_apn_set(qser_apn_info_s *apn)
1233{
1234 int ret = 0;
xf.lib33d4862023-12-13 00:40:37 -08001235 if(g_lynq_qser_data_init_flag == 0)
1236 {
1237 return LYNQ_E_NO_INIT;
1238 }
xf.li2fc84552023-06-23 05:26:47 -07001239 if (NULL == apn)
1240 {
1241 LYERRLOG("apn set incoming paramters error");
1242 return RESULT_ERROR;
1243 }
1244 ret = apn_xml_modify(apn);
1245 if (ret < 0)
1246 {
1247 LYERRLOG("apn_xml_modify error");
1248 return ret;
1249 }
xf.li6c7e3972023-10-27 20:01:59 -07001250#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001251 int apn_id = 0;
1252 char tmp_id[12];
1253 char *outinfo = NULL;
1254 char normalprotocol[16];
1255 char authtype[32];
1256 outinfo = (char *)malloc(sizeof(char)*512);
1257 bzero(tmp_id,12);
1258 bzero(outinfo,512);
1259 apn_id = apn->profile_idx + apndb_offset;
1260 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1261 judge_pdp_type(apn->pdp_type,normalprotocol);
1262 judge_authtype(apn->auth_proto,authtype);
1263 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1264 LYINFLOG("[output]:%s",outinfo);
1265 free(outinfo);
1266 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001267#endif
1268 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001269}
1270
1271int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1272{
xf.lib33d4862023-12-13 00:40:37 -08001273 if(g_lynq_qser_data_init_flag == 0)
1274 {
1275 return LYNQ_E_NO_INIT;
1276 }
xf.li2fc84552023-06-23 05:26:47 -07001277 if (profile_idx < 0 || profile_idx > 24 || NULL == apn)
1278 {
1279 LYERRLOG("apn get incoming paramters error");
1280 return RESULT_ERROR;
1281 }
1282 int ret = 0;
1283 ret = apn_xml_query(profile_idx,apn);
1284 if (ret < 0)
1285 {
1286 LYERRLOG("apn_xml_query error");
1287 return ret;
1288 }
1289 return ret;
1290}
1291
1292int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1293{
1294 int ret = 0;
xf.lib33d4862023-12-13 00:40:37 -08001295 if(g_lynq_qser_data_init_flag == 0)
1296 {
1297 return LYNQ_E_NO_INIT;
1298 }
xf.li2fc84552023-06-23 05:26:47 -07001299 if (NULL == apn || NULL == profile_idx)
1300 {
1301 LYERRLOG("apn add incoming paramters error");
1302 return RESULT_ERROR;
1303 }
1304 ret = apn_xml_add(apn,profile_idx);
1305 if (ret < 0)
1306 {
1307 LYERRLOG("apn_xml_add error");
1308 return ret;
1309 }
xf.li6c7e3972023-10-27 20:01:59 -07001310#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001311 int apn_id = 0;
1312 char tmp_id[12];
1313 char *outinfo = NULL;
1314 char normalprotocol[16];
1315 char authtype[32];
1316 outinfo = (char *)malloc(sizeof(char)*512);
1317 bzero(tmp_id,12);
1318 bzero(outinfo,512);
1319 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1320 judge_pdp_type(apn->pdp_type,normalprotocol);
1321 judge_authtype(apn->auth_proto,authtype);
1322 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1323 LYINFLOG("[output]:%s",outinfo);
1324 free(outinfo);
1325 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001326#endif
1327 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001328}
1329
1330int qser_apn_del(unsigned char profile_idx)
1331{
xf.lib33d4862023-12-13 00:40:37 -08001332 if(g_lynq_qser_data_init_flag == 0)
1333 {
1334 return LYNQ_E_NO_INIT;
1335 }
xf.li2fc84552023-06-23 05:26:47 -07001336 if (profile_idx < 0 || profile_idx > 24)
1337 {
1338 LYERRLOG("apn del incoming paramters error");
1339 return RESULT_OK;
1340 }
1341 int ret = 0;
1342 ret = apn_xml_delete(profile_idx);
1343 if (ret < 0)
1344 {
1345 LYERRLOG("apn_xml_delete error");
1346 return ret;
1347 }
xf.li6c7e3972023-10-27 20:01:59 -07001348#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001349 int apn_id = 0;
1350 char tmp_id[12];
1351 char *outinfo = NULL;
1352 outinfo = (char *)malloc(sizeof(char)*512);
1353 bzero(tmp_id,12);
1354 bzero(outinfo,512);
1355 apn_id = profile_idx+apndb_offset;
1356 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1357 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1358 LYINFLOG("[output]:%s",outinfo);
1359 free(outinfo);
1360 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001361#endif
xf.li2fc84552023-06-23 05:26:47 -07001362 return ret;
1363}
1364
1365int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1366{
xf.lib33d4862023-12-13 00:40:37 -08001367 if(g_lynq_qser_data_init_flag == 0)
1368 {
1369 return LYNQ_E_NO_INIT;
1370 }
xf.li2fc84552023-06-23 05:26:47 -07001371 if (NULL == apn_list)
1372 {
1373 LYERRLOG("apn_list incoming paramters error");
1374 return RESULT_ERROR;
1375 }
1376 int ret = 0;
1377 ret = apn_xml_query_list(apn_list);
1378 if (ret < 0)
1379 {
1380 LYERRLOG("apn_xml_query_list error");
1381 return ret;
1382 }
1383 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001384}
you.chen21c62b72023-09-08 09:41:11 +08001385
1386DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1387