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