📄 wlan_config.c
字号:
if (argc == 6) {
buf[1] = atoval(argv[3]); //func
tmp = atoval(argv[4]); //reg
buf[2] = tmp & 0xff;
buf[3] = (tmp >> 8) & 0xff;
buf[4] = (tmp >> 16) & 0xff;
buf[5] = (tmp >> 24) & 0xff;
buf[6] = atoval(argv[5]); //dat
} else {
fprintf(stderr, "Invalid number of parameters!\n");
return -1;
}
strncpy(userdata.ifr_name, DevName, IFNAMSIZ);
userdata.ifr_data = buf;
if (ioctl(sockfd, WLANCMD52RDWR, &userdata)) {
perror("wlanconfig");
fprintf(stderr,
"wlanconfig: CMD52 R/W not supported by "
"interface %s\n", DevName);
return -1;
}
printf("sdcmd52w returns 0x%02X\n",buf[0]);
return 0;
}
int process_sdcmd53r(void)
{
struct ifreq userdata;
char buf[CMD53BUFLEN];
int i;
strncpy(userdata.ifr_name, DevName, IFNAMSIZ);
userdata.ifr_data = buf;
for(i=0; i < sizeof(buf); i++)
buf[i] = i & 0xff;
if (ioctl(sockfd, WLANCMD53RDWR, &userdata)) {
perror("wlanconfig");
fprintf(stderr,
"wlanconfig: CMD53 R/W not supported by "
"interface %s\n", DevName);
return -1;
}
for(i=0; i < sizeof(buf); i++) {
if (buf[i] != (i ^ 0xff))
printf("i=%02X %02X\n",i,buf[i]);
}
return 0;
}
void display_calibration(wlan_ioctl_cal_data *cal_data, int type)
{
printf("Calibration %s calling the cal_data command:\n",
type ? "after" : "before");
printf("------------------------------------------------\n");
printf("Action : %x\n", cal_data->Action);
printf("PAOption : %x\n", cal_data->PAOption);
printf("ExtPA : %x\n", cal_data->ExtPA);
printf("Ant : %x\n", cal_data->Ant);
hexdump("IntPA ", &cal_data->IntPA, 28, ' ');
hexdump("PAConfig ", &cal_data->PAConfig, 4, ' ');
printf("Domain : %02x %02x\n", cal_data->Domain & 0x00ff,
(cal_data->Domain & 0xff00) >> 8);
printf("ECO : %x\n", cal_data->ECO);
printf("LCT_cal : %x\n", cal_data->LCT_cal);
hexdump("MAC Addr ", &cal_data->MacAddr, 6, ' ');
printf("\n");
}
#ifdef WMM
int process_wmm_ack_policy(int argc, char *argv[])
{
unsigned char buf[(WMM_ACK_POLICY_PRIO * 2) + 3];
int count, i;
struct ifreq userdata;
if ((argc != 3) && (argc != 5)) {
printf("Error: invalid no of arguments\n");
printf("Syntax: ./wlanconfig eth1 wmm_ack_policy\n");
printf("Syntax: ./wlanconfig eth1 wmm_ack_policy <AC> <POLICY>\n");
exit(1);
}
memset(buf, 0, (WMM_ACK_POLICY_PRIO * 2) + 3);
buf[0] = WMM_ACK_POLICY;
if (argc == 5) {
buf[1] = HostCmd_ACT_SET;
buf[2] = 0;
buf[3] = atoi(argv[3]);
if (buf[3] > WMM_ACK_POLICY_PRIO - 1) {
printf("Invalid Priority. Should be between 0 and %d\n",
WMM_ACK_POLICY_PRIO - 1);
exit(1);
}
buf[4] = atoi(argv[4]);
if(buf[4] > 1) {
printf("Invalid Ack Policy. Should be 1 or 0\n");
exit(1);
}
count = 5;
} else {
count = 2;
buf[1] = HostCmd_ACT_GET;
}
strncpy(userdata.ifr_name, DevName, IFNAMSIZ);
userdata.ifr_data = buf;
// hexdump(argv[2], buf, count, ' ');
if (ioctl(sockfd, WLAN_SETCONF_GETCONF, &userdata)) {
fprintf(stderr, "wlanconfig: %s not supported by %s\n",
argv[2], DevName);
return -1;
}
if (buf[1] == HostCmd_ACT_GET) {
printf("AC Value Priority\n");
for (i=0; i < WMM_ACK_POLICY_PRIO; ++i) {
count = SKIP_TYPE_ACTION + (i*2);
printf("%4x %5x\n", buf[count], buf[count+1]);
}
}
return 0;
}
int process_wmm_para_conf(int argc, char *argv[], int cmd)
{
int count;
FILE *fp;
char buf[256];
char filename[48] = "";
struct ifreq userdata;
if (argc != 4) {
printf("Error: invalid no of arguments\n");
printf("Syntax: ./wlanconfig eth1 %s <filename>\n",argv[2]);
exit(1);
}
strncpy(filename, argv[3], MIN(sizeof(filename)-1, strlen(argv[3])));
if ((fp = fopen(filename, "r")) == NULL) {
fprintf(stderr, "Cannot open file %s\n", argv[3]);
exit(1);
}
count = fparse_for_cmd_and_hex(fp, buf + SKIP_TYPE, argv[2]);
if(count < 0) {
printf("Invalid command parsing failed !!!\n");
return -EINVAL;
}
/* This will set the type of command sent */
buf[0] = (cmd - CMD_WMM_TSPEC) + WMM_TSPEC;
hexdump(argv[2], buf, count + SKIP_TYPE, ' ');
strncpy(userdata.ifr_name, DevName, IFNAMSIZ);
userdata.ifr_data = buf;
if (ioctl(sockfd, WLAN_SETCONF_GETCONF, &userdata)) {
fprintf(stderr, "wlanconfig: %s not supported by %s\n",
argv[2], DevName);
return -1;
}
hexdump(argv[2], buf, count + SKIP_TYPE, ' ');
return 0;
}
#endif /* WMM */
static int hex2num(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
return -1;
}
static int hex2byte(const char *hex)
{
int a, b;
a = hex2num(*hex++);
if (a < 0)
return -1;
b = hex2num(*hex++);
if (b < 0)
return -1;
return (a << 4) | b;
}
int hexstr2bin(const char *hex, u8 *buf, size_t len)
{
int i, a;
const char *ipos = hex;
char *opos = buf;
for (i = 0; i < len; i++) {
a = hex2byte(ipos);
if (a < 0)
return -1;
*opos++ = a;
ipos += 2;
}
return 0;
}
unsigned int a2hex_or_atoi(char *value)
{
if (value[0] == '0' && (value[1] == 'X' || value[1] == 'x'))
return a2hex(value + 2);
else
return atoi(value);
}
static char * wlan_config_get_line(char *s, int size, FILE *stream, int *line)
{
char *pos, *end, *sstart;
while (fgets(s, size, stream)) {
(*line)++;
s[size - 1] = '\0';
pos = s;
while (*pos == ' ' || *pos == '\t')
pos++;
if (*pos == '#' || (*pos == '\r' && *(pos+1) == '\n') ||
*pos == '\n' || *pos == '\0')
continue;
/* Remove # comments unless they are within a double quoted
* string. Remove trailing white space. */
sstart = strchr(pos, '"');
if (sstart)
sstart = strchr(sstart + 1, '"');
if (!sstart)
sstart = pos;
end = strchr(sstart, '#');
if (end)
*end-- = '\0';
else
end = pos + strlen(pos) - 1;
while (end > pos && (*end == '\r' || *end == '\n' ||
*end == ' ' || *end == '\t')) {
*end-- = '\0';
}
if (*pos == '\0')
continue;
return pos;
}
return NULL;
}
#ifdef BG_SCAN
static int wlan_config_parse_string(const char *value, char *str, size_t *len)
{
if (*value == '"') {
char *pos;
value++;
pos = strchr(value, '"');
if (pos == NULL || pos[1] != '\0') {
value--;
return -1;
}
*pos = '\0';
*len = strlen(value);
strcpy(str, value);
return 0;
} else {
int hlen = strlen(value);
if (hlen % 1)
return -1;
*len = hlen / 2;
if (str == NULL)
return -1;
if (hexstr2bin(value, str, *len)) {
return -1;
}
return 0;
}
}
int bgscan_parse_action(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->Action = (u16)a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_enable(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->Enable = (u8)a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_bsstype(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->BssType = (u8)a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_channelsperscan(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->ChannelsPerScan = (u8)a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_discardwhenfull(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->DiscardWhenFull = (u8)a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_scaninternal(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->ScanInternal = (u16)a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_storecondition(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->StoreCondition = a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_reportconditions(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->ReportConditions = a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_maxscanresults(u8 *CmdBuf, int line, char *value)
{
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config =
(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
bgscan_config->MaxScanResults = (u16)a2hex_or_atoi(value);
return 0;
}
int bgscan_parse_ssid(u8 *CmdBuf, int line, char *value)
{
static int ssidCnt;
MrvlIEtypes_SsIdParamSet_t *SsIdParamSet = NULL;
char *buf;
size_t len = 0;
SsIdParamSet = (MrvlIEtypes_SsIdParamSet_t *)(CmdBuf + ActualPos);
buf = (char *)malloc(strlen(value));
if(wlan_config_parse_string(value, buf, &len)) {
printf("Invalid SSID\n");
free(buf);
return -1;
}
ssidCnt++;
if(!strlen(buf)) {
printf("The %dth SSID is NULL.\n", ssidCnt);
}
SsIdParamSet->Header.Type = cpu_to_le16(TLV_TYPE_SSID); /*0x0000; */
SsIdParamSet->Header.Len = strlen(buf);
TLVSsidSize += SsIdParamSet->Header.Len +
sizeof(MrvlIEtypesHeader_t);
ActualPos += SsIdParamSet->Header.Len +
sizeof(MrvlIEtypesHeader_t);
SsIdParamSet->Header.Len = cpu_to_le16(SsIdParamSet->Header.Len);
memcpy(SsIdParamSet->SsId, buf, strlen(buf));
free(buf);
return 0;
}
int bgscan_parse_probes(u8 *CmdBuf, int line, char *value)
{
MrvlIEtypes_NumProbes_t *Probes = NULL;
#define PROBES_PAYLOAD_SIZE 2
Probes = (MrvlIEtypes_NumProbes_t *)(CmdBuf + ActualPos);
Probes->Header.Type = TLV_TYPE_NUMPROBES;
Probes->Header.Len = PROBES_PAYLOAD_SIZE;
Probes->NumProbes = (u16)a2hex_or_atoi(value);
if (Probes->NumProbes) {
TLVProbeSize += sizeof(MrvlIEtypesHeader_t) +
Probes->Header.Len;
} else {
TLVProbeSize = 0;
}
ActualPos += TLVProbeSize;
return 0;
}
int bgscan_parse_channellist(u8 *CmdBuf, int line, char *value)
{
MrvlIEtypes_ChanListParamSet_t *chan;
char *buf, *grp0, *grp1;
int len, idx;
chan = (MrvlIEtypes_ChanListParamSet_t *)(CmdBuf + ActualPos);
len = strlen(value) + 1;
buf = malloc(len);
if (buf == NULL)
return -1;
memset(buf, 0, len);
strcpy(buf, value);
chan->Header.Type = cpu_to_le16(TLV_TYPE_CHANLIST);
grp1 = buf;
idx = 0;
while ((grp1 != NULL) && (*grp1 != 0))
{
grp0 = strsep(&grp1, "\";");
if ((grp0 != NULL) && (*grp0 != 0))
{
chan->ChanScanParam[idx].RadioType = atoi(strtok(grp0, ","));
chan->ChanScanParam[idx].ChanNumber = atoi(strtok(NULL, ","));
chan->ChanScanParam[idx].ScanType = atoi(strtok(NULL, ","));
chan->ChanScanParam[idx].MinScanTime = atoi(strtok(NULL, ","));
chan->ChanScanParam[idx].MaxScanTime = atoi(strtok(NULL, ","));
idx ++;
}
}
chan->Header.Len = (idx * sizeof(ChanScanParamSet_t));
TLVChanSize += (chan->Header.Len + sizeof(MrvlIEtypesHeader_t));
chan->Header.Len = cpu_to_le16(chan->Header.Len);
ActualPos += TLVChanSize;
free (buf);
return 0;
}
int wlan_get_bgscan_data(FILE *fp, int *line,
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config)
{
int errors = 0, i, end = 0;
char buf[256], *pos, *pos2;
while ((pos = wlan_config_get_line(buf, sizeof(buf), fp, line))) {
if (strcmp(pos, "}") == 0) {
end = 1;
break;
}
pos2 = strchr(pos, '=');
if (pos2 == NULL) {
printf("Line %d: Invalid bgscan line '%s'.",
*line, pos);
errors++;
continue;
}
*pos2++ = '\0';
if (*pos2 == '"') {
if (strchr(pos2 + 1, '"') == NULL) {
printf("Line %d: invalid quotation '%s'.",
*line, pos2);
errors++;
continue;
}
}
for (i = 0; i < NUM_BGSCAN_FIELDS; i++) {
if (strcmp(pos, bgscan_fields[i].name) == 0) {
if (bgscan_fields[i].parser((u8 *)bgscan_config,
*line, pos2)) {
printf("Line %d: failed to parse %s"
"'%s'.", *line, pos, pos2);
errors++;
}
break;
}
}
if (i == NUM_BGSCAN_FIELDS) {
printf("Line %d: unknown bgscan field '%s'.",
*line, pos);
errors++;
}
}
return 0;
}
int process_bg_scan_config(int argc, char *argv[])
{
u8 scanCfg[512], *pos, *buf = NULL;
char filename[48] = "";
FILE *fp;
HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config;
struct ifreq userdata;
int line = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -