blob: 179e5496e7b4c3d92704f3fdf814e6e74f07bfb1 [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);
68
xf.li2fc84552023-06-23 05:26:47 -070069void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
70{
xf.li3c0a4752023-09-03 20:46:19 -070071#ifdef MOBILETEK_TARGET_PLATFORM_T106
72 char *tmp_char = NULL;
73 char *addresses = NULL;
74 char *dnses = NULL;
75 const char addresses_separator[2] = "/";
76 const char dnses_separator[2] = " ";
77
78 addresses = libdata->addresses;
79 dnses = libdata->dnses;
80 //get addresses
81 tmp_char = strsep(&addresses, addresses_separator);
82 if(tmp_char != NULL)
83 {
84 LYINFLOG("ipv4 addresses = %s", tmp_char);
85 inet_aton(tmp_char,&(data_res->v4.ip));
86 }
87
88 //get dnses
89 tmp_char = strsep(&dnses, dnses_separator);
90 if(tmp_char != NULL)
91 {
92 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
93 inet_aton(tmp_char,&(data_res->v4.pri_dns));
94 }
95 tmp_char = strsep(&dnses, dnses_separator);
96 if(tmp_char != NULL)
97 {
98 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
99 inet_aton(tmp_char, &(data_res->v4.sec_dns));
100 }
101 //get gateway
102 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
103
104#else
xf.li2fc84552023-06-23 05:26:47 -0700105 inet_aton(libdata->addresses,&(data_res->v4.ip));
106 inet_aton(libdata->gateways,&(data_res->v4.gateway));
107 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
108 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700109#endif
xf.li2fc84552023-06-23 05:26:47 -0700110 return ;
111}
112
113void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
114{
xf.li3c0a4752023-09-03 20:46:19 -0700115#ifdef MOBILETEK_TARGET_PLATFORM_T106
116 char *tmp_char = NULL;
117 char *addresses = NULL;
118 char *dnses = NULL;
119 const char addresses_separator[2] = "/";
120 const char dnses_separator[2] = " ";
121
122 addresses = libdata->addresses;
123 dnses = libdata->dnses;
124 //get addresses
125 tmp_char = strsep(&addresses, addresses_separator);
126 if(tmp_char != NULL)
127 {
128 LYINFLOG("ipv6 addresses = %s", tmp_char);
129 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
130 }
131 //get dnses
132 tmp_char = strsep(&dnses, dnses_separator);
133 if(tmp_char != NULL)
134 {
135 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
136 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
137 }
138 tmp_char = strsep(&dnses, dnses_separator);
139 if(tmp_char != NULL)
140 {
141 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
142 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
143 }
144 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
145#else
xf.li2fc84552023-06-23 05:26:47 -0700146 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
147 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
148 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
149 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700150#endif
151
152 return ;
153}
154
155void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
156{
157 char *tmp_char = NULL;
158 char *addresses = NULL;
159 char *dnses = NULL;
160 const char addresses_separator[2] = "/";
161 const char dnses_separator[2] = " ";
162
xf.li03baf1f2023-12-19 21:30:38 -0800163 char buf_ip[64] = {0};
164 char buf_gateway[64] = {0};
165 char buf_pri_dns[64] = {0};
166 char buf_sec_dns[64] = {0};
167
xf.li3c0a4752023-09-03 20:46:19 -0700168 addresses = libdata->addresses;
169 dnses = libdata->dnses;
170 //get addresses
171 tmp_char = strsep(&addresses, addresses_separator);
172 if(tmp_char != NULL)
173 {
174 LYINFLOG("ipv4 addresses = %s", tmp_char);
175 inet_aton(tmp_char,&(data_res->v4.ip));
176 }
177 tmp_char = strsep(&addresses, addresses_separator);
178 if(tmp_char != NULL)
179 {
180 LYINFLOG("ipv6 addresses = %s", tmp_char);
181 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
182 }
183 //get dnses
184 tmp_char = strsep(&dnses, dnses_separator);
185 if(tmp_char != NULL)
186 {
187 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
188 inet_aton(tmp_char,&(data_res->v4.pri_dns));
189 }
190 tmp_char = strsep(&dnses, dnses_separator);
191 if(tmp_char != NULL)
192 {
193 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
194 inet_aton(tmp_char, &(data_res->v4.sec_dns));
195 }
196 tmp_char = strsep(&dnses, dnses_separator);
197 if(tmp_char != NULL)
198 {
199 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
200 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
201 }
202 tmp_char = strsep(&dnses, dnses_separator);
203 if(tmp_char != NULL)
204 {
205 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
206 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
207 }
208 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800209 inet_aton(libdata->gateways,&(data_res->v4.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700210 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
211
xf.li03baf1f2023-12-19 21:30:38 -0800212 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip));
213 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns));
214 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns));
215
216 inet_ntop(AF_INET6, &(data_res->v6.ip), buf_ip, sizeof(buf_ip));
217 inet_ntop(AF_INET6, &(data_res->v6.gateway), buf_gateway, sizeof(buf_gateway));
218 inet_ntop(AF_INET6, &(data_res->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
219 inet_ntop(AF_INET6, &(data_res->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
220 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
221 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
xf.li2fc84552023-06-23 05:26:47 -0700222 return ;
223}
224
225void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
226{
xf.li3c0a4752023-09-03 20:46:19 -0700227#ifdef MOBILETEK_TARGET_PLATFORM_T106
228 char *tmp_char = NULL;
229 char *addresses = NULL;
230 char *dnses = NULL;
231 const char addresses_separator[2] = "/";
232 const char dnses_separator[2] = " ";
233
234 addresses = libdata->addresses;
235 dnses = libdata->dnses;
236 //get addresses
237 tmp_char = strsep(&addresses, addresses_separator);
238 if(tmp_char != NULL)
239 {
240 LYINFLOG("ipv4 addresses = %s", tmp_char);
241 inet_aton(tmp_char,&(data_res->v4.addr.ip));
242 }
243 //get dnses
244 tmp_char = strsep(&dnses, dnses_separator);
245 if(tmp_char != NULL)
246 {
247 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
248 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
249 }
250 tmp_char = strsep(&dnses, dnses_separator);
251 if(tmp_char != NULL)
252 {
253 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
254 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
255 }
256 //get gateway
257 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
258 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
259
260 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
261 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
262 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
263#else
xf.li2fc84552023-06-23 05:26:47 -0700264 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
265 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
266 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
267 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700268#endif
xf.li2fc84552023-06-23 05:26:47 -0700269 data_res->v4.stats.pkts_tx = 0;
270 data_res->v4.stats.pkts_rx = 0;
271 data_res->v4.stats.bytes_tx = 0;
272 data_res->v4.stats.bytes_rx = 0;
273 data_res->v4.stats.pkts_dropped_tx = 0;
274 data_res->v4.stats.pkts_dropped_rx = 0;
275 return ;
276}
277
278void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
279{
xf.li3c0a4752023-09-03 20:46:19 -0700280#ifdef MOBILETEK_TARGET_PLATFORM_T106
281 char *tmp_char = NULL;
282 char *addresses = NULL;
283 char *dnses = NULL;
284 const char addresses_separator[2] = "/";
285 const char dnses_separator[2] = " ";
286
287 addresses = libdata->addresses;
288 dnses = libdata->dnses;
289 //get addresses
290 tmp_char = strsep(&addresses, addresses_separator);
291 if(tmp_char != NULL)
292 {
293 LYINFLOG("ipv6 addresses = %s", tmp_char);
294 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
295 }
296 //get dnses
297 tmp_char = strsep(&dnses, dnses_separator);
298 if(tmp_char != NULL)
299 {
300 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
301 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
302 }
303 tmp_char = strsep(&dnses, dnses_separator);
304 if(tmp_char != NULL)
305 {
306 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
307 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
308 }
309 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
310#else
xf.li2fc84552023-06-23 05:26:47 -0700311 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
312 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
313 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
314 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700315#endif
316 data_res->v6.stats.pkts_tx = 0;
317 data_res->v6.stats.pkts_rx = 0;
318 data_res->v6.stats.bytes_tx = 0;
319 data_res->v6.stats.bytes_rx = 0;
320 data_res->v6.stats.pkts_dropped_tx = 0;
321 data_res->v6.stats.pkts_dropped_rx = 0;
322 return ;
323}
324void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
325{
326 char *tmp_char = NULL;
327 char *addresses = NULL;
328 char *dnses = NULL;
329 const char addresses_separator[2] = "/";
330 const char dnses_separator[2] = " ";
331
332 char buf_ip[64] = {0};
333 char buf_gateway[64] = {0};
334 char buf_pri_dns[64] = {0};
335 char buf_sec_dns[64] = {0};
336
337 addresses = libdata->addresses;
338 dnses = libdata->dnses;
339 //get addresses
340 tmp_char = strsep(&addresses, addresses_separator);
341 if(tmp_char != NULL)
342 {
343 LYINFLOG("ipv4 addresses = %s", tmp_char);
344 inet_aton(tmp_char,&(data_res->v4.addr.ip));
345 }
346 tmp_char = strsep(&addresses, addresses_separator);
347 if(tmp_char != NULL)
348 {
349 LYINFLOG("ipv6 addresses = %s", tmp_char);
350 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
351 }
352 //get dnses
353 tmp_char = strsep(&dnses, dnses_separator);
354 if(tmp_char != NULL)
355 {
356 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
357 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
358 }
359 tmp_char = strsep(&dnses, dnses_separator);
360 if(tmp_char != NULL)
361 {
362 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
363 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
364 }
365 tmp_char = strsep(&dnses, dnses_separator);
366 if(tmp_char != NULL)
367 {
368 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
369 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
370 }
371 tmp_char = strsep(&dnses, dnses_separator);
372 if(tmp_char != NULL)
373 {
374 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
375 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
376 }
377 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800378 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700379 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
380
381 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
xf.li03baf1f2023-12-19 21:30:38 -0800382 LYINFLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700383 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
384 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
385
386 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
387 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
388 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
389 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
390 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
391 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
392 data_res->v4.stats.pkts_tx = 0;
393 data_res->v4.stats.pkts_rx = 0;
394 data_res->v4.stats.bytes_tx = 0;
395 data_res->v4.stats.bytes_rx = 0;
396 data_res->v4.stats.pkts_dropped_tx = 0;
397 data_res->v4.stats.pkts_dropped_rx = 0;
398
xf.li2fc84552023-06-23 05:26:47 -0700399 data_res->v6.stats.pkts_tx = 0;
400 data_res->v6.stats.pkts_rx = 0;
401 data_res->v6.stats.bytes_tx = 0;
402 data_res->v6.stats.bytes_rx = 0;
403 data_res->v6.stats.pkts_dropped_tx = 0;
404 data_res->v6.stats.pkts_dropped_rx = 0;
405 return ;
406}
407
408void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
409{
xf.lib5dc0632023-11-30 18:20:35 -0800410 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700411 {
412 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
413 data_res->v4.reconnect = 1;
414 }
415 else
416 {
417 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
418 data_res->v4.reconnect = 0;
419 }
420 return ;
421}
422
423void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
424{
xf.lib5dc0632023-11-30 18:20:35 -0800425 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700426 {
427 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
428 data_res->v6.reconnect = 1;
429 }
430 else
431 {
432 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
433 data_res->v6.reconnect = 0;
434 }
435 return ;
436}
437
xf.licb6cd282024-02-21 22:06:14 -0800438// ****************apn DB start******************
439static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName)
xf.li0fd6acf2023-12-20 18:16:34 -0800440{
xf.licb6cd282024-02-21 22:06:14 -0800441 if(data==NULL)
xf.li0fd6acf2023-12-20 18:16:34 -0800442 {
xf.licb6cd282024-02-21 22:06:14 -0800443 return 1;
xf.li0fd6acf2023-12-20 18:16:34 -0800444 }
xf.licb6cd282024-02-21 22:06:14 -0800445 int *temp = (int *)data;
446 for(int i=0; i<argc; i++){
447 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li0fd6acf2023-12-20 18:16:34 -0800448 }
xf.licb6cd282024-02-21 22:06:14 -0800449 *temp = atoi(argv[0]);
450 return 0;
451}
452static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx)
453{
454 char *zErrMsg = 0;
455 int rc;
456 int idx = 0;
xf.liff415202024-09-19 23:08:09 -0700457 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800458
459 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700460 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800461 rc = sqlite3_open(APN_DB_PATH, &apnDb);
462 if( rc )
xf.li0fd6acf2023-12-20 18:16:34 -0800463 {
xf.licb6cd282024-02-21 22:06:14 -0800464 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700465 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800466 return LYNQ_E_APN_DB_FAIL;
467 }
468
469 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
470 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700471 sprintf(sql,"SELECT ID from LYNQAPN WHERE HANDLE=%d", handle);
xf.licb6cd282024-02-21 22:06:14 -0800472 LYINFLOG("sql: %s\n", sql);
473 /* Execute SQL statement */
474 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_profile_cb, &idx, &zErrMsg);
475 if( rc != SQLITE_OK )
476 {
477 LYERRLOG("SQL error: %s\n", zErrMsg);
478 sqlite3_free(zErrMsg);
479 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700480 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800481 return LYNQ_E_APN_DB_FAIL;
482 };
483 *profile_idx = (unsigned char)idx;
484 LYINFLOG("get idx %d successfully\n", *profile_idx);
485 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700486 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800487 return 0;
488}
489static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName){
490 int i;
491
492 apn_indexs[atoi(argv[0])] = atoi(argv[0]);
493 LYINFLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]);
494
495 for(i=0; i<argc; i++){
496 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
497 }
498 return 0;
499}
500/**
501 * @brief Check whether the ID exists in the database
502 *
503 * @param index
504 * @return int
505 * find:turn 1
506 * not find:turn 0
507 */
508static int lynq_check_index(unsigned char index)
509{
510 memset(apn_indexs,0,sizeof(apn_indexs));
511 next_index = 0;
512 char *zErrMsg = 0;
513 int rc;
514 char sql[128]={0};
515 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700516 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800517 rc = sqlite3_open(APN_DB_PATH, &apnDb);
518 if( rc )
519 {
520 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700521 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800522 return LYNQ_E_APN_DB_FAIL;
523 }
524 sprintf(sql,"%s", "SELECT * from LYNQAPN");
525 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback, NULL, &zErrMsg);
526 if( rc != SQLITE_OK )
527 {
528 LYERRLOG("SQL error: %s\n", zErrMsg);
529 sqlite3_free(zErrMsg);
530 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700531 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800532 return LYNQ_E_APN_DB_FAIL;
533 }
534 //for(int cnt = 0; cnt < next_index;cnt++)
535 for(int cnt = 0; cnt <= QSER_APN_MAX_LIST; cnt++)
536 {
537 if(index == apn_indexs[cnt])
538 {
539 LYINFLOG("index = apn_index\n");
540 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700541 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800542 return 1;
543 }
544 }
545 LYINFLOG("cant find the index %d\n", index);
546 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700547 pthread_mutex_unlock(&s_qser_data_database_mutex);
548
xf.licb6cd282024-02-21 22:06:14 -0800549 return 0;
550}
551
552static int apn_db_handle_set(unsigned char profile_idx, int handle)
553{
554 char *zErrMsg = 0;
555 int rc;
xf.liff415202024-09-19 23:08:09 -0700556 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800557 if(!lynq_check_index(profile_idx))
558 {
559 return LYNQ_E_APN_DB_FAIL;
560 }
561 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700562 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800563 rc = sqlite3_open(APN_DB_PATH, &apnDb);
564 if( rc )
565 {
566 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700567 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800568 return LYNQ_E_APN_DB_FAIL;
569 }
570
571 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
572 /* Create SQL statement */
573 //sql = "SELECT * from LYNQAPN";
xf.liff415202024-09-19 23:08:09 -0700574 sprintf(sql,"UPDATE LYNQAPN SET HANDLE=%d WHERE ID=%d", handle, (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800575 LYINFLOG("sql: %s\n", sql);
576 /* Execute SQL statement */
577 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
578 if( rc != SQLITE_OK )
579 {
580 LYERRLOG("SQL error: %s\n", zErrMsg);
581 sqlite3_free(zErrMsg);
582 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700583 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800584 return LYNQ_E_APN_DB_FAIL;
585 }
586 LYINFLOG("update apn %d successfully\n", profile_idx);
587 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700588 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800589 return 0;
590}
591static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName)
592{
593 if(data==NULL)
594 {
595 return 1;
596 }
597 int *temp = (int *)data;
598 for(int i=0; i<argc; i++){
599 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
600 }
601 *temp = atoi(argv[0]);
602 LYINFLOG("The handle is %d\n", *temp);
603 return 0;
604}
605static int apn_db_handle_get(unsigned char profile_idx, int *handle)
606{
607 char *zErrMsg = 0;
608 int rc;
xf.liff415202024-09-19 23:08:09 -0700609 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800610
xf.licb6cd282024-02-21 22:06:14 -0800611 if(!lynq_check_index(profile_idx))
612 {
613 return LYNQ_E_APN_DB_FAIL;
614 }
615 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700616 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800617 rc = sqlite3_open(APN_DB_PATH, &apnDb);
618 if( rc )
619 {
620 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700621 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800622 return LYNQ_E_APN_DB_FAIL;
623 }
624
625 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
626 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700627 sprintf(sql,"SELECT HANDLE from LYNQAPN WHERE ID=%d", (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800628 LYINFLOG("sql: %s\n", sql);
629 /* Execute SQL statement */
630 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_cb, handle, &zErrMsg);
631 if( rc != SQLITE_OK )
632 {
633 LYERRLOG("SQL error: %s\n", zErrMsg);
634 sqlite3_free(zErrMsg);
635 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700636 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800637 return LYNQ_E_APN_DB_FAIL;
638 }
639 LYINFLOG("get idx %d successfully\n", *handle);
640 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700641 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800642 return 0;
643}
644
645static int has_apn_db_created(char *path,sqlite3* apnDb_l)
646{
647 if (path == NULL || strlen(path) == 0)
648 {
649 LYERRLOG("initApnDb error with null path!");
650 return APN_DB_ERR;
651 }
652 int rc = sqlite3_open_v2(path, &apnDb_l, SQLITE_OPEN_READWRITE,NULL);
653 if (rc == SQLITE_OK)
654 {
655 LYINFLOG("check init success!");
xf.lib5d82bf2024-03-09 01:54:50 -0800656 sqlite3_close_v2(apnDb_l);
xf.licb6cd282024-02-21 22:06:14 -0800657 return APN_DB_READED;
658 }
659 else
660 {
661 LYERRLOG("db has not create %s!", sqlite3_errmsg(apnDb_l));
662 sqlite3_close_v2(apnDb_l);
663 return APN_DB_ERR;
664 }
665}
666static int create_apn_db(char *path)
667{
668 if (path == NULL || strlen(path) == 0) {
669 LYERRLOG("initApnDb error with null path!");
670 return APN_DB_ERR;
671 }
672 if(APN_DB_READED==has_apn_db_created(path,apnDb))
673 {
674 return APN_DB_READED;
675 }
676 int rc = sqlite3_open(path, &apnDb);
677 if (rc != SQLITE_OK) {
678 LYERRLOG("initDb failed %d", sqlite3_errcode(apnDb));
679 return APN_DB_ERR;
680 } else {
681 LYINFLOG("create db in %s", path);
682 }
683 sqlite3_close(apnDb);
684 return APN_DB_CREATE;
685}
686static int create_apn_table(char*path)
687{
688 char *zErrMsg = 0;
689 int rc;
690 char *sql;
691
692 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700693 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800694 rc = sqlite3_open(path, &apnDb);
695 if( rc )
696 {
697 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700698 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800699 return 1;
700 }
701 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
702 /* Create SQL statement */
703 sql = "CREATE TABLE LYNQAPN( \
704 ID INT NOT NULL, \
705 PDP_TYPE INT NOT NULL, \
706 AUTH_PROTO INT NOT NULL, \
707 APN_NAME TEXT NOT NULL, \
708 USERNAME TEXT NOT NULL,\
709 PASSWORD TEXT NOT NULL, \
710 APN_TYPE TEXT PRIMARY KEY NOT NULL, \
711 HANDLE INT NOT NULL)";
712 /* Execute SQL statement */
713 rc = sqlite3_exec(apnDb, sql, NULL, 0, &zErrMsg);
714 if( rc != SQLITE_OK )
715 {
716 LYERRLOG("SQL error: %s\n", zErrMsg);
717 sqlite3_free(zErrMsg);
718 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700719 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800720 return 1;
721 }
722 LYINFLOG("Table LYNQAPN created successfully\n");
723 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700724 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800725 return 0;
726}
xf.li1bbfc7d2024-07-15 23:50:41 -0700727check_apn_table_cb(void *data, int argc, char **argv, char **azColName)
728{
729 if(data==NULL)
730 {
731 return 1;
732 }
733 int *temp = (int *)data;
734 for(int i=0; i<argc; i++){
735 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
736 }
737 *temp = atoi(argv[0]);
738 LYINFLOG("\nThe number is %d\n", *temp);
739 return 0;
740}
741int check_apn_table(char*path)
742{
743 char *zErrMsg = 0;
744 int rc;
745 char *sql;
746 int num = -1;
747
748 /* Open database */
749 pthread_mutex_lock(&s_qser_data_database_mutex);
750 rc = sqlite3_open(path, &apnDb);
751 if( rc )
752 {
753 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
754 pthread_mutex_unlock(&s_qser_data_database_mutex);
755 return 1;
756 }
757 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
758 /* Create SQL statement */
759 sql = "SELECT COUNT(*) FROM sqlite_master where type ='table' and name = 'LYNQAPN'";
760 /* Execute SQL statement */
761 rc = sqlite3_exec(apnDb, sql, check_apn_table_cb, &num, &zErrMsg);
762 if( rc != SQLITE_OK )
763 {
764 LYERRLOG("SQL error: %s\n", zErrMsg);
765 sqlite3_free(zErrMsg);
766 sqlite3_close(apnDb);
767 pthread_mutex_unlock(&s_qser_data_database_mutex);
768 return 1;
769 }
770 LYINFLOG("Table LYNQAPN check successfully\n");
771 sqlite3_close(apnDb);
772 pthread_mutex_unlock(&s_qser_data_database_mutex);
773 if(num <= 0)
774 {
775 LYINFLOG("No table LYNQAPN, num = %d\n", num);
776 return APN_TABLE_NEED_CREATE;
777 }
778 else
779 {
780 LYINFLOG("The table LYNQAPN exist, num = %d\n", num);
781 return APN_TABLE_CREATE;
782 }
783
784 return 0;
785}
xf.licb6cd282024-02-21 22:06:14 -0800786static int init_apn_db()
787{
788 int db_ret=0;
xf.li1bbfc7d2024-07-15 23:50:41 -0700789 int check_ret=0;
xf.licb6cd282024-02-21 22:06:14 -0800790 int table_ret=0;
xf.li87f6e6e2024-06-19 02:23:05 -0700791
792 pthread_mutex_init(&s_qser_data_database_mutex, NULL);
793
xf.licb6cd282024-02-21 22:06:14 -0800794 db_ret = create_apn_db(APN_DB_PATH);
795 if(db_ret==APN_DB_CREATE)
796 {
797 table_ret = create_apn_table(APN_DB_PATH);
798 if(table_ret!=0)
799 {
800 LYERRLOG("create apn table fail!!!");
801 return RESULT_ERROR;
802 }
803 apn_db_add(0, &default_apn);
804 }
805 else if(db_ret==APN_DB_READED)
806 {
xf.li1bbfc7d2024-07-15 23:50:41 -0700807 LYINFLOG("[%s] apn db has be build!!!",__FUNCTION__);
808 check_ret = check_apn_table(APN_DB_PATH);
809 if(check_ret == APN_TABLE_NEED_CREATE)
810 {
811 table_ret = create_apn_table(APN_DB_PATH);
812 if(table_ret!=0)
813 {
814 LYERRLOG("create apn table fail!!!");
815 return 1;
816 }
817 apn_db_add(0, &default_apn);
818 }
819 else if(check_ret == APN_TABLE_CREATE)
820 {
821 LYINFLOG("Table LYNQAPN has created");
822 }
823 else
824 {
825 LYERRLOG("check table fail!!!, ret = %d", check_ret);
826 }
xf.li0fd6acf2023-12-20 18:16:34 -0800827 }
828 else
829 {
xf.licb6cd282024-02-21 22:06:14 -0800830 LYERRLOG("init apn db fail!!!");
xf.li0fd6acf2023-12-20 18:16:34 -0800831 }
xf.li0fd6acf2023-12-20 18:16:34 -0800832 return RESULT_OK;
xf.li0fd6acf2023-12-20 18:16:34 -0800833}
xf.li2fc84552023-06-23 05:26:47 -0700834
xf.licb6cd282024-02-21 22:06:14 -0800835static int apn_db_handle_clean()
xf.li63b87e82024-01-04 00:43:35 -0800836{
xf.licb6cd282024-02-21 22:06:14 -0800837 char *zErrMsg = 0;
838 int rc;
xf.li63b87e82024-01-04 00:43:35 -0800839 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.liff415202024-09-19 23:08:09 -0700840 char sql[128]={0};
xf.li63b87e82024-01-04 00:43:35 -0800841
xf.licb6cd282024-02-21 22:06:14 -0800842 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700843 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800844 rc = sqlite3_open(APN_DB_PATH, &apnDb);
845 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800846 {
xf.licb6cd282024-02-21 22:06:14 -0800847 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700848 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800849 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800850 }
xf.licb6cd282024-02-21 22:06:14 -0800851
852 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
853 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700854 sprintf(sql,"UPDATE LYNQAPN SET HANDLE=%d", default_handle);
xf.licb6cd282024-02-21 22:06:14 -0800855 LYINFLOG("sql: %s\n", sql);
856 /* Execute SQL statement */
857 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
858 if( rc != SQLITE_OK )
xf.li63b87e82024-01-04 00:43:35 -0800859 {
xf.licb6cd282024-02-21 22:06:14 -0800860 LYERRLOG("SQL error: %s\n", zErrMsg);
861 sqlite3_free(zErrMsg);
862 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700863 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800864 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800865 }
xf.licb6cd282024-02-21 22:06:14 -0800866 LYINFLOG("clean apn table successfully\n");
867 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700868 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800869 return RESULT_OK;
870}
871
872static int find_unuse_apn_index(char *path)
873{
874 char *zErrMsg = 0;
875 int rc;
876 int count =1;
877 bool apn_usable = false;
878 char *sql;
879
880 memset(apn_indexs,0,sizeof(apn_indexs));
881 next_index = 0;
882 LYINFLOG("index = %p",apn_indexs);
883 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700884 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800885 rc = sqlite3_open(APN_DB_PATH, &apnDb);
886 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800887 {
xf.licb6cd282024-02-21 22:06:14 -0800888 LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700889 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800890 return -1;
xf.li63b87e82024-01-04 00:43:35 -0800891 }
892 else
893 {
xf.licb6cd282024-02-21 22:06:14 -0800894 LYINFLOG("Opened database successfully\n");
xf.li63b87e82024-01-04 00:43:35 -0800895 }
xf.li63b87e82024-01-04 00:43:35 -0800896
xf.licb6cd282024-02-21 22:06:14 -0800897 /* Create SQL statement */
898 sql = "SELECT ID from LYNQAPN";
899 /* Execute SQL statement */
900 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg);
901 if( rc != SQLITE_OK )
902 {
903 LYERRLOG("SQL error: %s\n", zErrMsg);
904 sqlite3_free(zErrMsg);
xf.lib5d82bf2024-03-09 01:54:50 -0800905 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700906 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800907 return -1;
908 }
909 else
910 {
911 LYINFLOG("Operation done successfully\n");
912 }
913 //indexs = temp_index;
914 LYINFLOG("index = %p",apn_indexs);
915 for(count;count<=QSER_APN_MAX_LIST;count++)
916 {
917 //if(apn_indexs[count-1]!=count)
918 LYINFLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count);
919 if(apn_indexs[count]!=count)
920 {
921 //apn_usable=true;
922 break;
923 }
924 }
925 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700926 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800927 LYINFLOG("count is %d\n", count);
928 return count;
xf.li63b87e82024-01-04 00:43:35 -0800929}
930
xf.licb6cd282024-02-21 22:06:14 -0800931static int apn_db_add(int profile_id, qser_apn_add_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700932{
xf.licb6cd282024-02-21 22:06:14 -0800933 char *zErrMsg = 0;
934 int rc;
xf.li0fd6acf2023-12-20 18:16:34 -0800935 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.licb6cd282024-02-21 22:06:14 -0800936 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700937 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800938 rc = sqlite3_open(APN_DB_PATH, &apnDb);
939 if( rc )
xf.li2fc84552023-06-23 05:26:47 -0700940 {
xf.licb6cd282024-02-21 22:06:14 -0800941 LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700942 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800943 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700944 }
xf.licb6cd282024-02-21 22:06:14 -0800945 LYINFLOG("[%s] Opened database successfully",__FUNCTION__);
946 /* Create SQL statement */
947 /* Execute SQL statement */
948 LYINFLOG("the profile id is %d\n", profile_id);
949 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);
950 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
xf.liff415202024-09-19 23:08:09 -0700951 sqlite3_free(sql);
xf.licb6cd282024-02-21 22:06:14 -0800952 if( rc != SQLITE_OK )
xf.li2fc84552023-06-23 05:26:47 -0700953 {
xf.licb6cd282024-02-21 22:06:14 -0800954 LYERRLOG( "SQL error: %s", zErrMsg);
955 sqlite3_free(zErrMsg);
956 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700957 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800958 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700959 }
xf.licb6cd282024-02-21 22:06:14 -0800960 LYINFLOG("write apn to apn db successfully");
961 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700962 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800963 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700964}
965
xf.licb6cd282024-02-21 22:06:14 -0800966static int apn_db_delete(unsigned char profile_idx)
xf.li2fc84552023-06-23 05:26:47 -0700967{
xf.licb6cd282024-02-21 22:06:14 -0800968 char *zErrMsg = 0;
969 int rc;
xf.liff415202024-09-19 23:08:09 -0700970 char sql[128]={0};
xf.li2fc84552023-06-23 05:26:47 -0700971
xf.licb6cd282024-02-21 22:06:14 -0800972 if(!lynq_check_index(profile_idx))
973 {
974 return LYNQ_E_APN_DB_FAIL;
975 }
976 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700977 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800978 rc = sqlite3_open(APN_DB_PATH, &apnDb);
979 if( rc )
980 {
981 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700982 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800983 return LYNQ_E_APN_DB_FAIL;
984 }
985
986 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
987 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700988 sprintf(sql,"DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800989 LYINFLOG("sql: %s\n", sql);
990 /* Execute SQL statement */
991 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
992 if( rc != SQLITE_OK )
993 {
994 LYERRLOG("SQL error: %s\n", zErrMsg);
995 sqlite3_free(zErrMsg);
996 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700997 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800998 return LYNQ_E_APN_DB_FAIL;
999 }
1000 LYINFLOG("delete apn %d successfully\n", profile_idx);
1001 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001002 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001003 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001004}
1005
xf.licb6cd282024-02-21 22:06:14 -08001006static int apn_db_modify(qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001007{
xf.licb6cd282024-02-21 22:06:14 -08001008 char *zErrMsg = 0;
1009 int rc;
xf.li2fc84552023-06-23 05:26:47 -07001010
xf.licb6cd282024-02-21 22:06:14 -08001011 if(!lynq_check_index(apn->profile_idx))
1012 {
1013 return LYNQ_E_APN_DB_FAIL;
1014 }
1015 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001016 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001017 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1018 if( rc )
1019 {
1020 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001021 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001022 return LYNQ_E_APN_DB_FAIL;
1023 }
1024
1025 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1026 /* Create SQL statement */
1027 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);
1028 LYINFLOG("sql: %s\n", sql);
1029 /* Execute SQL statement */
1030 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
xf.liff415202024-09-19 23:08:09 -07001031 sqlite3_free(sql);
xf.licb6cd282024-02-21 22:06:14 -08001032 if( rc != SQLITE_OK )
1033 {
1034 LYERRLOG("SQL error: %s\n", zErrMsg);
1035 sqlite3_free(zErrMsg);
1036 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001037 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001038 return LYNQ_E_APN_DB_FAIL;
1039 }
1040 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1041 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001042 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001043 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001044}
1045
xf.licb6cd282024-02-21 22:06:14 -08001046static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName)
xf.li2fc84552023-06-23 05:26:47 -07001047{
xf.licb6cd282024-02-21 22:06:14 -08001048 if(data==NULL)
xf.li2fc84552023-06-23 05:26:47 -07001049 {
xf.licb6cd282024-02-21 22:06:14 -08001050 return 1;
xf.li2fc84552023-06-23 05:26:47 -07001051 }
xf.licb6cd282024-02-21 22:06:14 -08001052 qser_apn_info_s* temp = (qser_apn_info_s *)data;
1053 for(int i=0; i<argc; i++){
1054 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001055 }
xf.licb6cd282024-02-21 22:06:14 -08001056 temp->profile_idx = atoi(argv[0]);
1057 temp->pdp_type = atoi(argv[1]);
1058 temp->auth_proto = atoi(argv[2]);
1059 memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE);
1060 memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE);
1061 memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE);
1062 memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE);
1063 LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0]));
1064 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001065}
xf.licb6cd282024-02-21 22:06:14 -08001066static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001067{
xf.licb6cd282024-02-21 22:06:14 -08001068 char *zErrMsg = 0;
1069 int rc;
xf.liff415202024-09-19 23:08:09 -07001070 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -08001071
1072 if(!lynq_check_index(profile_idx))
xf.li2fc84552023-06-23 05:26:47 -07001073 {
xf.licb6cd282024-02-21 22:06:14 -08001074 return LYNQ_E_APN_DB_FAIL;
1075 }
1076 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001077 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001078 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1079 if( rc )
1080 {
1081 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001082 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001083 return LYNQ_E_APN_DB_FAIL;
1084 }
1085
1086 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1087 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001088 sprintf(sql,"SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -08001089 LYINFLOG("sql: %s\n", sql);
1090 /* Execute SQL statement */
1091 rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg);
1092 if( rc != SQLITE_OK )
1093 {
1094 LYERRLOG("SQL error: %s\n", zErrMsg);
1095 sqlite3_free(zErrMsg);
1096 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001097 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001098 return LYNQ_E_APN_DB_FAIL;
1099 }
1100 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1101 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001102 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001103 return 0;
1104}
1105static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName)
1106{
1107 int i;
1108
1109 //apn_count++;
1110
1111 qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data;
1112 for(i=0; i<argc; i++){
1113 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001114 }
1115
xf.licb6cd282024-02-21 22:06:14 -08001116 temp->apn[temp->cnt].profile_idx = atoi(argv[0]);
1117 temp->apn[temp->cnt].pdp_type = atoi(argv[1]);
1118 temp->apn[temp->cnt].auth_proto = atoi(argv[2]);
1119 memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE);
1120 memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE);
1121 memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE);
1122 memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE);
1123 temp->cnt++;
1124 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001125}
xf.licb6cd282024-02-21 22:06:14 -08001126static int apn_db_query_list(qser_apn_info_list_s *apn_list)
1127{
1128 char *zErrMsg = 0;
1129 int rc;
xf.liff415202024-09-19 23:08:09 -07001130 char sql[128]={0};
xf.li2fc84552023-06-23 05:26:47 -07001131
xf.licb6cd282024-02-21 22:06:14 -08001132 /* Open database */
1133 apn_count = 0;
1134 apn_list->cnt = 0;
xf.li87f6e6e2024-06-19 02:23:05 -07001135 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001136 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1137 if( rc )
1138 {
1139 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001140 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001141 return LYNQ_E_APN_DB_FAIL;
1142 }
1143
1144 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1145 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001146 sprintf(sql,"SELECT * from LYNQAPN");
xf.licb6cd282024-02-21 22:06:14 -08001147 LYINFLOG("sql: %s\n", sql);
1148 /* Execute SQL statement */
1149 rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg);
1150 if( rc != SQLITE_OK )
1151 {
1152 LYERRLOG("SQL error: %s\n", zErrMsg);
1153 sqlite3_free(zErrMsg);
1154 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001155 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001156 return LYNQ_E_APN_DB_FAIL;
1157 }
1158 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001159 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001160 return 0;
1161}
1162// **************apn DB end****************************
xf.li2fc84552023-06-23 05:26:47 -07001163void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
1164{
1165 switch (pdp_type)
1166 {
1167 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -08001168#ifdef MOBILETEK_TARGET_PLATFORM_T106
1169 strcpy(out_pdp_type,"IP");
1170#else
xf.li2fc84552023-06-23 05:26:47 -07001171 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -08001172#endif
xf.li2fc84552023-06-23 05:26:47 -07001173 break;
1174 case QSER_APN_PDP_TYPE_PPP:
1175 strcpy(out_pdp_type,"PPP");
1176 break;
1177 case QSER_APN_PDP_TYPE_IPV6:
1178 strcpy(out_pdp_type,"IPV6");
1179 break;
1180 case QSER_APN_PDP_TYPE_IPV4V6:
1181 strcpy(out_pdp_type,"IPV4V6");
1182 break;
1183 default:
1184 strcpy(out_pdp_type,"NULL");
1185 break;
1186 }
1187 return;
1188}
1189void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
1190{
1191 switch (auth_proto)
1192 {
1193 case QSER_APN_AUTH_PROTO_DEFAULT:
xf.lifb6134e2024-05-09 01:26:54 -07001194 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001195 break;
1196 case QSER_APN_AUTH_PROTO_NONE:
xf.lifb6134e2024-05-09 01:26:54 -07001197 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001198 break;
1199 case QSER_APN_AUTH_PROTO_PAP:
xf.lifb6134e2024-05-09 01:26:54 -07001200 strcpy(out_proto,"1");
xf.li2fc84552023-06-23 05:26:47 -07001201 break;
1202 case QSER_APN_AUTH_PROTO_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001203 strcpy(out_proto,"2");
xf.li2fc84552023-06-23 05:26:47 -07001204 break;
1205 case QSER_APN_AUTH_PROTO_PAP_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001206 strcpy(out_proto,"3");
xf.li2fc84552023-06-23 05:26:47 -07001207 break;
1208 default:
xf.lifb6134e2024-05-09 01:26:54 -07001209 strcpy(out_proto,"NULL");
xf.li2fc84552023-06-23 05:26:47 -07001210 break;
1211 }
1212 return ;
1213}
1214
1215int data_call_handle_get(const char profile_idx,int *handle)
1216{
1217 int num = LYNQ_APN_CHANNEL_MAX;
1218 int table_num = 0;
1219 lynq_apn_info **apn_table = NULL;
1220 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001221 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001222 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1223 if (NULL == apn_table)
1224 {
1225 LYERRLOG("malloc apn_table fail ");
1226 return RESULT_ERROR;
1227 }
1228 for(int i =0;i<10;i++)
1229 {
1230 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1231 if (apn_table[i]==NULL)
1232 {
1233 for (int n=0;n<i;n++)
1234 {
1235 free(apn_table[n]);
1236 }
1237 return RESULT_ERROR;
1238 }
1239 memset(apn_table[i],0,sizeof(lynq_apn_info));
1240 }
1241 lynq_get_apn_table(&table_num,apn_table);
1242 memset(&apn,0,sizeof(qser_apn_info_s));
xf.licb6cd282024-02-21 22:06:14 -08001243 ret = apn_db_query(profile_idx,&apn);
xf.li0fc26502023-09-16 02:10:17 -07001244 if (ret < 0)
1245 {
xf.licb6cd282024-02-21 22:06:14 -08001246 LYERRLOG("apn_db_query error");
xf.li0fc26502023-09-16 02:10:17 -07001247 return ret;
1248 }
xf.li2fc84552023-06-23 05:26:47 -07001249 for (int j = 0;j < table_num;j++)
1250 {
1251 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1252 {
1253 *handle = apn_table[j]->index;
1254 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1255 break;
1256 }
1257 }
1258
1259 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1260 {
1261 if (apn_table[i]!=NULL)
1262 {
1263 free(apn_table[i]);
1264 apn_table[i]=NULL;
1265 }
1266 }
1267 free(apn_table);
1268 apn_table=NULL;
1269 LYINFLOG("data_call_handle_get end");
1270 return RESULT_OK;
1271}
1272
xf.li789f7a12024-10-24 03:02:37 -07001273static void acquire_wake_lock()
1274{
1275 int ret = 0;
1276
1277 ret = system("echo data_call_wakelock 5000000000 > /sys/power/wake_lock");//timeout 5s
1278 if(ret != 0)
1279 {
1280 LYERRLOG("acquire_wake_lock error !!!");
1281 }
1282 return;
1283}
1284
1285static void release_wake_lock()
1286{
1287 int ret = 0;
1288
1289 ret = system("echo data_call_wakelock > /sys/power/wake_unlock");
1290 if(ret != 0)
1291 {
1292 LYERRLOG("release_wake_lock error !!!");
1293 }
1294 return;
1295}
1296
xf.li2fc84552023-06-23 05:26:47 -07001297void *thread_wait_cb_status(void)
1298{
1299 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001300 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001301 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001302 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001303 qser_data_call_state_s data_cb_state;
1304 while (s_qser_data_cb_thread_status)
1305 {
xf.li6b0d8502023-09-04 18:49:12 -07001306 ret = lynq_wait_data_call_state_change(&handle);
1307 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
1308 if(s_qser_data_cb_thread_status == 0)
1309 {
1310 return NULL;
1311 }
1312 else if(ret < 0)
1313 {
1314 continue;
1315 }
xf.li789f7a12024-10-24 03:02:37 -07001316 acquire_wake_lock();
xf.li8535bc02023-12-12 23:28:35 -08001317 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
1318 memset(&data_urc_info, 0, sizeof(data_urc_info));
1319 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001320 lynq_get_data_call_list(&handle,&data_urc_info);
1321 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001322 //data_cb_state.profile_idx = (char)handle;
xf.licb6cd282024-02-21 22:06:14 -08001323 apn_db_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li87f6e6e2024-06-19 02:23:05 -07001324 LYINFLOG("[thread_wait_cb_status]: callback profile_idx is %d\n", data_cb_state.profile_idx);
xf.li8535bc02023-12-12 23:28:35 -08001325 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",
1326 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
1327 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
1328 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -07001329 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001330 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001331 {
1332 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1333 }
1334 else if (!strcmp(data_urc_info.type,"IPV6"))
1335 {
1336 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1337 }
xf.li8535bc02023-12-12 23:28:35 -08001338 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001339 {
1340 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1341 }
1342 else
1343 {
xf.li8535bc02023-12-12 23:28:35 -08001344 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001345 }
1346
xf.li8535bc02023-12-12 23:28:35 -08001347 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001348 {
1349 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1350 }
1351 else
1352 {
1353 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.licb6cd282024-02-21 22:06:14 -08001354 ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001355 if(ret != 0)
1356 {
1357 LYERRLOG("handle set error");
1358 }
xf.li2fc84552023-06-23 05:26:47 -07001359 }
1360 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1361 {
1362 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1363 }
1364 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1365 {
1366 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1367 }
1368 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1369 {
xf.li3c0a4752023-09-03 20:46:19 -07001370#ifdef MOBILETEK_TARGET_PLATFORM_T106
1371 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1372#else
xf.li2fc84552023-06-23 05:26:47 -07001373 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001374#endif
xf.li2fc84552023-06-23 05:26:47 -07001375 }
1376 else
1377 {
xf.li789f7a12024-10-24 03:02:37 -07001378 release_wake_lock();
xf.li2fc84552023-06-23 05:26:47 -07001379 LYERRLOG("unknow ip_family");
1380 continue;
1381 }
1382 if (s_data_call_cb != NULL)
1383 {
xf.li789f7a12024-10-24 03:02:37 -07001384 s_data_call_cb(&data_cb_state);
1385 release_wake_lock();
1386 LYINFLOG("[%s] call back s_data_call_cb end", __FUNCTION__);
xf.li2fc84552023-06-23 05:26:47 -07001387 }
1388 }
1389 return NULL;
1390}
1391
1392int qser_cb_pthread_create()
1393{
xf.lib5d82bf2024-03-09 01:54:50 -08001394 pthread_attr_t attr;
xf.li2fc84552023-06-23 05:26:47 -07001395 int ret;
1396 s_qser_data_cb_thread_status = 1;
xf.lib5d82bf2024-03-09 01:54:50 -08001397
1398 pthread_attr_init(&attr);
1399 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1400
1401 ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL);
xf.li2fc84552023-06-23 05:26:47 -07001402 if (ret < 0)
1403 {
1404 LYERRLOG("pthread create fail");
1405 s_qser_data_cb_thread_status = 0;
1406 return RESULT_ERROR;
1407 }
xf.lib5d82bf2024-03-09 01:54:50 -08001408 pthread_attr_destroy(&attr);
xf.li2fc84552023-06-23 05:26:47 -07001409 return RESULT_OK;
1410}
1411
1412void qser_cb_pthread_cancel()
1413{
xf.li2fc84552023-06-23 05:26:47 -07001414 s_qser_data_cb_thread_status = 0;
1415 if (s_cb_tid != -1)
1416 {
xf.li6b0d8502023-09-04 18:49:12 -07001417 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001418 }
1419 return;
1420}
xf.li2fc84552023-06-23 05:26:47 -07001421int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1422{
1423 int ret = 0;
1424 int utoken = 0;
1425 if (NULL == evt_cb)
1426 {
1427 LYERRLOG("init incoming paramters error");
1428 return RESULT_ERROR;
1429 }
xf.li09b46db2024-03-13 19:21:18 -07001430 if(g_lynq_qser_data_init_flag == 1)
1431 {
1432 LYERRLOG("init twice is not allowed");
1433 return RESULT_ERROR;
1434 }
xf.li2fc84552023-06-23 05:26:47 -07001435 ret = lynq_init_data(utoken);
1436 if (ret != RESULT_OK)
1437 {
xf.li6b0d8502023-09-04 18:49:12 -07001438 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001439 s_data_call_cb = NULL;
1440 return RESULT_ERROR;
1441 }
xf.li6b0d8502023-09-04 18:49:12 -07001442 qser_cb_pthread_create();
xf.licb6cd282024-02-21 22:06:14 -08001443 ret = init_apn_db();
1444 if(ret != RESULT_OK)
xf.lie3f55f42023-12-01 22:47:33 -08001445 {
xf.licb6cd282024-02-21 22:06:14 -08001446 LYERRLOG("init apn db error");
xf.lie3f55f42023-12-01 22:47:33 -08001447 return RESULT_ERROR;
1448 }
xf.licb6cd282024-02-21 22:06:14 -08001449
1450 ret = apn_db_handle_clean();
xf.li63b87e82024-01-04 00:43:35 -08001451 if(ret != RESULT_OK)
1452 {
1453 LYERRLOG("clean handle error");
1454 return RESULT_ERROR;
1455 }
xf.li09b46db2024-03-13 19:21:18 -07001456 s_data_call_cb = evt_cb;
xf.lib33d4862023-12-13 00:40:37 -08001457 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001458 return RESULT_OK;
1459}
1460
1461void qser_data_call_destroy(void)
1462{
xf.li6b0d8502023-09-04 18:49:12 -07001463 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001464 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001465 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001466 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001467 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001468 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001469 return ;
1470}
1471
1472int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1473{
1474 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001475 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001476 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001477 if(g_lynq_qser_data_init_flag == 0)
1478 {
1479 if(err != NULL)
1480 {
1481 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1482 }
1483 return LYNQ_E_NO_INIT;
1484 }
xf.li2fc84552023-06-23 05:26:47 -07001485 if (NULL == data_call || NULL == err)
1486 {
1487 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001488 if(err != NULL)
1489 {
1490 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1491 }
xf.li2fc84552023-06-23 05:26:47 -07001492 return ret;
1493 }
1494 if (data_call->profile_idx == 0)
1495 {
1496 ret = lynq_setup_data_call(&handle);
1497 }
1498 else
1499 {
1500 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001501 char auth_proto[16];
xf.li2fc84552023-06-23 05:26:47 -07001502 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001503 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1504 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li0fc26502023-09-16 02:10:17 -07001505 if (ret != 0)
1506 {
1507 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001508 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001509 return ret;
1510 }
xf.li2fc84552023-06-23 05:26:47 -07001511 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001512 judge_authtype(apn_info.auth_proto,auth_proto);
1513 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 -07001514 }
xf.lic12b3702023-11-22 22:39:01 -08001515 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001516 {
1517 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1518 }
xf.li0fd6acf2023-12-20 18:16:34 -08001519 else
1520 {
xf.licb6cd282024-02-21 22:06:14 -08001521 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001522 if(error != 0)
1523 {
1524 LYERRLOG("handle set error");
1525 }
1526 }
xf.li2fc84552023-06-23 05:26:47 -07001527 return ret;
1528}
1529
xf.li8535bc02023-12-12 23:28:35 -08001530int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1531{
1532 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001533 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001534 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001535 if(g_lynq_qser_data_init_flag == 0)
1536 {
1537 if(err != NULL)
1538 {
1539 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1540 }
1541 return LYNQ_E_NO_INIT;
1542 }
xf.li8535bc02023-12-12 23:28:35 -08001543 if (NULL == data_call || NULL == err)
1544 {
1545 LYERRLOG("call start incoming paramters error");
1546 if(err != NULL)
1547 {
1548 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1549 }
1550 return ret;
1551 }
1552 if (data_call->profile_idx == 0)
1553 {
1554 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1555 }
1556 else
1557 {
1558 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001559 char auth_proto[16];
xf.li8535bc02023-12-12 23:28:35 -08001560 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001561 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1562 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li8535bc02023-12-12 23:28:35 -08001563 if (ret != 0)
1564 {
1565 LYERRLOG("qser_apn_get error");
1566 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1567 return ret;
1568 }
1569 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001570 judge_authtype(apn_info.auth_proto,auth_proto);
1571 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 -08001572 }
1573 if (ret != 0)
1574 {
1575 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1576 }
xf.li0fd6acf2023-12-20 18:16:34 -08001577 else
1578 {
xf.licb6cd282024-02-21 22:06:14 -08001579 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001580 if(error != 0)
1581 {
1582 LYERRLOG("handle set error");
1583 }
1584 }
xf.li8535bc02023-12-12 23:28:35 -08001585 return ret;
1586}
1587
xf.li2fc84552023-06-23 05:26:47 -07001588int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1589{
1590 int ret = 0;
1591 int handle = -1;
1592
xf.lib33d4862023-12-13 00:40:37 -08001593 if(g_lynq_qser_data_init_flag == 0)
1594 {
1595 if(err != NULL)
1596 {
1597 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1598 }
1599 return LYNQ_E_NO_INIT;
1600 }
xf.li2fc84552023-06-23 05:26:47 -07001601 if (NULL == err)
1602 {
1603 LYERRLOG("call stop incoming paramters error");
1604 return ret;
1605 }
xf.lic12b3702023-11-22 22:39:01 -08001606 ret = data_call_handle_get(profile_idx,&handle);
1607 if(ret != 0)
1608 {
1609 LYERRLOG("datacall handle get error");
1610 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1611 return ret;
1612 }
xf.li2fc84552023-06-23 05:26:47 -07001613 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001614 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001615 {
1616 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001617 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001618 }
xy.hee2daacc2023-09-18 00:57:51 -07001619 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001620}
1621int 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)
1622{
1623 int ret = 0;
1624 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001625 if(g_lynq_qser_data_init_flag == 0)
1626 {
1627 if(err != NULL)
1628 {
1629 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1630 }
1631 return LYNQ_E_NO_INIT;
1632 }
xf.li4ab455d2024-07-30 01:21:56 -07001633 lynq_data_call_response_v11_t data_call_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001634 data_call_handle_get(profile_idx,&handle);
1635 ret = lynq_get_data_call_list(&handle,&data_call_info);
1636 if (ret == 0)
1637 {
1638 info->profile_idx = profile_idx;
1639 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001640 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 -07001641 {
xf.li0400b382024-06-05 19:20:36 -07001642 info->ip_family = QSER_DATA_CALL_TYPE_IPV4;
xf.li2fc84552023-06-23 05:26:47 -07001643 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001644 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001645 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1646 lynq_ipv4_aton_getinfo(&data_call_info,info);
1647 }
xf.li3c0a4752023-09-03 20:46:19 -07001648 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001649 {
xf.li0400b382024-06-05 19:20:36 -07001650 info->ip_family = QSER_DATA_CALL_TYPE_IPV6;
xf.li2fc84552023-06-23 05:26:47 -07001651 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001652 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001653 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1654 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1655 }
xf.li3c0a4752023-09-03 20:46:19 -07001656 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001657 {
xf.li0400b382024-06-05 19:20:36 -07001658 info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
xf.li2fc84552023-06-23 05:26:47 -07001659 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001660 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001661 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 -07001662#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001663 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001664#endif
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.li2fc84552023-06-23 05:26:47 -07001667 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 -07001668#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001669 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001670#endif
1671#ifdef MOBILETEK_TARGET_PLATFORM_T106
1672 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1673#endif
xf.li2fc84552023-06-23 05:26:47 -07001674 }
1675 else
1676 {
1677 LYERRLOG("useless qser_data_call_ip_family_e");
1678 }
1679 }
1680 return ret;
1681}
xf.lifb6134e2024-05-09 01:26:54 -07001682int check_pdp_type(qser_apn_pdp_type_e pdp_type)
1683{
1684 switch (pdp_type)
1685 {
1686 case QSER_APN_PDP_TYPE_IPV4:
1687 case QSER_APN_PDP_TYPE_PPP:
1688 case QSER_APN_PDP_TYPE_IPV6:
1689 case QSER_APN_PDP_TYPE_IPV4V6:
1690 return 0;
1691 default:
1692 return -1;
1693 }
1694}
1695int check_auth_proto(qser_apn_auth_proto_e auth_proto)
1696{
1697 switch (auth_proto)
1698 {
1699 case QSER_APN_AUTH_PROTO_DEFAULT:
1700 case QSER_APN_AUTH_PROTO_NONE:
1701 case QSER_APN_AUTH_PROTO_PAP:
1702 case QSER_APN_AUTH_PROTO_CHAP:
1703 case QSER_APN_AUTH_PROTO_PAP_CHAP:
1704 return 0;
1705 default:
1706 return -1;
1707 }
1708}
xf.li2fc84552023-06-23 05:26:47 -07001709int qser_apn_set(qser_apn_info_s *apn)
1710{
1711 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001712 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001713 if(g_lynq_qser_data_init_flag == 0)
1714 {
1715 return LYNQ_E_NO_INIT;
1716 }
xf.li4b18fa62023-12-19 19:38:10 -08001717 if (NULL == apn || apn->profile_idx == 0)
xf.li2fc84552023-06-23 05:26:47 -07001718 {
1719 LYERRLOG("apn set incoming paramters error");
1720 return RESULT_ERROR;
1721 }
xf.licb6cd282024-02-21 22:06:14 -08001722 ret = apn_db_handle_get(apn->profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001723 if(ret != 0)
1724 {
1725 LYERRLOG("handle set error");
1726 }
1727 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1728 {
1729 LYERRLOG("It has setup datacall");
1730 return RESULT_ERROR;
1731 }
xf.lifb6134e2024-05-09 01:26:54 -07001732
1733 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1734 {
1735 LYERRLOG("apn_name out of range\n");
1736 return RESULT_ERROR;
1737 }
1738 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1739 {
1740 LYERRLOG("username out of range\n");
1741 return RESULT_ERROR;
1742 }
1743 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1744 {
1745 LYERRLOG("password out of range\n");
1746 return RESULT_ERROR;
1747 }
1748 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1749 {
1750 LYERRLOG("apn_type out of range\n");
1751 return RESULT_ERROR;
1752 }
1753 if(check_pdp_type(apn->pdp_type) != 0)
1754 {
1755 LYERRLOG("pdp_type out of range\n");
1756 return RESULT_ERROR;
1757 }
1758 if(check_auth_proto(apn->auth_proto) != 0)
1759 {
1760 LYERRLOG("auth_proto out of range\n");
1761 return RESULT_ERROR;
1762 }
1763
xf.licb6cd282024-02-21 22:06:14 -08001764 ret = apn_db_modify(apn);
xf.li2fc84552023-06-23 05:26:47 -07001765 if (ret < 0)
1766 {
xf.licb6cd282024-02-21 22:06:14 -08001767 LYERRLOG("apn_db_modify error");
xf.li2fc84552023-06-23 05:26:47 -07001768 return ret;
1769 }
xf.li6c7e3972023-10-27 20:01:59 -07001770#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001771 int apn_id = 0;
1772 char tmp_id[12];
1773 char *outinfo = NULL;
1774 char normalprotocol[16];
1775 char authtype[32];
1776 outinfo = (char *)malloc(sizeof(char)*512);
1777 bzero(tmp_id,12);
1778 bzero(outinfo,512);
1779 apn_id = apn->profile_idx + apndb_offset;
1780 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1781 judge_pdp_type(apn->pdp_type,normalprotocol);
1782 judge_authtype(apn->auth_proto,authtype);
1783 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1784 LYINFLOG("[output]:%s",outinfo);
1785 free(outinfo);
1786 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001787#endif
1788 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001789}
1790
1791int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1792{
xf.lib33d4862023-12-13 00:40:37 -08001793 if(g_lynq_qser_data_init_flag == 0)
1794 {
1795 return LYNQ_E_NO_INIT;
1796 }
xf.licb6cd282024-02-21 22:06:14 -08001797 if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn)
xf.li2fc84552023-06-23 05:26:47 -07001798 {
1799 LYERRLOG("apn get incoming paramters error");
1800 return RESULT_ERROR;
1801 }
1802 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001803 ret = apn_db_query(profile_idx,apn);
xf.li2fc84552023-06-23 05:26:47 -07001804 if (ret < 0)
1805 {
xf.licb6cd282024-02-21 22:06:14 -08001806 LYERRLOG("apn_db_query error");
xf.li2fc84552023-06-23 05:26:47 -07001807 return ret;
1808 }
1809 return ret;
1810}
1811
1812int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1813{
1814 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001815
xf.lib33d4862023-12-13 00:40:37 -08001816 if(g_lynq_qser_data_init_flag == 0)
1817 {
1818 return LYNQ_E_NO_INIT;
1819 }
xf.li2fc84552023-06-23 05:26:47 -07001820 if (NULL == apn || NULL == profile_idx)
1821 {
1822 LYERRLOG("apn add incoming paramters error");
1823 return RESULT_ERROR;
1824 }
xf.lifb6134e2024-05-09 01:26:54 -07001825
1826 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1827 {
1828 LYERRLOG("apn_name out of range\n");
1829 return RESULT_ERROR;
1830 }
1831 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1832 {
1833 LYERRLOG("username out of range\n");
1834 return RESULT_ERROR;
1835 }
1836 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1837 {
1838 LYERRLOG("password out of range\n");
1839 return RESULT_ERROR;
1840 }
1841 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1842 {
1843 LYERRLOG("apn_type out of range\n");
1844 return RESULT_ERROR;
1845 }
1846 if(check_pdp_type(apn->pdp_type) != 0)
1847 {
1848 LYERRLOG("pdp_type out of range\n");
1849 return RESULT_ERROR;
1850 }
1851 if(check_auth_proto(apn->auth_proto) != 0)
1852 {
1853 LYERRLOG("auth_proto out of range\n");
1854 return RESULT_ERROR;
1855 }
xf.licb6cd282024-02-21 22:06:14 -08001856
1857 *profile_idx = 0;
1858 *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH);
1859 LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx);
1860 if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001861 {
xf.licb6cd282024-02-21 22:06:14 -08001862 LYINFLOG("[%s] apn full is false\n",__FUNCTION__);
1863 ret = apn_db_add((int)*profile_idx, apn);
1864 if (ret != 0)
1865 {
1866 LYERRLOG("apn_db_add error");
1867 return RESULT_ERROR;
1868 }
1869 else
1870 {
1871 return RESULT_OK;
1872 }
xf.li2fc84552023-06-23 05:26:47 -07001873 }
xf.licb6cd282024-02-21 22:06:14 -08001874 LYERRLOG("apn storage space is full!!!");
1875 return RESULT_ERROR;
xf.li6c7e3972023-10-27 20:01:59 -07001876#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001877 int apn_id = 0;
1878 char tmp_id[12];
1879 char *outinfo = NULL;
1880 char normalprotocol[16];
1881 char authtype[32];
1882 outinfo = (char *)malloc(sizeof(char)*512);
1883 bzero(tmp_id,12);
1884 bzero(outinfo,512);
1885 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1886 judge_pdp_type(apn->pdp_type,normalprotocol);
1887 judge_authtype(apn->auth_proto,authtype);
1888 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1889 LYINFLOG("[output]:%s",outinfo);
1890 free(outinfo);
1891 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001892#endif
1893 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001894}
1895
1896int qser_apn_del(unsigned char profile_idx)
1897{
xf.li87f6e6e2024-06-19 02:23:05 -07001898 int ret = 0;
1899 int handle = -1;
1900
1901 LYINFLOG("[%s] entry\n",__FUNCTION__);
xf.lib33d4862023-12-13 00:40:37 -08001902 if(g_lynq_qser_data_init_flag == 0)
1903 {
1904 return LYNQ_E_NO_INIT;
1905 }
xf.li4b18fa62023-12-19 19:38:10 -08001906 if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001907 {
1908 LYERRLOG("apn del incoming paramters error");
xf.li4b18fa62023-12-19 19:38:10 -08001909 return RESULT_ERROR;
xf.li2fc84552023-06-23 05:26:47 -07001910 }
xf.li87f6e6e2024-06-19 02:23:05 -07001911
xf.licb6cd282024-02-21 22:06:14 -08001912 ret = apn_db_handle_get(profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001913 if(ret != 0)
1914 {
1915 LYERRLOG("handle set error");
1916 }
1917 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1918 {
1919 LYERRLOG("It has setup datacall");
1920 return RESULT_ERROR;
1921 }
xf.licb6cd282024-02-21 22:06:14 -08001922 ret = apn_db_delete(profile_idx);
xf.li2fc84552023-06-23 05:26:47 -07001923 if (ret < 0)
1924 {
xf.licb6cd282024-02-21 22:06:14 -08001925 LYERRLOG("apn_db_delete error");
xf.li2fc84552023-06-23 05:26:47 -07001926 return ret;
1927 }
xf.li6c7e3972023-10-27 20:01:59 -07001928#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001929 int apn_id = 0;
1930 char tmp_id[12];
1931 char *outinfo = NULL;
1932 outinfo = (char *)malloc(sizeof(char)*512);
1933 bzero(tmp_id,12);
1934 bzero(outinfo,512);
1935 apn_id = profile_idx+apndb_offset;
1936 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1937 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1938 LYINFLOG("[output]:%s",outinfo);
1939 free(outinfo);
1940 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001941#endif
xf.li2fc84552023-06-23 05:26:47 -07001942 return ret;
1943}
1944
1945int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1946{
xf.lib33d4862023-12-13 00:40:37 -08001947 if(g_lynq_qser_data_init_flag == 0)
1948 {
1949 return LYNQ_E_NO_INIT;
1950 }
xf.li2fc84552023-06-23 05:26:47 -07001951 if (NULL == apn_list)
1952 {
1953 LYERRLOG("apn_list incoming paramters error");
1954 return RESULT_ERROR;
1955 }
1956 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001957 ret = apn_db_query_list(apn_list);
xf.li2fc84552023-06-23 05:26:47 -07001958 if (ret < 0)
1959 {
xf.licb6cd282024-02-21 22:06:14 -08001960 LYERRLOG("apn_db_query_list error");
xf.li2fc84552023-06-23 05:26:47 -07001961 return ret;
1962 }
1963 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001964}
you.chen21c62b72023-09-08 09:41:11 +08001965
1966DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1967