blob: 995b7e4da97d5446071a57b32238c63e7368134c [file] [log] [blame]
xf.li2fc84552023-06-23 05:26:47 -07001#include <stdio.h>
2#include <stdint.h>
3#include <sys/types.h>
4#include <arpa/inet.h>
5#include <string.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <log/log.h>
9#include <libdata/lynq_data.h>
10#include <liblog/lynq_deflog.h>
11#include <pthread.h>
xf.licb6cd282024-02-21 22:06:14 -080012#include <sqlite3.h>
xf.li2fc84552023-06-23 05:26:47 -070013#include "lynq-qser-data.h"
14
15#define USER_LOG_TAG "LYNQ_QSER_DATA"
xf.licb6cd282024-02-21 22:06:14 -080016#define APN_DB_PATH "/mnt/userdata/apn.db"
17#define APN_DB_READED 0
18#define APN_DB_ERR 1
19#define APN_DB_CREATE 2
xf.li2fc84552023-06-23 05:26:47 -070020#define RESULT_OK (0)
21#define RESULT_ERROR (-1)
22
xf.lib33d4862023-12-13 00:40:37 -080023typedef enum{
xf.licb6cd282024-02-21 22:06:14 -080024 LYNQ_E_NO_INIT=9002,
25 LYNQ_E_APN_DB_FAIL=9003
xf.lib33d4862023-12-13 00:40:37 -080026}LYNQ_E;
27
28static int g_lynq_qser_data_init_flag = 0;
xf.li2fc84552023-06-23 05:26:47 -070029static pthread_t s_cb_tid = -1;
30static int s_qser_data_cb_thread_status = 0;
31static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
xf.li87f6e6e2024-06-19 02:23:05 -070032static pthread_mutex_t s_qser_data_database_mutex = PTHREAD_MUTEX_INITIALIZER;
xf.li2fc84552023-06-23 05:26:47 -070033static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER;
34
xf.li2fc84552023-06-23 05:26:47 -070035
36static qser_data_call_evt_cb_t s_data_call_cb = NULL;
xf.licb6cd282024-02-21 22:06:14 -080037static sqlite3* apnDb;
38qser_apn_add_s default_apn = {QSER_APN_PDP_TYPE_IPV4V6, QSER_APN_AUTH_PROTO_DEFAULT, "default", "NULL", "NULL", "default"};
39int apn_indexs[LYNQ_APN_CHANNEL_MAX]={0};
40int next_index = 0;
41int apn_count = 0;
xf.li2fc84552023-06-23 05:26:47 -070042const int apndb_offset = 683;
43
xf.licb6cd282024-02-21 22:06:14 -080044static int init_apn_db();
45static int create_apn_db(char *path);
46static int create_apn_table(char*path);
47static int has_apn_db_created(char *path,sqlite3* apnDb_l);
48static int apn_db_handle_clean();
49
50static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName);
51static int lynq_check_index(unsigned char index);
52static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName);
53static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx);
54static int apn_db_handle_set(unsigned char profile_idx, int handle);
55static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName);
56static int apn_db_handle_get(unsigned char profile_idx, int *handle);
57
58static int find_unuse_apn_index(char *path);
59static int apn_db_add(int profile_id, qser_apn_add_s *apn);
60static int apn_db_delete(unsigned char profile_idx);
61static int apn_db_modify(qser_apn_info_s *apn);
62static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName);
63static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn);
64static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName);
65static int apn_db_query_list(qser_apn_info_list_s *apn_list);
66
xf.li2fc84552023-06-23 05:26:47 -070067void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
68{
xf.li3c0a4752023-09-03 20:46:19 -070069#ifdef MOBILETEK_TARGET_PLATFORM_T106
70 char *tmp_char = NULL;
71 char *addresses = NULL;
72 char *dnses = NULL;
73 const char addresses_separator[2] = "/";
74 const char dnses_separator[2] = " ";
75
76 addresses = libdata->addresses;
77 dnses = libdata->dnses;
78 //get addresses
79 tmp_char = strsep(&addresses, addresses_separator);
80 if(tmp_char != NULL)
81 {
82 LYINFLOG("ipv4 addresses = %s", tmp_char);
83 inet_aton(tmp_char,&(data_res->v4.ip));
84 }
85
86 //get dnses
87 tmp_char = strsep(&dnses, dnses_separator);
88 if(tmp_char != NULL)
89 {
90 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
91 inet_aton(tmp_char,&(data_res->v4.pri_dns));
92 }
93 tmp_char = strsep(&dnses, dnses_separator);
94 if(tmp_char != NULL)
95 {
96 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
97 inet_aton(tmp_char, &(data_res->v4.sec_dns));
98 }
99 //get gateway
100 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
101
102#else
xf.li2fc84552023-06-23 05:26:47 -0700103 inet_aton(libdata->addresses,&(data_res->v4.ip));
104 inet_aton(libdata->gateways,&(data_res->v4.gateway));
105 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
106 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700107#endif
xf.li2fc84552023-06-23 05:26:47 -0700108 return ;
109}
110
111void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
112{
xf.li3c0a4752023-09-03 20:46:19 -0700113#ifdef MOBILETEK_TARGET_PLATFORM_T106
114 char *tmp_char = NULL;
115 char *addresses = NULL;
116 char *dnses = NULL;
117 const char addresses_separator[2] = "/";
118 const char dnses_separator[2] = " ";
119
120 addresses = libdata->addresses;
121 dnses = libdata->dnses;
122 //get addresses
123 tmp_char = strsep(&addresses, addresses_separator);
124 if(tmp_char != NULL)
125 {
126 LYINFLOG("ipv6 addresses = %s", tmp_char);
127 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
128 }
129 //get dnses
130 tmp_char = strsep(&dnses, dnses_separator);
131 if(tmp_char != NULL)
132 {
133 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
134 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
135 }
136 tmp_char = strsep(&dnses, dnses_separator);
137 if(tmp_char != NULL)
138 {
139 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
140 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
141 }
142 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
143#else
xf.li2fc84552023-06-23 05:26:47 -0700144 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
145 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
146 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
147 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700148#endif
149
150 return ;
151}
152
153void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
154{
155 char *tmp_char = NULL;
156 char *addresses = NULL;
157 char *dnses = NULL;
158 const char addresses_separator[2] = "/";
159 const char dnses_separator[2] = " ";
160
xf.li03baf1f2023-12-19 21:30:38 -0800161 char buf_ip[64] = {0};
162 char buf_gateway[64] = {0};
163 char buf_pri_dns[64] = {0};
164 char buf_sec_dns[64] = {0};
165
xf.li3c0a4752023-09-03 20:46:19 -0700166 addresses = libdata->addresses;
167 dnses = libdata->dnses;
168 //get addresses
169 tmp_char = strsep(&addresses, addresses_separator);
170 if(tmp_char != NULL)
171 {
172 LYINFLOG("ipv4 addresses = %s", tmp_char);
173 inet_aton(tmp_char,&(data_res->v4.ip));
174 }
175 tmp_char = strsep(&addresses, addresses_separator);
176 if(tmp_char != NULL)
177 {
178 LYINFLOG("ipv6 addresses = %s", tmp_char);
179 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
180 }
181 //get dnses
182 tmp_char = strsep(&dnses, dnses_separator);
183 if(tmp_char != NULL)
184 {
185 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
186 inet_aton(tmp_char,&(data_res->v4.pri_dns));
187 }
188 tmp_char = strsep(&dnses, dnses_separator);
189 if(tmp_char != NULL)
190 {
191 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
192 inet_aton(tmp_char, &(data_res->v4.sec_dns));
193 }
194 tmp_char = strsep(&dnses, dnses_separator);
195 if(tmp_char != NULL)
196 {
197 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
198 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
199 }
200 tmp_char = strsep(&dnses, dnses_separator);
201 if(tmp_char != NULL)
202 {
203 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
204 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
205 }
206 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800207 inet_aton(libdata->gateways,&(data_res->v4.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700208 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
209
xf.li03baf1f2023-12-19 21:30:38 -0800210 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip));
211 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns));
212 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns));
213
214 inet_ntop(AF_INET6, &(data_res->v6.ip), buf_ip, sizeof(buf_ip));
215 inet_ntop(AF_INET6, &(data_res->v6.gateway), buf_gateway, sizeof(buf_gateway));
216 inet_ntop(AF_INET6, &(data_res->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
217 inet_ntop(AF_INET6, &(data_res->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
218 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
219 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
xf.li2fc84552023-06-23 05:26:47 -0700220 return ;
221}
222
223void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
224{
xf.li3c0a4752023-09-03 20:46:19 -0700225#ifdef MOBILETEK_TARGET_PLATFORM_T106
226 char *tmp_char = NULL;
227 char *addresses = NULL;
228 char *dnses = NULL;
229 const char addresses_separator[2] = "/";
230 const char dnses_separator[2] = " ";
231
232 addresses = libdata->addresses;
233 dnses = libdata->dnses;
234 //get addresses
235 tmp_char = strsep(&addresses, addresses_separator);
236 if(tmp_char != NULL)
237 {
238 LYINFLOG("ipv4 addresses = %s", tmp_char);
239 inet_aton(tmp_char,&(data_res->v4.addr.ip));
240 }
241 //get dnses
242 tmp_char = strsep(&dnses, dnses_separator);
243 if(tmp_char != NULL)
244 {
245 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
246 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
247 }
248 tmp_char = strsep(&dnses, dnses_separator);
249 if(tmp_char != NULL)
250 {
251 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
252 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
253 }
254 //get gateway
255 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
256 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
257
258 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
259 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
260 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
261#else
xf.li2fc84552023-06-23 05:26:47 -0700262 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
263 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
264 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
265 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700266#endif
xf.li2fc84552023-06-23 05:26:47 -0700267 data_res->v4.stats.pkts_tx = 0;
268 data_res->v4.stats.pkts_rx = 0;
269 data_res->v4.stats.bytes_tx = 0;
270 data_res->v4.stats.bytes_rx = 0;
271 data_res->v4.stats.pkts_dropped_tx = 0;
272 data_res->v4.stats.pkts_dropped_rx = 0;
273 return ;
274}
275
276void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
277{
xf.li3c0a4752023-09-03 20:46:19 -0700278#ifdef MOBILETEK_TARGET_PLATFORM_T106
279 char *tmp_char = NULL;
280 char *addresses = NULL;
281 char *dnses = NULL;
282 const char addresses_separator[2] = "/";
283 const char dnses_separator[2] = " ";
284
285 addresses = libdata->addresses;
286 dnses = libdata->dnses;
287 //get addresses
288 tmp_char = strsep(&addresses, addresses_separator);
289 if(tmp_char != NULL)
290 {
291 LYINFLOG("ipv6 addresses = %s", tmp_char);
292 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
293 }
294 //get dnses
295 tmp_char = strsep(&dnses, dnses_separator);
296 if(tmp_char != NULL)
297 {
298 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
299 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
300 }
301 tmp_char = strsep(&dnses, dnses_separator);
302 if(tmp_char != NULL)
303 {
304 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
305 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
306 }
307 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
308#else
xf.li2fc84552023-06-23 05:26:47 -0700309 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
310 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
311 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
312 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700313#endif
314 data_res->v6.stats.pkts_tx = 0;
315 data_res->v6.stats.pkts_rx = 0;
316 data_res->v6.stats.bytes_tx = 0;
317 data_res->v6.stats.bytes_rx = 0;
318 data_res->v6.stats.pkts_dropped_tx = 0;
319 data_res->v6.stats.pkts_dropped_rx = 0;
320 return ;
321}
322void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
323{
324 char *tmp_char = NULL;
325 char *addresses = NULL;
326 char *dnses = NULL;
327 const char addresses_separator[2] = "/";
328 const char dnses_separator[2] = " ";
329
330 char buf_ip[64] = {0};
331 char buf_gateway[64] = {0};
332 char buf_pri_dns[64] = {0};
333 char buf_sec_dns[64] = {0};
334
335 addresses = libdata->addresses;
336 dnses = libdata->dnses;
337 //get addresses
338 tmp_char = strsep(&addresses, addresses_separator);
339 if(tmp_char != NULL)
340 {
341 LYINFLOG("ipv4 addresses = %s", tmp_char);
342 inet_aton(tmp_char,&(data_res->v4.addr.ip));
343 }
344 tmp_char = strsep(&addresses, addresses_separator);
345 if(tmp_char != NULL)
346 {
347 LYINFLOG("ipv6 addresses = %s", tmp_char);
348 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
349 }
350 //get dnses
351 tmp_char = strsep(&dnses, dnses_separator);
352 if(tmp_char != NULL)
353 {
354 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
355 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
356 }
357 tmp_char = strsep(&dnses, dnses_separator);
358 if(tmp_char != NULL)
359 {
360 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
361 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
362 }
363 tmp_char = strsep(&dnses, dnses_separator);
364 if(tmp_char != NULL)
365 {
366 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
367 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
368 }
369 tmp_char = strsep(&dnses, dnses_separator);
370 if(tmp_char != NULL)
371 {
372 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
373 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
374 }
375 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800376 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700377 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
378
379 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
xf.li03baf1f2023-12-19 21:30:38 -0800380 LYINFLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700381 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
382 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
383
384 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
385 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
386 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
387 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
388 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
389 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
390 data_res->v4.stats.pkts_tx = 0;
391 data_res->v4.stats.pkts_rx = 0;
392 data_res->v4.stats.bytes_tx = 0;
393 data_res->v4.stats.bytes_rx = 0;
394 data_res->v4.stats.pkts_dropped_tx = 0;
395 data_res->v4.stats.pkts_dropped_rx = 0;
396
xf.li2fc84552023-06-23 05:26:47 -0700397 data_res->v6.stats.pkts_tx = 0;
398 data_res->v6.stats.pkts_rx = 0;
399 data_res->v6.stats.bytes_tx = 0;
400 data_res->v6.stats.bytes_rx = 0;
401 data_res->v6.stats.pkts_dropped_tx = 0;
402 data_res->v6.stats.pkts_dropped_rx = 0;
403 return ;
404}
405
406void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
407{
xf.lib5dc0632023-11-30 18:20:35 -0800408 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700409 {
410 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
411 data_res->v4.reconnect = 1;
412 }
413 else
414 {
415 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
416 data_res->v4.reconnect = 0;
417 }
418 return ;
419}
420
421void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
422{
xf.lib5dc0632023-11-30 18:20:35 -0800423 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700424 {
425 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
426 data_res->v6.reconnect = 1;
427 }
428 else
429 {
430 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
431 data_res->v6.reconnect = 0;
432 }
433 return ;
434}
435
xf.licb6cd282024-02-21 22:06:14 -0800436// ****************apn DB start******************
437static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName)
xf.li0fd6acf2023-12-20 18:16:34 -0800438{
xf.licb6cd282024-02-21 22:06:14 -0800439 if(data==NULL)
xf.li0fd6acf2023-12-20 18:16:34 -0800440 {
xf.licb6cd282024-02-21 22:06:14 -0800441 return 1;
xf.li0fd6acf2023-12-20 18:16:34 -0800442 }
xf.licb6cd282024-02-21 22:06:14 -0800443 int *temp = (int *)data;
444 for(int i=0; i<argc; i++){
445 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li0fd6acf2023-12-20 18:16:34 -0800446 }
xf.licb6cd282024-02-21 22:06:14 -0800447 *temp = atoi(argv[0]);
448 return 0;
449}
450static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx)
451{
452 char *zErrMsg = 0;
453 int rc;
454 int idx = 0;
455
456 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700457 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800458 rc = sqlite3_open(APN_DB_PATH, &apnDb);
459 if( rc )
xf.li0fd6acf2023-12-20 18:16:34 -0800460 {
xf.licb6cd282024-02-21 22:06:14 -0800461 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700462 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800463 return LYNQ_E_APN_DB_FAIL;
464 }
465
466 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
467 /* Create SQL statement */
468 char *sql = sqlite3_mprintf("SELECT ID from LYNQAPN WHERE HANDLE=%d", handle);
469 LYINFLOG("sql: %s\n", sql);
470 /* Execute SQL statement */
471 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_profile_cb, &idx, &zErrMsg);
472 if( rc != SQLITE_OK )
473 {
474 LYERRLOG("SQL error: %s\n", zErrMsg);
475 sqlite3_free(zErrMsg);
476 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700477 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800478 return LYNQ_E_APN_DB_FAIL;
479 };
480 *profile_idx = (unsigned char)idx;
481 LYINFLOG("get idx %d successfully\n", *profile_idx);
482 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700483 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800484 return 0;
485}
486static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName){
487 int i;
488
489 apn_indexs[atoi(argv[0])] = atoi(argv[0]);
490 LYINFLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]);
491
492 for(i=0; i<argc; i++){
493 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
494 }
495 return 0;
496}
497/**
498 * @brief Check whether the ID exists in the database
499 *
500 * @param index
501 * @return int
502 * find:turn 1
503 * not find:turn 0
504 */
505static int lynq_check_index(unsigned char index)
506{
507 memset(apn_indexs,0,sizeof(apn_indexs));
508 next_index = 0;
509 char *zErrMsg = 0;
510 int rc;
511 char sql[128]={0};
512 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700513 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800514 rc = sqlite3_open(APN_DB_PATH, &apnDb);
515 if( rc )
516 {
517 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700518 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800519 return LYNQ_E_APN_DB_FAIL;
520 }
521 sprintf(sql,"%s", "SELECT * from LYNQAPN");
522 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback, NULL, &zErrMsg);
523 if( rc != SQLITE_OK )
524 {
525 LYERRLOG("SQL error: %s\n", zErrMsg);
526 sqlite3_free(zErrMsg);
527 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700528 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800529 return LYNQ_E_APN_DB_FAIL;
530 }
531 //for(int cnt = 0; cnt < next_index;cnt++)
532 for(int cnt = 0; cnt <= QSER_APN_MAX_LIST; cnt++)
533 {
534 if(index == apn_indexs[cnt])
535 {
536 LYINFLOG("index = apn_index\n");
537 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700538 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800539 return 1;
540 }
541 }
542 LYINFLOG("cant find the index %d\n", index);
543 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700544 pthread_mutex_unlock(&s_qser_data_database_mutex);
545
xf.licb6cd282024-02-21 22:06:14 -0800546 return 0;
547}
548
549static int apn_db_handle_set(unsigned char profile_idx, int handle)
550{
551 char *zErrMsg = 0;
552 int rc;
553 //char sql[128]={0};
554 if(!lynq_check_index(profile_idx))
555 {
556 return LYNQ_E_APN_DB_FAIL;
557 }
558 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700559 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800560 rc = sqlite3_open(APN_DB_PATH, &apnDb);
561 if( rc )
562 {
563 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700564 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800565 return LYNQ_E_APN_DB_FAIL;
566 }
567
568 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
569 /* Create SQL statement */
570 //sql = "SELECT * from LYNQAPN";
571 char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d WHERE ID=%d", handle, (int)profile_idx);
572 LYINFLOG("sql: %s\n", sql);
573 /* Execute SQL statement */
574 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
575 if( rc != SQLITE_OK )
576 {
577 LYERRLOG("SQL error: %s\n", zErrMsg);
578 sqlite3_free(zErrMsg);
579 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700580 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800581 return LYNQ_E_APN_DB_FAIL;
582 }
583 LYINFLOG("update apn %d successfully\n", profile_idx);
584 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700585 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800586 return 0;
587}
588static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName)
589{
590 if(data==NULL)
591 {
592 return 1;
593 }
594 int *temp = (int *)data;
595 for(int i=0; i<argc; i++){
596 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
597 }
598 *temp = atoi(argv[0]);
599 LYINFLOG("The handle is %d\n", *temp);
600 return 0;
601}
602static int apn_db_handle_get(unsigned char profile_idx, int *handle)
603{
604 char *zErrMsg = 0;
605 int rc;
606
607 //char sql[128]={0};
608 if(!lynq_check_index(profile_idx))
609 {
610 return LYNQ_E_APN_DB_FAIL;
611 }
612 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700613 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800614 rc = sqlite3_open(APN_DB_PATH, &apnDb);
615 if( rc )
616 {
617 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700618 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800619 return LYNQ_E_APN_DB_FAIL;
620 }
621
622 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
623 /* Create SQL statement */
624 char *sql = sqlite3_mprintf("SELECT HANDLE from LYNQAPN WHERE ID=%d", (int)profile_idx);
625 LYINFLOG("sql: %s\n", sql);
626 /* Execute SQL statement */
627 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_cb, handle, &zErrMsg);
628 if( rc != SQLITE_OK )
629 {
630 LYERRLOG("SQL error: %s\n", zErrMsg);
631 sqlite3_free(zErrMsg);
632 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700633 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800634 return LYNQ_E_APN_DB_FAIL;
635 }
636 LYINFLOG("get idx %d successfully\n", *handle);
637 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700638 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800639 return 0;
640}
641
642static int has_apn_db_created(char *path,sqlite3* apnDb_l)
643{
644 if (path == NULL || strlen(path) == 0)
645 {
646 LYERRLOG("initApnDb error with null path!");
647 return APN_DB_ERR;
648 }
649 int rc = sqlite3_open_v2(path, &apnDb_l, SQLITE_OPEN_READWRITE,NULL);
650 if (rc == SQLITE_OK)
651 {
652 LYINFLOG("check init success!");
xf.lib5d82bf2024-03-09 01:54:50 -0800653 sqlite3_close_v2(apnDb_l);
xf.licb6cd282024-02-21 22:06:14 -0800654 return APN_DB_READED;
655 }
656 else
657 {
658 LYERRLOG("db has not create %s!", sqlite3_errmsg(apnDb_l));
659 sqlite3_close_v2(apnDb_l);
660 return APN_DB_ERR;
661 }
662}
663static int create_apn_db(char *path)
664{
665 if (path == NULL || strlen(path) == 0) {
666 LYERRLOG("initApnDb error with null path!");
667 return APN_DB_ERR;
668 }
669 if(APN_DB_READED==has_apn_db_created(path,apnDb))
670 {
671 return APN_DB_READED;
672 }
673 int rc = sqlite3_open(path, &apnDb);
674 if (rc != SQLITE_OK) {
675 LYERRLOG("initDb failed %d", sqlite3_errcode(apnDb));
676 return APN_DB_ERR;
677 } else {
678 LYINFLOG("create db in %s", path);
679 }
680 sqlite3_close(apnDb);
681 return APN_DB_CREATE;
682}
683static int create_apn_table(char*path)
684{
685 char *zErrMsg = 0;
686 int rc;
687 char *sql;
688
689 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700690 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800691 rc = sqlite3_open(path, &apnDb);
692 if( rc )
693 {
694 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700695 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800696 return 1;
697 }
698 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
699 /* Create SQL statement */
700 sql = "CREATE TABLE LYNQAPN( \
701 ID INT NOT NULL, \
702 PDP_TYPE INT NOT NULL, \
703 AUTH_PROTO INT NOT NULL, \
704 APN_NAME TEXT NOT NULL, \
705 USERNAME TEXT NOT NULL,\
706 PASSWORD TEXT NOT NULL, \
707 APN_TYPE TEXT PRIMARY KEY NOT NULL, \
708 HANDLE INT NOT NULL)";
709 /* Execute SQL statement */
710 rc = sqlite3_exec(apnDb, sql, NULL, 0, &zErrMsg);
711 if( rc != SQLITE_OK )
712 {
713 LYERRLOG("SQL error: %s\n", zErrMsg);
714 sqlite3_free(zErrMsg);
715 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700716 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800717 return 1;
718 }
719 LYINFLOG("Table LYNQAPN created successfully\n");
720 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700721 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800722 return 0;
723}
724static int init_apn_db()
725{
726 int db_ret=0;
727 int table_ret=0;
xf.li87f6e6e2024-06-19 02:23:05 -0700728
729 pthread_mutex_init(&s_qser_data_database_mutex, NULL);
730
xf.licb6cd282024-02-21 22:06:14 -0800731 db_ret = create_apn_db(APN_DB_PATH);
732 if(db_ret==APN_DB_CREATE)
733 {
734 table_ret = create_apn_table(APN_DB_PATH);
735 if(table_ret!=0)
736 {
737 LYERRLOG("create apn table fail!!!");
738 return RESULT_ERROR;
739 }
740 apn_db_add(0, &default_apn);
741 }
742 else if(db_ret==APN_DB_READED)
743 {
744 LYERRLOG("[%s] apn db has be build!!!",__FUNCTION__);
xf.li0fd6acf2023-12-20 18:16:34 -0800745 }
746 else
747 {
xf.licb6cd282024-02-21 22:06:14 -0800748 LYERRLOG("init apn db fail!!!");
xf.li0fd6acf2023-12-20 18:16:34 -0800749 }
xf.li0fd6acf2023-12-20 18:16:34 -0800750 return RESULT_OK;
xf.li0fd6acf2023-12-20 18:16:34 -0800751}
xf.li2fc84552023-06-23 05:26:47 -0700752
xf.licb6cd282024-02-21 22:06:14 -0800753static int apn_db_handle_clean()
xf.li63b87e82024-01-04 00:43:35 -0800754{
xf.licb6cd282024-02-21 22:06:14 -0800755 char *zErrMsg = 0;
756 int rc;
xf.li63b87e82024-01-04 00:43:35 -0800757 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li63b87e82024-01-04 00:43:35 -0800758
xf.licb6cd282024-02-21 22:06:14 -0800759 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700760 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800761 rc = sqlite3_open(APN_DB_PATH, &apnDb);
762 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800763 {
xf.licb6cd282024-02-21 22:06:14 -0800764 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700765 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800766 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800767 }
xf.licb6cd282024-02-21 22:06:14 -0800768
769 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
770 /* Create SQL statement */
771 char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d", default_handle);
772 LYINFLOG("sql: %s\n", sql);
773 /* Execute SQL statement */
774 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
775 if( rc != SQLITE_OK )
xf.li63b87e82024-01-04 00:43:35 -0800776 {
xf.licb6cd282024-02-21 22:06:14 -0800777 LYERRLOG("SQL error: %s\n", zErrMsg);
778 sqlite3_free(zErrMsg);
779 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700780 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800781 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800782 }
xf.licb6cd282024-02-21 22:06:14 -0800783 LYINFLOG("clean apn table successfully\n");
784 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700785 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800786 return RESULT_OK;
787}
788
789static int find_unuse_apn_index(char *path)
790{
791 char *zErrMsg = 0;
792 int rc;
793 int count =1;
794 bool apn_usable = false;
795 char *sql;
796
797 memset(apn_indexs,0,sizeof(apn_indexs));
798 next_index = 0;
799 LYINFLOG("index = %p",apn_indexs);
800 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700801 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800802 rc = sqlite3_open(APN_DB_PATH, &apnDb);
803 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800804 {
xf.licb6cd282024-02-21 22:06:14 -0800805 LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700806 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800807 return -1;
xf.li63b87e82024-01-04 00:43:35 -0800808 }
809 else
810 {
xf.licb6cd282024-02-21 22:06:14 -0800811 LYINFLOG("Opened database successfully\n");
xf.li63b87e82024-01-04 00:43:35 -0800812 }
xf.li63b87e82024-01-04 00:43:35 -0800813
xf.licb6cd282024-02-21 22:06:14 -0800814 /* Create SQL statement */
815 sql = "SELECT ID from LYNQAPN";
816 /* Execute SQL statement */
817 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg);
818 if( rc != SQLITE_OK )
819 {
820 LYERRLOG("SQL error: %s\n", zErrMsg);
821 sqlite3_free(zErrMsg);
xf.lib5d82bf2024-03-09 01:54:50 -0800822 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700823 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800824 return -1;
825 }
826 else
827 {
828 LYINFLOG("Operation done successfully\n");
829 }
830 //indexs = temp_index;
831 LYINFLOG("index = %p",apn_indexs);
832 for(count;count<=QSER_APN_MAX_LIST;count++)
833 {
834 //if(apn_indexs[count-1]!=count)
835 LYINFLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count);
836 if(apn_indexs[count]!=count)
837 {
838 //apn_usable=true;
839 break;
840 }
841 }
842 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700843 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800844 LYINFLOG("count is %d\n", count);
845 return count;
xf.li63b87e82024-01-04 00:43:35 -0800846}
847
xf.licb6cd282024-02-21 22:06:14 -0800848static int apn_db_add(int profile_id, qser_apn_add_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700849{
xf.licb6cd282024-02-21 22:06:14 -0800850 char *zErrMsg = 0;
851 int rc;
xf.li0fd6acf2023-12-20 18:16:34 -0800852 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.licb6cd282024-02-21 22:06:14 -0800853 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700854 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800855 rc = sqlite3_open(APN_DB_PATH, &apnDb);
856 if( rc )
xf.li2fc84552023-06-23 05:26:47 -0700857 {
xf.licb6cd282024-02-21 22:06:14 -0800858 LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700859 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800860 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700861 }
xf.licb6cd282024-02-21 22:06:14 -0800862 LYINFLOG("[%s] Opened database successfully",__FUNCTION__);
863 /* Create SQL statement */
864 /* Execute SQL statement */
865 LYINFLOG("the profile id is %d\n", profile_id);
866 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);
867 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
868 if( rc != SQLITE_OK )
xf.li2fc84552023-06-23 05:26:47 -0700869 {
xf.licb6cd282024-02-21 22:06:14 -0800870 LYERRLOG( "SQL error: %s", zErrMsg);
871 sqlite3_free(zErrMsg);
872 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700873 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800874 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700875 }
xf.licb6cd282024-02-21 22:06:14 -0800876 LYINFLOG("write apn to apn db successfully");
877 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700878 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800879 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700880}
881
xf.licb6cd282024-02-21 22:06:14 -0800882static int apn_db_delete(unsigned char profile_idx)
xf.li2fc84552023-06-23 05:26:47 -0700883{
xf.licb6cd282024-02-21 22:06:14 -0800884 char *zErrMsg = 0;
885 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700886
xf.licb6cd282024-02-21 22:06:14 -0800887 if(!lynq_check_index(profile_idx))
888 {
889 return LYNQ_E_APN_DB_FAIL;
890 }
891 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700892 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800893 rc = sqlite3_open(APN_DB_PATH, &apnDb);
894 if( rc )
895 {
896 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700897 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800898 return LYNQ_E_APN_DB_FAIL;
899 }
900
901 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
902 /* Create SQL statement */
903 //sql = "SELECT * from LYNQAPN";
xf.li87f6e6e2024-06-19 02:23:05 -0700904 char *sql = sqlite3_mprintf("DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800905 LYINFLOG("sql: %s\n", sql);
906 /* Execute SQL statement */
907 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
908 if( rc != SQLITE_OK )
909 {
910 LYERRLOG("SQL error: %s\n", zErrMsg);
911 sqlite3_free(zErrMsg);
912 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700913 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800914 return LYNQ_E_APN_DB_FAIL;
915 }
916 LYINFLOG("delete apn %d successfully\n", profile_idx);
917 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700918 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800919 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700920}
921
xf.licb6cd282024-02-21 22:06:14 -0800922static int apn_db_modify(qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700923{
xf.licb6cd282024-02-21 22:06:14 -0800924 char *zErrMsg = 0;
925 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700926
xf.licb6cd282024-02-21 22:06:14 -0800927 if(!lynq_check_index(apn->profile_idx))
928 {
929 return LYNQ_E_APN_DB_FAIL;
930 }
931 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700932 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800933 rc = sqlite3_open(APN_DB_PATH, &apnDb);
934 if( rc )
935 {
936 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700937 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800938 return LYNQ_E_APN_DB_FAIL;
939 }
940
941 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
942 /* Create SQL statement */
943 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);
944 LYINFLOG("sql: %s\n", sql);
945 /* Execute SQL statement */
946 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
947 if( rc != SQLITE_OK )
948 {
949 LYERRLOG("SQL error: %s\n", zErrMsg);
950 sqlite3_free(zErrMsg);
951 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700952 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800953 return LYNQ_E_APN_DB_FAIL;
954 }
955 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
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 0;
xf.li2fc84552023-06-23 05:26:47 -0700959}
960
xf.licb6cd282024-02-21 22:06:14 -0800961static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName)
xf.li2fc84552023-06-23 05:26:47 -0700962{
xf.licb6cd282024-02-21 22:06:14 -0800963 if(data==NULL)
xf.li2fc84552023-06-23 05:26:47 -0700964 {
xf.licb6cd282024-02-21 22:06:14 -0800965 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700966 }
xf.licb6cd282024-02-21 22:06:14 -0800967 qser_apn_info_s* temp = (qser_apn_info_s *)data;
968 for(int i=0; i<argc; i++){
969 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -0700970 }
xf.licb6cd282024-02-21 22:06:14 -0800971 temp->profile_idx = atoi(argv[0]);
972 temp->pdp_type = atoi(argv[1]);
973 temp->auth_proto = atoi(argv[2]);
974 memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE);
975 memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE);
976 memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE);
977 memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE);
978 LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0]));
979 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700980}
xf.licb6cd282024-02-21 22:06:14 -0800981static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700982{
xf.licb6cd282024-02-21 22:06:14 -0800983 char *zErrMsg = 0;
984 int rc;
985
986 if(!lynq_check_index(profile_idx))
xf.li2fc84552023-06-23 05:26:47 -0700987 {
xf.licb6cd282024-02-21 22:06:14 -0800988 return LYNQ_E_APN_DB_FAIL;
989 }
990 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700991 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800992 rc = sqlite3_open(APN_DB_PATH, &apnDb);
993 if( rc )
994 {
995 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700996 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800997 return LYNQ_E_APN_DB_FAIL;
998 }
999
1000 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1001 /* Create SQL statement */
1002 char *sql = sqlite3_mprintf("SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx);
1003 LYINFLOG("sql: %s\n", sql);
1004 /* Execute SQL statement */
1005 rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg);
1006 if( rc != SQLITE_OK )
1007 {
1008 LYERRLOG("SQL error: %s\n", zErrMsg);
1009 sqlite3_free(zErrMsg);
1010 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001011 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001012 return LYNQ_E_APN_DB_FAIL;
1013 }
1014 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1015 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001016 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001017 return 0;
1018}
1019static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName)
1020{
1021 int i;
1022
1023 //apn_count++;
1024
1025 qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data;
1026 for(i=0; i<argc; i++){
1027 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001028 }
1029
xf.licb6cd282024-02-21 22:06:14 -08001030 temp->apn[temp->cnt].profile_idx = atoi(argv[0]);
1031 temp->apn[temp->cnt].pdp_type = atoi(argv[1]);
1032 temp->apn[temp->cnt].auth_proto = atoi(argv[2]);
1033 memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE);
1034 memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE);
1035 memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE);
1036 memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE);
1037 temp->cnt++;
1038 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001039}
xf.licb6cd282024-02-21 22:06:14 -08001040static int apn_db_query_list(qser_apn_info_list_s *apn_list)
1041{
1042 char *zErrMsg = 0;
1043 int rc;
xf.li2fc84552023-06-23 05:26:47 -07001044
xf.licb6cd282024-02-21 22:06:14 -08001045 /* Open database */
1046 apn_count = 0;
1047 apn_list->cnt = 0;
xf.li87f6e6e2024-06-19 02:23:05 -07001048 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001049 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1050 if( rc )
1051 {
1052 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001053 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001054 return LYNQ_E_APN_DB_FAIL;
1055 }
1056
1057 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1058 /* Create SQL statement */
1059 char *sql = sqlite3_mprintf("SELECT * from LYNQAPN");
1060 LYINFLOG("sql: %s\n", sql);
1061 /* Execute SQL statement */
1062 rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg);
1063 if( rc != SQLITE_OK )
1064 {
1065 LYERRLOG("SQL error: %s\n", zErrMsg);
1066 sqlite3_free(zErrMsg);
1067 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001068 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001069 return LYNQ_E_APN_DB_FAIL;
1070 }
1071 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001072 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001073 return 0;
1074}
1075// **************apn DB end****************************
xf.li2fc84552023-06-23 05:26:47 -07001076void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
1077{
1078 switch (pdp_type)
1079 {
1080 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -08001081#ifdef MOBILETEK_TARGET_PLATFORM_T106
1082 strcpy(out_pdp_type,"IP");
1083#else
xf.li2fc84552023-06-23 05:26:47 -07001084 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -08001085#endif
xf.li2fc84552023-06-23 05:26:47 -07001086 break;
1087 case QSER_APN_PDP_TYPE_PPP:
1088 strcpy(out_pdp_type,"PPP");
1089 break;
1090 case QSER_APN_PDP_TYPE_IPV6:
1091 strcpy(out_pdp_type,"IPV6");
1092 break;
1093 case QSER_APN_PDP_TYPE_IPV4V6:
1094 strcpy(out_pdp_type,"IPV4V6");
1095 break;
1096 default:
1097 strcpy(out_pdp_type,"NULL");
1098 break;
1099 }
1100 return;
1101}
1102void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
1103{
1104 switch (auth_proto)
1105 {
1106 case QSER_APN_AUTH_PROTO_DEFAULT:
xf.lifb6134e2024-05-09 01:26:54 -07001107 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001108 break;
1109 case QSER_APN_AUTH_PROTO_NONE:
xf.lifb6134e2024-05-09 01:26:54 -07001110 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001111 break;
1112 case QSER_APN_AUTH_PROTO_PAP:
xf.lifb6134e2024-05-09 01:26:54 -07001113 strcpy(out_proto,"1");
xf.li2fc84552023-06-23 05:26:47 -07001114 break;
1115 case QSER_APN_AUTH_PROTO_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001116 strcpy(out_proto,"2");
xf.li2fc84552023-06-23 05:26:47 -07001117 break;
1118 case QSER_APN_AUTH_PROTO_PAP_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001119 strcpy(out_proto,"3");
xf.li2fc84552023-06-23 05:26:47 -07001120 break;
1121 default:
xf.lifb6134e2024-05-09 01:26:54 -07001122 strcpy(out_proto,"NULL");
xf.li2fc84552023-06-23 05:26:47 -07001123 break;
1124 }
1125 return ;
1126}
1127
1128int data_call_handle_get(const char profile_idx,int *handle)
1129{
1130 int num = LYNQ_APN_CHANNEL_MAX;
1131 int table_num = 0;
1132 lynq_apn_info **apn_table = NULL;
1133 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001134 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001135 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1136 if (NULL == apn_table)
1137 {
1138 LYERRLOG("malloc apn_table fail ");
1139 return RESULT_ERROR;
1140 }
1141 for(int i =0;i<10;i++)
1142 {
1143 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1144 if (apn_table[i]==NULL)
1145 {
1146 for (int n=0;n<i;n++)
1147 {
1148 free(apn_table[n]);
1149 }
1150 return RESULT_ERROR;
1151 }
1152 memset(apn_table[i],0,sizeof(lynq_apn_info));
1153 }
1154 lynq_get_apn_table(&table_num,apn_table);
1155 memset(&apn,0,sizeof(qser_apn_info_s));
xf.licb6cd282024-02-21 22:06:14 -08001156 ret = apn_db_query(profile_idx,&apn);
xf.li0fc26502023-09-16 02:10:17 -07001157 if (ret < 0)
1158 {
xf.licb6cd282024-02-21 22:06:14 -08001159 LYERRLOG("apn_db_query error");
xf.li0fc26502023-09-16 02:10:17 -07001160 return ret;
1161 }
xf.li2fc84552023-06-23 05:26:47 -07001162 for (int j = 0;j < table_num;j++)
1163 {
1164 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1165 {
1166 *handle = apn_table[j]->index;
1167 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1168 break;
1169 }
1170 }
1171
1172 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1173 {
1174 if (apn_table[i]!=NULL)
1175 {
1176 free(apn_table[i]);
1177 apn_table[i]=NULL;
1178 }
1179 }
1180 free(apn_table);
1181 apn_table=NULL;
1182 LYINFLOG("data_call_handle_get end");
1183 return RESULT_OK;
1184}
1185
1186void *thread_wait_cb_status(void)
1187{
1188 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001189 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001190 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001191 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001192 qser_data_call_state_s data_cb_state;
1193 while (s_qser_data_cb_thread_status)
1194 {
xf.li6b0d8502023-09-04 18:49:12 -07001195 ret = lynq_wait_data_call_state_change(&handle);
1196 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
1197 if(s_qser_data_cb_thread_status == 0)
1198 {
1199 return NULL;
1200 }
1201 else if(ret < 0)
1202 {
1203 continue;
1204 }
xf.li8535bc02023-12-12 23:28:35 -08001205 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
1206 memset(&data_urc_info, 0, sizeof(data_urc_info));
1207 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001208 lynq_get_data_call_list(&handle,&data_urc_info);
1209 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001210 //data_cb_state.profile_idx = (char)handle;
xf.licb6cd282024-02-21 22:06:14 -08001211 apn_db_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li87f6e6e2024-06-19 02:23:05 -07001212 LYINFLOG("[thread_wait_cb_status]: callback profile_idx is %d\n", data_cb_state.profile_idx);
xf.li8535bc02023-12-12 23:28:35 -08001213 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",
1214 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
1215 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
1216 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -07001217 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001218 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001219 {
1220 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1221 }
1222 else if (!strcmp(data_urc_info.type,"IPV6"))
1223 {
1224 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1225 }
xf.li8535bc02023-12-12 23:28:35 -08001226 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001227 {
1228 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1229 }
1230 else
1231 {
xf.li8535bc02023-12-12 23:28:35 -08001232 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001233 }
1234
xf.li8535bc02023-12-12 23:28:35 -08001235 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001236 {
1237 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1238 }
1239 else
1240 {
1241 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.licb6cd282024-02-21 22:06:14 -08001242 ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001243 if(ret != 0)
1244 {
1245 LYERRLOG("handle set error");
1246 }
xf.li2fc84552023-06-23 05:26:47 -07001247 }
1248 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1249 {
1250 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1251 }
1252 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1253 {
1254 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1255 }
1256 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1257 {
xf.li3c0a4752023-09-03 20:46:19 -07001258#ifdef MOBILETEK_TARGET_PLATFORM_T106
1259 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1260#else
xf.li2fc84552023-06-23 05:26:47 -07001261 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001262#endif
xf.li2fc84552023-06-23 05:26:47 -07001263 }
1264 else
1265 {
1266 LYERRLOG("unknow ip_family");
1267 continue;
1268 }
1269 if (s_data_call_cb != NULL)
1270 {
1271 s_data_call_cb(&data_cb_state);
1272 }
1273 }
1274 return NULL;
1275}
1276
1277int qser_cb_pthread_create()
1278{
xf.lib5d82bf2024-03-09 01:54:50 -08001279 pthread_attr_t attr;
xf.li2fc84552023-06-23 05:26:47 -07001280 int ret;
1281 s_qser_data_cb_thread_status = 1;
xf.lib5d82bf2024-03-09 01:54:50 -08001282
1283 pthread_attr_init(&attr);
1284 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1285
1286 ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL);
xf.li2fc84552023-06-23 05:26:47 -07001287 if (ret < 0)
1288 {
1289 LYERRLOG("pthread create fail");
1290 s_qser_data_cb_thread_status = 0;
1291 return RESULT_ERROR;
1292 }
xf.lib5d82bf2024-03-09 01:54:50 -08001293 pthread_attr_destroy(&attr);
xf.li2fc84552023-06-23 05:26:47 -07001294 return RESULT_OK;
1295}
1296
1297void qser_cb_pthread_cancel()
1298{
xf.li2fc84552023-06-23 05:26:47 -07001299 s_qser_data_cb_thread_status = 0;
1300 if (s_cb_tid != -1)
1301 {
xf.li6b0d8502023-09-04 18:49:12 -07001302 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001303 }
1304 return;
1305}
xf.li2fc84552023-06-23 05:26:47 -07001306int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1307{
1308 int ret = 0;
1309 int utoken = 0;
1310 if (NULL == evt_cb)
1311 {
1312 LYERRLOG("init incoming paramters error");
1313 return RESULT_ERROR;
1314 }
xf.li09b46db2024-03-13 19:21:18 -07001315 if(g_lynq_qser_data_init_flag == 1)
1316 {
1317 LYERRLOG("init twice is not allowed");
1318 return RESULT_ERROR;
1319 }
xf.li2fc84552023-06-23 05:26:47 -07001320 ret = lynq_init_data(utoken);
1321 if (ret != RESULT_OK)
1322 {
xf.li6b0d8502023-09-04 18:49:12 -07001323 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001324 s_data_call_cb = NULL;
1325 return RESULT_ERROR;
1326 }
xf.li6b0d8502023-09-04 18:49:12 -07001327 qser_cb_pthread_create();
xf.licb6cd282024-02-21 22:06:14 -08001328 ret = init_apn_db();
1329 if(ret != RESULT_OK)
xf.lie3f55f42023-12-01 22:47:33 -08001330 {
xf.licb6cd282024-02-21 22:06:14 -08001331 LYERRLOG("init apn db error");
xf.lie3f55f42023-12-01 22:47:33 -08001332 return RESULT_ERROR;
1333 }
xf.licb6cd282024-02-21 22:06:14 -08001334
1335 ret = apn_db_handle_clean();
xf.li63b87e82024-01-04 00:43:35 -08001336 if(ret != RESULT_OK)
1337 {
1338 LYERRLOG("clean handle error");
1339 return RESULT_ERROR;
1340 }
xf.li09b46db2024-03-13 19:21:18 -07001341 s_data_call_cb = evt_cb;
xf.lib33d4862023-12-13 00:40:37 -08001342 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001343 return RESULT_OK;
1344}
1345
1346void qser_data_call_destroy(void)
1347{
xf.li6b0d8502023-09-04 18:49:12 -07001348 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001349 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001350 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001351 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001352 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001353 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001354 return ;
1355}
1356
1357int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1358{
1359 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001360 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001361 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001362 if(g_lynq_qser_data_init_flag == 0)
1363 {
1364 if(err != NULL)
1365 {
1366 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1367 }
1368 return LYNQ_E_NO_INIT;
1369 }
xf.li2fc84552023-06-23 05:26:47 -07001370 if (NULL == data_call || NULL == err)
1371 {
1372 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001373 if(err != NULL)
1374 {
1375 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1376 }
xf.li2fc84552023-06-23 05:26:47 -07001377 return ret;
1378 }
1379 if (data_call->profile_idx == 0)
1380 {
1381 ret = lynq_setup_data_call(&handle);
1382 }
1383 else
1384 {
1385 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001386 char auth_proto[16];
xf.li2fc84552023-06-23 05:26:47 -07001387 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001388 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1389 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li0fc26502023-09-16 02:10:17 -07001390 if (ret != 0)
1391 {
1392 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001393 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001394 return ret;
1395 }
xf.li2fc84552023-06-23 05:26:47 -07001396 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001397 judge_authtype(apn_info.auth_proto,auth_proto);
1398 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 -07001399 }
xf.lic12b3702023-11-22 22:39:01 -08001400 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001401 {
1402 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1403 }
xf.li0fd6acf2023-12-20 18:16:34 -08001404 else
1405 {
xf.licb6cd282024-02-21 22:06:14 -08001406 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001407 if(error != 0)
1408 {
1409 LYERRLOG("handle set error");
1410 }
1411 }
xf.li2fc84552023-06-23 05:26:47 -07001412 return ret;
1413}
1414
xf.li8535bc02023-12-12 23:28:35 -08001415int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1416{
1417 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001418 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001419 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001420 if(g_lynq_qser_data_init_flag == 0)
1421 {
1422 if(err != NULL)
1423 {
1424 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1425 }
1426 return LYNQ_E_NO_INIT;
1427 }
xf.li8535bc02023-12-12 23:28:35 -08001428 if (NULL == data_call || NULL == err)
1429 {
1430 LYERRLOG("call start incoming paramters error");
1431 if(err != NULL)
1432 {
1433 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1434 }
1435 return ret;
1436 }
1437 if (data_call->profile_idx == 0)
1438 {
1439 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1440 }
1441 else
1442 {
1443 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001444 char auth_proto[16];
xf.li8535bc02023-12-12 23:28:35 -08001445 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001446 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1447 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li8535bc02023-12-12 23:28:35 -08001448 if (ret != 0)
1449 {
1450 LYERRLOG("qser_apn_get error");
1451 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1452 return ret;
1453 }
1454 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001455 judge_authtype(apn_info.auth_proto,auth_proto);
1456 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 -08001457 }
1458 if (ret != 0)
1459 {
1460 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1461 }
xf.li0fd6acf2023-12-20 18:16:34 -08001462 else
1463 {
xf.licb6cd282024-02-21 22:06:14 -08001464 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001465 if(error != 0)
1466 {
1467 LYERRLOG("handle set error");
1468 }
1469 }
xf.li8535bc02023-12-12 23:28:35 -08001470 return ret;
1471}
1472
xf.li2fc84552023-06-23 05:26:47 -07001473int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1474{
1475 int ret = 0;
1476 int handle = -1;
1477
xf.lib33d4862023-12-13 00:40:37 -08001478 if(g_lynq_qser_data_init_flag == 0)
1479 {
1480 if(err != NULL)
1481 {
1482 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1483 }
1484 return LYNQ_E_NO_INIT;
1485 }
xf.li2fc84552023-06-23 05:26:47 -07001486 if (NULL == err)
1487 {
1488 LYERRLOG("call stop incoming paramters error");
1489 return ret;
1490 }
xf.lic12b3702023-11-22 22:39:01 -08001491 ret = data_call_handle_get(profile_idx,&handle);
1492 if(ret != 0)
1493 {
1494 LYERRLOG("datacall handle get error");
1495 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1496 return ret;
1497 }
xf.li2fc84552023-06-23 05:26:47 -07001498 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001499 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001500 {
1501 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001502 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001503 }
xy.hee2daacc2023-09-18 00:57:51 -07001504 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001505}
1506int 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)
1507{
1508 int ret = 0;
1509 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001510 if(g_lynq_qser_data_init_flag == 0)
1511 {
1512 if(err != NULL)
1513 {
1514 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1515 }
1516 return LYNQ_E_NO_INIT;
1517 }
xf.li2fc84552023-06-23 05:26:47 -07001518 lynq_data_call_response_v11_t data_call_info;
1519 data_call_handle_get(profile_idx,&handle);
1520 ret = lynq_get_data_call_list(&handle,&data_call_info);
1521 if (ret == 0)
1522 {
1523 info->profile_idx = profile_idx;
1524 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001525 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 -07001526 {
xf.li0400b382024-06-05 19:20:36 -07001527 info->ip_family = QSER_DATA_CALL_TYPE_IPV4;
xf.li2fc84552023-06-23 05:26:47 -07001528 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001529 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001530 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1531 lynq_ipv4_aton_getinfo(&data_call_info,info);
1532 }
xf.li3c0a4752023-09-03 20:46:19 -07001533 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001534 {
xf.li0400b382024-06-05 19:20:36 -07001535 info->ip_family = QSER_DATA_CALL_TYPE_IPV6;
xf.li2fc84552023-06-23 05:26:47 -07001536 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001537 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001538 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1539 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1540 }
xf.li3c0a4752023-09-03 20:46:19 -07001541 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001542 {
xf.li0400b382024-06-05 19:20:36 -07001543 info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
xf.li2fc84552023-06-23 05:26:47 -07001544 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001545 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001546 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 -07001547#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001548 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001549#endif
xf.li2fc84552023-06-23 05:26:47 -07001550 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001551 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001552 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 -07001553#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001554 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001555#endif
1556#ifdef MOBILETEK_TARGET_PLATFORM_T106
1557 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1558#endif
xf.li2fc84552023-06-23 05:26:47 -07001559 }
1560 else
1561 {
1562 LYERRLOG("useless qser_data_call_ip_family_e");
1563 }
1564 }
1565 return ret;
1566}
xf.lifb6134e2024-05-09 01:26:54 -07001567int check_pdp_type(qser_apn_pdp_type_e pdp_type)
1568{
1569 switch (pdp_type)
1570 {
1571 case QSER_APN_PDP_TYPE_IPV4:
1572 case QSER_APN_PDP_TYPE_PPP:
1573 case QSER_APN_PDP_TYPE_IPV6:
1574 case QSER_APN_PDP_TYPE_IPV4V6:
1575 return 0;
1576 default:
1577 return -1;
1578 }
1579}
1580int check_auth_proto(qser_apn_auth_proto_e auth_proto)
1581{
1582 switch (auth_proto)
1583 {
1584 case QSER_APN_AUTH_PROTO_DEFAULT:
1585 case QSER_APN_AUTH_PROTO_NONE:
1586 case QSER_APN_AUTH_PROTO_PAP:
1587 case QSER_APN_AUTH_PROTO_CHAP:
1588 case QSER_APN_AUTH_PROTO_PAP_CHAP:
1589 return 0;
1590 default:
1591 return -1;
1592 }
1593}
xf.li2fc84552023-06-23 05:26:47 -07001594int qser_apn_set(qser_apn_info_s *apn)
1595{
1596 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001597 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001598 if(g_lynq_qser_data_init_flag == 0)
1599 {
1600 return LYNQ_E_NO_INIT;
1601 }
xf.li4b18fa62023-12-19 19:38:10 -08001602 if (NULL == apn || apn->profile_idx == 0)
xf.li2fc84552023-06-23 05:26:47 -07001603 {
1604 LYERRLOG("apn set incoming paramters error");
1605 return RESULT_ERROR;
1606 }
xf.licb6cd282024-02-21 22:06:14 -08001607 ret = apn_db_handle_get(apn->profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001608 if(ret != 0)
1609 {
1610 LYERRLOG("handle set error");
1611 }
1612 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1613 {
1614 LYERRLOG("It has setup datacall");
1615 return RESULT_ERROR;
1616 }
xf.lifb6134e2024-05-09 01:26:54 -07001617
1618 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1619 {
1620 LYERRLOG("apn_name out of range\n");
1621 return RESULT_ERROR;
1622 }
1623 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1624 {
1625 LYERRLOG("username out of range\n");
1626 return RESULT_ERROR;
1627 }
1628 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1629 {
1630 LYERRLOG("password out of range\n");
1631 return RESULT_ERROR;
1632 }
1633 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1634 {
1635 LYERRLOG("apn_type out of range\n");
1636 return RESULT_ERROR;
1637 }
1638 if(check_pdp_type(apn->pdp_type) != 0)
1639 {
1640 LYERRLOG("pdp_type out of range\n");
1641 return RESULT_ERROR;
1642 }
1643 if(check_auth_proto(apn->auth_proto) != 0)
1644 {
1645 LYERRLOG("auth_proto out of range\n");
1646 return RESULT_ERROR;
1647 }
1648
xf.licb6cd282024-02-21 22:06:14 -08001649 ret = apn_db_modify(apn);
xf.li2fc84552023-06-23 05:26:47 -07001650 if (ret < 0)
1651 {
xf.licb6cd282024-02-21 22:06:14 -08001652 LYERRLOG("apn_db_modify error");
xf.li2fc84552023-06-23 05:26:47 -07001653 return ret;
1654 }
xf.li6c7e3972023-10-27 20:01:59 -07001655#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001656 int apn_id = 0;
1657 char tmp_id[12];
1658 char *outinfo = NULL;
1659 char normalprotocol[16];
1660 char authtype[32];
1661 outinfo = (char *)malloc(sizeof(char)*512);
1662 bzero(tmp_id,12);
1663 bzero(outinfo,512);
1664 apn_id = apn->profile_idx + apndb_offset;
1665 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1666 judge_pdp_type(apn->pdp_type,normalprotocol);
1667 judge_authtype(apn->auth_proto,authtype);
1668 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1669 LYINFLOG("[output]:%s",outinfo);
1670 free(outinfo);
1671 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001672#endif
1673 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001674}
1675
1676int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1677{
xf.lib33d4862023-12-13 00:40:37 -08001678 if(g_lynq_qser_data_init_flag == 0)
1679 {
1680 return LYNQ_E_NO_INIT;
1681 }
xf.licb6cd282024-02-21 22:06:14 -08001682 if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn)
xf.li2fc84552023-06-23 05:26:47 -07001683 {
1684 LYERRLOG("apn get incoming paramters error");
1685 return RESULT_ERROR;
1686 }
1687 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001688 ret = apn_db_query(profile_idx,apn);
xf.li2fc84552023-06-23 05:26:47 -07001689 if (ret < 0)
1690 {
xf.licb6cd282024-02-21 22:06:14 -08001691 LYERRLOG("apn_db_query error");
xf.li2fc84552023-06-23 05:26:47 -07001692 return ret;
1693 }
1694 return ret;
1695}
1696
1697int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1698{
1699 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001700
xf.lib33d4862023-12-13 00:40:37 -08001701 if(g_lynq_qser_data_init_flag == 0)
1702 {
1703 return LYNQ_E_NO_INIT;
1704 }
xf.li2fc84552023-06-23 05:26:47 -07001705 if (NULL == apn || NULL == profile_idx)
1706 {
1707 LYERRLOG("apn add incoming paramters error");
1708 return RESULT_ERROR;
1709 }
xf.lifb6134e2024-05-09 01:26:54 -07001710
1711 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1712 {
1713 LYERRLOG("apn_name out of range\n");
1714 return RESULT_ERROR;
1715 }
1716 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1717 {
1718 LYERRLOG("username out of range\n");
1719 return RESULT_ERROR;
1720 }
1721 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1722 {
1723 LYERRLOG("password out of range\n");
1724 return RESULT_ERROR;
1725 }
1726 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1727 {
1728 LYERRLOG("apn_type out of range\n");
1729 return RESULT_ERROR;
1730 }
1731 if(check_pdp_type(apn->pdp_type) != 0)
1732 {
1733 LYERRLOG("pdp_type out of range\n");
1734 return RESULT_ERROR;
1735 }
1736 if(check_auth_proto(apn->auth_proto) != 0)
1737 {
1738 LYERRLOG("auth_proto out of range\n");
1739 return RESULT_ERROR;
1740 }
xf.licb6cd282024-02-21 22:06:14 -08001741
1742 *profile_idx = 0;
1743 *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH);
1744 LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx);
1745 if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001746 {
xf.licb6cd282024-02-21 22:06:14 -08001747 LYINFLOG("[%s] apn full is false\n",__FUNCTION__);
1748 ret = apn_db_add((int)*profile_idx, apn);
1749 if (ret != 0)
1750 {
1751 LYERRLOG("apn_db_add error");
1752 return RESULT_ERROR;
1753 }
1754 else
1755 {
1756 return RESULT_OK;
1757 }
xf.li2fc84552023-06-23 05:26:47 -07001758 }
xf.licb6cd282024-02-21 22:06:14 -08001759 LYERRLOG("apn storage space is full!!!");
1760 return RESULT_ERROR;
xf.li6c7e3972023-10-27 20:01:59 -07001761#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001762 int apn_id = 0;
1763 char tmp_id[12];
1764 char *outinfo = NULL;
1765 char normalprotocol[16];
1766 char authtype[32];
1767 outinfo = (char *)malloc(sizeof(char)*512);
1768 bzero(tmp_id,12);
1769 bzero(outinfo,512);
1770 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1771 judge_pdp_type(apn->pdp_type,normalprotocol);
1772 judge_authtype(apn->auth_proto,authtype);
1773 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1774 LYINFLOG("[output]:%s",outinfo);
1775 free(outinfo);
1776 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001777#endif
1778 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001779}
1780
1781int qser_apn_del(unsigned char profile_idx)
1782{
xf.li87f6e6e2024-06-19 02:23:05 -07001783 int ret = 0;
1784 int handle = -1;
1785
1786 LYINFLOG("[%s] entry\n",__FUNCTION__);
xf.lib33d4862023-12-13 00:40:37 -08001787 if(g_lynq_qser_data_init_flag == 0)
1788 {
1789 return LYNQ_E_NO_INIT;
1790 }
xf.li4b18fa62023-12-19 19:38:10 -08001791 if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001792 {
1793 LYERRLOG("apn del incoming paramters error");
xf.li4b18fa62023-12-19 19:38:10 -08001794 return RESULT_ERROR;
xf.li2fc84552023-06-23 05:26:47 -07001795 }
xf.li87f6e6e2024-06-19 02:23:05 -07001796
xf.licb6cd282024-02-21 22:06:14 -08001797 ret = apn_db_handle_get(profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001798 if(ret != 0)
1799 {
1800 LYERRLOG("handle set error");
1801 }
1802 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1803 {
1804 LYERRLOG("It has setup datacall");
1805 return RESULT_ERROR;
1806 }
xf.licb6cd282024-02-21 22:06:14 -08001807 ret = apn_db_delete(profile_idx);
xf.li2fc84552023-06-23 05:26:47 -07001808 if (ret < 0)
1809 {
xf.licb6cd282024-02-21 22:06:14 -08001810 LYERRLOG("apn_db_delete error");
xf.li2fc84552023-06-23 05:26:47 -07001811 return ret;
1812 }
xf.li6c7e3972023-10-27 20:01:59 -07001813#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001814 int apn_id = 0;
1815 char tmp_id[12];
1816 char *outinfo = NULL;
1817 outinfo = (char *)malloc(sizeof(char)*512);
1818 bzero(tmp_id,12);
1819 bzero(outinfo,512);
1820 apn_id = profile_idx+apndb_offset;
1821 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1822 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1823 LYINFLOG("[output]:%s",outinfo);
1824 free(outinfo);
1825 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001826#endif
xf.li2fc84552023-06-23 05:26:47 -07001827 return ret;
1828}
1829
1830int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1831{
xf.lib33d4862023-12-13 00:40:37 -08001832 if(g_lynq_qser_data_init_flag == 0)
1833 {
1834 return LYNQ_E_NO_INIT;
1835 }
xf.li2fc84552023-06-23 05:26:47 -07001836 if (NULL == apn_list)
1837 {
1838 LYERRLOG("apn_list incoming paramters error");
1839 return RESULT_ERROR;
1840 }
1841 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001842 ret = apn_db_query_list(apn_list);
xf.li2fc84552023-06-23 05:26:47 -07001843 if (ret < 0)
1844 {
xf.licb6cd282024-02-21 22:06:14 -08001845 LYERRLOG("apn_db_query_list error");
xf.li2fc84552023-06-23 05:26:47 -07001846 return ret;
1847 }
1848 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001849}
you.chen21c62b72023-09-08 09:41:11 +08001850
1851DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1852