blob: 421383bda41c87c06284d39f5dac26f78e6d62f3 [file] [log] [blame]
xf.li2fc84552023-06-23 05:26:47 -07001#include <stdio.h>
2#include <stdint.h>
3#include <sys/types.h>
4#include <arpa/inet.h>
5#include <string.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <log/log.h>
9#include <libdata/lynq_data.h>
10#include <liblog/lynq_deflog.h>
11#include <pthread.h>
xf.licb6cd282024-02-21 22:06:14 -080012#include <sqlite3.h>
xf.li2fc84552023-06-23 05:26:47 -070013#include "lynq-qser-data.h"
14
15#define USER_LOG_TAG "LYNQ_QSER_DATA"
xf.licb6cd282024-02-21 22:06:14 -080016#define APN_DB_PATH "/mnt/userdata/apn.db"
17#define APN_DB_READED 0
18#define APN_DB_ERR 1
19#define APN_DB_CREATE 2
xf.li1bbfc7d2024-07-15 23:50:41 -070020#define APN_TABLE_CREATE 3
21#define APN_TABLE_NEED_CREATE 4
xf.li2fc84552023-06-23 05:26:47 -070022#define RESULT_OK (0)
23#define RESULT_ERROR (-1)
24
xf.lib33d4862023-12-13 00:40:37 -080025typedef enum{
xf.licb6cd282024-02-21 22:06:14 -080026 LYNQ_E_NO_INIT=9002,
27 LYNQ_E_APN_DB_FAIL=9003
xf.lib33d4862023-12-13 00:40:37 -080028}LYNQ_E;
29
30static int g_lynq_qser_data_init_flag = 0;
xf.li2fc84552023-06-23 05:26:47 -070031static pthread_t s_cb_tid = -1;
32static int s_qser_data_cb_thread_status = 0;
33static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
xf.li87f6e6e2024-06-19 02:23:05 -070034static pthread_mutex_t s_qser_data_database_mutex = PTHREAD_MUTEX_INITIALIZER;
xf.li2fc84552023-06-23 05:26:47 -070035static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER;
36
xf.li2fc84552023-06-23 05:26:47 -070037
38static qser_data_call_evt_cb_t s_data_call_cb = NULL;
xf.licb6cd282024-02-21 22:06:14 -080039static sqlite3* apnDb;
40qser_apn_add_s default_apn = {QSER_APN_PDP_TYPE_IPV4V6, QSER_APN_AUTH_PROTO_DEFAULT, "default", "NULL", "NULL", "default"};
41int apn_indexs[LYNQ_APN_CHANNEL_MAX]={0};
42int next_index = 0;
43int apn_count = 0;
xf.li2fc84552023-06-23 05:26:47 -070044const int apndb_offset = 683;
45
xf.licb6cd282024-02-21 22:06:14 -080046static int init_apn_db();
47static int create_apn_db(char *path);
48static int create_apn_table(char*path);
49static int has_apn_db_created(char *path,sqlite3* apnDb_l);
50static int apn_db_handle_clean();
51
52static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName);
53static int lynq_check_index(unsigned char index);
54static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName);
55static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx);
56static int apn_db_handle_set(unsigned char profile_idx, int handle);
57static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName);
58static int apn_db_handle_get(unsigned char profile_idx, int *handle);
59
60static int find_unuse_apn_index(char *path);
61static int apn_db_add(int profile_id, qser_apn_add_s *apn);
62static int apn_db_delete(unsigned char profile_idx);
63static int apn_db_modify(qser_apn_info_s *apn);
64static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName);
65static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn);
66static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName);
67static int apn_db_query_list(qser_apn_info_list_s *apn_list);
68
xf.li2fc84552023-06-23 05:26:47 -070069void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
70{
xf.li3c0a4752023-09-03 20:46:19 -070071#ifdef MOBILETEK_TARGET_PLATFORM_T106
72 char *tmp_char = NULL;
73 char *addresses = NULL;
74 char *dnses = NULL;
75 const char addresses_separator[2] = "/";
76 const char dnses_separator[2] = " ";
77
78 addresses = libdata->addresses;
79 dnses = libdata->dnses;
80 //get addresses
81 tmp_char = strsep(&addresses, addresses_separator);
82 if(tmp_char != NULL)
83 {
84 LYINFLOG("ipv4 addresses = %s", tmp_char);
85 inet_aton(tmp_char,&(data_res->v4.ip));
86 }
87
88 //get dnses
89 tmp_char = strsep(&dnses, dnses_separator);
90 if(tmp_char != NULL)
91 {
92 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
93 inet_aton(tmp_char,&(data_res->v4.pri_dns));
94 }
95 tmp_char = strsep(&dnses, dnses_separator);
96 if(tmp_char != NULL)
97 {
98 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
99 inet_aton(tmp_char, &(data_res->v4.sec_dns));
100 }
101 //get gateway
102 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
103
104#else
xf.li2fc84552023-06-23 05:26:47 -0700105 inet_aton(libdata->addresses,&(data_res->v4.ip));
106 inet_aton(libdata->gateways,&(data_res->v4.gateway));
107 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
108 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700109#endif
xf.li2fc84552023-06-23 05:26:47 -0700110 return ;
111}
112
113void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
114{
xf.li3c0a4752023-09-03 20:46:19 -0700115#ifdef MOBILETEK_TARGET_PLATFORM_T106
116 char *tmp_char = NULL;
117 char *addresses = NULL;
118 char *dnses = NULL;
119 const char addresses_separator[2] = "/";
120 const char dnses_separator[2] = " ";
121
122 addresses = libdata->addresses;
123 dnses = libdata->dnses;
124 //get addresses
125 tmp_char = strsep(&addresses, addresses_separator);
126 if(tmp_char != NULL)
127 {
128 LYINFLOG("ipv6 addresses = %s", tmp_char);
129 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
130 }
131 //get dnses
132 tmp_char = strsep(&dnses, dnses_separator);
133 if(tmp_char != NULL)
134 {
135 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
136 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
137 }
138 tmp_char = strsep(&dnses, dnses_separator);
139 if(tmp_char != NULL)
140 {
141 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
142 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
143 }
144 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
145#else
xf.li2fc84552023-06-23 05:26:47 -0700146 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
147 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
148 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
149 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700150#endif
151
152 return ;
153}
154
155void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
156{
157 char *tmp_char = NULL;
158 char *addresses = NULL;
159 char *dnses = NULL;
160 const char addresses_separator[2] = "/";
161 const char dnses_separator[2] = " ";
162
xf.li03baf1f2023-12-19 21:30:38 -0800163 char buf_ip[64] = {0};
164 char buf_gateway[64] = {0};
165 char buf_pri_dns[64] = {0};
166 char buf_sec_dns[64] = {0};
167
xf.li3c0a4752023-09-03 20:46:19 -0700168 addresses = libdata->addresses;
169 dnses = libdata->dnses;
170 //get addresses
171 tmp_char = strsep(&addresses, addresses_separator);
172 if(tmp_char != NULL)
173 {
174 LYINFLOG("ipv4 addresses = %s", tmp_char);
175 inet_aton(tmp_char,&(data_res->v4.ip));
176 }
177 tmp_char = strsep(&addresses, addresses_separator);
178 if(tmp_char != NULL)
179 {
180 LYINFLOG("ipv6 addresses = %s", tmp_char);
181 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
182 }
183 //get dnses
184 tmp_char = strsep(&dnses, dnses_separator);
185 if(tmp_char != NULL)
186 {
187 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
188 inet_aton(tmp_char,&(data_res->v4.pri_dns));
189 }
190 tmp_char = strsep(&dnses, dnses_separator);
191 if(tmp_char != NULL)
192 {
193 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
194 inet_aton(tmp_char, &(data_res->v4.sec_dns));
195 }
196 tmp_char = strsep(&dnses, dnses_separator);
197 if(tmp_char != NULL)
198 {
199 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
200 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
201 }
202 tmp_char = strsep(&dnses, dnses_separator);
203 if(tmp_char != NULL)
204 {
205 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
206 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
207 }
208 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800209 inet_aton(libdata->gateways,&(data_res->v4.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700210 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
211
xf.li03baf1f2023-12-19 21:30:38 -0800212 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip));
213 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns));
214 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns));
215
216 inet_ntop(AF_INET6, &(data_res->v6.ip), buf_ip, sizeof(buf_ip));
217 inet_ntop(AF_INET6, &(data_res->v6.gateway), buf_gateway, sizeof(buf_gateway));
218 inet_ntop(AF_INET6, &(data_res->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
219 inet_ntop(AF_INET6, &(data_res->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
220 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
221 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
xf.li2fc84552023-06-23 05:26:47 -0700222 return ;
223}
224
225void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
226{
xf.li3c0a4752023-09-03 20:46:19 -0700227#ifdef MOBILETEK_TARGET_PLATFORM_T106
228 char *tmp_char = NULL;
229 char *addresses = NULL;
230 char *dnses = NULL;
231 const char addresses_separator[2] = "/";
232 const char dnses_separator[2] = " ";
233
234 addresses = libdata->addresses;
235 dnses = libdata->dnses;
236 //get addresses
237 tmp_char = strsep(&addresses, addresses_separator);
238 if(tmp_char != NULL)
239 {
240 LYINFLOG("ipv4 addresses = %s", tmp_char);
241 inet_aton(tmp_char,&(data_res->v4.addr.ip));
242 }
243 //get dnses
244 tmp_char = strsep(&dnses, dnses_separator);
245 if(tmp_char != NULL)
246 {
247 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
248 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
249 }
250 tmp_char = strsep(&dnses, dnses_separator);
251 if(tmp_char != NULL)
252 {
253 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
254 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
255 }
256 //get gateway
257 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
258 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
259
260 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
261 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
262 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
263#else
xf.li2fc84552023-06-23 05:26:47 -0700264 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
265 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
266 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
267 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700268#endif
xf.li2fc84552023-06-23 05:26:47 -0700269 data_res->v4.stats.pkts_tx = 0;
270 data_res->v4.stats.pkts_rx = 0;
271 data_res->v4.stats.bytes_tx = 0;
272 data_res->v4.stats.bytes_rx = 0;
273 data_res->v4.stats.pkts_dropped_tx = 0;
274 data_res->v4.stats.pkts_dropped_rx = 0;
275 return ;
276}
277
278void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
279{
xf.li3c0a4752023-09-03 20:46:19 -0700280#ifdef MOBILETEK_TARGET_PLATFORM_T106
281 char *tmp_char = NULL;
282 char *addresses = NULL;
283 char *dnses = NULL;
284 const char addresses_separator[2] = "/";
285 const char dnses_separator[2] = " ";
286
287 addresses = libdata->addresses;
288 dnses = libdata->dnses;
289 //get addresses
290 tmp_char = strsep(&addresses, addresses_separator);
291 if(tmp_char != NULL)
292 {
293 LYINFLOG("ipv6 addresses = %s", tmp_char);
294 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
295 }
296 //get dnses
297 tmp_char = strsep(&dnses, dnses_separator);
298 if(tmp_char != NULL)
299 {
300 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
301 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
302 }
303 tmp_char = strsep(&dnses, dnses_separator);
304 if(tmp_char != NULL)
305 {
306 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
307 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
308 }
309 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
310#else
xf.li2fc84552023-06-23 05:26:47 -0700311 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
312 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
313 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
314 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700315#endif
316 data_res->v6.stats.pkts_tx = 0;
317 data_res->v6.stats.pkts_rx = 0;
318 data_res->v6.stats.bytes_tx = 0;
319 data_res->v6.stats.bytes_rx = 0;
320 data_res->v6.stats.pkts_dropped_tx = 0;
321 data_res->v6.stats.pkts_dropped_rx = 0;
322 return ;
323}
324void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
325{
326 char *tmp_char = NULL;
327 char *addresses = NULL;
328 char *dnses = NULL;
329 const char addresses_separator[2] = "/";
330 const char dnses_separator[2] = " ";
331
332 char buf_ip[64] = {0};
333 char buf_gateway[64] = {0};
334 char buf_pri_dns[64] = {0};
335 char buf_sec_dns[64] = {0};
336
337 addresses = libdata->addresses;
338 dnses = libdata->dnses;
339 //get addresses
340 tmp_char = strsep(&addresses, addresses_separator);
341 if(tmp_char != NULL)
342 {
343 LYINFLOG("ipv4 addresses = %s", tmp_char);
344 inet_aton(tmp_char,&(data_res->v4.addr.ip));
345 }
346 tmp_char = strsep(&addresses, addresses_separator);
347 if(tmp_char != NULL)
348 {
349 LYINFLOG("ipv6 addresses = %s", tmp_char);
350 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
351 }
352 //get dnses
353 tmp_char = strsep(&dnses, dnses_separator);
354 if(tmp_char != NULL)
355 {
356 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
357 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
358 }
359 tmp_char = strsep(&dnses, dnses_separator);
360 if(tmp_char != NULL)
361 {
362 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
363 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
364 }
365 tmp_char = strsep(&dnses, dnses_separator);
366 if(tmp_char != NULL)
367 {
368 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
369 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
370 }
371 tmp_char = strsep(&dnses, dnses_separator);
372 if(tmp_char != NULL)
373 {
374 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
375 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
376 }
377 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800378 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700379 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
380
381 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
xf.li03baf1f2023-12-19 21:30:38 -0800382 LYINFLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700383 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
384 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
385
386 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
387 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
388 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
389 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
390 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
391 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
392 data_res->v4.stats.pkts_tx = 0;
393 data_res->v4.stats.pkts_rx = 0;
394 data_res->v4.stats.bytes_tx = 0;
395 data_res->v4.stats.bytes_rx = 0;
396 data_res->v4.stats.pkts_dropped_tx = 0;
397 data_res->v4.stats.pkts_dropped_rx = 0;
398
xf.li2fc84552023-06-23 05:26:47 -0700399 data_res->v6.stats.pkts_tx = 0;
400 data_res->v6.stats.pkts_rx = 0;
401 data_res->v6.stats.bytes_tx = 0;
402 data_res->v6.stats.bytes_rx = 0;
403 data_res->v6.stats.pkts_dropped_tx = 0;
404 data_res->v6.stats.pkts_dropped_rx = 0;
405 return ;
406}
407
408void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
409{
xf.lib5dc0632023-11-30 18:20:35 -0800410 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700411 {
412 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
413 data_res->v4.reconnect = 1;
414 }
415 else
416 {
417 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
418 data_res->v4.reconnect = 0;
419 }
420 return ;
421}
422
423void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
424{
xf.lib5dc0632023-11-30 18:20:35 -0800425 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700426 {
427 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
428 data_res->v6.reconnect = 1;
429 }
430 else
431 {
432 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
433 data_res->v6.reconnect = 0;
434 }
435 return ;
436}
437
xf.licb6cd282024-02-21 22:06:14 -0800438// ****************apn DB start******************
439static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName)
xf.li0fd6acf2023-12-20 18:16:34 -0800440{
xf.licb6cd282024-02-21 22:06:14 -0800441 if(data==NULL)
xf.li0fd6acf2023-12-20 18:16:34 -0800442 {
xf.licb6cd282024-02-21 22:06:14 -0800443 return 1;
xf.li0fd6acf2023-12-20 18:16:34 -0800444 }
xf.licb6cd282024-02-21 22:06:14 -0800445 int *temp = (int *)data;
446 for(int i=0; i<argc; i++){
447 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li0fd6acf2023-12-20 18:16:34 -0800448 }
xf.licb6cd282024-02-21 22:06:14 -0800449 *temp = atoi(argv[0]);
450 return 0;
451}
452static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx)
453{
454 char *zErrMsg = 0;
455 int rc;
456 int idx = 0;
457
458 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700459 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800460 rc = sqlite3_open(APN_DB_PATH, &apnDb);
461 if( rc )
xf.li0fd6acf2023-12-20 18:16:34 -0800462 {
xf.licb6cd282024-02-21 22:06:14 -0800463 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700464 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800465 return LYNQ_E_APN_DB_FAIL;
466 }
467
468 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
469 /* Create SQL statement */
470 char *sql = sqlite3_mprintf("SELECT ID from LYNQAPN WHERE HANDLE=%d", handle);
471 LYINFLOG("sql: %s\n", sql);
472 /* Execute SQL statement */
473 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_profile_cb, &idx, &zErrMsg);
474 if( rc != SQLITE_OK )
475 {
476 LYERRLOG("SQL error: %s\n", zErrMsg);
477 sqlite3_free(zErrMsg);
478 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700479 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800480 return LYNQ_E_APN_DB_FAIL;
481 };
482 *profile_idx = (unsigned char)idx;
483 LYINFLOG("get idx %d successfully\n", *profile_idx);
484 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700485 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800486 return 0;
487}
488static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName){
489 int i;
490
491 apn_indexs[atoi(argv[0])] = atoi(argv[0]);
492 LYINFLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]);
493
494 for(i=0; i<argc; i++){
495 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
496 }
497 return 0;
498}
499/**
500 * @brief Check whether the ID exists in the database
501 *
502 * @param index
503 * @return int
504 * find:turn 1
505 * not find:turn 0
506 */
507static int lynq_check_index(unsigned char index)
508{
509 memset(apn_indexs,0,sizeof(apn_indexs));
510 next_index = 0;
511 char *zErrMsg = 0;
512 int rc;
513 char sql[128]={0};
514 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700515 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800516 rc = sqlite3_open(APN_DB_PATH, &apnDb);
517 if( rc )
518 {
519 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700520 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800521 return LYNQ_E_APN_DB_FAIL;
522 }
523 sprintf(sql,"%s", "SELECT * from LYNQAPN");
524 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback, NULL, &zErrMsg);
525 if( rc != SQLITE_OK )
526 {
527 LYERRLOG("SQL error: %s\n", zErrMsg);
528 sqlite3_free(zErrMsg);
529 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700530 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800531 return LYNQ_E_APN_DB_FAIL;
532 }
533 //for(int cnt = 0; cnt < next_index;cnt++)
534 for(int cnt = 0; cnt <= QSER_APN_MAX_LIST; cnt++)
535 {
536 if(index == apn_indexs[cnt])
537 {
538 LYINFLOG("index = apn_index\n");
539 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700540 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800541 return 1;
542 }
543 }
544 LYINFLOG("cant find the index %d\n", index);
545 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700546 pthread_mutex_unlock(&s_qser_data_database_mutex);
547
xf.licb6cd282024-02-21 22:06:14 -0800548 return 0;
549}
550
551static int apn_db_handle_set(unsigned char profile_idx, int handle)
552{
553 char *zErrMsg = 0;
554 int rc;
555 //char sql[128]={0};
556 if(!lynq_check_index(profile_idx))
557 {
558 return LYNQ_E_APN_DB_FAIL;
559 }
560 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700561 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800562 rc = sqlite3_open(APN_DB_PATH, &apnDb);
563 if( rc )
564 {
565 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700566 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800567 return LYNQ_E_APN_DB_FAIL;
568 }
569
570 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
571 /* Create SQL statement */
572 //sql = "SELECT * from LYNQAPN";
573 char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d WHERE ID=%d", handle, (int)profile_idx);
574 LYINFLOG("sql: %s\n", sql);
575 /* Execute SQL statement */
576 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
577 if( rc != SQLITE_OK )
578 {
579 LYERRLOG("SQL error: %s\n", zErrMsg);
580 sqlite3_free(zErrMsg);
581 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700582 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800583 return LYNQ_E_APN_DB_FAIL;
584 }
585 LYINFLOG("update apn %d successfully\n", profile_idx);
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 0;
589}
590static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName)
591{
592 if(data==NULL)
593 {
594 return 1;
595 }
596 int *temp = (int *)data;
597 for(int i=0; i<argc; i++){
598 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
599 }
600 *temp = atoi(argv[0]);
601 LYINFLOG("The handle is %d\n", *temp);
602 return 0;
603}
604static int apn_db_handle_get(unsigned char profile_idx, int *handle)
605{
606 char *zErrMsg = 0;
607 int rc;
608
609 //char sql[128]={0};
610 if(!lynq_check_index(profile_idx))
611 {
612 return LYNQ_E_APN_DB_FAIL;
613 }
614 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700615 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800616 rc = sqlite3_open(APN_DB_PATH, &apnDb);
617 if( rc )
618 {
619 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700620 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800621 return LYNQ_E_APN_DB_FAIL;
622 }
623
624 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
625 /* Create SQL statement */
626 char *sql = sqlite3_mprintf("SELECT HANDLE from LYNQAPN WHERE ID=%d", (int)profile_idx);
627 LYINFLOG("sql: %s\n", sql);
628 /* Execute SQL statement */
629 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_cb, handle, &zErrMsg);
630 if( rc != SQLITE_OK )
631 {
632 LYERRLOG("SQL error: %s\n", zErrMsg);
633 sqlite3_free(zErrMsg);
634 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700635 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800636 return LYNQ_E_APN_DB_FAIL;
637 }
638 LYINFLOG("get idx %d successfully\n", *handle);
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 0;
642}
643
644static int has_apn_db_created(char *path,sqlite3* apnDb_l)
645{
646 if (path == NULL || strlen(path) == 0)
647 {
648 LYERRLOG("initApnDb error with null path!");
649 return APN_DB_ERR;
650 }
651 int rc = sqlite3_open_v2(path, &apnDb_l, SQLITE_OPEN_READWRITE,NULL);
652 if (rc == SQLITE_OK)
653 {
654 LYINFLOG("check init success!");
xf.lib5d82bf2024-03-09 01:54:50 -0800655 sqlite3_close_v2(apnDb_l);
xf.licb6cd282024-02-21 22:06:14 -0800656 return APN_DB_READED;
657 }
658 else
659 {
660 LYERRLOG("db has not create %s!", sqlite3_errmsg(apnDb_l));
661 sqlite3_close_v2(apnDb_l);
662 return APN_DB_ERR;
663 }
664}
665static int create_apn_db(char *path)
666{
667 if (path == NULL || strlen(path) == 0) {
668 LYERRLOG("initApnDb error with null path!");
669 return APN_DB_ERR;
670 }
671 if(APN_DB_READED==has_apn_db_created(path,apnDb))
672 {
673 return APN_DB_READED;
674 }
675 int rc = sqlite3_open(path, &apnDb);
676 if (rc != SQLITE_OK) {
677 LYERRLOG("initDb failed %d", sqlite3_errcode(apnDb));
678 return APN_DB_ERR;
679 } else {
680 LYINFLOG("create db in %s", path);
681 }
682 sqlite3_close(apnDb);
683 return APN_DB_CREATE;
684}
685static int create_apn_table(char*path)
686{
687 char *zErrMsg = 0;
688 int rc;
689 char *sql;
690
691 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700692 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800693 rc = sqlite3_open(path, &apnDb);
694 if( rc )
695 {
696 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700697 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800698 return 1;
699 }
700 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
701 /* Create SQL statement */
702 sql = "CREATE TABLE LYNQAPN( \
703 ID INT NOT NULL, \
704 PDP_TYPE INT NOT NULL, \
705 AUTH_PROTO INT NOT NULL, \
706 APN_NAME TEXT NOT NULL, \
707 USERNAME TEXT NOT NULL,\
708 PASSWORD TEXT NOT NULL, \
709 APN_TYPE TEXT PRIMARY KEY NOT NULL, \
710 HANDLE INT NOT NULL)";
711 /* Execute SQL statement */
712 rc = sqlite3_exec(apnDb, sql, NULL, 0, &zErrMsg);
713 if( rc != SQLITE_OK )
714 {
715 LYERRLOG("SQL error: %s\n", zErrMsg);
716 sqlite3_free(zErrMsg);
717 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700718 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800719 return 1;
720 }
721 LYINFLOG("Table LYNQAPN created successfully\n");
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 0;
725}
xf.li1bbfc7d2024-07-15 23:50:41 -0700726check_apn_table_cb(void *data, int argc, char **argv, char **azColName)
727{
728 if(data==NULL)
729 {
730 return 1;
731 }
732 int *temp = (int *)data;
733 for(int i=0; i<argc; i++){
734 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
735 }
736 *temp = atoi(argv[0]);
737 LYINFLOG("\nThe number is %d\n", *temp);
738 return 0;
739}
740int check_apn_table(char*path)
741{
742 char *zErrMsg = 0;
743 int rc;
744 char *sql;
745 int num = -1;
746
747 /* Open database */
748 pthread_mutex_lock(&s_qser_data_database_mutex);
749 rc = sqlite3_open(path, &apnDb);
750 if( rc )
751 {
752 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
753 pthread_mutex_unlock(&s_qser_data_database_mutex);
754 return 1;
755 }
756 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
757 /* Create SQL statement */
758 sql = "SELECT COUNT(*) FROM sqlite_master where type ='table' and name = 'LYNQAPN'";
759 /* Execute SQL statement */
760 rc = sqlite3_exec(apnDb, sql, check_apn_table_cb, &num, &zErrMsg);
761 if( rc != SQLITE_OK )
762 {
763 LYERRLOG("SQL error: %s\n", zErrMsg);
764 sqlite3_free(zErrMsg);
765 sqlite3_close(apnDb);
766 pthread_mutex_unlock(&s_qser_data_database_mutex);
767 return 1;
768 }
769 LYINFLOG("Table LYNQAPN check successfully\n");
770 sqlite3_close(apnDb);
771 pthread_mutex_unlock(&s_qser_data_database_mutex);
772 if(num <= 0)
773 {
774 LYINFLOG("No table LYNQAPN, num = %d\n", num);
775 return APN_TABLE_NEED_CREATE;
776 }
777 else
778 {
779 LYINFLOG("The table LYNQAPN exist, num = %d\n", num);
780 return APN_TABLE_CREATE;
781 }
782
783 return 0;
784}
xf.licb6cd282024-02-21 22:06:14 -0800785static int init_apn_db()
786{
787 int db_ret=0;
xf.li1bbfc7d2024-07-15 23:50:41 -0700788 int check_ret=0;
xf.licb6cd282024-02-21 22:06:14 -0800789 int table_ret=0;
xf.li87f6e6e2024-06-19 02:23:05 -0700790
791 pthread_mutex_init(&s_qser_data_database_mutex, NULL);
792
xf.licb6cd282024-02-21 22:06:14 -0800793 db_ret = create_apn_db(APN_DB_PATH);
794 if(db_ret==APN_DB_CREATE)
795 {
796 table_ret = create_apn_table(APN_DB_PATH);
797 if(table_ret!=0)
798 {
799 LYERRLOG("create apn table fail!!!");
800 return RESULT_ERROR;
801 }
802 apn_db_add(0, &default_apn);
803 }
804 else if(db_ret==APN_DB_READED)
805 {
xf.li1bbfc7d2024-07-15 23:50:41 -0700806 LYINFLOG("[%s] apn db has be build!!!",__FUNCTION__);
807 check_ret = check_apn_table(APN_DB_PATH);
808 if(check_ret == APN_TABLE_NEED_CREATE)
809 {
810 table_ret = create_apn_table(APN_DB_PATH);
811 if(table_ret!=0)
812 {
813 LYERRLOG("create apn table fail!!!");
814 return 1;
815 }
816 apn_db_add(0, &default_apn);
817 }
818 else if(check_ret == APN_TABLE_CREATE)
819 {
820 LYINFLOG("Table LYNQAPN has created");
821 }
822 else
823 {
824 LYERRLOG("check table fail!!!, ret = %d", check_ret);
825 }
xf.li0fd6acf2023-12-20 18:16:34 -0800826 }
827 else
828 {
xf.licb6cd282024-02-21 22:06:14 -0800829 LYERRLOG("init apn db fail!!!");
xf.li0fd6acf2023-12-20 18:16:34 -0800830 }
xf.li0fd6acf2023-12-20 18:16:34 -0800831 return RESULT_OK;
xf.li0fd6acf2023-12-20 18:16:34 -0800832}
xf.li2fc84552023-06-23 05:26:47 -0700833
xf.licb6cd282024-02-21 22:06:14 -0800834static int apn_db_handle_clean()
xf.li63b87e82024-01-04 00:43:35 -0800835{
xf.licb6cd282024-02-21 22:06:14 -0800836 char *zErrMsg = 0;
837 int rc;
xf.li63b87e82024-01-04 00:43:35 -0800838 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li63b87e82024-01-04 00:43:35 -0800839
xf.licb6cd282024-02-21 22:06:14 -0800840 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700841 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800842 rc = sqlite3_open(APN_DB_PATH, &apnDb);
843 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800844 {
xf.licb6cd282024-02-21 22:06:14 -0800845 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700846 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800847 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800848 }
xf.licb6cd282024-02-21 22:06:14 -0800849
850 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
851 /* Create SQL statement */
852 char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d", default_handle);
853 LYINFLOG("sql: %s\n", sql);
854 /* Execute SQL statement */
855 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
856 if( rc != SQLITE_OK )
xf.li63b87e82024-01-04 00:43:35 -0800857 {
xf.licb6cd282024-02-21 22:06:14 -0800858 LYERRLOG("SQL error: %s\n", zErrMsg);
859 sqlite3_free(zErrMsg);
860 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700861 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800862 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800863 }
xf.licb6cd282024-02-21 22:06:14 -0800864 LYINFLOG("clean apn table successfully\n");
865 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700866 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800867 return RESULT_OK;
868}
869
870static int find_unuse_apn_index(char *path)
871{
872 char *zErrMsg = 0;
873 int rc;
874 int count =1;
875 bool apn_usable = false;
876 char *sql;
877
878 memset(apn_indexs,0,sizeof(apn_indexs));
879 next_index = 0;
880 LYINFLOG("index = %p",apn_indexs);
881 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700882 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800883 rc = sqlite3_open(APN_DB_PATH, &apnDb);
884 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800885 {
xf.licb6cd282024-02-21 22:06:14 -0800886 LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700887 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800888 return -1;
xf.li63b87e82024-01-04 00:43:35 -0800889 }
890 else
891 {
xf.licb6cd282024-02-21 22:06:14 -0800892 LYINFLOG("Opened database successfully\n");
xf.li63b87e82024-01-04 00:43:35 -0800893 }
xf.li63b87e82024-01-04 00:43:35 -0800894
xf.licb6cd282024-02-21 22:06:14 -0800895 /* Create SQL statement */
896 sql = "SELECT ID from LYNQAPN";
897 /* Execute SQL statement */
898 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg);
899 if( rc != SQLITE_OK )
900 {
901 LYERRLOG("SQL error: %s\n", zErrMsg);
902 sqlite3_free(zErrMsg);
xf.lib5d82bf2024-03-09 01:54:50 -0800903 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700904 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800905 return -1;
906 }
907 else
908 {
909 LYINFLOG("Operation done successfully\n");
910 }
911 //indexs = temp_index;
912 LYINFLOG("index = %p",apn_indexs);
913 for(count;count<=QSER_APN_MAX_LIST;count++)
914 {
915 //if(apn_indexs[count-1]!=count)
916 LYINFLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count);
917 if(apn_indexs[count]!=count)
918 {
919 //apn_usable=true;
920 break;
921 }
922 }
923 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700924 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800925 LYINFLOG("count is %d\n", count);
926 return count;
xf.li63b87e82024-01-04 00:43:35 -0800927}
928
xf.licb6cd282024-02-21 22:06:14 -0800929static int apn_db_add(int profile_id, qser_apn_add_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700930{
xf.licb6cd282024-02-21 22:06:14 -0800931 char *zErrMsg = 0;
932 int rc;
xf.li0fd6acf2023-12-20 18:16:34 -0800933 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.licb6cd282024-02-21 22:06:14 -0800934 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700935 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800936 rc = sqlite3_open(APN_DB_PATH, &apnDb);
937 if( rc )
xf.li2fc84552023-06-23 05:26:47 -0700938 {
xf.licb6cd282024-02-21 22:06:14 -0800939 LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700940 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800941 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700942 }
xf.licb6cd282024-02-21 22:06:14 -0800943 LYINFLOG("[%s] Opened database successfully",__FUNCTION__);
944 /* Create SQL statement */
945 /* Execute SQL statement */
946 LYINFLOG("the profile id is %d\n", profile_id);
947 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);
948 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
949 if( rc != SQLITE_OK )
xf.li2fc84552023-06-23 05:26:47 -0700950 {
xf.licb6cd282024-02-21 22:06:14 -0800951 LYERRLOG( "SQL error: %s", zErrMsg);
952 sqlite3_free(zErrMsg);
953 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700954 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800955 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700956 }
xf.licb6cd282024-02-21 22:06:14 -0800957 LYINFLOG("write apn to apn db successfully");
958 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700959 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800960 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700961}
962
xf.licb6cd282024-02-21 22:06:14 -0800963static int apn_db_delete(unsigned char profile_idx)
xf.li2fc84552023-06-23 05:26:47 -0700964{
xf.licb6cd282024-02-21 22:06:14 -0800965 char *zErrMsg = 0;
966 int rc;
xf.li2fc84552023-06-23 05:26:47 -0700967
xf.licb6cd282024-02-21 22:06:14 -0800968 if(!lynq_check_index(profile_idx))
969 {
970 return LYNQ_E_APN_DB_FAIL;
971 }
972 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700973 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800974 rc = sqlite3_open(APN_DB_PATH, &apnDb);
975 if( rc )
976 {
977 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700978 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800979 return LYNQ_E_APN_DB_FAIL;
980 }
981
982 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
983 /* Create SQL statement */
984 //sql = "SELECT * from LYNQAPN";
xf.li87f6e6e2024-06-19 02:23:05 -0700985 char *sql = sqlite3_mprintf("DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800986 LYINFLOG("sql: %s\n", sql);
987 /* Execute SQL statement */
988 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
989 if( rc != SQLITE_OK )
990 {
991 LYERRLOG("SQL error: %s\n", zErrMsg);
992 sqlite3_free(zErrMsg);
993 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700994 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800995 return LYNQ_E_APN_DB_FAIL;
996 }
997 LYINFLOG("delete apn %d successfully\n", profile_idx);
998 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700999 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001000 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001001}
1002
xf.licb6cd282024-02-21 22:06:14 -08001003static int apn_db_modify(qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001004{
xf.licb6cd282024-02-21 22:06:14 -08001005 char *zErrMsg = 0;
1006 int rc;
xf.li2fc84552023-06-23 05:26:47 -07001007
xf.licb6cd282024-02-21 22:06:14 -08001008 if(!lynq_check_index(apn->profile_idx))
1009 {
1010 return LYNQ_E_APN_DB_FAIL;
1011 }
1012 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001013 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001014 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1015 if( rc )
1016 {
1017 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001018 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001019 return LYNQ_E_APN_DB_FAIL;
1020 }
1021
1022 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1023 /* Create SQL statement */
1024 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);
1025 LYINFLOG("sql: %s\n", sql);
1026 /* Execute SQL statement */
1027 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
1028 if( rc != SQLITE_OK )
1029 {
1030 LYERRLOG("SQL error: %s\n", zErrMsg);
1031 sqlite3_free(zErrMsg);
1032 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001033 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001034 return LYNQ_E_APN_DB_FAIL;
1035 }
1036 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1037 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001038 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001039 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001040}
1041
xf.licb6cd282024-02-21 22:06:14 -08001042static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName)
xf.li2fc84552023-06-23 05:26:47 -07001043{
xf.licb6cd282024-02-21 22:06:14 -08001044 if(data==NULL)
xf.li2fc84552023-06-23 05:26:47 -07001045 {
xf.licb6cd282024-02-21 22:06:14 -08001046 return 1;
xf.li2fc84552023-06-23 05:26:47 -07001047 }
xf.licb6cd282024-02-21 22:06:14 -08001048 qser_apn_info_s* temp = (qser_apn_info_s *)data;
1049 for(int i=0; i<argc; i++){
1050 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001051 }
xf.licb6cd282024-02-21 22:06:14 -08001052 temp->profile_idx = atoi(argv[0]);
1053 temp->pdp_type = atoi(argv[1]);
1054 temp->auth_proto = atoi(argv[2]);
1055 memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE);
1056 memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE);
1057 memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE);
1058 memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE);
1059 LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0]));
1060 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001061}
xf.licb6cd282024-02-21 22:06:14 -08001062static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001063{
xf.licb6cd282024-02-21 22:06:14 -08001064 char *zErrMsg = 0;
1065 int rc;
1066
1067 if(!lynq_check_index(profile_idx))
xf.li2fc84552023-06-23 05:26:47 -07001068 {
xf.licb6cd282024-02-21 22:06:14 -08001069 return LYNQ_E_APN_DB_FAIL;
1070 }
1071 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001072 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001073 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1074 if( rc )
1075 {
1076 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001077 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001078 return LYNQ_E_APN_DB_FAIL;
1079 }
1080
1081 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1082 /* Create SQL statement */
1083 char *sql = sqlite3_mprintf("SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx);
1084 LYINFLOG("sql: %s\n", sql);
1085 /* Execute SQL statement */
1086 rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg);
1087 if( rc != SQLITE_OK )
1088 {
1089 LYERRLOG("SQL error: %s\n", zErrMsg);
1090 sqlite3_free(zErrMsg);
1091 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001092 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001093 return LYNQ_E_APN_DB_FAIL;
1094 }
1095 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1096 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001097 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001098 return 0;
1099}
1100static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName)
1101{
1102 int i;
1103
1104 //apn_count++;
1105
1106 qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data;
1107 for(i=0; i<argc; i++){
1108 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001109 }
1110
xf.licb6cd282024-02-21 22:06:14 -08001111 temp->apn[temp->cnt].profile_idx = atoi(argv[0]);
1112 temp->apn[temp->cnt].pdp_type = atoi(argv[1]);
1113 temp->apn[temp->cnt].auth_proto = atoi(argv[2]);
1114 memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE);
1115 memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE);
1116 memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE);
1117 memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE);
1118 temp->cnt++;
1119 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001120}
xf.licb6cd282024-02-21 22:06:14 -08001121static int apn_db_query_list(qser_apn_info_list_s *apn_list)
1122{
1123 char *zErrMsg = 0;
1124 int rc;
xf.li2fc84552023-06-23 05:26:47 -07001125
xf.licb6cd282024-02-21 22:06:14 -08001126 /* Open database */
1127 apn_count = 0;
1128 apn_list->cnt = 0;
xf.li87f6e6e2024-06-19 02:23:05 -07001129 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001130 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1131 if( rc )
1132 {
1133 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001134 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001135 return LYNQ_E_APN_DB_FAIL;
1136 }
1137
1138 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1139 /* Create SQL statement */
1140 char *sql = sqlite3_mprintf("SELECT * from LYNQAPN");
1141 LYINFLOG("sql: %s\n", sql);
1142 /* Execute SQL statement */
1143 rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg);
1144 if( rc != SQLITE_OK )
1145 {
1146 LYERRLOG("SQL error: %s\n", zErrMsg);
1147 sqlite3_free(zErrMsg);
1148 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001149 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001150 return LYNQ_E_APN_DB_FAIL;
1151 }
1152 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001153 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001154 return 0;
1155}
1156// **************apn DB end****************************
xf.li2fc84552023-06-23 05:26:47 -07001157void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
1158{
1159 switch (pdp_type)
1160 {
1161 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -08001162#ifdef MOBILETEK_TARGET_PLATFORM_T106
1163 strcpy(out_pdp_type,"IP");
1164#else
xf.li2fc84552023-06-23 05:26:47 -07001165 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -08001166#endif
xf.li2fc84552023-06-23 05:26:47 -07001167 break;
1168 case QSER_APN_PDP_TYPE_PPP:
1169 strcpy(out_pdp_type,"PPP");
1170 break;
1171 case QSER_APN_PDP_TYPE_IPV6:
1172 strcpy(out_pdp_type,"IPV6");
1173 break;
1174 case QSER_APN_PDP_TYPE_IPV4V6:
1175 strcpy(out_pdp_type,"IPV4V6");
1176 break;
1177 default:
1178 strcpy(out_pdp_type,"NULL");
1179 break;
1180 }
1181 return;
1182}
1183void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
1184{
1185 switch (auth_proto)
1186 {
1187 case QSER_APN_AUTH_PROTO_DEFAULT:
xf.lifb6134e2024-05-09 01:26:54 -07001188 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001189 break;
1190 case QSER_APN_AUTH_PROTO_NONE:
xf.lifb6134e2024-05-09 01:26:54 -07001191 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001192 break;
1193 case QSER_APN_AUTH_PROTO_PAP:
xf.lifb6134e2024-05-09 01:26:54 -07001194 strcpy(out_proto,"1");
xf.li2fc84552023-06-23 05:26:47 -07001195 break;
1196 case QSER_APN_AUTH_PROTO_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001197 strcpy(out_proto,"2");
xf.li2fc84552023-06-23 05:26:47 -07001198 break;
1199 case QSER_APN_AUTH_PROTO_PAP_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001200 strcpy(out_proto,"3");
xf.li2fc84552023-06-23 05:26:47 -07001201 break;
1202 default:
xf.lifb6134e2024-05-09 01:26:54 -07001203 strcpy(out_proto,"NULL");
xf.li2fc84552023-06-23 05:26:47 -07001204 break;
1205 }
1206 return ;
1207}
1208
1209int data_call_handle_get(const char profile_idx,int *handle)
1210{
1211 int num = LYNQ_APN_CHANNEL_MAX;
1212 int table_num = 0;
1213 lynq_apn_info **apn_table = NULL;
1214 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001215 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001216 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1217 if (NULL == apn_table)
1218 {
1219 LYERRLOG("malloc apn_table fail ");
1220 return RESULT_ERROR;
1221 }
1222 for(int i =0;i<10;i++)
1223 {
1224 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1225 if (apn_table[i]==NULL)
1226 {
1227 for (int n=0;n<i;n++)
1228 {
1229 free(apn_table[n]);
1230 }
1231 return RESULT_ERROR;
1232 }
1233 memset(apn_table[i],0,sizeof(lynq_apn_info));
1234 }
1235 lynq_get_apn_table(&table_num,apn_table);
1236 memset(&apn,0,sizeof(qser_apn_info_s));
xf.licb6cd282024-02-21 22:06:14 -08001237 ret = apn_db_query(profile_idx,&apn);
xf.li0fc26502023-09-16 02:10:17 -07001238 if (ret < 0)
1239 {
xf.licb6cd282024-02-21 22:06:14 -08001240 LYERRLOG("apn_db_query error");
xf.li0fc26502023-09-16 02:10:17 -07001241 return ret;
1242 }
xf.li2fc84552023-06-23 05:26:47 -07001243 for (int j = 0;j < table_num;j++)
1244 {
1245 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1246 {
1247 *handle = apn_table[j]->index;
1248 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1249 break;
1250 }
1251 }
1252
1253 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1254 {
1255 if (apn_table[i]!=NULL)
1256 {
1257 free(apn_table[i]);
1258 apn_table[i]=NULL;
1259 }
1260 }
1261 free(apn_table);
1262 apn_table=NULL;
1263 LYINFLOG("data_call_handle_get end");
1264 return RESULT_OK;
1265}
1266
1267void *thread_wait_cb_status(void)
1268{
1269 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001270 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001271 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001272 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001273 qser_data_call_state_s data_cb_state;
1274 while (s_qser_data_cb_thread_status)
1275 {
xf.li6b0d8502023-09-04 18:49:12 -07001276 ret = lynq_wait_data_call_state_change(&handle);
1277 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
1278 if(s_qser_data_cb_thread_status == 0)
1279 {
1280 return NULL;
1281 }
1282 else if(ret < 0)
1283 {
1284 continue;
1285 }
xf.li8535bc02023-12-12 23:28:35 -08001286 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
1287 memset(&data_urc_info, 0, sizeof(data_urc_info));
1288 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001289 lynq_get_data_call_list(&handle,&data_urc_info);
1290 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001291 //data_cb_state.profile_idx = (char)handle;
xf.licb6cd282024-02-21 22:06:14 -08001292 apn_db_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li87f6e6e2024-06-19 02:23:05 -07001293 LYINFLOG("[thread_wait_cb_status]: callback profile_idx is %d\n", data_cb_state.profile_idx);
xf.li8535bc02023-12-12 23:28:35 -08001294 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",
1295 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
1296 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
1297 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -07001298 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001299 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001300 {
1301 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1302 }
1303 else if (!strcmp(data_urc_info.type,"IPV6"))
1304 {
1305 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1306 }
xf.li8535bc02023-12-12 23:28:35 -08001307 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001308 {
1309 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1310 }
1311 else
1312 {
xf.li8535bc02023-12-12 23:28:35 -08001313 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001314 }
1315
xf.li8535bc02023-12-12 23:28:35 -08001316 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001317 {
1318 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1319 }
1320 else
1321 {
1322 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.licb6cd282024-02-21 22:06:14 -08001323 ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001324 if(ret != 0)
1325 {
1326 LYERRLOG("handle set error");
1327 }
xf.li2fc84552023-06-23 05:26:47 -07001328 }
1329 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1330 {
1331 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1332 }
1333 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1334 {
1335 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1336 }
1337 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1338 {
xf.li3c0a4752023-09-03 20:46:19 -07001339#ifdef MOBILETEK_TARGET_PLATFORM_T106
1340 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1341#else
xf.li2fc84552023-06-23 05:26:47 -07001342 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001343#endif
xf.li2fc84552023-06-23 05:26:47 -07001344 }
1345 else
1346 {
1347 LYERRLOG("unknow ip_family");
1348 continue;
1349 }
1350 if (s_data_call_cb != NULL)
1351 {
1352 s_data_call_cb(&data_cb_state);
1353 }
1354 }
1355 return NULL;
1356}
1357
1358int qser_cb_pthread_create()
1359{
xf.lib5d82bf2024-03-09 01:54:50 -08001360 pthread_attr_t attr;
xf.li2fc84552023-06-23 05:26:47 -07001361 int ret;
1362 s_qser_data_cb_thread_status = 1;
xf.lib5d82bf2024-03-09 01:54:50 -08001363
1364 pthread_attr_init(&attr);
1365 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1366
1367 ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL);
xf.li2fc84552023-06-23 05:26:47 -07001368 if (ret < 0)
1369 {
1370 LYERRLOG("pthread create fail");
1371 s_qser_data_cb_thread_status = 0;
1372 return RESULT_ERROR;
1373 }
xf.lib5d82bf2024-03-09 01:54:50 -08001374 pthread_attr_destroy(&attr);
xf.li2fc84552023-06-23 05:26:47 -07001375 return RESULT_OK;
1376}
1377
1378void qser_cb_pthread_cancel()
1379{
xf.li2fc84552023-06-23 05:26:47 -07001380 s_qser_data_cb_thread_status = 0;
1381 if (s_cb_tid != -1)
1382 {
xf.li6b0d8502023-09-04 18:49:12 -07001383 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001384 }
1385 return;
1386}
xf.li2fc84552023-06-23 05:26:47 -07001387int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1388{
1389 int ret = 0;
1390 int utoken = 0;
1391 if (NULL == evt_cb)
1392 {
1393 LYERRLOG("init incoming paramters error");
1394 return RESULT_ERROR;
1395 }
xf.li09b46db2024-03-13 19:21:18 -07001396 if(g_lynq_qser_data_init_flag == 1)
1397 {
1398 LYERRLOG("init twice is not allowed");
1399 return RESULT_ERROR;
1400 }
xf.li2fc84552023-06-23 05:26:47 -07001401 ret = lynq_init_data(utoken);
1402 if (ret != RESULT_OK)
1403 {
xf.li6b0d8502023-09-04 18:49:12 -07001404 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001405 s_data_call_cb = NULL;
1406 return RESULT_ERROR;
1407 }
xf.li6b0d8502023-09-04 18:49:12 -07001408 qser_cb_pthread_create();
xf.licb6cd282024-02-21 22:06:14 -08001409 ret = init_apn_db();
1410 if(ret != RESULT_OK)
xf.lie3f55f42023-12-01 22:47:33 -08001411 {
xf.licb6cd282024-02-21 22:06:14 -08001412 LYERRLOG("init apn db error");
xf.lie3f55f42023-12-01 22:47:33 -08001413 return RESULT_ERROR;
1414 }
xf.licb6cd282024-02-21 22:06:14 -08001415
1416 ret = apn_db_handle_clean();
xf.li63b87e82024-01-04 00:43:35 -08001417 if(ret != RESULT_OK)
1418 {
1419 LYERRLOG("clean handle error");
1420 return RESULT_ERROR;
1421 }
xf.li09b46db2024-03-13 19:21:18 -07001422 s_data_call_cb = evt_cb;
xf.lib33d4862023-12-13 00:40:37 -08001423 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001424 return RESULT_OK;
1425}
1426
1427void qser_data_call_destroy(void)
1428{
xf.li6b0d8502023-09-04 18:49:12 -07001429 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001430 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001431 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001432 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001433 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001434 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001435 return ;
1436}
1437
1438int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1439{
1440 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001441 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001442 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001443 if(g_lynq_qser_data_init_flag == 0)
1444 {
1445 if(err != NULL)
1446 {
1447 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1448 }
1449 return LYNQ_E_NO_INIT;
1450 }
xf.li2fc84552023-06-23 05:26:47 -07001451 if (NULL == data_call || NULL == err)
1452 {
1453 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001454 if(err != NULL)
1455 {
1456 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1457 }
xf.li2fc84552023-06-23 05:26:47 -07001458 return ret;
1459 }
1460 if (data_call->profile_idx == 0)
1461 {
1462 ret = lynq_setup_data_call(&handle);
1463 }
1464 else
1465 {
1466 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001467 char auth_proto[16];
xf.li2fc84552023-06-23 05:26:47 -07001468 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001469 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1470 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li0fc26502023-09-16 02:10:17 -07001471 if (ret != 0)
1472 {
1473 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001474 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001475 return ret;
1476 }
xf.li2fc84552023-06-23 05:26:47 -07001477 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001478 judge_authtype(apn_info.auth_proto,auth_proto);
1479 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 -07001480 }
xf.lic12b3702023-11-22 22:39:01 -08001481 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001482 {
1483 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1484 }
xf.li0fd6acf2023-12-20 18:16:34 -08001485 else
1486 {
xf.licb6cd282024-02-21 22:06:14 -08001487 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001488 if(error != 0)
1489 {
1490 LYERRLOG("handle set error");
1491 }
1492 }
xf.li2fc84552023-06-23 05:26:47 -07001493 return ret;
1494}
1495
xf.li8535bc02023-12-12 23:28:35 -08001496int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1497{
1498 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001499 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001500 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001501 if(g_lynq_qser_data_init_flag == 0)
1502 {
1503 if(err != NULL)
1504 {
1505 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1506 }
1507 return LYNQ_E_NO_INIT;
1508 }
xf.li8535bc02023-12-12 23:28:35 -08001509 if (NULL == data_call || NULL == err)
1510 {
1511 LYERRLOG("call start incoming paramters error");
1512 if(err != NULL)
1513 {
1514 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1515 }
1516 return ret;
1517 }
1518 if (data_call->profile_idx == 0)
1519 {
1520 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1521 }
1522 else
1523 {
1524 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001525 char auth_proto[16];
xf.li8535bc02023-12-12 23:28:35 -08001526 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001527 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1528 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li8535bc02023-12-12 23:28:35 -08001529 if (ret != 0)
1530 {
1531 LYERRLOG("qser_apn_get error");
1532 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1533 return ret;
1534 }
1535 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001536 judge_authtype(apn_info.auth_proto,auth_proto);
1537 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 -08001538 }
1539 if (ret != 0)
1540 {
1541 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1542 }
xf.li0fd6acf2023-12-20 18:16:34 -08001543 else
1544 {
xf.licb6cd282024-02-21 22:06:14 -08001545 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001546 if(error != 0)
1547 {
1548 LYERRLOG("handle set error");
1549 }
1550 }
xf.li8535bc02023-12-12 23:28:35 -08001551 return ret;
1552}
1553
xf.li2fc84552023-06-23 05:26:47 -07001554int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1555{
1556 int ret = 0;
1557 int handle = -1;
1558
xf.lib33d4862023-12-13 00:40:37 -08001559 if(g_lynq_qser_data_init_flag == 0)
1560 {
1561 if(err != NULL)
1562 {
1563 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1564 }
1565 return LYNQ_E_NO_INIT;
1566 }
xf.li2fc84552023-06-23 05:26:47 -07001567 if (NULL == err)
1568 {
1569 LYERRLOG("call stop incoming paramters error");
1570 return ret;
1571 }
xf.lic12b3702023-11-22 22:39:01 -08001572 ret = data_call_handle_get(profile_idx,&handle);
1573 if(ret != 0)
1574 {
1575 LYERRLOG("datacall handle get error");
1576 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1577 return ret;
1578 }
xf.li2fc84552023-06-23 05:26:47 -07001579 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001580 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001581 {
1582 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001583 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001584 }
xy.hee2daacc2023-09-18 00:57:51 -07001585 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001586}
1587int 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)
1588{
1589 int ret = 0;
1590 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001591 if(g_lynq_qser_data_init_flag == 0)
1592 {
1593 if(err != NULL)
1594 {
1595 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1596 }
1597 return LYNQ_E_NO_INIT;
1598 }
xf.li2fc84552023-06-23 05:26:47 -07001599 lynq_data_call_response_v11_t data_call_info;
1600 data_call_handle_get(profile_idx,&handle);
1601 ret = lynq_get_data_call_list(&handle,&data_call_info);
1602 if (ret == 0)
1603 {
1604 info->profile_idx = profile_idx;
1605 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001606 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 -07001607 {
xf.li0400b382024-06-05 19:20:36 -07001608 info->ip_family = QSER_DATA_CALL_TYPE_IPV4;
xf.li2fc84552023-06-23 05:26:47 -07001609 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001610 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001611 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1612 lynq_ipv4_aton_getinfo(&data_call_info,info);
1613 }
xf.li3c0a4752023-09-03 20:46:19 -07001614 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001615 {
xf.li0400b382024-06-05 19:20:36 -07001616 info->ip_family = QSER_DATA_CALL_TYPE_IPV6;
xf.li2fc84552023-06-23 05:26:47 -07001617 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001618 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001619 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1620 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1621 }
xf.li3c0a4752023-09-03 20:46:19 -07001622 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001623 {
xf.li0400b382024-06-05 19:20:36 -07001624 info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
xf.li2fc84552023-06-23 05:26:47 -07001625 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001626 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001627 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 -07001628#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001629 lynq_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001630#endif
xf.li2fc84552023-06-23 05:26:47 -07001631 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001632 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001633 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 -07001634#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001635 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001636#endif
1637#ifdef MOBILETEK_TARGET_PLATFORM_T106
1638 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1639#endif
xf.li2fc84552023-06-23 05:26:47 -07001640 }
1641 else
1642 {
1643 LYERRLOG("useless qser_data_call_ip_family_e");
1644 }
1645 }
1646 return ret;
1647}
xf.lifb6134e2024-05-09 01:26:54 -07001648int check_pdp_type(qser_apn_pdp_type_e pdp_type)
1649{
1650 switch (pdp_type)
1651 {
1652 case QSER_APN_PDP_TYPE_IPV4:
1653 case QSER_APN_PDP_TYPE_PPP:
1654 case QSER_APN_PDP_TYPE_IPV6:
1655 case QSER_APN_PDP_TYPE_IPV4V6:
1656 return 0;
1657 default:
1658 return -1;
1659 }
1660}
1661int check_auth_proto(qser_apn_auth_proto_e auth_proto)
1662{
1663 switch (auth_proto)
1664 {
1665 case QSER_APN_AUTH_PROTO_DEFAULT:
1666 case QSER_APN_AUTH_PROTO_NONE:
1667 case QSER_APN_AUTH_PROTO_PAP:
1668 case QSER_APN_AUTH_PROTO_CHAP:
1669 case QSER_APN_AUTH_PROTO_PAP_CHAP:
1670 return 0;
1671 default:
1672 return -1;
1673 }
1674}
xf.li2fc84552023-06-23 05:26:47 -07001675int qser_apn_set(qser_apn_info_s *apn)
1676{
1677 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001678 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001679 if(g_lynq_qser_data_init_flag == 0)
1680 {
1681 return LYNQ_E_NO_INIT;
1682 }
xf.li4b18fa62023-12-19 19:38:10 -08001683 if (NULL == apn || apn->profile_idx == 0)
xf.li2fc84552023-06-23 05:26:47 -07001684 {
1685 LYERRLOG("apn set incoming paramters error");
1686 return RESULT_ERROR;
1687 }
xf.licb6cd282024-02-21 22:06:14 -08001688 ret = apn_db_handle_get(apn->profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001689 if(ret != 0)
1690 {
1691 LYERRLOG("handle set error");
1692 }
1693 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1694 {
1695 LYERRLOG("It has setup datacall");
1696 return RESULT_ERROR;
1697 }
xf.lifb6134e2024-05-09 01:26:54 -07001698
1699 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1700 {
1701 LYERRLOG("apn_name out of range\n");
1702 return RESULT_ERROR;
1703 }
1704 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1705 {
1706 LYERRLOG("username out of range\n");
1707 return RESULT_ERROR;
1708 }
1709 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1710 {
1711 LYERRLOG("password out of range\n");
1712 return RESULT_ERROR;
1713 }
1714 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1715 {
1716 LYERRLOG("apn_type out of range\n");
1717 return RESULT_ERROR;
1718 }
1719 if(check_pdp_type(apn->pdp_type) != 0)
1720 {
1721 LYERRLOG("pdp_type out of range\n");
1722 return RESULT_ERROR;
1723 }
1724 if(check_auth_proto(apn->auth_proto) != 0)
1725 {
1726 LYERRLOG("auth_proto out of range\n");
1727 return RESULT_ERROR;
1728 }
1729
xf.licb6cd282024-02-21 22:06:14 -08001730 ret = apn_db_modify(apn);
xf.li2fc84552023-06-23 05:26:47 -07001731 if (ret < 0)
1732 {
xf.licb6cd282024-02-21 22:06:14 -08001733 LYERRLOG("apn_db_modify error");
xf.li2fc84552023-06-23 05:26:47 -07001734 return ret;
1735 }
xf.li6c7e3972023-10-27 20:01:59 -07001736#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001737 int apn_id = 0;
1738 char tmp_id[12];
1739 char *outinfo = NULL;
1740 char normalprotocol[16];
1741 char authtype[32];
1742 outinfo = (char *)malloc(sizeof(char)*512);
1743 bzero(tmp_id,12);
1744 bzero(outinfo,512);
1745 apn_id = apn->profile_idx + apndb_offset;
1746 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1747 judge_pdp_type(apn->pdp_type,normalprotocol);
1748 judge_authtype(apn->auth_proto,authtype);
1749 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1750 LYINFLOG("[output]:%s",outinfo);
1751 free(outinfo);
1752 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001753#endif
1754 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001755}
1756
1757int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1758{
xf.lib33d4862023-12-13 00:40:37 -08001759 if(g_lynq_qser_data_init_flag == 0)
1760 {
1761 return LYNQ_E_NO_INIT;
1762 }
xf.licb6cd282024-02-21 22:06:14 -08001763 if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn)
xf.li2fc84552023-06-23 05:26:47 -07001764 {
1765 LYERRLOG("apn get incoming paramters error");
1766 return RESULT_ERROR;
1767 }
1768 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001769 ret = apn_db_query(profile_idx,apn);
xf.li2fc84552023-06-23 05:26:47 -07001770 if (ret < 0)
1771 {
xf.licb6cd282024-02-21 22:06:14 -08001772 LYERRLOG("apn_db_query error");
xf.li2fc84552023-06-23 05:26:47 -07001773 return ret;
1774 }
1775 return ret;
1776}
1777
1778int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1779{
1780 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001781
xf.lib33d4862023-12-13 00:40:37 -08001782 if(g_lynq_qser_data_init_flag == 0)
1783 {
1784 return LYNQ_E_NO_INIT;
1785 }
xf.li2fc84552023-06-23 05:26:47 -07001786 if (NULL == apn || NULL == profile_idx)
1787 {
1788 LYERRLOG("apn add incoming paramters error");
1789 return RESULT_ERROR;
1790 }
xf.lifb6134e2024-05-09 01:26:54 -07001791
1792 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1793 {
1794 LYERRLOG("apn_name out of range\n");
1795 return RESULT_ERROR;
1796 }
1797 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1798 {
1799 LYERRLOG("username out of range\n");
1800 return RESULT_ERROR;
1801 }
1802 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1803 {
1804 LYERRLOG("password out of range\n");
1805 return RESULT_ERROR;
1806 }
1807 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1808 {
1809 LYERRLOG("apn_type out of range\n");
1810 return RESULT_ERROR;
1811 }
1812 if(check_pdp_type(apn->pdp_type) != 0)
1813 {
1814 LYERRLOG("pdp_type out of range\n");
1815 return RESULT_ERROR;
1816 }
1817 if(check_auth_proto(apn->auth_proto) != 0)
1818 {
1819 LYERRLOG("auth_proto out of range\n");
1820 return RESULT_ERROR;
1821 }
xf.licb6cd282024-02-21 22:06:14 -08001822
1823 *profile_idx = 0;
1824 *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH);
1825 LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx);
1826 if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001827 {
xf.licb6cd282024-02-21 22:06:14 -08001828 LYINFLOG("[%s] apn full is false\n",__FUNCTION__);
1829 ret = apn_db_add((int)*profile_idx, apn);
1830 if (ret != 0)
1831 {
1832 LYERRLOG("apn_db_add error");
1833 return RESULT_ERROR;
1834 }
1835 else
1836 {
1837 return RESULT_OK;
1838 }
xf.li2fc84552023-06-23 05:26:47 -07001839 }
xf.licb6cd282024-02-21 22:06:14 -08001840 LYERRLOG("apn storage space is full!!!");
1841 return RESULT_ERROR;
xf.li6c7e3972023-10-27 20:01:59 -07001842#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001843 int apn_id = 0;
1844 char tmp_id[12];
1845 char *outinfo = NULL;
1846 char normalprotocol[16];
1847 char authtype[32];
1848 outinfo = (char *)malloc(sizeof(char)*512);
1849 bzero(tmp_id,12);
1850 bzero(outinfo,512);
1851 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1852 judge_pdp_type(apn->pdp_type,normalprotocol);
1853 judge_authtype(apn->auth_proto,authtype);
1854 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1855 LYINFLOG("[output]:%s",outinfo);
1856 free(outinfo);
1857 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001858#endif
1859 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001860}
1861
1862int qser_apn_del(unsigned char profile_idx)
1863{
xf.li87f6e6e2024-06-19 02:23:05 -07001864 int ret = 0;
1865 int handle = -1;
1866
1867 LYINFLOG("[%s] entry\n",__FUNCTION__);
xf.lib33d4862023-12-13 00:40:37 -08001868 if(g_lynq_qser_data_init_flag == 0)
1869 {
1870 return LYNQ_E_NO_INIT;
1871 }
xf.li4b18fa62023-12-19 19:38:10 -08001872 if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001873 {
1874 LYERRLOG("apn del incoming paramters error");
xf.li4b18fa62023-12-19 19:38:10 -08001875 return RESULT_ERROR;
xf.li2fc84552023-06-23 05:26:47 -07001876 }
xf.li87f6e6e2024-06-19 02:23:05 -07001877
xf.licb6cd282024-02-21 22:06:14 -08001878 ret = apn_db_handle_get(profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001879 if(ret != 0)
1880 {
1881 LYERRLOG("handle set error");
1882 }
1883 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1884 {
1885 LYERRLOG("It has setup datacall");
1886 return RESULT_ERROR;
1887 }
xf.licb6cd282024-02-21 22:06:14 -08001888 ret = apn_db_delete(profile_idx);
xf.li2fc84552023-06-23 05:26:47 -07001889 if (ret < 0)
1890 {
xf.licb6cd282024-02-21 22:06:14 -08001891 LYERRLOG("apn_db_delete error");
xf.li2fc84552023-06-23 05:26:47 -07001892 return ret;
1893 }
xf.li6c7e3972023-10-27 20:01:59 -07001894#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001895 int apn_id = 0;
1896 char tmp_id[12];
1897 char *outinfo = NULL;
1898 outinfo = (char *)malloc(sizeof(char)*512);
1899 bzero(tmp_id,12);
1900 bzero(outinfo,512);
1901 apn_id = profile_idx+apndb_offset;
1902 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1903 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1904 LYINFLOG("[output]:%s",outinfo);
1905 free(outinfo);
1906 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001907#endif
xf.li2fc84552023-06-23 05:26:47 -07001908 return ret;
1909}
1910
1911int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1912{
xf.lib33d4862023-12-13 00:40:37 -08001913 if(g_lynq_qser_data_init_flag == 0)
1914 {
1915 return LYNQ_E_NO_INIT;
1916 }
xf.li2fc84552023-06-23 05:26:47 -07001917 if (NULL == apn_list)
1918 {
1919 LYERRLOG("apn_list incoming paramters error");
1920 return RESULT_ERROR;
1921 }
1922 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001923 ret = apn_db_query_list(apn_list);
xf.li2fc84552023-06-23 05:26:47 -07001924 if (ret < 0)
1925 {
xf.licb6cd282024-02-21 22:06:14 -08001926 LYERRLOG("apn_db_query_list error");
xf.li2fc84552023-06-23 05:26:47 -07001927 return ret;
1928 }
1929 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001930}
you.chen21c62b72023-09-08 09:41:11 +08001931
1932DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1933