aboutsummaryrefslogtreecommitdiffstats
path: root/wlantest/monitor.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2010-11-06 14:20:45 (GMT)
committerJouni Malinen <j@w1.fi>2010-11-07 21:29:00 (GMT)
commita149fcc77d3322bf23d1f53c2cd9fc84a1097c31 (patch)
tree50869affc977d98c872265f0493fa28bb10cb0bb /wlantest/monitor.c
parent6fc58a89e1dc41a315b15c8e067dc50f30dd741e (diff)
downloadhostap-a149fcc77d3322bf23d1f53c2cd9fc84a1097c31.zip
hostap-a149fcc77d3322bf23d1f53c2cd9fc84a1097c31.tar.gz
hostap-a149fcc77d3322bf23d1f53c2cd9fc84a1097c31.tar.bz2
wlantest: Add preliminary version of IEEE 802.11 protocol testing tool
This tool can be used to capture IEEE 802.11 frames either from a monitor interface for realtime capturing or from pcap files for offline analysis. This version is only adding basic infrastructure for going through the frames and parsing their headers.
Diffstat (limited to 'wlantest/monitor.c')
-rw-r--r--wlantest/monitor.c87
1 files changed, 87 insertions, 0 deletions
diff --git a/wlantest/monitor.c b/wlantest/monitor.c
new file mode 100644
index 0000000..d01d8b3
--- /dev/null
+++ b/wlantest/monitor.c
@@ -0,0 +1,87 @@
+/*
+ * Linux packet socket monitor
+ * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * Alternatively, this software may be distributed under the terms of BSD
+ * license.
+ *
+ * See README and COPYING for more details.
+ */
+
+#include "utils/includes.h"
+#include <net/if.h>
+#include <netpacket/packet.h>
+
+#include "utils/common.h"
+#include "utils/eloop.h"
+#include "wlantest.h"
+
+
+static void monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
+{
+ struct wlantest *wt = eloop_ctx;
+ u8 buf[3000];
+ int len;
+
+ len = recv(sock, buf, sizeof(buf), 0);
+ if (len < 0) {
+ wpa_printf(MSG_INFO, "recv(PACKET): %s", strerror(errno));
+ return;
+ }
+
+ wlantest_process(wt, buf, len);
+}
+
+
+int monitor_init(struct wlantest *wt, const char *ifname)
+{
+ struct sockaddr_ll ll;
+
+ os_memset(&ll, 0, sizeof(ll));
+ ll.sll_family = AF_PACKET;
+ ll.sll_ifindex = if_nametoindex(ifname);
+ if (ll.sll_ifindex == 0) {
+ wpa_printf(MSG_ERROR, "Monitor interface '%s' does not exist",
+ ifname);
+ return -1;
+ }
+
+ wt->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+ if (wt->monitor_sock < 0) {
+ wpa_printf(MSG_ERROR, "socket(PF_PACKET,SOCK_RAW): %s",
+ strerror(errno));
+ return -1;
+ }
+
+ if (bind(wt->monitor_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
+ wpa_printf(MSG_ERROR, "bind(PACKET): %s", strerror(errno));
+ close(wt->monitor_sock);
+ wt->monitor_sock = -1;
+ return -1;
+ }
+
+ if (eloop_register_read_sock(wt->monitor_sock, monitor_read, wt, NULL))
+ {
+ wpa_printf(MSG_ERROR, "Could not register monitor read "
+ "socket");
+ close(wt->monitor_sock);
+ wt->monitor_sock = -1;
+ return -1;
+ }
+
+ return 0;
+}
+
+
+void monitor_deinit(struct wlantest *wt)
+{
+ if (wt->monitor_sock >= 0) {
+ eloop_unregister_read_sock(wt->monitor_sock);
+ close(wt->monitor_sock);
+ wt->monitor_sock = -1;
+ }
+}