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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 88 | LYDBGLOG("ipv4 addresses = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 96 | LYDBGLOG("ipv4 pri_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 97 | inet_aton(tmp_char,&(data_res->v4.pri_dns)); |
| 98 | } |
| 99 | tmp_char = strsep(&dnses, dnses_separator); |
| 100 | if(tmp_char != NULL) |
| 101 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 102 | LYDBGLOG("ipv4 sec_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 132 | LYDBGLOG("ipv6 addresses = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 139 | LYDBGLOG("ipv6 pri_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 145 | LYDBGLOG("ipv6 sec_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 178 | LYDBGLOG("ipv4 addresses = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 179 | inet_aton(tmp_char,&(data_res->v4.ip)); |
| 180 | } |
| 181 | tmp_char = strsep(&addresses, addresses_separator); |
| 182 | if(tmp_char != NULL) |
| 183 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 184 | LYDBGLOG("ipv6 addresses = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 191 | LYDBGLOG("ipv4 pri_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 192 | inet_aton(tmp_char,&(data_res->v4.pri_dns)); |
| 193 | } |
| 194 | tmp_char = strsep(&dnses, dnses_separator); |
| 195 | if(tmp_char != NULL) |
| 196 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 197 | LYDBGLOG("ipv4 sec_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 198 | inet_aton(tmp_char, &(data_res->v4.sec_dns)); |
| 199 | } |
| 200 | tmp_char = strsep(&dnses, dnses_separator); |
| 201 | if(tmp_char != NULL) |
| 202 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 203 | LYDBGLOG("ipv6 pri_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 209 | LYDBGLOG("ipv6 sec_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 216 | LYDBGLOG("v4.ip=%s", inet_ntoa(data_res->v4.ip)); |
| 217 | LYDBGLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.pri_dns)); |
| 218 | LYDBGLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.sec_dns)); |
xf.li | 03baf1f | 2023-12-19 21:30:38 -0800 | [diff] [blame] | 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)); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 224 | LYDBGLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n" |
xf.li | 03baf1f | 2023-12-19 21:30:38 -0800 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 244 | LYDBGLOG("ipv4 addresses = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 251 | LYDBGLOG("ipv4 pri_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 257 | LYDBGLOG("ipv4 sec_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 258 | inet_aton(tmp_char, &(data_res->v4.addr.sec_dns)); |
| 259 | } |
| 260 | //get gateway |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 261 | LYDBGLOG("ipv4 gateways = %s", libdata->gateways); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 262 | inet_aton(libdata->gateways,&(data_res->v4.addr.gateway)); |
| 263 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 264 | LYDBGLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip)); |
| 265 | LYDBGLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns)); |
| 266 | LYDBGLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 297 | LYDBGLOG("ipv6 addresses = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 304 | LYDBGLOG("ipv6 pri_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 310 | LYDBGLOG("ipv6 sec_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 347 | LYDBGLOG("ipv4 addresses = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 348 | inet_aton(tmp_char,&(data_res->v4.addr.ip)); |
| 349 | } |
| 350 | tmp_char = strsep(&addresses, addresses_separator); |
| 351 | if(tmp_char != NULL) |
| 352 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 353 | LYDBGLOG("ipv6 addresses = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 360 | LYDBGLOG("ipv4 pri_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 366 | LYDBGLOG("ipv4 sec_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 372 | LYDBGLOG("ipv6 pri_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 378 | LYDBGLOG("ipv6 sec_dns = %s", tmp_char); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 385 | LYDBGLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip)); |
| 386 | LYDBGLOG("ipv4 gateways = %s", inet_ntoa(data_res->v4.addr.gateway)); |
| 387 | LYDBGLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns)); |
| 388 | LYDBGLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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)); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 394 | LYDBGLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n" |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 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++){ |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 451 | LYDBGLOG("[%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 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 473 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 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]); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 497 | LYDBGLOG("apn_indexs[%d] is %d", atoi(argv[0]), apn_indexs[atoi(argv[0])]); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 498 | |
| 499 | for(i=0; i<argc; i++){ |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 500 | LYDBGLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL"); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 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 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 543 | LYDBGLOG("index = apn_index\n"); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 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 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 575 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 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++){ |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 603 | LYDBGLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL"); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 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 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 629 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 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 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 705 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 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 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 726 | LYDBGLOG("Table LYNQAPN created successfully\n"); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 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++){ |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 739 | LYDBGLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL"); |
xf.li | 1bbfc7d | 2024-07-15 23:50:41 -0700 | [diff] [blame] | 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 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 761 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | 1bbfc7d | 2024-07-15 23:50:41 -0700 | [diff] [blame] | 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 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 774 | LYDBGLOG("Table LYNQAPN check successfully\n"); |
xf.li | 1bbfc7d | 2024-07-15 23:50:41 -0700 | [diff] [blame] | 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 | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 793 | int ret = 0; |
xf.li | 1bbfc7d | 2024-07-15 23:50:41 -0700 | [diff] [blame] | 794 | int check_ret=0; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 795 | int table_ret=0; |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 796 | |
| 797 | pthread_mutex_init(&s_qser_data_database_mutex, NULL); |
| 798 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 799 | db_ret = create_apn_db(APN_DB_PATH); |
| 800 | if(db_ret==APN_DB_CREATE) |
| 801 | { |
| 802 | table_ret = create_apn_table(APN_DB_PATH); |
| 803 | if(table_ret!=0) |
| 804 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 805 | LYERRLOG("ret = %d, create apn table fail!!!", table_ret); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 806 | return RESULT_ERROR; |
| 807 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 808 | ret = apn_db_add(0, &default_apn); |
| 809 | if(ret != 0) |
| 810 | { |
| 811 | LYERRLOG("ret = %d, apn add fail!!!", ret); |
| 812 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 813 | } |
| 814 | else if(db_ret==APN_DB_READED) |
| 815 | { |
xf.li | 1bbfc7d | 2024-07-15 23:50:41 -0700 | [diff] [blame] | 816 | LYINFLOG("[%s] apn db has be build!!!",__FUNCTION__); |
| 817 | check_ret = check_apn_table(APN_DB_PATH); |
| 818 | if(check_ret == APN_TABLE_NEED_CREATE) |
| 819 | { |
| 820 | table_ret = create_apn_table(APN_DB_PATH); |
| 821 | if(table_ret!=0) |
| 822 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 823 | LYERRLOG("ret = %d, create apn table fail!!!", table_ret); |
xf.li | 1bbfc7d | 2024-07-15 23:50:41 -0700 | [diff] [blame] | 824 | return 1; |
| 825 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 826 | ret = apn_db_add(0, &default_apn); |
| 827 | if(ret != 0) |
| 828 | { |
| 829 | LYERRLOG("ret = %d, apn add fail!!!", ret); |
| 830 | } |
xf.li | 1bbfc7d | 2024-07-15 23:50:41 -0700 | [diff] [blame] | 831 | } |
| 832 | else if(check_ret == APN_TABLE_CREATE) |
| 833 | { |
| 834 | LYINFLOG("Table LYNQAPN has created"); |
| 835 | } |
| 836 | else |
| 837 | { |
| 838 | LYERRLOG("check table fail!!!, ret = %d", check_ret); |
| 839 | } |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 840 | } |
| 841 | else |
| 842 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 843 | LYERRLOG("init apn db fail!!!"); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 844 | } |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 845 | return RESULT_OK; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 846 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 847 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 848 | static int apn_db_handle_clean() |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 849 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 850 | char *zErrMsg = 0; |
| 851 | int rc; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 852 | int default_handle = LYNQ_APN_CHANNEL_MAX + 1; |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 853 | char sql[128]={0}; |
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 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 856 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 857 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 858 | if( rc ) |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 859 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 860 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 861 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 862 | return LYNQ_E_APN_DB_FAIL; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 863 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 864 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 865 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 866 | /* Create SQL statement */ |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 867 | sprintf(sql,"UPDATE LYNQAPN SET HANDLE=%d", default_handle); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 868 | LYINFLOG("sql: %s\n", sql); |
| 869 | /* Execute SQL statement */ |
| 870 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
| 871 | if( rc != SQLITE_OK ) |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 872 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 873 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 874 | sqlite3_free(zErrMsg); |
| 875 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 876 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 877 | return LYNQ_E_APN_DB_FAIL; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 878 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 879 | LYDBGLOG("clean apn table successfully\n"); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 880 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 881 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 882 | return RESULT_OK; |
| 883 | } |
| 884 | |
| 885 | static int find_unuse_apn_index(char *path) |
| 886 | { |
| 887 | char *zErrMsg = 0; |
| 888 | int rc; |
| 889 | int count =1; |
| 890 | bool apn_usable = false; |
| 891 | char *sql; |
| 892 | |
| 893 | memset(apn_indexs,0,sizeof(apn_indexs)); |
| 894 | next_index = 0; |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 895 | LYDBGLOG("index = %p",apn_indexs); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 896 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 897 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 898 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 899 | if( rc ) |
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 | LYERRLOG("Can't open database: %s\n", sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 902 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 903 | return -1; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 904 | } |
| 905 | else |
| 906 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 907 | LYDBGLOG("Opened database successfully\n"); |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 908 | } |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 909 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 910 | /* Create SQL statement */ |
| 911 | sql = "SELECT ID from LYNQAPN"; |
| 912 | /* Execute SQL statement */ |
| 913 | rc = sqlite3_exec(apnDb, sql, lynq_apn_callback,NULL, &zErrMsg); |
| 914 | if( rc != SQLITE_OK ) |
| 915 | { |
| 916 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 917 | sqlite3_free(zErrMsg); |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 918 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 919 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 920 | return -1; |
| 921 | } |
| 922 | else |
| 923 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 924 | LYDBGLOG("Operation done successfully\n"); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 925 | } |
| 926 | //indexs = temp_index; |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 927 | LYDBGLOG("index = %p",apn_indexs); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 928 | for(count;count<=QSER_APN_MAX_LIST;count++) |
| 929 | { |
| 930 | //if(apn_indexs[count-1]!=count) |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 931 | LYDBGLOG("apn_indexs[count] = %d, count = %d\n", apn_indexs[count], count); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 932 | if(apn_indexs[count]!=count) |
| 933 | { |
| 934 | //apn_usable=true; |
| 935 | break; |
| 936 | } |
| 937 | } |
| 938 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 939 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 940 | LYDBGLOG("count is %d\n", count); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 941 | return count; |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 942 | } |
| 943 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 944 | 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] | 945 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 946 | char *zErrMsg = 0; |
| 947 | int rc; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 948 | int default_handle = LYNQ_APN_CHANNEL_MAX + 1; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 949 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 950 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 951 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 952 | if( rc ) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 953 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 954 | LYERRLOG("[%s] Can't open database: %s",__FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 955 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 956 | return 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 957 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 958 | LYDBGLOG("[%s] Opened database successfully",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 959 | /* Create SQL statement */ |
| 960 | /* Execute SQL statement */ |
| 961 | LYINFLOG("the profile id is %d\n", profile_id); |
| 962 | 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); |
| 963 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 964 | sqlite3_free(sql); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 965 | if( rc != SQLITE_OK ) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 966 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 967 | LYERRLOG( "SQL error: %s", zErrMsg); |
| 968 | sqlite3_free(zErrMsg); |
| 969 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 970 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 971 | return 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 972 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 973 | LYDBGLOG("write apn to apn db successfully"); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 974 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 975 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 976 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 977 | } |
| 978 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 979 | static int apn_db_delete(unsigned char profile_idx) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 980 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 981 | char *zErrMsg = 0; |
| 982 | int rc; |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 983 | char sql[128]={0}; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 984 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 985 | if(!lynq_check_index(profile_idx)) |
| 986 | { |
| 987 | return LYNQ_E_APN_DB_FAIL; |
| 988 | } |
| 989 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 990 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 991 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 992 | if( rc ) |
| 993 | { |
| 994 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 995 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 996 | return LYNQ_E_APN_DB_FAIL; |
| 997 | } |
| 998 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 999 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1000 | /* Create SQL statement */ |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 1001 | sprintf(sql,"DELETE from LYNQAPN WHERE ID=%d",(int)profile_idx); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1002 | LYINFLOG("sql: %s\n", sql); |
| 1003 | /* Execute SQL statement */ |
| 1004 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
| 1005 | if( rc != SQLITE_OK ) |
| 1006 | { |
| 1007 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 1008 | sqlite3_free(zErrMsg); |
| 1009 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1010 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1011 | return LYNQ_E_APN_DB_FAIL; |
| 1012 | } |
| 1013 | LYINFLOG("delete apn %d successfully\n", profile_idx); |
| 1014 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1015 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1016 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1019 | static int apn_db_modify(qser_apn_info_s *apn) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1020 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1021 | char *zErrMsg = 0; |
| 1022 | int rc; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1023 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1024 | if(!lynq_check_index(apn->profile_idx)) |
| 1025 | { |
| 1026 | return LYNQ_E_APN_DB_FAIL; |
| 1027 | } |
| 1028 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1029 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1030 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 1031 | if( rc ) |
| 1032 | { |
| 1033 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1034 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1035 | return LYNQ_E_APN_DB_FAIL; |
| 1036 | } |
| 1037 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1038 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1039 | /* Create SQL statement */ |
| 1040 | 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); |
| 1041 | LYINFLOG("sql: %s\n", sql); |
| 1042 | /* Execute SQL statement */ |
| 1043 | rc = sqlite3_exec(apnDb, sql, NULL, NULL, &zErrMsg); |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 1044 | sqlite3_free(sql); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1045 | if( rc != SQLITE_OK ) |
| 1046 | { |
| 1047 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 1048 | sqlite3_free(zErrMsg); |
| 1049 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1050 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1051 | return LYNQ_E_APN_DB_FAIL; |
| 1052 | } |
| 1053 | LYINFLOG("set apn %d successfully\n",apn->profile_idx); |
| 1054 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1055 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1056 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1059 | 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] | 1060 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1061 | if(data==NULL) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1062 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1063 | return 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1064 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1065 | qser_apn_info_s* temp = (qser_apn_info_s *)data; |
| 1066 | for(int i=0; i<argc; i++){ |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1067 | LYDBGLOG("[%s]%s = %s", __FUNCTION__,azColName[i], argv[i] ? argv[i] : "NULL"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1068 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1069 | temp->profile_idx = atoi(argv[0]); |
| 1070 | temp->pdp_type = atoi(argv[1]); |
| 1071 | temp->auth_proto = atoi(argv[2]); |
| 1072 | memcpy(temp->apn_name,argv[3],QSER_APN_NAME_SIZE); |
| 1073 | memcpy(temp->username,argv[4],QSER_APN_USERNAME_SIZE); |
| 1074 | memcpy(temp->password,argv[5],QSER_APN_PASSWORD_SIZE); |
| 1075 | memcpy(temp->apn_type,argv[6],QSER_APN_NAME_SIZE); |
| 1076 | LYINFLOG("lynq_apn_db_query_cb: profile_idx is %d", atoi(argv[0])); |
| 1077 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1078 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1079 | 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] | 1080 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1081 | char *zErrMsg = 0; |
| 1082 | int rc; |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 1083 | char sql[128]={0}; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1084 | |
| 1085 | if(!lynq_check_index(profile_idx)) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1086 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1087 | return LYNQ_E_APN_DB_FAIL; |
| 1088 | } |
| 1089 | /* Open database */ |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1090 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1091 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 1092 | if( rc ) |
| 1093 | { |
| 1094 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1095 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1096 | return LYNQ_E_APN_DB_FAIL; |
| 1097 | } |
| 1098 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1099 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1100 | /* Create SQL statement */ |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 1101 | sprintf(sql,"SELECT * from LYNQAPN WHERE ID=%d", (int)profile_idx); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1102 | LYINFLOG("sql: %s\n", sql); |
| 1103 | /* Execute SQL statement */ |
| 1104 | rc = sqlite3_exec(apnDb, sql, lynq_apn_db_query_cb, (qser_apn_info_s *)apn, &zErrMsg); |
| 1105 | if( rc != SQLITE_OK ) |
| 1106 | { |
| 1107 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 1108 | sqlite3_free(zErrMsg); |
| 1109 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1110 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1111 | return LYNQ_E_APN_DB_FAIL; |
| 1112 | } |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1113 | LYDBGLOG("set apn %d successfully\n",apn->profile_idx); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1114 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1115 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1116 | return 0; |
| 1117 | } |
| 1118 | static int apn_db_query_list_cb(void *data, int argc, char **argv, char **azColName) |
| 1119 | { |
| 1120 | int i; |
| 1121 | |
| 1122 | //apn_count++; |
| 1123 | |
| 1124 | qser_apn_info_list_s* temp = (qser_apn_info_list_s *)data; |
| 1125 | for(i=0; i<argc; i++){ |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1126 | LYDBGLOG("%s = %s", azColName[i], argv[i] ? argv[i] : "NULL"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1127 | } |
| 1128 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1129 | temp->apn[temp->cnt].profile_idx = atoi(argv[0]); |
| 1130 | temp->apn[temp->cnt].pdp_type = atoi(argv[1]); |
| 1131 | temp->apn[temp->cnt].auth_proto = atoi(argv[2]); |
| 1132 | memcpy(temp->apn[temp->cnt].apn_name,argv[3],QSER_APN_NAME_SIZE); |
| 1133 | memcpy(temp->apn[temp->cnt].username,argv[4],QSER_APN_USERNAME_SIZE); |
| 1134 | memcpy(temp->apn[temp->cnt].password,argv[5],QSER_APN_PASSWORD_SIZE); |
| 1135 | memcpy(temp->apn[temp->cnt].apn_type,argv[6],QSER_APN_NAME_SIZE); |
| 1136 | temp->cnt++; |
| 1137 | return 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1138 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1139 | static int apn_db_query_list(qser_apn_info_list_s *apn_list) |
| 1140 | { |
| 1141 | char *zErrMsg = 0; |
| 1142 | int rc; |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 1143 | char sql[128]={0}; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1144 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1145 | /* Open database */ |
| 1146 | apn_count = 0; |
| 1147 | apn_list->cnt = 0; |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1148 | pthread_mutex_lock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1149 | rc = sqlite3_open(APN_DB_PATH, &apnDb); |
| 1150 | if( rc ) |
| 1151 | { |
| 1152 | LYERRLOG("[%s] Can't open database: %s\n", __FUNCTION__,sqlite3_errmsg(apnDb)); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1153 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1154 | return LYNQ_E_APN_DB_FAIL; |
| 1155 | } |
| 1156 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1157 | LYDBGLOG("[%s] Opened database successfully\n",__FUNCTION__); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1158 | /* Create SQL statement */ |
xf.li | ff41520 | 2024-09-19 23:08:09 -0700 | [diff] [blame] | 1159 | sprintf(sql,"SELECT * from LYNQAPN"); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1160 | LYINFLOG("sql: %s\n", sql); |
| 1161 | /* Execute SQL statement */ |
| 1162 | rc = sqlite3_exec(apnDb, sql, apn_db_query_list_cb, (qser_apn_info_list_s *)apn_list, &zErrMsg); |
| 1163 | if( rc != SQLITE_OK ) |
| 1164 | { |
| 1165 | LYERRLOG("SQL error: %s\n", zErrMsg); |
| 1166 | sqlite3_free(zErrMsg); |
| 1167 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1168 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1169 | return LYNQ_E_APN_DB_FAIL; |
| 1170 | } |
| 1171 | sqlite3_close(apnDb); |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1172 | pthread_mutex_unlock(&s_qser_data_database_mutex); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
| 1175 | // **************apn DB end**************************** |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1176 | void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type) |
| 1177 | { |
| 1178 | switch (pdp_type) |
| 1179 | { |
| 1180 | case QSER_APN_PDP_TYPE_IPV4: |
xf.li | 9e27f3d | 2023-11-30 00:43:13 -0800 | [diff] [blame] | 1181 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1182 | strcpy(out_pdp_type,"IP"); |
| 1183 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1184 | strcpy(out_pdp_type,"IPV4"); |
xf.li | 9e27f3d | 2023-11-30 00:43:13 -0800 | [diff] [blame] | 1185 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1186 | break; |
| 1187 | case QSER_APN_PDP_TYPE_PPP: |
| 1188 | strcpy(out_pdp_type,"PPP"); |
| 1189 | break; |
| 1190 | case QSER_APN_PDP_TYPE_IPV6: |
| 1191 | strcpy(out_pdp_type,"IPV6"); |
| 1192 | break; |
| 1193 | case QSER_APN_PDP_TYPE_IPV4V6: |
| 1194 | strcpy(out_pdp_type,"IPV4V6"); |
| 1195 | break; |
| 1196 | default: |
| 1197 | strcpy(out_pdp_type,"NULL"); |
| 1198 | break; |
| 1199 | } |
| 1200 | return; |
| 1201 | } |
| 1202 | void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto) |
| 1203 | { |
| 1204 | switch (auth_proto) |
| 1205 | { |
| 1206 | case QSER_APN_AUTH_PROTO_DEFAULT: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1207 | strcpy(out_proto,"0"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1208 | break; |
| 1209 | case QSER_APN_AUTH_PROTO_NONE: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1210 | strcpy(out_proto,"0"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1211 | break; |
| 1212 | case QSER_APN_AUTH_PROTO_PAP: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1213 | strcpy(out_proto,"1"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1214 | break; |
| 1215 | case QSER_APN_AUTH_PROTO_CHAP: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1216 | strcpy(out_proto,"2"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1217 | break; |
| 1218 | case QSER_APN_AUTH_PROTO_PAP_CHAP: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1219 | strcpy(out_proto,"3"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1220 | break; |
| 1221 | default: |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1222 | strcpy(out_proto,"NULL"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1223 | break; |
| 1224 | } |
| 1225 | return ; |
| 1226 | } |
| 1227 | |
| 1228 | int data_call_handle_get(const char profile_idx,int *handle) |
| 1229 | { |
| 1230 | int num = LYNQ_APN_CHANNEL_MAX; |
| 1231 | int table_num = 0; |
| 1232 | lynq_apn_info **apn_table = NULL; |
| 1233 | qser_apn_info_s apn; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1234 | int ret = 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1235 | apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX); |
| 1236 | if (NULL == apn_table) |
| 1237 | { |
| 1238 | LYERRLOG("malloc apn_table fail "); |
| 1239 | return RESULT_ERROR; |
| 1240 | } |
| 1241 | for(int i =0;i<10;i++) |
| 1242 | { |
| 1243 | apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info)); |
| 1244 | if (apn_table[i]==NULL) |
| 1245 | { |
| 1246 | for (int n=0;n<i;n++) |
| 1247 | { |
| 1248 | free(apn_table[n]); |
| 1249 | } |
| 1250 | return RESULT_ERROR; |
| 1251 | } |
| 1252 | memset(apn_table[i],0,sizeof(lynq_apn_info)); |
| 1253 | } |
| 1254 | lynq_get_apn_table(&table_num,apn_table); |
| 1255 | memset(&apn,0,sizeof(qser_apn_info_s)); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1256 | ret = apn_db_query(profile_idx,&apn); |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1257 | if (ret < 0) |
| 1258 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1259 | LYERRLOG("apn_db_query error"); |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1260 | return ret; |
| 1261 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1262 | for (int j = 0;j < table_num;j++) |
| 1263 | { |
| 1264 | if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0) |
| 1265 | { |
| 1266 | *handle = apn_table[j]->index; |
| 1267 | LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle); |
| 1268 | break; |
| 1269 | } |
| 1270 | } |
| 1271 | |
| 1272 | for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++) |
| 1273 | { |
| 1274 | if (apn_table[i]!=NULL) |
| 1275 | { |
| 1276 | free(apn_table[i]); |
| 1277 | apn_table[i]=NULL; |
| 1278 | } |
| 1279 | } |
| 1280 | free(apn_table); |
| 1281 | apn_table=NULL; |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1282 | LYDBGLOG("data_call_handle_get end"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1283 | return RESULT_OK; |
| 1284 | } |
| 1285 | |
xf.li | 789f7a1 | 2024-10-24 03:02:37 -0700 | [diff] [blame] | 1286 | static void acquire_wake_lock() |
| 1287 | { |
| 1288 | int ret = 0; |
| 1289 | |
| 1290 | ret = system("echo data_call_wakelock 5000000000 > /sys/power/wake_lock");//timeout 5s |
| 1291 | if(ret != 0) |
| 1292 | { |
| 1293 | LYERRLOG("acquire_wake_lock error !!!"); |
| 1294 | } |
| 1295 | return; |
| 1296 | } |
| 1297 | |
| 1298 | static void release_wake_lock() |
| 1299 | { |
| 1300 | int ret = 0; |
| 1301 | |
| 1302 | ret = system("echo data_call_wakelock > /sys/power/wake_unlock"); |
| 1303 | if(ret != 0) |
| 1304 | { |
| 1305 | LYERRLOG("release_wake_lock error !!!"); |
| 1306 | } |
| 1307 | return; |
| 1308 | } |
| 1309 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1310 | void *thread_wait_cb_status(void) |
| 1311 | { |
| 1312 | int handle = -1; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1313 | int ret = 0; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1314 | int default_handle = LYNQ_APN_CHANNEL_MAX + 1; |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1315 | lynq_data_call_response_v11_t data_urc_info = {0}; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1316 | qser_data_call_state_s data_cb_state; |
| 1317 | while (s_qser_data_cb_thread_status) |
| 1318 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1319 | ret = lynq_wait_data_call_state_change(&handle); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1320 | LYINFLOG("[thread_wait_cb_status]: ret = %d, handle = %d, wait data call state change end!!!\n", ret, handle); |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1321 | if(s_qser_data_cb_thread_status == 0) |
| 1322 | { |
| 1323 | return NULL; |
| 1324 | } |
| 1325 | else if(ret < 0) |
| 1326 | { |
| 1327 | continue; |
| 1328 | } |
xf.li | 789f7a1 | 2024-10-24 03:02:37 -0700 | [diff] [blame] | 1329 | acquire_wake_lock(); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1330 | //LYINFLOG("[thread_wait_cb_status]: handle = %d", handle); |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1331 | memset(&data_urc_info, 0, sizeof(data_urc_info)); |
| 1332 | memset(&data_cb_state, 0, sizeof(data_cb_state)); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1333 | lynq_get_data_call_list(&handle,&data_urc_info); |
| 1334 | /*compare paramter*/ |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1335 | //data_cb_state.profile_idx = (char)handle; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1336 | apn_db_handle_get_profile(handle, &data_cb_state.profile_idx); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1337 | LYINFLOG("[thread_wait_cb_status]: callback profile_idx is %d, status=%d, suggestedRetryTime=%d, cid=%d, active=%d, type=%s, ifname=%s, \n", |
| 1338 | data_cb_state.profile_idx, data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active, data_urc_info.type, data_urc_info.ifname); |
| 1339 | |
| 1340 | LYINFLOG("[thread_wait_cb_status]: addresses=%s, dnses=%s, gateways=%s, pcscf=%s, mtu=%d\n", |
| 1341 | data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf, data_urc_info.mtu); |
| 1342 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1343 | 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] | 1344 | 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] | 1345 | { |
| 1346 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4; |
| 1347 | } |
| 1348 | else if (!strcmp(data_urc_info.type,"IPV6")) |
| 1349 | { |
| 1350 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6; |
| 1351 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1352 | else if (!strcmp(data_urc_info.type,"IPV4V6")) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1353 | { |
| 1354 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 1355 | } |
| 1356 | else |
| 1357 | { |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1358 | LYERRLOG("unknow data call type: %s", data_urc_info.type); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1361 | if (data_urc_info.active != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1362 | { |
| 1363 | data_cb_state.state = QSER_DATA_CALL_CONNECTED; |
| 1364 | } |
| 1365 | else |
| 1366 | { |
| 1367 | data_cb_state.state = QSER_DATA_CALL_DISCONNECTED; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1368 | ret = apn_db_handle_set(data_cb_state.profile_idx, default_handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1369 | if(ret != 0) |
| 1370 | { |
| 1371 | LYERRLOG("handle set error"); |
| 1372 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1373 | } |
| 1374 | if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4) |
| 1375 | { |
| 1376 | lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state); |
| 1377 | } |
| 1378 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6) |
| 1379 | { |
| 1380 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 1381 | } |
| 1382 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6) |
| 1383 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1384 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1385 | lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 1386 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1387 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1388 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1389 | } |
| 1390 | else |
| 1391 | { |
xf.li | 789f7a1 | 2024-10-24 03:02:37 -0700 | [diff] [blame] | 1392 | release_wake_lock(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1393 | LYERRLOG("unknow ip_family"); |
| 1394 | continue; |
| 1395 | } |
| 1396 | if (s_data_call_cb != NULL) |
| 1397 | { |
xf.li | 789f7a1 | 2024-10-24 03:02:37 -0700 | [diff] [blame] | 1398 | s_data_call_cb(&data_cb_state); |
| 1399 | release_wake_lock(); |
| 1400 | LYINFLOG("[%s] call back s_data_call_cb end", __FUNCTION__); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | return NULL; |
| 1404 | } |
| 1405 | |
| 1406 | int qser_cb_pthread_create() |
| 1407 | { |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 1408 | pthread_attr_t attr; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1409 | int ret; |
| 1410 | s_qser_data_cb_thread_status = 1; |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 1411 | |
| 1412 | pthread_attr_init(&attr); |
| 1413 | pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
| 1414 | |
| 1415 | ret = pthread_create(&s_cb_tid,&attr,thread_wait_cb_status,NULL); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1416 | if (ret < 0) |
| 1417 | { |
| 1418 | LYERRLOG("pthread create fail"); |
| 1419 | s_qser_data_cb_thread_status = 0; |
| 1420 | return RESULT_ERROR; |
| 1421 | } |
xf.li | b5d82bf | 2024-03-09 01:54:50 -0800 | [diff] [blame] | 1422 | pthread_attr_destroy(&attr); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1423 | return RESULT_OK; |
| 1424 | } |
| 1425 | |
| 1426 | void qser_cb_pthread_cancel() |
| 1427 | { |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1428 | s_qser_data_cb_thread_status = 0; |
| 1429 | if (s_cb_tid != -1) |
| 1430 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1431 | lynq_release_wait_data_call(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1432 | } |
| 1433 | return; |
| 1434 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1435 | int qser_data_call_init(qser_data_call_evt_cb_t evt_cb) |
| 1436 | { |
| 1437 | int ret = 0; |
| 1438 | int utoken = 0; |
| 1439 | if (NULL == evt_cb) |
| 1440 | { |
| 1441 | LYERRLOG("init incoming paramters error"); |
| 1442 | return RESULT_ERROR; |
| 1443 | } |
xf.li | 09b46db | 2024-03-13 19:21:18 -0700 | [diff] [blame] | 1444 | if(g_lynq_qser_data_init_flag == 1) |
| 1445 | { |
| 1446 | LYERRLOG("init twice is not allowed"); |
| 1447 | return RESULT_ERROR; |
| 1448 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1449 | ret = lynq_init_data(utoken); |
| 1450 | if (ret != RESULT_OK) |
| 1451 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1452 | //qser_cb_pthread_cancel(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1453 | s_data_call_cb = NULL; |
| 1454 | return RESULT_ERROR; |
| 1455 | } |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1456 | qser_cb_pthread_create(); |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1457 | ret = init_apn_db(); |
| 1458 | if(ret != RESULT_OK) |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 1459 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1460 | LYERRLOG("init apn db error"); |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 1461 | return RESULT_ERROR; |
| 1462 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1463 | |
| 1464 | ret = apn_db_handle_clean(); |
xf.li | 63b87e8 | 2024-01-04 00:43:35 -0800 | [diff] [blame] | 1465 | if(ret != RESULT_OK) |
| 1466 | { |
| 1467 | LYERRLOG("clean handle error"); |
| 1468 | return RESULT_ERROR; |
| 1469 | } |
xf.li | 09b46db | 2024-03-13 19:21:18 -0700 | [diff] [blame] | 1470 | s_data_call_cb = evt_cb; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1471 | g_lynq_qser_data_init_flag = 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1472 | return RESULT_OK; |
| 1473 | } |
| 1474 | |
| 1475 | void qser_data_call_destroy(void) |
| 1476 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1477 | LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1478 | lynq_deinit_data(); |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1479 | qser_cb_pthread_cancel(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1480 | s_data_call_cb = NULL; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1481 | g_lynq_qser_data_init_flag = 0; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1482 | LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1483 | return ; |
| 1484 | } |
| 1485 | |
| 1486 | int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 1487 | { |
| 1488 | int ret = -1; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1489 | int error = -1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1490 | int handle = 0; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1491 | if(g_lynq_qser_data_init_flag == 0) |
| 1492 | { |
| 1493 | if(err != NULL) |
| 1494 | { |
| 1495 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1496 | } |
| 1497 | return LYNQ_E_NO_INIT; |
| 1498 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1499 | if (NULL == data_call || NULL == err) |
| 1500 | { |
| 1501 | LYERRLOG("call start incoming paramters error"); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1502 | if(err != NULL) |
| 1503 | { |
| 1504 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1505 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1506 | return ret; |
| 1507 | } |
| 1508 | if (data_call->profile_idx == 0) |
| 1509 | { |
| 1510 | ret = lynq_setup_data_call(&handle); |
| 1511 | } |
| 1512 | else |
| 1513 | { |
| 1514 | char pdptype[16]; |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1515 | char auth_proto[16]; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1516 | qser_apn_info_s apn_info; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1517 | LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx); |
| 1518 | ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info); |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1519 | if (ret != 0) |
| 1520 | { |
| 1521 | LYERRLOG("qser_apn_get error"); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1522 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1523 | return ret; |
| 1524 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1525 | judge_pdp_type(apn_info.pdp_type,pdptype); |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1526 | judge_authtype(apn_info.auth_proto,auth_proto); |
| 1527 | 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] | 1528 | } |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1529 | if (ret != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1530 | { |
| 1531 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1532 | } |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1533 | else |
| 1534 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1535 | error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1536 | if(error != 0) |
| 1537 | { |
| 1538 | LYERRLOG("handle set error"); |
| 1539 | } |
| 1540 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1541 | return ret; |
| 1542 | } |
| 1543 | |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1544 | int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 1545 | { |
| 1546 | int ret = -1; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1547 | int error = -1; |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1548 | int handle = 0; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1549 | if(g_lynq_qser_data_init_flag == 0) |
| 1550 | { |
| 1551 | if(err != NULL) |
| 1552 | { |
| 1553 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1554 | } |
| 1555 | return LYNQ_E_NO_INIT; |
| 1556 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1557 | if (NULL == data_call || NULL == err) |
| 1558 | { |
| 1559 | LYERRLOG("call start incoming paramters error"); |
| 1560 | if(err != NULL) |
| 1561 | { |
| 1562 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1563 | } |
| 1564 | return ret; |
| 1565 | } |
| 1566 | if (data_call->profile_idx == 0) |
| 1567 | { |
| 1568 | ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL); |
| 1569 | } |
| 1570 | else |
| 1571 | { |
| 1572 | char pdptype[16]; |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1573 | char auth_proto[16]; |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1574 | qser_apn_info_s apn_info; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1575 | LYINFLOG("datacall->profile_idx is %d\n", data_call->profile_idx); |
| 1576 | ret = qser_apn_get((unsigned char)data_call->profile_idx,&apn_info); |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1577 | if (ret != 0) |
| 1578 | { |
| 1579 | LYERRLOG("qser_apn_get error"); |
| 1580 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1581 | return ret; |
| 1582 | } |
| 1583 | judge_pdp_type(apn_info.pdp_type,pdptype); |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1584 | judge_authtype(apn_info.auth_proto,auth_proto); |
| 1585 | 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] | 1586 | } |
| 1587 | if (ret != 0) |
| 1588 | { |
| 1589 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1590 | } |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1591 | else |
| 1592 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1593 | error = apn_db_handle_set((unsigned char)data_call->profile_idx, handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1594 | if(error != 0) |
| 1595 | { |
| 1596 | LYERRLOG("handle set error"); |
| 1597 | } |
| 1598 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1599 | return ret; |
| 1600 | } |
| 1601 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1602 | int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err) |
| 1603 | { |
| 1604 | int ret = 0; |
| 1605 | int handle = -1; |
| 1606 | |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1607 | if(g_lynq_qser_data_init_flag == 0) |
| 1608 | { |
| 1609 | if(err != NULL) |
| 1610 | { |
| 1611 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1612 | } |
| 1613 | return LYNQ_E_NO_INIT; |
| 1614 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1615 | if (NULL == err) |
| 1616 | { |
| 1617 | LYERRLOG("call stop incoming paramters error"); |
| 1618 | return ret; |
| 1619 | } |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1620 | ret = data_call_handle_get(profile_idx,&handle); |
| 1621 | if(ret != 0) |
| 1622 | { |
| 1623 | LYERRLOG("datacall handle get error"); |
| 1624 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1625 | return ret; |
| 1626 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1627 | ret = lynq_deactive_data_call(&handle); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1628 | if (ret != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1629 | { |
| 1630 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1631 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1632 | } |
xy.he | e2daacc | 2023-09-18 00:57:51 -0700 | [diff] [blame] | 1633 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1634 | } |
| 1635 | 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) |
| 1636 | { |
| 1637 | int ret = 0; |
| 1638 | int handle = -1; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1639 | if(g_lynq_qser_data_init_flag == 0) |
| 1640 | { |
| 1641 | if(err != NULL) |
| 1642 | { |
| 1643 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1644 | } |
| 1645 | return LYNQ_E_NO_INIT; |
| 1646 | } |
xf.li | 4ab455d | 2024-07-30 01:21:56 -0700 | [diff] [blame] | 1647 | lynq_data_call_response_v11_t data_call_info = {0}; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1648 | data_call_handle_get(profile_idx,&handle); |
| 1649 | ret = lynq_get_data_call_list(&handle,&data_call_info); |
| 1650 | if (ret == 0) |
| 1651 | { |
| 1652 | info->profile_idx = profile_idx; |
| 1653 | info->ip_family = ip_family; |
xf.li | 157f7e9 | 2023-10-19 23:22:46 -0700 | [diff] [blame] | 1654 | 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] | 1655 | { |
xf.li | 0400b38 | 2024-06-05 19:20:36 -0700 | [diff] [blame] | 1656 | info->ip_family = QSER_DATA_CALL_TYPE_IPV4; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1657 | strcpy(info->v4.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1658 | datacall_ipv4_status_judge(data_call_info.active,info); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1659 | LYDBGLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1660 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
| 1661 | } |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1662 | else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1663 | { |
xf.li | 0400b38 | 2024-06-05 19:20:36 -0700 | [diff] [blame] | 1664 | info->ip_family = QSER_DATA_CALL_TYPE_IPV6; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1665 | strcpy(info->v6.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1666 | datacall_ipv6_status_judge(data_call_info.active,info); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1667 | LYDBGLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1668 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
| 1669 | } |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1670 | else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1671 | { |
xf.li | 0400b38 | 2024-06-05 19:20:36 -0700 | [diff] [blame] | 1672 | info->ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1673 | strcpy(info->v4.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1674 | datacall_ipv4_status_judge(data_call_info.active,info); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1675 | LYDBGLOG("[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] | 1676 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1677 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1678 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1679 | strcpy(info->v6.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1680 | datacall_ipv6_status_judge(data_call_info.active,info); |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1681 | LYDBGLOG("[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] | 1682 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1683 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1684 | #endif |
| 1685 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1686 | lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info); |
| 1687 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1688 | } |
| 1689 | else |
| 1690 | { |
| 1691 | LYERRLOG("useless qser_data_call_ip_family_e"); |
| 1692 | } |
| 1693 | } |
| 1694 | return ret; |
| 1695 | } |
xf.li | 7aca5c0 | 2025-01-02 02:48:47 -0800 | [diff] [blame] | 1696 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1697 | int qser_set_initial_apnname(char *apnname) |
| 1698 | { |
| 1699 | int ret = -1; |
| 1700 | |
| 1701 | if(g_lynq_qser_data_init_flag == 0) |
| 1702 | { |
| 1703 | return LYNQ_E_NO_INIT; |
| 1704 | } |
| 1705 | |
| 1706 | ret = lynq_init_attach_apn(apnname, "IP", "0", "null", "null"); |
| 1707 | return ret; |
| 1708 | } |
| 1709 | int qser_get_initial_apnname(char apnname[QSER_APN_NAME_SIZE]) |
| 1710 | { |
| 1711 | int ret = -1; |
| 1712 | lynq_apn_list_response apnList = {-1, "", "", "", -1, -1, -1, -1, -1, -1}; |
| 1713 | |
| 1714 | if(g_lynq_qser_data_init_flag == 0) |
| 1715 | { |
| 1716 | return LYNQ_E_NO_INIT; |
| 1717 | } |
| 1718 | |
| 1719 | if(apnname == NULL) |
| 1720 | { |
| 1721 | LYERRLOG("[%s][%d] apnname is NULL",__FUNCTION__,__LINE__); |
| 1722 | } |
| 1723 | ret = lynq_get_apn_list(1, &apnList); |
| 1724 | if(ret == 0) |
| 1725 | { |
| 1726 | memcpy(apnname, apnList.apn, sizeof(apnList.apn)); |
| 1727 | LYINFLOG("qser_get_initial_apnname: %s", apnname); |
| 1728 | } |
| 1729 | return ret; |
| 1730 | } |
| 1731 | #endif |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1732 | int check_pdp_type(qser_apn_pdp_type_e pdp_type) |
| 1733 | { |
| 1734 | switch (pdp_type) |
| 1735 | { |
| 1736 | case QSER_APN_PDP_TYPE_IPV4: |
| 1737 | case QSER_APN_PDP_TYPE_PPP: |
| 1738 | case QSER_APN_PDP_TYPE_IPV6: |
| 1739 | case QSER_APN_PDP_TYPE_IPV4V6: |
| 1740 | return 0; |
| 1741 | default: |
| 1742 | return -1; |
| 1743 | } |
| 1744 | } |
| 1745 | int check_auth_proto(qser_apn_auth_proto_e auth_proto) |
| 1746 | { |
| 1747 | switch (auth_proto) |
| 1748 | { |
| 1749 | case QSER_APN_AUTH_PROTO_DEFAULT: |
| 1750 | case QSER_APN_AUTH_PROTO_NONE: |
| 1751 | case QSER_APN_AUTH_PROTO_PAP: |
| 1752 | case QSER_APN_AUTH_PROTO_CHAP: |
| 1753 | case QSER_APN_AUTH_PROTO_PAP_CHAP: |
| 1754 | return 0; |
| 1755 | default: |
| 1756 | return -1; |
| 1757 | } |
| 1758 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1759 | int qser_apn_set(qser_apn_info_s *apn) |
| 1760 | { |
| 1761 | int ret = 0; |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1762 | int handle = -1; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1763 | if(g_lynq_qser_data_init_flag == 0) |
| 1764 | { |
| 1765 | return LYNQ_E_NO_INIT; |
| 1766 | } |
xf.li | 4b18fa6 | 2023-12-19 19:38:10 -0800 | [diff] [blame] | 1767 | if (NULL == apn || apn->profile_idx == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1768 | { |
| 1769 | LYERRLOG("apn set incoming paramters error"); |
| 1770 | return RESULT_ERROR; |
| 1771 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1772 | ret = apn_db_handle_get(apn->profile_idx, &handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1773 | if(ret != 0) |
| 1774 | { |
| 1775 | LYERRLOG("handle set error"); |
| 1776 | } |
| 1777 | if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX) |
| 1778 | { |
| 1779 | LYERRLOG("It has setup datacall"); |
| 1780 | return RESULT_ERROR; |
| 1781 | } |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1782 | |
| 1783 | if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE) |
| 1784 | { |
| 1785 | LYERRLOG("apn_name out of range\n"); |
| 1786 | return RESULT_ERROR; |
| 1787 | } |
| 1788 | if(strlen(apn->username) > QSER_APN_USERNAME_SIZE) |
| 1789 | { |
| 1790 | LYERRLOG("username out of range\n"); |
| 1791 | return RESULT_ERROR; |
| 1792 | } |
| 1793 | if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE) |
| 1794 | { |
| 1795 | LYERRLOG("password out of range\n"); |
| 1796 | return RESULT_ERROR; |
| 1797 | } |
| 1798 | if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE) |
| 1799 | { |
| 1800 | LYERRLOG("apn_type out of range\n"); |
| 1801 | return RESULT_ERROR; |
| 1802 | } |
| 1803 | if(check_pdp_type(apn->pdp_type) != 0) |
| 1804 | { |
| 1805 | LYERRLOG("pdp_type out of range\n"); |
| 1806 | return RESULT_ERROR; |
| 1807 | } |
| 1808 | if(check_auth_proto(apn->auth_proto) != 0) |
| 1809 | { |
| 1810 | LYERRLOG("auth_proto out of range\n"); |
| 1811 | return RESULT_ERROR; |
| 1812 | } |
| 1813 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1814 | ret = apn_db_modify(apn); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1815 | if (ret < 0) |
| 1816 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1817 | LYERRLOG("apn_db_modify error"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1818 | return ret; |
| 1819 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1820 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1821 | int apn_id = 0; |
| 1822 | char tmp_id[12]; |
| 1823 | char *outinfo = NULL; |
| 1824 | char normalprotocol[16]; |
| 1825 | char authtype[32]; |
| 1826 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1827 | bzero(tmp_id,12); |
| 1828 | bzero(outinfo,512); |
| 1829 | apn_id = apn->profile_idx + apndb_offset; |
| 1830 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1831 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 1832 | judge_authtype(apn->auth_proto,authtype); |
| 1833 | lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 1834 | LYINFLOG("[output]:%s",outinfo); |
| 1835 | free(outinfo); |
| 1836 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1837 | #endif |
| 1838 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn) |
| 1842 | { |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1843 | if(g_lynq_qser_data_init_flag == 0) |
| 1844 | { |
| 1845 | return LYNQ_E_NO_INIT; |
| 1846 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1847 | if (profile_idx < 0 || profile_idx > QSER_APN_MAX_LIST || NULL == apn) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1848 | { |
| 1849 | LYERRLOG("apn get incoming paramters error"); |
| 1850 | return RESULT_ERROR; |
| 1851 | } |
| 1852 | int ret = 0; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1853 | ret = apn_db_query(profile_idx,apn); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1854 | if (ret < 0) |
| 1855 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1856 | LYERRLOG("apn_db_query error"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1857 | return ret; |
| 1858 | } |
| 1859 | return ret; |
| 1860 | } |
| 1861 | |
| 1862 | int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx) |
| 1863 | { |
| 1864 | int ret = 0; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1865 | |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1866 | if(g_lynq_qser_data_init_flag == 0) |
| 1867 | { |
| 1868 | return LYNQ_E_NO_INIT; |
| 1869 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1870 | if (NULL == apn || NULL == profile_idx) |
| 1871 | { |
| 1872 | LYERRLOG("apn add incoming paramters error"); |
| 1873 | return RESULT_ERROR; |
| 1874 | } |
xf.li | fb6134e | 2024-05-09 01:26:54 -0700 | [diff] [blame] | 1875 | |
| 1876 | if(strlen(apn->apn_name) > QSER_APN_NAME_SIZE) |
| 1877 | { |
| 1878 | LYERRLOG("apn_name out of range\n"); |
| 1879 | return RESULT_ERROR; |
| 1880 | } |
| 1881 | if(strlen(apn->username) > QSER_APN_USERNAME_SIZE) |
| 1882 | { |
| 1883 | LYERRLOG("username out of range\n"); |
| 1884 | return RESULT_ERROR; |
| 1885 | } |
| 1886 | if(strlen(apn->password) > QSER_APN_PASSWORD_SIZE) |
| 1887 | { |
| 1888 | LYERRLOG("password out of range\n"); |
| 1889 | return RESULT_ERROR; |
| 1890 | } |
| 1891 | if(strlen(apn->apn_type) > QSER_APN_NAME_SIZE) |
| 1892 | { |
| 1893 | LYERRLOG("apn_type out of range\n"); |
| 1894 | return RESULT_ERROR; |
| 1895 | } |
| 1896 | if(check_pdp_type(apn->pdp_type) != 0) |
| 1897 | { |
| 1898 | LYERRLOG("pdp_type out of range\n"); |
| 1899 | return RESULT_ERROR; |
| 1900 | } |
| 1901 | if(check_auth_proto(apn->auth_proto) != 0) |
| 1902 | { |
| 1903 | LYERRLOG("auth_proto out of range\n"); |
| 1904 | return RESULT_ERROR; |
| 1905 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1906 | |
| 1907 | *profile_idx = 0; |
| 1908 | *profile_idx = (unsigned char)find_unuse_apn_index(APN_DB_PATH); |
| 1909 | LYINFLOG("[%s] id = %d\n",__FUNCTION__,(int)*profile_idx); |
| 1910 | if((int)*profile_idx > 0 && (int)*profile_idx < QSER_APN_MAX_LIST) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1911 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1912 | LYINFLOG("[%s] apn full is false\n",__FUNCTION__); |
| 1913 | ret = apn_db_add((int)*profile_idx, apn); |
| 1914 | if (ret != 0) |
| 1915 | { |
| 1916 | LYERRLOG("apn_db_add error"); |
| 1917 | return RESULT_ERROR; |
| 1918 | } |
| 1919 | else |
| 1920 | { |
| 1921 | return RESULT_OK; |
| 1922 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1923 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1924 | LYERRLOG("apn storage space is full!!!"); |
| 1925 | return RESULT_ERROR; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1926 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1927 | int apn_id = 0; |
| 1928 | char tmp_id[12]; |
| 1929 | char *outinfo = NULL; |
| 1930 | char normalprotocol[16]; |
| 1931 | char authtype[32]; |
| 1932 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1933 | bzero(tmp_id,12); |
| 1934 | bzero(outinfo,512); |
| 1935 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1936 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 1937 | judge_authtype(apn->auth_proto,authtype); |
| 1938 | lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 1939 | LYINFLOG("[output]:%s",outinfo); |
| 1940 | free(outinfo); |
| 1941 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1942 | #endif |
| 1943 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1944 | } |
| 1945 | |
| 1946 | int qser_apn_del(unsigned char profile_idx) |
| 1947 | { |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1948 | int ret = 0; |
| 1949 | int handle = -1; |
| 1950 | |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1951 | LYDBGLOG("[%s] entry\n",__FUNCTION__); |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1952 | if(g_lynq_qser_data_init_flag == 0) |
| 1953 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 1954 | LYERRLOG("lynq qser data uninit"); |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1955 | return LYNQ_E_NO_INIT; |
| 1956 | } |
xf.li | 4b18fa6 | 2023-12-19 19:38:10 -0800 | [diff] [blame] | 1957 | if (profile_idx <= 0 || profile_idx > QSER_APN_MAX_LIST) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1958 | { |
| 1959 | LYERRLOG("apn del incoming paramters error"); |
xf.li | 4b18fa6 | 2023-12-19 19:38:10 -0800 | [diff] [blame] | 1960 | return RESULT_ERROR; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1961 | } |
xf.li | 87f6e6e | 2024-06-19 02:23:05 -0700 | [diff] [blame] | 1962 | |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1963 | ret = apn_db_handle_get(profile_idx, &handle); |
xf.li | 0fd6acf | 2023-12-20 18:16:34 -0800 | [diff] [blame] | 1964 | if(ret != 0) |
| 1965 | { |
| 1966 | LYERRLOG("handle set error"); |
| 1967 | } |
| 1968 | if(handle >= 0 && handle < LYNQ_APN_CHANNEL_MAX) |
| 1969 | { |
| 1970 | LYERRLOG("It has setup datacall"); |
| 1971 | return RESULT_ERROR; |
| 1972 | } |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1973 | ret = apn_db_delete(profile_idx); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1974 | if (ret < 0) |
| 1975 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 1976 | LYERRLOG("apn_db_delete error"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1977 | return ret; |
| 1978 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1979 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1980 | int apn_id = 0; |
| 1981 | char tmp_id[12]; |
| 1982 | char *outinfo = NULL; |
| 1983 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1984 | bzero(tmp_id,12); |
| 1985 | bzero(outinfo,512); |
| 1986 | apn_id = profile_idx+apndb_offset; |
| 1987 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1988 | lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo); |
| 1989 | LYINFLOG("[output]:%s",outinfo); |
| 1990 | free(outinfo); |
| 1991 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1992 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1993 | return ret; |
| 1994 | } |
| 1995 | |
| 1996 | int qser_apn_get_list(qser_apn_info_list_s *apn_list) |
| 1997 | { |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1998 | if(g_lynq_qser_data_init_flag == 0) |
| 1999 | { |
xf.li | 7d256b6 | 2025-03-21 00:07:36 -0700 | [diff] [blame^] | 2000 | LYERRLOG("lynq qser data uninit"); |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 2001 | return LYNQ_E_NO_INIT; |
| 2002 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 2003 | if (NULL == apn_list) |
| 2004 | { |
| 2005 | LYERRLOG("apn_list incoming paramters error"); |
| 2006 | return RESULT_ERROR; |
| 2007 | } |
| 2008 | int ret = 0; |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 2009 | ret = apn_db_query_list(apn_list); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 2010 | if (ret < 0) |
| 2011 | { |
xf.li | cb6cd28 | 2024-02-21 22:06:14 -0800 | [diff] [blame] | 2012 | LYERRLOG("apn_db_query_list error"); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 2013 | return ret; |
| 2014 | } |
| 2015 | return ret; |
xf.li | 3f891cb | 2023-08-23 23:11:24 -0700 | [diff] [blame] | 2016 | } |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 2017 | |
| 2018 | DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA) |
| 2019 | |