コード例 #1
0
ファイル: athtestcmd.c プロジェクト: Ar3kkusu/AR6kSDK.3.1
int main (int argc, char **argv)
{
    void (*reportCB)(void *) = NULL;
    void (*cmdRespCB)(void *) = cmdReplyFunc_readThermal;
#endif /* ATHTESTCMD_LIB */
    int c, s=-1;
    char ifname[IFNAMSIZ];
    unsigned int cmd = 0;
    progname = argv[0];
    struct ifreq ifr;
    char buf[2048];
    TCMD_CONT_TX *txCmd = (TCMD_CONT_TX *)((A_UINT32 *)buf + 1); /* first 32-bit is XIOCTL_CMD */
    TCMD_CONT_RX *rxCmd   = (TCMD_CONT_RX *)((A_UINT32 *)buf + 1);
    TCMD_PM *pmCmd = (TCMD_PM *)((A_UINT32 *)buf + 1);
    WMI_SET_LPREAMBLE_CMD *setLpreambleCmd = (WMI_SET_LPREAMBLE_CMD *)((A_UINT32 *)buf + 1);
    TCMD_SET_REG *setRegCmd = (TCMD_SET_REG *)((A_UINT32 *)buf + 1);
    TC_CMDS  *tCmds = (TC_CMDS *)((A_UINT32 *)buf + 1);
    A_BOOL needRxReport = FALSE;    
#ifndef ATHTESTCMD_LIB
    A_UINT16 efuse_begin = 0, efuse_end = (VENUS_OTP_SIZE - 1);
    A_UINT8  efuseBuf[VENUS_OTP_SIZE];
    A_UINT8  efuseWriteBuf[VENUS_OTP_SIZE];
    A_UINT16 data_length = 0;
#endif
    txCmd->numPackets = 0;
    txCmd->wlanMode = TCMD_WLAN_MODE_NOHT;
    txCmd->tpcm = TPC_TX_PWR;
/* default to tx power */
    rxCmd->u.para.wlanMode = TCMD_WLAN_MODE_NOHT;
#ifdef ATHTESTCMD_LIB
    if (setjmp(*jbuf)!=0) {
        if (s>=0)
            close(s);
        return -1;
    }
#endif 

    if (argc == 1) {
        usage();
    }

    memset(buf, 0, sizeof(buf));
    memset(ifname, '\0', IFNAMSIZ);
    strcpy(ifname, "eth1");
    s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s < 0) {
        A_ERR(1, "socket");
    }

    while (1) {
        int option_index = 0;
        static struct option long_options[] = {
            {"version", 0, NULL, 'v'},
            {"interface", 1, NULL, 'i'},
            {"tx", 1, NULL, 't'},
            {"txfreq", 1, NULL, 'f'},
            {"txrate", 1, NULL, 'g'},
            {"txpwr", 1, NULL, 'h'},
            {"tgtpwr", 0, NULL, 'H'},
            {"pcdac", 1, NULL, 'I'},
            {"txantenna", 1, NULL, 'j'},
            {"txpktsz", 1, NULL, 'z'},
            {"txpattern", 1, NULL, 'e'},
            {"rx", 1, NULL, 'r'},
            {"rxfreq", 1, NULL, 'p'},
            {"rxantenna", 1, NULL, 'q'},
            {"pm", 1, NULL, 'x'},
            {"setmac", 1, NULL, 's'},
            {"ani", 0, NULL, 'a'},
            {"scrambleroff", 0, NULL, 'o'},
            {"aifsn", 1, NULL, 'u'},
            {"SetAntSwitchTable", 1, NULL, 'S'},
            {"shortguard", 0, NULL, 'G'},
            {"numpackets", 1, NULL, 'n'},
            {"mode", 1, NULL, 'M'},
            {"setlongpreamble", 1, NULL, 'l'},
            {"setreg", 1, NULL, 'R'},                  
            {"regval", 1, NULL, 'V'},                
            {"flag", 1, NULL, 'F'},     
            {"writeotp", 0, NULL, 'w'},  	
            {"otpregdmn", 1, NULL, 'E'},		
#ifndef ATHTESTCMD_LIB
            {"efusedump", 0, NULL, 'm'},
            {"efusewrite", 0, NULL, 'W'},
            {"start", 1, NULL, 'A'},
            {"end", 1, NULL, 'L'},
            {"data", 1, NULL, 'U'},
            {"otpwrite", 0, NULL, 'O'},
            {"otpdump", 0, NULL, 'P'},
#endif
            {"btaddr", 1, NULL, 'B'},			
            {"therm", 0, NULL, 'c'},
            {0, 0, 0, 0}
        };

        c = getopt_long(argc, argv, "vi:t:f:g:h:HI:r:p:q:x:u:ao:M:A:L:mU:WOP",
                         long_options, &option_index);
        if (c == -1)
            break;

        switch (c) {
        case 'i':
            memset(ifname, '\0', 8);
            strcpy(ifname, optarg);
            break;
        case 't':
            cmd = TESTMODE_CONT_TX;
			txCmd->testCmdId = TCMD_CONT_TX_ID;
            if (!strcmp(optarg, "sine")) {
                txCmd->mode = TCMD_CONT_TX_SINE;
            } else if (!strcmp(optarg, "frame")) {
                txCmd->mode = TCMD_CONT_TX_FRAME;
            } else if (!strcmp(optarg, "tx99")) {
                txCmd->mode = TCMD_CONT_TX_TX99;
            } else if (!strcmp(optarg, "tx100")) {
                txCmd->mode = TCMD_CONT_TX_TX100;
            } else if (!strcmp(optarg, "off")) {
                txCmd->mode = TCMD_CONT_TX_OFF;
            }else {
                cmd = 0;
            }
            break;
        case 'f':
            txCmd->freq = freqValid(atoi(optarg));
            break;
        case 'G':
            txCmd->shortGuard = 1;
            break;
        case 'M':
            if(cmd == TESTMODE_CONT_TX) {
                if (!strcmp(optarg, "ht20")) {
                    txCmd->wlanMode = TCMD_WLAN_MODE_HT20;
                } else if (!strcmp(optarg, "ht40plus")) {
                    txCmd->wlanMode = TCMD_WLAN_MODE_HT40PLUS;
                } else if (!strcmp(optarg, "ht40minus")) {
                    txCmd->wlanMode = TCMD_WLAN_MODE_HT40MINUS;
                }
            } else if(cmd == TESTMODE_CONT_RX) {
                if (!strcmp(optarg, "ht20")) {
                    rxCmd->u.para.wlanMode = TCMD_WLAN_MODE_HT20;
                } else if (!strcmp(optarg, "ht40plus")) {
                    rxCmd->u.para.wlanMode = TCMD_WLAN_MODE_HT40PLUS;
                } else if (!strcmp(optarg, "ht40minus")) {
                    rxCmd->u.para.wlanMode = TCMD_WLAN_MODE_HT40MINUS;
                }
            }
            break;
        case 'n':
            txCmd->numPackets = atoi(optarg);
            break;
        case 'g':
            /* let user input index of rateTable instead of string parse */
            txCmd->dataRate = rateValid(atoi(optarg), txCmd->freq);
            break;
        case 'h':
        {
            int txPowerAsInt;
            /* Get tx power from user.  This is given in the form of a number
             * that's supposed to be either an integer, or an integer + 0.5
             */
            double txPowerIndBm = atof(optarg);

            /*
             * Check to make sure that the number given is either an integer
             * or an integer + 0.5
             */
            txPowerAsInt = (int)txPowerIndBm;
            if (((txPowerIndBm - (double)txPowerAsInt) == 0) ||
                (((txPowerIndBm - (double)txPowerAsInt)) == 0.5) ||
                (((txPowerIndBm - (double)txPowerAsInt)) == -0.5)) {
                if (txCmd->mode != TCMD_CONT_TX_SINE) {
                    txCmd->txPwr = txPowerIndBm * 2;
                } else {
                    txCmd->txPwr = txPowerIndBm;
                }
           } else {
                printf("Bad argument to --txpwr, must be in steps of 0.5 dBm\n");
                cmd = 0;
           }
             
            txCmd->tpcm = TPC_TX_PWR;
        }
            break;
        case 'H':
            txCmd->tpcm = TPC_TGT_PWR;
            break;
        case 'I':
            txCmd->tpcm = TPC_FORCED_GAIN;
            txCmd->txPwr = atof(optarg);
            break;
        case 'j':
            txCmd->antenna = antValid(atoi(optarg));
            break;       
        case 'z':
            txCmd->pktSz = pktSzValid(atoi(optarg));
            break;
        case 'e':
            txCmd->txPattern = atoi(optarg);
            break;
        case 'r':
            cmd = TESTMODE_CONT_RX;
			rxCmd->testCmdId = TCMD_CONT_RX_ID;
            if (!strcmp(optarg, "promis")) {
                rxCmd->act = TCMD_CONT_RX_PROMIS;
			 	printf(" Its cont Rx promis mode \n");
            } else if (!strcmp(optarg, "filter")) {
                rxCmd->act = TCMD_CONT_RX_FILTER;
				printf(" Its cont Rx  filter  mode \n");
            } else if (!strcmp(optarg, "report")) {
				 printf(" Its cont Rx report  mode \n");
                rxCmd->act = TCMD_CONT_RX_REPORT;
                needRxReport = TRUE;
            } else {
                cmd = 0;
            }
            break;
        case 'p':
            rxCmd->u.para.freq = freqValid(atoi(optarg));
            break;
        case 'q':
            rxCmd->u.para.antenna = antValid(atoi(optarg));
            break;
        case 'x':
            cmd = TESTMODE_PM;
			pmCmd->testCmdId = TCMD_PM_ID;
            if (!strcmp(optarg, "wakeup")) {
                pmCmd->mode = TCMD_PM_WAKEUP;
            } else if (!strcmp(optarg, "sleep")) {
                pmCmd->mode = TCMD_PM_SLEEP;
            } else if (!strcmp(optarg, "deepsleep")) {
                pmCmd->mode = TCMD_PM_DEEPSLEEP;
            } else {
                cmd = 0;
            }
            break;
        case 's':
            {
                A_UINT8 mac[ATH_MAC_LEN];

                cmd = TESTMODE_CONT_RX;
                rxCmd->testCmdId = TCMD_CONT_RX_ID;
                rxCmd->act = TCMD_CONT_RX_SETMAC;
                if (ath_ether_aton(optarg, mac) != A_OK) {
                    A_ERR(-1, "Invalid mac address format! \n");
                }
                memcpy(rxCmd->u.mac.addr, mac, ATH_MAC_LEN);
#ifdef TCMD_DEBUG
                printf("JLU: tcmd: setmac 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", 
                        mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
#endif
                break;
            }
        case 'u':
            {
                txCmd->aifsn = atoi(optarg) & 0xff;
                printf("AIFS:%d\n", txCmd->aifsn);
            }
            break;
        case 'a':
            if(cmd == TESTMODE_CONT_TX) {
                txCmd->enANI = TRUE;
            } else if(cmd == TESTMODE_CONT_RX) {
                rxCmd->enANI = TRUE;
            }
            break;
        case 'o':
            txCmd->scramblerOff = TRUE;
            break;
        case 'S':
            if (argc < 4)
                usage();
            cmd = TESTMODE_CONT_RX;
            rxCmd->testCmdId = TCMD_CONT_RX_ID;		
            rxCmd->act = TCMD_CONT_RX_SET_ANT_SWITCH_TABLE;				
            rxCmd->u.antswitchtable.antswitch1 = strtoul(argv[2], (char **)NULL,0);
            rxCmd->u.antswitchtable.antswitch2 = strtoul(argv[3], (char **)NULL,0);
            break;
        case 'l':
            cmd = TESTMODE_SETLPREAMBLE;
            setLpreambleCmd->status = atoi(optarg);
            break;
        case 'R':
            if (argc < 5) {
                printf("usage:athtestcmd -i eth0 --setreg 0x1234 --regval 0x01 --flag 0\n");
            }
            cmd = TESTMODE_SETREG;
            setRegCmd->testCmdId = TCMD_SET_REG_ID;
            setRegCmd->regAddr   = strtoul(optarg, (char **)NULL, 0);//atoi(optarg);
            break; 
        case 'V':
            setRegCmd->val = strtoul(optarg, (char **)NULL, 0);
            break;            
        case 'F':
            setRegCmd->flag = atoi(optarg);
            break;                       
        case 'w':
            rxCmd->u.mac.otpWriteFlag = 1;	
            break;		
        case 'E':
            rxCmd->u.mac.regDmn[0] = 0xffff&(strtoul(optarg, (char **)NULL, 0));
            rxCmd->u.mac.regDmn[1] = 0xffff&(strtoul(optarg, (char **)NULL, 0)>>16);		
            break;		
        case 'B':
            {    				           
                A_UINT8 btaddr[ATH_MAC_LEN];
                if (ath_ether_aton(optarg, btaddr) != A_OK) {
                    A_ERR(-1, "Invalid mac address format! \n");
                } 
                memcpy(rxCmd->u.mac.btaddr, btaddr, ATH_MAC_LEN);
#ifdef TCMD_DEBUG
                printf("JLU: tcmd: setbtaddr 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x\n", 
                        btaddr[0], btaddr[1], btaddr[2], btaddr[3], btaddr[4], btaddr[5]);
#endif		
            }
            break;		
        case 'c':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId = TC_CMDS_ID;
            {
                tCmds->hdr.u.parm.length = (A_UINT16)0;    
                tCmds->hdr.u.parm.version = TC_CMDS_VERSION_TS;    
                tCmds->hdr.act = TC_CMDS_READTHERMAL;//TC_CMDS_CAL_THERMALVOLT;
            }
            break;
	
#ifndef ATHTESTCMD_LIB
        case 'A':
            efuse_begin = atoi(optarg);
            break;

        case 'L':
            efuse_end = atoi(optarg);
            break;

        case 'U':
            {
                A_UINT8* pucArg = (A_UINT8*)optarg;
                A_UINT8  c;
                A_UINT8  strBuf[256];
                A_UINT8  pos = 0;
                A_UINT16 length = 0;
                A_UINT32  data;

                /* Sweep string to end */
                while (1) {
                    c = *pucArg++;
                    if (isHex(c)) {
                        strBuf[pos++] = c;
                    } else {
                        strBuf[pos] = '\0';
                        pos = 0;
                        sscanf(((char *)&strBuf), "%x", &data);
                        efuseWriteBuf[length++] = (data & 0xFF);

                        /* End of arg string */
                        if (c == '\0') {
                            break;
                        }
                    }
                }

                data_length = length;
            }
            break;

        case 'm':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId      = TC_CMDS_ID;
            tCmds->hdr.act            = TC_CMDS_EFUSEDUMP;
            cmdRespCB = cmdReplyFunc;
            break;

        case 'W':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId      = TC_CMDS_ID;
            tCmds->hdr.act            = TC_CMDS_EFUSEWRITE;
            cmdRespCB = cmdReplyFunc;
            break;

        case 'O':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId      = TC_CMDS_ID;
            tCmds->hdr.act            = TC_CMDS_OTPSTREAMWRITE;
            cmdRespCB = cmdReplyFunc;
            break;

        case 'P':
            cmd = TESTMODE_CMDS;
            tCmds->hdr.testCmdId      = TC_CMDS_ID;
            tCmds->hdr.act            = TC_CMDS_OTPDUMP;
            cmdRespCB = cmdReplyFunc;
            break;
#endif		
        default:
            usage();
        }
    }

    strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));

    switch (cmd) {
    case TESTMODE_CONT_TX:
#ifdef CONFIG_HOST_TCMD_SUPPORT
        *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_CONT_TX;

        txPwrValid(txCmd);

        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            A_ERR(1, "%s", ifr.ifr_name);
        }
#endif /* CONFIG_HOST_TCMD_SUPPORT */
        break;
    case TESTMODE_CONT_RX:
#ifdef CONFIG_HOST_TCMD_SUPPORT
        *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_CONT_RX;

        if (rxCmd->act == TCMD_CONT_RX_PROMIS ||
             rxCmd->act == TCMD_CONT_RX_FILTER) {
            if (rxCmd->u.para.freq == 0)
                rxCmd->u.para.freq = 2412;
        }

        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            A_ERR(1, "%s", ifr.ifr_name);
        }
        if (reportCB) {
            reportCB(ifr.ifr_data);
        }
        if (needRxReport) {
            rxReport(ifr.ifr_data);
            needRxReport = FALSE;
        }
#endif /* CONFIG_HOST_TCMD_SUPPORT */
        break;
    case TESTMODE_PM:
#ifdef CONFIG_HOST_TCMD_SUPPORT
        *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_PM;
        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            A_ERR(1, "%s", ifr.ifr_name);
        }
#endif /* CONFIG_HOST_TCMD_SUPPORT */
        break;
    case TESTMODE_SETLPREAMBLE:
        *(A_UINT32 *)buf = AR6000_XIOCTL_WMI_SET_LPREAMBLE;
        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            A_ERR(1, "%s", ifr.ifr_name);
        }   
        break;   
    case TESTMODE_SETREG:
        *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_SETREG;
        ifr.ifr_data = (void *)buf;
        if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
            printf("%s", ifr.ifr_name);
        }   
        break;
#ifndef ATHTESTCMD_LIB              
    case TESTMODE_CMDS:
        if (tCmds->hdr.act == TC_CMDS_EFUSEDUMP) {
            int i, k;
            int blkNum;
            A_UINT16 efuseEnd   = efuse_end;
            A_UINT16 efuseBegin = efuse_begin;
            A_UINT16 efusePrintAnkor;
            A_UINT16 numPlaceHolder;

            /* Input check */
            if (efuseEnd > (VENUS_OTP_SIZE - 1)) {
                efuseEnd = (VENUS_OTP_SIZE - 1);
            }

            if (efuseBegin > efuseEnd) {
                efuseBegin = efuseEnd;
            }

            efusePrintAnkor = efuseBegin;

            blkNum = ((efuseEnd - efuseBegin) / TC_CMDS_SIZE_MAX) + 1;

            /* Request data in several trys */
            for (i = 0; i < blkNum; i++) {
                tCmds->hdr.testCmdId      = TC_CMDS_ID;
                tCmds->hdr.act            = TC_CMDS_EFUSEDUMP;
                tCmds->hdr.u.parm.length  = 4;    
                tCmds->hdr.u.parm.version = TC_CMDS_VERSION_TS;  

                tCmds->buf[0] = (efuseBegin & 0xFF);
                tCmds->buf[1] = (efuseBegin >> 8) & 0xFF;
                tCmds->buf[2] = (efuseEnd & 0xFF);
                tCmds->buf[3] = (efuseEnd >> 8) & 0xFF;      

                *(A_UINT32 *)buf = AR6000_XIOCTL_TCMD_CMDS;

                ifr.ifr_data = (void *)buf;

                if (ioctl(s, AR6000_IOCTL_EXTENDED, &ifr) < 0) {
                    A_ERR(1,"%s", ifr.ifr_name);
                }

                if (cmdRespCB) {
                    cmdRespCB(ifr.ifr_data);
                }

                /* Last block? */
                if ((efuseEnd - efuseBegin + 1) < TC_CMDS_SIZE_MAX) {
                    memcpy((void*)(efuseBuf + efuseBegin), (void*)&(sTcCmds.buf[0]), (efuseEnd - efuseBegin + 1));
                } else {
                    memcpy((void*)(efuseBuf + efuseBegin), (void*)&(sTcCmds.buf[0]), TC_CMDS_SIZE_MAX);
                }

                /* Adjust the efuseBegin but keep efuseEnd unchanged */
                efuseBegin += TC_CMDS_SIZE_MAX;
            }

            /* Output Dump */
            printf("------------------- eFuse Dump ----------------------");
            for (i = efusePrintAnkor; i <= efuseEnd; i++) {
                /* Cosmetics */
                if (i == efusePrintAnkor) {
                    numPlaceHolder = (efusePrintAnkor & 0x0F);
                    printf("\n%04X:", (efusePrintAnkor & 0xFFF0));
                    for (k = 0; k < numPlaceHolder; k++) {
                        printf("   ");
                    }
                } else if ((i & 0x0F) == 0) {
                    printf("\n%04X:", i);
                }

                printf(" %02X", efuseBuf[i]);
            }
            printf("\n\n");
        } else if (tCmds->hdr.act == TC_CMDS_EFUSEWRITE) {
コード例 #2
0
ファイル: tx99tool.c プロジェクト: KHATEEBNSIT/AP
int
main(int argc, char *argv[])
{
	const char *ifname, *cmd;
	tx99_wcmd_t i_req;
	int s;
	struct ifreq ifr;
	int value = 0;

	if (argc < 3)
		usage();
	ifname = argv[1];
	cmd = argv[2];
	
    (void) memset(&ifr, 0, sizeof(ifr));
    (void) strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
    (void) memset(&i_req, 0, sizeof(i_req));
    (void) strncpy(i_req.if_name, ifname, IFNAMSIZ);

    /* enable */
	if(!strcasecmp(cmd, "start")) {
		if(argc > 3) {
			fprintf(stderr,"Too many arguments\n");
			fprintf(stderr,"usage: tx99tool wifi0 start\n");
			goto ErrExit;
		}
		i_req.type = TX99_WCMD_ENABLE;
	}	
	/* disable */
	else if(!strcasecmp(cmd, "stop")) {
		if(argc > 3) {
			fprintf(stderr,"Too many arguments\n");
			fprintf(stderr,"usage: tx99tool wifi0 stop\n");
			goto ErrExit;
		}
		i_req.type = TX99_WCMD_DISABLE;
	} 
	/* get */
	else if (!strcasecmp(cmd, "get")) {
	    if(argc > 3) {
			fprintf(stderr,"Too many arguments\n");
			fprintf(stderr,"usage: tx99tool wifi0 get\n");
			goto ErrExit;
		}
        i_req.type = TX99_WCMD_GET;
    } 
    /* set */
    else if (!strcasecmp(cmd, "set")) {
        if (argc < 4)
		    usage();
    
    	/* Tx frequency, bandwidth and extension channel offset */
    	if(!strcasecmp(argv[3], "freq") && argc ==9) {
			
    		i_req.type = TX99_WCMD_SET_FREQ;
			value = freqValid(atoi(argv[4]));
			if(!value) {
				fprintf(stderr,"invalid the freqency \r\n");
				goto ErrExit;
			}
    		i_req.data.freq = value;

			if(!strncmp(argv[5], "band", strlen("band"))){
				value = atoi(argv[6]);
			    if(!((value >= 0) && (value <= 2))){
					fprintf(stderr,"The value of bandwidth is invalid, the valid value: 0: 20MHZ, 1:20+40MHZ,2:40 MHZ \r\n");
					goto ErrExit;
				}

	    		i_req.data.htmode = value;
			}
			if(!strncmp(argv[7], "ht", strlen("ht"))){
				value = atoi(argv[8]);
			    if(!(( value >= 0)&&( value <= 2))) {
					fprintf(stderr,"The value of htext is invalid, the valid value: 0: legacy, 1:when the extension is plus,2:when extension is minus \r\n");
					goto ErrExit;
				}
				i_req.data.htext = value;

			}
    	}
    	/* rate - Kbits/s */
    	else if(!strcasecmp(argv[3], "rate")) {
    		if(argc != 5) {
    			fprintf(stderr,"Wrong arguments\n");
    			fprintf(stderr,"usage: tx99tool wifi0 set rate [Tx rate]\n");
				goto ErrExit;
    		}
    		i_req.type = TX99_WCMD_SET_RATE;
			value =  atoi(argv[4]);
			if (value < 0){
    			fprintf(stderr,"Wrong arguments, the rate should > 0 \n");
				goto ErrExit;
			}
    		i_req.data.rate = value;
    	}
    	/* Tx power */
    	else if(!strcasecmp(argv[3], "pwr")) {
    		if(argc != 5) {
    			fprintf(stderr,"Wrong arguments\n");
    			fprintf(stderr,"usage: tx99tool wifi0 set pwr [Tx pwr]\n");
				goto ErrExit;
    		}
			
    		i_req.type = TX99_WCMD_SET_POWER;
			value =  atoi(argv[4]);
			
			if (value < 0) {
    			fprintf(stderr,"Wrong arguments, the power should > 0 \n");
				goto ErrExit;
			}
			i_req.data.power = value;
		
    	}
		
    	/* tx chain mask - 1, 2, 3 (for 2*2) */
    	else if(!strcasecmp(argv[3], "txchain")) {
    		if(argc != 5) {
    			fprintf(stderr,"Wrong arguments\n");
    			fprintf(stderr,"usage: tx99tool wifi0 set txchain [Tx chain mask]\n");
				goto ErrExit;
    		}
    		i_req.type = TX99_WCMD_SET_CHANMASK;
			value = atoi(argv[4]);
			if( !((value == 1) || (value ==3 )|| (value ==7))) {
    			fprintf(stderr,"The valid value of txchain: 1: 1x1, 3: 2x2, 7:3x3 \r\n");
				goto ErrExit;
			}
				
    		i_req.data.chanmask = value;
    	}
    	/* Tx type - 0: data modulated, 1:single carrier */
    	else if(!strcasecmp(argv[3], "type")) {
			#if 0
    		if(argc != 5) {
    			fprintf(stderr,"Wrong arguments\n");
    			fprintf(stderr,"usage: tx99tool wifi0 set type [Tx type]\n");
    			goto ErrExit;
    		}
    		i_req.type = TX99_WCMD_SET_TYPE;
    		i_req.data.type = atoi(argv[4]);
			#else
			fprintf(stderr,"usage: don't support configure the tx type ");
			goto ErrExit;
			#endif
    	}    else if(!strcasecmp(argv[3], "txmode")) {
            if(argc != 5) {
                fprintf(stderr,"Wrong arguements \n");
                fprintf(stderr,"usage: tx99tool wifi0 set txmode [0: 11A 1: 11B  2: 11G 5: 11NAHT20 6: 11NGHT20 7: 11NAHT40PLUS 8: 11NAHT40MINUS 9: 11NGHT40PLUS 10: 11NGHT40MINUS] \n");
                goto ErrExit;
            }
            i_req.type = TX99_WCMD_SET_TXMODE;
			value = atoi(argv[4]);
		    if(!(( value >= 0) && (value <= 10) && (value !=4 ) && (value !=3 ))) {
				fprintf(stderr,"usage: tx99tool wifi0 set txmode [0: 11A1: 11B 2: 11G 5: 11NAHT20 6: 11NGHT20 7: 11NAHT40PLUS 8: 11NAHT40MINUS 9: 11NGHT40PLUS 10: 11NGHT40MINUS] \n");
				goto ErrExit;
		   }
            i_req.data.txmode = value;
        }
        else if(!strcasecmp(argv[3], "testmode")) {
            if(argc != 5) {
                fprintf(stderr,"Wrong arguments\n");
                fprintf(stderr,"usage: tx99tool wifi0 set testmode [Test Mode]\n");
                goto ErrExit;
            }
            i_req.type = TX99_WCMD_SET_TESTMODE;
			value = atoi(argv[4]);
		    if(!(( value >= 0) && ( value <= 4))) {
	            fprintf(stderr,"usage: tx99tool wifi0 set testmode[0:TransMIT PN9 data 1:Transmit All zeros 2:Transmit All ones, 3:Receive only 4:Single Carrier mode\n");
				goto ErrExit;
			}

            i_req.data.testmode = value;
        }
    	else 
        	usage();

    } else
        usage();
    
    ifr.ifr_data = (void *) &i_req;
    
	s = socket(AF_INET, SOCK_DGRAM, 0);
	if (s < 0)
		err(1, "socket(SOCK_DRAGM)");
	
    if (ioctl(s, SIOCIOCTLTX99, &ifr) < 0)
		err(1, "ioctl");


    return 0;
ErrExit:
		exit(-1);


}