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 | } |
xf.li | f7c68e3 | 2023-10-10 23:18:42 -0700 | [diff] [blame] | 414 | else if(strcmp((char *)xmlGetProp(sum_node, "apn_type"), apn->apn_type) == 0) |
| 415 | { |
| 416 | LYERRLOG("apntype already exists\n"); |
| 417 | goto FAILED; |
| 418 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 419 | node_num++; |
| 420 | sum_node = sum_node->next; |
| 421 | } |
xf.li | 3f891cb | 2023-08-23 23:11:24 -0700 | [diff] [blame] | 422 | LYINFLOG("apn_num = %d ",node_num); |
| 423 | if(node_num >= QSER_APN_MAX_LIST) |
| 424 | { |
| 425 | LYERRLOG("apn num reached the max"); |
| 426 | goto FAILED; |
| 427 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 428 | tmp_node = xmlNewNode(NULL,BAD_CAST"apn"); |
| 429 | *apn_num = node_num; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 430 | bzero(temp_buff,12); |
| 431 | snprintf(temp_buff,sizeof(temp_buff),"%d",*apn_num); |
| 432 | xmlNewProp(tmp_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 433 | bzero(temp_buff,12); |
| 434 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type); |
| 435 | xmlNewProp(tmp_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff); |
| 436 | bzero(temp_buff,12); |
| 437 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto); |
| 438 | xmlNewProp(tmp_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff); |
| 439 | xmlNewProp(tmp_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name); |
| 440 | xmlNewProp(tmp_node,BAD_CAST"username",(xmlChar *)apn->username); |
| 441 | xmlNewProp(tmp_node,BAD_CAST"password",(xmlChar *)apn->password); |
| 442 | xmlNewProp(tmp_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type); |
| 443 | xmlAddChild(node,tmp_node); |
| 444 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 445 | xmlFreeDoc(pdoc); |
| 446 | return RESULT_OK; |
| 447 | |
| 448 | FAILED: |
| 449 | if (pdoc) |
| 450 | { |
| 451 | xmlFreeDoc(pdoc); |
| 452 | } |
| 453 | return RESULT_ERROR; |
| 454 | } |
| 455 | |
| 456 | int apn_xml_delete(unsigned char profile_idx) |
| 457 | { |
| 458 | int node_num = 0; |
| 459 | char temp_buff[12]; |
| 460 | xmlDocPtr pdoc = NULL; |
| 461 | xmlNodePtr node = NULL; |
| 462 | xmlNodePtr modify_node = NULL; |
| 463 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 464 | if(NULL == pdoc) |
| 465 | { |
| 466 | LYERRLOG("open xml file error"); |
| 467 | goto FAILED; |
| 468 | } |
| 469 | |
| 470 | node = xmlDocGetRootElement(pdoc); |
| 471 | if (NULL == node) |
| 472 | { |
| 473 | LYERRLOG("xmlDocGetRootElement() error"); |
| 474 | goto FAILED; |
| 475 | } |
| 476 | modify_node = node->xmlChildrenNode; |
| 477 | modify_node = modify_node->next; |
| 478 | for (node_num=0 ;node_num<(int)profile_idx ; node_num++) |
| 479 | { |
| 480 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 481 | { |
| 482 | modify_node = modify_node->next; |
| 483 | node_num--; |
| 484 | continue; |
| 485 | } |
| 486 | modify_node = modify_node->next; |
| 487 | } |
| 488 | xmlUnlinkNode(modify_node); |
| 489 | xmlFreeNode(modify_node); |
| 490 | modify_node = NULL; |
| 491 | node_num = 0; |
| 492 | modify_node = node->xmlChildrenNode; |
| 493 | modify_node = modify_node->next; |
| 494 | while (modify_node != NULL) |
| 495 | { |
| 496 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 497 | { |
| 498 | modify_node = modify_node->next; |
| 499 | continue; |
| 500 | } |
| 501 | bzero(temp_buff,12); |
| 502 | snprintf(temp_buff,sizeof(temp_buff),"%d",node_num); |
| 503 | xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 504 | modify_node = modify_node->next; |
| 505 | node_num++; |
| 506 | } |
| 507 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 508 | xmlFreeDoc(pdoc); |
| 509 | return RESULT_OK; |
| 510 | |
| 511 | FAILED: |
| 512 | if (pdoc) |
| 513 | { |
| 514 | xmlFreeDoc(pdoc); |
| 515 | } |
| 516 | return RESULT_ERROR; |
| 517 | } |
| 518 | |
| 519 | int apn_xml_modify(qser_apn_info_s *apn) |
| 520 | { |
| 521 | int node_num = 0; |
| 522 | char temp_buff[12]; |
| 523 | xmlDocPtr pdoc = NULL; |
| 524 | xmlNodePtr node = NULL; |
| 525 | xmlNodePtr modify_node = NULL; |
| 526 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 527 | if(NULL == pdoc) |
| 528 | { |
| 529 | LYERRLOG("open xml file error"); |
| 530 | goto FAILED; |
| 531 | } |
| 532 | |
| 533 | node = xmlDocGetRootElement(pdoc); |
| 534 | if (NULL == node) |
| 535 | { |
| 536 | LYERRLOG("xmlDocGetRootElement() error"); |
| 537 | goto FAILED; |
| 538 | } |
| 539 | modify_node = node->xmlChildrenNode; |
| 540 | modify_node = modify_node->next; |
| 541 | for (node_num=0; node_num<(int)apn->profile_idx;node_num++) |
| 542 | { |
| 543 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 544 | { |
| 545 | modify_node = modify_node->next; |
| 546 | node_num--; |
| 547 | continue; |
| 548 | } |
| 549 | modify_node = modify_node->next; |
| 550 | } |
| 551 | bzero(temp_buff,12); |
| 552 | snprintf(temp_buff,sizeof(temp_buff),"%d",node_num); |
| 553 | xmlSetProp(modify_node,BAD_CAST"profile_idx",(xmlChar *)temp_buff); |
| 554 | bzero(temp_buff,12); |
| 555 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->pdp_type); |
| 556 | xmlSetProp(modify_node,BAD_CAST"pdp_type",(xmlChar *)temp_buff); |
| 557 | bzero(temp_buff,12); |
| 558 | snprintf(temp_buff,sizeof(temp_buff),"%d",apn->auth_proto); |
| 559 | xmlSetProp(modify_node,BAD_CAST"auth_proto",(xmlChar *)temp_buff); |
| 560 | xmlSetProp(modify_node,BAD_CAST"apn_name",(xmlChar *)apn->apn_name); |
| 561 | xmlSetProp(modify_node,BAD_CAST"username",(xmlChar *)apn->username); |
| 562 | xmlSetProp(modify_node,BAD_CAST"password",(xmlChar *)apn->password); |
| 563 | xmlSetProp(modify_node,BAD_CAST"apn_type",(xmlChar *)apn->apn_type); |
| 564 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 565 | xmlFreeDoc(pdoc); |
| 566 | return RESULT_OK; |
| 567 | |
| 568 | FAILED: |
| 569 | if (pdoc) |
| 570 | { |
| 571 | xmlFreeDoc(pdoc); |
| 572 | } |
| 573 | return RESULT_ERROR; |
| 574 | } |
| 575 | |
| 576 | |
| 577 | int apn_xml_query(unsigned char profile_idx,qser_apn_info_s *apn) |
| 578 | { |
| 579 | int node_num = 0; |
| 580 | xmlDocPtr pdoc = NULL; |
| 581 | xmlNodePtr node = NULL; |
| 582 | xmlNodePtr modify_node = NULL; |
| 583 | unsigned char temp = NULL; |
| 584 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 585 | if(NULL == pdoc) |
| 586 | { |
| 587 | LYERRLOG("open xml file error"); |
| 588 | goto FAILED; |
| 589 | } |
| 590 | |
| 591 | node = xmlDocGetRootElement(pdoc); |
| 592 | if (NULL == node) |
| 593 | { |
| 594 | LYERRLOG("xmlDocGetRootElement() error"); |
| 595 | goto FAILED; |
| 596 | } |
| 597 | modify_node = node->xmlChildrenNode; |
xf.li | bf9df4c | 2023-07-02 02:42:35 -0700 | [diff] [blame] | 598 | if(modify_node != NULL) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 599 | { |
xf.li | bf9df4c | 2023-07-02 02:42:35 -0700 | [diff] [blame] | 600 | modify_node = modify_node->next; |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | LYERRLOG("modify_node is null\n"); |
| 605 | goto FAILED; |
| 606 | } |
| 607 | LYINFLOG("profile_idx is %d\n", (int)profile_idx); |
| 608 | for (node_num = 0;(node_num<(int)profile_idx);node_num++) |
| 609 | { |
| 610 | if(modify_node == NULL) |
| 611 | { |
| 612 | LYERRLOG("modify_node is null\n"); |
| 613 | goto FAILED; |
| 614 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 615 | if (xmlGetProp(modify_node, "profile_idx") == NULL) //Null Node |
| 616 | { |
| 617 | modify_node = modify_node->next; |
| 618 | node_num--; |
| 619 | continue; |
| 620 | } |
| 621 | modify_node = modify_node->next; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 622 | if(modify_node == NULL) |
| 623 | { |
| 624 | LYERRLOG("modify_node is null\n"); |
| 625 | goto FAILED; |
| 626 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 627 | } |
| 628 | apn->profile_idx = (unsigned char)atoi(xmlGetProp(modify_node, "profile_idx")); |
| 629 | apn->pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type")); |
| 630 | 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^] | 631 | strncpy(apn->apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE); |
| 632 | strncpy(apn->username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE); |
| 633 | strncpy(apn->password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE); |
| 634 | strncpy(apn->apn_type,(char *)xmlGetProp(modify_node, "apn_type"), QSER_APN_NAME_SIZE); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 635 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 636 | xmlFreeDoc(pdoc); |
| 637 | return RESULT_OK; |
| 638 | |
| 639 | FAILED: |
| 640 | if (pdoc) |
| 641 | { |
| 642 | xmlFreeDoc(pdoc); |
| 643 | } |
| 644 | return RESULT_ERROR; |
| 645 | } |
| 646 | |
| 647 | int apn_xml_query_list(qser_apn_info_list_s *apn_list) |
| 648 | { |
| 649 | int node_num = 0; |
| 650 | xmlDocPtr pdoc = NULL; |
| 651 | xmlNodePtr node = NULL; |
| 652 | xmlNodePtr modify_node = NULL; |
| 653 | xmlChar *temp_char; |
| 654 | char temp[64]; |
| 655 | pdoc = xmlReadFile(data_xml_path ,"UTF-8",XML_PARSE_RECOVER); |
| 656 | if(NULL == pdoc) |
| 657 | { |
| 658 | LYERRLOG("open xml file error"); |
| 659 | goto FAILED; |
| 660 | } |
| 661 | |
| 662 | node = xmlDocGetRootElement(pdoc); |
| 663 | if (NULL == node) |
| 664 | { |
| 665 | LYERRLOG("xmlDocGetRootElement() error"); |
| 666 | goto FAILED; |
| 667 | } |
| 668 | modify_node = node->xmlChildrenNode; |
| 669 | modify_node = modify_node->next; |
| 670 | while (modify_node != NULL) |
| 671 | { |
| 672 | temp_char = xmlGetProp(modify_node, "profile_idx"); |
| 673 | if (temp_char == NULL) |
| 674 | { |
| 675 | modify_node = modify_node->next; |
| 676 | continue; |
| 677 | } |
| 678 | sprintf(temp,"%s",temp_char); |
| 679 | apn_list->apn[node_num].profile_idx = (unsigned char)atoi(temp); |
| 680 | apn_list->apn[node_num].pdp_type = (qser_apn_pdp_type_e)atoi(xmlGetProp(modify_node, "pdp_type")); |
| 681 | 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^] | 682 | strncpy(apn_list->apn[node_num].apn_name,(char *)xmlGetProp(modify_node, "apn_name"), QSER_APN_NAME_SIZE); |
| 683 | strncpy(apn_list->apn[node_num].username,(char *)xmlGetProp(modify_node, "username"), QSER_APN_USERNAME_SIZE); |
| 684 | strncpy(apn_list->apn[node_num].password,(char *)xmlGetProp(modify_node, "password"), QSER_APN_PASSWORD_SIZE); |
| 685 | 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] | 686 | node_num ++; |
| 687 | modify_node = modify_node->next; |
| 688 | } |
| 689 | apn_list->cnt = node_num; |
| 690 | xmlSaveFormatFileEnc(data_xml_path, pdoc, "UTF-8", 1); |
| 691 | xmlFreeDoc(pdoc); |
| 692 | return RESULT_OK; |
| 693 | |
| 694 | FAILED: |
| 695 | if (pdoc) |
| 696 | { |
| 697 | xmlFreeDoc(pdoc); |
| 698 | } |
| 699 | return RESULT_ERROR; |
| 700 | } |
| 701 | |
| 702 | void judge_pdp_type(qser_apn_pdp_type_e pdp_type,char *out_pdp_type) |
| 703 | { |
| 704 | switch (pdp_type) |
| 705 | { |
| 706 | case QSER_APN_PDP_TYPE_IPV4: |
| 707 | strcpy(out_pdp_type,"IPV4"); |
| 708 | break; |
| 709 | case QSER_APN_PDP_TYPE_PPP: |
| 710 | strcpy(out_pdp_type,"PPP"); |
| 711 | break; |
| 712 | case QSER_APN_PDP_TYPE_IPV6: |
| 713 | strcpy(out_pdp_type,"IPV6"); |
| 714 | break; |
| 715 | case QSER_APN_PDP_TYPE_IPV4V6: |
| 716 | strcpy(out_pdp_type,"IPV4V6"); |
| 717 | break; |
| 718 | default: |
| 719 | strcpy(out_pdp_type,"NULL"); |
| 720 | break; |
| 721 | } |
| 722 | return; |
| 723 | } |
| 724 | void judge_authtype(qser_apn_auth_proto_e auth_proto,char *out_proto) |
| 725 | { |
| 726 | switch (auth_proto) |
| 727 | { |
| 728 | case QSER_APN_AUTH_PROTO_DEFAULT: |
| 729 | strcpy(out_proto,"NULL;authType=0"); |
| 730 | break; |
| 731 | case QSER_APN_AUTH_PROTO_NONE: |
| 732 | strcpy(out_proto,"NULL;authType=1"); |
| 733 | break; |
| 734 | case QSER_APN_AUTH_PROTO_PAP: |
| 735 | strcpy(out_proto,"NULL;authType=2"); |
| 736 | break; |
| 737 | case QSER_APN_AUTH_PROTO_CHAP: |
| 738 | strcpy(out_proto,"NULL;authtype=3"); |
| 739 | break; |
| 740 | case QSER_APN_AUTH_PROTO_PAP_CHAP: |
| 741 | strcpy(out_proto,"NULL;authtype=4"); |
| 742 | break; |
| 743 | default: |
| 744 | strcpy(out_proto,"NULL;authType=NULL"); |
| 745 | break; |
| 746 | } |
| 747 | return ; |
| 748 | } |
| 749 | |
| 750 | int data_call_handle_get(const char profile_idx,int *handle) |
| 751 | { |
| 752 | int num = LYNQ_APN_CHANNEL_MAX; |
| 753 | int table_num = 0; |
| 754 | lynq_apn_info **apn_table = NULL; |
| 755 | qser_apn_info_s apn; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 756 | int ret = 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 757 | apn_table = (lynq_apn_info **)malloc(sizeof(lynq_apn_info *)*LYNQ_APN_CHANNEL_MAX); |
| 758 | if (NULL == apn_table) |
| 759 | { |
| 760 | LYERRLOG("malloc apn_table fail "); |
| 761 | return RESULT_ERROR; |
| 762 | } |
| 763 | for(int i =0;i<10;i++) |
| 764 | { |
| 765 | apn_table[i] = (lynq_apn_info*)malloc(sizeof(lynq_apn_info)); |
| 766 | if (apn_table[i]==NULL) |
| 767 | { |
| 768 | for (int n=0;n<i;n++) |
| 769 | { |
| 770 | free(apn_table[n]); |
| 771 | } |
| 772 | return RESULT_ERROR; |
| 773 | } |
| 774 | memset(apn_table[i],0,sizeof(lynq_apn_info)); |
| 775 | } |
| 776 | lynq_get_apn_table(&table_num,apn_table); |
| 777 | memset(&apn,0,sizeof(qser_apn_info_s)); |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 778 | ret = apn_xml_query(profile_idx,&apn); |
| 779 | if (ret < 0) |
| 780 | { |
| 781 | LYERRLOG("apn_xml_query error"); |
| 782 | return ret; |
| 783 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 784 | for (int j = 0;j < table_num;j++) |
| 785 | { |
| 786 | if (strcmp(apn.apn_type,apn_table[j]->apnType) == 0) |
| 787 | { |
| 788 | *handle = apn_table[j]->index; |
| 789 | LYINFLOG("apn_table->index:%d,handle:%d ",apn_table[j]->index,*handle); |
| 790 | break; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | for (int i = 0; i < LYNQ_APN_CHANNEL_MAX; i++) |
| 795 | { |
| 796 | if (apn_table[i]!=NULL) |
| 797 | { |
| 798 | free(apn_table[i]); |
| 799 | apn_table[i]=NULL; |
| 800 | } |
| 801 | } |
| 802 | free(apn_table); |
| 803 | apn_table=NULL; |
| 804 | LYINFLOG("data_call_handle_get end"); |
| 805 | return RESULT_OK; |
| 806 | } |
| 807 | |
| 808 | void *thread_wait_cb_status(void) |
| 809 | { |
| 810 | int handle = -1; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 811 | int ret = 0; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 812 | lynq_data_call_response_v11_t data_urc_info; |
| 813 | qser_data_call_state_s data_cb_state; |
| 814 | while (s_qser_data_cb_thread_status) |
| 815 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 816 | ret = lynq_wait_data_call_state_change(&handle); |
| 817 | LYINFLOG("ret = %d, wait data call state change end!!!\n", ret); |
| 818 | if(s_qser_data_cb_thread_status == 0) |
| 819 | { |
| 820 | return NULL; |
| 821 | } |
| 822 | else if(ret < 0) |
| 823 | { |
| 824 | continue; |
| 825 | } |
| 826 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 827 | lynq_get_data_call_list(&handle,&data_urc_info); |
| 828 | /*compare paramter*/ |
| 829 | data_cb_state.profile_idx = (char)handle; |
| 830 | |
| 831 | memcpy(data_cb_state.name,data_urc_info.ifname,strlen(data_urc_info.ifname)+1); |
| 832 | if (!strcmp(data_urc_info.type,"IPV4")) |
| 833 | { |
| 834 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4; |
| 835 | } |
| 836 | else if (!strcmp(data_urc_info.type,"IPV6")) |
| 837 | { |
| 838 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV6; |
| 839 | } |
| 840 | else if (strcmp(data_urc_info.type,"IPV4V6")) |
| 841 | { |
| 842 | data_cb_state.ip_family = QSER_DATA_CALL_TYPE_IPV4V6; |
| 843 | } |
| 844 | else |
| 845 | { |
| 846 | LYERRLOG("unknow data call type"); |
| 847 | continue; |
| 848 | } |
| 849 | |
| 850 | if (data_urc_info.status != 0) |
| 851 | { |
| 852 | data_cb_state.state = QSER_DATA_CALL_CONNECTED; |
| 853 | } |
| 854 | else |
| 855 | { |
| 856 | data_cb_state.state = QSER_DATA_CALL_DISCONNECTED; |
| 857 | } |
| 858 | if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4) |
| 859 | { |
| 860 | lynq_ipv4_aton_urc(&data_urc_info,&data_cb_state); |
| 861 | } |
| 862 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV6) |
| 863 | { |
| 864 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 865 | } |
| 866 | else if (data_cb_state.ip_family == QSER_DATA_CALL_TYPE_IPV4V6) |
| 867 | { |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 868 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 869 | lynq_ipv4v6_inet_pton_urc(&data_urc_info,&data_cb_state); |
| 870 | #else |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 871 | lynq_ipv6_inet_pton_urc(&data_urc_info,&data_cb_state); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 872 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 873 | } |
| 874 | else |
| 875 | { |
| 876 | LYERRLOG("unknow ip_family"); |
| 877 | continue; |
| 878 | } |
| 879 | if (s_data_call_cb != NULL) |
| 880 | { |
| 881 | s_data_call_cb(&data_cb_state); |
| 882 | } |
| 883 | } |
| 884 | return NULL; |
| 885 | } |
| 886 | |
| 887 | int qser_cb_pthread_create() |
| 888 | { |
| 889 | int ret; |
| 890 | s_qser_data_cb_thread_status = 1; |
| 891 | ret = pthread_create(&s_cb_tid,NULL,thread_wait_cb_status,NULL); |
| 892 | if (ret < 0) |
| 893 | { |
| 894 | LYERRLOG("pthread create fail"); |
| 895 | s_qser_data_cb_thread_status = 0; |
| 896 | return RESULT_ERROR; |
| 897 | } |
| 898 | return RESULT_OK; |
| 899 | } |
| 900 | |
| 901 | void qser_cb_pthread_cancel() |
| 902 | { |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 903 | s_qser_data_cb_thread_status = 0; |
| 904 | if (s_cb_tid != -1) |
| 905 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 906 | lynq_release_wait_data_call(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 907 | } |
| 908 | return; |
| 909 | } |
xf.li | 7b0bfd0 | 2023-08-03 01:11:52 -0700 | [diff] [blame] | 910 | int check_xml_file(const char *file) |
| 911 | { |
| 912 | /* Check for existence */ |
| 913 | if((access(file, F_OK)) == -1) |
| 914 | { |
| 915 | LYERRLOG("no such xml file.\n"); |
| 916 | system("cp /data/lynq_qser_data_apn.xml /mnt/userdata/"); |
| 917 | } |
| 918 | |
| 919 | if((access(file, F_OK)) == -1) |
| 920 | { |
| 921 | LYERRLOG("error copy xml file.\n"); |
| 922 | return -1; |
| 923 | } |
| 924 | return RESULT_OK; |
| 925 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 926 | |
| 927 | int qser_data_call_init(qser_data_call_evt_cb_t evt_cb) |
| 928 | { |
| 929 | int ret = 0; |
| 930 | int utoken = 0; |
| 931 | if (NULL == evt_cb) |
| 932 | { |
| 933 | LYERRLOG("init incoming paramters error"); |
| 934 | return RESULT_ERROR; |
| 935 | } |
xf.li | 7b0bfd0 | 2023-08-03 01:11:52 -0700 | [diff] [blame] | 936 | |
| 937 | ret = check_xml_file(data_xml_path); |
| 938 | if (ret != RESULT_OK) |
| 939 | { |
| 940 | LYERRLOG("check xml file error"); |
| 941 | return RESULT_ERROR; |
| 942 | } |
| 943 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 944 | s_data_call_cb = evt_cb; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 945 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 946 | ret = lynq_init_data(utoken); |
| 947 | if (ret != RESULT_OK) |
| 948 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 949 | //qser_cb_pthread_cancel(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 950 | s_data_call_cb = NULL; |
| 951 | return RESULT_ERROR; |
| 952 | } |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 953 | qser_cb_pthread_create(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 954 | return RESULT_OK; |
| 955 | } |
| 956 | |
| 957 | void qser_data_call_destroy(void) |
| 958 | { |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 959 | LYINFLOG("[%s] start [%d]",__FUNCTION__,__LINE__); |
| 960 | |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 961 | lynq_deinit_data(); |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 962 | qser_cb_pthread_cancel(); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 963 | s_data_call_cb = NULL; |
xf.li | 6b0d850 | 2023-09-04 18:49:12 -0700 | [diff] [blame] | 964 | LYINFLOG("[%s] end [%d]",__FUNCTION__,__LINE__); |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 965 | return ; |
| 966 | } |
| 967 | |
| 968 | int qser_data_call_start(qser_data_call_s *data_call, qser_data_call_error_e *err) |
| 969 | { |
| 970 | int ret = -1; |
| 971 | int handle = 0; |
| 972 | if (NULL == data_call || NULL == err) |
| 973 | { |
| 974 | LYERRLOG("call start incoming paramters error"); |
| 975 | return ret; |
| 976 | } |
| 977 | if (data_call->profile_idx == 0) |
| 978 | { |
| 979 | ret = lynq_setup_data_call(&handle); |
| 980 | } |
| 981 | else |
| 982 | { |
| 983 | char pdptype[16]; |
| 984 | qser_apn_info_s apn_info; |
xf.li | 0fc2650 | 2023-09-16 02:10:17 -0700 | [diff] [blame] | 985 | ret = qser_apn_get(data_call->profile_idx,&apn_info); |
| 986 | if (ret != 0) |
| 987 | { |
| 988 | LYERRLOG("qser_apn_get error"); |
| 989 | return ret; |
| 990 | } |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 991 | judge_pdp_type(apn_info.pdp_type,pdptype); |
| 992 | ret = lynq_setup_data_call_sp(&handle,apn_info.apn_name,apn_info.apn_type,apn_info.username,apn_info.password,NULL,pdptype,pdptype); |
| 993 | } |
| 994 | if (ret < 0) |
| 995 | { |
| 996 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
| 997 | } |
| 998 | return ret; |
| 999 | } |
| 1000 | |
| 1001 | int qser_data_call_stop(char profile_idx, qser_data_call_ip_family_e ip_family, qser_data_call_error_e *err) |
| 1002 | { |
| 1003 | int ret = 0; |
| 1004 | int handle = -1; |
| 1005 | |
| 1006 | if (NULL == err) |
| 1007 | { |
| 1008 | LYERRLOG("call stop incoming paramters error"); |
| 1009 | return ret; |
| 1010 | } |
| 1011 | data_call_handle_get(profile_idx,&handle); |
| 1012 | ret = lynq_deactive_data_call(&handle); |
| 1013 | if (ret < 0) |
| 1014 | { |
| 1015 | *err = QSER_DATA_CALL_ERROR_INVALID_PARAMS; |
xy.he | e2daacc | 2023-09-18 00:57:51 -0700 | [diff] [blame] | 1016 | return *err; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1017 | } |
xy.he | e2daacc | 2023-09-18 00:57:51 -0700 | [diff] [blame] | 1018 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1019 | } |
| 1020 | 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) |
| 1021 | { |
| 1022 | int ret = 0; |
| 1023 | int handle = -1; |
| 1024 | lynq_data_call_response_v11_t data_call_info; |
| 1025 | data_call_handle_get(profile_idx,&handle); |
| 1026 | ret = lynq_get_data_call_list(&handle,&data_call_info); |
| 1027 | if (ret == 0) |
| 1028 | { |
| 1029 | info->profile_idx = profile_idx; |
| 1030 | info->ip_family = ip_family; |
xf.li | 157f7e9 | 2023-10-19 23:22:46 -0700 | [diff] [blame] | 1031 | 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] | 1032 | { |
| 1033 | strcpy(info->v4.name,data_call_info.ifname); |
| 1034 | datacall_ipv4_status_judge(data_call_info.status,info); |
| 1035 | LYINFLOG("[IPV4]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 1036 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
| 1037 | } |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1038 | else if (strncmp(data_call_info.type,"IPV6", strlen("IPV6") + 1) == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1039 | { |
| 1040 | strcpy(info->v6.name,data_call_info.ifname); |
| 1041 | |
| 1042 | datacall_ipv6_status_judge(data_call_info.status,info); |
| 1043 | LYINFLOG("[IPV6]addresses:%s,gateways:%s,dnses:%s",data_call_info.addresses,data_call_info.gateways,data_call_info.dnses); |
| 1044 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
| 1045 | } |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1046 | else if (strncmp(data_call_info.type,"IPV4V6", strlen("IPV4V6") + 1) == 0) |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1047 | { |
| 1048 | strcpy(info->v4.name,data_call_info.ifname); |
| 1049 | datacall_ipv4_status_judge(data_call_info.status,info); |
| 1050 | 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] | 1051 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1052 | lynq_ipv4_aton_getinfo(&data_call_info,info); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1053 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1054 | strcpy(info->v6.name,data_call_info.ifname); |
| 1055 | datacall_ipv6_status_judge(data_call_info.status,info); |
| 1056 | 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] | 1057 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1058 | lynq_ipv6_inet_pton_getinfo(&data_call_info,info); |
xf.li | 3c0a475 | 2023-09-03 20:46:19 -0700 | [diff] [blame] | 1059 | #endif |
| 1060 | #ifdef MOBILETEK_TARGET_PLATFORM_T106 |
| 1061 | lynq_ipv4v6_inet_pton_getinfo(&data_call_info,info); |
| 1062 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1063 | } |
| 1064 | else |
| 1065 | { |
| 1066 | LYERRLOG("useless qser_data_call_ip_family_e"); |
| 1067 | } |
| 1068 | } |
| 1069 | return ret; |
| 1070 | } |
| 1071 | int qser_apn_set(qser_apn_info_s *apn) |
| 1072 | { |
| 1073 | int ret = 0; |
| 1074 | if (NULL == apn) |
| 1075 | { |
| 1076 | LYERRLOG("apn set incoming paramters error"); |
| 1077 | return RESULT_ERROR; |
| 1078 | } |
| 1079 | ret = apn_xml_modify(apn); |
| 1080 | if (ret < 0) |
| 1081 | { |
| 1082 | LYERRLOG("apn_xml_modify error"); |
| 1083 | return ret; |
| 1084 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame^] | 1085 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1086 | int apn_id = 0; |
| 1087 | char tmp_id[12]; |
| 1088 | char *outinfo = NULL; |
| 1089 | char normalprotocol[16]; |
| 1090 | char authtype[32]; |
| 1091 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1092 | bzero(tmp_id,12); |
| 1093 | bzero(outinfo,512); |
| 1094 | apn_id = apn->profile_idx + apndb_offset; |
| 1095 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1096 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 1097 | judge_authtype(apn->auth_proto,authtype); |
| 1098 | lynq_modify_apn_db(3,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 1099 | LYINFLOG("[output]:%s",outinfo); |
| 1100 | free(outinfo); |
| 1101 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame^] | 1102 | #endif |
| 1103 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | int qser_apn_get(unsigned char profile_idx, qser_apn_info_s *apn) |
| 1107 | { |
| 1108 | if (profile_idx < 0 || profile_idx > 24 || NULL == apn) |
| 1109 | { |
| 1110 | LYERRLOG("apn get incoming paramters error"); |
| 1111 | return RESULT_ERROR; |
| 1112 | } |
| 1113 | int ret = 0; |
| 1114 | ret = apn_xml_query(profile_idx,apn); |
| 1115 | if (ret < 0) |
| 1116 | { |
| 1117 | LYERRLOG("apn_xml_query error"); |
| 1118 | return ret; |
| 1119 | } |
| 1120 | return ret; |
| 1121 | } |
| 1122 | |
| 1123 | int qser_apn_add(qser_apn_add_s *apn, unsigned char *profile_idx) |
| 1124 | { |
| 1125 | int ret = 0; |
| 1126 | if (NULL == apn || NULL == profile_idx) |
| 1127 | { |
| 1128 | LYERRLOG("apn add incoming paramters error"); |
| 1129 | return RESULT_ERROR; |
| 1130 | } |
| 1131 | ret = apn_xml_add(apn,profile_idx); |
| 1132 | if (ret < 0) |
| 1133 | { |
| 1134 | LYERRLOG("apn_xml_add error"); |
| 1135 | return ret; |
| 1136 | } |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame^] | 1137 | #ifndef MOBILETEK_TARGET_PLATFORM_T106 |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1138 | int apn_id = 0; |
| 1139 | char tmp_id[12]; |
| 1140 | char *outinfo = NULL; |
| 1141 | char normalprotocol[16]; |
| 1142 | char authtype[32]; |
| 1143 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1144 | bzero(tmp_id,12); |
| 1145 | bzero(outinfo,512); |
| 1146 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1147 | judge_pdp_type(apn->pdp_type,normalprotocol); |
| 1148 | judge_authtype(apn->auth_proto,authtype); |
| 1149 | lynq_modify_apn_db(0,tmp_id,NULL,NULL,apn->apn_name,apn->apn_type,apn->username,apn->password,normalprotocol,normalprotocol,authtype,outinfo); |
| 1150 | LYINFLOG("[output]:%s",outinfo); |
| 1151 | free(outinfo); |
| 1152 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame^] | 1153 | #endif |
| 1154 | return ret; |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | int qser_apn_del(unsigned char profile_idx) |
| 1158 | { |
| 1159 | if (profile_idx < 0 || profile_idx > 24) |
| 1160 | { |
| 1161 | LYERRLOG("apn del incoming paramters error"); |
| 1162 | return RESULT_OK; |
| 1163 | } |
| 1164 | int ret = 0; |
| 1165 | ret = apn_xml_delete(profile_idx); |
| 1166 | if (ret < 0) |
| 1167 | { |
| 1168 | LYERRLOG("apn_xml_delete 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 | outinfo = (char *)malloc(sizeof(char)*512); |
| 1176 | bzero(tmp_id,12); |
| 1177 | bzero(outinfo,512); |
| 1178 | apn_id = profile_idx+apndb_offset; |
| 1179 | snprintf(tmp_id,sizeof(tmp_id),"%d",apn_id); |
| 1180 | lynq_modify_apn_db(1,tmp_id,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,outinfo); |
| 1181 | LYINFLOG("[output]:%s",outinfo); |
| 1182 | free(outinfo); |
| 1183 | outinfo = NULL; |
xf.li | 6c7e397 | 2023-10-27 20:01:59 -0700 | [diff] [blame^] | 1184 | #endif |
xf.li | 2fc8455 | 2023-06-23 05:26:47 -0700 | [diff] [blame] | 1185 | return ret; |
| 1186 | } |
| 1187 | |
| 1188 | int qser_apn_get_list(qser_apn_info_list_s *apn_list) |
| 1189 | { |
| 1190 | if (NULL == apn_list) |
| 1191 | { |
| 1192 | LYERRLOG("apn_list incoming paramters error"); |
| 1193 | return RESULT_ERROR; |
| 1194 | } |
| 1195 | int ret = 0; |
| 1196 | ret = apn_xml_query_list(apn_list); |
| 1197 | if (ret < 0) |
| 1198 | { |
| 1199 | LYERRLOG("apn_xml_query_list error"); |
| 1200 | return ret; |
| 1201 | } |
| 1202 | return ret; |
xf.li | 3f891cb | 2023-08-23 23:11:24 -0700 | [diff] [blame] | 1203 | } |
you.chen | 21c62b7 | 2023-09-08 09:41:11 +0800 | [diff] [blame] | 1204 | |
| 1205 | DEFINE_LYNQ_LIB_LOG(LYNQ_QSER_DATA) |
| 1206 | |