blob: 23a783182e5dcecb82f3724da7185cc18b17f771 [file] [log] [blame]
xf.li2fc84552023-06-23 05:26:47 -07001#include <stdio.h>
2#include <stdint.h>
3#include <sys/types.h>
4#include <arpa/inet.h>
5#include <string.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <log/log.h>
9#include <libdata/lynq_data.h>
10#include <liblog/lynq_deflog.h>
11#include <pthread.h>
xf.licb6cd282024-02-21 22:06:14 -080012#include <sqlite3.h>
xf.li2fc84552023-06-23 05:26:47 -070013#include "lynq-qser-data.h"
14
15#define USER_LOG_TAG "LYNQ_QSER_DATA"
xf.licb6cd282024-02-21 22:06:14 -080016#define APN_DB_PATH "/mnt/userdata/apn.db"
17#define APN_DB_READED 0
18#define APN_DB_ERR 1
19#define APN_DB_CREATE 2
xf.li1bbfc7d2024-07-15 23:50:41 -070020#define APN_TABLE_CREATE 3
21#define APN_TABLE_NEED_CREATE 4
xf.li2fc84552023-06-23 05:26:47 -070022#define RESULT_OK (0)
23#define RESULT_ERROR (-1)
24
xf.lib33d4862023-12-13 00:40:37 -080025typedef enum{
xf.licb6cd282024-02-21 22:06:14 -080026 LYNQ_E_NO_INIT=9002,
27 LYNQ_E_APN_DB_FAIL=9003
xf.lib33d4862023-12-13 00:40:37 -080028}LYNQ_E;
29
30static int g_lynq_qser_data_init_flag = 0;
xf.li2fc84552023-06-23 05:26:47 -070031static pthread_t s_cb_tid = -1;
32static int s_qser_data_cb_thread_status = 0;
33static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER;
xf.li87f6e6e2024-06-19 02:23:05 -070034static pthread_mutex_t s_qser_data_database_mutex = PTHREAD_MUTEX_INITIALIZER;
xf.li2fc84552023-06-23 05:26:47 -070035static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER;
36
xf.li2fc84552023-06-23 05:26:47 -070037
38static qser_data_call_evt_cb_t s_data_call_cb = NULL;
xf.licb6cd282024-02-21 22:06:14 -080039static sqlite3* apnDb;
40qser_apn_add_s default_apn = {QSER_APN_PDP_TYPE_IPV4V6, QSER_APN_AUTH_PROTO_DEFAULT, "default", "NULL", "NULL", "default"};
41int apn_indexs[LYNQ_APN_CHANNEL_MAX]={0};
42int next_index = 0;
43int apn_count = 0;
xf.li2fc84552023-06-23 05:26:47 -070044const int apndb_offset = 683;
45
xf.licb6cd282024-02-21 22:06:14 -080046static int init_apn_db();
47static int create_apn_db(char *path);
48static int create_apn_table(char*path);
49static int has_apn_db_created(char *path,sqlite3* apnDb_l);
50static int apn_db_handle_clean();
51
52static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName);
53static int lynq_check_index(unsigned char index);
54static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName);
55static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx);
56static int apn_db_handle_set(unsigned char profile_idx, int handle);
57static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName);
58static int apn_db_handle_get(unsigned char profile_idx, int *handle);
59
60static int find_unuse_apn_index(char *path);
61static int apn_db_add(int profile_id, qser_apn_add_s *apn);
62static int apn_db_delete(unsigned char profile_idx);
63static int apn_db_modify(qser_apn_info_s *apn);
64static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName);
65static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn);
66static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName);
67static int apn_db_query_list(qser_apn_info_list_s *apn_list);
68
xf.li2fc84552023-06-23 05:26:47 -070069void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
70{
xf.li3c0a4752023-09-03 20:46:19 -070071#ifdef MOBILETEK_TARGET_PLATFORM_T106
72 char *tmp_char = NULL;
73 char *addresses = NULL;
74 char *dnses = NULL;
75 const char addresses_separator[2] = "/";
76 const char dnses_separator[2] = " ";
77
78 addresses = libdata->addresses;
79 dnses = libdata->dnses;
80 //get addresses
81 tmp_char = strsep(&addresses, addresses_separator);
82 if(tmp_char != NULL)
83 {
84 LYINFLOG("ipv4 addresses = %s", tmp_char);
85 inet_aton(tmp_char,&(data_res->v4.ip));
86 }
87
88 //get dnses
89 tmp_char = strsep(&dnses, dnses_separator);
90 if(tmp_char != NULL)
91 {
92 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
93 inet_aton(tmp_char,&(data_res->v4.pri_dns));
94 }
95 tmp_char = strsep(&dnses, dnses_separator);
96 if(tmp_char != NULL)
97 {
98 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
99 inet_aton(tmp_char, &(data_res->v4.sec_dns));
100 }
101 //get gateway
102 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
103
104#else
xf.li2fc84552023-06-23 05:26:47 -0700105 inet_aton(libdata->addresses,&(data_res->v4.ip));
106 inet_aton(libdata->gateways,&(data_res->v4.gateway));
107 inet_aton(libdata->dnses,&(data_res->v4.pri_dns));
108 inet_aton(libdata->dnses,&(data_res->v4.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700109#endif
xf.li2fc84552023-06-23 05:26:47 -0700110 return ;
111}
112
113void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
114{
xf.li3c0a4752023-09-03 20:46:19 -0700115#ifdef MOBILETEK_TARGET_PLATFORM_T106
116 char *tmp_char = NULL;
117 char *addresses = NULL;
118 char *dnses = NULL;
119 const char addresses_separator[2] = "/";
120 const char dnses_separator[2] = " ";
121
122 addresses = libdata->addresses;
123 dnses = libdata->dnses;
124 //get addresses
125 tmp_char = strsep(&addresses, addresses_separator);
126 if(tmp_char != NULL)
127 {
128 LYINFLOG("ipv6 addresses = %s", tmp_char);
129 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
130 }
131 //get dnses
132 tmp_char = strsep(&dnses, dnses_separator);
133 if(tmp_char != NULL)
134 {
135 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
136 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
137 }
138 tmp_char = strsep(&dnses, dnses_separator);
139 if(tmp_char != NULL)
140 {
141 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
142 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
143 }
144 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
145#else
xf.li2fc84552023-06-23 05:26:47 -0700146 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip));
147 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
148 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns));
149 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700150#endif
151
152 return ;
153}
154
155void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res)
156{
157 char *tmp_char = NULL;
158 char *addresses = NULL;
159 char *dnses = NULL;
160 const char addresses_separator[2] = "/";
161 const char dnses_separator[2] = " ";
162
xf.li03baf1f2023-12-19 21:30:38 -0800163 char buf_ip[64] = {0};
164 char buf_gateway[64] = {0};
165 char buf_pri_dns[64] = {0};
166 char buf_sec_dns[64] = {0};
167
xf.li3c0a4752023-09-03 20:46:19 -0700168 addresses = libdata->addresses;
169 dnses = libdata->dnses;
170 //get addresses
171 tmp_char = strsep(&addresses, addresses_separator);
172 if(tmp_char != NULL)
173 {
174 LYINFLOG("ipv4 addresses = %s", tmp_char);
175 inet_aton(tmp_char,&(data_res->v4.ip));
176 }
177 tmp_char = strsep(&addresses, addresses_separator);
178 if(tmp_char != NULL)
179 {
180 LYINFLOG("ipv6 addresses = %s", tmp_char);
181 inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip));
182 }
183 //get dnses
184 tmp_char = strsep(&dnses, dnses_separator);
185 if(tmp_char != NULL)
186 {
187 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
188 inet_aton(tmp_char,&(data_res->v4.pri_dns));
189 }
190 tmp_char = strsep(&dnses, dnses_separator);
191 if(tmp_char != NULL)
192 {
193 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
194 inet_aton(tmp_char, &(data_res->v4.sec_dns));
195 }
196 tmp_char = strsep(&dnses, dnses_separator);
197 if(tmp_char != NULL)
198 {
199 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
200 inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns));
201 }
202 tmp_char = strsep(&dnses, dnses_separator);
203 if(tmp_char != NULL)
204 {
205 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
206 inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns));
207 }
208 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800209 inet_aton(libdata->gateways,&(data_res->v4.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700210 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway));
211
xf.li03baf1f2023-12-19 21:30:38 -0800212 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip));
213 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns));
214 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns));
215
216 inet_ntop(AF_INET6, &(data_res->v6.ip), buf_ip, sizeof(buf_ip));
217 inet_ntop(AF_INET6, &(data_res->v6.gateway), buf_gateway, sizeof(buf_gateway));
218 inet_ntop(AF_INET6, &(data_res->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
219 inet_ntop(AF_INET6, &(data_res->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
220 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
221 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
xf.li2fc84552023-06-23 05:26:47 -0700222 return ;
223}
224
225void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
226{
xf.li3c0a4752023-09-03 20:46:19 -0700227#ifdef MOBILETEK_TARGET_PLATFORM_T106
228 char *tmp_char = NULL;
229 char *addresses = NULL;
230 char *dnses = NULL;
231 const char addresses_separator[2] = "/";
232 const char dnses_separator[2] = " ";
233
234 addresses = libdata->addresses;
235 dnses = libdata->dnses;
236 //get addresses
237 tmp_char = strsep(&addresses, addresses_separator);
238 if(tmp_char != NULL)
239 {
240 LYINFLOG("ipv4 addresses = %s", tmp_char);
241 inet_aton(tmp_char,&(data_res->v4.addr.ip));
242 }
243 //get dnses
244 tmp_char = strsep(&dnses, dnses_separator);
245 if(tmp_char != NULL)
246 {
247 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
248 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
249 }
250 tmp_char = strsep(&dnses, dnses_separator);
251 if(tmp_char != NULL)
252 {
253 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
254 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
255 }
256 //get gateway
257 LYINFLOG("ipv4 gateways = %s", libdata->gateways);
258 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
259
260 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
261 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
262 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
263#else
xf.li2fc84552023-06-23 05:26:47 -0700264 inet_aton(libdata->addresses,&(data_res->v4.addr.ip));
265 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
266 inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns));
267 inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700268#endif
xf.li2fc84552023-06-23 05:26:47 -0700269 data_res->v4.stats.pkts_tx = 0;
270 data_res->v4.stats.pkts_rx = 0;
271 data_res->v4.stats.bytes_tx = 0;
272 data_res->v4.stats.bytes_rx = 0;
273 data_res->v4.stats.pkts_dropped_tx = 0;
274 data_res->v4.stats.pkts_dropped_rx = 0;
275 return ;
276}
277
278void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
279{
xf.li3c0a4752023-09-03 20:46:19 -0700280#ifdef MOBILETEK_TARGET_PLATFORM_T106
281 char *tmp_char = NULL;
282 char *addresses = NULL;
283 char *dnses = NULL;
284 const char addresses_separator[2] = "/";
285 const char dnses_separator[2] = " ";
286
287 addresses = libdata->addresses;
288 dnses = libdata->dnses;
289 //get addresses
290 tmp_char = strsep(&addresses, addresses_separator);
291 if(tmp_char != NULL)
292 {
293 LYINFLOG("ipv6 addresses = %s", tmp_char);
294 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
295 }
296 //get dnses
297 tmp_char = strsep(&dnses, dnses_separator);
298 if(tmp_char != NULL)
299 {
300 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
301 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
302 }
303 tmp_char = strsep(&dnses, dnses_separator);
304 if(tmp_char != NULL)
305 {
306 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
307 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
308 }
309 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
310#else
xf.li2fc84552023-06-23 05:26:47 -0700311 inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip));
312 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
313 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns));
314 inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns));
xf.li3c0a4752023-09-03 20:46:19 -0700315#endif
316 data_res->v6.stats.pkts_tx = 0;
317 data_res->v6.stats.pkts_rx = 0;
318 data_res->v6.stats.bytes_tx = 0;
319 data_res->v6.stats.bytes_rx = 0;
320 data_res->v6.stats.pkts_dropped_tx = 0;
321 data_res->v6.stats.pkts_dropped_rx = 0;
322 return ;
323}
324void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res)
325{
326 char *tmp_char = NULL;
327 char *addresses = NULL;
328 char *dnses = NULL;
329 const char addresses_separator[2] = "/";
330 const char dnses_separator[2] = " ";
331
332 char buf_ip[64] = {0};
333 char buf_gateway[64] = {0};
334 char buf_pri_dns[64] = {0};
335 char buf_sec_dns[64] = {0};
336
337 addresses = libdata->addresses;
338 dnses = libdata->dnses;
339 //get addresses
340 tmp_char = strsep(&addresses, addresses_separator);
341 if(tmp_char != NULL)
342 {
343 LYINFLOG("ipv4 addresses = %s", tmp_char);
344 inet_aton(tmp_char,&(data_res->v4.addr.ip));
345 }
346 tmp_char = strsep(&addresses, addresses_separator);
347 if(tmp_char != NULL)
348 {
349 LYINFLOG("ipv6 addresses = %s", tmp_char);
350 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip));
351 }
352 //get dnses
353 tmp_char = strsep(&dnses, dnses_separator);
354 if(tmp_char != NULL)
355 {
356 LYINFLOG("ipv4 pri_dns = %s", tmp_char);
357 inet_aton(tmp_char,&(data_res->v4.addr.pri_dns));
358 }
359 tmp_char = strsep(&dnses, dnses_separator);
360 if(tmp_char != NULL)
361 {
362 LYINFLOG("ipv4 sec_dns = %s", tmp_char);
363 inet_aton(tmp_char, &(data_res->v4.addr.sec_dns));
364 }
365 tmp_char = strsep(&dnses, dnses_separator);
366 if(tmp_char != NULL)
367 {
368 LYINFLOG("ipv6 pri_dns = %s", tmp_char);
369 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns));
370 }
371 tmp_char = strsep(&dnses, dnses_separator);
372 if(tmp_char != NULL)
373 {
374 LYINFLOG("ipv6 sec_dns = %s", tmp_char);
375 inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns));
376 }
377 //get gateway
xf.li03baf1f2023-12-19 21:30:38 -0800378 inet_aton(libdata->gateways,&(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700379 inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway));
380
381 LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip));
xf.li03baf1f2023-12-19 21:30:38 -0800382 LYINFLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway));
xf.li3c0a4752023-09-03 20:46:19 -0700383 LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns));
384 LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns));
385
386 inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip));
387 inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway));
388 inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns));
389 inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns));
390 LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n"
391 , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns);
392 data_res->v4.stats.pkts_tx = 0;
393 data_res->v4.stats.pkts_rx = 0;
394 data_res->v4.stats.bytes_tx = 0;
395 data_res->v4.stats.bytes_rx = 0;
396 data_res->v4.stats.pkts_dropped_tx = 0;
397 data_res->v4.stats.pkts_dropped_rx = 0;
398
xf.li2fc84552023-06-23 05:26:47 -0700399 data_res->v6.stats.pkts_tx = 0;
400 data_res->v6.stats.pkts_rx = 0;
401 data_res->v6.stats.bytes_tx = 0;
402 data_res->v6.stats.bytes_rx = 0;
403 data_res->v6.stats.pkts_dropped_tx = 0;
404 data_res->v6.stats.pkts_dropped_rx = 0;
405 return ;
406}
407
408void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res)
409{
xf.lib5dc0632023-11-30 18:20:35 -0800410 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700411 {
412 data_res->v4.state = QSER_DATA_CALL_CONNECTED;
413 data_res->v4.reconnect = 1;
414 }
415 else
416 {
417 data_res->v4.state = QSER_DATA_CALL_DISCONNECTED;
418 data_res->v4.reconnect = 0;
419 }
420 return ;
421}
422
423void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res)
424{
xf.lib5dc0632023-11-30 18:20:35 -0800425 if(state != 0)
xf.li2fc84552023-06-23 05:26:47 -0700426 {
427 data_res->v6.state = QSER_DATA_CALL_CONNECTED;
428 data_res->v6.reconnect = 1;
429 }
430 else
431 {
432 data_res->v6.state = QSER_DATA_CALL_DISCONNECTED;
433 data_res->v6.reconnect = 0;
434 }
435 return ;
436}
437
xf.licb6cd282024-02-21 22:06:14 -0800438// ****************apn DB start******************
439static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName)
xf.li0fd6acf2023-12-20 18:16:34 -0800440{
xf.licb6cd282024-02-21 22:06:14 -0800441 if(data==NULL)
xf.li0fd6acf2023-12-20 18:16:34 -0800442 {
xf.licb6cd282024-02-21 22:06:14 -0800443 return 1;
xf.li0fd6acf2023-12-20 18:16:34 -0800444 }
xf.licb6cd282024-02-21 22:06:14 -0800445 int *temp = (int *)data;
446 for(int i=0; i<argc; i++){
447 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li0fd6acf2023-12-20 18:16:34 -0800448 }
xf.licb6cd282024-02-21 22:06:14 -0800449 *temp = atoi(argv[0]);
450 return 0;
451}
452static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx)
453{
454 char *zErrMsg = 0;
455 int rc;
456 int idx = 0;
xf.liff415202024-09-19 23:08:09 -0700457 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800458
459 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700460 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800461 rc = sqlite3_open(APN_DB_PATH, &apnDb);
462 if( rc )
xf.li0fd6acf2023-12-20 18:16:34 -0800463 {
xf.licb6cd282024-02-21 22:06:14 -0800464 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700465 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800466 return LYNQ_E_APN_DB_FAIL;
467 }
468
469 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
470 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700471 sprintf(sql,"SELECT ID from LYNQAPN WHERE HANDLE=%d", handle);
xf.licb6cd282024-02-21 22:06:14 -0800472 LYINFLOG("sql: %s\n", sql);
473 /* Execute SQL statement */
474 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_profile_cb, &idx, &zErrMsg);
475 if( rc != SQLITE_OK )
476 {
477 LYERRLOG("SQL error: %s\n", zErrMsg);
478 sqlite3_free(zErrMsg);
479 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700480 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800481 return LYNQ_E_APN_DB_FAIL;
482 };
483 *profile_idx = (unsigned char)idx;
484 LYINFLOG("get idx %d successfully\n", *profile_idx);
485 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700486 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800487 return 0;
488}
489static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName){
490 int i;
491
492 apn_indexs[atoi(argv[0])] = atoi(argv[0]);
493 LYINFLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]);
494
495 for(i=0; i<argc; i++){
496 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
497 }
498 return 0;
499}
500/**
501 * @brief Check whether the ID exists in the database
502 *
503 * @param index
504 * @return int
505 * find:turn 1
506 * not find:turn 0
507 */
508static int lynq_check_index(unsigned char index)
509{
510 memset(apn_indexs,0,sizeof(apn_indexs));
511 next_index = 0;
512 char *zErrMsg = 0;
513 int rc;
514 char sql[128]={0};
515 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700516 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800517 rc = sqlite3_open(APN_DB_PATH, &apnDb);
518 if( rc )
519 {
520 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700521 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800522 return LYNQ_E_APN_DB_FAIL;
523 }
524 sprintf(sql,"%s", "SELECT * from LYNQAPN");
525 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback, NULL, &zErrMsg);
526 if( rc != SQLITE_OK )
527 {
528 LYERRLOG("SQL error: %s\n", zErrMsg);
529 sqlite3_free(zErrMsg);
530 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700531 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800532 return LYNQ_E_APN_DB_FAIL;
533 }
534 //for(int cnt = 0; cnt < next_index;cnt++)
535 for(int cnt = 0; cnt <= QSER_APN_MAX_LIST; cnt++)
536 {
537 if(index == apn_indexs[cnt])
538 {
539 LYINFLOG("index = apn_index\n");
540 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700541 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800542 return 1;
543 }
544 }
545 LYINFLOG("cant find the index %d\n", index);
546 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700547 pthread_mutex_unlock(&s_qser_data_database_mutex);
548
xf.licb6cd282024-02-21 22:06:14 -0800549 return 0;
550}
551
552static int apn_db_handle_set(unsigned char profile_idx, int handle)
553{
554 char *zErrMsg = 0;
555 int rc;
xf.liff415202024-09-19 23:08:09 -0700556 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800557 if(!lynq_check_index(profile_idx))
558 {
559 return LYNQ_E_APN_DB_FAIL;
560 }
561 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700562 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800563 rc = sqlite3_open(APN_DB_PATH, &apnDb);
564 if( rc )
565 {
566 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700567 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800568 return LYNQ_E_APN_DB_FAIL;
569 }
570
571 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
572 /* Create SQL statement */
573 //sql = "SELECT * from LYNQAPN";
xf.liff415202024-09-19 23:08:09 -0700574 sprintf(sql,"UPDATE LYNQAPN SET HANDLE=%d WHERE ID=%d", handle, (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800575 LYINFLOG("sql: %s\n", sql);
576 /* Execute SQL statement */
577 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
578 if( rc != SQLITE_OK )
579 {
580 LYERRLOG("SQL error: %s\n", zErrMsg);
581 sqlite3_free(zErrMsg);
582 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700583 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800584 return LYNQ_E_APN_DB_FAIL;
585 }
586 LYINFLOG("update apn %d successfully\n", profile_idx);
587 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700588 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800589 return 0;
590}
591static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName)
592{
593 if(data==NULL)
594 {
595 return 1;
596 }
597 int *temp = (int *)data;
598 for(int i=0; i<argc; i++){
599 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
600 }
601 *temp = atoi(argv[0]);
602 LYINFLOG("The handle is %d\n", *temp);
603 return 0;
604}
605static int apn_db_handle_get(unsigned char profile_idx, int *handle)
606{
607 char *zErrMsg = 0;
608 int rc;
xf.liff415202024-09-19 23:08:09 -0700609 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -0800610
xf.licb6cd282024-02-21 22:06:14 -0800611 if(!lynq_check_index(profile_idx))
612 {
613 return LYNQ_E_APN_DB_FAIL;
614 }
615 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700616 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800617 rc = sqlite3_open(APN_DB_PATH, &apnDb);
618 if( rc )
619 {
620 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700621 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800622 return LYNQ_E_APN_DB_FAIL;
623 }
624
625 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
626 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700627 sprintf(sql,"SELECT HANDLE from LYNQAPN WHERE ID=%d", (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800628 LYINFLOG("sql: %s\n", sql);
629 /* Execute SQL statement */
630 rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_cb, handle, &zErrMsg);
631 if( rc != SQLITE_OK )
632 {
633 LYERRLOG("SQL error: %s\n", zErrMsg);
634 sqlite3_free(zErrMsg);
635 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700636 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800637 return LYNQ_E_APN_DB_FAIL;
638 }
639 LYINFLOG("get idx %d successfully\n", *handle);
640 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700641 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800642 return 0;
643}
644
645static int has_apn_db_created(char *path,sqlite3* apnDb_l)
646{
647 if (path == NULL || strlen(path) == 0)
648 {
649 LYERRLOG("initApnDb error with null path!");
650 return APN_DB_ERR;
651 }
652 int rc = sqlite3_open_v2(path, &apnDb_l, SQLITE_OPEN_READWRITE,NULL);
653 if (rc == SQLITE_OK)
654 {
655 LYINFLOG("check init success!");
xf.lib5d82bf2024-03-09 01:54:50 -0800656 sqlite3_close_v2(apnDb_l);
xf.licb6cd282024-02-21 22:06:14 -0800657 return APN_DB_READED;
658 }
659 else
660 {
661 LYERRLOG("db has not create %s!", sqlite3_errmsg(apnDb_l));
662 sqlite3_close_v2(apnDb_l);
663 return APN_DB_ERR;
664 }
665}
666static int create_apn_db(char *path)
667{
668 if (path == NULL || strlen(path) == 0) {
669 LYERRLOG("initApnDb error with null path!");
670 return APN_DB_ERR;
671 }
672 if(APN_DB_READED==has_apn_db_created(path,apnDb))
673 {
674 return APN_DB_READED;
675 }
676 int rc = sqlite3_open(path, &apnDb);
677 if (rc != SQLITE_OK) {
678 LYERRLOG("initDb failed %d", sqlite3_errcode(apnDb));
679 return APN_DB_ERR;
680 } else {
681 LYINFLOG("create db in %s", path);
682 }
683 sqlite3_close(apnDb);
684 return APN_DB_CREATE;
685}
686static int create_apn_table(char*path)
687{
688 char *zErrMsg = 0;
689 int rc;
690 char *sql;
691
692 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700693 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800694 rc = sqlite3_open(path, &apnDb);
695 if( rc )
696 {
697 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700698 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800699 return 1;
700 }
701 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
702 /* Create SQL statement */
703 sql = "CREATE TABLE LYNQAPN( \
704 ID INT NOT NULL, \
705 PDP_TYPE INT NOT NULL, \
706 AUTH_PROTO INT NOT NULL, \
707 APN_NAME TEXT NOT NULL, \
708 USERNAME TEXT NOT NULL,\
709 PASSWORD TEXT NOT NULL, \
710 APN_TYPE TEXT PRIMARY KEY NOT NULL, \
711 HANDLE INT NOT NULL)";
712 /* Execute SQL statement */
713 rc = sqlite3_exec(apnDb, sql, NULL, 0, &zErrMsg);
714 if( rc != SQLITE_OK )
715 {
716 LYERRLOG("SQL error: %s\n", zErrMsg);
717 sqlite3_free(zErrMsg);
718 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700719 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800720 return 1;
721 }
722 LYINFLOG("Table LYNQAPN created successfully\n");
723 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700724 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800725 return 0;
726}
xf.li1bbfc7d2024-07-15 23:50:41 -0700727check_apn_table_cb(void *data, int argc, char **argv, char **azColName)
728{
729 if(data==NULL)
730 {
731 return 1;
732 }
733 int *temp = (int *)data;
734 for(int i=0; i<argc; i++){
735 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
736 }
737 *temp = atoi(argv[0]);
738 LYINFLOG("\nThe number is %d\n", *temp);
739 return 0;
740}
741int check_apn_table(char*path)
742{
743 char *zErrMsg = 0;
744 int rc;
745 char *sql;
746 int num = -1;
747
748 /* Open database */
749 pthread_mutex_lock(&s_qser_data_database_mutex);
750 rc = sqlite3_open(path, &apnDb);
751 if( rc )
752 {
753 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
754 pthread_mutex_unlock(&s_qser_data_database_mutex);
755 return 1;
756 }
757 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
758 /* Create SQL statement */
759 sql = "SELECT COUNT(*) FROM sqlite_master where type ='table' and name = 'LYNQAPN'";
760 /* Execute SQL statement */
761 rc = sqlite3_exec(apnDb, sql, check_apn_table_cb, &num, &zErrMsg);
762 if( rc != SQLITE_OK )
763 {
764 LYERRLOG("SQL error: %s\n", zErrMsg);
765 sqlite3_free(zErrMsg);
766 sqlite3_close(apnDb);
767 pthread_mutex_unlock(&s_qser_data_database_mutex);
768 return 1;
769 }
770 LYINFLOG("Table LYNQAPN check successfully\n");
771 sqlite3_close(apnDb);
772 pthread_mutex_unlock(&s_qser_data_database_mutex);
773 if(num <= 0)
774 {
775 LYINFLOG("No table LYNQAPN, num = %d\n", num);
776 return APN_TABLE_NEED_CREATE;
777 }
778 else
779 {
780 LYINFLOG("The table LYNQAPN exist, num = %d\n", num);
781 return APN_TABLE_CREATE;
782 }
783
784 return 0;
785}
xf.licb6cd282024-02-21 22:06:14 -0800786static int init_apn_db()
787{
788 int db_ret=0;
xf.li1bbfc7d2024-07-15 23:50:41 -0700789 int check_ret=0;
xf.licb6cd282024-02-21 22:06:14 -0800790 int table_ret=0;
xf.li87f6e6e2024-06-19 02:23:05 -0700791
792 pthread_mutex_init(&s_qser_data_database_mutex, NULL);
793
xf.licb6cd282024-02-21 22:06:14 -0800794 db_ret = create_apn_db(APN_DB_PATH);
795 if(db_ret==APN_DB_CREATE)
796 {
797 table_ret = create_apn_table(APN_DB_PATH);
798 if(table_ret!=0)
799 {
800 LYERRLOG("create apn table fail!!!");
801 return RESULT_ERROR;
802 }
803 apn_db_add(0, &default_apn);
804 }
805 else if(db_ret==APN_DB_READED)
806 {
xf.li1bbfc7d2024-07-15 23:50:41 -0700807 LYINFLOG("[%s] apn db has be build!!!",__FUNCTION__);
808 check_ret = check_apn_table(APN_DB_PATH);
809 if(check_ret == APN_TABLE_NEED_CREATE)
810 {
811 table_ret = create_apn_table(APN_DB_PATH);
812 if(table_ret!=0)
813 {
814 LYERRLOG("create apn table fail!!!");
815 return 1;
816 }
817 apn_db_add(0, &default_apn);
818 }
819 else if(check_ret == APN_TABLE_CREATE)
820 {
821 LYINFLOG("Table LYNQAPN has created");
822 }
823 else
824 {
825 LYERRLOG("check table fail!!!, ret = %d", check_ret);
826 }
xf.li0fd6acf2023-12-20 18:16:34 -0800827 }
828 else
829 {
xf.licb6cd282024-02-21 22:06:14 -0800830 LYERRLOG("init apn db fail!!!");
xf.li0fd6acf2023-12-20 18:16:34 -0800831 }
xf.li0fd6acf2023-12-20 18:16:34 -0800832 return RESULT_OK;
xf.li0fd6acf2023-12-20 18:16:34 -0800833}
xf.li2fc84552023-06-23 05:26:47 -0700834
xf.licb6cd282024-02-21 22:06:14 -0800835static int apn_db_handle_clean()
xf.li63b87e82024-01-04 00:43:35 -0800836{
xf.licb6cd282024-02-21 22:06:14 -0800837 char *zErrMsg = 0;
838 int rc;
xf.li63b87e82024-01-04 00:43:35 -0800839 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.liff415202024-09-19 23:08:09 -0700840 char sql[128]={0};
xf.li63b87e82024-01-04 00:43:35 -0800841
xf.licb6cd282024-02-21 22:06:14 -0800842 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700843 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800844 rc = sqlite3_open(APN_DB_PATH, &apnDb);
845 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800846 {
xf.licb6cd282024-02-21 22:06:14 -0800847 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700848 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800849 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800850 }
xf.licb6cd282024-02-21 22:06:14 -0800851
852 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
853 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700854 sprintf(sql,"UPDATE LYNQAPN SET HANDLE=%d", default_handle);
xf.licb6cd282024-02-21 22:06:14 -0800855 LYINFLOG("sql: %s\n", sql);
856 /* Execute SQL statement */
857 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
858 if( rc != SQLITE_OK )
xf.li63b87e82024-01-04 00:43:35 -0800859 {
xf.licb6cd282024-02-21 22:06:14 -0800860 LYERRLOG("SQL error: %s\n", zErrMsg);
861 sqlite3_free(zErrMsg);
862 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700863 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800864 return LYNQ_E_APN_DB_FAIL;
xf.li63b87e82024-01-04 00:43:35 -0800865 }
xf.licb6cd282024-02-21 22:06:14 -0800866 LYINFLOG("clean apn table successfully\n");
867 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700868 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800869 return RESULT_OK;
870}
871
872static int find_unuse_apn_index(char *path)
873{
874 char *zErrMsg = 0;
875 int rc;
876 int count =1;
877 bool apn_usable = false;
878 char *sql;
879
880 memset(apn_indexs,0,sizeof(apn_indexs));
881 next_index = 0;
882 LYINFLOG("index = %p",apn_indexs);
883 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700884 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800885 rc = sqlite3_open(APN_DB_PATH, &apnDb);
886 if( rc )
xf.li63b87e82024-01-04 00:43:35 -0800887 {
xf.licb6cd282024-02-21 22:06:14 -0800888 LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700889 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800890 return -1;
xf.li63b87e82024-01-04 00:43:35 -0800891 }
892 else
893 {
xf.licb6cd282024-02-21 22:06:14 -0800894 LYINFLOG("Opened database successfully\n");
xf.li63b87e82024-01-04 00:43:35 -0800895 }
xf.li63b87e82024-01-04 00:43:35 -0800896
xf.licb6cd282024-02-21 22:06:14 -0800897 /* Create SQL statement */
898 sql = "SELECT ID from LYNQAPN";
899 /* Execute SQL statement */
900 rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg);
901 if( rc != SQLITE_OK )
902 {
903 LYERRLOG("SQL error: %s\n", zErrMsg);
904 sqlite3_free(zErrMsg);
xf.lib5d82bf2024-03-09 01:54:50 -0800905 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700906 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800907 return -1;
908 }
909 else
910 {
911 LYINFLOG("Operation done successfully\n");
912 }
913 //indexs = temp_index;
914 LYINFLOG("index = %p",apn_indexs);
915 for(count;count<=QSER_APN_MAX_LIST;count++)
916 {
917 //if(apn_indexs[count-1]!=count)
918 LYINFLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count);
919 if(apn_indexs[count]!=count)
920 {
921 //apn_usable=true;
922 break;
923 }
924 }
925 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700926 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800927 LYINFLOG("count is %d\n", count);
928 return count;
xf.li63b87e82024-01-04 00:43:35 -0800929}
930
xf.licb6cd282024-02-21 22:06:14 -0800931static int apn_db_add(int profile_id, qser_apn_add_s *apn)
xf.li2fc84552023-06-23 05:26:47 -0700932{
xf.licb6cd282024-02-21 22:06:14 -0800933 char *zErrMsg = 0;
934 int rc;
xf.li0fd6acf2023-12-20 18:16:34 -0800935 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.licb6cd282024-02-21 22:06:14 -0800936 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700937 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800938 rc = sqlite3_open(APN_DB_PATH, &apnDb);
939 if( rc )
xf.li2fc84552023-06-23 05:26:47 -0700940 {
xf.licb6cd282024-02-21 22:06:14 -0800941 LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700942 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800943 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700944 }
xf.licb6cd282024-02-21 22:06:14 -0800945 LYINFLOG("[%s] Opened database successfully",__FUNCTION__);
946 /* Create SQL statement */
947 /* Execute SQL statement */
948 LYINFLOG("the profile id is %d\n", profile_id);
949 char *sql = sqlite3_mprintf("INSERT INTO LYNQAPN VALUES('%d','%d','%d','%q','%q','%q','%q','%d')", profile_id, apn->pdp_type, apn->auth_proto, apn->apn_name, apn->username, apn->password, apn->apn_type, default_handle);
950 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
xf.liff415202024-09-19 23:08:09 -0700951 sqlite3_free(sql);
xf.licb6cd282024-02-21 22:06:14 -0800952 if( rc != SQLITE_OK )
xf.li2fc84552023-06-23 05:26:47 -0700953 {
xf.licb6cd282024-02-21 22:06:14 -0800954 LYERRLOG( "SQL error: %s", zErrMsg);
955 sqlite3_free(zErrMsg);
956 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700957 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800958 return 1;
xf.li2fc84552023-06-23 05:26:47 -0700959 }
xf.licb6cd282024-02-21 22:06:14 -0800960 LYINFLOG("write apn to apn db successfully");
961 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700962 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800963 return 0;
xf.li2fc84552023-06-23 05:26:47 -0700964}
965
xf.licb6cd282024-02-21 22:06:14 -0800966static int apn_db_delete(unsigned char profile_idx)
xf.li2fc84552023-06-23 05:26:47 -0700967{
xf.licb6cd282024-02-21 22:06:14 -0800968 char *zErrMsg = 0;
969 int rc;
xf.liff415202024-09-19 23:08:09 -0700970 char sql[128]={0};
xf.li2fc84552023-06-23 05:26:47 -0700971
xf.licb6cd282024-02-21 22:06:14 -0800972 if(!lynq_check_index(profile_idx))
973 {
974 return LYNQ_E_APN_DB_FAIL;
975 }
976 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -0700977 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800978 rc = sqlite3_open(APN_DB_PATH, &apnDb);
979 if( rc )
980 {
981 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -0700982 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800983 return LYNQ_E_APN_DB_FAIL;
984 }
985
986 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
987 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -0700988 sprintf(sql,"DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -0800989 LYINFLOG("sql: %s\n", sql);
990 /* Execute SQL statement */
991 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
992 if( rc != SQLITE_OK )
993 {
994 LYERRLOG("SQL error: %s\n", zErrMsg);
995 sqlite3_free(zErrMsg);
996 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -0700997 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -0800998 return LYNQ_E_APN_DB_FAIL;
999 }
1000 LYINFLOG("delete apn %d successfully\n", profile_idx);
1001 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001002 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001003 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001004}
1005
xf.licb6cd282024-02-21 22:06:14 -08001006static int apn_db_modify(qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001007{
xf.licb6cd282024-02-21 22:06:14 -08001008 char *zErrMsg = 0;
1009 int rc;
xf.li2fc84552023-06-23 05:26:47 -07001010
xf.licb6cd282024-02-21 22:06:14 -08001011 if(!lynq_check_index(apn->profile_idx))
1012 {
1013 return LYNQ_E_APN_DB_FAIL;
1014 }
1015 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001016 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001017 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1018 if( rc )
1019 {
1020 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001021 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001022 return LYNQ_E_APN_DB_FAIL;
1023 }
1024
1025 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1026 /* Create SQL statement */
1027 char *sql = sqlite3_mprintf("UPDATE LYNQAPN set PDP_TYPE = %d, AUTH_PROTO = %d, APN_NAME = '%q', USERNAME = '%q', PASSWORD = '%q', APN_TYPE = '%q' WHERE ID=%d", apn->pdp_type, apn->auth_proto, apn->apn_name, apn->username, apn->password, apn->apn_type, apn->profile_idx);
1028 LYINFLOG("sql: %s\n", sql);
1029 /* Execute SQL statement */
1030 rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg);
xf.liff415202024-09-19 23:08:09 -07001031 sqlite3_free(sql);
xf.licb6cd282024-02-21 22:06:14 -08001032 if( rc != SQLITE_OK )
1033 {
1034 LYERRLOG("SQL error: %s\n", zErrMsg);
1035 sqlite3_free(zErrMsg);
1036 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001037 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001038 return LYNQ_E_APN_DB_FAIL;
1039 }
1040 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1041 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001042 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001043 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001044}
1045
xf.licb6cd282024-02-21 22:06:14 -08001046static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName)
xf.li2fc84552023-06-23 05:26:47 -07001047{
xf.licb6cd282024-02-21 22:06:14 -08001048 if(data==NULL)
xf.li2fc84552023-06-23 05:26:47 -07001049 {
xf.licb6cd282024-02-21 22:06:14 -08001050 return 1;
xf.li2fc84552023-06-23 05:26:47 -07001051 }
xf.licb6cd282024-02-21 22:06:14 -08001052 qser_apn_info_s* temp = (qser_apn_info_s *)data;
1053 for(int i=0; i<argc; i++){
1054 LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001055 }
xf.licb6cd282024-02-21 22:06:14 -08001056 temp->profile_idx = atoi(argv[0]);
1057 temp->pdp_type = atoi(argv[1]);
1058 temp->auth_proto = atoi(argv[2]);
1059 memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE);
1060 memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE);
1061 memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE);
1062 memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE);
1063 LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0]));
1064 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001065}
xf.licb6cd282024-02-21 22:06:14 -08001066static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn)
xf.li2fc84552023-06-23 05:26:47 -07001067{
xf.licb6cd282024-02-21 22:06:14 -08001068 char *zErrMsg = 0;
1069 int rc;
xf.liff415202024-09-19 23:08:09 -07001070 char sql[128]={0};
xf.licb6cd282024-02-21 22:06:14 -08001071
1072 if(!lynq_check_index(profile_idx))
xf.li2fc84552023-06-23 05:26:47 -07001073 {
xf.licb6cd282024-02-21 22:06:14 -08001074 return LYNQ_E_APN_DB_FAIL;
1075 }
1076 /* Open database */
xf.li87f6e6e2024-06-19 02:23:05 -07001077 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001078 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1079 if( rc )
1080 {
1081 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001082 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001083 return LYNQ_E_APN_DB_FAIL;
1084 }
1085
1086 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1087 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001088 sprintf(sql,"SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx);
xf.licb6cd282024-02-21 22:06:14 -08001089 LYINFLOG("sql: %s\n", sql);
1090 /* Execute SQL statement */
1091 rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg);
1092 if( rc != SQLITE_OK )
1093 {
1094 LYERRLOG("SQL error: %s\n", zErrMsg);
1095 sqlite3_free(zErrMsg);
1096 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001097 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001098 return LYNQ_E_APN_DB_FAIL;
1099 }
1100 LYINFLOG("set apn %d successfully\n",apn->profile_idx);
1101 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001102 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001103 return 0;
1104}
1105static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName)
1106{
1107 int i;
1108
1109 //apn_count++;
1110
1111 qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data;
1112 for(i=0; i<argc; i++){
1113 LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
xf.li2fc84552023-06-23 05:26:47 -07001114 }
1115
xf.licb6cd282024-02-21 22:06:14 -08001116 temp->apn[temp->cnt].profile_idx = atoi(argv[0]);
1117 temp->apn[temp->cnt].pdp_type = atoi(argv[1]);
1118 temp->apn[temp->cnt].auth_proto = atoi(argv[2]);
1119 memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE);
1120 memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE);
1121 memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE);
1122 memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE);
1123 temp->cnt++;
1124 return 0;
xf.li2fc84552023-06-23 05:26:47 -07001125}
xf.licb6cd282024-02-21 22:06:14 -08001126static int apn_db_query_list(qser_apn_info_list_s *apn_list)
1127{
1128 char *zErrMsg = 0;
1129 int rc;
xf.liff415202024-09-19 23:08:09 -07001130 char sql[128]={0};
xf.li2fc84552023-06-23 05:26:47 -07001131
xf.licb6cd282024-02-21 22:06:14 -08001132 /* Open database */
1133 apn_count = 0;
1134 apn_list->cnt = 0;
xf.li87f6e6e2024-06-19 02:23:05 -07001135 pthread_mutex_lock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001136 rc = sqlite3_open(APN_DB_PATH, &apnDb);
1137 if( rc )
1138 {
1139 LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb));
xf.li87f6e6e2024-06-19 02:23:05 -07001140 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001141 return LYNQ_E_APN_DB_FAIL;
1142 }
1143
1144 LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__);
1145 /* Create SQL statement */
xf.liff415202024-09-19 23:08:09 -07001146 sprintf(sql,"SELECT * from LYNQAPN");
xf.licb6cd282024-02-21 22:06:14 -08001147 LYINFLOG("sql: %s\n", sql);
1148 /* Execute SQL statement */
1149 rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg);
1150 if( rc != SQLITE_OK )
1151 {
1152 LYERRLOG("SQL error: %s\n", zErrMsg);
1153 sqlite3_free(zErrMsg);
1154 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001155 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001156 return LYNQ_E_APN_DB_FAIL;
1157 }
1158 sqlite3_close(apnDb);
xf.li87f6e6e2024-06-19 02:23:05 -07001159 pthread_mutex_unlock(&s_qser_data_database_mutex);
xf.licb6cd282024-02-21 22:06:14 -08001160 return 0;
1161}
1162// **************apn DB end****************************
xf.li2fc84552023-06-23 05:26:47 -07001163void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type)
1164{
1165 switch (pdp_type)
1166 {
1167 case QSER_APN_PDP_TYPE_IPV4:
xf.li9e27f3d2023-11-30 00:43:13 -08001168#ifdef MOBILETEK_TARGET_PLATFORM_T106
1169 strcpy(out_pdp_type,"IP");
1170#else
xf.li2fc84552023-06-23 05:26:47 -07001171 strcpy(out_pdp_type,"IPV4");
xf.li9e27f3d2023-11-30 00:43:13 -08001172#endif
xf.li2fc84552023-06-23 05:26:47 -07001173 break;
1174 case QSER_APN_PDP_TYPE_PPP:
1175 strcpy(out_pdp_type,"PPP");
1176 break;
1177 case QSER_APN_PDP_TYPE_IPV6:
1178 strcpy(out_pdp_type,"IPV6");
1179 break;
1180 case QSER_APN_PDP_TYPE_IPV4V6:
1181 strcpy(out_pdp_type,"IPV4V6");
1182 break;
1183 default:
1184 strcpy(out_pdp_type,"NULL");
1185 break;
1186 }
1187 return;
1188}
1189void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto)
1190{
1191 switch (auth_proto)
1192 {
1193 case QSER_APN_AUTH_PROTO_DEFAULT:
xf.lifb6134e2024-05-09 01:26:54 -07001194 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001195 break;
1196 case QSER_APN_AUTH_PROTO_NONE:
xf.lifb6134e2024-05-09 01:26:54 -07001197 strcpy(out_proto,"0");
xf.li2fc84552023-06-23 05:26:47 -07001198 break;
1199 case QSER_APN_AUTH_PROTO_PAP:
xf.lifb6134e2024-05-09 01:26:54 -07001200 strcpy(out_proto,"1");
xf.li2fc84552023-06-23 05:26:47 -07001201 break;
1202 case QSER_APN_AUTH_PROTO_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001203 strcpy(out_proto,"2");
xf.li2fc84552023-06-23 05:26:47 -07001204 break;
1205 case QSER_APN_AUTH_PROTO_PAP_CHAP:
xf.lifb6134e2024-05-09 01:26:54 -07001206 strcpy(out_proto,"3");
xf.li2fc84552023-06-23 05:26:47 -07001207 break;
1208 default:
xf.lifb6134e2024-05-09 01:26:54 -07001209 strcpy(out_proto,"NULL");
xf.li2fc84552023-06-23 05:26:47 -07001210 break;
1211 }
1212 return ;
1213}
1214
1215int data_call_handle_get(const char profile_idx,int *handle)
1216{
1217 int num = LYNQ_APN_CHANNEL_MAX;
1218 int table_num = 0;
1219 lynq_apn_info **apn_table = NULL;
1220 qser_apn_info_s apn;
xf.li0fc26502023-09-16 02:10:17 -07001221 int ret = 0;
xf.li2fc84552023-06-23 05:26:47 -07001222 apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX);
1223 if (NULL == apn_table)
1224 {
1225 LYERRLOG("malloc apn_table fail ");
1226 return RESULT_ERROR;
1227 }
1228 for(int i =0;i<10;i++)
1229 {
1230 apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info));
1231 if (apn_table[i]==NULL)
1232 {
1233 for (int n=0;n<i;n++)
1234 {
1235 free(apn_table[n]);
1236 }
1237 return RESULT_ERROR;
1238 }
1239 memset(apn_table[i],0,sizeof(lynq_apn_info));
1240 }
1241 lynq_get_apn_table(&table_num,apn_table);
1242 memset(&apn,0,sizeof(qser_apn_info_s));
xf.licb6cd282024-02-21 22:06:14 -08001243 ret = apn_db_query(profile_idx,&apn);
xf.li0fc26502023-09-16 02:10:17 -07001244 if (ret < 0)
1245 {
xf.licb6cd282024-02-21 22:06:14 -08001246 LYERRLOG("apn_db_query error");
xf.li0fc26502023-09-16 02:10:17 -07001247 return ret;
1248 }
xf.li2fc84552023-06-23 05:26:47 -07001249 for (int j = 0;j < table_num;j++)
1250 {
1251 if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0)
1252 {
1253 *handle = apn_table[j]->index;
1254 LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle);
1255 break;
1256 }
1257 }
1258
1259 for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++)
1260 {
1261 if (apn_table[i]!=NULL)
1262 {
1263 free(apn_table[i]);
1264 apn_table[i]=NULL;
1265 }
1266 }
1267 free(apn_table);
1268 apn_table=NULL;
1269 LYINFLOG("data_call_handle_get end");
1270 return RESULT_OK;
1271}
1272
1273void *thread_wait_cb_status(void)
1274{
1275 int handle = -1;
xf.li6b0d8502023-09-04 18:49:12 -07001276 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001277 int default_handle = LYNQ_APN_CHANNEL_MAX + 1;
xf.li8535bc02023-12-12 23:28:35 -08001278 lynq_data_call_response_v11_t data_urc_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001279 qser_data_call_state_s data_cb_state;
1280 while (s_qser_data_cb_thread_status)
1281 {
xf.li6b0d8502023-09-04 18:49:12 -07001282 ret = lynq_wait_data_call_state_change(&handle);
1283 LYINFLOG("ret = %d, wait data call state change end!!!\n", ret);
1284 if(s_qser_data_cb_thread_status == 0)
1285 {
1286 return NULL;
1287 }
1288 else if(ret < 0)
1289 {
1290 continue;
1291 }
xf.li8535bc02023-12-12 23:28:35 -08001292 LYINFLOG("[thread_wait_cb_status]: handle = %d", handle);
1293 memset(&data_urc_info, 0, sizeof(data_urc_info));
1294 memset(&data_cb_state, 0, sizeof(data_cb_state));
xf.li2fc84552023-06-23 05:26:47 -07001295 lynq_get_data_call_list(&handle,&data_urc_info);
1296 /*compare paramter*/
xf.li0fd6acf2023-12-20 18:16:34 -08001297 //data_cb_state.profile_idx = (char)handle;
xf.licb6cd282024-02-21 22:06:14 -08001298 apn_db_handle_get_profile(handle, &data_cb_state.profile_idx);
xf.li87f6e6e2024-06-19 02:23:05 -07001299 LYINFLOG("[thread_wait_cb_status]: callback profile_idx is %d\n", data_cb_state.profile_idx);
xf.li8535bc02023-12-12 23:28:35 -08001300 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",
1301 data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active,
1302 data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf,
1303 data_urc_info.mtu);
xf.li2fc84552023-06-23 05:26:47 -07001304 memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1);
xf.li9e27f3d2023-11-30 00:43:13 -08001305 if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0))
xf.li2fc84552023-06-23 05:26:47 -07001306 {
1307 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4;
1308 }
1309 else if (!strcmp(data_urc_info.type,"IPV6"))
1310 {
1311 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6;
1312 }
xf.li8535bc02023-12-12 23:28:35 -08001313 else if (!strcmp(data_urc_info.type,"IPV4V6"))
xf.li2fc84552023-06-23 05:26:47 -07001314 {
1315 data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
1316 }
1317 else
1318 {
xf.li8535bc02023-12-12 23:28:35 -08001319 LYERRLOG("unknow data call type: %s", data_urc_info.type);
xf.li2fc84552023-06-23 05:26:47 -07001320 }
1321
xf.li8535bc02023-12-12 23:28:35 -08001322 if (data_urc_info.active != 0)
xf.li2fc84552023-06-23 05:26:47 -07001323 {
1324 data_cb_state.state = QSER_DATA_CALL_CONNECTED;
1325 }
1326 else
1327 {
1328 data_cb_state.state = QSER_DATA_CALL_DISCONNECTED;
xf.licb6cd282024-02-21 22:06:14 -08001329 ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001330 if(ret != 0)
1331 {
1332 LYERRLOG("handle set error");
1333 }
xf.li2fc84552023-06-23 05:26:47 -07001334 }
1335 if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4)
1336 {
1337 lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state);
1338 }
1339 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6)
1340 {
1341 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
1342 }
1343 else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6)
1344 {
xf.li3c0a4752023-09-03 20:46:19 -07001345#ifdef MOBILETEK_TARGET_PLATFORM_T106
1346 lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state);
1347#else
xf.li2fc84552023-06-23 05:26:47 -07001348 lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state);
xf.li3c0a4752023-09-03 20:46:19 -07001349#endif
xf.li2fc84552023-06-23 05:26:47 -07001350 }
1351 else
1352 {
1353 LYERRLOG("unknow ip_family");
1354 continue;
1355 }
1356 if (s_data_call_cb != NULL)
1357 {
1358 s_data_call_cb(&data_cb_state);
1359 }
1360 }
1361 return NULL;
1362}
1363
1364int qser_cb_pthread_create()
1365{
xf.lib5d82bf2024-03-09 01:54:50 -08001366 pthread_attr_t attr;
xf.li2fc84552023-06-23 05:26:47 -07001367 int ret;
1368 s_qser_data_cb_thread_status = 1;
xf.lib5d82bf2024-03-09 01:54:50 -08001369
1370 pthread_attr_init(&attr);
1371 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
1372
1373 ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL);
xf.li2fc84552023-06-23 05:26:47 -07001374 if (ret < 0)
1375 {
1376 LYERRLOG("pthread create fail");
1377 s_qser_data_cb_thread_status = 0;
1378 return RESULT_ERROR;
1379 }
xf.lib5d82bf2024-03-09 01:54:50 -08001380 pthread_attr_destroy(&attr);
xf.li2fc84552023-06-23 05:26:47 -07001381 return RESULT_OK;
1382}
1383
1384void qser_cb_pthread_cancel()
1385{
xf.li2fc84552023-06-23 05:26:47 -07001386 s_qser_data_cb_thread_status = 0;
1387 if (s_cb_tid != -1)
1388 {
xf.li6b0d8502023-09-04 18:49:12 -07001389 lynq_release_wait_data_call();
xf.li2fc84552023-06-23 05:26:47 -07001390 }
1391 return;
1392}
xf.li2fc84552023-06-23 05:26:47 -07001393int qser_data_call_init(qser_data_call_evt_cb_t evt_cb)
1394{
1395 int ret = 0;
1396 int utoken = 0;
1397 if (NULL == evt_cb)
1398 {
1399 LYERRLOG("init incoming paramters error");
1400 return RESULT_ERROR;
1401 }
xf.li09b46db2024-03-13 19:21:18 -07001402 if(g_lynq_qser_data_init_flag == 1)
1403 {
1404 LYERRLOG("init twice is not allowed");
1405 return RESULT_ERROR;
1406 }
xf.li2fc84552023-06-23 05:26:47 -07001407 ret = lynq_init_data(utoken);
1408 if (ret != RESULT_OK)
1409 {
xf.li6b0d8502023-09-04 18:49:12 -07001410 //qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001411 s_data_call_cb = NULL;
1412 return RESULT_ERROR;
1413 }
xf.li6b0d8502023-09-04 18:49:12 -07001414 qser_cb_pthread_create();
xf.licb6cd282024-02-21 22:06:14 -08001415 ret = init_apn_db();
1416 if(ret != RESULT_OK)
xf.lie3f55f42023-12-01 22:47:33 -08001417 {
xf.licb6cd282024-02-21 22:06:14 -08001418 LYERRLOG("init apn db error");
xf.lie3f55f42023-12-01 22:47:33 -08001419 return RESULT_ERROR;
1420 }
xf.licb6cd282024-02-21 22:06:14 -08001421
1422 ret = apn_db_handle_clean();
xf.li63b87e82024-01-04 00:43:35 -08001423 if(ret != RESULT_OK)
1424 {
1425 LYERRLOG("clean handle error");
1426 return RESULT_ERROR;
1427 }
xf.li09b46db2024-03-13 19:21:18 -07001428 s_data_call_cb = evt_cb;
xf.lib33d4862023-12-13 00:40:37 -08001429 g_lynq_qser_data_init_flag = 1;
xf.li2fc84552023-06-23 05:26:47 -07001430 return RESULT_OK;
1431}
1432
1433void qser_data_call_destroy(void)
1434{
xf.li6b0d8502023-09-04 18:49:12 -07001435 LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001436 lynq_deinit_data();
xf.li6b0d8502023-09-04 18:49:12 -07001437 qser_cb_pthread_cancel();
xf.li2fc84552023-06-23 05:26:47 -07001438 s_data_call_cb = NULL;
xf.lib33d4862023-12-13 00:40:37 -08001439 g_lynq_qser_data_init_flag = 0;
xf.li6b0d8502023-09-04 18:49:12 -07001440 LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__);
xf.li2fc84552023-06-23 05:26:47 -07001441 return ;
1442}
1443
1444int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err)
1445{
1446 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001447 int error = -1;
xf.li2fc84552023-06-23 05:26:47 -07001448 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001449 if(g_lynq_qser_data_init_flag == 0)
1450 {
1451 if(err != NULL)
1452 {
1453 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1454 }
1455 return LYNQ_E_NO_INIT;
1456 }
xf.li2fc84552023-06-23 05:26:47 -07001457 if (NULL == data_call || NULL == err)
1458 {
1459 LYERRLOG("call start incoming paramters error");
xf.lic12b3702023-11-22 22:39:01 -08001460 if(err != NULL)
1461 {
1462 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1463 }
xf.li2fc84552023-06-23 05:26:47 -07001464 return ret;
1465 }
1466 if (data_call->profile_idx == 0)
1467 {
1468 ret = lynq_setup_data_call(&handle);
1469 }
1470 else
1471 {
1472 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001473 char auth_proto[16];
xf.li2fc84552023-06-23 05:26:47 -07001474 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001475 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1476 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li0fc26502023-09-16 02:10:17 -07001477 if (ret != 0)
1478 {
1479 LYERRLOG("qser_apn_get error");
xf.lic12b3702023-11-22 22:39:01 -08001480 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.li0fc26502023-09-16 02:10:17 -07001481 return ret;
1482 }
xf.li2fc84552023-06-23 05:26:47 -07001483 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001484 judge_authtype(apn_info.auth_proto,auth_proto);
1485 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 -07001486 }
xf.lic12b3702023-11-22 22:39:01 -08001487 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001488 {
1489 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1490 }
xf.li0fd6acf2023-12-20 18:16:34 -08001491 else
1492 {
xf.licb6cd282024-02-21 22:06:14 -08001493 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001494 if(error != 0)
1495 {
1496 LYERRLOG("handle set error");
1497 }
1498 }
xf.li2fc84552023-06-23 05:26:47 -07001499 return ret;
1500}
1501
xf.li8535bc02023-12-12 23:28:35 -08001502int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err)
1503{
1504 int ret = -1;
xf.li0fd6acf2023-12-20 18:16:34 -08001505 int error = -1;
xf.li8535bc02023-12-12 23:28:35 -08001506 int handle = 0;
xf.lib33d4862023-12-13 00:40:37 -08001507 if(g_lynq_qser_data_init_flag == 0)
1508 {
1509 if(err != NULL)
1510 {
1511 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1512 }
1513 return LYNQ_E_NO_INIT;
1514 }
xf.li8535bc02023-12-12 23:28:35 -08001515 if (NULL == data_call || NULL == err)
1516 {
1517 LYERRLOG("call start incoming paramters error");
1518 if(err != NULL)
1519 {
1520 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1521 }
1522 return ret;
1523 }
1524 if (data_call->profile_idx == 0)
1525 {
1526 ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL);
1527 }
1528 else
1529 {
1530 char pdptype[16];
xf.lifb6134e2024-05-09 01:26:54 -07001531 char auth_proto[16];
xf.li8535bc02023-12-12 23:28:35 -08001532 qser_apn_info_s apn_info;
xf.licb6cd282024-02-21 22:06:14 -08001533 LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx);
1534 ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info);
xf.li8535bc02023-12-12 23:28:35 -08001535 if (ret != 0)
1536 {
1537 LYERRLOG("qser_apn_get error");
1538 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1539 return ret;
1540 }
1541 judge_pdp_type(apn_info.pdp_type,pdptype);
xf.lifb6134e2024-05-09 01:26:54 -07001542 judge_authtype(apn_info.auth_proto,auth_proto);
1543 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 -08001544 }
1545 if (ret != 0)
1546 {
1547 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1548 }
xf.li0fd6acf2023-12-20 18:16:34 -08001549 else
1550 {
xf.licb6cd282024-02-21 22:06:14 -08001551 error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001552 if(error != 0)
1553 {
1554 LYERRLOG("handle set error");
1555 }
1556 }
xf.li8535bc02023-12-12 23:28:35 -08001557 return ret;
1558}
1559
xf.li2fc84552023-06-23 05:26:47 -07001560int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err)
1561{
1562 int ret = 0;
1563 int handle = -1;
1564
xf.lib33d4862023-12-13 00:40:37 -08001565 if(g_lynq_qser_data_init_flag == 0)
1566 {
1567 if(err != NULL)
1568 {
1569 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1570 }
1571 return LYNQ_E_NO_INIT;
1572 }
xf.li2fc84552023-06-23 05:26:47 -07001573 if (NULL == err)
1574 {
1575 LYERRLOG("call stop incoming paramters error");
1576 return ret;
1577 }
xf.lic12b3702023-11-22 22:39:01 -08001578 ret = data_call_handle_get(profile_idx,&handle);
1579 if(ret != 0)
1580 {
1581 LYERRLOG("datacall handle get error");
1582 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
1583 return ret;
1584 }
xf.li2fc84552023-06-23 05:26:47 -07001585 ret = lynq_deactive_data_call(&handle);
xf.lic12b3702023-11-22 22:39:01 -08001586 if (ret != 0)
xf.li2fc84552023-06-23 05:26:47 -07001587 {
1588 *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS;
xf.lic12b3702023-11-22 22:39:01 -08001589 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001590 }
xy.hee2daacc2023-09-18 00:57:51 -07001591 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001592}
1593int 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)
1594{
1595 int ret = 0;
1596 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001597 if(g_lynq_qser_data_init_flag == 0)
1598 {
1599 if(err != NULL)
1600 {
1601 *err = QSER_DATA_CALL_ERROR_NO_INIT;
1602 }
1603 return LYNQ_E_NO_INIT;
1604 }
xf.li4ab455d2024-07-30 01:21:56 -07001605 lynq_data_call_response_v11_t data_call_info = {0};
xf.li2fc84552023-06-23 05:26:47 -07001606 data_call_handle_get(profile_idx,&handle);
1607 ret = lynq_get_data_call_list(&handle,&data_call_info);
1608 if (ret == 0)
1609 {
1610 info->profile_idx = profile_idx;
1611 info->ip_family = ip_family;
xf.li157f7e92023-10-19 23:22:46 -07001612 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 -07001613 {
xf.li0400b382024-06-05 19:20:36 -07001614 info->ip_family = QSER_DATA_CALL_TYPE_IPV4;
xf.li2fc84552023-06-23 05:26:47 -07001615 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001616 datacall_ipv4_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001617 LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1618 lynq_ipv4_aton_getinfo(&data_call_info,info);
1619 }
xf.li3c0a4752023-09-03 20:46:19 -07001620 else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001621 {
xf.li0400b382024-06-05 19:20:36 -07001622 info->ip_family = QSER_DATA_CALL_TYPE_IPV6;
xf.li2fc84552023-06-23 05:26:47 -07001623 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001624 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001625 LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses);
1626 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
1627 }
xf.li3c0a4752023-09-03 20:46:19 -07001628 else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0)
xf.li2fc84552023-06-23 05:26:47 -07001629 {
xf.li0400b382024-06-05 19:20:36 -07001630 info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6;
xf.li2fc84552023-06-23 05:26:47 -07001631 strcpy(info->v4.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001632 datacall_ipv4_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_ipv4_aton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001636#endif
xf.li2fc84552023-06-23 05:26:47 -07001637 strcpy(info->v6.name,data_call_info.ifname);
xf.lib5dc0632023-11-30 18:20:35 -08001638 datacall_ipv6_status_judge(data_call_info.active,info);
xf.li2fc84552023-06-23 05:26:47 -07001639 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 -07001640#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001641 lynq_ipv6_inet_pton_getinfo(&data_call_info,info);
xf.li3c0a4752023-09-03 20:46:19 -07001642#endif
1643#ifdef MOBILETEK_TARGET_PLATFORM_T106
1644 lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info);
1645#endif
xf.li2fc84552023-06-23 05:26:47 -07001646 }
1647 else
1648 {
1649 LYERRLOG("useless qser_data_call_ip_family_e");
1650 }
1651 }
1652 return ret;
1653}
xf.lifb6134e2024-05-09 01:26:54 -07001654int check_pdp_type(qser_apn_pdp_type_e pdp_type)
1655{
1656 switch (pdp_type)
1657 {
1658 case QSER_APN_PDP_TYPE_IPV4:
1659 case QSER_APN_PDP_TYPE_PPP:
1660 case QSER_APN_PDP_TYPE_IPV6:
1661 case QSER_APN_PDP_TYPE_IPV4V6:
1662 return 0;
1663 default:
1664 return -1;
1665 }
1666}
1667int check_auth_proto(qser_apn_auth_proto_e auth_proto)
1668{
1669 switch (auth_proto)
1670 {
1671 case QSER_APN_AUTH_PROTO_DEFAULT:
1672 case QSER_APN_AUTH_PROTO_NONE:
1673 case QSER_APN_AUTH_PROTO_PAP:
1674 case QSER_APN_AUTH_PROTO_CHAP:
1675 case QSER_APN_AUTH_PROTO_PAP_CHAP:
1676 return 0;
1677 default:
1678 return -1;
1679 }
1680}
xf.li2fc84552023-06-23 05:26:47 -07001681int qser_apn_set(qser_apn_info_s *apn)
1682{
1683 int ret = 0;
xf.li0fd6acf2023-12-20 18:16:34 -08001684 int handle = -1;
xf.lib33d4862023-12-13 00:40:37 -08001685 if(g_lynq_qser_data_init_flag == 0)
1686 {
1687 return LYNQ_E_NO_INIT;
1688 }
xf.li4b18fa62023-12-19 19:38:10 -08001689 if (NULL == apn || apn->profile_idx == 0)
xf.li2fc84552023-06-23 05:26:47 -07001690 {
1691 LYERRLOG("apn set incoming paramters error");
1692 return RESULT_ERROR;
1693 }
xf.licb6cd282024-02-21 22:06:14 -08001694 ret = apn_db_handle_get(apn->profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001695 if(ret != 0)
1696 {
1697 LYERRLOG("handle set error");
1698 }
1699 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1700 {
1701 LYERRLOG("It has setup datacall");
1702 return RESULT_ERROR;
1703 }
xf.lifb6134e2024-05-09 01:26:54 -07001704
1705 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1706 {
1707 LYERRLOG("apn_name out of range\n");
1708 return RESULT_ERROR;
1709 }
1710 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1711 {
1712 LYERRLOG("username out of range\n");
1713 return RESULT_ERROR;
1714 }
1715 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1716 {
1717 LYERRLOG("password out of range\n");
1718 return RESULT_ERROR;
1719 }
1720 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1721 {
1722 LYERRLOG("apn_type out of range\n");
1723 return RESULT_ERROR;
1724 }
1725 if(check_pdp_type(apn->pdp_type) != 0)
1726 {
1727 LYERRLOG("pdp_type out of range\n");
1728 return RESULT_ERROR;
1729 }
1730 if(check_auth_proto(apn->auth_proto) != 0)
1731 {
1732 LYERRLOG("auth_proto out of range\n");
1733 return RESULT_ERROR;
1734 }
1735
xf.licb6cd282024-02-21 22:06:14 -08001736 ret = apn_db_modify(apn);
xf.li2fc84552023-06-23 05:26:47 -07001737 if (ret < 0)
1738 {
xf.licb6cd282024-02-21 22:06:14 -08001739 LYERRLOG("apn_db_modify error");
xf.li2fc84552023-06-23 05:26:47 -07001740 return ret;
1741 }
xf.li6c7e3972023-10-27 20:01:59 -07001742#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001743 int apn_id = 0;
1744 char tmp_id[12];
1745 char *outinfo = NULL;
1746 char normalprotocol[16];
1747 char authtype[32];
1748 outinfo = (char *)malloc(sizeof(char)*512);
1749 bzero(tmp_id,12);
1750 bzero(outinfo,512);
1751 apn_id = apn->profile_idx + apndb_offset;
1752 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1753 judge_pdp_type(apn->pdp_type,normalprotocol);
1754 judge_authtype(apn->auth_proto,authtype);
1755 lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1756 LYINFLOG("[output]:%s",outinfo);
1757 free(outinfo);
1758 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001759#endif
1760 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001761}
1762
1763int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn)
1764{
xf.lib33d4862023-12-13 00:40:37 -08001765 if(g_lynq_qser_data_init_flag == 0)
1766 {
1767 return LYNQ_E_NO_INIT;
1768 }
xf.licb6cd282024-02-21 22:06:14 -08001769 if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn)
xf.li2fc84552023-06-23 05:26:47 -07001770 {
1771 LYERRLOG("apn get incoming paramters error");
1772 return RESULT_ERROR;
1773 }
1774 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001775 ret = apn_db_query(profile_idx,apn);
xf.li2fc84552023-06-23 05:26:47 -07001776 if (ret < 0)
1777 {
xf.licb6cd282024-02-21 22:06:14 -08001778 LYERRLOG("apn_db_query error");
xf.li2fc84552023-06-23 05:26:47 -07001779 return ret;
1780 }
1781 return ret;
1782}
1783
1784int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx)
1785{
1786 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001787
xf.lib33d4862023-12-13 00:40:37 -08001788 if(g_lynq_qser_data_init_flag == 0)
1789 {
1790 return LYNQ_E_NO_INIT;
1791 }
xf.li2fc84552023-06-23 05:26:47 -07001792 if (NULL == apn || NULL == profile_idx)
1793 {
1794 LYERRLOG("apn add incoming paramters error");
1795 return RESULT_ERROR;
1796 }
xf.lifb6134e2024-05-09 01:26:54 -07001797
1798 if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE)
1799 {
1800 LYERRLOG("apn_name out of range\n");
1801 return RESULT_ERROR;
1802 }
1803 if(strlen(apn->username) > QSER_APN_USERNAME_SIZE)
1804 {
1805 LYERRLOG("username out of range\n");
1806 return RESULT_ERROR;
1807 }
1808 if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE)
1809 {
1810 LYERRLOG("password out of range\n");
1811 return RESULT_ERROR;
1812 }
1813 if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE)
1814 {
1815 LYERRLOG("apn_type out of range\n");
1816 return RESULT_ERROR;
1817 }
1818 if(check_pdp_type(apn->pdp_type) != 0)
1819 {
1820 LYERRLOG("pdp_type out of range\n");
1821 return RESULT_ERROR;
1822 }
1823 if(check_auth_proto(apn->auth_proto) != 0)
1824 {
1825 LYERRLOG("auth_proto out of range\n");
1826 return RESULT_ERROR;
1827 }
xf.licb6cd282024-02-21 22:06:14 -08001828
1829 *profile_idx = 0;
1830 *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH);
1831 LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx);
1832 if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001833 {
xf.licb6cd282024-02-21 22:06:14 -08001834 LYINFLOG("[%s] apn full is false\n",__FUNCTION__);
1835 ret = apn_db_add((int)*profile_idx, apn);
1836 if (ret != 0)
1837 {
1838 LYERRLOG("apn_db_add error");
1839 return RESULT_ERROR;
1840 }
1841 else
1842 {
1843 return RESULT_OK;
1844 }
xf.li2fc84552023-06-23 05:26:47 -07001845 }
xf.licb6cd282024-02-21 22:06:14 -08001846 LYERRLOG("apn storage space is full!!!");
1847 return RESULT_ERROR;
xf.li6c7e3972023-10-27 20:01:59 -07001848#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001849 int apn_id = 0;
1850 char tmp_id[12];
1851 char *outinfo = NULL;
1852 char normalprotocol[16];
1853 char authtype[32];
1854 outinfo = (char *)malloc(sizeof(char)*512);
1855 bzero(tmp_id,12);
1856 bzero(outinfo,512);
1857 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1858 judge_pdp_type(apn->pdp_type,normalprotocol);
1859 judge_authtype(apn->auth_proto,authtype);
1860 lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo);
1861 LYINFLOG("[output]:%s",outinfo);
1862 free(outinfo);
1863 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001864#endif
1865 return ret;
xf.li2fc84552023-06-23 05:26:47 -07001866}
1867
1868int qser_apn_del(unsigned char profile_idx)
1869{
xf.li87f6e6e2024-06-19 02:23:05 -07001870 int ret = 0;
1871 int handle = -1;
1872
1873 LYINFLOG("[%s] entry\n",__FUNCTION__);
xf.lib33d4862023-12-13 00:40:37 -08001874 if(g_lynq_qser_data_init_flag == 0)
1875 {
1876 return LYNQ_E_NO_INIT;
1877 }
xf.li4b18fa62023-12-19 19:38:10 -08001878 if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST)
xf.li2fc84552023-06-23 05:26:47 -07001879 {
1880 LYERRLOG("apn del incoming paramters error");
xf.li4b18fa62023-12-19 19:38:10 -08001881 return RESULT_ERROR;
xf.li2fc84552023-06-23 05:26:47 -07001882 }
xf.li87f6e6e2024-06-19 02:23:05 -07001883
xf.licb6cd282024-02-21 22:06:14 -08001884 ret = apn_db_handle_get(profile_idx, &handle);
xf.li0fd6acf2023-12-20 18:16:34 -08001885 if(ret != 0)
1886 {
1887 LYERRLOG("handle set error");
1888 }
1889 if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX)
1890 {
1891 LYERRLOG("It has setup datacall");
1892 return RESULT_ERROR;
1893 }
xf.licb6cd282024-02-21 22:06:14 -08001894 ret = apn_db_delete(profile_idx);
xf.li2fc84552023-06-23 05:26:47 -07001895 if (ret < 0)
1896 {
xf.licb6cd282024-02-21 22:06:14 -08001897 LYERRLOG("apn_db_delete error");
xf.li2fc84552023-06-23 05:26:47 -07001898 return ret;
1899 }
xf.li6c7e3972023-10-27 20:01:59 -07001900#ifndef MOBILETEK_TARGET_PLATFORM_T106
xf.li2fc84552023-06-23 05:26:47 -07001901 int apn_id = 0;
1902 char tmp_id[12];
1903 char *outinfo = NULL;
1904 outinfo = (char *)malloc(sizeof(char)*512);
1905 bzero(tmp_id,12);
1906 bzero(outinfo,512);
1907 apn_id = profile_idx+apndb_offset;
1908 snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id);
1909 lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo);
1910 LYINFLOG("[output]:%s",outinfo);
1911 free(outinfo);
1912 outinfo = NULL;
xf.li6c7e3972023-10-27 20:01:59 -07001913#endif
xf.li2fc84552023-06-23 05:26:47 -07001914 return ret;
1915}
1916
1917int qser_apn_get_list(qser_apn_info_list_s *apn_list)
1918{
xf.lib33d4862023-12-13 00:40:37 -08001919 if(g_lynq_qser_data_init_flag == 0)
1920 {
1921 return LYNQ_E_NO_INIT;
1922 }
xf.li2fc84552023-06-23 05:26:47 -07001923 if (NULL == apn_list)
1924 {
1925 LYERRLOG("apn_list incoming paramters error");
1926 return RESULT_ERROR;
1927 }
1928 int ret = 0;
xf.licb6cd282024-02-21 22:06:14 -08001929 ret = apn_db_query_list(apn_list);
xf.li2fc84552023-06-23 05:26:47 -07001930 if (ret < 0)
1931 {
xf.licb6cd282024-02-21 22:06:14 -08001932 LYERRLOG("apn_db_query_list error");
xf.li2fc84552023-06-23 05:26:47 -07001933 return ret;
1934 }
1935 return ret;
xf.li3f891cb2023-08-23 23:11:24 -07001936}
you.chen21c62b72023-09-08 09:41:11 +08001937
1938DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA)
1939