📄 wetctl.c
字号:
/*
* Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
* All rights reserved.
*
* This software is copyrighted by and is the sole property of
* VIA Networking Technologies, Inc. This software may only be used
* in accordance with the corresponding license agreement. Any unauthorized
* use, duplication, transmission, distribution, or disclosure of this
* software is expressly forbidden.
*
* This software is provided by VIA Networking Technologies, Inc. "as is"
* and any express or implied warranties, including, but not limited to, the
* implied warranties of merchantability and fitness for a particular purpose
* are disclaimed. In no event shall VIA Networking Technologies, Inc.
* be liable for any direct, indirect, incidental, special, exemplary, or
* consequential damages.
*
*
* File: wetctl.c
*
* Purpose:
*
* Command mode utility for Solomon 802.11a/b/g wireless card
*
* Author: lyndon chen
*
* Date: Jan 2, 2003
*
* Functions:
* s_cmdBSSJoin- join an existing BSS set via ioctl command
* s_cmdScan- scan all channels via ioctl command
* s_cmdSetWEP- set wep key via ioctl command
* s_cmdGetLink- get link status via ioctl command
* s_cmdGetList- get scan list via ioctl command
* s_cmdGetMIB- get DOT11 MIB via ioctl command
* s_cmdGetSTAT- get Statistics via ioctl command
* vShowList- print scan list
* vByteToWEP232- byte string to Hex key
* vAddrToStr- print MAC address
* vCmdUsage- command help list
* Revision History:
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include "wetctl.h"
#include "ttype.h"
#include "iocmd.h"
/*--------------------- Static Definitions -------------------------*/
/*--------------------- Static Classes ----------------------------*/
/*--------------------- Static Variables --------------------------*/
BYTE AppName[20];
/*--------------------- Static Functions --------------------------*/
static int s_cmdBSSJoin(int skfd, int argc, char **argv);
static int s_cmdAPStart(int skfd, int argc, char **argv);
static int s_cmdScan(int skfd, int argc, char **argv);
static int s_cmdSetWEP(int skfd, int argc, char **argv);
static int s_cmdGetLink(int skfd, int argc, char **argv);
static int s_cmdGetList(int skfd, int argc, char **argv);
static int s_cmdGetMIB(int skfd, int argc, char **argv);
//static int s_cmdGetSTAT(int skfd, int argc, char **argv);
static int s_cmdStopMAC(int skfd, int argc, char **argv);
static int s_cmdStartMAC(int skfd, int argc, char **argv);
static int s_cmdGetNodeList(int skfd, int argc, char **argv);
static VOID vShowList(PSBSSIDList pList);
static VOID vShowNodeList(PSNodeList pList);
static VOID vByteToWEP232(PBYTE abyKey, char *abyStr);
static VOID vAddrToStr(PBYTE abyAddr, PBYTE abyStr);
static VOID vWEPToStr(PBYTE abyWEP, PBYTE abyStr);
static VOID vCmdUsage(void);
/*--------------------- Export Variables --------------------------*/
/*--------------------- Export Functions --------------------------*/
/*+
*
* Description:
* Entry of utility
*
* Parameters:
* In:
* argc, argv
* Out:
* none
*
* Return Value: int
*
-*/
int main(int argc, char *argv[]) {
int skfd;
int result = 0;
SCmdRequest sReq;
strcpy((char*)AppName, APPNAME);
if (argc <= 2) {
vCmdUsage();
result = 1;
return result;
};
// get a socket
skfd = socket(AF_INET, SOCK_STREAM, 0);
if (skfd < 0) {
printf("%s: can't find the socket driver!\n", AppName);
result = 1;
return result;
};
strcpy((char *)sReq.name, argv[1]);
sReq.wResult = 0;
sReq.data = NULL;
sReq.wCmdCode = 0;
result = ioctl(skfd, IOCTL_CMD_TEST, &sReq);
if ((result < 0) || (sReq.wResult != MAGIC_CODE)) {
printf("%s: failed in testing interface, '%s'may be not running.",
AppName, argv[1]);
result = 1;
return result;
}
if (strcasecmp(argv[2], PRIVACY) == 0) {
result = s_cmdSetWEP(skfd, argc, argv);
}
else if (strcasecmp(argv[2], SCAN) == 0) {
result = s_cmdScan(skfd, argc, argv);
}
else if (strcasecmp(argv[2], JOIN) == 0) {
result = s_cmdBSSJoin(skfd, argc, argv);
}
else if ( strcasecmp(argv[2], GETLIST) == 0) {
result = s_cmdGetList(skfd, argc, argv);
}
else if ( strcasecmp(argv[2], GETLINK) == 0) {
result = s_cmdGetLink(skfd, argc, argv);
}
else if ( strcasecmp(argv[2], GETMIB) == 0) {
result = s_cmdGetMIB(skfd, argc, argv);
}
/*
else if ( strcasecmp(argv[2], GETSTAT) == 0) {
result = s_cmdGetSTAT(skfd, argc, argv);
}
*/
else if (strcasecmp(argv[2], STOP) == 0) {
result = s_cmdStopMAC(skfd, argc, argv);
}
else if (strcasecmp(argv[2], START) == 0) {
result = s_cmdStartMAC(skfd, argc, argv);
}
else if (strcasecmp(argv[2], APSTART) == 0) {
result = s_cmdAPStart(skfd, argc, argv);
}
else if (strcasecmp(argv[2], GETNODE) == 0) {
result = s_cmdGetNodeList(skfd, argc, argv);
}
else {
printf("%s: %s is an invalid command\n",AppName, argv[2]);
vCmdUsage();
result = 1;
}
if (result < 0) {
printf("%s: failed in ioctl sRequest! result= %d\n",
AppName, result);
}
return result;
}
/*+
*
* Description:
* Reformat input string to wep key
*
* Parameters:
* In:
* array of string
* Out:
* array of hex char
*
* Return Value: none
*
-*/
VOID vByteToWEP232(PBYTE abyKey, char *abyStr) {
PBYTE pChr;
int ii;
UINT val;
// i = 29 byte/232 bit
for (ii = 0; ii < 29; ii++) {
pChr = (PBYTE)strchr(abyStr, ':');
if (pChr == NULL) {
break;
}
else {
*pChr = '\0';
sscanf((char *)abyStr, "%x", &val);
abyKey[ii] = (BYTE)val;
abyStr = (char *)(pChr+1);
}
}
sscanf((char *)abyStr, "%x", &val);
abyKey[ii] = (BYTE)val;
}
/*+
*
* Description:
* Print MAC address
*
* Parameters:
* In:
* MAC address
* Out:
* none
*
* Return Value: none
*
-*/
VOID vAddrToStr(PBYTE abyAddr, PBYTE abyStr)
{
sprintf((char *)abyStr, "%02x:%02x:%02x:%02x:%02x:%02x",
abyAddr[0], abyAddr[1], abyAddr[2], abyAddr[3], abyAddr[4], abyAddr[5]);
}
/*+
*
* Description:
* Print WEP key
*
* Parameters:
* In:
* array of hex wep key
* Out:
* array of wep key string
*
* Return Value: none
*
-*/
VOID vWEPToStr(PBYTE abyWEP, PBYTE abyStr)
{
sprintf((char *)abyStr, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
abyWEP[0], abyWEP[1], abyWEP[2], abyWEP[3], abyWEP[4], abyWEP[5],
abyWEP[6], abyWEP[7], abyWEP[8], abyWEP[9], abyWEP[10], abyWEP[11],
abyWEP[12]
);
}
/*+
*
* Description:
*
* Called when the user set the 'scan' command at the
* command line to scan all available channels.
*
*
* Parameters:
* In:
* skfd, argc, argv
* Out:
* none
*
* Return Value: '0' if success
*
-*/
int s_cmdScan(int skfd, int argc, char **argv) {
int result = 0;
SCmdRequest sReq;
SCmdScan cmd;
strcpy((char *)sReq.name, argv[1]);
cmd.ssid[0] = SSID_ID;
cmd.ssid[1] = 0;
cmd.ssid[2] = 0;
if (argc > 3) {
if ((cmd.ssid[1] = strlen(argv[3])) <= 32 ) {
if (strcmp(argv[3], "any") != 0 ) {
memcpy( &(cmd.ssid[2]), argv[3], cmd.ssid[1]);
}
}
}
sReq.wResult = 0;
sReq.data = &cmd;
sReq.wCmdCode = WLAN_CMD_BSS_SCAN;
result = ioctl(skfd, IOCTL_CMD_SET, &sReq);
if (sReq.wResult) {
printf( "%s: fail in scan command !\n",AppName);
result = 1;
}
return result;
}
/*+
*
* Description:
*
* Called when the user set the 'stop' command at the
* command line to stop the MAC
*
* Parameters:
* In:
* skfd, argc, argv
* Out:
* none
*
* Return Value: '0' if success
*
-*/
int s_cmdStopMAC( int skfd, int argc, char **argv ) {
int result = 0;
SCmdRequest sReq;
strcpy((char *)sReq.name, argv[1]);
sReq.wResult = 0;
sReq.data = NULL;
sReq.wCmdCode = WLAN_CMD_STOP_MAC;
result = ioctl(skfd, IOCTL_CMD_SET, &sReq);
if ( sReq.wResult ) {
printf( "%s: fail in stop command !\n",AppName);
result = 1;
}
return result;
}
/*+
*
* Description:
*
* Called when the user set the 'start' command at the
* command line to enable the MAC
*
* Parameters:
* In:
* skfd, argc, argv
* Out:
* none
*
* Return Value: '0' if success
*
-*/
int s_cmdStartMAC( int skfd, int argc, char **argv ) {
int result = 0;
SCmdRequest sReq;
strcpy((char *)sReq.name, argv[1]);
sReq.wResult = 0;
sReq.data = NULL;
sReq.wCmdCode = WLAN_CMD_START_MAC;
result = ioctl(skfd, IOCTL_CMD_SET, &sReq);
if ( sReq.wResult ) {
printf( "%s: fail in start command !\n",AppName);
result = 1;
}
return result;
}
/*+
*
* Description:
*
* Called when the user set 'join' command at the
* command line to join an existing BSS set
*
* Parameters:
* In:
* skfd, argc, argv
* Out:
* none
*
* Return Value: '0' if success
*
-*/
int s_cmdBSSJoin(int skfd, int argc, char **argv) {
int result = 0;
SCmdRequest sReq;
SCmdBSSJoin cmd;
if ( argc < 5 ) {
printf("%s: not enough arguments for the 'join' command;\n ", AppName);
vCmdUsage();
result = 1;
}
else {
strcpy((char *)sReq.name, argv[1]);
sReq.wResult = 0;
sReq.data = &cmd;
sReq.wCmdCode = WLAN_CMD_BSS_JOIN;
if ( (strcmp(argv[3], "adhoc") == 0) ||
(strcmp(argv[3], "ad-hoc") == 0) ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -