blob: 93494cac61083c79229b266751443fa307b97d93 [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!");
xf.lib5d82bf2024-03-09 01:54:50 -0800635 sqlite3_close_v2(apnDb_l);
xf.licb6cd282024-02-21 22:06:14 -0800636 return APN_DB_READED;
637 }
638 else
639 {
640 LYERRLOG("db has not create %s!", sqlite3_errmsg(apnDb_l));
641 sqlite3_close_v2(apnDb_l);
642 return APN_DB_ERR;
643 }
644}
645static int create_apn_db(char *path)
646{
647 if (path == NULL || strlen(path) == 0) {
648 LYERRLOG("initApnDb error with null path!");
649 return APN_DB_ERR;
650 }
651 if(APN_DB_READED==has_apn_db_created(path,apnDb))
652 {
653 return APN_DB_READED;
654 }
655 int rc = sqlite3_open(path, &apnDb);
656 if (rc != SQLITE_OK) {
657 LYERRLOG("initDb failed %d", sqlite3_errcode(apnDb));
658 return APN_DB_ERR;
659 } else {
660 LYINFLOG("create db in %s", path);
661 }
662 sqlite3_close(apnDb);
663 return APN_DB_CREATE;
664}
665static int create_apn_table(char*path)
666{
667 char *zErrMsg = 0;
668 int rc;
669 char *sql;
670
671 /* Open database */
672 rc = sqlite3_open(path, &apnDb);
673 if( rc )
674 {
675 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
676 return 1;
677 }
678 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
679 /* Create SQL statement */
680 sql = "CREATE TABLE LYNQAPN( \
681 ID INT NOT NULL, \
682 PDP_TYPE INT NOT NULL, \
683 AUTH_PROTO INT NOT NULL, \
684 APN_NAME TEXT NOT NULL, \
685 USERNAME TEXT NOT NULL,\
686 PASSWORD TEXT NOT NULL, \
687 APN_TYPE TEXT PRIMARY KEY NOT NULL, \
688 HANDLE INT NOT NULL)";
689 /* Execute SQL statement */
690 rc = sqlite3_exec(apnDb, sql, NULL, 0, &zErrMsg);
691 if( rc != SQLITE_OK )
692 {
693 LYERRLOG("SQL error: %s\n", zErrMsg);
694 sqlite3_free(zErrMsg);
695 sqlite3_close(apnDb);
696 return 1;
697 }
698 LYINFLOG("Table LYNQAPN created successfully\n");
699 sqlite3_close(apnDb);
700 return 0;
701}
702static int init_apn_db()
703{
704 int db_ret=0;
705 int table_ret=0;
706 db_ret = create_apn_db(APN_DB_PATH);
707 if(db_ret==APN_DB_CREATE)
708 {
709 table_ret = create_apn_table(APN_DB_PATH);
710 if(table_ret!=0)
711 {
712 LYERRLOG("create apn table fail!!!");
713 return RESULT_ERROR;
714 }
715 apn_db_add(0, &default_apn);
716 }
717 else if(db_ret==APN_DB_READED)
718 {
719 LYERRLOG("[%s] apn db has be build!!!",__FUNCTION__);
xf.li0fd6acf2023-12-20 18:16:34 -0800720 }
721 else
722 {
xf.licb6cd282024-02-21 22:06:14 -0800723 LYERRLOG("init apn db fail!!!");
xf.li0fd6acf2023-12-20 18:16:34 -0800724 }
xf.li0fd6acf2023-12-20 18:16:34 -0800725 return RESULT_OK;
xf.li0fd6acf2023-12-20 18:16:34 -0800726}
xf.li2fc84552023-06-23 05:26:47 -0700727
xf.licb6cd282024-02-21 22:06:14 -0800728static int apn_db_handle_clean()
xf.li63b87e82024-01-04 00:43:35 -0800729{
xf.licb6cd282024-02-21 22:06:14 -0800730 char *zErrMsg = 0;
731 int rc;
xf.li63b87e82024-01-04 00:43:35 -0800732 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li63b87e82024-01-04 00:43:35 -0800733
xf.licb6cd282024-02-21 22:06:14 -0800734 /* Open database */
735 rc = sqlite3_open(APN_DB_PATH, &apnDb);
736 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800737 {
xf.licb6cd282024-02-21 22:06:14 -0800738 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
739 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800740 }
xf.licb6cd282024-02-21 22:06:14 -0800741
742 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
743 /* Create SQL statement */
744 char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d", default_handle);
745 LYINFLOG("sql: %s\n", sql);
746 /* Execute SQL statement */
747 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
748 if( rc != SQLITE_OK )
xf.li63b87e82024-01-04 00:43:35 -0800749 {
xf.licb6cd282024-02-21 22:06:14 -0800750 LYERRLOG("SQL error: %s\n", zErrMsg);
751 sqlite3_free(zErrMsg);
752 sqlite3_close(apnDb);
753 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800754 }
xf.licb6cd282024-02-21 22:06:14 -0800755 LYINFLOG("clean apn table successfully\n");
756 sqlite3_close(apnDb);
757 return RESULT_OK;
758}
759
760static int find_unuse_apn_index(char *path)
761{
762 char *zErrMsg = 0;
763 int rc;
764 int count =1;
765 bool apn_usable = false;
766 char *sql;
767
768 memset(apn_indexs,0,sizeof(apn_indexs));
769 next_index = 0;
770 LYINFLOG("index = %p",apn_indexs);
771 /* Open database */
772 rc = sqlite3_open(APN_DB_PATH, &apnDb);
773 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800774 {
xf.licb6cd282024-02-21 22:06:14 -0800775 LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb));
776 return -1;
xf.li63b87e82024-01-04 00:43:35 -0800777 }
778 else
779 {
xf.licb6cd282024-02-21 22:06:14 -0800780 LYINFLOG("Opened database successfully\n");
xf.li63b87e82024-01-04 00:43:35 -0800781 }
xf.li63b87e82024-01-04 00:43:35 -0800782
xf.licb6cd282024-02-21 22:06:14 -0800783 /* Create SQL statement */
784 sql = "SELECT ID from LYNQAPN";
785 /* Execute SQL statement */
786 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg);
787 if( rc != SQLITE_OK )
788 {
789 LYERRLOG("SQL error: %s\n", zErrMsg);
790 sqlite3_free(zErrMsg);
xf.lib5d82bf2024-03-09 01:54:50 -0800791 sqlite3_close(apnDb);
xf.licb6cd282024-02-21 22:06:14 -0800792 return -1;
793 }
794 else
795 {
796 LYINFLOG("Operation done successfully\n");
797 }
798 //indexs = temp_index;
799 LYINFLOG("index = %p",apn_indexs);
800 for(count;count<=QSER_APN_MAX_LIST;count++)
801 {
802 //if(apn_indexs[count-1]!=count)
803 LYINFLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count);
804 if(apn_indexs[count]!=count)
805 {
806 //apn_usable=true;
807 break;
808 }
809 }
810 sqlite3_close(apnDb);
811 LYINFLOG("count is %d\n", count);
812 return count;
xf.li63b87e82024-01-04 00:43:35 -0800813}
814
xf.licb6cd282024-02-21 22:06:14 -0800815static int apn_db_add(int profile_id, qser_apn_add_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700816{
xf.licb6cd282024-02-21 22:06:14 -0800817 char *zErrMsg = 0;
818 int rc;
xf.li0fd6acf2023-12-20 18:16:34 -0800819 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.licb6cd282024-02-21 22:06:14 -0800820 /* Open database */
821 rc = sqlite3_open(APN_DB_PATH, &apnDb);
822 if( rc )
xf.li2fc84552023-06-23 05:26:47 -0700823 {
xf.licb6cd282024-02-21 22:06:14 -0800824 LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb));
825 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700826 }
xf.licb6cd282024-02-21 22:06:14 -0800827 LYINFLOG("[%s] Opened database successfully",__FUNCTION__);
828 /* Create SQL statement */
829 /* Execute SQL statement */
830 LYINFLOG("the profile id is %d\n", profile_id);
831 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);
832 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
833 if( rc != SQLITE_OK )
xf.li2fc84552023-06-23 05:26:47 -0700834 {
xf.licb6cd282024-02-21 22:06:14 -0800835 LYERRLOG( "SQL error: %s", zErrMsg);
836 sqlite3_free(zErrMsg);
837 sqlite3_close(apnDb);
838 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700839 }
xf.licb6cd282024-02-21 22:06:14 -0800840 LYINFLOG("write apn to apn db successfully");
841 sqlite3_close(apnDb);
842 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700843}
844
xf.licb6cd282024-02-21 22:06:14 -0800845static int apn_db_delete(unsigned char profile_idx)
xf.li2fc84552023-06-23 05:26:47 -0700846{
xf.licb6cd282024-02-21 22:06:14 -0800847 char *zErrMsg = 0;
848 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700849
xf.licb6cd282024-02-21 22:06:14 -0800850 if(!lynq_check_index(profile_idx))
851 {
852 return LYNQ_E_APN_DB_FAIL;
853 }
854 /* Open database */
855
856 rc = sqlite3_open(APN_DB_PATH, &apnDb);
857 if( rc )
858 {
859 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
860 return LYNQ_E_APN_DB_FAIL;
861 }
862
863 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
864 /* Create SQL statement */
865 //sql = "SELECT * from LYNQAPN";
866 char *sql = sqlite3_mprintf("DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx);
867 LYINFLOG("sql: %s\n", sql);
868 /* Execute SQL statement */
869 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
870 if( rc != SQLITE_OK )
871 {
872 LYERRLOG("SQL error: %s\n", zErrMsg);
873 sqlite3_free(zErrMsg);
874 sqlite3_close(apnDb);
875 return LYNQ_E_APN_DB_FAIL;
876 }
877 LYINFLOG("delete apn %d successfully\n", profile_idx);
878 sqlite3_close(apnDb);
879 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700880}
881
xf.licb6cd282024-02-21 22:06:14 -0800882static int apn_db_modify(qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700883{
xf.licb6cd282024-02-21 22:06:14 -0800884 char *zErrMsg = 0;
885 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700886
xf.licb6cd282024-02-21 22:06:14 -0800887 if(!lynq_check_index(apn->profile_idx))
888 {
889 return LYNQ_E_APN_DB_FAIL;
890 }
891 /* Open database */
892
893 rc = sqlite3_open(APN_DB_PATH, &apnDb);
894 if( rc )
895 {
896 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
897 return LYNQ_E_APN_DB_FAIL;
898 }
899
900 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
901 /* Create SQL statement */
902 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);
903 LYINFLOG("sql: %s\n", sql);
904 /* Execute SQL statement */
905 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
906 if( rc != SQLITE_OK )
907 {
908 LYERRLOG("SQL error: %s\n", zErrMsg);
909 sqlite3_free(zErrMsg);
910 sqlite3_close(apnDb);
911 return LYNQ_E_APN_DB_FAIL;
912 }
913 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
914 sqlite3_close(apnDb);
915 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700916}
917
xf.licb6cd282024-02-21 22:06:14 -0800918static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName)
xf.li2fc84552023-06-23 05:26:47 -0700919{
xf.licb6cd282024-02-21 22:06:14 -0800920 if(data==NULL)
xf.li2fc84552023-06-23 05:26:47 -0700921 {
xf.licb6cd282024-02-21 22:06:14 -0800922 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700923 }
xf.licb6cd282024-02-21 22:06:14 -0800924 qser_apn_info_s* temp = (qser_apn_info_s *)data;
925 for(int i=0; i<argc; i++){
926 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -0700927 }
xf.licb6cd282024-02-21 22:06:14 -0800928 temp->profile_idx = atoi(argv[0]);
929 temp->pdp_type = atoi(argv[1]);
930 temp->auth_proto = atoi(argv[2]);
931 memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE);
932 memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE);
933 memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE);
934 memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE);
935 LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0]));
936 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700937}
xf.licb6cd282024-02-21 22:06:14 -0800938static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700939{
xf.licb6cd282024-02-21 22:06:14 -0800940 char *zErrMsg = 0;
941 int rc;
942
943 if(!lynq_check_index(profile_idx))
xf.li2fc84552023-06-23 05:26:47 -0700944 {
xf.licb6cd282024-02-21 22:06:14 -0800945 return LYNQ_E_APN_DB_FAIL;
946 }
947 /* Open database */
948
949 rc = sqlite3_open(APN_DB_PATH, &apnDb);
950 if( rc )
951 {
952 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
953 return LYNQ_E_APN_DB_FAIL;
954 }
955
956 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
957 /* Create SQL statement */
958 char *sql = sqlite3_mprintf("SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx);
959 LYINFLOG("sql: %s\n", sql);
960 /* Execute SQL statement */
961 rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg);
962 if( rc != SQLITE_OK )
963 {
964 LYERRLOG("SQL error: %s\n", zErrMsg);
965 sqlite3_free(zErrMsg);
966 sqlite3_close(apnDb);
967 return LYNQ_E_APN_DB_FAIL;
968 }
969 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
970 sqlite3_close(apnDb);
971 return 0;
972}
973static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName)
974{
975 int i;
976
977 //apn_count++;
978
979 qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data;
980 for(i=0; i<argc; i++){
981 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -0700982 }
983
xf.licb6cd282024-02-21 22:06:14 -0800984 temp->apn[temp->cnt].profile_idx = atoi(argv[0]);
985 temp->apn[temp->cnt].pdp_type = atoi(argv[1]);
986 temp->apn[temp->cnt].auth_proto = atoi(argv[2]);
987 memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE);
988 memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE);
989 memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE);
990 memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE);
991 temp->cnt++;
992 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700993}
xf.licb6cd282024-02-21 22:06:14 -0800994static int apn_db_query_list(qser_apn_info_list_s *apn_list)
995{
996 char *zErrMsg = 0;
997 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700998
xf.licb6cd282024-02-21 22:06:14 -0800999 /* Open database */
1000 apn_count = 0;
1001 apn_list->cnt = 0;
1002 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1003 if( rc )
1004 {
1005 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
1006 return LYNQ_E_APN_DB_FAIL;
1007 }
1008
1009 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1010 /* Create SQL statement */
1011 char *sql = sqlite3_mprintf("SELECT * from LYNQAPN");
1012 LYINFLOG("sql: %s\n", sql);
1013 /* Execute SQL statement */
1014 rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg);
1015 if( rc != SQLITE_OK )
1016 {
1017 LYERRLOG("SQL error: %s\n", zErrMsg);
1018 sqlite3_free(zErrMsg);
1019 sqlite3_close(apnDb);
1020 return LYNQ_E_APN_DB_FAIL;
1021 }
1022 sqlite3_close(apnDb);
1023 return 0;
1024}
1025// **************apn DB end****************************
xf.li2fc84552023-06-23 05:26:47 -07001026void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
1027{
1028 switch (pdp_type)
1029 {
1030 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -08001031#ifdef MOBILETEK_TARGET_PLATFORM_T106
1032 strcpy(out_pdp_type,"IP");
1033#else
xf.li2fc84552023-06-23 05:26:47 -07001034 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -08001035#endif
xf.li2fc84552023-06-23 05:26:47 -07001036 break;
1037 case QSER_APN_PDP_TYPE_PPP:
1038 strcpy(out_pdp_type,"PPP");
1039 break;
1040 case QSER_APN_PDP_TYPE_IPV6:
1041 strcpy(out_pdp_type,"IPV6");
1042 break;
1043 case QSER_APN_PDP_TYPE_IPV4V6:
1044 strcpy(out_pdp_type,"IPV4V6");
1045 break;
1046 default:
1047 strcpy(out_pdp_type,"NULL");
1048 break;
1049 }
1050 return;
1051}
1052void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
1053{
1054 switch (auth_proto)
1055 {
1056 case QSER_APN_AUTH_PROTO_DEFAULT:
1057 strcpy(out_proto,"NULL;authType=0");
1058 break;
1059 case QSER_APN_AUTH_PROTO_NONE:
1060 strcpy(out_proto,"NULL;authType=1");
1061 break;
1062 case QSER_APN_AUTH_PROTO_PAP:
1063 strcpy(out_proto,"NULL;authType=2");
1064 break;
1065 case QSER_APN_AUTH_PROTO_CHAP:
1066 strcpy(out_proto,"NULL;authtype=3");
1067 break;
1068 case QSER_APN_AUTH_PROTO_PAP_CHAP:
1069 strcpy(out_proto,"NULL;authtype=4");
1070 break;
1071 default:
1072 strcpy(out_proto,"NULL;authType=NULL");
1073 break;
1074 }
1075 return ;
1076}
1077
1078int data_call_handle_get(const char profile_idx,int *handle)
1079{
1080 int num = LYNQ_APN_CHANNEL_MAX;
1081 int table_num = 0;
1082 lynq_apn_info **apn_table = NULL;
1083 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001084 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001085 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1086 if (NULL == apn_table)
1087 {
1088 LYERRLOG("malloc apn_table fail ");
1089 return RESULT_ERROR;
1090 }
1091 for(int i =0;i<10;i++)
1092 {
1093 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1094 if (apn_table[i]==NULL)
1095 {
1096 for (int n=0;n<i;n++)
1097 {
1098 free(apn_table[n]);
1099 }
1100 return RESULT_ERROR;
1101 }
1102 memset(apn_table[i],0,sizeof(lynq_apn_info));
1103 }
1104 lynq_get_apn_table(&table_num,apn_table);
1105 memset(&apn,0,sizeof(qser_apn_info_s));
xf.licb6cd282024-02-21 22:06:14 -08001106 ret = apn_db_query(profile_idx,&apn);
xf.li0fc26502023-09-16 02:10:17 -07001107 if (ret < 0)
1108 {
xf.licb6cd282024-02-21 22:06:14 -08001109 LYERRLOG("apn_db_query error");
xf.li0fc26502023-09-16 02:10:17 -07001110 return ret;
1111 }
xf.li2fc84552023-06-23 05:26:47 -07001112 for (int j = 0;j < table_num;j++)
1113 {
1114 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1115 {
1116 *handle = apn_table[j]->index;
1117 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1118 break;
1119 }
1120 }
1121
1122 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1123 {
1124 if (apn_table[i]!=NULL)
1125 {
1126 free(apn_table[i]);
1127 apn_table[i]=NULL;
1128 }
1129 }
1130 free(apn_table);
1131 apn_table=NULL;
1132 LYINFLOG("data_call_handle_get end");
1133 return RESULT_OK;
1134}
1135
1136void *thread_wait_cb_status(void)
1137{
1138 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001139 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001140 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001141 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001142 qser_data_call_state_s data_cb_state;
1143 while (s_qser_data_cb_thread_status)
1144 {
xf.li6b0d8502023-09-04 18:49:12 -07001145 ret = lynq_wait_data_call_state_change(&handle);
1146 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
1147 if(s_qser_data_cb_thread_status == 0)
1148 {
1149 return NULL;
1150 }
1151 else if(ret < 0)
1152 {
1153 continue;
1154 }
xf.li8535bc02023-12-12 23:28:35 -08001155 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
1156 memset(&data_urc_info, 0, sizeof(data_urc_info));
1157 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001158 lynq_get_data_call_list(&handle,&data_urc_info);
1159 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001160 //data_cb_state.profile_idx = (char)handle;
xf.licb6cd282024-02-21 22:06:14 -08001161 apn_db_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li8535bc02023-12-12 23:28:35 -08001162 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",
1163 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
1164 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
1165 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -07001166 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001167 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001168 {
1169 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1170 }
1171 else if (!strcmp(data_urc_info.type,"IPV6"))
1172 {
1173 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1174 }
xf.li8535bc02023-12-12 23:28:35 -08001175 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001176 {
1177 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1178 }
1179 else
1180 {
xf.li8535bc02023-12-12 23:28:35 -08001181 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001182 }
1183
xf.li8535bc02023-12-12 23:28:35 -08001184 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001185 {
1186 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1187 }
1188 else
1189 {
1190 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.licb6cd282024-02-21 22:06:14 -08001191 ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001192 if(ret != 0)
1193 {
1194 LYERRLOG("handle set error");
1195 }
xf.li2fc84552023-06-23 05:26:47 -07001196 }
1197 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1198 {
1199 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1200 }
1201 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1202 {
1203 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1204 }
1205 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1206 {
xf.li3c0a4752023-09-03 20:46:19 -07001207#ifdef MOBILETEK_TARGET_PLATFORM_T106
1208 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1209#else
xf.li2fc84552023-06-23 05:26:47 -07001210 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001211#endif
xf.li2fc84552023-06-23 05:26:47 -07001212 }
1213 else
1214 {
1215 LYERRLOG("unknow ip_family");
1216 continue;
1217 }
1218 if (s_data_call_cb != NULL)
1219 {
1220 s_data_call_cb(&data_cb_state);
1221 }
1222 }
1223 return NULL;
1224}
1225
1226int qser_cb_pthread_create()
1227{
xf.lib5d82bf2024-03-09 01:54:50 -08001228 pthread_attr_t attr;
xf.li2fc84552023-06-23 05:26:47 -07001229 int ret;
1230 s_qser_data_cb_thread_status = 1;
xf.lib5d82bf2024-03-09 01:54:50 -08001231
1232 pthread_attr_init(&attr);
1233 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1234
1235 ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL);
xf.li2fc84552023-06-23 05:26:47 -07001236 if (ret < 0)
1237 {
1238 LYERRLOG("pthread create fail");
1239 s_qser_data_cb_thread_status = 0;
1240 return RESULT_ERROR;
1241 }
xf.lib5d82bf2024-03-09 01:54:50 -08001242 pthread_attr_destroy(&attr);
xf.li2fc84552023-06-23 05:26:47 -07001243 return RESULT_OK;
1244}
1245
1246void qser_cb_pthread_cancel()
1247{
xf.li2fc84552023-06-23 05:26:47 -07001248 s_qser_data_cb_thread_status = 0;
1249 if (s_cb_tid != -1)
1250 {
xf.li6b0d8502023-09-04 18:49:12 -07001251 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001252 }
1253 return;
1254}
xf.li2fc84552023-06-23 05:26:47 -07001255int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1256{
1257 int ret = 0;
1258 int utoken = 0;
1259 if (NULL == evt_cb)
1260 {
1261 LYERRLOG("init incoming paramters error");
1262 return RESULT_ERROR;
1263 }
xf.li7b0bfd02023-08-03 01:11:52 -07001264
xf.li2fc84552023-06-23 05:26:47 -07001265 s_data_call_cb = evt_cb;
xf.li6b0d8502023-09-04 18:49:12 -07001266
xf.li2fc84552023-06-23 05:26:47 -07001267 ret = lynq_init_data(utoken);
1268 if (ret != RESULT_OK)
1269 {
xf.li6b0d8502023-09-04 18:49:12 -07001270 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001271 s_data_call_cb = NULL;
1272 return RESULT_ERROR;
1273 }
xf.li6b0d8502023-09-04 18:49:12 -07001274 qser_cb_pthread_create();
xf.licb6cd282024-02-21 22:06:14 -08001275 ret = init_apn_db();
1276 if(ret != RESULT_OK)
xf.lie3f55f42023-12-01 22:47:33 -08001277 {
xf.licb6cd282024-02-21 22:06:14 -08001278 LYERRLOG("init apn db error");
xf.lie3f55f42023-12-01 22:47:33 -08001279 return RESULT_ERROR;
1280 }
xf.licb6cd282024-02-21 22:06:14 -08001281
1282 ret = apn_db_handle_clean();
xf.li63b87e82024-01-04 00:43:35 -08001283 if(ret != RESULT_OK)
1284 {
1285 LYERRLOG("clean handle error");
1286 return RESULT_ERROR;
1287 }
xf.lib33d4862023-12-13 00:40:37 -08001288 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001289 return RESULT_OK;
1290}
1291
1292void qser_data_call_destroy(void)
1293{
xf.li6b0d8502023-09-04 18:49:12 -07001294 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001295 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001296 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001297 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001298 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001299 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001300 return ;
1301}
1302
1303int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1304{
1305 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001306 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001307 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001308 if(g_lynq_qser_data_init_flag == 0)
1309 {
1310 if(err != NULL)
1311 {
1312 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1313 }
1314 return LYNQ_E_NO_INIT;
1315 }
xf.li2fc84552023-06-23 05:26:47 -07001316 if (NULL == data_call || NULL == err)
1317 {
1318 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001319 if(err != NULL)
1320 {
1321 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1322 }
xf.li2fc84552023-06-23 05:26:47 -07001323 return ret;
1324 }
1325 if (data_call->profile_idx == 0)
1326 {
1327 ret = lynq_setup_data_call(&handle);
1328 }
1329 else
1330 {
1331 char pdptype[16];
1332 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001333 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1334 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li0fc26502023-09-16 02:10:17 -07001335 if (ret != 0)
1336 {
1337 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001338 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001339 return ret;
1340 }
xf.li2fc84552023-06-23 05:26:47 -07001341 judge_pdp_type(apn_info.pdp_type,pdptype);
1342 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype);
1343 }
xf.lic12b3702023-11-22 22:39:01 -08001344 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001345 {
1346 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1347 }
xf.li0fd6acf2023-12-20 18:16:34 -08001348 else
1349 {
xf.licb6cd282024-02-21 22:06:14 -08001350 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001351 if(error != 0)
1352 {
1353 LYERRLOG("handle set error");
1354 }
1355 }
xf.li2fc84552023-06-23 05:26:47 -07001356 return ret;
1357}
1358
xf.li8535bc02023-12-12 23:28:35 -08001359int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1360{
1361 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001362 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001363 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001364 if(g_lynq_qser_data_init_flag == 0)
1365 {
1366 if(err != NULL)
1367 {
1368 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1369 }
1370 return LYNQ_E_NO_INIT;
1371 }
xf.li8535bc02023-12-12 23:28:35 -08001372 if (NULL == data_call || NULL == err)
1373 {
1374 LYERRLOG("call start incoming paramters error");
1375 if(err != NULL)
1376 {
1377 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1378 }
1379 return ret;
1380 }
1381 if (data_call->profile_idx == 0)
1382 {
1383 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1384 }
1385 else
1386 {
1387 char pdptype[16];
1388 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001389 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1390 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li8535bc02023-12-12 23:28:35 -08001391 if (ret != 0)
1392 {
1393 LYERRLOG("qser_apn_get error");
1394 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1395 return ret;
1396 }
1397 judge_pdp_type(apn_info.pdp_type,pdptype);
1398 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);
1399 }
1400 if (ret != 0)
1401 {
1402 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1403 }
xf.li0fd6acf2023-12-20 18:16:34 -08001404 else
1405 {
xf.licb6cd282024-02-21 22:06:14 -08001406 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001407 if(error != 0)
1408 {
1409 LYERRLOG("handle set error");
1410 }
1411 }
xf.li8535bc02023-12-12 23:28:35 -08001412 return ret;
1413}
1414
xf.li2fc84552023-06-23 05:26:47 -07001415int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1416{
1417 int ret = 0;
1418 int handle = -1;
1419
xf.lib33d4862023-12-13 00:40:37 -08001420 if(g_lynq_qser_data_init_flag == 0)
1421 {
1422 if(err != NULL)
1423 {
1424 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1425 }
1426 return LYNQ_E_NO_INIT;
1427 }
xf.li2fc84552023-06-23 05:26:47 -07001428 if (NULL == err)
1429 {
1430 LYERRLOG("call stop incoming paramters error");
1431 return ret;
1432 }
xf.lic12b3702023-11-22 22:39:01 -08001433 ret = data_call_handle_get(profile_idx,&handle);
1434 if(ret != 0)
1435 {
1436 LYERRLOG("datacall handle get error");
1437 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1438 return ret;
1439 }
xf.li2fc84552023-06-23 05:26:47 -07001440 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001441 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001442 {
1443 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001444 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001445 }
xy.hee2daacc2023-09-18 00:57:51 -07001446 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001447}
1448int 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)
1449{
1450 int ret = 0;
1451 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001452 if(g_lynq_qser_data_init_flag == 0)
1453 {
1454 if(err != NULL)
1455 {
1456 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1457 }
1458 return LYNQ_E_NO_INIT;
1459 }
xf.li2fc84552023-06-23 05:26:47 -07001460 lynq_data_call_response_v11_t data_call_info;
1461 data_call_handle_get(profile_idx,&handle);
1462 ret = lynq_get_data_call_list(&handle,&data_call_info);
1463 if (ret == 0)
1464 {
1465 info->profile_idx = profile_idx;
1466 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001467 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 -07001468 {
1469 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001470 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001471 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1472 lynq_ipv4_aton_getinfo(&data_call_info,info);
1473 }
xf.li3c0a4752023-09-03 20:46:19 -07001474 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001475 {
1476 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001477 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001478 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1479 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1480 }
xf.li3c0a4752023-09-03 20:46:19 -07001481 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001482 {
1483 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001484 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001485 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 -07001486#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001487 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001488#endif
xf.li2fc84552023-06-23 05:26:47 -07001489 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001490 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001491 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 -07001492#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001493 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001494#endif
1495#ifdef MOBILETEK_TARGET_PLATFORM_T106
1496 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1497#endif
xf.li2fc84552023-06-23 05:26:47 -07001498 }
1499 else
1500 {
1501 LYERRLOG("useless qser_data_call_ip_family_e");
1502 }
1503 }
1504 return ret;
1505}
1506int qser_apn_set(qser_apn_info_s *apn)
1507{
1508 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001509 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001510 if(g_lynq_qser_data_init_flag == 0)
1511 {
1512 return LYNQ_E_NO_INIT;
1513 }
xf.li4b18fa62023-12-19 19:38:10 -08001514 if (NULL == apn || apn->profile_idx == 0)
xf.li2fc84552023-06-23 05:26:47 -07001515 {
1516 LYERRLOG("apn set incoming paramters error");
1517 return RESULT_ERROR;
1518 }
xf.licb6cd282024-02-21 22:06:14 -08001519 ret = apn_db_handle_get(apn->profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001520 if(ret != 0)
1521 {
1522 LYERRLOG("handle set error");
1523 }
1524 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1525 {
1526 LYERRLOG("It has setup datacall");
1527 return RESULT_ERROR;
1528 }
xf.licb6cd282024-02-21 22:06:14 -08001529 ret = apn_db_modify(apn);
xf.li2fc84552023-06-23 05:26:47 -07001530 if (ret < 0)
1531 {
xf.licb6cd282024-02-21 22:06:14 -08001532 LYERRLOG("apn_db_modify error");
xf.li2fc84552023-06-23 05:26:47 -07001533 return ret;
1534 }
xf.li6c7e3972023-10-27 20:01:59 -07001535#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001536 int apn_id = 0;
1537 char tmp_id[12];
1538 char *outinfo = NULL;
1539 char normalprotocol[16];
1540 char authtype[32];
1541 outinfo = (char *)malloc(sizeof(char)*512);
1542 bzero(tmp_id,12);
1543 bzero(outinfo,512);
1544 apn_id = apn->profile_idx + apndb_offset;
1545 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1546 judge_pdp_type(apn->pdp_type,normalprotocol);
1547 judge_authtype(apn->auth_proto,authtype);
1548 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1549 LYINFLOG("[output]:%s",outinfo);
1550 free(outinfo);
1551 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001552#endif
1553 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001554}
1555
1556int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1557{
xf.lib33d4862023-12-13 00:40:37 -08001558 if(g_lynq_qser_data_init_flag == 0)
1559 {
1560 return LYNQ_E_NO_INIT;
1561 }
xf.licb6cd282024-02-21 22:06:14 -08001562 if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn)
xf.li2fc84552023-06-23 05:26:47 -07001563 {
1564 LYERRLOG("apn get incoming paramters error");
1565 return RESULT_ERROR;
1566 }
1567 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001568 ret = apn_db_query(profile_idx,apn);
xf.li2fc84552023-06-23 05:26:47 -07001569 if (ret < 0)
1570 {
xf.licb6cd282024-02-21 22:06:14 -08001571 LYERRLOG("apn_db_query error");
xf.li2fc84552023-06-23 05:26:47 -07001572 return ret;
1573 }
1574 return ret;
1575}
1576
1577int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1578{
1579 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001580
xf.lib33d4862023-12-13 00:40:37 -08001581 if(g_lynq_qser_data_init_flag == 0)
1582 {
1583 return LYNQ_E_NO_INIT;
1584 }
xf.li2fc84552023-06-23 05:26:47 -07001585 if (NULL == apn || NULL == profile_idx)
1586 {
1587 LYERRLOG("apn add incoming paramters error");
1588 return RESULT_ERROR;
1589 }
xf.licb6cd282024-02-21 22:06:14 -08001590
1591 *profile_idx = 0;
1592 *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH);
1593 LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx);
1594 if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001595 {
xf.licb6cd282024-02-21 22:06:14 -08001596 LYINFLOG("[%s] apn full is false\n",__FUNCTION__);
1597 ret = apn_db_add((int)*profile_idx, apn);
1598 if (ret != 0)
1599 {
1600 LYERRLOG("apn_db_add error");
1601 return RESULT_ERROR;
1602 }
1603 else
1604 {
1605 return RESULT_OK;
1606 }
xf.li2fc84552023-06-23 05:26:47 -07001607 }
xf.licb6cd282024-02-21 22:06:14 -08001608 LYERRLOG("apn storage space is full!!!");
1609 return RESULT_ERROR;
xf.li6c7e3972023-10-27 20:01:59 -07001610#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001611 int apn_id = 0;
1612 char tmp_id[12];
1613 char *outinfo = NULL;
1614 char normalprotocol[16];
1615 char authtype[32];
1616 outinfo = (char *)malloc(sizeof(char)*512);
1617 bzero(tmp_id,12);
1618 bzero(outinfo,512);
1619 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1620 judge_pdp_type(apn->pdp_type,normalprotocol);
1621 judge_authtype(apn->auth_proto,authtype);
1622 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1623 LYINFLOG("[output]:%s",outinfo);
1624 free(outinfo);
1625 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001626#endif
1627 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001628}
1629
1630int qser_apn_del(unsigned char profile_idx)
1631{
xf.lib33d4862023-12-13 00:40:37 -08001632 if(g_lynq_qser_data_init_flag == 0)
1633 {
1634 return LYNQ_E_NO_INIT;
1635 }
xf.li4b18fa62023-12-19 19:38:10 -08001636 if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001637 {
1638 LYERRLOG("apn del incoming paramters error");
xf.li4b18fa62023-12-19 19:38:10 -08001639 return RESULT_ERROR;
xf.li2fc84552023-06-23 05:26:47 -07001640 }
1641 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001642 int handle = -1;
xf.licb6cd282024-02-21 22:06:14 -08001643 ret = apn_db_handle_get(profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001644 if(ret != 0)
1645 {
1646 LYERRLOG("handle set error");
1647 }
1648 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1649 {
1650 LYERRLOG("It has setup datacall");
1651 return RESULT_ERROR;
1652 }
xf.licb6cd282024-02-21 22:06:14 -08001653 ret = apn_db_delete(profile_idx);
xf.li2fc84552023-06-23 05:26:47 -07001654 if (ret < 0)
1655 {
xf.licb6cd282024-02-21 22:06:14 -08001656 LYERRLOG("apn_db_delete error");
xf.li2fc84552023-06-23 05:26:47 -07001657 return ret;
1658 }
xf.li6c7e3972023-10-27 20:01:59 -07001659#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001660 int apn_id = 0;
1661 char tmp_id[12];
1662 char *outinfo = NULL;
1663 outinfo = (char *)malloc(sizeof(char)*512);
1664 bzero(tmp_id,12);
1665 bzero(outinfo,512);
1666 apn_id = profile_idx+apndb_offset;
1667 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1668 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1669 LYINFLOG("[output]:%s",outinfo);
1670 free(outinfo);
1671 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001672#endif
xf.li2fc84552023-06-23 05:26:47 -07001673 return ret;
1674}
1675
1676int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1677{
xf.lib33d4862023-12-13 00:40:37 -08001678 if(g_lynq_qser_data_init_flag == 0)
1679 {
1680 return LYNQ_E_NO_INIT;
1681 }
xf.li2fc84552023-06-23 05:26:47 -07001682 if (NULL == apn_list)
1683 {
1684 LYERRLOG("apn_list incoming paramters error");
1685 return RESULT_ERROR;
1686 }
1687 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001688 ret = apn_db_query_list(apn_list);
xf.li2fc84552023-06-23 05:26:47 -07001689 if (ret < 0)
1690 {
xf.licb6cd282024-02-21 22:06:14 -08001691 LYERRLOG("apn_db_query_list error");
xf.li2fc84552023-06-23 05:26:47 -07001692 return ret;
1693 }
1694 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001695}
you.chen21c62b72023-09-08 09:41:11 +08001696
1697DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1698