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