xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1 | #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.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 12 | #include <sqlite3.h> |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 13 | #include "lynq-qser-data.h" |
| 14 | |
| 15 | #define USER_LOG_TAG "LYNQ_QSER_DATA" |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 16 | #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.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 20 | #define RESULT_OK (0) |
| 21 | #define RESULT_ERROR (-1) |
| 22 | |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 23 | typedef enum{ |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 24 | LYNQ_E_NO_INIT=9002, |
| 25 | LYNQ_E_APN_DB_FAIL=9003 |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 26 | }LYNQ_E; |
| 27 | |
| 28 | static int g_lynq_qser_data_init_flag = 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 29 | static pthread_t s_cb_tid = -1; |
| 30 | static int s_qser_data_cb_thread_status = 0; |
| 31 | static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER; |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 32 | static pthread_mutex_t s_qser_data_database_mutex = PTHREAD_MUTEX_INITIALIZER; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 33 | static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER; |
| 34 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 35 | |
| 36 | static qser_data_call_evt_cb_t s_data_call_cb = NULL; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 37 | static sqlite3* apnDb; |
| 38 | qser_apn_add_s default_apn = {QSER_APN_PDP_TYPE_IPV4V6, QSER_APN_AUTH_PROTO_DEFAULT, "default", "NULL", "NULL", "default"}; |
| 39 | int apn_indexs[LYNQ_APN_CHANNEL_MAX]={0}; |
| 40 | int next_index = 0; |
| 41 | int apn_count = 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 42 | const int apndb_offset = 683; |
| 43 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 44 | static int init_apn_db(); |
| 45 | static int create_apn_db(char *path); |
| 46 | static int create_apn_table(char*path); |
| 47 | static int has_apn_db_created(char *path,sqlite3* apnDb_l); |
| 48 | static int apn_db_handle_clean(); |
| 49 | |
| 50 | static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName); |
| 51 | static int lynq_check_index(unsigned char index); |
| 52 | static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName); |
| 53 | static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx); |
| 54 | static int apn_db_handle_set(unsigned char profile_idx, int handle); |
| 55 | static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName); |
| 56 | static int apn_db_handle_get(unsigned char profile_idx, int *handle); |
| 57 | |
| 58 | static int find_unuse_apn_index(char *path); |
| 59 | static int apn_db_add(int profile_id, qser_apn_add_s *apn); |
| 60 | static int apn_db_delete(unsigned char profile_idx); |
| 61 | static int apn_db_modify(qser_apn_info_s *apn); |
| 62 | static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName); |
| 63 | static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn); |
| 64 | static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName); |
| 65 | static int apn_db_query_list(qser_apn_info_list_s *apn_list); |
| 66 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 67 | void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res) |
| 68 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 69 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 70 | char *tmp_char = NULL; |
| 71 | char *addresses = NULL; |
| 72 | char *dnses = NULL; |
| 73 | const char addresses_separator[2] = "/"; |
| 74 | const char dnses_separator[2] = " "; |
| 75 | |
| 76 | addresses = libdata->addresses; |
| 77 | dnses = libdata->dnses; |
| 78 | //get addresses |
| 79 | tmp_char = strsep(&addresses, addresses_separator); |
| 80 | if(tmp_char != NULL) |
| 81 | { |
| 82 | LYINFLOG("ipv4 addresses = %s", tmp_char); |
| 83 | inet_aton(tmp_char,&(data_res->v4.ip)); |
| 84 | } |
| 85 | |
| 86 | //get dnses |
| 87 | tmp_char = strsep(&dnses, dnses_separator); |
| 88 | if(tmp_char != NULL) |
| 89 | { |
| 90 | LYINFLOG("ipv4 pri_dns = %s", tmp_char); |
| 91 | inet_aton(tmp_char,&(data_res->v4.pri_dns)); |
| 92 | } |
| 93 | tmp_char = strsep(&dnses, dnses_separator); |
| 94 | if(tmp_char != NULL) |
| 95 | { |
| 96 | LYINFLOG("ipv4 sec_dns = %s", tmp_char); |
| 97 | inet_aton(tmp_char, &(data_res->v4.sec_dns)); |
| 98 | } |
| 99 | //get gateway |
| 100 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 101 | |
| 102 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 103 | inet_aton(libdata->addresses,&(data_res->v4.ip)); |
| 104 | inet_aton(libdata->gateways,&(data_res->v4.gateway)); |
| 105 | inet_aton(libdata->dnses,&(data_res->v4.pri_dns)); |
| 106 | inet_aton(libdata->dnses,&(data_res->v4.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 107 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 108 | return ; |
| 109 | } |
| 110 | |
| 111 | void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res) |
| 112 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 113 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 114 | char *tmp_char = NULL; |
| 115 | char *addresses = NULL; |
| 116 | char *dnses = NULL; |
| 117 | const char addresses_separator[2] = "/"; |
| 118 | const char dnses_separator[2] = " "; |
| 119 | |
| 120 | addresses = libdata->addresses; |
| 121 | dnses = libdata->dnses; |
| 122 | //get addresses |
| 123 | tmp_char = strsep(&addresses, addresses_separator); |
| 124 | if(tmp_char != NULL) |
| 125 | { |
| 126 | LYINFLOG("ipv6 addresses = %s", tmp_char); |
| 127 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip)); |
| 128 | } |
| 129 | //get dnses |
| 130 | tmp_char = strsep(&dnses, dnses_separator); |
| 131 | if(tmp_char != NULL) |
| 132 | { |
| 133 | LYINFLOG("ipv6 pri_dns = %s", tmp_char); |
| 134 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns)); |
| 135 | } |
| 136 | tmp_char = strsep(&dnses, dnses_separator); |
| 137 | if(tmp_char != NULL) |
| 138 | { |
| 139 | LYINFLOG("ipv6 sec_dns = %s", tmp_char); |
| 140 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns)); |
| 141 | } |
| 142 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 143 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 144 | inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip)); |
| 145 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 146 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns)); |
| 147 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 148 | #endif |
| 149 | |
| 150 | return ; |
| 151 | } |
| 152 | |
| 153 | void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res) |
| 154 | { |
| 155 | char *tmp_char = NULL; |
| 156 | char *addresses = NULL; |
| 157 | char *dnses = NULL; |
| 158 | const char addresses_separator[2] = "/"; |
| 159 | const char dnses_separator[2] = " "; |
| 160 | |
xf.li | 03baf1f | 2023-12-19 21:30:38 -0800 | [diff] [blame] | 161 | char buf_ip[64] = {0}; |
| 162 | char buf_gateway[64] = {0}; |
| 163 | char buf_pri_dns[64] = {0}; |
| 164 | char buf_sec_dns[64] = {0}; |
| 165 | |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 166 | addresses = libdata->addresses; |
| 167 | dnses = libdata->dnses; |
| 168 | //get addresses |
| 169 | tmp_char = strsep(&addresses, addresses_separator); |
| 170 | if(tmp_char != NULL) |
| 171 | { |
| 172 | LYINFLOG("ipv4 addresses = %s", tmp_char); |
| 173 | inet_aton(tmp_char,&(data_res->v4.ip)); |
| 174 | } |
| 175 | tmp_char = strsep(&addresses, addresses_separator); |
| 176 | if(tmp_char != NULL) |
| 177 | { |
| 178 | LYINFLOG("ipv6 addresses = %s", tmp_char); |
| 179 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip)); |
| 180 | } |
| 181 | //get dnses |
| 182 | tmp_char = strsep(&dnses, dnses_separator); |
| 183 | if(tmp_char != NULL) |
| 184 | { |
| 185 | LYINFLOG("ipv4 pri_dns = %s", tmp_char); |
| 186 | inet_aton(tmp_char,&(data_res->v4.pri_dns)); |
| 187 | } |
| 188 | tmp_char = strsep(&dnses, dnses_separator); |
| 189 | if(tmp_char != NULL) |
| 190 | { |
| 191 | LYINFLOG("ipv4 sec_dns = %s", tmp_char); |
| 192 | inet_aton(tmp_char, &(data_res->v4.sec_dns)); |
| 193 | } |
| 194 | tmp_char = strsep(&dnses, dnses_separator); |
| 195 | if(tmp_char != NULL) |
| 196 | { |
| 197 | LYINFLOG("ipv6 pri_dns = %s", tmp_char); |
| 198 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns)); |
| 199 | } |
| 200 | tmp_char = strsep(&dnses, dnses_separator); |
| 201 | if(tmp_char != NULL) |
| 202 | { |
| 203 | LYINFLOG("ipv6 sec_dns = %s", tmp_char); |
| 204 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns)); |
| 205 | } |
| 206 | //get gateway |
xf.li | 03baf1f | 2023-12-19 21:30:38 -0800 | [diff] [blame] | 207 | inet_aton(libdata->gateways,&(data_res->v4.gateway)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 208 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 209 | |
xf.li | 03baf1f | 2023-12-19 21:30:38 -0800 | [diff] [blame] | 210 | LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip)); |
| 211 | LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns)); |
| 212 | LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns)); |
| 213 | |
| 214 | inet_ntop(AF_INET6, &(data_res->v6.ip), buf_ip, sizeof(buf_ip)); |
| 215 | inet_ntop(AF_INET6, &(data_res->v6.gateway), buf_gateway, sizeof(buf_gateway)); |
| 216 | inet_ntop(AF_INET6, &(data_res->v6.pri_dns), buf_pri_dns, sizeof(buf_pri_dns)); |
| 217 | inet_ntop(AF_INET6, &(data_res->v6.sec_dns), buf_sec_dns, sizeof(buf_sec_dns)); |
| 218 | LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n" |
| 219 | , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 220 | return ; |
| 221 | } |
| 222 | |
| 223 | void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res) |
| 224 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 225 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 226 | char *tmp_char = NULL; |
| 227 | char *addresses = NULL; |
| 228 | char *dnses = NULL; |
| 229 | const char addresses_separator[2] = "/"; |
| 230 | const char dnses_separator[2] = " "; |
| 231 | |
| 232 | addresses = libdata->addresses; |
| 233 | dnses = libdata->dnses; |
| 234 | //get addresses |
| 235 | tmp_char = strsep(&addresses, addresses_separator); |
| 236 | if(tmp_char != NULL) |
| 237 | { |
| 238 | LYINFLOG("ipv4 addresses = %s", tmp_char); |
| 239 | inet_aton(tmp_char,&(data_res->v4.addr.ip)); |
| 240 | } |
| 241 | //get dnses |
| 242 | tmp_char = strsep(&dnses, dnses_separator); |
| 243 | if(tmp_char != NULL) |
| 244 | { |
| 245 | LYINFLOG("ipv4 pri_dns = %s", tmp_char); |
| 246 | inet_aton(tmp_char,&(data_res->v4.addr.pri_dns)); |
| 247 | } |
| 248 | tmp_char = strsep(&dnses, dnses_separator); |
| 249 | if(tmp_char != NULL) |
| 250 | { |
| 251 | LYINFLOG("ipv4 sec_dns = %s", tmp_char); |
| 252 | inet_aton(tmp_char, &(data_res->v4.addr.sec_dns)); |
| 253 | } |
| 254 | //get gateway |
| 255 | LYINFLOG("ipv4 gateways = %s", libdata->gateways); |
| 256 | inet_aton(libdata->gateways,&(data_res->v4.addr.gateway)); |
| 257 | |
| 258 | LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip)); |
| 259 | LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns)); |
| 260 | LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns)); |
| 261 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 262 | inet_aton(libdata->addresses,&(data_res->v4.addr.ip)); |
| 263 | inet_aton(libdata->gateways,&(data_res->v4.addr.gateway)); |
| 264 | inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns)); |
| 265 | inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 266 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 267 | data_res->v4.stats.pkts_tx = 0; |
| 268 | data_res->v4.stats.pkts_rx = 0; |
| 269 | data_res->v4.stats.bytes_tx = 0; |
| 270 | data_res->v4.stats.bytes_rx = 0; |
| 271 | data_res->v4.stats.pkts_dropped_tx = 0; |
| 272 | data_res->v4.stats.pkts_dropped_rx = 0; |
| 273 | return ; |
| 274 | } |
| 275 | |
| 276 | void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res) |
| 277 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 278 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 279 | char *tmp_char = NULL; |
| 280 | char *addresses = NULL; |
| 281 | char *dnses = NULL; |
| 282 | const char addresses_separator[2] = "/"; |
| 283 | const char dnses_separator[2] = " "; |
| 284 | |
| 285 | addresses = libdata->addresses; |
| 286 | dnses = libdata->dnses; |
| 287 | //get addresses |
| 288 | tmp_char = strsep(&addresses, addresses_separator); |
| 289 | if(tmp_char != NULL) |
| 290 | { |
| 291 | LYINFLOG("ipv6 addresses = %s", tmp_char); |
| 292 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip)); |
| 293 | } |
| 294 | //get dnses |
| 295 | tmp_char = strsep(&dnses, dnses_separator); |
| 296 | if(tmp_char != NULL) |
| 297 | { |
| 298 | LYINFLOG("ipv6 pri_dns = %s", tmp_char); |
| 299 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns)); |
| 300 | } |
| 301 | tmp_char = strsep(&dnses, dnses_separator); |
| 302 | if(tmp_char != NULL) |
| 303 | { |
| 304 | LYINFLOG("ipv6 sec_dns = %s", tmp_char); |
| 305 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns)); |
| 306 | } |
| 307 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway)); |
| 308 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 309 | inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip)); |
| 310 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway)); |
| 311 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns)); |
| 312 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 313 | #endif |
| 314 | data_res->v6.stats.pkts_tx = 0; |
| 315 | data_res->v6.stats.pkts_rx = 0; |
| 316 | data_res->v6.stats.bytes_tx = 0; |
| 317 | data_res->v6.stats.bytes_rx = 0; |
| 318 | data_res->v6.stats.pkts_dropped_tx = 0; |
| 319 | data_res->v6.stats.pkts_dropped_rx = 0; |
| 320 | return ; |
| 321 | } |
| 322 | void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res) |
| 323 | { |
| 324 | char *tmp_char = NULL; |
| 325 | char *addresses = NULL; |
| 326 | char *dnses = NULL; |
| 327 | const char addresses_separator[2] = "/"; |
| 328 | const char dnses_separator[2] = " "; |
| 329 | |
| 330 | char buf_ip[64] = {0}; |
| 331 | char buf_gateway[64] = {0}; |
| 332 | char buf_pri_dns[64] = {0}; |
| 333 | char buf_sec_dns[64] = {0}; |
| 334 | |
| 335 | addresses = libdata->addresses; |
| 336 | dnses = libdata->dnses; |
| 337 | //get addresses |
| 338 | tmp_char = strsep(&addresses, addresses_separator); |
| 339 | if(tmp_char != NULL) |
| 340 | { |
| 341 | LYINFLOG("ipv4 addresses = %s", tmp_char); |
| 342 | inet_aton(tmp_char,&(data_res->v4.addr.ip)); |
| 343 | } |
| 344 | tmp_char = strsep(&addresses, addresses_separator); |
| 345 | if(tmp_char != NULL) |
| 346 | { |
| 347 | LYINFLOG("ipv6 addresses = %s", tmp_char); |
| 348 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip)); |
| 349 | } |
| 350 | //get dnses |
| 351 | tmp_char = strsep(&dnses, dnses_separator); |
| 352 | if(tmp_char != NULL) |
| 353 | { |
| 354 | LYINFLOG("ipv4 pri_dns = %s", tmp_char); |
| 355 | inet_aton(tmp_char,&(data_res->v4.addr.pri_dns)); |
| 356 | } |
| 357 | tmp_char = strsep(&dnses, dnses_separator); |
| 358 | if(tmp_char != NULL) |
| 359 | { |
| 360 | LYINFLOG("ipv4 sec_dns = %s", tmp_char); |
| 361 | inet_aton(tmp_char, &(data_res->v4.addr.sec_dns)); |
| 362 | } |
| 363 | tmp_char = strsep(&dnses, dnses_separator); |
| 364 | if(tmp_char != NULL) |
| 365 | { |
| 366 | LYINFLOG("ipv6 pri_dns = %s", tmp_char); |
| 367 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns)); |
| 368 | } |
| 369 | tmp_char = strsep(&dnses, dnses_separator); |
| 370 | if(tmp_char != NULL) |
| 371 | { |
| 372 | LYINFLOG("ipv6 sec_dns = %s", tmp_char); |
| 373 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns)); |
| 374 | } |
| 375 | //get gateway |
xf.li | 03baf1f | 2023-12-19 21:30:38 -0800 | [diff] [blame] | 376 | inet_aton(libdata->gateways,&(data_res->v4.addr.gateway)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 377 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway)); |
| 378 | |
| 379 | LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip)); |
xf.li | 03baf1f | 2023-12-19 21:30:38 -0800 | [diff] [blame] | 380 | LYINFLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 381 | LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns)); |
| 382 | LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns)); |
| 383 | |
| 384 | inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip)); |
| 385 | inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway)); |
| 386 | inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns)); |
| 387 | inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns)); |
| 388 | LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n" |
| 389 | , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns); |
| 390 | data_res->v4.stats.pkts_tx = 0; |
| 391 | data_res->v4.stats.pkts_rx = 0; |
| 392 | data_res->v4.stats.bytes_tx = 0; |
| 393 | data_res->v4.stats.bytes_rx = 0; |
| 394 | data_res->v4.stats.pkts_dropped_tx = 0; |
| 395 | data_res->v4.stats.pkts_dropped_rx = 0; |
| 396 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 397 | data_res->v6.stats.pkts_tx = 0; |
| 398 | data_res->v6.stats.pkts_rx = 0; |
| 399 | data_res->v6.stats.bytes_tx = 0; |
| 400 | data_res->v6.stats.bytes_rx = 0; |
| 401 | data_res->v6.stats.pkts_dropped_tx = 0; |
| 402 | data_res->v6.stats.pkts_dropped_rx = 0; |
| 403 | return ; |
| 404 | } |
| 405 | |
| 406 | void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res) |
| 407 | { |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 408 | if(state != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 409 | { |
| 410 | data_res->v4.state = QSER_DATA_CALL_CONNECTED; |
| 411 | data_res->v4.reconnect = 1; |
| 412 | } |
| 413 | else |
| 414 | { |
| 415 | data_res->v4.state = QSER_DATA_CALL_DISCONNECTED; |
| 416 | data_res->v4.reconnect = 0; |
| 417 | } |
| 418 | return ; |
| 419 | } |
| 420 | |
| 421 | void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res) |
| 422 | { |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 423 | if(state != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 424 | { |
| 425 | data_res->v6.state = QSER_DATA_CALL_CONNECTED; |
| 426 | data_res->v6.reconnect = 1; |
| 427 | } |
| 428 | else |
| 429 | { |
| 430 | data_res->v6.state = QSER_DATA_CALL_DISCONNECTED; |
| 431 | data_res->v6.reconnect = 0; |
| 432 | } |
| 433 | return ; |
| 434 | } |
| 435 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 436 | // ****************apn DB start****************** |
| 437 | static int apn_db_handle_get_profile_cb(void *data, int argc, char **argv, char **azColName) |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 438 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 439 | if(data==NULL) |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 440 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 441 | return 1; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 442 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 443 | int *temp = (int *)data; |
| 444 | for(int i=0; i<argc; i++){ |
| 445 | LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL"); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 446 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 447 | *temp = atoi(argv[0]); |
| 448 | return 0; |
| 449 | } |
| 450 | static int apn_db_handle_get_profile(int handle, unsigned char *profile_idx) |
| 451 | { |
| 452 | char *zErrMsg = 0; |
| 453 | int rc; |
| 454 | int idx = 0; |
| 455 | |
| 456 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 457 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 458 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 459 | if( rc ) |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 460 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 461 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 462 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 463 | return LYNQ_E_APN_DB_FAIL; |
| 464 | } |
| 465 | |
| 466 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 467 | /* Create SQL statement */ |
| 468 | char *sql = sqlite3_mprintf("SELECT ID from LYNQAPN WHERE HANDLE=%d", handle); |
| 469 | LYINFLOG("sql: %s\n", sql); |
| 470 | /* Execute SQL statement */ |
| 471 | rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_profile_cb, &idx, &zErrMsg); |
| 472 | if( rc != SQLITE_OK ) |
| 473 | { |
| 474 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 475 | sqlite3_free(zErrMsg); |
| 476 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 477 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 478 | return LYNQ_E_APN_DB_FAIL; |
| 479 | }; |
| 480 | *profile_idx = (unsigned char)idx; |
| 481 | LYINFLOG("get idx %d successfully\n", *profile_idx); |
| 482 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 483 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 484 | return 0; |
| 485 | } |
| 486 | static int lynq_apn_callback(void *data, int argc, char **argv, char **azColName){ |
| 487 | int i; |
| 488 | |
| 489 | apn_indexs[atoi(argv[0])] = atoi(argv[0]); |
| 490 | LYINFLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]); |
| 491 | |
| 492 | for(i=0; i<argc; i++){ |
| 493 | LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL"); |
| 494 | } |
| 495 | return 0; |
| 496 | } |
| 497 | /** |
| 498 | * @brief Check whether the ID exists in the database |
| 499 | * |
| 500 | * @param index |
| 501 | * @return int |
| 502 | * find:turn 1 |
| 503 | * not find:turn 0 |
| 504 | */ |
| 505 | static int lynq_check_index(unsigned char index) |
| 506 | { |
| 507 | memset(apn_indexs,0,sizeof(apn_indexs)); |
| 508 | next_index = 0; |
| 509 | char *zErrMsg = 0; |
| 510 | int rc; |
| 511 | char sql[128]={0}; |
| 512 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 513 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 514 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 515 | if( rc ) |
| 516 | { |
| 517 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 518 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 519 | return LYNQ_E_APN_DB_FAIL; |
| 520 | } |
| 521 | sprintf(sql,"%s", "SELECT * from LYNQAPN"); |
| 522 | rc = sqlite3_exec(apnDb, sql, lynq_apn_callback, NULL, &zErrMsg); |
| 523 | if( rc != SQLITE_OK ) |
| 524 | { |
| 525 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 526 | sqlite3_free(zErrMsg); |
| 527 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 528 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 529 | return LYNQ_E_APN_DB_FAIL; |
| 530 | } |
| 531 | //for(int cnt = 0; cnt < next_index;cnt++) |
| 532 | for(int cnt = 0; cnt <= QSER_APN_MAX_LIST; cnt++) |
| 533 | { |
| 534 | if(index == apn_indexs[cnt]) |
| 535 | { |
| 536 | LYINFLOG("index = apn_index\n"); |
| 537 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 538 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 539 | return 1; |
| 540 | } |
| 541 | } |
| 542 | LYINFLOG("cant find the index %d\n", index); |
| 543 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 544 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
| 545 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | static int apn_db_handle_set(unsigned char profile_idx, int handle) |
| 550 | { |
| 551 | char *zErrMsg = 0; |
| 552 | int rc; |
| 553 | //char sql[128]={0}; |
| 554 | if(!lynq_check_index(profile_idx)) |
| 555 | { |
| 556 | return LYNQ_E_APN_DB_FAIL; |
| 557 | } |
| 558 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 559 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 560 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 561 | if( rc ) |
| 562 | { |
| 563 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 564 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 565 | return LYNQ_E_APN_DB_FAIL; |
| 566 | } |
| 567 | |
| 568 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 569 | /* Create SQL statement */ |
| 570 | //sql = "SELECT * from LYNQAPN"; |
| 571 | char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d WHERE ID=%d", handle, (int)profile_idx); |
| 572 | LYINFLOG("sql: %s\n", sql); |
| 573 | /* Execute SQL statement */ |
| 574 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
| 575 | if( rc != SQLITE_OK ) |
| 576 | { |
| 577 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 578 | sqlite3_free(zErrMsg); |
| 579 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 580 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 581 | return LYNQ_E_APN_DB_FAIL; |
| 582 | } |
| 583 | LYINFLOG("update apn %d successfully\n", profile_idx); |
| 584 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 585 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 586 | return 0; |
| 587 | } |
| 588 | static int apn_db_handle_get_cb(void *data, int argc, char **argv, char **azColName) |
| 589 | { |
| 590 | if(data==NULL) |
| 591 | { |
| 592 | return 1; |
| 593 | } |
| 594 | int *temp = (int *)data; |
| 595 | for(int i=0; i<argc; i++){ |
| 596 | LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL"); |
| 597 | } |
| 598 | *temp = atoi(argv[0]); |
| 599 | LYINFLOG("The handle is %d\n", *temp); |
| 600 | return 0; |
| 601 | } |
| 602 | static int apn_db_handle_get(unsigned char profile_idx, int *handle) |
| 603 | { |
| 604 | char *zErrMsg = 0; |
| 605 | int rc; |
| 606 | |
| 607 | //char sql[128]={0}; |
| 608 | if(!lynq_check_index(profile_idx)) |
| 609 | { |
| 610 | return LYNQ_E_APN_DB_FAIL; |
| 611 | } |
| 612 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 613 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 614 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 615 | if( rc ) |
| 616 | { |
| 617 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 618 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 619 | return LYNQ_E_APN_DB_FAIL; |
| 620 | } |
| 621 | |
| 622 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 623 | /* Create SQL statement */ |
| 624 | char *sql = sqlite3_mprintf("SELECT HANDLE from LYNQAPN WHERE ID=%d", (int)profile_idx); |
| 625 | LYINFLOG("sql: %s\n", sql); |
| 626 | /* Execute SQL statement */ |
| 627 | rc = sqlite3_exec(apnDb, sql, apn_db_handle_get_cb, handle, &zErrMsg); |
| 628 | if( rc != SQLITE_OK ) |
| 629 | { |
| 630 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 631 | sqlite3_free(zErrMsg); |
| 632 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 633 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 634 | return LYNQ_E_APN_DB_FAIL; |
| 635 | } |
| 636 | LYINFLOG("get idx %d successfully\n", *handle); |
| 637 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 638 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static int has_apn_db_created(char *path,sqlite3* apnDb_l) |
| 643 | { |
| 644 | if (path == NULL || strlen(path) == 0) |
| 645 | { |
| 646 | LYERRLOG("initApnDb error with null path!"); |
| 647 | return APN_DB_ERR; |
| 648 | } |
| 649 | int rc = sqlite3_open_v2(path, &apnDb_l, SQLITE_OPEN_READWRITE,NULL); |
| 650 | if (rc == SQLITE_OK) |
| 651 | { |
| 652 | LYINFLOG("check init success!"); |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 653 | sqlite3_close_v2(apnDb_l); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 654 | return APN_DB_READED; |
| 655 | } |
| 656 | else |
| 657 | { |
| 658 | LYERRLOG("db has not create %s!", sqlite3_errmsg(apnDb_l)); |
| 659 | sqlite3_close_v2(apnDb_l); |
| 660 | return APN_DB_ERR; |
| 661 | } |
| 662 | } |
| 663 | static int create_apn_db(char *path) |
| 664 | { |
| 665 | if (path == NULL || strlen(path) == 0) { |
| 666 | LYERRLOG("initApnDb error with null path!"); |
| 667 | return APN_DB_ERR; |
| 668 | } |
| 669 | if(APN_DB_READED==has_apn_db_created(path,apnDb)) |
| 670 | { |
| 671 | return APN_DB_READED; |
| 672 | } |
| 673 | int rc = sqlite3_open(path, &apnDb); |
| 674 | if (rc != SQLITE_OK) { |
| 675 | LYERRLOG("initDb failed %d", sqlite3_errcode(apnDb)); |
| 676 | return APN_DB_ERR; |
| 677 | } else { |
| 678 | LYINFLOG("create db in %s", path); |
| 679 | } |
| 680 | sqlite3_close(apnDb); |
| 681 | return APN_DB_CREATE; |
| 682 | } |
| 683 | static int create_apn_table(char*path) |
| 684 | { |
| 685 | char *zErrMsg = 0; |
| 686 | int rc; |
| 687 | char *sql; |
| 688 | |
| 689 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 690 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 691 | rc = sqlite3_open(path, &apnDb); |
| 692 | if( rc ) |
| 693 | { |
| 694 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 695 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 696 | return 1; |
| 697 | } |
| 698 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 699 | /* Create SQL statement */ |
| 700 | sql = "CREATE TABLE LYNQAPN( \ |
| 701 | ID INT NOT NULL, \ |
| 702 | PDP_TYPE INT NOT NULL, \ |
| 703 | AUTH_PROTO INT NOT NULL, \ |
| 704 | APN_NAME TEXT NOT NULL, \ |
| 705 | USERNAME TEXT NOT NULL,\ |
| 706 | PASSWORD TEXT NOT NULL, \ |
| 707 | APN_TYPE TEXT PRIMARY KEY NOT NULL, \ |
| 708 | HANDLE INT NOT NULL)"; |
| 709 | /* Execute SQL statement */ |
| 710 | rc = sqlite3_exec(apnDb, sql, NULL, 0, &zErrMsg); |
| 711 | if( rc != SQLITE_OK ) |
| 712 | { |
| 713 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 714 | sqlite3_free(zErrMsg); |
| 715 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 716 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 717 | return 1; |
| 718 | } |
| 719 | LYINFLOG("Table LYNQAPN created successfully\n"); |
| 720 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 721 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 722 | return 0; |
| 723 | } |
| 724 | static int init_apn_db() |
| 725 | { |
| 726 | int db_ret=0; |
| 727 | int table_ret=0; |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 728 | |
| 729 | pthread_mutex_init(&s_qser_data_database_mutex, NULL); |
| 730 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 731 | db_ret = create_apn_db(APN_DB_PATH); |
| 732 | if(db_ret==APN_DB_CREATE) |
| 733 | { |
| 734 | table_ret = create_apn_table(APN_DB_PATH); |
| 735 | if(table_ret!=0) |
| 736 | { |
| 737 | LYERRLOG("create apn table fail!!!"); |
| 738 | return RESULT_ERROR; |
| 739 | } |
| 740 | apn_db_add(0, &default_apn); |
| 741 | } |
| 742 | else if(db_ret==APN_DB_READED) |
| 743 | { |
| 744 | LYERRLOG("[%s] apn db has be build!!!",__FUNCTION__); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 745 | } |
| 746 | else |
| 747 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 748 | LYERRLOG("init apn db fail!!!"); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 749 | } |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 750 | return RESULT_OK; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 751 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 752 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 753 | static int apn_db_handle_clean() |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 754 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 755 | char *zErrMsg = 0; |
| 756 | int rc; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 757 | int default_handle = LYNQ_APN_CHANNEL_MAX + 1; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 758 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 759 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 760 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 761 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 762 | if( rc ) |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 763 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 764 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 765 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 766 | return LYNQ_E_APN_DB_FAIL; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 767 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 768 | |
| 769 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 770 | /* Create SQL statement */ |
| 771 | char *sql = sqlite3_mprintf("UPDATE LYNQAPN SET HANDLE=%d", default_handle); |
| 772 | LYINFLOG("sql: %s\n", sql); |
| 773 | /* Execute SQL statement */ |
| 774 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
| 775 | if( rc != SQLITE_OK ) |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 776 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 777 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 778 | sqlite3_free(zErrMsg); |
| 779 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 780 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 781 | return LYNQ_E_APN_DB_FAIL; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 782 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 783 | LYINFLOG("clean apn table successfully\n"); |
| 784 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 785 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 786 | return RESULT_OK; |
| 787 | } |
| 788 | |
| 789 | static int find_unuse_apn_index(char *path) |
| 790 | { |
| 791 | char *zErrMsg = 0; |
| 792 | int rc; |
| 793 | int count =1; |
| 794 | bool apn_usable = false; |
| 795 | char *sql; |
| 796 | |
| 797 | memset(apn_indexs,0,sizeof(apn_indexs)); |
| 798 | next_index = 0; |
| 799 | LYINFLOG("index = %p",apn_indexs); |
| 800 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 801 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 802 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 803 | if( rc ) |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 804 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 805 | LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 806 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 807 | return -1; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 808 | } |
| 809 | else |
| 810 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 811 | LYINFLOG("Opened database successfully\n"); |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 812 | } |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 813 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 814 | /* Create SQL statement */ |
| 815 | sql = "SELECT ID from LYNQAPN"; |
| 816 | /* Execute SQL statement */ |
| 817 | rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg); |
| 818 | if( rc != SQLITE_OK ) |
| 819 | { |
| 820 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 821 | sqlite3_free(zErrMsg); |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 822 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 823 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 824 | return -1; |
| 825 | } |
| 826 | else |
| 827 | { |
| 828 | LYINFLOG("Operation done successfully\n"); |
| 829 | } |
| 830 | //indexs = temp_index; |
| 831 | LYINFLOG("index = %p",apn_indexs); |
| 832 | for(count;count<=QSER_APN_MAX_LIST;count++) |
| 833 | { |
| 834 | //if(apn_indexs[count-1]!=count) |
| 835 | LYINFLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count); |
| 836 | if(apn_indexs[count]!=count) |
| 837 | { |
| 838 | //apn_usable=true; |
| 839 | break; |
| 840 | } |
| 841 | } |
| 842 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 843 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 844 | LYINFLOG("count is %d\n", count); |
| 845 | return count; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 846 | } |
| 847 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 848 | static int apn_db_add(int profile_id, qser_apn_add_s *apn) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 849 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 850 | char *zErrMsg = 0; |
| 851 | int rc; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 852 | int default_handle = LYNQ_APN_CHANNEL_MAX + 1; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 853 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 854 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 855 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 856 | if( rc ) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 857 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 858 | LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 859 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 860 | return 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 861 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 862 | LYINFLOG("[%s] Opened database successfully",__FUNCTION__); |
| 863 | /* Create SQL statement */ |
| 864 | /* Execute SQL statement */ |
| 865 | LYINFLOG("the profile id is %d\n", profile_id); |
| 866 | char *sql = sqlite3_mprintf("INSERT INTO LYNQAPN VALUES('%d','%d','%d','%q','%q','%q','%q','%d')", profile_id, apn->pdp_type, apn->auth_proto, apn->apn_name, apn->username, apn->password, apn->apn_type, default_handle); |
| 867 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
| 868 | if( rc != SQLITE_OK ) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 869 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 870 | LYERRLOG( "SQL error: %s", zErrMsg); |
| 871 | sqlite3_free(zErrMsg); |
| 872 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 873 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 874 | return 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 875 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 876 | LYINFLOG("write apn to apn db successfully"); |
| 877 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 878 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 879 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 880 | } |
| 881 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 882 | static int apn_db_delete(unsigned char profile_idx) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 883 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 884 | char *zErrMsg = 0; |
| 885 | int rc; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 886 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 887 | if(!lynq_check_index(profile_idx)) |
| 888 | { |
| 889 | return LYNQ_E_APN_DB_FAIL; |
| 890 | } |
| 891 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 892 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 893 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 894 | if( rc ) |
| 895 | { |
| 896 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 897 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 898 | return LYNQ_E_APN_DB_FAIL; |
| 899 | } |
| 900 | |
| 901 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 902 | /* Create SQL statement */ |
| 903 | //sql = "SELECT * from LYNQAPN"; |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 904 | char *sql = sqlite3_mprintf("DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 905 | LYINFLOG("sql: %s\n", sql); |
| 906 | /* Execute SQL statement */ |
| 907 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
| 908 | if( rc != SQLITE_OK ) |
| 909 | { |
| 910 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 911 | sqlite3_free(zErrMsg); |
| 912 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 913 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 914 | return LYNQ_E_APN_DB_FAIL; |
| 915 | } |
| 916 | LYINFLOG("delete apn %d successfully\n", profile_idx); |
| 917 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 918 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 919 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 920 | } |
| 921 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 922 | static int apn_db_modify(qser_apn_info_s *apn) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 923 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 924 | char *zErrMsg = 0; |
| 925 | int rc; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 926 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 927 | if(!lynq_check_index(apn->profile_idx)) |
| 928 | { |
| 929 | return LYNQ_E_APN_DB_FAIL; |
| 930 | } |
| 931 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 932 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 933 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 934 | if( rc ) |
| 935 | { |
| 936 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 937 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 938 | return LYNQ_E_APN_DB_FAIL; |
| 939 | } |
| 940 | |
| 941 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 942 | /* Create SQL statement */ |
| 943 | char *sql = sqlite3_mprintf("UPDATE LYNQAPN set PDP_TYPE = %d, AUTH_PROTO = %d, APN_NAME = '%q', USERNAME = '%q', PASSWORD = '%q', APN_TYPE = '%q' WHERE ID=%d", apn->pdp_type, apn->auth_proto, apn->apn_name, apn->username, apn->password, apn->apn_type, apn->profile_idx); |
| 944 | LYINFLOG("sql: %s\n", sql); |
| 945 | /* Execute SQL statement */ |
| 946 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
| 947 | if( rc != SQLITE_OK ) |
| 948 | { |
| 949 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 950 | sqlite3_free(zErrMsg); |
| 951 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 952 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 953 | return LYNQ_E_APN_DB_FAIL; |
| 954 | } |
| 955 | LYINFLOG("set apn %d successfully\n",apn->profile_idx); |
| 956 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 957 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 958 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 959 | } |
| 960 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 961 | static int lynq_apn_db_query_cb(void *data, int argc, char **argv, char **azColName) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 962 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 963 | if(data==NULL) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 964 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 965 | return 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 966 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 967 | qser_apn_info_s* temp = (qser_apn_info_s *)data; |
| 968 | for(int i=0; i<argc; i++){ |
| 969 | LYINFLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 970 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 971 | temp->profile_idx = atoi(argv[0]); |
| 972 | temp->pdp_type = atoi(argv[1]); |
| 973 | temp->auth_proto = atoi(argv[2]); |
| 974 | memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE); |
| 975 | memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE); |
| 976 | memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE); |
| 977 | memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE); |
| 978 | LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0])); |
| 979 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 980 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 981 | static int apn_db_query(unsigned char profile_idx,qser_apn_info_s *apn) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 982 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 983 | char *zErrMsg = 0; |
| 984 | int rc; |
| 985 | |
| 986 | if(!lynq_check_index(profile_idx)) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 987 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 988 | return LYNQ_E_APN_DB_FAIL; |
| 989 | } |
| 990 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 991 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 992 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 993 | if( rc ) |
| 994 | { |
| 995 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 996 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 997 | return LYNQ_E_APN_DB_FAIL; |
| 998 | } |
| 999 | |
| 1000 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 1001 | /* Create SQL statement */ |
| 1002 | char *sql = sqlite3_mprintf("SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx); |
| 1003 | LYINFLOG("sql: %s\n", sql); |
| 1004 | /* Execute SQL statement */ |
| 1005 | rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg); |
| 1006 | if( rc != SQLITE_OK ) |
| 1007 | { |
| 1008 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 1009 | sqlite3_free(zErrMsg); |
| 1010 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1011 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1012 | return LYNQ_E_APN_DB_FAIL; |
| 1013 | } |
| 1014 | LYINFLOG("set apn %d successfully\n",apn->profile_idx); |
| 1015 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1016 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
| 1019 | static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName) |
| 1020 | { |
| 1021 | int i; |
| 1022 | |
| 1023 | //apn_count++; |
| 1024 | |
| 1025 | qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data; |
| 1026 | for(i=0; i<argc; i++){ |
| 1027 | LYINFLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1028 | } |
| 1029 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1030 | temp->apn[temp->cnt].profile_idx = atoi(argv[0]); |
| 1031 | temp->apn[temp->cnt].pdp_type = atoi(argv[1]); |
| 1032 | temp->apn[temp->cnt].auth_proto = atoi(argv[2]); |
| 1033 | memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE); |
| 1034 | memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE); |
| 1035 | memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE); |
| 1036 | memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE); |
| 1037 | temp->cnt++; |
| 1038 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1039 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1040 | static int apn_db_query_list(qser_apn_info_list_s *apn_list) |
| 1041 | { |
| 1042 | char *zErrMsg = 0; |
| 1043 | int rc; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1044 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1045 | /* Open database */ |
| 1046 | apn_count = 0; |
| 1047 | apn_list->cnt = 0; |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1048 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1049 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 1050 | if( rc ) |
| 1051 | { |
| 1052 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1053 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1054 | return LYNQ_E_APN_DB_FAIL; |
| 1055 | } |
| 1056 | |
| 1057 | LYINFLOG("[%s] Opened database successfully\n",__FUNCTION__); |
| 1058 | /* Create SQL statement */ |
| 1059 | char *sql = sqlite3_mprintf("SELECT * from LYNQAPN"); |
| 1060 | LYINFLOG("sql: %s\n", sql); |
| 1061 | /* Execute SQL statement */ |
| 1062 | rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg); |
| 1063 | if( rc != SQLITE_OK ) |
| 1064 | { |
| 1065 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 1066 | sqlite3_free(zErrMsg); |
| 1067 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1068 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1069 | return LYNQ_E_APN_DB_FAIL; |
| 1070 | } |
| 1071 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1072 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1073 | return 0; |
| 1074 | } |
| 1075 | // **************apn DB end**************************** |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1076 | void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type) |
| 1077 | { |
| 1078 | switch (pdp_type) |
| 1079 | { |
| 1080 | case QSER_APN_PDP_TYPE_IPV4: |
xf.li | 9e27f3d | 2023-11-30 00:43:13 -0800 | [diff] [blame] | 1081 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1082 | strcpy(out_pdp_type,"IP"); |
| 1083 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1084 | strcpy(out_pdp_type,"IPV4"); |
xf.li | 9e27f3d | 2023-11-30 00:43:13 -0800 | [diff] [blame] | 1085 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1086 | break; |
| 1087 | case QSER_APN_PDP_TYPE_PPP: |
| 1088 | strcpy(out_pdp_type,"PPP"); |
| 1089 | break; |
| 1090 | case QSER_APN_PDP_TYPE_IPV6: |
| 1091 | strcpy(out_pdp_type,"IPV6"); |
| 1092 | break; |
| 1093 | case QSER_APN_PDP_TYPE_IPV4V6: |
| 1094 | strcpy(out_pdp_type,"IPV4V6"); |
| 1095 | break; |
| 1096 | default: |
| 1097 | strcpy(out_pdp_type,"NULL"); |
| 1098 | break; |
| 1099 | } |
| 1100 | return; |
| 1101 | } |
| 1102 | void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto) |
| 1103 | { |
| 1104 | switch (auth_proto) |
| 1105 | { |
| 1106 | case QSER_APN_AUTH_PROTO_DEFAULT: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1107 | strcpy(out_proto,"0"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1108 | break; |
| 1109 | case QSER_APN_AUTH_PROTO_NONE: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1110 | strcpy(out_proto,"0"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1111 | break; |
| 1112 | case QSER_APN_AUTH_PROTO_PAP: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1113 | strcpy(out_proto,"1"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1114 | break; |
| 1115 | case QSER_APN_AUTH_PROTO_CHAP: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1116 | strcpy(out_proto,"2"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1117 | break; |
| 1118 | case QSER_APN_AUTH_PROTO_PAP_CHAP: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1119 | strcpy(out_proto,"3"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1120 | break; |
| 1121 | default: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1122 | strcpy(out_proto,"NULL"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1123 | break; |
| 1124 | } |
| 1125 | return ; |
| 1126 | } |
| 1127 | |
| 1128 | int data_call_handle_get(const char profile_idx,int *handle) |
| 1129 | { |
| 1130 | int num = LYNQ_APN_CHANNEL_MAX; |
| 1131 | int table_num = 0; |
| 1132 | lynq_apn_info **apn_table = NULL; |
| 1133 | qser_apn_info_s apn; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1134 | int ret = 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1135 | apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX); |
| 1136 | if (NULL == apn_table) |
| 1137 | { |
| 1138 | LYERRLOG("malloc apn_table fail "); |
| 1139 | return RESULT_ERROR; |
| 1140 | } |
| 1141 | for(int i =0;i<10;i++) |
| 1142 | { |
| 1143 | apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info)); |
| 1144 | if (apn_table[i]==NULL) |
| 1145 | { |
| 1146 | for (int n=0;n<i;n++) |
| 1147 | { |
| 1148 | free(apn_table[n]); |
| 1149 | } |
| 1150 | return RESULT_ERROR; |
| 1151 | } |
| 1152 | memset(apn_table[i],0,sizeof(lynq_apn_info)); |
| 1153 | } |
| 1154 | lynq_get_apn_table(&table_num,apn_table); |
| 1155 | memset(&apn,0,sizeof(qser_apn_info_s)); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1156 | ret = apn_db_query(profile_idx,&apn); |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1157 | if (ret < 0) |
| 1158 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1159 | LYERRLOG("apn_db_query error"); |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1160 | return ret; |
| 1161 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1162 | for (int j = 0;j < table_num;j++) |
| 1163 | { |
| 1164 | if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0) |
| 1165 | { |
| 1166 | *handle = apn_table[j]->index; |
| 1167 | LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle); |
| 1168 | break; |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++) |
| 1173 | { |
| 1174 | if (apn_table[i]!=NULL) |
| 1175 | { |
| 1176 | free(apn_table[i]); |
| 1177 | apn_table[i]=NULL; |
| 1178 | } |
| 1179 | } |
| 1180 | free(apn_table); |
| 1181 | apn_table=NULL; |
| 1182 | LYINFLOG("data_call_handle_get end"); |
| 1183 | return RESULT_OK; |
| 1184 | } |
| 1185 | |
| 1186 | void *thread_wait_cb_status(void) |
| 1187 | { |
| 1188 | int handle = -1; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1189 | int ret = 0; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1190 | int default_handle = LYNQ_APN_CHANNEL_MAX + 1; |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1191 | lynq_data_call_response_v11_t data_urc_info = {0}; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1192 | qser_data_call_state_s data_cb_state; |
| 1193 | while (s_qser_data_cb_thread_status) |
| 1194 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1195 | ret = lynq_wait_data_call_state_change(&handle); |
| 1196 | LYINFLOG("ret = %d, wait data call state change end!!!\n", ret); |
| 1197 | if(s_qser_data_cb_thread_status == 0) |
| 1198 | { |
| 1199 | return NULL; |
| 1200 | } |
| 1201 | else if(ret < 0) |
| 1202 | { |
| 1203 | continue; |
| 1204 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1205 | LYINFLOG("[thread_wait_cb_status]: handle = %d", handle); |
| 1206 | memset(&data_urc_info, 0, sizeof(data_urc_info)); |
| 1207 | memset(&data_cb_state, 0, sizeof(data_cb_state)); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1208 | lynq_get_data_call_list(&handle,&data_urc_info); |
| 1209 | /*compare paramter*/ |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1210 | //data_cb_state.profile_idx = (char)handle; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1211 | apn_db_handle_get_profile(handle, &data_cb_state.profile_idx); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1212 | LYINFLOG("[thread_wait_cb_status]: callback profile_idx is %d\n", data_cb_state.profile_idx); |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1213 | LYINFLOG("[thread_wait_cb_status]: status=%d, suggestedRetryTime=%d, cid=%d, active=%d, type=%s, ifname=%s, addresses=%s, dnses=%s, gateways=%s, pcscf=%s, mtu=%d\n", |
| 1214 | data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active, |
| 1215 | data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf, |
| 1216 | data_urc_info.mtu); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1217 | memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1); |
xf.li | 9e27f3d | 2023-11-30 00:43:13 -0800 | [diff] [blame] | 1218 | if ((strcmp(data_urc_info.type,"IPV4") == 0) || (strcmp(data_urc_info.type,"IP") == 0)) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1219 | { |
| 1220 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4; |
| 1221 | } |
| 1222 | else if (!strcmp(data_urc_info.type,"IPV6")) |
| 1223 | { |
| 1224 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6; |
| 1225 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1226 | else if (!strcmp(data_urc_info.type,"IPV4V6")) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1227 | { |
| 1228 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 1229 | } |
| 1230 | else |
| 1231 | { |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1232 | LYERRLOG("unknow data call type: %s", data_urc_info.type); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1235 | if (data_urc_info.active != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1236 | { |
| 1237 | data_cb_state.state = QSER_DATA_CALL_CONNECTED; |
| 1238 | } |
| 1239 | else |
| 1240 | { |
| 1241 | data_cb_state.state = QSER_DATA_CALL_DISCONNECTED; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1242 | ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1243 | if(ret != 0) |
| 1244 | { |
| 1245 | LYERRLOG("handle set error"); |
| 1246 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1247 | } |
| 1248 | if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4) |
| 1249 | { |
| 1250 | lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state); |
| 1251 | } |
| 1252 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6) |
| 1253 | { |
| 1254 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 1255 | } |
| 1256 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6) |
| 1257 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1258 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1259 | lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 1260 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1261 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1262 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1263 | } |
| 1264 | else |
| 1265 | { |
| 1266 | LYERRLOG("unknow ip_family"); |
| 1267 | continue; |
| 1268 | } |
| 1269 | if (s_data_call_cb != NULL) |
| 1270 | { |
| 1271 | s_data_call_cb(&data_cb_state); |
| 1272 | } |
| 1273 | } |
| 1274 | return NULL; |
| 1275 | } |
| 1276 | |
| 1277 | int qser_cb_pthread_create() |
| 1278 | { |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 1279 | pthread_attr_t attr; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1280 | int ret; |
| 1281 | s_qser_data_cb_thread_status = 1; |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 1282 | |
| 1283 | pthread_attr_init(&attr); |
| 1284 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 1285 | |
| 1286 | ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1287 | if (ret < 0) |
| 1288 | { |
| 1289 | LYERRLOG("pthread create fail"); |
| 1290 | s_qser_data_cb_thread_status = 0; |
| 1291 | return RESULT_ERROR; |
| 1292 | } |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 1293 | pthread_attr_destroy(&attr); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1294 | return RESULT_OK; |
| 1295 | } |
| 1296 | |
| 1297 | void qser_cb_pthread_cancel() |
| 1298 | { |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1299 | s_qser_data_cb_thread_status = 0; |
| 1300 | if (s_cb_tid != -1) |
| 1301 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1302 | lynq_release_wait_data_call(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1303 | } |
| 1304 | return; |
| 1305 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1306 | int qser_data_call_init(qser_data_call_evt_cb_t evt_cb) |
| 1307 | { |
| 1308 | int ret = 0; |
| 1309 | int utoken = 0; |
| 1310 | if (NULL == evt_cb) |
| 1311 | { |
| 1312 | LYERRLOG("init incoming paramters error"); |
| 1313 | return RESULT_ERROR; |
| 1314 | } |
xf.li | 09b46db | 2024-03-13 19:21:18 -0700 | [diff] [blame] | 1315 | if(g_lynq_qser_data_init_flag == 1) |
| 1316 | { |
| 1317 | LYERRLOG("init twice is not allowed"); |
| 1318 | return RESULT_ERROR; |
| 1319 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1320 | ret = lynq_init_data(utoken); |
| 1321 | if (ret != RESULT_OK) |
| 1322 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1323 | //qser_cb_pthread_cancel(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1324 | s_data_call_cb = NULL; |
| 1325 | return RESULT_ERROR; |
| 1326 | } |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1327 | qser_cb_pthread_create(); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1328 | ret = init_apn_db(); |
| 1329 | if(ret != RESULT_OK) |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 1330 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1331 | LYERRLOG("init apn db error"); |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 1332 | return RESULT_ERROR; |
| 1333 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1334 | |
| 1335 | ret = apn_db_handle_clean(); |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 1336 | if(ret != RESULT_OK) |
| 1337 | { |
| 1338 | LYERRLOG("clean handle error"); |
| 1339 | return RESULT_ERROR; |
| 1340 | } |
xf.li | 09b46db | 2024-03-13 19:21:18 -0700 | [diff] [blame] | 1341 | s_data_call_cb = evt_cb; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1342 | g_lynq_qser_data_init_flag = 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1343 | return RESULT_OK; |
| 1344 | } |
| 1345 | |
| 1346 | void qser_data_call_destroy(void) |
| 1347 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1348 | LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1349 | lynq_deinit_data(); |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1350 | qser_cb_pthread_cancel(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1351 | s_data_call_cb = NULL; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1352 | g_lynq_qser_data_init_flag = 0; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1353 | LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1354 | return ; |
| 1355 | } |
| 1356 | |
| 1357 | int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 1358 | { |
| 1359 | int ret = -1; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1360 | int error = -1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1361 | int handle = 0; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1362 | if(g_lynq_qser_data_init_flag == 0) |
| 1363 | { |
| 1364 | if(err != NULL) |
| 1365 | { |
| 1366 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1367 | } |
| 1368 | return LYNQ_E_NO_INIT; |
| 1369 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1370 | if (NULL == data_call || NULL == err) |
| 1371 | { |
| 1372 | LYERRLOG("call start incoming paramters error"); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1373 | if(err != NULL) |
| 1374 | { |
| 1375 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1376 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1377 | return ret; |
| 1378 | } |
| 1379 | if (data_call->profile_idx == 0) |
| 1380 | { |
| 1381 | ret = lynq_setup_data_call(&handle); |
| 1382 | } |
| 1383 | else |
| 1384 | { |
| 1385 | char pdptype[16]; |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1386 | char auth_proto[16]; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1387 | qser_apn_info_s apn_info; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1388 | LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx); |
| 1389 | ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info); |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1390 | if (ret != 0) |
| 1391 | { |
| 1392 | LYERRLOG("qser_apn_get error"); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1393 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1394 | return ret; |
| 1395 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1396 | judge_pdp_type(apn_info.pdp_type,pdptype); |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1397 | judge_authtype(apn_info.auth_proto,auth_proto); |
| 1398 | ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,auth_proto,pdptype,pdptype); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1399 | } |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1400 | if (ret != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1401 | { |
| 1402 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1403 | } |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1404 | else |
| 1405 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1406 | error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1407 | if(error != 0) |
| 1408 | { |
| 1409 | LYERRLOG("handle set error"); |
| 1410 | } |
| 1411 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1412 | return ret; |
| 1413 | } |
| 1414 | |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1415 | int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 1416 | { |
| 1417 | int ret = -1; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1418 | int error = -1; |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1419 | int handle = 0; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1420 | if(g_lynq_qser_data_init_flag == 0) |
| 1421 | { |
| 1422 | if(err != NULL) |
| 1423 | { |
| 1424 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1425 | } |
| 1426 | return LYNQ_E_NO_INIT; |
| 1427 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1428 | if (NULL == data_call || NULL == err) |
| 1429 | { |
| 1430 | LYERRLOG("call start incoming paramters error"); |
| 1431 | if(err != NULL) |
| 1432 | { |
| 1433 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1434 | } |
| 1435 | return ret; |
| 1436 | } |
| 1437 | if (data_call->profile_idx == 0) |
| 1438 | { |
| 1439 | ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL); |
| 1440 | } |
| 1441 | else |
| 1442 | { |
| 1443 | char pdptype[16]; |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1444 | char auth_proto[16]; |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1445 | qser_apn_info_s apn_info; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1446 | LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx); |
| 1447 | ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info); |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1448 | if (ret != 0) |
| 1449 | { |
| 1450 | LYERRLOG("qser_apn_get error"); |
| 1451 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1452 | return ret; |
| 1453 | } |
| 1454 | judge_pdp_type(apn_info.pdp_type,pdptype); |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1455 | judge_authtype(apn_info.auth_proto,auth_proto); |
| 1456 | ret = lynq_setup_data_call_sp_t106_async(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,auth_proto,pdptype,pdptype); |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1457 | } |
| 1458 | if (ret != 0) |
| 1459 | { |
| 1460 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1461 | } |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1462 | else |
| 1463 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1464 | error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1465 | if(error != 0) |
| 1466 | { |
| 1467 | LYERRLOG("handle set error"); |
| 1468 | } |
| 1469 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1470 | return ret; |
| 1471 | } |
| 1472 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1473 | int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err) |
| 1474 | { |
| 1475 | int ret = 0; |
| 1476 | int handle = -1; |
| 1477 | |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1478 | if(g_lynq_qser_data_init_flag == 0) |
| 1479 | { |
| 1480 | if(err != NULL) |
| 1481 | { |
| 1482 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1483 | } |
| 1484 | return LYNQ_E_NO_INIT; |
| 1485 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1486 | if (NULL == err) |
| 1487 | { |
| 1488 | LYERRLOG("call stop incoming paramters error"); |
| 1489 | return ret; |
| 1490 | } |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1491 | ret = data_call_handle_get(profile_idx,&handle); |
| 1492 | if(ret != 0) |
| 1493 | { |
| 1494 | LYERRLOG("datacall handle get error"); |
| 1495 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1496 | return ret; |
| 1497 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1498 | ret = lynq_deactive_data_call(&handle); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1499 | if (ret != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1500 | { |
| 1501 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1502 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1503 | } |
xy.he | e2daacc | 2023-09-18 00:57:51 -0700 | [diff] [blame] | 1504 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1505 | } |
| 1506 | int qser_data_call_info_get(char profile_idx,qser_data_call_ip_family_e ip_family,qser_data_call_info_s *info,qser_data_call_error_e *err) |
| 1507 | { |
| 1508 | int ret = 0; |
| 1509 | int handle = -1; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1510 | if(g_lynq_qser_data_init_flag == 0) |
| 1511 | { |
| 1512 | if(err != NULL) |
| 1513 | { |
| 1514 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1515 | } |
| 1516 | return LYNQ_E_NO_INIT; |
| 1517 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1518 | lynq_data_call_response_v11_t data_call_info; |
| 1519 | data_call_handle_get(profile_idx,&handle); |
| 1520 | ret = lynq_get_data_call_list(&handle,&data_call_info); |
| 1521 | if (ret == 0) |
| 1522 | { |
| 1523 | info->profile_idx = profile_idx; |
| 1524 | info->ip_family = ip_family; |
xf.li | 157f7e9 | 2023-10-19 23:22:46 -0700 | [diff] [blame] | 1525 | if ((strncmp(data_call_info.type,"IPV4", strlen("IPV4") + 1) == 0) || (strncmp(data_call_info.type,"IP", strlen("IP") + 1) == 0)) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1526 | { |
xf.li | 0400b38 | 2024-06-05 19:20:36 -0700 | [diff] [blame] | 1527 | info->ip_family = QSER_DATA_CALL_TYPE_IPV4; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1528 | strcpy(info->v4.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1529 | datacall_ipv4_status_judge(data_call_info.active,info); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1530 | LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 1531 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
| 1532 | } |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1533 | else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1534 | { |
xf.li | 0400b38 | 2024-06-05 19:20:36 -0700 | [diff] [blame] | 1535 | info->ip_family = QSER_DATA_CALL_TYPE_IPV6; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1536 | strcpy(info->v6.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1537 | datacall_ipv6_status_judge(data_call_info.active,info); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1538 | LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 1539 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
| 1540 | } |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1541 | else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1542 | { |
xf.li | 0400b38 | 2024-06-05 19:20:36 -0700 | [diff] [blame] | 1543 | info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1544 | strcpy(info->v4.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1545 | datacall_ipv4_status_judge(data_call_info.active,info); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1546 | LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1547 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1548 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1549 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1550 | strcpy(info->v6.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1551 | datacall_ipv6_status_judge(data_call_info.active,info); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1552 | LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1553 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1554 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1555 | #endif |
| 1556 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1557 | lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info); |
| 1558 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1559 | } |
| 1560 | else |
| 1561 | { |
| 1562 | LYERRLOG("useless qser_data_call_ip_family_e"); |
| 1563 | } |
| 1564 | } |
| 1565 | return ret; |
| 1566 | } |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1567 | int check_pdp_type(qser_apn_pdp_type_e pdp_type) |
| 1568 | { |
| 1569 | switch (pdp_type) |
| 1570 | { |
| 1571 | case QSER_APN_PDP_TYPE_IPV4: |
| 1572 | case QSER_APN_PDP_TYPE_PPP: |
| 1573 | case QSER_APN_PDP_TYPE_IPV6: |
| 1574 | case QSER_APN_PDP_TYPE_IPV4V6: |
| 1575 | return 0; |
| 1576 | default: |
| 1577 | return -1; |
| 1578 | } |
| 1579 | } |
| 1580 | int check_auth_proto(qser_apn_auth_proto_e auth_proto) |
| 1581 | { |
| 1582 | switch (auth_proto) |
| 1583 | { |
| 1584 | case QSER_APN_AUTH_PROTO_DEFAULT: |
| 1585 | case QSER_APN_AUTH_PROTO_NONE: |
| 1586 | case QSER_APN_AUTH_PROTO_PAP: |
| 1587 | case QSER_APN_AUTH_PROTO_CHAP: |
| 1588 | case QSER_APN_AUTH_PROTO_PAP_CHAP: |
| 1589 | return 0; |
| 1590 | default: |
| 1591 | return -1; |
| 1592 | } |
| 1593 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1594 | int qser_apn_set(qser_apn_info_s *apn) |
| 1595 | { |
| 1596 | int ret = 0; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1597 | int handle = -1; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1598 | if(g_lynq_qser_data_init_flag == 0) |
| 1599 | { |
| 1600 | return LYNQ_E_NO_INIT; |
| 1601 | } |
xf.li | 4b18fa6 | 2023-12-19 19:38:10 -0800 | [diff] [blame] | 1602 | if (NULL == apn || apn->profile_idx == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1603 | { |
| 1604 | LYERRLOG("apn set incoming paramters error"); |
| 1605 | return RESULT_ERROR; |
| 1606 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1607 | ret = apn_db_handle_get(apn->profile_idx, &handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1608 | if(ret != 0) |
| 1609 | { |
| 1610 | LYERRLOG("handle set error"); |
| 1611 | } |
| 1612 | if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX) |
| 1613 | { |
| 1614 | LYERRLOG("It has setup datacall"); |
| 1615 | return RESULT_ERROR; |
| 1616 | } |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1617 | |
| 1618 | if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE) |
| 1619 | { |
| 1620 | LYERRLOG("apn_name out of range\n"); |
| 1621 | return RESULT_ERROR; |
| 1622 | } |
| 1623 | if(strlen(apn->username) > QSER_APN_USERNAME_SIZE) |
| 1624 | { |
| 1625 | LYERRLOG("username out of range\n"); |
| 1626 | return RESULT_ERROR; |
| 1627 | } |
| 1628 | if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE) |
| 1629 | { |
| 1630 | LYERRLOG("password out of range\n"); |
| 1631 | return RESULT_ERROR; |
| 1632 | } |
| 1633 | if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE) |
| 1634 | { |
| 1635 | LYERRLOG("apn_type out of range\n"); |
| 1636 | return RESULT_ERROR; |
| 1637 | } |
| 1638 | if(check_pdp_type(apn->pdp_type) != 0) |
| 1639 | { |
| 1640 | LYERRLOG("pdp_type out of range\n"); |
| 1641 | return RESULT_ERROR; |
| 1642 | } |
| 1643 | if(check_auth_proto(apn->auth_proto) != 0) |
| 1644 | { |
| 1645 | LYERRLOG("auth_proto out of range\n"); |
| 1646 | return RESULT_ERROR; |
| 1647 | } |
| 1648 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1649 | ret = apn_db_modify(apn); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1650 | if (ret < 0) |
| 1651 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1652 | LYERRLOG("apn_db_modify error"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1653 | return ret; |
| 1654 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1655 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1656 | int apn_id = 0; |
| 1657 | char tmp_id[12]; |
| 1658 | char *outinfo = NULL; |
| 1659 | char normalprotocol[16]; |
| 1660 | char authtype[32]; |
| 1661 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1662 | bzero(tmp_id,12); |
| 1663 | bzero(outinfo,512); |
| 1664 | apn_id = apn->profile_idx + apndb_offset; |
| 1665 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1666 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 1667 | judge_authtype(apn->auth_proto,authtype); |
| 1668 | lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 1669 | LYINFLOG("[output]:%s",outinfo); |
| 1670 | free(outinfo); |
| 1671 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1672 | #endif |
| 1673 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn) |
| 1677 | { |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1678 | if(g_lynq_qser_data_init_flag == 0) |
| 1679 | { |
| 1680 | return LYNQ_E_NO_INIT; |
| 1681 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1682 | if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1683 | { |
| 1684 | LYERRLOG("apn get incoming paramters error"); |
| 1685 | return RESULT_ERROR; |
| 1686 | } |
| 1687 | int ret = 0; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1688 | ret = apn_db_query(profile_idx,apn); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1689 | if (ret < 0) |
| 1690 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1691 | LYERRLOG("apn_db_query error"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1692 | return ret; |
| 1693 | } |
| 1694 | return ret; |
| 1695 | } |
| 1696 | |
| 1697 | int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx) |
| 1698 | { |
| 1699 | int ret = 0; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1700 | |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1701 | if(g_lynq_qser_data_init_flag == 0) |
| 1702 | { |
| 1703 | return LYNQ_E_NO_INIT; |
| 1704 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1705 | if (NULL == apn || NULL == profile_idx) |
| 1706 | { |
| 1707 | LYERRLOG("apn add incoming paramters error"); |
| 1708 | return RESULT_ERROR; |
| 1709 | } |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1710 | |
| 1711 | if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE) |
| 1712 | { |
| 1713 | LYERRLOG("apn_name out of range\n"); |
| 1714 | return RESULT_ERROR; |
| 1715 | } |
| 1716 | if(strlen(apn->username) > QSER_APN_USERNAME_SIZE) |
| 1717 | { |
| 1718 | LYERRLOG("username out of range\n"); |
| 1719 | return RESULT_ERROR; |
| 1720 | } |
| 1721 | if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE) |
| 1722 | { |
| 1723 | LYERRLOG("password out of range\n"); |
| 1724 | return RESULT_ERROR; |
| 1725 | } |
| 1726 | if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE) |
| 1727 | { |
| 1728 | LYERRLOG("apn_type out of range\n"); |
| 1729 | return RESULT_ERROR; |
| 1730 | } |
| 1731 | if(check_pdp_type(apn->pdp_type) != 0) |
| 1732 | { |
| 1733 | LYERRLOG("pdp_type out of range\n"); |
| 1734 | return RESULT_ERROR; |
| 1735 | } |
| 1736 | if(check_auth_proto(apn->auth_proto) != 0) |
| 1737 | { |
| 1738 | LYERRLOG("auth_proto out of range\n"); |
| 1739 | return RESULT_ERROR; |
| 1740 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1741 | |
| 1742 | *profile_idx = 0; |
| 1743 | *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH); |
| 1744 | LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx); |
| 1745 | if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1746 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1747 | LYINFLOG("[%s] apn full is false\n",__FUNCTION__); |
| 1748 | ret = apn_db_add((int)*profile_idx, apn); |
| 1749 | if (ret != 0) |
| 1750 | { |
| 1751 | LYERRLOG("apn_db_add error"); |
| 1752 | return RESULT_ERROR; |
| 1753 | } |
| 1754 | else |
| 1755 | { |
| 1756 | return RESULT_OK; |
| 1757 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1758 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1759 | LYERRLOG("apn storage space is full!!!"); |
| 1760 | return RESULT_ERROR; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1761 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1762 | int apn_id = 0; |
| 1763 | char tmp_id[12]; |
| 1764 | char *outinfo = NULL; |
| 1765 | char normalprotocol[16]; |
| 1766 | char authtype[32]; |
| 1767 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1768 | bzero(tmp_id,12); |
| 1769 | bzero(outinfo,512); |
| 1770 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1771 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 1772 | judge_authtype(apn->auth_proto,authtype); |
| 1773 | lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 1774 | LYINFLOG("[output]:%s",outinfo); |
| 1775 | free(outinfo); |
| 1776 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1777 | #endif |
| 1778 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
| 1781 | int qser_apn_del(unsigned char profile_idx) |
| 1782 | { |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1783 | int ret = 0; |
| 1784 | int handle = -1; |
| 1785 | |
| 1786 | LYINFLOG("[%s] entry\n",__FUNCTION__); |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1787 | if(g_lynq_qser_data_init_flag == 0) |
| 1788 | { |
| 1789 | return LYNQ_E_NO_INIT; |
| 1790 | } |
xf.li | 4b18fa6 | 2023-12-19 19:38:10 -0800 | [diff] [blame] | 1791 | if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1792 | { |
| 1793 | LYERRLOG("apn del incoming paramters error"); |
xf.li | 4b18fa6 | 2023-12-19 19:38:10 -0800 | [diff] [blame] | 1794 | return RESULT_ERROR; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1795 | } |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame^] | 1796 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1797 | ret = apn_db_handle_get(profile_idx, &handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1798 | if(ret != 0) |
| 1799 | { |
| 1800 | LYERRLOG("handle set error"); |
| 1801 | } |
| 1802 | if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX) |
| 1803 | { |
| 1804 | LYERRLOG("It has setup datacall"); |
| 1805 | return RESULT_ERROR; |
| 1806 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1807 | ret = apn_db_delete(profile_idx); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1808 | if (ret < 0) |
| 1809 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1810 | LYERRLOG("apn_db_delete error"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1811 | return ret; |
| 1812 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1813 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1814 | int apn_id = 0; |
| 1815 | char tmp_id[12]; |
| 1816 | char *outinfo = NULL; |
| 1817 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1818 | bzero(tmp_id,12); |
| 1819 | bzero(outinfo,512); |
| 1820 | apn_id = profile_idx+apndb_offset; |
| 1821 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1822 | lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo); |
| 1823 | LYINFLOG("[output]:%s",outinfo); |
| 1824 | free(outinfo); |
| 1825 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1826 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1827 | return ret; |
| 1828 | } |
| 1829 | |
| 1830 | int qser_apn_get_list(qser_apn_info_list_s *apn_list) |
| 1831 | { |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1832 | if(g_lynq_qser_data_init_flag == 0) |
| 1833 | { |
| 1834 | return LYNQ_E_NO_INIT; |
| 1835 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1836 | if (NULL == apn_list) |
| 1837 | { |
| 1838 | LYERRLOG("apn_list incoming paramters error"); |
| 1839 | return RESULT_ERROR; |
| 1840 | } |
| 1841 | int ret = 0; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1842 | ret = apn_db_query_list(apn_list); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1843 | if (ret < 0) |
| 1844 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1845 | LYERRLOG("apn_db_query_list error"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1846 | return ret; |
| 1847 | } |
| 1848 | return ret; |
xf.li | 3f891cb | 2023-08-23 23:11:24 -0700 | [diff] [blame] | 1849 | } |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 1850 | |
| 1851 | DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA) |
| 1852 | |