b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <fcntl.h> |
| 3 | #include <string.h> |
| 4 | #include <sys/socket.h> |
| 5 | #include <sys/ioctl.h> |
| 6 | #include <net/if.h> |
| 7 | #include<stdlib.h> |
| 8 | #include <stdint.h> |
| 9 | #include <errno.h> |
| 10 | #define WIFI_DRIVER_FW_PATH "sta" |
| 11 | #define WIFI_DRIVER_MODULE_NAME "rwnx_fdrv" |
| 12 | #define WIFI_DRIVER_MODULE_PATH "/vendor/modules/rwnx_fdrv.ko" |
| 13 | #define MAX_DRV_CMD_SIZE 1536 |
| 14 | #define TXRX_PARA SIOCDEVPRIVATE+1 |
| 15 | |
| 16 | #define CHIP_AIC8800D 0 |
| 17 | #define CHIP_AIC8800DCDW 1 |
| 18 | #define CHIP_AIC8800D80 2 |
| 19 | #define CHIP_AIC8800D80X2 3 |
| 20 | |
| 21 | #define CHIP_SELECT CHIP_AIC8800D80 |
| 22 | |
| 23 | #if (CHIP_SELECT == CHIP_AIC8800D) |
| 24 | #define EFUSE_CMD_OLD_FORMAT_EN 1 |
| 25 | #else |
| 26 | #define EFUSE_CMD_OLD_FORMAT_EN 0 |
| 27 | #endif |
| 28 | |
| 29 | #define RELEASE_DATE "2024_0701" |
| 30 | |
| 31 | //static const char IFACE_DIR[] = ""; |
| 32 | //static const char DRIVER_MODULE_NAME[] = "rwnx_fdrv"; |
| 33 | //static const char DRIVER_MODULE_TAG[] = WIFI_DRIVER_MODULE_NAME " "; |
| 34 | //static const char DRIVER_MODULE_PATH[] = WIFI_DRIVER_MODULE_PATH; |
| 35 | //static const char DRIVER_MODULE_ARG[] = ""; |
| 36 | //static const char FIRMWARE_LOADER[] = ""; |
| 37 | //static const char DRIVER_PROP_NAME[] = "wlan.driver.status"; |
| 38 | |
| 39 | #ifndef TEMP_FAILURE_RETRY |
| 40 | #define TEMP_FAILURE_RETRY(expression) \ |
| 41 | (__extension__ \ |
| 42 | ({ long int __result; \ |
| 43 | do __result = (long int) (expression); \ |
| 44 | while (__result == -1L && errno == EINTR); \ |
| 45 | __result; })) |
| 46 | #endif |
| 47 | |
| 48 | typedef struct android_wifi_priv_cmd { |
| 49 | char *buf; |
| 50 | int used_len; |
| 51 | int total_len; |
| 52 | } android_wifi_priv_cmd; |
| 53 | typedef struct cob_result_ptr_t { |
| 54 | uint16_t dut_rcv_golden_num; |
| 55 | uint8_t golden_rcv_dut_num; |
| 56 | int8_t rssi_static; |
| 57 | int8_t snr_static; |
| 58 | int8_t dut_rssi_static; |
| 59 | uint16_t reserved; |
| 60 | }cob_result_ptr_t; |
| 61 | |
| 62 | struct aicwf_cs_info { |
| 63 | uint8_t phymode; |
| 64 | uint8_t bandwidth; |
| 65 | uint16_t freq; |
| 66 | |
| 67 | int8_t rssi; |
| 68 | int8_t snr; |
| 69 | int8_t noise; |
| 70 | uint8_t txpwr; |
| 71 | |
| 72 | //chanutil |
| 73 | uint16_t chan_time_ms; |
| 74 | uint16_t chan_time_busy_ms; |
| 75 | |
| 76 | char countrycode[4]; |
| 77 | uint8_t rxnss; |
| 78 | uint8_t rxmcs; |
| 79 | uint8_t txnss; |
| 80 | uint8_t txmcs; |
| 81 | |
| 82 | uint32_t tx_phyrate; |
| 83 | uint32_t rx_phyrate; |
| 84 | |
| 85 | uint32_t tx_ack_succ_stat; |
| 86 | uint32_t tx_ack_fail_stat; |
| 87 | }; |
| 88 | |
| 89 | int wifi_send_cmd_to_net_interface(const char* if_name, int argC, char *argV[]) |
| 90 | { |
| 91 | int sock; |
| 92 | struct ifreq ifr; |
| 93 | int ret = 0; |
| 94 | int i = 0; |
| 95 | char buf[MAX_DRV_CMD_SIZE]; |
| 96 | struct android_wifi_priv_cmd priv_cmd; |
| 97 | struct cob_result_ptr_t *cob_result_ptr; |
| 98 | char is_param_err = 0; |
| 99 | int buf_len = 0; |
| 100 | |
| 101 | sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 102 | if (sock < 0) { |
| 103 | printf("bad sock!\n"); |
| 104 | return -1; |
| 105 | } |
| 106 | |
| 107 | memset(&ifr, 0, sizeof(ifr)); |
| 108 | strcpy(ifr.ifr_name, if_name); |
| 109 | |
| 110 | if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) { |
| 111 | printf("%s Could not read interface %s flags: %s",__func__, if_name, strerror(errno)); |
| 112 | return -1; |
| 113 | } |
| 114 | |
| 115 | if (!(ifr.ifr_flags & IFF_UP)) { |
| 116 | printf("%s is not up!\n",if_name); |
| 117 | return -1; |
| 118 | } |
| 119 | |
| 120 | // printf("ifr.ifr_name = %s\n", ifr.ifr_name); |
| 121 | memset(&priv_cmd, 0, sizeof(priv_cmd)); |
| 122 | memset(buf, 0, sizeof(buf)); |
| 123 | |
| 124 | for(i=2; i<argC; i++){ |
| 125 | strcat(buf, argV[i]); |
| 126 | strcat(buf, " "); |
| 127 | } |
| 128 | |
| 129 | priv_cmd.buf = buf; |
| 130 | priv_cmd.used_len = strlen(buf); |
| 131 | priv_cmd.total_len = sizeof(buf); |
| 132 | ifr.ifr_data = (void*)&priv_cmd; |
| 133 | |
| 134 | printf("%s:\n", argV[2]); |
| 135 | if (strcasecmp(argV[2], "SET_TX") == 0) { |
| 136 | if (argC < 8) { |
| 137 | is_param_err = 1; |
| 138 | } |
| 139 | } else if (strcasecmp(argV[2], "country_set") == 0) { |
| 140 | if (argC < 3) |
| 141 | is_param_err = 1; |
| 142 | } else if (strcasecmp(argV[2], "SET_TXTONE") == 0) { |
| 143 | if (((argC == 4) && (argV[3][0] != '0')) |
| 144 | || ((argC == 5) && (argV[3][0] == '0'))) { |
| 145 | is_param_err = 1; |
| 146 | } |
| 147 | } else if ((strcasecmp(argV[2], "SET_RX") == 0) |
| 148 | || (strcasecmp(argV[2], "SET_COB_CAL") == 0)) { |
| 149 | if (argC < 5) { |
| 150 | is_param_err = 1; |
| 151 | } |
| 152 | } else if ((strcasecmp(argV[2], "SET_XTAL_CAP") == 0) |
| 153 | || (strcasecmp(argV[2], "SET_XTAL_CAP_FINE") == 0)) { |
| 154 | if (argC < 4) { |
| 155 | is_param_err = 1; |
| 156 | } |
| 157 | } else if ((strcasecmp(argV[2], "GET_EFUSE_BLOCK") == 0) |
| 158 | || (strcasecmp(argV[2], "SET_FREQ_CAL") == 0) |
| 159 | || (strcasecmp(argV[2], "SET_FREQ_CAL_FINE") == 0)) { |
| 160 | if (argC < 4) { |
| 161 | is_param_err = 1; |
| 162 | } |
| 163 | } else if ((strcasecmp(argV[2], "SET_MAC_ADDR") == 0) |
| 164 | || (strcasecmp(argV[2], "SET_BT_MAC_ADDR") == 0)) { |
| 165 | if (argC < 8) { |
| 166 | is_param_err = 1; |
| 167 | } |
| 168 | } else if (strcasecmp(argV[2], "SET_VENDOR_INFO") == 0) { |
| 169 | if (argC < 4) { |
| 170 | is_param_err = 1; |
| 171 | } |
| 172 | } else if (strcasecmp(argV[2], "GET_VENDOR_INFO") == 0) { |
| 173 | if (argC < 3) { |
| 174 | is_param_err = 1; |
| 175 | } |
| 176 | } else if ((strcasecmp(argV[2], "RDWR_PWRIDX") == 0) |
| 177 | || (strcasecmp(argV[2], "RDWR_PWRLVL") == 0) |
| 178 | || (strcasecmp(argV[2], "RDWR_PWROFST") == 0) |
| 179 | || (strcasecmp(argV[2], "RDWR_PWROFSTFINE") == 0) |
| 180 | || (strcasecmp(argV[2], "RDWR_EFUSE_PWROFST") == 0) |
| 181 | || (strcasecmp(argV[2], "RDWR_EFUSE_PWROFSTFINE") == 0)) { |
| 182 | if (((argC == 4) && (argV[3][0] != '0')) |
| 183 | || (argC == 5) |
| 184 | || ((argC == 6) && (argV[3][0] == '0'))) { |
| 185 | is_param_err = 1; |
| 186 | } |
| 187 | } else if ((strcasecmp(argV[2], "RDWR_DRVIBIT") == 0) |
| 188 | || (strcasecmp(argV[2], "RDWR_EFUSE_DRVIBIT") == 0) |
| 189 | || (strcasecmp(argV[2], "RDWR_EFUSE_SDIOCFG") == 0) |
| 190 | || (strcasecmp(argV[2], "RDWR_EFUSE_USBVIDPID") == 0)) { |
| 191 | if (((argC == 4) && (argV[3][0] != '0')) |
| 192 | || ((argC == 5) && (argV[3][0] == '0'))) { |
| 193 | is_param_err = 1; |
| 194 | } |
| 195 | } else if ((strcasecmp(argV[2], "SET_PAPR") == 0)) { |
| 196 | if (argC < 4) { |
| 197 | is_param_err = 1; |
| 198 | } |
| 199 | } else if ((strcasecmp(argV[2], "SET_NOTCH") == 0) |
| 200 | || (strcasecmp(argV[2], "SET_SRRC") == 0) |
| 201 | || (strcasecmp(argV[2], "SET_FSS") == 0)) { |
| 202 | if (argC < 4) { |
| 203 | is_param_err = 1; |
| 204 | } |
| 205 | } else if ((strcasecmp(argV[2], "BT_RESET") == 0)) { |
| 206 | char bt_reset_hci_cmd[32] = "01 03 0c 00"; |
| 207 | if (argC == 3) { |
| 208 | buf_len = priv_cmd.used_len; |
| 209 | memcpy(&priv_cmd.buf[buf_len], &bt_reset_hci_cmd[0], strlen(bt_reset_hci_cmd)); |
| 210 | buf_len += strlen(bt_reset_hci_cmd); |
| 211 | priv_cmd.used_len = buf_len; |
| 212 | } else { |
| 213 | is_param_err = 1; |
| 214 | } |
| 215 | } else if ((strcasecmp(argV[2], "BT_TXDH") == 0)) { |
| 216 | char bt_txdh_hci_cmd[255] = "01 06 18 0e "; |
| 217 | if (argC == 17) { |
| 218 | buf_len = priv_cmd.used_len; |
| 219 | int arg_len = strlen(argV[2]); |
| 220 | int txdh_cmd_len = strlen(bt_txdh_hci_cmd); |
| 221 | memcpy(&bt_txdh_hci_cmd[txdh_cmd_len], &priv_cmd.buf[arg_len+1], buf_len - arg_len - 1); |
| 222 | memcpy(&priv_cmd.buf[arg_len+1], &bt_txdh_hci_cmd[0], strlen(bt_txdh_hci_cmd)); |
| 223 | buf_len += strlen(bt_txdh_hci_cmd); |
| 224 | priv_cmd.used_len = buf_len; |
| 225 | } else { |
| 226 | is_param_err = 1; |
| 227 | } |
| 228 | } else if ((strcasecmp(argV[2], "BT_RXDH") == 0)) { |
| 229 | if (argC == 16) { |
| 230 | char bt_rxdh_hci_cmd[255] = "01 0b 18 0d "; |
| 231 | buf_len = priv_cmd.used_len; |
| 232 | int arg_len = strlen(argV[2]); |
| 233 | int rxdh_cmd_len = strlen(bt_rxdh_hci_cmd); |
| 234 | memcpy(&bt_rxdh_hci_cmd[rxdh_cmd_len], &priv_cmd.buf[arg_len+1], buf_len - arg_len - 1); |
| 235 | memcpy(&priv_cmd.buf[arg_len+1], &bt_rxdh_hci_cmd[0], strlen(bt_rxdh_hci_cmd)); |
| 236 | buf_len += strlen(bt_rxdh_hci_cmd); |
| 237 | priv_cmd.used_len = buf_len; |
| 238 | } else { |
| 239 | is_param_err = 1; |
| 240 | } |
| 241 | } else if ((strcasecmp(argV[2], "BT_STOP") == 0)) { |
| 242 | char bt_stop_hci_cmd[255] = "01 0C 18 01 "; |
| 243 | if (argC == 4) { |
| 244 | buf_len = priv_cmd.used_len; |
| 245 | int arg_len = strlen(argV[2]); |
| 246 | int stop_cmd_len = strlen(bt_stop_hci_cmd); |
| 247 | memcpy(&bt_stop_hci_cmd[stop_cmd_len], &priv_cmd.buf[arg_len+1], buf_len - arg_len - 1); |
| 248 | memcpy(&priv_cmd.buf[arg_len+1], &bt_stop_hci_cmd[0], strlen(bt_stop_hci_cmd)); |
| 249 | buf_len += strlen(bt_stop_hci_cmd); |
| 250 | priv_cmd.used_len = buf_len; |
| 251 | } else { |
| 252 | is_param_err = 1; |
| 253 | } |
| 254 | } else if ((strcasecmp(argV[2], "BT_DATA") == 0)) { |
| 255 | //char bt_raw_data_cmd[255]; |
| 256 | int arg_len = strlen(argV[2]); |
| 257 | buf_len = priv_cmd.used_len; |
| 258 | memcpy(&priv_cmd.buf[arg_len+1], &priv_cmd.buf[arg_len+1], buf_len - arg_len - 1); |
| 259 | priv_cmd.used_len = buf_len - arg_len - 1; |
| 260 | } else { |
| 261 | is_param_err = 0; |
| 262 | } |
| 263 | |
| 264 | if (is_param_err) { |
| 265 | printf("param error!!!\n"); |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | if ((ret = ioctl(sock, TXRX_PARA, &ifr)) < 0) { |
| 270 | printf("cmd or param error\n"); |
| 271 | printf("%s: error ioctl[TX_PARA] ret= %d\n", __func__, ret); |
| 272 | return ret; |
| 273 | } |
| 274 | |
| 275 | memcpy(&priv_cmd, ifr.ifr_data, sizeof(struct android_wifi_priv_cmd)); |
| 276 | if (strcasecmp(argV[2], "SET_FREQ_CAL") == 0) { |
| 277 | #if (EFUSE_CMD_OLD_FORMAT_EN) |
| 278 | printf("done: freq_cal: 0x%8x\n", *(unsigned int *)priv_cmd.buf); |
| 279 | #else |
| 280 | signed char rem_cnt = (signed char)priv_cmd.buf[1]; |
| 281 | if (rem_cnt < 0) { |
| 282 | printf("failed to set freq_cal, no room!\n"); |
| 283 | } else { |
| 284 | printf("done: freq_cal: 0x%2x (remain:%x)\n", (unsigned char)priv_cmd.buf[0], rem_cnt); |
| 285 | } |
| 286 | #endif |
| 287 | } else if (strcasecmp(argV[2], "SET_FREQ_CAL_FINE") == 0) { |
| 288 | #if (EFUSE_CMD_OLD_FORMAT_EN) |
| 289 | printf("done: freq_cal_fine: 0x%8x\n", *(unsigned int *)priv_cmd.buf); |
| 290 | #else |
| 291 | signed char rem_cnt = (signed char)priv_cmd.buf[1]; |
| 292 | if (rem_cnt < 0) { |
| 293 | printf("failed to set freq_cal_fine, no room!\n"); |
| 294 | } else { |
| 295 | printf("done: freq_cal_fine: 0x%2x (remain:%x)\n", (unsigned char)priv_cmd.buf[0], rem_cnt); |
| 296 | } |
| 297 | #endif |
| 298 | } else if (strcasecmp(argV[2], "GET_EFUSE_BLOCK") == 0) |
| 299 | printf("done:efuse: 0x%8x\n", *(unsigned int *)priv_cmd.buf); |
| 300 | else if (strcasecmp(argV[2], "SET_XTAL_CAP") == 0) |
| 301 | printf("done:xtal cap: 0x%x\n", *(unsigned int *)priv_cmd.buf); |
| 302 | else if (strcasecmp(argV[2], "SET_XTAL_CAP_FINE") == 0) |
| 303 | printf("done:xtal cap fine: 0x%x\n", *(unsigned int *)priv_cmd.buf); |
| 304 | else if (strcasecmp(argV[2], "GET_RX_RESULT") == 0) |
| 305 | printf("done: getrx fcsok=%d, total=%d\n", *(unsigned int *)priv_cmd.buf, *(unsigned int *)&priv_cmd.buf[4]); |
| 306 | else if (strcasecmp(argV[2], "GET_MAC_ADDR") == 0) { |
| 307 | printf("done: get macaddr = %02x : %02x : %02x : %02x : %02x : %02x\n", |
| 308 | *(unsigned char *)&priv_cmd.buf[5], *(unsigned char *)&priv_cmd.buf[4], *(unsigned char *)&priv_cmd.buf[3], |
| 309 | *(unsigned char *)&priv_cmd.buf[2], *(unsigned char *)&priv_cmd.buf[1], *(unsigned char *)&priv_cmd.buf[0]); |
| 310 | #if (!EFUSE_CMD_OLD_FORMAT_EN) |
| 311 | printf(" (remain:%x)\n", priv_cmd.buf[6]); |
| 312 | #endif |
| 313 | } else if (strcasecmp(argV[2], "GET_BT_MAC_ADDR") == 0) { |
| 314 | printf("done: get bt macaddr = %02x : %02x : %02x : %02x : %02x : %02x\n", |
| 315 | *(unsigned char *)&priv_cmd.buf[5], *(unsigned char *)&priv_cmd.buf[4], *(unsigned char *)&priv_cmd.buf[3], |
| 316 | *(unsigned char *)&priv_cmd.buf[2], *(unsigned char *)&priv_cmd.buf[1], *(unsigned char *)&priv_cmd.buf[0]); |
| 317 | #if (!EFUSE_CMD_OLD_FORMAT_EN) |
| 318 | printf(" (remain:%x)\n", priv_cmd.buf[6]); |
| 319 | #endif |
| 320 | } else if (strcasecmp(argV[2], "GET_FREQ_CAL") == 0) { |
| 321 | unsigned int val = *(unsigned int *)&priv_cmd.buf[0]; |
| 322 | #if (EFUSE_CMD_OLD_FORMAT_EN) |
| 323 | printf("done: get_freq_cal: xtal_cap=0x%x, xtal_cap_fine=0x%x\n", val & 0x000000ff, (val >> 8) & 0x000000ff); |
| 324 | #elif (CHIP_SELECT == CHIP_AIC8800DCDW) |
| 325 | printf("done: get_freq_cal: xtal_cap=0x%x (remain:%x), xtal_cap_fine=0x%x (remain:%x)\n", |
| 326 | val & 0xff, (val >> 8) & 0xff, (val >> 16) & 0xff, (val >> 24) & 0xff); |
| 327 | #else |
| 328 | printf("done: get_freq_cal: xtal_cap=0x%x (remain:%x), xtal_cap_fine=0x%x (remain:%x)\n", |
| 329 | val & 0xff, (val >> 16) & 0xff, (val >> 8) & 0xff, (val >> 24) & 0xff); |
| 330 | #endif |
| 331 | } else if (strcasecmp(argV[2], "GET_VENDOR_INFO") == 0) { |
| 332 | #if (EFUSE_CMD_OLD_FORMAT_EN) |
| 333 | printf("done: get_vendor_info = 0x%x\n", *(unsigned char *)&priv_cmd.buf[0]); |
| 334 | #else |
| 335 | printf("done: get_vendor_info = 0x%x (remain:%x)\n", *(unsigned char *)&priv_cmd.buf[0], priv_cmd.buf[1]); |
| 336 | #endif |
| 337 | } else if (strcasecmp(argV[2], "RDWR_PWRMM") == 0) { |
| 338 | printf("done: txpwr manual mode = %x\n", *(unsigned int *)&priv_cmd.buf[0]); |
| 339 | } else if (strcasecmp(argV[2], "RDWR_PWRIDX") == 0) { |
| 340 | char *buff = &priv_cmd.buf[0]; |
| 341 | printf("done:\n" |
| 342 | "txpwr index 2.4g:\n" |
| 343 | " [0]=%d(ofdmlowrate)\n" |
| 344 | " [1]=%d(ofdm64qam)\n" |
| 345 | " [2]=%d(ofdm256qam)\n" |
| 346 | " [3]=%d(ofdm1024qam)\n" |
| 347 | " [4]=%d(dsss)\n", buff[0], buff[1], buff[2], buff[3], buff[4]); |
| 348 | printf("txpwr index 5g:\n" |
| 349 | " [0]=%d(ofdmlowrate)\n" |
| 350 | " [1]=%d(ofdm64qam)\n" |
| 351 | " [2]=%d(ofdm256qam)\n" |
| 352 | " [3]=%d(ofdm1024qam)\n", buff[5], buff[6], buff[7], buff[8]); |
| 353 | } else if (strcasecmp(argV[2], "RDWR_PWRLVL") == 0) { |
| 354 | char *buff = &priv_cmd.buf[0]; |
| 355 | int grp = 0; |
| 356 | int idx = 0; |
| 357 | int cnt = 0; |
| 358 | int tmp_idx = 0; |
| 359 | printf("done:\n" |
| 360 | "txpwr index 2.4g: [0]:11b+11a/g, [1]:11n/11ac, [2]:11ax\n"); |
| 361 | for (grp = 0; grp < 3; grp++) { |
| 362 | int cnt = 12; |
| 363 | if (grp == 1) { |
| 364 | cnt = 10; |
| 365 | } |
| 366 | printf(" [%x] =", grp); |
| 367 | for (idx = 0; idx < cnt; idx++) { |
| 368 | if (idx && !(idx & 0x3)) { |
| 369 | printf(" "); |
| 370 | } |
| 371 | printf(" %2d", buff[12 * grp + idx]); |
| 372 | } |
| 373 | printf("\r\n"); |
| 374 | } |
| 375 | printf("txpwr index 5g: [0]:11a, [1]:11n/11ac, [2]:11ax\n"); |
| 376 | for (grp = 0; grp < 3; grp++) { |
| 377 | cnt = 12; |
| 378 | idx = 0; |
| 379 | if (grp == 0) { |
| 380 | tmp_idx = 4; |
| 381 | } |
| 382 | if (grp == 1) { |
| 383 | cnt = 10; |
| 384 | tmp_idx = 0; |
| 385 | } |
| 386 | printf(" [%x] =", grp); |
| 387 | for (idx = tmp_idx ; idx < cnt; idx++) { |
| 388 | if (idx & !(idx & 0x3)) { |
| 389 | printf(" "); |
| 390 | } |
| 391 | printf(" %2d", buff[12 * (grp + 3) + idx]); |
| 392 | } |
| 393 | printf("\r\n"); |
| 394 | } |
| 395 | |
| 396 | } else if (strcasecmp(argV[2], "RDWR_PWROFST") == 0) { |
| 397 | signed char *buff = (signed char *)&priv_cmd.buf[0]; |
| 398 | #if (CHIP_SELECT < CHIP_AIC8800D80) |
| 399 | printf("done:\n" |
| 400 | "txpwr offset 2.4g: \n" |
| 401 | " [0]=%d(ch1~4)\n" |
| 402 | " [1]=%d(ch5~9)\n" |
| 403 | " [2]=%d(ch10~13)\n", (int8_t)buff[0], (int8_t)buff[1], (int8_t)buff[2]); |
| 404 | printf("txpwr offset 5g:\n" |
| 405 | " [0]=%d(ch36~64)\n" |
| 406 | " [1]=%d(ch100~120)\n" |
| 407 | " [2]=%d(ch122~140)\n" |
| 408 | " [3]=%d(ch142~165)\n", (int8_t)buff[3], (int8_t)buff[4], (int8_t)buff[5], (int8_t)buff[6]); |
| 409 | #elif (CHIP_SELECT == CHIP_AIC8800D80X2) |
| 410 | int type, ch_grp; |
| 411 | printf("done:\n" |
| 412 | "pwrofst2x_2.4g(ant0/ant1): [0]:11b, [1]:ofdm_highrate\n" |
| 413 | " chan=" "\t1-4" "\t5-9" "\t10-13"); |
| 414 | for (type = 0; type < 2; type++) { |
| 415 | printf("\n [%d] =", type); |
| 416 | for (ch_grp = 0; ch_grp < 3; ch_grp++) { |
| 417 | printf("\t%d/%d", buff[type + 3 * ch_grp], buff[type + 3 * ch_grp + 3 * 3]); |
| 418 | } |
| 419 | } |
| 420 | printf("\npwrofst2x_5g(ant0/ant1): [0]:ofdm_lowrate, [1]:ofdm_highrate\n" |
| 421 | " chan=" "\t36-50" "\t51-64" "\t98-114" "\t115-130" "\t131-146" "\t147-166"); |
| 422 | buff = (signed char *)&priv_cmd.buf[3 * 3 * 2]; |
| 423 | for (type = 0; type < 1; type++) { |
| 424 | printf("\n [%d] =", type); |
| 425 | for (ch_grp = 0; ch_grp < 6; ch_grp++) { |
| 426 | printf("\t%d/%d", buff[type + 3 *ch_grp], buff[type + 3 *ch_grp + 3 * 6]); |
| 427 | } |
| 428 | } |
| 429 | printf("\n"); |
| 430 | #else |
| 431 | int type, ch_grp; |
| 432 | printf("done:\n" |
| 433 | "pwrofst2x 2.4g: [0]:11b, [1]:ofdm_highrate, [2]:ofdm_lowrate\n" |
| 434 | " chan=" "\t1-4" "\t5-9" "\t10-13"); |
| 435 | for (type = 0; type < 3; type++) { |
| 436 | printf("\n [%d] =", type); |
| 437 | for (ch_grp = 0; ch_grp < 3; ch_grp++) { |
| 438 | printf("\t%d", buff[3 * type + ch_grp]); |
| 439 | } |
| 440 | } |
| 441 | printf("\npwrofst2x 5g: [0]:ofdm_lowrate, [1]:ofdm_highrate, [2]:ofdm_midrate\n" |
| 442 | " chan=" "\t36-50" "\t51-64" "\t98-114" "\t115-130" "\t131-146" "\t147-166"); |
| 443 | buff = (signed char *)&priv_cmd.buf[3 * 3]; |
| 444 | for (type = 0; type < 3; type++) { |
| 445 | printf("\n [%d] =", type); |
| 446 | for (ch_grp = 0; ch_grp < 6; ch_grp++) { |
| 447 | printf("\t%d", buff[6 * type + ch_grp]); |
| 448 | } |
| 449 | } |
| 450 | printf("\n"); |
| 451 | #endif |
| 452 | } else if (strcasecmp(argV[2], "RDWR_PWROFSTFINE") == 0) { |
| 453 | signed char *buff = (signed char *)&priv_cmd.buf[0]; |
| 454 | printf("done:\n" |
| 455 | "txpwr offset fine 2.4g: \n" |
| 456 | " [0]=%d(ch1~4)\n" |
| 457 | " [1]=%d(ch5~9)\n" |
| 458 | " [2]=%d(ch10~13)\n", (int8_t)buff[0], (int8_t)buff[1], (int8_t)buff[2]); |
| 459 | printf("txpwr offset fine 5g:\n" |
| 460 | " [0]=%d(ch36~64)\n" |
| 461 | " [1]=%d(ch100~120)\n" |
| 462 | " [2]=%d(ch122~140)\n" |
| 463 | " [3]=%d(ch142~165)\n", (int8_t)buff[3], (int8_t)buff[4], (int8_t)buff[5], (int8_t)buff[6]); |
| 464 | } else if (strcasecmp(argV[2], "RDWR_DRVIBIT") == 0) { |
| 465 | char *buff = &priv_cmd.buf[0]; |
| 466 | int idx = 0; |
| 467 | printf("done: 2.4g txgain tbl pa drv_ibit:\n"); |
| 468 | for (idx = 0; idx < 16; idx++) { |
| 469 | printf(" %x", buff[idx]); |
| 470 | if (!((idx + 1) & 0x03)) { |
| 471 | printf(" [%x~%x]\n", idx - 3, idx); |
| 472 | } |
| 473 | } |
| 474 | } else if (strcasecmp(argV[2], "RDWR_EFUSE_PWROFST") == 0) { |
| 475 | signed char *buff = (signed char *)&priv_cmd.buf[0]; |
| 476 | #if (EFUSE_CMD_OLD_FORMAT_EN) |
| 477 | printf("done:\n" |
| 478 | "efuse txpwr offset 2.4g:\n" |
| 479 | " [0]=%d(ch1~4)\n" |
| 480 | " [1]=%d(ch5~9)\n" |
| 481 | " [2]=%d(ch10~13)\n", (int8_t)buff[0], (int8_t)buff[1], (int8_t)buff[2]); |
| 482 | printf("efuse txpwr offset 5g:\n" |
| 483 | " [0]=%d(ch36~64)\n" |
| 484 | " [1]=%d(ch100~120)\n" |
| 485 | " [2]=%d(ch122~140)\n" |
| 486 | " [3]=%d(ch142~165)\n", (int8_t)buff[3], (int8_t)buff[4], (int8_t)buff[5], (int8_t)buff[6]); |
| 487 | #else |
| 488 | #if (CHIP_SELECT < CHIP_AIC8800D80) |
| 489 | printf("done:\n" |
| 490 | "efuse txpwr offset 2.4g:\n" |
| 491 | " [0]=%d(remain:%x, ch1~4)\n" |
| 492 | " [1]=%d(remain:%x, ch5~9)\n" |
| 493 | " [2]=%d(remain:%x, ch10~13)\n", |
| 494 | (int8_t)buff[0], (int8_t)buff[3], |
| 495 | (int8_t)buff[1], (int8_t)buff[4], |
| 496 | (int8_t)buff[2], (int8_t)buff[5]); |
| 497 | if (ret > 6) { // 5g_en |
| 498 | printf("efuse txpwr offset 5g:\n" |
| 499 | " [0]=%d(remain:%x, ch36~64)\n" |
| 500 | " [1]=%d(remain:%x, ch100~120)\n" |
| 501 | " [2]=%d(remain:%x, ch122~140)\n" |
| 502 | " [3]=%d(remain:%x, ch142~165)\n", |
| 503 | (int8_t)buff[6], (int8_t)buff[10], |
| 504 | (int8_t)buff[7], (int8_t)buff[11], |
| 505 | (int8_t)buff[8], (int8_t)buff[12], |
| 506 | (int8_t)buff[9], (int8_t)buff[13]); |
| 507 | } |
| 508 | #elif (CHIP_SELECT == CHIP_AIC8800D80X2) |
| 509 | int type, ch_grp; |
| 510 | printf("done:\n" |
| 511 | "ef_pwrofst2x_2.4g(ant0/ant1): [0]:11b, [1]:ofdm_highrate\n" |
| 512 | " chan=" "\t1-4" "\t5-9" "\t10-13"); |
| 513 | for (type = 0; type < 2; type++) { |
| 514 | printf("\n [%d] =", type); |
| 515 | for (ch_grp = 0; ch_grp < 3; ch_grp++) { |
| 516 | printf("\t%d/%d", buff[type + 3 * ch_grp], buff[type + 3 * ch_grp + 3 * 3]); |
| 517 | } |
| 518 | } |
| 519 | printf("\nef_pwrofst2x_5g(ant0/ant1): [0]:ofdm_lowrate, [1]:ofdm_highrate\n" |
| 520 | " chan=" "\t36-50" "\t51-64" "\t98-114" "\t115-130" "\t131-146" "\t147-166"); |
| 521 | buff = (signed char *)&priv_cmd.buf[3 * 3 * 2]; |
| 522 | for (type = 0; type < 1; type++) { |
| 523 | printf("\n [%d] =", type); |
| 524 | for (ch_grp = 0; ch_grp < 6; ch_grp++) { |
| 525 | printf("\t%d/%d", buff[type + 3 *ch_grp], buff[type + 3 *ch_grp + 3 * 6]); |
| 526 | } |
| 527 | } |
| 528 | printf("\n"); |
| 529 | #else |
| 530 | int type, ch_grp; |
| 531 | int tmp_index = 3*3 + 3*6;; |
| 532 | signed char * rem_buff ; |
| 533 | rem_buff = (signed char *)&priv_cmd.buf[tmp_index]; |
| 534 | printf("done:\n" |
| 535 | "pwrofst2x 2.4g: [0]:11b, [1]:ofdm_highrate, [2]:ofdm_lowrate\n" |
| 536 | " chan=" "\t1-4\t" "\t5-9\t" "\t10-13\t"); |
| 537 | for (type = 0; type < 3; type++) { |
| 538 | printf("\n [%d] =", type); |
| 539 | for (ch_grp = 0; ch_grp < 3; ch_grp++) { |
| 540 | if (rem_buff[3 * type + ch_grp] < 0) { |
| 541 | printf("\t%d(no room,r%d)", (signed char)priv_cmd.buf[3 * type + ch_grp], rem_buff[3 * type + ch_grp]); |
| 542 | } else { |
| 543 | printf("\t%d(r:%x)\t", (signed char)priv_cmd.buf[3 * type + ch_grp], rem_buff[3 * type + ch_grp]); |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | printf("\npwrofst2x 5g: [0]:ofdm_lowrate, [1]:ofdm_highrate, [2]:ofdm_midrate\n" |
| 548 | " chan=" "\t36-50\t" "\t51-64\t" "\t98-114\t" "\t115-130\t" "\t131-146\t" "\t147-166\t"); |
| 549 | buff = (signed char *)&priv_cmd.buf[3 * 3]; |
| 550 | tmp_index += 3*3; |
| 551 | rem_buff = (signed char *)&priv_cmd.buf[tmp_index]; |
| 552 | for (type = 0; type < 3; type++) { |
| 553 | printf("\n [%d] =", type); |
| 554 | for (ch_grp = 0; ch_grp < 6; ch_grp++) { |
| 555 | if (rem_buff[6 * type + ch_grp] < 0) { |
| 556 | printf("\t%d(no room,r%d)", buff[6 * type + ch_grp], rem_buff[6 * type + ch_grp]); |
| 557 | } else { |
| 558 | printf("\t%d(r:%x)\t", buff[6 * type + ch_grp], rem_buff[6 * type + ch_grp]); |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | printf("\n"); |
| 563 | #endif |
| 564 | #endif |
| 565 | } else if (strcasecmp(argV[2], "RDWR_EFUSE_PWROFSTFINE") == 0) { |
| 566 | signed char *buff = (signed char *)&priv_cmd.buf[0]; |
| 567 | #if (EFUSE_CMD_OLD_FORMAT_EN) |
| 568 | printf("done:\n" |
| 569 | "efuse txpwr offset fine 2.4g:\n" |
| 570 | " [0]=%d(ch1~4)\n" |
| 571 | " [1]=%d(ch5~9)\n" |
| 572 | " [2]=%d(ch10~13)\n", (int8_t)buff[0], (int8_t)buff[1], (int8_t)buff[2]); |
| 573 | printf("efuse txpwr offset fine 5g:\n" |
| 574 | " [0]=%d(ch36~64)\n" |
| 575 | " [1]=%d(ch100~120)\n" |
| 576 | " [2]=%d(ch122~140)\n" |
| 577 | " [3]=%d(ch142~165)\n", (int8_t)buff[3], (int8_t)buff[4], (int8_t)buff[5], (int8_t)buff[6]); |
| 578 | #else |
| 579 | printf("done:\n" |
| 580 | "efuse txpwr offset fine 2.4g:\n" |
| 581 | " [0]=%d(remain:%x, ch1~4)\n" |
| 582 | " [1]=%d(remain:%x, ch5~9)\n" |
| 583 | " [2]=%d(remain:%x, ch10~13)\n", |
| 584 | (int8_t)buff[0], (int8_t)buff[3], |
| 585 | (int8_t)buff[1], (int8_t)buff[4], |
| 586 | (int8_t)buff[2], (int8_t)buff[5]); |
| 587 | if (ret > 6) { // 5g_en |
| 588 | printf("efuse txpwr offset fine 5g:\n" |
| 589 | " [0]=%d(remain:%x, ch36~64)\n" |
| 590 | " [1]=%d(remain:%x, ch100~120)\n" |
| 591 | " [2]=%d(remain:%x, ch122~140)\n" |
| 592 | " [3]=%d(remain:%x, ch142~165)\n", |
| 593 | (int8_t)buff[6], (int8_t)buff[10], |
| 594 | (int8_t)buff[7], (int8_t)buff[11], |
| 595 | (int8_t)buff[8], (int8_t)buff[12], |
| 596 | (int8_t)buff[9], (int8_t)buff[13]); |
| 597 | } |
| 598 | #endif |
| 599 | } else if (strcasecmp(argV[2], "RDWR_EFUSE_DRVIBIT") == 0) { |
| 600 | #if (EFUSE_CMD_OLD_FORMAT_EN) |
| 601 | printf("done: efsue 2.4g txgain tbl pa drv_ibit: %x\n", priv_cmd.buf[0]); |
| 602 | #else |
| 603 | int val = *(int *)&priv_cmd.buf[0]; |
| 604 | if (val < 0) { |
| 605 | printf("failed to rd/wr efuse drv_ibit, ret=%d\n", val); |
| 606 | } else { |
| 607 | printf("done: efsue 2.4g txgain tbl pa drv_ibit: %x (remain: %x)\n", priv_cmd.buf[0], priv_cmd.buf[1]); |
| 608 | } |
| 609 | #endif |
| 610 | } else if (strcasecmp(argV[2], "RDWR_EFUSE_SDIOCFG") == 0) { |
| 611 | printf("done: efsue sdio cfg: %x\n", priv_cmd.buf[0]); |
| 612 | } else if (strcasecmp(argV[2], "RDWR_EFUSE_USBVIDPID") == 0) { |
| 613 | unsigned int val = (unsigned int)priv_cmd.buf[0] | |
| 614 | (unsigned int)(priv_cmd.buf[1] & 0xff) << 8 | |
| 615 | (unsigned int)(priv_cmd.buf[2] & 0xff) << 16 | |
| 616 | (unsigned int)(priv_cmd.buf[3] & 0xff) << 24; |
| 617 | printf("done: efsue usb vid/pid: %x\n", val); |
| 618 | } else if (strcasecmp(argV[2], "GET_CAL_XTAL_RES") == 0) { |
| 619 | unsigned int val = *(unsigned int *)&priv_cmd.buf[0]; |
| 620 | printf("done: get_cal_xtal_res: cap=0x%x, cap_fine=0x%x\n", val & 0x000000ff, (val >> 8) & 0x000000ff); |
| 621 | } else if ((strcasecmp(argV[2], "GET_COB_CAL_RES") == 0) || (strcasecmp(argV[2], "DO_COB_TEST") == 0)){ |
| 622 | unsigned int val = *(unsigned int *)&priv_cmd.buf[0]; |
| 623 | unsigned int val0 = *(unsigned int *)&priv_cmd.buf[4]; |
| 624 | cob_result_ptr = (cob_result_ptr_t *) (unsigned int *)&priv_cmd.buf[8]; |
| 625 | printf("done:\ncap= 0x%x cap_fine= 0x%x freq_ofst= %d Hz golden_rcv_dut= %d tx_rssi= %d dBm snr= %d dB dut_rcv_godlden= %d rx_rssi= %d dBm\n", |
| 626 | val & 0x000000ff, (val >> 8) & 0x000000ff, val0, cob_result_ptr->golden_rcv_dut_num, cob_result_ptr->rssi_static, cob_result_ptr->snr_static, cob_result_ptr->dut_rcv_golden_num, cob_result_ptr->dut_rssi_static); |
| 627 | } else if (strcasecmp(argV[2], "RDWR_EFUSE_USRDATA") == 0) { |
| 628 | unsigned int usr_data[3]; |
| 629 | usr_data[0] = *(unsigned int *)&priv_cmd.buf[0]; |
| 630 | usr_data[1] = *(unsigned int *)&priv_cmd.buf[4]; |
| 631 | usr_data[2] = *(unsigned int *)&priv_cmd.buf[8]; |
| 632 | printf("done: efuse usrdata:\n [0]=0x%08x\n [1]=0x%08x\n [2]=0x%08x\n", |
| 633 | usr_data[0], usr_data[1], usr_data[2]); |
| 634 | } else if (strcasecmp(argV[2], "RDWR_EFUSE_HE_OFF") == 0) { |
| 635 | printf("EFUSE_HE_OFF: %d\n", priv_cmd.buf[0]); |
| 636 | } else if (strcasecmp(argV[2], "GET_BT_RX_RESULT") == 0) { |
| 637 | printf("done: get bt rx total=%d, ok=%d, err=%d\n", *(unsigned int *)priv_cmd.buf, |
| 638 | *(unsigned int *)&priv_cmd.buf[4], |
| 639 | *(unsigned int *)&priv_cmd.buf[8]); |
| 640 | } else if (strcasecmp(argV[2], "BT_DATA") == 0) { |
| 641 | unsigned char *buff = (unsigned char *)&priv_cmd.buf[1]; |
| 642 | int len = priv_cmd.buf[0]; |
| 643 | int idx = 0; |
| 644 | printf("done: %d\n", len); |
| 645 | for (idx = 0; idx < len; idx++) { |
| 646 | printf("%02x ", buff[idx]); |
| 647 | } |
| 648 | printf("\n"); |
| 649 | } else if (strcasecmp(argV[2], "RDWR_BT_EFUSE_PWROFST") == 0) { |
| 650 | signed char *buff = (signed char *)&priv_cmd.buf[0]; |
| 651 | printf("done: bt efsue pwrofst %d (remain: %x)\n", priv_cmd.buf[0], priv_cmd.buf[1]); |
| 652 | } else if(strcasecmp(argV[2], "GET_CS_INFO") == 0) { |
| 653 | struct aicwf_cs_info *cs_info = (struct aicwf_cs_info *)priv_cmd.buf; |
| 654 | printf("phymode=%d(0:B 1:G 2:A 3:N 4:AC 5:AX)\n", cs_info->phymode); |
| 655 | printf("bandwidth=%d(0:20 1:40 2:80)\n", cs_info->bandwidth); |
| 656 | printf("freq=%d\n", cs_info->freq); |
| 657 | printf("rssi=%d\n", cs_info->rssi); |
| 658 | printf("snr=%d\n", cs_info->snr); |
| 659 | printf("noise=%d\n", cs_info->noise); |
| 660 | printf("txpwr=%d\n", cs_info->txpwr); |
| 661 | //chanutil |
| 662 | printf("chan busy times=%d/%d(ms)\n", cs_info->chan_time_busy_ms, cs_info->chan_time_ms); |
| 663 | printf("coutry code =%s\n", cs_info->countrycode); |
| 664 | printf("rx nss=%d, mcs=%x\n", cs_info->rxnss, cs_info->rxmcs); |
| 665 | printf("tx nss=%d, mcs=%x\n", cs_info->txnss, cs_info->txmcs); |
| 666 | printf("tx_phyrate=%d\n", cs_info->tx_phyrate); |
| 667 | printf("rx_phyrate=%d\n", cs_info->rx_phyrate); |
| 668 | printf("tx_ack_succ_stat=%d\n", cs_info->tx_ack_succ_stat); |
| 669 | printf("tx_ack_fail_stat=%d\n", cs_info->tx_ack_fail_stat); |
| 670 | } else { |
| 671 | printf("done\n"); |
| 672 | } |
| 673 | |
| 674 | return ret; |
| 675 | } |
| 676 | |
| 677 | int main(int argC, char *argV[]) |
| 678 | { |
| 679 | |
| 680 | //char* ins = "insmod"; |
| 681 | //char* rm = "rmmod"; |
| 682 | //char* ko = "rwnx_fdrv.ko"; |
| 683 | |
| 684 | //printf("enter!!!AIC argC=%d argV[0]=%s argV[1]=%s argV[2]=%s\n", argC, argV[0], argV[1],argV[2]); |
| 685 | if(argC >= 3) |
| 686 | wifi_send_cmd_to_net_interface(argV[1], argC, argV); |
| 687 | else if ((strcasecmp(argV[1], "-v") == 0) || (strcasecmp(argV[1], "version") == 0)) |
| 688 | printf("wifi_test %s_%d\n", RELEASE_DATE, CHIP_SELECT); |
| 689 | else |
| 690 | printf("Bad parameter! %d\n",argC); |
| 691 | |
| 692 | return 0; |
| 693 | } |