aboutsummaryrefslogtreecommitdiffstats
path: root/wlantest
diff options
context:
space:
mode:
Diffstat (limited to 'wlantest')
-rw-r--r--wlantest/process.c5
-rw-r--r--wlantest/rx_ip.c40
-rw-r--r--wlantest/wired.c29
-rw-r--r--wlantest/wlantest.c9
-rw-r--r--wlantest/wlantest.h3
-rw-r--r--wlantest/writepcap.c12
6 files changed, 55 insertions, 43 deletions
diff --git a/wlantest/process.c b/wlantest/process.c
index c496e0d..4d174ba 100644
--- a/wlantest/process.c
+++ b/wlantest/process.c
@@ -1,6 +1,6 @@
/*
* Received frame processing
- * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
@@ -278,6 +278,9 @@ void wlantest_process(struct wlantest *wt, const u8 *data, size_t len)
const u8 *frame, *fcspos;
size_t frame_len;
+ if (wt->ethernet)
+ return;
+
wpa_hexdump(MSG_EXCESSIVE, "Process data", data, len);
if (ieee80211_radiotap_iterator_init(&iter, (void *) data, len, NULL)) {
diff --git a/wlantest/rx_ip.c b/wlantest/rx_ip.c
index 19b338b..0e833ec 100644
--- a/wlantest/rx_ip.c
+++ b/wlantest/rx_ip.c
@@ -116,62 +116,62 @@ void rx_data_ip(struct wlantest *wt, const u8 *bssid, const u8 *sta_addr,
const u8 *dst, const u8 *src, const u8 *data, size_t len,
const u8 *peer_addr)
{
- const struct iphdr *ip;
+ const struct ip *ip;
const u8 *payload;
size_t plen;
- u16 frag_off, tot_len;
+ uint16_t frag_off, ip_len;
- ip = (const struct iphdr *) data;
+ ip = (const struct ip *) data;
if (len < sizeof(*ip))
return;
- if (ip->version != 4) {
+ if (ip->ip_v != 4) {
if (hwsim_test_packet(data, len)) {
add_note(wt, MSG_INFO, "hwsim_test package");
return;
}
add_note(wt, MSG_DEBUG, "Unexpected IP protocol version %u in "
"IPv4 packet (bssid=" MACSTR " str=" MACSTR
- " dst=" MACSTR ")", ip->version, MAC2STR(bssid),
+ " dst=" MACSTR ")", ip->ip_v, MAC2STR(bssid),
MAC2STR(src), MAC2STR(dst));
return;
}
- if (ip->ihl * 4 < sizeof(*ip)) {
+ if (ip->ip_hl * 4 < sizeof(*ip)) {
add_note(wt, MSG_DEBUG, "Unexpected IP header length %u in "
"IPv4 packet (bssid=" MACSTR " str=" MACSTR
- " dst=" MACSTR ")", ip->ihl, MAC2STR(bssid),
+ " dst=" MACSTR ")", ip->ip_hl, MAC2STR(bssid),
MAC2STR(src), MAC2STR(dst));
return;
}
- if (ip->ihl * 4 > len) {
+ if (ip->ip_hl * 4 > len) {
add_note(wt, MSG_DEBUG, "Truncated IP header (ihl=%u len=%u) "
"in IPv4 packet (bssid=" MACSTR " str=" MACSTR
- " dst=" MACSTR ")", ip->ihl, (unsigned) len,
+ " dst=" MACSTR ")", ip->ip_hl, (unsigned) len,
MAC2STR(bssid), MAC2STR(src), MAC2STR(dst));
return;
}
- /* TODO: check header checksum in ip->check */
+ /* TODO: check header checksum in ip->ip_sum */
- frag_off = be_to_host16(ip->frag_off);
+ frag_off = be_to_host16(ip->ip_off);
if (frag_off & 0x1fff) {
wpa_printf(MSG_EXCESSIVE, "IP fragment reassembly not yet "
"supported");
return;
}
- tot_len = be_to_host16(ip->tot_len);
- if (tot_len > len)
+ ip_len = be_to_host16(ip->ip_len);
+ if (ip_len > len)
return;
- if (tot_len < len)
- len = tot_len;
+ if (ip_len < len)
+ len = ip_len;
- payload = data + 4 * ip->ihl;
- plen = len - 4 * ip->ihl;
+ payload = data + 4 * ip->ip_hl;
+ plen = len - 4 * ip->ip_hl;
- switch (ip->protocol) {
+ switch (ip->ip_p) {
case IPPROTO_ICMP:
- rx_data_icmp(wt, bssid, sta_addr, ip->daddr, ip->saddr,
- payload, plen, peer_addr);
+ rx_data_icmp(wt, bssid, sta_addr, ip->ip_dst.s_addr,
+ ip->ip_src.s_addr, payload, plen, peer_addr);
break;
}
}
diff --git a/wlantest/wired.c b/wlantest/wired.c
index 9267f97..653be33 100644
--- a/wlantest/wired.c
+++ b/wlantest/wired.c
@@ -231,43 +231,44 @@ static void process_udp(struct wlantest *wt, u32 dst, u32 src,
static void process_ipv4(struct wlantest *wt, const u8 *data, size_t len)
{
- const struct iphdr *ip;
+ const struct ip *ip;
const u8 *payload;
size_t plen;
- u16 frag_off, tot_len;
+ uint16_t frag_off, ip_len;
if (len < sizeof(*ip))
return;
- ip = (const struct iphdr *) data;
- if (ip->version != 4)
+ ip = (const struct ip *) data;
+ if (ip->ip_v != 4)
return;
- if (ip->ihl < 5)
+ if (ip->ip_hl < 5)
return;
/* TODO: check header checksum in ip->check */
- frag_off = be_to_host16(ip->frag_off);
+ frag_off = be_to_host16(ip->ip_off);
if (frag_off & 0x1fff) {
wpa_printf(MSG_EXCESSIVE, "IP fragment reassembly not yet "
"supported");
return;
}
- tot_len = be_to_host16(ip->tot_len);
- if (tot_len > len)
+ ip_len = be_to_host16(ip->ip_len);
+ if (ip_len > len)
return;
- if (tot_len < len)
- len = tot_len;
+ if (ip_len < len)
+ len = ip_len;
- payload = data + 4 * ip->ihl;
- plen = len - 4 * ip->ihl;
+ payload = data + 4 * ip->ip_hl;
+ plen = len - 4 * ip->ip_hl;
if (payload + plen > data + len)
return;
- switch (ip->protocol) {
+ switch (ip->ip_p) {
case IPPROTO_UDP:
- process_udp(wt, ip->daddr, ip->saddr, payload, plen);
+ process_udp(wt, ip->ip_dst.s_addr, ip->ip_src.s_addr,
+ payload, plen);
break;
}
}
diff --git a/wlantest/wlantest.c b/wlantest/wlantest.c
index e46850a..1b8d714 100644
--- a/wlantest/wlantest.c
+++ b/wlantest/wlantest.c
@@ -1,6 +1,6 @@
/*
* wlantest - IEEE 802.11 protocol monitoring and testing tool
- * Copyright (c) 2010-2015, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
@@ -21,7 +21,7 @@ static void wlantest_terminate(int sig, void *signal_ctx)
static void usage(void)
{
- printf("wlantest [-cddhqqFNt] [-i<ifname>] [-r<pcap file>] "
+ printf("wlantest [-cddehqqFNt] [-i<ifname>] [-r<pcap file>] "
"[-p<passphrase>]\n"
" [-I<wired ifname>] [-R<wired pcap file>] "
"[-P<RADIUS shared secret>]\n"
@@ -367,7 +367,7 @@ int main(int argc, char *argv[])
wlantest_init(&wt);
for (;;) {
- c = getopt(argc, argv, "cdf:Fhi:I:L:n:Np:P:qr:R:tT:w:W:");
+ c = getopt(argc, argv, "cdef:Fhi:I:L:n:Np:P:qr:R:tT:w:W:");
if (c < 0)
break;
switch (c) {
@@ -378,6 +378,9 @@ int main(int argc, char *argv[])
if (wpa_debug_level > 0)
wpa_debug_level--;
break;
+ case 'e':
+ wt.ethernet = 1;
+ break;
case 'f':
if (add_pmk_file(&wt, optarg) < 0)
return -1;
diff --git a/wlantest/wlantest.h b/wlantest/wlantest.h
index 9324aa9..4f90b20 100644
--- a/wlantest/wlantest.h
+++ b/wlantest/wlantest.h
@@ -1,6 +1,6 @@
/*
* wlantest - IEEE 802.11 protocol monitoring and testing tool
- * Copyright (c) 2010-2013, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
@@ -208,6 +208,7 @@ struct wlantest {
unsigned int assume_fcs:1;
unsigned int pcap_no_buffer:1;
+ unsigned int ethernet:1;
char *notes[MAX_NOTES];
size_t num_notes;
diff --git a/wlantest/writepcap.c b/wlantest/writepcap.c
index abd889f..fee2c40 100644
--- a/wlantest/writepcap.c
+++ b/wlantest/writepcap.c
@@ -1,6 +1,6 @@
/*
* PCAP capture file writer
- * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2010-2019, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
@@ -17,7 +17,9 @@
int write_pcap_init(struct wlantest *wt, const char *fname)
{
- wt->write_pcap = pcap_open_dead(DLT_IEEE802_11_RADIO, 4000);
+ int linktype = wt->ethernet ? DLT_EN10MB : DLT_IEEE802_11_RADIO;
+
+ wt->write_pcap = pcap_open_dead(linktype, 4000);
if (wt->write_pcap == NULL)
return -1;
wt->write_pcap_dumper = pcap_dump_open(wt->write_pcap, fname);
@@ -182,7 +184,7 @@ int write_pcapng_init(struct wlantest *wt, const char *fname)
desc.block_type = PCAPNG_BLOCK_IFACE_DESC;
desc.block_total_len = sizeof(desc);
desc.block_total_len2 = desc.block_total_len;
- desc.link_type = LINKTYPE_IEEE802_11_RADIO;
+ desc.link_type = wt->ethernet ? DLT_EN10MB : LINKTYPE_IEEE802_11_RADIO;
desc.snap_len = 65535;
fwrite(&desc, sizeof(desc), 1, wt->pcapng);
if (wt->pcap_no_buffer)
@@ -317,6 +319,7 @@ void write_pcapng_write_read(struct wlantest *wt, int dlt,
pos = (u8 *) (pkt + 1);
switch (dlt) {
+ case DLT_EN10MB:
case DLT_IEEE802_11_RADIO:
break;
case DLT_PRISM_HEADER:
@@ -365,5 +368,6 @@ void write_pcapng_captured(struct wlantest *wt, const u8 *buf, size_t len)
gettimeofday(&h.ts, NULL);
h.caplen = len;
h.len = len;
- write_pcapng_write_read(wt, DLT_IEEE802_11_RADIO, &h, buf);
+ write_pcapng_write_read(wt, wt->ethernet ? DLT_EN10MB :
+ DLT_IEEE802_11_RADIO, &h, buf);
}