blob: e27a2057b9a4968d1d9fb13387a0feb186023c8d [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.li1bbfc7d2024-07-15 23:50:41 -070020#define APN_TABLE_CREATE 3
21#define APN_TABLE_NEED_CREATE 4
xf.li2fc84552023-06-23 05:26:47 -070022#define RESULT_OK (0)
23#define RESULT_ERROR (-1)
24
xf.lib33d4862023-12-13 00:40:37 -080025typedef enum{
xf.licb6cd282024-02-21 22:06:14 -080026 LYNQ_E_NO_INIT=9002,
27 LYNQ_E_APN_DB_FAIL=9003
xf.lib33d4862023-12-13 00:40:37 -080028}LYNQ_E;
29
30static int g_lynq_qser_data_init_flag = 0;
xf.li2fc84552023-06-23 05:26:47 -070031static pthread_t s_cb_tid = -1;
32static int s_qser_data_cb_thread_status = 0;
33static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
xf.li87f6e6e2024-06-19 02:23:05 -070034static pthread_mutex_t s_qser_data_database_mutex = PTHREAD_MUTEX_INITIALIZER;
xf.li2fc84552023-06-23 05:26:47 -070035static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER;
36
xf.li2fc84552023-06-23 05:26:47 -070037
38static qser_data_call_evt_cb_t s_data_call_cb = NULL;
xf.licb6cd282024-02-21 22:06:14 -080039static sqlite3* apnDb;
40qser_apn_add_s default_apn = {QSER_APN_PDP_TYPE_IPV4V6, QSER_APN_AUTH_PROTO_DEFAULT, "default", "NULL", "NULL", "default"};
41int apn_indexs[LYNQ_APN_CHANNEL_MAX]={0};
42int next_index = 0;
43int apn_count = 0;
xf.li2fc84552023-06-23 05:26:47 -070044const int apndb_offset = 683;
45
xf.licb6cd282024-02-21 22:06:14 -080046static int init_apn_db();
47static int create_apn_db(char *path);
48static int create_apn_table(char*path);
49static int has_apn_db_created(char *path,sqlite3* apnDb_l);
50static int apn_db_handle_clean();
51
52static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName);
53static int lynq_check_index(unsigned char index);
54static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName);
55static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx);
56static int apn_db_handle_set(unsigned char profile_idx, int handle);
57static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName);
58static int apn_db_handle_get(unsigned char profile_idx, int *handle);
59
60static int find_unuse_apn_index(char *path);
61static int apn_db_add(int profile_id, qser_apn_add_s *apn);
62static int apn_db_delete(unsigned char profile_idx);
63static int apn_db_modify(qser_apn_info_s *apn);
64static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName);
65static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn);
66static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName);
67static int apn_db_query_list(qser_apn_info_list_s *apn_list);
xf.li7aca5c02025-01-02 02:48:47 -080068#ifdef MOBILETEK_TARGET_PLATFORM_T106
69int qser_set_initial_apnname(char *apnname);
70int qser_get_initial_apnname(char apnname[QSER_APN_NAME_SIZE]);
71#endif
xf.licb6cd282024-02-21 22:06:14 -080072
xf.li2fc84552023-06-23 05:26:47 -070073void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
74{
xf.li3c0a4752023-09-03 20:46:19 -070075#ifdef MOBILETEK_TARGET_PLATFORM_T106
76 char *tmp_char = NULL;
77 char *addresses = NULL;
78 char *dnses = NULL;
79 const char addresses_separator[2] = "/";
80 const char dnses_separator[2] = " ";
81
82 addresses = libdata->addresses;
83 dnses = libdata->dnses;
84 //get addresses
85 tmp_char = strsep(&addresses, addresses_separator);
86 if(tmp_char != NULL)
87 {
xf.li7d256b62025-03-21 00:07:36 -070088 LYDBGLOG("ipv4 addresses = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -070089 inet_aton(tmp_char,&(data_res->v4.ip));
90 }
91
92 //get dnses
93 tmp_char = strsep(&dnses, dnses_separator);
94 if(tmp_char != NULL)
95 {
xf.li7d256b62025-03-21 00:07:36 -070096 LYDBGLOG("ipv4 pri_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -070097 inet_aton(tmp_char,&(data_res->v4.pri_dns));
98 }
99 tmp_char = strsep(&dnses, dnses_separator);
100 if(tmp_char != NULL)
101 {
xf.li7d256b62025-03-21 00:07:36 -0700102 LYDBGLOG("ipv4 sec_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700103 inet_aton(tmp_char, &(data_res->v4.sec_dns));
104 }
105 //get gateway
106 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
107
108#else
xf.li2fc84552023-06-23 05:26:47 -0700109 inet_aton(libdata->addresses,&(data_res->v4.ip));
110 inet_aton(libdata->gateways,&(data_res->v4.gateway));
111 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
112 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700113#endif
xf.li2fc84552023-06-23 05:26:47 -0700114 return ;
115}
116
117void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
118{
xf.li3c0a4752023-09-03 20:46:19 -0700119#ifdef MOBILETEK_TARGET_PLATFORM_T106
120 char *tmp_char = NULL;
121 char *addresses = NULL;
122 char *dnses = NULL;
123 const char addresses_separator[2] = "/";
124 const char dnses_separator[2] = " ";
125
126 addresses = libdata->addresses;
127 dnses = libdata->dnses;
128 //get addresses
129 tmp_char = strsep(&addresses, addresses_separator);
130 if(tmp_char != NULL)
131 {
xf.li7d256b62025-03-21 00:07:36 -0700132 LYDBGLOG("ipv6 addresses = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700133 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
134 }
135 //get dnses
136 tmp_char = strsep(&dnses, dnses_separator);
137 if(tmp_char != NULL)
138 {
xf.li7d256b62025-03-21 00:07:36 -0700139 LYDBGLOG("ipv6 pri_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700140 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
141 }
142 tmp_char = strsep(&dnses, dnses_separator);
143 if(tmp_char != NULL)
144 {
xf.li7d256b62025-03-21 00:07:36 -0700145 LYDBGLOG("ipv6 sec_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700146 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
147 }
148 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
149#else
xf.li2fc84552023-06-23 05:26:47 -0700150 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
151 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
152 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
153 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700154#endif
155
156 return ;
157}
158
159void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
160{
161 char *tmp_char = NULL;
162 char *addresses = NULL;
163 char *dnses = NULL;
164 const char addresses_separator[2] = "/";
165 const char dnses_separator[2] = " ";
166
xf.li03baf1f2023-12-19 21:30:38 -0800167 char buf_ip[64] = {0};
168 char buf_gateway[64] = {0};
169 char buf_pri_dns[64] = {0};
170 char buf_sec_dns[64] = {0};
171
xf.li3c0a4752023-09-03 20:46:19 -0700172 addresses = libdata->addresses;
173 dnses = libdata->dnses;
174 //get addresses
175 tmp_char = strsep(&addresses, addresses_separator);
176 if(tmp_char != NULL)
177 {
xf.li7d256b62025-03-21 00:07:36 -0700178 LYDBGLOG("ipv4 addresses = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700179 inet_aton(tmp_char,&(data_res->v4.ip));
180 }
181 tmp_char = strsep(&addresses, addresses_separator);
182 if(tmp_char != NULL)
183 {
xf.li7d256b62025-03-21 00:07:36 -0700184 LYDBGLOG("ipv6 addresses = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700185 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
186 }
187 //get dnses
188 tmp_char = strsep(&dnses, dnses_separator);
189 if(tmp_char != NULL)
190 {
xf.li7d256b62025-03-21 00:07:36 -0700191 LYDBGLOG("ipv4 pri_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700192 inet_aton(tmp_char,&(data_res->v4.pri_dns));
193 }
194 tmp_char = strsep(&dnses, dnses_separator);
195 if(tmp_char != NULL)
196 {
xf.li7d256b62025-03-21 00:07:36 -0700197 LYDBGLOG("ipv4 sec_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700198 inet_aton(tmp_char, &(data_res->v4.sec_dns));
199 }
200 tmp_char = strsep(&dnses, dnses_separator);
201 if(tmp_char != NULL)
202 {
xf.li7d256b62025-03-21 00:07:36 -0700203 LYDBGLOG("ipv6 pri_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700204 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
205 }
206 tmp_char = strsep(&dnses, dnses_separator);
207 if(tmp_char != NULL)
208 {
xf.li7d256b62025-03-21 00:07:36 -0700209 LYDBGLOG("ipv6 sec_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700210 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
211 }
212 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800213 inet_aton(libdata->gateways,&(data_res->v4.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700214 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
215
xf.li7d256b62025-03-21 00:07:36 -0700216 LYDBGLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip));
217 LYDBGLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns));
218 LYDBGLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns));
xf.li03baf1f2023-12-19 21:30:38 -0800219
220 inet_ntop(AF_INET6, &(data_res->v6.ip), buf_ip, sizeof(buf_ip));
221 inet_ntop(AF_INET6, &(data_res->v6.gateway), buf_gateway, sizeof(buf_gateway));
222 inet_ntop(AF_INET6, &(data_res->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
223 inet_ntop(AF_INET6, &(data_res->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
xf.li7d256b62025-03-21 00:07:36 -0700224 LYDBGLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
xf.li03baf1f2023-12-19 21:30:38 -0800225 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
xf.li2fc84552023-06-23 05:26:47 -0700226 return ;
227}
228
229void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
230{
xf.li3c0a4752023-09-03 20:46:19 -0700231#ifdef MOBILETEK_TARGET_PLATFORM_T106
232 char *tmp_char = NULL;
233 char *addresses = NULL;
234 char *dnses = NULL;
235 const char addresses_separator[2] = "/";
236 const char dnses_separator[2] = " ";
237
238 addresses = libdata->addresses;
239 dnses = libdata->dnses;
240 //get addresses
241 tmp_char = strsep(&addresses, addresses_separator);
242 if(tmp_char != NULL)
243 {
xf.li7d256b62025-03-21 00:07:36 -0700244 LYDBGLOG("ipv4 addresses = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700245 inet_aton(tmp_char,&(data_res->v4.addr.ip));
246 }
247 //get dnses
248 tmp_char = strsep(&dnses, dnses_separator);
249 if(tmp_char != NULL)
250 {
xf.li7d256b62025-03-21 00:07:36 -0700251 LYDBGLOG("ipv4 pri_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700252 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
253 }
254 tmp_char = strsep(&dnses, dnses_separator);
255 if(tmp_char != NULL)
256 {
xf.li7d256b62025-03-21 00:07:36 -0700257 LYDBGLOG("ipv4 sec_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700258 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
259 }
260 //get gateway
xf.li7d256b62025-03-21 00:07:36 -0700261 LYDBGLOG("ipv4 gateways = %s", libdata->gateways);
xf.li3c0a4752023-09-03 20:46:19 -0700262 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
263
xf.li7d256b62025-03-21 00:07:36 -0700264 LYDBGLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
265 LYDBGLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
266 LYDBGLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700267#else
xf.li2fc84552023-06-23 05:26:47 -0700268 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
269 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
270 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
271 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700272#endif
xf.li2fc84552023-06-23 05:26:47 -0700273 data_res->v4.stats.pkts_tx = 0;
274 data_res->v4.stats.pkts_rx = 0;
275 data_res->v4.stats.bytes_tx = 0;
276 data_res->v4.stats.bytes_rx = 0;
277 data_res->v4.stats.pkts_dropped_tx = 0;
278 data_res->v4.stats.pkts_dropped_rx = 0;
279 return ;
280}
281
282void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
283{
xf.li3c0a4752023-09-03 20:46:19 -0700284#ifdef MOBILETEK_TARGET_PLATFORM_T106
285 char *tmp_char = NULL;
286 char *addresses = NULL;
287 char *dnses = NULL;
288 const char addresses_separator[2] = "/";
289 const char dnses_separator[2] = " ";
290
291 addresses = libdata->addresses;
292 dnses = libdata->dnses;
293 //get addresses
294 tmp_char = strsep(&addresses, addresses_separator);
295 if(tmp_char != NULL)
296 {
xf.li7d256b62025-03-21 00:07:36 -0700297 LYDBGLOG("ipv6 addresses = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700298 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
299 }
300 //get dnses
301 tmp_char = strsep(&dnses, dnses_separator);
302 if(tmp_char != NULL)
303 {
xf.li7d256b62025-03-21 00:07:36 -0700304 LYDBGLOG("ipv6 pri_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700305 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
306 }
307 tmp_char = strsep(&dnses, dnses_separator);
308 if(tmp_char != NULL)
309 {
xf.li7d256b62025-03-21 00:07:36 -0700310 LYDBGLOG("ipv6 sec_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700311 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
312 }
313 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
314#else
xf.li2fc84552023-06-23 05:26:47 -0700315 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
316 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
317 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
318 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700319#endif
320 data_res->v6.stats.pkts_tx = 0;
321 data_res->v6.stats.pkts_rx = 0;
322 data_res->v6.stats.bytes_tx = 0;
323 data_res->v6.stats.bytes_rx = 0;
324 data_res->v6.stats.pkts_dropped_tx = 0;
325 data_res->v6.stats.pkts_dropped_rx = 0;
326 return ;
327}
328void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
329{
330 char *tmp_char = NULL;
331 char *addresses = NULL;
332 char *dnses = NULL;
333 const char addresses_separator[2] = "/";
334 const char dnses_separator[2] = " ";
335
336 char buf_ip[64] = {0};
337 char buf_gateway[64] = {0};
338 char buf_pri_dns[64] = {0};
339 char buf_sec_dns[64] = {0};
340
341 addresses = libdata->addresses;
342 dnses = libdata->dnses;
343 //get addresses
344 tmp_char = strsep(&addresses, addresses_separator);
345 if(tmp_char != NULL)
346 {
xf.li7d256b62025-03-21 00:07:36 -0700347 LYDBGLOG("ipv4 addresses = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700348 inet_aton(tmp_char,&(data_res->v4.addr.ip));
349 }
350 tmp_char = strsep(&addresses, addresses_separator);
351 if(tmp_char != NULL)
352 {
xf.li7d256b62025-03-21 00:07:36 -0700353 LYDBGLOG("ipv6 addresses = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700354 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
355 }
356 //get dnses
357 tmp_char = strsep(&dnses, dnses_separator);
358 if(tmp_char != NULL)
359 {
xf.li7d256b62025-03-21 00:07:36 -0700360 LYDBGLOG("ipv4 pri_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700361 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
362 }
363 tmp_char = strsep(&dnses, dnses_separator);
364 if(tmp_char != NULL)
365 {
xf.li7d256b62025-03-21 00:07:36 -0700366 LYDBGLOG("ipv4 sec_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700367 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
368 }
369 tmp_char = strsep(&dnses, dnses_separator);
370 if(tmp_char != NULL)
371 {
xf.li7d256b62025-03-21 00:07:36 -0700372 LYDBGLOG("ipv6 pri_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700373 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
374 }
375 tmp_char = strsep(&dnses, dnses_separator);
376 if(tmp_char != NULL)
377 {
xf.li7d256b62025-03-21 00:07:36 -0700378 LYDBGLOG("ipv6 sec_dns = %s", tmp_char);
xf.li3c0a4752023-09-03 20:46:19 -0700379 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
380 }
381 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800382 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700383 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
384
xf.li7d256b62025-03-21 00:07:36 -0700385 LYDBGLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
386 LYDBGLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway));
387 LYDBGLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
388 LYDBGLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700389
390 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
391 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
392 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
393 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
xf.li7d256b62025-03-21 00:07:36 -0700394 LYDBGLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
xf.li3c0a4752023-09-03 20:46:19 -0700395 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
396 data_res->v4.stats.pkts_tx = 0;
397 data_res->v4.stats.pkts_rx = 0;
398 data_res->v4.stats.bytes_tx = 0;
399 data_res->v4.stats.bytes_rx = 0;
400 data_res->v4.stats.pkts_dropped_tx = 0;
401 data_res->v4.stats.pkts_dropped_rx = 0;
402
xf.li2fc84552023-06-23 05:26:47 -0700403 data_res->v6.stats.pkts_tx = 0;
404 data_res->v6.stats.pkts_rx = 0;
405 data_res->v6.stats.bytes_tx = 0;
406 data_res->v6.stats.bytes_rx = 0;
407 data_res->v6.stats.pkts_dropped_tx = 0;
408 data_res->v6.stats.pkts_dropped_rx = 0;
409 return ;
410}
411
412void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
413{
xf.lib5dc0632023-11-30 18:20:35 -0800414 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700415 {
416 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
417 data_res->v4.reconnect = 1;
418 }
419 else
420 {
421 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
422 data_res->v4.reconnect = 0;
423 }
424 return ;
425}
426
427void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
428{
xf.lib5dc0632023-11-30 18:20:35 -0800429 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700430 {
431 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
432 data_res->v6.reconnect = 1;
433 }
434 else
435 {
436 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
437 data_res->v6.reconnect = 0;
438 }
439 return ;
440}
441
xf.licb6cd282024-02-21 22:06:14 -0800442// ****************apn DB start******************
443static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName)
xf.li0fd6acf2023-12-20 18:16:34 -0800444{
xf.licb6cd282024-02-21 22:06:14 -0800445 if(data==NULL)
xf.li0fd6acf2023-12-20 18:16:34 -0800446 {
xf.licb6cd282024-02-21 22:06:14 -0800447 return 1;
xf.li0fd6acf2023-12-20 18:16:34 -0800448 }
xf.licb6cd282024-02-21 22:06:14 -0800449 int *temp = (int *)data;
450 for(int i=0; i<argc; i++){
xf.li7d256b62025-03-21 00:07:36 -0700451 LYDBGLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li0fd6acf2023-12-20 18:16:34 -0800452 }
xf.licb6cd282024-02-21 22:06:14 -0800453 *temp = atoi(argv[0]);
454 return 0;
455}
456static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx)
457{
458 char *zErrMsg = 0;
459 int rc;
460 int idx = 0;
xf.liff415202024-09-19 23:08:09 -0700461 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800462
463 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700464 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800465 rc = sqlite3_open(APN_DB_PATH, &apnDb);
466 if( rc )
xf.li0fd6acf2023-12-20 18:16:34 -0800467 {
xf.licb6cd282024-02-21 22:06:14 -0800468 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700469 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800470 return LYNQ_E_APN_DB_FAIL;
471 }
472
xf.li7d256b62025-03-21 00:07:36 -0700473 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -0800474 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700475 sprintf(sql,"SELECT ID from LYNQAPN WHERE HANDLE=%d", handle);
xf.licb6cd282024-02-21 22:06:14 -0800476 LYINFLOG("sql: %s\n", sql);
477 /* Execute SQL statement */
478 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_profile_cb, &idx, &zErrMsg);
479 if( rc != SQLITE_OK )
480 {
481 LYERRLOG("SQL error: %s\n", zErrMsg);
482 sqlite3_free(zErrMsg);
483 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700484 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800485 return LYNQ_E_APN_DB_FAIL;
486 };
487 *profile_idx = (unsigned char)idx;
488 LYINFLOG("get idx %d successfully\n", *profile_idx);
489 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700490 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800491 return 0;
492}
493static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName){
494 int i;
495
496 apn_indexs[atoi(argv[0])] = atoi(argv[0]);
xf.li7d256b62025-03-21 00:07:36 -0700497 LYDBGLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]);
xf.licb6cd282024-02-21 22:06:14 -0800498
499 for(i=0; i<argc; i++){
xf.li7d256b62025-03-21 00:07:36 -0700500 LYDBGLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.licb6cd282024-02-21 22:06:14 -0800501 }
502 return 0;
503}
504/**
505 * @brief Check whether the ID exists in the database
506 *
507 * @param index
508 * @return int
509 * find:turn 1
510 * not find:turn 0
511 */
512static int lynq_check_index(unsigned char index)
513{
514 memset(apn_indexs,0,sizeof(apn_indexs));
515 next_index = 0;
516 char *zErrMsg = 0;
517 int rc;
518 char sql[128]={0};
519 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700520 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800521 rc = sqlite3_open(APN_DB_PATH, &apnDb);
522 if( rc )
523 {
524 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700525 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800526 return LYNQ_E_APN_DB_FAIL;
527 }
528 sprintf(sql,"%s", "SELECT * from LYNQAPN");
529 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback, NULL, &zErrMsg);
530 if( rc != SQLITE_OK )
531 {
532 LYERRLOG("SQL error: %s\n", zErrMsg);
533 sqlite3_free(zErrMsg);
534 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700535 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800536 return LYNQ_E_APN_DB_FAIL;
537 }
538 //for(int cnt = 0; cnt < next_index;cnt++)
539 for(int cnt = 0; cnt <= QSER_APN_MAX_LIST; cnt++)
540 {
541 if(index == apn_indexs[cnt])
542 {
xf.li7d256b62025-03-21 00:07:36 -0700543 LYDBGLOG("index = apn_index\n");
xf.licb6cd282024-02-21 22:06:14 -0800544 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700545 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800546 return 1;
547 }
548 }
549 LYINFLOG("cant find the index %d\n", index);
550 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700551 pthread_mutex_unlock(&s_qser_data_database_mutex);
552
xf.licb6cd282024-02-21 22:06:14 -0800553 return 0;
554}
555
556static int apn_db_handle_set(unsigned char profile_idx, int handle)
557{
558 char *zErrMsg = 0;
559 int rc;
xf.liff415202024-09-19 23:08:09 -0700560 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800561 if(!lynq_check_index(profile_idx))
562 {
563 return LYNQ_E_APN_DB_FAIL;
564 }
565 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700566 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800567 rc = sqlite3_open(APN_DB_PATH, &apnDb);
568 if( rc )
569 {
570 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700571 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800572 return LYNQ_E_APN_DB_FAIL;
573 }
574
xf.li7d256b62025-03-21 00:07:36 -0700575 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -0800576 /* Create SQL statement */
577 //sql = "SELECT * from LYNQAPN";
xf.liff415202024-09-19 23:08:09 -0700578 sprintf(sql,"UPDATE LYNQAPN SET HANDLE=%d WHERE ID=%d", handle, (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800579 LYINFLOG("sql: %s\n", sql);
580 /* Execute SQL statement */
581 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
582 if( rc != SQLITE_OK )
583 {
584 LYERRLOG("SQL error: %s\n", zErrMsg);
585 sqlite3_free(zErrMsg);
586 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700587 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800588 return LYNQ_E_APN_DB_FAIL;
589 }
590 LYINFLOG("update apn %d successfully\n", profile_idx);
591 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700592 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800593 return 0;
594}
595static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName)
596{
597 if(data==NULL)
598 {
599 return 1;
600 }
601 int *temp = (int *)data;
602 for(int i=0; i<argc; i++){
xf.li7d256b62025-03-21 00:07:36 -0700603 LYDBGLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.licb6cd282024-02-21 22:06:14 -0800604 }
605 *temp = atoi(argv[0]);
606 LYINFLOG("The handle is %d\n", *temp);
607 return 0;
608}
609static int apn_db_handle_get(unsigned char profile_idx, int *handle)
610{
611 char *zErrMsg = 0;
612 int rc;
xf.liff415202024-09-19 23:08:09 -0700613 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800614
xf.licb6cd282024-02-21 22:06:14 -0800615 if(!lynq_check_index(profile_idx))
616 {
617 return LYNQ_E_APN_DB_FAIL;
618 }
619 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700620 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800621 rc = sqlite3_open(APN_DB_PATH, &apnDb);
622 if( rc )
623 {
624 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700625 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800626 return LYNQ_E_APN_DB_FAIL;
627 }
628
xf.li7d256b62025-03-21 00:07:36 -0700629 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -0800630 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700631 sprintf(sql,"SELECT HANDLE from LYNQAPN WHERE ID=%d", (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800632 LYINFLOG("sql: %s\n", sql);
633 /* Execute SQL statement */
634 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_cb, handle, &zErrMsg);
635 if( rc != SQLITE_OK )
636 {
637 LYERRLOG("SQL error: %s\n", zErrMsg);
638 sqlite3_free(zErrMsg);
639 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700640 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800641 return LYNQ_E_APN_DB_FAIL;
642 }
643 LYINFLOG("get idx %d successfully\n", *handle);
644 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700645 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800646 return 0;
647}
648
649static int has_apn_db_created(char *path,sqlite3* apnDb_l)
650{
651 if (path == NULL || strlen(path) == 0)
652 {
653 LYERRLOG("initApnDb error with null path!");
654 return APN_DB_ERR;
655 }
656 int rc = sqlite3_open_v2(path, &apnDb_l, SQLITE_OPEN_READWRITE,NULL);
657 if (rc == SQLITE_OK)
658 {
659 LYINFLOG("check init success!");
xf.lib5d82bf2024-03-09 01:54:50 -0800660 sqlite3_close_v2(apnDb_l);
xf.licb6cd282024-02-21 22:06:14 -0800661 return APN_DB_READED;
662 }
663 else
664 {
665 LYERRLOG("db has not create %s!", sqlite3_errmsg(apnDb_l));
666 sqlite3_close_v2(apnDb_l);
667 return APN_DB_ERR;
668 }
669}
670static int create_apn_db(char *path)
671{
672 if (path == NULL || strlen(path) == 0) {
673 LYERRLOG("initApnDb error with null path!");
674 return APN_DB_ERR;
675 }
676 if(APN_DB_READED==has_apn_db_created(path,apnDb))
677 {
678 return APN_DB_READED;
679 }
680 int rc = sqlite3_open(path, &apnDb);
681 if (rc != SQLITE_OK) {
682 LYERRLOG("initDb failed %d", sqlite3_errcode(apnDb));
683 return APN_DB_ERR;
684 } else {
685 LYINFLOG("create db in %s", path);
686 }
687 sqlite3_close(apnDb);
688 return APN_DB_CREATE;
689}
690static int create_apn_table(char*path)
691{
692 char *zErrMsg = 0;
693 int rc;
694 char *sql;
695
696 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700697 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800698 rc = sqlite3_open(path, &apnDb);
699 if( rc )
700 {
701 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700702 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800703 return 1;
704 }
xf.li7d256b62025-03-21 00:07:36 -0700705 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -0800706 /* Create SQL statement */
707 sql = "CREATE TABLE LYNQAPN( \
708 ID INT NOT NULL, \
709 PDP_TYPE INT NOT NULL, \
710 AUTH_PROTO INT NOT NULL, \
711 APN_NAME TEXT NOT NULL, \
712 USERNAME TEXT NOT NULL,\
713 PASSWORD TEXT NOT NULL, \
714 APN_TYPE TEXT PRIMARY KEY NOT NULL, \
715 HANDLE INT NOT NULL)";
716 /* Execute SQL statement */
717 rc = sqlite3_exec(apnDb, sql, NULL, 0, &zErrMsg);
718 if( rc != SQLITE_OK )
719 {
720 LYERRLOG("SQL error: %s\n", zErrMsg);
721 sqlite3_free(zErrMsg);
722 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700723 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800724 return 1;
725 }
xf.li7d256b62025-03-21 00:07:36 -0700726 LYDBGLOG("Table LYNQAPN created successfully\n");
xf.licb6cd282024-02-21 22:06:14 -0800727 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700728 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800729 return 0;
730}
xf.li1bbfc7d2024-07-15 23:50:41 -0700731check_apn_table_cb(void *data, int argc, char **argv, char **azColName)
732{
733 if(data==NULL)
734 {
735 return 1;
736 }
737 int *temp = (int *)data;
738 for(int i=0; i<argc; i++){
xf.li7d256b62025-03-21 00:07:36 -0700739 LYDBGLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li1bbfc7d2024-07-15 23:50:41 -0700740 }
741 *temp = atoi(argv[0]);
742 LYINFLOG("\nThe number is %d\n", *temp);
743 return 0;
744}
745int check_apn_table(char*path)
746{
747 char *zErrMsg = 0;
748 int rc;
749 char *sql;
750 int num = -1;
751
752 /* Open database */
753 pthread_mutex_lock(&s_qser_data_database_mutex);
754 rc = sqlite3_open(path, &apnDb);
755 if( rc )
756 {
757 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
758 pthread_mutex_unlock(&s_qser_data_database_mutex);
759 return 1;
760 }
xf.li7d256b62025-03-21 00:07:36 -0700761 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.li1bbfc7d2024-07-15 23:50:41 -0700762 /* Create SQL statement */
763 sql = "SELECT COUNT(*) FROM sqlite_master where type ='table' and name = 'LYNQAPN'";
764 /* Execute SQL statement */
765 rc = sqlite3_exec(apnDb, sql, check_apn_table_cb, &num, &zErrMsg);
766 if( rc != SQLITE_OK )
767 {
768 LYERRLOG("SQL error: %s\n", zErrMsg);
769 sqlite3_free(zErrMsg);
770 sqlite3_close(apnDb);
771 pthread_mutex_unlock(&s_qser_data_database_mutex);
772 return 1;
773 }
xf.li7d256b62025-03-21 00:07:36 -0700774 LYDBGLOG("Table LYNQAPN check successfully\n");
xf.li1bbfc7d2024-07-15 23:50:41 -0700775 sqlite3_close(apnDb);
776 pthread_mutex_unlock(&s_qser_data_database_mutex);
777 if(num <= 0)
778 {
779 LYINFLOG("No table LYNQAPN, num = %d\n", num);
780 return APN_TABLE_NEED_CREATE;
781 }
782 else
783 {
784 LYINFLOG("The table LYNQAPN exist, num = %d\n", num);
785 return APN_TABLE_CREATE;
786 }
787
788 return 0;
789}
xf.licb6cd282024-02-21 22:06:14 -0800790static int init_apn_db()
791{
792 int db_ret=0;
xf.li7d256b62025-03-21 00:07:36 -0700793 int ret = 0;
xf.li1bbfc7d2024-07-15 23:50:41 -0700794 int check_ret=0;
xf.licb6cd282024-02-21 22:06:14 -0800795 int table_ret=0;
xf.li87f6e6e2024-06-19 02:23:05 -0700796
797 pthread_mutex_init(&s_qser_data_database_mutex, NULL);
798
xf.licb6cd282024-02-21 22:06:14 -0800799 db_ret = create_apn_db(APN_DB_PATH);
800 if(db_ret==APN_DB_CREATE)
801 {
802 table_ret = create_apn_table(APN_DB_PATH);
803 if(table_ret!=0)
804 {
xf.li7d256b62025-03-21 00:07:36 -0700805 LYERRLOG("ret = %d, create apn table fail!!!", table_ret);
xf.licb6cd282024-02-21 22:06:14 -0800806 return RESULT_ERROR;
807 }
xf.li7d256b62025-03-21 00:07:36 -0700808 ret = apn_db_add(0, &default_apn);
809 if(ret != 0)
810 {
811 LYERRLOG("ret = %d, apn add fail!!!", ret);
812 }
xf.licb6cd282024-02-21 22:06:14 -0800813 }
814 else if(db_ret==APN_DB_READED)
815 {
xf.li1bbfc7d2024-07-15 23:50:41 -0700816 LYINFLOG("[%s] apn db has be build!!!",__FUNCTION__);
817 check_ret = check_apn_table(APN_DB_PATH);
818 if(check_ret == APN_TABLE_NEED_CREATE)
819 {
820 table_ret = create_apn_table(APN_DB_PATH);
821 if(table_ret!=0)
822 {
xf.li7d256b62025-03-21 00:07:36 -0700823 LYERRLOG("ret = %d, create apn table fail!!!", table_ret);
xf.li1bbfc7d2024-07-15 23:50:41 -0700824 return 1;
825 }
xf.li7d256b62025-03-21 00:07:36 -0700826 ret = apn_db_add(0, &default_apn);
827 if(ret != 0)
828 {
829 LYERRLOG("ret = %d, apn add fail!!!", ret);
830 }
xf.li1bbfc7d2024-07-15 23:50:41 -0700831 }
832 else if(check_ret == APN_TABLE_CREATE)
833 {
834 LYINFLOG("Table LYNQAPN has created");
835 }
836 else
837 {
838 LYERRLOG("check table fail!!!, ret = %d", check_ret);
839 }
xf.li0fd6acf2023-12-20 18:16:34 -0800840 }
841 else
842 {
xf.licb6cd282024-02-21 22:06:14 -0800843 LYERRLOG("init apn db fail!!!");
xf.li0fd6acf2023-12-20 18:16:34 -0800844 }
xf.li0fd6acf2023-12-20 18:16:34 -0800845 return RESULT_OK;
xf.li0fd6acf2023-12-20 18:16:34 -0800846}
xf.li2fc84552023-06-23 05:26:47 -0700847
xf.licb6cd282024-02-21 22:06:14 -0800848static int apn_db_handle_clean()
xf.li63b87e82024-01-04 00:43:35 -0800849{
xf.licb6cd282024-02-21 22:06:14 -0800850 char *zErrMsg = 0;
851 int rc;
xf.li63b87e82024-01-04 00:43:35 -0800852 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.liff415202024-09-19 23:08:09 -0700853 char sql[128]={0};
xf.li63b87e82024-01-04 00:43:35 -0800854
xf.licb6cd282024-02-21 22:06:14 -0800855 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700856 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800857 rc = sqlite3_open(APN_DB_PATH, &apnDb);
858 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800859 {
xf.licb6cd282024-02-21 22:06:14 -0800860 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700861 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800862 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800863 }
xf.licb6cd282024-02-21 22:06:14 -0800864
xf.li7d256b62025-03-21 00:07:36 -0700865 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -0800866 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700867 sprintf(sql,"UPDATE LYNQAPN SET HANDLE=%d", default_handle);
xf.licb6cd282024-02-21 22:06:14 -0800868 LYINFLOG("sql: %s\n", sql);
869 /* Execute SQL statement */
870 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
871 if( rc != SQLITE_OK )
xf.li63b87e82024-01-04 00:43:35 -0800872 {
xf.licb6cd282024-02-21 22:06:14 -0800873 LYERRLOG("SQL error: %s\n", zErrMsg);
874 sqlite3_free(zErrMsg);
875 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700876 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800877 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800878 }
xf.li7d256b62025-03-21 00:07:36 -0700879 LYDBGLOG("clean apn table successfully\n");
xf.licb6cd282024-02-21 22:06:14 -0800880 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700881 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800882 return RESULT_OK;
883}
884
885static int find_unuse_apn_index(char *path)
886{
887 char *zErrMsg = 0;
888 int rc;
889 int count =1;
890 bool apn_usable = false;
891 char *sql;
892
893 memset(apn_indexs,0,sizeof(apn_indexs));
894 next_index = 0;
xf.li7d256b62025-03-21 00:07:36 -0700895 LYDBGLOG("index = %p",apn_indexs);
xf.licb6cd282024-02-21 22:06:14 -0800896 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700897 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800898 rc = sqlite3_open(APN_DB_PATH, &apnDb);
899 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800900 {
xf.licb6cd282024-02-21 22:06:14 -0800901 LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700902 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800903 return -1;
xf.li63b87e82024-01-04 00:43:35 -0800904 }
905 else
906 {
xf.li7d256b62025-03-21 00:07:36 -0700907 LYDBGLOG("Opened database successfully\n");
xf.li63b87e82024-01-04 00:43:35 -0800908 }
xf.li63b87e82024-01-04 00:43:35 -0800909
xf.licb6cd282024-02-21 22:06:14 -0800910 /* Create SQL statement */
911 sql = "SELECT ID from LYNQAPN";
912 /* Execute SQL statement */
913 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg);
914 if( rc != SQLITE_OK )
915 {
916 LYERRLOG("SQL error: %s\n", zErrMsg);
917 sqlite3_free(zErrMsg);
xf.lib5d82bf2024-03-09 01:54:50 -0800918 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700919 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800920 return -1;
921 }
922 else
923 {
xf.li7d256b62025-03-21 00:07:36 -0700924 LYDBGLOG("Operation done successfully\n");
xf.licb6cd282024-02-21 22:06:14 -0800925 }
926 //indexs = temp_index;
xf.li7d256b62025-03-21 00:07:36 -0700927 LYDBGLOG("index = %p",apn_indexs);
xf.licb6cd282024-02-21 22:06:14 -0800928 for(count;count<=QSER_APN_MAX_LIST;count++)
929 {
930 //if(apn_indexs[count-1]!=count)
xf.li7d256b62025-03-21 00:07:36 -0700931 LYDBGLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count);
xf.licb6cd282024-02-21 22:06:14 -0800932 if(apn_indexs[count]!=count)
933 {
934 //apn_usable=true;
935 break;
936 }
937 }
938 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700939 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.li7d256b62025-03-21 00:07:36 -0700940 LYDBGLOG("count is %d\n", count);
xf.licb6cd282024-02-21 22:06:14 -0800941 return count;
xf.li63b87e82024-01-04 00:43:35 -0800942}
943
xf.licb6cd282024-02-21 22:06:14 -0800944static int apn_db_add(int profile_id, qser_apn_add_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700945{
xf.licb6cd282024-02-21 22:06:14 -0800946 char *zErrMsg = 0;
947 int rc;
xf.li0fd6acf2023-12-20 18:16:34 -0800948 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.licb6cd282024-02-21 22:06:14 -0800949 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700950 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800951 rc = sqlite3_open(APN_DB_PATH, &apnDb);
952 if( rc )
xf.li2fc84552023-06-23 05:26:47 -0700953 {
xf.licb6cd282024-02-21 22:06:14 -0800954 LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700955 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800956 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700957 }
xf.li7d256b62025-03-21 00:07:36 -0700958 LYDBGLOG("[%s] Opened database successfully",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -0800959 /* Create SQL statement */
960 /* Execute SQL statement */
961 LYINFLOG("the profile id is %d\n", profile_id);
962 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);
963 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
xf.liff415202024-09-19 23:08:09 -0700964 sqlite3_free(sql);
xf.licb6cd282024-02-21 22:06:14 -0800965 if( rc != SQLITE_OK )
xf.li2fc84552023-06-23 05:26:47 -0700966 {
xf.licb6cd282024-02-21 22:06:14 -0800967 LYERRLOG( "SQL error: %s", zErrMsg);
968 sqlite3_free(zErrMsg);
969 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700970 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800971 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700972 }
xf.li7d256b62025-03-21 00:07:36 -0700973 LYDBGLOG("write apn to apn db successfully");
xf.licb6cd282024-02-21 22:06:14 -0800974 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700975 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800976 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700977}
978
xf.licb6cd282024-02-21 22:06:14 -0800979static int apn_db_delete(unsigned char profile_idx)
xf.li2fc84552023-06-23 05:26:47 -0700980{
xf.licb6cd282024-02-21 22:06:14 -0800981 char *zErrMsg = 0;
982 int rc;
xf.liff415202024-09-19 23:08:09 -0700983 char sql[128]={0};
xf.li2fc84552023-06-23 05:26:47 -0700984
xf.licb6cd282024-02-21 22:06:14 -0800985 if(!lynq_check_index(profile_idx))
986 {
987 return LYNQ_E_APN_DB_FAIL;
988 }
989 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700990 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800991 rc = sqlite3_open(APN_DB_PATH, &apnDb);
992 if( rc )
993 {
994 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700995 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800996 return LYNQ_E_APN_DB_FAIL;
997 }
998
xf.li7d256b62025-03-21 00:07:36 -0700999 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -08001000 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001001 sprintf(sql,"DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -08001002 LYINFLOG("sql: %s\n", sql);
1003 /* Execute SQL statement */
1004 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
1005 if( rc != SQLITE_OK )
1006 {
1007 LYERRLOG("SQL error: %s\n", zErrMsg);
1008 sqlite3_free(zErrMsg);
1009 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001010 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001011 return LYNQ_E_APN_DB_FAIL;
1012 }
1013 LYINFLOG("delete apn %d successfully\n", profile_idx);
1014 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001015 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001016 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001017}
1018
xf.licb6cd282024-02-21 22:06:14 -08001019static int apn_db_modify(qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001020{
xf.licb6cd282024-02-21 22:06:14 -08001021 char *zErrMsg = 0;
1022 int rc;
xf.li2fc84552023-06-23 05:26:47 -07001023
xf.licb6cd282024-02-21 22:06:14 -08001024 if(!lynq_check_index(apn->profile_idx))
1025 {
1026 return LYNQ_E_APN_DB_FAIL;
1027 }
1028 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001029 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001030 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1031 if( rc )
1032 {
1033 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001034 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001035 return LYNQ_E_APN_DB_FAIL;
1036 }
1037
xf.li7d256b62025-03-21 00:07:36 -07001038 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -08001039 /* Create SQL statement */
1040 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);
1041 LYINFLOG("sql: %s\n", sql);
1042 /* Execute SQL statement */
1043 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
xf.liff415202024-09-19 23:08:09 -07001044 sqlite3_free(sql);
xf.licb6cd282024-02-21 22:06:14 -08001045 if( rc != SQLITE_OK )
1046 {
1047 LYERRLOG("SQL error: %s\n", zErrMsg);
1048 sqlite3_free(zErrMsg);
1049 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001050 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001051 return LYNQ_E_APN_DB_FAIL;
1052 }
1053 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1054 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001055 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001056 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001057}
1058
xf.licb6cd282024-02-21 22:06:14 -08001059static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName)
xf.li2fc84552023-06-23 05:26:47 -07001060{
xf.licb6cd282024-02-21 22:06:14 -08001061 if(data==NULL)
xf.li2fc84552023-06-23 05:26:47 -07001062 {
xf.licb6cd282024-02-21 22:06:14 -08001063 return 1;
xf.li2fc84552023-06-23 05:26:47 -07001064 }
xf.licb6cd282024-02-21 22:06:14 -08001065 qser_apn_info_s* temp = (qser_apn_info_s *)data;
1066 for(int i=0; i<argc; i++){
xf.li7d256b62025-03-21 00:07:36 -07001067 LYDBGLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001068 }
xf.licb6cd282024-02-21 22:06:14 -08001069 temp->profile_idx = atoi(argv[0]);
1070 temp->pdp_type = atoi(argv[1]);
1071 temp->auth_proto = atoi(argv[2]);
1072 memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE);
1073 memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE);
1074 memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE);
1075 memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE);
1076 LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0]));
1077 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001078}
xf.licb6cd282024-02-21 22:06:14 -08001079static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001080{
xf.licb6cd282024-02-21 22:06:14 -08001081 char *zErrMsg = 0;
1082 int rc;
xf.liff415202024-09-19 23:08:09 -07001083 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -08001084
1085 if(!lynq_check_index(profile_idx))
xf.li2fc84552023-06-23 05:26:47 -07001086 {
xf.licb6cd282024-02-21 22:06:14 -08001087 return LYNQ_E_APN_DB_FAIL;
1088 }
1089 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001090 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001091 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1092 if( rc )
1093 {
1094 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001095 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001096 return LYNQ_E_APN_DB_FAIL;
1097 }
1098
xf.li7d256b62025-03-21 00:07:36 -07001099 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -08001100 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001101 sprintf(sql,"SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -08001102 LYINFLOG("sql: %s\n", sql);
1103 /* Execute SQL statement */
1104 rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg);
1105 if( rc != SQLITE_OK )
1106 {
1107 LYERRLOG("SQL error: %s\n", zErrMsg);
1108 sqlite3_free(zErrMsg);
1109 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001110 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001111 return LYNQ_E_APN_DB_FAIL;
1112 }
xf.li7d256b62025-03-21 00:07:36 -07001113 LYDBGLOG("set apn %d successfully\n",apn->profile_idx);
xf.licb6cd282024-02-21 22:06:14 -08001114 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001115 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001116 return 0;
1117}
1118static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName)
1119{
1120 int i;
1121
1122 //apn_count++;
1123
1124 qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data;
1125 for(i=0; i<argc; i++){
xf.li7d256b62025-03-21 00:07:36 -07001126 LYDBGLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001127 }
1128
xf.licb6cd282024-02-21 22:06:14 -08001129 temp->apn[temp->cnt].profile_idx = atoi(argv[0]);
1130 temp->apn[temp->cnt].pdp_type = atoi(argv[1]);
1131 temp->apn[temp->cnt].auth_proto = atoi(argv[2]);
1132 memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE);
1133 memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE);
1134 memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE);
1135 memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE);
1136 temp->cnt++;
1137 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001138}
xf.licb6cd282024-02-21 22:06:14 -08001139static int apn_db_query_list(qser_apn_info_list_s *apn_list)
1140{
1141 char *zErrMsg = 0;
1142 int rc;
xf.liff415202024-09-19 23:08:09 -07001143 char sql[128]={0};
xf.li2fc84552023-06-23 05:26:47 -07001144
xf.licb6cd282024-02-21 22:06:14 -08001145 /* Open database */
1146 apn_count = 0;
1147 apn_list->cnt = 0;
xf.li87f6e6e2024-06-19 02:23:05 -07001148 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001149 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1150 if( rc )
1151 {
1152 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001153 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001154 return LYNQ_E_APN_DB_FAIL;
1155 }
1156
xf.li7d256b62025-03-21 00:07:36 -07001157 LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__);
xf.licb6cd282024-02-21 22:06:14 -08001158 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001159 sprintf(sql,"SELECT * from LYNQAPN");
xf.licb6cd282024-02-21 22:06:14 -08001160 LYINFLOG("sql: %s\n", sql);
1161 /* Execute SQL statement */
1162 rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg);
1163 if( rc != SQLITE_OK )
1164 {
1165 LYERRLOG("SQL error: %s\n", zErrMsg);
1166 sqlite3_free(zErrMsg);
1167 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001168 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001169 return LYNQ_E_APN_DB_FAIL;
1170 }
1171 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001172 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001173 return 0;
1174}
1175// **************apn DB end****************************
xf.li2fc84552023-06-23 05:26:47 -07001176void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
1177{
1178 switch (pdp_type)
1179 {
1180 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -08001181#ifdef MOBILETEK_TARGET_PLATFORM_T106
1182 strcpy(out_pdp_type,"IP");
1183#else
xf.li2fc84552023-06-23 05:26:47 -07001184 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -08001185#endif
xf.li2fc84552023-06-23 05:26:47 -07001186 break;
1187 case QSER_APN_PDP_TYPE_PPP:
1188 strcpy(out_pdp_type,"PPP");
1189 break;
1190 case QSER_APN_PDP_TYPE_IPV6:
1191 strcpy(out_pdp_type,"IPV6");
1192 break;
1193 case QSER_APN_PDP_TYPE_IPV4V6:
1194 strcpy(out_pdp_type,"IPV4V6");
1195 break;
1196 default:
1197 strcpy(out_pdp_type,"NULL");
1198 break;
1199 }
1200 return;
1201}
1202void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
1203{
1204 switch (auth_proto)
1205 {
1206 case QSER_APN_AUTH_PROTO_DEFAULT:
xf.lifb6134e2024-05-09 01:26:54 -07001207 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001208 break;
1209 case QSER_APN_AUTH_PROTO_NONE:
xf.lifb6134e2024-05-09 01:26:54 -07001210 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001211 break;
1212 case QSER_APN_AUTH_PROTO_PAP:
xf.lifb6134e2024-05-09 01:26:54 -07001213 strcpy(out_proto,"1");
xf.li2fc84552023-06-23 05:26:47 -07001214 break;
1215 case QSER_APN_AUTH_PROTO_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001216 strcpy(out_proto,"2");
xf.li2fc84552023-06-23 05:26:47 -07001217 break;
1218 case QSER_APN_AUTH_PROTO_PAP_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001219 strcpy(out_proto,"3");
xf.li2fc84552023-06-23 05:26:47 -07001220 break;
1221 default:
xf.lifb6134e2024-05-09 01:26:54 -07001222 strcpy(out_proto,"NULL");
xf.li2fc84552023-06-23 05:26:47 -07001223 break;
1224 }
1225 return ;
1226}
1227
1228int data_call_handle_get(const char profile_idx,int *handle)
1229{
1230 int num = LYNQ_APN_CHANNEL_MAX;
1231 int table_num = 0;
1232 lynq_apn_info **apn_table = NULL;
1233 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001234 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001235 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1236 if (NULL == apn_table)
1237 {
1238 LYERRLOG("malloc apn_table fail ");
1239 return RESULT_ERROR;
1240 }
1241 for(int i =0;i<10;i++)
1242 {
1243 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1244 if (apn_table[i]==NULL)
1245 {
1246 for (int n=0;n<i;n++)
1247 {
1248 free(apn_table[n]);
1249 }
1250 return RESULT_ERROR;
1251 }
1252 memset(apn_table[i],0,sizeof(lynq_apn_info));
1253 }
1254 lynq_get_apn_table(&table_num,apn_table);
1255 memset(&apn,0,sizeof(qser_apn_info_s));
xf.licb6cd282024-02-21 22:06:14 -08001256 ret = apn_db_query(profile_idx,&apn);
xf.li0fc26502023-09-16 02:10:17 -07001257 if (ret < 0)
1258 {
xf.licb6cd282024-02-21 22:06:14 -08001259 LYERRLOG("apn_db_query error");
xf.li0fc26502023-09-16 02:10:17 -07001260 return ret;
1261 }
xf.li2fc84552023-06-23 05:26:47 -07001262 for (int j = 0;j < table_num;j++)
1263 {
1264 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1265 {
1266 *handle = apn_table[j]->index;
1267 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1268 break;
1269 }
1270 }
1271
1272 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1273 {
1274 if (apn_table[i]!=NULL)
1275 {
1276 free(apn_table[i]);
1277 apn_table[i]=NULL;
1278 }
1279 }
1280 free(apn_table);
1281 apn_table=NULL;
xf.li7d256b62025-03-21 00:07:36 -07001282 LYDBGLOG("data_call_handle_get end");
xf.li2fc84552023-06-23 05:26:47 -07001283 return RESULT_OK;
1284}
1285
xf.li789f7a12024-10-24 03:02:37 -07001286static void acquire_wake_lock()
1287{
1288 int ret = 0;
1289
1290 ret = system("echo data_call_wakelock 5000000000 > /sys/power/wake_lock");//timeout 5s
1291 if(ret != 0)
1292 {
1293 LYERRLOG("acquire_wake_lock error !!!");
1294 }
1295 return;
1296}
1297
1298static void release_wake_lock()
1299{
1300 int ret = 0;
1301
1302 ret = system("echo data_call_wakelock > /sys/power/wake_unlock");
1303 if(ret != 0)
1304 {
1305 LYERRLOG("release_wake_lock error !!!");
1306 }
1307 return;
1308}
1309
xf.li2fc84552023-06-23 05:26:47 -07001310void *thread_wait_cb_status(void)
1311{
1312 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001313 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001314 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001315 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001316 qser_data_call_state_s data_cb_state;
1317 while (s_qser_data_cb_thread_status)
1318 {
xf.li6b0d8502023-09-04 18:49:12 -07001319 ret = lynq_wait_data_call_state_change(&handle);
xf.li7d256b62025-03-21 00:07:36 -07001320 LYINFLOG("[thread_wait_cb_status]: ret = %d, handle = %d, wait data call state change end!!!\n", ret, handle);
xf.li6b0d8502023-09-04 18:49:12 -07001321 if(s_qser_data_cb_thread_status == 0)
1322 {
1323 return NULL;
1324 }
1325 else if(ret < 0)
1326 {
1327 continue;
1328 }
xf.li789f7a12024-10-24 03:02:37 -07001329 acquire_wake_lock();
xf.li7d256b62025-03-21 00:07:36 -07001330 //LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
xf.li8535bc02023-12-12 23:28:35 -08001331 memset(&data_urc_info, 0, sizeof(data_urc_info));
1332 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001333 lynq_get_data_call_list(&handle,&data_urc_info);
1334 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001335 //data_cb_state.profile_idx = (char)handle;
xf.licb6cd282024-02-21 22:06:14 -08001336 apn_db_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li7d256b62025-03-21 00:07:36 -07001337 LYINFLOG("[thread_wait_cb_status]: callback profile_idx is %d, status=%d, suggestedRetryTime=%d, cid=%d, active=%d, type=%s, ifname=%s, \n",
1338 data_cb_state.profile_idx, data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active, data_urc_info.type, data_urc_info.ifname);
1339
1340 LYINFLOG("[thread_wait_cb_status]: addresses=%s, dnses=%s, gateways=%s, pcscf=%s, mtu=%d\n",
1341 data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf, data_urc_info.mtu);
1342
xf.li2fc84552023-06-23 05:26:47 -07001343 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001344 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001345 {
1346 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1347 }
1348 else if (!strcmp(data_urc_info.type,"IPV6"))
1349 {
1350 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1351 }
xf.li8535bc02023-12-12 23:28:35 -08001352 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001353 {
1354 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1355 }
1356 else
1357 {
xf.li8535bc02023-12-12 23:28:35 -08001358 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001359 }
1360
xf.li8535bc02023-12-12 23:28:35 -08001361 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001362 {
1363 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1364 }
1365 else
1366 {
1367 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.licb6cd282024-02-21 22:06:14 -08001368 ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001369 if(ret != 0)
1370 {
1371 LYERRLOG("handle set error");
1372 }
xf.li2fc84552023-06-23 05:26:47 -07001373 }
1374 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1375 {
1376 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1377 }
1378 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1379 {
1380 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1381 }
1382 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1383 {
xf.li3c0a4752023-09-03 20:46:19 -07001384#ifdef MOBILETEK_TARGET_PLATFORM_T106
1385 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1386#else
xf.li2fc84552023-06-23 05:26:47 -07001387 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001388#endif
xf.li2fc84552023-06-23 05:26:47 -07001389 }
1390 else
1391 {
xf.li789f7a12024-10-24 03:02:37 -07001392 release_wake_lock();
xf.li2fc84552023-06-23 05:26:47 -07001393 LYERRLOG("unknow ip_family");
1394 continue;
1395 }
1396 if (s_data_call_cb != NULL)
1397 {
xf.li789f7a12024-10-24 03:02:37 -07001398 s_data_call_cb(&data_cb_state);
1399 release_wake_lock();
1400 LYINFLOG("[%s] call back s_data_call_cb end", __FUNCTION__);
xf.li2fc84552023-06-23 05:26:47 -07001401 }
1402 }
1403 return NULL;
1404}
1405
1406int qser_cb_pthread_create()
1407{
xf.lib5d82bf2024-03-09 01:54:50 -08001408 pthread_attr_t attr;
xf.li2fc84552023-06-23 05:26:47 -07001409 int ret;
1410 s_qser_data_cb_thread_status = 1;
xf.lib5d82bf2024-03-09 01:54:50 -08001411
1412 pthread_attr_init(&attr);
1413 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1414
1415 ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL);
xf.li2fc84552023-06-23 05:26:47 -07001416 if (ret < 0)
1417 {
1418 LYERRLOG("pthread create fail");
1419 s_qser_data_cb_thread_status = 0;
1420 return RESULT_ERROR;
1421 }
xf.lib5d82bf2024-03-09 01:54:50 -08001422 pthread_attr_destroy(&attr);
xf.li2fc84552023-06-23 05:26:47 -07001423 return RESULT_OK;
1424}
1425
1426void qser_cb_pthread_cancel()
1427{
xf.li2fc84552023-06-23 05:26:47 -07001428 s_qser_data_cb_thread_status = 0;
1429 if (s_cb_tid != -1)
1430 {
xf.li6b0d8502023-09-04 18:49:12 -07001431 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001432 }
1433 return;
1434}
xf.li2fc84552023-06-23 05:26:47 -07001435int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1436{
1437 int ret = 0;
1438 int utoken = 0;
1439 if (NULL == evt_cb)
1440 {
1441 LYERRLOG("init incoming paramters error");
1442 return RESULT_ERROR;
1443 }
xf.li09b46db2024-03-13 19:21:18 -07001444 if(g_lynq_qser_data_init_flag == 1)
1445 {
1446 LYERRLOG("init twice is not allowed");
1447 return RESULT_ERROR;
1448 }
xf.li2fc84552023-06-23 05:26:47 -07001449 ret = lynq_init_data(utoken);
1450 if (ret != RESULT_OK)
1451 {
xf.li6b0d8502023-09-04 18:49:12 -07001452 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001453 s_data_call_cb = NULL;
1454 return RESULT_ERROR;
1455 }
xf.li6b0d8502023-09-04 18:49:12 -07001456 qser_cb_pthread_create();
xf.licb6cd282024-02-21 22:06:14 -08001457 ret = init_apn_db();
1458 if(ret != RESULT_OK)
xf.lie3f55f42023-12-01 22:47:33 -08001459 {
xf.licb6cd282024-02-21 22:06:14 -08001460 LYERRLOG("init apn db error");
xf.lie3f55f42023-12-01 22:47:33 -08001461 return RESULT_ERROR;
1462 }
xf.licb6cd282024-02-21 22:06:14 -08001463
1464 ret = apn_db_handle_clean();
xf.li63b87e82024-01-04 00:43:35 -08001465 if(ret != RESULT_OK)
1466 {
1467 LYERRLOG("clean handle error");
1468 return RESULT_ERROR;
1469 }
xf.li09b46db2024-03-13 19:21:18 -07001470 s_data_call_cb = evt_cb;
xf.lib33d4862023-12-13 00:40:37 -08001471 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001472 return RESULT_OK;
1473}
1474
1475void qser_data_call_destroy(void)
1476{
xf.li6b0d8502023-09-04 18:49:12 -07001477 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001478 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001479 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001480 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001481 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001482 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001483 return ;
1484}
1485
1486int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1487{
1488 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001489 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001490 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001491 if(g_lynq_qser_data_init_flag == 0)
1492 {
1493 if(err != NULL)
1494 {
1495 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1496 }
1497 return LYNQ_E_NO_INIT;
1498 }
xf.li2fc84552023-06-23 05:26:47 -07001499 if (NULL == data_call || NULL == err)
1500 {
1501 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001502 if(err != NULL)
1503 {
1504 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1505 }
xf.li2fc84552023-06-23 05:26:47 -07001506 return ret;
1507 }
1508 if (data_call->profile_idx == 0)
1509 {
1510 ret = lynq_setup_data_call(&handle);
1511 }
1512 else
1513 {
1514 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001515 char auth_proto[16];
xf.li2fc84552023-06-23 05:26:47 -07001516 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001517 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1518 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li0fc26502023-09-16 02:10:17 -07001519 if (ret != 0)
1520 {
1521 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001522 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001523 return ret;
1524 }
xf.li2fc84552023-06-23 05:26:47 -07001525 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001526 judge_authtype(apn_info.auth_proto,auth_proto);
1527 ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,auth_proto,pdptype,pdptype);
xf.li2fc84552023-06-23 05:26:47 -07001528 }
xf.lic12b3702023-11-22 22:39:01 -08001529 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001530 {
1531 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1532 }
xf.li0fd6acf2023-12-20 18:16:34 -08001533 else
1534 {
xf.licb6cd282024-02-21 22:06:14 -08001535 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001536 if(error != 0)
1537 {
1538 LYERRLOG("handle set error");
1539 }
1540 }
xf.li2fc84552023-06-23 05:26:47 -07001541 return ret;
1542}
1543
xf.li8535bc02023-12-12 23:28:35 -08001544int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1545{
1546 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001547 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001548 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001549 if(g_lynq_qser_data_init_flag == 0)
1550 {
1551 if(err != NULL)
1552 {
1553 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1554 }
1555 return LYNQ_E_NO_INIT;
1556 }
xf.li8535bc02023-12-12 23:28:35 -08001557 if (NULL == data_call || NULL == err)
1558 {
1559 LYERRLOG("call start incoming paramters error");
1560 if(err != NULL)
1561 {
1562 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1563 }
1564 return ret;
1565 }
1566 if (data_call->profile_idx == 0)
1567 {
1568 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1569 }
1570 else
1571 {
1572 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001573 char auth_proto[16];
xf.li8535bc02023-12-12 23:28:35 -08001574 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001575 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1576 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li8535bc02023-12-12 23:28:35 -08001577 if (ret != 0)
1578 {
1579 LYERRLOG("qser_apn_get error");
1580 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1581 return ret;
1582 }
1583 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001584 judge_authtype(apn_info.auth_proto,auth_proto);
1585 ret = lynq_setup_data_call_sp_t106_async(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,auth_proto,pdptype,pdptype);
xf.li8535bc02023-12-12 23:28:35 -08001586 }
1587 if (ret != 0)
1588 {
1589 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1590 }
xf.li0fd6acf2023-12-20 18:16:34 -08001591 else
1592 {
xf.licb6cd282024-02-21 22:06:14 -08001593 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001594 if(error != 0)
1595 {
1596 LYERRLOG("handle set error");
1597 }
1598 }
xf.li8535bc02023-12-12 23:28:35 -08001599 return ret;
1600}
1601
xf.li2fc84552023-06-23 05:26:47 -07001602int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1603{
1604 int ret = 0;
1605 int handle = -1;
1606
xf.lib33d4862023-12-13 00:40:37 -08001607 if(g_lynq_qser_data_init_flag == 0)
1608 {
1609 if(err != NULL)
1610 {
1611 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1612 }
1613 return LYNQ_E_NO_INIT;
1614 }
xf.li2fc84552023-06-23 05:26:47 -07001615 if (NULL == err)
1616 {
1617 LYERRLOG("call stop incoming paramters error");
1618 return ret;
1619 }
xf.lic12b3702023-11-22 22:39:01 -08001620 ret = data_call_handle_get(profile_idx,&handle);
1621 if(ret != 0)
1622 {
1623 LYERRLOG("datacall handle get error");
1624 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1625 return ret;
1626 }
xf.li2fc84552023-06-23 05:26:47 -07001627 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001628 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001629 {
1630 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001631 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001632 }
xy.hee2daacc2023-09-18 00:57:51 -07001633 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001634}
1635int 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)
1636{
1637 int ret = 0;
1638 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001639 if(g_lynq_qser_data_init_flag == 0)
1640 {
1641 if(err != NULL)
1642 {
1643 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1644 }
1645 return LYNQ_E_NO_INIT;
1646 }
xf.li4ab455d2024-07-30 01:21:56 -07001647 lynq_data_call_response_v11_t data_call_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001648 data_call_handle_get(profile_idx,&handle);
1649 ret = lynq_get_data_call_list(&handle,&data_call_info);
1650 if (ret == 0)
1651 {
1652 info->profile_idx = profile_idx;
1653 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001654 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 -07001655 {
xf.li0400b382024-06-05 19:20:36 -07001656 info->ip_family = QSER_DATA_CALL_TYPE_IPV4;
xf.li2fc84552023-06-23 05:26:47 -07001657 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001658 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li7d256b62025-03-21 00:07:36 -07001659 LYDBGLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
xf.li2fc84552023-06-23 05:26:47 -07001660 lynq_ipv4_aton_getinfo(&data_call_info,info);
1661 }
xf.li3c0a4752023-09-03 20:46:19 -07001662 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001663 {
xf.li0400b382024-06-05 19:20:36 -07001664 info->ip_family = QSER_DATA_CALL_TYPE_IPV6;
xf.li2fc84552023-06-23 05:26:47 -07001665 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001666 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li7d256b62025-03-21 00:07:36 -07001667 LYDBGLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
xf.li2fc84552023-06-23 05:26:47 -07001668 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1669 }
xf.li3c0a4752023-09-03 20:46:19 -07001670 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001671 {
xf.li0400b382024-06-05 19:20:36 -07001672 info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
xf.li2fc84552023-06-23 05:26:47 -07001673 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001674 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li7d256b62025-03-21 00:07:36 -07001675 LYDBGLOG("[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 -07001676#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001677 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001678#endif
xf.li2fc84552023-06-23 05:26:47 -07001679 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001680 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li7d256b62025-03-21 00:07:36 -07001681 LYDBGLOG("[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 -07001682#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001683 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001684#endif
1685#ifdef MOBILETEK_TARGET_PLATFORM_T106
1686 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1687#endif
xf.li2fc84552023-06-23 05:26:47 -07001688 }
1689 else
1690 {
1691 LYERRLOG("useless qser_data_call_ip_family_e");
1692 }
1693 }
1694 return ret;
1695}
xf.li7aca5c02025-01-02 02:48:47 -08001696#ifdef MOBILETEK_TARGET_PLATFORM_T106
1697int qser_set_initial_apnname(char *apnname)
1698{
1699 int ret = -1;
1700
1701 if(g_lynq_qser_data_init_flag == 0)
1702 {
1703 return LYNQ_E_NO_INIT;
1704 }
1705
1706 ret = lynq_init_attach_apn(apnname, "IP", "0", "null", "null");
1707 return ret;
1708}
1709int qser_get_initial_apnname(char apnname[QSER_APN_NAME_SIZE])
1710{
1711 int ret = -1;
1712 lynq_apn_list_response apnList = {-1, "", "", "", -1, -1, -1, -1, -1, -1};
1713
1714 if(g_lynq_qser_data_init_flag == 0)
1715 {
1716 return LYNQ_E_NO_INIT;
1717 }
1718
1719 if(apnname == NULL)
1720 {
1721 LYERRLOG("[%s][%d] apnname is NULL",__FUNCTION__,__LINE__);
1722 }
1723 ret = lynq_get_apn_list(1, &apnList);
1724 if(ret == 0)
1725 {
1726 memcpy(apnname, apnList.apn, sizeof(apnList.apn));
1727 LYINFLOG("qser_get_initial_apnname: %s", apnname);
1728 }
1729 return ret;
1730}
1731#endif
xf.lifb6134e2024-05-09 01:26:54 -07001732int check_pdp_type(qser_apn_pdp_type_e pdp_type)
1733{
1734 switch (pdp_type)
1735 {
1736 case QSER_APN_PDP_TYPE_IPV4:
1737 case QSER_APN_PDP_TYPE_PPP:
1738 case QSER_APN_PDP_TYPE_IPV6:
1739 case QSER_APN_PDP_TYPE_IPV4V6:
1740 return 0;
1741 default:
1742 return -1;
1743 }
1744}
1745int check_auth_proto(qser_apn_auth_proto_e auth_proto)
1746{
1747 switch (auth_proto)
1748 {
1749 case QSER_APN_AUTH_PROTO_DEFAULT:
1750 case QSER_APN_AUTH_PROTO_NONE:
1751 case QSER_APN_AUTH_PROTO_PAP:
1752 case QSER_APN_AUTH_PROTO_CHAP:
1753 case QSER_APN_AUTH_PROTO_PAP_CHAP:
1754 return 0;
1755 default:
1756 return -1;
1757 }
1758}
xf.li2fc84552023-06-23 05:26:47 -07001759int qser_apn_set(qser_apn_info_s *apn)
1760{
1761 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001762 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001763 if(g_lynq_qser_data_init_flag == 0)
1764 {
1765 return LYNQ_E_NO_INIT;
1766 }
xf.li4b18fa62023-12-19 19:38:10 -08001767 if (NULL == apn || apn->profile_idx == 0)
xf.li2fc84552023-06-23 05:26:47 -07001768 {
1769 LYERRLOG("apn set incoming paramters error");
1770 return RESULT_ERROR;
1771 }
xf.licb6cd282024-02-21 22:06:14 -08001772 ret = apn_db_handle_get(apn->profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001773 if(ret != 0)
1774 {
1775 LYERRLOG("handle set error");
1776 }
1777 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1778 {
1779 LYERRLOG("It has setup datacall");
1780 return RESULT_ERROR;
1781 }
xf.lifb6134e2024-05-09 01:26:54 -07001782
1783 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1784 {
1785 LYERRLOG("apn_name out of range\n");
1786 return RESULT_ERROR;
1787 }
1788 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1789 {
1790 LYERRLOG("username out of range\n");
1791 return RESULT_ERROR;
1792 }
1793 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1794 {
1795 LYERRLOG("password out of range\n");
1796 return RESULT_ERROR;
1797 }
1798 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1799 {
1800 LYERRLOG("apn_type out of range\n");
1801 return RESULT_ERROR;
1802 }
1803 if(check_pdp_type(apn->pdp_type) != 0)
1804 {
1805 LYERRLOG("pdp_type out of range\n");
1806 return RESULT_ERROR;
1807 }
1808 if(check_auth_proto(apn->auth_proto) != 0)
1809 {
1810 LYERRLOG("auth_proto out of range\n");
1811 return RESULT_ERROR;
1812 }
1813
xf.licb6cd282024-02-21 22:06:14 -08001814 ret = apn_db_modify(apn);
xf.li2fc84552023-06-23 05:26:47 -07001815 if (ret < 0)
1816 {
xf.licb6cd282024-02-21 22:06:14 -08001817 LYERRLOG("apn_db_modify error");
xf.li2fc84552023-06-23 05:26:47 -07001818 return ret;
1819 }
xf.li6c7e3972023-10-27 20:01:59 -07001820#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001821 int apn_id = 0;
1822 char tmp_id[12];
1823 char *outinfo = NULL;
1824 char normalprotocol[16];
1825 char authtype[32];
1826 outinfo = (char *)malloc(sizeof(char)*512);
1827 bzero(tmp_id,12);
1828 bzero(outinfo,512);
1829 apn_id = apn->profile_idx + apndb_offset;
1830 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1831 judge_pdp_type(apn->pdp_type,normalprotocol);
1832 judge_authtype(apn->auth_proto,authtype);
1833 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1834 LYINFLOG("[output]:%s",outinfo);
1835 free(outinfo);
1836 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001837#endif
1838 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001839}
1840
1841int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1842{
xf.lib33d4862023-12-13 00:40:37 -08001843 if(g_lynq_qser_data_init_flag == 0)
1844 {
1845 return LYNQ_E_NO_INIT;
1846 }
xf.licb6cd282024-02-21 22:06:14 -08001847 if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn)
xf.li2fc84552023-06-23 05:26:47 -07001848 {
1849 LYERRLOG("apn get incoming paramters error");
1850 return RESULT_ERROR;
1851 }
1852 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001853 ret = apn_db_query(profile_idx,apn);
xf.li2fc84552023-06-23 05:26:47 -07001854 if (ret < 0)
1855 {
xf.licb6cd282024-02-21 22:06:14 -08001856 LYERRLOG("apn_db_query error");
xf.li2fc84552023-06-23 05:26:47 -07001857 return ret;
1858 }
1859 return ret;
1860}
1861
1862int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1863{
1864 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001865
xf.lib33d4862023-12-13 00:40:37 -08001866 if(g_lynq_qser_data_init_flag == 0)
1867 {
1868 return LYNQ_E_NO_INIT;
1869 }
xf.li2fc84552023-06-23 05:26:47 -07001870 if (NULL == apn || NULL == profile_idx)
1871 {
1872 LYERRLOG("apn add incoming paramters error");
1873 return RESULT_ERROR;
1874 }
xf.lifb6134e2024-05-09 01:26:54 -07001875
1876 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1877 {
1878 LYERRLOG("apn_name out of range\n");
1879 return RESULT_ERROR;
1880 }
1881 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1882 {
1883 LYERRLOG("username out of range\n");
1884 return RESULT_ERROR;
1885 }
1886 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1887 {
1888 LYERRLOG("password out of range\n");
1889 return RESULT_ERROR;
1890 }
1891 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1892 {
1893 LYERRLOG("apn_type out of range\n");
1894 return RESULT_ERROR;
1895 }
1896 if(check_pdp_type(apn->pdp_type) != 0)
1897 {
1898 LYERRLOG("pdp_type out of range\n");
1899 return RESULT_ERROR;
1900 }
1901 if(check_auth_proto(apn->auth_proto) != 0)
1902 {
1903 LYERRLOG("auth_proto out of range\n");
1904 return RESULT_ERROR;
1905 }
xf.licb6cd282024-02-21 22:06:14 -08001906
1907 *profile_idx = 0;
1908 *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH);
1909 LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx);
1910 if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001911 {
xf.licb6cd282024-02-21 22:06:14 -08001912 LYINFLOG("[%s] apn full is false\n",__FUNCTION__);
1913 ret = apn_db_add((int)*profile_idx, apn);
1914 if (ret != 0)
1915 {
1916 LYERRLOG("apn_db_add error");
1917 return RESULT_ERROR;
1918 }
1919 else
1920 {
1921 return RESULT_OK;
1922 }
xf.li2fc84552023-06-23 05:26:47 -07001923 }
xf.licb6cd282024-02-21 22:06:14 -08001924 LYERRLOG("apn storage space is full!!!");
1925 return RESULT_ERROR;
xf.li6c7e3972023-10-27 20:01:59 -07001926#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001927 int apn_id = 0;
1928 char tmp_id[12];
1929 char *outinfo = NULL;
1930 char normalprotocol[16];
1931 char authtype[32];
1932 outinfo = (char *)malloc(sizeof(char)*512);
1933 bzero(tmp_id,12);
1934 bzero(outinfo,512);
1935 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1936 judge_pdp_type(apn->pdp_type,normalprotocol);
1937 judge_authtype(apn->auth_proto,authtype);
1938 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1939 LYINFLOG("[output]:%s",outinfo);
1940 free(outinfo);
1941 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001942#endif
1943 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001944}
1945
1946int qser_apn_del(unsigned char profile_idx)
1947{
xf.li87f6e6e2024-06-19 02:23:05 -07001948 int ret = 0;
1949 int handle = -1;
1950
xf.li7d256b62025-03-21 00:07:36 -07001951 LYDBGLOG("[%s] entry\n",__FUNCTION__);
xf.lib33d4862023-12-13 00:40:37 -08001952 if(g_lynq_qser_data_init_flag == 0)
1953 {
xf.li7d256b62025-03-21 00:07:36 -07001954 LYERRLOG("lynq qser data uninit");
xf.lib33d4862023-12-13 00:40:37 -08001955 return LYNQ_E_NO_INIT;
1956 }
xf.li4b18fa62023-12-19 19:38:10 -08001957 if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001958 {
1959 LYERRLOG("apn del incoming paramters error");
xf.li4b18fa62023-12-19 19:38:10 -08001960 return RESULT_ERROR;
xf.li2fc84552023-06-23 05:26:47 -07001961 }
xf.li87f6e6e2024-06-19 02:23:05 -07001962
xf.licb6cd282024-02-21 22:06:14 -08001963 ret = apn_db_handle_get(profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001964 if(ret != 0)
1965 {
1966 LYERRLOG("handle set error");
1967 }
1968 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1969 {
1970 LYERRLOG("It has setup datacall");
1971 return RESULT_ERROR;
1972 }
xf.licb6cd282024-02-21 22:06:14 -08001973 ret = apn_db_delete(profile_idx);
xf.li2fc84552023-06-23 05:26:47 -07001974 if (ret < 0)
1975 {
xf.licb6cd282024-02-21 22:06:14 -08001976 LYERRLOG("apn_db_delete error");
xf.li2fc84552023-06-23 05:26:47 -07001977 return ret;
1978 }
xf.li6c7e3972023-10-27 20:01:59 -07001979#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001980 int apn_id = 0;
1981 char tmp_id[12];
1982 char *outinfo = NULL;
1983 outinfo = (char *)malloc(sizeof(char)*512);
1984 bzero(tmp_id,12);
1985 bzero(outinfo,512);
1986 apn_id = profile_idx+apndb_offset;
1987 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1988 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1989 LYINFLOG("[output]:%s",outinfo);
1990 free(outinfo);
1991 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001992#endif
xf.li2fc84552023-06-23 05:26:47 -07001993 return ret;
1994}
1995
1996int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1997{
xf.lib33d4862023-12-13 00:40:37 -08001998 if(g_lynq_qser_data_init_flag == 0)
1999 {
xf.li7d256b62025-03-21 00:07:36 -07002000 LYERRLOG("lynq qser data uninit");
xf.lib33d4862023-12-13 00:40:37 -08002001 return LYNQ_E_NO_INIT;
2002 }
xf.li2fc84552023-06-23 05:26:47 -07002003 if (NULL == apn_list)
2004 {
2005 LYERRLOG("apn_list incoming paramters error");
2006 return RESULT_ERROR;
2007 }
2008 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08002009 ret = apn_db_query_list(apn_list);
xf.li2fc84552023-06-23 05:26:47 -07002010 if (ret < 0)
2011 {
xf.licb6cd282024-02-21 22:06:14 -08002012 LYERRLOG("apn_db_query_list error");
xf.li2fc84552023-06-23 05:26:47 -07002013 return ret;
2014 }
2015 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07002016}
you.chen21c62b72023-09-08 09:41:11 +08002017
2018DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
2019