📄 wetctl.c
字号:
cmd.wBSSType = ADHOC;
}
else {
cmd.wBSSType = INFRA;
}
cmd.ssid[0] = SSID_ID;
if ((cmd.ssid[1] = strlen(argv[4])) <= 32 ) {
if (strcmp(argv[4], "any") == 0 ) {
cmd.ssid[1] = 0;
cmd.ssid[2] = 0;
}
else {
memcpy( &(cmd.ssid[2]), argv[4], cmd.ssid[1]);
}
}
else {
printf("warning: ssid longer than 32 chars set to 'any ssid'");
cmd.ssid[1] = 0;
cmd.ssid[2] = 0;
}
cmd.uChannel = atoi(argv[5]);
if (strcmp(argv[6], "yes") == 0) {
cmd.bPSEnable = TRUE;
}
else {
cmd.bPSEnable= FALSE;
}
if (strcmp(argv[7], "share") == 0) {
cmd.bShareKeyAuth = TRUE;
}
else {
cmd.bShareKeyAuth = FALSE;
}
result = ioctl( skfd, IOCTL_CMD_SET, &sReq);
if ( sReq.wResult ) {
printf("%s: Fail in Join a wireless network command !\n", AppName);
result = 1;
}
}
return result;
}
/*+
*
* Description:
*
* Called when set 'apstart' command at the
* command line to start ESS
*
* Parameters:
* In:
* skfd, argc, argv
* Out:
* none
*
* Return Value: '0' if success
*
-*/
int s_cmdAPStart(int skfd, int argc, char **argv) {
int result = 0;
SCmdRequest sReq;
SCmdStartAP cmd;
if ( argc < 6 ) {
printf("%s: not enough arguments for the 'startap' command;\n ", AppName);
vCmdUsage();
result = 1;
}
else {
strcpy((char *)sReq.name, argv[1]);
sReq.wResult = 0;
sReq.data = &cmd;
sReq.wCmdCode = WLAN_CMD_AP_START;
if (strcmp(argv[3], "ap") == 0) {
cmd.wBSSType = AP;
}
else {
cmd.wBSSType =INFRA;
}
cmd.ssid[0] = SSID_ID;
if ((cmd.ssid[1] = strlen(argv[4])) <= 32 ) {
if (strcmp(argv[4], "any") == 0 ) {
cmd.ssid[1] = 0;
cmd.ssid[2] = 0;
}
else {
memcpy( &(cmd.ssid[2]), argv[4], cmd.ssid[1]);
}
}
else {
printf("warning: ssid longer than 32 chars set to 'any ssid'");
cmd.ssid[1] = 0;
cmd.ssid[2] = 0;
}
cmd.uChannel = atoi(argv[5]);
cmd.uBeaconInt = atoi(argv[6]);
if (strcmp(argv[7], "share") == 0) {
cmd.bShareKeyAuth = TRUE;
}
else {
cmd.bShareKeyAuth = FALSE;
}
cmd.byBasicRate = atoi(argv[8]);
cmd.wBBPType = atoi(argv[9]);
result = ioctl( skfd, IOCTL_CMD_SET, &sReq);
if ( sReq.wResult ) {
printf("%s: Fail in start a wireless network command !\n", AppName);
result = 1;
}
}
return result;
}
/*+
*
* Description:
*
* Called when the user has requested the 'privacy' command at the
* command line to set WEP key.
*
* Parameters:
* In:
* skfd, argc, argv
* Out:
* none
*
* Return Value: '0' if success
*
-*/
int s_cmdSetWEP(int skfd, int argc, char **argv) {
int result, ii;
SCmdRequest sReq;
SCmdSetWEP cmd;
int StrLen;
result = 0;
if ( argc < 4 ) {
printf("%s: not enough arguments for the privacy command;\n ", AppName);
vCmdUsage();
result = 1;
return result;
}
if (strcmp(argv[3], "off") == 0) {
cmd.bEnableWep = FALSE;
}
else {
cmd.bEnableWep = TRUE;
if ( argc < 5 ) {
printf("%s: not enough arguments for the privacy command;\n ", AppName);
vCmdUsage();
result = 1;
return result;
}
else {
memset(&cmd.abyWepKey, 0, (WEP_NKEYS * WEP_KEYMAXLEN));
cmd.byKeyIndex = atoi(argv[3]);
for(ii = 4; ii < argc ; ii++) {
if (strcmp(argv[ii], "key0") == 0) {
if (strcmp(argv[ii+1], "no") != 0) {
StrLen = strlen(argv[ii+1]);
if (StrLen <= 14) {
if (StrLen == 14) {
cmd.auWepKeyLength[0] = WEP_40BIT_LEN;
}else {
printf("%s: WEP_KEY0 40bit format error!\n", AppName);
break;
}
} //38 = 26 + 12
else if (StrLen <= 38) {
if (StrLen == 38) {
cmd.auWepKeyLength[0] = WEP_104BIT_LEN;
}else {
printf("%s: WEP_KEY0 104bit format error!\n", AppName);
break;
}
} //86 = 29x2 + 28
else if (StrLen <= 86) {
if (StrLen == 86) {
cmd.auWepKeyLength[0] = WEP_232BIT_LEN;
}else {
printf("%s: WEP_KEY0 232bit format error!\n", AppName);
break;
}
}
vByteToWEP232(&(cmd.abyWepKey[0][0]), argv[ii+1]);
cmd.bWepKeyAvailable[0] = TRUE;
}
else {
cmd.bWepKeyAvailable[0] = FALSE;
}
}
if (strcmp(argv[ii], "key1") == 0) {
if (strcmp(argv[ii+1], "no") != 0) {
StrLen = strlen(argv[ii+1]);
if (StrLen <= 14) {
if (StrLen == 14) {
cmd.auWepKeyLength[1] = WEP_40BIT_LEN;
}else {
printf("%s: WEP_KEY1 40bit format error!\n", AppName);
break;
}
} //38 = 26 + 12
else if (StrLen <= 38) {
if (StrLen == 38) {
cmd.auWepKeyLength[1] = WEP_104BIT_LEN;
}else {
printf("%s: WEP_KEY1 104bit format error!\n", AppName);
break;
}
} //47 = 32 + 15
else if (StrLen <= 86) {
if (StrLen == 86) {
cmd.auWepKeyLength[1] = WEP_232BIT_LEN;
}else {
printf("%s: WEP_KEY1 232bit format error!\n", AppName);
break;
}
}
vByteToWEP232(&(cmd.abyWepKey[1][0]), argv[ii+1]);
cmd.bWepKeyAvailable[1] = TRUE;
}
else {
cmd.bWepKeyAvailable[1] = FALSE;
}
}
if (strcmp(argv[ii], "key2") == 0) {
if (strcmp(argv[ii+1], "no") != 0) {
StrLen = strlen(argv[ii+1]);
if (StrLen <= 14) {
if (StrLen == 14) {
cmd.auWepKeyLength[2] = WEP_40BIT_LEN;
}else {
printf("%s: WEP_KEY2 40bit format error!\n", AppName);
break;
}
} //38 = 26 + 12
else if (StrLen <= 38) {
if (StrLen == 38) {
cmd.auWepKeyLength[2] = WEP_104BIT_LEN;
}else {
printf("%s: WEP_KEY2 104bit format error!\n", AppName);
break;
}
} //47 = 32 + 15
else if (StrLen <= 86) {
if (StrLen == 86) {
cmd.auWepKeyLength[2] = WEP_232BIT_LEN;
}else {
printf("%s: WEP_KEY2 232bit format error!\n", AppName);
break;
}
}
vByteToWEP232(&(cmd.abyWepKey[2][0]), argv[ii+1]);
cmd.bWepKeyAvailable[2] = TRUE;
}
else {
cmd.bWepKeyAvailable[2] = FALSE;
}
}
if (strcmp(argv[ii], "key3") == 0) {
if (strcmp(argv[ii+1], "no") != 0) {
StrLen = strlen(argv[ii+1]);
if (StrLen <= 14) {
if (StrLen == 14) {
cmd.auWepKeyLength[3] = WEP_40BIT_LEN;
}else {
printf("%s: WEP_KEY3 40bit format error!\n", AppName);
break;
}
} //38 = 26 + 12
else if (StrLen <= 38) {
if (StrLen == 38) {
cmd.auWepKeyLength[3] = WEP_104BIT_LEN;
}else {
printf("%s: WEP_KEY3 104bit format error!\n", AppName);
break;
}
} //47 = 32 + 15
else if (StrLen <= 86) {
if (StrLen == 86) {
cmd.auWepKeyLength[3] = WEP_232BIT_LEN;
}else {
printf("%s: WEP_KEY3 232bit format error!\n", AppName);
break;
}
}
vByteToWEP232(&(cmd.abyWepKey[3][0]), argv[ii+1]);
cmd.bWepKeyAvailable[3] = TRUE;
}
else {
cmd.bWepKeyAvailable[3] = FALSE;
}
}
}
}
}
strcpy((char *)sReq.name, argv[1]);
sReq.wResult = 0;
sReq.data = &cmd;
sReq.wCmdCode = WLAN_CMD_SET_WEP;
result = ioctl( skfd, IOCTL_CMD_SET, &sReq);
if (sReq.wResult) {
printf("%s: Either the wep key was invalid or mac function didn't work.\n",
AppName);
result = 1;
}
return result;
}
/*+
*
* Description:
*
* Called when the user has requested the 'list' command at the
* command line.
* This function prints all the BSS's in the current list of BSS's
* generated from the last scan.
*
* Parameters:
* In:
* skfd, argc, argv
* Out:
* none
*
* Return Value: '0' if success
*
-*/
int s_cmdGetList(int skfd, int argc, char **argv)
{
int result;
SCmdRequest sReq;
SBSSIDList sList;
PSBSSIDList pList;
result = 0;
memset(&sList, 0, sizeof(SBSSIDList));
strcpy((char *)sReq.name, argv[1]);
sReq.wResult = 0;
sReq.data = &sList;
sReq.wCmdCode = WLAN_CMD_GET_LISTLEN;
result = ioctl( skfd, IOCTL_CMD_SET, &sReq);
if (result || sReq.wResult) {
printf( "%s: failed in get bssid list command.\n", AppName);
result = 1;
}
else {
pList = malloc( sizeof(SBSSIDList) + (sList.uItem * sizeof(SBSSIDItem)));
pList->uItem = sList.uItem;
sReq.wResult = 0;
sReq.data = pList;
sReq.wCmdCode = WLAN_CMD_GET_LIST;
result = ioctl( skfd, IOCTL_CMD_SET, &sReq);
if (result || sReq.wResult) {
printf( "%s: failed get bssid list command\n", AppName);
result = 1;
}
else {
vShowList(pList);
}
}
return result;
}
/*+
*
* Description:
*
*
* Show basic service sets list
*
* Parameters:
* In:
* pList
* Out:
* none
*
* Return Value: none
*
-*/
VOID vShowList(PSBSSIDList pList)
{
int ii;
BYTE buf[80];
printf("CH BSSID BCN TYPE WEP RSSI SSID\n");
for (ii = 0; ii < pList->uItem; ii++) {
// printf("CH BSSID BCN TYPE WEP RSSI SSID\n");
printf("%03d ", (int)pList->sBSSIDList[ii].uChannel);
vAddrToStr(pList->sBSSIDList[ii].abyBSSID, buf);
printf("%s ", buf);
printf("%04d ", pList->sBSSIDList[ii].wBeaconInterval);
if(pList->sBSSIDList[ii].byNetType == ADHOC) {
printf("Adhoc ");
}
else {
printf("Infra ");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -