blob: 94af56b74a91e35267c68df31586930fca04591d [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>
xf.licb6cd282024-02-21 22:06:14 -080012#include <sqlite3.h>
xf.li2fc84552023-06-23 05:26:47 -070013#include "lynq-qser-data.h"
14
15#define USER_LOG_TAG "LYNQ_QSER_DATA"
xf.licb6cd282024-02-21 22:06:14 -080016#define APN_DB_PATH "/mnt/userdata/apn.db"
17#define APN_DB_READED 0
18#define APN_DB_ERR 1
19#define APN_DB_CREATE 2
xf.li2fc84552023-06-23 05:26:47 -070020#define RESULT_OK (0)
21#define RESULT_ERROR (-1)
22
xf.lib33d4862023-12-13 00:40:37 -080023typedef enum{
xf.licb6cd282024-02-21 22:06:14 -080024 LYNQ_E_NO_INIT=9002,
25 LYNQ_E_APN_DB_FAIL=9003
xf.lib33d4862023-12-13 00:40:37 -080026}LYNQ_E;
27
28static int g_lynq_qser_data_init_flag = 0;
xf.li2fc84552023-06-23 05:26:47 -070029static pthread_t s_cb_tid = -1;
30static int s_qser_data_cb_thread_status = 0;
31static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
32static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER;
33
xf.li2fc84552023-06-23 05:26:47 -070034
35static qser_data_call_evt_cb_t s_data_call_cb = NULL;
xf.licb6cd282024-02-21 22:06:14 -080036static sqlite3* apnDb;
37qser_apn_add_s default_apn = {QSER_APN_PDP_TYPE_IPV4V6, QSER_APN_AUTH_PROTO_DEFAULT, "default", "NULL", "NULL", "default"};
38int apn_indexs[LYNQ_APN_CHANNEL_MAX]={0};
39int next_index = 0;
40int apn_count = 0;
xf.li2fc84552023-06-23 05:26:47 -070041const int apndb_offset = 683;
42
xf.licb6cd282024-02-21 22:06:14 -080043static int init_apn_db();
44static int create_apn_db(char *path);
45static int create_apn_table(char*path);
46static int has_apn_db_created(char *path,sqlite3* apnDb_l);
47static int apn_db_handle_clean();
48
49static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName);
50static int lynq_check_index(unsigned char index);
51static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName);
52static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx);
53static int apn_db_handle_set(unsigned char profile_idx, int handle);
54static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName);
55static int apn_db_handle_get(unsigned char profile_idx, int *handle);
56
57static int find_unuse_apn_index(char *path);
58static int apn_db_add(int profile_id, qser_apn_add_s *apn);
59static int apn_db_delete(unsigned char profile_idx);
60static int apn_db_modify(qser_apn_info_s *apn);
61static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName);
62static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn);
63static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName);
64static int apn_db_query_list(qser_apn_info_list_s *apn_list);
65
xf.li2fc84552023-06-23 05:26:47 -070066void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
67{
xf.li3c0a4752023-09-03 20:46:19 -070068#ifdef MOBILETEK_TARGET_PLATFORM_T106
69 char *tmp_char = NULL;
70 char *addresses = NULL;
71 char *dnses = NULL;
72 const char addresses_separator[2] = "/";
73 const char dnses_separator[2] = " ";
74
75 addresses = libdata->addresses;
76 dnses = libdata->dnses;
77 //get addresses
78 tmp_char = strsep(&addresses, addresses_separator);
79 if(tmp_char != NULL)
80 {
81 LYINFLOG("ipv4 addresses = %s", tmp_char);
82 inet_aton(tmp_char,&(data_res->v4.ip));
83 }
84
85 //get dnses
86 tmp_char = strsep(&dnses, dnses_separator);
87 if(tmp_char != NULL)
88 {
89 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
90 inet_aton(tmp_char,&(data_res->v4.pri_dns));
91 }
92 tmp_char = strsep(&dnses, dnses_separator);
93 if(tmp_char != NULL)
94 {
95 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
96 inet_aton(tmp_char, &(data_res->v4.sec_dns));
97 }
98 //get gateway
99 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
100
101#else
xf.li2fc84552023-06-23 05:26:47 -0700102 inet_aton(libdata->addresses,&(data_res->v4.ip));
103 inet_aton(libdata->gateways,&(data_res->v4.gateway));
104 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
105 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700106#endif
xf.li2fc84552023-06-23 05:26:47 -0700107 return ;
108}
109
110void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
111{
xf.li3c0a4752023-09-03 20:46:19 -0700112#ifdef MOBILETEK_TARGET_PLATFORM_T106
113 char *tmp_char = NULL;
114 char *addresses = NULL;
115 char *dnses = NULL;
116 const char addresses_separator[2] = "/";
117 const char dnses_separator[2] = " ";
118
119 addresses = libdata->addresses;
120 dnses = libdata->dnses;
121 //get addresses
122 tmp_char = strsep(&addresses, addresses_separator);
123 if(tmp_char != NULL)
124 {
125 LYINFLOG("ipv6 addresses = %s", tmp_char);
126 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
127 }
128 //get dnses
129 tmp_char = strsep(&dnses, dnses_separator);
130 if(tmp_char != NULL)
131 {
132 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
133 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
134 }
135 tmp_char = strsep(&dnses, dnses_separator);
136 if(tmp_char != NULL)
137 {
138 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
139 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
140 }
141 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
142#else
xf.li2fc84552023-06-23 05:26:47 -0700143 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
144 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
145 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
146 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700147#endif
148
149 return ;
150}
151
152void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
153{
154 char *tmp_char = NULL;
155 char *addresses = NULL;
156 char *dnses = NULL;
157 const char addresses_separator[2] = "/";
158 const char dnses_separator[2] = " ";
159
xf.li03baf1f2023-12-19 21:30:38 -0800160 char buf_ip[64] = {0};
161 char buf_gateway[64] = {0};
162 char buf_pri_dns[64] = {0};
163 char buf_sec_dns[64] = {0};
164
xf.li3c0a4752023-09-03 20:46:19 -0700165 addresses = libdata->addresses;
166 dnses = libdata->dnses;
167 //get addresses
168 tmp_char = strsep(&addresses, addresses_separator);
169 if(tmp_char != NULL)
170 {
171 LYINFLOG("ipv4 addresses = %s", tmp_char);
172 inet_aton(tmp_char,&(data_res->v4.ip));
173 }
174 tmp_char = strsep(&addresses, addresses_separator);
175 if(tmp_char != NULL)
176 {
177 LYINFLOG("ipv6 addresses = %s", tmp_char);
178 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
179 }
180 //get dnses
181 tmp_char = strsep(&dnses, dnses_separator);
182 if(tmp_char != NULL)
183 {
184 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
185 inet_aton(tmp_char,&(data_res->v4.pri_dns));
186 }
187 tmp_char = strsep(&dnses, dnses_separator);
188 if(tmp_char != NULL)
189 {
190 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
191 inet_aton(tmp_char, &(data_res->v4.sec_dns));
192 }
193 tmp_char = strsep(&dnses, dnses_separator);
194 if(tmp_char != NULL)
195 {
196 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
197 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
198 }
199 tmp_char = strsep(&dnses, dnses_separator);
200 if(tmp_char != NULL)
201 {
202 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
203 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
204 }
205 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800206 inet_aton(libdata->gateways,&(data_res->v4.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700207 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
208
xf.li03baf1f2023-12-19 21:30:38 -0800209 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip));
210 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns));
211 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns));
212
213 inet_ntop(AF_INET6, &(data_res->v6.ip), buf_ip, sizeof(buf_ip));
214 inet_ntop(AF_INET6, &(data_res->v6.gateway), buf_gateway, sizeof(buf_gateway));
215 inet_ntop(AF_INET6, &(data_res->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
216 inet_ntop(AF_INET6, &(data_res->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
217 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
218 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
xf.li2fc84552023-06-23 05:26:47 -0700219 return ;
220}
221
222void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
223{
xf.li3c0a4752023-09-03 20:46:19 -0700224#ifdef MOBILETEK_TARGET_PLATFORM_T106
225 char *tmp_char = NULL;
226 char *addresses = NULL;
227 char *dnses = NULL;
228 const char addresses_separator[2] = "/";
229 const char dnses_separator[2] = " ";
230
231 addresses = libdata->addresses;
232 dnses = libdata->dnses;
233 //get addresses
234 tmp_char = strsep(&addresses, addresses_separator);
235 if(tmp_char != NULL)
236 {
237 LYINFLOG("ipv4 addresses = %s", tmp_char);
238 inet_aton(tmp_char,&(data_res->v4.addr.ip));
239 }
240 //get dnses
241 tmp_char = strsep(&dnses, dnses_separator);
242 if(tmp_char != NULL)
243 {
244 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
245 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
246 }
247 tmp_char = strsep(&dnses, dnses_separator);
248 if(tmp_char != NULL)
249 {
250 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
251 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
252 }
253 //get gateway
254 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
255 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
256
257 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
258 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
259 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
260#else
xf.li2fc84552023-06-23 05:26:47 -0700261 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
262 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
263 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
264 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700265#endif
xf.li2fc84552023-06-23 05:26:47 -0700266 data_res->v4.stats.pkts_tx = 0;
267 data_res->v4.stats.pkts_rx = 0;
268 data_res->v4.stats.bytes_tx = 0;
269 data_res->v4.stats.bytes_rx = 0;
270 data_res->v4.stats.pkts_dropped_tx = 0;
271 data_res->v4.stats.pkts_dropped_rx = 0;
272 return ;
273}
274
275void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
276{
xf.li3c0a4752023-09-03 20:46:19 -0700277#ifdef MOBILETEK_TARGET_PLATFORM_T106
278 char *tmp_char = NULL;
279 char *addresses = NULL;
280 char *dnses = NULL;
281 const char addresses_separator[2] = "/";
282 const char dnses_separator[2] = " ";
283
284 addresses = libdata->addresses;
285 dnses = libdata->dnses;
286 //get addresses
287 tmp_char = strsep(&addresses, addresses_separator);
288 if(tmp_char != NULL)
289 {
290 LYINFLOG("ipv6 addresses = %s", tmp_char);
291 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
292 }
293 //get dnses
294 tmp_char = strsep(&dnses, dnses_separator);
295 if(tmp_char != NULL)
296 {
297 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
298 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
299 }
300 tmp_char = strsep(&dnses, dnses_separator);
301 if(tmp_char != NULL)
302 {
303 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
304 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
305 }
306 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
307#else
xf.li2fc84552023-06-23 05:26:47 -0700308 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
309 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
310 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
311 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700312#endif
313 data_res->v6.stats.pkts_tx = 0;
314 data_res->v6.stats.pkts_rx = 0;
315 data_res->v6.stats.bytes_tx = 0;
316 data_res->v6.stats.bytes_rx = 0;
317 data_res->v6.stats.pkts_dropped_tx = 0;
318 data_res->v6.stats.pkts_dropped_rx = 0;
319 return ;
320}
321void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
322{
323 char *tmp_char = NULL;
324 char *addresses = NULL;
325 char *dnses = NULL;
326 const char addresses_separator[2] = "/";
327 const char dnses_separator[2] = " ";
328
329 char buf_ip[64] = {0};
330 char buf_gateway[64] = {0};
331 char buf_pri_dns[64] = {0};
332 char buf_sec_dns[64] = {0};
333
334 addresses = libdata->addresses;
335 dnses = libdata->dnses;
336 //get addresses
337 tmp_char = strsep(&addresses, addresses_separator);
338 if(tmp_char != NULL)
339 {
340 LYINFLOG("ipv4 addresses = %s", tmp_char);
341 inet_aton(tmp_char,&(data_res->v4.addr.ip));
342 }
343 tmp_char = strsep(&addresses, addresses_separator);
344 if(tmp_char != NULL)
345 {
346 LYINFLOG("ipv6 addresses = %s", tmp_char);
347 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
348 }
349 //get dnses
350 tmp_char = strsep(&dnses, dnses_separator);
351 if(tmp_char != NULL)
352 {
353 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
354 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
355 }
356 tmp_char = strsep(&dnses, dnses_separator);
357 if(tmp_char != NULL)
358 {
359 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
360 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
361 }
362 tmp_char = strsep(&dnses, dnses_separator);
363 if(tmp_char != NULL)
364 {
365 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
366 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
367 }
368 tmp_char = strsep(&dnses, dnses_separator);
369 if(tmp_char != NULL)
370 {
371 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
372 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
373 }
374 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800375 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700376 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
377
378 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
xf.li03baf1f2023-12-19 21:30:38 -0800379 LYINFLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700380 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
381 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
382
383 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
384 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
385 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
386 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
387 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
388 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
389 data_res->v4.stats.pkts_tx = 0;
390 data_res->v4.stats.pkts_rx = 0;
391 data_res->v4.stats.bytes_tx = 0;
392 data_res->v4.stats.bytes_rx = 0;
393 data_res->v4.stats.pkts_dropped_tx = 0;
394 data_res->v4.stats.pkts_dropped_rx = 0;
395
xf.li2fc84552023-06-23 05:26:47 -0700396 data_res->v6.stats.pkts_tx = 0;
397 data_res->v6.stats.pkts_rx = 0;
398 data_res->v6.stats.bytes_tx = 0;
399 data_res->v6.stats.bytes_rx = 0;
400 data_res->v6.stats.pkts_dropped_tx = 0;
401 data_res->v6.stats.pkts_dropped_rx = 0;
402 return ;
403}
404
405void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
406{
xf.lib5dc0632023-11-30 18:20:35 -0800407 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700408 {
409 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
410 data_res->v4.reconnect = 1;
411 }
412 else
413 {
414 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
415 data_res->v4.reconnect = 0;
416 }
417 return ;
418}
419
420void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
421{
xf.lib5dc0632023-11-30 18:20:35 -0800422 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700423 {
424 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
425 data_res->v6.reconnect = 1;
426 }
427 else
428 {
429 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
430 data_res->v6.reconnect = 0;
431 }
432 return ;
433}
434
xf.licb6cd282024-02-21 22:06:14 -0800435// ****************apn DB start******************
436static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName)
xf.li0fd6acf2023-12-20 18:16:34 -0800437{
xf.licb6cd282024-02-21 22:06:14 -0800438 if(data==NULL)
xf.li0fd6acf2023-12-20 18:16:34 -0800439 {
xf.licb6cd282024-02-21 22:06:14 -0800440 return 1;
xf.li0fd6acf2023-12-20 18:16:34 -0800441 }
xf.licb6cd282024-02-21 22:06:14 -0800442 int *temp = (int *)data;
443 for(int i=0; i<argc; i++){
444 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li0fd6acf2023-12-20 18:16:34 -0800445 }
xf.licb6cd282024-02-21 22:06:14 -0800446 *temp = atoi(argv[0]);
447 return 0;
448}
449static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx)
450{
451 char *zErrMsg = 0;
452 int rc;
453 int idx = 0;
454
455 /* Open database */
456 rc = sqlite3_open(APN_DB_PATH, &apnDb);
457 if( rc )
xf.li0fd6acf2023-12-20 18:16:34 -0800458 {
xf.licb6cd282024-02-21 22:06:14 -0800459 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
460 return LYNQ_E_APN_DB_FAIL;
461 }
462
463 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
464 /* Create SQL statement */
465 char *sql = sqlite3_mprintf("SELECT ID from LYNQAPN WHERE HANDLE=%d", handle);
466 LYINFLOG("sql: %s\n", sql);
467 /* Execute SQL statement */
468 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_profile_cb, &idx, &zErrMsg);
469 if( rc != SQLITE_OK )
470 {
471 LYERRLOG("SQL error: %s\n", zErrMsg);
472 sqlite3_free(zErrMsg);
473 sqlite3_close(apnDb);
474 return LYNQ_E_APN_DB_FAIL;
475 };
476 *profile_idx = (unsigned char)idx;
477 LYINFLOG("get idx %d successfully\n", *profile_idx);
478 sqlite3_close(apnDb);
479 return 0;
480}
481static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName){
482 int i;
483
484 apn_indexs[atoi(argv[0])] = atoi(argv[0]);
485 LYINFLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]);
486
487 for(i=0; i<argc; i++){
488 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
489 }
490 return 0;
491}
492/**
493 * @brief Check whether the ID exists in the database
494 *
495 * @param index
496 * @return int
497 * find:turn 1
498 * not find:turn 0
499 */
500static int lynq_check_index(unsigned char index)
501{
502 memset(apn_indexs,0,sizeof(apn_indexs));
503 next_index = 0;
504 char *zErrMsg = 0;
505 int rc;
506 char sql[128]={0};
507 /* Open database */
508 rc = sqlite3_open(APN_DB_PATH, &apnDb);
509 if( rc )
510 {
511 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
512 return LYNQ_E_APN_DB_FAIL;
513 }
514 sprintf(sql,"%s", "SELECT * from LYNQAPN");
515 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback, NULL, &zErrMsg);
516 if( rc != SQLITE_OK )
517 {
518 LYERRLOG("SQL error: %s\n", zErrMsg);
519 sqlite3_free(zErrMsg);
520 sqlite3_close(apnDb);
521 return LYNQ_E_APN_DB_FAIL;
522 }
523 //for(int cnt = 0; cnt < next_index;cnt++)
524 for(int cnt = 0; cnt <= QSER_APN_MAX_LIST; cnt++)
525 {
526 if(index == apn_indexs[cnt])
527 {
528 LYINFLOG("index = apn_index\n");
529 sqlite3_close(apnDb);
530 return 1;
531 }
532 }
533 LYINFLOG("cant find the index %d\n", index);
534 sqlite3_close(apnDb);
535 return 0;
536}
537
538static int apn_db_handle_set(unsigned char profile_idx, int handle)
539{
540 char *zErrMsg = 0;
541 int rc;
542 //char sql[128]={0};
543 if(!lynq_check_index(profile_idx))
544 {
545 return LYNQ_E_APN_DB_FAIL;
546 }
547 /* Open database */
548
549 rc = sqlite3_open(APN_DB_PATH, &apnDb);
550 if( rc )
551 {
552 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
553 return LYNQ_E_APN_DB_FAIL;
554 }
555
556 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
557 /* Create SQL statement */
558 //sql = "SELECT * from LYNQAPN";
559 char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d WHERE ID=%d", handle, (int)profile_idx);
560 LYINFLOG("sql: %s\n", sql);
561 /* Execute SQL statement */
562 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
563 if( rc != SQLITE_OK )
564 {
565 LYERRLOG("SQL error: %s\n", zErrMsg);
566 sqlite3_free(zErrMsg);
567 sqlite3_close(apnDb);
568 return LYNQ_E_APN_DB_FAIL;
569 }
570 LYINFLOG("update apn %d successfully\n", profile_idx);
571 sqlite3_close(apnDb);
572 return 0;
573}
574static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName)
575{
576 if(data==NULL)
577 {
578 return 1;
579 }
580 int *temp = (int *)data;
581 for(int i=0; i<argc; i++){
582 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
583 }
584 *temp = atoi(argv[0]);
585 LYINFLOG("The handle is %d\n", *temp);
586 return 0;
587}
588static int apn_db_handle_get(unsigned char profile_idx, int *handle)
589{
590 char *zErrMsg = 0;
591 int rc;
592
593 //char sql[128]={0};
594 if(!lynq_check_index(profile_idx))
595 {
596 return LYNQ_E_APN_DB_FAIL;
597 }
598 /* Open database */
599 rc = sqlite3_open(APN_DB_PATH, &apnDb);
600 if( rc )
601 {
602 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
603 return LYNQ_E_APN_DB_FAIL;
604 }
605
606 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
607 /* Create SQL statement */
608 char *sql = sqlite3_mprintf("SELECT HANDLE from LYNQAPN WHERE ID=%d", (int)profile_idx);
609 LYINFLOG("sql: %s\n", sql);
610 /* Execute SQL statement */
611 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_cb, handle, &zErrMsg);
612 if( rc != SQLITE_OK )
613 {
614 LYERRLOG("SQL error: %s\n", zErrMsg);
615 sqlite3_free(zErrMsg);
616 sqlite3_close(apnDb);
617 return LYNQ_E_APN_DB_FAIL;
618 }
619 LYINFLOG("get idx %d successfully\n", *handle);
620 sqlite3_close(apnDb);
621 return 0;
622}
623
624static int has_apn_db_created(char *path,sqlite3* apnDb_l)
625{
626 if (path == NULL || strlen(path) == 0)
627 {
628 LYERRLOG("initApnDb error with null path!");
629 return APN_DB_ERR;
630 }
631 int rc = sqlite3_open_v2(path, &apnDb_l, SQLITE_OPEN_READWRITE,NULL);
632 if (rc == SQLITE_OK)
633 {
634 LYINFLOG("check init success!");
635 return APN_DB_READED;
636 }
637 else
638 {
639 LYERRLOG("db has not create %s!", sqlite3_errmsg(apnDb_l));
640 sqlite3_close_v2(apnDb_l);
641 return APN_DB_ERR;
642 }
643}
644static int create_apn_db(char *path)
645{
646 if (path == NULL || strlen(path) == 0) {
647 LYERRLOG("initApnDb error with null path!");
648 return APN_DB_ERR;
649 }
650 if(APN_DB_READED==has_apn_db_created(path,apnDb))
651 {
652 return APN_DB_READED;
653 }
654 int rc = sqlite3_open(path, &apnDb);
655 if (rc != SQLITE_OK) {
656 LYERRLOG("initDb failed %d", sqlite3_errcode(apnDb));
657 return APN_DB_ERR;
658 } else {
659 LYINFLOG("create db in %s", path);
660 }
661 sqlite3_close(apnDb);
662 return APN_DB_CREATE;
663}
664static int create_apn_table(char*path)
665{
666 char *zErrMsg = 0;
667 int rc;
668 char *sql;
669
670 /* Open database */
671 rc = sqlite3_open(path, &apnDb);
672 if( rc )
673 {
674 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
675 return 1;
676 }
677 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
678 /* Create SQL statement */
679 sql = "CREATE TABLE LYNQAPN( \
680 ID INT NOT NULL, \
681 PDP_TYPE INT NOT NULL, \
682 AUTH_PROTO INT NOT NULL, \
683 APN_NAME TEXT NOT NULL, \
684 USERNAME TEXT NOT NULL,\
685 PASSWORD TEXT NOT NULL, \
686 APN_TYPE TEXT PRIMARY KEY NOT NULL, \
687 HANDLE INT NOT NULL)";
688 /* Execute SQL statement */
689 rc = sqlite3_exec(apnDb, sql, NULL, 0, &zErrMsg);
690 if( rc != SQLITE_OK )
691 {
692 LYERRLOG("SQL error: %s\n", zErrMsg);
693 sqlite3_free(zErrMsg);
694 sqlite3_close(apnDb);
695 return 1;
696 }
697 LYINFLOG("Table LYNQAPN created successfully\n");
698 sqlite3_close(apnDb);
699 return 0;
700}
701static int init_apn_db()
702{
703 int db_ret=0;
704 int table_ret=0;
705 db_ret = create_apn_db(APN_DB_PATH);
706 if(db_ret==APN_DB_CREATE)
707 {
708 table_ret = create_apn_table(APN_DB_PATH);
709 if(table_ret!=0)
710 {
711 LYERRLOG("create apn table fail!!!");
712 return RESULT_ERROR;
713 }
714 apn_db_add(0, &default_apn);
715 }
716 else if(db_ret==APN_DB_READED)
717 {
718 LYERRLOG("[%s] apn db has be build!!!",__FUNCTION__);
xf.li0fd6acf2023-12-20 18:16:34 -0800719 }
720 else
721 {
xf.licb6cd282024-02-21 22:06:14 -0800722 LYERRLOG("init apn db fail!!!");
xf.li0fd6acf2023-12-20 18:16:34 -0800723 }
xf.li0fd6acf2023-12-20 18:16:34 -0800724 return RESULT_OK;
xf.li0fd6acf2023-12-20 18:16:34 -0800725}
xf.li2fc84552023-06-23 05:26:47 -0700726
xf.licb6cd282024-02-21 22:06:14 -0800727static int apn_db_handle_clean()
xf.li63b87e82024-01-04 00:43:35 -0800728{
xf.licb6cd282024-02-21 22:06:14 -0800729 char *zErrMsg = 0;
730 int rc;
xf.li63b87e82024-01-04 00:43:35 -0800731 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li63b87e82024-01-04 00:43:35 -0800732
xf.licb6cd282024-02-21 22:06:14 -0800733 /* Open database */
734 rc = sqlite3_open(APN_DB_PATH, &apnDb);
735 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800736 {
xf.licb6cd282024-02-21 22:06:14 -0800737 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
738 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800739 }
xf.licb6cd282024-02-21 22:06:14 -0800740
741 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
742 /* Create SQL statement */
743 char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d", default_handle);
744 LYINFLOG("sql: %s\n", sql);
745 /* Execute SQL statement */
746 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
747 if( rc != SQLITE_OK )
xf.li63b87e82024-01-04 00:43:35 -0800748 {
xf.licb6cd282024-02-21 22:06:14 -0800749 LYERRLOG("SQL error: %s\n", zErrMsg);
750 sqlite3_free(zErrMsg);
751 sqlite3_close(apnDb);
752 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800753 }
xf.licb6cd282024-02-21 22:06:14 -0800754 LYINFLOG("clean apn table successfully\n");
755 sqlite3_close(apnDb);
756 return RESULT_OK;
757}
758
759static int find_unuse_apn_index(char *path)
760{
761 char *zErrMsg = 0;
762 int rc;
763 int count =1;
764 bool apn_usable = false;
765 char *sql;
766
767 memset(apn_indexs,0,sizeof(apn_indexs));
768 next_index = 0;
769 LYINFLOG("index = %p",apn_indexs);
770 /* Open database */
771 rc = sqlite3_open(APN_DB_PATH, &apnDb);
772 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800773 {
xf.licb6cd282024-02-21 22:06:14 -0800774 LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb));
775 return -1;
xf.li63b87e82024-01-04 00:43:35 -0800776 }
777 else
778 {
xf.licb6cd282024-02-21 22:06:14 -0800779 LYINFLOG("Opened database successfully\n");
xf.li63b87e82024-01-04 00:43:35 -0800780 }
xf.li63b87e82024-01-04 00:43:35 -0800781
xf.licb6cd282024-02-21 22:06:14 -0800782 /* Create SQL statement */
783 sql = "SELECT ID from LYNQAPN";
784 /* Execute SQL statement */
785 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg);
786 if( rc != SQLITE_OK )
787 {
788 LYERRLOG("SQL error: %s\n", zErrMsg);
789 sqlite3_free(zErrMsg);
790 return -1;
791 }
792 else
793 {
794 LYINFLOG("Operation done successfully\n");
795 }
796 //indexs = temp_index;
797 LYINFLOG("index = %p",apn_indexs);
798 for(count;count<=QSER_APN_MAX_LIST;count++)
799 {
800 //if(apn_indexs[count-1]!=count)
801 LYINFLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count);
802 if(apn_indexs[count]!=count)
803 {
804 //apn_usable=true;
805 break;
806 }
807 }
808 sqlite3_close(apnDb);
809 LYINFLOG("count is %d\n", count);
810 return count;
xf.li63b87e82024-01-04 00:43:35 -0800811}
812
xf.licb6cd282024-02-21 22:06:14 -0800813static int apn_db_add(int profile_id, qser_apn_add_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700814{
xf.licb6cd282024-02-21 22:06:14 -0800815 char *zErrMsg = 0;
816 int rc;
xf.li0fd6acf2023-12-20 18:16:34 -0800817 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.licb6cd282024-02-21 22:06:14 -0800818 /* Open database */
819 rc = sqlite3_open(APN_DB_PATH, &apnDb);
820 if( rc )
xf.li2fc84552023-06-23 05:26:47 -0700821 {
xf.licb6cd282024-02-21 22:06:14 -0800822 LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb));
823 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700824 }
xf.licb6cd282024-02-21 22:06:14 -0800825 LYINFLOG("[%s] Opened database successfully",__FUNCTION__);
826 /* Create SQL statement */
827 /* Execute SQL statement */
828 LYINFLOG("the profile id is %d\n", profile_id);
829 char *sql = sqlite3_mprintf("INSERT INTO LYNQAPN VALUES('%d','%d','%d','%q','%q','%q','%q','%d')", profile_id, apn->pdp_type, apn->auth_proto, apn->apn_name, apn->username, apn->password, apn->apn_type, default_handle);
830 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
831 if( rc != SQLITE_OK )
xf.li2fc84552023-06-23 05:26:47 -0700832 {
xf.licb6cd282024-02-21 22:06:14 -0800833 LYERRLOG( "SQL error: %s", zErrMsg);
834 sqlite3_free(zErrMsg);
835 sqlite3_close(apnDb);
836 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700837 }
xf.licb6cd282024-02-21 22:06:14 -0800838 LYINFLOG("write apn to apn db successfully");
839 sqlite3_close(apnDb);
840 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700841}
842
xf.licb6cd282024-02-21 22:06:14 -0800843static int apn_db_delete(unsigned char profile_idx)
xf.li2fc84552023-06-23 05:26:47 -0700844{
xf.licb6cd282024-02-21 22:06:14 -0800845 char *zErrMsg = 0;
846 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700847
xf.licb6cd282024-02-21 22:06:14 -0800848 if(!lynq_check_index(profile_idx))
849 {
850 return LYNQ_E_APN_DB_FAIL;
851 }
852 /* Open database */
853
854 rc = sqlite3_open(APN_DB_PATH, &apnDb);
855 if( rc )
856 {
857 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
858 return LYNQ_E_APN_DB_FAIL;
859 }
860
861 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
862 /* Create SQL statement */
863 //sql = "SELECT * from LYNQAPN";
864 char *sql = sqlite3_mprintf("DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx);
865 LYINFLOG("sql: %s\n", sql);
866 /* Execute SQL statement */
867 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
868 if( rc != SQLITE_OK )
869 {
870 LYERRLOG("SQL error: %s\n", zErrMsg);
871 sqlite3_free(zErrMsg);
872 sqlite3_close(apnDb);
873 return LYNQ_E_APN_DB_FAIL;
874 }
875 LYINFLOG("delete apn %d successfully\n", profile_idx);
876 sqlite3_close(apnDb);
877 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700878}
879
xf.licb6cd282024-02-21 22:06:14 -0800880static int apn_db_modify(qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700881{
xf.licb6cd282024-02-21 22:06:14 -0800882 char *zErrMsg = 0;
883 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700884
xf.licb6cd282024-02-21 22:06:14 -0800885 if(!lynq_check_index(apn->profile_idx))
886 {
887 return LYNQ_E_APN_DB_FAIL;
888 }
889 /* Open database */
890
891 rc = sqlite3_open(APN_DB_PATH, &apnDb);
892 if( rc )
893 {
894 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
895 return LYNQ_E_APN_DB_FAIL;
896 }
897
898 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
899 /* Create SQL statement */
900 char *sql = sqlite3_mprintf("UPDATE LYNQAPN set PDP_TYPE = %d, AUTH_PROTO = %d, APN_NAME = '%q', USERNAME = '%q', PASSWORD = '%q', APN_TYPE = '%q' WHERE ID=%d", apn->pdp_type, apn->auth_proto, apn->apn_name, apn->username, apn->password, apn->apn_type, apn->profile_idx);
901 LYINFLOG("sql: %s\n", sql);
902 /* Execute SQL statement */
903 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
904 if( rc != SQLITE_OK )
905 {
906 LYERRLOG("SQL error: %s\n", zErrMsg);
907 sqlite3_free(zErrMsg);
908 sqlite3_close(apnDb);
909 return LYNQ_E_APN_DB_FAIL;
910 }
911 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
912 sqlite3_close(apnDb);
913 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700914}
915
xf.licb6cd282024-02-21 22:06:14 -0800916static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName)
xf.li2fc84552023-06-23 05:26:47 -0700917{
xf.licb6cd282024-02-21 22:06:14 -0800918 if(data==NULL)
xf.li2fc84552023-06-23 05:26:47 -0700919 {
xf.licb6cd282024-02-21 22:06:14 -0800920 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700921 }
xf.licb6cd282024-02-21 22:06:14 -0800922 qser_apn_info_s* temp = (qser_apn_info_s *)data;
923 for(int i=0; i<argc; i++){
924 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -0700925 }
xf.licb6cd282024-02-21 22:06:14 -0800926 temp->profile_idx = atoi(argv[0]);
927 temp->pdp_type = atoi(argv[1]);
928 temp->auth_proto = atoi(argv[2]);
929 memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE);
930 memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE);
931 memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE);
932 memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE);
933 LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0]));
934 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700935}
xf.licb6cd282024-02-21 22:06:14 -0800936static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700937{
xf.licb6cd282024-02-21 22:06:14 -0800938 char *zErrMsg = 0;
939 int rc;
940
941 if(!lynq_check_index(profile_idx))
xf.li2fc84552023-06-23 05:26:47 -0700942 {
xf.licb6cd282024-02-21 22:06:14 -0800943 return LYNQ_E_APN_DB_FAIL;
944 }
945 /* Open database */
946
947 rc = sqlite3_open(APN_DB_PATH, &apnDb);
948 if( rc )
949 {
950 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
951 return LYNQ_E_APN_DB_FAIL;
952 }
953
954 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
955 /* Create SQL statement */
956 char *sql = sqlite3_mprintf("SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx);
957 LYINFLOG("sql: %s\n", sql);
958 /* Execute SQL statement */
959 rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg);
960 if( rc != SQLITE_OK )
961 {
962 LYERRLOG("SQL error: %s\n", zErrMsg);
963 sqlite3_free(zErrMsg);
964 sqlite3_close(apnDb);
965 return LYNQ_E_APN_DB_FAIL;
966 }
967 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
968 sqlite3_close(apnDb);
969 return 0;
970}
971static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName)
972{
973 int i;
974
975 //apn_count++;
976
977 qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data;
978 for(i=0; i<argc; i++){
979 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -0700980 }
981
xf.licb6cd282024-02-21 22:06:14 -0800982 temp->apn[temp->cnt].profile_idx = atoi(argv[0]);
983 temp->apn[temp->cnt].pdp_type = atoi(argv[1]);
984 temp->apn[temp->cnt].auth_proto = atoi(argv[2]);
985 memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE);
986 memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE);
987 memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE);
988 memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE);
989 temp->cnt++;
990 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700991}
xf.licb6cd282024-02-21 22:06:14 -0800992static int apn_db_query_list(qser_apn_info_list_s *apn_list)
993{
994 char *zErrMsg = 0;
995 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700996
xf.licb6cd282024-02-21 22:06:14 -0800997 /* Open database */
998 apn_count = 0;
999 apn_list->cnt = 0;
1000 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1001 if( rc )
1002 {
1003 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
1004 return LYNQ_E_APN_DB_FAIL;
1005 }
1006
1007 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1008 /* Create SQL statement */
1009 char *sql = sqlite3_mprintf("SELECT * from LYNQAPN");
1010 LYINFLOG("sql: %s\n", sql);
1011 /* Execute SQL statement */
1012 rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg);
1013 if( rc != SQLITE_OK )
1014 {
1015 LYERRLOG("SQL error: %s\n", zErrMsg);
1016 sqlite3_free(zErrMsg);
1017 sqlite3_close(apnDb);
1018 return LYNQ_E_APN_DB_FAIL;
1019 }
1020 sqlite3_close(apnDb);
1021 return 0;
1022}
1023// **************apn DB end****************************
xf.li2fc84552023-06-23 05:26:47 -07001024void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
1025{
1026 switch (pdp_type)
1027 {
1028 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -08001029#ifdef MOBILETEK_TARGET_PLATFORM_T106
1030 strcpy(out_pdp_type,"IP");
1031#else
xf.li2fc84552023-06-23 05:26:47 -07001032 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -08001033#endif
xf.li2fc84552023-06-23 05:26:47 -07001034 break;
1035 case QSER_APN_PDP_TYPE_PPP:
1036 strcpy(out_pdp_type,"PPP");
1037 break;
1038 case QSER_APN_PDP_TYPE_IPV6:
1039 strcpy(out_pdp_type,"IPV6");
1040 break;
1041 case QSER_APN_PDP_TYPE_IPV4V6:
1042 strcpy(out_pdp_type,"IPV4V6");
1043 break;
1044 default:
1045 strcpy(out_pdp_type,"NULL");
1046 break;
1047 }
1048 return;
1049}
1050void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
1051{
1052 switch (auth_proto)
1053 {
1054 case QSER_APN_AUTH_PROTO_DEFAULT:
1055 strcpy(out_proto,"NULL;authType=0");
1056 break;
1057 case QSER_APN_AUTH_PROTO_NONE:
1058 strcpy(out_proto,"NULL;authType=1");
1059 break;
1060 case QSER_APN_AUTH_PROTO_PAP:
1061 strcpy(out_proto,"NULL;authType=2");
1062 break;
1063 case QSER_APN_AUTH_PROTO_CHAP:
1064 strcpy(out_proto,"NULL;authtype=3");
1065 break;
1066 case QSER_APN_AUTH_PROTO_PAP_CHAP:
1067 strcpy(out_proto,"NULL;authtype=4");
1068 break;
1069 default:
1070 strcpy(out_proto,"NULL;authType=NULL");
1071 break;
1072 }
1073 return ;
1074}
1075
1076int data_call_handle_get(const char profile_idx,int *handle)
1077{
1078 int num = LYNQ_APN_CHANNEL_MAX;
1079 int table_num = 0;
1080 lynq_apn_info **apn_table = NULL;
1081 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001082 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001083 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1084 if (NULL == apn_table)
1085 {
1086 LYERRLOG("malloc apn_table fail ");
1087 return RESULT_ERROR;
1088 }
1089 for(int i =0;i<10;i++)
1090 {
1091 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1092 if (apn_table[i]==NULL)
1093 {
1094 for (int n=0;n<i;n++)
1095 {
1096 free(apn_table[n]);
1097 }
1098 return RESULT_ERROR;
1099 }
1100 memset(apn_table[i],0,sizeof(lynq_apn_info));
1101 }
1102 lynq_get_apn_table(&table_num,apn_table);
1103 memset(&apn,0,sizeof(qser_apn_info_s));
xf.licb6cd282024-02-21 22:06:14 -08001104 ret = apn_db_query(profile_idx,&apn);
xf.li0fc26502023-09-16 02:10:17 -07001105 if (ret < 0)
1106 {
xf.licb6cd282024-02-21 22:06:14 -08001107 LYERRLOG("apn_db_query error");
xf.li0fc26502023-09-16 02:10:17 -07001108 return ret;
1109 }
xf.li2fc84552023-06-23 05:26:47 -07001110 for (int j = 0;j < table_num;j++)
1111 {
1112 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1113 {
1114 *handle = apn_table[j]->index;
1115 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1116 break;
1117 }
1118 }
1119
1120 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1121 {
1122 if (apn_table[i]!=NULL)
1123 {
1124 free(apn_table[i]);
1125 apn_table[i]=NULL;
1126 }
1127 }
1128 free(apn_table);
1129 apn_table=NULL;
1130 LYINFLOG("data_call_handle_get end");
1131 return RESULT_OK;
1132}
1133
1134void *thread_wait_cb_status(void)
1135{
1136 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001137 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001138 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001139 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001140 qser_data_call_state_s data_cb_state;
1141 while (s_qser_data_cb_thread_status)
1142 {
xf.li6b0d8502023-09-04 18:49:12 -07001143 ret = lynq_wait_data_call_state_change(&handle);
1144 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
1145 if(s_qser_data_cb_thread_status == 0)
1146 {
1147 return NULL;
1148 }
1149 else if(ret < 0)
1150 {
1151 continue;
1152 }
xf.li8535bc02023-12-12 23:28:35 -08001153 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
1154 memset(&data_urc_info, 0, sizeof(data_urc_info));
1155 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001156 lynq_get_data_call_list(&handle,&data_urc_info);
1157 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001158 //data_cb_state.profile_idx = (char)handle;
xf.licb6cd282024-02-21 22:06:14 -08001159 apn_db_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li8535bc02023-12-12 23:28:35 -08001160 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",
1161 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
1162 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
1163 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -07001164 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001165 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001166 {
1167 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1168 }
1169 else if (!strcmp(data_urc_info.type,"IPV6"))
1170 {
1171 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1172 }
xf.li8535bc02023-12-12 23:28:35 -08001173 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001174 {
1175 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1176 }
1177 else
1178 {
xf.li8535bc02023-12-12 23:28:35 -08001179 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001180 }
1181
xf.li8535bc02023-12-12 23:28:35 -08001182 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001183 {
1184 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1185 }
1186 else
1187 {
1188 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.licb6cd282024-02-21 22:06:14 -08001189 ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001190 if(ret != 0)
1191 {
1192 LYERRLOG("handle set error");
1193 }
xf.li2fc84552023-06-23 05:26:47 -07001194 }
1195 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1196 {
1197 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1198 }
1199 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1200 {
1201 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1202 }
1203 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1204 {
xf.li3c0a4752023-09-03 20:46:19 -07001205#ifdef MOBILETEK_TARGET_PLATFORM_T106
1206 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1207#else
xf.li2fc84552023-06-23 05:26:47 -07001208 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001209#endif
xf.li2fc84552023-06-23 05:26:47 -07001210 }
1211 else
1212 {
1213 LYERRLOG("unknow ip_family");
1214 continue;
1215 }
1216 if (s_data_call_cb != NULL)
1217 {
1218 s_data_call_cb(&data_cb_state);
1219 }
1220 }
1221 return NULL;
1222}
1223
1224int qser_cb_pthread_create()
1225{
1226 int ret;
1227 s_qser_data_cb_thread_status = 1;
1228 ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL);
1229 if (ret < 0)
1230 {
1231 LYERRLOG("pthread create fail");
1232 s_qser_data_cb_thread_status = 0;
1233 return RESULT_ERROR;
1234 }
1235 return RESULT_OK;
1236}
1237
1238void qser_cb_pthread_cancel()
1239{
xf.li2fc84552023-06-23 05:26:47 -07001240 s_qser_data_cb_thread_status = 0;
1241 if (s_cb_tid != -1)
1242 {
xf.li6b0d8502023-09-04 18:49:12 -07001243 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001244 }
1245 return;
1246}
xf.li2fc84552023-06-23 05:26:47 -07001247int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1248{
1249 int ret = 0;
1250 int utoken = 0;
1251 if (NULL == evt_cb)
1252 {
1253 LYERRLOG("init incoming paramters error");
1254 return RESULT_ERROR;
1255 }
xf.li7b0bfd02023-08-03 01:11:52 -07001256
xf.li2fc84552023-06-23 05:26:47 -07001257 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -07001258
xf.li2fc84552023-06-23 05:26:47 -07001259 ret = lynq_init_data(utoken);
1260 if (ret != RESULT_OK)
1261 {
xf.li6b0d8502023-09-04 18:49:12 -07001262 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001263 s_data_call_cb = NULL;
1264 return RESULT_ERROR;
1265 }
xf.li6b0d8502023-09-04 18:49:12 -07001266 qser_cb_pthread_create();
xf.licb6cd282024-02-21 22:06:14 -08001267 ret = init_apn_db();
1268 if(ret != RESULT_OK)
xf.lie3f55f42023-12-01 22:47:33 -08001269 {
xf.licb6cd282024-02-21 22:06:14 -08001270 LYERRLOG("init apn db error");
xf.lie3f55f42023-12-01 22:47:33 -08001271 return RESULT_ERROR;
1272 }
xf.licb6cd282024-02-21 22:06:14 -08001273
1274 ret = apn_db_handle_clean();
xf.li63b87e82024-01-04 00:43:35 -08001275 if(ret != RESULT_OK)
1276 {
1277 LYERRLOG("clean handle error");
1278 return RESULT_ERROR;
1279 }
xf.lib33d4862023-12-13 00:40:37 -08001280 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001281 return RESULT_OK;
1282}
1283
1284void qser_data_call_destroy(void)
1285{
xf.li6b0d8502023-09-04 18:49:12 -07001286 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001287 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001288 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001289 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001290 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001291 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001292 return ;
1293}
1294
1295int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1296{
1297 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001298 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001299 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001300 if(g_lynq_qser_data_init_flag == 0)
1301 {
1302 if(err != NULL)
1303 {
1304 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1305 }
1306 return LYNQ_E_NO_INIT;
1307 }
xf.li2fc84552023-06-23 05:26:47 -07001308 if (NULL == data_call || NULL == err)
1309 {
1310 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001311 if(err != NULL)
1312 {
1313 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1314 }
xf.li2fc84552023-06-23 05:26:47 -07001315 return ret;
1316 }
1317 if (data_call->profile_idx == 0)
1318 {
1319 ret = lynq_setup_data_call(&handle);
1320 }
1321 else
1322 {
1323 char pdptype[16];
1324 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001325 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1326 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li0fc26502023-09-16 02:10:17 -07001327 if (ret != 0)
1328 {
1329 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001330 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001331 return ret;
1332 }
xf.li2fc84552023-06-23 05:26:47 -07001333 judge_pdp_type(apn_info.pdp_type,pdptype);
1334 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1335 }
xf.lic12b3702023-11-22 22:39:01 -08001336 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001337 {
1338 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1339 }
xf.li0fd6acf2023-12-20 18:16:34 -08001340 else
1341 {
xf.licb6cd282024-02-21 22:06:14 -08001342 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001343 if(error != 0)
1344 {
1345 LYERRLOG("handle set error");
1346 }
1347 }
xf.li2fc84552023-06-23 05:26:47 -07001348 return ret;
1349}
1350
xf.li8535bc02023-12-12 23:28:35 -08001351int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1352{
1353 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001354 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001355 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001356 if(g_lynq_qser_data_init_flag == 0)
1357 {
1358 if(err != NULL)
1359 {
1360 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1361 }
1362 return LYNQ_E_NO_INIT;
1363 }
xf.li8535bc02023-12-12 23:28:35 -08001364 if (NULL == data_call || NULL == err)
1365 {
1366 LYERRLOG("call start incoming paramters error");
1367 if(err != NULL)
1368 {
1369 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1370 }
1371 return ret;
1372 }
1373 if (data_call->profile_idx == 0)
1374 {
1375 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1376 }
1377 else
1378 {
1379 char pdptype[16];
1380 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001381 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1382 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li8535bc02023-12-12 23:28:35 -08001383 if (ret != 0)
1384 {
1385 LYERRLOG("qser_apn_get error");
1386 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1387 return ret;
1388 }
1389 judge_pdp_type(apn_info.pdp_type,pdptype);
1390 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);
1391 }
1392 if (ret != 0)
1393 {
1394 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1395 }
xf.li0fd6acf2023-12-20 18:16:34 -08001396 else
1397 {
xf.licb6cd282024-02-21 22:06:14 -08001398 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001399 if(error != 0)
1400 {
1401 LYERRLOG("handle set error");
1402 }
1403 }
xf.li8535bc02023-12-12 23:28:35 -08001404 return ret;
1405}
1406
xf.li2fc84552023-06-23 05:26:47 -07001407int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1408{
1409 int ret = 0;
1410 int handle = -1;
1411
xf.lib33d4862023-12-13 00:40:37 -08001412 if(g_lynq_qser_data_init_flag == 0)
1413 {
1414 if(err != NULL)
1415 {
1416 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1417 }
1418 return LYNQ_E_NO_INIT;
1419 }
xf.li2fc84552023-06-23 05:26:47 -07001420 if (NULL == err)
1421 {
1422 LYERRLOG("call stop incoming paramters error");
1423 return ret;
1424 }
xf.lic12b3702023-11-22 22:39:01 -08001425 ret = data_call_handle_get(profile_idx,&handle);
1426 if(ret != 0)
1427 {
1428 LYERRLOG("datacall handle get error");
1429 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1430 return ret;
1431 }
xf.li2fc84552023-06-23 05:26:47 -07001432 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001433 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001434 {
1435 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001436 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001437 }
xy.hee2daacc2023-09-18 00:57:51 -07001438 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001439}
1440int 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)
1441{
1442 int ret = 0;
1443 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001444 if(g_lynq_qser_data_init_flag == 0)
1445 {
1446 if(err != NULL)
1447 {
1448 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1449 }
1450 return LYNQ_E_NO_INIT;
1451 }
xf.li2fc84552023-06-23 05:26:47 -07001452 lynq_data_call_response_v11_t data_call_info;
1453 data_call_handle_get(profile_idx,&handle);
1454 ret = lynq_get_data_call_list(&handle,&data_call_info);
1455 if (ret == 0)
1456 {
1457 info->profile_idx = profile_idx;
1458 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001459 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 -07001460 {
1461 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001462 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001463 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1464 lynq_ipv4_aton_getinfo(&data_call_info,info);
1465 }
xf.li3c0a4752023-09-03 20:46:19 -07001466 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001467 {
1468 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001469 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001470 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1471 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1472 }
xf.li3c0a4752023-09-03 20:46:19 -07001473 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001474 {
1475 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001476 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001477 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 -07001478#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001479 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001480#endif
xf.li2fc84552023-06-23 05:26:47 -07001481 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001482 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001483 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 -07001484#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001485 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001486#endif
1487#ifdef MOBILETEK_TARGET_PLATFORM_T106
1488 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1489#endif
xf.li2fc84552023-06-23 05:26:47 -07001490 }
1491 else
1492 {
1493 LYERRLOG("useless qser_data_call_ip_family_e");
1494 }
1495 }
1496 return ret;
1497}
1498int qser_apn_set(qser_apn_info_s *apn)
1499{
1500 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001501 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001502 if(g_lynq_qser_data_init_flag == 0)
1503 {
1504 return LYNQ_E_NO_INIT;
1505 }
xf.li4b18fa62023-12-19 19:38:10 -08001506 if (NULL == apn || apn->profile_idx == 0)
xf.li2fc84552023-06-23 05:26:47 -07001507 {
1508 LYERRLOG("apn set incoming paramters error");
1509 return RESULT_ERROR;
1510 }
xf.licb6cd282024-02-21 22:06:14 -08001511 ret = apn_db_handle_get(apn->profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001512 if(ret != 0)
1513 {
1514 LYERRLOG("handle set error");
1515 }
1516 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1517 {
1518 LYERRLOG("It has setup datacall");
1519 return RESULT_ERROR;
1520 }
xf.licb6cd282024-02-21 22:06:14 -08001521 ret = apn_db_modify(apn);
xf.li2fc84552023-06-23 05:26:47 -07001522 if (ret < 0)
1523 {
xf.licb6cd282024-02-21 22:06:14 -08001524 LYERRLOG("apn_db_modify error");
xf.li2fc84552023-06-23 05:26:47 -07001525 return ret;
1526 }
xf.li6c7e3972023-10-27 20:01:59 -07001527#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001528 int apn_id = 0;
1529 char tmp_id[12];
1530 char *outinfo = NULL;
1531 char normalprotocol[16];
1532 char authtype[32];
1533 outinfo = (char *)malloc(sizeof(char)*512);
1534 bzero(tmp_id,12);
1535 bzero(outinfo,512);
1536 apn_id = apn->profile_idx + apndb_offset;
1537 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1538 judge_pdp_type(apn->pdp_type,normalprotocol);
1539 judge_authtype(apn->auth_proto,authtype);
1540 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1541 LYINFLOG("[output]:%s",outinfo);
1542 free(outinfo);
1543 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001544#endif
1545 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001546}
1547
1548int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1549{
xf.lib33d4862023-12-13 00:40:37 -08001550 if(g_lynq_qser_data_init_flag == 0)
1551 {
1552 return LYNQ_E_NO_INIT;
1553 }
xf.licb6cd282024-02-21 22:06:14 -08001554 if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn)
xf.li2fc84552023-06-23 05:26:47 -07001555 {
1556 LYERRLOG("apn get incoming paramters error");
1557 return RESULT_ERROR;
1558 }
1559 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001560 ret = apn_db_query(profile_idx,apn);
xf.li2fc84552023-06-23 05:26:47 -07001561 if (ret < 0)
1562 {
xf.licb6cd282024-02-21 22:06:14 -08001563 LYERRLOG("apn_db_query error");
xf.li2fc84552023-06-23 05:26:47 -07001564 return ret;
1565 }
1566 return ret;
1567}
1568
1569int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1570{
1571 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001572
xf.lib33d4862023-12-13 00:40:37 -08001573 if(g_lynq_qser_data_init_flag == 0)
1574 {
1575 return LYNQ_E_NO_INIT;
1576 }
xf.li2fc84552023-06-23 05:26:47 -07001577 if (NULL == apn || NULL == profile_idx)
1578 {
1579 LYERRLOG("apn add incoming paramters error");
1580 return RESULT_ERROR;
1581 }
xf.licb6cd282024-02-21 22:06:14 -08001582
1583 *profile_idx = 0;
1584 *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH);
1585 LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx);
1586 if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001587 {
xf.licb6cd282024-02-21 22:06:14 -08001588 LYINFLOG("[%s] apn full is false\n",__FUNCTION__);
1589 ret = apn_db_add((int)*profile_idx, apn);
1590 if (ret != 0)
1591 {
1592 LYERRLOG("apn_db_add error");
1593 return RESULT_ERROR;
1594 }
1595 else
1596 {
1597 return RESULT_OK;
1598 }
xf.li2fc84552023-06-23 05:26:47 -07001599 }
xf.licb6cd282024-02-21 22:06:14 -08001600 LYERRLOG("apn storage space is full!!!");
1601 return RESULT_ERROR;
xf.li6c7e3972023-10-27 20:01:59 -07001602#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001603 int apn_id = 0;
1604 char tmp_id[12];
1605 char *outinfo = NULL;
1606 char normalprotocol[16];
1607 char authtype[32];
1608 outinfo = (char *)malloc(sizeof(char)*512);
1609 bzero(tmp_id,12);
1610 bzero(outinfo,512);
1611 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1612 judge_pdp_type(apn->pdp_type,normalprotocol);
1613 judge_authtype(apn->auth_proto,authtype);
1614 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1615 LYINFLOG("[output]:%s",outinfo);
1616 free(outinfo);
1617 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001618#endif
1619 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001620}
1621
1622int qser_apn_del(unsigned char profile_idx)
1623{
xf.lib33d4862023-12-13 00:40:37 -08001624 if(g_lynq_qser_data_init_flag == 0)
1625 {
1626 return LYNQ_E_NO_INIT;
1627 }
xf.li4b18fa62023-12-19 19:38:10 -08001628 if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001629 {
1630 LYERRLOG("apn del incoming paramters error");
xf.li4b18fa62023-12-19 19:38:10 -08001631 return RESULT_ERROR;
xf.li2fc84552023-06-23 05:26:47 -07001632 }
1633 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001634 int handle = -1;
xf.licb6cd282024-02-21 22:06:14 -08001635 ret = apn_db_handle_get(profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001636 if(ret != 0)
1637 {
1638 LYERRLOG("handle set error");
1639 }
1640 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1641 {
1642 LYERRLOG("It has setup datacall");
1643 return RESULT_ERROR;
1644 }
xf.licb6cd282024-02-21 22:06:14 -08001645 ret = apn_db_delete(profile_idx);
xf.li2fc84552023-06-23 05:26:47 -07001646 if (ret < 0)
1647 {
xf.licb6cd282024-02-21 22:06:14 -08001648 LYERRLOG("apn_db_delete error");
xf.li2fc84552023-06-23 05:26:47 -07001649 return ret;
1650 }
xf.li6c7e3972023-10-27 20:01:59 -07001651#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001652 int apn_id = 0;
1653 char tmp_id[12];
1654 char *outinfo = NULL;
1655 outinfo = (char *)malloc(sizeof(char)*512);
1656 bzero(tmp_id,12);
1657 bzero(outinfo,512);
1658 apn_id = profile_idx+apndb_offset;
1659 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1660 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1661 LYINFLOG("[output]:%s",outinfo);
1662 free(outinfo);
1663 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001664#endif
xf.li2fc84552023-06-23 05:26:47 -07001665 return ret;
1666}
1667
1668int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1669{
xf.lib33d4862023-12-13 00:40:37 -08001670 if(g_lynq_qser_data_init_flag == 0)
1671 {
1672 return LYNQ_E_NO_INIT;
1673 }
xf.li2fc84552023-06-23 05:26:47 -07001674 if (NULL == apn_list)
1675 {
1676 LYERRLOG("apn_list incoming paramters error");
1677 return RESULT_ERROR;
1678 }
1679 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001680 ret = apn_db_query_list(apn_list);
xf.li2fc84552023-06-23 05:26:47 -07001681 if (ret < 0)
1682 {
xf.licb6cd282024-02-21 22:06:14 -08001683 LYERRLOG("apn_db_query_list error");
xf.li2fc84552023-06-23 05:26:47 -07001684 return ret;
1685 }
1686 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001687}
you.chen21c62b72023-09-08 09:41:11 +08001688
1689DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1690