rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* Copyright Statement: |
| 2 | * |
| 3 | * This software/firmware and related documentation ("MediaTek Software") are |
| 4 | * protected under relevant copyright laws. The information contained herein is |
| 5 | * confidential and proprietary to MediaTek Inc. and/or its licensors. Without |
| 6 | * the prior written permission of MediaTek inc. and/or its licensors, any |
| 7 | * reproduction, modification, use or disclosure of MediaTek Software, and |
| 8 | * information contained herein, in whole or in part, shall be strictly |
| 9 | * prohibited. |
| 10 | * |
| 11 | * MediaTek Inc. (C) 2010. All rights reserved. |
| 12 | * |
| 13 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 14 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 15 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER |
| 16 | * ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL |
| 17 | * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED |
| 18 | * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR |
| 19 | * NONINFRINGEMENT. NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH |
| 20 | * RESPECT TO THE SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, |
| 21 | * INCORPORATED IN, OR SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES |
| 22 | * TO LOOK ONLY TO SUCH THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. |
| 23 | * RECEIVER EXPRESSLY ACKNOWLEDGES THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO |
| 24 | * OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES CONTAINED IN MEDIATEK |
| 25 | * SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE |
| 26 | * RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 27 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S |
| 28 | * ENTIRE AND CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE |
| 29 | * RELEASED HEREUNDER WILL BE, AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE |
| 30 | * MEDIATEK SOFTWARE AT ISSUE, OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE |
| 31 | * CHARGE PAID BY RECEIVER TO MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 32 | * |
| 33 | * The following software/firmware and/or related documentation ("MediaTek |
| 34 | * Software") have been modified by MediaTek Inc. All revisions are subject to |
| 35 | * any receiver's applicable license agreements with MediaTek Inc. |
| 36 | */ |
| 37 | |
| 38 | /* |
| 39 | * This is sample code for WLAN test library implementation |
| 40 | */ |
| 41 | |
| 42 | #include <stdio.h> |
| 43 | #include <stdint.h> |
| 44 | #include <sched.h> |
| 45 | #include <unistd.h> |
| 46 | #include <string.h> |
| 47 | #include <sys/ioctl.h> |
| 48 | #include <sys/types.h> |
| 49 | #include <sys/stat.h> |
| 50 | #include <fcntl.h> |
| 51 | #ifndef __linux__ |
| 52 | #include <net/if.h> |
| 53 | #endif |
| 54 | #include <arpa/inet.h> |
| 55 | |
| 56 | #ifdef ANDROID |
| 57 | #include <cutils/log.h> |
| 58 | #include <cutils/misc.h> /* load_file() */ |
| 59 | #include <libnvram.h> |
| 60 | #include <Custom_NvRam_LID.h> |
| 61 | #include <CFG_Wifi_File.h> |
| 62 | #endif |
| 63 | |
| 64 | #include "libwifitest.h" |
| 65 | |
| 66 | #define DBG 1 |
| 67 | |
| 68 | extern int init_module(void *, unsigned long, const char *); |
| 69 | |
| 70 | /******************************************************************************* |
| 71 | * M A C R O S |
| 72 | ******************************************************************************* |
| 73 | */ |
| 74 | |
| 75 | #ifndef BIT |
| 76 | #define BIT(n) ((uint32_t) 1 << (n)) |
| 77 | #define BITS(m,n) (~(BIT(m)-1) & ((BIT(n) - 1) | BIT(n))) |
| 78 | #endif /* BIT */ |
| 79 | |
| 80 | #define MAC_ADDR_LEN 6 |
| 81 | |
| 82 | #define IS_BMCAST_MAC_ADDR(_pucDestAddr) \ |
| 83 | ((bool) ( ((uint8_t *)(_pucDestAddr))[0] & BIT(0) )) |
| 84 | |
| 85 | #define EQUAL_MAC_ADDR(_pucDestAddr, _pucSrcAddr) \ |
| 86 | (!memcmp(_pucDestAddr, _pucSrcAddr, MAC_ADDR_LEN)) |
| 87 | |
| 88 | /* Debug print format string for the MAC Address */ |
| 89 | #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" |
| 90 | |
| 91 | /* Debug print argument for the MAC Address */ |
| 92 | #define MAC2STR(a) ((uint8_t *)a)[0], ((uint8_t *)a)[1], ((uint8_t *)a)[2], \ |
| 93 | ((uint8_t *)a)[3], ((uint8_t *)a)[4], ((uint8_t *)a)[5] |
| 94 | |
| 95 | /******************************************************************************* |
| 96 | * C O N S T A N T S |
| 97 | ******************************************************************************* |
| 98 | */ |
| 99 | |
| 100 | #ifndef WIFI_DRIVER_MODULE_PATH |
| 101 | #define WIFI_DRIVER_MODULE_PATH "/system/lib/modules/wlan.ko" |
| 102 | #endif |
| 103 | #ifndef WIFI_DRIVER_MODULE_NAME |
| 104 | #define WIFI_DRIVER_MODULE_NAME "wlan" |
| 105 | #endif |
| 106 | #ifndef WIFI_DRIVER_MODULE_ARG |
| 107 | #define WIFI_DRIVER_MODULE_ARG "" |
| 108 | #endif |
| 109 | |
| 110 | #if 0 |
| 111 | #ifndef WIFI_IF_NAME |
| 112 | #define WIFI_IF_NAME "wlan0" |
| 113 | #endif |
| 114 | #endif |
| 115 | |
| 116 | char WIFI_IF_NAME[256] = "wlan0"; |
| 117 | bool fgDebugMode = false; |
| 118 | |
| 119 | static const char DRIVER_PROP_NAME[] = "wlan.driver.status"; |
| 120 | static const char DRIVER_MODULE_NAME[] = WIFI_DRIVER_MODULE_NAME; |
| 121 | //static const char DRIVER_MODULE_TAG[] = WIFI_DRIVER_MODULE_NAME " "; |
| 122 | static const char DRIVER_MODULE_TAG[] = WIFI_DRIVER_MODULE_NAME; |
| 123 | static const char DRIVER_MODULE_PATH[] = WIFI_DRIVER_MODULE_PATH; |
| 124 | static const char DRIVER_MODULE_ARG[] = WIFI_DRIVER_MODULE_ARG; |
| 125 | static const char MODULE_FILE[] = "/proc/modules"; |
| 126 | |
| 127 | #define IOCTL_SET_STRUCT (SIOCIWFIRSTPRIV + 8) |
| 128 | #define IOCTL_GET_STRUCT (SIOCIWFIRSTPRIV + 9) |
| 129 | #define IOCTL_SET_STRUCT_FOR_EM (SIOCIWFIRSTPRIV + 11) |
| 130 | |
| 131 | #define PRIV_CMD_OID 15 |
| 132 | |
| 133 | /* RF Test specific OIDs */ |
| 134 | #define OID_CUSTOM_TEST_MODE 0xFFA0C901 |
| 135 | #define OID_CUSTOM_ABORT_TEST_MODE 0xFFA0C906 |
| 136 | #define OID_CUSTOM_MTK_WIFI_TEST_ 0xFFA0C911 |
| 137 | #define OID_CUSTOM_MCR_RW 0xFFA0c801 |
| 138 | |
| 139 | /* command mask */ |
| 140 | #define TEST_FUNC_IDX_MASK BITS(0,7) |
| 141 | #define TEST_SET_CMD_OFFSET_MASK BITS(16,31) |
| 142 | #define TEST_SET_CMD_OFFSET 16 |
| 143 | |
| 144 | /* RF Test Properties */ |
| 145 | #define RF_AT_PARAM_RATE_MCS_MASK BIT(31) |
| 146 | #define RF_AT_PARAM_RATE_MASK BITS(0,7) |
| 147 | #define RF_AT_PARAM_RATE_1M 0 |
| 148 | #define RF_AT_PARAM_RATE_2M 1 |
| 149 | #define RF_AT_PARAM_RATE_5_5M 2 |
| 150 | #define RF_AT_PARAM_RATE_11M 3 |
| 151 | #define RF_AT_PARAM_RATE_6M 4 |
| 152 | #define RF_AT_PARAM_RATE_9M 5 |
| 153 | #define RF_AT_PARAM_RATE_12M 6 |
| 154 | #define RF_AT_PARAM_RATE_18M 7 |
| 155 | #define RF_AT_PARAM_RATE_24M 8 |
| 156 | #define RF_AT_PARAM_RATE_36M 9 |
| 157 | #define RF_AT_PARAM_RATE_48M 10 |
| 158 | #define RF_AT_PARAM_RATE_54M 11 |
| 159 | |
| 160 | #define NULL_MAC_ADDR {0x00, 0x00, 0x00, 0x00, 0x00, 0x00} |
| 161 | |
| 162 | #ifndef ALOGD |
| 163 | #define ALOGD printf |
| 164 | #endif |
| 165 | #ifndef ALOGE |
| 166 | #define ALOGE printf |
| 167 | #endif |
| 168 | #ifndef ALOGW |
| 169 | #define ALOGW |
| 170 | #endif |
| 171 | |
| 172 | /******************************************************************************* |
| 173 | * D A T A T Y P E S |
| 174 | ******************************************************************************* |
| 175 | */ |
| 176 | typedef struct _NDIS_TRANSPORT_STRUCT { |
| 177 | uint32_t ndisOidCmd; |
| 178 | uint32_t inNdisOidlength; |
| 179 | uint32_t outNdisOidLength; |
| 180 | uint8_t ndisOidContent[16]; |
| 181 | } NDIS_TRANSPORT_STRUCT, *P_NDIS_TRANSPORT_STRUCT; |
| 182 | |
| 183 | typedef struct _PARAM_MTK_WIFI_TEST_STRUC_T { |
| 184 | uint32_t u4FuncIndex; |
| 185 | uint32_t u4FuncData; |
| 186 | } PARAM_MTK_WIFI_TEST_STRUC_T, *P_PARAM_MTK_WIFI_TEST_STRUC_T; |
| 187 | |
| 188 | typedef struct _PARAM_CUSTOM_MCR_RW_STRUC_T { |
| 189 | uint32_t u4McrOffset; |
| 190 | uint32_t u4McrData; |
| 191 | } PARAM_CUSTOM_MCR_RW_STRUC_T, *P_PARAM_CUSTOM_MCR_RW_STRUC_T; |
| 192 | |
| 193 | typedef enum _ENUM_RF_AT_BW_T { |
| 194 | |
| 195 | RF_AT_BW_20 = 0, |
| 196 | RF_AT_BW_40, |
| 197 | RF_AT_BW_U20, |
| 198 | RF_AT_BW_L20, |
| 199 | RF_AT_BW_NUM |
| 200 | |
| 201 | } ENUM_RF_AT_BW_T, *P_ENUM_RF_AT_BW_T; |
| 202 | |
| 203 | typedef enum _ENUM_RF_AT_RXOK_MATCH_RULE_T { |
| 204 | |
| 205 | RF_AT_RXOK_DISABLED = 0, |
| 206 | RF_AT_RXOK_MATCH_RA_ONLY, |
| 207 | RF_AT_RXOK_MATCH_TA_ONLY, |
| 208 | RF_AT_RXOK_MATCH_RA_TA, |
| 209 | RF_AT_RXOK_NUM |
| 210 | |
| 211 | } ENUM_RF_AT_RXOK_MATCH_RULE_T, *P_ENUM_RF_AT_RXOK_MATCH_RULE_T; |
| 212 | |
| 213 | |
| 214 | |
| 215 | /******************************************************************************* |
| 216 | * P R I V A T E D A T A |
| 217 | ******************************************************************************* |
| 218 | */ |
| 219 | //static int wifi_rfkill_id = -1; |
| 220 | //static char *wifi_rfkill_state_path = NULL; |
| 221 | static int skfd = -1; |
| 222 | static bool fgIsTesting = false; |
| 223 | |
| 224 | /*----------------------------------------------------------------------------*/ |
| 225 | /*! |
| 226 | * @brief This function is called to initial rfkill variables |
| 227 | * |
| 228 | * @param |
| 229 | * |
| 230 | * @return |
| 231 | */ |
| 232 | /*----------------------------------------------------------------------------*/ |
| 233 | #if 0 |
| 234 | static int |
| 235 | wifi_init_rfkill( |
| 236 | void |
| 237 | ) |
| 238 | { |
| 239 | char path[64]; |
| 240 | char buf[16]; |
| 241 | int fd; |
| 242 | int sz; |
| 243 | int id; |
| 244 | |
| 245 | for (id = 0; ; id++) { |
| 246 | snprintf(path, sizeof(path), "/sys/class/rfkill/rfkill%d/type", id); |
| 247 | fd = open(path, O_RDONLY); |
| 248 | if (fd < 0) { |
| 249 | ALOGW("[%s] open(%s) failed: %s (%d)\n", __func__, path, strerror(errno), errno); |
| 250 | return -1; |
| 251 | } |
| 252 | sz = read(fd, &buf, sizeof(buf)); |
| 253 | close(fd); |
| 254 | if (sz >= 4 && memcmp(buf, "wlan", 4) == 0) { |
| 255 | wifi_rfkill_id = id; |
| 256 | break; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | asprintf(&wifi_rfkill_state_path, "/sys/class/rfkill/rfkill%d/state", |
| 261 | wifi_rfkill_id); |
| 262 | return 0; |
| 263 | } |
| 264 | #endif |
| 265 | |
| 266 | /*----------------------------------------------------------------------------*/ |
| 267 | /*! |
| 268 | * @brief This function is called to turn on/off Wi-Fi interface |
| 269 | * |
| 270 | * @param |
| 271 | * |
| 272 | * @return |
| 273 | */ |
| 274 | /*----------------------------------------------------------------------------*/ |
| 275 | #if 0 |
| 276 | static int |
| 277 | wifi_set_power( |
| 278 | int on |
| 279 | ) |
| 280 | { |
| 281 | int sz; |
| 282 | int fd = -1; |
| 283 | int ret = -1; |
| 284 | const char buffer = (on ? '1' : '0'); |
| 285 | |
| 286 | ALOGD("[%s] %d", __func__, on); |
| 287 | |
| 288 | if (wifi_rfkill_id == -1) { |
| 289 | if (wifi_init_rfkill()) { |
| 290 | goto out; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | fd = open(wifi_rfkill_state_path, O_WRONLY); |
| 295 | ALOGD("[%s] %s", __func__, wifi_rfkill_state_path); |
| 296 | if (fd < 0) { |
| 297 | ALOGE("open(%s) for write failed: %s (%d)", |
| 298 | wifi_rfkill_state_path, |
| 299 | strerror(errno), |
| 300 | errno); |
| 301 | goto out; |
| 302 | } |
| 303 | sz = write(fd, &buffer, 1); |
| 304 | if (sz < 0) { |
| 305 | ALOGE("write(%s) failed: %s (%d)", |
| 306 | wifi_rfkill_state_path, |
| 307 | strerror(errno), |
| 308 | errno); |
| 309 | goto out; |
| 310 | } |
| 311 | ret = 0; |
| 312 | |
| 313 | out: |
| 314 | if (fd >= 0) { |
| 315 | close(fd); |
| 316 | } |
| 317 | return ret; |
| 318 | } |
| 319 | #else |
| 320 | #define WIFI_POWER_PATH "/dev/wmtWifi" |
| 321 | |
| 322 | int wifi_set_power(int enable) { |
| 323 | int sz; |
| 324 | int fd = -1; |
| 325 | const char buffer = (enable ? '1' : '0'); |
| 326 | |
| 327 | fd = open(WIFI_POWER_PATH, O_WRONLY); |
| 328 | if (fd < 0) { |
| 329 | ALOGE("Open \"%s\" failed", WIFI_POWER_PATH); |
| 330 | goto out; |
| 331 | } |
| 332 | sz = write(fd, &buffer, 1); |
| 333 | if (sz < 0) { |
| 334 | ALOGE("Set \"%s\" [%c] failed", WIFI_POWER_PATH, buffer); |
| 335 | goto out; |
| 336 | } |
| 337 | |
| 338 | out: |
| 339 | if (fd >= 0) close(fd); |
| 340 | return 0; |
| 341 | } |
| 342 | |
| 343 | #endif |
| 344 | |
| 345 | /*----------------------------------------------------------------------------*/ |
| 346 | /*! |
| 347 | * @brief This function is to insert module |
| 348 | * |
| 349 | * @param |
| 350 | * |
| 351 | * @return |
| 352 | */ |
| 353 | /*----------------------------------------------------------------------------*/ |
| 354 | static int |
| 355 | insmod( |
| 356 | const char *filename, |
| 357 | const char *args |
| 358 | ) |
| 359 | { |
| 360 | #if 1 |
| 361 | ALOGE("%s not supported\n", __func__); |
| 362 | return -1; |
| 363 | #else |
| 364 | void *module; |
| 365 | unsigned int size; |
| 366 | int ret; |
| 367 | |
| 368 | module = load_file(filename, &size); |
| 369 | if (!module) |
| 370 | return -1; |
| 371 | |
| 372 | ret = init_module(module, size, args); |
| 373 | |
| 374 | free(module); |
| 375 | |
| 376 | return ret; |
| 377 | #endif |
| 378 | } |
| 379 | |
| 380 | |
| 381 | /*----------------------------------------------------------------------------*/ |
| 382 | /*! |
| 383 | * @brief This function is to check if driver is loaded or not |
| 384 | * |
| 385 | * @param |
| 386 | * |
| 387 | * @return |
| 388 | */ |
| 389 | /*----------------------------------------------------------------------------*/ |
| 390 | static int |
| 391 | check_driver_loaded( |
| 392 | void |
| 393 | ) |
| 394 | { |
| 395 | #if 1 |
| 396 | return 1; |
| 397 | #else |
| 398 | FILE *proc; |
| 399 | char line[sizeof(DRIVER_MODULE_TAG)+10]; |
| 400 | |
| 401 | if ((proc = fopen(MODULE_FILE, "r")) == NULL) { |
| 402 | ALOGW("Could not open %s: %s", MODULE_FILE, strerror(errno)); |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | while ((fgets(line, sizeof(line), proc)) != NULL) { |
| 407 | if (strncmp(line, DRIVER_MODULE_TAG, strlen(DRIVER_MODULE_TAG)) == 0) { |
| 408 | fclose(proc); |
| 409 | return 1; |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | fclose(proc); |
| 414 | return 0; |
| 415 | #endif |
| 416 | } |
| 417 | |
| 418 | |
| 419 | /*----------------------------------------------------------------------------*/ |
| 420 | /*! |
| 421 | * @brief This function is to extract interface name |
| 422 | * |
| 423 | * @param name pointer to name buffer |
| 424 | * nsize size of name buffer |
| 425 | * buf current position in buffer |
| 426 | * @return |
| 427 | */ |
| 428 | /*----------------------------------------------------------------------------*/ |
| 429 | static inline char * |
| 430 | iw_get_ifname( |
| 431 | char *name, |
| 432 | int nsize, |
| 433 | char *buf |
| 434 | ) |
| 435 | { |
| 436 | char *end; |
| 437 | |
| 438 | /* Skip leading spaces */ |
| 439 | while(isspace(*buf)) |
| 440 | buf++; |
| 441 | |
| 442 | end = strrchr(buf, ':'); |
| 443 | |
| 444 | /* Not found ??? To big ??? */ |
| 445 | if((end == NULL) || (((end - buf) + 1) > nsize)) |
| 446 | return(NULL); |
| 447 | |
| 448 | /* Copy */ |
| 449 | memcpy(name, buf, (end - buf)); |
| 450 | name[end - buf] = '\0'; |
| 451 | |
| 452 | /* Return value currently unused, just make sure it's non-NULL */ |
| 453 | return(end); |
| 454 | } |
| 455 | |
| 456 | /*----------------------------------------------------------------------------*/ |
| 457 | /*! |
| 458 | * @brief This function is to check whether wlan0 has been spawn or not |
| 459 | * |
| 460 | * @param |
| 461 | * |
| 462 | * @return |
| 463 | */ |
| 464 | /*----------------------------------------------------------------------------*/ |
| 465 | static int |
| 466 | find_wifi_device( |
| 467 | void |
| 468 | ) |
| 469 | { |
| 470 | FILE *fh; |
| 471 | char buff[1024]; |
| 472 | int ret = -1; |
| 473 | |
| 474 | fh = fopen(PROC_NET_DEV, "r"); |
| 475 | |
| 476 | if(fh != NULL) { |
| 477 | /* Success : use data from /proc/net/wireless */ |
| 478 | /* Eat 2 lines of header */ |
| 479 | fgets(buff, sizeof(buff), fh); |
| 480 | fgets(buff, sizeof(buff), fh); |
| 481 | |
| 482 | /* Read each device line */ |
| 483 | while(fgets(buff, sizeof(buff), fh)) { |
| 484 | char name[IFNAMSIZ + 1]; |
| 485 | char *s; |
| 486 | |
| 487 | /* Skip empty or almost empty lines. It seems that in some |
| 488 | * * * cases fgets return a line with only a newline. */ |
| 489 | if ((buff[0] == '\0') || (buff[1] == '\0')) |
| 490 | continue; |
| 491 | /* Extract interface name */ |
| 492 | s = iw_get_ifname(name, sizeof(name), buff); |
| 493 | |
| 494 | if(s) { |
| 495 | ALOGD("[%s] %s", __func__, name); |
| 496 | if (strcmp(name, WIFI_IF_NAME) == 0 ){ |
| 497 | ret = 0; |
| 498 | break; |
| 499 | } |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | fclose(fh); |
| 504 | } |
| 505 | |
| 506 | return ret; |
| 507 | } |
| 508 | |
| 509 | /*----------------------------------------------------------------------------*/ |
| 510 | /*! |
| 511 | * @brief Wrapper to push some Wireless Parameter in the driver |
| 512 | * |
| 513 | * @param request Wireless extension identifier |
| 514 | * pwrq Pointer to wireless extension request |
| 515 | * |
| 516 | * @return |
| 517 | */ |
| 518 | /*----------------------------------------------------------------------------*/ |
| 519 | static inline int |
| 520 | ioctl_iw_ext( |
| 521 | int request, |
| 522 | struct iwreq *pwrq |
| 523 | ) |
| 524 | { |
| 525 | if(skfd > 0) { |
| 526 | /* Set device name */ |
| 527 | strncpy(pwrq->ifr_name, WIFI_IF_NAME, (IFNAMSIZ - 1)); |
| 528 | |
| 529 | /* Do the request */ |
| 530 | return(ioctl(skfd, request, pwrq)); |
| 531 | } |
| 532 | else { |
| 533 | return -1; |
| 534 | } |
| 535 | } |
| 536 | |
| 537 | |
| 538 | /*----------------------------------------------------------------------------*/ |
| 539 | /*! |
| 540 | * @brief This API is to ask underlying software to enter/leave RF test mode |
| 541 | * |
| 542 | * @param |
| 543 | * |
| 544 | * @return |
| 545 | */ |
| 546 | /*----------------------------------------------------------------------------*/ |
| 547 | static int |
| 548 | wifi_switch_test_mode( |
| 549 | int on |
| 550 | ) |
| 551 | { |
| 552 | int retval; |
| 553 | struct iwreq wrq; |
| 554 | NDIS_TRANSPORT_STRUCT rNdisStruct; |
| 555 | |
| 556 | /* zeroize */ |
| 557 | memset(&wrq, 0, sizeof(struct iwreq)); |
| 558 | |
| 559 | /* configure NDIS_TRANSPORT_STRUC */ |
| 560 | if(on == 1) { |
| 561 | rNdisStruct.ndisOidCmd = OID_CUSTOM_TEST_MODE; |
| 562 | } |
| 563 | else if(on == 0) { |
| 564 | rNdisStruct.ndisOidCmd = OID_CUSTOM_ABORT_TEST_MODE; |
| 565 | } |
| 566 | else { |
| 567 | return -1; |
| 568 | } |
| 569 | |
| 570 | rNdisStruct.inNdisOidlength = 0; |
| 571 | rNdisStruct.outNdisOidLength = 0; |
| 572 | |
| 573 | /* configure struct iwreq */ |
| 574 | wrq.u.data.pointer = &rNdisStruct; |
| 575 | wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT); |
| 576 | wrq.u.data.flags = PRIV_CMD_OID; |
| 577 | |
| 578 | retval = ioctl_iw_ext(IOCTL_SET_STRUCT, &wrq); |
| 579 | |
| 580 | if(retval == 0) { |
| 581 | if(on == 1) { |
| 582 | fgIsTesting = true; |
| 583 | } |
| 584 | else { |
| 585 | fgIsTesting = false; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | return retval; |
| 590 | } |
| 591 | |
| 592 | /*----------------------------------------------------------------------------*/ |
| 593 | /*! |
| 594 | * @brief This API provided a generic service for RF test set commands |
| 595 | * |
| 596 | * @param |
| 597 | * |
| 598 | * @return |
| 599 | */ |
| 600 | /*----------------------------------------------------------------------------*/ |
| 601 | int |
| 602 | WIFI_TEST_set( |
| 603 | uint32_t u4FuncIndex, |
| 604 | uint32_t u4FuncData, |
| 605 | uint32_t *pu4FuncIndex, |
| 606 | uint32_t *pu4FuncData |
| 607 | ) |
| 608 | { |
| 609 | int retval; |
| 610 | struct iwreq wrq; |
| 611 | NDIS_TRANSPORT_STRUCT rNdisStruct; |
| 612 | P_PARAM_MTK_WIFI_TEST_STRUC_T prTestStruct; |
| 613 | |
| 614 | prTestStruct = (P_PARAM_MTK_WIFI_TEST_STRUC_T)rNdisStruct.ndisOidContent; |
| 615 | |
| 616 | /* zeroize */ |
| 617 | memset(&wrq, 0, sizeof(struct iwreq)); |
| 618 | |
| 619 | /* configure TEST_STRUCT */ |
| 620 | prTestStruct->u4FuncIndex = u4FuncIndex; |
| 621 | prTestStruct->u4FuncData = u4FuncData; |
| 622 | |
| 623 | /* configure NDIS_TRANSPORT_STRUC */ |
| 624 | rNdisStruct.ndisOidCmd = OID_CUSTOM_MTK_WIFI_TEST_; |
| 625 | rNdisStruct.inNdisOidlength = sizeof(PARAM_MTK_WIFI_TEST_STRUC_T); |
| 626 | rNdisStruct.outNdisOidLength = sizeof(PARAM_MTK_WIFI_TEST_STRUC_T); |
| 627 | |
| 628 | /* configure struct iwreq */ |
| 629 | wrq.u.data.pointer = &rNdisStruct; |
| 630 | wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT); |
| 631 | wrq.u.data.flags = PRIV_CMD_OID; |
| 632 | |
| 633 | retval = ioctl_iw_ext(IOCTL_SET_STRUCT, &wrq); |
| 634 | |
| 635 | if(retval == 0) { |
| 636 | if(pu4FuncIndex) { |
| 637 | *pu4FuncIndex = prTestStruct->u4FuncIndex; |
| 638 | } |
| 639 | |
| 640 | if(pu4FuncData) { |
| 641 | *pu4FuncData = prTestStruct->u4FuncData; |
| 642 | } |
| 643 | |
| 644 | DBGLOG("<ok> Set CMD[%03u] DATA[0x%08x]\n", |
| 645 | (u4FuncIndex & TEST_FUNC_IDX_MASK), u4FuncData); |
| 646 | } |
| 647 | else { |
| 648 | DBGLOG("<failed> Set CMD[%03u] DATA[0x%08x]\n", |
| 649 | (u4FuncIndex & TEST_FUNC_IDX_MASK), u4FuncData); |
| 650 | } |
| 651 | |
| 652 | return retval; |
| 653 | } |
| 654 | |
| 655 | |
| 656 | /*----------------------------------------------------------------------------*/ |
| 657 | /*! |
| 658 | * @brief This API provided a generic service for RF test query commands |
| 659 | * |
| 660 | * @param |
| 661 | * |
| 662 | * @return |
| 663 | */ |
| 664 | /*----------------------------------------------------------------------------*/ |
| 665 | static int |
| 666 | WIFI_TEST_get( |
| 667 | uint32_t u4FuncIndex, |
| 668 | uint32_t u4FuncData, |
| 669 | uint32_t *pu4FuncIndex, |
| 670 | uint32_t *pu4FuncData |
| 671 | ) |
| 672 | { |
| 673 | int retval; |
| 674 | struct iwreq wrq; |
| 675 | NDIS_TRANSPORT_STRUCT rNdisStruct; |
| 676 | P_PARAM_MTK_WIFI_TEST_STRUC_T prTestStruct; |
| 677 | |
| 678 | prTestStruct = (P_PARAM_MTK_WIFI_TEST_STRUC_T)rNdisStruct.ndisOidContent; |
| 679 | |
| 680 | /* zeroize */ |
| 681 | memset(&wrq, 0, sizeof(struct iwreq)); |
| 682 | |
| 683 | /* configure TEST_STRUCT */ |
| 684 | prTestStruct->u4FuncIndex = u4FuncIndex; |
| 685 | prTestStruct->u4FuncData = u4FuncData; |
| 686 | |
| 687 | /* configure NDIS_TRANSPORT_STRUC */ |
| 688 | rNdisStruct.ndisOidCmd = OID_CUSTOM_MTK_WIFI_TEST_; |
| 689 | rNdisStruct.inNdisOidlength = sizeof(PARAM_MTK_WIFI_TEST_STRUC_T); |
| 690 | rNdisStruct.outNdisOidLength = sizeof(PARAM_MTK_WIFI_TEST_STRUC_T); |
| 691 | |
| 692 | /* configure struct iwreq */ |
| 693 | wrq.u.data.pointer = &rNdisStruct; |
| 694 | wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT); |
| 695 | wrq.u.data.flags = PRIV_CMD_OID; |
| 696 | |
| 697 | retval = ioctl_iw_ext(IOCTL_GET_STRUCT, &wrq); |
| 698 | |
| 699 | if(retval == 0) { |
| 700 | if(pu4FuncIndex) { |
| 701 | *pu4FuncIndex = prTestStruct->u4FuncIndex; |
| 702 | } |
| 703 | |
| 704 | if(pu4FuncData) { |
| 705 | *pu4FuncData = prTestStruct->u4FuncData; |
| 706 | } |
| 707 | |
| 708 | DBGLOG("<ok> Get CMD[%03u] DATA[0x%08x] RESULT[0x%08x]\n", |
| 709 | (u4FuncIndex & TEST_FUNC_IDX_MASK), u4FuncData, *pu4FuncData); |
| 710 | } |
| 711 | else { |
| 712 | DBGLOG("<failed> Get CMD[%03u] DATA[0x%08x]\n", |
| 713 | (u4FuncIndex & TEST_FUNC_IDX_MASK), u4FuncData); |
| 714 | } |
| 715 | |
| 716 | return retval; |
| 717 | } |
| 718 | |
| 719 | |
| 720 | /* API |
| 721 | * ========================================================================== */ |
| 722 | bool WIFI_TEST_OpenDUT(void) |
| 723 | { |
| 724 | int count = 60; |
| 725 | bool retval = false; |
| 726 | |
| 727 | ALOGD("[%s] entry\n", __func__); |
| 728 | |
| 729 | wifi_set_power(1); |
| 730 | |
| 731 | if (!check_driver_loaded()) { |
| 732 | ALOGD("[%s] loading wifi driver ... ...\n", __func__); |
| 733 | |
| 734 | if (insmod(DRIVER_MODULE_PATH, DRIVER_MODULE_ARG) < 0) { |
| 735 | ALOGD("[%s] failed to load wifi driver!!\n", __func__); |
| 736 | goto error; |
| 737 | } |
| 738 | } |
| 739 | |
| 740 | sched_yield(); |
| 741 | |
| 742 | while(count -- > 0) { |
| 743 | if(find_wifi_device()==0) { |
| 744 | retval = true; |
| 745 | ALOGD("[%s] find wifi device\n", __func__); |
| 746 | break; |
| 747 | } |
| 748 | usleep(50000); |
| 749 | } |
| 750 | |
| 751 | if (retval == false) { |
| 752 | goto error; |
| 753 | } |
| 754 | else { |
| 755 | /* initialize skfd */ |
| 756 | if ((skfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { |
| 757 | ALOGE("[%s] failed to open net socket\n", __func__); |
| 758 | goto error; |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | /* switch into test mode */ |
| 763 | if(wifi_switch_test_mode(1) != 0) { |
| 764 | goto error; |
| 765 | } |
| 766 | |
| 767 | return true; |
| 768 | |
| 769 | error: |
| 770 | ALOGD("[%s] failure", __func__); |
| 771 | |
| 772 | WIFI_TEST_CloseDUT(); |
| 773 | |
| 774 | return false; |
| 775 | } |
| 776 | |
| 777 | bool WIFI_TEST_CloseDUT(void) |
| 778 | { |
| 779 | /* turn off test mode */ |
| 780 | wifi_switch_test_mode(0); |
| 781 | |
| 782 | /* close socket if necessary */ |
| 783 | if(skfd > 0) { |
| 784 | close(skfd); |
| 785 | skfd = -1; |
| 786 | } |
| 787 | |
| 788 | /* no need to remove module, just turn off host power via rfkill */ |
| 789 | wifi_set_power(0); |
| 790 | |
| 791 | return true; |
| 792 | } |
| 793 | |
| 794 | bool WIFI_TEST_TxDataRate(int TxDataRate) |
| 795 | { |
| 796 | int retval; |
| 797 | |
| 798 | switch (TxDataRate) { |
| 799 | case WIFI_TEST_RATE_AUTO: |
| 800 | return false; //@FIXME |
| 801 | |
| 802 | case WIFI_TEST_RATE_1MBPS: |
| 803 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 804 | RF_AT_PARAM_RATE_1M, |
| 805 | NULL, |
| 806 | NULL); |
| 807 | break; |
| 808 | |
| 809 | case WIFI_TEST_RATE_2MBPS: |
| 810 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 811 | RF_AT_PARAM_RATE_2M, |
| 812 | NULL, |
| 813 | NULL); |
| 814 | break; |
| 815 | |
| 816 | case WIFI_TEST_RATE_5_5MBPS: |
| 817 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 818 | RF_AT_PARAM_RATE_5_5M, |
| 819 | NULL, |
| 820 | NULL); |
| 821 | break; |
| 822 | |
| 823 | case WIFI_TEST_RATE_6MBPS: |
| 824 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 825 | RF_AT_PARAM_RATE_6M, |
| 826 | NULL, |
| 827 | NULL); |
| 828 | break; |
| 829 | |
| 830 | case WIFI_TEST_RATE_9MBPS: |
| 831 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 832 | RF_AT_PARAM_RATE_9M, |
| 833 | NULL, |
| 834 | NULL); |
| 835 | break; |
| 836 | |
| 837 | case WIFI_TEST_RATE_11MBPS: |
| 838 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 839 | RF_AT_PARAM_RATE_11M, |
| 840 | NULL, |
| 841 | NULL); |
| 842 | break; |
| 843 | |
| 844 | case WIFI_TEST_RATE_12MBPS: |
| 845 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 846 | RF_AT_PARAM_RATE_12M, |
| 847 | NULL, |
| 848 | NULL); |
| 849 | break; |
| 850 | |
| 851 | case WIFI_TEST_RATE_18MBPS: |
| 852 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 853 | RF_AT_PARAM_RATE_18M, |
| 854 | NULL, |
| 855 | NULL); |
| 856 | break; |
| 857 | |
| 858 | case WIFI_TEST_RATE_24MBPS: |
| 859 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 860 | RF_AT_PARAM_RATE_24M, |
| 861 | NULL, |
| 862 | NULL); |
| 863 | break; |
| 864 | |
| 865 | case WIFI_TEST_RATE_36MBPS: |
| 866 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 867 | RF_AT_PARAM_RATE_36M, |
| 868 | NULL, |
| 869 | NULL); |
| 870 | break; |
| 871 | |
| 872 | case WIFI_TEST_RATE_48MBPS: |
| 873 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 874 | RF_AT_PARAM_RATE_48M, |
| 875 | NULL, |
| 876 | NULL); |
| 877 | break; |
| 878 | |
| 879 | case WIFI_TEST_RATE_54MBPS: |
| 880 | retval = WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 881 | RF_AT_PARAM_RATE_54M, |
| 882 | NULL, |
| 883 | NULL); |
| 884 | break; |
| 885 | |
| 886 | default: |
| 887 | return false; |
| 888 | |
| 889 | } |
| 890 | |
| 891 | /* return value checking */ |
| 892 | if(retval == 0) { |
| 893 | return true; |
| 894 | } |
| 895 | else { |
| 896 | return false; |
| 897 | } |
| 898 | } |
| 899 | |
| 900 | bool WIFI_TEST_SetPreamble(WIFI_PreambleType_t PreambleType) |
| 901 | { |
| 902 | int retval; |
| 903 | |
| 904 | switch (PreambleType) { |
| 905 | case WIFI_TEST_PREAMBLE_LONG: |
| 906 | retval = WIFI_TEST_set(RF_AT_FUNCID_PREAMBLE, |
| 907 | RF_AT_PREAMBLE_NORMAL, |
| 908 | NULL, |
| 909 | NULL); |
| 910 | break; |
| 911 | |
| 912 | case WIFI_TEST_PREAMBLE_SHORT: |
| 913 | retval = WIFI_TEST_set(RF_AT_FUNCID_PREAMBLE, |
| 914 | RF_AT_PREAMBLE_CCK_SHORT, |
| 915 | NULL, |
| 916 | NULL); |
| 917 | break; |
| 918 | |
| 919 | default: |
| 920 | return false; |
| 921 | } |
| 922 | |
| 923 | /* return value checking */ |
| 924 | if(retval == 0) { |
| 925 | return true; |
| 926 | } |
| 927 | else { |
| 928 | return false; |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | bool WIFI_TEST_Channel(int ChannelNo) |
| 933 | { |
| 934 | uint32_t u4Freq; |
| 935 | |
| 936 | if(ChannelNo < 0) { |
| 937 | return false; /* invalid channel number */ |
| 938 | } |
| 939 | /* 2.4GHz band */ |
| 940 | else if(ChannelNo <= 13) { |
| 941 | u4Freq = 2412000 + (ChannelNo - 1) * 5000; |
| 942 | } |
| 943 | else if(ChannelNo == 14) { |
| 944 | u4Freq = 2484000; |
| 945 | } |
| 946 | /* 5GHz band */ |
| 947 | else if(ChannelNo >= 36) { |
| 948 | u4Freq = 5180000 + (ChannelNo - 36) * 5000; |
| 949 | } |
| 950 | else { |
| 951 | return false; /* invalid channel number */ |
| 952 | } |
| 953 | |
| 954 | if(WIFI_TEST_set(RF_AT_FUNCID_CHNL_FREQ, |
| 955 | u4Freq, |
| 956 | NULL, |
| 957 | NULL) == 0) { |
| 958 | return true; |
| 959 | } |
| 960 | else { |
| 961 | return false; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | bool WIFI_TEST_TxGain(float TxGain) |
| 966 | { |
| 967 | /* assign TX power gain */ |
| 968 | if(WIFI_TEST_set(RF_AT_FUNCID_POWER, |
| 969 | (uint32_t)(TxGain * 2.0), // in unit of 0.5dBm |
| 970 | NULL, |
| 971 | NULL) == 0) { |
| 972 | return true; |
| 973 | } |
| 974 | else { |
| 975 | return false; |
| 976 | } |
| 977 | } |
| 978 | |
| 979 | bool WIFI_TEST_TxBurstInterval(int SIFS) |
| 980 | { |
| 981 | if (SIFS < 20 || SIFS > 1000) |
| 982 | return false; |
| 983 | |
| 984 | /* specify packet interval */ |
| 985 | if(WIFI_TEST_set(RF_AT_FUNCID_PKTINTERVAL, |
| 986 | SIFS, |
| 987 | NULL, |
| 988 | NULL) == 0) { |
| 989 | return true; |
| 990 | } |
| 991 | else { |
| 992 | return false; |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | bool WIFI_TEST_TxPayloadLength(int TxPayLength) |
| 997 | { |
| 998 | if (TxPayLength <= 0) |
| 999 | return false; |
| 1000 | |
| 1001 | /* specify packet length */ |
| 1002 | if(WIFI_TEST_set(RF_AT_FUNCID_PKTLEN, |
| 1003 | TxPayLength, |
| 1004 | NULL, |
| 1005 | NULL) == 0) { |
| 1006 | return true; |
| 1007 | } |
| 1008 | else { |
| 1009 | return false; |
| 1010 | } |
| 1011 | } |
| 1012 | |
| 1013 | bool WIFI_TEST_TxBurstFrames(int Frames) |
| 1014 | { |
| 1015 | if (Frames < 0) |
| 1016 | return false; |
| 1017 | |
| 1018 | /* specify packet count */ |
| 1019 | if(WIFI_TEST_set(RF_AT_FUNCID_PKTCNT, |
| 1020 | Frames, |
| 1021 | NULL, |
| 1022 | NULL) == 0) { |
| 1023 | return true; |
| 1024 | } |
| 1025 | else { |
| 1026 | return false; |
| 1027 | } |
| 1028 | } |
| 1029 | |
| 1030 | bool WIFI_TEST_TxDestAddress(unsigned char *addr) |
| 1031 | { |
| 1032 | uint8_t aucMacAddr[4]; |
| 1033 | uint32_t u4MacAddr; |
| 1034 | |
| 1035 | /* specify MAC address[0:3] */ |
| 1036 | memcpy(aucMacAddr, addr, sizeof(uint8_t) * 4); |
| 1037 | u4MacAddr = *(uint32_t *)(&(aucMacAddr[0])); |
| 1038 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_DST_ADDRESS, |
| 1039 | u4MacAddr, |
| 1040 | NULL, |
| 1041 | NULL) != 0) { |
| 1042 | return false; |
| 1043 | } |
| 1044 | |
| 1045 | /* specify MAC address[4:5] */ |
| 1046 | memset(aucMacAddr, 0, sizeof(uint8_t) * 4); |
| 1047 | memcpy(aucMacAddr, addr + 4, sizeof(uint8_t) * 2); |
| 1048 | u4MacAddr = *(uint32_t *)(&(aucMacAddr[0])); |
| 1049 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_DST_ADDRESS | (4 << TEST_SET_CMD_OFFSET), |
| 1050 | u4MacAddr, |
| 1051 | NULL, |
| 1052 | NULL) != 0) { |
| 1053 | return false; |
| 1054 | } |
| 1055 | |
| 1056 | return true; |
| 1057 | } |
| 1058 | |
| 1059 | bool WIFI_TEST_TxStart(void) |
| 1060 | { |
| 1061 | /* tx start: without ack, async mode */ |
| 1062 | if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND, |
| 1063 | RF_AT_COMMAND_STARTTX, |
| 1064 | NULL, |
| 1065 | NULL) == 0) { |
| 1066 | return true; |
| 1067 | } |
| 1068 | else { |
| 1069 | return false; |
| 1070 | } |
| 1071 | } |
| 1072 | |
| 1073 | bool WIFI_TEST_TxStop(void) |
| 1074 | { |
| 1075 | /* checking for testing mode */ |
| 1076 | if(WIFI_TEST_IsRunning() == false) { |
| 1077 | WIFI_TEST_OpenDUT(); |
| 1078 | } |
| 1079 | |
| 1080 | /* tx stop */ |
| 1081 | if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND, |
| 1082 | RF_AT_COMMAND_STOPTEST, |
| 1083 | NULL, |
| 1084 | NULL) == 0) { |
| 1085 | return true; |
| 1086 | } |
| 1087 | else { |
| 1088 | return false; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | bool WIFI_TEST_RxStart(void) |
| 1093 | { |
| 1094 | /* rx start: without ack, async mode */ |
| 1095 | if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND, |
| 1096 | RF_AT_COMMAND_STARTRX, |
| 1097 | NULL, |
| 1098 | NULL) == 0) { |
| 1099 | return true; |
| 1100 | } |
| 1101 | else { |
| 1102 | return false; |
| 1103 | } |
| 1104 | } |
| 1105 | |
| 1106 | bool WIFI_TEST_RxStop(void) |
| 1107 | { |
| 1108 | /* checking for testing mode */ |
| 1109 | if(WIFI_TEST_IsRunning() == false) { |
| 1110 | WIFI_TEST_OpenDUT(); |
| 1111 | } |
| 1112 | |
| 1113 | /* rx stop */ |
| 1114 | if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND, |
| 1115 | RF_AT_COMMAND_STOPTEST, |
| 1116 | NULL, |
| 1117 | NULL) == 0) { |
| 1118 | return true; |
| 1119 | } |
| 1120 | else { |
| 1121 | return false; |
| 1122 | } |
| 1123 | } |
| 1124 | |
| 1125 | bool WIFI_TEST_FRError(int *FError) |
| 1126 | { |
| 1127 | if (!FError) |
| 1128 | return false; |
| 1129 | |
| 1130 | if(WIFI_TEST_get(RF_AT_FUNCID_RXERROR_COUNT, |
| 1131 | 0, |
| 1132 | NULL, |
| 1133 | (uint32_t *)FError) == 0) { |
| 1134 | return true; |
| 1135 | } |
| 1136 | else { |
| 1137 | return false; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | bool WIFI_TEST_FRGood(int *FRGood) |
| 1142 | { |
| 1143 | if (!FRGood) |
| 1144 | return false; |
| 1145 | |
| 1146 | if(WIFI_TEST_get(RF_AT_FUNCID_RXOK_COUNT, |
| 1147 | 0, |
| 1148 | NULL, |
| 1149 | (uint32_t *)FRGood) == 0) { |
| 1150 | return true; |
| 1151 | } |
| 1152 | else { |
| 1153 | return false; |
| 1154 | } |
| 1155 | } |
| 1156 | |
| 1157 | bool WIFI_TEST_TxCount(uint32_t *TxCount) |
| 1158 | { |
| 1159 | if (!TxCount) |
| 1160 | return false; |
| 1161 | |
| 1162 | if(WIFI_TEST_get(RF_AT_FUNCID_TXED_COUNT, |
| 1163 | 0, |
| 1164 | NULL, |
| 1165 | (uint32_t *)TxCount) == 0) { |
| 1166 | return true; |
| 1167 | } |
| 1168 | else { |
| 1169 | return false; |
| 1170 | } |
| 1171 | } |
| 1172 | |
| 1173 | bool WIFI_TEST_TxGoodCount(uint32_t *TxGoodCount) |
| 1174 | { |
| 1175 | if (!TxGoodCount) |
| 1176 | return false; |
| 1177 | |
| 1178 | if(WIFI_TEST_get(RF_AT_FUNCID_TXOK_COUNT, |
| 1179 | 0, |
| 1180 | NULL, |
| 1181 | (uint32_t *)TxGoodCount) == 0) { |
| 1182 | return true; |
| 1183 | } |
| 1184 | else { |
| 1185 | return false; |
| 1186 | } |
| 1187 | } |
| 1188 | |
| 1189 | bool WIFI_TEST_RSSI(int *RSSI) |
| 1190 | { |
| 1191 | uint32_t u4Result; |
| 1192 | |
| 1193 | if (!RSSI) |
| 1194 | return false; |
| 1195 | |
| 1196 | if(WIFI_TEST_get(RF_AT_FUNCID_RX_RSSI, |
| 1197 | 0, |
| 1198 | NULL, |
| 1199 | &u4Result) == 0) { |
| 1200 | /* u4Result[0:7] Average RSSI (dbM) |
| 1201 | * u4Result[8:15] Minimum RCPI |
| 1202 | * u4Result[16:23] Maximum RCPI |
| 1203 | * u4Result[24:31] Last RCPI |
| 1204 | */ |
| 1205 | *RSSI = (int)(u4Result & BITS(0,7)); |
| 1206 | return true; |
| 1207 | } |
| 1208 | else { |
| 1209 | return false; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | bool WIFI_TEST_IsRunning(void) |
| 1214 | { |
| 1215 | return fgIsTesting; |
| 1216 | } |
| 1217 | |
| 1218 | bool WIFI_TEST_IsUp(void) |
| 1219 | { |
| 1220 | struct ifreq ifr; |
| 1221 | int sk, up; |
| 1222 | |
| 1223 | /* NULL ptr checking */ |
| 1224 | sk = socket(PF_INET, SOCK_STREAM, 0); |
| 1225 | if (sk == -1) { |
| 1226 | return false; |
| 1227 | } |
| 1228 | |
| 1229 | strncpy(ifr.ifr_name, WIFI_IF_NAME, sizeof(ifr.ifr_name)-1); |
| 1230 | ifr.ifr_name[sizeof(ifr.ifr_name)-1]='\0'; |
| 1231 | |
| 1232 | /* retrieve hardware address */ |
| 1233 | if (ioctl(sk, SIOCGIFFLAGS, &ifr) == -1) { |
| 1234 | close(sk); |
| 1235 | return false; |
| 1236 | } |
| 1237 | |
| 1238 | up = ifr.ifr_flags & IFF_UP; |
| 1239 | |
| 1240 | close(sk); |
| 1241 | |
| 1242 | if(up) { |
| 1243 | return true; |
| 1244 | } |
| 1245 | else { |
| 1246 | return false; |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | /* for 11n test */ |
| 1251 | // FrameFormat : 1 (Mixed Mode), 2 (Green field mode) |
| 1252 | // GI (Gard interval) : 1 (Long GI), 2 (Short GI) |
| 1253 | bool WIFI_TEST_TxDataRate11n( |
| 1254 | ENUM_WIFI_TEST_MCS_RATE eTxDataRate11n, |
| 1255 | ENUM_WIFI_TEST_PREAMBLE_TYPE ePreambleType, |
| 1256 | ENUM_WIFI_TEST_GI_TYPE eGIType |
| 1257 | ) |
| 1258 | { |
| 1259 | uint32_t u4Rate, u4Preamble; |
| 1260 | |
| 1261 | if( eTxDataRate11n > WIFI_TEST_MCS_RATE_7 && eTxDataRate11n != WIFI_TEST_MCS_RATE_32 ) |
| 1262 | { |
| 1263 | DBGLOG("<failed> Unsupported MCS rate index[%u]\n", eTxDataRate11n); |
| 1264 | return false; |
| 1265 | } |
| 1266 | |
| 1267 | if( (ePreambleType != 0) && (ePreambleType != 1) ) |
| 1268 | { |
| 1269 | DBGLOG("<failed> Unsupported N mode preamable type[%u]\n", ePreambleType); |
| 1270 | return false; |
| 1271 | } |
| 1272 | |
| 1273 | if( (eGIType != 0) && (eGIType != 1) ) |
| 1274 | { |
| 1275 | return false; |
| 1276 | } |
| 1277 | |
| 1278 | /* specify 11n rate */ |
| 1279 | u4Rate = RF_AT_PARAM_RATE_MCS_MASK | (uint32_t)(eTxDataRate11n); |
| 1280 | if(WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 1281 | u4Rate, |
| 1282 | NULL, |
| 1283 | NULL) != 0) { |
| 1284 | return false; |
| 1285 | } |
| 1286 | |
| 1287 | /* specify preamble type */ |
| 1288 | switch(ePreambleType) { |
| 1289 | case WIFI_TEST_PREAMBLE_TYPE_MIXED_MODE: |
| 1290 | u4Preamble = RF_AT_PREAMBLE_11N_MM; |
| 1291 | break; |
| 1292 | |
| 1293 | case WIFI_TEST_PREAMBLE_TYPE_GREENFIELD: |
| 1294 | u4Preamble = RF_AT_PREAMBLE_11N_GF; |
| 1295 | break; |
| 1296 | |
| 1297 | default: |
| 1298 | return false; |
| 1299 | } |
| 1300 | |
| 1301 | if(WIFI_TEST_set(RF_AT_FUNCID_PREAMBLE, |
| 1302 | u4Preamble, |
| 1303 | NULL, |
| 1304 | NULL) != 0) { |
| 1305 | return false; |
| 1306 | } |
| 1307 | |
| 1308 | /* specify Guard Interval type */ |
| 1309 | if(WIFI_TEST_set(RF_AT_FUNCID_GI, |
| 1310 | eGIType, |
| 1311 | NULL, |
| 1312 | NULL) != 0) { |
| 1313 | return false; |
| 1314 | } |
| 1315 | |
| 1316 | return true; |
| 1317 | } |
| 1318 | |
| 1319 | |
| 1320 | /* for 11ac test */ |
| 1321 | // GI (Gard interval) : 1 (Long GI), 2 (Short GI) |
| 1322 | bool WIFI_TEST_TxDataRate11ac( |
| 1323 | ENUM_WIFI_TEST_MCS_RATE eTxMcsRate, |
| 1324 | ENUM_WIFI_TEST_GI_TYPE eGIType |
| 1325 | ) |
| 1326 | { |
| 1327 | uint32_t u4Rate; |
| 1328 | |
| 1329 | if(eTxMcsRate > WIFI_TEST_MCS_RATE_9) |
| 1330 | { |
| 1331 | return false; |
| 1332 | } |
| 1333 | |
| 1334 | if( (eGIType != 0) && (eGIType != 1) ) |
| 1335 | { |
| 1336 | return false; |
| 1337 | } |
| 1338 | |
| 1339 | /* specify MCS rate */ |
| 1340 | u4Rate = RF_AT_PARAM_RATE_MCS_MASK | (uint32_t)(eTxMcsRate); |
| 1341 | if(WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 1342 | u4Rate, |
| 1343 | NULL, |
| 1344 | NULL) != 0) { |
| 1345 | return false; |
| 1346 | } |
| 1347 | |
| 1348 | if(WIFI_TEST_set(RF_AT_FUNCID_PREAMBLE, |
| 1349 | RF_AT_PREAMBLE_11AC, |
| 1350 | NULL, |
| 1351 | NULL) != 0) { |
| 1352 | return false; |
| 1353 | } |
| 1354 | |
| 1355 | /* specify Guard Interval type */ |
| 1356 | if(WIFI_TEST_set(RF_AT_FUNCID_GI, |
| 1357 | eGIType, |
| 1358 | NULL, |
| 1359 | NULL) != 0) { |
| 1360 | return false; |
| 1361 | } |
| 1362 | |
| 1363 | return true; |
| 1364 | } |
| 1365 | |
| 1366 | /* for 11n test */ |
| 1367 | bool WIFI_TEST_FrequencyAccuracy(int ChannelNo) |
| 1368 | { |
| 1369 | /* set channel */ |
| 1370 | if(WIFI_TEST_Channel(ChannelNo) == false) { |
| 1371 | return false; |
| 1372 | } |
| 1373 | |
| 1374 | /* start carrier tone */ |
| 1375 | if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND, |
| 1376 | RF_AT_COMMAND_LO_LEAKAGE, |
| 1377 | NULL, |
| 1378 | NULL) == 0) { |
| 1379 | return true; |
| 1380 | } |
| 1381 | else { |
| 1382 | return false; |
| 1383 | } |
| 1384 | } |
| 1385 | |
| 1386 | /* for 11n test */ |
| 1387 | bool WIFI_TEST_FrequencyAccuracy_Stop() |
| 1388 | { |
| 1389 | /* checking for testing mode */ |
| 1390 | if(WIFI_TEST_IsRunning() == false) { |
| 1391 | WIFI_TEST_OpenDUT(); |
| 1392 | } |
| 1393 | |
| 1394 | /* stop */ |
| 1395 | if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND, |
| 1396 | RF_AT_COMMAND_STOPTEST, |
| 1397 | NULL, |
| 1398 | NULL) == 0) { |
| 1399 | return true; |
| 1400 | } |
| 1401 | else { |
| 1402 | return false; |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | |
| 1407 | /******************************************************************************* |
| 1408 | * STYLE #B Control API |
| 1409 | ******************************************************************************* |
| 1410 | */ |
| 1411 | /* static variables for Style #B Control API */ |
| 1412 | static ENUM_WIFI_TEST_MODE eWifiTestMode = WIFI_TEST_MODE_BY_API_CONTROL; |
| 1413 | static ENUM_WIFI_BANDWIDTH eWifiBw = WIFI_TEST_BW_20MHZ; |
| 1414 | static uint32_t u4NumGoodFrames = 0; |
| 1415 | static uint32_t u4NumBadFrames = 0; |
| 1416 | |
| 1417 | bool WIFI_TEST_SetMode(ENUM_WIFI_TEST_MODE eMode) |
| 1418 | { |
| 1419 | if(eMode >= WIFI_TEST_MODE_NUM) { |
| 1420 | return false; |
| 1421 | } |
| 1422 | else { |
| 1423 | eWifiTestMode = eMode; |
| 1424 | return true; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | bool WIFI_TEST_GetSupportedMode(uint32_t *pu4SupportedMode) { |
| 1429 | uint8_t ucSupportVht = 1; |
| 1430 | |
| 1431 | if(pu4SupportedMode == NULL) { |
| 1432 | return false; |
| 1433 | } |
| 1434 | else { |
| 1435 | #if 1 |
| 1436 | ALOGE("%s: not supported\n", __func__); |
| 1437 | #else |
| 1438 | /* read fgEnable5GBand / fgSupport5GBand field from NVRAM */ |
| 1439 | uint8_t ucSupport5GBand = 0, ucEnable5GBand = 0; |
| 1440 | F_INFO rFileInfo; |
| 1441 | int fd; |
| 1442 | |
| 1443 | rFileInfo = NVM_ReadFileVerInfo(AP_CFG_RDEB_FILE_WIFI_LID); |
| 1444 | fd = open(rFileInfo.cFileName, O_RDONLY, S_IRUSR); |
| 1445 | if(fd != -1) { |
| 1446 | lseek(fd, offsetof(WIFI_CFG_PARAM_STRUCT, ucSupport5GBand), SEEK_SET); |
| 1447 | read(fd, &ucSupport5GBand, sizeof(uint8_t)); |
| 1448 | |
| 1449 | lseek(fd, offsetof(WIFI_CFG_PARAM_STRUCT, ucEnable5GBand), SEEK_SET); |
| 1450 | read(fd, &ucEnable5GBand, sizeof(uint8_t)); |
| 1451 | |
| 1452 | close(fd); |
| 1453 | } |
| 1454 | |
| 1455 | if(ucSupport5GBand && ucEnable5GBand) { |
| 1456 | *pu4SupportedMode = BIT((int)WIFI_TEST_MODE_80211A_ONLY) |
| 1457 | | BIT((int)WIFI_TEST_MODE_80211B_ONLY) |
| 1458 | | BIT((int)WIFI_TEST_MODE_80211G_ONLY) |
| 1459 | | BIT((int)WIFI_TEST_MODE_80211N_ONLY); |
| 1460 | } |
| 1461 | else { |
| 1462 | *pu4SupportedMode = BIT((int)WIFI_TEST_MODE_80211B_ONLY) |
| 1463 | | BIT((int)WIFI_TEST_MODE_80211G_ONLY) |
| 1464 | | BIT((int)WIFI_TEST_MODE_80211N_ONLY); |
| 1465 | } |
| 1466 | |
| 1467 | if(ucSupportVht) { |
| 1468 | *pu4SupportedMode |= BIT((int)WIFI_TEST_MODE_80211AC_ONLY); |
| 1469 | } |
| 1470 | |
| 1471 | return true; |
| 1472 | #endif |
| 1473 | } |
| 1474 | |
| 1475 | return false; |
| 1476 | } |
| 1477 | |
| 1478 | bool WIFI_TEST_SetBandwidth(ENUM_WIFI_BANDWIDTH eBandwidth) |
| 1479 | { |
| 1480 | int result = 0; |
| 1481 | ENUM_WIFI_CHANNEL_BANDWIDTH eChBw; |
| 1482 | |
| 1483 | if(eBandwidth >= WIFI_TEST_BW_NUM) { |
| 1484 | return false; |
| 1485 | } |
| 1486 | |
| 1487 | /* Legacy/11n BW */ |
| 1488 | if(eBandwidth < WIFI_TEST_BW_80MHZ) { |
| 1489 | result = WIFI_TEST_set(RF_AT_FUNCID_BANDWIDTH, (uint32_t)eBandwidth, |
| 1490 | NULL, NULL); |
| 1491 | } else { |
| 1492 | switch(eBandwidth) { |
| 1493 | case WIFI_TEST_BW_80MHZ: |
| 1494 | eChBw = WIFI_TEST_CH_BW_80MHZ; |
| 1495 | break; |
| 1496 | |
| 1497 | case WIFI_TEST_BW_160MHZ: |
| 1498 | eChBw = WIFI_TEST_CH_BW_160MHZ; |
| 1499 | break; |
| 1500 | |
| 1501 | default: |
| 1502 | return false; |
| 1503 | } |
| 1504 | |
| 1505 | result = WIFI_TEST_set(RF_AT_FUNCID_SET_CHANNEL_BANDWIDTH, |
| 1506 | (uint32_t)eChBw, NULL, NULL); |
| 1507 | } |
| 1508 | |
| 1509 | if(result == 0) { |
| 1510 | eWifiBw = eBandwidth; |
| 1511 | return true; |
| 1512 | } |
| 1513 | else { |
| 1514 | return false; |
| 1515 | } |
| 1516 | } |
| 1517 | |
| 1518 | bool WIFI_TEST_SetBandwidthV2(ENUM_WIFI_CHANNEL_BANDWIDTH eBandwidth) |
| 1519 | { |
| 1520 | int result = 0; |
| 1521 | |
| 1522 | if(eBandwidth >= WIFI_TEST_CH_BW_NUM) { |
| 1523 | return false; |
| 1524 | } |
| 1525 | |
| 1526 | result = WIFI_TEST_set(RF_AT_FUNCID_SET_CHANNEL_BANDWIDTH, |
| 1527 | (uint32_t)eBandwidth, NULL, NULL); |
| 1528 | |
| 1529 | return (result == 0)? true:false; |
| 1530 | } |
| 1531 | |
| 1532 | bool WIFI_TEST_SetPriChannelSetting(uint8_t ucPrimaryChSetting) |
| 1533 | { |
| 1534 | int result = 0; |
| 1535 | |
| 1536 | if(ucPrimaryChSetting >= WIFI_TEST_PRI_CH_SETTING_NUM) { |
| 1537 | return false; |
| 1538 | } |
| 1539 | |
| 1540 | result = WIFI_TEST_set(RF_AT_FUNCID_SET_PRI_SETTING, |
| 1541 | (uint32_t)ucPrimaryChSetting, NULL, NULL); |
| 1542 | |
| 1543 | return (result == 0)? true:false; |
| 1544 | } |
| 1545 | |
| 1546 | bool WIFI_TEST_SetTxBandwidth(ENUM_WIFI_CHANNEL_BANDWIDTH eBandwidth) |
| 1547 | { |
| 1548 | int result = 0; |
| 1549 | |
| 1550 | if(eBandwidth >= WIFI_TEST_CH_BW_NUM) { |
| 1551 | return false; |
| 1552 | } |
| 1553 | |
| 1554 | result = WIFI_TEST_set(RF_AT_FUNCID_SET_DATA_BANDWIDTH, |
| 1555 | (uint32_t)eBandwidth, NULL, NULL); |
| 1556 | |
| 1557 | return (result == 0)? true:false; |
| 1558 | } |
| 1559 | |
| 1560 | bool WIFI_TEST_SetFrequency(uint32_t u4FreqInMHz, uint32_t u4OffsetInKHz) |
| 1561 | { |
| 1562 | if(u4OffsetInKHz != 0) { |
| 1563 | /* not supporting offset frequency */ |
| 1564 | return false; |
| 1565 | } |
| 1566 | else { |
| 1567 | switch(eWifiTestMode) { |
| 1568 | case WIFI_TEST_MODE_80211B_ONLY: |
| 1569 | case WIFI_TEST_MODE_80211G_ONLY: |
| 1570 | /* check for channel #1 ~ channel #14 */ |
| 1571 | switch(u4FreqInMHz) { |
| 1572 | case 2412: |
| 1573 | return WIFI_TEST_Channel(1); |
| 1574 | case 2417: |
| 1575 | return WIFI_TEST_Channel(2); |
| 1576 | case 2422: |
| 1577 | return WIFI_TEST_Channel(3); |
| 1578 | case 2427: |
| 1579 | return WIFI_TEST_Channel(4); |
| 1580 | case 2432: |
| 1581 | return WIFI_TEST_Channel(5); |
| 1582 | case 2437: |
| 1583 | return WIFI_TEST_Channel(6); |
| 1584 | case 2442: |
| 1585 | return WIFI_TEST_Channel(7); |
| 1586 | case 2447: |
| 1587 | return WIFI_TEST_Channel(8); |
| 1588 | case 2452: |
| 1589 | return WIFI_TEST_Channel(9); |
| 1590 | case 2457: |
| 1591 | return WIFI_TEST_Channel(10); |
| 1592 | case 2462: |
| 1593 | return WIFI_TEST_Channel(11); |
| 1594 | case 2467: |
| 1595 | return WIFI_TEST_Channel(12); |
| 1596 | case 2472: |
| 1597 | return WIFI_TEST_Channel(13); |
| 1598 | case 2484: |
| 1599 | return WIFI_TEST_Channel(14); |
| 1600 | default: |
| 1601 | break; |
| 1602 | } |
| 1603 | break; |
| 1604 | |
| 1605 | case WIFI_TEST_MODE_80211A_ONLY: |
| 1606 | switch(u4FreqInMHz) { |
| 1607 | case 4915: |
| 1608 | return WIFI_TEST_Channel(183); |
| 1609 | case 4920: |
| 1610 | return WIFI_TEST_Channel(184); |
| 1611 | case 4925: |
| 1612 | return WIFI_TEST_Channel(185); |
| 1613 | case 4935: |
| 1614 | return WIFI_TEST_Channel(187); |
| 1615 | case 4940: |
| 1616 | return WIFI_TEST_Channel(188); |
| 1617 | case 4945: |
| 1618 | return WIFI_TEST_Channel(189); |
| 1619 | case 4960: |
| 1620 | return WIFI_TEST_Channel(192); |
| 1621 | case 4980: |
| 1622 | return WIFI_TEST_Channel(196); |
| 1623 | case 5170: |
| 1624 | return WIFI_TEST_Channel(34); |
| 1625 | case 5180: |
| 1626 | return WIFI_TEST_Channel(36); |
| 1627 | case 5190: |
| 1628 | return WIFI_TEST_Channel(38); |
| 1629 | case 5200: |
| 1630 | return WIFI_TEST_Channel(40); |
| 1631 | case 5210: |
| 1632 | return WIFI_TEST_Channel(42); |
| 1633 | case 5220: |
| 1634 | return WIFI_TEST_Channel(44); |
| 1635 | case 5230: |
| 1636 | return WIFI_TEST_Channel(46); |
| 1637 | case 5240: |
| 1638 | return WIFI_TEST_Channel(48); |
| 1639 | case 5260: |
| 1640 | return WIFI_TEST_Channel(52); |
| 1641 | case 5280: |
| 1642 | return WIFI_TEST_Channel(56); |
| 1643 | case 5300: |
| 1644 | return WIFI_TEST_Channel(60); |
| 1645 | case 5320: |
| 1646 | return WIFI_TEST_Channel(64); |
| 1647 | case 5500: |
| 1648 | return WIFI_TEST_Channel(100); |
| 1649 | case 5520: |
| 1650 | return WIFI_TEST_Channel(104); |
| 1651 | case 5540: |
| 1652 | return WIFI_TEST_Channel(108); |
| 1653 | case 5560: |
| 1654 | return WIFI_TEST_Channel(112); |
| 1655 | case 5580: |
| 1656 | return WIFI_TEST_Channel(116); |
| 1657 | case 5600: |
| 1658 | return WIFI_TEST_Channel(120); |
| 1659 | case 5620: |
| 1660 | return WIFI_TEST_Channel(124); |
| 1661 | case 5640: |
| 1662 | return WIFI_TEST_Channel(128); |
| 1663 | case 5660: |
| 1664 | return WIFI_TEST_Channel(132); |
| 1665 | case 5680: |
| 1666 | return WIFI_TEST_Channel(136); |
| 1667 | case 5700: |
| 1668 | return WIFI_TEST_Channel(140); |
| 1669 | case 5745: |
| 1670 | return WIFI_TEST_Channel(149); |
| 1671 | case 5765: |
| 1672 | return WIFI_TEST_Channel(153); |
| 1673 | case 5785: |
| 1674 | return WIFI_TEST_Channel(157); |
| 1675 | case 5805: |
| 1676 | return WIFI_TEST_Channel(161); |
| 1677 | case 5825: |
| 1678 | return WIFI_TEST_Channel(165); |
| 1679 | default: |
| 1680 | break; |
| 1681 | } |
| 1682 | break; |
| 1683 | |
| 1684 | case WIFI_TEST_MODE_80211N_ONLY: |
| 1685 | case WIFI_TEST_MODE_80211AC_ONLY: |
| 1686 | switch(u4FreqInMHz) { |
| 1687 | case 2412: |
| 1688 | return WIFI_TEST_Channel(1); |
| 1689 | case 2417: |
| 1690 | return WIFI_TEST_Channel(2); |
| 1691 | case 2422: |
| 1692 | return WIFI_TEST_Channel(3); |
| 1693 | case 2427: |
| 1694 | return WIFI_TEST_Channel(4); |
| 1695 | case 2432: |
| 1696 | return WIFI_TEST_Channel(5); |
| 1697 | case 2437: |
| 1698 | return WIFI_TEST_Channel(6); |
| 1699 | case 2442: |
| 1700 | return WIFI_TEST_Channel(7); |
| 1701 | case 2447: |
| 1702 | return WIFI_TEST_Channel(8); |
| 1703 | case 2452: |
| 1704 | return WIFI_TEST_Channel(9); |
| 1705 | case 2457: |
| 1706 | return WIFI_TEST_Channel(10); |
| 1707 | case 2462: |
| 1708 | return WIFI_TEST_Channel(11); |
| 1709 | case 2467: |
| 1710 | return WIFI_TEST_Channel(12); |
| 1711 | case 2472: |
| 1712 | return WIFI_TEST_Channel(13); |
| 1713 | case 2484: |
| 1714 | return WIFI_TEST_Channel(14); |
| 1715 | case 4915: |
| 1716 | return WIFI_TEST_Channel(183); |
| 1717 | case 4920: |
| 1718 | return WIFI_TEST_Channel(184); |
| 1719 | case 4925: |
| 1720 | return WIFI_TEST_Channel(185); |
| 1721 | case 4935: |
| 1722 | return WIFI_TEST_Channel(187); |
| 1723 | case 4940: |
| 1724 | return WIFI_TEST_Channel(188); |
| 1725 | case 4945: |
| 1726 | return WIFI_TEST_Channel(189); |
| 1727 | case 4960: |
| 1728 | return WIFI_TEST_Channel(192); |
| 1729 | case 4980: |
| 1730 | return WIFI_TEST_Channel(196); |
| 1731 | case 5170: |
| 1732 | return WIFI_TEST_Channel(34); |
| 1733 | case 5180: |
| 1734 | return WIFI_TEST_Channel(36); |
| 1735 | case 5190: |
| 1736 | return WIFI_TEST_Channel(38); |
| 1737 | case 5200: |
| 1738 | return WIFI_TEST_Channel(40); |
| 1739 | case 5210: |
| 1740 | return WIFI_TEST_Channel(42); |
| 1741 | case 5220: |
| 1742 | return WIFI_TEST_Channel(44); |
| 1743 | case 5230: |
| 1744 | return WIFI_TEST_Channel(46); |
| 1745 | case 5240: |
| 1746 | return WIFI_TEST_Channel(48); |
| 1747 | case 5260: |
| 1748 | return WIFI_TEST_Channel(52); |
| 1749 | case 5280: |
| 1750 | return WIFI_TEST_Channel(56); |
| 1751 | case 5300: |
| 1752 | return WIFI_TEST_Channel(60); |
| 1753 | case 5320: |
| 1754 | return WIFI_TEST_Channel(64); |
| 1755 | case 5500: |
| 1756 | return WIFI_TEST_Channel(100); |
| 1757 | case 5520: |
| 1758 | return WIFI_TEST_Channel(104); |
| 1759 | case 5540: |
| 1760 | return WIFI_TEST_Channel(108); |
| 1761 | case 5560: |
| 1762 | return WIFI_TEST_Channel(112); |
| 1763 | case 5580: |
| 1764 | return WIFI_TEST_Channel(116); |
| 1765 | case 5600: |
| 1766 | return WIFI_TEST_Channel(120); |
| 1767 | case 5620: |
| 1768 | return WIFI_TEST_Channel(124); |
| 1769 | case 5640: |
| 1770 | return WIFI_TEST_Channel(128); |
| 1771 | case 5660: |
| 1772 | return WIFI_TEST_Channel(132); |
| 1773 | case 5680: |
| 1774 | return WIFI_TEST_Channel(136); |
| 1775 | case 5700: |
| 1776 | return WIFI_TEST_Channel(140); |
| 1777 | case 5745: |
| 1778 | return WIFI_TEST_Channel(149); |
| 1779 | case 5765: |
| 1780 | return WIFI_TEST_Channel(153); |
| 1781 | case 5785: |
| 1782 | return WIFI_TEST_Channel(157); |
| 1783 | case 5805: |
| 1784 | return WIFI_TEST_Channel(161); |
| 1785 | case 5825: |
| 1786 | return WIFI_TEST_Channel(165); |
| 1787 | default: |
| 1788 | break; |
| 1789 | } |
| 1790 | break; |
| 1791 | |
| 1792 | default: |
| 1793 | break; |
| 1794 | } |
| 1795 | |
| 1796 | return false; |
| 1797 | } |
| 1798 | } |
| 1799 | |
| 1800 | bool WIFI_TEST_SetRate(uint32_t u4Rate) |
| 1801 | { |
| 1802 | ENUM_WIFI_TEST_GI_TYPE eGIType; |
| 1803 | uint32_t u4RateCode; |
| 1804 | ALOGD("[%s] Rate=[%d]\n", __func__, u4Rate); |
| 1805 | |
| 1806 | /* validate rate by mode/bandwidth settings */ |
| 1807 | if(eWifiTestMode == WIFI_TEST_MODE_80211B_ONLY) { |
| 1808 | switch(u4Rate) { |
| 1809 | case 100: |
| 1810 | u4RateCode = RF_AT_PARAM_RATE_1M; |
| 1811 | break; |
| 1812 | |
| 1813 | case 200: |
| 1814 | u4RateCode = RF_AT_PARAM_RATE_2M; |
| 1815 | break; |
| 1816 | |
| 1817 | case 550: |
| 1818 | u4RateCode = RF_AT_PARAM_RATE_5_5M; |
| 1819 | break; |
| 1820 | |
| 1821 | case 1100: |
| 1822 | u4RateCode = RF_AT_PARAM_RATE_11M; |
| 1823 | break; |
| 1824 | |
| 1825 | default: |
| 1826 | return false; |
| 1827 | } |
| 1828 | } |
| 1829 | else if(eWifiTestMode == WIFI_TEST_MODE_80211G_ONLY || eWifiTestMode == WIFI_TEST_MODE_80211A_ONLY) { |
| 1830 | switch(u4Rate) { |
| 1831 | case 600: |
| 1832 | u4RateCode = RF_AT_PARAM_RATE_6M; |
| 1833 | break; |
| 1834 | |
| 1835 | case 900: |
| 1836 | u4RateCode = RF_AT_PARAM_RATE_9M; |
| 1837 | break; |
| 1838 | |
| 1839 | case 1200: |
| 1840 | u4RateCode = RF_AT_PARAM_RATE_12M; |
| 1841 | break; |
| 1842 | |
| 1843 | case 1800: |
| 1844 | u4RateCode = RF_AT_PARAM_RATE_18M; |
| 1845 | break; |
| 1846 | |
| 1847 | case 2400: |
| 1848 | u4RateCode = RF_AT_PARAM_RATE_24M; |
| 1849 | break; |
| 1850 | |
| 1851 | case 3600: |
| 1852 | u4RateCode = RF_AT_PARAM_RATE_36M; |
| 1853 | break; |
| 1854 | |
| 1855 | case 4800: |
| 1856 | u4RateCode = RF_AT_PARAM_RATE_48M; |
| 1857 | break; |
| 1858 | |
| 1859 | case 5400: |
| 1860 | u4RateCode = RF_AT_PARAM_RATE_54M; |
| 1861 | break; |
| 1862 | |
| 1863 | default: |
| 1864 | return false; |
| 1865 | } |
| 1866 | } |
| 1867 | else if(eWifiTestMode == WIFI_TEST_MODE_80211N_ONLY && eWifiBw == WIFI_TEST_BW_20MHZ) { |
| 1868 | switch(u4Rate) { |
| 1869 | case 650: |
| 1870 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_0; |
| 1871 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1872 | break; |
| 1873 | case 720: |
| 1874 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_0; |
| 1875 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1876 | break; |
| 1877 | case 1300: |
| 1878 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_1; |
| 1879 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1880 | break; |
| 1881 | case 1440: |
| 1882 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_1; |
| 1883 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1884 | break; |
| 1885 | case 1950: |
| 1886 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_2; |
| 1887 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1888 | break; |
| 1889 | case 2170: |
| 1890 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_2; |
| 1891 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1892 | break; |
| 1893 | case 2600: |
| 1894 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_3; |
| 1895 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1896 | break; |
| 1897 | case 2890: |
| 1898 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_3; |
| 1899 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1900 | break; |
| 1901 | case 3900: |
| 1902 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_4; |
| 1903 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1904 | break; |
| 1905 | case 4330: |
| 1906 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_4; |
| 1907 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1908 | break; |
| 1909 | case 5200: |
| 1910 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_5; |
| 1911 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1912 | break; |
| 1913 | case 5780: |
| 1914 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_5; |
| 1915 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1916 | break; |
| 1917 | case 5850: |
| 1918 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_6; |
| 1919 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1920 | break; |
| 1921 | case 6500: |
| 1922 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_7; |
| 1923 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1924 | break; |
| 1925 | case 7200: |
| 1926 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_7; |
| 1927 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1928 | break; |
| 1929 | default: |
| 1930 | return false; |
| 1931 | } |
| 1932 | } |
| 1933 | else if(eWifiTestMode == WIFI_TEST_MODE_80211N_ONLY && eWifiBw == WIFI_TEST_BW_40MHZ) { |
| 1934 | switch(u4Rate) { |
| 1935 | case 1350: |
| 1936 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_0; |
| 1937 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1938 | break; |
| 1939 | case 1500: |
| 1940 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_0; |
| 1941 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1942 | break; |
| 1943 | case 2700: |
| 1944 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_1; |
| 1945 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1946 | break; |
| 1947 | case 3000: |
| 1948 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_1; |
| 1949 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1950 | break; |
| 1951 | case 4050: |
| 1952 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_2; |
| 1953 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1954 | break; |
| 1955 | case 4500: |
| 1956 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_2; |
| 1957 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1958 | break; |
| 1959 | case 5400: |
| 1960 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_3; |
| 1961 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1962 | break; |
| 1963 | case 6000: |
| 1964 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_3; |
| 1965 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1966 | break; |
| 1967 | case 8100: |
| 1968 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_4; |
| 1969 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1970 | break; |
| 1971 | case 9000: |
| 1972 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_4; |
| 1973 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1974 | break; |
| 1975 | case 10800: |
| 1976 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_5; |
| 1977 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1978 | break; |
| 1979 | case 12000: |
| 1980 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_5; |
| 1981 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1982 | break; |
| 1983 | case 12150: |
| 1984 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_6; |
| 1985 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1986 | break; |
| 1987 | case 13500: |
| 1988 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_7; |
| 1989 | eGIType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 1990 | break; |
| 1991 | case 15000: |
| 1992 | u4RateCode = RF_AT_PARAM_RATE_MCS_MASK | WIFI_TEST_MCS_RATE_7; |
| 1993 | eGIType = WIFI_TEST_GI_TYPE_SHORT_GI; |
| 1994 | break; |
| 1995 | default: |
| 1996 | return false; |
| 1997 | } |
| 1998 | } |
| 1999 | else { |
| 2000 | return false; |
| 2001 | } |
| 2002 | |
| 2003 | /* set GI type */ |
| 2004 | if(eWifiTestMode == WIFI_TEST_MODE_80211N_ONLY && |
| 2005 | WIFI_TEST_set(RF_AT_FUNCID_GI, |
| 2006 | eGIType, |
| 2007 | NULL, |
| 2008 | NULL) != 0) { |
| 2009 | return false; |
| 2010 | } |
| 2011 | |
| 2012 | /* set rate code */ |
| 2013 | if(WIFI_TEST_set(RF_AT_FUNCID_RATE, |
| 2014 | u4RateCode, |
| 2015 | NULL, |
| 2016 | NULL) == 0) { |
| 2017 | return true; |
| 2018 | } |
| 2019 | else { |
| 2020 | return false; |
| 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | bool WIFI_TEST_SetTXPower(uint32_t u4Gain) |
| 2025 | { |
| 2026 | if(u4Gain > 6350) { |
| 2027 | return false; |
| 2028 | } |
| 2029 | else if(WIFI_TEST_set(RF_AT_FUNCID_POWER, |
| 2030 | u4Gain / 50, // convert to unit of 0.5dBm |
| 2031 | NULL, |
| 2032 | NULL) == 0) { |
| 2033 | return true; |
| 2034 | } |
| 2035 | else { |
| 2036 | return false; |
| 2037 | } |
| 2038 | } |
| 2039 | |
| 2040 | bool WIFI_TEST_SetTX(bool fgEnable) |
| 2041 | { |
| 2042 | if(fgEnable == true) { |
| 2043 | return WIFI_TEST_TxStart(); |
| 2044 | } |
| 2045 | else { |
| 2046 | return WIFI_TEST_TxStop(); |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | bool WIFI_TEST_SetRX(bool fgEnable, char *aucSrcAddr, char *aucDstAddr) |
| 2051 | { |
| 2052 | uint8_t aucMacAddr[4]; |
| 2053 | uint32_t u4MacAddr; |
| 2054 | ENUM_RF_AT_RXOK_MATCH_RULE_T eRxRule; |
| 2055 | |
| 2056 | if(fgEnable == true) { |
| 2057 | if(aucSrcAddr && aucDstAddr) { |
| 2058 | eRxRule = RF_AT_RXOK_DISABLED; |
| 2059 | } |
| 2060 | else if(aucDstAddr) { |
| 2061 | eRxRule = RF_AT_RXOK_MATCH_RA_ONLY; |
| 2062 | } |
| 2063 | else if(aucSrcAddr) { |
| 2064 | eRxRule = RF_AT_RXOK_MATCH_TA_ONLY; |
| 2065 | } |
| 2066 | else { |
| 2067 | eRxRule = RF_AT_RXOK_DISABLED; |
| 2068 | } |
| 2069 | |
| 2070 | /* specify policy */ |
| 2071 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_RXOK_MATCH_RULE, |
| 2072 | eRxRule, |
| 2073 | NULL, |
| 2074 | NULL) != 0) { |
| 2075 | return false; |
| 2076 | } |
| 2077 | |
| 2078 | if(aucDstAddr) { |
| 2079 | /* specify MAC address[0:3] */ |
| 2080 | memcpy(aucMacAddr, aucDstAddr, sizeof(uint8_t) * 4); |
| 2081 | u4MacAddr = *(uint32_t *)(&(aucMacAddr[0])); |
| 2082 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_DST_ADDRESS, |
| 2083 | u4MacAddr, |
| 2084 | NULL, |
| 2085 | NULL) != 0) { |
| 2086 | return false; |
| 2087 | } |
| 2088 | |
| 2089 | /* specify MAC address[4:5] */ |
| 2090 | memset(aucMacAddr, 0, sizeof(uint8_t) * 4); |
| 2091 | memcpy(aucMacAddr, &(aucDstAddr[4]), sizeof(uint8_t) * 2); |
| 2092 | u4MacAddr = *(uint32_t *)(&(aucMacAddr[0])); |
| 2093 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_DST_ADDRESS | (4 << TEST_SET_CMD_OFFSET), |
| 2094 | u4MacAddr, |
| 2095 | NULL, |
| 2096 | NULL) != 0) { |
| 2097 | return false; |
| 2098 | } |
| 2099 | } |
| 2100 | |
| 2101 | if(aucSrcAddr) { |
| 2102 | /* specify MAC address[0:3] */ |
| 2103 | memcpy(aucMacAddr, aucSrcAddr, sizeof(uint8_t) * 4); |
| 2104 | u4MacAddr = *(uint32_t *)(&(aucMacAddr[0])); |
| 2105 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_SRC_ADDRESS, |
| 2106 | u4MacAddr, |
| 2107 | NULL, |
| 2108 | NULL) != 0) { |
| 2109 | return false; |
| 2110 | } |
| 2111 | |
| 2112 | /* specify MAC address[4:5] */ |
| 2113 | memset(aucMacAddr, 0, sizeof(uint8_t) * 4); |
| 2114 | memcpy(aucMacAddr, &(aucSrcAddr[4]), sizeof(uint8_t) * 2); |
| 2115 | u4MacAddr = *(uint32_t *)(&(aucMacAddr[0])); |
| 2116 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_MAC_SRC_ADDRESS | (4 << TEST_SET_CMD_OFFSET), |
| 2117 | u4MacAddr, |
| 2118 | NULL, |
| 2119 | NULL) != 0) { |
| 2120 | return false; |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | /* Start RX */ |
| 2125 | //return WIFI_TEST_RxStart(); |
| 2126 | return true; |
| 2127 | } |
| 2128 | else { |
| 2129 | if(aucSrcAddr && aucDstAddr) { |
| 2130 | eRxRule = RF_AT_RXOK_DISABLED; |
| 2131 | } |
| 2132 | else if(aucDstAddr) { |
| 2133 | eRxRule = RF_AT_RXOK_MATCH_RA_ONLY; |
| 2134 | } |
| 2135 | else if(aucSrcAddr) { |
| 2136 | eRxRule = RF_AT_RXOK_MATCH_TA_ONLY; |
| 2137 | } |
| 2138 | else { |
| 2139 | eRxRule = RF_AT_RXOK_DISABLED; |
| 2140 | } |
| 2141 | /* specify policy */ |
| 2142 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_RXOK_MATCH_RULE, |
| 2143 | eRxRule, |
| 2144 | NULL, |
| 2145 | NULL) != 0) { |
| 2146 | return false; |
| 2147 | } |
| 2148 | //return WIFI_TEST_RxStop(); |
| 2149 | return true; |
| 2150 | } |
| 2151 | } |
| 2152 | |
| 2153 | bool WIFI_TEST_ClearResult(void) |
| 2154 | { |
| 2155 | if(WIFI_TEST_get(RF_AT_FUNCID_RXOK_COUNT, |
| 2156 | 0, |
| 2157 | NULL, |
| 2158 | &u4NumGoodFrames) == 0 && |
| 2159 | WIFI_TEST_get(RF_AT_FUNCID_RXERROR_COUNT, |
| 2160 | 0, |
| 2161 | NULL, |
| 2162 | &u4NumBadFrames) == 0) { |
| 2163 | return true; |
| 2164 | } |
| 2165 | else { |
| 2166 | return false; |
| 2167 | } |
| 2168 | } |
| 2169 | |
| 2170 | bool WIFI_TEST_GetResult(uint32_t *pu4GoodFrameCount, uint32_t *pu4BadFrameCount) |
| 2171 | { |
| 2172 | uint32_t u4GoodCnt, u4BadCnt; |
| 2173 | |
| 2174 | if(WIFI_TEST_get(RF_AT_FUNCID_RXOK_COUNT, |
| 2175 | 0, |
| 2176 | NULL, |
| 2177 | &u4GoodCnt) == 0 && |
| 2178 | WIFI_TEST_get(RF_AT_FUNCID_RXERROR_COUNT, |
| 2179 | 0, |
| 2180 | NULL, |
| 2181 | &u4BadCnt) == 0) { |
| 2182 | |
| 2183 | if(pu4GoodFrameCount) { |
| 2184 | *pu4GoodFrameCount = u4GoodCnt - u4NumGoodFrames; |
| 2185 | } |
| 2186 | if(pu4BadFrameCount) { |
| 2187 | *pu4BadFrameCount = u4BadCnt - u4NumBadFrames; |
| 2188 | } |
| 2189 | |
| 2190 | return true; |
| 2191 | } |
| 2192 | else { |
| 2193 | return false; |
| 2194 | } |
| 2195 | } |
| 2196 | |
| 2197 | |
| 2198 | /* Set Rx default antenna for Rx diversity */ |
| 2199 | /* 0: main antenna */ |
| 2200 | /* 1: AUX antenna */ |
| 2201 | bool WIFI_TEST_SetRxDefaultAnt(uint8_t ucUseAuxAnt) |
| 2202 | { |
| 2203 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_RX_DEF_ANT, |
| 2204 | ucUseAuxAnt, |
| 2205 | NULL, |
| 2206 | NULL) == 0) { |
| 2207 | return true; |
| 2208 | } |
| 2209 | else { |
| 2210 | return false; |
| 2211 | } |
| 2212 | } |
| 2213 | |
| 2214 | /* Set Tx encoding mode */ |
| 2215 | /* 0: BCC */ |
| 2216 | /* 1: LDPC */ |
| 2217 | bool WIFI_TEST_SetTxCodingMode(uint8_t ucLdpc) |
| 2218 | { |
| 2219 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_TX_ENCODE_MODE, |
| 2220 | ucLdpc, |
| 2221 | NULL, |
| 2222 | NULL) == 0) { |
| 2223 | return true; |
| 2224 | } |
| 2225 | else { |
| 2226 | return false; |
| 2227 | } |
| 2228 | } |
| 2229 | |
| 2230 | /* Set J mode */ |
| 2231 | /* 0: disable */ |
| 2232 | /* 1: 5M single tone */ |
| 2233 | /* 2: 10M single tone */ |
| 2234 | bool WIFI_TEST_SetJMode(ENUM_WIFI_J_MODE eJModeSetting) |
| 2235 | { |
| 2236 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_J_MODE_SETTING, |
| 2237 | eJModeSetting, |
| 2238 | NULL, |
| 2239 | NULL) == 0) { |
| 2240 | return true; |
| 2241 | } |
| 2242 | else { |
| 2243 | return false; |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | //for cw mode |
| 2248 | bool WIFI_TEST_TxTraining(void) |
| 2249 | { |
| 2250 | bool result = false; |
| 2251 | |
| 2252 | result = WIFI_TEST_TxBurstInterval(20); |
| 2253 | if(!result) |
| 2254 | return result; |
| 2255 | |
| 2256 | result = WIFI_TEST_TxBurstFrames(50); |
| 2257 | if(!result) |
| 2258 | return result; |
| 2259 | |
| 2260 | result = WIFI_TEST_TxPayloadLength(500); |
| 2261 | if(!result) |
| 2262 | return result; |
| 2263 | |
| 2264 | result = WIFI_TEST_TxStart(); |
| 2265 | if(!result) |
| 2266 | return result; |
| 2267 | |
| 2268 | usleep(200000); |
| 2269 | |
| 2270 | result = WIFI_TEST_TxStop(); |
| 2271 | if(!result) |
| 2272 | return result; |
| 2273 | |
| 2274 | return true; |
| 2275 | } |
| 2276 | |
| 2277 | bool WIFI_TEST_CW_MODE(int mode) |
| 2278 | { |
| 2279 | if(WIFI_TEST_set(RF_AT_FUNCID_SET_CW_MODE, |
| 2280 | (uint32_t)mode, |
| 2281 | NULL, |
| 2282 | NULL) == 0) { |
| 2283 | return true; |
| 2284 | } |
| 2285 | else { |
| 2286 | return false; |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | bool WIFI_TEST_DPD_MODE(int mode) |
| 2291 | { |
| 2292 | if(WIFI_TEST_set(RF_AT_FUNCID_DPD_MODE, |
| 2293 | (uint32_t)mode, |
| 2294 | NULL, |
| 2295 | NULL) == 0) { |
| 2296 | return true; |
| 2297 | } |
| 2298 | else { |
| 2299 | return false; |
| 2300 | } |
| 2301 | } |
| 2302 | |
| 2303 | bool WIFI_TEST_TEMP_COMPEN_MODE(int mode) |
| 2304 | { |
| 2305 | if(WIFI_TEST_set(RF_AT_FUNCID_TEMP_COMPEN, |
| 2306 | (uint32_t)mode, |
| 2307 | NULL, |
| 2308 | NULL) == 0) { |
| 2309 | return true; |
| 2310 | } |
| 2311 | else { |
| 2312 | return false; |
| 2313 | } |
| 2314 | } |
| 2315 | |
| 2316 | bool WIFI_TEST_TX_POWER_MODE(int mode) |
| 2317 | { |
| 2318 | if(WIFI_TEST_set(RF_AT_FUNCID_TX_PWR_MODE, |
| 2319 | (uint32_t)mode, |
| 2320 | NULL, |
| 2321 | NULL) == 0) { |
| 2322 | return true; |
| 2323 | } |
| 2324 | else { |
| 2325 | return false; |
| 2326 | } |
| 2327 | } |
| 2328 | |
| 2329 | bool WIFI_TEST_CW_MODE_START(void) |
| 2330 | { |
| 2331 | /* cw mode start */ |
| 2332 | if(WIFI_TEST_TxTraining() == false) { |
| 2333 | return false; |
| 2334 | } |
| 2335 | |
| 2336 | if(WIFI_TEST_set(RF_AT_FUNCID_COMMAND, |
| 2337 | RF_AT_COMMAND_CW, |
| 2338 | NULL, |
| 2339 | NULL) == 0) { |
| 2340 | return true; |
| 2341 | } |
| 2342 | else { |
| 2343 | return false; |
| 2344 | } |
| 2345 | |
| 2346 | |
| 2347 | } |
| 2348 | |
| 2349 | bool WIFI_TEST_init(void) { |
| 2350 | /* initialize skfd */ |
| 2351 | if (skfd < 0 && (skfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { |
| 2352 | ALOGE("[%s] failed to open net socket\n", __func__); |
| 2353 | return false; |
| 2354 | } |
| 2355 | return true; |
| 2356 | } |
| 2357 | |
| 2358 | void WIFI_TEST_deinit(void) { |
| 2359 | /* close socket if necessary */ |
| 2360 | if(skfd > 0) { |
| 2361 | close(skfd); |
| 2362 | skfd = -1; |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | /*----------------------------------------------------------------------------*/ |
| 2367 | /*! |
| 2368 | * @brief This API provided a service for EFUSE query commands |
| 2369 | * |
| 2370 | * @param |
| 2371 | * |
| 2372 | * @return |
| 2373 | */ |
| 2374 | /*----------------------------------------------------------------------------*/ |
| 2375 | |
| 2376 | bool WIFI_TEST_EFUSE_Read(unsigned int offset, unsigned int *val) |
| 2377 | { |
| 2378 | if (!val) { |
| 2379 | return false; |
| 2380 | } |
| 2381 | |
| 2382 | if (WIFI_TEST_get(RF_AT_FUNCID_READ_EFUSE, |
| 2383 | offset, |
| 2384 | NULL, |
| 2385 | (uint32_t *)val) != 0) { |
| 2386 | return false; |
| 2387 | } |
| 2388 | return true; |
| 2389 | } |
| 2390 | |
| 2391 | /*----------------------------------------------------------------------------*/ |
| 2392 | /*! |
| 2393 | * @brief This API provided a service for EFUSE write commands |
| 2394 | * |
| 2395 | * @param |
| 2396 | * |
| 2397 | * @return |
| 2398 | */ |
| 2399 | /*----------------------------------------------------------------------------*/ |
| 2400 | |
| 2401 | bool WIFI_TEST_EFUSE_Write(unsigned int offset, unsigned int val) |
| 2402 | { |
| 2403 | if (WIFI_TEST_set(RF_AT_FUNCID_WRITE_EFUSE | (offset << TEST_SET_CMD_OFFSET), |
| 2404 | val, |
| 2405 | NULL, |
| 2406 | NULL) != 0) { |
| 2407 | return false; |
| 2408 | } |
| 2409 | return true; |
| 2410 | } |
| 2411 | |
| 2412 | /*----------------------------------------------------------------------------*/ |
| 2413 | /*! |
| 2414 | * @brief This API provided a service for MCR query commands |
| 2415 | * |
| 2416 | * @param |
| 2417 | * |
| 2418 | * @return |
| 2419 | */ |
| 2420 | /*----------------------------------------------------------------------------*/ |
| 2421 | |
| 2422 | bool WIFI_TEST_MCR_Read(unsigned int addr, unsigned int *val) |
| 2423 | { |
| 2424 | int retval = -1; |
| 2425 | struct iwreq wrq; |
| 2426 | NDIS_TRANSPORT_STRUCT rNdisStruct; |
| 2427 | P_PARAM_CUSTOM_MCR_RW_STRUC_T prMCRStruct; |
| 2428 | |
| 2429 | prMCRStruct = (P_PARAM_CUSTOM_MCR_RW_STRUC_T)rNdisStruct.ndisOidContent; |
| 2430 | /* zeroize */ |
| 2431 | memset(&wrq, 0, sizeof(struct iwreq)); |
| 2432 | |
| 2433 | prMCRStruct->u4McrOffset = addr; |
| 2434 | /* zeroize */ |
| 2435 | rNdisStruct.ndisOidCmd = OID_CUSTOM_MCR_RW; |
| 2436 | rNdisStruct.inNdisOidlength = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T); |
| 2437 | rNdisStruct.outNdisOidLength = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T); |
| 2438 | |
| 2439 | wrq.u.data.pointer = &rNdisStruct; |
| 2440 | wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT); |
| 2441 | wrq.u.data.flags = PRIV_CMD_OID; |
| 2442 | |
| 2443 | retval = ioctl_iw_ext(IOCTL_GET_STRUCT, &wrq); |
| 2444 | |
| 2445 | if (retval == 0) { |
| 2446 | *val = prMCRStruct->u4McrData; |
| 2447 | } |
| 2448 | |
| 2449 | return !retval; |
| 2450 | } |
| 2451 | |
| 2452 | /*----------------------------------------------------------------------------*/ |
| 2453 | /*! |
| 2454 | * @brief This API provided a service for MCR set commands |
| 2455 | * |
| 2456 | * @param |
| 2457 | * |
| 2458 | * @return |
| 2459 | */ |
| 2460 | /*----------------------------------------------------------------------------*/ |
| 2461 | |
| 2462 | bool WIFI_TEST_MCR_Write(unsigned int addr, unsigned int val) |
| 2463 | { |
| 2464 | int retval = -1; |
| 2465 | struct iwreq wrq; |
| 2466 | NDIS_TRANSPORT_STRUCT rNdisStruct; |
| 2467 | P_PARAM_CUSTOM_MCR_RW_STRUC_T prMCRStruct; |
| 2468 | |
| 2469 | prMCRStruct = (P_PARAM_CUSTOM_MCR_RW_STRUC_T)rNdisStruct.ndisOidContent; |
| 2470 | /* zeroize */ |
| 2471 | memset(&wrq, 0, sizeof(struct iwreq)); |
| 2472 | |
| 2473 | prMCRStruct->u4McrOffset = addr; |
| 2474 | prMCRStruct->u4McrData = val; |
| 2475 | /* zeroize */ |
| 2476 | rNdisStruct.ndisOidCmd = OID_CUSTOM_MCR_RW; |
| 2477 | rNdisStruct.inNdisOidlength = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T); |
| 2478 | rNdisStruct.outNdisOidLength = sizeof(PARAM_CUSTOM_MCR_RW_STRUC_T); |
| 2479 | |
| 2480 | wrq.u.data.pointer = &rNdisStruct; |
| 2481 | wrq.u.data.length = sizeof(NDIS_TRANSPORT_STRUCT); |
| 2482 | wrq.u.data.flags = PRIV_CMD_OID; |
| 2483 | |
| 2484 | retval = ioctl_iw_ext(IOCTL_SET_STRUCT, &wrq); |
| 2485 | |
| 2486 | return !retval; |
| 2487 | } |
| 2488 | |