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