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> |
| 12 | #include <libxml/tree.h> |
| 13 | #include <libxml/parser.h> |
| 14 | #include "lynq-qser-data.h" |
| 15 | |
| 16 | #define USER_LOG_TAG "LYNQ_QSER_DATA" |
| 17 | |
| 18 | #define RESULT_OK (0) |
| 19 | #define RESULT_ERROR (-1) |
| 20 | |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 21 | typedef enum{ |
| 22 | LYNQ_E_NO_INIT=9002 |
| 23 | }LYNQ_E; |
| 24 | |
| 25 | static int g_lynq_qser_data_init_flag = 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 26 | static pthread_t s_cb_tid = -1; |
| 27 | static int s_qser_data_cb_thread_status = 0; |
| 28 | static pthread_mutex_t s_qser_data_cb_mutex = PTHREAD_MUTEX_INITIALIZER; |
| 29 | static pthread_cond_t s_qser_data_cb_cond = PTHREAD_COND_INITIALIZER; |
| 30 | |
xf.li | 807fd13 | 2023-07-02 02:45:36 -0700 | [diff] [blame] | 31 | #define data_xml_path "/mnt/userdata/lynq_qser_data_apn.xml" |
xf.li | 7b0bfd0 | 2023-08-03 01:11:52 -0700 | [diff] [blame] | 32 | #define COPY_XML_RETRY_TIMES 3 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 33 | |
| 34 | static qser_data_call_evt_cb_t s_data_call_cb = NULL; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 35 | static xmlDocPtr apn_table_xml_pdoc = NULL; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 36 | const int apndb_offset = 683; |
| 37 | |
| 38 | void lynq_ipv4_aton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res) |
| 39 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 40 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 41 | char *tmp_char = NULL; |
| 42 | char *addresses = NULL; |
| 43 | char *dnses = NULL; |
| 44 | const char addresses_separator[2] = "/"; |
| 45 | const char dnses_separator[2] = " "; |
| 46 | |
| 47 | addresses = libdata->addresses; |
| 48 | dnses = libdata->dnses; |
| 49 | //get addresses |
| 50 | tmp_char = strsep(&addresses, addresses_separator); |
| 51 | if(tmp_char != NULL) |
| 52 | { |
| 53 | LYINFLOG("ipv4 addresses = %s", tmp_char); |
| 54 | inet_aton(tmp_char,&(data_res->v4.ip)); |
| 55 | } |
| 56 | |
| 57 | //get dnses |
| 58 | tmp_char = strsep(&dnses, dnses_separator); |
| 59 | if(tmp_char != NULL) |
| 60 | { |
| 61 | LYINFLOG("ipv4 pri_dns = %s", tmp_char); |
| 62 | inet_aton(tmp_char,&(data_res->v4.pri_dns)); |
| 63 | } |
| 64 | tmp_char = strsep(&dnses, dnses_separator); |
| 65 | if(tmp_char != NULL) |
| 66 | { |
| 67 | LYINFLOG("ipv4 sec_dns = %s", tmp_char); |
| 68 | inet_aton(tmp_char, &(data_res->v4.sec_dns)); |
| 69 | } |
| 70 | //get gateway |
| 71 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 72 | |
| 73 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 74 | inet_aton(libdata->addresses,&(data_res->v4.ip)); |
| 75 | inet_aton(libdata->gateways,&(data_res->v4.gateway)); |
| 76 | inet_aton(libdata->dnses,&(data_res->v4.pri_dns)); |
| 77 | inet_aton(libdata->dnses,&(data_res->v4.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 78 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 79 | return ; |
| 80 | } |
| 81 | |
| 82 | void lynq_ipv6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res) |
| 83 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 84 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 85 | char *tmp_char = NULL; |
| 86 | char *addresses = NULL; |
| 87 | char *dnses = NULL; |
| 88 | const char addresses_separator[2] = "/"; |
| 89 | const char dnses_separator[2] = " "; |
| 90 | |
| 91 | addresses = libdata->addresses; |
| 92 | dnses = libdata->dnses; |
| 93 | //get addresses |
| 94 | tmp_char = strsep(&addresses, addresses_separator); |
| 95 | if(tmp_char != NULL) |
| 96 | { |
| 97 | LYINFLOG("ipv6 addresses = %s", tmp_char); |
| 98 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip)); |
| 99 | } |
| 100 | //get dnses |
| 101 | tmp_char = strsep(&dnses, dnses_separator); |
| 102 | if(tmp_char != NULL) |
| 103 | { |
| 104 | LYINFLOG("ipv6 pri_dns = %s", tmp_char); |
| 105 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns)); |
| 106 | } |
| 107 | tmp_char = strsep(&dnses, dnses_separator); |
| 108 | if(tmp_char != NULL) |
| 109 | { |
| 110 | LYINFLOG("ipv6 sec_dns = %s", tmp_char); |
| 111 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns)); |
| 112 | } |
| 113 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 114 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 115 | inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.ip)); |
| 116 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 117 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.pri_dns)); |
| 118 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 119 | #endif |
| 120 | |
| 121 | return ; |
| 122 | } |
| 123 | |
| 124 | void lynq_ipv4v6_inet_pton_urc(lynq_data_call_response_v11_t *libdata,qser_data_call_state_s *data_res) |
| 125 | { |
| 126 | char *tmp_char = NULL; |
| 127 | char *addresses = NULL; |
| 128 | char *dnses = NULL; |
| 129 | const char addresses_separator[2] = "/"; |
| 130 | const char dnses_separator[2] = " "; |
| 131 | |
| 132 | addresses = libdata->addresses; |
| 133 | dnses = libdata->dnses; |
| 134 | //get addresses |
| 135 | tmp_char = strsep(&addresses, addresses_separator); |
| 136 | if(tmp_char != NULL) |
| 137 | { |
| 138 | LYINFLOG("ipv4 addresses = %s", tmp_char); |
| 139 | inet_aton(tmp_char,&(data_res->v4.ip)); |
| 140 | } |
| 141 | tmp_char = strsep(&addresses, addresses_separator); |
| 142 | if(tmp_char != NULL) |
| 143 | { |
| 144 | LYINFLOG("ipv6 addresses = %s", tmp_char); |
| 145 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.ip)); |
| 146 | } |
| 147 | //get dnses |
| 148 | tmp_char = strsep(&dnses, dnses_separator); |
| 149 | if(tmp_char != NULL) |
| 150 | { |
| 151 | LYINFLOG("ipv4 pri_dns = %s", tmp_char); |
| 152 | inet_aton(tmp_char,&(data_res->v4.pri_dns)); |
| 153 | } |
| 154 | tmp_char = strsep(&dnses, dnses_separator); |
| 155 | if(tmp_char != NULL) |
| 156 | { |
| 157 | LYINFLOG("ipv4 sec_dns = %s", tmp_char); |
| 158 | inet_aton(tmp_char, &(data_res->v4.sec_dns)); |
| 159 | } |
| 160 | tmp_char = strsep(&dnses, dnses_separator); |
| 161 | if(tmp_char != NULL) |
| 162 | { |
| 163 | LYINFLOG("ipv6 pri_dns = %s", tmp_char); |
| 164 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.pri_dns)); |
| 165 | } |
| 166 | tmp_char = strsep(&dnses, dnses_separator); |
| 167 | if(tmp_char != NULL) |
| 168 | { |
| 169 | LYINFLOG("ipv6 sec_dns = %s", tmp_char); |
| 170 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.sec_dns)); |
| 171 | } |
| 172 | //get gateway |
| 173 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.gateway)); |
| 174 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 175 | return ; |
| 176 | } |
| 177 | |
| 178 | void lynq_ipv4_aton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res) |
| 179 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 180 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 181 | char *tmp_char = NULL; |
| 182 | char *addresses = NULL; |
| 183 | char *dnses = NULL; |
| 184 | const char addresses_separator[2] = "/"; |
| 185 | const char dnses_separator[2] = " "; |
| 186 | |
| 187 | addresses = libdata->addresses; |
| 188 | dnses = libdata->dnses; |
| 189 | //get addresses |
| 190 | tmp_char = strsep(&addresses, addresses_separator); |
| 191 | if(tmp_char != NULL) |
| 192 | { |
| 193 | LYINFLOG("ipv4 addresses = %s", tmp_char); |
| 194 | inet_aton(tmp_char,&(data_res->v4.addr.ip)); |
| 195 | } |
| 196 | //get dnses |
| 197 | tmp_char = strsep(&dnses, dnses_separator); |
| 198 | if(tmp_char != NULL) |
| 199 | { |
| 200 | LYINFLOG("ipv4 pri_dns = %s", tmp_char); |
| 201 | inet_aton(tmp_char,&(data_res->v4.addr.pri_dns)); |
| 202 | } |
| 203 | tmp_char = strsep(&dnses, dnses_separator); |
| 204 | if(tmp_char != NULL) |
| 205 | { |
| 206 | LYINFLOG("ipv4 sec_dns = %s", tmp_char); |
| 207 | inet_aton(tmp_char, &(data_res->v4.addr.sec_dns)); |
| 208 | } |
| 209 | //get gateway |
| 210 | LYINFLOG("ipv4 gateways = %s", libdata->gateways); |
| 211 | inet_aton(libdata->gateways,&(data_res->v4.addr.gateway)); |
| 212 | |
| 213 | LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip)); |
| 214 | LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns)); |
| 215 | LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns)); |
| 216 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 217 | inet_aton(libdata->addresses,&(data_res->v4.addr.ip)); |
| 218 | inet_aton(libdata->gateways,&(data_res->v4.addr.gateway)); |
| 219 | inet_aton(libdata->dnses,&(data_res->v4.addr.pri_dns)); |
| 220 | inet_aton(libdata->dnses,&(data_res->v4.addr.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 221 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 222 | data_res->v4.stats.pkts_tx = 0; |
| 223 | data_res->v4.stats.pkts_rx = 0; |
| 224 | data_res->v4.stats.bytes_tx = 0; |
| 225 | data_res->v4.stats.bytes_rx = 0; |
| 226 | data_res->v4.stats.pkts_dropped_tx = 0; |
| 227 | data_res->v4.stats.pkts_dropped_rx = 0; |
| 228 | return ; |
| 229 | } |
| 230 | |
| 231 | void lynq_ipv6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res) |
| 232 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 233 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 234 | char *tmp_char = NULL; |
| 235 | char *addresses = NULL; |
| 236 | char *dnses = NULL; |
| 237 | const char addresses_separator[2] = "/"; |
| 238 | const char dnses_separator[2] = " "; |
| 239 | |
| 240 | addresses = libdata->addresses; |
| 241 | dnses = libdata->dnses; |
| 242 | //get addresses |
| 243 | tmp_char = strsep(&addresses, addresses_separator); |
| 244 | if(tmp_char != NULL) |
| 245 | { |
| 246 | LYINFLOG("ipv6 addresses = %s", tmp_char); |
| 247 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip)); |
| 248 | } |
| 249 | //get dnses |
| 250 | tmp_char = strsep(&dnses, dnses_separator); |
| 251 | if(tmp_char != NULL) |
| 252 | { |
| 253 | LYINFLOG("ipv6 pri_dns = %s", tmp_char); |
| 254 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns)); |
| 255 | } |
| 256 | tmp_char = strsep(&dnses, dnses_separator); |
| 257 | if(tmp_char != NULL) |
| 258 | { |
| 259 | LYINFLOG("ipv6 sec_dns = %s", tmp_char); |
| 260 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns)); |
| 261 | } |
| 262 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway)); |
| 263 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 264 | inet_pton(AF_INET6,libdata->addresses,&(data_res->v6.addr.ip)); |
| 265 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway)); |
| 266 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.pri_dns)); |
| 267 | inet_pton(AF_INET6,libdata->dnses,&(data_res->v6.addr.sec_dns)); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 268 | #endif |
| 269 | data_res->v6.stats.pkts_tx = 0; |
| 270 | data_res->v6.stats.pkts_rx = 0; |
| 271 | data_res->v6.stats.bytes_tx = 0; |
| 272 | data_res->v6.stats.bytes_rx = 0; |
| 273 | data_res->v6.stats.pkts_dropped_tx = 0; |
| 274 | data_res->v6.stats.pkts_dropped_rx = 0; |
| 275 | return ; |
| 276 | } |
| 277 | void lynq_ipv4v6_inet_pton_getinfo(lynq_data_call_response_v11_t *libdata,qser_data_call_info_s *data_res) |
| 278 | { |
| 279 | char *tmp_char = NULL; |
| 280 | char *addresses = NULL; |
| 281 | char *dnses = NULL; |
| 282 | const char addresses_separator[2] = "/"; |
| 283 | const char dnses_separator[2] = " "; |
| 284 | |
| 285 | char buf_ip[64] = {0}; |
| 286 | char buf_gateway[64] = {0}; |
| 287 | char buf_pri_dns[64] = {0}; |
| 288 | char buf_sec_dns[64] = {0}; |
| 289 | |
| 290 | addresses = libdata->addresses; |
| 291 | dnses = libdata->dnses; |
| 292 | //get addresses |
| 293 | tmp_char = strsep(&addresses, addresses_separator); |
| 294 | if(tmp_char != NULL) |
| 295 | { |
| 296 | LYINFLOG("ipv4 addresses = %s", tmp_char); |
| 297 | inet_aton(tmp_char,&(data_res->v4.addr.ip)); |
| 298 | } |
| 299 | tmp_char = strsep(&addresses, addresses_separator); |
| 300 | if(tmp_char != NULL) |
| 301 | { |
| 302 | LYINFLOG("ipv6 addresses = %s", tmp_char); |
| 303 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.ip)); |
| 304 | } |
| 305 | //get dnses |
| 306 | tmp_char = strsep(&dnses, dnses_separator); |
| 307 | if(tmp_char != NULL) |
| 308 | { |
| 309 | LYINFLOG("ipv4 pri_dns = %s", tmp_char); |
| 310 | inet_aton(tmp_char,&(data_res->v4.addr.pri_dns)); |
| 311 | } |
| 312 | tmp_char = strsep(&dnses, dnses_separator); |
| 313 | if(tmp_char != NULL) |
| 314 | { |
| 315 | LYINFLOG("ipv4 sec_dns = %s", tmp_char); |
| 316 | inet_aton(tmp_char, &(data_res->v4.addr.sec_dns)); |
| 317 | } |
| 318 | tmp_char = strsep(&dnses, dnses_separator); |
| 319 | if(tmp_char != NULL) |
| 320 | { |
| 321 | LYINFLOG("ipv6 pri_dns = %s", tmp_char); |
| 322 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.pri_dns)); |
| 323 | } |
| 324 | tmp_char = strsep(&dnses, dnses_separator); |
| 325 | if(tmp_char != NULL) |
| 326 | { |
| 327 | LYINFLOG("ipv6 sec_dns = %s", tmp_char); |
| 328 | inet_pton(AF_INET6, tmp_char, &(data_res->v6.addr.sec_dns)); |
| 329 | } |
| 330 | //get gateway |
| 331 | inet_pton(AF_INET6,libdata->gateways,&(data_res->v6.addr.gateway)); |
| 332 | |
| 333 | LYINFLOG("v4.ip=%s", inet_ntoa(data_res->v4.addr.ip)); |
| 334 | LYINFLOG("v4.pri_dns=%s", inet_ntoa(data_res->v4.addr.pri_dns)); |
| 335 | LYINFLOG("v4.sec_dns=%s", inet_ntoa(data_res->v4.addr.sec_dns)); |
| 336 | |
| 337 | inet_ntop(AF_INET6, &(data_res->v6.addr.ip), buf_ip, sizeof(buf_ip)); |
| 338 | inet_ntop(AF_INET6, &(data_res->v6.addr.gateway), buf_gateway, sizeof(buf_gateway)); |
| 339 | inet_ntop(AF_INET6, &(data_res->v6.addr.pri_dns), buf_pri_dns, sizeof(buf_pri_dns)); |
| 340 | inet_ntop(AF_INET6, &(data_res->v6.addr.sec_dns), buf_sec_dns, sizeof(buf_sec_dns)); |
| 341 | LYINFLOG("v6.ip=%s, v6.gateway=%s, v6.pri_dns=%s, v6.sec_dns=%s\n" |
| 342 | , buf_ip, buf_gateway, buf_pri_dns, buf_sec_dns); |
| 343 | data_res->v4.stats.pkts_tx = 0; |
| 344 | data_res->v4.stats.pkts_rx = 0; |
| 345 | data_res->v4.stats.bytes_tx = 0; |
| 346 | data_res->v4.stats.bytes_rx = 0; |
| 347 | data_res->v4.stats.pkts_dropped_tx = 0; |
| 348 | data_res->v4.stats.pkts_dropped_rx = 0; |
| 349 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 350 | data_res->v6.stats.pkts_tx = 0; |
| 351 | data_res->v6.stats.pkts_rx = 0; |
| 352 | data_res->v6.stats.bytes_tx = 0; |
| 353 | data_res->v6.stats.bytes_rx = 0; |
| 354 | data_res->v6.stats.pkts_dropped_tx = 0; |
| 355 | data_res->v6.stats.pkts_dropped_rx = 0; |
| 356 | return ; |
| 357 | } |
| 358 | |
| 359 | void datacall_ipv4_status_judge(int state,qser_data_call_info_s *data_res) |
| 360 | { |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 361 | if(state != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 362 | { |
| 363 | data_res->v4.state = QSER_DATA_CALL_CONNECTED; |
| 364 | data_res->v4.reconnect = 1; |
| 365 | } |
| 366 | else |
| 367 | { |
| 368 | data_res->v4.state = QSER_DATA_CALL_DISCONNECTED; |
| 369 | data_res->v4.reconnect = 0; |
| 370 | } |
| 371 | return ; |
| 372 | } |
| 373 | |
| 374 | void datacall_ipv6_status_judge(int state,qser_data_call_info_s *data_res) |
| 375 | { |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 376 | if(state != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 377 | { |
| 378 | data_res->v6.state = QSER_DATA_CALL_CONNECTED; |
| 379 | data_res->v6.reconnect = 1; |
| 380 | } |
| 381 | else |
| 382 | { |
| 383 | data_res->v6.state = QSER_DATA_CALL_DISCONNECTED; |
| 384 | data_res->v6.reconnect = 0; |
| 385 | } |
| 386 | return ; |
| 387 | } |
| 388 | |
| 389 | |
| 390 | int apn_xml_add(qser_apn_add_s *apn,unsigned char *apn_num) |
| 391 | { |
| 392 | int node_num = 0; |
| 393 | char temp_buff[12]; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 394 | //xmlDocPtr apn_table_xml_pdoc = NULL; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 395 | xmlNodePtr node = NULL; |
| 396 | xmlNodePtr tmp_node = NULL; |
| 397 | xmlNodePtr sum_node = NULL; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 398 | |
| 399 | // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 400 | if(NULL == apn_table_xml_pdoc) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 401 | { |
| 402 | LYERRLOG("open xml file error"); |
| 403 | goto FAILED; |
| 404 | } |
| 405 | |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 406 | node = xmlDocGetRootElement(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 407 | if (NULL == node) |
| 408 | { |
| 409 | LYERRLOG("xmlDocGetRootElement() error"); |
| 410 | goto FAILED; |
| 411 | } |
| 412 | sum_node = node->xmlChildrenNode; |
| 413 | sum_node = sum_node->next; |
| 414 | while (sum_node != NULL) |
| 415 | { |
| 416 | if (xmlGetProp(sum_node, "profile_idx") == NULL) //Null Node |
| 417 | { |
| 418 | sum_node = sum_node->next; |
| 419 | continue; |
| 420 | } |
xf.li | f7c68e3 | 2023-10-10 23:18:42 -0700 | [diff] [blame] | 421 | else if(strcmp((char *)xmlGetProp(sum_node, "apn_type"), apn->apn_type) == 0) |
| 422 | { |
| 423 | LYERRLOG("apntype already exists\n"); |
| 424 | goto FAILED; |
| 425 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 426 | node_num++; |
| 427 | sum_node = sum_node->next; |
| 428 | } |
xf.li | 3f891cb | 2023-08-23 23:11:24 -0700 | [diff] [blame] | 429 | LYINFLOG("apn_num = %d ",node_num); |
| 430 | if(node_num >= QSER_APN_MAX_LIST) |
| 431 | { |
| 432 | LYERRLOG("apn num reached the max"); |
| 433 | goto FAILED; |
| 434 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 435 | tmp_node = xmlNewNode(NULL,BAD_CAST"apn"); |
| 436 | *apn_num = node_num; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 437 | bzero(temp_buff,12); |
| 438 | snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num); |
| 439 | xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 440 | bzero(temp_buff,12); |
| 441 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type); |
| 442 | xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff); |
| 443 | bzero(temp_buff,12); |
| 444 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto); |
| 445 | xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff); |
| 446 | xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name); |
| 447 | xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username); |
| 448 | xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password); |
| 449 | xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type); |
| 450 | xmlAddChild(node,tmp_node); |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 451 | xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1); |
| 452 | |
| 453 | // xmlFreeDoc(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 454 | return RESULT_OK; |
| 455 | |
| 456 | FAILED: |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 457 | /* if (apn_table_xml_pdoc) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 458 | { |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 459 | xmlFreeDoc(apn_table_xml_pdoc); |
| 460 | }*/ |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 461 | return RESULT_ERROR; |
| 462 | } |
| 463 | |
| 464 | int apn_xml_delete(unsigned char profile_idx) |
| 465 | { |
| 466 | int node_num = 0; |
| 467 | char temp_buff[12]; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 468 | //xmlDocPtr apn_table_xml_pdoc = NULL; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 469 | xmlNodePtr node = NULL; |
| 470 | xmlNodePtr modify_node = NULL; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 471 | // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 472 | if(NULL == apn_table_xml_pdoc) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 473 | { |
| 474 | LYERRLOG("open xml file error"); |
| 475 | goto FAILED; |
| 476 | } |
| 477 | |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 478 | node = xmlDocGetRootElement(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 479 | if (NULL == node) |
| 480 | { |
| 481 | LYERRLOG("xmlDocGetRootElement() error"); |
| 482 | goto FAILED; |
| 483 | } |
| 484 | modify_node = node->xmlChildrenNode; |
xf.li | 029a9e7 | 2023-11-04 02:29:45 -0700 | [diff] [blame] | 485 | if(modify_node != NULL) |
| 486 | { |
| 487 | modify_node = modify_node->next; |
| 488 | } |
| 489 | else |
| 490 | { |
| 491 | LYERRLOG("modify_node is null\n"); |
| 492 | goto FAILED; |
| 493 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 494 | for (node_num=0 ;node_num<(int)profile_idx ; node_num++) |
| 495 | { |
xf.li | 029a9e7 | 2023-11-04 02:29:45 -0700 | [diff] [blame] | 496 | if(modify_node == NULL) |
| 497 | { |
| 498 | LYERRLOG("modify_node is null\n"); |
| 499 | goto FAILED; |
| 500 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 501 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 502 | { |
| 503 | modify_node = modify_node->next; |
| 504 | node_num--; |
| 505 | continue; |
| 506 | } |
| 507 | modify_node = modify_node->next; |
| 508 | } |
xf.li | 029a9e7 | 2023-11-04 02:29:45 -0700 | [diff] [blame] | 509 | if(modify_node == NULL) |
| 510 | { |
| 511 | LYERRLOG("modify_node is null\n"); |
| 512 | goto FAILED; |
| 513 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 514 | xmlUnlinkNode(modify_node); |
| 515 | xmlFreeNode(modify_node); |
| 516 | modify_node = NULL; |
| 517 | node_num = 0; |
| 518 | modify_node = node->xmlChildrenNode; |
| 519 | modify_node = modify_node->next; |
| 520 | while (modify_node != NULL) |
| 521 | { |
| 522 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 523 | { |
| 524 | modify_node = modify_node->next; |
| 525 | continue; |
| 526 | } |
| 527 | bzero(temp_buff,12); |
| 528 | snprintf(temp_buff,sizeof(temp_buff),"%d",node_num); |
| 529 | xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 530 | modify_node = modify_node->next; |
| 531 | node_num++; |
| 532 | } |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 533 | xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1); |
| 534 | // xmlFreeDoc(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 535 | return RESULT_OK; |
| 536 | |
| 537 | FAILED: |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 538 | // if (apn_table_xml_pdoc) |
| 539 | // { |
| 540 | // xmlFreeDoc(apn_table_xml_pdoc); |
| 541 | // } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 542 | return RESULT_ERROR; |
| 543 | } |
| 544 | |
| 545 | int apn_xml_modify(qser_apn_info_s *apn) |
| 546 | { |
| 547 | int node_num = 0; |
| 548 | char temp_buff[12]; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 549 | //xmlDocPtr apn_table_xml_pdoc = NULL; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 550 | xmlNodePtr node = NULL; |
| 551 | xmlNodePtr modify_node = NULL; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 552 | // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 553 | if(NULL == apn_table_xml_pdoc) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 554 | { |
| 555 | LYERRLOG("open xml file error"); |
| 556 | goto FAILED; |
| 557 | } |
| 558 | |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 559 | node = xmlDocGetRootElement(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 560 | if (NULL == node) |
| 561 | { |
| 562 | LYERRLOG("xmlDocGetRootElement() error"); |
| 563 | goto FAILED; |
| 564 | } |
| 565 | modify_node = node->xmlChildrenNode; |
xf.li | fb8bf04 | 2023-12-13 18:09:49 -0800 | [diff] [blame^] | 566 | if(modify_node != NULL) |
| 567 | { |
| 568 | modify_node = modify_node->next; |
| 569 | } |
| 570 | else |
| 571 | { |
| 572 | LYERRLOG("modify_node is null\n"); |
| 573 | goto FAILED; |
| 574 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 575 | for (node_num=0; node_num<(int)apn->profile_idx;node_num++) |
| 576 | { |
xf.li | fb8bf04 | 2023-12-13 18:09:49 -0800 | [diff] [blame^] | 577 | if(modify_node == NULL) |
| 578 | { |
| 579 | LYERRLOG("modify_node is null\n"); |
| 580 | goto FAILED; |
| 581 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 582 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 583 | { |
| 584 | modify_node = modify_node->next; |
| 585 | node_num--; |
| 586 | continue; |
| 587 | } |
| 588 | modify_node = modify_node->next; |
| 589 | } |
xf.li | fb8bf04 | 2023-12-13 18:09:49 -0800 | [diff] [blame^] | 590 | if(modify_node == NULL) |
| 591 | { |
| 592 | LYERRLOG("modify_node is null\n"); |
| 593 | goto FAILED; |
| 594 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 595 | bzero(temp_buff,12); |
| 596 | snprintf(temp_buff,sizeof(temp_buff),"%d",node_num); |
| 597 | xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 598 | bzero(temp_buff,12); |
| 599 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type); |
| 600 | xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff); |
| 601 | bzero(temp_buff,12); |
| 602 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto); |
| 603 | xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff); |
| 604 | xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name); |
| 605 | xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username); |
| 606 | xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password); |
| 607 | xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type); |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 608 | xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1); |
| 609 | // xmlFreeDoc(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 610 | return RESULT_OK; |
| 611 | |
| 612 | FAILED: |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 613 | // if (apn_table_xml_pdoc) |
| 614 | // { |
| 615 | // xmlFreeDoc(apn_table_xml_pdoc); |
| 616 | // } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 617 | return RESULT_ERROR; |
| 618 | } |
| 619 | |
| 620 | |
| 621 | int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn) |
| 622 | { |
| 623 | int node_num = 0; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 624 | //xmlDocPtr apn_table_xml_pdoc = NULL; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 625 | xmlNodePtr node = NULL; |
| 626 | xmlNodePtr modify_node = NULL; |
| 627 | unsigned char temp = NULL; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 628 | // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 629 | if(NULL == apn_table_xml_pdoc) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 630 | { |
| 631 | LYERRLOG("open xml file error"); |
| 632 | goto FAILED; |
| 633 | } |
| 634 | |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 635 | node = xmlDocGetRootElement(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 636 | if (NULL == node) |
| 637 | { |
| 638 | LYERRLOG("xmlDocGetRootElement() error"); |
| 639 | goto FAILED; |
| 640 | } |
| 641 | modify_node = node->xmlChildrenNode; |
xf.li | bf9df4c | 2023-07-02 02:42:35 -0700 | [diff] [blame] | 642 | if(modify_node != NULL) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 643 | { |
xf.li | bf9df4c | 2023-07-02 02:42:35 -0700 | [diff] [blame] | 644 | modify_node = modify_node->next; |
| 645 | } |
| 646 | else |
| 647 | { |
| 648 | LYERRLOG("modify_node is null\n"); |
| 649 | goto FAILED; |
| 650 | } |
| 651 | LYINFLOG("profile_idx is %d\n", (int)profile_idx); |
| 652 | for (node_num = 0;(node_num<(int)profile_idx);node_num++) |
| 653 | { |
| 654 | if(modify_node == NULL) |
| 655 | { |
| 656 | LYERRLOG("modify_node is null\n"); |
| 657 | goto FAILED; |
| 658 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 659 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 660 | { |
| 661 | modify_node = modify_node->next; |
| 662 | node_num--; |
| 663 | continue; |
| 664 | } |
| 665 | modify_node = modify_node->next; |
xf.li | 029a9e7 | 2023-11-04 02:29:45 -0700 | [diff] [blame] | 666 | } |
| 667 | if(modify_node == NULL) |
| 668 | { |
| 669 | LYERRLOG("modify_node is null\n"); |
| 670 | goto FAILED; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 671 | } |
| 672 | apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx")); |
| 673 | apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type")); |
| 674 | apn->auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto")); |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 675 | strncpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE); |
| 676 | strncpy(apn->username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE); |
| 677 | strncpy(apn->password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE); |
| 678 | strncpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE); |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 679 | // xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1); |
| 680 | // xmlFreeDoc(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 681 | return RESULT_OK; |
| 682 | |
| 683 | FAILED: |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 684 | // if (apn_table_xml_pdoc) |
| 685 | // { |
| 686 | // xmlFreeDoc(apn_table_xml_pdoc); |
| 687 | // } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 688 | return RESULT_ERROR; |
| 689 | } |
| 690 | |
| 691 | int apn_xml_query_list(qser_apn_info_list_s *apn_list) |
| 692 | { |
| 693 | int node_num = 0; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 694 | //xmlDocPtr apn_table_xml_pdoc = NULL; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 695 | xmlNodePtr node = NULL; |
| 696 | xmlNodePtr modify_node = NULL; |
| 697 | xmlChar *temp_char; |
| 698 | char temp[64]; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 699 | // apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 700 | if(NULL == apn_table_xml_pdoc) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 701 | { |
| 702 | LYERRLOG("open xml file error"); |
| 703 | goto FAILED; |
| 704 | } |
| 705 | |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 706 | node = xmlDocGetRootElement(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 707 | if (NULL == node) |
| 708 | { |
| 709 | LYERRLOG("xmlDocGetRootElement() error"); |
| 710 | goto FAILED; |
| 711 | } |
| 712 | modify_node = node->xmlChildrenNode; |
| 713 | modify_node = modify_node->next; |
| 714 | while (modify_node != NULL) |
| 715 | { |
| 716 | temp_char = xmlGetProp(modify_node, "profile_idx"); |
| 717 | if (temp_char == NULL) |
| 718 | { |
| 719 | modify_node = modify_node->next; |
| 720 | continue; |
| 721 | } |
| 722 | sprintf(temp,"%s",temp_char); |
| 723 | apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp); |
| 724 | apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type")); |
| 725 | apn_list->apn[node_num].auth_proto = (qser_apn_auth_proto_e)atoi(xmlGetProp(modify_node, "auth_proto")); |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 726 | strncpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE); |
| 727 | strncpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE); |
| 728 | strncpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE); |
| 729 | strncpy(apn_list->apn[node_num].apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 730 | node_num ++; |
| 731 | modify_node = modify_node->next; |
| 732 | } |
| 733 | apn_list->cnt = node_num; |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 734 | // xmlSaveFormatFileEnc(data_xml_path, apn_table_xml_pdoc, "UTF-8", 1); |
| 735 | // xmlFreeDoc(apn_table_xml_pdoc); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 736 | return RESULT_OK; |
| 737 | |
| 738 | FAILED: |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 739 | // if (apn_table_xml_pdoc) |
| 740 | // { |
| 741 | // xmlFreeDoc(apn_table_xml_pdoc); |
| 742 | // } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 743 | return RESULT_ERROR; |
| 744 | } |
| 745 | |
| 746 | void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type) |
| 747 | { |
| 748 | switch (pdp_type) |
| 749 | { |
| 750 | case QSER_APN_PDP_TYPE_IPV4: |
xf.li | 9e27f3d | 2023-11-30 00:43:13 -0800 | [diff] [blame] | 751 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 752 | strcpy(out_pdp_type,"IP"); |
| 753 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 754 | strcpy(out_pdp_type,"IPV4"); |
xf.li | 9e27f3d | 2023-11-30 00:43:13 -0800 | [diff] [blame] | 755 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 756 | break; |
| 757 | case QSER_APN_PDP_TYPE_PPP: |
| 758 | strcpy(out_pdp_type,"PPP"); |
| 759 | break; |
| 760 | case QSER_APN_PDP_TYPE_IPV6: |
| 761 | strcpy(out_pdp_type,"IPV6"); |
| 762 | break; |
| 763 | case QSER_APN_PDP_TYPE_IPV4V6: |
| 764 | strcpy(out_pdp_type,"IPV4V6"); |
| 765 | break; |
| 766 | default: |
| 767 | strcpy(out_pdp_type,"NULL"); |
| 768 | break; |
| 769 | } |
| 770 | return; |
| 771 | } |
| 772 | void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto) |
| 773 | { |
| 774 | switch (auth_proto) |
| 775 | { |
| 776 | case QSER_APN_AUTH_PROTO_DEFAULT: |
| 777 | strcpy(out_proto,"NULL;authType=0"); |
| 778 | break; |
| 779 | case QSER_APN_AUTH_PROTO_NONE: |
| 780 | strcpy(out_proto,"NULL;authType=1"); |
| 781 | break; |
| 782 | case QSER_APN_AUTH_PROTO_PAP: |
| 783 | strcpy(out_proto,"NULL;authType=2"); |
| 784 | break; |
| 785 | case QSER_APN_AUTH_PROTO_CHAP: |
| 786 | strcpy(out_proto,"NULL;authtype=3"); |
| 787 | break; |
| 788 | case QSER_APN_AUTH_PROTO_PAP_CHAP: |
| 789 | strcpy(out_proto,"NULL;authtype=4"); |
| 790 | break; |
| 791 | default: |
| 792 | strcpy(out_proto,"NULL;authType=NULL"); |
| 793 | break; |
| 794 | } |
| 795 | return ; |
| 796 | } |
| 797 | |
| 798 | int data_call_handle_get(const char profile_idx,int *handle) |
| 799 | { |
| 800 | int num = LYNQ_APN_CHANNEL_MAX; |
| 801 | int table_num = 0; |
| 802 | lynq_apn_info **apn_table = NULL; |
| 803 | qser_apn_info_s apn; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 804 | int ret = 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 805 | apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX); |
| 806 | if (NULL == apn_table) |
| 807 | { |
| 808 | LYERRLOG("malloc apn_table fail "); |
| 809 | return RESULT_ERROR; |
| 810 | } |
| 811 | for(int i =0;i<10;i++) |
| 812 | { |
| 813 | apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info)); |
| 814 | if (apn_table[i]==NULL) |
| 815 | { |
| 816 | for (int n=0;n<i;n++) |
| 817 | { |
| 818 | free(apn_table[n]); |
| 819 | } |
| 820 | return RESULT_ERROR; |
| 821 | } |
| 822 | memset(apn_table[i],0,sizeof(lynq_apn_info)); |
| 823 | } |
| 824 | lynq_get_apn_table(&table_num,apn_table); |
| 825 | memset(&apn,0,sizeof(qser_apn_info_s)); |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 826 | ret = apn_xml_query(profile_idx,&apn); |
| 827 | if (ret < 0) |
| 828 | { |
| 829 | LYERRLOG("apn_xml_query error"); |
| 830 | return ret; |
| 831 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 832 | for (int j = 0;j < table_num;j++) |
| 833 | { |
| 834 | if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0) |
| 835 | { |
| 836 | *handle = apn_table[j]->index; |
| 837 | LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle); |
| 838 | break; |
| 839 | } |
| 840 | } |
| 841 | |
| 842 | for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++) |
| 843 | { |
| 844 | if (apn_table[i]!=NULL) |
| 845 | { |
| 846 | free(apn_table[i]); |
| 847 | apn_table[i]=NULL; |
| 848 | } |
| 849 | } |
| 850 | free(apn_table); |
| 851 | apn_table=NULL; |
| 852 | LYINFLOG("data_call_handle_get end"); |
| 853 | return RESULT_OK; |
| 854 | } |
| 855 | |
| 856 | void *thread_wait_cb_status(void) |
| 857 | { |
| 858 | int handle = -1; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 859 | int ret = 0; |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 860 | lynq_data_call_response_v11_t data_urc_info = {0}; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 861 | qser_data_call_state_s data_cb_state; |
| 862 | while (s_qser_data_cb_thread_status) |
| 863 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 864 | ret = lynq_wait_data_call_state_change(&handle); |
| 865 | LYINFLOG("ret = %d, wait data call state change end!!!\n", ret); |
| 866 | if(s_qser_data_cb_thread_status == 0) |
| 867 | { |
| 868 | return NULL; |
| 869 | } |
| 870 | else if(ret < 0) |
| 871 | { |
| 872 | continue; |
| 873 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 874 | LYINFLOG("[thread_wait_cb_status]: handle = %d", handle); |
| 875 | memset(&data_urc_info, 0, sizeof(data_urc_info)); |
| 876 | memset(&data_cb_state, 0, sizeof(data_cb_state)); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 877 | lynq_get_data_call_list(&handle,&data_urc_info); |
| 878 | /*compare paramter*/ |
| 879 | data_cb_state.profile_idx = (char)handle; |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 880 | LYINFLOG("[thread_wait_cb_status]: status=%d, suggestedRetryTime=%d, cid=%d, active=%d, type=%s, ifname=%s, addresses=%s, dnses=%s, gateways=%s, pcscf=%s, mtu=%d\n", |
| 881 | data_urc_info.status, data_urc_info.suggestedRetryTime, data_urc_info.cid, data_urc_info.active, |
| 882 | data_urc_info.type, data_urc_info.ifname, data_urc_info.addresses, data_urc_info.dnses, data_urc_info.gateways, data_urc_info.pcscf, |
| 883 | data_urc_info.mtu); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 884 | 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] | 885 | 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] | 886 | { |
| 887 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4; |
| 888 | } |
| 889 | else if (!strcmp(data_urc_info.type,"IPV6")) |
| 890 | { |
| 891 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6; |
| 892 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 893 | else if (!strcmp(data_urc_info.type,"IPV4V6")) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 894 | { |
| 895 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 896 | } |
| 897 | else |
| 898 | { |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 899 | LYERRLOG("unknow data call type: %s", data_urc_info.type); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 900 | } |
| 901 | |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 902 | if (data_urc_info.active != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 903 | { |
| 904 | data_cb_state.state = QSER_DATA_CALL_CONNECTED; |
| 905 | } |
| 906 | else |
| 907 | { |
| 908 | data_cb_state.state = QSER_DATA_CALL_DISCONNECTED; |
| 909 | } |
| 910 | if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4) |
| 911 | { |
| 912 | lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state); |
| 913 | } |
| 914 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6) |
| 915 | { |
| 916 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 917 | } |
| 918 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6) |
| 919 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 920 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 921 | lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 922 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 923 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 924 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 925 | } |
| 926 | else |
| 927 | { |
| 928 | LYERRLOG("unknow ip_family"); |
| 929 | continue; |
| 930 | } |
| 931 | if (s_data_call_cb != NULL) |
| 932 | { |
| 933 | s_data_call_cb(&data_cb_state); |
| 934 | } |
| 935 | } |
| 936 | return NULL; |
| 937 | } |
| 938 | |
| 939 | int qser_cb_pthread_create() |
| 940 | { |
| 941 | int ret; |
| 942 | s_qser_data_cb_thread_status = 1; |
| 943 | ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL); |
| 944 | if (ret < 0) |
| 945 | { |
| 946 | LYERRLOG("pthread create fail"); |
| 947 | s_qser_data_cb_thread_status = 0; |
| 948 | return RESULT_ERROR; |
| 949 | } |
| 950 | return RESULT_OK; |
| 951 | } |
| 952 | |
| 953 | void qser_cb_pthread_cancel() |
| 954 | { |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 955 | s_qser_data_cb_thread_status = 0; |
| 956 | if (s_cb_tid != -1) |
| 957 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 958 | lynq_release_wait_data_call(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 959 | } |
| 960 | return; |
| 961 | } |
xf.li | 7b0bfd0 | 2023-08-03 01:11:52 -0700 | [diff] [blame] | 962 | int check_xml_file(const char *file) |
| 963 | { |
| 964 | /* Check for existence */ |
| 965 | if((access(file, F_OK)) == -1) |
| 966 | { |
| 967 | LYERRLOG("no such xml file.\n"); |
| 968 | system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/"); |
| 969 | } |
| 970 | |
| 971 | if((access(file, F_OK)) == -1) |
| 972 | { |
| 973 | LYERRLOG("error copy xml file.\n"); |
| 974 | return -1; |
| 975 | } |
| 976 | return RESULT_OK; |
| 977 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 978 | |
| 979 | int qser_data_call_init(qser_data_call_evt_cb_t evt_cb) |
| 980 | { |
| 981 | int ret = 0; |
| 982 | int utoken = 0; |
| 983 | if (NULL == evt_cb) |
| 984 | { |
| 985 | LYERRLOG("init incoming paramters error"); |
| 986 | return RESULT_ERROR; |
| 987 | } |
xf.li | 7b0bfd0 | 2023-08-03 01:11:52 -0700 | [diff] [blame] | 988 | |
| 989 | ret = check_xml_file(data_xml_path); |
| 990 | if (ret != RESULT_OK) |
| 991 | { |
| 992 | LYERRLOG("check xml file error"); |
| 993 | return RESULT_ERROR; |
| 994 | } |
| 995 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 996 | s_data_call_cb = evt_cb; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 997 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 998 | ret = lynq_init_data(utoken); |
| 999 | if (ret != RESULT_OK) |
| 1000 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1001 | //qser_cb_pthread_cancel(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1002 | s_data_call_cb = NULL; |
| 1003 | return RESULT_ERROR; |
| 1004 | } |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1005 | qser_cb_pthread_create(); |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 1006 | apn_table_xml_pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 1007 | if(NULL == apn_table_xml_pdoc) |
| 1008 | { |
| 1009 | LYERRLOG("open xml file error"); |
| 1010 | return RESULT_ERROR; |
| 1011 | } |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1012 | g_lynq_qser_data_init_flag = 1; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1013 | return RESULT_OK; |
| 1014 | } |
| 1015 | |
| 1016 | void qser_data_call_destroy(void) |
| 1017 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1018 | LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__); |
xf.li | e3f55f4 | 2023-12-01 22:47:33 -0800 | [diff] [blame] | 1019 | if(apn_table_xml_pdoc) |
| 1020 | { |
| 1021 | xmlFreeDoc(apn_table_xml_pdoc); |
| 1022 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1023 | lynq_deinit_data(); |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1024 | qser_cb_pthread_cancel(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1025 | s_data_call_cb = NULL; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1026 | g_lynq_qser_data_init_flag = 0; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 1027 | LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1028 | return ; |
| 1029 | } |
| 1030 | |
| 1031 | int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 1032 | { |
| 1033 | int ret = -1; |
| 1034 | int handle = 0; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1035 | if(g_lynq_qser_data_init_flag == 0) |
| 1036 | { |
| 1037 | if(err != NULL) |
| 1038 | { |
| 1039 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1040 | } |
| 1041 | return LYNQ_E_NO_INIT; |
| 1042 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1043 | if (NULL == data_call || NULL == err) |
| 1044 | { |
| 1045 | LYERRLOG("call start incoming paramters error"); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1046 | if(err != NULL) |
| 1047 | { |
| 1048 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1049 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1050 | return ret; |
| 1051 | } |
| 1052 | if (data_call->profile_idx == 0) |
| 1053 | { |
| 1054 | ret = lynq_setup_data_call(&handle); |
| 1055 | } |
| 1056 | else |
| 1057 | { |
| 1058 | char pdptype[16]; |
| 1059 | qser_apn_info_s apn_info; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1060 | ret = qser_apn_get(data_call->profile_idx,&apn_info); |
| 1061 | if (ret != 0) |
| 1062 | { |
| 1063 | LYERRLOG("qser_apn_get error"); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1064 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 1065 | return ret; |
| 1066 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1067 | judge_pdp_type(apn_info.pdp_type,pdptype); |
| 1068 | ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype); |
| 1069 | } |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1070 | if (ret != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1071 | { |
| 1072 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1073 | } |
| 1074 | return ret; |
| 1075 | } |
| 1076 | |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1077 | int qser_data_call_start_async(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 1078 | { |
| 1079 | int ret = -1; |
| 1080 | int handle = 0; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1081 | if(g_lynq_qser_data_init_flag == 0) |
| 1082 | { |
| 1083 | if(err != NULL) |
| 1084 | { |
| 1085 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1086 | } |
| 1087 | return LYNQ_E_NO_INIT; |
| 1088 | } |
xf.li | 8535bc0 | 2023-12-12 23:28:35 -0800 | [diff] [blame] | 1089 | if (NULL == data_call || NULL == err) |
| 1090 | { |
| 1091 | LYERRLOG("call start incoming paramters error"); |
| 1092 | if(err != NULL) |
| 1093 | { |
| 1094 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1095 | } |
| 1096 | return ret; |
| 1097 | } |
| 1098 | if (data_call->profile_idx == 0) |
| 1099 | { |
| 1100 | ret = lynq_setup_data_call_sp_t106_async(&handle,"default","default",NULL,NULL,NULL,NULL,NULL); |
| 1101 | } |
| 1102 | else |
| 1103 | { |
| 1104 | char pdptype[16]; |
| 1105 | qser_apn_info_s apn_info; |
| 1106 | ret = qser_apn_get(data_call->profile_idx,&apn_info); |
| 1107 | if (ret != 0) |
| 1108 | { |
| 1109 | LYERRLOG("qser_apn_get error"); |
| 1110 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1111 | return ret; |
| 1112 | } |
| 1113 | judge_pdp_type(apn_info.pdp_type,pdptype); |
| 1114 | ret = lynq_setup_data_call_sp_t106_async(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype); |
| 1115 | } |
| 1116 | if (ret != 0) |
| 1117 | { |
| 1118 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1119 | } |
| 1120 | return ret; |
| 1121 | } |
| 1122 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1123 | int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err) |
| 1124 | { |
| 1125 | int ret = 0; |
| 1126 | int handle = -1; |
| 1127 | |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1128 | if(g_lynq_qser_data_init_flag == 0) |
| 1129 | { |
| 1130 | if(err != NULL) |
| 1131 | { |
| 1132 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1133 | } |
| 1134 | return LYNQ_E_NO_INIT; |
| 1135 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1136 | if (NULL == err) |
| 1137 | { |
| 1138 | LYERRLOG("call stop incoming paramters error"); |
| 1139 | return ret; |
| 1140 | } |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1141 | ret = data_call_handle_get(profile_idx,&handle); |
| 1142 | if(ret != 0) |
| 1143 | { |
| 1144 | LYERRLOG("datacall handle get error"); |
| 1145 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 1146 | return ret; |
| 1147 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1148 | ret = lynq_deactive_data_call(&handle); |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1149 | if (ret != 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1150 | { |
| 1151 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
xf.li | c12b370 | 2023-11-22 22:39:01 -0800 | [diff] [blame] | 1152 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1153 | } |
xy.he | e2daacc | 2023-09-18 00:57:51 -0700 | [diff] [blame] | 1154 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1155 | } |
| 1156 | 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) |
| 1157 | { |
| 1158 | int ret = 0; |
| 1159 | int handle = -1; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1160 | if(g_lynq_qser_data_init_flag == 0) |
| 1161 | { |
| 1162 | if(err != NULL) |
| 1163 | { |
| 1164 | *err = QSER_DATA_CALL_ERROR_NO_INIT; |
| 1165 | } |
| 1166 | return LYNQ_E_NO_INIT; |
| 1167 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1168 | lynq_data_call_response_v11_t data_call_info; |
| 1169 | data_call_handle_get(profile_idx,&handle); |
| 1170 | ret = lynq_get_data_call_list(&handle,&data_call_info); |
| 1171 | if (ret == 0) |
| 1172 | { |
| 1173 | info->profile_idx = profile_idx; |
| 1174 | info->ip_family = ip_family; |
xf.li | 157f7e9 | 2023-10-19 23:22:46 -0700 | [diff] [blame] | 1175 | 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] | 1176 | { |
| 1177 | strcpy(info->v4.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1178 | datacall_ipv4_status_judge(data_call_info.active,info); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1179 | LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 1180 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
| 1181 | } |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1182 | else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1183 | { |
| 1184 | strcpy(info->v6.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1185 | datacall_ipv6_status_judge(data_call_info.active,info); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1186 | LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 1187 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
| 1188 | } |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1189 | else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1190 | { |
| 1191 | strcpy(info->v4.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1192 | datacall_ipv4_status_judge(data_call_info.active,info); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1193 | LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1194 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1195 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1196 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1197 | strcpy(info->v6.name,data_call_info.ifname); |
xf.li | b5dc063 | 2023-11-30 18:20:35 -0800 | [diff] [blame] | 1198 | datacall_ipv6_status_judge(data_call_info.active,info); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1199 | LYINFLOG("[IPV4V6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1200 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1201 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1202 | #endif |
| 1203 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1204 | lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info); |
| 1205 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1206 | } |
| 1207 | else |
| 1208 | { |
| 1209 | LYERRLOG("useless qser_data_call_ip_family_e"); |
| 1210 | } |
| 1211 | } |
| 1212 | return ret; |
| 1213 | } |
| 1214 | int qser_apn_set(qser_apn_info_s *apn) |
| 1215 | { |
| 1216 | int ret = 0; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1217 | if(g_lynq_qser_data_init_flag == 0) |
| 1218 | { |
| 1219 | return LYNQ_E_NO_INIT; |
| 1220 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1221 | if (NULL == apn) |
| 1222 | { |
| 1223 | LYERRLOG("apn set incoming paramters error"); |
| 1224 | return RESULT_ERROR; |
| 1225 | } |
| 1226 | ret = apn_xml_modify(apn); |
| 1227 | if (ret < 0) |
| 1228 | { |
| 1229 | LYERRLOG("apn_xml_modify error"); |
| 1230 | return ret; |
| 1231 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1232 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1233 | int apn_id = 0; |
| 1234 | char tmp_id[12]; |
| 1235 | char *outinfo = NULL; |
| 1236 | char normalprotocol[16]; |
| 1237 | char authtype[32]; |
| 1238 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1239 | bzero(tmp_id,12); |
| 1240 | bzero(outinfo,512); |
| 1241 | apn_id = apn->profile_idx + apndb_offset; |
| 1242 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1243 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 1244 | judge_authtype(apn->auth_proto,authtype); |
| 1245 | lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 1246 | LYINFLOG("[output]:%s",outinfo); |
| 1247 | free(outinfo); |
| 1248 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1249 | #endif |
| 1250 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn) |
| 1254 | { |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1255 | if(g_lynq_qser_data_init_flag == 0) |
| 1256 | { |
| 1257 | return LYNQ_E_NO_INIT; |
| 1258 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1259 | if (profile_idx < 0 || profile_idx > 24 || NULL == apn) |
| 1260 | { |
| 1261 | LYERRLOG("apn get incoming paramters error"); |
| 1262 | return RESULT_ERROR; |
| 1263 | } |
| 1264 | int ret = 0; |
| 1265 | ret = apn_xml_query(profile_idx,apn); |
| 1266 | if (ret < 0) |
| 1267 | { |
| 1268 | LYERRLOG("apn_xml_query error"); |
| 1269 | return ret; |
| 1270 | } |
| 1271 | return ret; |
| 1272 | } |
| 1273 | |
| 1274 | int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx) |
| 1275 | { |
| 1276 | int ret = 0; |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1277 | if(g_lynq_qser_data_init_flag == 0) |
| 1278 | { |
| 1279 | return LYNQ_E_NO_INIT; |
| 1280 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1281 | if (NULL == apn || NULL == profile_idx) |
| 1282 | { |
| 1283 | LYERRLOG("apn add incoming paramters error"); |
| 1284 | return RESULT_ERROR; |
| 1285 | } |
| 1286 | ret = apn_xml_add(apn,profile_idx); |
| 1287 | if (ret < 0) |
| 1288 | { |
| 1289 | LYERRLOG("apn_xml_add error"); |
| 1290 | return ret; |
| 1291 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1292 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1293 | int apn_id = 0; |
| 1294 | char tmp_id[12]; |
| 1295 | char *outinfo = NULL; |
| 1296 | char normalprotocol[16]; |
| 1297 | char authtype[32]; |
| 1298 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1299 | bzero(tmp_id,12); |
| 1300 | bzero(outinfo,512); |
| 1301 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1302 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 1303 | judge_authtype(apn->auth_proto,authtype); |
| 1304 | lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 1305 | LYINFLOG("[output]:%s",outinfo); |
| 1306 | free(outinfo); |
| 1307 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1308 | #endif |
| 1309 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | int qser_apn_del(unsigned char profile_idx) |
| 1313 | { |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1314 | if(g_lynq_qser_data_init_flag == 0) |
| 1315 | { |
| 1316 | return LYNQ_E_NO_INIT; |
| 1317 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1318 | if (profile_idx < 0 || profile_idx > 24) |
| 1319 | { |
| 1320 | LYERRLOG("apn del incoming paramters error"); |
| 1321 | return RESULT_OK; |
| 1322 | } |
| 1323 | int ret = 0; |
| 1324 | ret = apn_xml_delete(profile_idx); |
| 1325 | if (ret < 0) |
| 1326 | { |
| 1327 | LYERRLOG("apn_xml_delete error"); |
| 1328 | return ret; |
| 1329 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1330 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1331 | int apn_id = 0; |
| 1332 | char tmp_id[12]; |
| 1333 | char *outinfo = NULL; |
| 1334 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1335 | bzero(tmp_id,12); |
| 1336 | bzero(outinfo,512); |
| 1337 | apn_id = profile_idx+apndb_offset; |
| 1338 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1339 | lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo); |
| 1340 | LYINFLOG("[output]:%s",outinfo); |
| 1341 | free(outinfo); |
| 1342 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame] | 1343 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1344 | return ret; |
| 1345 | } |
| 1346 | |
| 1347 | int qser_apn_get_list(qser_apn_info_list_s *apn_list) |
| 1348 | { |
xf.li | b33d486 | 2023-12-13 00:40:37 -0800 | [diff] [blame] | 1349 | if(g_lynq_qser_data_init_flag == 0) |
| 1350 | { |
| 1351 | return LYNQ_E_NO_INIT; |
| 1352 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1353 | if (NULL == apn_list) |
| 1354 | { |
| 1355 | LYERRLOG("apn_list incoming paramters error"); |
| 1356 | return RESULT_ERROR; |
| 1357 | } |
| 1358 | int ret = 0; |
| 1359 | ret = apn_xml_query_list(apn_list); |
| 1360 | if (ret < 0) |
| 1361 | { |
| 1362 | LYERRLOG("apn_xml_query_list error"); |
| 1363 | return ret; |
| 1364 | } |
| 1365 | return ret; |
xf.li | 3f891cb | 2023-08-23 23:11:24 -0700 | [diff] [blame] | 1366 | } |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 1367 | |
| 1368 | DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA) |
| 1369 | |