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