rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | /* MediaTek Inc. (C) 2010. All rights reserved. |
| 2 | * |
| 3 | * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES |
| 4 | * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE") |
| 5 | * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO RECEIVER ON |
| 6 | * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES, |
| 7 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF |
| 8 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT. |
| 9 | * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE |
| 10 | * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR |
| 11 | * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH |
| 12 | * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES |
| 13 | * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES |
| 14 | * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK |
| 15 | * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR |
| 16 | * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND |
| 17 | * CUMULATIVE LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE, |
| 18 | * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE, |
| 19 | * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO |
| 20 | * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. |
| 21 | * |
| 22 | * The following software/firmware and/or related documentation ("MediaTek Software") |
| 23 | * have been modified by MediaTek Inc. All revisions are subject to any receiver's |
| 24 | * applicable license agreements with MediaTek Inc. |
| 25 | */ |
| 26 | |
| 27 | #include <stdio.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <unistd.h> |
| 30 | #include <signal.h> |
| 31 | #include <string.h> |
| 32 | #include <sys/stat.h> |
| 33 | #include "libwifitest.h" |
| 34 | #include "lib.h" |
| 35 | #ifdef ANDROID |
| 36 | #include <cutils/properties.h> |
| 37 | #include <sys/system_properties.h> |
| 38 | #endif |
| 39 | #include <errno.h> |
| 40 | |
| 41 | #define PACKAGE "WifiHwTestTool" |
| 42 | |
| 43 | char proc_name[256]; |
| 44 | |
| 45 | typedef enum { |
| 46 | WLAN_MODE_OFF, |
| 47 | NORMAL_MODE_ON, |
| 48 | TEST_MODE_ON |
| 49 | }WlanStatus; |
| 50 | |
| 51 | typedef enum { |
| 52 | OPER_NONE, |
| 53 | TEST_TX, |
| 54 | TEST_RX, |
| 55 | READ_EFUSE, |
| 56 | WRITE_EFUSE, |
| 57 | READ_MCR, |
| 58 | WRITE_MCR, |
| 59 | TEST_STOP, |
| 60 | QUERY_RESULT |
| 61 | }Oper_Mode; |
| 62 | |
| 63 | typedef enum _ENUM_RX_MATCH_RULE_T { |
| 64 | RX_MATCH_RULE_DISABLE, |
| 65 | RX_MATCH_RULE_RA, /* RA only */ |
| 66 | RX_MATCH_RULE_TA, /* TA only */ |
| 67 | RX_MATCH_RULE_RA_TA, /* Both RA and TA */ |
| 68 | RX_MATCH_RULE_NUM |
| 69 | } ENUM_RX_MATCH_RULE_T, *P_ENUM_RX_MATCH_RULE_T; |
| 70 | |
| 71 | typedef enum _ENUM_FUNCTION_MODE { |
| 72 | MODE_DISABLE = 0, |
| 73 | MODE_ENABLE |
| 74 | } ENUM_FUNCTION_MODE_T, *P__ENUM_FUNCTION_MODE_T; |
| 75 | |
| 76 | char *bg_rate[] = { |
| 77 | "RATE_AUTO", |
| 78 | "RATE_1MBPS", |
| 79 | "RATE_2MBPS", |
| 80 | "RATE_5_5MBPS", |
| 81 | "RATE_6MBPS", |
| 82 | "RATE_9MBPS", |
| 83 | "RATE_11MBPS", |
| 84 | "RATE_12MBPS", |
| 85 | "RATE_18MBPS", |
| 86 | "RATE_24MBPS", |
| 87 | "RATE_36MBPS", |
| 88 | "RATE_48MBPS", |
| 89 | "RATE_54MBPS", |
| 90 | }; |
| 91 | char *preamble[] = { |
| 92 | "LONG", |
| 93 | "SHORT", |
| 94 | }; |
| 95 | char *bandwidth[] = { |
| 96 | "BW20", |
| 97 | "BW40", |
| 98 | "BW20U", |
| 99 | "BW20L", |
| 100 | "BW80", |
| 101 | "BW160" |
| 102 | }; |
| 103 | |
| 104 | char *bandwidthV2[] = { |
| 105 | "BW20", |
| 106 | "BW40", |
| 107 | "BW80", |
| 108 | "BW160" |
| 109 | }; |
| 110 | |
| 111 | static void wifi_sensitivity(int, int); |
| 112 | static void wifi_tx(); |
| 113 | static WlanStatus wifiStatus(); |
| 114 | void wifiTestStop(); |
| 115 | void wifiGetResult(); |
| 116 | |
| 117 | void signal_handler(int sig) |
| 118 | { |
| 119 | int retval = 0; |
| 120 | |
| 121 | retval = WIFI_TEST_CloseDUT(); |
| 122 | printf("\n(%d) aborted .., sig=%d\n", retval,sig); |
| 123 | |
| 124 | signal(SIGINT, SIG_DFL); |
| 125 | exit(0); |
| 126 | } |
| 127 | |
| 128 | // "E:e:M:g:G:I:B:R:N:T:m:s:p:b:t:hVw:v:l:f :c:rn:" |
| 129 | |
| 130 | |
| 131 | void print_help(int exval) |
| 132 | { |
| 133 | printf("Usage: %s [options]\n", proc_name); |
| 134 | printf("\n"); |
| 135 | |
| 136 | printf("<Test mode control>\n"); |
| 137 | printf(" %s -O Enable Wi-Fi test mode\n", proc_name); |
| 138 | printf(" %s -C Disable Wi-Fi test mode\n", proc_name); |
| 139 | printf("\n"); |
| 140 | |
| 141 | printf("<MCR read/write>\n"); |
| 142 | printf(" %s [-M addr] Read value from CR address\n", proc_name); |
| 143 | printf(" %s [-w addr] [-v value] Write value to CR address\n", proc_name); |
| 144 | printf("\n"); |
| 145 | |
| 146 | printf("<EFUSE read/write>\n"); |
| 147 | printf(" %s [-E offset] Read value from EFUSE at offset\n", proc_name); |
| 148 | printf(" %s [-e offset] [-v value] Write value to EFUSE at offset\n", proc_name); |
| 149 | printf("\n"); |
| 150 | |
| 151 | printf("<Tx test>\n"); |
| 152 | printf("A/B/G Mode:\n"); |
| 153 | printf(" %s [-t 0] [-R legacy rate] [-s preamble] [options]\n", proc_name); |
| 154 | |
| 155 | printf("N Mode:\n"); |
| 156 | printf(" %s [-t 1] [-N MCS rate] [-g greenfield] [-G SGI] [options]\n", proc_name); |
| 157 | |
| 158 | printf("AC Mode:\n"); |
| 159 | printf(" %s [-t 2] [-N MCS rate] [-G SGI] [options]\n", proc_name); |
| 160 | printf("\n"); |
| 161 | |
| 162 | printf("<Rx test>\n"); |
| 163 | printf(" %s [-r] [-n time] [options]\n", proc_name); |
| 164 | printf("\n"); |
| 165 | |
| 166 | printf("Common for Tx/Rx:\n"); |
| 167 | printf(" -c # Central channel number\n"); |
| 168 | printf(" -b [0~3] RF bandwidth <0:20/1:40/2:80/3:160>Mhz <default 20Mhz>\n"); |
| 169 | printf(" -P [0~7] Primary channel setting in unit of 20Mhz <default 0>\n"); |
| 170 | printf(" -B [0~3] Bandwidth <0:20/1:40/2:20U/3:20L>Mhz (Legacy commaand, *deprecated)\n"); |
| 171 | printf(" -j [0~2] J mode setting <0:disable/1:5Mhz/2:10Mhz>\n"); |
| 172 | printf(" -d [0/1] Set Rx default antenna <0:main/1:AUX>\n"); |
| 173 | |
| 174 | printf(" -S # Test mode <0:non-blocking/others:blocking mode timeout in seconds>\n"); |
| 175 | printf(" -T Test terminate command for non-blocking test\n"); |
| 176 | printf(" -a # Blocking mode test result query interval in seconds\n"); |
| 177 | printf(" -o # Max Tx/Rx packet count in blocking mode test\n"); |
| 178 | |
| 179 | printf(" -q Query test result\n"); |
| 180 | |
| 181 | printf(" -D Enable debug mode(dump AT command sequence)\n"); |
| 182 | |
| 183 | printf(" -f RX Filter type <0:default,Disalbe,1:filter RA>\n"); |
| 184 | printf(" -A Set RA address on enabling RX Filter. ex:-A 123456789ABC is set mac 12:34:56:78:9A:BC to RA address\n"); |
| 185 | printf("\n"); |
| 186 | |
| 187 | printf("Rx specific:\n"); |
| 188 | printf(" -n # Test time in seconds.\n"); |
| 189 | printf("\n"); |
| 190 | |
| 191 | printf("Tx specific:\n"); |
| 192 | |
| 193 | printf(" -n # TX Packet number, 0 is meaning that TX Packet number = unlimited\n"); |
| 194 | |
| 195 | printf(" -t [0/1/2] Tx mode <0:11abg/1:11n/2:11ac>\n"); |
| 196 | printf(" -x [0~3] Tx bandwidth <0:20/1:40/2:80/3:160>Mhz <default follow RF BW>\n"); |
| 197 | printf(" -p # Tx gain in dBm\n"); |
| 198 | |
| 199 | |
| 200 | |
| 201 | printf(" -n # Frame count\n"); |
| 202 | printf(" -l # Frame length in bytes\n"); |
| 203 | |
| 204 | printf(" -R [1~12] Legacy rate code\n"); |
| 205 | printf(" <1M/2M/5.5M/6M/9M/11M/12M/18M/24M/36M/48M/54M>\n"); |
| 206 | printf(" -s [0/1] <0:short/1:long> preamble\n"); |
| 207 | |
| 208 | printf(" -N [0~15/32] MCS rate index\n"); |
| 209 | printf(" -g [0/1] <0:mixed mode/1:greenfield> \n"); |
| 210 | printf(" -G [0/1] <0:normal/1:short> guard interval\n"); |
| 211 | printf(" -L Enable LDPC <default BCC>\n"); |
| 212 | |
| 213 | printf(" -m [0/3] <0:disable/3:enable> continuous waveform mode\n"); |
| 214 | printf("\n"); |
| 215 | |
| 216 | exit(exval); |
| 217 | } |
| 218 | |
| 219 | static int channel = 1; |
| 220 | static int times = 10; |
| 221 | //static int numBurst = 0; |
| 222 | static int txMode = 0; |
| 223 | static unsigned char macAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
| 224 | #define Default_TxGain -1.0 |
| 225 | static float txGain = Default_TxGain; |
| 226 | static int payloadLength = 1024; |
| 227 | static int g_rate = 6; |
| 228 | static ENUM_WIFI_TEST_MCS_RATE gMCSrate = WIFI_TEST_MCS_RATE_0; |
| 229 | static int g_bandwidth = WIFI_TEST_BW_20MHZ; |
| 230 | static ENUM_WIFI_TEST_PREAMBLE_TYPE gMode = WIFI_TEST_PREAMBLE_TYPE_MIXED_MODE; |
| 231 | static ENUM_WIFI_TEST_GI_TYPE giType = WIFI_TEST_GI_TYPE_NORMAL_GI; |
| 232 | extern char WIFI_IF_NAME[256]; |
| 233 | static WIFI_PreambleType_t pType = WIFI_TEST_PREAMBLE_SHORT; |
| 234 | static unsigned int mcr_addr = 0; |
| 235 | static unsigned int mcr_value = 0; |
| 236 | static unsigned int efuse_addr = 0; |
| 237 | static int cw_mode = -1; |
| 238 | static int sleep_time = 10; |
| 239 | static bool sleepModeSet = false; |
| 240 | |
| 241 | static int priSetting = 0; |
| 242 | static bool isNewBwSet = false; |
| 243 | static ENUM_WIFI_CHANNEL_BANDWIDTH rfBw = WIFI_TEST_CH_BW_20MHZ; |
| 244 | static bool isTxBwSet = false; |
| 245 | static ENUM_WIFI_CHANNEL_BANDWIDTH txBw = WIFI_TEST_CH_BW_20MHZ; |
| 246 | static int coding = 0; /* BCC */ |
| 247 | static int rxDefaultAnt = 0; |
| 248 | static int jModeSetting = 0; |
| 249 | static int printInterval = 1; |
| 250 | static uint32_t maxPktCount = 0; |
| 251 | static int user_expect = 0; |
| 252 | |
| 253 | static ENUM_RX_MATCH_RULE_T eRxOkMatchRule = RX_MATCH_RULE_DISABLE; |
| 254 | static bool bRxFilterMacAddrLegalFg = false; |
| 255 | static unsigned char aucRxFilterMacAddr[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
| 256 | |
| 257 | #define WIFI_TEST_BW_MAX 5 |
| 258 | |
| 259 | extern bool fgDebugMode; |
| 260 | |
| 261 | int main(int argc, char *argv[]) |
| 262 | { |
| 263 | int opt = 0; |
| 264 | int result = 0; |
| 265 | Oper_Mode operation = OPER_NONE; |
| 266 | WlanStatus wlan_status = 0; |
| 267 | int band_width[] = {WIFI_TEST_BW_20MHZ, WIFI_TEST_BW_40MHZ, |
| 268 | WIFI_TEST_BW_U20MHZ, WIFI_TEST_BW_D20MHZ, WIFI_TEST_BW_80MHZ, |
| 269 | WIFI_TEST_BW_160MHZ}; |
| 270 | |
| 271 | strncpy(proc_name, argv[0], 255); |
| 272 | proc_name[255] = '\0'; |
| 273 | |
| 274 | if (argc == 1){ |
| 275 | fprintf(stderr, "Needs arguments....\n\n"); |
| 276 | print_help(1); |
| 277 | } |
| 278 | // set up the Ctrl + C handler |
| 279 | signal(SIGINT, signal_handler); |
| 280 | while ((opt = getopt(argc, argv, "A:f:E:e:M:g:G:I:B:R:N:Tm:S:s:p:b:t:hVw:v:k:l:f:c:rOCn:DP:x:Ld:j:qa:o")) != -1) { |
| 281 | switch(opt) { |
| 282 | case 'e': |
| 283 | if (operation == OPER_NONE){ |
| 284 | operation = WRITE_EFUSE; |
| 285 | xtoi(optarg, &efuse_addr); |
| 286 | } |
| 287 | break; |
| 288 | case 'E': |
| 289 | if (operation == OPER_NONE){ |
| 290 | operation = READ_EFUSE; |
| 291 | xtoi(optarg, &efuse_addr); |
| 292 | } |
| 293 | break; |
| 294 | case 'w': |
| 295 | if (operation == OPER_NONE){ |
| 296 | operation = WRITE_MCR; |
| 297 | xtoi(optarg, &mcr_addr); |
| 298 | } |
| 299 | break; |
| 300 | case 'M': |
| 301 | if (operation == OPER_NONE){ |
| 302 | operation = READ_MCR; |
| 303 | xtoi(optarg, &mcr_addr); |
| 304 | } |
| 305 | break; |
| 306 | case 'r': |
| 307 | if (operation == OPER_NONE) |
| 308 | operation = TEST_RX; |
| 309 | break; |
| 310 | case 't': |
| 311 | if (operation == OPER_NONE) |
| 312 | operation = TEST_TX; |
| 313 | txMode = atoi(optarg); |
| 314 | break; |
| 315 | |
| 316 | case 'q': |
| 317 | if (operation == OPER_NONE) |
| 318 | operation = QUERY_RESULT; |
| 319 | break; |
| 320 | |
| 321 | case 'g': |
| 322 | gMode = !atoi(optarg) ? WIFI_TEST_PREAMBLE_TYPE_MIXED_MODE:WIFI_TEST_PREAMBLE_TYPE_GREENFIELD; |
| 323 | break; |
| 324 | case 'G': |
| 325 | giType = !atoi(optarg) ? WIFI_TEST_GI_TYPE_NORMAL_GI:WIFI_TEST_GI_TYPE_SHORT_GI; |
| 326 | break; |
| 327 | case 'I': |
| 328 | strncpy(WIFI_IF_NAME, optarg, strlen(WIFI_IF_NAME) - 1); |
| 329 | WIFI_IF_NAME[sizeof(WIFI_IF_NAME) - 1] = '\0'; |
| 330 | break; |
| 331 | case 'B': |
| 332 | { |
| 333 | int index = atoi(optarg); |
| 334 | if (index > WIFI_TEST_BW_MAX){ |
| 335 | printf("not support this band"); |
| 336 | return -1; |
| 337 | } |
| 338 | g_bandwidth = band_width[index]; |
| 339 | break; |
| 340 | } |
| 341 | case 'N': |
| 342 | gMCSrate = atoi(optarg); |
| 343 | break; |
| 344 | case 'R': |
| 345 | g_rate = atoi(optarg); |
| 346 | break; |
| 347 | case 'p': |
| 348 | txGain = strtod(optarg, NULL); |
| 349 | break; |
| 350 | case 'l': |
| 351 | payloadLength = atoi(optarg); |
| 352 | break; |
| 353 | |
| 354 | case 'b': |
| 355 | rfBw = atoi(optarg); |
| 356 | isNewBwSet = true; |
| 357 | break; |
| 358 | |
| 359 | case 'j': |
| 360 | jModeSetting = atoi(optarg); |
| 361 | break; |
| 362 | |
| 363 | case 'P': |
| 364 | priSetting = atoi(optarg); |
| 365 | break; |
| 366 | |
| 367 | case 'x': |
| 368 | txBw = atoi(optarg); |
| 369 | isTxBwSet = true; |
| 370 | break; |
| 371 | |
| 372 | case 'L': |
| 373 | coding = 1; |
| 374 | break; |
| 375 | |
| 376 | case 'd': |
| 377 | rxDefaultAnt = atoi(optarg); |
| 378 | break; |
| 379 | |
| 380 | case 'a': |
| 381 | printInterval = atoi(optarg); |
| 382 | break; |
| 383 | |
| 384 | case 'o': |
| 385 | maxPktCount = atoi(optarg); |
| 386 | break; |
| 387 | |
| 388 | case 'h': |
| 389 | case ':': |
| 390 | print_help(0); |
| 391 | break; |
| 392 | case 'n': |
| 393 | times = atoi(optarg); |
| 394 | break; |
| 395 | case 'c': |
| 396 | channel = atoi(optarg); |
| 397 | break; |
| 398 | case 'V': |
| 399 | break; |
| 400 | case 'v': |
| 401 | xtoi(optarg, &mcr_value); |
| 402 | break; |
| 403 | case 's': |
| 404 | pType = !atoi(optarg) ? WIFI_TEST_PREAMBLE_SHORT:WIFI_TEST_PREAMBLE_LONG; |
| 405 | break; |
| 406 | case 'm': |
| 407 | cw_mode = atoi(optarg); |
| 408 | break; |
| 409 | case '?': |
| 410 | fprintf(stderr, "%s: Error - No such option: `%c`\r", proc_name, optopt); |
| 411 | print_help(1); |
| 412 | break; |
| 413 | case 'S': |
| 414 | sleep_time = atoi(optarg); |
| 415 | sleepModeSet = true; |
| 416 | break; |
| 417 | case 'O': |
| 418 | user_expect = 1; |
| 419 | break; |
| 420 | case 'C': |
| 421 | user_expect |= 2; |
| 422 | break; |
| 423 | case 'T': |
| 424 | operation = TEST_STOP; |
| 425 | break; |
| 426 | case 'D': |
| 427 | fgDebugMode = true; |
| 428 | break; |
| 429 | case 'f': |
| 430 | eRxOkMatchRule = atoi(optarg); |
| 431 | break; |
| 432 | case 'A': |
| 433 | result = xtoAddrptr(optarg, aucRxFilterMacAddr); |
| 434 | if (!result) |
| 435 | { |
| 436 | printf("Address format doesn't support\n"); |
| 437 | return -1; |
| 438 | } |
| 439 | else |
| 440 | { |
| 441 | bRxFilterMacAddrLegalFg = true; |
| 442 | } |
| 443 | break; |
| 444 | case 'k': |
| 445 | result = xtoAddrptr(optarg, macAddr); |
| 446 | if (!result) |
| 447 | { |
| 448 | printf("Address format doesn't support\n"); |
| 449 | return -1; |
| 450 | } |
| 451 | break; |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | /* Decide RF/Tx bandwidth */ |
| 456 | if(isNewBwSet) { |
| 457 | if(!isTxBwSet) { |
| 458 | txBw = rfBw; |
| 459 | } |
| 460 | else if(txBw > rfBw){ |
| 461 | txBw = rfBw; |
| 462 | } |
| 463 | } |
| 464 | else if(isTxBwSet) { |
| 465 | isNewBwSet = true; |
| 466 | rfBw = txBw; |
| 467 | } |
| 468 | |
| 469 | /* BW coding check */ |
| 470 | if((txBw >= WIFI_TEST_CH_BW_NUM) || (rfBw >= WIFI_TEST_CH_BW_NUM)) { |
| 471 | printf("Invalid bandwidth setting RF[%u] Tx[%u]", rfBw, txBw); |
| 472 | return -1; |
| 473 | } |
| 474 | |
| 475 | wlan_status = wifiStatus(); |
| 476 | switch (wlan_status){ |
| 477 | case WLAN_MODE_OFF: |
| 478 | if ((user_expect & 0x1) == 1){ |
| 479 | bool ret = false; |
| 480 | if ((user_expect & 0x2)==0x2 && operation == OPER_NONE){ |
| 481 | return 0; |
| 482 | } |
| 483 | ret = WIFI_TEST_OpenDUT(); |
| 484 | printf("[%s] Enable Wi-Fi test mode %s\n", |
| 485 | WIFI_IF_NAME, ret==true ? "success":"fail"); |
| 486 | if (ret == true){ |
| 487 | wlan_status = TEST_MODE_ON; |
| 488 | break; |
| 489 | } |
| 490 | } |
| 491 | printf("[%s] Not in test mode, use -O to enable.\n", |
| 492 | WIFI_IF_NAME); |
| 493 | return 0; |
| 494 | |
| 495 | case TEST_MODE_ON: |
| 496 | if ((user_expect & 0x1) == 1) |
| 497 | printf("[%s] Already in test mode\n", WIFI_IF_NAME); |
| 498 | break; |
| 499 | |
| 500 | case NORMAL_MODE_ON: |
| 501 | printf("Please turn off normal mode wlan first!\n"); |
| 502 | return 0; |
| 503 | } |
| 504 | |
| 505 | WIFI_TEST_init(); |
| 506 | |
| 507 | /* J mode setting */ |
| 508 | if(jModeSetting) { |
| 509 | bool retval = false; |
| 510 | retval = WIFI_TEST_SetJMode(jModeSetting); |
| 511 | printf("(%s) Set J mode to %d\n", retval ? "success":"fail", |
| 512 | jModeSetting); |
| 513 | if (retval == 0) return -1; |
| 514 | } |
| 515 | |
| 516 | switch (operation){ |
| 517 | case WRITE_EFUSE: |
| 518 | { |
| 519 | bool retval = WIFI_TEST_EFUSE_Write(efuse_addr, mcr_value); |
| 520 | printf("(%s) Wirte EFUSE addr 0x%x value 0x%x\n", retval ? "success":"fail", efuse_addr, mcr_value); |
| 521 | break; |
| 522 | } |
| 523 | case READ_EFUSE: |
| 524 | { |
| 525 | unsigned int val = 0; |
| 526 | bool retval = WIFI_TEST_EFUSE_Read(efuse_addr, &val); |
| 527 | printf("(%s) EFUSE addr 0x%x value 0x%x\n", retval ? "success":"fail", efuse_addr, val); |
| 528 | break; |
| 529 | } |
| 530 | case WRITE_MCR: |
| 531 | { |
| 532 | bool retval = WIFI_TEST_MCR_Write(mcr_addr, mcr_value); |
| 533 | printf("(%s) MCR addr 0x%x is set to value 0x%x\n", retval ? "success":"fail", mcr_addr, mcr_value); |
| 534 | break; |
| 535 | } |
| 536 | case READ_MCR: |
| 537 | { |
| 538 | unsigned int val = 0; |
| 539 | bool retval = WIFI_TEST_MCR_Read(mcr_addr, &val); |
| 540 | printf("(%s) MCR addr 0x%x value 0x%x\n", retval ? "success":"fail", mcr_addr, val); |
| 541 | break; |
| 542 | } |
| 543 | case TEST_RX: |
| 544 | { |
| 545 | int testDuration; |
| 546 | |
| 547 | if(sleepModeSet) { |
| 548 | testDuration = sleep_time; |
| 549 | } |
| 550 | else { |
| 551 | testDuration = times; |
| 552 | } |
| 553 | |
| 554 | wifi_sensitivity(testDuration, channel); |
| 555 | break; |
| 556 | } |
| 557 | case TEST_TX: |
| 558 | wifi_tx(); |
| 559 | break; |
| 560 | case TEST_STOP: |
| 561 | wifiTestStop(); |
| 562 | break; |
| 563 | |
| 564 | case QUERY_RESULT: |
| 565 | wifiGetResult(); |
| 566 | break; |
| 567 | |
| 568 | default: |
| 569 | case OPER_NONE: |
| 570 | //printf("not give any operation\n"); |
| 571 | break; |
| 572 | } |
| 573 | WIFI_TEST_deinit(); |
| 574 | |
| 575 | if ((user_expect & 0x2) == 0x2 && wlan_status == TEST_MODE_ON){ |
| 576 | int ret = WIFI_TEST_CloseDUT(); |
| 577 | printf("[%s] Disable Wi-Fi test mode %s\n", WIFI_IF_NAME, |
| 578 | ret==true ? "success":"fail"); |
| 579 | } |
| 580 | return 0; |
| 581 | } |
| 582 | |
| 583 | void wifi_sensitivity(int times, int channel) |
| 584 | { |
| 585 | int i, nextInterval; |
| 586 | int rxOk, rxErr; |
| 587 | int rxRssisFinal; |
| 588 | bool retval; |
| 589 | bool finalResult = false; |
| 590 | bool ret[3]; |
| 591 | |
| 592 | retval = WIFI_TEST_Channel(channel); |
| 593 | printf("(%s) Set central channel number to %d\n", retval ? "success":"fail", |
| 594 | channel); |
| 595 | if (retval == 0) return; |
| 596 | |
| 597 | retval = WIFI_TEST_SetRxDefaultAnt(rxDefaultAnt); |
| 598 | printf("(%s) Set Rx default antenna to %s\n", retval ? "success":"fail", |
| 599 | rxDefaultAnt?"AUX":"main"); |
| 600 | if (retval == 0) return; |
| 601 | |
| 602 | if(isNewBwSet) { |
| 603 | retval = WIFI_TEST_SetBandwidthV2(rfBw); |
| 604 | printf("(%s) Set RF bandwidth to %s\n", retval ? "success":"fail", |
| 605 | bandwidthV2[rfBw]); |
| 606 | if (retval == 0) return; |
| 607 | |
| 608 | retval = WIFI_TEST_SetPriChannelSetting(priSetting); |
| 609 | printf("(%s) Set primary channel index to %u\n", |
| 610 | retval ? "success":"fail", priSetting); |
| 611 | if (retval == 0) return; |
| 612 | } |
| 613 | else { |
| 614 | retval = WIFI_TEST_SetBandwidth(g_bandwidth); |
| 615 | printf("(%s) Set bandwidth to %s\n", retval ? "success":"fail", |
| 616 | bandwidth[g_bandwidth]); |
| 617 | if (retval == 0) return; |
| 618 | } |
| 619 | if (eRxOkMatchRule == RX_MATCH_RULE_DISABLE) { |
| 620 | retval = WIFI_TEST_SetRX(false, NULL, NULL); |
| 621 | printf("(%s) Disable RX filter\n", retval ? "success":"fail"); |
| 622 | } else if (eRxOkMatchRule == RX_MATCH_RULE_RA) { |
| 623 | if (bRxFilterMacAddrLegalFg) { |
| 624 | retval = WIFI_TEST_SetRX(true, NULL, (char *)aucRxFilterMacAddr); |
| 625 | printf("(%s) Enable RX filter, Set RA Address to %02x:%02x:%02x:%02x:%02x:%02x\n", retval ? "success":"fail", |
| 626 | aucRxFilterMacAddr[0], |
| 627 | aucRxFilterMacAddr[1], |
| 628 | aucRxFilterMacAddr[2], |
| 629 | aucRxFilterMacAddr[3], |
| 630 | aucRxFilterMacAddr[4], |
| 631 | aucRxFilterMacAddr[5] |
| 632 | ); |
| 633 | if (retval == 0) return; |
| 634 | } else { |
| 635 | printf("Enalbe RX filter, need to set RA address\n"); |
| 636 | return; |
| 637 | } |
| 638 | } else if (eRxOkMatchRule == RX_MATCH_RULE_TA) { |
| 639 | if (bRxFilterMacAddrLegalFg) { |
| 640 | retval = WIFI_TEST_SetRX(true, (char *)aucRxFilterMacAddr, NULL); |
| 641 | printf("(%s) Enable TA filter, Set TA Address to %02x:%02x:%02x:%02x:%02x:%02x\n", retval ? "success":"fail", |
| 642 | aucRxFilterMacAddr[0], |
| 643 | aucRxFilterMacAddr[1], |
| 644 | aucRxFilterMacAddr[2], |
| 645 | aucRxFilterMacAddr[3], |
| 646 | aucRxFilterMacAddr[4], |
| 647 | aucRxFilterMacAddr[5] |
| 648 | ); |
| 649 | if (retval == 0) return; |
| 650 | } else { |
| 651 | printf("Enalbe TA filter, need to set TA address\n"); |
| 652 | return; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | retval = WIFI_TEST_RxStart(); |
| 657 | printf("(%s) RX test started\n", retval ? "success":"fail"); |
| 658 | if (retval == 0) return; |
| 659 | |
| 660 | nextInterval = printInterval; |
| 661 | |
| 662 | for(i = 0; (i < times) || !finalResult; i += nextInterval) { |
| 663 | |
| 664 | if(i >= times) { |
| 665 | finalResult = true; |
| 666 | } |
| 667 | |
| 668 | ret[0] = WIFI_TEST_FRGood(&rxOk); |
| 669 | ret[1] = WIFI_TEST_FRError(&rxErr); |
| 670 | ret[2] = WIFI_TEST_RSSI(&rxRssisFinal); |
| 671 | if ((rxOk + rxErr) == 0){ |
| 672 | fprintf(stdout, "[%3d] (%d)RX OK: %4d / (%d)RX ERR: %4d\n", |
| 673 | i, ret[0], rxOk, ret[1], rxErr); |
| 674 | } |
| 675 | else{ |
| 676 | fprintf(stdout, "[%3d] (%d)RX OK: %4d / (%d)RX ERR: %4d / PER: %2d .. /" |
| 677 | " (%d)RSSI: %i\r\n", i, ret[0], rxOk, ret[1], rxErr, |
| 678 | (100 * rxErr)/(rxOk + rxErr), ret[2], (signed char)rxRssisFinal); |
| 679 | } |
| 680 | fflush(stdout); |
| 681 | |
| 682 | if((times - i) < printInterval) { |
| 683 | nextInterval = times - i; |
| 684 | } |
| 685 | |
| 686 | if((rxOk + rxErr >= (int)maxPktCount) && maxPktCount) { |
| 687 | printf("Rx packet count[%u] >= max count[%u], break!\n", |
| 688 | rxOk + rxErr, maxPktCount); |
| 689 | break; |
| 690 | } |
| 691 | |
| 692 | sleep(nextInterval); |
| 693 | } |
| 694 | |
| 695 | if (times == 0) { |
| 696 | printf("Rx test is running! use -T to stop Rx test...\n"); |
| 697 | } |
| 698 | else { |
| 699 | retval = WIFI_TEST_RxStop(); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | void wifi_tx(void) |
| 704 | { |
| 705 | bool retval; |
| 706 | bool finalResult = false; |
| 707 | |
| 708 | WIFI_TEST_TxDestAddress(macAddr); |
| 709 | |
| 710 | retval = WIFI_TEST_Channel(channel); |
| 711 | printf("(%s) Set central channel number to %d\n", retval ? "success":"fail", |
| 712 | channel); |
| 713 | if (retval == 0) return; |
| 714 | |
| 715 | retval = WIFI_TEST_SetRxDefaultAnt(rxDefaultAnt); |
| 716 | printf("(%s) Set Rx default antenna to %s\n", retval ? "success":"fail", |
| 717 | rxDefaultAnt?"AUX":"main"); |
| 718 | if (retval == 0) return; |
| 719 | |
| 720 | if(isNewBwSet) { |
| 721 | retval = WIFI_TEST_SetBandwidthV2(rfBw); |
| 722 | printf("(%s) Set RF bandwidth to %s\n", retval ? "success":"fail", |
| 723 | bandwidthV2[rfBw]); |
| 724 | if (retval == 0) return; |
| 725 | |
| 726 | retval = WIFI_TEST_SetTxBandwidth(txBw); |
| 727 | printf("(%s) Set Tx bandwidth to %s\n", retval ? "success":"fail", |
| 728 | bandwidthV2[txBw]); |
| 729 | if (retval == 0) return; |
| 730 | |
| 731 | retval = WIFI_TEST_SetPriChannelSetting(priSetting); |
| 732 | printf("(%s) Set primary channel index to %u\n", |
| 733 | retval ? "success":"fail", priSetting); |
| 734 | if (retval == 0) return; |
| 735 | } |
| 736 | else { |
| 737 | retval = WIFI_TEST_SetBandwidth(g_bandwidth); |
| 738 | printf("(%s) Set bandwidth to %s\n", retval ? "success":"fail", |
| 739 | bandwidth[g_bandwidth]); |
| 740 | if (retval == 0) return; |
| 741 | } |
| 742 | |
| 743 | // if txGain = Default_TxGain, then use NVRAM tx pwr setting |
| 744 | if(txGain != Default_TxGain){ |
| 745 | retval = WIFI_TEST_TxGain(txGain); |
| 746 | printf("(%s) Set Tx power gain to %.2f dBm\n", retval ? "success":"fail", |
| 747 | txGain); |
| 748 | if (retval == 0) return; |
| 749 | } |
| 750 | else{ |
| 751 | printf("(success) Set Tx power gain by NVRAM Setting\n"); |
| 752 | } |
| 753 | |
| 754 | retval = WIFI_TEST_TxPayloadLength(payloadLength); |
| 755 | printf("(%s) Set Tx payload to %d bytes..\n", retval ? "success":"fail", payloadLength); |
| 756 | if (retval == 0) return; |
| 757 | |
| 758 | retval = WIFI_TEST_DPD_MODE(MODE_DISABLE); |
| 759 | printf("(%s) Disable DPD\n", retval ? "success":"fail"); |
| 760 | if (retval == 0) return; |
| 761 | |
| 762 | retval = WIFI_TEST_TEMP_COMPEN_MODE(MODE_DISABLE); |
| 763 | printf("(%s) Disable TEMP_COMP\n", retval ? "success":"fail"); |
| 764 | if (retval == 0) return; |
| 765 | |
| 766 | retval = WIFI_TEST_TX_POWER_MODE(MODE_DISABLE); |
| 767 | printf("(%s) TX power mode 0\n", retval ? "success":"fail"); |
| 768 | if (retval == 0) return; |
| 769 | |
| 770 | retval = WIFI_TEST_TxBurstFrames(times); |
| 771 | printf("(%s) Set frame count to %d \n", retval ? "success":"fail", times); |
| 772 | if (retval == 0) return; |
| 773 | |
| 774 | switch(txMode) { |
| 775 | case 0: /* A/B/G mode */ |
| 776 | retval = WIFI_TEST_SetPreamble(pType); |
| 777 | printf("(%s) Set %s preamble\n", retval ? "success":"fail", preamble[pType]); |
| 778 | if (retval == 0) return; |
| 779 | |
| 780 | retval = WIFI_TEST_TxDataRate(g_rate); |
| 781 | printf("(%s) Set Tx mode to 11a/b/g, tx rate %s\n", retval ? "success":"fail", bg_rate[g_rate]); |
| 782 | if (retval == 0) return; |
| 783 | break; |
| 784 | |
| 785 | case 1: /* N mode */ |
| 786 | retval = WIFI_TEST_TxDataRate11n(gMCSrate, gMode, giType); |
| 787 | printf("(%s) Set Tx mode to 11n, MCS%u, %s, %s GI, %s\n", retval ? "success":"fail", |
| 788 | gMCSrate, gMode?"greenfield":"mixed-mode", giType?"Short":"Normal", |
| 789 | coding?"LDPC":"BCC"); |
| 790 | if (retval == 0) return; |
| 791 | |
| 792 | retval = WIFI_TEST_SetTxCodingMode(coding); |
| 793 | if (retval == 0) return; |
| 794 | |
| 795 | break; |
| 796 | |
| 797 | case 2: /* AC mode */ |
| 798 | retval = WIFI_TEST_TxDataRate11ac(gMCSrate, giType); |
| 799 | printf("(%s) Set Tx mode to 11ac MCS%u, %s GI, %s\n", retval ? "success":"fail", |
| 800 | gMCSrate, giType?"Short":"Normal", coding?"LDPC":"BCC"); |
| 801 | if (retval == 0) return; |
| 802 | |
| 803 | retval = WIFI_TEST_SetTxCodingMode(coding); |
| 804 | if (retval == 0) return; |
| 805 | |
| 806 | break; |
| 807 | |
| 808 | default: |
| 809 | printf("Unsupported Tx mode[%u]!\n", txMode); |
| 810 | return; |
| 811 | } |
| 812 | |
| 813 | //for CW mode |
| 814 | if(-1 != cw_mode){ |
| 815 | retval = WIFI_TEST_CW_MODE(cw_mode); |
| 816 | printf("(%s) cw mode set to %d\n", retval ? "success":"fail", cw_mode); |
| 817 | if (retval == 0) return; |
| 818 | |
| 819 | retval = WIFI_TEST_CW_MODE_START(); |
| 820 | printf("(%s) cw mode start.\n", retval ? "success":"fail"); |
| 821 | if (retval == 0) return; |
| 822 | }else{ |
| 823 | printf("no cw mode configuration.\n"); |
| 824 | retval = WIFI_TEST_TxStart(); |
| 825 | printf("(%s) TX test started..\n", retval ? "success":"fail"); |
| 826 | if (retval == 0) return; |
| 827 | } |
| 828 | |
| 829 | if (sleep_time == 0) { |
| 830 | printf("Tx test is running! use -T to stop Tx test...\n"); |
| 831 | return; |
| 832 | } |
| 833 | else { |
| 834 | int i, nextInterval; |
| 835 | uint32_t u4TxOk, u4Tx; |
| 836 | |
| 837 | nextInterval = printInterval; |
| 838 | |
| 839 | printf("Tx test is running! wait for %us...\n", sleep_time); |
| 840 | |
| 841 | for(i = 0; (i < sleep_time) || !finalResult; i += nextInterval) { |
| 842 | if(i >= sleep_time) { |
| 843 | finalResult = true; |
| 844 | } |
| 845 | |
| 846 | retval = WIFI_TEST_TxCount(&u4Tx); |
| 847 | retval = WIFI_TEST_TxGoodCount(&u4TxOk); |
| 848 | |
| 849 | if(retval == 0) { |
| 850 | printf("(%s) Cannot get test result!\n", retval ?"success":"fail"); |
| 851 | } |
| 852 | else { |
| 853 | printf("[%u] Tx total/good count: %u/%u\n", i, u4Tx, u4TxOk); |
| 854 | } |
| 855 | |
| 856 | if(i >= sleep_time) { |
| 857 | break; |
| 858 | } |
| 859 | |
| 860 | if((u4Tx >= maxPktCount) && maxPktCount) { |
| 861 | printf("Tx packet count[%u] >= max count[%u], break!\n", |
| 862 | u4Tx, maxPktCount); |
| 863 | break; |
| 864 | } |
| 865 | |
| 866 | if((sleep_time - i) < printInterval) { |
| 867 | nextInterval = (sleep_time - i); |
| 868 | } |
| 869 | |
| 870 | sleep(nextInterval); |
| 871 | } |
| 872 | |
| 873 | printf("Stop Tx test!\n"); |
| 874 | } |
| 875 | |
| 876 | retval = WIFI_TEST_TxStop(); |
| 877 | } |
| 878 | |
| 879 | void wifiGetResult(void) { |
| 880 | uint32_t u4RxOk, u4RxFailed, u4Rssi; |
| 881 | uint32_t u4TxOk, u4Tx; |
| 882 | bool retval; |
| 883 | |
| 884 | do { |
| 885 | |
| 886 | retval = WIFI_TEST_FRGood((int*)&u4RxOk); |
| 887 | if (retval == 0) break; |
| 888 | |
| 889 | retval = WIFI_TEST_FRError((int*)&u4RxFailed); |
| 890 | if (retval == 0) break; |
| 891 | |
| 892 | retval = WIFI_TEST_RSSI((int*)&u4Rssi); |
| 893 | if (retval == 0) break; |
| 894 | |
| 895 | retval = WIFI_TEST_TxCount(&u4Tx); |
| 896 | if (retval == 0) break; |
| 897 | |
| 898 | retval = WIFI_TEST_TxGoodCount(&u4TxOk); |
| 899 | if (retval == 0) break; |
| 900 | |
| 901 | } while(false); |
| 902 | |
| 903 | if(retval == 0) { |
| 904 | printf("(%s) Cannot get test result!\n", retval ?"success":"fail"); |
| 905 | } |
| 906 | else { |
| 907 | printf("Tx total/good count: %u/%u\n", u4Tx, u4TxOk); |
| 908 | printf("Rx good/err count: %u/%u PER: %u RSSI:%i\n", u4RxOk, u4RxFailed, |
| 909 | (100 * u4RxFailed)/(u4RxOk + u4RxFailed), (signed char)u4Rssi); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | void wifiTestStop(void){ |
| 914 | bool retval = WIFI_TEST_TxStop(); |
| 915 | printf("(%s) stop Tx\n", retval ? "success":"fail"); |
| 916 | |
| 917 | retval = WIFI_TEST_RxStop(); |
| 918 | printf("(%s) stop Rx\n", retval ? "success":"fail"); |
| 919 | } |
| 920 | |
| 921 | /* if wlan.driver.status is ok, then wlan normal mode is on |
| 922 | if /sys/class/net/wlan0 is not exist, then wlan is off |
| 923 | otherwise, we think the wlan may be turned on by us */ |
| 924 | static WlanStatus wifiStatus(void){ |
| 925 | #ifdef ANDROID |
| 926 | char driver_status[PROP_VALUE_MAX]; |
| 927 | bool normal_mode_on = false; |
| 928 | char netdevPath[256]; |
| 929 | |
| 930 | struct stat buf; |
| 931 | property_get("wlan.driver.status", driver_status, "unloaded"); |
| 932 | if (strncmp(driver_status, "ok", 2) == 0){ |
| 933 | normal_mode_on = true; |
| 934 | } |
| 935 | |
| 936 | snprintf(netdevPath, 255, "/sys/class/net/%s", WIFI_IF_NAME); |
| 937 | |
| 938 | if (stat(netdevPath, &buf) < 0 && errno==ENOENT) |
| 939 | return WLAN_MODE_OFF; |
| 940 | return normal_mode_on ? NORMAL_MODE_ON:TEST_MODE_ON; |
| 941 | #else |
| 942 | bool normal_mode_on = false; |
| 943 | char netdevPath[256]; |
| 944 | struct stat buf; |
| 945 | |
| 946 | snprintf(netdevPath, 255, "/sys/class/net/%s", WIFI_IF_NAME); |
| 947 | |
| 948 | if (stat(netdevPath, &buf) < 0 && errno==ENOENT) |
| 949 | return WLAN_MODE_OFF; |
| 950 | |
| 951 | return TEST_MODE_ON; |
| 952 | #endif |
| 953 | } |