aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorSam Leffler <sam@FreeBSD.org>2006-03-07 05:54:20 +0000
committerSam Leffler <sam@FreeBSD.org>2006-03-07 05:54:20 +0000
commit99122c96a30276d9143cca3e560f8a270354d3d0 (patch)
tree71109b51f18b2430ee5028f4d31e9c0897b4d55e /usr.sbin
parentf40bc3005ef5b9b0879a1478694f209a43924962 (diff)
downloadsrc-99122c96a30276d9143cca3e560f8a270354d3d0.tar.gz
src-99122c96a30276d9143cca3e560f8a270354d3d0.zip
update for v0.4.8 import of wpa_supplicant and hostapd
MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=156378
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/wpa/hostapd/driver_freebsd.c44
-rw-r--r--usr.sbin/wpa/hostapd_cli/Makefile9
-rw-r--r--usr.sbin/wpa/l2_packet.c76
-rw-r--r--usr.sbin/wpa/wpa_supplicant/Makefile11
-rw-r--r--usr.sbin/wpa/wpa_supplicant/driver_freebsd.c3
5 files changed, 117 insertions, 26 deletions
diff --git a/usr.sbin/wpa/hostapd/driver_freebsd.c b/usr.sbin/wpa/hostapd/driver_freebsd.c
index ec9fdfa948d2..0099c2034d69 100644
--- a/usr.sbin/wpa/hostapd/driver_freebsd.c
+++ b/usr.sbin/wpa/hostapd/driver_freebsd.c
@@ -40,6 +40,8 @@
#include "wpa.h"
#include "radius.h"
#include "ieee802_11.h"
+#include "common.h"
+#include "hostap_common.h"
struct bsd_driver_data {
struct driver_ops ops; /* base class */
@@ -274,7 +276,7 @@ bsd_set_ieee8021x(void *priv, int enabled)
}
if (!conf->wpa && !conf->ieee802_1x) {
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
- HOSTAPD_LEVEL_WARNING, "No 802.1x or WPA enabled!");
+ HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
return -1;
}
if (conf->wpa && bsd_configure_wpa(drv) != 0) {
@@ -285,7 +287,7 @@ bsd_set_ieee8021x(void *priv, int enabled)
if (set80211param(priv, IEEE80211_IOC_AUTHMODE,
(conf->wpa ? IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
- HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1x!");
+ HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!");
return -1;
}
return bsd_set_iface_flags(priv, 1);
@@ -455,6 +457,22 @@ bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
}
static int
+bsd_sta_clear_stats(void *priv, u8 *addr)
+{
+ struct bsd_driver_data *drv = priv;
+ hostapd *hapd = drv->hapd;
+ struct ieee80211req_sta_stats stats;
+
+ HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "%s: addr=%s\n",
+ __func__, ether_sprintf(addr));
+
+ /* zero station statistics */
+ memset(&stats, 0, sizeof(stats));
+ memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
+ return set80211var(drv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats));
+}
+
+static int
bsd_set_opt_ie(void *priv, const u8 *ie, size_t ie_len)
{
/*
@@ -584,7 +602,7 @@ bsd_new_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
if (new_assoc) {
if (conf->wpa)
wpa_sm_event(hapd, sta, WPA_ASSOC);
- hostapd_new_assoc_sta(hapd, sta);
+ hostapd_new_assoc_sta(hapd, sta, !new_assoc);
} else {
if (conf->wpa)
wpa_sm_event(hapd, sta, WPA_REAUTH);
@@ -726,7 +744,7 @@ bsd_send_eapol(void *priv, u8 *addr, u8 *data, size_t data_len, int encrypt)
if (HOSTAPD_DEBUG_COND(HOSTAPD_DEBUG_MSGDUMPS))
hostapd_hexdump("TX EAPOL", bp, len);
- status = l2_packet_send(drv->sock_xmit, bp, len);
+ status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
if (bp != buf)
free(bp);
@@ -734,7 +752,7 @@ bsd_send_eapol(void *priv, u8 *addr, u8 *data, size_t data_len, int encrypt)
}
static void
-handle_read(void *ctx, unsigned char *src_addr, unsigned char *buf, size_t len)
+handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
{
struct bsd_driver_data *drv = ctx;
hostapd *hapd = drv->hapd;
@@ -747,7 +765,8 @@ handle_read(void *ctx, unsigned char *src_addr, unsigned char *buf, size_t len)
/* XXX cannot happen */
return;
}
- ieee802_1x_receive(hapd, src_addr, buf, len);
+ ieee802_1x_receive(hapd, src_addr, buf + sizeof(struct l2_ethhdr),
+ len - sizeof(struct l2_ethhdr));
}
static int
@@ -776,6 +795,15 @@ bsd_set_ssid(void *priv, u8 *buf, int len)
}
static int
+bsd_set_countermeasures(void *priv, int enabled)
+{
+ struct bsd_driver_data *drv = priv;
+
+ wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
+ return set80211param(drv, IEEE80211_IOC_COUNTERMEASURES, enabled);
+}
+
+static int
bsd_init(struct hostapd_data *hapd)
{
struct bsd_driver_data *drv;
@@ -797,7 +825,7 @@ bsd_init(struct hostapd_data *hapd)
memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
- handle_read, drv);
+ handle_read, drv, 1);
if (drv->sock_xmit == NULL)
goto bad;
if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
@@ -852,6 +880,8 @@ static const struct driver_ops bsd_driver_ops = {
.sta_deauth = bsd_sta_deauth,
.set_ssid = bsd_set_ssid,
.get_ssid = bsd_get_ssid,
+ .set_countermeasures = bsd_set_countermeasures,
+ .sta_clear_stats = bsd_sta_clear_stats,
};
void bsd_driver_register(void)
diff --git a/usr.sbin/wpa/hostapd_cli/Makefile b/usr.sbin/wpa/hostapd_cli/Makefile
index 6c0a8973a21c..0923dad405aa 100644
--- a/usr.sbin/wpa/hostapd_cli/Makefile
+++ b/usr.sbin/wpa/hostapd_cli/Makefile
@@ -1,10 +1,13 @@
# $FreeBSD$
-HOSTAPD_DISTDIR?= ${.CURDIR}/../../../contrib/hostapd
-.PATH: ${HOSTAPD_DISTDIR}
+CONTRIB= ${.CURDIR}/../../../contrib
+HOSTAPD_DISTDIR?= ${CONTRIB}/hostapd
+WPA_SUPPLICANT_DISTDIR?= ${CONTRIB}/wpa_supplicant
+
+.PATH: ${HOSTAPD_DISTDIR} ${WPA_SUPPLICANT_DISTDIR}
PROG= hostapd_cli
-SRCS= hostapd_cli.c hostapd_ctrl.c
+SRCS= hostapd_cli.c wpa_ctrl.c
MAN= hostapd_cli.8
diff --git a/usr.sbin/wpa/l2_packet.c b/usr.sbin/wpa/l2_packet.c
index 5304a9d51340..541bcbe5864e 100644
--- a/usr.sbin/wpa/l2_packet.c
+++ b/usr.sbin/wpa/l2_packet.c
@@ -31,6 +31,8 @@
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
#include "common.h"
#include "eloop.h"
@@ -40,11 +42,11 @@ struct l2_packet_data {
pcap_t *pcap;
char ifname[100];
u8 own_addr[ETH_ALEN];
- void (*rx_callback)(void *ctx, unsigned char *src_addr,
- unsigned char *buf, size_t len);
+ void (*rx_callback)(void *ctx, const u8 *src_addr,
+ const u8 *buf, size_t len);
void *rx_callback_ctx;
- int rx_l2_hdr; /* whether to include layer 2 (Ethernet) header in calls
- * to rx_callback */
+ int l2_hdr; /* whether to include layer 2 (Ethernet) header data
+ * buffers */
};
int
@@ -54,16 +56,65 @@ l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
return 0;
}
+int
+l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
+{
+ pcap_if_t *devs, *dev;
+ struct pcap_addr *addr;
+ struct sockaddr_in *saddr;
+ int found = 0;
+ char err[PCAP_ERRBUF_SIZE + 1];
+
+ if (pcap_findalldevs(&devs, err) < 0) {
+ wpa_printf(MSG_DEBUG, "pcap_findalldevs: %s\n", err);
+ return -1;
+ }
+
+ for (dev = devs; dev && !found; dev = dev->next) {
+ if (strcmp(dev->name, l2->ifname) != 0)
+ continue;
+
+ addr = dev->addresses;
+ while (addr) {
+ saddr = (struct sockaddr_in *) addr->addr;
+ if (saddr && saddr->sin_family == AF_INET) {
+ snprintf(buf, len, "%s",
+ inet_ntoa(saddr->sin_addr));
+ found = 1;
+ break;
+ }
+ addr = addr->next;
+ }
+ }
+
+ pcap_freealldevs(devs);
+
+ return found ? 0 : -1;
+}
+
void
-l2_packet_set_rx_l2_hdr(struct l2_packet_data *l2, int rx_l2_hdr)
+l2_packet_notify_auth_start(struct l2_packet_data *l2)
{
- l2->rx_l2_hdr = rx_l2_hdr;
}
int
-l2_packet_send(struct l2_packet_data *l2, u8 *buf, size_t len)
+l2_packet_send(struct l2_packet_data *l2,
+ const u8 *dst_addr, u16 proto, const u8 *buf, size_t len)
{
- return pcap_inject(l2->pcap, buf, len);
+ if (!l2->l2_hdr) {
+ int ret;
+ struct l2_ethhdr *eth = malloc(sizeof(*eth) + len);
+ if (eth == NULL)
+ return -1;
+ memcpy(eth->h_dest, dst_addr, ETH_ALEN);
+ memcpy(eth->h_source, l2->own_addr, ETH_ALEN);
+ eth->h_proto = htons(proto);
+ memcpy(eth + 1, buf, len);
+ ret = pcap_inject(l2->pcap, (u8 *) eth, len + sizeof(*eth));
+ free(eth);
+ return ret;
+ } else
+ return pcap_inject(l2->pcap, buf, len);
}
@@ -84,7 +135,7 @@ l2_packet_receive(int sock, void *eloop_ctx, void *sock_ctx)
return;
ethhdr = (struct l2_ethhdr *) packet;
- if (l2->rx_l2_hdr) {
+ if (l2->l2_hdr) {
buf = (unsigned char *) ethhdr;
len = hdr.caplen;
} else {
@@ -198,9 +249,9 @@ eth_get(const char *device, u8 ea[ETH_ALEN])
struct l2_packet_data *
l2_packet_init(const char *ifname, const u8 *own_addr, unsigned short protocol,
- void (*rx_callback)(void *ctx, unsigned char *src_addr,
- unsigned char *buf, size_t len),
- void *rx_callback_ctx)
+ void (*rx_callback)(void *ctx, const u8 *src_addr,
+ const u8 *buf, size_t len),
+ void *rx_callback_ctx, int l2_hdr)
{
struct l2_packet_data *l2;
@@ -211,6 +262,7 @@ l2_packet_init(const char *ifname, const u8 *own_addr, unsigned short protocol,
strncpy(l2->ifname, ifname, sizeof(l2->ifname));
l2->rx_callback = rx_callback;
l2->rx_callback_ctx = rx_callback_ctx;
+ l2->l2_hdr = l2_hdr;
if (eth_get(l2->ifname, l2->own_addr) < 0) {
fprintf(stderr, "Failed to get link-level address for "
diff --git a/usr.sbin/wpa/wpa_supplicant/Makefile b/usr.sbin/wpa/wpa_supplicant/Makefile
index 3c138fcde49a..62ecde8a2e4e 100644
--- a/usr.sbin/wpa/wpa_supplicant/Makefile
+++ b/usr.sbin/wpa/wpa_supplicant/Makefile
@@ -5,8 +5,8 @@ WPA_SUPPLICANT_DISTDIR?= ${.CURDIR}/../../../contrib/wpa_supplicant
PROG= wpa_supplicant
SRCS= config.c eloop.c common.c md5.c rc4.c sha1.c aes_wrap.c \
- wpa_supplicant.c wpa.c \
- ctrl_iface.c l2_packet.c drivers.c driver_freebsd.c \
+ wpa_supplicant.c events.c wpa.c preauth.c \
+ ctrl_iface.c l2_packet.c main.c drivers.c driver_freebsd.c \
driver_ndis.c driver_ndis_.c Packet32.c
MAN= wpa_supplicant.8 wpa_supplicant.conf.5
@@ -19,6 +19,10 @@ CFLAGS+= -g
DPADD+= ${LIBPCAP}
LDADD+= -lpcap
+# NB: we only support wpa_supplicant.conf file
+SRCS+= config_file.c base64.c
+CFLAGS+=-DCONFIG_BACKEND_FILE
+
.if !defined(NO_WPA_SUPPLICANT_EAPOL)
SRCS+= eapol_sm.c eap.c
CFLAGS+= -DIEEE8021X_EAPOL
@@ -26,7 +30,8 @@ CFLAGS+= -DIEEE8021X_EAPOL
.if !defined(NO_CRYPT) && !defined(NO_OPENSSL) && !defined(RELEASE_CRUNCH)
CFLAGS+=-DEAP_TLS -DEAP_PEAP -DEAP_MSCHAPv2 -DEAP_LEAP -DEAP_PSK \
-DEAP_TLV -DEAP_TLS_FUNCS
-SRCS+= eap_tls.c eap_peap.c eap_mschapv2.c eap_leap.c eap_psk.c \
+SRCS+= eap_tls.c eap_peap.c eap_mschapv2.c eap_leap.c \
+ eap_psk.c eap_psk_common.c \
eap_tlv.c eap_tls_common.c tls_openssl.c ms_funcs.c crypto.c
CFLAGS+=-DEAP_TTLS -DEAP_MD5
diff --git a/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c b/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c
index 6a02df60f2e0..b88a9ccd68c9 100644
--- a/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c
+++ b/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c
@@ -78,7 +78,8 @@ get80211var(struct wpa_driver_bsd_data *drv, int op, void *arg, int arg_len)
ireq.i_data = arg;
if (ioctl(drv->sock, SIOCG80211, &ireq) < 0) {
- perror("ioctl[SIOCG80211]");
+ fprintf(stderr, "ioctl[SIOCG80211, op %u, len %u]: %s\n",
+ op, arg_len, strerror(errno));
return -1;
}
return ireq.i_len;