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