blob: 094547f14bb1784a237711734572f638e495c5d9 [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 {
88 LYINFLOG("ipv4 addresses = %s", tmp_char);
89 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 {
96 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
97 inet_aton(tmp_char,&(data_res->v4.pri_dns));
98 }
99 tmp_char = strsep(&dnses, dnses_separator);
100 if(tmp_char != NULL)
101 {
102 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
103 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 {
132 LYINFLOG("ipv6 addresses = %s", tmp_char);
133 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 {
139 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
140 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 {
145 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
146 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 {
178 LYINFLOG("ipv4 addresses = %s", tmp_char);
179 inet_aton(tmp_char,&(data_res->v4.ip));
180 }
181 tmp_char = strsep(&addresses, addresses_separator);
182 if(tmp_char != NULL)
183 {
184 LYINFLOG("ipv6 addresses = %s", tmp_char);
185 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 {
191 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
192 inet_aton(tmp_char,&(data_res->v4.pri_dns));
193 }
194 tmp_char = strsep(&dnses, dnses_separator);
195 if(tmp_char != NULL)
196 {
197 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
198 inet_aton(tmp_char, &(data_res->v4.sec_dns));
199 }
200 tmp_char = strsep(&dnses, dnses_separator);
201 if(tmp_char != NULL)
202 {
203 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
204 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 {
209 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
210 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.li03baf1f2023-12-19 21:30:38 -0800216 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip));
217 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns));
218 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns));
219
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));
224 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
225 , 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 {
244 LYINFLOG("ipv4 addresses = %s", tmp_char);
245 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 {
251 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
252 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
253 }
254 tmp_char = strsep(&dnses, dnses_separator);
255 if(tmp_char != NULL)
256 {
257 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
258 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
259 }
260 //get gateway
261 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
262 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
263
264 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
265 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
266 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
267#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 {
297 LYINFLOG("ipv6 addresses = %s", tmp_char);
298 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 {
304 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
305 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 {
310 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
311 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 {
347 LYINFLOG("ipv4 addresses = %s", tmp_char);
348 inet_aton(tmp_char,&(data_res->v4.addr.ip));
349 }
350 tmp_char = strsep(&addresses, addresses_separator);
351 if(tmp_char != NULL)
352 {
353 LYINFLOG("ipv6 addresses = %s", tmp_char);
354 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 {
360 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
361 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
362 }
363 tmp_char = strsep(&dnses, dnses_separator);
364 if(tmp_char != NULL)
365 {
366 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
367 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
368 }
369 tmp_char = strsep(&dnses, dnses_separator);
370 if(tmp_char != NULL)
371 {
372 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
373 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 {
378 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
379 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
385 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
xf.li03baf1f2023-12-19 21:30:38 -0800386 LYINFLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700387 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
388 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
389
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));
394 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
395 , 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++){
451 LYINFLOG("[%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
473 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
474 /* 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]);
497 LYINFLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]);
498
499 for(i=0; i<argc; i++){
500 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
501 }
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 {
543 LYINFLOG("index = apn_index\n");
544 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
575 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
576 /* 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++){
603 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
604 }
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
629 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
630 /* 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 }
705 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
706 /* 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 }
726 LYINFLOG("Table LYNQAPN created successfully\n");
727 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++){
739 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
740 }
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 }
761 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
762 /* 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 }
774 LYINFLOG("Table LYNQAPN check successfully\n");
775 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.li1bbfc7d2024-07-15 23:50:41 -0700793 int check_ret=0;
xf.licb6cd282024-02-21 22:06:14 -0800794 int table_ret=0;
xf.li87f6e6e2024-06-19 02:23:05 -0700795
796 pthread_mutex_init(&s_qser_data_database_mutex, NULL);
797
xf.licb6cd282024-02-21 22:06:14 -0800798 db_ret = create_apn_db(APN_DB_PATH);
799 if(db_ret==APN_DB_CREATE)
800 {
801 table_ret = create_apn_table(APN_DB_PATH);
802 if(table_ret!=0)
803 {
804 LYERRLOG("create apn table fail!!!");
805 return RESULT_ERROR;
806 }
807 apn_db_add(0, &default_apn);
808 }
809 else if(db_ret==APN_DB_READED)
810 {
xf.li1bbfc7d2024-07-15 23:50:41 -0700811 LYINFLOG("[%s] apn db has be build!!!",__FUNCTION__);
812 check_ret = check_apn_table(APN_DB_PATH);
813 if(check_ret == APN_TABLE_NEED_CREATE)
814 {
815 table_ret = create_apn_table(APN_DB_PATH);
816 if(table_ret!=0)
817 {
818 LYERRLOG("create apn table fail!!!");
819 return 1;
820 }
821 apn_db_add(0, &default_apn);
822 }
823 else if(check_ret == APN_TABLE_CREATE)
824 {
825 LYINFLOG("Table LYNQAPN has created");
826 }
827 else
828 {
829 LYERRLOG("check table fail!!!, ret = %d", check_ret);
830 }
xf.li0fd6acf2023-12-20 18:16:34 -0800831 }
832 else
833 {
xf.licb6cd282024-02-21 22:06:14 -0800834 LYERRLOG("init apn db fail!!!");
xf.li0fd6acf2023-12-20 18:16:34 -0800835 }
xf.li0fd6acf2023-12-20 18:16:34 -0800836 return RESULT_OK;
xf.li0fd6acf2023-12-20 18:16:34 -0800837}
xf.li2fc84552023-06-23 05:26:47 -0700838
xf.licb6cd282024-02-21 22:06:14 -0800839static int apn_db_handle_clean()
xf.li63b87e82024-01-04 00:43:35 -0800840{
xf.licb6cd282024-02-21 22:06:14 -0800841 char *zErrMsg = 0;
842 int rc;
xf.li63b87e82024-01-04 00:43:35 -0800843 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.liff415202024-09-19 23:08:09 -0700844 char sql[128]={0};
xf.li63b87e82024-01-04 00:43:35 -0800845
xf.licb6cd282024-02-21 22:06:14 -0800846 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700847 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800848 rc = sqlite3_open(APN_DB_PATH, &apnDb);
849 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800850 {
xf.licb6cd282024-02-21 22:06:14 -0800851 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700852 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800853 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800854 }
xf.licb6cd282024-02-21 22:06:14 -0800855
856 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
857 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700858 sprintf(sql,"UPDATE LYNQAPN SET HANDLE=%d", default_handle);
xf.licb6cd282024-02-21 22:06:14 -0800859 LYINFLOG("sql: %s\n", sql);
860 /* Execute SQL statement */
861 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
862 if( rc != SQLITE_OK )
xf.li63b87e82024-01-04 00:43:35 -0800863 {
xf.licb6cd282024-02-21 22:06:14 -0800864 LYERRLOG("SQL error: %s\n", zErrMsg);
865 sqlite3_free(zErrMsg);
866 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700867 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800868 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800869 }
xf.licb6cd282024-02-21 22:06:14 -0800870 LYINFLOG("clean apn table successfully\n");
871 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700872 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800873 return RESULT_OK;
874}
875
876static int find_unuse_apn_index(char *path)
877{
878 char *zErrMsg = 0;
879 int rc;
880 int count =1;
881 bool apn_usable = false;
882 char *sql;
883
884 memset(apn_indexs,0,sizeof(apn_indexs));
885 next_index = 0;
886 LYINFLOG("index = %p",apn_indexs);
887 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700888 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800889 rc = sqlite3_open(APN_DB_PATH, &apnDb);
890 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800891 {
xf.licb6cd282024-02-21 22:06:14 -0800892 LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700893 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800894 return -1;
xf.li63b87e82024-01-04 00:43:35 -0800895 }
896 else
897 {
xf.licb6cd282024-02-21 22:06:14 -0800898 LYINFLOG("Opened database successfully\n");
xf.li63b87e82024-01-04 00:43:35 -0800899 }
xf.li63b87e82024-01-04 00:43:35 -0800900
xf.licb6cd282024-02-21 22:06:14 -0800901 /* Create SQL statement */
902 sql = "SELECT ID from LYNQAPN";
903 /* Execute SQL statement */
904 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg);
905 if( rc != SQLITE_OK )
906 {
907 LYERRLOG("SQL error: %s\n", zErrMsg);
908 sqlite3_free(zErrMsg);
xf.lib5d82bf2024-03-09 01:54:50 -0800909 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700910 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800911 return -1;
912 }
913 else
914 {
915 LYINFLOG("Operation done successfully\n");
916 }
917 //indexs = temp_index;
918 LYINFLOG("index = %p",apn_indexs);
919 for(count;count<=QSER_APN_MAX_LIST;count++)
920 {
921 //if(apn_indexs[count-1]!=count)
922 LYINFLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count);
923 if(apn_indexs[count]!=count)
924 {
925 //apn_usable=true;
926 break;
927 }
928 }
929 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700930 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800931 LYINFLOG("count is %d\n", count);
932 return count;
xf.li63b87e82024-01-04 00:43:35 -0800933}
934
xf.licb6cd282024-02-21 22:06:14 -0800935static int apn_db_add(int profile_id, qser_apn_add_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700936{
xf.licb6cd282024-02-21 22:06:14 -0800937 char *zErrMsg = 0;
938 int rc;
xf.li0fd6acf2023-12-20 18:16:34 -0800939 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.licb6cd282024-02-21 22:06:14 -0800940 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700941 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800942 rc = sqlite3_open(APN_DB_PATH, &apnDb);
943 if( rc )
xf.li2fc84552023-06-23 05:26:47 -0700944 {
xf.licb6cd282024-02-21 22:06:14 -0800945 LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700946 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800947 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700948 }
xf.licb6cd282024-02-21 22:06:14 -0800949 LYINFLOG("[%s] Opened database successfully",__FUNCTION__);
950 /* Create SQL statement */
951 /* Execute SQL statement */
952 LYINFLOG("the profile id is %d\n", profile_id);
953 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);
954 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
xf.liff415202024-09-19 23:08:09 -0700955 sqlite3_free(sql);
xf.licb6cd282024-02-21 22:06:14 -0800956 if( rc != SQLITE_OK )
xf.li2fc84552023-06-23 05:26:47 -0700957 {
xf.licb6cd282024-02-21 22:06:14 -0800958 LYERRLOG( "SQL error: %s", zErrMsg);
959 sqlite3_free(zErrMsg);
960 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700961 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800962 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700963 }
xf.licb6cd282024-02-21 22:06:14 -0800964 LYINFLOG("write apn to apn db successfully");
965 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700966 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800967 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700968}
969
xf.licb6cd282024-02-21 22:06:14 -0800970static int apn_db_delete(unsigned char profile_idx)
xf.li2fc84552023-06-23 05:26:47 -0700971{
xf.licb6cd282024-02-21 22:06:14 -0800972 char *zErrMsg = 0;
973 int rc;
xf.liff415202024-09-19 23:08:09 -0700974 char sql[128]={0};
xf.li2fc84552023-06-23 05:26:47 -0700975
xf.licb6cd282024-02-21 22:06:14 -0800976 if(!lynq_check_index(profile_idx))
977 {
978 return LYNQ_E_APN_DB_FAIL;
979 }
980 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700981 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800982 rc = sqlite3_open(APN_DB_PATH, &apnDb);
983 if( rc )
984 {
985 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700986 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800987 return LYNQ_E_APN_DB_FAIL;
988 }
989
990 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
991 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700992 sprintf(sql,"DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800993 LYINFLOG("sql: %s\n", sql);
994 /* Execute SQL statement */
995 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
996 if( rc != SQLITE_OK )
997 {
998 LYERRLOG("SQL error: %s\n", zErrMsg);
999 sqlite3_free(zErrMsg);
1000 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001001 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001002 return LYNQ_E_APN_DB_FAIL;
1003 }
1004 LYINFLOG("delete apn %d successfully\n", profile_idx);
1005 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001006 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001007 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001008}
1009
xf.licb6cd282024-02-21 22:06:14 -08001010static int apn_db_modify(qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001011{
xf.licb6cd282024-02-21 22:06:14 -08001012 char *zErrMsg = 0;
1013 int rc;
xf.li2fc84552023-06-23 05:26:47 -07001014
xf.licb6cd282024-02-21 22:06:14 -08001015 if(!lynq_check_index(apn->profile_idx))
1016 {
1017 return LYNQ_E_APN_DB_FAIL;
1018 }
1019 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001020 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001021 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1022 if( rc )
1023 {
1024 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001025 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001026 return LYNQ_E_APN_DB_FAIL;
1027 }
1028
1029 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1030 /* Create SQL statement */
1031 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);
1032 LYINFLOG("sql: %s\n", sql);
1033 /* Execute SQL statement */
1034 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
xf.liff415202024-09-19 23:08:09 -07001035 sqlite3_free(sql);
xf.licb6cd282024-02-21 22:06:14 -08001036 if( rc != SQLITE_OK )
1037 {
1038 LYERRLOG("SQL error: %s\n", zErrMsg);
1039 sqlite3_free(zErrMsg);
1040 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001041 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001042 return LYNQ_E_APN_DB_FAIL;
1043 }
1044 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1045 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001046 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001047 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001048}
1049
xf.licb6cd282024-02-21 22:06:14 -08001050static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName)
xf.li2fc84552023-06-23 05:26:47 -07001051{
xf.licb6cd282024-02-21 22:06:14 -08001052 if(data==NULL)
xf.li2fc84552023-06-23 05:26:47 -07001053 {
xf.licb6cd282024-02-21 22:06:14 -08001054 return 1;
xf.li2fc84552023-06-23 05:26:47 -07001055 }
xf.licb6cd282024-02-21 22:06:14 -08001056 qser_apn_info_s* temp = (qser_apn_info_s *)data;
1057 for(int i=0; i<argc; i++){
1058 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001059 }
xf.licb6cd282024-02-21 22:06:14 -08001060 temp->profile_idx = atoi(argv[0]);
1061 temp->pdp_type = atoi(argv[1]);
1062 temp->auth_proto = atoi(argv[2]);
1063 memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE);
1064 memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE);
1065 memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE);
1066 memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE);
1067 LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0]));
1068 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001069}
xf.licb6cd282024-02-21 22:06:14 -08001070static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001071{
xf.licb6cd282024-02-21 22:06:14 -08001072 char *zErrMsg = 0;
1073 int rc;
xf.liff415202024-09-19 23:08:09 -07001074 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -08001075
1076 if(!lynq_check_index(profile_idx))
xf.li2fc84552023-06-23 05:26:47 -07001077 {
xf.licb6cd282024-02-21 22:06:14 -08001078 return LYNQ_E_APN_DB_FAIL;
1079 }
1080 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001081 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001082 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1083 if( rc )
1084 {
1085 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001086 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001087 return LYNQ_E_APN_DB_FAIL;
1088 }
1089
1090 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1091 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001092 sprintf(sql,"SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -08001093 LYINFLOG("sql: %s\n", sql);
1094 /* Execute SQL statement */
1095 rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg);
1096 if( rc != SQLITE_OK )
1097 {
1098 LYERRLOG("SQL error: %s\n", zErrMsg);
1099 sqlite3_free(zErrMsg);
1100 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001101 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001102 return LYNQ_E_APN_DB_FAIL;
1103 }
1104 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1105 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001106 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001107 return 0;
1108}
1109static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName)
1110{
1111 int i;
1112
1113 //apn_count++;
1114
1115 qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data;
1116 for(i=0; i<argc; i++){
1117 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001118 }
1119
xf.licb6cd282024-02-21 22:06:14 -08001120 temp->apn[temp->cnt].profile_idx = atoi(argv[0]);
1121 temp->apn[temp->cnt].pdp_type = atoi(argv[1]);
1122 temp->apn[temp->cnt].auth_proto = atoi(argv[2]);
1123 memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE);
1124 memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE);
1125 memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE);
1126 memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE);
1127 temp->cnt++;
1128 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001129}
xf.licb6cd282024-02-21 22:06:14 -08001130static int apn_db_query_list(qser_apn_info_list_s *apn_list)
1131{
1132 char *zErrMsg = 0;
1133 int rc;
xf.liff415202024-09-19 23:08:09 -07001134 char sql[128]={0};
xf.li2fc84552023-06-23 05:26:47 -07001135
xf.licb6cd282024-02-21 22:06:14 -08001136 /* Open database */
1137 apn_count = 0;
1138 apn_list->cnt = 0;
xf.li87f6e6e2024-06-19 02:23:05 -07001139 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001140 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1141 if( rc )
1142 {
1143 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001144 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001145 return LYNQ_E_APN_DB_FAIL;
1146 }
1147
1148 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1149 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001150 sprintf(sql,"SELECT * from LYNQAPN");
xf.licb6cd282024-02-21 22:06:14 -08001151 LYINFLOG("sql: %s\n", sql);
1152 /* Execute SQL statement */
1153 rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg);
1154 if( rc != SQLITE_OK )
1155 {
1156 LYERRLOG("SQL error: %s\n", zErrMsg);
1157 sqlite3_free(zErrMsg);
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 LYNQ_E_APN_DB_FAIL;
1161 }
1162 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001163 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001164 return 0;
1165}
1166// **************apn DB end****************************
xf.li2fc84552023-06-23 05:26:47 -07001167void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
1168{
1169 switch (pdp_type)
1170 {
1171 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -08001172#ifdef MOBILETEK_TARGET_PLATFORM_T106
1173 strcpy(out_pdp_type,"IP");
1174#else
xf.li2fc84552023-06-23 05:26:47 -07001175 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -08001176#endif
xf.li2fc84552023-06-23 05:26:47 -07001177 break;
1178 case QSER_APN_PDP_TYPE_PPP:
1179 strcpy(out_pdp_type,"PPP");
1180 break;
1181 case QSER_APN_PDP_TYPE_IPV6:
1182 strcpy(out_pdp_type,"IPV6");
1183 break;
1184 case QSER_APN_PDP_TYPE_IPV4V6:
1185 strcpy(out_pdp_type,"IPV4V6");
1186 break;
1187 default:
1188 strcpy(out_pdp_type,"NULL");
1189 break;
1190 }
1191 return;
1192}
1193void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
1194{
1195 switch (auth_proto)
1196 {
1197 case QSER_APN_AUTH_PROTO_DEFAULT:
xf.lifb6134e2024-05-09 01:26:54 -07001198 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001199 break;
1200 case QSER_APN_AUTH_PROTO_NONE:
xf.lifb6134e2024-05-09 01:26:54 -07001201 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001202 break;
1203 case QSER_APN_AUTH_PROTO_PAP:
xf.lifb6134e2024-05-09 01:26:54 -07001204 strcpy(out_proto,"1");
xf.li2fc84552023-06-23 05:26:47 -07001205 break;
1206 case QSER_APN_AUTH_PROTO_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001207 strcpy(out_proto,"2");
xf.li2fc84552023-06-23 05:26:47 -07001208 break;
1209 case QSER_APN_AUTH_PROTO_PAP_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001210 strcpy(out_proto,"3");
xf.li2fc84552023-06-23 05:26:47 -07001211 break;
1212 default:
xf.lifb6134e2024-05-09 01:26:54 -07001213 strcpy(out_proto,"NULL");
xf.li2fc84552023-06-23 05:26:47 -07001214 break;
1215 }
1216 return ;
1217}
1218
1219int data_call_handle_get(const char profile_idx,int *handle)
1220{
1221 int num = LYNQ_APN_CHANNEL_MAX;
1222 int table_num = 0;
1223 lynq_apn_info **apn_table = NULL;
1224 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001225 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001226 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1227 if (NULL == apn_table)
1228 {
1229 LYERRLOG("malloc apn_table fail ");
1230 return RESULT_ERROR;
1231 }
1232 for(int i =0;i<10;i++)
1233 {
1234 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1235 if (apn_table[i]==NULL)
1236 {
1237 for (int n=0;n<i;n++)
1238 {
1239 free(apn_table[n]);
1240 }
1241 return RESULT_ERROR;
1242 }
1243 memset(apn_table[i],0,sizeof(lynq_apn_info));
1244 }
1245 lynq_get_apn_table(&table_num,apn_table);
1246 memset(&apn,0,sizeof(qser_apn_info_s));
xf.licb6cd282024-02-21 22:06:14 -08001247 ret = apn_db_query(profile_idx,&apn);
xf.li0fc26502023-09-16 02:10:17 -07001248 if (ret < 0)
1249 {
xf.licb6cd282024-02-21 22:06:14 -08001250 LYERRLOG("apn_db_query error");
xf.li0fc26502023-09-16 02:10:17 -07001251 return ret;
1252 }
xf.li2fc84552023-06-23 05:26:47 -07001253 for (int j = 0;j < table_num;j++)
1254 {
1255 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1256 {
1257 *handle = apn_table[j]->index;
1258 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1259 break;
1260 }
1261 }
1262
1263 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1264 {
1265 if (apn_table[i]!=NULL)
1266 {
1267 free(apn_table[i]);
1268 apn_table[i]=NULL;
1269 }
1270 }
1271 free(apn_table);
1272 apn_table=NULL;
1273 LYINFLOG("data_call_handle_get end");
1274 return RESULT_OK;
1275}
1276
xf.li789f7a12024-10-24 03:02:37 -07001277static void acquire_wake_lock()
1278{
1279 int ret = 0;
1280
1281 ret = system("echo data_call_wakelock 5000000000 > /sys/power/wake_lock");//timeout 5s
1282 if(ret != 0)
1283 {
1284 LYERRLOG("acquire_wake_lock error !!!");
1285 }
1286 return;
1287}
1288
1289static void release_wake_lock()
1290{
1291 int ret = 0;
1292
1293 ret = system("echo data_call_wakelock > /sys/power/wake_unlock");
1294 if(ret != 0)
1295 {
1296 LYERRLOG("release_wake_lock error !!!");
1297 }
1298 return;
1299}
1300
xf.li2fc84552023-06-23 05:26:47 -07001301void *thread_wait_cb_status(void)
1302{
1303 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001304 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001305 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001306 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001307 qser_data_call_state_s data_cb_state;
1308 while (s_qser_data_cb_thread_status)
1309 {
xf.li6b0d8502023-09-04 18:49:12 -07001310 ret = lynq_wait_data_call_state_change(&handle);
1311 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
1312 if(s_qser_data_cb_thread_status == 0)
1313 {
1314 return NULL;
1315 }
1316 else if(ret < 0)
1317 {
1318 continue;
1319 }
xf.li789f7a12024-10-24 03:02:37 -07001320 acquire_wake_lock();
xf.li8535bc02023-12-12 23:28:35 -08001321 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
1322 memset(&data_urc_info, 0, sizeof(data_urc_info));
1323 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001324 lynq_get_data_call_list(&handle,&data_urc_info);
1325 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001326 //data_cb_state.profile_idx = (char)handle;
xf.licb6cd282024-02-21 22:06:14 -08001327 apn_db_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li87f6e6e2024-06-19 02:23:05 -07001328 LYINFLOG("[thread_wait_cb_status]: callback profile_idx is %d\n", data_cb_state.profile_idx);
xf.li8535bc02023-12-12 23:28:35 -08001329 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",
1330 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
1331 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
1332 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -07001333 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001334 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001335 {
1336 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1337 }
1338 else if (!strcmp(data_urc_info.type,"IPV6"))
1339 {
1340 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1341 }
xf.li8535bc02023-12-12 23:28:35 -08001342 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001343 {
1344 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1345 }
1346 else
1347 {
xf.li8535bc02023-12-12 23:28:35 -08001348 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001349 }
1350
xf.li8535bc02023-12-12 23:28:35 -08001351 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001352 {
1353 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1354 }
1355 else
1356 {
1357 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.licb6cd282024-02-21 22:06:14 -08001358 ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001359 if(ret != 0)
1360 {
1361 LYERRLOG("handle set error");
1362 }
xf.li2fc84552023-06-23 05:26:47 -07001363 }
1364 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1365 {
1366 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1367 }
1368 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1369 {
1370 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1371 }
1372 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1373 {
xf.li3c0a4752023-09-03 20:46:19 -07001374#ifdef MOBILETEK_TARGET_PLATFORM_T106
1375 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1376#else
xf.li2fc84552023-06-23 05:26:47 -07001377 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001378#endif
xf.li2fc84552023-06-23 05:26:47 -07001379 }
1380 else
1381 {
xf.li789f7a12024-10-24 03:02:37 -07001382 release_wake_lock();
xf.li2fc84552023-06-23 05:26:47 -07001383 LYERRLOG("unknow ip_family");
1384 continue;
1385 }
1386 if (s_data_call_cb != NULL)
1387 {
xf.li789f7a12024-10-24 03:02:37 -07001388 s_data_call_cb(&data_cb_state);
1389 release_wake_lock();
1390 LYINFLOG("[%s] call back s_data_call_cb end", __FUNCTION__);
xf.li2fc84552023-06-23 05:26:47 -07001391 }
1392 }
1393 return NULL;
1394}
1395
1396int qser_cb_pthread_create()
1397{
xf.lib5d82bf2024-03-09 01:54:50 -08001398 pthread_attr_t attr;
xf.li2fc84552023-06-23 05:26:47 -07001399 int ret;
1400 s_qser_data_cb_thread_status = 1;
xf.lib5d82bf2024-03-09 01:54:50 -08001401
1402 pthread_attr_init(&attr);
1403 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1404
1405 ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL);
xf.li2fc84552023-06-23 05:26:47 -07001406 if (ret < 0)
1407 {
1408 LYERRLOG("pthread create fail");
1409 s_qser_data_cb_thread_status = 0;
1410 return RESULT_ERROR;
1411 }
xf.lib5d82bf2024-03-09 01:54:50 -08001412 pthread_attr_destroy(&attr);
xf.li2fc84552023-06-23 05:26:47 -07001413 return RESULT_OK;
1414}
1415
1416void qser_cb_pthread_cancel()
1417{
xf.li2fc84552023-06-23 05:26:47 -07001418 s_qser_data_cb_thread_status = 0;
1419 if (s_cb_tid != -1)
1420 {
xf.li6b0d8502023-09-04 18:49:12 -07001421 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001422 }
1423 return;
1424}
xf.li2fc84552023-06-23 05:26:47 -07001425int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1426{
1427 int ret = 0;
1428 int utoken = 0;
1429 if (NULL == evt_cb)
1430 {
1431 LYERRLOG("init incoming paramters error");
1432 return RESULT_ERROR;
1433 }
xf.li09b46db2024-03-13 19:21:18 -07001434 if(g_lynq_qser_data_init_flag == 1)
1435 {
1436 LYERRLOG("init twice is not allowed");
1437 return RESULT_ERROR;
1438 }
xf.li2fc84552023-06-23 05:26:47 -07001439 ret = lynq_init_data(utoken);
1440 if (ret != RESULT_OK)
1441 {
xf.li6b0d8502023-09-04 18:49:12 -07001442 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001443 s_data_call_cb = NULL;
1444 return RESULT_ERROR;
1445 }
xf.li6b0d8502023-09-04 18:49:12 -07001446 qser_cb_pthread_create();
xf.licb6cd282024-02-21 22:06:14 -08001447 ret = init_apn_db();
1448 if(ret != RESULT_OK)
xf.lie3f55f42023-12-01 22:47:33 -08001449 {
xf.licb6cd282024-02-21 22:06:14 -08001450 LYERRLOG("init apn db error");
xf.lie3f55f42023-12-01 22:47:33 -08001451 return RESULT_ERROR;
1452 }
xf.licb6cd282024-02-21 22:06:14 -08001453
1454 ret = apn_db_handle_clean();
xf.li63b87e82024-01-04 00:43:35 -08001455 if(ret != RESULT_OK)
1456 {
1457 LYERRLOG("clean handle error");
1458 return RESULT_ERROR;
1459 }
xf.li09b46db2024-03-13 19:21:18 -07001460 s_data_call_cb = evt_cb;
xf.lib33d4862023-12-13 00:40:37 -08001461 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001462 return RESULT_OK;
1463}
1464
1465void qser_data_call_destroy(void)
1466{
xf.li6b0d8502023-09-04 18:49:12 -07001467 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001468 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001469 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001470 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001471 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001472 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001473 return ;
1474}
1475
1476int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1477{
1478 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001479 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001480 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001481 if(g_lynq_qser_data_init_flag == 0)
1482 {
1483 if(err != NULL)
1484 {
1485 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1486 }
1487 return LYNQ_E_NO_INIT;
1488 }
xf.li2fc84552023-06-23 05:26:47 -07001489 if (NULL == data_call || NULL == err)
1490 {
1491 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001492 if(err != NULL)
1493 {
1494 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1495 }
xf.li2fc84552023-06-23 05:26:47 -07001496 return ret;
1497 }
1498 if (data_call->profile_idx == 0)
1499 {
1500 ret = lynq_setup_data_call(&handle);
1501 }
1502 else
1503 {
1504 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001505 char auth_proto[16];
xf.li2fc84552023-06-23 05:26:47 -07001506 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001507 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1508 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li0fc26502023-09-16 02:10:17 -07001509 if (ret != 0)
1510 {
1511 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001512 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001513 return ret;
1514 }
xf.li2fc84552023-06-23 05:26:47 -07001515 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001516 judge_authtype(apn_info.auth_proto,auth_proto);
1517 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 -07001518 }
xf.lic12b3702023-11-22 22:39:01 -08001519 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001520 {
1521 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1522 }
xf.li0fd6acf2023-12-20 18:16:34 -08001523 else
1524 {
xf.licb6cd282024-02-21 22:06:14 -08001525 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001526 if(error != 0)
1527 {
1528 LYERRLOG("handle set error");
1529 }
1530 }
xf.li2fc84552023-06-23 05:26:47 -07001531 return ret;
1532}
1533
xf.li8535bc02023-12-12 23:28:35 -08001534int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1535{
1536 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001537 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001538 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001539 if(g_lynq_qser_data_init_flag == 0)
1540 {
1541 if(err != NULL)
1542 {
1543 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1544 }
1545 return LYNQ_E_NO_INIT;
1546 }
xf.li8535bc02023-12-12 23:28:35 -08001547 if (NULL == data_call || NULL == err)
1548 {
1549 LYERRLOG("call start incoming paramters error");
1550 if(err != NULL)
1551 {
1552 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1553 }
1554 return ret;
1555 }
1556 if (data_call->profile_idx == 0)
1557 {
1558 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1559 }
1560 else
1561 {
1562 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001563 char auth_proto[16];
xf.li8535bc02023-12-12 23:28:35 -08001564 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001565 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1566 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li8535bc02023-12-12 23:28:35 -08001567 if (ret != 0)
1568 {
1569 LYERRLOG("qser_apn_get error");
1570 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1571 return ret;
1572 }
1573 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001574 judge_authtype(apn_info.auth_proto,auth_proto);
1575 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 -08001576 }
1577 if (ret != 0)
1578 {
1579 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1580 }
xf.li0fd6acf2023-12-20 18:16:34 -08001581 else
1582 {
xf.licb6cd282024-02-21 22:06:14 -08001583 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001584 if(error != 0)
1585 {
1586 LYERRLOG("handle set error");
1587 }
1588 }
xf.li8535bc02023-12-12 23:28:35 -08001589 return ret;
1590}
1591
xf.li2fc84552023-06-23 05:26:47 -07001592int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1593{
1594 int ret = 0;
1595 int handle = -1;
1596
xf.lib33d4862023-12-13 00:40:37 -08001597 if(g_lynq_qser_data_init_flag == 0)
1598 {
1599 if(err != NULL)
1600 {
1601 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1602 }
1603 return LYNQ_E_NO_INIT;
1604 }
xf.li2fc84552023-06-23 05:26:47 -07001605 if (NULL == err)
1606 {
1607 LYERRLOG("call stop incoming paramters error");
1608 return ret;
1609 }
xf.lic12b3702023-11-22 22:39:01 -08001610 ret = data_call_handle_get(profile_idx,&handle);
1611 if(ret != 0)
1612 {
1613 LYERRLOG("datacall handle get error");
1614 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1615 return ret;
1616 }
xf.li2fc84552023-06-23 05:26:47 -07001617 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001618 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001619 {
1620 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001621 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001622 }
xy.hee2daacc2023-09-18 00:57:51 -07001623 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001624}
1625int 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)
1626{
1627 int ret = 0;
1628 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001629 if(g_lynq_qser_data_init_flag == 0)
1630 {
1631 if(err != NULL)
1632 {
1633 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1634 }
1635 return LYNQ_E_NO_INIT;
1636 }
xf.li4ab455d2024-07-30 01:21:56 -07001637 lynq_data_call_response_v11_t data_call_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001638 data_call_handle_get(profile_idx,&handle);
1639 ret = lynq_get_data_call_list(&handle,&data_call_info);
1640 if (ret == 0)
1641 {
1642 info->profile_idx = profile_idx;
1643 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001644 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 -07001645 {
xf.li0400b382024-06-05 19:20:36 -07001646 info->ip_family = QSER_DATA_CALL_TYPE_IPV4;
xf.li2fc84552023-06-23 05:26:47 -07001647 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001648 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001649 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1650 lynq_ipv4_aton_getinfo(&data_call_info,info);
1651 }
xf.li3c0a4752023-09-03 20:46:19 -07001652 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001653 {
xf.li0400b382024-06-05 19:20:36 -07001654 info->ip_family = QSER_DATA_CALL_TYPE_IPV6;
xf.li2fc84552023-06-23 05:26:47 -07001655 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001656 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001657 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1658 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1659 }
xf.li3c0a4752023-09-03 20:46:19 -07001660 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001661 {
xf.li0400b382024-06-05 19:20:36 -07001662 info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
xf.li2fc84552023-06-23 05:26:47 -07001663 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001664 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001665 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 -07001666#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001667 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001668#endif
xf.li2fc84552023-06-23 05:26:47 -07001669 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001670 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001671 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 -07001672#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001673 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001674#endif
1675#ifdef MOBILETEK_TARGET_PLATFORM_T106
1676 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1677#endif
xf.li2fc84552023-06-23 05:26:47 -07001678 }
1679 else
1680 {
1681 LYERRLOG("useless qser_data_call_ip_family_e");
1682 }
1683 }
1684 return ret;
1685}
xf.li7aca5c02025-01-02 02:48:47 -08001686#ifdef MOBILETEK_TARGET_PLATFORM_T106
1687int qser_set_initial_apnname(char *apnname)
1688{
1689 int ret = -1;
1690
1691 if(g_lynq_qser_data_init_flag == 0)
1692 {
1693 return LYNQ_E_NO_INIT;
1694 }
1695
1696 ret = lynq_init_attach_apn(apnname, "IP", "0", "null", "null");
1697 return ret;
1698}
1699int qser_get_initial_apnname(char apnname[QSER_APN_NAME_SIZE])
1700{
1701 int ret = -1;
1702 lynq_apn_list_response apnList = {-1, "", "", "", -1, -1, -1, -1, -1, -1};
1703
1704 if(g_lynq_qser_data_init_flag == 0)
1705 {
1706 return LYNQ_E_NO_INIT;
1707 }
1708
1709 if(apnname == NULL)
1710 {
1711 LYERRLOG("[%s][%d] apnname is NULL",__FUNCTION__,__LINE__);
1712 }
1713 ret = lynq_get_apn_list(1, &apnList);
1714 if(ret == 0)
1715 {
1716 memcpy(apnname, apnList.apn, sizeof(apnList.apn));
1717 LYINFLOG("qser_get_initial_apnname: %s", apnname);
1718 }
1719 return ret;
1720}
1721#endif
xf.lifb6134e2024-05-09 01:26:54 -07001722int check_pdp_type(qser_apn_pdp_type_e pdp_type)
1723{
1724 switch (pdp_type)
1725 {
1726 case QSER_APN_PDP_TYPE_IPV4:
1727 case QSER_APN_PDP_TYPE_PPP:
1728 case QSER_APN_PDP_TYPE_IPV6:
1729 case QSER_APN_PDP_TYPE_IPV4V6:
1730 return 0;
1731 default:
1732 return -1;
1733 }
1734}
1735int check_auth_proto(qser_apn_auth_proto_e auth_proto)
1736{
1737 switch (auth_proto)
1738 {
1739 case QSER_APN_AUTH_PROTO_DEFAULT:
1740 case QSER_APN_AUTH_PROTO_NONE:
1741 case QSER_APN_AUTH_PROTO_PAP:
1742 case QSER_APN_AUTH_PROTO_CHAP:
1743 case QSER_APN_AUTH_PROTO_PAP_CHAP:
1744 return 0;
1745 default:
1746 return -1;
1747 }
1748}
xf.li2fc84552023-06-23 05:26:47 -07001749int qser_apn_set(qser_apn_info_s *apn)
1750{
1751 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001752 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001753 if(g_lynq_qser_data_init_flag == 0)
1754 {
1755 return LYNQ_E_NO_INIT;
1756 }
xf.li4b18fa62023-12-19 19:38:10 -08001757 if (NULL == apn || apn->profile_idx == 0)
xf.li2fc84552023-06-23 05:26:47 -07001758 {
1759 LYERRLOG("apn set incoming paramters error");
1760 return RESULT_ERROR;
1761 }
xf.licb6cd282024-02-21 22:06:14 -08001762 ret = apn_db_handle_get(apn->profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001763 if(ret != 0)
1764 {
1765 LYERRLOG("handle set error");
1766 }
1767 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1768 {
1769 LYERRLOG("It has setup datacall");
1770 return RESULT_ERROR;
1771 }
xf.lifb6134e2024-05-09 01:26:54 -07001772
1773 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1774 {
1775 LYERRLOG("apn_name out of range\n");
1776 return RESULT_ERROR;
1777 }
1778 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1779 {
1780 LYERRLOG("username out of range\n");
1781 return RESULT_ERROR;
1782 }
1783 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1784 {
1785 LYERRLOG("password out of range\n");
1786 return RESULT_ERROR;
1787 }
1788 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1789 {
1790 LYERRLOG("apn_type out of range\n");
1791 return RESULT_ERROR;
1792 }
1793 if(check_pdp_type(apn->pdp_type) != 0)
1794 {
1795 LYERRLOG("pdp_type out of range\n");
1796 return RESULT_ERROR;
1797 }
1798 if(check_auth_proto(apn->auth_proto) != 0)
1799 {
1800 LYERRLOG("auth_proto out of range\n");
1801 return RESULT_ERROR;
1802 }
1803
xf.licb6cd282024-02-21 22:06:14 -08001804 ret = apn_db_modify(apn);
xf.li2fc84552023-06-23 05:26:47 -07001805 if (ret < 0)
1806 {
xf.licb6cd282024-02-21 22:06:14 -08001807 LYERRLOG("apn_db_modify error");
xf.li2fc84552023-06-23 05:26:47 -07001808 return ret;
1809 }
xf.li6c7e3972023-10-27 20:01:59 -07001810#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001811 int apn_id = 0;
1812 char tmp_id[12];
1813 char *outinfo = NULL;
1814 char normalprotocol[16];
1815 char authtype[32];
1816 outinfo = (char *)malloc(sizeof(char)*512);
1817 bzero(tmp_id,12);
1818 bzero(outinfo,512);
1819 apn_id = apn->profile_idx + apndb_offset;
1820 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1821 judge_pdp_type(apn->pdp_type,normalprotocol);
1822 judge_authtype(apn->auth_proto,authtype);
1823 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1824 LYINFLOG("[output]:%s",outinfo);
1825 free(outinfo);
1826 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001827#endif
1828 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001829}
1830
1831int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1832{
xf.lib33d4862023-12-13 00:40:37 -08001833 if(g_lynq_qser_data_init_flag == 0)
1834 {
1835 return LYNQ_E_NO_INIT;
1836 }
xf.licb6cd282024-02-21 22:06:14 -08001837 if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn)
xf.li2fc84552023-06-23 05:26:47 -07001838 {
1839 LYERRLOG("apn get incoming paramters error");
1840 return RESULT_ERROR;
1841 }
1842 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001843 ret = apn_db_query(profile_idx,apn);
xf.li2fc84552023-06-23 05:26:47 -07001844 if (ret < 0)
1845 {
xf.licb6cd282024-02-21 22:06:14 -08001846 LYERRLOG("apn_db_query error");
xf.li2fc84552023-06-23 05:26:47 -07001847 return ret;
1848 }
1849 return ret;
1850}
1851
1852int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1853{
1854 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001855
xf.lib33d4862023-12-13 00:40:37 -08001856 if(g_lynq_qser_data_init_flag == 0)
1857 {
1858 return LYNQ_E_NO_INIT;
1859 }
xf.li2fc84552023-06-23 05:26:47 -07001860 if (NULL == apn || NULL == profile_idx)
1861 {
1862 LYERRLOG("apn add incoming paramters error");
1863 return RESULT_ERROR;
1864 }
xf.lifb6134e2024-05-09 01:26:54 -07001865
1866 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1867 {
1868 LYERRLOG("apn_name out of range\n");
1869 return RESULT_ERROR;
1870 }
1871 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1872 {
1873 LYERRLOG("username out of range\n");
1874 return RESULT_ERROR;
1875 }
1876 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1877 {
1878 LYERRLOG("password out of range\n");
1879 return RESULT_ERROR;
1880 }
1881 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1882 {
1883 LYERRLOG("apn_type out of range\n");
1884 return RESULT_ERROR;
1885 }
1886 if(check_pdp_type(apn->pdp_type) != 0)
1887 {
1888 LYERRLOG("pdp_type out of range\n");
1889 return RESULT_ERROR;
1890 }
1891 if(check_auth_proto(apn->auth_proto) != 0)
1892 {
1893 LYERRLOG("auth_proto out of range\n");
1894 return RESULT_ERROR;
1895 }
xf.licb6cd282024-02-21 22:06:14 -08001896
1897 *profile_idx = 0;
1898 *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH);
1899 LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx);
1900 if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001901 {
xf.licb6cd282024-02-21 22:06:14 -08001902 LYINFLOG("[%s] apn full is false\n",__FUNCTION__);
1903 ret = apn_db_add((int)*profile_idx, apn);
1904 if (ret != 0)
1905 {
1906 LYERRLOG("apn_db_add error");
1907 return RESULT_ERROR;
1908 }
1909 else
1910 {
1911 return RESULT_OK;
1912 }
xf.li2fc84552023-06-23 05:26:47 -07001913 }
xf.licb6cd282024-02-21 22:06:14 -08001914 LYERRLOG("apn storage space is full!!!");
1915 return RESULT_ERROR;
xf.li6c7e3972023-10-27 20:01:59 -07001916#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001917 int apn_id = 0;
1918 char tmp_id[12];
1919 char *outinfo = NULL;
1920 char normalprotocol[16];
1921 char authtype[32];
1922 outinfo = (char *)malloc(sizeof(char)*512);
1923 bzero(tmp_id,12);
1924 bzero(outinfo,512);
1925 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1926 judge_pdp_type(apn->pdp_type,normalprotocol);
1927 judge_authtype(apn->auth_proto,authtype);
1928 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1929 LYINFLOG("[output]:%s",outinfo);
1930 free(outinfo);
1931 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001932#endif
1933 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001934}
1935
1936int qser_apn_del(unsigned char profile_idx)
1937{
xf.li87f6e6e2024-06-19 02:23:05 -07001938 int ret = 0;
1939 int handle = -1;
1940
1941 LYINFLOG("[%s] entry\n",__FUNCTION__);
xf.lib33d4862023-12-13 00:40:37 -08001942 if(g_lynq_qser_data_init_flag == 0)
1943 {
1944 return LYNQ_E_NO_INIT;
1945 }
xf.li4b18fa62023-12-19 19:38:10 -08001946 if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001947 {
1948 LYERRLOG("apn del incoming paramters error");
xf.li4b18fa62023-12-19 19:38:10 -08001949 return RESULT_ERROR;
xf.li2fc84552023-06-23 05:26:47 -07001950 }
xf.li87f6e6e2024-06-19 02:23:05 -07001951
xf.licb6cd282024-02-21 22:06:14 -08001952 ret = apn_db_handle_get(profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001953 if(ret != 0)
1954 {
1955 LYERRLOG("handle set error");
1956 }
1957 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1958 {
1959 LYERRLOG("It has setup datacall");
1960 return RESULT_ERROR;
1961 }
xf.licb6cd282024-02-21 22:06:14 -08001962 ret = apn_db_delete(profile_idx);
xf.li2fc84552023-06-23 05:26:47 -07001963 if (ret < 0)
1964 {
xf.licb6cd282024-02-21 22:06:14 -08001965 LYERRLOG("apn_db_delete error");
xf.li2fc84552023-06-23 05:26:47 -07001966 return ret;
1967 }
xf.li6c7e3972023-10-27 20:01:59 -07001968#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001969 int apn_id = 0;
1970 char tmp_id[12];
1971 char *outinfo = NULL;
1972 outinfo = (char *)malloc(sizeof(char)*512);
1973 bzero(tmp_id,12);
1974 bzero(outinfo,512);
1975 apn_id = profile_idx+apndb_offset;
1976 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1977 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1978 LYINFLOG("[output]:%s",outinfo);
1979 free(outinfo);
1980 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001981#endif
xf.li2fc84552023-06-23 05:26:47 -07001982 return ret;
1983}
1984
1985int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1986{
xf.lib33d4862023-12-13 00:40:37 -08001987 if(g_lynq_qser_data_init_flag == 0)
1988 {
1989 return LYNQ_E_NO_INIT;
1990 }
xf.li2fc84552023-06-23 05:26:47 -07001991 if (NULL == apn_list)
1992 {
1993 LYERRLOG("apn_list incoming paramters error");
1994 return RESULT_ERROR;
1995 }
1996 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001997 ret = apn_db_query_list(apn_list);
xf.li2fc84552023-06-23 05:26:47 -07001998 if (ret < 0)
1999 {
xf.licb6cd282024-02-21 22:06:14 -08002000 LYERRLOG("apn_db_query_list error");
xf.li2fc84552023-06-23 05:26:47 -07002001 return ret;
2002 }
2003 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07002004}
you.chen21c62b72023-09-08 09:41:11 +08002005
2006DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
2007