#include <net/if.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <stdbool.h>
#include <netlink/genl/genl.h>
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
#include <netlink/msg.h>
#include <netlink/attr.h>
#include "nl80211.h"
#include "iw.h"
#define WLAN_CAPABILITY_ESS (1<<0)
#define WLAN_CAPABILITY_IBSS (1<<1)
#define WLAN_CAPABILITY_CF_POLLABLE (1<<2)
#define WLAN_CAPABILITY_CF_POLL_REQUEST (1<<3)
#define WLAN_CAPABILITY_PRIVACY (1<<4)
#define WLAN_CAPABILITY_SHORT_PREAMBLE (1<<5)
#define WLAN_CAPABILITY_PBCC (1<<6)
#define WLAN_CAPABILITY_CHANNEL_AGILITY (1<<7)
#define WLAN_CAPABILITY_SPECTRUM_MGMT (1<<8)
#define WLAN_CAPABILITY_QOS (1<<9)
#define WLAN_CAPABILITY_SHORT_SLOT_TIME (1<<10)
#define WLAN_CAPABILITY_APSD (1<<11)
#define WLAN_CAPABILITY_DSSS_OFDM (1<<13)
static unsigned char wifi_oui[3] = { 0x00, 0x50, 0xf2 };
static unsigned char ieee80211_oui[3] = { 0x00, 0x0f, 0xac };
struct scan_params {
bool unknown;
enum print_ie_type type;
bool show_both_ie_sets;
};
#define IEEE80211_COUNTRY_EXTENSION_ID 201
union ieee80211_country_ie_triplet {
struct {
__u8 first_channel;
__u8 num_channels;
__s8 max_power;
} __attribute__ ((packed)) chans;
struct {
__u8 reg_extension_id;
__u8 reg_class;
__u8 coverage_class;
} __attribute__ ((packed)) ext;
} __attribute__ ((packed));
static int handle_scan(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv)
{
struct nl_msg *ssids = NULL, *freqs = NULL;
char *eptr;
int err = -ENOBUFS;
int i;
enum {
NONE,
FREQ,
IES,
SSID,
DONE,
} parse = NONE;
int freq;
bool passive = false, have_ssids = false, have_freqs = false;
size_t tmp;
unsigned char *ies;
ssids = nlmsg_alloc();
if (!ssids)
return -ENOMEM;
freqs = nlmsg_alloc();
if (!freqs) {
nlmsg_free(ssids);
return -ENOMEM;
}
for (i = 0; i < argc; i++) {
switch (parse) {
case NONE:
if (strcmp(argv[i], "freq") == 0) {
parse = FREQ;
have_freqs = true;
break;
} else if (strcmp(argv[i], "ies") == 0) {
parse = IES;
break;
} else if (strcmp(argv[i], "ssid") == 0) {
parse = SSID;
have_ssids = true;
break;
} else if (strcmp(argv[i], "passive") == 0) {
parse = DONE;
passive = true;
break;
}
case DONE:
return 1;
case FREQ:
freq = strtoul(argv[i], &eptr, 10);
if (eptr != argv[i] + strlen(argv[i]))
return 1;
NLA_PUT_U32(freqs, i, freq);
parse = NONE;
break;
case IES:
ies = parse_hex(argv[i], &tmp);
if (!ies)
goto nla_put_failure;
NLA_PUT(msg, NL80211_ATTR_IE, tmp, ies);
free(ies);
parse = NONE;
break;
case SSID:
NLA_PUT(ssids, i, strlen(argv[i]), argv[i]);
break;
}
}
if (!have_ssids)
NLA_PUT(ssids, 1, 0, "");
if (!passive)
nla_put_nested(msg, NL80211_ATTR_SCAN_SSIDS, ssids);
if (have_freqs)
nla_put_nested(msg, NL80211_ATTR_SCAN_FREQUENCIES, freqs);
err = 0;
nla_put_failure:
nlmsg_free(ssids);
nlmsg_free(freqs);
return err;
}
static void tab_on_first(bool *first)
{
if (!*first)
printf("\t");
else
*first = false;
}
static void print_ssid(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" ");
print_ssid_escaped(len, data);
printf("\n");
}
static void print_supprates(const uint8_t type, uint8_t len, const uint8_t *data)
{
int i;
printf(" ");
for (i = 0; i < len; i++) {
int r = data[i] & 0x7f;
printf("%d.%d%s ", r/2, 5*(r&1), data[i] & 0x80 ? "*":"");
}
printf("\n");
}
static void print_ds(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" channel %d\n", data[0]);
}
static const char *country_env_str(char environment)
{
switch (environment) {
case 'I':
return "Indoor only";
case 'O':
return "Outdoor only";
case ' ':
return "Indoor/Outdoor";
default:
return "bogus";
}
}
static void print_country(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" %.*s", 2, data);
printf("\tEnvironment: %s\n", country_env_str(data[2]));
data += 3;
len -= 3;
if (len < 3) {
printf("\t\tNo country IE triplets present\n");
return;
}
while (len >= 3) {
int end_channel;
union ieee80211_country_ie_triplet *triplet = (void *) data;
if (triplet->ext.reg_extension_id >= IEEE80211_COUNTRY_EXTENSION_ID) {
printf("\t\tExtension ID: %d Regulatory Class: %d Coverage class: %d (up to %dm)\n",
triplet->ext.reg_extension_id,
triplet->ext.reg_class,
triplet->ext.coverage_class,
triplet->ext.coverage_class * 450);
data += 3;
len -= 3;
continue;
}
/* 2 GHz */
if (triplet->chans.first_channel <= 14)
end_channel = triplet->chans.first_channel + (triplet->chans.num_channels - 1);
else
end_channel = triplet->chans.first_channel + (4 * (triplet->chans.num_channels - 1));
printf("\t\tChannels [%d - %d]\n", triplet->chans.first_channel, end_channel);
data += 3;
len -= 3;
}
return;
}
static void print_powerconstraint(const uint8_t type, uint8_t len, const uint8_t *data)
{
printf(" %d dB\n", data[0]);
}
static void print_erp(const uint8_t type, uint8_t len, const uint8_t *data)
{
if (data[0] == 0x00)
printf(" <no flags>");
if (data[0] & 0x01)
printf(" NonERP_Present");
if (data[0] & 0x02)
printf(" Use_Protection");
if (data[0] & 0x04)
printf(" Barker_Preamble_Mode");
printf("\n");
}
static void print_cipher(const uint8_t *data)
{
if (memcmp(data, wifi_oui, 3) == 0) {
switch (data[3]) {
case 0:
printf("Use group cipher suite");
break;
case 1:
printf("WEP-40");
break;
case 2:
printf("TKIP");
break;
case 4:
printf("CCMP");
break;
case 5:
printf("WEP-104");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else if (memcmp(data, ieee80211_oui, 3) == 0) {
switch (data[3]) {
case 0:
printf("Use group cipher suite");
break;
case 1:
printf("WEP-40");
break;
case 2:
printf("TKIP");
break;
case 4:
printf("CCMP");
break;
case 5:
printf("WEP-104");
break;
case 6:
printf("AES-128-CMAC");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
}
static void print_auth(const uint8_t *data)
{
if (memcmp(data, wifi_oui, 3) == 0) {
switch (data[3]) {
case 1:
printf("IEEE 802.1X");
break;
case 2:
printf("PSK");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else if (memcmp(data, ieee80211_oui, 3) == 0) {
switch (data[3]) {
case 1:
printf("IEEE 802.1X");
break;
case 2:
printf("PSK");
break;
case 3:
printf("FT/IEEE 802.1X");
break;
case 4:
printf("FT/PSK");
break;
case 5:
printf("IEEE 802.1X/SHA-256");
break;
case 6:
printf("PSK/SHA-256");
break;
default:
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
break;
}
} else
printf("%.02x-%.02x-%.02x:%d",
data[0], data[1] ,data[2], data[3]);
}
static void print_rsn_ie(const char *defcipher, const char *defauth,
uint8_t len, const uint8_t *data)
{
bool first = true;
__u16 version, count, capa;
int i;
version = data[0] + (data[1] << 8);
tab_on_first(&first);
printf("\t * Version: %d\n", version);
data += 2;
len -= 2;
if (len < 4) {
tab_on_first(&first);
printf("\t * Group cipher: %s\n", defcipher);
printf("\t * Pairwise ciphers: %s\n", defcipher);
return;
}
tab_on_first(&first);
printf("\t * Group cipher: ");
print_cipher(data);
printf("\n");
data += 4;
len -= 4;
if (len < 2) {
tab_on_first(&first);
printf("\t * Pairwise ciphers: %s\n", defcipher);
return;
}
count = data[0] | (data[1] << 8);
if (2 + (count * 4) > len)
goto invalid;
tab_on_first(&first);
printf("\t * Pairwise ciphers:");
for (i = 0; i < count
没有合适的资源?快使用搜索试试~ 我知道了~
iw.tar.gz_cfg80211_iw 源码
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 82 浏览量
2022-09-22
21:24:15
上传
评论
收藏 317KB GZ 举报
温馨提示
共65个文件
c:24个
o:24个
vpwhist:2个
iw.tar.gz 基于nl80211/cfg80211 无线局域网工具源码
资源详情
资源评论
资源推荐
收起资源包目录
iw.tar.gz (65个子文件)
iw
station.c 8KB
asfasd.vpj 2KB
sss.vpj 2KB
ps.o 3KB
version.c 52B
scan.o 30KB
mesh.c 7KB
genl.c 2KB
iw.o 10KB
sss.vpw 199B
phy.c 7KB
mesh.o 7KB
status.c 4KB
nl80211.h 69KB
offch.o 2KB
link.o 6KB
iw.c 10KB
util.o 12KB
sss.vtg 192KB
connect.c 3KB
status.o 5KB
event.o 12KB
iw 358KB
mpath.c 5KB
sections.c 45B
asfasd.vtg 192KB
ibss.c 3KB
README 464B
bitrate.o 3KB
util.c 12KB
offch.c 868B
survey.o 3KB
station.o 8KB
version.sh 482B
reg.c 5KB
bitrate.c 3KB
.gitignore 44B
genl.o 3KB
iw.8 1024B
ibss.o 4KB
mpath.o 5KB
cqm.o 2KB
link.c 7KB
cqm.c 1KB
info.c 7KB
sections.o 1KB
Makefile 2KB
version.o 874B
interface.o 9KB
ps.c 2KB
connect.o 3KB
reason.o 4KB
reg.o 5KB
asfasd.vpw 202B
iw.h 4KB
interface.c 9KB
scan.c 28KB
event.c 13KB
reason.c 3KB
phy.o 7KB
survey.c 2KB
COPYING 849B
sss.vpwhist 110B
asfasd.vpwhist 5KB
info.o 7KB
共 65 条
- 1
寒泊
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0