Browse Source

Merge wpa_supplicant and hostapd driver wrapper implementations

This commit merges the driver_ops structures and implementations from
hostapd/driver*.[ch] into src/drivers. This is only an initial step and
there is room for number of cleanups to share code between the hostapd
and wpa_supplicant parts of the wrappers to avoid unnecessary source
code duplication.
Jouni Malinen 16 years ago
parent
commit
c51218372f

+ 14 - 10
hostapd/Makefile

@@ -41,11 +41,15 @@ endif
 OBJS =	hostapd.o main.o ieee802_1x.o eapol_sm.o \
 	config.o ieee802_11_auth.o \
 	sta_info.o wpa.o \
-	drivers.o preauth.o pmksa_cache.o \
+	preauth.o pmksa_cache.o \
 	drv_callbacks.o \
 	tkip_countermeasures.o \
 	mlme.o wpa_auth_ie.o
 
+OBJS += ../src/drivers/drivers.o
+OBJS += ../src/drivers/scan_helpers.o
+CFLAGS += -DHOSTAPD
+
 OBJS += ../src/utils/eloop.o
 OBJS += ../src/utils/common.o
 OBJS += ../src/utils/wpa_debug.o
@@ -127,35 +131,35 @@ endif
 ifdef CONFIG_DRIVER_HOSTAP
 NEED_MLME=y
 CFLAGS += -DCONFIG_DRIVER_HOSTAP
-OBJS += driver_hostap.o
+OBJS += ../src/drivers/driver_hostap.o
 endif
 
 ifdef CONFIG_DRIVER_WIRED
 CFLAGS += -DCONFIG_DRIVER_WIRED
-OBJS += driver_wired.o
+OBJS += ../src/drivers/driver_wired.o
 endif
 
 ifdef CONFIG_DRIVER_MADWIFI
 CFLAGS += -DCONFIG_DRIVER_MADWIFI
-OBJS += driver_madwifi.o
+OBJS += ../src/drivers/driver_madwifi.o
 CONFIG_L2_PACKET=y
 endif
 
 ifdef CONFIG_DRIVER_ATHEROS
 CFLAGS += -DCONFIG_DRIVER_ATHEROS
-OBJS += driver_atheros.o
+OBJS += ../src/drivers/driver_atheros.o
 CONFIG_L2_PACKET=y
 endif
 
 ifdef CONFIG_DRIVER_PRISM54
 CFLAGS += -DCONFIG_DRIVER_PRISM54
-OBJS += driver_prism54.o
+OBJS += ../src/drivers/driver_prism54.o
 endif
 
 ifdef CONFIG_DRIVER_NL80211
 NEED_MLME=y
 CFLAGS += -DCONFIG_DRIVER_NL80211
-OBJS += driver_nl80211.o
+OBJS += ../src/drivers/driver_nl80211.o
 OBJS += ../src/utils/radiotap.o
 LIBS += -lnl
 ifdef CONFIG_LIBNL20
@@ -166,7 +170,7 @@ endif
 
 ifdef CONFIG_DRIVER_BSD
 CFLAGS += -DCONFIG_DRIVER_BSD
-OBJS += driver_bsd.o
+OBJS += ../src/drivers/driver_bsd.o
 CONFIG_L2_PACKET=y
 CONFIG_DNET_PCAP=y
 CONFIG_L2_FREEBSD=y
@@ -175,12 +179,12 @@ endif
 ifdef CONFIG_DRIVER_TEST
 NEED_MLME=y
 CFLAGS += -DCONFIG_DRIVER_TEST
-OBJS += driver_test.o
+OBJS += ../src/drivers/driver_test.o
 endif
 
 ifdef CONFIG_DRIVER_NONE
 CFLAGS += -DCONFIG_DRIVER_NONE
-OBJS += driver_none.o
+OBJS += ../src/drivers/driver_none.o
 endif
 
 ifdef CONFIG_L2_PACKET

+ 1 - 1
hostapd/ap_list.c

@@ -25,7 +25,7 @@
 #include "ap_list.h"
 #include "hw_features.h"
 #include "beacon.h"
-#include "driver.h"
+#include "drivers/driver.h"
 
 
 struct ieee80211_frame_info {

+ 7 - 7
hostapd/config.c

@@ -19,7 +19,7 @@
 #endif /* CONFIG_NATIVE_WINDOWS */
 
 #include "hostapd.h"
-#include "driver.h"
+#include "drivers/driver.h"
 #include "sha1.h"
 #include "eap_server/eap.h"
 #include "radius/radius_client.h"
@@ -33,7 +33,7 @@
 
 #define MAX_STA_COUNT 2007
 
-extern struct hapd_driver_ops *hostapd_drivers[];
+extern struct wpa_driver_ops *wpa_drivers[];
 
 
 #ifndef CONFIG_NO_VLAN
@@ -226,7 +226,7 @@ struct hostapd_config * hostapd_config_defaults(void)
 	}
 
 	/* set default driver based on configuration */
-	conf->driver = hostapd_drivers[0];
+	conf->driver = wpa_drivers[0];
 	if (conf->driver == NULL) {
 		wpa_printf(MSG_ERROR, "No driver wrappers registered!");
 		os_free(conf);
@@ -1461,10 +1461,10 @@ struct hostapd_config * hostapd_config_read(const char *fname)
 			int j;
 			/* clear to get error below if setting is invalid */
 			conf->driver = NULL;
-			for (j = 0; hostapd_drivers[j]; j++) {
-				if (os_strcmp(pos, hostapd_drivers[j]->name) ==
-				    0) {
-					conf->driver = hostapd_drivers[j];
+			for (j = 0; wpa_drivers[j]; j++) {
+				if (os_strcmp(pos, wpa_drivers[j]->name) == 0)
+				{
+					conf->driver = wpa_drivers[j];
 					break;
 				}
 			}

+ 1 - 1
hostapd/config.h

@@ -339,7 +339,7 @@ struct hostapd_config {
 	int *supported_rates;
 	int *basic_rates;
 
-	const struct hapd_driver_ops *driver;
+	const struct wpa_driver_ops *driver;
 
 	int passive_scan_interval; /* seconds, 0 = disabled */
 	int passive_scan_listen; /* usec */

+ 5 - 1
hostapd/ctrl_iface.c

@@ -31,7 +31,7 @@
 #include "sta_info.h"
 #include "accounting.h"
 #include "wps_hostapd.h"
-#include "driver.h"
+#include "drivers/driver.h"
 
 
 struct wpa_ctrl_dst {
@@ -231,6 +231,7 @@ static int hostapd_ctrl_iface_new_sta(struct hostapd_data *hapd,
 
 
 #ifdef CONFIG_IEEE80211W
+#ifdef NEED_MLME
 static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
 				       const char *txtaddr)
 {
@@ -247,6 +248,7 @@ static int hostapd_ctrl_iface_sa_query(struct hostapd_data *hapd,
 
 	return 0;
 }
+#endif /* NEED_MLME */
 #endif /* CONFIG_IEEE80211W */
 
 
@@ -370,9 +372,11 @@ static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx,
 		if (hostapd_ctrl_iface_new_sta(hapd, buf + 8))
 			reply_len = -1;
 #ifdef CONFIG_IEEE80211W
+#ifdef NEED_MLME
 	} else if (os_strncmp(buf, "SA_QUERY ", 9) == 0) {
 		if (hostapd_ctrl_iface_sa_query(hapd, buf + 9))
 			reply_len = -1;
+#endif /* NEED_MLME */
 #endif /* CONFIG_IEEE80211W */
 #ifdef CONFIG_WPS
 	} else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {

+ 0 - 243
hostapd/driver.h

@@ -1,243 +0,0 @@
-/*
- * hostapd - driver interface definition
- * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2007-2008, Intel Corporation
- *
- * 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.
- */
-
-#ifndef HOSTAPD_DRIVER_H
-#define HOSTAPD_DRIVER_H
-
-#include "defs.h"
-#include "sta_flags.h"
-
-struct hostapd_data;
-
-struct hostap_sta_driver_data {
-	unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes;
-	unsigned long current_tx_rate;
-	unsigned long inactive_msec;
-	unsigned long flags;
-	unsigned long num_ps_buf_frames;
-	unsigned long tx_retry_failed;
-	unsigned long tx_retry_count;
-	int last_rssi;
-	int last_ack_rssi;
-};
-
-struct hostapd_sta_add_params {
-	const u8 *addr;
-	u16 aid;
-	u16 capability;
-	const u8 *supp_rates;
-	size_t supp_rates_len;
-	int flags;
-	u16 listen_interval;
-	const struct ht_cap_ie *ht_capabilities;
-};
-
-struct hostapd_freq_params {
-	int mode;
-	int freq;
-	int channel;
-	int ht_enabled;
-	int sec_channel_offset; /* 0 = HT40 disabled, -1 = HT40 enabled,
-				 * secondary channel below primary, 1 = HT40
-				 * enabled, secondary channel above primary */
-};
-
-enum hostapd_driver_if_type {
-	HOSTAPD_IF_VLAN, HOSTAPD_IF_WDS
-};
-
-struct hostapd_neighbor_bss {
-	u8 bssid[ETH_ALEN];
-	int freq; /* MHz */
-	unsigned int ht:1;
-	int pri_chan;
-	int sec_chan; /* 0 for 20 MHz channels */
-};
-
-struct hapd_driver_ops {
-	const char *name;		/* as appears in the config file */
-
-	void * (*init)(struct hostapd_data *hapd);
-	void * (*init_bssid)(struct hostapd_data *hapd, const u8 *bssid);
-	void (*deinit)(void *priv);
-
-	/**
-	 * set_8021x - enable/disable IEEE 802.1X support
-	 * @ifname: Interface name (for multi-SSID/VLAN support)
-	 * @priv: driver private data
-	 * @enabled: 1 = enable, 0 = disable
-	 *
-	 * Returns: 0 on success, -1 on failure
-	 *
-	 * Configure the kernel driver to enable/disable 802.1X support.
-	 * This may be an empty function if 802.1X support is always enabled.
-	 */
-	int (*set_ieee8021x)(const char *ifname, void *priv, int enabled);
-
-	/**
-	 * set_privacy - enable/disable privacy
-	 * @priv: driver private data
-	 * @enabled: 1 = privacy enabled, 0 = disabled
-	 *
-	 * Return: 0 on success, -1 on failure
-	 *
-	 * Configure privacy.
-	 */
-	int (*set_privacy)(const char *ifname, void *priv, int enabled);
-
-	int (*set_key)(const char *ifname, void *priv, wpa_alg alg,
-		       const u8 *addr, int key_idx, int set_tx, const u8 *seq,
-		       size_t seq_len, const u8 *key, size_t key_len);
-	int (*get_seqnum)(const char *ifname, void *priv, const u8 *addr,
-			  int idx, u8 *seq);
-	int (*get_seqnum_igtk)(const char *ifname, void *priv, const u8 *addr,
-			       int idx, u8 *seq);
-	int (*flush)(void *priv);
-	int (*set_generic_elem)(const char *ifname, void *priv, const u8 *elem,
-				size_t elem_len);
-
-	int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
-			     const u8 *addr);
-	int (*send_eapol)(void *priv, const u8 *addr, const u8 *data,
-			  size_t data_len, int encrypt, const u8 *own_addr);
-	int (*sta_deauth)(void *priv, const u8 *addr, int reason);
-	int (*sta_disassoc)(void *priv, const u8 *addr, int reason);
-	int (*sta_remove)(void *priv, const u8 *addr);
-	int (*get_ssid)(const char *ifname, void *priv, u8 *buf, int len);
-	int (*set_ssid)(const char *ifname, void *priv, const u8 *buf,
-			int len);
-	int (*set_countermeasures)(void *priv, int enabled);
-	int (*send_mgmt_frame)(void *priv, const void *msg, size_t len,
-			       int flags);
-	int (*sta_add)(const char *ifname, void *priv,
-		       struct hostapd_sta_add_params *params);
-	int (*get_inact_sec)(void *priv, const u8 *addr);
-	int (*sta_clear_stats)(void *priv, const u8 *addr);
-
-	int (*set_freq)(void *priv, struct hostapd_freq_params *freq);
-	int (*set_rts)(void *priv, int rts);
-	int (*set_frag)(void *priv, int frag);
-	int (*set_retry)(void *priv, int short_retry, int long_retry);
-
-	int (*sta_set_flags)(void *priv, const u8 *addr,
-			     int total_flags, int flags_or, int flags_and);
-	int (*set_rate_sets)(void *priv, int *supp_rates, int *basic_rates,
-			     int mode);
-	int (*set_country)(void *priv, const char *country);
-	int (*set_ieee80211d)(void *priv, int enabled);
-	int (*set_beacon)(const char *ifname, void *priv,
-			  const u8 *head, size_t head_len,
-			  const u8 *tail, size_t tail_len, int dtim_period);
-
-	/* Configure internal bridge:
-	 * 0 = disabled, i.e., client separation is enabled (no bridging of
-	 *     packets between associated STAs
-	 * 1 = enabled, i.e., bridge packets between associated STAs (default)
-	 */
-	int (*set_internal_bridge)(void *priv, int value);
-	int (*set_beacon_int)(void *priv, int value);
-	/* Configure broadcast SSID mode:
-	 * 0 = include SSID in Beacon frames and reply to Probe Request frames
-	 *     that use broadcast SSID
-	 * 1 = hide SSID from Beacon frames and ignore Probe Request frames for
-	 *     broadcast SSID
-	 */
-	int (*set_broadcast_ssid)(void *priv, int value);
-	int (*set_cts_protect)(void *priv, int value);
-	int (*set_preamble)(void *priv, int value);
-	int (*set_short_slot_time)(void *priv, int value);
-	int (*set_tx_queue_params)(void *priv, int queue, int aifs, int cw_min,
-				   int cw_max, int burst_time);
-	int (*bss_add)(void *priv, const char *ifname, const u8 *bssid);
-	int (*bss_remove)(void *priv, const char *ifname);
-	int (*valid_bss_mask)(void *priv, const u8 *addr, const u8 *mask);
-	int (*passive_scan)(void *priv, int now, int our_mode_only,
-			    int interval, int _listen, int *channel,
-			    int *last_rx);
-	struct hostapd_hw_modes * (*get_hw_feature_data)(void *priv,
-							 u16 *num_modes,
-							 u16 *flags);
-	int (*if_add)(const char *iface, void *priv,
-		      enum hostapd_driver_if_type type, char *ifname,
-		      const u8 *addr);
-	int (*if_update)(void *priv, enum hostapd_driver_if_type type,
-			 char *ifname, const u8 *addr);
-	int (*if_remove)(void *priv, enum hostapd_driver_if_type type,
-			 const char *ifname, const u8 *addr);
-	int (*set_sta_vlan)(void *priv, const u8 *addr, const char *ifname,
-			    int vlan_id);
-	/**
-	 * commit - Optional commit changes handler
-	 * @priv: driver private data
-	 * Returns: 0 on success, -1 on failure
-	 *
-	 * This optional handler function can be registered if the driver
-	 * interface implementation needs to commit changes (e.g., by setting
-	 * network interface up) at the end of initial configuration. If set,
-	 * this handler will be called after initial setup has been completed.
-	 */
-	int (*commit)(void *priv);
-
-	int (*send_ether)(void *priv, const u8 *dst, const u8 *src, u16 proto,
-			  const u8 *data, size_t data_len);
-
-	int (*set_radius_acl_auth)(void *priv, const u8 *mac, int accepted, 
-				   u32 session_timeout);
-	int (*set_radius_acl_expire)(void *priv, const u8 *mac);
-
-	int (*set_ht_params)(const char *ifname, void *priv,
-			     const u8 *ht_capab, size_t ht_capab_len,
-			     const u8 *ht_oper, size_t ht_oper_len);
-
-	int (*set_wps_beacon_ie)(const char *ifname, void *priv,
-				 const u8 *ie, size_t len);
-	int (*set_wps_probe_resp_ie)(const char *ifname, void *priv,
-				     const u8 *ie, size_t len);
-
-	const struct hostapd_neighbor_bss *
-	(*get_neighbor_bss)(void *priv, size_t *num);
-};
-
-struct sta_info;
-
-void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
-			   int reassoc);
-void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
-		       const u8 *buf, size_t len, int ack);
-void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, const u8 *addr);
-int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
-			const u8 *ie, size_t ielen);
-void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
-void hostapd_eapol_receive(struct hostapd_data *hapd, const u8 *sa,
-			   const u8 *buf, size_t len);
-
-struct hostapd_frame_info {
-	u32 phytype;
-	u32 channel;
-	u32 datarate;
-	u32 ssi_signal;
-
-	unsigned int passive_scan:1;
-};
-
-void hostapd_mgmt_rx(struct hostapd_data *hapd, u8 *buf, size_t len,
-		     u16 stype, struct hostapd_frame_info *fi);
-void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
-			u16 stype, int ok);
-void hostapd_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr);
-struct hostapd_data * hostapd_sta_get_bss(struct hostapd_data *hapd,
-					  const u8 *addr);
-
-#endif /* HOSTAPD_DRIVER_H */

+ 0 - 768
hostapd/driver_bsd.c

@@ -1,768 +0,0 @@
-/*
- * hostapd / Driver interaction with BSD net80211 layer
- * Copyright (c) 2004, Sam Leffler <sam@errno.com>
- * Copyright (c) 2004, 2Wire, Inc
- *
- * 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 "includes.h"
-#include <sys/ioctl.h>
-
-#include <net/if.h>
-
-#include <net80211/ieee80211.h>
-#include <net80211/ieee80211_crypto.h>
-#include <net80211/ieee80211_ioctl.h>
-
-/*
- * Avoid conflicts with hostapd definitions by undefining couple of defines
- * from net80211 header files.
- */
-#undef RSN_VERSION
-#undef WPA_VERSION
-#undef WPA_OUI_TYPE
-
-#include "hostapd.h"
-#include "config.h"
-#include "driver.h"
-#include "eloop.h"
-#include "l2_packet/l2_packet.h"
-
-#include "eapol_sm.h"
-#include "common.h"
-
-struct bsd_driver_data {
-	struct hostapd_data *hapd;		/* back pointer */
-
-	char	iface[IFNAMSIZ + 1];
-	struct l2_packet_data *sock_xmit;	/* raw packet xmit socket */
-	int	ioctl_sock;			/* socket for ioctl() use */
-	int	wext_sock;			/* socket for wireless events */
-};
-
-static int bsd_sta_deauth(void *priv, const u8 *addr, int reason_code);
-
-static int
-set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len)
-{
-	struct ieee80211req ireq;
-
-	memset(&ireq, 0, sizeof(ireq));
-	os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
-	ireq.i_type = op;
-	ireq.i_len = arg_len;
-	ireq.i_data = (void *) arg;
-
-	if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
-		perror("ioctl[SIOCS80211]");
-		return -1;
-	}
-	return 0;
-}
-
-static int
-get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len)
-{
-	struct ieee80211req ireq;
-
-	memset(&ireq, 0, sizeof(ireq));
-	os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
-	ireq.i_type = op;
-	ireq.i_len = arg_len;
-	ireq.i_data = arg;
-
-	if (ioctl(drv->ioctl_sock, SIOCG80211, &ireq) < 0) {
-		perror("ioctl[SIOCG80211]");
-		return -1;
-	}
-	return ireq.i_len;
-}
-
-static int
-set80211param(struct bsd_driver_data *drv, int op, int arg)
-{
-	struct ieee80211req ireq;
-
-	memset(&ireq, 0, sizeof(ireq));
-	os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
-	ireq.i_type = op;
-	ireq.i_val = arg;
-
-	if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
-		perror("ioctl[SIOCS80211]");
-		return -1;
-	}
-	return 0;
-}
-
-static const char *
-ether_sprintf(const u8 *addr)
-{
-	static char buf[sizeof(MACSTR)];
-
-	if (addr != NULL)
-		snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
-	else
-		snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
-	return buf;
-}
-
-/*
- * Configure WPA parameters.
- */
-static int
-bsd_configure_wpa(struct bsd_driver_data *drv)
-{
-	static const char *ciphernames[] =
-		{ "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" };
-	struct hostapd_data *hapd = drv->hapd;
-	struct hostapd_bss_config *conf = hapd->conf;
-	int v;
-
-	switch (conf->wpa_group) {
-	case WPA_CIPHER_CCMP:
-		v = IEEE80211_CIPHER_AES_CCM;
-		break;
-	case WPA_CIPHER_TKIP:
-		v = IEEE80211_CIPHER_TKIP;
-		break;
-	case WPA_CIPHER_WEP104:
-		v = IEEE80211_CIPHER_WEP;
-		break;
-	case WPA_CIPHER_WEP40:
-		v = IEEE80211_CIPHER_WEP;
-		break;
-	case WPA_CIPHER_NONE:
-		v = IEEE80211_CIPHER_NONE;
-		break;
-	default:
-		printf("Unknown group key cipher %u\n",
-			conf->wpa_group);
-		return -1;
-	}
-	wpa_printf(MSG_DEBUG, "%s: group key cipher=%s (%u)",
-		   __func__, ciphernames[v], v);
-	if (set80211param(drv, IEEE80211_IOC_MCASTCIPHER, v)) {
-		printf("Unable to set group key cipher to %u (%s)\n",
-			v, ciphernames[v]);
-		return -1;
-	}
-	if (v == IEEE80211_CIPHER_WEP) {
-		/* key length is done only for specific ciphers */
-		v = (conf->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
-		if (set80211param(drv, IEEE80211_IOC_MCASTKEYLEN, v)) {
-			printf("Unable to set group key length to %u\n", v);
-			return -1;
-		}
-	}
-
-	v = 0;
-	if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
-		v |= 1<<IEEE80211_CIPHER_AES_CCM;
-	if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
-		v |= 1<<IEEE80211_CIPHER_TKIP;
-	if (conf->wpa_pairwise & WPA_CIPHER_NONE)
-		v |= 1<<IEEE80211_CIPHER_NONE;
-	wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
-	if (set80211param(drv, IEEE80211_IOC_UCASTCIPHERS, v)) {
-		printf("Unable to set pairwise key ciphers to 0x%x\n", v);
-		return -1;
-	}
-
-	wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
-		   __func__, conf->wpa_key_mgmt);
-	if (set80211param(drv, IEEE80211_IOC_KEYMGTALGS, conf->wpa_key_mgmt)) {
-		printf("Unable to set key management algorithms to 0x%x\n",
-			conf->wpa_key_mgmt);
-		return -1;
-	}
-
-	v = 0;
-	if (conf->rsn_preauth)
-		v |= BIT(0);
-	wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x",
-		   __func__, conf->rsn_preauth);
-	if (set80211param(drv, IEEE80211_IOC_RSNCAPS, v)) {
-		printf("Unable to set RSN capabilities to 0x%x\n", v);
-		return -1;
-	}
-
-	wpa_printf(MSG_DEBUG, "%s: enable WPA= 0x%x", __func__, conf->wpa);
-	if (set80211param(drv, IEEE80211_IOC_WPA, conf->wpa)) {
-		printf("Unable to set WPA to %u\n", conf->wpa);
-		return -1;
-	}
-	return 0;
-}
-
-
-static int
-bsd_set_iface_flags(void *priv, int dev_up)
-{
-	struct bsd_driver_data *drv = priv;
-	struct ifreq ifr;
-
-	wpa_printf(MSG_DEBUG, "%s: dev_up=%d", __func__, dev_up);
-
-	if (drv->ioctl_sock < 0)
-		return -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
-
-	if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
-		perror("ioctl[SIOCGIFFLAGS]");
-		return -1;
-	}
-
-	if (dev_up)
-		ifr.ifr_flags |= IFF_UP;
-	else
-		ifr.ifr_flags &= ~IFF_UP;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
-		perror("ioctl[SIOCSIFFLAGS]");
-		return -1;
-	}
-
-	if (dev_up) {
-		memset(&ifr, 0, sizeof(ifr));
-		os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
-		ifr.ifr_mtu = HOSTAPD_MTU;
-		if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
-			perror("ioctl[SIOCSIFMTU]");
-			printf("Setting MTU failed - trying to survive with "
-			       "current value\n");
-		}
-	}
-
-	return 0;
-}
-
-static int
-bsd_set_ieee8021x(const char *ifname, void *priv, int enabled)
-{
-	struct bsd_driver_data *drv = priv;
-	struct hostapd_data *hapd = drv->hapd;
-	struct hostapd_bss_config *conf = hapd->conf;
-
-	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
-
-	if (!enabled) {
-		/* XXX restore state */
-		return set80211param(priv, IEEE80211_IOC_AUTHMODE,
-			IEEE80211_AUTH_AUTO);
-	}
-	if (!conf->wpa && !conf->ieee802_1x) {
-		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
-			HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
-		return -1;
-	}
-	if (conf->wpa && bsd_configure_wpa(drv) != 0) {
-		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
-			HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");
-		return -1;
-	}
-	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!");
-		return -1;
-	}
-	return bsd_set_iface_flags(priv, 1);
-}
-
-static int
-bsd_set_privacy(const char *ifname, void *priv, int enabled)
-{
-	struct bsd_driver_data *drv = priv;
-
-	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
-
-	return set80211param(drv, IEEE80211_IOC_PRIVACY, enabled);
-}
-
-static int
-bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized)
-{
-	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
-		   __func__, ether_sprintf(addr), authorized);
-
-	if (authorized)
-		mlme.im_op = IEEE80211_MLME_AUTHORIZE;
-	else
-		mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
-	mlme.im_reason = 0;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-bsd_sta_set_flags(void *priv, const u8 *addr, int total_flags, int flags_or,
-		  int flags_and)
-{
-	/* For now, only support setting Authorized flag */
-	if (flags_or & WLAN_STA_AUTHORIZED)
-		return bsd_set_sta_authorized(priv, addr, 1);
-	if (!(flags_and & WLAN_STA_AUTHORIZED))
-		return bsd_set_sta_authorized(priv, addr, 0);
-	return 0;
-}
-
-static int
-bsd_del_key(void *priv, const u8 *addr, int key_idx)
-{
-	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_del_key wk;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
-		   __func__, ether_sprintf(addr), key_idx);
-
-	memset(&wk, 0, sizeof(wk));
-	if (addr != NULL) {
-		memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
-		wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE;	/* XXX */
-	} else {
-		wk.idk_keyix = key_idx;
-	}
-
-	return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
-}
-
-static int
-bsd_set_key(const char *ifname, void *priv, wpa_alg alg,
-	    const u8 *addr, int key_idx, int set_tx, const u8 *seq,
-	    size_t seq_len, const u8 *key, size_t key_len)
-{
-	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_key wk;
-	u_int8_t cipher;
-
-	if (alg == WPA_ALG_NONE)
-		return bsd_del_key(drv, addr, key_idx);
-
-	wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
-		   __func__, alg, ether_sprintf(addr), key_idx);
-
-	if (alg == WPA_ALG_WEP)
-		cipher = IEEE80211_CIPHER_WEP;
-	else if (alg == WPA_ALG_TKIP)
-		cipher = IEEE80211_CIPHER_TKIP;
-	else if (alg == WPA_ALG_CCMP)
-		cipher = IEEE80211_CIPHER_AES_CCM;
-	else {
-		printf("%s: unknown/unsupported algorithm %d\n",
-			__func__, alg);
-		return -1;
-	}
-
-	if (key_len > sizeof(wk.ik_keydata)) {
-		printf("%s: key length %d too big\n", __func__, key_len);
-		return -3;
-	}
-
-	memset(&wk, 0, sizeof(wk));
-	wk.ik_type = cipher;
-	wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
-	if (addr == NULL) {
-		memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
-		wk.ik_keyix = key_idx;
-		wk.ik_flags |= IEEE80211_KEY_DEFAULT;
-	} else {
-		memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
-		wk.ik_keyix = IEEE80211_KEYIX_NONE;
-	}
-	wk.ik_keylen = key_len;
-	memcpy(wk.ik_keydata, key, key_len);
-
-	return set80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
-}
-
-
-static int
-bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
-	       u8 *seq)
-{
-	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_key wk;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
-		   __func__, ether_sprintf(addr), idx);
-
-	memset(&wk, 0, sizeof(wk));
-	if (addr == NULL)
-		memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
-	else
-		memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
-	wk.ik_keyix = idx;
-
-	if (get80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) {
-		printf("Failed to get encryption.\n");
-		return -1;
-	}
-
-#ifdef WORDS_BIGENDIAN
-	{
-		/*
-		 * wk.ik_keytsc is in host byte order (big endian), need to
-		 * swap it to match with the byte order used in WPA.
-		 */
-		int i;
-		u8 tmp[WPA_KEY_RSC_LEN];
-		memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
-		for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
-			seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
-		}
-	}
-#else /* WORDS_BIGENDIAN */
-	memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
-#endif /* WORDS_BIGENDIAN */
-	return 0;
-}
-
-
-static int 
-bsd_flush(void *priv)
-{
-	u8 allsta[IEEE80211_ADDR_LEN];
-
-	memset(allsta, 0xff, IEEE80211_ADDR_LEN);
-	return bsd_sta_deauth(priv, allsta, IEEE80211_REASON_AUTH_LEAVE);
-}
-
-
-static int
-bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
-			 const u8 *addr)
-{
-	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_sta_stats stats;
-
-	memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
-	if (get80211var(drv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) > 0) {
-		/* XXX? do packets counts include non-data frames? */
-		data->rx_packets = stats.is_stats.ns_rx_data;
-		data->rx_bytes = stats.is_stats.ns_rx_bytes;
-		data->tx_packets = stats.is_stats.ns_tx_data;
-		data->tx_bytes = stats.is_stats.ns_tx_bytes;
-	}
-	return 0;
-}
-
-static int
-bsd_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len)
-{
-	/*
-	 * Do nothing; we setup parameters at startup that define the
-	 * contents of the beacon information element.
-	 */
-	return 0;
-}
-
-static int
-bsd_sta_deauth(void *priv, const u8 *addr, int reason_code)
-{
-	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
-		   __func__, ether_sprintf(addr), reason_code);
-
-	mlme.im_op = IEEE80211_MLME_DEAUTH;
-	mlme.im_reason = reason_code;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-bsd_sta_disassoc(void *priv, const u8 *addr, int reason_code)
-{
-	struct bsd_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
-		   __func__, ether_sprintf(addr), reason_code);
-
-	mlme.im_op = IEEE80211_MLME_DISASSOC;
-	mlme.im_reason = reason_code;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
-}
-
-static int
-bsd_new_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
-{
-	struct hostapd_data *hapd = drv->hapd;
-	struct ieee80211req_wpaie ie;
-	int ielen = 0;
-	u8 *iebuf = NULL;
-
-	/*
-	 * Fetch and validate any negotiated WPA/RSN parameters.
-	 */
-	memset(&ie, 0, sizeof(ie));
-	memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
-	if (get80211var(drv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) {
-		printf("Failed to get WPA/RSN information element.\n");
-		goto no_ie;
-	}
-	iebuf = ie.wpa_ie;
-	ielen = ie.wpa_ie[1];
-	if (ielen == 0)
-		iebuf = NULL;
-	else
-		ielen += 2;
-
-no_ie:
-	return hostapd_notif_assoc(hapd, addr, iebuf, ielen);
-}
-
-#include <net/route.h>
-#include <net80211/ieee80211_freebsd.h>
-
-static void
-bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
-{
-	struct bsd_driver_data *drv = ctx;
-	struct hostapd_data *hapd = drv->hapd;
-	char buf[2048];
-	struct if_announcemsghdr *ifan;
-	struct rt_msghdr *rtm;
-	struct ieee80211_michael_event *mic;
-	struct ieee80211_join_event *join;
-	struct ieee80211_leave_event *leave;
-	int n;
-
-	n = read(sock, buf, sizeof(buf));
-	if (n < 0) {
-		if (errno != EINTR && errno != EAGAIN)
-			perror("read(PF_ROUTE)");
-		return;
-	}
-
-	rtm = (struct rt_msghdr *) buf;
-	if (rtm->rtm_version != RTM_VERSION) {
-		wpa_printf(MSG_DEBUG, "Routing message version %d not "
-			"understood\n", rtm->rtm_version);
-		return;
-	}
-	ifan = (struct if_announcemsghdr *) rtm;
-	switch (rtm->rtm_type) {
-	case RTM_IEEE80211:
-		switch (ifan->ifan_what) {
-		case RTM_IEEE80211_ASSOC:
-		case RTM_IEEE80211_REASSOC:
-		case RTM_IEEE80211_DISASSOC:
-		case RTM_IEEE80211_SCAN:
-			break;
-		case RTM_IEEE80211_LEAVE:
-			leave = (struct ieee80211_leave_event *) &ifan[1];
-			hostapd_notif_disassoc(drv->hapd, leave->iev_addr);
-			break;
-		case RTM_IEEE80211_JOIN:
-#ifdef RTM_IEEE80211_REJOIN
-		case RTM_IEEE80211_REJOIN:
-#endif
-			join = (struct ieee80211_join_event *) &ifan[1];
-			bsd_new_sta(drv, join->iev_addr);
-			break;
-		case RTM_IEEE80211_REPLAY:
-			/* ignore */
-			break;
-		case RTM_IEEE80211_MICHAEL:
-			mic = (struct ieee80211_michael_event *) &ifan[1];
-			wpa_printf(MSG_DEBUG,
-				"Michael MIC failure wireless event: "
-				"keyix=%u src_addr=" MACSTR, mic->iev_keyix,
-				MAC2STR(mic->iev_src));
-			hostapd_michael_mic_failure(hapd, mic->iev_src);
-			break;
-		}
-		break;
-	}
-}
-
-static int
-bsd_wireless_event_init(struct bsd_driver_data *drv)
-{
-	int s;
-
-	drv->wext_sock = -1;
-
-	s = socket(PF_ROUTE, SOCK_RAW, 0);
-	if (s < 0) {
-		perror("socket(PF_ROUTE,SOCK_RAW)");
-		return -1;
-	}
-	eloop_register_read_sock(s, bsd_wireless_event_receive, drv, NULL);
-	drv->wext_sock = s;
-
-	return 0;
-}
-
-static void
-bsd_wireless_event_deinit(struct bsd_driver_data *drv)
-{
-	if (drv->wext_sock < 0)
-		return;
-	eloop_unregister_read_sock(drv->wext_sock);
-	close(drv->wext_sock);
-}
-
-
-static int
-bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
-	       int encrypt, const u8 *own_addr)
-{
-	struct bsd_driver_data *drv = priv;
-	unsigned char buf[3000];
-	unsigned char *bp = buf;
-	struct l2_ethhdr *eth;
-	size_t len;
-	int status;
-
-	/*
-	 * Prepend the Etherent header.  If the caller left us
-	 * space at the front we could just insert it but since
-	 * we don't know we copy to a local buffer.  Given the frequency
-	 * and size of frames this probably doesn't matter.
-	 */
-	len = data_len + sizeof(struct l2_ethhdr);
-	if (len > sizeof(buf)) {
-		bp = malloc(len);
-		if (bp == NULL) {
-			printf("EAPOL frame discarded, cannot malloc temp "
-				"buffer of size %u!\n", len);
-			return -1;
-		}
-	}
-	eth = (struct l2_ethhdr *) bp;
-	memcpy(eth->h_dest, addr, ETH_ALEN);
-	memcpy(eth->h_source, own_addr, ETH_ALEN);
-	eth->h_proto = htons(ETH_P_EAPOL);
-	memcpy(eth+1, data, data_len);
-
-	wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
-
-	status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
-
-	if (bp != buf)
-		free(bp);
-	return status;
-}
-
-static void
-handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
-{
-	struct bsd_driver_data *drv = ctx;
-	hostapd_eapol_receive(drv->hapd, src_addr,
-			      buf + sizeof(struct l2_ethhdr),
-			      len - sizeof(struct l2_ethhdr));
-}
-
-static int
-bsd_get_ssid(const char *ifname, void *priv, u8 *buf, int len)
-{
-	struct bsd_driver_data *drv = priv;
-	int ssid_len = get80211var(drv, IEEE80211_IOC_SSID, buf, len);
-
-	wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"", __func__, ssid_len, buf);
-
-	return ssid_len;
-}
-
-static int
-bsd_set_ssid(const char *ifname, void *priv, const u8 *buf, int len)
-{
-	struct bsd_driver_data *drv = priv;
-
-	wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"", __func__, len, buf);
-
-	return set80211var(drv, IEEE80211_IOC_SSID, buf, len);
-}
-
-static void *
-bsd_init(struct hostapd_data *hapd)
-{
-	struct bsd_driver_data *drv;
-
-	drv = os_zalloc(sizeof(struct bsd_driver_data));
-	if (drv == NULL) {
-		printf("Could not allocate memory for bsd driver data\n");
-		goto bad;
-	}
-
-	drv->hapd = hapd;
-	drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
-	if (drv->ioctl_sock < 0) {
-		perror("socket[PF_INET,SOCK_DGRAM]");
-		goto bad;
-	}
-	memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
-
-	drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
-					handle_read, drv, 1);
-	if (drv->sock_xmit == NULL)
-		goto bad;
-	if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
-		goto bad;
-
-	bsd_set_iface_flags(drv, 0);	/* mark down during setup */
-	if (bsd_wireless_event_init(drv))
-		goto bad;
-
-	return drv;
-bad:
-	if (drv->sock_xmit != NULL)
-		l2_packet_deinit(drv->sock_xmit);
-	if (drv->ioctl_sock >= 0)
-		close(drv->ioctl_sock);
-	if (drv != NULL)
-		free(drv);
-	return NULL;
-}
-
-
-static void
-bsd_deinit(void *priv)
-{
-	struct bsd_driver_data *drv = priv;
-
-	bsd_wireless_event_deinit(drv);
-	(void) bsd_set_iface_flags(drv, 0);
-	if (drv->ioctl_sock >= 0)
-		close(drv->ioctl_sock);
-	if (drv->sock_xmit != NULL)
-		l2_packet_deinit(drv->sock_xmit);
-	free(drv);
-}
-
-const struct hapd_driver_ops wpa_driver_bsd_ops = {
-	.name			= "bsd",
-	.init			= bsd_init,
-	.deinit			= bsd_deinit,
-	.set_ieee8021x		= bsd_set_ieee8021x,
-	.set_privacy		= bsd_set_privacy,
-	.set_key		= bsd_set_key,
-	.get_seqnum		= bsd_get_seqnum,
-	.flush			= bsd_flush,
-	.set_generic_elem	= bsd_set_opt_ie,
-	.sta_set_flags		= bsd_sta_set_flags,
-	.read_sta_data		= bsd_read_sta_driver_data,
-	.send_eapol		= bsd_send_eapol,
-	.sta_disassoc		= bsd_sta_disassoc,
-	.sta_deauth		= bsd_sta_deauth,
-	.set_ssid		= bsd_set_ssid,
-	.get_ssid		= bsd_get_ssid,
-};

+ 0 - 1253
hostapd/driver_hostap.c

@@ -1,1253 +0,0 @@
-/*
- * hostapd / Kernel driver communication with Linux Host AP driver
- * Copyright (c) 2002-2009, 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 "includes.h"
-#include <sys/ioctl.h>
-
-#ifdef USE_KERNEL_HEADERS
-/* compat-wireless does not include linux/compiler.h to define __user, so
- * define it here */
-#ifndef __user
-#define __user
-#endif /* __user */
-#include <asm/types.h>
-#include <linux/if_packet.h>
-#include <linux/if_ether.h>   /* The L2 protocols */
-#include <linux/if_arp.h>
-#include <linux/wireless.h>
-#else /* USE_KERNEL_HEADERS */
-#include <net/if_arp.h>
-#include <netpacket/packet.h>
-#include "wireless_copy.h"
-#endif /* USE_KERNEL_HEADERS */
-
-#include "hostapd.h"
-#include "config.h"
-#include "driver.h"
-#include "eloop.h"
-#include "priv_netlink.h"
-#include "hostap_common.h"
-#include "hw_features.h"
-#include "ieee802_11_defs.h"
-
-static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
-
-struct hostap_driver_data {
-	struct hostapd_data *hapd;
-
-	char iface[IFNAMSIZ + 1];
-	int sock; /* raw packet socket for driver access */
-	int ioctl_sock; /* socket for ioctl() use */
-	int wext_sock; /* socket for wireless events */
-
-	int we_version;
-
-	u8 *generic_ie;
-	size_t generic_ie_len;
-	u8 *wps_ie;
-	size_t wps_ie_len;
-};
-
-
-static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
-			 int len);
-static int hostap_set_iface_flags(void *priv, int dev_up);
-static int hostap_sta_disassoc(void *priv, const u8 *addr, int reason);
-static int hostap_sta_deauth(void *priv, const u8 *addr, int reason);
-
-static void handle_data(struct hostap_driver_data *drv, u8 *buf, size_t len,
-			u16 stype)
-{
-	struct ieee80211_hdr *hdr;
-	u16 fc, ethertype;
-	u8 *pos, *sa;
-	size_t left;
-
-	if (len < sizeof(struct ieee80211_hdr))
-		return;
-
-	hdr = (struct ieee80211_hdr *) buf;
-	fc = le_to_host16(hdr->frame_control);
-
-	if ((fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) != WLAN_FC_TODS) {
-		printf("Not ToDS data frame (fc=0x%04x)\n", fc);
-		return;
-	}
-
-	sa = hdr->addr2;
-	hostapd_rx_from_unknown_sta(drv->hapd, sa);
-
-	pos = (u8 *) (hdr + 1);
-	left = len - sizeof(*hdr);
-
-	if (left < sizeof(rfc1042_header)) {
-		printf("Too short data frame\n");
-		return;
-	}
-
-	if (memcmp(pos, rfc1042_header, sizeof(rfc1042_header)) != 0) {
-		printf("Data frame with no RFC1042 header\n");
-		return;
-	}
-	pos += sizeof(rfc1042_header);
-	left -= sizeof(rfc1042_header);
-
-	if (left < 2) {
-		printf("No ethertype in data frame\n");
-		return;
-	}
-
-	ethertype = WPA_GET_BE16(pos);
-	pos += 2;
-	left -= 2;
-	switch (ethertype) {
-	case ETH_P_PAE:
-		hostapd_eapol_receive(drv->hapd, sa, pos, left);
-		break;
-
-	default:
-		printf("Unknown ethertype 0x%04x in data frame\n", ethertype);
-		break;
-	}
-}
-
-
-static void handle_tx_callback(struct hostap_driver_data *drv, u8 *buf,
-			       size_t len, int ok)
-{
-	struct ieee80211_hdr *hdr;
-	u16 fc, type, stype;
-
-	hdr = (struct ieee80211_hdr *) buf;
-	fc = le_to_host16(hdr->frame_control);
-
-	type = WLAN_FC_GET_TYPE(fc);
-	stype = WLAN_FC_GET_STYPE(fc);
-
-	switch (type) {
-	case WLAN_FC_TYPE_MGMT:
-		wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
-			   ok ? "ACK" : "fail");
-		hostapd_mgmt_tx_cb(drv->hapd, buf, len, stype, ok);
-		break;
-	case WLAN_FC_TYPE_CTRL:
-		wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
-			   ok ? "ACK" : "fail");
-		break;
-	case WLAN_FC_TYPE_DATA:
-		wpa_printf(MSG_DEBUG, "DATA (TX callback) %s",
-			   ok ? "ACK" : "fail");
-		hostapd_tx_status(drv->hapd, hdr->addr1, buf, len, ok);
-		break;
-	default:
-		printf("unknown TX callback frame type %d\n", type);
-		break;
-	}
-}
-
-
-static void handle_frame(struct hostap_driver_data *drv, u8 *buf, size_t len)
-{
-	struct ieee80211_hdr *hdr;
-	u16 fc, extra_len, type, stype;
-	unsigned char *extra = NULL;
-	size_t data_len = len;
-	int ver;
-
-	/* PSPOLL is only 16 bytes, but driver does not (at least yet) pass
-	 * these to user space */
-	if (len < 24) {
-		wpa_printf(MSG_MSGDUMP, "handle_frame: too short (%lu)",
-			   (unsigned long) len);
-		return;
-	}
-
-	hdr = (struct ieee80211_hdr *) buf;
-	fc = le_to_host16(hdr->frame_control);
-	type = WLAN_FC_GET_TYPE(fc);
-	stype = WLAN_FC_GET_STYPE(fc);
-
-	if (type != WLAN_FC_TYPE_MGMT || stype != WLAN_FC_STYPE_BEACON) {
-		wpa_hexdump(MSG_MSGDUMP, "Received management frame",
-			    buf, len);
-	}
-
-	ver = fc & WLAN_FC_PVER;
-
-	/* protocol version 3 is reserved for indicating extra data after the
-	 * payload, version 2 for indicating ACKed frame (TX callbacks), and
-	 * version 1 for indicating failed frame (no ACK, TX callbacks) */
-	if (ver == 3) {
-		u8 *pos = buf + len - 2;
-		extra_len = WPA_GET_LE16(pos);
-		printf("extra data in frame (elen=%d)\n", extra_len);
-		if ((size_t) extra_len + 2 > len) {
-			printf("  extra data overflow\n");
-			return;
-		}
-		len -= extra_len + 2;
-		extra = buf + len;
-	} else if (ver == 1 || ver == 2) {
-		handle_tx_callback(drv, buf, data_len, ver == 2 ? 1 : 0);
-		return;
-	} else if (ver != 0) {
-		printf("unknown protocol version %d\n", ver);
-		return;
-	}
-
-	switch (type) {
-	case WLAN_FC_TYPE_MGMT:
-		if (stype != WLAN_FC_STYPE_BEACON)
-			wpa_printf(MSG_MSGDUMP, "MGMT");
-		hostapd_mgmt_rx(drv->hapd, buf, data_len, stype, NULL);
-		break;
-	case WLAN_FC_TYPE_CTRL:
-		wpa_printf(MSG_DEBUG, "CTRL");
-		break;
-	case WLAN_FC_TYPE_DATA:
-		wpa_printf(MSG_DEBUG, "DATA");
-		handle_data(drv, buf, data_len, stype);
-		break;
-	default:
-		wpa_printf(MSG_DEBUG, "unknown frame type %d", type);
-		break;
-	}
-}
-
-
-static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	struct hostap_driver_data *drv = eloop_ctx;
-	int len;
-	unsigned char buf[3000];
-
-	len = recv(sock, buf, sizeof(buf), 0);
-	if (len < 0) {
-		perror("recv");
-		return;
-	}
-
-	handle_frame(drv, buf, len);
-}
-
-
-static int hostap_init_sockets(struct hostap_driver_data *drv)
-{
-	struct ifreq ifr;
-	struct sockaddr_ll addr;
-
-	drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
-	if (drv->sock < 0) {
-		perror("socket[PF_PACKET,SOCK_RAW]");
-		return -1;
-	}
-
-	if (eloop_register_read_sock(drv->sock, handle_read, drv, NULL)) {
-		printf("Could not register read socket\n");
-		return -1;
-	}
-
-        memset(&ifr, 0, sizeof(ifr));
-        snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
-        if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
-		perror("ioctl(SIOCGIFINDEX)");
-		return -1;
-        }
-
-	if (hostap_set_iface_flags(drv, 1)) {
-		return -1;
-	}
-
-	memset(&addr, 0, sizeof(addr));
-	addr.sll_family = AF_PACKET;
-	addr.sll_ifindex = ifr.ifr_ifindex;
-	wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
-		   addr.sll_ifindex);
-
-	if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		perror("bind");
-		return -1;
-	}
-
-        memset(&ifr, 0, sizeof(ifr));
-        os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
-        if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
-		perror("ioctl(SIOCGIFHWADDR)");
-		return -1;
-        }
-
-	if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
-		printf("Invalid HW-addr family 0x%04x\n",
-		       ifr.ifr_hwaddr.sa_family);
-		return -1;
-	}
-	memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
-	return 0;
-}
-
-
-static int hostap_send_mgmt_frame(void *priv, const void *msg, size_t len,
-				  int flags)
-{
-	struct hostap_driver_data *drv = priv;
-	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) msg;
-	int res;
-
-	/* Request TX callback */
-	hdr->frame_control |= host_to_le16(BIT(1));
-	res = send(drv->sock, msg, len, flags);
-	hdr->frame_control &= ~host_to_le16(BIT(1));
-
-	return res;
-}
-
-
-static int hostap_send_eapol(void *priv, const u8 *addr, const u8 *data,
-			     size_t data_len, int encrypt, const u8 *own_addr)
-{
-	struct hostap_driver_data *drv = priv;
-	struct ieee80211_hdr *hdr;
-	size_t len;
-	u8 *pos;
-	int res;
-
-	len = sizeof(*hdr) + sizeof(rfc1042_header) + 2 + data_len;
-	hdr = os_zalloc(len);
-	if (hdr == NULL) {
-		printf("malloc() failed for hostapd_send_data(len=%lu)\n",
-		       (unsigned long) len);
-		return -1;
-	}
-
-	hdr->frame_control =
-		IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
-	hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
-	if (encrypt)
-		hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
-	memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
-	memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
-	memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
-
-	pos = (u8 *) (hdr + 1);
-	memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
-	pos += sizeof(rfc1042_header);
-	*((u16 *) pos) = htons(ETH_P_PAE);
-	pos += 2;
-	memcpy(pos, data, data_len);
-
-	res = hostap_send_mgmt_frame(drv, (u8 *) hdr, len, 0);
-	free(hdr);
-
-	if (res < 0) {
-		perror("hostapd_send_eapol: send");
-		printf("hostapd_send_eapol - packet len: %lu - failed\n",
-		       (unsigned long) len);
-	}
-
-	return res;
-}
-
-
-static int hostap_sta_set_flags(void *priv, const u8 *addr,
-				int total_flags, int flags_or, int flags_and)
-{
-	struct hostap_driver_data *drv = priv;
-	struct prism2_hostapd_param param;
-
-	memset(&param, 0, sizeof(param));
-	param.cmd = PRISM2_HOSTAPD_SET_FLAGS_STA;
-	memcpy(param.sta_addr, addr, ETH_ALEN);
-	param.u.set_flags_sta.flags_or = flags_or;
-	param.u.set_flags_sta.flags_and = flags_and;
-	return hostapd_ioctl(drv, &param, sizeof(param));
-}
-
-
-static int hostap_set_iface_flags(void *priv, int dev_up)
-{
-	struct hostap_driver_data *drv = priv;
-	struct ifreq ifr;
-
-	if (drv->ioctl_sock < 0)
-		return -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-	snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
-
-	if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
-		perror("ioctl[SIOCGIFFLAGS]");
-		return -1;
-	}
-
-	if (dev_up)
-		ifr.ifr_flags |= IFF_UP;
-	else
-		ifr.ifr_flags &= ~IFF_UP;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
-		perror("ioctl[SIOCSIFFLAGS]");
-		return -1;
-	}
-
-	if (dev_up) {
-		memset(&ifr, 0, sizeof(ifr));
-		snprintf(ifr.ifr_name, IFNAMSIZ, "%sap", drv->iface);
-		ifr.ifr_mtu = HOSTAPD_MTU;
-		if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
-			perror("ioctl[SIOCSIFMTU]");
-			printf("Setting MTU failed - trying to survive with "
-			       "current value\n");
-		}
-	}
-
-	return 0;
-}
-
-
-static int hostapd_ioctl(void *priv, struct prism2_hostapd_param *param,
-			 int len)
-{
-	struct hostap_driver_data *drv = priv;
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.data.pointer = (caddr_t) param;
-	iwr.u.data.length = len;
-
-	if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_HOSTAPD, &iwr) < 0) {
-		perror("ioctl[PRISM2_IOCTL_HOSTAPD]");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int hostap_set_key(const char *ifname, void *priv, wpa_alg alg,
-			  const u8 *addr, int key_idx, int set_tx,
-			  const u8 *seq, size_t seq_len, const u8 *key,
-			  size_t key_len)
-{
-	struct hostap_driver_data *drv = priv;
-	struct prism2_hostapd_param *param;
-	u8 *buf;
-	size_t blen;
-	int ret = 0;
-
-	blen = sizeof(*param) + key_len;
-	buf = os_zalloc(blen);
-	if (buf == NULL)
-		return -1;
-
-	param = (struct prism2_hostapd_param *) buf;
-	param->cmd = PRISM2_SET_ENCRYPTION;
-	if (addr == NULL)
-		memset(param->sta_addr, 0xff, ETH_ALEN);
-	else
-		memcpy(param->sta_addr, addr, ETH_ALEN);
-	switch (alg) {
-	case WPA_ALG_NONE:
-		os_strlcpy((char *) param->u.crypt.alg, "NONE",
-			   HOSTAP_CRYPT_ALG_NAME_LEN);
-		break;
-	case WPA_ALG_WEP:
-		os_strlcpy((char *) param->u.crypt.alg, "WEP",
-			   HOSTAP_CRYPT_ALG_NAME_LEN);
-		break;
-	case WPA_ALG_TKIP:
-		os_strlcpy((char *) param->u.crypt.alg, "TKIP",
-			   HOSTAP_CRYPT_ALG_NAME_LEN);
-		break;
-	case WPA_ALG_CCMP:
-		os_strlcpy((char *) param->u.crypt.alg, "CCMP",
-			   HOSTAP_CRYPT_ALG_NAME_LEN);
-		break;
-	default:
-		os_free(buf);
-		return -1;
-	}
-	param->u.crypt.flags = set_tx ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
-	param->u.crypt.idx = key_idx;
-	param->u.crypt.key_len = key_len;
-	memcpy((u8 *) (param + 1), key, key_len);
-
-	if (hostapd_ioctl(drv, param, blen)) {
-		printf("Failed to set encryption.\n");
-		ret = -1;
-	}
-	free(buf);
-
-	return ret;
-}
-
-
-static int hostap_get_seqnum(const char *ifname, void *priv, const u8 *addr,
-			     int idx, u8 *seq)
-{
-	struct hostap_driver_data *drv = priv;
-	struct prism2_hostapd_param *param;
-	u8 *buf;
-	size_t blen;
-	int ret = 0;
-
-	blen = sizeof(*param) + 32;
-	buf = os_zalloc(blen);
-	if (buf == NULL)
-		return -1;
-
-	param = (struct prism2_hostapd_param *) buf;
-	param->cmd = PRISM2_GET_ENCRYPTION;
-	if (addr == NULL)
-		memset(param->sta_addr, 0xff, ETH_ALEN);
-	else
-		memcpy(param->sta_addr, addr, ETH_ALEN);
-	param->u.crypt.idx = idx;
-
-	if (hostapd_ioctl(drv, param, blen)) {
-		printf("Failed to get encryption.\n");
-		ret = -1;
-	} else {
-		memcpy(seq, param->u.crypt.seq, 8);
-	}
-	free(buf);
-
-	return ret;
-}
-
-
-static int hostap_ioctl_prism2param(void *priv, int param, int value)
-{
-	struct hostap_driver_data *drv = priv;
-	struct iwreq iwr;
-	int *i;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	i = (int *) iwr.u.name;
-	*i++ = param;
-	*i++ = value;
-
-	if (ioctl(drv->ioctl_sock, PRISM2_IOCTL_PRISM2_PARAM, &iwr) < 0) {
-		perror("ioctl[PRISM2_IOCTL_PRISM2_PARAM]");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int hostap_set_ieee8021x(const char *ifname, void *priv, int enabled)
-{
-	struct hostap_driver_data *drv = priv;
-
-	/* enable kernel driver support for IEEE 802.1X */
-	if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_IEEE_802_1X, enabled)) {
-		printf("Could not setup IEEE 802.1X support in kernel driver."
-		       "\n");
-		return -1;
-	}
-
-	if (!enabled)
-		return 0;
-
-	/* use host driver implementation of encryption to allow
-	 * individual keys and passing plaintext EAPOL frames */
-	if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_DECRYPT, 1) ||
-	    hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOST_ENCRYPT, 1)) {
-		printf("Could not setup host-based encryption in kernel "
-		       "driver.\n");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int hostap_set_privacy(const char *ifname, void *priv, int enabled)
-{
-	struct hostap_drvier_data *drv = priv;
-
-	return hostap_ioctl_prism2param(drv, PRISM2_PARAM_PRIVACY_INVOKED,
-					enabled);
-}
-
- 
-static int hostap_set_ssid(const char *ifname, void *priv, const u8 *buf,
-			   int len)
-{
-	struct hostap_driver_data *drv = priv;
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.essid.flags = 1; /* SSID active */
-	iwr.u.essid.pointer = (caddr_t) buf;
-	iwr.u.essid.length = len + 1;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
-		perror("ioctl[SIOCSIWESSID]");
-		printf("len=%d\n", len);
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int hostap_flush(void *priv)
-{
-	struct hostap_driver_data *drv = priv;
-	struct prism2_hostapd_param param;
-
-	memset(&param, 0, sizeof(param));
-	param.cmd = PRISM2_HOSTAPD_FLUSH;
-	return hostapd_ioctl(drv, &param, sizeof(param));
-}
-
-
-static int hostap_read_sta_data(void *priv,
-				struct hostap_sta_driver_data *data,
-				const u8 *addr)
-{
-	struct hostap_driver_data *drv = priv;
-	char buf[1024], line[128], *pos;
-	FILE *f;
-	unsigned long val;
-
-	memset(data, 0, sizeof(*data));
-	snprintf(buf, sizeof(buf), "/proc/net/hostap/%s/" MACSTR,
-		 drv->iface, MAC2STR(addr));
-
-	f = fopen(buf, "r");
-	if (!f)
-		return -1;
-	/* Need to read proc file with in one piece, so use large enough
-	 * buffer. */
-	setbuffer(f, buf, sizeof(buf));
-
-	while (fgets(line, sizeof(line), f)) {
-		pos = strchr(line, '=');
-		if (!pos)
-			continue;
-		*pos++ = '\0';
-		val = strtoul(pos, NULL, 10);
-		if (strcmp(line, "rx_packets") == 0)
-			data->rx_packets = val;
-		else if (strcmp(line, "tx_packets") == 0)
-			data->tx_packets = val;
-		else if (strcmp(line, "rx_bytes") == 0)
-			data->rx_bytes = val;
-		else if (strcmp(line, "tx_bytes") == 0)
-			data->tx_bytes = val;
-	}
-
-	fclose(f);
-
-	return 0;
-}
-
-
-static int hostap_sta_add(const char *ifname, void *priv,
-			  struct hostapd_sta_add_params *params)
-{
-	struct hostap_driver_data *drv = priv;
-	struct prism2_hostapd_param param;
-	int tx_supp_rates = 0;
-	size_t i;
-
-#define WLAN_RATE_1M BIT(0)
-#define WLAN_RATE_2M BIT(1)
-#define WLAN_RATE_5M5 BIT(2)
-#define WLAN_RATE_11M BIT(3)
-
-	for (i = 0; i < params->supp_rates_len; i++) {
-		if ((params->supp_rates[i] & 0x7f) == 2)
-			tx_supp_rates |= WLAN_RATE_1M;
-		if ((params->supp_rates[i] & 0x7f) == 4)
-			tx_supp_rates |= WLAN_RATE_2M;
-		if ((params->supp_rates[i] & 0x7f) == 11)
-			tx_supp_rates |= WLAN_RATE_5M5;
-		if ((params->supp_rates[i] & 0x7f) == 22)
-			tx_supp_rates |= WLAN_RATE_11M;
-	}
-
-	memset(&param, 0, sizeof(param));
-	param.cmd = PRISM2_HOSTAPD_ADD_STA;
-	memcpy(param.sta_addr, params->addr, ETH_ALEN);
-	param.u.add_sta.aid = params->aid;
-	param.u.add_sta.capability = params->capability;
-	param.u.add_sta.tx_supp_rates = tx_supp_rates;
-	return hostapd_ioctl(drv, &param, sizeof(param));
-}
-
-
-static int hostap_sta_remove(void *priv, const u8 *addr)
-{
-	struct hostap_driver_data *drv = priv;
-	struct prism2_hostapd_param param;
-
-	hostap_sta_set_flags(drv, addr, 0, 0, ~WLAN_STA_AUTHORIZED);
-
-	memset(&param, 0, sizeof(param));
-	param.cmd = PRISM2_HOSTAPD_REMOVE_STA;
-	memcpy(param.sta_addr, addr, ETH_ALEN);
-	if (hostapd_ioctl(drv, &param, sizeof(param))) {
-		printf("Could not remove station from kernel driver.\n");
-		return -1;
-	}
-	return 0;
-}
-
-
-static int hostap_get_inact_sec(void *priv, const u8 *addr)
-{
-	struct hostap_driver_data *drv = priv;
-	struct prism2_hostapd_param param;
-
-	memset(&param, 0, sizeof(param));
-	param.cmd = PRISM2_HOSTAPD_GET_INFO_STA;
-	memcpy(param.sta_addr, addr, ETH_ALEN);
-	if (hostapd_ioctl(drv, &param, sizeof(param))) {
-		return -1;
-	}
-
-	return param.u.get_info_sta.inactive_sec;
-}
-
-
-static int hostap_sta_clear_stats(void *priv, const u8 *addr)
-{
-	struct hostap_driver_data *drv = priv;
-	struct prism2_hostapd_param param;
-
-	memset(&param, 0, sizeof(param));
-	param.cmd = PRISM2_HOSTAPD_STA_CLEAR_STATS;
-	memcpy(param.sta_addr, addr, ETH_ALEN);
-	if (hostapd_ioctl(drv, &param, sizeof(param))) {
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int hostapd_ioctl_set_generic_elem(struct hostap_driver_data *drv)
-{
-	struct prism2_hostapd_param *param;
-	int res;
-	size_t blen, elem_len;
-
-	elem_len = drv->generic_ie_len + drv->wps_ie_len;
-	blen = PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN + elem_len;
-	if (blen < sizeof(*param))
-		blen = sizeof(*param);
-
-	param = os_zalloc(blen);
-	if (param == NULL)
-		return -1;
-
-	param->cmd = PRISM2_HOSTAPD_SET_GENERIC_ELEMENT;
-	param->u.generic_elem.len = elem_len;
-	if (drv->generic_ie) {
-		os_memcpy(param->u.generic_elem.data, drv->generic_ie,
-			  drv->generic_ie_len);
-	}
-	if (drv->wps_ie) {
-		os_memcpy(&param->u.generic_elem.data[drv->generic_ie_len],
-			  drv->wps_ie, drv->wps_ie_len);
-	}
-	wpa_hexdump(MSG_DEBUG, "hostap: Set generic IE",
-		    param->u.generic_elem.data, elem_len);
-	res = hostapd_ioctl(drv, param, blen);
-
-	os_free(param);
-
-	return res;
-}
-
-
-static int hostap_set_generic_elem(const char *ifname, void *priv,
-				   const u8 *elem, size_t elem_len)
-{
-	struct hostap_driver_data *drv = priv;
-
-	os_free(drv->generic_ie);
-	drv->generic_ie = NULL;
-	drv->generic_ie_len = 0;
-	if (elem) {
-		drv->generic_ie = os_malloc(elem_len);
-		if (drv->generic_ie == NULL)
-			return -1;
-		os_memcpy(drv->generic_ie, elem, elem_len);
-		drv->generic_ie_len = elem_len;
-	}
-
-	return hostapd_ioctl_set_generic_elem(drv);
-}
-
-
-static int hostap_set_wps_beacon_ie(const char *ifname, void *priv,
-				    const u8 *ie, size_t len)
-{
-	/* Host AP driver supports only one set of extra IEs, so we need to
-	 * use the ProbeResp IEs also for Beacon frames since they include more
-	 * information. */
-	return 0;
-}
-
-
-static int hostap_set_wps_probe_resp_ie(const char *ifname, void *priv,
-					const u8 *ie, size_t len)
-{
-	struct hostap_driver_data *drv = priv;
-
-	os_free(drv->wps_ie);
-	drv->wps_ie = NULL;
-	drv->wps_ie_len = 0;
-	if (ie) {
-		drv->wps_ie = os_malloc(len);
-		if (drv->wps_ie == NULL)
-			return -1;
-		os_memcpy(drv->wps_ie, ie, len);
-		drv->wps_ie_len = len;
-	}
-
-	return hostapd_ioctl_set_generic_elem(drv);
-}
-
-
-static void
-hostapd_wireless_event_wireless_custom(struct hostap_driver_data *drv,
-				       char *custom)
-{
-	wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
-
-	if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
-		char *pos;
-		u8 addr[ETH_ALEN];
-		pos = strstr(custom, "addr=");
-		if (pos == NULL) {
-			wpa_printf(MSG_DEBUG,
-				   "MLME-MICHAELMICFAILURE.indication "
-				   "without sender address ignored");
-			return;
-		}
-		pos += 5;
-		if (hwaddr_aton(pos, addr) == 0) {
-			hostapd_michael_mic_failure(drv->hapd, addr);
-		} else {
-			wpa_printf(MSG_DEBUG,
-				   "MLME-MICHAELMICFAILURE.indication "
-				   "with invalid MAC address");
-		}
-	}
-}
-
-
-static void hostapd_wireless_event_wireless(struct hostap_driver_data *drv,
-					    char *data, int len)
-{
-	struct iw_event iwe_buf, *iwe = &iwe_buf;
-	char *pos, *end, *custom, *buf;
-
-	pos = data;
-	end = data + len;
-
-	while (pos + IW_EV_LCP_LEN <= end) {
-		/* Event data may be unaligned, so make a local, aligned copy
-		 * before processing. */
-		memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
-		wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
-			   iwe->cmd, iwe->len);
-		if (iwe->len <= IW_EV_LCP_LEN)
-			return;
-
-		custom = pos + IW_EV_POINT_LEN;
-		if (drv->we_version > 18 &&
-		    (iwe->cmd == IWEVMICHAELMICFAILURE ||
-		     iwe->cmd == IWEVCUSTOM)) {
-			/* WE-19 removed the pointer from struct iw_point */
-			char *dpos = (char *) &iwe_buf.u.data.length;
-			int dlen = dpos - (char *) &iwe_buf;
-			memcpy(dpos, pos + IW_EV_LCP_LEN,
-			       sizeof(struct iw_event) - dlen);
-		} else {
-			memcpy(&iwe_buf, pos, sizeof(struct iw_event));
-			custom += IW_EV_POINT_OFF;
-		}
-
-		switch (iwe->cmd) {
-		case IWEVCUSTOM:
-			if (custom + iwe->u.data.length > end)
-				return;
-			buf = malloc(iwe->u.data.length + 1);
-			if (buf == NULL)
-				return;
-			memcpy(buf, custom, iwe->u.data.length);
-			buf[iwe->u.data.length] = '\0';
-			hostapd_wireless_event_wireless_custom(drv, buf);
-			free(buf);
-			break;
-		}
-
-		pos += iwe->len;
-	}
-}
-
-
-static void hostapd_wireless_event_rtm_newlink(struct hostap_driver_data *drv,
-					       struct nlmsghdr *h, int len)
-{
-	struct ifinfomsg *ifi;
-	int attrlen, nlmsg_len, rta_len;
-	struct rtattr * attr;
-
-	if (len < (int) sizeof(*ifi))
-		return;
-
-	ifi = NLMSG_DATA(h);
-
-	/* TODO: use ifi->ifi_index to filter out wireless events from other
-	 * interfaces */
-
-	nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
-
-	attrlen = h->nlmsg_len - nlmsg_len;
-	if (attrlen < 0)
-		return;
-
-	attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
-
-	rta_len = RTA_ALIGN(sizeof(struct rtattr));
-	while (RTA_OK(attr, attrlen)) {
-		if (attr->rta_type == IFLA_WIRELESS) {
-			hostapd_wireless_event_wireless(
-				drv, ((char *) attr) + rta_len,
-				attr->rta_len - rta_len);
-		}
-		attr = RTA_NEXT(attr, attrlen);
-	}
-}
-
-
-static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
-					   void *sock_ctx)
-{
-	char buf[256];
-	int left;
-	struct sockaddr_nl from;
-	socklen_t fromlen;
-	struct nlmsghdr *h;
-	struct hostap_driver_data *drv = eloop_ctx;
-
-	fromlen = sizeof(from);
-	left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
-			(struct sockaddr *) &from, &fromlen);
-	if (left < 0) {
-		if (errno != EINTR && errno != EAGAIN)
-			perror("recvfrom(netlink)");
-		return;
-	}
-
-	h = (struct nlmsghdr *) buf;
-	while (left >= (int) sizeof(*h)) {
-		int len, plen;
-
-		len = h->nlmsg_len;
-		plen = len - sizeof(*h);
-		if (len > left || plen < 0) {
-			printf("Malformed netlink message: "
-			       "len=%d left=%d plen=%d\n",
-			       len, left, plen);
-			break;
-		}
-
-		switch (h->nlmsg_type) {
-		case RTM_NEWLINK:
-			hostapd_wireless_event_rtm_newlink(drv, h, plen);
-			break;
-		}
-
-		len = NLMSG_ALIGN(len);
-		left -= len;
-		h = (struct nlmsghdr *) ((char *) h + len);
-	}
-
-	if (left > 0) {
-		printf("%d extra bytes in the end of netlink message\n", left);
-	}
-}
-
-
-static int hostap_get_we_version(struct hostap_driver_data *drv)
-{
-	struct iw_range *range;
-	struct iwreq iwr;
-	int minlen;
-	size_t buflen;
-
-	drv->we_version = 0;
-
-	/*
-	 * Use larger buffer than struct iw_range in order to allow the
-	 * structure to grow in the future.
-	 */
-	buflen = sizeof(struct iw_range) + 500;
-	range = os_zalloc(buflen);
-	if (range == NULL)
-		return -1;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.data.pointer = (caddr_t) range;
-	iwr.u.data.length = buflen;
-
-	minlen = ((char *) &range->enc_capa) - (char *) range +
-		sizeof(range->enc_capa);
-
-	if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
-		perror("ioctl[SIOCGIWRANGE]");
-		free(range);
-		return -1;
-	} else if (iwr.u.data.length >= minlen &&
-		   range->we_version_compiled >= 18) {
-		wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
-			   "WE(source)=%d enc_capa=0x%x",
-			   range->we_version_compiled,
-			   range->we_version_source,
-			   range->enc_capa);
-		drv->we_version = range->we_version_compiled;
-	}
-
-	free(range);
-	return 0;
-}
-
-
-static int hostap_wireless_event_init(struct hostap_driver_data *drv)
-{
-	int s;
-	struct sockaddr_nl local;
-
-	hostap_get_we_version(drv);
-
-	drv->wext_sock = -1;
-
-	s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-	if (s < 0) {
-		perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
-		return -1;
-	}
-
-	memset(&local, 0, sizeof(local));
-	local.nl_family = AF_NETLINK;
-	local.nl_groups = RTMGRP_LINK;
-	if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
-		perror("bind(netlink)");
-		close(s);
-		return -1;
-	}
-
-	eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
-				 NULL);
-	drv->wext_sock = s;
-
-	return 0;
-}
-
-
-static void hostap_wireless_event_deinit(struct hostap_driver_data *drv)
-{
-	if (drv->wext_sock < 0)
-		return;
-	eloop_unregister_read_sock(drv->wext_sock);
-	close(drv->wext_sock);
-}
-
-
-static void * hostap_init(struct hostapd_data *hapd)
-{
-	struct hostap_driver_data *drv;
-
-	drv = os_zalloc(sizeof(struct hostap_driver_data));
-	if (drv == NULL) {
-		printf("Could not allocate memory for hostapd driver data\n");
-		return NULL;
-	}
-
-	drv->hapd = hapd;
-	drv->ioctl_sock = drv->sock = -1;
-	memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
-
-	drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
-	if (drv->ioctl_sock < 0) {
-		perror("socket[PF_INET,SOCK_DGRAM]");
-		free(drv);
-		return NULL;
-	}
-
-	if (hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 1)) {
-		printf("Could not enable hostapd mode for interface %s\n",
-		       drv->iface);
-		close(drv->ioctl_sock);
-		free(drv);
-		return NULL;
-	}
-
-	if (hostap_init_sockets(drv) || hostap_wireless_event_init(drv)) {
-		close(drv->ioctl_sock);
-		free(drv);
-		return NULL;
-	}
-
-	return drv;
-}
-
-
-static void hostap_driver_deinit(void *priv)
-{
-	struct hostap_driver_data *drv = priv;
-
-	hostap_wireless_event_deinit(drv);
-	(void) hostap_set_iface_flags(drv, 0);
-	(void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD, 0);
-	(void) hostap_ioctl_prism2param(drv, PRISM2_PARAM_HOSTAPD_STA, 0);
-
-	if (drv->ioctl_sock >= 0)
-		close(drv->ioctl_sock);
-
-	if (drv->sock >= 0)
-		close(drv->sock);
-
-	os_free(drv->generic_ie);
-	os_free(drv->wps_ie);
-
-	free(drv);
-}
-
-
-static int hostap_sta_deauth(void *priv, const u8 *addr, int reason)
-{
-	struct hostap_driver_data *drv = priv;
-	struct ieee80211_mgmt mgmt;
-
-	memset(&mgmt, 0, sizeof(mgmt));
-	mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
-					  WLAN_FC_STYPE_DEAUTH);
-	memcpy(mgmt.da, addr, ETH_ALEN);
-	memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
-	memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
-	mgmt.u.deauth.reason_code = host_to_le16(reason);
-	return hostap_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
-				      sizeof(mgmt.u.deauth), 0);
-}
-
-
-static int hostap_sta_disassoc(void *priv, const u8 *addr, int reason)
-{
-	struct hostap_driver_data *drv = priv;
-	struct ieee80211_mgmt mgmt;
-
-	memset(&mgmt, 0, sizeof(mgmt));
-	mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
-					  WLAN_FC_STYPE_DISASSOC);
-	memcpy(mgmt.da, addr, ETH_ALEN);
-	memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
-	memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
-	mgmt.u.disassoc.reason_code = host_to_le16(reason);
-	return  hostap_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
-				       sizeof(mgmt.u.disassoc), 0);
-}
-
-
-static struct hostapd_hw_modes * hostap_get_hw_feature_data(void *priv,
-							    u16 *num_modes,
-							    u16 *flags)
-{
-	struct hostapd_hw_modes *mode;
-	int i, clen, rlen;
-	const short chan2freq[14] = {
-		2412, 2417, 2422, 2427, 2432, 2437, 2442,
-		2447, 2452, 2457, 2462, 2467, 2472, 2484
-	};
-
-	mode = os_zalloc(sizeof(struct hostapd_hw_modes));
-	if (mode == NULL)
-		return NULL;
-
-	*num_modes = 1;
-	*flags = 0;
-
-	mode->mode = HOSTAPD_MODE_IEEE80211B;
-	mode->num_channels = 14;
-	mode->num_rates = 4;
-
-	clen = mode->num_channels * sizeof(struct hostapd_channel_data);
-	rlen = mode->num_rates * sizeof(struct hostapd_rate_data);
-
-	mode->channels = os_zalloc(clen);
-	mode->rates = os_zalloc(rlen);
-	if (mode->channels == NULL || mode->rates == NULL) {
-		hostapd_free_hw_features(mode, *num_modes);
-		return NULL;
-	}
-
-	for (i = 0; i < 14; i++) {
-		mode->channels[i].chan = i + 1;
-		mode->channels[i].freq = chan2freq[i];
-		/* TODO: Get allowed channel list from the driver */
-		if (i >= 11)
-			mode->channels[i].flag = HOSTAPD_CHAN_DISABLED;
-	}
-
-	mode->rates[0].rate = 10;
-	mode->rates[0].flags = HOSTAPD_RATE_CCK;
-	mode->rates[1].rate = 20;
-	mode->rates[1].flags = HOSTAPD_RATE_CCK;
-	mode->rates[2].rate = 55;
-	mode->rates[2].flags = HOSTAPD_RATE_CCK;
-	mode->rates[3].rate = 110;
-	mode->rates[3].flags = HOSTAPD_RATE_CCK;
-
-	return mode;
-}
-
-
-const struct hapd_driver_ops wpa_driver_hostap_ops = {
-	.name = "hostap",
-	.init = hostap_init,
-	.deinit = hostap_driver_deinit,
-	.set_ieee8021x = hostap_set_ieee8021x,
-	.set_privacy = hostap_set_privacy,
-	.set_key = hostap_set_key,
-	.get_seqnum = hostap_get_seqnum,
-	.flush = hostap_flush,
-	.set_generic_elem = hostap_set_generic_elem,
-	.read_sta_data = hostap_read_sta_data,
-	.send_eapol = hostap_send_eapol,
-	.sta_set_flags = hostap_sta_set_flags,
-	.sta_deauth = hostap_sta_deauth,
-	.sta_disassoc = hostap_sta_disassoc,
-	.sta_remove = hostap_sta_remove,
-	.set_ssid = hostap_set_ssid,
-	.send_mgmt_frame = hostap_send_mgmt_frame,
-	.sta_add = hostap_sta_add,
-	.get_inact_sec = hostap_get_inact_sec,
-	.sta_clear_stats = hostap_sta_clear_stats,
-	.get_hw_feature_data = hostap_get_hw_feature_data,
-	.set_wps_beacon_ie = hostap_set_wps_beacon_ie,
-	.set_wps_probe_resp_ie = hostap_set_wps_probe_resp_ie,
-};

+ 35 - 30
hostapd/driver_i.h

@@ -16,15 +16,15 @@
 #ifndef DRIVER_I_H
 #define DRIVER_I_H
 
-#include "driver.h"
+#include "drivers/driver.h"
 #include "config.h"
 
 static inline void *
 hostapd_driver_init(struct hostapd_data *hapd)
 {
-	if (hapd->driver == NULL || hapd->driver->init == NULL)
+	if (hapd->driver == NULL || hapd->driver->hapd_init == NULL)
 		return NULL;
-	return hapd->driver->init(hapd);
+	return hapd->driver->hapd_init(hapd);
 }
 
 static inline void *
@@ -38,9 +38,9 @@ hostapd_driver_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
 static inline void
 hostapd_driver_deinit(struct hostapd_data *hapd)
 {
-	if (hapd->driver == NULL || hapd->driver->deinit == NULL)
+	if (hapd->driver == NULL || hapd->driver->hapd_deinit == NULL)
 		return;
-	hapd->driver->deinit(hapd->drv_priv);
+	hapd->driver->hapd_deinit(hapd->drv_priv);
 }
 
 static inline int
@@ -67,11 +67,11 @@ hostapd_set_key(const char *ifname, struct hostapd_data *hapd,
 		int set_tx, const u8 *seq, size_t seq_len,
 		const u8 *key, size_t key_len)
 {
-	if (hapd->driver == NULL || hapd->driver->set_key == NULL)
+	if (hapd->driver == NULL || hapd->driver->hapd_set_key == NULL)
 		return 0;
-	return hapd->driver->set_key(ifname, hapd->drv_priv, alg, addr,
-				     key_idx, set_tx, seq, seq_len, key,
-				     key_len);
+	return hapd->driver->hapd_set_key(ifname, hapd->drv_priv, alg, addr,
+					  key_idx, set_tx, seq, seq_len, key,
+					  key_len);
 }
 
 static inline int
@@ -125,10 +125,11 @@ static inline int
 hostapd_send_eapol(struct hostapd_data *hapd, const u8 *addr, const u8 *data,
 		   size_t data_len, int encrypt)
 {
-	if (hapd->driver == NULL || hapd->driver->send_eapol == NULL)
+	if (hapd->driver == NULL || hapd->driver->hapd_send_eapol == NULL)
 		return 0;
-	return hapd->driver->send_eapol(hapd->drv_priv, addr, data, data_len,
-					encrypt, hapd->own_addr);
+	return hapd->driver->hapd_send_eapol(hapd->drv_priv, addr, data,
+					     data_len, encrypt,
+					     hapd->own_addr);
 }
 
 static inline int
@@ -158,19 +159,19 @@ hostapd_sta_remove(struct hostapd_data *hapd, const u8 *addr)
 static inline int
 hostapd_get_ssid(struct hostapd_data *hapd, u8 *buf, size_t len)
 {
-	if (hapd->driver == NULL || hapd->driver->get_ssid == NULL)
+	if (hapd->driver == NULL || hapd->driver->hapd_get_ssid == NULL)
 		return 0;
-	return hapd->driver->get_ssid(hapd->conf->iface, hapd->drv_priv, buf,
-				      len);
+	return hapd->driver->hapd_get_ssid(hapd->conf->iface, hapd->drv_priv,
+					   buf, len);
 }
 
 static inline int
 hostapd_set_ssid(struct hostapd_data *hapd, const u8 *buf, size_t len)
 {
-	if (hapd->driver == NULL || hapd->driver->set_ssid == NULL)
+	if (hapd->driver == NULL || hapd->driver->hapd_set_ssid == NULL)
 		return 0;
-	return hapd->driver->set_ssid(hapd->conf->iface, hapd->drv_priv, buf,
-				      len);
+	return hapd->driver->hapd_set_ssid(hapd->conf->iface, hapd->drv_priv,
+					   buf, len);
 }
 
 static inline int
@@ -185,9 +186,10 @@ hostapd_send_mgmt_frame(struct hostapd_data *hapd, const void *msg, size_t len,
 static inline int
 hostapd_set_countermeasures(struct hostapd_data *hapd, int enabled)
 {
-	if (hapd->driver == NULL || hapd->driver->set_countermeasures == NULL)
+	if (hapd->driver == NULL ||
+	    hapd->driver->hapd_set_countermeasures == NULL)
 		return 0;
-	return hapd->driver->set_countermeasures(hapd->drv_priv, enabled);
+	return hapd->driver->hapd_set_countermeasures(hapd->drv_priv, enabled);
 }
 
 static inline int
@@ -290,9 +292,9 @@ static inline int
 hostapd_set_country(struct hostapd_data *hapd, const char *country)
 {
 	if (hapd->driver == NULL ||
-	    hapd->driver->set_country == NULL)
+	    hapd->driver->hapd_set_country == NULL)
 		return 0;
-	return hapd->driver->set_country(hapd->drv_priv, country);
+	return hapd->driver->hapd_set_country(hapd->drv_priv, country);
 }
 
 static inline int
@@ -317,10 +319,11 @@ hostapd_set_beacon(const char *ifname, struct hostapd_data *hapd,
 		   const u8 *head, size_t head_len,
 		   const u8 *tail, size_t tail_len, int dtim_period)
 {
-	if (hapd->driver == NULL || hapd->driver->set_beacon == NULL)
+	if (hapd->driver == NULL || hapd->driver->hapd_set_beacon == NULL)
 		return 0;
-	return hapd->driver->set_beacon(ifname, hapd->drv_priv, head, head_len,
-					tail, tail_len, dtim_period);
+	return hapd->driver->hapd_set_beacon(ifname, hapd->drv_priv,
+					     head, head_len,
+					     tail, tail_len, dtim_period);
 }
 
 static inline int
@@ -334,9 +337,9 @@ hostapd_set_internal_bridge(struct hostapd_data *hapd, int value)
 static inline int
 hostapd_set_beacon_int(struct hostapd_data *hapd, int value)
 {
-	if (hapd->driver == NULL || hapd->driver->set_beacon_int == NULL)
+	if (hapd->driver == NULL || hapd->driver->hapd_set_beacon_int == NULL)
 		return 0;
-	return hapd->driver->set_beacon_int(hapd->drv_priv, value);
+	return hapd->driver->hapd_set_beacon_int(hapd->drv_priv, value);
 }
 
 static inline int
@@ -449,10 +452,12 @@ static inline struct hostapd_hw_modes *
 hostapd_get_hw_feature_data(struct hostapd_data *hapd, u16 *num_modes,
 			    u16 *flags)
 {
-	if (hapd->driver == NULL || hapd->driver->get_hw_feature_data == NULL)
+	if (hapd->driver == NULL ||
+	    hapd->driver->hapd_get_hw_feature_data == NULL)
 		return NULL;
-	return hapd->driver->get_hw_feature_data(hapd->drv_priv, num_modes,
-						 flags);
+	return hapd->driver->hapd_get_hw_feature_data(hapd->drv_priv,
+						      num_modes,
+						      flags);
 }
 
 static inline int

+ 0 - 1396
hostapd/driver_madwifi.c

@@ -1,1396 +0,0 @@
-/*
- * hostapd / Driver interaction with MADWIFI 802.11 driver
- * Copyright (c) 2004, Sam Leffler <sam@errno.com>
- * Copyright (c) 2004, Video54 Technologies
- * Copyright (c) 2005-2007, 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 "includes.h"
-#include <net/if.h>
-#include <sys/ioctl.h>
-
-#include <include/compat.h>
-#include <net80211/ieee80211.h>
-#ifdef WME_NUM_AC
-/* Assume this is built against BSD branch of madwifi driver. */
-#define MADWIFI_BSD
-#include <net80211/_ieee80211.h>
-#endif /* WME_NUM_AC */
-#include <net80211/ieee80211_crypto.h>
-#include <net80211/ieee80211_ioctl.h>
-
-#ifdef CONFIG_WPS
-#ifdef IEEE80211_IOCTL_FILTERFRAME
-#include <netpacket/packet.h>
-
-#ifndef ETH_P_80211_RAW
-#define ETH_P_80211_RAW 0x0019
-#endif
-#endif /* IEEE80211_IOCTL_FILTERFRAME */
-#endif /* CONFIG_WPS */
-
-/*
- * Avoid conflicts with hostapd definitions by undefining couple of defines
- * from madwifi header files.
- */
-#undef RSN_VERSION
-#undef WPA_VERSION
-#undef WPA_OUI_TYPE
-#undef WME_OUI_TYPE
-
-
-#ifdef IEEE80211_IOCTL_SETWMMPARAMS
-/* Assume this is built against madwifi-ng */
-#define MADWIFI_NG
-#endif /* IEEE80211_IOCTL_SETWMMPARAMS */
-
-#include "wireless_copy.h"
-
-#include "hostapd.h"
-#include "config.h"
-#include "driver.h"
-#include "eloop.h"
-#include "priv_netlink.h"
-#include "l2_packet/l2_packet.h"
-
-#include "common.h"
-#include "wps_hostapd.h"
-#include "ieee802_11_defs.h"
-
-
-struct madwifi_driver_data {
-	struct hostapd_data *hapd;		/* back pointer */
-
-	char	iface[IFNAMSIZ + 1];
-	int     ifindex;
-	struct l2_packet_data *sock_xmit;	/* raw packet xmit socket */
-	struct l2_packet_data *sock_recv;	/* raw packet recv socket */
-	int	ioctl_sock;			/* socket for ioctl() use */
-	int	wext_sock;			/* socket for wireless events */
-	int	we_version;
-	u8	acct_mac[ETH_ALEN];
-	struct hostap_sta_driver_data acct_data;
-
-	struct l2_packet_data *sock_raw; /* raw 802.11 management frames */
-};
-
-static int madwifi_sta_deauth(void *priv, const u8 *addr, int reason_code);
-
-static int
-set80211priv(struct madwifi_driver_data *drv, int op, void *data, int len)
-{
-	struct iwreq iwr;
-	int do_inline = len < IFNAMSIZ;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-#ifdef IEEE80211_IOCTL_FILTERFRAME
-	/* FILTERFRAME must be NOT inline, regardless of size. */
-	if (op == IEEE80211_IOCTL_FILTERFRAME)
-		do_inline = 0;
-#endif /* IEEE80211_IOCTL_FILTERFRAME */
-	if (op == IEEE80211_IOCTL_SET_APPIEBUF)
-		do_inline = 0;
-	if (do_inline) {
-		/*
-		 * Argument data fits inline; put it there.
-		 */
-		memcpy(iwr.u.name, data, len);
-	} else {
-		/*
-		 * Argument data too big for inline transfer; setup a
-		 * parameter block instead; the kernel will transfer
-		 * the data for the driver.
-		 */
-		iwr.u.data.pointer = data;
-		iwr.u.data.length = len;
-	}
-
-	if (ioctl(drv->ioctl_sock, op, &iwr) < 0) {
-#ifdef MADWIFI_NG
-		int first = IEEE80211_IOCTL_SETPARAM;
-		static const char *opnames[] = {
-			"ioctl[IEEE80211_IOCTL_SETPARAM]",
-			"ioctl[IEEE80211_IOCTL_GETPARAM]",
-			"ioctl[IEEE80211_IOCTL_SETMODE]",
-			"ioctl[IEEE80211_IOCTL_GETMODE]",
-			"ioctl[IEEE80211_IOCTL_SETWMMPARAMS]",
-			"ioctl[IEEE80211_IOCTL_GETWMMPARAMS]",
-			"ioctl[IEEE80211_IOCTL_SETCHANLIST]",
-			"ioctl[IEEE80211_IOCTL_GETCHANLIST]",
-			"ioctl[IEEE80211_IOCTL_CHANSWITCH]",
-			"ioctl[IEEE80211_IOCTL_GET_APPIEBUF]",
-			"ioctl[IEEE80211_IOCTL_SET_APPIEBUF]",
-			"ioctl[IEEE80211_IOCTL_GETSCANRESULTS]",
-			"ioctl[IEEE80211_IOCTL_FILTERFRAME]",
-			"ioctl[IEEE80211_IOCTL_GETCHANINFO]",
-			"ioctl[IEEE80211_IOCTL_SETOPTIE]",
-			"ioctl[IEEE80211_IOCTL_GETOPTIE]",
-			"ioctl[IEEE80211_IOCTL_SETMLME]",
-			NULL,
-			"ioctl[IEEE80211_IOCTL_SETKEY]",
-			NULL,
-			"ioctl[IEEE80211_IOCTL_DELKEY]",
-			NULL,
-			"ioctl[IEEE80211_IOCTL_ADDMAC]",
-			NULL,
-			"ioctl[IEEE80211_IOCTL_DELMAC]",
-			NULL,
-			"ioctl[IEEE80211_IOCTL_WDSMAC]",
-			NULL,
-			"ioctl[IEEE80211_IOCTL_WDSDELMAC]",
-			NULL,
-			"ioctl[IEEE80211_IOCTL_KICKMAC]",
-		};
-#else /* MADWIFI_NG */
-		int first = IEEE80211_IOCTL_SETPARAM;
-		static const char *opnames[] = {
-			"ioctl[IEEE80211_IOCTL_SETPARAM]",
-			"ioctl[IEEE80211_IOCTL_GETPARAM]",
-			"ioctl[IEEE80211_IOCTL_SETKEY]",
-			"ioctl[SIOCIWFIRSTPRIV+3]",
-			"ioctl[IEEE80211_IOCTL_DELKEY]",
-			"ioctl[SIOCIWFIRSTPRIV+5]",
-			"ioctl[IEEE80211_IOCTL_SETMLME]",
-			"ioctl[SIOCIWFIRSTPRIV+7]",
-			"ioctl[IEEE80211_IOCTL_SETOPTIE]",
-			"ioctl[IEEE80211_IOCTL_GETOPTIE]",
-			"ioctl[IEEE80211_IOCTL_ADDMAC]",
-			"ioctl[SIOCIWFIRSTPRIV+11]",
-			"ioctl[IEEE80211_IOCTL_DELMAC]",
-			"ioctl[SIOCIWFIRSTPRIV+13]",
-			"ioctl[IEEE80211_IOCTL_CHANLIST]",
-			"ioctl[SIOCIWFIRSTPRIV+15]",
-			"ioctl[IEEE80211_IOCTL_GETRSN]",
-			"ioctl[SIOCIWFIRSTPRIV+17]",
-			"ioctl[IEEE80211_IOCTL_GETKEY]",
-		};
-#endif /* MADWIFI_NG */
-		int idx = op - first;
-		if (first <= op &&
-		    idx < (int) (sizeof(opnames) / sizeof(opnames[0])) &&
-		    opnames[idx])
-			perror(opnames[idx]);
-		else
-			perror("ioctl[unknown???]");
-		return -1;
-	}
-	return 0;
-}
-
-static int
-set80211param(struct madwifi_driver_data *drv, int op, int arg)
-{
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.mode = op;
-	memcpy(iwr.u.name+sizeof(__u32), &arg, sizeof(arg));
-
-	if (ioctl(drv->ioctl_sock, IEEE80211_IOCTL_SETPARAM, &iwr) < 0) {
-		perror("ioctl[IEEE80211_IOCTL_SETPARAM]");
-		wpa_printf(MSG_DEBUG, "%s: Failed to set parameter (op %d "
-			   "arg %d)", __func__, op, arg);
-		return -1;
-	}
-	return 0;
-}
-
-#ifndef CONFIG_NO_STDOUT_DEBUG
-static const char *
-ether_sprintf(const u8 *addr)
-{
-	static char buf[sizeof(MACSTR)];
-
-	if (addr != NULL)
-		snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
-	else
-		snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
-	return buf;
-}
-#endif /* CONFIG_NO_STDOUT_DEBUG */
-
-/*
- * Configure WPA parameters.
- */
-static int
-madwifi_configure_wpa(struct madwifi_driver_data *drv)
-{
-	struct hostapd_data *hapd = drv->hapd;
-	struct hostapd_bss_config *conf = hapd->conf;
-	int v;
-
-	switch (conf->wpa_group) {
-	case WPA_CIPHER_CCMP:
-		v = IEEE80211_CIPHER_AES_CCM;
-		break;
-	case WPA_CIPHER_TKIP:
-		v = IEEE80211_CIPHER_TKIP;
-		break;
-	case WPA_CIPHER_WEP104:
-		v = IEEE80211_CIPHER_WEP;
-		break;
-	case WPA_CIPHER_WEP40:
-		v = IEEE80211_CIPHER_WEP;
-		break;
-	case WPA_CIPHER_NONE:
-		v = IEEE80211_CIPHER_NONE;
-		break;
-	default:
-		wpa_printf(MSG_ERROR, "Unknown group key cipher %u",
-			   conf->wpa_group);
-		return -1;
-	}
-	wpa_printf(MSG_DEBUG, "%s: group key cipher=%d", __func__, v);
-	if (set80211param(drv, IEEE80211_PARAM_MCASTCIPHER, v)) {
-		printf("Unable to set group key cipher to %u\n", v);
-		return -1;
-	}
-	if (v == IEEE80211_CIPHER_WEP) {
-		/* key length is done only for specific ciphers */
-		v = (conf->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
-		if (set80211param(drv, IEEE80211_PARAM_MCASTKEYLEN, v)) {
-			printf("Unable to set group key length to %u\n", v);
-			return -1;
-		}
-	}
-
-	v = 0;
-	if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
-		v |= 1<<IEEE80211_CIPHER_AES_CCM;
-	if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
-		v |= 1<<IEEE80211_CIPHER_TKIP;
-	if (conf->wpa_pairwise & WPA_CIPHER_NONE)
-		v |= 1<<IEEE80211_CIPHER_NONE;
-	wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
-	if (set80211param(drv, IEEE80211_PARAM_UCASTCIPHERS, v)) {
-		printf("Unable to set pairwise key ciphers to 0x%x\n", v);
-		return -1;
-	}
-
-	wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
-		   __func__, conf->wpa_key_mgmt);
-	if (set80211param(drv, IEEE80211_PARAM_KEYMGTALGS, conf->wpa_key_mgmt)) {
-		printf("Unable to set key management algorithms to 0x%x\n",
-			conf->wpa_key_mgmt);
-		return -1;
-	}
-
-	v = 0;
-	if (conf->rsn_preauth)
-		v |= BIT(0);
-	wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x",
-		   __func__, conf->rsn_preauth);
-	if (set80211param(drv, IEEE80211_PARAM_RSNCAPS, v)) {
-		printf("Unable to set RSN capabilities to 0x%x\n", v);
-		return -1;
-	}
-
-	wpa_printf(MSG_DEBUG, "%s: enable WPA=0x%x", __func__, conf->wpa);
-	if (set80211param(drv, IEEE80211_PARAM_WPA, conf->wpa)) {
-		printf("Unable to set WPA to %u\n", conf->wpa);
-		return -1;
-	}
-	return 0;
-}
-
-
-static int
-madwifi_set_iface_flags(void *priv, int dev_up)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct ifreq ifr;
-
-	wpa_printf(MSG_DEBUG, "%s: dev_up=%d", __func__, dev_up);
-
-	if (drv->ioctl_sock < 0)
-		return -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
-
-	if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
-		perror("ioctl[SIOCGIFFLAGS]");
-		return -1;
-	}
-
-	if (dev_up)
-		ifr.ifr_flags |= IFF_UP;
-	else
-		ifr.ifr_flags &= ~IFF_UP;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
-		perror("ioctl[SIOCSIFFLAGS]");
-		return -1;
-	}
-
-	if (dev_up) {
-		memset(&ifr, 0, sizeof(ifr));
-		os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
-		ifr.ifr_mtu = HOSTAPD_MTU;
-		if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
-			perror("ioctl[SIOCSIFMTU]");
-			printf("Setting MTU failed - trying to survive with "
-			       "current value\n");
-		}
-	}
-
-	return 0;
-}
-
-static int
-madwifi_set_ieee8021x(const char *ifname, void *priv, int enabled)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct hostapd_data *hapd = drv->hapd;
-	struct hostapd_bss_config *conf = hapd->conf;
-
-	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
-
-	if (!enabled) {
-		/* XXX restore state */
-		return set80211param(priv, IEEE80211_PARAM_AUTHMODE,
-			IEEE80211_AUTH_AUTO);
-	}
-	if (!conf->wpa && !conf->ieee802_1x) {
-		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
-			HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
-		return -1;
-	}
-	if (conf->wpa && madwifi_configure_wpa(drv) != 0) {
-		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
-			HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");
-		return -1;
-	}
-	if (set80211param(priv, IEEE80211_PARAM_AUTHMODE,
-		(conf->wpa ?  IEEE80211_AUTH_WPA : IEEE80211_AUTH_8021X))) {
-		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
-			HOSTAPD_LEVEL_WARNING, "Error enabling WPA/802.1X!");
-		return -1;
-	}
-
-	return 0;
-}
-
-static int
-madwifi_set_privacy(const char *ifname, void *priv, int enabled)
-{
-	struct madwifi_driver_data *drv = priv;
-
-	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
-
-	return set80211param(drv, IEEE80211_PARAM_PRIVACY, enabled);
-}
-
-static int
-madwifi_set_sta_authorized(void *priv, const u8 *addr, int authorized)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
-	int ret;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
-		   __func__, ether_sprintf(addr), authorized);
-
-	if (authorized)
-		mlme.im_op = IEEE80211_MLME_AUTHORIZE;
-	else
-		mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
-	mlme.im_reason = 0;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
-	if (ret < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to %sauthorize STA " MACSTR,
-			   __func__, authorized ? "" : "un", MAC2STR(addr));
-	}
-
-	return ret;
-}
-
-static int
-madwifi_sta_set_flags(void *priv, const u8 *addr, int total_flags,
-		      int flags_or, int flags_and)
-{
-	/* For now, only support setting Authorized flag */
-	if (flags_or & WLAN_STA_AUTHORIZED)
-		return madwifi_set_sta_authorized(priv, addr, 1);
-	if (!(flags_and & WLAN_STA_AUTHORIZED))
-		return madwifi_set_sta_authorized(priv, addr, 0);
-	return 0;
-}
-
-static int
-madwifi_del_key(void *priv, const u8 *addr, int key_idx)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct ieee80211req_del_key wk;
-	int ret;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
-		   __func__, ether_sprintf(addr), key_idx);
-
-	memset(&wk, 0, sizeof(wk));
-	if (addr != NULL) {
-		memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
-		wk.idk_keyix = (u8) IEEE80211_KEYIX_NONE;
-	} else {
-		wk.idk_keyix = key_idx;
-	}
-
-	ret = set80211priv(drv, IEEE80211_IOCTL_DELKEY, &wk, sizeof(wk));
-	if (ret < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to delete key (addr %s"
-			   " key_idx %d)", __func__, ether_sprintf(addr),
-			   key_idx);
-	}
-
-	return ret;
-}
-
-static int
-madwifi_set_key(const char *ifname, void *priv, wpa_alg alg,
-		const u8 *addr, int key_idx, int set_tx, const u8 *seq,
-		size_t seq_len, const u8 *key, size_t key_len)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct ieee80211req_key wk;
-	u_int8_t cipher;
-	int ret;
-
-	if (alg == WPA_ALG_NONE)
-		return madwifi_del_key(drv, addr, key_idx);
-
-	wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
-		   __func__, alg, ether_sprintf(addr), key_idx);
-
-	if (alg == WPA_ALG_WEP)
-		cipher = IEEE80211_CIPHER_WEP;
-	else if (alg == WPA_ALG_TKIP)
-		cipher = IEEE80211_CIPHER_TKIP;
-	else if (alg == WPA_ALG_CCMP)
-		cipher = IEEE80211_CIPHER_AES_CCM;
-	else {
-		printf("%s: unknown/unsupported algorithm %d\n",
-			__func__, alg);
-		return -1;
-	}
-
-	if (key_len > sizeof(wk.ik_keydata)) {
-		printf("%s: key length %lu too big\n", __func__,
-		       (unsigned long) key_len);
-		return -3;
-	}
-
-	memset(&wk, 0, sizeof(wk));
-	wk.ik_type = cipher;
-	wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
-	if (addr == NULL) {
-		memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
-		wk.ik_keyix = key_idx;
-		wk.ik_flags |= IEEE80211_KEY_DEFAULT;
-	} else {
-		memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
-		wk.ik_keyix = IEEE80211_KEYIX_NONE;
-	}
-	wk.ik_keylen = key_len;
-	memcpy(wk.ik_keydata, key, key_len);
-
-	ret = set80211priv(drv, IEEE80211_IOCTL_SETKEY, &wk, sizeof(wk));
-	if (ret < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to set key (addr %s"
-			   " key_idx %d alg %d key_len %lu set_tx %d)",
-			   __func__, ether_sprintf(wk.ik_macaddr), key_idx,
-			   alg, (unsigned long) key_len, set_tx);
-	}
-
-	return ret;
-}
-
-
-static int
-madwifi_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
-		   u8 *seq)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct ieee80211req_key wk;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
-		   __func__, ether_sprintf(addr), idx);
-
-	memset(&wk, 0, sizeof(wk));
-	if (addr == NULL)
-		memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
-	else
-		memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
-	wk.ik_keyix = idx;
-
-	if (set80211priv(drv, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk))) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to get encryption data "
-			   "(addr " MACSTR " key_idx %d)",
-			   __func__, MAC2STR(wk.ik_macaddr), idx);
-		return -1;
-	}
-
-#ifdef WORDS_BIGENDIAN
-	{
-		/*
-		 * wk.ik_keytsc is in host byte order (big endian), need to
-		 * swap it to match with the byte order used in WPA.
-		 */
-		int i;
-		u8 tmp[WPA_KEY_RSC_LEN];
-		memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
-		for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
-			seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
-		}
-	}
-#else /* WORDS_BIGENDIAN */
-	memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
-#endif /* WORDS_BIGENDIAN */
-	return 0;
-}
-
-
-static int 
-madwifi_flush(void *priv)
-{
-#ifdef MADWIFI_BSD
-	u8 allsta[IEEE80211_ADDR_LEN];
-	memset(allsta, 0xff, IEEE80211_ADDR_LEN);
-	return madwifi_sta_deauth(priv, allsta, IEEE80211_REASON_AUTH_LEAVE);
-#else /* MADWIFI_BSD */
-	return 0;		/* XXX */
-#endif /* MADWIFI_BSD */
-}
-
-
-static int
-madwifi_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
-			     const u8 *addr)
-{
-	struct madwifi_driver_data *drv = priv;
-
-#ifdef MADWIFI_BSD
-	struct ieee80211req_sta_stats stats;
-
-	memset(data, 0, sizeof(*data));
-
-	/*
-	 * Fetch statistics for station from the system.
-	 */
-	memset(&stats, 0, sizeof(stats));
-	memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
-	if (set80211priv(drv,
-#ifdef MADWIFI_NG
-			 IEEE80211_IOCTL_STA_STATS,
-#else /* MADWIFI_NG */
-			 IEEE80211_IOCTL_GETSTASTATS,
-#endif /* MADWIFI_NG */
-			 &stats, sizeof(stats))) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to fetch STA stats (addr "
-			   MACSTR ")", __func__, MAC2STR(addr));
-		if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
-			memcpy(data, &drv->acct_data, sizeof(*data));
-			return 0;
-		}
-
-		printf("Failed to get station stats information element.\n");
-		return -1;
-	}
-
-	data->rx_packets = stats.is_stats.ns_rx_data;
-	data->rx_bytes = stats.is_stats.ns_rx_bytes;
-	data->tx_packets = stats.is_stats.ns_tx_data;
-	data->tx_bytes = stats.is_stats.ns_tx_bytes;
-	return 0;
-
-#else /* MADWIFI_BSD */
-
-	char buf[1024], line[128], *pos;
-	FILE *f;
-	unsigned long val;
-
-	memset(data, 0, sizeof(*data));
-	snprintf(buf, sizeof(buf), "/proc/net/madwifi/%s/" MACSTR,
-		 drv->iface, MAC2STR(addr));
-
-	f = fopen(buf, "r");
-	if (!f) {
-		if (memcmp(addr, drv->acct_mac, ETH_ALEN) != 0)
-			return -1;
-		memcpy(data, &drv->acct_data, sizeof(*data));
-		return 0;
-	}
-	/* Need to read proc file with in one piece, so use large enough
-	 * buffer. */
-	setbuffer(f, buf, sizeof(buf));
-
-	while (fgets(line, sizeof(line), f)) {
-		pos = strchr(line, '=');
-		if (!pos)
-			continue;
-		*pos++ = '\0';
-		val = strtoul(pos, NULL, 10);
-		if (strcmp(line, "rx_packets") == 0)
-			data->rx_packets = val;
-		else if (strcmp(line, "tx_packets") == 0)
-			data->tx_packets = val;
-		else if (strcmp(line, "rx_bytes") == 0)
-			data->rx_bytes = val;
-		else if (strcmp(line, "tx_bytes") == 0)
-			data->tx_bytes = val;
-	}
-
-	fclose(f);
-
-	return 0;
-#endif /* MADWIFI_BSD */
-}
-
-
-static int
-madwifi_sta_clear_stats(void *priv, const u8 *addr)
-{
-#if defined(MADWIFI_BSD) && defined(IEEE80211_MLME_CLEAR_STATS)
-	struct madwifi_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
-	int ret;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s", __func__, ether_sprintf(addr));
-
-	mlme.im_op = IEEE80211_MLME_CLEAR_STATS;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme,
-			   sizeof(mlme));
-	if (ret < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to clear STA stats (addr "
-			   MACSTR ")", __func__, MAC2STR(addr));
-	}
-
-	return ret;
-#else /* MADWIFI_BSD && IEEE80211_MLME_CLEAR_STATS */
-	return 0; /* FIX */
-#endif /* MADWIFI_BSD && IEEE80211_MLME_CLEAR_STATS */
-}
-
-
-static int
-madwifi_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len)
-{
-	/*
-	 * Do nothing; we setup parameters at startup that define the
-	 * contents of the beacon information element.
-	 */
-	return 0;
-}
-
-static int
-madwifi_sta_deauth(void *priv, const u8 *addr, int reason_code)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
-	int ret;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
-		   __func__, ether_sprintf(addr), reason_code);
-
-	mlme.im_op = IEEE80211_MLME_DEAUTH;
-	mlme.im_reason = reason_code;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
-	if (ret < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to deauth STA (addr " MACSTR
-			   " reason %d)",
-			   __func__, MAC2STR(addr), reason_code);
-	}
-
-	return ret;
-}
-
-static int
-madwifi_sta_disassoc(void *priv, const u8 *addr, int reason_code)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct ieee80211req_mlme mlme;
-	int ret;
-
-	wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
-		   __func__, ether_sprintf(addr), reason_code);
-
-	mlme.im_op = IEEE80211_MLME_DISASSOC;
-	mlme.im_reason = reason_code;
-	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
-	ret = set80211priv(drv, IEEE80211_IOCTL_SETMLME, &mlme, sizeof(mlme));
-	if (ret < 0) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to disassoc STA (addr "
-			   MACSTR " reason %d)",
-			   __func__, MAC2STR(addr), reason_code);
-	}
-
-	return ret;
-}
-
-#ifdef CONFIG_WPS
-#ifdef IEEE80211_IOCTL_FILTERFRAME
-static void madwifi_raw_receive(void *ctx, const u8 *src_addr, const u8 *buf,
-				size_t len)
-{
-	struct madwifi_driver_data *drv = ctx;
-	const struct ieee80211_mgmt *mgmt;
-	const u8 *end, *ie;
-	u16 fc;
-	size_t ie_len;
-
-	/* Send Probe Request information to WPS processing */
-
-	if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
-		return;
-	mgmt = (const struct ieee80211_mgmt *) buf;
-
-	fc = le_to_host16(mgmt->frame_control);
-	if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT ||
-	    WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_PROBE_REQ)
-		return;
-
-	end = buf + len;
-	ie = mgmt->u.probe_req.variable;
-	ie_len = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req));
-
-	hostapd_wps_probe_req_rx(drv->hapd, mgmt->sa, ie, ie_len);
-}
-#endif /* IEEE80211_IOCTL_FILTERFRAME */
-#endif /* CONFIG_WPS */
-
-static int madwifi_receive_probe_req(struct madwifi_driver_data *drv)
-{
-	int ret = 0;
-#ifdef CONFIG_WPS
-#ifdef IEEE80211_IOCTL_FILTERFRAME
-	struct ieee80211req_set_filter filt;
-
-	wpa_printf(MSG_DEBUG, "%s Enter", __func__);
-	filt.app_filterype = IEEE80211_FILTER_TYPE_PROBE_REQ;
-
-	ret = set80211priv(drv, IEEE80211_IOCTL_FILTERFRAME, &filt,
-			   sizeof(struct ieee80211req_set_filter));
-	if (ret)
-		return ret;
-
-	drv->sock_raw = l2_packet_init(drv->iface, NULL, ETH_P_80211_RAW,
-				       madwifi_raw_receive, drv, 1);
-	if (drv->sock_raw == NULL)
-		return -1;
-#endif /* IEEE80211_IOCTL_FILTERFRAME */
-#endif /* CONFIG_WPS */
-	return ret;
-}
-
-#ifdef CONFIG_WPS
-static int
-madwifi_set_wps_ie(void *priv, const u8 *ie, size_t len, u32 frametype)
-{
-	struct madwifi_driver_data *drv = priv;
-	u8 buf[256];
-	struct ieee80211req_getset_appiebuf *beac_ie;
-
-	wpa_printf(MSG_DEBUG, "%s buflen = %lu", __func__,
-		   (unsigned long) len);
-
-	beac_ie = (struct ieee80211req_getset_appiebuf *) buf;
-	beac_ie->app_frmtype = frametype;
-	beac_ie->app_buflen = len;
-	memcpy(&(beac_ie->app_buf[0]), ie, len);
-
-	return set80211priv(drv, IEEE80211_IOCTL_SET_APPIEBUF, beac_ie,
-			    sizeof(struct ieee80211req_getset_appiebuf) + len);
-}
-
-static int
-madwifi_set_wps_beacon_ie(const char *ifname, void *priv, const u8 *ie,
-			  size_t len)
-{
-	return madwifi_set_wps_ie(priv, ie, len, IEEE80211_APPIE_FRAME_BEACON);
-}
-
-static int
-madwifi_set_wps_probe_resp_ie(const char *ifname, void *priv, const u8 *ie,
-			      size_t len)
-{
-	return madwifi_set_wps_ie(priv, ie, len,
-				  IEEE80211_APPIE_FRAME_PROBE_RESP);
-}
-#else /* CONFIG_WPS */
-#define madwifi_set_wps_beacon_ie NULL
-#define madwifi_set_wps_probe_resp_ie NULL
-#endif /* CONFIG_WPS */
-
-static int
-madwifi_new_sta(struct madwifi_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
-{
-	struct hostapd_data *hapd = drv->hapd;
-	struct ieee80211req_wpaie ie;
-	int ielen = 0, res;
-	u8 *iebuf = NULL;
-
-	/*
-	 * Fetch negotiated WPA/RSN parameters from the system.
-	 */
-	memset(&ie, 0, sizeof(ie));
-	memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
-	if (set80211priv(drv, IEEE80211_IOCTL_GETWPAIE, &ie, sizeof(ie))) {
-		wpa_printf(MSG_DEBUG, "%s: Failed to get WPA/RSN IE",
-			   __func__);
-		goto no_ie;
-	}
-	wpa_hexdump(MSG_MSGDUMP, "madwifi req WPA IE",
-		    ie.wpa_ie, IEEE80211_MAX_OPT_IE);
-	iebuf = ie.wpa_ie;
-	/* madwifi seems to return some random data if WPA/RSN IE is not set.
-	 * Assume the IE was not included if the IE type is unknown. */
-	if (iebuf[0] != WLAN_EID_VENDOR_SPECIFIC)
-		iebuf[1] = 0;
-#ifdef MADWIFI_NG
-	wpa_hexdump(MSG_MSGDUMP, "madwifi req RSN IE",
-		    ie.rsn_ie, IEEE80211_MAX_OPT_IE);
-	if (iebuf[1] == 0 && ie.rsn_ie[1] > 0) {
-		/* madwifi-ng svn #1453 added rsn_ie. Use it, if wpa_ie was not
-		 * set. This is needed for WPA2. */
-		iebuf = ie.rsn_ie;
-		if (iebuf[0] != WLAN_EID_RSN)
-			iebuf[1] = 0;
-	}
-#endif /* MADWIFI_NG */
-
-	ielen = iebuf[1];
-	if (ielen == 0)
-		iebuf = NULL;
-	else
-		ielen += 2;
-
-no_ie:
-	res = hostapd_notif_assoc(hapd, addr, iebuf, ielen);
-
-	if (memcmp(addr, drv->acct_mac, ETH_ALEN) == 0) {
-		/* Cached accounting data is not valid anymore. */
-		memset(drv->acct_mac, 0, ETH_ALEN);
-		memset(&drv->acct_data, 0, sizeof(drv->acct_data));
-	}
-
-	return res;
-}
-
-static void
-madwifi_wireless_event_wireless_custom(struct madwifi_driver_data *drv,
-				       char *custom)
-{
-	wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
-
-	if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
-		char *pos;
-		u8 addr[ETH_ALEN];
-		pos = strstr(custom, "addr=");
-		if (pos == NULL) {
-			wpa_printf(MSG_DEBUG,
-				   "MLME-MICHAELMICFAILURE.indication "
-				   "without sender address ignored");
-			return;
-		}
-		pos += 5;
-		if (hwaddr_aton(pos, addr) == 0) {
-			hostapd_michael_mic_failure(drv->hapd, addr);
-		} else {
-			wpa_printf(MSG_DEBUG,
-				   "MLME-MICHAELMICFAILURE.indication "
-				   "with invalid MAC address");
-		}
-	} else if (strncmp(custom, "STA-TRAFFIC-STAT", 16) == 0) {
-		char *key, *value;
-		u32 val;
-		key = custom;
-		while ((key = strchr(key, '\n')) != NULL) {
-			key++;
-			value = strchr(key, '=');
-			if (value == NULL)
-				continue;
-			*value++ = '\0';
-			val = strtoul(value, NULL, 10);
-			if (strcmp(key, "mac") == 0)
-				hwaddr_aton(value, drv->acct_mac);
-			else if (strcmp(key, "rx_packets") == 0)
-				drv->acct_data.rx_packets = val;
-			else if (strcmp(key, "tx_packets") == 0)
-				drv->acct_data.tx_packets = val;
-			else if (strcmp(key, "rx_bytes") == 0)
-				drv->acct_data.rx_bytes = val;
-			else if (strcmp(key, "tx_bytes") == 0)
-				drv->acct_data.tx_bytes = val;
-			key = value;
-		}
-	}
-}
-
-static void
-madwifi_wireless_event_wireless(struct madwifi_driver_data *drv,
-					    char *data, int len)
-{
-	struct iw_event iwe_buf, *iwe = &iwe_buf;
-	char *pos, *end, *custom, *buf;
-
-	pos = data;
-	end = data + len;
-
-	while (pos + IW_EV_LCP_LEN <= end) {
-		/* Event data may be unaligned, so make a local, aligned copy
-		 * before processing. */
-		memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
-		wpa_printf(MSG_MSGDUMP, "Wireless event: cmd=0x%x len=%d",
-			   iwe->cmd, iwe->len);
-		if (iwe->len <= IW_EV_LCP_LEN)
-			return;
-
-		custom = pos + IW_EV_POINT_LEN;
-		if (drv->we_version > 18 &&
-		    (iwe->cmd == IWEVMICHAELMICFAILURE ||
-		     iwe->cmd == IWEVCUSTOM)) {
-			/* WE-19 removed the pointer from struct iw_point */
-			char *dpos = (char *) &iwe_buf.u.data.length;
-			int dlen = dpos - (char *) &iwe_buf;
-			memcpy(dpos, pos + IW_EV_LCP_LEN,
-			       sizeof(struct iw_event) - dlen);
-		} else {
-			memcpy(&iwe_buf, pos, sizeof(struct iw_event));
-			custom += IW_EV_POINT_OFF;
-		}
-
-		switch (iwe->cmd) {
-		case IWEVEXPIRED:
-			hostapd_notif_disassoc(drv->hapd,
-					       (u8 *) iwe->u.addr.sa_data);
-			break;
-		case IWEVREGISTERED:
-			madwifi_new_sta(drv, (u8 *) iwe->u.addr.sa_data);
-			break;
-		case IWEVCUSTOM:
-			if (custom + iwe->u.data.length > end)
-				return;
-			buf = malloc(iwe->u.data.length + 1);
-			if (buf == NULL)
-				return;		/* XXX */
-			memcpy(buf, custom, iwe->u.data.length);
-			buf[iwe->u.data.length] = '\0';
-			madwifi_wireless_event_wireless_custom(drv, buf);
-			free(buf);
-			break;
-		}
-
-		pos += iwe->len;
-	}
-}
-
-
-static void
-madwifi_wireless_event_rtm_newlink(struct madwifi_driver_data *drv,
-					       struct nlmsghdr *h, int len)
-{
-	struct ifinfomsg *ifi;
-	int attrlen, nlmsg_len, rta_len;
-	struct rtattr * attr;
-
-	if (len < (int) sizeof(*ifi))
-		return;
-
-	ifi = NLMSG_DATA(h);
-
-	if (ifi->ifi_index != drv->ifindex)
-		return;
-
-	nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
-
-	attrlen = h->nlmsg_len - nlmsg_len;
-	if (attrlen < 0)
-		return;
-
-	attr = (struct rtattr *) (((char *) ifi) + nlmsg_len);
-
-	rta_len = RTA_ALIGN(sizeof(struct rtattr));
-	while (RTA_OK(attr, attrlen)) {
-		if (attr->rta_type == IFLA_WIRELESS) {
-			madwifi_wireless_event_wireless(
-				drv, ((char *) attr) + rta_len,
-				attr->rta_len - rta_len);
-		}
-		attr = RTA_NEXT(attr, attrlen);
-	}
-}
-
-
-static void
-madwifi_wireless_event_receive(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	char buf[256];
-	int left;
-	struct sockaddr_nl from;
-	socklen_t fromlen;
-	struct nlmsghdr *h;
-	struct madwifi_driver_data *drv = eloop_ctx;
-
-	fromlen = sizeof(from);
-	left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
-			(struct sockaddr *) &from, &fromlen);
-	if (left < 0) {
-		if (errno != EINTR && errno != EAGAIN)
-			perror("recvfrom(netlink)");
-		return;
-	}
-
-	h = (struct nlmsghdr *) buf;
-	while (left >= (int) sizeof(*h)) {
-		int len, plen;
-
-		len = h->nlmsg_len;
-		plen = len - sizeof(*h);
-		if (len > left || plen < 0) {
-			printf("Malformed netlink message: "
-			       "len=%d left=%d plen=%d\n",
-			       len, left, plen);
-			break;
-		}
-
-		switch (h->nlmsg_type) {
-		case RTM_NEWLINK:
-			madwifi_wireless_event_rtm_newlink(drv, h, plen);
-			break;
-		}
-
-		len = NLMSG_ALIGN(len);
-		left -= len;
-		h = (struct nlmsghdr *) ((char *) h + len);
-	}
-
-	if (left > 0) {
-		printf("%d extra bytes in the end of netlink message\n", left);
-	}
-}
-
-
-static int
-madwifi_get_we_version(struct madwifi_driver_data *drv)
-{
-	struct iw_range *range;
-	struct iwreq iwr;
-	int minlen;
-	size_t buflen;
-
-	drv->we_version = 0;
-
-	/*
-	 * Use larger buffer than struct iw_range in order to allow the
-	 * structure to grow in the future.
-	 */
-	buflen = sizeof(struct iw_range) + 500;
-	range = os_zalloc(buflen);
-	if (range == NULL)
-		return -1;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.data.pointer = (caddr_t) range;
-	iwr.u.data.length = buflen;
-
-	minlen = ((char *) &range->enc_capa) - (char *) range +
-		sizeof(range->enc_capa);
-
-	if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
-		perror("ioctl[SIOCGIWRANGE]");
-		free(range);
-		return -1;
-	} else if (iwr.u.data.length >= minlen &&
-		   range->we_version_compiled >= 18) {
-		wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
-			   "WE(source)=%d enc_capa=0x%x",
-			   range->we_version_compiled,
-			   range->we_version_source,
-			   range->enc_capa);
-		drv->we_version = range->we_version_compiled;
-	}
-
-	free(range);
-	return 0;
-}
-
-
-static int
-madwifi_wireless_event_init(struct madwifi_driver_data *drv)
-{
-	int s;
-	struct sockaddr_nl local;
-
-	madwifi_get_we_version(drv);
-
-	drv->wext_sock = -1;
-
-	s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-	if (s < 0) {
-		perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
-		return -1;
-	}
-
-	memset(&local, 0, sizeof(local));
-	local.nl_family = AF_NETLINK;
-	local.nl_groups = RTMGRP_LINK;
-	if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
-		perror("bind(netlink)");
-		close(s);
-		return -1;
-	}
-
-	eloop_register_read_sock(s, madwifi_wireless_event_receive, drv, NULL);
-	drv->wext_sock = s;
-
-	return 0;
-}
-
-
-static void
-madwifi_wireless_event_deinit(struct madwifi_driver_data *drv)
-{
-	if (drv->wext_sock < 0)
-		return;
-	eloop_unregister_read_sock(drv->wext_sock);
-	close(drv->wext_sock);
-}
-
-
-static int
-madwifi_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
-		   int encrypt, const u8 *own_addr)
-{
-	struct madwifi_driver_data *drv = priv;
-	unsigned char buf[3000];
-	unsigned char *bp = buf;
-	struct l2_ethhdr *eth;
-	size_t len;
-	int status;
-
-	/*
-	 * Prepend the Ethernet header.  If the caller left us
-	 * space at the front we could just insert it but since
-	 * we don't know we copy to a local buffer.  Given the frequency
-	 * and size of frames this probably doesn't matter.
-	 */
-	len = data_len + sizeof(struct l2_ethhdr);
-	if (len > sizeof(buf)) {
-		bp = malloc(len);
-		if (bp == NULL) {
-			printf("EAPOL frame discarded, cannot malloc temp "
-			       "buffer of size %lu!\n", (unsigned long) len);
-			return -1;
-		}
-	}
-	eth = (struct l2_ethhdr *) bp;
-	memcpy(eth->h_dest, addr, ETH_ALEN);
-	memcpy(eth->h_source, own_addr, ETH_ALEN);
-	eth->h_proto = host_to_be16(ETH_P_EAPOL);
-	memcpy(eth+1, data, data_len);
-
-	wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
-
-	status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
-
-	if (bp != buf)
-		free(bp);
-	return status;
-}
-
-static void
-handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
-{
-	struct madwifi_driver_data *drv = ctx;
-	hostapd_eapol_receive(drv->hapd, src_addr,
-			      buf + sizeof(struct l2_ethhdr),
-			      len - sizeof(struct l2_ethhdr));
-}
-
-static void *
-madwifi_init(struct hostapd_data *hapd)
-{
-	struct madwifi_driver_data *drv;
-	struct ifreq ifr;
-	struct iwreq iwr;
-
-	drv = os_zalloc(sizeof(struct madwifi_driver_data));
-	if (drv == NULL) {
-		printf("Could not allocate memory for madwifi driver data\n");
-		return NULL;
-	}
-
-	drv->hapd = hapd;
-	drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
-	if (drv->ioctl_sock < 0) {
-		perror("socket[PF_INET,SOCK_DGRAM]");
-		goto bad;
-	}
-	memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
-
-	memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
-	if (ioctl(drv->ioctl_sock, SIOCGIFINDEX, &ifr) != 0) {
-		perror("ioctl(SIOCGIFINDEX)");
-		goto bad;
-	}
-	drv->ifindex = ifr.ifr_ifindex;
-
-	drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
-					handle_read, drv, 1);
-	if (drv->sock_xmit == NULL)
-		goto bad;
-	if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
-		goto bad;
-	if (hapd->conf->bridge[0] != '\0') {
-		wpa_printf(MSG_DEBUG, "Configure bridge %s for EAPOL traffic.",
-			   hapd->conf->bridge);
-		drv->sock_recv = l2_packet_init(hapd->conf->bridge, NULL,
-						ETH_P_EAPOL, handle_read, drv,
-						1);
-		if (drv->sock_recv == NULL)
-			goto bad;
-	} else
-		drv->sock_recv = drv->sock_xmit;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-
-	iwr.u.mode = IW_MODE_MASTER;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIWMODE, &iwr) < 0) {
-		perror("ioctl[SIOCSIWMODE]");
-		printf("Could not set interface to master mode!\n");
-		goto bad;
-	}
-
-	madwifi_set_iface_flags(drv, 0);	/* mark down during setup */
-	madwifi_set_privacy(drv->iface, drv, 0); /* default to no privacy */
-
-	madwifi_receive_probe_req(drv);
-
-	if (madwifi_wireless_event_init(drv))
-		goto bad;
-
-	return drv;
-bad:
-	if (drv->sock_xmit != NULL)
-		l2_packet_deinit(drv->sock_xmit);
-	if (drv->ioctl_sock >= 0)
-		close(drv->ioctl_sock);
-	if (drv != NULL)
-		free(drv);
-	return NULL;
-}
-
-
-static void
-madwifi_deinit(void *priv)
-{
-	struct madwifi_driver_data *drv = priv;
-
-	madwifi_wireless_event_deinit(drv);
-	(void) madwifi_set_iface_flags(drv, 0);
-	if (drv->ioctl_sock >= 0)
-		close(drv->ioctl_sock);
-	if (drv->sock_recv != NULL && drv->sock_recv != drv->sock_xmit)
-		l2_packet_deinit(drv->sock_recv);
-	if (drv->sock_xmit != NULL)
-		l2_packet_deinit(drv->sock_xmit);
-	if (drv->sock_raw)
-		l2_packet_deinit(drv->sock_raw);
-	free(drv);
-}
-
-static int
-madwifi_set_ssid(const char *ifname, void *priv, const u8 *buf, int len)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.essid.flags = 1; /* SSID active */
-	iwr.u.essid.pointer = (caddr_t) buf;
-	iwr.u.essid.length = len + 1;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIWESSID, &iwr) < 0) {
-		perror("ioctl[SIOCSIWESSID]");
-		printf("len=%d\n", len);
-		return -1;
-	}
-	return 0;
-}
-
-static int
-madwifi_get_ssid(const char *ifname, void *priv, u8 *buf, int len)
-{
-	struct madwifi_driver_data *drv = priv;
-	struct iwreq iwr;
-	int ret = 0;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.essid.pointer = (caddr_t) buf;
-	iwr.u.essid.length = len;
-
-	if (ioctl(drv->ioctl_sock, SIOCGIWESSID, &iwr) < 0) {
-		perror("ioctl[SIOCGIWESSID]");
-		ret = -1;
-	} else
-		ret = iwr.u.essid.length;
-
-	return ret;
-}
-
-static int
-madwifi_set_countermeasures(void *priv, int enabled)
-{
-	struct madwifi_driver_data *drv = priv;
-	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __FUNCTION__, enabled);
-	return set80211param(drv, IEEE80211_PARAM_COUNTERMEASURES, enabled);
-}
-
-static int
-madwifi_commit(void *priv)
-{
-	return madwifi_set_iface_flags(priv, 1);
-}
-
-const struct hapd_driver_ops wpa_driver_madwifi_ops = {
-	.name			= "madwifi",
-	.init			= madwifi_init,
-	.deinit			= madwifi_deinit,
-	.set_ieee8021x		= madwifi_set_ieee8021x,
-	.set_privacy		= madwifi_set_privacy,
-	.set_key		= madwifi_set_key,
-	.get_seqnum		= madwifi_get_seqnum,
-	.flush			= madwifi_flush,
-	.set_generic_elem	= madwifi_set_opt_ie,
-	.sta_set_flags		= madwifi_sta_set_flags,
-	.read_sta_data		= madwifi_read_sta_driver_data,
-	.send_eapol		= madwifi_send_eapol,
-	.sta_disassoc		= madwifi_sta_disassoc,
-	.sta_deauth		= madwifi_sta_deauth,
-	.set_ssid		= madwifi_set_ssid,
-	.get_ssid		= madwifi_get_ssid,
-	.set_countermeasures	= madwifi_set_countermeasures,
-	.sta_clear_stats        = madwifi_sta_clear_stats,
-	.commit			= madwifi_commit,
-	.set_wps_beacon_ie	= madwifi_set_wps_beacon_ie,
-	.set_wps_probe_resp_ie	= madwifi_set_wps_probe_resp_ie,
-};

+ 0 - 3008
hostapd/driver_nl80211.c

@@ -1,3008 +0,0 @@
-/*
- * hostapd / Kernel driver communication via nl80211
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2003-2004, Instant802 Networks, Inc.
- * Copyright (c) 2005-2006, Devicescape Software, Inc.
- * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
- *
- * 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 "includes.h"
-
-#include <sys/ioctl.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_copy.h"
-#include <net/if.h>
-#include <netpacket/packet.h>
-#include "wireless_copy.h"
-#include <linux/filter.h>
-#include <net/if_arp.h>
-
-#include "hostapd.h"
-#include "config.h"
-#include "driver.h"
-#include "eloop.h"
-#include "hw_features.h"
-#include "mlme.h"
-#include "radiotap.h"
-#include "radiotap_iter.h"
-#include "ieee802_11_defs.h"
-#include "ieee802_11_common.h"
-
-#ifdef CONFIG_LIBNL20
-/* libnl 2.0 compatibility code */
-#define nl_handle_alloc_cb nl_socket_alloc_cb
-#define nl_handle_destroy nl_socket_free
-#endif /* CONFIG_LIBNL20 */
-
-static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
-
-enum ieee80211_msg_type {
-	ieee80211_msg_normal = 0,
-	ieee80211_msg_tx_callback_ack = 1,
-	ieee80211_msg_tx_callback_fail = 2,
-};
-
-struct i802_bss {
-	struct i802_bss *next;
-	char iface[IFNAMSIZ + 1];
-	unsigned int beacon_set:1;
-};
-
-struct i802_driver_data {
-	struct hostapd_data *hapd;
-
-	char iface[IFNAMSIZ + 1];
-	int ioctl_sock; /* socket for ioctl() use */
-	int wext_sock; /* socket for wireless events */
-	int eapol_sock; /* socket for EAPOL frames */
-	int monitor_sock; /* socket for monitor */
-	int monitor_ifidx;
-
-	int default_if_indices[16];
-	int *if_indices;
-	int num_if_indices;
-
-	int we_version;
-	struct nl_handle *nl_handle;
-	struct nl_cache *nl_cache;
-	struct nl_cb *nl_cb;
-	struct genl_family *nl80211;
-	int beacon_int;
-	struct i802_bss bss;
-	unsigned int ht_40mhz_scan:1;
-
-	int last_freq;
-	int last_freq_ht;
-	struct hostapd_neighbor_bss *neighbors;
-	size_t num_neighbors;
-};
-
-
-static int i802_sta_deauth(void *priv, const u8 *addr, int reason);
-static int i802_sta_disassoc(void *priv, const u8 *addr, int reason);
-
-
-static struct i802_bss * get_bss(struct i802_driver_data *drv,
-				 const char *iface)
-{
-	struct i802_bss *bss = &drv->bss;
-	while (bss) {
-		if (os_strncmp(iface, bss->iface, IFNAMSIZ) == 0)
-			return bss;
-		bss = bss->next;
-	}
-	wpa_printf(MSG_DEBUG, "nl80211: get_bss(%s) failed", iface);
-	return NULL;
-}
-
-
-static void add_ifidx(struct i802_driver_data *drv, int ifidx)
-{
-	int i;
-	int *old;
-
-	wpa_printf(MSG_DEBUG, "nl80211: Add own interface ifindex %d",
-		   ifidx);
-	for (i = 0; i < drv->num_if_indices; i++) {
-		if (drv->if_indices[i] == 0) {
-			drv->if_indices[i] = ifidx;
-			return;
-		}
-	}
-
-	if (drv->if_indices != drv->default_if_indices)
-		old = drv->if_indices;
-	else
-		old = NULL;
-
-	drv->if_indices = realloc(old,
-				  sizeof(int) * (drv->num_if_indices + 1));
-	if (!drv->if_indices) {
-		if (!old)
-			drv->if_indices = drv->default_if_indices;
-		else
-			drv->if_indices = old;
-		wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
-			   "interfaces");
-		wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
-		return;
-	}
-	drv->if_indices[drv->num_if_indices] = ifidx;
-	drv->num_if_indices++;
-}
-
-
-static void del_ifidx(struct i802_driver_data *drv, int ifidx)
-{
-	int i;
-
-	for (i = 0; i < drv->num_if_indices; i++) {
-		if (drv->if_indices[i] == ifidx) {
-			drv->if_indices[i] = 0;
-			break;
-		}
-	}
-}
-
-
-static int have_ifidx(struct i802_driver_data *drv, int ifidx)
-{
-	int i;
-
-	for (i = 0; i < drv->num_if_indices; i++)
-		if (drv->if_indices[i] == ifidx)
-			return 1;
-
-	return 0;
-}
-
-
-/* nl80211 code */
-static int ack_handler(struct nl_msg *msg, void *arg)
-{
-	int *err = arg;
-	*err = 0;
-	return NL_STOP;
-}
-
-static int finish_handler(struct nl_msg *msg, void *arg)
-{
-	int *ret = arg;
-	*ret = 0;
-	return NL_SKIP;
-}
-
-static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
-			 void *arg)
-{
-	int *ret = arg;
-	*ret = err->error;
-	return NL_SKIP;
-}
-
-static int send_and_recv_msgs(struct i802_driver_data *drv,
-			      struct nl_msg *msg,
-			      int (*valid_handler)(struct nl_msg *, void *),
-			      void *valid_data)
-{
-	struct nl_cb *cb;
-	int err = -ENOMEM;
-
-	cb = nl_cb_clone(drv->nl_cb);
-	if (!cb)
-		goto out;
-
-	err = nl_send_auto_complete(drv->nl_handle, msg);
-	if (err < 0)
-		goto out;
-
-	err = 1;
-
-	nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
-	nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
-	nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
-
-	if (valid_handler)
-		nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
-			  valid_handler, valid_data);
-
-	while (err > 0)
-		nl_recvmsgs(drv->nl_handle, cb);
- out:
-	nl_cb_put(cb);
-	nlmsg_free(msg);
-	return err;
-}
-
-static int hostapd_set_iface_flags(struct i802_driver_data *drv,
-				   const char *ifname, int dev_up)
-{
-	struct ifreq ifr;
-
-	if (drv->ioctl_sock < 0)
-		return -1;
-
-	memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, ifname, IFNAMSIZ);
-
-	if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
-		perror("ioctl[SIOCGIFFLAGS]");
-		wpa_printf(MSG_DEBUG, "Could not read interface flags (%s)",
-			   drv->iface);
-		return -1;
-	}
-
-	if (dev_up)
-		ifr.ifr_flags |= IFF_UP;
-	else
-		ifr.ifr_flags &= ~IFF_UP;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
-		perror("ioctl[SIOCSIFFLAGS]");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int nl_set_encr(int ifindex, struct i802_driver_data *drv,
-		       wpa_alg alg, const u8 *addr, int idx, const u8 *key,
-		       size_t key_len, int txkey)
-{
-	struct nl_msg *msg;
-	int ret;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	if (alg == WPA_ALG_NONE) {
-		genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-			    0, NL80211_CMD_DEL_KEY, 0);
-	} else {
-		genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-			    0, NL80211_CMD_NEW_KEY, 0);
-		NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key);
-		switch (alg) {
-		case WPA_ALG_WEP:
-			if (key_len == 5)
-				NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
-					    0x000FAC01);
-			else
-				NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
-					    0x000FAC05);
-			break;
-		case WPA_ALG_TKIP:
-			NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC02);
-			break;
-		case WPA_ALG_CCMP:
-			NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC04);
-			break;
-		case WPA_ALG_IGTK:
-			NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC06);
-			break;
-		default:
-			wpa_printf(MSG_ERROR, "%s: Unsupported encryption "
-				   "algorithm %d", __func__, alg);
-			nlmsg_free(msg);
-			return -1;
-		}
-	}
-
-	if (addr)
-		NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
-	NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
-
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
-	if (ret == -ENOENT)
-		ret = 0;
-
-	/*
-	 * If we failed or don't need to set the default TX key (below),
-	 * we're done here.
-	 */
-	if (ret || !txkey || addr)
-		return ret;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_SET_KEY, 0);
-	NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifindex);
-	if (alg == WPA_ALG_IGTK)
-		NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT_MGMT);
-	else
-		NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
-
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
-	if (ret == -ENOENT)
-		ret = 0;
-	return ret;
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_set_key(const char *iface, void *priv, wpa_alg alg,
-			const u8 *addr, int key_idx, int set_tx, const u8 *seq,
-			size_t seq_len, const u8 *key, size_t key_len)
-{
-	struct i802_driver_data *drv = priv;
-	int ret;
-
-	ret = nl_set_encr(if_nametoindex(iface), drv, alg, addr, key_idx, key,
-			  key_len, set_tx);
-	if (ret < 0)
-		return ret;
-
-	return ret;
-}
-
-
-static inline int min_int(int a, int b)
-{
-	if (a < b)
-		return a;
-	return b;
-}
-
-
-static int get_key_handler(struct nl_msg *msg, void *arg)
-{
-	struct nlattr *tb[NL80211_ATTR_MAX + 1];
-	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
-
-	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
-		  genlmsg_attrlen(gnlh, 0), NULL);
-
-	/*
-	 * TODO: validate the key index and mac address!
-	 * Otherwise, there's a race condition as soon as
-	 * the kernel starts sending key notifications.
-	 */
-
-	if (tb[NL80211_ATTR_KEY_SEQ])
-		memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
-		       min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
-	return NL_SKIP;
-}
-
-
-static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
-			   int idx, u8 *seq)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_GET_KEY, 0);
-
-	if (addr)
-		NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
-	NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
-
-	memset(seq, 0, 6);
-
-	return send_and_recv_msgs(drv, msg, get_key_handler, seq);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_set_rate_sets(void *priv, int *supp_rates, int *basic_rates,
-			      int mode)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-	u8 rates[NL80211_MAX_SUPP_RATES];
-	u8 rates_len = 0;
-	int i;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
-		    NL80211_CMD_SET_BSS, 0);
-
-	for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
-		rates[rates_len++] = basic_rates[i] / 5;
-
-	NLA_PUT(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
-
-	/* TODO: multi-BSS support */
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-
-	return send_and_recv_msgs(drv, msg, NULL, NULL);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_send_frame(void *priv, const void *data, size_t len,
-			   int encrypt, int flags)
-{
-	__u8 rtap_hdr[] = {
-		0x00, 0x00, /* radiotap version */
-		0x0e, 0x00, /* radiotap length */
-		0x02, 0xc0, 0x00, 0x00, /* bmap: flags, tx and rx flags */
-		IEEE80211_RADIOTAP_F_FRAG, /* F_FRAG (fragment if required) */
-		0x00,       /* padding */
-		0x00, 0x00, /* RX and TX flags to indicate that */
-		0x00, 0x00, /* this is the injected frame directly */
-	};
-	struct i802_driver_data *drv = priv;
-	struct iovec iov[2] = {
-		{
-			.iov_base = &rtap_hdr,
-			.iov_len = sizeof(rtap_hdr),
-		},
-		{
-			.iov_base = (void*)data,
-			.iov_len = len,
-		}
-	};
-	struct msghdr msg = {
-		.msg_name = NULL,
-		.msg_namelen = 0,
-		.msg_iov = iov,
-		.msg_iovlen = 2,
-		.msg_control = NULL,
-		.msg_controllen = 0,
-		.msg_flags = 0,
-	};
-
-	if (encrypt)
-		rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
-
-	return sendmsg(drv->monitor_sock, &msg, flags);
-}
-
-static int i802_send_mgmt_frame(void *priv, const void *data, size_t len,
-				int flags)
-{
-	struct ieee80211_mgmt *mgmt;
-	int do_not_encrypt = 0;
-	u16 fc;
-
-	mgmt = (struct ieee80211_mgmt *) data;
-	fc = le_to_host16(mgmt->frame_control);
-
-	if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
-	    WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
-		/*
-		 * Only one of the authentication frame types is encrypted.
-		 * In order for static WEP encryption to work properly (i.e.,
-		 * to not encrypt the frame), we need to tell mac80211 about
-		 * the frames that must not be encrypted.
-		 */
-		u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
-		u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
-		if (auth_alg == WLAN_AUTH_OPEN ||
-		    (auth_alg == WLAN_AUTH_SHARED_KEY && auth_trans != 3))
-			do_not_encrypt = 1;
-	}
-
-	return i802_send_frame(priv, data, len, !do_not_encrypt, flags);
-}
-
-/* Set kernel driver on given frequency (MHz) */
-static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -1;
-
-	drv->last_freq = freq->freq;
-	drv->last_freq_ht = freq->ht_enabled;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
-		    NL80211_CMD_SET_WIPHY, 0);
-
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq);
-	if (freq->ht_enabled) {
-		switch (freq->sec_channel_offset) {
-		case -1:
-			NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
-				    NL80211_CHAN_HT40MINUS);
-			break;
-		case 1:
-			NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
-				    NL80211_CHAN_HT40PLUS);
-			break;
-		default:
-			NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
-				    NL80211_CHAN_HT20);
-			break;
-		}
-	}
-
-	if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
-		return 0;
- nla_put_failure:
-	return -1;
-}
-
-
-static int i802_set_rts(void *priv, int rts)
-{
-	struct i802_driver_data *drv = priv;
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.rts.value = rts;
-	iwr.u.rts.fixed = 1;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIWRTS, &iwr) < 0) {
-		perror("ioctl[SIOCSIWRTS]");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int i802_set_frag(void *priv, int frag)
-{
-	struct i802_driver_data *drv = priv;
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.frag.value = frag;
-	iwr.u.frag.fixed = 1;
-
-	if (ioctl(drv->ioctl_sock, SIOCSIWFRAG, &iwr) < 0) {
-		perror("ioctl[SIOCSIWFRAG]");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int i802_set_retry(void *priv, int short_retry, int long_retry)
-{
-	struct i802_driver_data *drv = priv;
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-
-	iwr.u.retry.value = short_retry;
-	iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
-	if (ioctl(drv->ioctl_sock, SIOCSIWRETRY, &iwr) < 0) {
-		perror("ioctl[SIOCSIWRETRY(short)]");
-		return -1;
-	}
-
-	iwr.u.retry.value = long_retry;
-	iwr.u.retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
-	if (ioctl(drv->ioctl_sock, SIOCSIWRETRY, &iwr) < 0) {
-		perror("ioctl[SIOCSIWRETRY(long)]");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int i802_flush(void *priv)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -1;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_DEL_STATION, 0);
-
-	/*
-	 * XXX: FIX! this needs to flush all VLANs too
-	 */
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->iface));
-
-	return send_and_recv_msgs(drv, msg, NULL, NULL);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int get_sta_handler(struct nl_msg *msg, void *arg)
-{
-	struct nlattr *tb[NL80211_ATTR_MAX + 1];
-	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
-	struct hostap_sta_driver_data *data = arg;
-	struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
-	static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
-		[NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
-		[NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
-		[NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
-		[NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
-		[NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
-	};
-
-	nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
-		  genlmsg_attrlen(gnlh, 0), NULL);
-
-	/*
-	 * TODO: validate the interface and mac address!
-	 * Otherwise, there's a race condition as soon as
-	 * the kernel starts sending station notifications.
-	 */
-
-	if (!tb[NL80211_ATTR_STA_INFO]) {
-		wpa_printf(MSG_DEBUG, "sta stats missing!");
-		return NL_SKIP;
-	}
-	if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
-			     tb[NL80211_ATTR_STA_INFO],
-			     stats_policy)) {
-		wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
-		return NL_SKIP;
-	}
-
-	if (stats[NL80211_STA_INFO_INACTIVE_TIME])
-		data->inactive_msec =
-			nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
-	if (stats[NL80211_STA_INFO_RX_BYTES])
-		data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
-	if (stats[NL80211_STA_INFO_TX_BYTES])
-		data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
-	if (stats[NL80211_STA_INFO_RX_PACKETS])
-		data->rx_packets =
-			nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
-	if (stats[NL80211_STA_INFO_TX_PACKETS])
-		data->tx_packets =
-			nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
-
-	return NL_SKIP;
-}
-
-static int i802_read_sta_data(void *priv, struct hostap_sta_driver_data *data,
-			      const u8 *addr)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-
-	os_memset(data, 0, sizeof(*data));
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_GET_STATION, 0);
-
-	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-
-	return send_and_recv_msgs(drv, msg, get_sta_handler, data);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_send_eapol(void *priv, const u8 *addr, const u8 *data,
-			   size_t data_len, int encrypt, const u8 *own_addr)
-{
-	struct i802_driver_data *drv = priv;
-	struct ieee80211_hdr *hdr;
-	size_t len;
-	u8 *pos;
-	int res;
-#if 0 /* FIX */
-	int qos = sta->flags & WLAN_STA_WME;
-#else
-	int qos = 0;
-#endif
-
-	len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
-		data_len;
-	hdr = os_zalloc(len);
-	if (hdr == NULL) {
-		printf("malloc() failed for i802_send_data(len=%lu)\n",
-		       (unsigned long) len);
-		return -1;
-	}
-
-	hdr->frame_control =
-		IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
-	hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
-	if (encrypt)
-		hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
-#if 0 /* To be enabled if qos determination is added above */
-	if (qos) {
-		hdr->frame_control |=
-			host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
-	}
-#endif
-
-	memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
-	memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
-	memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
-	pos = (u8 *) (hdr + 1);
-
-#if 0 /* To be enabled if qos determination is added above */
-	if (qos) {
-		/* add an empty QoS header if needed */
-		pos[0] = 0;
-		pos[1] = 0;
-		pos += 2;
-	}
-#endif
-
-	memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
-	pos += sizeof(rfc1042_header);
-	WPA_PUT_BE16(pos, ETH_P_PAE);
-	pos += 2;
-	memcpy(pos, data, data_len);
-
-	res = i802_send_frame(drv, (u8 *) hdr, len, encrypt, 0);
-	free(hdr);
-
-	if (res < 0) {
-		perror("i802_send_eapol: send");
-		printf("i802_send_eapol - packet len: %lu - failed\n",
-		       (unsigned long) len);
-	}
-
-	return res;
-}
-
-
-static int i802_sta_add(const char *ifname, void *priv,
-			struct hostapd_sta_add_params *params)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-	int ret = -ENOBUFS;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_NEW_STATION, 0);
-
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->iface));
-	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr);
-	NLA_PUT_U16(msg, NL80211_ATTR_STA_AID, params->aid);
-	NLA_PUT(msg, NL80211_ATTR_STA_SUPPORTED_RATES, params->supp_rates_len,
-		params->supp_rates);
-	NLA_PUT_U16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
-		    params->listen_interval);
-
-#ifdef CONFIG_IEEE80211N
-	if (params->ht_capabilities) {
-		NLA_PUT(msg, NL80211_ATTR_HT_CAPABILITY,
-			params->ht_capabilities->length,
-			&params->ht_capabilities->data);
-	}
-#endif /* CONFIG_IEEE80211N */
-
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
-	if (ret)
-		wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_NEW_STATION "
-			   "result: %d (%s)", ret, strerror(-ret));
-	if (ret == -EEXIST)
-		ret = 0;
- nla_put_failure:
-	return ret;
-}
-
-
-static int i802_sta_remove(void *priv, const u8 *addr)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-	int ret;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_DEL_STATION, 0);
-
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->iface));
-	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
-
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
-	if (ret == -ENOENT)
-		return 0;
-	return ret;
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_sta_set_flags(void *priv, const u8 *addr,
-			      int total_flags, int flags_or, int flags_and)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg, *flags = NULL;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	flags = nlmsg_alloc();
-	if (!flags) {
-		nlmsg_free(msg);
-		return -ENOMEM;
-	}
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_SET_STATION, 0);
-
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->iface));
-	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
-
-	if (total_flags & WLAN_STA_AUTHORIZED)
-		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_AUTHORIZED);
-
-	if (total_flags & WLAN_STA_WMM)
-		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_WME);
-
-	if (total_flags & WLAN_STA_SHORT_PREAMBLE)
-		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_SHORT_PREAMBLE);
-
-	if (total_flags & WLAN_STA_MFP)
-		NLA_PUT_FLAG(flags, NL80211_STA_FLAG_MFP);
-
-	if (nla_put_nested(msg, NL80211_ATTR_STA_FLAGS, flags))
-		goto nla_put_failure;
-
-	nlmsg_free(flags);
-
-	return send_and_recv_msgs(drv, msg, NULL, NULL);
- nla_put_failure:
- 	nlmsg_free(flags);
-	return -ENOBUFS;
-}
-
-
-static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
-				    int cw_min, int cw_max, int burst_time)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-	struct nlattr *txq, *params;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -1;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_SET_WIPHY, 0);
-
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-
-	txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
-	if (!txq)
-		goto nla_put_failure;
-
-	/* We are only sending parameters for a single TXQ at a time */
-	params = nla_nest_start(msg, 1);
-	if (!params)
-		goto nla_put_failure;
-
-	NLA_PUT_U8(msg, NL80211_TXQ_ATTR_QUEUE, queue);
-	/* Burst time is configured in units of 0.1 msec and TXOP parameter in
-	 * 32 usec, so need to convert the value here. */
-	NLA_PUT_U16(msg, NL80211_TXQ_ATTR_TXOP, (burst_time * 100 + 16) / 32);
-	NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min);
-	NLA_PUT_U16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max);
-	NLA_PUT_U8(msg, NL80211_TXQ_ATTR_AIFS, aifs);
-
-	nla_nest_end(msg, params);
-
-	nla_nest_end(msg, txq);
-
-	if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
-		return 0;
- nla_put_failure:
-	return -1;
-}
-
-
-static void nl80211_remove_iface(struct i802_driver_data *drv, int ifidx)
-{
-	struct nl_msg *msg;
-
-	/* stop listening for EAPOL on this interface */
-	del_ifidx(drv, ifidx);
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		goto nla_put_failure;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_DEL_INTERFACE, 0);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, ifidx);
-
-	if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
-		return;
- nla_put_failure:
-	printf("Failed to remove interface.\n");
-}
-
-
-static int nl80211_create_iface(struct i802_driver_data *drv,
-				const char *ifname,
-				enum nl80211_iftype iftype,
-				const u8 *addr)
-{
-	struct nl_msg *msg, *flags = NULL;
-	int ifidx;
-	struct ifreq ifreq;
-	struct iwreq iwr;
-	int ret = -ENOBUFS;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -1;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_NEW_INTERFACE, 0);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-	NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, ifname);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, iftype);
-
-	if (iftype == NL80211_IFTYPE_MONITOR) {
-		int err;
-
-		flags = nlmsg_alloc();
-		if (!flags)
-			goto nla_put_failure;
-
-		NLA_PUT_FLAG(flags, NL80211_MNTR_FLAG_COOK_FRAMES);
-
-		err = nla_put_nested(msg, NL80211_ATTR_MNTR_FLAGS, flags);
-
-		nlmsg_free(flags);
-
-		if (err)
-			goto nla_put_failure;
-	}
-
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
-	if (ret) {
- nla_put_failure:
-		printf("Failed to create interface %s.\n", ifname);
-		return ret;
-	}
-
-	ifidx = if_nametoindex(ifname);
-
-	if (ifidx <= 0)
-		return -1;
-
-	/* start listening for EAPOL on this interface */
-	add_ifidx(drv, ifidx);
-
-	if (addr) {
-		switch (iftype) {
-		case NL80211_IFTYPE_AP:
-			os_strlcpy(ifreq.ifr_name, ifname, IFNAMSIZ);
-			memcpy(ifreq.ifr_hwaddr.sa_data, addr, ETH_ALEN);
-			ifreq.ifr_hwaddr.sa_family = ARPHRD_ETHER;
-
-			if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifreq)) {
-				nl80211_remove_iface(drv, ifidx);
-				return -1;
-			}
-			break;
-		case NL80211_IFTYPE_WDS:
-			memset(&iwr, 0, sizeof(iwr));
-			os_strlcpy(iwr.ifr_name, ifname, IFNAMSIZ);
-			iwr.u.addr.sa_family = ARPHRD_ETHER;
-			memcpy(iwr.u.addr.sa_data, addr, ETH_ALEN);
-			if (ioctl(drv->ioctl_sock, SIOCSIWAP, &iwr))
-				return -1;
-			break;
-		default:
-			/* nothing */
-			break;
-		}
-	}
-
-	return ifidx;
-}
-
-
-static int i802_bss_add(void *priv, const char *ifname, const u8 *bssid)
-{
-	struct i802_driver_data *drv = priv;
-	int ifidx;
-	struct i802_bss *bss;
-
-	bss = os_zalloc(sizeof(*bss));
-	if (bss == NULL)
-		return -1;
-	os_strlcpy(bss->iface, ifname, IFNAMSIZ);
-
-	ifidx = nl80211_create_iface(priv, ifname, NL80211_IFTYPE_AP, bssid);
-	if (ifidx < 0) {
-		os_free(bss);
-		return -1;
-	}
-	if (hostapd_set_iface_flags(priv, ifname, 1)) {
-		nl80211_remove_iface(priv, ifidx);
-		os_free(bss);
-		return -1;
-	}
-	bss->next = drv->bss.next;
-	drv->bss.next = bss;
-	return 0;
-}
-
-
-static int i802_bss_remove(void *priv, const char *ifname)
-{
-	struct i802_driver_data *drv = priv;
-	struct i802_bss *bss, *prev;
-	nl80211_remove_iface(priv, if_nametoindex(ifname));
-	prev = &drv->bss;
-	bss = drv->bss.next;
-	while (bss) {
-		if (os_strncmp(ifname, bss->iface, IFNAMSIZ) == 0) {
-			prev->next = bss->next;
-			os_free(bss);
-			break;
-		}
-		prev = bss;
-		bss = bss->next;
-	}
-	return 0;
-}
-
-
-static int i802_set_beacon(const char *iface, void *priv,
-			   const u8 *head, size_t head_len,
-			   const u8 *tail, size_t tail_len, int dtim_period)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-	u8 cmd = NL80211_CMD_NEW_BEACON;
-	int ret;
-	struct i802_bss *bss;
-
-	bss = get_bss(drv, iface);
-	if (bss == NULL)
-		return -ENOENT;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	wpa_printf(MSG_DEBUG, "nl80211: Set beacon (iface=%s beacon_set=%d)",
-		   iface, bss->beacon_set);
-	if (bss->beacon_set)
-		cmd = NL80211_CMD_SET_BEACON;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, cmd, 0);
-	NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head);
-	NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
-	NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, drv->beacon_int);
-	NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period);
-
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
-	if (!ret)
-		bss->beacon_set = 1;
-	return ret;
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_del_beacon(struct i802_driver_data *drv)
-{
-	struct nl_msg *msg;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_DEL_BEACON, 0);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-
-	return send_and_recv_msgs(drv, msg, NULL, NULL);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_set_beacon_int(void *priv, int value)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-
-	drv->beacon_int = value;
-
-	if (!drv->bss.beacon_set)
-		return 0;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	wpa_printf(MSG_DEBUG, "nl80211: Set beacon interval %d "
-		   "(beacon_set=%d)", value, drv->bss.beacon_set);
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_SET_BEACON, 0);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-
-	NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, value);
-
-	return send_and_recv_msgs(drv, msg, NULL, NULL);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_set_bss(void *priv, int cts, int preamble, int slot)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, 0,
-		    NL80211_CMD_SET_BSS, 0);
-
-	if (cts >= 0)
-		NLA_PUT_U8(msg, NL80211_ATTR_BSS_CTS_PROT, cts);
-	if (preamble >= 0)
-		NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble);
-	if (slot >= 0)
-		NLA_PUT_U8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot);
-
-	/* TODO: multi-BSS support */
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-
-	return send_and_recv_msgs(drv, msg, NULL, NULL);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_set_cts_protect(void *priv, int value)
-{
-	return i802_set_bss(priv, value, -1, -1);
-}
-
-
-static int i802_set_preamble(void *priv, int value)
-{
-	return i802_set_bss(priv, -1, value, -1);
-}
-
-
-static int i802_set_short_slot_time(void *priv, int value)
-{
-	return i802_set_bss(priv, -1, -1, value);
-}
-
-
-static enum nl80211_iftype i802_if_type(enum hostapd_driver_if_type type)
-{
-	switch (type) {
-	case HOSTAPD_IF_VLAN:
-		return NL80211_IFTYPE_AP_VLAN;
-	case HOSTAPD_IF_WDS:
-		return NL80211_IFTYPE_WDS;
-	}
-	return -1;
-}
-
-
-static int i802_if_add(const char *iface, void *priv,
-		       enum hostapd_driver_if_type type, char *ifname,
-		       const u8 *addr)
-{
-	if (nl80211_create_iface(priv, ifname, i802_if_type(type), addr) < 0)
-		return -1;
-	return 0;
-}
-
-
-static int i802_if_update(void *priv, enum hostapd_driver_if_type type,
-			  char *ifname, const u8 *addr)
-{
-	/* unused at the moment */
-	return -1;
-}
-
-
-static int i802_if_remove(void *priv, enum hostapd_driver_if_type type,
-			  const char *ifname, const u8 *addr)
-{
-	nl80211_remove_iface(priv, if_nametoindex(ifname));
-	return 0;
-}
-
-
-struct phy_info_arg {
-	u16 *num_modes;
-	struct hostapd_hw_modes *modes;
-};
-
-static int phy_info_handler(struct nl_msg *msg, void *arg)
-{
-	struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
-	struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
-	struct phy_info_arg *phy_info = arg;
-
-	struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
-
-	struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
-	static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
-		[NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
-		[NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
-		[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
-		[NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
-		[NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
-		[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
-	};
-
-	struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
-	static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
-		[NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
-		[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
-	};
-
-	struct nlattr *nl_band;
-	struct nlattr *nl_freq;
-	struct nlattr *nl_rate;
-	int rem_band, rem_freq, rem_rate;
-	struct hostapd_hw_modes *mode;
-	int idx, mode_is_set;
-
-	nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
-		  genlmsg_attrlen(gnlh, 0), NULL);
-
-	if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
-		return NL_SKIP;
-
-	nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
-		mode = realloc(phy_info->modes, (*phy_info->num_modes + 1) * sizeof(*mode));
-		if (!mode)
-			return NL_SKIP;
-		phy_info->modes = mode;
-
-		mode_is_set = 0;
-
-		mode = &phy_info->modes[*(phy_info->num_modes)];
-		memset(mode, 0, sizeof(*mode));
-		*(phy_info->num_modes) += 1;
-
-		nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
-			  nla_len(nl_band), NULL);
-
-		if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) {
-			mode->ht_capab = nla_get_u16(
-				tb_band[NL80211_BAND_ATTR_HT_CAPA]);
-		}
-
-		nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
-			nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
-				  nla_len(nl_freq), freq_policy);
-			if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
-				continue;
-			mode->num_channels++;
-		}
-
-		mode->channels = calloc(mode->num_channels, sizeof(struct hostapd_channel_data));
-		if (!mode->channels)
-			return NL_SKIP;
-
-		idx = 0;
-
-		nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
-			nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
-				  nla_len(nl_freq), freq_policy);
-			if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
-				continue;
-
-			mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
-			mode->channels[idx].flag = 0;
-
-			if (!mode_is_set) {
-				/* crude heuristic */
-				if (mode->channels[idx].freq < 4000)
-					mode->mode = HOSTAPD_MODE_IEEE80211B;
-				else
-					mode->mode = HOSTAPD_MODE_IEEE80211A;
-				mode_is_set = 1;
-			}
-
-			/* crude heuristic */
-			if (mode->channels[idx].freq < 4000)
-				if (mode->channels[idx].freq == 2848)
-					mode->channels[idx].chan = 14;
-				else
-					mode->channels[idx].chan = (mode->channels[idx].freq - 2407) / 5;
-			else
-				mode->channels[idx].chan = mode->channels[idx].freq/5 - 1000;
-
-			if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
-				mode->channels[idx].flag |=
-					HOSTAPD_CHAN_DISABLED;
-			if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
-				mode->channels[idx].flag |=
-					HOSTAPD_CHAN_PASSIVE_SCAN;
-			if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
-				mode->channels[idx].flag |=
-					HOSTAPD_CHAN_NO_IBSS;
-			if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
-				mode->channels[idx].flag |=
-					HOSTAPD_CHAN_RADAR;
-
-			if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
-			    !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
-				mode->channels[idx].max_tx_power =
-					nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER]) / 100;
-
-			idx++;
-		}
-
-		nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
-			nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
-				  nla_len(nl_rate), rate_policy);
-			if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
-				continue;
-			mode->num_rates++;
-		}
-
-		mode->rates = calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
-		if (!mode->rates)
-			return NL_SKIP;
-
-		idx = 0;
-
-		nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
-			nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
-				  nla_len(nl_rate), rate_policy);
-			if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
-				continue;
-			mode->rates[idx].rate = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]);
-
-			/* crude heuristic */
-			if (mode->mode == HOSTAPD_MODE_IEEE80211B &&
-			    mode->rates[idx].rate > 200)
-				mode->mode = HOSTAPD_MODE_IEEE80211G;
-
-			if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
-				mode->rates[idx].flags |= HOSTAPD_RATE_PREAMBLE2;
-
-			idx++;
-		}
-	}
-
-	return NL_SKIP;
-}
-
-static struct hostapd_hw_modes *i802_add_11b(struct hostapd_hw_modes *modes,
-					     u16 *num_modes)
-{
-	u16 m;
-	struct hostapd_hw_modes *mode11g = NULL, *nmodes, *mode;
-	int i, mode11g_idx = -1;
-
-	/* If only 802.11g mode is included, use it to construct matching
-	 * 802.11b mode data. */
-
-	for (m = 0; m < *num_modes; m++) {
-		if (modes[m].mode == HOSTAPD_MODE_IEEE80211B)
-			return modes; /* 802.11b already included */
-		if (modes[m].mode == HOSTAPD_MODE_IEEE80211G)
-			mode11g_idx = m;
-	}
-
-	if (mode11g_idx < 0)
-		return modes; /* 2.4 GHz band not supported at all */
-
-	nmodes = os_realloc(modes, (*num_modes + 1) * sizeof(*nmodes));
-	if (nmodes == NULL)
-		return modes; /* Could not add 802.11b mode */
-
-	mode = &nmodes[*num_modes];
-	os_memset(mode, 0, sizeof(*mode));
-	(*num_modes)++;
-	modes = nmodes;
-
-	mode->mode = HOSTAPD_MODE_IEEE80211B;
-
-	mode11g = &modes[mode11g_idx];
-	mode->num_channels = mode11g->num_channels;
-	mode->channels = os_malloc(mode11g->num_channels *
-				   sizeof(struct hostapd_channel_data));
-	if (mode->channels == NULL) {
-		(*num_modes)--;
-		return modes; /* Could not add 802.11b mode */
-	}
-	os_memcpy(mode->channels, mode11g->channels,
-		  mode11g->num_channels * sizeof(struct hostapd_channel_data));
-
-	mode->num_rates = 0;
-	mode->rates = os_malloc(4 * sizeof(struct hostapd_rate_data));
-	if (mode->rates == NULL) {
-		os_free(mode->channels);
-		(*num_modes)--;
-		return modes; /* Could not add 802.11b mode */
-	}
-
-	for (i = 0; i < mode11g->num_rates; i++) {
-		if (mode11g->rates[i].rate > 110 ||
-		    mode11g->rates[i].flags &
-		    (HOSTAPD_RATE_ERP | HOSTAPD_RATE_OFDM))
-			continue;
-		mode->rates[mode->num_rates] = mode11g->rates[i];
-		mode->num_rates++;
-		if (mode->num_rates == 4)
-			break;
-	}
-
-	if (mode->num_rates == 0) {
-		os_free(mode->channels);
-		os_free(mode->rates);
-		(*num_modes)--;
-		return modes; /* No 802.11b rates */
-	}
-
-	wpa_printf(MSG_DEBUG, "nl80211: Added 802.11b mode based on 802.11g "
-		   "information");
-
-	return modes;
-}
-
-static struct hostapd_hw_modes *i802_get_hw_feature_data(void *priv,
-							 u16 *num_modes,
-							 u16 *flags)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-	struct phy_info_arg result = {
-		.num_modes = num_modes,
-		.modes = NULL,
-	};
-
-	*num_modes = 0;
-	*flags = 0;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return NULL;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_GET_WIPHY, 0);
-
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
-
-	if (send_and_recv_msgs(drv, msg, phy_info_handler, &result) == 0)
-		return i802_add_11b(result.modes, num_modes);
- nla_put_failure:
-	return NULL;
-}
-
-
-static int i802_set_sta_vlan(void *priv, const u8 *addr,
-			     const char *ifname, int vlan_id)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_SET_STATION, 0);
-
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(drv->iface));
-	NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(ifname));
-
-	return send_and_recv_msgs(drv, msg, NULL, NULL);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static int i802_set_country(void *priv, const char *country)
-{
-	struct i802_driver_data *drv = priv;
-	struct nl_msg *msg;
-	char alpha2[3];
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_REQ_SET_REG, 0);
-
-	alpha2[0] = country[0];
-	alpha2[1] = country[1];
-	alpha2[2] = '\0';
-	NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, alpha2);
-
-	return send_and_recv_msgs(drv, msg, NULL, NULL);
- nla_put_failure:
-	return -ENOBUFS;
-}
-
-
-static void handle_tx_callback(struct hostapd_data *hapd, u8 *buf, size_t len,
-			       int ok)
-{
-	struct ieee80211_hdr *hdr;
-	u16 fc, type, stype;
-
-	hdr = (struct ieee80211_hdr *) buf;
-	fc = le_to_host16(hdr->frame_control);
-
-	type = WLAN_FC_GET_TYPE(fc);
-	stype = WLAN_FC_GET_STYPE(fc);
-
-	switch (type) {
-	case WLAN_FC_TYPE_MGMT:
-		wpa_printf(MSG_DEBUG, "MGMT (TX callback) %s",
-			   ok ? "ACK" : "fail");
-		hostapd_mgmt_tx_cb(hapd, buf, len, stype, ok);
-		break;
-	case WLAN_FC_TYPE_CTRL:
-		wpa_printf(MSG_DEBUG, "CTRL (TX callback) %s",
-			   ok ? "ACK" : "fail");
-		break;
-	case WLAN_FC_TYPE_DATA:
-		hostapd_tx_status(hapd, hdr->addr1, buf, len, ok);
-		break;
-	default:
-		printf("unknown TX callback frame type %d\n", type);
-		break;
-	}
-}
-
-
-static void handle_frame(struct i802_driver_data *drv,
-			 struct hostapd_iface *iface, u8 *buf, size_t len,
-			 struct hostapd_frame_info *hfi,
-			 enum ieee80211_msg_type msg_type)
-{
-	struct ieee80211_hdr *hdr;
-	u16 fc, type, stype;
-	size_t data_len = len;
-	struct hostapd_data *hapd = NULL;
-	int broadcast_bssid = 0;
-	size_t i;
-	u8 *bssid;
-
-	/*
-	 * PS-Poll frames are 16 bytes. All other frames are
-	 * 24 bytes or longer.
-	 */
-	if (len < 16)
-		return;
-
-	hdr = (struct ieee80211_hdr *) buf;
-	fc = le_to_host16(hdr->frame_control);
-
-	type = WLAN_FC_GET_TYPE(fc);
-	stype = WLAN_FC_GET_STYPE(fc);
-
-	switch (type) {
-	case WLAN_FC_TYPE_DATA:
-		if (len < 24)
-			return;
-		switch (fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) {
-		case WLAN_FC_TODS:
-			bssid = hdr->addr1;
-			break;
-		case WLAN_FC_FROMDS:
-			bssid = hdr->addr2;
-			break;
-		default:
-			/* discard */
-			return;
-		}
-		break;
-	case WLAN_FC_TYPE_CTRL:
-		/* discard non-ps-poll frames */
-		if (stype != WLAN_FC_STYPE_PSPOLL)
-			return;
-		bssid = hdr->addr1;
-		break;
-	case WLAN_FC_TYPE_MGMT:
-		bssid = hdr->addr3;
-		break;
-	default:
-		/* discard */
-		return;
-	}
-
-	/* find interface frame belongs to */
-	for (i = 0; i < iface->num_bss; i++) {
-		if (memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0) {
-			hapd = iface->bss[i];
-			break;
-		}
-	}
-
-	if (hapd == NULL) {
-		hapd = iface->bss[0];
-
-		if (bssid[0] != 0xff || bssid[1] != 0xff ||
-		    bssid[2] != 0xff || bssid[3] != 0xff ||
-		    bssid[4] != 0xff || bssid[5] != 0xff) {
-			/*
-			 * Unknown BSSID - drop frame if this is not from
-			 * passive scanning or a beacon (at least ProbeReq
-			 * frames to other APs may be allowed through RX
-			 * filtering in the wlan hw/driver)
-			 */
-			if ((type != WLAN_FC_TYPE_MGMT ||
-			     stype != WLAN_FC_STYPE_BEACON))
-				return;
-		} else
-			broadcast_bssid = 1;
-	}
-
-	switch (msg_type) {
-	case ieee80211_msg_normal:
-		/* continue processing */
-		break;
-	case ieee80211_msg_tx_callback_ack:
-		handle_tx_callback(hapd, buf, data_len, 1);
-		return;
-	case ieee80211_msg_tx_callback_fail:
-		handle_tx_callback(hapd, buf, data_len, 0);
-		return;
-	}
-
-	switch (type) {
-	case WLAN_FC_TYPE_MGMT:
-		if (stype != WLAN_FC_STYPE_BEACON &&
-		    stype != WLAN_FC_STYPE_PROBE_REQ)
-			wpa_printf(MSG_MSGDUMP, "MGMT");
-		if (broadcast_bssid) {
-			for (i = 0; i < iface->num_bss; i++)
-				hostapd_mgmt_rx(iface->bss[i], buf, data_len,
-						stype, hfi);
-		} else
-			hostapd_mgmt_rx(hapd, buf, data_len, stype, hfi);
-		break;
-	case WLAN_FC_TYPE_CTRL:
-		/* can only get here with PS-Poll frames */
-		wpa_printf(MSG_DEBUG, "CTRL");
-		hostapd_rx_from_unknown_sta(drv->hapd, hdr->addr2);
-		break;
-	case WLAN_FC_TYPE_DATA:
-		hostapd_rx_from_unknown_sta(drv->hapd, hdr->addr2);
-		break;
-	}
-}
-
-
-static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	struct i802_driver_data *drv = eloop_ctx;
-	struct sockaddr_ll lladdr;
-	unsigned char buf[3000];
-	int len;
-	socklen_t fromlen = sizeof(lladdr);
-
-	len = recvfrom(sock, buf, sizeof(buf), 0,
-		       (struct sockaddr *)&lladdr, &fromlen);
-	if (len < 0) {
-		perror("recv");
-		return;
-	}
-
-	if (have_ifidx(drv, lladdr.sll_ifindex)) {
-		struct hostapd_data *hapd;
-		hapd = hostapd_sta_get_bss(drv->hapd, lladdr.sll_addr);
-		if (!hapd)
-			return;
-		hostapd_eapol_receive(hapd, lladdr.sll_addr, buf, len);
-	}
-}
-
-
-static void handle_monitor_read(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	struct i802_driver_data *drv = eloop_ctx;
-	int len;
-	unsigned char buf[3000];
-	struct hostapd_data *hapd = drv->hapd;
-	struct ieee80211_radiotap_iterator iter;
-	int ret;
-	struct hostapd_frame_info hfi;
-	int injected = 0, failed = 0, msg_type, rxflags = 0;
-
-	len = recv(sock, buf, sizeof(buf), 0);
-	if (len < 0) {
-		perror("recv");
-		return;
-	}
-
-	if (ieee80211_radiotap_iterator_init(&iter, (void*)buf, len)) {
-		printf("received invalid radiotap frame\n");
-		return;
-	}
-
-	memset(&hfi, 0, sizeof(hfi));
-
-	while (1) {
-		ret = ieee80211_radiotap_iterator_next(&iter);
-		if (ret == -ENOENT)
-			break;
-		if (ret) {
-			printf("received invalid radiotap frame (%d)\n", ret);
-			return;
-		}
-		switch (iter.this_arg_index) {
-		case IEEE80211_RADIOTAP_FLAGS:
-			if (*iter.this_arg & IEEE80211_RADIOTAP_F_FCS)
-				len -= 4;
-			break;
-		case IEEE80211_RADIOTAP_RX_FLAGS:
-			rxflags = 1;
-			break;
-		case IEEE80211_RADIOTAP_TX_FLAGS:
-			injected = 1;
-			failed = le_to_host16((*(uint16_t *) iter.this_arg)) &
-					IEEE80211_RADIOTAP_F_TX_FAIL;
-			break;
-		case IEEE80211_RADIOTAP_DATA_RETRIES:
-			break;
-		case IEEE80211_RADIOTAP_CHANNEL:
-			/* TODO convert from freq/flags to channel number
-			hfi.channel = XXX;
-			hfi.phytype = XXX;
-			 */
-			break;
-		case IEEE80211_RADIOTAP_RATE:
-			hfi.datarate = *iter.this_arg * 5;
-			break;
-		case IEEE80211_RADIOTAP_DB_ANTSIGNAL:
-			hfi.ssi_signal = *iter.this_arg;
-			break;
-		}
-	}
-
-	if (rxflags && injected)
-		return;
-
-	if (!injected)
-		msg_type = ieee80211_msg_normal;
-	else if (failed)
-		msg_type = ieee80211_msg_tx_callback_fail;
-	else
-		msg_type = ieee80211_msg_tx_callback_ack;
-
-	handle_frame(drv, hapd->iface, buf + iter.max_length,
-		     len - iter.max_length, &hfi, msg_type);
-}
-
-
-/*
- * we post-process the filter code later and rewrite
- * this to the offset to the last instruction
- */
-#define PASS	0xFF
-#define FAIL	0xFE
-
-static struct sock_filter msock_filter_insns[] = {
-	/*
-	 * do a little-endian load of the radiotap length field
-	 */
-	/* load lower byte into A */
-	BPF_STMT(BPF_LD  | BPF_B | BPF_ABS, 2),
-	/* put it into X (== index register) */
-	BPF_STMT(BPF_MISC| BPF_TAX, 0),
-	/* load upper byte into A */
-	BPF_STMT(BPF_LD  | BPF_B | BPF_ABS, 3),
-	/* left-shift it by 8 */
-	BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 8),
-	/* or with X */
-	BPF_STMT(BPF_ALU | BPF_OR | BPF_X, 0),
-	/* put result into X */
-	BPF_STMT(BPF_MISC| BPF_TAX, 0),
-
-	/*
-	 * Allow management frames through, this also gives us those
-	 * management frames that we sent ourselves with status
-	 */
-	/* load the lower byte of the IEEE 802.11 frame control field */
-	BPF_STMT(BPF_LD  | BPF_B | BPF_IND, 0),
-	/* mask off frame type and version */
-	BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xF),
-	/* accept frame if it's both 0, fall through otherwise */
-	BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0, PASS, 0),
-
-	/*
-	 * TODO: add a bit to radiotap RX flags that indicates
-	 * that the sending station is not associated, then
-	 * add a filter here that filters on our DA and that flag
-	 * to allow us to deauth frames to that bad station.
-	 *
-	 * Not a regression -- we didn't do it before either.
-	 */
-
-#if 0
-	/*
-	 * drop non-data frames, WDS frames
-	 */
-	/* load the lower byte of the frame control field */
-	BPF_STMT(BPF_LD   | BPF_B | BPF_IND, 0),
-	/* mask off QoS bit */
-	BPF_STMT(BPF_ALU  | BPF_AND | BPF_K, 0x0c),
-	/* drop non-data frames */
-	BPF_JUMP(BPF_JMP  | BPF_JEQ | BPF_K, 8, 0, FAIL),
-	/* load the upper byte of the frame control field */
-	BPF_STMT(BPF_LD   | BPF_B | BPF_IND, 0),
-	/* mask off toDS/fromDS */
-	BPF_STMT(BPF_ALU  | BPF_AND | BPF_K, 0x03),
-	/* drop WDS frames */
-	BPF_JUMP(BPF_JMP  | BPF_JEQ | BPF_K, 3, FAIL, 0),
-#endif
-
-	/*
-	 * add header length to index
-	 */
-	/* load the lower byte of the frame control field */
-	BPF_STMT(BPF_LD   | BPF_B | BPF_IND, 0),
-	/* mask off QoS bit */
-	BPF_STMT(BPF_ALU  | BPF_AND | BPF_K, 0x80),
-	/* right shift it by 6 to give 0 or 2 */
-	BPF_STMT(BPF_ALU  | BPF_RSH | BPF_K, 6),
-	/* add data frame header length */
-	BPF_STMT(BPF_ALU  | BPF_ADD | BPF_K, 24),
-	/* add index, was start of 802.11 header */
-	BPF_STMT(BPF_ALU  | BPF_ADD | BPF_X, 0),
-	/* move to index, now start of LL header */
-	BPF_STMT(BPF_MISC | BPF_TAX, 0),
-
-	/*
-	 * Accept empty data frames, we use those for
-	 * polling activity.
-	 */
-	BPF_STMT(BPF_LD  | BPF_W | BPF_LEN, 0),
-	BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, PASS, 0),
-
-	/*
-	 * Accept EAPOL frames
-	 */
-	BPF_STMT(BPF_LD  | BPF_W | BPF_IND, 0),
-	BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0xAAAA0300, 0, FAIL),
-	BPF_STMT(BPF_LD  | BPF_W | BPF_IND, 4),
-	BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0000888E, PASS, FAIL),
-
-	/* keep these last two statements or change the code below */
-	/* return 0 == "DROP" */
-	BPF_STMT(BPF_RET | BPF_K, 0),
-	/* return ~0 == "keep all" */
-	BPF_STMT(BPF_RET | BPF_K, ~0),
-};
-
-static struct sock_fprog msock_filter = {
-	.len = sizeof(msock_filter_insns)/sizeof(msock_filter_insns[0]),
-	.filter = msock_filter_insns,
-};
-
-
-static int add_monitor_filter(int s)
-{
-	int idx;
-
-	/* rewrite all PASS/FAIL jump offsets */
-	for (idx = 0; idx < msock_filter.len; idx++) {
-		struct sock_filter *insn = &msock_filter_insns[idx];
-
-		if (BPF_CLASS(insn->code) == BPF_JMP) {
-			if (insn->code == (BPF_JMP|BPF_JA)) {
-				if (insn->k == PASS)
-					insn->k = msock_filter.len - idx - 2;
-				else if (insn->k == FAIL)
-					insn->k = msock_filter.len - idx - 3;
-			}
-
-			if (insn->jt == PASS)
-				insn->jt = msock_filter.len - idx - 2;
-			else if (insn->jt == FAIL)
-				insn->jt = msock_filter.len - idx - 3;
-
-			if (insn->jf == PASS)
-				insn->jf = msock_filter.len - idx - 2;
-			else if (insn->jf == FAIL)
-				insn->jf = msock_filter.len - idx - 3;
-		}
-	}
-
-	if (setsockopt(s, SOL_SOCKET, SO_ATTACH_FILTER,
-		       &msock_filter, sizeof(msock_filter))) {
-		perror("SO_ATTACH_FILTER");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int nl80211_create_monitor_interface(struct i802_driver_data *drv)
-{
-	char buf[IFNAMSIZ];
-	struct sockaddr_ll ll;
-	int optval;
-	socklen_t optlen;
-
-	snprintf(buf, IFNAMSIZ, "mon.%s", drv->iface);
-	buf[IFNAMSIZ - 1] = '\0';
-
-	drv->monitor_ifidx =
-		nl80211_create_iface(drv, buf, NL80211_IFTYPE_MONITOR, NULL);
-
-	if (drv->monitor_ifidx < 0)
-		return -1;
-
-	if (hostapd_set_iface_flags(drv, buf, 1))
-		goto error;
-
-	memset(&ll, 0, sizeof(ll));
-	ll.sll_family = AF_PACKET;
-	ll.sll_ifindex = drv->monitor_ifidx;
-	drv->monitor_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
-	if (drv->monitor_sock < 0) {
-		perror("socket[PF_PACKET,SOCK_RAW]");
-		goto error;
-	}
-
-	if (add_monitor_filter(drv->monitor_sock)) {
-		wpa_printf(MSG_INFO, "Failed to set socket filter for monitor "
-			   "interface; do filtering in user space");
-		/* This works, but will cost in performance. */
-	}
-
-	if (bind(drv->monitor_sock, (struct sockaddr *) &ll,
-		 sizeof(ll)) < 0) {
-		perror("monitor socket bind");
-		goto error;
-	}
-
-	optlen = sizeof(optval);
-	optval = 20;
-	if (setsockopt
-	    (drv->monitor_sock, SOL_SOCKET, SO_PRIORITY, &optval, optlen)) {
-		perror("Failed to set socket priority");
-		goto error;
-	}
-
-	if (eloop_register_read_sock(drv->monitor_sock, handle_monitor_read,
-				     drv, NULL)) {
-		printf("Could not register monitor read socket\n");
-		goto error;
-	}
-
-	return 0;
- error:
-	nl80211_remove_iface(drv, drv->monitor_ifidx);
-	return -1;
-}
-
-
-static int nl80211_set_mode(struct i802_driver_data *drv, const char *ifname,
-			    int mode)
-{
-	struct nl_msg *msg;
-	int ret = -ENOBUFS;
-
-	msg = nlmsg_alloc();
-	if (!msg)
-		return -ENOMEM;
-
-	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
-		    0, NL80211_CMD_SET_INTERFACE, 0);
-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX,
-		    if_nametoindex(ifname));
-	NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, mode);
-
-	ret = send_and_recv_msgs(drv, msg, NULL, NULL);
-	if (!ret)
-		return 0;
- nla_put_failure:
-	wpa_printf(MSG_ERROR, "Failed to set interface %s to master "
-		   "mode.", ifname);
-	return ret;
-}
-
-
-#ifdef CONFIG_IEEE80211N
-static void i802_add_neighbor(struct i802_driver_data *drv, u8 *bssid,
-			      int freq, u8 *ie, size_t ie_len)
-{
-	struct ieee802_11_elems elems;
-	int ht, pri_chan = 0, sec_chan = 0;
-	struct ieee80211_ht_operation *oper;
-	struct hostapd_neighbor_bss *nnei;
-
-	ieee802_11_parse_elems(ie, ie_len, &elems, 0);
-	ht = elems.ht_capabilities || elems.ht_operation;
-	if (elems.ht_operation && elems.ht_operation_len >= sizeof(*oper)) {
-		oper = (struct ieee80211_ht_operation *) elems.ht_operation;
-		pri_chan = oper->control_chan;
-		if (oper->ht_param & HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH) {
-			if (oper->ht_param &
-			    HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
-				sec_chan = pri_chan + 4;
-			else if (oper->ht_param &
-			    HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
-				sec_chan = pri_chan - 4;
-		}
-	}
-
-	wpa_printf(MSG_DEBUG, "nl80211: Neighboring BSS - bssid=" MACSTR
-		   " freq=%d MHz HT=%d pri_chan=%d sec_chan=%d",
-		   MAC2STR(bssid), freq, ht, pri_chan, sec_chan);
-
-	nnei = os_realloc(drv->neighbors, (drv->num_neighbors + 1) *
-			  sizeof(struct hostapd_neighbor_bss));
-	if (nnei == NULL)
-		return;
-	drv->neighbors = nnei;
-	nnei = &nnei[drv->num_neighbors];
-	os_memcpy(nnei->bssid, bssid, ETH_ALEN);
-	nnei->freq = freq;
-	nnei->ht = !!ht;
-	nnei->pri_chan = pri_chan;
-	nnei->sec_chan = sec_chan;
-	drv->num_neighbors++;
-}
-
-
-static int i802_get_scan_freq(struct iw_event *iwe, int *freq)
-{
-	int divi = 1000000, i;
-
-	if (iwe->u.freq.e == 0) {
-		/*
-		 * Some drivers do not report frequency, but a channel.
-		 * Try to map this to frequency by assuming they are using
-		 * IEEE 802.11b/g.  But don't overwrite a previously parsed
-		 * frequency if the driver sends both frequency and channel,
-		 * since the driver may be sending an A-band channel that we
-		 * don't handle here.
-		 */
-
-		if (*freq)
-			return 0;
-
-		if (iwe->u.freq.m >= 1 && iwe->u.freq.m <= 13) {
-			*freq = 2407 + 5 * iwe->u.freq.m;
-			return 0;
-		} else if (iwe->u.freq.m == 14) {
-			*freq = 2484;
-			return 0;
-		}
-	}
-
-	if (iwe->u.freq.e > 6) {
-		wpa_printf(MSG_DEBUG, "Invalid freq in scan results: "
-			   "m=%d e=%d", iwe->u.freq.m, iwe->u.freq.e);
-		return -1;
-	}
-
-	for (i = 0; i < iwe->u.freq.e; i++)
-		divi /= 10;
-	*freq = iwe->u.freq.m / divi;
-	return 0;
-}
-
-
-static int i802_parse_scan(struct i802_driver_data *drv, u8 *res_buf,
-			   size_t len)
-{
-	size_t ap_num = 0;
-	int first;
-	struct iw_event iwe_buf, *iwe = &iwe_buf;
-	char *pos, *end, *custom;
-	u8 bssid[ETH_ALEN];
-	int freq = 0;
-	u8 *ie = NULL;
-	size_t ie_len = 0;
-
-	ap_num = 0;
-	first = 1;
-
-	pos = (char *) res_buf;
-	end = (char *) res_buf + len;
-
-	while (pos + IW_EV_LCP_LEN <= end) {
-		/* Event data may be unaligned, so make a local, aligned copy
-		 * before processing. */
-		os_memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
-		if (iwe->len <= IW_EV_LCP_LEN)
-			break;
-
-		custom = pos + IW_EV_POINT_LEN;
-		if (iwe->cmd == IWEVGENIE) {
-			/* WE-19 removed the pointer from struct iw_point */
-			char *dpos = (char *) &iwe_buf.u.data.length;
-			int dlen = dpos - (char *) &iwe_buf;
-			os_memcpy(dpos, pos + IW_EV_LCP_LEN,
-				  sizeof(struct iw_event) - dlen);
-		} else {
-			os_memcpy(&iwe_buf, pos, sizeof(struct iw_event));
-			custom += IW_EV_POINT_OFF;
-		}
-
-		switch (iwe->cmd) {
-		case SIOCGIWAP:
-			if (!first)
-				i802_add_neighbor(drv, bssid, freq, ie,
-						  ie_len);
-			first = 0;
-			os_memcpy(bssid, iwe->u.ap_addr.sa_data, ETH_ALEN);
-			freq = 0;
-			ie = NULL;
-			ie_len = 0;
-			break;
-		case SIOCGIWFREQ:
-			i802_get_scan_freq(iwe, &freq);
-			break;
-		case IWEVGENIE:
-			if (custom + iwe->u.data.length > end) {
-				wpa_printf(MSG_ERROR, "IWEVGENIE overflow");
-				return -1;
-			}
-			ie = (u8 *) custom;
-			ie_len = iwe->u.data.length;
-			break;
-		}
-
-		pos += iwe->len;
-	}
-
-	if (!first)
-		i802_add_neighbor(drv, bssid, freq, ie, ie_len);
-
-	return 0;
-}
-
-
-static int i802_get_ht_scan_res(struct i802_driver_data *drv)
-{
-	struct iwreq iwr;
-	u8 *res_buf;
-	size_t res_buf_len;
-	int res;
-
-	res_buf_len = IW_SCAN_MAX_DATA;
-	for (;;) {
-		res_buf = os_malloc(res_buf_len);
-		if (res_buf == NULL)
-			return -1;
-		os_memset(&iwr, 0, sizeof(iwr));
-		os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-		iwr.u.data.pointer = res_buf;
-		iwr.u.data.length = res_buf_len;
-
-		if (ioctl(drv->ioctl_sock, SIOCGIWSCAN, &iwr) == 0)
-			break;
-
-		if (errno == E2BIG && res_buf_len < 65535) {
-			os_free(res_buf);
-			res_buf = NULL;
-			res_buf_len *= 2;
-			if (res_buf_len > 65535)
-				res_buf_len = 65535; /* 16-bit length field */
-			wpa_printf(MSG_DEBUG, "Scan results did not fit - "
-				   "trying larger buffer (%lu bytes)",
-				   (unsigned long) res_buf_len);
-		} else {
-			perror("ioctl[SIOCGIWSCAN]");
-			os_free(res_buf);
-			return -1;
-		}
-	}
-
-	if (iwr.u.data.length > res_buf_len) {
-		os_free(res_buf);
-		return -1;
-	}
-
-	res = i802_parse_scan(drv, res_buf, iwr.u.data.length);
-	os_free(res_buf);
-
-	return res;
-}
-
-
-static int i802_is_event_wireless_scan_complete(char *data, int len)
-{
-	struct iw_event iwe_buf, *iwe = &iwe_buf;
-	char *pos, *end;
-
-	pos = data;
-	end = data + len;
-
-	while (pos + IW_EV_LCP_LEN <= end) {
-		/* Event data may be unaligned, so make a local, aligned copy
-		 * before processing. */
-		os_memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
-		if (iwe->cmd == SIOCGIWSCAN)
-			return 1;
-
-		pos += iwe->len;
-	}
-
-	return 0;
-}
-
-
-static int i802_is_rtm_scan_complete(int ifindex, struct nlmsghdr *h, int len)
-{
-	struct ifinfomsg *ifi;
-	int attrlen, _nlmsg_len, rta_len;
-	struct rtattr *attr;
-
-	if (len < (int) sizeof(*ifi))
-		return 0;
-
-	ifi = NLMSG_DATA(h);
-
-	if (ifindex != ifi->ifi_index)
-		return 0; /* event for foreign ifindex */
-
-	_nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
-
-	attrlen = h->nlmsg_len - _nlmsg_len;
-	if (attrlen < 0)
-		return 0;
-
-	attr = (struct rtattr *) (((char *) ifi) + _nlmsg_len);
-
-	rta_len = RTA_ALIGN(sizeof(struct rtattr));
-	while (RTA_OK(attr, attrlen)) {
-		if (attr->rta_type == IFLA_WIRELESS &&
-		    i802_is_event_wireless_scan_complete(
-			    ((char *) attr) + rta_len,
-			    attr->rta_len - rta_len))
-			return 1;
-		attr = RTA_NEXT(attr, attrlen);
-	}
-
-	return 0;
-}
-
-
-static int i802_is_scan_complete(int s, int ifindex)
-{
-	char buf[1024];
-	int left;
-	struct nlmsghdr *h;
-
-	left = recv(s, buf, sizeof(buf), MSG_DONTWAIT);
-	if (left < 0) {
-		perror("recv(netlink)");
-		return 0;
-	}
-
-	h = (struct nlmsghdr *) buf;
-	while (left >= (int) sizeof(*h)) {
-		int len, plen;
-
-		len = h->nlmsg_len;
-		plen = len - sizeof(*h);
-		if (len > left || plen < 0) {
-			wpa_printf(MSG_DEBUG, "Malformed netlink message: "
-				   "len=%d left=%d plen=%d",
-				   len, left, plen);
-			break;
-		}
-
-		switch (h->nlmsg_type) {
-		case RTM_NEWLINK:
-			if (i802_is_rtm_scan_complete(ifindex, h, plen))
-				return 1;
-			break;
-		}
-
-		len = NLMSG_ALIGN(len);
-		left -= len;
-		h = (struct nlmsghdr *) ((char *) h + len);
-	}
-
-	return 0;
-}
-
-
-static int i802_ht_scan(struct i802_driver_data *drv)
-{
-	struct iwreq iwr;
-	int s, res, ifindex;
-	struct sockaddr_nl local;
-	time_t now, end;
-	fd_set rfds;
-	struct timeval tv;
-
-	wpa_printf(MSG_DEBUG, "nl80211: Scanning overlapping BSSes before "
-		   "starting HT 20/40 MHz BSS");
-
-	/* Request a new scan */
-	/* TODO: would be enough to scan the selected band */
-	os_memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	if (ioctl(drv->ioctl_sock, SIOCSIWSCAN, &iwr) < 0) {
-		perror("ioctl[SIOCSIWSCAN]");
-		return -1;
-	}
-
-	ifindex = if_nametoindex(drv->iface);
-
-	/* Wait for scan completion event or timeout */
-	s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-	if (s < 0) {
-		perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
-		return -1;
-	}
-
-	os_memset(&local, 0, sizeof(local));
-	local.nl_family = AF_NETLINK;
-	local.nl_groups = RTMGRP_LINK;
-	if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
-		perror("bind(netlink)");
-		close(s);
-		return -1;
-	}
-
-	time(&end);
-	end += 30; /* Wait at most 30 seconds for scan results */
-	for (;;) {
-		time(&now);
-		tv.tv_sec = end > now ? end - now : 0;
-		tv.tv_usec = 0;
-		FD_ZERO(&rfds);
-		FD_SET(s, &rfds);
-		res = select(s + 1, &rfds, NULL, NULL, &tv);
-		if (res < 0) {
-			perror("select");
-			/* Assume results are ready after 10 seconds wait */
-			os_sleep(10, 0);
-			break;
-		} else if (res) {
-			if (i802_is_scan_complete(s, ifindex)) {
-				wpa_printf(MSG_DEBUG, "nl80211: Scan "
-					   "completed");
-				break;
-			}
-		} else {
-			wpa_printf(MSG_DEBUG, "nl80211: Scan timeout");
-			/* Assume results are ready to be read now */
-			break;
-		}
-	}
-
-	close(s);
-
-	return i802_get_ht_scan_res(drv);
-}
-#endif /* CONFIG_IEEE80211N */
-
-
-static int i802_init_sockets(struct i802_driver_data *drv, const u8 *bssid)
-{
-	struct ifreq ifr;
-
-	drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
-	if (drv->ioctl_sock < 0) {
-		perror("socket[PF_INET,SOCK_DGRAM]");
-		return -1;
-	}
-
-	/* start listening for EAPOL on the default AP interface */
-	add_ifidx(drv, if_nametoindex(drv->iface));
-
-	if (hostapd_set_iface_flags(drv, drv->iface, 0))
-		return -1;
-
-	if (bssid) {
-		os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
-		memcpy(ifr.ifr_hwaddr.sa_data, bssid, ETH_ALEN);
-		ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
-
-		if (ioctl(drv->ioctl_sock, SIOCSIFHWADDR, &ifr)) {
-			perror("ioctl(SIOCSIFHWADDR)");
-			return -1;
-		}
-	}
-
-	/*
-	 * initialise generic netlink and nl80211
-	 */
-	drv->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
-	if (!drv->nl_cb) {
-		printf("Failed to allocate netlink callbacks.\n");
-		return -1;
-	}
-
-	drv->nl_handle = nl_handle_alloc_cb(drv->nl_cb);
-	if (!drv->nl_handle) {
-		printf("Failed to allocate netlink handle.\n");
-		return -1;
-	}
-
-	if (genl_connect(drv->nl_handle)) {
-		printf("Failed to connect to generic netlink.\n");
-		return -1;
-	}
-
-#ifdef CONFIG_LIBNL20
-	if (genl_ctrl_alloc_cache(drv->nl_handle, &drv->nl_cache) < 0) {
-		printf("Failed to allocate generic netlink cache.\n");
-		return -1;
-	}
-#else /* CONFIG_LIBNL20 */
-	drv->nl_cache = genl_ctrl_alloc_cache(drv->nl_handle);
-	if (!drv->nl_cache) {
-		printf("Failed to allocate generic netlink cache.\n");
-		return -1;
-	}
-#endif /* CONFIG_LIBNL20 */
-
-	drv->nl80211 = genl_ctrl_search_by_name(drv->nl_cache, "nl80211");
-	if (!drv->nl80211) {
-		printf("nl80211 not found.\n");
-		return -1;
-	}
-
-#ifdef CONFIG_IEEE80211N
-	if (drv->ht_40mhz_scan) {
-		if (nl80211_set_mode(drv, drv->iface, NL80211_IFTYPE_STATION)
-		    || hostapd_set_iface_flags(drv, drv->iface, 1) ||
-		    i802_ht_scan(drv) ||
-		    hostapd_set_iface_flags(drv, drv->iface, 0)) {
-			wpa_printf(MSG_ERROR, "Failed to scan channels for "
-				   "HT 40 MHz operations");
-			return -1;
-		}
-	}
-#endif /* CONFIG_IEEE80211N */
-
-	/* Initialise a monitor interface */
-	if (nl80211_create_monitor_interface(drv))
-		return -1;
-
-	if (nl80211_set_mode(drv, drv->iface, NL80211_IFTYPE_AP))
-		goto fail1;
-
-	if (hostapd_set_iface_flags(drv, drv->iface, 1))
-		goto fail1;
-
-	drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
-	if (drv->eapol_sock < 0) {
-		perror("socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE)");
-		goto fail1;
-	}
-
-	if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
-	{
-		printf("Could not register read socket for eapol\n");
-		return -1;
-	}
-
-	memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
-	if (ioctl(drv->ioctl_sock, SIOCGIFHWADDR, &ifr) != 0) {
-		perror("ioctl(SIOCGIFHWADDR)");
-		goto fail1;
-	}
-
-	if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
-		printf("Invalid HW-addr family 0x%04x\n",
-		       ifr.ifr_hwaddr.sa_family);
-		goto fail1;
-	}
-	memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
-	return 0;
-
-fail1:
-	nl80211_remove_iface(drv, drv->monitor_ifidx);
-	return -1;
-}
-
-
-static int i802_get_inact_sec(void *priv, const u8 *addr)
-{
-	struct hostap_sta_driver_data data;
-	int ret;
-
-	data.inactive_msec = (unsigned long) -1;
-	ret = i802_read_sta_data(priv, &data, addr);
-	if (ret || data.inactive_msec == (unsigned long) -1)
-		return -1;
-	return data.inactive_msec / 1000;
-}
-
-
-static int i802_sta_clear_stats(void *priv, const u8 *addr)
-{
-#if 0
-	/* TODO */
-#endif
-	return 0;
-}
-
-
-static void
-hostapd_wireless_event_wireless_custom(struct i802_driver_data *drv,
-				       char *custom)
-{
-	wpa_printf(MSG_DEBUG, "Custom wireless event: '%s'", custom);
-
-	if (strncmp(custom, "MLME-MICHAELMICFAILURE.indication", 33) == 0) {
-		char *pos;
-		u8 addr[ETH_ALEN];
-		pos = strstr(custom, "addr=");
-		if (pos == NULL) {
-			wpa_printf(MSG_DEBUG,
-				   "MLME-MICHAELMICFAILURE.indication "
-				   "without sender address ignored");
-			return;
-		}
-		pos += 5;
-		if (hwaddr_aton(pos, addr) == 0) {
-			hostapd_michael_mic_failure(drv->hapd, addr);
-		} else {
-			wpa_printf(MSG_DEBUG,
-				   "MLME-MICHAELMICFAILURE.indication "
-				   "with invalid MAC address");
-		}
-	}
-}
-
-
-static void hostapd_wireless_event_wireless(struct i802_driver_data *drv,
-					    char *data, int len)
-{
-	struct iw_event iwe_buf, *iwe = &iwe_buf;
-	char *pos, *end, *custom, *buf;
-
-	pos = data;
-	end = data + len;
-
-	while (pos + IW_EV_LCP_LEN <= end) {
-		/* Event data may be unaligned, so make a local, aligned copy
-		 * before processing. */
-		memcpy(&iwe_buf, pos, IW_EV_LCP_LEN);
-		wpa_printf(MSG_DEBUG, "Wireless event: cmd=0x%x len=%d",
-			   iwe->cmd, iwe->len);
-		if (iwe->len <= IW_EV_LCP_LEN)
-			return;
-
-		custom = pos + IW_EV_POINT_LEN;
-		if (drv->we_version > 18 &&
-		    (iwe->cmd == IWEVMICHAELMICFAILURE ||
-		     iwe->cmd == IWEVCUSTOM)) {
-			/* WE-19 removed the pointer from struct iw_point */
-			char *dpos = (char *) &iwe_buf.u.data.length;
-			int dlen = dpos - (char *) &iwe_buf;
-			memcpy(dpos, pos + IW_EV_LCP_LEN,
-			       sizeof(struct iw_event) - dlen);
-		} else {
-			memcpy(&iwe_buf, pos, sizeof(struct iw_event));
-			custom += IW_EV_POINT_OFF;
-		}
-
-		switch (iwe->cmd) {
-		case IWEVCUSTOM:
-			if (custom + iwe->u.data.length > end)
-				return;
-			buf = malloc(iwe->u.data.length + 1);
-			if (buf == NULL)
-				return;
-			memcpy(buf, custom, iwe->u.data.length);
-			buf[iwe->u.data.length] = '\0';
-			hostapd_wireless_event_wireless_custom(drv, buf);
-			free(buf);
-			break;
-		}
-
-		pos += iwe->len;
-	}
-}
-
-
-static void hostapd_wireless_event_rtm_newlink(struct i802_driver_data *drv,
-					       struct nlmsghdr *h, int len)
-{
-	struct ifinfomsg *ifi;
-	int attrlen, _nlmsg_len, rta_len;
-	struct rtattr *attr;
-
-	if (len < (int) sizeof(*ifi))
-		return;
-
-	ifi = NLMSG_DATA(h);
-
-	/* TODO: use ifi->ifi_index to filter out wireless events from other
-	 * interfaces */
-
-	_nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
-
-	attrlen = h->nlmsg_len - _nlmsg_len;
-	if (attrlen < 0)
-		return;
-
-	attr = (struct rtattr *) (((char *) ifi) + _nlmsg_len);
-
-	rta_len = RTA_ALIGN(sizeof(struct rtattr));
-	while (RTA_OK(attr, attrlen)) {
-		if (attr->rta_type == IFLA_WIRELESS) {
-			hostapd_wireless_event_wireless(
-				drv, ((char *) attr) + rta_len,
-				attr->rta_len - rta_len);
-		}
-		attr = RTA_NEXT(attr, attrlen);
-	}
-}
-
-
-static void hostapd_wireless_event_receive(int sock, void *eloop_ctx,
-					   void *sock_ctx)
-{
-	char buf[256];
-	int left;
-	struct sockaddr_nl from;
-	socklen_t fromlen;
-	struct nlmsghdr *h;
-	struct i802_driver_data *drv = eloop_ctx;
-
-	fromlen = sizeof(from);
-	left = recvfrom(sock, buf, sizeof(buf), MSG_DONTWAIT,
-			(struct sockaddr *) &from, &fromlen);
-	if (left < 0) {
-		if (errno != EINTR && errno != EAGAIN)
-			perror("recvfrom(netlink)");
-		return;
-	}
-
-	h = (struct nlmsghdr *) buf;
-	while (left >= (int) sizeof(*h)) {
-		int len, plen;
-
-		len = h->nlmsg_len;
-		plen = len - sizeof(*h);
-		if (len > left || plen < 0) {
-			printf("Malformed netlink message: "
-			       "len=%d left=%d plen=%d\n",
-			       len, left, plen);
-			break;
-		}
-
-		switch (h->nlmsg_type) {
-		case RTM_NEWLINK:
-			hostapd_wireless_event_rtm_newlink(drv, h, plen);
-			break;
-		}
-
-		len = NLMSG_ALIGN(len);
-		left -= len;
-		h = (struct nlmsghdr *) ((char *) h + len);
-	}
-
-	if (left > 0) {
-		printf("%d extra bytes in the end of netlink message\n", left);
-	}
-}
-
-
-static int hostap_get_we_version(struct i802_driver_data *drv)
-{
-	struct iw_range *range;
-	struct iwreq iwr;
-	int minlen;
-	size_t buflen;
-
-	drv->we_version = 0;
-
-	/*
-	 * Use larger buffer than struct iw_range in order to allow the
-	 * structure to grow in the future.
-	 */
-	buflen = sizeof(struct iw_range) + 500;
-	range = os_zalloc(buflen);
-	if (range == NULL)
-		return -1;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.data.pointer = (caddr_t) range;
-	iwr.u.data.length = buflen;
-
-	minlen = ((char *) &range->enc_capa) - (char *) range +
-		sizeof(range->enc_capa);
-
-	if (ioctl(drv->ioctl_sock, SIOCGIWRANGE, &iwr) < 0) {
-		perror("ioctl[SIOCGIWRANGE]");
-		free(range);
-		return -1;
-	} else if (iwr.u.data.length >= minlen &&
-		   range->we_version_compiled >= 18) {
-		wpa_printf(MSG_DEBUG, "SIOCGIWRANGE: WE(compiled)=%d "
-			   "WE(source)=%d enc_capa=0x%x",
-			   range->we_version_compiled,
-			   range->we_version_source,
-			   range->enc_capa);
-		drv->we_version = range->we_version_compiled;
-	}
-
-	free(range);
-	return 0;
-}
-
-
-static int i802_wireless_event_init(struct i802_driver_data *drv)
-{
-	int s;
-	struct sockaddr_nl local;
-
-	hostap_get_we_version(drv);
-
-	drv->wext_sock = -1;
-
-	s = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-	if (s < 0) {
-		perror("socket(PF_NETLINK,SOCK_RAW,NETLINK_ROUTE)");
-		return -1;
-	}
-
-	memset(&local, 0, sizeof(local));
-	local.nl_family = AF_NETLINK;
-	local.nl_groups = RTMGRP_LINK;
-	if (bind(s, (struct sockaddr *) &local, sizeof(local)) < 0) {
-		perror("bind(netlink)");
-		close(s);
-		return -1;
-	}
-
-	eloop_register_read_sock(s, hostapd_wireless_event_receive, drv,
-				 NULL);
-	drv->wext_sock = s;
-
-	return 0;
-}
-
-
-static void i802_wireless_event_deinit(struct i802_driver_data *drv)
-{
-	if (drv->wext_sock < 0)
-		return;
-	eloop_unregister_read_sock(drv->wext_sock);
-	close(drv->wext_sock);
-}
-
-
-static int i802_sta_deauth(void *priv, const u8 *addr, int reason)
-{
-	struct i802_driver_data *drv = priv;
-	struct ieee80211_mgmt mgmt;
-
-	memset(&mgmt, 0, sizeof(mgmt));
-	mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
-					  WLAN_FC_STYPE_DEAUTH);
-	memcpy(mgmt.da, addr, ETH_ALEN);
-	memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
-	memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
-	mgmt.u.deauth.reason_code = host_to_le16(reason);
-	return i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
-				      sizeof(mgmt.u.deauth), 0);
-}
-
-
-static int i802_sta_disassoc(void *priv, const u8 *addr, int reason)
-{
-	struct i802_driver_data *drv = priv;
-	struct ieee80211_mgmt mgmt;
-
-	memset(&mgmt, 0, sizeof(mgmt));
-	mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
-					  WLAN_FC_STYPE_DISASSOC);
-	memcpy(mgmt.da, addr, ETH_ALEN);
-	memcpy(mgmt.sa, drv->hapd->own_addr, ETH_ALEN);
-	memcpy(mgmt.bssid, drv->hapd->own_addr, ETH_ALEN);
-	mgmt.u.disassoc.reason_code = host_to_le16(reason);
-	return  i802_send_mgmt_frame(drv, &mgmt, IEEE80211_HDRLEN +
-				       sizeof(mgmt.u.disassoc), 0);
-}
-
-
-static const struct hostapd_neighbor_bss *
-i802_get_neighbor_bss(void *priv, size_t *num)
-{
-	struct i802_driver_data *drv = priv;
-	*num = drv->num_neighbors;
-	return drv->neighbors;
-}
-
-
-static void *i802_init_bssid(struct hostapd_data *hapd, const u8 *bssid)
-{
-	struct i802_driver_data *drv;
-	size_t i;
-
-	drv = os_zalloc(sizeof(struct i802_driver_data));
-	if (drv == NULL) {
-		printf("Could not allocate memory for i802 driver data\n");
-		return NULL;
-	}
-
-	drv->hapd = hapd;
-	memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
-	memcpy(drv->bss.iface, hapd->conf->iface, sizeof(drv->iface));
-
-	drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
-	drv->if_indices = drv->default_if_indices;
-	for (i = 0; i < hapd->iface->num_bss; i++) {
-		struct hostapd_data *bss = hapd->iface->bss[i];
-		if (bss->conf->bridge)
-			add_ifidx(drv, if_nametoindex(bss->conf->bridge));
-	}
-	drv->ht_40mhz_scan = hapd->iconf->secondary_channel != 0;
-
-	if (i802_init_sockets(drv, bssid))
-		goto failed;
-
-	if (i802_wireless_event_init(drv))
-		goto failed;
-
-	return drv;
-
-failed:
-	free(drv);
-	return NULL;
-}
-
-
-static void *i802_init(struct hostapd_data *hapd)
-{
-	return i802_init_bssid(hapd, NULL);
-}
-
-
-static void i802_deinit(void *priv)
-{
-	struct i802_driver_data *drv = priv;
-	struct i802_bss *bss, *prev;
-
-	i802_wireless_event_deinit(drv);
-
-	if (drv->last_freq_ht) {
-		/* Clear HT flags from the driver */
-		struct hostapd_freq_params freq;
-		os_memset(&freq, 0, sizeof(freq));
-		freq.freq = drv->last_freq;
-		i802_set_freq(priv, &freq);
-	}
-
-	i802_del_beacon(drv);
-
-	/* remove monitor interface */
-	nl80211_remove_iface(drv, drv->monitor_ifidx);
-
-	(void) hostapd_set_iface_flags(drv, drv->iface, 0);
-
-	if (drv->monitor_sock >= 0) {
-		eloop_unregister_read_sock(drv->monitor_sock);
-		close(drv->monitor_sock);
-	}
-	if (drv->ioctl_sock >= 0)
-		close(drv->ioctl_sock);
-	if (drv->eapol_sock >= 0) {
-		eloop_unregister_read_sock(drv->eapol_sock);
-		close(drv->eapol_sock);
-	}
-
-	genl_family_put(drv->nl80211);
-	nl_cache_free(drv->nl_cache);
-	nl_handle_destroy(drv->nl_handle);
-	nl_cb_put(drv->nl_cb);
-
-	if (drv->if_indices != drv->default_if_indices)
-		free(drv->if_indices);
-
-	os_free(drv->neighbors);
-
-	bss = drv->bss.next;
-	while (bss) {
-		prev = bss;
-		bss = bss->next;
-		os_free(bss);
-	}
-
-	free(drv);
-}
-
-
-const struct hapd_driver_ops wpa_driver_nl80211_ops = {
-	.name = "nl80211",
-	.init = i802_init,
-	.init_bssid = i802_init_bssid,
-	.deinit = i802_deinit,
-	.set_key = i802_set_key,
-	.get_seqnum = i802_get_seqnum,
-	.flush = i802_flush,
-	.read_sta_data = i802_read_sta_data,
-	.send_eapol = i802_send_eapol,
-	.sta_set_flags = i802_sta_set_flags,
-	.sta_deauth = i802_sta_deauth,
-	.sta_disassoc = i802_sta_disassoc,
-	.sta_remove = i802_sta_remove,
-	.send_mgmt_frame = i802_send_mgmt_frame,
-	.sta_add = i802_sta_add,
-	.get_inact_sec = i802_get_inact_sec,
-	.sta_clear_stats = i802_sta_clear_stats,
-	.set_freq = i802_set_freq,
-	.set_rts = i802_set_rts,
-	.set_frag = i802_set_frag,
-	.set_retry = i802_set_retry,
-	.set_rate_sets = i802_set_rate_sets,
-	.set_beacon = i802_set_beacon,
-	.set_beacon_int = i802_set_beacon_int,
-	.set_cts_protect = i802_set_cts_protect,
-	.set_preamble = i802_set_preamble,
-	.set_short_slot_time = i802_set_short_slot_time,
-	.set_tx_queue_params = i802_set_tx_queue_params,
-	.bss_add = i802_bss_add,
-	.bss_remove = i802_bss_remove,
-	.if_add = i802_if_add,
-	.if_update = i802_if_update,
-	.if_remove = i802_if_remove,
-	.get_hw_feature_data = i802_get_hw_feature_data,
-	.set_sta_vlan = i802_set_sta_vlan,
-	.set_country = i802_set_country,
-	.get_neighbor_bss = i802_get_neighbor_bss,
-};

+ 0 - 1096
hostapd/driver_prism54.c

@@ -1,1096 +0,0 @@
-/*
- * hostapd / Driver interaction with Prism54 PIMFOR interface
- * Copyright (c) 2004, Bell Kin <bell_kin@pek.com.tw>
- * based on hostap driver.c, ieee802_11.c
- * Copyright (c) 2002-2007, 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 "includes.h"
-#include <sys/ioctl.h>
-#include <sys/select.h>
-
-#ifdef USE_KERNEL_HEADERS
-/* compat-wireless does not include linux/compiler.h to define __user, so
- * define it here */
-#ifndef __user
-#define __user
-#endif /* __user */
-#include <asm/types.h>
-#include <linux/if_packet.h>
-#include <linux/if_ether.h>   /* The L2 protocols */
-#include <linux/if_arp.h>
-#include <linux/wireless.h>
-#else /* USE_KERNEL_HEADERS */
-#include <net/if_arp.h>
-#include <netpacket/packet.h>
-#include "wireless_copy.h"
-#endif /* USE_KERNEL_HEADERS */
-
-#include "hostapd.h"
-#include "config.h"
-#include "driver.h"
-#include "ieee802_1x.h"
-#include "eloop.h"
-#include "ieee802_11.h"
-#include "prism54.h"
-#include "wpa.h"
-#include "radius/radius.h"
-#include "sta_info.h"
-#include "accounting.h"
-
-const int PIM_BUF_SIZE = 4096;
-
-struct prism54_driver_data {
-	struct hostapd_data *hapd;
-	char iface[IFNAMSIZ + 1];
-	int sock; /* raw packet socket for 802.3 access */
-	int pim_sock; /* socket for pimfor packet */
-	char macs[2007][6];
-};
-
-
-static int mac_id_refresh(struct prism54_driver_data *data, int id, char *mac)
-{
-	if (id < 0 || id > 2006) {
-		return -1;
-	}
-	memcpy(&data->macs[id][0], mac, ETH_ALEN);
-	return 0;
-}
-
-
-static char * mac_id_get(struct prism54_driver_data *data, int id)
-{
-	if (id < 0 || id > 2006) {
-		return NULL;
-	}
-	return &data->macs[id][0];
-}
-
-
-/* wait for a specific pimfor, timeout in 10ms resolution */
-/* pim_sock must be non-block to prevent dead lock from no response */
-/* or same response type in series */
-static int prism54_waitpim(void *priv, unsigned long oid, void *buf, int len,
-			   int timeout)
-{
-	struct prism54_driver_data *drv = priv;
-	struct timeval tv, stv, ctv;
-	fd_set pfd;
-	int rlen;
-	pimdev_hdr *pkt;
-
-	pkt = malloc(8192);
-	if (pkt == NULL)
-		return -1;
-
-	FD_ZERO(&pfd);
-	gettimeofday(&stv, NULL);
-	do {
-		FD_SET(drv->pim_sock, &pfd);
-		tv.tv_sec = 0;
-		tv.tv_usec = 10000;
-		if (select(drv->pim_sock + 1, &pfd, NULL, NULL, &tv)) {
-			rlen = recv(drv->pim_sock, pkt, 8192, 0);
-			if (rlen > 0) {
-				if (pkt->oid == htonl(oid)) {
-					if (rlen <= len) {
-						if (buf != NULL) {
-							memcpy(buf, pkt, rlen);
-						}
-						free(pkt);
-						return rlen;
-					} else {
-						printf("buffer too small\n");
-						free(pkt);
-						return -1;
-					}
-				} else {
-					gettimeofday(&ctv, NULL);
-					continue;
-				}
-			}
-		}
-		gettimeofday(&ctv, NULL);
-	} while (((ctv.tv_sec - stv.tv_sec) * 100 +
-		  (ctv.tv_usec - stv.tv_usec) / 10000) > timeout);
-	free(pkt);
-	return 0;
-}
-
-
-/* send an eapol packet */
-static int prism54_send_eapol(void *priv, const u8 *addr,
-			      const u8 *data, size_t data_len, int encrypt,
-			      const u8 *own_addr)
-{
-	struct prism54_driver_data *drv = priv;
-	ieee802_3_hdr *hdr;
-	size_t len;
-	u8 *pos;
-	int res;
-
-	len = sizeof(*hdr) + data_len;
-	hdr = os_zalloc(len);
-	if (hdr == NULL) {
-		printf("malloc() failed for prism54_send_data(len=%lu)\n",
-		       (unsigned long) len);
-		return -1;
-	}
-
-	memcpy(&hdr->da[0], addr, ETH_ALEN);
-	memcpy(&hdr->sa[0], own_addr, ETH_ALEN);
-	hdr->type = htons(ETH_P_PAE);
-	pos = (u8 *) (hdr + 1);
-	memcpy(pos, data, data_len);
-
-	res = send(drv->sock, hdr, len, 0);
-	free(hdr);
-
-	if (res < 0) {
-		perror("hostapd_send_eapol: send");
-		printf("hostapd_send_eapol - packet len: %lu - failed\n",
-		       (unsigned long) len);
-	}
-
-	return res;
-}
-
-
-/* open data channel(auth-1) or eapol only(unauth-0) */
-static int prism54_set_sta_authorized(void *priv, const u8 *addr,
-				      int authorized)
-{
-	struct prism54_driver_data *drv = priv;
-	pimdev_hdr *hdr;
-	char *pos;
-
-	hdr = malloc(sizeof(*hdr) + ETH_ALEN);
-	if (hdr == NULL)
-		return -1;
-	hdr->op = htonl(PIMOP_SET);
-	if (authorized) {
-		hdr->oid = htonl(DOT11_OID_EAPAUTHSTA);
-	} else {
-		hdr->oid = htonl(DOT11_OID_EAPUNAUTHSTA);
-	}
-	pos = (char *) (hdr + 1);
-	memcpy(pos, addr, ETH_ALEN);
-	send(drv->pim_sock, hdr, sizeof(*hdr) + ETH_ALEN, 0);
-	prism54_waitpim(priv, hdr->oid, hdr, sizeof(*hdr) + ETH_ALEN, 10);
-	free(hdr);
-	return 0;
-}
-
-
-static int
-prism54_sta_set_flags(void *priv, const u8 *addr, int total_flags,
-		      int flags_or, int flags_and)
-{
-	/* For now, only support setting Authorized flag */
-	if (flags_or & WLAN_STA_AUTHORIZED)
-		return prism54_set_sta_authorized(priv, addr, 1);
-	if (flags_and & WLAN_STA_AUTHORIZED)
-		return prism54_set_sta_authorized(priv, addr, 0);
-	return 0;
-}
-
-
-static int prism54_set_key(const char *ifname, void *priv, wpa_alg alg,
-			   const u8 *addr, int key_idx, int set_tx,
-			   const u8 *seq, size_t seq_len,
-			   const u8 *key, size_t key_len)
-{
-	struct prism54_driver_data *drv = priv;
-	pimdev_hdr *hdr;
-	struct obj_stakey *keys;
-	u8 *buf;
-	size_t blen;
-	int ret = 0;
-
-	blen = sizeof(struct obj_stakey) + sizeof(pimdev_hdr);
-	hdr = malloc(blen);
-	if (hdr == NULL) {
-		printf("memory low\n");
-		return -1;
-	}
-	keys = (struct obj_stakey *) &hdr[1];
-	if (!addr) {
-		memset(&keys->address[0], 0xff, ETH_ALEN);
-	} else {
-		memcpy(&keys->address[0], addr, ETH_ALEN);
-	}
-	switch (alg) {
-	case WPA_ALG_WEP:
-		keys->type = DOT11_PRIV_WEP;
-		break;
-	case WPA_ALG_TKIP:
-		keys->type = DOT11_PRIV_TKIP;
-		break;
-	case WPA_ALG_NONE:
-		/* the only way to clear the key is to deauth it */
-		/* and prism54 is capable to receive unencrypted packet */
-		/* so we do nothing here */
-		free(hdr);
-		return 0;
-	default:
-		printf("bad auth type: %d\n", alg);
-		free(hdr);
-		return -1;
-	}
-	buf = (u8 *) &keys->key[0];
-	keys->length = key_len;
-	keys->keyid = key_idx;
-	keys->options = htons(DOT11_STAKEY_OPTION_DEFAULTKEY);
-	keys->reserved = 0;
-
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_STAKEY);
-
-	memcpy(buf, key, key_len);
-	
-	ret = send(drv->pim_sock, hdr, blen, 0);
-	if (ret < 0) {
-		free(hdr);
-		return ret;
-	}
-	prism54_waitpim(priv, hdr->oid, hdr, blen, 10);
-
-	free(hdr);
-
-	return 0;
-}
-
-
-/* get TKIP station sequence counter, prism54 is only 6 bytes */
-static int prism54_get_seqnum(const char *ifname, void *priv, const u8 *addr,
-			      int idx, u8 *seq)
-{
-	struct prism54_driver_data *drv = priv;
-	struct obj_stasc *stasc;
-	pimdev_hdr *hdr;
-	size_t blen;
-	int ret = 0;
-
-	blen = sizeof(*stasc) + sizeof(*hdr);
-	hdr = malloc(blen);
-	if (hdr == NULL)
-		return -1;
-
-	stasc = (struct obj_stasc *) &hdr[1];
-	
-	if (addr == NULL)
-		memset(&stasc->address[0], 0xff, ETH_ALEN);
-	else
-		memcpy(&stasc->address[0], addr, ETH_ALEN);
-
-	hdr->oid = htonl(DOT11_OID_STASC);
-	hdr->op = htonl(PIMOP_GET);
-	stasc->keyid = idx;
-	if (send(drv->pim_sock,hdr,blen,0) <= 0) {
-		free(hdr);
-		return -1;
-	}
-	if (prism54_waitpim(priv, DOT11_OID_STASC, hdr, blen, 10) <= 0) {
-		ret = -1;
-	} else {
-		if (hdr->op == (int) htonl(PIMOP_RESPONSE)) {
-			memcpy(seq + 2, &stasc->sc_high, ETH_ALEN);
-			memset(seq, 0, 2);
-		} else {
-			ret = -1;
-		}
-	}
-	free(hdr);
-
-	return ret;
-}
-
-
-/* include unencrypted, set mlme autolevel to extended */
-static int prism54_init_1x(void *priv)
-{
-	struct prism54_driver_data *drv = priv;
-	pimdev_hdr *hdr;
-	unsigned long *ul;
-	int blen = sizeof(*hdr) + sizeof(*ul);
-
-	hdr = malloc(blen);
-	if (hdr == NULL)
-		return -1;
-
-	ul = (unsigned long *) &hdr[1];
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_EXUNENCRYPTED);
-	*ul = htonl(DOT11_BOOL_TRUE); /* not accept */
-	send(drv->pim_sock, hdr, blen, 0);
-	prism54_waitpim(priv, DOT11_OID_EXUNENCRYPTED, hdr, blen, 10);
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_MLMEAUTOLEVEL);
-	*ul = htonl(DOT11_MLME_EXTENDED);
-	send(drv->pim_sock, hdr, blen, 0);
-	prism54_waitpim(priv, DOT11_OID_MLMEAUTOLEVEL, hdr, blen, 10);
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_DOT1XENABLE);
-	*ul = htonl(DOT11_BOOL_TRUE);
-	send(drv->pim_sock, hdr, blen, 0);
-	prism54_waitpim(priv, DOT11_OID_DOT1XENABLE, hdr, blen, 10);
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_AUTHENABLE);
-	*ul = htonl(DOT11_AUTH_OS); /* OS */
-	send(drv->pim_sock, hdr, blen, 0);
-	prism54_waitpim(priv, DOT11_OID_AUTHENABLE, hdr, blen, 10);
-	free(hdr);
-	return 0;
-}
-
-
-static int prism54_set_privacy_invoked(const char *ifname, void *priv,
-				       int flag)
-{
-	struct prism54_driver_data *drv = priv;
-	pimdev_hdr *hdr;
-	unsigned long *ul;
-	int ret;
-	int blen = sizeof(*hdr) + sizeof(*ul);
-	hdr = malloc(blen);
-	if (hdr == NULL)
-		return -1;
-	ul = (unsigned long *) &hdr[1];
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_PRIVACYINVOKED);
-	if (flag) {
-		*ul = htonl(DOT11_BOOL_TRUE); /* has privacy */
-	} else {
-		*ul = 0;
-	}
-	ret = send(drv->pim_sock, hdr, blen, 0);
-	if (ret >= 0) {
-		ret = prism54_waitpim(priv, DOT11_OID_PRIVACYINVOKED, hdr,
-				      blen, 10);
-	}
-	free(hdr);
-	return ret;
-}
-
- 
-static int prism54_ioctl_setiwessid(const char *ifname, void *priv,
-				    const u8 *buf, int len)
-{
-#if 0
-	struct prism54_driver_data *drv = priv;
-	struct iwreq iwr;
-
-	memset(&iwr, 0, sizeof(iwr));
-	os_strlcpy(iwr.ifr_name, drv->iface, IFNAMSIZ);
-	iwr.u.essid.flags = 1; /* SSID active */
-	iwr.u.essid.pointer = (caddr_t) buf;
-	iwr.u.essid.length = len + 1;
-
-	if (ioctl(drv->pim_sock, SIOCSIWESSID, &iwr) < 0) {
-		perror("ioctl[SIOCSIWESSID]");
-		printf("len=%d\n", len);
-		return -1;
-	}
-#endif
-	return 0;
-}
-
-
-/* kick all stations */
-/* does not work during init, but at least it won't crash firmware */
-static int prism54_flush(void *priv)
-{
-	struct prism54_driver_data *drv = priv;
-	struct obj_mlmeex *mlme;
-	pimdev_hdr *hdr;
-	int ret;
-	unsigned int i;
-	long *nsta;
-	int blen = sizeof(*hdr) + sizeof(*mlme);
-	char *mac_id;
-
-	hdr = os_zalloc(blen);
-	if (hdr == NULL)
-		return -1;
-
-	mlme = (struct obj_mlmeex *) &hdr[1];
-	nsta = (long *) &hdr[1];
-	hdr->op = htonl(PIMOP_GET);
-	hdr->oid = htonl(DOT11_OID_CLIENTS);
-	ret = send(drv->pim_sock, hdr, sizeof(*hdr) + sizeof(long), 0);
-	ret = prism54_waitpim(priv, DOT11_OID_CLIENTS, hdr, blen, 10);
-	if ((ret < 0) || (hdr->op != (int) htonl(PIMOP_RESPONSE)) ||
-	    (le_to_host32(*nsta) > 2007)) {
-		free(hdr);
-		return 0;
-	}
-	for (i = 0; i < le_to_host32(*nsta); i++) {
-		mlme->id = -1;
-		mac_id = mac_id_get(drv, i);
-		if (mac_id)
-			memcpy(&mlme->address[0], mac_id, ETH_ALEN);
-		mlme->code = host_to_le16(WLAN_REASON_UNSPECIFIED);
-		mlme->state = htons(DOT11_STATE_NONE);
-		mlme->size = 0;
-		hdr->op = htonl(PIMOP_SET);
-		hdr->oid = htonl(DOT11_OID_DISASSOCIATEEX);
-		ret = send(drv->pim_sock, hdr, blen, 0);
-		prism54_waitpim(priv, DOT11_OID_DISASSOCIATEEX, hdr, blen,
-				100);
-	}
-	for (i = 0; i < le_to_host32(*nsta); i++) {
-		mlme->id = -1;
-		mac_id = mac_id_get(drv, i);
-		if (mac_id)
-			memcpy(&mlme->address[0], mac_id, ETH_ALEN);
-		mlme->code = host_to_le16(WLAN_REASON_UNSPECIFIED);
-		mlme->state = htons(DOT11_STATE_NONE);
-		mlme->size = 0;
-		hdr->op = htonl(PIMOP_SET);
-		hdr->oid = htonl(DOT11_OID_DEAUTHENTICATEEX);
-		ret = send(drv->pim_sock, hdr, blen, 0);
-		prism54_waitpim(priv, DOT11_OID_DEAUTHENTICATEEX, hdr, blen,
-				100);
-	}
-	free(hdr);
-	return 0;
-}
-
-
-static int prism54_sta_deauth(void *priv, const u8 *addr, int reason)
-{
-	struct prism54_driver_data *drv = priv;
-	pimdev_hdr *hdr;
-	struct obj_mlmeex *mlme;
-	int ret;
-	int blen = sizeof(*hdr) + sizeof(*mlme);
-	hdr = malloc(blen);
-	if (hdr == NULL)
-		return -1;
-	mlme = (struct obj_mlmeex *) &hdr[1];
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_DEAUTHENTICATEEX);
-	memcpy(&mlme->address[0], addr, ETH_ALEN);
-	mlme->id = -1;
-	mlme->state = htons(DOT11_STATE_NONE);
-	mlme->code = host_to_le16(reason);
-	mlme->size = 0;
-	ret = send(drv->pim_sock, hdr, blen, 0);
-	prism54_waitpim(priv, DOT11_OID_DEAUTHENTICATEEX, hdr, blen, 10);
-	free(hdr);
-	return ret;
-}
-
-
-static int prism54_sta_disassoc(void *priv, const u8 *addr, int reason)
-{
-	struct prism54_driver_data *drv = priv;
-        pimdev_hdr *hdr;
-        struct obj_mlmeex *mlme;
-	int ret;
-        int blen = sizeof(*hdr) + sizeof(*mlme);
-        hdr = malloc(blen);
-	if (hdr == NULL)
-		return -1;
-        mlme = (struct obj_mlmeex *) &hdr[1];
-        hdr->op = htonl(PIMOP_SET);
-        hdr->oid = htonl(DOT11_OID_DISASSOCIATEEX);
-        memcpy(&mlme->address[0], addr, ETH_ALEN);
-        mlme->id = -1;
-        mlme->state = htons(DOT11_STATE_NONE);
-        mlme->code = host_to_le16(reason);
-	mlme->size = 0;
-        ret = send(drv->pim_sock, hdr, blen, 0);
-        prism54_waitpim(priv, DOT11_OID_DISASSOCIATEEX, hdr, blen, 10);
-        free(hdr);
-        return ret;
-}
-
-
-static int prism54_get_inact_sec(void *priv, const u8 *addr)
-{
-	struct prism54_driver_data *drv = priv;
-	pimdev_hdr *hdr;
-	struct obj_sta *sta;
-	int blen = sizeof(*hdr) + sizeof(*sta);
-	int ret;
-
-	hdr = malloc(blen);
-	if (hdr == NULL)
-		return -1;
-	hdr->op = htonl(PIMOP_GET);
-	hdr->oid = htonl(DOT11_OID_CLIENTFIND);
-	sta = (struct obj_sta *) &hdr[1];
-	memcpy(&sta->address[0], addr, ETH_ALEN);
-	ret = send(drv->pim_sock, hdr, blen, 0);
-	ret = prism54_waitpim(priv, DOT11_OID_CLIENTFIND, hdr, blen, 10);
-	if (ret != blen) {
-		printf("get_inact_sec: bad return %d\n", ret);
-		free(hdr);
-		return -1;
-	}
-	if (hdr->op != (int) htonl(PIMOP_RESPONSE)) {
-		printf("get_inact_sec: bad resp\n");
-		free(hdr);
-		return -1;
-	}
-	free(hdr);
-	return le_to_host16(sta->age);
-}
-
-
-/* set attachments */
-static int prism54_set_generic_elem(const char *ifname, void *priv,
-				    const u8 *elem, size_t elem_len)
-{
-	struct prism54_driver_data *drv = priv;
-	pimdev_hdr *hdr;
-	char *pos;
-	struct obj_attachment_hdr *attach;
-	size_t blen = sizeof(*hdr) + sizeof(*attach) + elem_len;
-	hdr = os_zalloc(blen);
-	if (hdr == NULL) {
-		printf("%s: memory low\n", __func__);
-		return -1;
-	}
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_ATTACHMENT);
-	attach = (struct obj_attachment_hdr *)&hdr[1];
-	attach->type = DOT11_PKT_BEACON;
-	attach->id = -1;
-	attach->size = host_to_le16((short)elem_len);
-	pos = ((char*) attach) + sizeof(*attach);
-	if (elem)
-		memcpy(pos, elem, elem_len);
-	send(drv->pim_sock, hdr, blen, 0);
-	attach->type = DOT11_PKT_PROBE_RESP;
-	send(drv->pim_sock, hdr, blen, 0);
-	free(hdr);
-	return 0;
-}
-
-
-/* tell the card to auth the sta */
-static void prism54_handle_probe(struct prism54_driver_data *drv,
-				 void *buf, size_t len)
-{
-	struct obj_mlmeex *mlme;
-	pimdev_hdr *hdr;
-	struct sta_info *sta;
-	hdr = (pimdev_hdr *)buf;
-	mlme = (struct obj_mlmeex *) &hdr[1];
-	sta = ap_get_sta(drv->hapd, (u8 *) &mlme->address[0]);
-	if (sta != NULL) {
-		if (sta->flags & (WLAN_STA_AUTH | WLAN_STA_ASSOC))
-			return;
-	}
-	if (len < sizeof(*mlme)) {
-		printf("bad probe packet\n");
-		return;
-	}
-	mlme->state = htons(DOT11_STATE_AUTHING);
-	mlme->code = 0;
-	hdr->op = htonl(PIMOP_SET);
-	hdr->oid = htonl(DOT11_OID_AUTHENTICATEEX);
-	mlme->size = 0;
-	send(drv->pim_sock, hdr, sizeof(*hdr)+sizeof(*mlme), 0);
-}
-
-
-static void prism54_handle_deauth(struct prism54_driver_data *drv,
-				  void *buf, size_t len)
-{
-	struct obj_mlme *mlme;
-	pimdev_hdr *hdr;
-	struct sta_info *sta;
-	char *mac_id;
-
-	hdr = (pimdev_hdr *) buf;
-	mlme = (struct obj_mlme *) &hdr[1];
-	sta = ap_get_sta(drv->hapd, (u8 *) &mlme->address[0]);
-	mac_id = mac_id_get(drv, mlme->id);
-	if (sta == NULL || mac_id == NULL)
-		return;
-	memcpy(&mlme->address[0], mac_id, ETH_ALEN);
-	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
-	wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH);
-	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
-	ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
-	ap_free_sta(drv->hapd, sta);
-}
-
-
-static void prism54_handle_disassoc(struct prism54_driver_data *drv,
-				    void *buf, size_t len)
-{
-	struct obj_mlme *mlme;
-	pimdev_hdr *hdr;
-	struct sta_info *sta;
-	char *mac_id;
-
-	hdr = (pimdev_hdr *) buf;
-	mlme = (struct obj_mlme *) &hdr[1];
-	mac_id = mac_id_get(drv, mlme->id);
-	if (mac_id == NULL)
-		return;
-	memcpy(&mlme->address[0], mac_id, ETH_ALEN);
-	sta = ap_get_sta(drv->hapd, (u8 *) &mlme->address[0]);
-	if (sta == NULL) {
-		return;
-	}
-	sta->flags &= ~WLAN_STA_ASSOC;
-	wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
-	sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
-	ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
-	accounting_sta_stop(drv->hapd, sta);
-	ieee802_1x_free_station(sta);
-}
-
-
-/* to auth it, just allow it now, later for os/sk */
-static void prism54_handle_auth(struct prism54_driver_data *drv,
-				void *buf, size_t len)
-{
-	struct obj_mlmeex *mlme;
-	pimdev_hdr *hdr;
-	struct sta_info *sta;
-	int resp;
-
-	hdr = (pimdev_hdr *) buf;
-	mlme = (struct obj_mlmeex *) &hdr[1];
-	if (len < sizeof(*mlme)) {
-		printf("bad auth packet\n");
-		return;
-	}
-
-	if (mlme->state == htons(DOT11_STATE_AUTHING)) {
-		sta = ap_sta_add(drv->hapd, (u8 *) &mlme->address[0]);
-		if (drv->hapd->tkip_countermeasures) {
-			resp = WLAN_REASON_MICHAEL_MIC_FAILURE;
-			goto fail;
-		}
-		mac_id_refresh(drv, mlme->id, &mlme->address[0]);
-		if (!sta) {
-			resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
-			goto fail;
-		}
-		sta->flags &= ~WLAN_STA_PREAUTH;
-		
-		ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
-		sta->flags |= WLAN_STA_AUTH;
-		wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
-		mlme->code = 0;
-		mlme->state=htons(DOT11_STATE_AUTH);
-		hdr->op = htonl(PIMOP_SET);
-		hdr->oid = htonl(DOT11_OID_AUTHENTICATEEX);
-		mlme->size = 0;
-		sta->timeout_next = STA_NULLFUNC;
-		send(drv->pim_sock, hdr, sizeof(*hdr) + sizeof(*mlme), 0);
-	}
-	return;
-
-fail:
-	printf("auth fail: %x\n", resp);
-	mlme->code = host_to_le16(resp);
-	mlme->size = 0;
-	if (sta)
-		sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
-	hdr->oid = htonl(DOT11_OID_DEAUTHENTICATEEX);
-	hdr->op = htonl(PIMOP_SET);
-	send(drv->pim_sock, hdr, sizeof(*hdr)+sizeof(*mlme), 0);
-}
-
-
-/* do the wpa thing */
-static void prism54_handle_assoc(struct prism54_driver_data *drv,
-				 void *buf, size_t len)
-{
-	pimdev_hdr *hdr;
-	struct obj_mlmeex *mlme;
-	struct ieee802_11_elems elems;
-	struct sta_info *sta;
-	u8 *wpa_ie;
-	u8 *cb;
-	int ieofs = 0;
-	size_t wpa_ie_len;
-	int resp, new_assoc;
-	char *mac_id;
-
-	resp = 0;
-	hdr = (pimdev_hdr *) buf;
-	mlme = (struct obj_mlmeex *) &hdr[1];
-	switch (ntohl(hdr->oid)) {
-		case DOT11_OID_ASSOCIATE:
-		case DOT11_OID_REASSOCIATE:
-			mlme->size = 0;
-		default:
-			break;
-	}
-	if ((mlme->state == (int) htonl(DOT11_STATE_ASSOCING)) ||
-	    (mlme->state == (int) htonl(DOT11_STATE_REASSOCING))) {
-		if (len < sizeof(pimdev_hdr) + sizeof(struct obj_mlme)) {
-			printf("bad assoc packet\n");
-			return;
-		}
-		mac_id = mac_id_get(drv, mlme->id);
-		if (mac_id == NULL)
-			return;
-		memcpy(&mlme->address[0], mac_id, ETH_ALEN);
-		sta = ap_get_sta(drv->hapd, (u8 *) &mlme->address[0]);
-		if (sta == NULL) {
-			printf("cannot get sta\n");
-			return;
-		}
-		cb = (u8 *) &mlme->data[0];
-		if (hdr->oid == htonl(DOT11_OID_ASSOCIATEEX)) {
-			ieofs = 4;
-		} else if (hdr->oid == htonl(DOT11_OID_REASSOCIATEEX)) {
-			ieofs = 10;
-		}
-		if (le_to_host16(mlme->size) <= ieofs) {
-			printf("attach too small\n");
-			resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
-			goto fail;
-		}
-		if (ieee802_11_parse_elems(cb + ieofs,
-					   le_to_host16(mlme->size) - ieofs,
-					   &elems, 1) == ParseFailed) {
-			printf("STA " MACSTR " sent invalid association "
-			       "request\n", MAC2STR(sta->addr));
-			resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
-			goto fail;
-		}
-		if ((drv->hapd->conf->wpa & WPA_PROTO_RSN) &&
-		    elems.rsn_ie) {
-			wpa_ie = elems.rsn_ie;
-			wpa_ie_len = elems.rsn_ie_len;
-		} else if ((drv->hapd->conf->wpa & WPA_PROTO_WPA) &&
-			   elems.wpa_ie) {
-			wpa_ie = elems.wpa_ie;
-			wpa_ie_len = elems.wpa_ie_len;
-		} else {
-			wpa_ie = NULL;
-			wpa_ie_len = 0;
-		}
-		if (drv->hapd->conf->wpa && wpa_ie == NULL) {
-			printf("STA " MACSTR ": No WPA/RSN IE in association "
-			       "request\n", MAC2STR(sta->addr));
-			resp = WLAN_STATUS_INVALID_IE;
-			goto fail;
-		}
-		if (drv->hapd->conf->wpa) {
-			int res;
-			wpa_ie -= 2;
-			wpa_ie_len += 2;
-			if (sta->wpa_sm == NULL)
-				sta->wpa_sm = wpa_auth_sta_init(
-					drv->hapd->wpa_auth, sta->addr);
-			if (sta->wpa_sm == NULL) {
-				printf("Failed to initialize WPA state "
-				       "machine\n");
-				resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
-				goto fail;
-			}
-			res = wpa_validate_wpa_ie(drv->hapd->wpa_auth,
-						  sta->wpa_sm,
-						  wpa_ie, wpa_ie_len,
-						  NULL, 0);
-			if (res == WPA_INVALID_GROUP)
-				resp = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
-			else if (res == WPA_INVALID_PAIRWISE)
-				resp = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
-			else if (res == WPA_INVALID_AKMP)
-				resp = WLAN_STATUS_AKMP_NOT_VALID;
-			else if (res == WPA_ALLOC_FAIL)
-				resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
-			else if (res != WPA_IE_OK)
-				resp = WLAN_STATUS_INVALID_IE;
-			if (resp != WLAN_STATUS_SUCCESS)
-				goto fail;
-		}
-		hdr->oid = (hdr->oid == htonl(DOT11_OID_ASSOCIATEEX)) ?
-			htonl(DOT11_OID_ASSOCIATEEX) :
-			htonl(DOT11_OID_REASSOCIATEEX);
-		hdr->op = htonl(PIMOP_SET);
-		mlme->code = 0;
-		mlme->state = htons(DOT11_STATE_ASSOC);
-		mlme->size = 0;
-		send(drv->pim_sock, hdr, sizeof(*hdr) + sizeof(*mlme), 0);
-		return;
-	} else if (mlme->state==htons(DOT11_STATE_ASSOC)) {
-		if (len < sizeof(pimdev_hdr) + sizeof(struct obj_mlme)) {
-			printf("bad assoc packet\n");
-			return;
-		}
-		mac_id = mac_id_get(drv, mlme->id);
-		if (mac_id == NULL)
-			return;
-		memcpy(&mlme->address[0], mac_id, ETH_ALEN);
-		sta = ap_get_sta(drv->hapd, (u8 *) &mlme->address[0]);
-		if (sta == NULL) {
-			printf("cannot get sta\n");
-			return;
-		}
-		new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
-		sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
-		wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
-		hostapd_new_assoc_sta(drv->hapd, sta, !new_assoc);
-		ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
-		sta->timeout_next = STA_NULLFUNC;
-		return;
-	}
-	return;
-
-fail:
-	printf("Prism54: assoc fail: %x\n", resp);
-	mlme->code = host_to_le16(resp);
-	mlme->size = 0;
-	mlme->state = htons(DOT11_STATE_ASSOCING);
-	hdr->oid = htonl(DOT11_OID_DISASSOCIATEEX);
-	hdr->op = htonl(PIMOP_SET);
-	sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
-	send(drv->pim_sock, hdr, sizeof(*hdr) + sizeof(*mlme), 0);
-}
-
-
-static void handle_pim(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	struct prism54_driver_data *drv = eloop_ctx;
-	int len;
-	pimdev_hdr *hdr;
-
-	hdr = malloc(PIM_BUF_SIZE);
-	if (hdr == NULL)
-		return;
-	len = recv(sock, hdr, PIM_BUF_SIZE, 0);
-	if (len < 0) {
-		perror("recv");
-		free(hdr);
-		return;
-	}
-	if (len < 8) {
-		printf("handle_pim: too short (%d)\n", len);
-		free(hdr);
-		return;
-	}
-
-	if (hdr->op != (int) htonl(PIMOP_TRAP)) {
-		free(hdr);
-		return;
-	}
-	switch (ntohl(hdr->oid)) {
-		case DOT11_OID_PROBE:
-			prism54_handle_probe(drv, hdr, len);
-			break;
-		case DOT11_OID_DEAUTHENTICATEEX:
-		case DOT11_OID_DEAUTHENTICATE:
-			prism54_handle_deauth(drv, hdr, len);
-			break;
-		case DOT11_OID_DISASSOCIATEEX:
-		case DOT11_OID_DISASSOCIATE:
-			prism54_handle_disassoc(drv, hdr, len);
-			break;
-		case DOT11_OID_AUTHENTICATEEX:
-		case DOT11_OID_AUTHENTICATE:
-			prism54_handle_auth(drv, hdr, len);
-			break;
-		case DOT11_OID_ASSOCIATEEX:
-		case DOT11_OID_REASSOCIATEEX:
-		case DOT11_OID_ASSOCIATE:
-		case DOT11_OID_REASSOCIATE:
-			prism54_handle_assoc(drv, hdr, len);
-		default:
-			break;
-	}
-
-	free(hdr);
-}
-
-
-static void handle_802_3(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx;
-	int len;
-	ieee802_3_hdr *hdr;
-
-	hdr = malloc(PIM_BUF_SIZE);
-	if (hdr == NULL)
-		return;
-	len = recv(sock, hdr, PIM_BUF_SIZE, 0);
-	if (len < 0) {
-		perror("recv");
-		free(hdr);
-		return;
-	}
-        if (len < 14) {
-                wpa_printf(MSG_MSGDUMP, "handle_802_3: too short (%d)", len);
-		free(hdr);
-                return;
-        }
-        if (hdr->type == htons(ETH_P_PAE)) {
-                hostapd_eapol_receive(hapd, (u8 *) &hdr->sa[0], (u8 *) &hdr[1],
-				      len - sizeof(*hdr));
-        }
-	free(hdr);
-}
-
-
-static int prism54_init_sockets(struct prism54_driver_data *drv)
-{
-	struct hostapd_data *hapd = drv->hapd;
-	struct ifreq ifr;
-	struct sockaddr_ll addr;
-
-	drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
-	if (drv->sock < 0) {
-		perror("socket[PF_PACKET,SOCK_RAW]");
-		return -1;
-	}
-
-	if (eloop_register_read_sock(drv->sock, handle_802_3, drv->hapd, NULL))
-	{
-		printf("Could not register read socket\n");
-		return -1;
-	}
-
-        memset(&ifr, 0, sizeof(ifr));
-	if (hapd->conf->bridge[0] != '\0') {
-		printf("opening bridge: %s\n", hapd->conf->bridge);
-		os_strlcpy(ifr.ifr_name, hapd->conf->bridge,
-			   sizeof(ifr.ifr_name));
-	} else {
-		os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
-	}
-        if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
-		perror("ioctl(SIOCGIFINDEX)");
-		return -1;
-        }
-
-	memset(&addr, 0, sizeof(addr));
-	addr.sll_family = AF_PACKET;
-	addr.sll_ifindex = ifr.ifr_ifindex;
-	addr.sll_protocol = htons(ETH_P_PAE);
-	wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
-		   addr.sll_ifindex);
-
-	if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		perror("bind");
-		return -1;
-	}
-
-        memset(&ifr, 0, sizeof(ifr));
-        os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
-        if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
-		perror("ioctl(SIOCGIFHWADDR)");
-		return -1;
-        }
-
-	if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
-		printf("Invalid HW-addr family 0x%04x\n",
-		       ifr.ifr_hwaddr.sa_family);
-		return -1;
-	}
-	memcpy(drv->hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
-	drv->pim_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
-	if (drv->pim_sock < 0) {
-		perror("socket[PF_PACKET,SOCK_RAW]");
-		return -1;
-	}
-
-	if (eloop_register_read_sock(drv->pim_sock, handle_pim, drv, NULL)) {
-		printf("Could not register read socket\n");
-		return -1;
-	}
-
-        memset(&ifr, 0, sizeof(ifr));
-        snprintf(ifr.ifr_name, sizeof(ifr.ifr_name), "%sap", drv->iface);
-        if (ioctl(drv->pim_sock, SIOCGIFINDEX, &ifr) != 0) {
-		perror("ioctl(SIOCGIFINDEX)");
-		return -1;
-        }
-
-	memset(&addr, 0, sizeof(addr));
-	addr.sll_family = AF_PACKET;
-	addr.sll_ifindex = ifr.ifr_ifindex;
-	addr.sll_protocol = htons(ETH_P_ALL);
-	wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
-		   addr.sll_ifindex);
-
-	if (bind(drv->pim_sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		perror("bind");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static void * prism54_driver_init(struct hostapd_data *hapd)
-{
-	struct prism54_driver_data *drv;
-
-	drv = os_zalloc(sizeof(struct prism54_driver_data));
-	if (drv == NULL) {
-		printf("Could not allocate memory for hostapd Prism54 driver "
-		       "data\n");
-		return NULL;
-	}
-
-	drv->hapd = hapd;
-	drv->pim_sock = drv->sock = -1;
-	memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
-
-	if (prism54_init_sockets(drv)) {
-		free(drv);
-		return NULL;
-	}
-	prism54_init_1x(drv);
-	/* must clean previous elems */
-	prism54_set_generic_elem(drv->iface, drv, NULL, 0);
-
-	return drv;
-}
-
-
-static void prism54_driver_deinit(void *priv)
-{
-	struct prism54_driver_data *drv = priv;
-
-	if (drv->pim_sock >= 0)
-		close(drv->pim_sock);
-
-	if (drv->sock >= 0)
-		close(drv->sock);
-	
-	free(drv);
-}
-
-
-const struct hapd_driver_ops wpa_driver_prism54_ops = {
-	.name = "prism54",
-	.init = prism54_driver_init,
-	.deinit = prism54_driver_deinit,
-	/* .set_ieee8021x = prism54_init_1x, */
-	.set_privacy = prism54_set_privacy_invoked,
-	.set_key = prism54_set_key,
-	.get_seqnum = prism54_get_seqnum,
-	.flush = prism54_flush,
-	.set_generic_elem = prism54_set_generic_elem,
-	.send_eapol = prism54_send_eapol,
-	.sta_set_flags = prism54_sta_set_flags,
-	.sta_deauth = prism54_sta_deauth,
-	.sta_disassoc = prism54_sta_disassoc,
-	.set_ssid = prism54_ioctl_setiwessid,
-	.get_inact_sec = prism54_get_inact_sec,
-};

+ 0 - 1227
hostapd/driver_test.c

@@ -1,1227 +0,0 @@
-/*
- * hostapd / Driver interface for development testing
- * Copyright (c) 2004-2008, 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 "includes.h"
-#include <sys/un.h>
-#include <dirent.h>
-
-#include "hostapd.h"
-#include "config.h"
-#include "driver.h"
-#include "sha1.h"
-#include "eloop.h"
-#include "wpa.h"
-#include "l2_packet/l2_packet.h"
-#include "hw_features.h"
-#include "wps_hostapd.h"
-#include "ieee802_11_defs.h"
-
-
-struct test_client_socket {
-	struct test_client_socket *next;
-	u8 addr[ETH_ALEN];
-	struct sockaddr_un un;
-	socklen_t unlen;
-	struct test_driver_bss *bss;
-};
-
-struct test_driver_bss {
-	struct test_driver_bss *next;
-	char ifname[IFNAMSIZ + 1];
-	u8 bssid[ETH_ALEN];
-	u8 *ie;
-	size_t ielen;
-	u8 *wps_beacon_ie;
-	size_t wps_beacon_ie_len;
-	u8 *wps_probe_resp_ie;
-	size_t wps_probe_resp_ie_len;
-	u8 ssid[32];
-	size_t ssid_len;
-	int privacy;
-};
-
-struct test_driver_data {
-	struct hostapd_data *hapd;
-	struct test_client_socket *cli;
-	int test_socket;
-	struct test_driver_bss *bss;
-	char *socket_dir;
-	char *own_socket_path;
-	int udp_port;
-};
-
-
-static void test_driver_free_bss(struct test_driver_bss *bss)
-{
-	free(bss->ie);
-	free(bss->wps_beacon_ie);
-	free(bss->wps_probe_resp_ie);
-	free(bss);
-}
-
-
-static void test_driver_free_priv(struct test_driver_data *drv)
-{
-	struct test_driver_bss *bss, *prev;
-
-	if (drv == NULL)
-		return;
-
-	bss = drv->bss;
-	while (bss) {
-		prev = bss;
-		bss = bss->next;
-		test_driver_free_bss(prev);
-	}
-	free(drv->own_socket_path);
-	free(drv->socket_dir);
-	free(drv);
-}
-
-
-static struct test_client_socket *
-test_driver_get_cli(struct test_driver_data *drv, struct sockaddr_un *from,
-		    socklen_t fromlen)
-{
-	struct test_client_socket *cli = drv->cli;
-
-	while (cli) {
-		if (cli->unlen == fromlen &&
-		    strncmp(cli->un.sun_path, from->sun_path,
-			    fromlen - sizeof(cli->un.sun_family)) == 0)
-			return cli;
-		cli = cli->next;
-	}
-
-	return NULL;
-}
-
-
-static int test_driver_send_eapol(void *priv, const u8 *addr, const u8 *data,
-				  size_t data_len, int encrypt,
-				  const u8 *own_addr)
-{
-	struct test_driver_data *drv = priv;
-	struct test_client_socket *cli;
-	struct msghdr msg;
-	struct iovec io[3];
-	struct l2_ethhdr eth;
-
-	if (drv->test_socket < 0)
-		return -1;
-
-	cli = drv->cli;
-	while (cli) {
-		if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
-			break;
-		cli = cli->next;
-	}
-
-	if (!cli) {
-		wpa_printf(MSG_DEBUG, "%s: no destination client entry",
-			   __func__);
-		return -1;
-	}
-
-	memcpy(eth.h_dest, addr, ETH_ALEN);
-	memcpy(eth.h_source, own_addr, ETH_ALEN);
-	eth.h_proto = host_to_be16(ETH_P_EAPOL);
-
-	io[0].iov_base = "EAPOL ";
-	io[0].iov_len = 6;
-	io[1].iov_base = &eth;
-	io[1].iov_len = sizeof(eth);
-	io[2].iov_base = (u8 *) data;
-	io[2].iov_len = data_len;
-
-	memset(&msg, 0, sizeof(msg));
-	msg.msg_iov = io;
-	msg.msg_iovlen = 3;
-	msg.msg_name = &cli->un;
-	msg.msg_namelen = cli->unlen;
-	return sendmsg(drv->test_socket, &msg, 0);
-}
-
-
-static int test_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
-				  u16 proto, const u8 *data, size_t data_len)
-{
-	struct test_driver_data *drv = priv;
-	struct msghdr msg;
-	struct iovec io[3];
-	struct l2_ethhdr eth;
-	char desttxt[30];
-	struct sockaddr_un addr;
-	struct dirent *dent;
-	DIR *dir;
-	int ret = 0, broadcast = 0, count = 0;
-
-	if (drv->test_socket < 0 || drv->socket_dir == NULL) {
-		wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d "
-			   "socket_dir=%p)",
-			   __func__, drv->test_socket, drv->socket_dir);
-		return -1;
-	}
-
-	broadcast = memcmp(dst, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
-	snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dst));
-
-	memcpy(eth.h_dest, dst, ETH_ALEN);
-	memcpy(eth.h_source, src, ETH_ALEN);
-	eth.h_proto = host_to_be16(proto);
-
-	io[0].iov_base = "ETHER ";
-	io[0].iov_len = 6;
-	io[1].iov_base = &eth;
-	io[1].iov_len = sizeof(eth);
-	io[2].iov_base = (u8 *) data;
-	io[2].iov_len = data_len;
-
-	memset(&msg, 0, sizeof(msg));
-	msg.msg_iov = io;
-	msg.msg_iovlen = 3;
-
-	dir = opendir(drv->socket_dir);
-	if (dir == NULL) {
-		perror("test_driver: opendir");
-		return -1;
-	}
-	while ((dent = readdir(dir))) {
-#ifdef _DIRENT_HAVE_D_TYPE
-		/* Skip the file if it is not a socket. Also accept
-		 * DT_UNKNOWN (0) in case the C library or underlying file
-		 * system does not support d_type. */
-		if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
-			continue;
-#endif /* _DIRENT_HAVE_D_TYPE */
-		if (strcmp(dent->d_name, ".") == 0 ||
-		    strcmp(dent->d_name, "..") == 0)
-			continue;
-
-		memset(&addr, 0, sizeof(addr));
-		addr.sun_family = AF_UNIX;
-		snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
-			 drv->socket_dir, dent->d_name);
-
-		if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
-			continue;
-		if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
-			continue;
-
-		wpa_printf(MSG_DEBUG, "%s: Send ether frame to %s",
-			   __func__, dent->d_name);
-
-		msg.msg_name = &addr;
-		msg.msg_namelen = sizeof(addr);
-		ret = sendmsg(drv->test_socket, &msg, 0);
-		if (ret < 0)
-			perror("driver_test: sendmsg");
-		count++;
-	}
-	closedir(dir);
-
-	if (!broadcast && count == 0) {
-		wpa_printf(MSG_DEBUG, "%s: Destination " MACSTR " not found",
-			   __func__, MAC2STR(dst));
-		return -1;
-	}
-
-	return ret;
-}
-
-
-static int test_driver_send_mgmt_frame(void *priv, const void *buf,
-				       size_t len, int flags)
-{
-	struct test_driver_data *drv = priv;
-	struct msghdr msg;
-	struct iovec io[2];
-	const u8 *dest;
-	int ret = 0, broadcast = 0;
-	char desttxt[30];
-	struct sockaddr_un addr;
-	struct dirent *dent;
-	DIR *dir;
-	struct ieee80211_hdr *hdr;
-	u16 fc;
-
-	if (drv->test_socket < 0 || len < 10 || drv->socket_dir == NULL) {
-		wpa_printf(MSG_DEBUG, "%s: invalid parameters (sock=%d len=%lu"
-			   " socket_dir=%p)",
-			   __func__, drv->test_socket, (unsigned long) len,
-			   drv->socket_dir);
-		return -1;
-	}
-
-	dest = buf;
-	dest += 4;
-	broadcast = memcmp(dest, "\xff\xff\xff\xff\xff\xff", ETH_ALEN) == 0;
-	snprintf(desttxt, sizeof(desttxt), MACSTR, MAC2STR(dest));
-
-	io[0].iov_base = "MLME ";
-	io[0].iov_len = 5;
-	io[1].iov_base = (void *) buf;
-	io[1].iov_len = len;
-
-	memset(&msg, 0, sizeof(msg));
-	msg.msg_iov = io;
-	msg.msg_iovlen = 2;
-
-	dir = opendir(drv->socket_dir);
-	if (dir == NULL) {
-		perror("test_driver: opendir");
-		return -1;
-	}
-	while ((dent = readdir(dir))) {
-#ifdef _DIRENT_HAVE_D_TYPE
-		/* Skip the file if it is not a socket. Also accept
-		 * DT_UNKNOWN (0) in case the C library or underlying file
-		 * system does not support d_type. */
-		if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
-			continue;
-#endif /* _DIRENT_HAVE_D_TYPE */
-		if (strcmp(dent->d_name, ".") == 0 ||
-		    strcmp(dent->d_name, "..") == 0)
-			continue;
-
-		memset(&addr, 0, sizeof(addr));
-		addr.sun_family = AF_UNIX;
-		snprintf(addr.sun_path, sizeof(addr.sun_path), "%s/%s",
-			 drv->socket_dir, dent->d_name);
-
-		if (strcmp(addr.sun_path, drv->own_socket_path) == 0)
-			continue;
-		if (!broadcast && strstr(dent->d_name, desttxt) == NULL)
-			continue;
-
-		wpa_printf(MSG_DEBUG, "%s: Send management frame to %s",
-			   __func__, dent->d_name);
-
-		msg.msg_name = &addr;
-		msg.msg_namelen = sizeof(addr);
-		ret = sendmsg(drv->test_socket, &msg, 0);
-		if (ret < 0)
-			perror("driver_test: sendmsg");
-	}
-	closedir(dir);
-
-	hdr = (struct ieee80211_hdr *) buf;
-	fc = le_to_host16(hdr->frame_control);
-	hostapd_mgmt_tx_cb(drv->hapd, (u8 *) buf, len, WLAN_FC_GET_STYPE(fc),
-			   ret >= 0);
-
-	return ret;
-}
-
-
-static void test_driver_scan(struct test_driver_data *drv,
-			     struct sockaddr_un *from, socklen_t fromlen,
-			     char *data)
-{
-	char buf[512], *pos, *end;
-	int ret;
-	struct test_driver_bss *bss;
-	u8 sa[ETH_ALEN];
-	u8 ie[512];
-	size_t ielen;
-
-	/* data: optional [ ' ' | STA-addr | ' ' | IEs(hex) ] */
-
-	wpa_printf(MSG_DEBUG, "test_driver: SCAN");
-
-	if (*data) {
-		if (*data != ' ' ||
-		    hwaddr_aton(data + 1, sa)) {
-			wpa_printf(MSG_DEBUG, "test_driver: Unexpected SCAN "
-				   "command format");
-			return;
-		}
-
-		data += 18;
-		while (*data == ' ')
-			data++;
-		ielen = os_strlen(data) / 2;
-		if (ielen > sizeof(ie))
-			ielen = sizeof(ie);
-		if (hexstr2bin(data, ie, ielen) < 0)
-			ielen = 0;
-
-		wpa_printf(MSG_DEBUG, "test_driver: Scan from " MACSTR,
-			   MAC2STR(sa));
-		wpa_hexdump(MSG_MSGDUMP, "test_driver: scan IEs", ie, ielen);
-
-		hostapd_wps_probe_req_rx(drv->hapd, sa, ie, ielen);
-	}
-
-	for (bss = drv->bss; bss; bss = bss->next) {
-		pos = buf;
-		end = buf + sizeof(buf);
-
-		/* reply: SCANRESP BSSID SSID IEs */
-		ret = snprintf(pos, end - pos, "SCANRESP " MACSTR " ",
-			       MAC2STR(bss->bssid));
-		if (ret < 0 || ret >= end - pos)
-			return;
-		pos += ret;
-		pos += wpa_snprintf_hex(pos, end - pos,
-					bss->ssid, bss->ssid_len);
-		ret = snprintf(pos, end - pos, " ");
-		if (ret < 0 || ret >= end - pos)
-			return;
-		pos += ret;
-		pos += wpa_snprintf_hex(pos, end - pos, bss->ie, bss->ielen);
-		pos += wpa_snprintf_hex(pos, end - pos, bss->wps_probe_resp_ie,
-					bss->wps_probe_resp_ie_len);
-
-		if (bss->privacy) {
-			ret = snprintf(pos, end - pos, " PRIVACY");
-			if (ret < 0 || ret >= end - pos)
-				return;
-			pos += ret;
-		}
-
-		sendto(drv->test_socket, buf, pos - buf, 0,
-		       (struct sockaddr *) from, fromlen);
-	}
-}
-
-
-static struct hostapd_data * test_driver_get_hapd(struct test_driver_data *drv,
-						  struct test_driver_bss *bss)
-{
-	struct hostapd_iface *iface = drv->hapd->iface;
-	struct hostapd_data *hapd = NULL;
-	size_t i;
-
-	if (bss == NULL) {
-		wpa_printf(MSG_DEBUG, "%s: bss == NULL", __func__);
-		return NULL;
-	}
-
-	for (i = 0; i < iface->num_bss; i++) {
-		hapd = iface->bss[i];
-		if (memcmp(hapd->own_addr, bss->bssid, ETH_ALEN) == 0)
-			break;
-	}
-	if (i == iface->num_bss) {
-		wpa_printf(MSG_DEBUG, "%s: no matching interface entry found "
-			   "for BSSID " MACSTR, __func__, MAC2STR(bss->bssid));
-		return NULL;
-	}
-
-	return hapd;
-}
-
-
-static int test_driver_new_sta(struct test_driver_data *drv,
-			       struct test_driver_bss *bss, const u8 *addr,
-			       const u8 *ie, size_t ielen)
-{
-	struct hostapd_data *hapd;
-
-	hapd = test_driver_get_hapd(drv, bss);
-	if (hapd == NULL)
-		return -1;
-
-	return hostapd_notif_assoc(hapd, addr, ie, ielen);
-}
-
-
-static void test_driver_assoc(struct test_driver_data *drv,
-			      struct sockaddr_un *from, socklen_t fromlen,
-			      char *data)
-{
-	struct test_client_socket *cli;
-	u8 ie[256], ssid[32];
-	size_t ielen, ssid_len = 0;
-	char *pos, *pos2, cmd[50];
-	struct test_driver_bss *bss;
-
-	/* data: STA-addr SSID(hex) IEs(hex) */
-
-	cli = os_zalloc(sizeof(*cli));
-	if (cli == NULL)
-		return;
-
-	if (hwaddr_aton(data, cli->addr)) {
-		printf("test_socket: Invalid MAC address '%s' in ASSOC\n",
-		       data);
-		free(cli);
-		return;
-	}
-	pos = data + 17;
-	while (*pos == ' ')
-		pos++;
-	pos2 = strchr(pos, ' ');
-	ielen = 0;
-	if (pos2) {
-		ssid_len = (pos2 - pos) / 2;
-		if (hexstr2bin(pos, ssid, ssid_len) < 0) {
-			wpa_printf(MSG_DEBUG, "%s: Invalid SSID", __func__);
-			free(cli);
-			return;
-		}
-		wpa_hexdump_ascii(MSG_DEBUG, "test_driver_assoc: SSID",
-				  ssid, ssid_len);
-
-		pos = pos2 + 1;
-		ielen = strlen(pos) / 2;
-		if (ielen > sizeof(ie))
-			ielen = sizeof(ie);
-		if (hexstr2bin(pos, ie, ielen) < 0)
-			ielen = 0;
-	}
-
-	for (bss = drv->bss; bss; bss = bss->next) {
-		if (bss->ssid_len == ssid_len &&
-		    memcmp(bss->ssid, ssid, ssid_len) == 0)
-			break;
-	}
-	if (bss == NULL) {
-		wpa_printf(MSG_DEBUG, "%s: No matching SSID found from "
-			   "configured BSSes", __func__);
-		free(cli);
-		return;
-	}
-
-	cli->bss = bss;
-	memcpy(&cli->un, from, sizeof(cli->un));
-	cli->unlen = fromlen;
-	cli->next = drv->cli;
-	drv->cli = cli;
-	wpa_hexdump_ascii(MSG_DEBUG, "test_socket: ASSOC sun_path",
-			  (const u8 *) cli->un.sun_path,
-			  cli->unlen - sizeof(cli->un.sun_family));
-
-	snprintf(cmd, sizeof(cmd), "ASSOCRESP " MACSTR " 0",
-		 MAC2STR(bss->bssid));
-	sendto(drv->test_socket, cmd, strlen(cmd), 0,
-	       (struct sockaddr *) from, fromlen);
-
-	if (test_driver_new_sta(drv, bss, cli->addr, ie, ielen) < 0) {
-		wpa_printf(MSG_DEBUG, "test_driver: failed to add new STA");
-	}
-}
-
-
-static void test_driver_disassoc(struct test_driver_data *drv,
-				 struct sockaddr_un *from, socklen_t fromlen)
-{
-	struct test_client_socket *cli;
-
-	cli = test_driver_get_cli(drv, from, fromlen);
-	if (!cli)
-		return;
-
-	hostapd_notif_disassoc(drv->hapd, cli->addr);
-}
-
-
-static void test_driver_eapol(struct test_driver_data *drv,
-			      struct sockaddr_un *from, socklen_t fromlen,
-			      u8 *data, size_t datalen)
-{
-	struct test_client_socket *cli;
-	if (datalen > 14) {
-		/* Skip Ethernet header */
-		wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src="
-			   MACSTR " proto=%04x",
-			   MAC2STR(data), MAC2STR(data + ETH_ALEN),
-			   WPA_GET_BE16(data + 2 * ETH_ALEN));
-		data += 14;
-		datalen -= 14;
-	}
-	cli = test_driver_get_cli(drv, from, fromlen);
-	if (cli) {
-		struct hostapd_data *hapd;
-		hapd = test_driver_get_hapd(drv, cli->bss);
-		if (hapd == NULL)
-			return;
-		hostapd_eapol_receive(hapd, cli->addr, data, datalen);
-	} else {
-		wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown "
-			   "client");
-	}
-}
-
-
-static void test_driver_ether(struct test_driver_data *drv,
-			      struct sockaddr_un *from, socklen_t fromlen,
-			      u8 *data, size_t datalen)
-{
-	struct l2_ethhdr *eth;
-
-	if (datalen < sizeof(*eth))
-		return;
-
-	eth = (struct l2_ethhdr *) data;
-	wpa_printf(MSG_DEBUG, "test_driver: RX ETHER dst=" MACSTR " src="
-		   MACSTR " proto=%04x",
-		   MAC2STR(eth->h_dest), MAC2STR(eth->h_source),
-		   be_to_host16(eth->h_proto));
-
-#ifdef CONFIG_IEEE80211R
-	if (be_to_host16(eth->h_proto) == ETH_P_RRB) {
-		wpa_ft_rrb_rx(drv->hapd->wpa_auth, eth->h_source,
-			      data + sizeof(*eth), datalen - sizeof(*eth));
-	}
-#endif /* CONFIG_IEEE80211R */
-}
-
-
-static void test_driver_mlme(struct test_driver_data *drv,
-			     struct sockaddr_un *from, socklen_t fromlen,
-			     u8 *data, size_t datalen)
-{
-	struct ieee80211_hdr *hdr;
-	u16 fc;
-
-	hdr = (struct ieee80211_hdr *) data;
-
-	if (test_driver_get_cli(drv, from, fromlen) == NULL && datalen >= 16) {
-		struct test_client_socket *cli;
-		cli = os_zalloc(sizeof(*cli));
-		if (cli == NULL)
-			return;
-		wpa_printf(MSG_DEBUG, "Adding client entry for " MACSTR,
-			   MAC2STR(hdr->addr2));
-		memcpy(cli->addr, hdr->addr2, ETH_ALEN);
-		memcpy(&cli->un, from, sizeof(cli->un));
-		cli->unlen = fromlen;
-		cli->next = drv->cli;
-		drv->cli = cli;
-	}
-
-	wpa_hexdump(MSG_MSGDUMP, "test_driver_mlme: received frame",
-		    data, datalen);
-	fc = le_to_host16(hdr->frame_control);
-	if (WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT) {
-		wpa_printf(MSG_ERROR, "%s: received non-mgmt frame",
-			   __func__);
-		return;
-	}
-	hostapd_mgmt_rx(drv->hapd, data, datalen, WLAN_FC_GET_STYPE(fc), NULL);
-}
-
-
-static void test_driver_receive_unix(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	struct test_driver_data *drv = eloop_ctx;
-	char buf[2000];
-	int res;
-	struct sockaddr_un from;
-	socklen_t fromlen = sizeof(from);
-
-	res = recvfrom(sock, buf, sizeof(buf) - 1, 0,
-		       (struct sockaddr *) &from, &fromlen);
-	if (res < 0) {
-		perror("recvfrom(test_socket)");
-		return;
-	}
-	buf[res] = '\0';
-
-	wpa_printf(MSG_DEBUG, "test_driver: received %u bytes", res);
-
-	if (strncmp(buf, "SCAN", 4) == 0) {
-		test_driver_scan(drv, &from, fromlen, buf + 4);
-	} else if (strncmp(buf, "ASSOC ", 6) == 0) {
-		test_driver_assoc(drv, &from, fromlen, buf + 6);
-	} else if (strcmp(buf, "DISASSOC") == 0) {
-		test_driver_disassoc(drv, &from, fromlen);
-	} else if (strncmp(buf, "EAPOL ", 6) == 0) {
-		test_driver_eapol(drv, &from, fromlen, (u8 *) buf + 6,
-				  res - 6);
-	} else if (strncmp(buf, "ETHER ", 6) == 0) {
-		test_driver_ether(drv, &from, fromlen, (u8 *) buf + 6,
-				  res - 6);
-	} else if (strncmp(buf, "MLME ", 5) == 0) {
-		test_driver_mlme(drv, &from, fromlen, (u8 *) buf + 5, res - 5);
-	} else {
-		wpa_hexdump_ascii(MSG_DEBUG, "Unknown test_socket command",
-				  (u8 *) buf, res);
-	}
-}
-
-
-static struct test_driver_bss *
-test_driver_get_bss(struct test_driver_data *drv, const char *ifname)
-{
-	struct test_driver_bss *bss;
-
-	for (bss = drv->bss; bss; bss = bss->next) {
-		if (strcmp(bss->ifname, ifname) == 0)
-			return bss;
-	}
-	return NULL;
-}
-
-
-static int test_driver_set_generic_elem(const char *ifname, void *priv,
-					const u8 *elem, size_t elem_len)
-{
-	struct test_driver_data *drv = priv;
-	struct test_driver_bss *bss;
-
-	bss = test_driver_get_bss(drv, ifname);
-	if (bss == NULL)
-		return -1;
-
-	free(bss->ie);
-
-	if (elem == NULL) {
-		bss->ie = NULL;
-		bss->ielen = 0;
-		return 0;
-	}
-
-	bss->ie = malloc(elem_len);
-	if (bss->ie == NULL) {
-		bss->ielen = 0;
-		return -1;
-	}
-
-	memcpy(bss->ie, elem, elem_len);
-	bss->ielen = elem_len;
-	return 0;
-}
-
-
-static int test_driver_set_wps_beacon_ie(const char *ifname, void *priv,
-					 const u8 *ie, size_t len)
-{
-	struct test_driver_data *drv = priv;
-	struct test_driver_bss *bss;
-
-	wpa_hexdump(MSG_DEBUG, "test_driver: Beacon WPS IE", ie, len);
-	bss = test_driver_get_bss(drv, ifname);
-	if (bss == NULL)
-		return -1;
-
-	free(bss->wps_beacon_ie);
-
-	if (ie == NULL) {
-		bss->wps_beacon_ie = NULL;
-		bss->wps_beacon_ie_len = 0;
-		return 0;
-	}
-
-	bss->wps_beacon_ie = malloc(len);
-	if (bss->wps_beacon_ie == NULL) {
-		bss->wps_beacon_ie_len = 0;
-		return -1;
-	}
-
-	memcpy(bss->wps_beacon_ie, ie, len);
-	bss->wps_beacon_ie_len = len;
-	return 0;
-}
-
-
-static int test_driver_set_wps_probe_resp_ie(const char *ifname, void *priv,
-					     const u8 *ie, size_t len)
-{
-	struct test_driver_data *drv = priv;
-	struct test_driver_bss *bss;
-
-	wpa_hexdump(MSG_DEBUG, "test_driver: ProbeResp WPS IE", ie, len);
-	bss = test_driver_get_bss(drv, ifname);
-	if (bss == NULL)
-		return -1;
-
-	free(bss->wps_probe_resp_ie);
-
-	if (ie == NULL) {
-		bss->wps_probe_resp_ie = NULL;
-		bss->wps_probe_resp_ie_len = 0;
-		return 0;
-	}
-
-	bss->wps_probe_resp_ie = malloc(len);
-	if (bss->wps_probe_resp_ie == NULL) {
-		bss->wps_probe_resp_ie_len = 0;
-		return -1;
-	}
-
-	memcpy(bss->wps_probe_resp_ie, ie, len);
-	bss->wps_probe_resp_ie_len = len;
-	return 0;
-}
-
-
-static int test_driver_sta_deauth(void *priv, const u8 *addr, int reason)
-{
-	struct test_driver_data *drv = priv;
-	struct test_client_socket *cli;
-
-	if (drv->test_socket < 0)
-		return -1;
-
-	cli = drv->cli;
-	while (cli) {
-		if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
-			break;
-		cli = cli->next;
-	}
-
-	if (!cli)
-		return -1;
-
-	return sendto(drv->test_socket, "DEAUTH", 6, 0,
-		      (struct sockaddr *) &cli->un, cli->unlen);
-}
-
-
-static int test_driver_sta_disassoc(void *priv, const u8 *addr, int reason)
-{
-	struct test_driver_data *drv = priv;
-	struct test_client_socket *cli;
-
-	if (drv->test_socket < 0)
-		return -1;
-
-	cli = drv->cli;
-	while (cli) {
-		if (memcmp(cli->addr, addr, ETH_ALEN) == 0)
-			break;
-		cli = cli->next;
-	}
-
-	if (!cli)
-		return -1;
-
-	return sendto(drv->test_socket, "DISASSOC", 8, 0,
-		      (struct sockaddr *) &cli->un, cli->unlen);
-}
-
-
-static struct hostapd_hw_modes *
-test_driver_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
-{
-	struct hostapd_hw_modes *modes;
-
-	*num_modes = 3;
-	*flags = 0;
-	modes = os_zalloc(*num_modes * sizeof(struct hostapd_hw_modes));
-	if (modes == NULL)
-		return NULL;
-	modes[0].mode = HOSTAPD_MODE_IEEE80211G;
-	modes[0].num_channels = 1;
-	modes[0].num_rates = 1;
-	modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
-	modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
-	if (modes[0].channels == NULL || modes[0].rates == NULL) {
-		hostapd_free_hw_features(modes, *num_modes);
-		return NULL;
-	}
-	modes[0].channels[0].chan = 1;
-	modes[0].channels[0].freq = 2412;
-	modes[0].channels[0].flag = 0;
-	modes[0].rates[0].rate = 10;
-	modes[0].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
-		HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
-
-	modes[1].mode = HOSTAPD_MODE_IEEE80211B;
-	modes[1].num_channels = 1;
-	modes[1].num_rates = 1;
-	modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
-	modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
-	if (modes[1].channels == NULL || modes[1].rates == NULL) {
-		hostapd_free_hw_features(modes, *num_modes);
-		return NULL;
-	}
-	modes[1].channels[0].chan = 1;
-	modes[1].channels[0].freq = 2412;
-	modes[1].channels[0].flag = 0;
-	modes[1].rates[0].rate = 10;
-	modes[1].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
-		HOSTAPD_RATE_CCK | HOSTAPD_RATE_MANDATORY;
-
-	modes[2].mode = HOSTAPD_MODE_IEEE80211A;
-	modes[2].num_channels = 1;
-	modes[2].num_rates = 1;
-	modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
-	modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
-	if (modes[2].channels == NULL || modes[2].rates == NULL) {
-		hostapd_free_hw_features(modes, *num_modes);
-		return NULL;
-	}
-	modes[2].channels[0].chan = 60;
-	modes[2].channels[0].freq = 5300;
-	modes[2].channels[0].flag = 0;
-	modes[2].rates[0].rate = 60;
-	modes[2].rates[0].flags = HOSTAPD_RATE_BASIC | HOSTAPD_RATE_SUPPORTED |
-		HOSTAPD_RATE_MANDATORY;
-
-	return modes;
-}
-
-
-static int test_driver_bss_add(void *priv, const char *ifname, const u8 *bssid)
-{
-	struct test_driver_data *drv = priv;
-	struct test_driver_bss *bss;
-
-	wpa_printf(MSG_DEBUG, "%s(ifname=%s bssid=" MACSTR ")",
-		   __func__, ifname, MAC2STR(bssid));
-
-	bss = os_zalloc(sizeof(*bss));
-	if (bss == NULL)
-		return -1;
-
-	os_strlcpy(bss->ifname, ifname, IFNAMSIZ);
-	memcpy(bss->bssid, bssid, ETH_ALEN);
-
-	bss->next = drv->bss;
-	drv->bss = bss;
-
-	return 0;
-}
-
-
-static int test_driver_bss_remove(void *priv, const char *ifname)
-{
-	struct test_driver_data *drv = priv;
-	struct test_driver_bss *bss, *prev;
-	struct test_client_socket *cli, *prev_c;
-
-	wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
-
-	for (prev = NULL, bss = drv->bss; bss; prev = bss, bss = bss->next) {
-		if (strcmp(bss->ifname, ifname) != 0)
-			continue;
-
-		if (prev)
-			prev->next = bss->next;
-		else
-			drv->bss = bss->next;
-
-		for (prev_c = NULL, cli = drv->cli; cli;
-		     prev_c = cli, cli = cli->next) {
-			if (cli->bss != bss)
-				continue;
-			if (prev_c)
-				prev_c->next = cli->next;
-			else
-				drv->cli = cli->next;
-			free(cli);
-			break;
-		}
-
-		test_driver_free_bss(bss);
-		return 0;
-	}
-
-	return -1;
-}
-
-
-static int test_driver_if_add(const char *iface, void *priv,
-			      enum hostapd_driver_if_type type, char *ifname,
-			      const u8 *addr)
-{
-	wpa_printf(MSG_DEBUG, "%s(iface=%s type=%d ifname=%s)",
-		   __func__, iface, type, ifname);
-	return 0;
-}
-
-
-static int test_driver_if_update(void *priv, enum hostapd_driver_if_type type,
-				 char *ifname, const u8 *addr)
-{
-	wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
-	return 0;
-}
-
-
-static int test_driver_if_remove(void *priv, enum hostapd_driver_if_type type,
-				 const char *ifname, const u8 *addr)
-{
-	wpa_printf(MSG_DEBUG, "%s(type=%d ifname=%s)", __func__, type, ifname);
-	return 0;
-}
-
-
-static int test_driver_valid_bss_mask(void *priv, const u8 *addr,
-				      const u8 *mask)
-{
-	return 0;
-}
-
-
-static int test_driver_set_ssid(const char *ifname, void *priv, const u8 *buf,
-				int len)
-{
-	struct test_driver_data *drv = priv;
-	struct test_driver_bss *bss;
-
-	wpa_printf(MSG_DEBUG, "%s(ifname=%s)", __func__, ifname);
-	wpa_hexdump_ascii(MSG_DEBUG, "test_driver_set_ssid: SSID", buf, len);
-
-	for (bss = drv->bss; bss; bss = bss->next) {
-		if (strcmp(bss->ifname, ifname) != 0)
-			continue;
-
-		if (len < 0 || (size_t) len > sizeof(bss->ssid))
-			return -1;
-
-		memcpy(bss->ssid, buf, len);
-		bss->ssid_len = len;
-
-		return 0;
-	}
-
-	return -1;
-}
-
-
-static int test_driver_set_privacy(const char *ifname, void *priv, int enabled)
-{
-	struct test_driver_data *drv = priv;
-	struct test_driver_bss *bss;
-
-	wpa_printf(MSG_DEBUG, "%s(ifname=%s enabled=%d)",
-		   __func__, ifname, enabled);
-
-	for (bss = drv->bss; bss; bss = bss->next) {
-		if (strcmp(bss->ifname, ifname) != 0)
-			continue;
-
-		bss->privacy = enabled;
-
-		return 0;
-	}
-
-	return -1;
-}
-
-
-static int test_driver_set_key(const char *iface, void *priv, wpa_alg alg,
-			       const u8 *addr, int key_idx, int set_tx,
-			       const u8 *seq, size_t seq_len,
-			       const u8 *key, size_t key_len)
-{
-	wpa_printf(MSG_DEBUG, "%s(iface=%s alg=%d idx=%d set_tx=%d)",
-		   __func__, iface, alg, key_idx, set_tx);
-	if (addr)
-		wpa_printf(MSG_DEBUG, "   addr=" MACSTR, MAC2STR(addr));
-	if (key)
-		wpa_hexdump_key(MSG_DEBUG, "   key", key, key_len);
-	return 0;
-}
-
-
-static int test_driver_set_sta_vlan(void *priv, const u8 *addr,
-				    const char *ifname, int vlan_id)
-{
-	wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " ifname=%s vlan_id=%d)",
-		   __func__, MAC2STR(addr), ifname, vlan_id);
-	return 0;
-}
-
-
-static int test_driver_sta_add(const char *ifname, void *priv,
-			       struct hostapd_sta_add_params *params)
-{
-	struct test_driver_data *drv = priv;
-	struct test_client_socket *cli;
-	struct test_driver_bss *bss;
-
-	wpa_printf(MSG_DEBUG, "%s(ifname=%s addr=" MACSTR " aid=%d "
-		   "capability=0x%x flags=0x%x listen_interval=%d)",
-		   __func__, ifname, MAC2STR(params->addr), params->aid,
-		   params->capability, params->flags,
-		   params->listen_interval);
-	wpa_hexdump(MSG_DEBUG, "test_driver_sta_add - supp_rates",
-		    params->supp_rates, params->supp_rates_len);
-
-	cli = drv->cli;
-	while (cli) {
-		if (os_memcmp(cli->addr, params->addr, ETH_ALEN) == 0)
-			break;
-		cli = cli->next;
-	}
-	if (!cli) {
-		wpa_printf(MSG_DEBUG, "%s: no matching client entry",
-			   __func__);
-		return -1;
-	}
-
-	for (bss = drv->bss; bss; bss = bss->next) {
-		if (strcmp(ifname, bss->ifname) == 0)
-			break;
-	}
-	if (bss == NULL) {
-		wpa_printf(MSG_DEBUG, "%s: No matching interface found from "
-			   "configured BSSes", __func__);
-		return -1;
-	}
-
-	cli->bss = bss;
-
-	return 0;
-}
-
-
-static void * test_driver_init(struct hostapd_data *hapd)
-{
-	struct test_driver_data *drv;
-	struct sockaddr_un addr_un;
-	struct sockaddr_in addr_in;
-	struct sockaddr *addr;
-	socklen_t alen;
-
-	drv = os_zalloc(sizeof(struct test_driver_data));
-	if (drv == NULL) {
-		printf("Could not allocate memory for test driver data\n");
-		return NULL;
-	}
-	drv->bss = os_zalloc(sizeof(*drv->bss));
-	if (drv->bss == NULL) {
-		printf("Could not allocate memory for test driver BSS data\n");
-		free(drv);
-		return NULL;
-	}
-
-	drv->hapd = hapd;
-
-	/* Generate a MAC address to help testing with multiple APs */
-	hapd->own_addr[0] = 0x02; /* locally administered */
-	sha1_prf((const u8 *) hapd->conf->iface, strlen(hapd->conf->iface),
-		 "hostapd test bssid generation",
-		 (const u8 *) hapd->conf->ssid.ssid, hapd->conf->ssid.ssid_len,
-		 hapd->own_addr + 1, ETH_ALEN - 1);
-
-	os_strlcpy(drv->bss->ifname, hapd->conf->iface, IFNAMSIZ);
-	memcpy(drv->bss->bssid, hapd->own_addr, ETH_ALEN);
-
-	if (hapd->conf->test_socket) {
-		if (strlen(hapd->conf->test_socket) >=
-		    sizeof(addr_un.sun_path)) {
-			printf("Too long test_socket path\n");
-			test_driver_free_priv(drv);
-			return NULL;
-		}
-		if (strncmp(hapd->conf->test_socket, "DIR:", 4) == 0) {
-			size_t len = strlen(hapd->conf->test_socket) + 30;
-			drv->socket_dir = strdup(hapd->conf->test_socket + 4);
-			drv->own_socket_path = malloc(len);
-			if (drv->own_socket_path) {
-				snprintf(drv->own_socket_path, len,
-					 "%s/AP-" MACSTR,
-					 hapd->conf->test_socket + 4,
-					 MAC2STR(hapd->own_addr));
-			}
-		} else if (strncmp(hapd->conf->test_socket, "UDP:", 4) == 0) {
-			drv->udp_port = atoi(hapd->conf->test_socket + 4);
-		} else {
-			drv->own_socket_path = strdup(hapd->conf->test_socket);
-		}
-		if (drv->own_socket_path == NULL && drv->udp_port == 0) {
-			test_driver_free_priv(drv);
-			return NULL;
-		}
-
-		drv->test_socket = socket(drv->udp_port ? PF_INET : PF_UNIX,
-					  SOCK_DGRAM, 0);
-		if (drv->test_socket < 0) {
-			perror("socket");
-			test_driver_free_priv(drv);
-			return NULL;
-		}
-
-		if (drv->udp_port) {
-			os_memset(&addr_in, 0, sizeof(addr_in));
-			addr_in.sin_family = AF_INET;
-			addr_in.sin_port = htons(drv->udp_port);
-			addr = (struct sockaddr *) &addr_in;
-			alen = sizeof(addr_in);
-		} else {
-			os_memset(&addr_un, 0, sizeof(addr_un));
-			addr_un.sun_family = AF_UNIX;
-			os_strlcpy(addr_un.sun_path, drv->own_socket_path,
-				   sizeof(addr_un.sun_path));
-			addr = (struct sockaddr *) &addr_un;
-			alen = sizeof(addr_un);
-		}
-		if (bind(drv->test_socket, addr, alen) < 0) {
-			perror("bind(PF_UNIX)");
-			close(drv->test_socket);
-			if (drv->own_socket_path)
-				unlink(drv->own_socket_path);
-			test_driver_free_priv(drv);
-			return NULL;
-		}
-		eloop_register_read_sock(drv->test_socket,
-					 test_driver_receive_unix, drv, NULL);
-	} else
-		drv->test_socket = -1;
-
-	return drv;
-}
-
-
-static void test_driver_deinit(void *priv)
-{
-	struct test_driver_data *drv = priv;
-	struct test_client_socket *cli, *prev;
-
-	cli = drv->cli;
-	while (cli) {
-		prev = cli;
-		cli = cli->next;
-		free(prev);
-	}
-
-	if (drv->test_socket >= 0) {
-		eloop_unregister_read_sock(drv->test_socket);
-		close(drv->test_socket);
-		if (drv->own_socket_path)
-			unlink(drv->own_socket_path);
-	}
-
-	/* There should be only one BSS remaining at this point. */
-	if (drv->bss == NULL)
-		wpa_printf(MSG_ERROR, "%s: drv->bss == NULL", __func__);
-	else if (drv->bss->next)
-		wpa_printf(MSG_ERROR, "%s: drv->bss->next != NULL", __func__);
-
-	test_driver_free_priv(drv);
-}
-
-
-const struct hapd_driver_ops wpa_driver_test_ops = {
-	.name = "test",
-	.init = test_driver_init,
-	.deinit = test_driver_deinit,
-	.send_eapol = test_driver_send_eapol,
-	.send_mgmt_frame = test_driver_send_mgmt_frame,
-	.set_generic_elem = test_driver_set_generic_elem,
-	.sta_deauth = test_driver_sta_deauth,
-	.sta_disassoc = test_driver_sta_disassoc,
-	.get_hw_feature_data = test_driver_get_hw_feature_data,
-	.bss_add = test_driver_bss_add,
-	.bss_remove = test_driver_bss_remove,
-	.if_add = test_driver_if_add,
-	.if_update = test_driver_if_update,
-	.if_remove = test_driver_if_remove,
-	.valid_bss_mask = test_driver_valid_bss_mask,
-	.set_ssid = test_driver_set_ssid,
-	.set_privacy = test_driver_set_privacy,
-	.set_key = test_driver_set_key,
-	.set_sta_vlan = test_driver_set_sta_vlan,
-	.sta_add = test_driver_sta_add,
-	.send_ether = test_driver_send_ether,
-	.set_wps_beacon_ie = test_driver_set_wps_beacon_ie,
-	.set_wps_probe_resp_ie = test_driver_set_wps_probe_resp_ie,
-};

+ 0 - 374
hostapd/driver_wired.c

@@ -1,374 +0,0 @@
-/*
- * hostapd / Kernel driver communication for wired (Ethernet) drivers
- * Copyright (c) 2002-2007, Jouni Malinen <j@w1.fi>
- * Copyright (c) 2004, Gunter Burchardt <tira@isx.de>
- *
- * 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 "includes.h"
-#include <sys/ioctl.h>
-
-#ifdef USE_KERNEL_HEADERS
-#include <asm/types.h>
-#include <linux/if_packet.h>
-#include <linux/if_ether.h>   /* The L2 protocols */
-#include <linux/if_arp.h>
-#include <linux/if.h>
-#else /* USE_KERNEL_HEADERS */
-#include <net/if_arp.h>
-#include <net/if.h>
-#include <netpacket/packet.h>
-#endif /* USE_KERNEL_HEADERS */
-
-#include "hostapd.h"
-#include "config.h"
-#include "eloop.h"
-#include "sta_info.h"
-#include "driver.h"
-#include "accounting.h"
-
-
-struct wired_driver_data {
-	struct hostapd_data *hapd;
-	char iface[IFNAMSIZ + 1];
-
-	int sock; /* raw packet socket for driver access */
-	int dhcp_sock; /* socket for dhcp packets */
-	int use_pae_group_addr;
-};
-
-
-#define WIRED_EAPOL_MULTICAST_GROUP	{0x01,0x80,0xc2,0x00,0x00,0x03}
-
-
-/* TODO: detecting new devices should eventually be changed from using DHCP
- * snooping to trigger on any packet from a new layer 2 MAC address, e.g.,
- * based on ebtables, etc. */
-
-struct dhcp_message {
-	u_int8_t op;
-	u_int8_t htype;
-	u_int8_t hlen;
-	u_int8_t hops;
-	u_int32_t xid;
-	u_int16_t secs;
-	u_int16_t flags;
-	u_int32_t ciaddr;
-	u_int32_t yiaddr;
-	u_int32_t siaddr;
-	u_int32_t giaddr;
-	u_int8_t chaddr[16];
-	u_int8_t sname[64];
-	u_int8_t file[128];
-	u_int32_t cookie;
-	u_int8_t options[308]; /* 312 - cookie */
-};
-
-
-static void wired_possible_new_sta(struct hostapd_data *hapd, u8 *addr)
-{
-	struct sta_info *sta;
-
-	sta = ap_get_sta(hapd, addr);
-	if (sta)
-		return;
-
-	wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
-		   " - adding a new STA", MAC2STR(addr));
-	sta = ap_sta_add(hapd, addr);
-	if (sta) {
-		hostapd_new_assoc_sta(hapd, sta, 0);
-	} else {
-		wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
-			   MAC2STR(addr));
-	}
-}
-
-
-static void handle_data(struct hostapd_data *hapd, unsigned char *buf,
-			size_t len)
-{
-	struct ieee8023_hdr *hdr;
-	u8 *pos, *sa;
-	size_t left;
-
-	/* must contain at least ieee8023_hdr 6 byte source, 6 byte dest,
-	 * 2 byte ethertype */
-	if (len < 14) {
-		wpa_printf(MSG_MSGDUMP, "handle_data: too short (%lu)",
-			   (unsigned long) len);
-		return;
-	}
-
-	hdr = (struct ieee8023_hdr *) buf;
-
-	switch (ntohs(hdr->ethertype)) {
-		case ETH_P_PAE:
-			wpa_printf(MSG_MSGDUMP, "Received EAPOL packet");
-			sa = hdr->src;
-			wired_possible_new_sta(hapd, sa);
-
-			pos = (u8 *) (hdr + 1);
-			left = len - sizeof(*hdr);
-
-			hostapd_eapol_receive(hapd, sa, pos, left);
-		break;
-
-	default:
-		wpa_printf(MSG_DEBUG, "Unknown ethertype 0x%04x in data frame",
-			   ntohs(hdr->ethertype));
-		break;
-	}
-}
-
-
-static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx;
-	int len;
-	unsigned char buf[3000];
-
-	len = recv(sock, buf, sizeof(buf), 0);
-	if (len < 0) {
-		perror("recv");
-		return;
-	}
-	
-	handle_data(hapd, buf, len);
-}
-
-
-static void handle_dhcp(int sock, void *eloop_ctx, void *sock_ctx)
-{
-	struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx;
-	int len;
-	unsigned char buf[3000];
-	struct dhcp_message *msg;
-	u8 *mac_address;
-
-	len = recv(sock, buf, sizeof(buf), 0);
-	if (len < 0) {
-		perror("recv"); 
-		return;
-	}
-
-	/* must contain at least dhcp_message->chaddr */
-	if (len < 44) {
-		wpa_printf(MSG_MSGDUMP, "handle_dhcp: too short (%d)", len);
-		return;
-	}
-	
-	msg = (struct dhcp_message *) buf;
-	mac_address = (u8 *) &(msg->chaddr);
-	
-	wpa_printf(MSG_MSGDUMP, "Got DHCP broadcast packet from " MACSTR,
-		   MAC2STR(mac_address));
-
-	wired_possible_new_sta(hapd, mac_address);
-}
-
-
-static int wired_init_sockets(struct wired_driver_data *drv)
-{
-	struct hostapd_data *hapd = drv->hapd;
-	struct ifreq ifr;
-	struct sockaddr_ll addr;
-	struct sockaddr_in addr2;
-	struct packet_mreq mreq;
-	u8 multicastgroup_eapol[6] = WIRED_EAPOL_MULTICAST_GROUP;
-	int n = 1;
-
-	drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
-	if (drv->sock < 0) {
-		perror("socket[PF_PACKET,SOCK_RAW]");
-		return -1;
-	}
-
-	if (eloop_register_read_sock(drv->sock, handle_read, hapd, NULL)) {
-		printf("Could not register read socket\n");
-		return -1;
-	}
-
-	memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
-	if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
-		perror("ioctl(SIOCGIFINDEX)");
-		return -1;
-	}
-
-	
-	memset(&addr, 0, sizeof(addr));
-	addr.sll_family = AF_PACKET;
-	addr.sll_ifindex = ifr.ifr_ifindex;
-	wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
-		   addr.sll_ifindex);
-
-	if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-		perror("bind");
-		return -1;
-	}
-
-	/* filter multicast address */
-	memset(&mreq, 0, sizeof(mreq));
-	mreq.mr_ifindex = ifr.ifr_ifindex;
-	mreq.mr_type = PACKET_MR_MULTICAST;
-	mreq.mr_alen = 6;
-	memcpy(mreq.mr_address, multicastgroup_eapol, mreq.mr_alen);
-
-	if (setsockopt(drv->sock, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq,
-		       sizeof(mreq)) < 0) {
-		perror("setsockopt[SOL_SOCKET,PACKET_ADD_MEMBERSHIP]");
-		return -1;
-	}
-
-	memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
-	if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
-		perror("ioctl(SIOCGIFHWADDR)");
-		return -1;
-	}
-
-	if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
-		printf("Invalid HW-addr family 0x%04x\n",
-		       ifr.ifr_hwaddr.sa_family);
-		return -1;
-	}
-	memcpy(hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
-
-	/* setup dhcp listen socket for sta detection */
-	if ((drv->dhcp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
-		perror("socket call failed for dhcp");
-		return -1;
-	}
-
-	if (eloop_register_read_sock(drv->dhcp_sock, handle_dhcp, hapd, NULL))
-	{
-		printf("Could not register read socket\n");
-		return -1;
-	}
-	
-	memset(&addr2, 0, sizeof(addr2));
-	addr2.sin_family = AF_INET;
-	addr2.sin_port = htons(67);
-	addr2.sin_addr.s_addr = INADDR_ANY;
-
-	if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_REUSEADDR, (char *) &n,
-		       sizeof(n)) == -1) {
-		perror("setsockopt[SOL_SOCKET,SO_REUSEADDR]");
-		return -1;
-	}
-	if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BROADCAST, (char *) &n,
-		       sizeof(n)) == -1) {
-		perror("setsockopt[SOL_SOCKET,SO_BROADCAST]");
-		return -1;
-	}
-
-	memset(&ifr, 0, sizeof(ifr));
-	os_strlcpy(ifr.ifr_ifrn.ifrn_name, drv->iface, IFNAMSIZ);
-	if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BINDTODEVICE,
-		       (char *) &ifr, sizeof(ifr)) < 0) {
-		perror("setsockopt[SOL_SOCKET,SO_BINDTODEVICE]");
-		return -1;
-	}
-
-	if (bind(drv->dhcp_sock, (struct sockaddr *) &addr2,
-		 sizeof(struct sockaddr)) == -1) {
-		perror("bind");
-		return -1;
-	}
-
-	return 0;
-}
-
-
-static int wired_send_eapol(void *priv, const u8 *addr,
-			    const u8 *data, size_t data_len, int encrypt,
-			    const u8 *own_addr)
-{
-	struct wired_driver_data *drv = priv;
-	u8 pae_group_addr[ETH_ALEN] = WIRED_EAPOL_MULTICAST_GROUP;
-	struct ieee8023_hdr *hdr;
-	size_t len;
-	u8 *pos;
-	int res;
-
-	len = sizeof(*hdr) + data_len;
-	hdr = os_zalloc(len);
-	if (hdr == NULL) {
-		printf("malloc() failed for wired_send_eapol(len=%lu)\n",
-		       (unsigned long) len);
-		return -1;
-	}
-
-	memcpy(hdr->dest, drv->use_pae_group_addr ? pae_group_addr : addr,
-	       ETH_ALEN);
-	memcpy(hdr->src, own_addr, ETH_ALEN);
-	hdr->ethertype = htons(ETH_P_PAE);
-
-	pos = (u8 *) (hdr + 1);
-	memcpy(pos, data, data_len);
-
-	res = send(drv->sock, (u8 *) hdr, len, 0);
-	free(hdr);
-
-	if (res < 0) {
-		perror("wired_send_eapol: send");
-		printf("wired_send_eapol - packet len: %lu - failed\n",
-		       (unsigned long) len);
-	}
-
-	return res;
-}
-
-
-static void * wired_driver_init(struct hostapd_data *hapd)
-{
-	struct wired_driver_data *drv;
-
-	drv = os_zalloc(sizeof(struct wired_driver_data));
-	if (drv == NULL) {
-		printf("Could not allocate memory for wired driver data\n");
-		return NULL;
-	}
-
-	drv->hapd = hapd;
-	os_strlcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
-	drv->use_pae_group_addr = hapd->conf->use_pae_group_addr;
-
-	if (wired_init_sockets(drv)) {
-		free(drv);
-		return NULL;
-	}
-
-	return drv;
-}
-
-
-static void wired_driver_deinit(void *priv)
-{
-	struct wired_driver_data *drv = priv;
-
-	if (drv->sock >= 0)
-		close(drv->sock);
-	
-	if (drv->dhcp_sock >= 0)
-		close(drv->dhcp_sock);
-
-	free(drv);
-}
-
-
-const struct hapd_driver_ops wpa_driver_wired_ops = {
-	.name = "wired",
-	.init = wired_driver_init,
-	.deinit = wired_driver_deinit,
-	.send_eapol = wired_send_eapol,
-};

+ 0 - 77
hostapd/drivers.c

@@ -1,77 +0,0 @@
-/*
- * hostapd / driver interface list
- * Copyright (c) 2007, 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 "includes.h"
-
-
-#ifdef CONFIG_DRIVER_HOSTAP
-extern struct hapd_driver_ops wpa_driver_hostap_ops; /* driver_hostap.c */
-#endif /* CONFIG_DRIVER_HOSTAP */
-#ifdef CONFIG_DRIVER_NL80211
-extern struct hapd_driver_ops wpa_driver_nl80211_ops; /* driver_nl80211.c */
-#endif /* CONFIG_DRIVER_NL80211 */
-#ifdef CONFIG_DRIVER_PRISM54
-extern struct hapd_driver_ops wpa_driver_prism54_ops; /* driver_prism54.c */
-#endif /* CONFIG_DRIVER_PRISM54 */
-#ifdef CONFIG_DRIVER_MADWIFI
-extern struct hapd_driver_ops wpa_driver_madwifi_ops; /* driver_madwifi.c */
-#endif /* CONFIG_DRIVER_MADWIFI */
-#ifdef CONFIG_DRIVER_ATHEROS
-extern struct hapd_driver_ops wpa_driver_atheros_ops; /* driver_atheros.c */
-#endif /* CONFIG_DRIVER_ATHEROS */
-#ifdef CONFIG_DRIVER_BSD
-extern struct hapd_driver_ops wpa_driver_bsd_ops; /* driver_bsd.c */
-#endif /* CONFIG_DRIVER_BSD */
-#ifdef CONFIG_DRIVER_WIRED
-extern struct hapd_driver_ops wpa_driver_wired_ops; /* driver_wired.c */
-#endif /* CONFIG_DRIVER_WIRED */
-#ifdef CONFIG_DRIVER_TEST
-extern struct hapd_driver_ops wpa_driver_test_ops; /* driver_test.c */
-#endif /* CONFIG_DRIVER_TEST */
-#ifdef CONFIG_DRIVER_NONE
-extern struct hapd_driver_ops wpa_driver_none_ops; /* driver_none.c */
-#endif /* CONFIG_DRIVER_NONE */
-
-
-struct hapd_driver_ops *hostapd_drivers[] =
-{
-#ifdef CONFIG_DRIVER_HOSTAP
-	&wpa_driver_hostap_ops,
-#endif /* CONFIG_DRIVER_HOSTAP */
-#ifdef CONFIG_DRIVER_NL80211
-	&wpa_driver_nl80211_ops,
-#endif /* CONFIG_DRIVER_NL80211 */
-#ifdef CONFIG_DRIVER_PRISM54
-	&wpa_driver_prism54_ops,
-#endif /* CONFIG_DRIVER_PRISM54 */
-#ifdef CONFIG_DRIVER_MADWIFI
-	&wpa_driver_madwifi_ops,
-#endif /* CONFIG_DRIVER_MADWIFI */
-#ifdef CONFIG_DRIVER_ATHEROS
-	&wpa_driver_atheros_ops,
-#endif /* CONFIG_DRIVER_ATHEROS */
-#ifdef CONFIG_DRIVER_BSD
-	&wpa_driver_bsd_ops,
-#endif /* CONFIG_DRIVER_BSD */
-#ifdef CONFIG_DRIVER_WIRED
-	&wpa_driver_wired_ops,
-#endif /* CONFIG_DRIVER_WIRED */
-#ifdef CONFIG_DRIVER_TEST
-	&wpa_driver_test_ops,
-#endif /* CONFIG_DRIVER_TEST */
-#ifdef CONFIG_DRIVER_NONE
-	&wpa_driver_none_ops,
-#endif /* CONFIG_DRIVER_NONE */
-	NULL
-};

+ 0 - 216
hostapd/hostap_common.h

@@ -1,216 +0,0 @@
-/*
- * hostapd / Kernel driver communication with Linux Host AP driver
- * Copyright (c) 2002-2006, 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.
- */
-
-#ifndef HOSTAP_COMMON_H
-#define HOSTAP_COMMON_H
-
-/* netdevice private ioctls (used, e.g., with iwpriv from user space) */
-
-/* New wireless extensions API - SET/GET convention (even ioctl numbers are
- * root only)
- */
-#define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
-#define PRISM2_IOCTL_GET_PRISM2_PARAM (SIOCIWFIRSTPRIV + 1)
-#define PRISM2_IOCTL_WRITEMIF (SIOCIWFIRSTPRIV + 2)
-#define PRISM2_IOCTL_READMIF (SIOCIWFIRSTPRIV + 3)
-#define PRISM2_IOCTL_MONITOR (SIOCIWFIRSTPRIV + 4)
-#define PRISM2_IOCTL_RESET (SIOCIWFIRSTPRIV + 6)
-#define PRISM2_IOCTL_INQUIRE (SIOCIWFIRSTPRIV + 8)
-#define PRISM2_IOCTL_WDS_ADD (SIOCIWFIRSTPRIV + 10)
-#define PRISM2_IOCTL_WDS_DEL (SIOCIWFIRSTPRIV + 12)
-#define PRISM2_IOCTL_SET_RID_WORD (SIOCIWFIRSTPRIV + 14)
-#define PRISM2_IOCTL_MACCMD (SIOCIWFIRSTPRIV + 16)
-#define PRISM2_IOCTL_ADDMAC (SIOCIWFIRSTPRIV + 18)
-#define PRISM2_IOCTL_DELMAC (SIOCIWFIRSTPRIV + 20)
-#define PRISM2_IOCTL_KICKMAC (SIOCIWFIRSTPRIV + 22)
-
-/* following are not in SIOCGIWPRIV list; check permission in the driver code
- */
-#define PRISM2_IOCTL_DOWNLOAD (SIOCDEVPRIVATE + 13)
-#define PRISM2_IOCTL_HOSTAPD (SIOCDEVPRIVATE + 14)
-
-
-/* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
-enum {
-	/* PRISM2_PARAM_PTYPE = 1, */ /* REMOVED 2003-10-22 */
-	PRISM2_PARAM_TXRATECTRL = 2,
-	PRISM2_PARAM_BEACON_INT = 3,
-	PRISM2_PARAM_PSEUDO_IBSS = 4,
-	PRISM2_PARAM_ALC = 5,
-	/* PRISM2_PARAM_TXPOWER = 6, */ /* REMOVED 2003-10-22 */
-	PRISM2_PARAM_DUMP = 7,
-	PRISM2_PARAM_OTHER_AP_POLICY = 8,
-	PRISM2_PARAM_AP_MAX_INACTIVITY = 9,
-	PRISM2_PARAM_AP_BRIDGE_PACKETS = 10,
-	PRISM2_PARAM_DTIM_PERIOD = 11,
-	PRISM2_PARAM_AP_NULLFUNC_ACK = 12,
-	PRISM2_PARAM_MAX_WDS = 13,
-	PRISM2_PARAM_AP_AUTOM_AP_WDS = 14,
-	PRISM2_PARAM_AP_AUTH_ALGS = 15,
-	PRISM2_PARAM_MONITOR_ALLOW_FCSERR = 16,
-	PRISM2_PARAM_HOST_ENCRYPT = 17,
-	PRISM2_PARAM_HOST_DECRYPT = 18,
-	PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX = 19,
-	PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX = 20,
-	PRISM2_PARAM_HOST_ROAMING = 21,
-	PRISM2_PARAM_BCRX_STA_KEY = 22,
-	PRISM2_PARAM_IEEE_802_1X = 23,
-	PRISM2_PARAM_ANTSEL_TX = 24,
-	PRISM2_PARAM_ANTSEL_RX = 25,
-	PRISM2_PARAM_MONITOR_TYPE = 26,
-	PRISM2_PARAM_WDS_TYPE = 27,
-	PRISM2_PARAM_HOSTSCAN = 28,
-	PRISM2_PARAM_AP_SCAN = 29,
-	PRISM2_PARAM_ENH_SEC = 30,
-	PRISM2_PARAM_IO_DEBUG = 31,
-	PRISM2_PARAM_BASIC_RATES = 32,
-	PRISM2_PARAM_OPER_RATES = 33,
-	PRISM2_PARAM_HOSTAPD = 34,
-	PRISM2_PARAM_HOSTAPD_STA = 35,
-	PRISM2_PARAM_WPA = 36,
-	PRISM2_PARAM_PRIVACY_INVOKED = 37,
-	PRISM2_PARAM_TKIP_COUNTERMEASURES = 38,
-	PRISM2_PARAM_DROP_UNENCRYPTED = 39,
-	PRISM2_PARAM_SCAN_CHANNEL_MASK = 40,
-};
-
-enum { HOSTAP_ANTSEL_DO_NOT_TOUCH = 0, HOSTAP_ANTSEL_DIVERSITY = 1,
-       HOSTAP_ANTSEL_LOW = 2, HOSTAP_ANTSEL_HIGH = 3 };
-
-
-/* PRISM2_IOCTL_MACCMD ioctl() subcommands: */
-enum { AP_MAC_CMD_POLICY_OPEN = 0, AP_MAC_CMD_POLICY_ALLOW = 1,
-       AP_MAC_CMD_POLICY_DENY = 2, AP_MAC_CMD_FLUSH = 3,
-       AP_MAC_CMD_KICKALL = 4 };
-
-
-/* PRISM2_IOCTL_DOWNLOAD ioctl() dl_cmd: */
-enum {
-	PRISM2_DOWNLOAD_VOLATILE = 1 /* RAM */,
-	/* Note! Old versions of prism2_srec have a fatal error in CRC-16
-	 * calculation, which will corrupt all non-volatile downloads.
-	 * PRISM2_DOWNLOAD_NON_VOLATILE used to be 2, but it is now 3 to
-	 * prevent use of old versions of prism2_srec for non-volatile
-	 * download. */
-	PRISM2_DOWNLOAD_NON_VOLATILE = 3 /* FLASH */,
-	PRISM2_DOWNLOAD_VOLATILE_GENESIS = 4 /* RAM in Genesis mode */,
-	/* Persistent versions of volatile download commands (keep firmware
-	 * data in memory and automatically re-download after hw_reset */
-	PRISM2_DOWNLOAD_VOLATILE_PERSISTENT = 5,
-	PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT = 6,
-};
-
-struct prism2_download_param {
-	u32 dl_cmd;
-	u32 start_addr;
-	u32 num_areas;
-	struct prism2_download_area {
-		u32 addr; /* wlan card address */
-		u32 len;
-		caddr_t ptr; /* pointer to data in user space */
-	} data[0];
-};
-
-#define PRISM2_MAX_DOWNLOAD_AREA_LEN 131072
-#define PRISM2_MAX_DOWNLOAD_LEN 262144
-
-
-/* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
-enum {
-	PRISM2_HOSTAPD_FLUSH = 1,
-	PRISM2_HOSTAPD_ADD_STA = 2,
-	PRISM2_HOSTAPD_REMOVE_STA = 3,
-	PRISM2_HOSTAPD_GET_INFO_STA = 4,
-	/* REMOVED: PRISM2_HOSTAPD_RESET_TXEXC_STA = 5, */
-	PRISM2_SET_ENCRYPTION = 6,
-	PRISM2_GET_ENCRYPTION = 7,
-	PRISM2_HOSTAPD_SET_FLAGS_STA = 8,
-	PRISM2_HOSTAPD_GET_RID = 9,
-	PRISM2_HOSTAPD_SET_RID = 10,
-	PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR = 11,
-	PRISM2_HOSTAPD_SET_GENERIC_ELEMENT = 12,
-	PRISM2_HOSTAPD_MLME = 13,
-	PRISM2_HOSTAPD_SCAN_REQ = 14,
-	PRISM2_HOSTAPD_STA_CLEAR_STATS = 15,
-};
-
-#define PRISM2_HOSTAPD_MAX_BUF_SIZE 1024
-#define PRISM2_HOSTAPD_RID_HDR_LEN \
-((size_t) (&((struct prism2_hostapd_param *) 0)->u.rid.data))
-#define PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN \
-((size_t) (&((struct prism2_hostapd_param *) 0)->u.generic_elem.data))
-
-/* Maximum length for algorithm names (-1 for nul termination) used in ioctl()
- */
-#define HOSTAP_CRYPT_ALG_NAME_LEN 16
-
-
-struct prism2_hostapd_param {
-	u32 cmd;
-	u8 sta_addr[ETH_ALEN];
-	union {
-		struct {
-			u16 aid;
-			u16 capability;
-			u8 tx_supp_rates;
-		} add_sta;
-		struct {
-			u32 inactive_sec;
-		} get_info_sta;
-		struct {
-			u8 alg[HOSTAP_CRYPT_ALG_NAME_LEN];
-			u32 flags;
-			u32 err;
-			u8 idx;
-			u8 seq[8]; /* sequence counter (set: RX, get: TX) */
-			u16 key_len;
-			u8 key[0];
-		} crypt;
-		struct {
-			u32 flags_and;
-			u32 flags_or;
-		} set_flags_sta;
-		struct {
-			u16 rid;
-			u16 len;
-			u8 data[0];
-		} rid;
-		struct {
-			u8 len;
-			u8 data[0];
-		} generic_elem;
-		struct {
-#define MLME_STA_DEAUTH 0
-#define MLME_STA_DISASSOC 1
-			u16 cmd;
-			u16 reason_code;
-		} mlme;
-		struct {
-			u8 ssid_len;
-			u8 ssid[32];
-		} scan_req;
-	} u;
-};
-
-#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
-#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
-
-#define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
-#define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3
-#define HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED 4
-#define HOSTAP_CRYPT_ERR_KEY_SET_FAILED 5
-#define HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED 6
-#define HOSTAP_CRYPT_ERR_CARD_CONF_FAILED 7
-
-#endif /* HOSTAP_COMMON_H */

+ 2 - 2
hostapd/hostapd.h

@@ -20,7 +20,7 @@
 #include "common.h"
 #include "hostapd_defs.h"
 
-struct hapd_driver_ops;
+struct wpa_driver_ops;
 struct wpa_ctrl_dst;
 struct radius_server_data;
 struct upnp_wps_device_sm;
@@ -54,7 +54,7 @@ struct hostapd_data {
 #define AID_WORDS ((2008 + 31) / 32)
 	u32 sta_aid[AID_WORDS];
 
-	const struct hapd_driver_ops *driver;
+	const struct wpa_driver_ops *driver;
 	void *drv_priv;
 
 	u8 *default_wep_key;

+ 0 - 71
hostapd/priv_netlink.h

@@ -1,71 +0,0 @@
-#ifndef PRIV_NETLINK_H
-#define PRIV_NETLINK_H
-
-/* Private copy of needed Linux netlink/rtnetlink definitions.
- *
- * This should be replaced with user space header once one is available with C
- * library, etc..
- */
-
-#ifndef IFLA_IFNAME
-#define IFLA_IFNAME 3
-#endif
-#ifndef IFLA_WIRELESS
-#define IFLA_WIRELESS 11
-#endif
-
-#define NETLINK_ROUTE 0
-#define RTMGRP_LINK 1
-#define RTM_BASE 0x10
-#define RTM_NEWLINK (RTM_BASE + 0)
-#define RTM_DELLINK (RTM_BASE + 1)
-
-#define NLMSG_ALIGNTO 4
-#define NLMSG_ALIGN(len) (((len) + NLMSG_ALIGNTO - 1) & ~(NLMSG_ALIGNTO - 1))
-#define NLMSG_LENGTH(len) ((len) + NLMSG_ALIGN(sizeof(struct nlmsghdr)))
-#define NLMSG_DATA(nlh) ((void*) (((char*) nlh) + NLMSG_LENGTH(0)))
-
-#define RTA_ALIGNTO 4
-#define RTA_ALIGN(len) (((len) + RTA_ALIGNTO - 1) & ~(RTA_ALIGNTO - 1))
-#define RTA_OK(rta,len) \
-((len) > 0 && (rta)->rta_len >= sizeof(struct rtattr) && \
-(rta)->rta_len <= (len))
-#define RTA_NEXT(rta,attrlen) \
-((attrlen) -= RTA_ALIGN((rta)->rta_len), \
-(struct rtattr *) (((char *)(rta)) + RTA_ALIGN((rta)->rta_len)))
-
-
-struct sockaddr_nl
-{
-	sa_family_t nl_family;
-	unsigned short nl_pad;
-	u32 nl_pid;
-	u32 nl_groups;
-};
-
-struct nlmsghdr
-{
-	u32 nlmsg_len;
-	u16 nlmsg_type;
-	u16 nlmsg_flags;
-	u32 nlmsg_seq;
-	u32 nlmsg_pid;
-};
-
-struct ifinfomsg
-{
-	unsigned char ifi_family;
-	unsigned char __ifi_pad;
-	unsigned short ifi_type;
-	int ifi_index;
-	unsigned ifi_flags;
-	unsigned ifi_change;
-};
-
-struct rtattr
-{
-	unsigned short rta_len;
-	unsigned short rta_type;
-};
-
-#endif /* PRIV_NETLINK_H */

+ 4 - 0
hostapd/sta_info.c

@@ -171,8 +171,10 @@ void ap_free_sta(struct hostapd_data *hapd, struct sta_info *sta)
 		hapd->iface->num_sta_ht_20mhz--;
 	}
 
+#ifdef NEED_MLME
 	if (hostapd_ht_operation_update(hapd->iface) > 0)
 		set_beacon++;
+#endif /* NEED_MLME */
 #endif /* CONFIG_IEEE80211N */
 
 	if (set_beacon)
@@ -695,7 +697,9 @@ static void ap_sa_query_timer(void *eloop_ctx, void *timeout_ctx)
 		       HOSTAPD_LEVEL_DEBUG,
 		       "association SA Query attempt %d", sta->sa_query_count);
 
+#ifdef NEED_MLME
 	ieee802_11_send_sa_query_req(hapd, sta->addr, trans_id);
+#endif /* NEED_MLME */
 }
 
 

+ 1 - 1
hostapd/vlan_init.c

@@ -28,7 +28,7 @@
 #include <linux/if_vlan.h>
 #include <linux/if_bridge.h>
 
-#include "priv_netlink.h"
+#include "drivers/priv_netlink.h"
 #include "eloop.h"
 
 

+ 2 - 0
hostapd/wpa_ft.c

@@ -526,6 +526,7 @@ static u8 * wpa_ft_process_rdie(u8 *pos, u8 *end, u8 id, u8 descr_count,
 		return pos;
 	}
 
+#ifdef NEED_MLME
 	if (parse.wmm_tspec) {
 		struct wmm_tspec_element *tspec;
 		int res;
@@ -561,6 +562,7 @@ static u8 * wpa_ft_process_rdie(u8 *pos, u8 *end, u8 id, u8 descr_count,
 		}
 		return pos;
 	}
+#endif /* NEED_MLME */
 
 	wpa_printf(MSG_DEBUG, "FT: No supported resource requested");
 	rdie->status_code = host_to_le16(WLAN_STATUS_UNSPECIFIED_FAILURE);

+ 0 - 37
src/common/defs.h

@@ -213,34 +213,6 @@ enum mfp_options {
 	IEEE80211W_REQUIRED = 2
 };
 
-
-/* Hardware features */
-
-#define HOSTAPD_CHAN_DISABLED 0x00000001
-#define HOSTAPD_CHAN_PASSIVE_SCAN 0x00000002
-#define HOSTAPD_CHAN_NO_IBSS 0x00000004
-#define HOSTAPD_CHAN_RADAR 0x00000008
-
-struct hostapd_channel_data {
-	short chan; /* channel number (IEEE 802.11) */
-	short freq; /* frequency in MHz */
-	int flag; /* flag for hostapd use (HOSTAPD_CHAN_*) */
-	u8 max_tx_power; /* maximum transmit power in dBm */
-};
-
-#define HOSTAPD_RATE_ERP 0x00000001
-#define HOSTAPD_RATE_BASIC 0x00000002
-#define HOSTAPD_RATE_PREAMBLE2 0x00000004
-#define HOSTAPD_RATE_SUPPORTED 0x00000010
-#define HOSTAPD_RATE_OFDM 0x00000020
-#define HOSTAPD_RATE_CCK 0x00000040
-#define HOSTAPD_RATE_MANDATORY 0x00000100
-
-struct hostapd_rate_data {
-	int rate; /* rate in 100 kbps */
-	int flags; /* HOSTAPD_RATE_ flags */
-};
-
 typedef enum {
 	HOSTAPD_MODE_IEEE80211B,
 	HOSTAPD_MODE_IEEE80211G,
@@ -248,13 +220,4 @@ typedef enum {
 	NUM_HOSTAPD_MODES
 } hostapd_hw_mode;
 
-struct hostapd_hw_modes {
-	hostapd_hw_mode mode;
-	int num_channels;
-	struct hostapd_channel_data *channels;
-	int num_rates;
-	struct hostapd_rate_data *rates;
-	u16 ht_capab;
-};
-
 #endif /* DEFS_H */

+ 258 - 0
src/drivers/driver.h

@@ -19,6 +19,41 @@
 
 #include "defs.h"
 
+#define HOSTAPD_CHAN_DISABLED 0x00000001
+#define HOSTAPD_CHAN_PASSIVE_SCAN 0x00000002
+#define HOSTAPD_CHAN_NO_IBSS 0x00000004
+#define HOSTAPD_CHAN_RADAR 0x00000008
+
+struct hostapd_channel_data {
+	short chan; /* channel number (IEEE 802.11) */
+	short freq; /* frequency in MHz */
+	int flag; /* flag for hostapd use (HOSTAPD_CHAN_*) */
+	u8 max_tx_power; /* maximum transmit power in dBm */
+};
+
+#define HOSTAPD_RATE_ERP 0x00000001
+#define HOSTAPD_RATE_BASIC 0x00000002
+#define HOSTAPD_RATE_PREAMBLE2 0x00000004
+#define HOSTAPD_RATE_SUPPORTED 0x00000010
+#define HOSTAPD_RATE_OFDM 0x00000020
+#define HOSTAPD_RATE_CCK 0x00000040
+#define HOSTAPD_RATE_MANDATORY 0x00000100
+
+struct hostapd_rate_data {
+	int rate; /* rate in 100 kbps */
+	int flags; /* HOSTAPD_RATE_ flags */
+};
+
+struct hostapd_hw_modes {
+	hostapd_hw_mode mode;
+	int num_channels;
+	struct hostapd_channel_data *channels;
+	int num_rates;
+	struct hostapd_rate_data *rates;
+	u16 ht_capab;
+};
+
+
 #define AUTH_ALG_OPEN_SYSTEM	0x01
 #define AUTH_ALG_SHARED_KEY	0x02
 #define AUTH_ALG_LEAP		0x04
@@ -420,6 +455,54 @@ struct ieee80211_rx_status {
 };
 
 
+struct hostapd_data;
+
+struct hostap_sta_driver_data {
+	unsigned long rx_packets, tx_packets, rx_bytes, tx_bytes;
+	unsigned long current_tx_rate;
+	unsigned long inactive_msec;
+	unsigned long flags;
+	unsigned long num_ps_buf_frames;
+	unsigned long tx_retry_failed;
+	unsigned long tx_retry_count;
+	int last_rssi;
+	int last_ack_rssi;
+};
+
+struct hostapd_sta_add_params {
+	const u8 *addr;
+	u16 aid;
+	u16 capability;
+	const u8 *supp_rates;
+	size_t supp_rates_len;
+	int flags;
+	u16 listen_interval;
+	const struct ht_cap_ie *ht_capabilities;
+};
+
+struct hostapd_freq_params {
+	int mode;
+	int freq;
+	int channel;
+	int ht_enabled;
+	int sec_channel_offset; /* 0 = HT40 disabled, -1 = HT40 enabled,
+				 * secondary channel below primary, 1 = HT40
+				 * enabled, secondary channel above primary */
+};
+
+enum hostapd_driver_if_type {
+	HOSTAPD_IF_VLAN, HOSTAPD_IF_WDS
+};
+
+struct hostapd_neighbor_bss {
+	u8 bssid[ETH_ALEN];
+	int freq; /* MHz */
+	unsigned int ht:1;
+	int pri_chan;
+	int sec_chan; /* 0 for 20 MHz channels */
+};
+
+
 /**
  * struct wpa_driver_ops - Driver interface API definition
  *
@@ -1113,6 +1196,149 @@ struct wpa_driver_ops {
 			  const u8 *tail, size_t tail_len, int dtim_period);
 
 	int (*set_beacon_int)(void *priv, int value);
+
+	void * (*hapd_init)(struct hostapd_data *hapd);
+	void * (*init_bssid)(struct hostapd_data *hapd, const u8 *bssid);
+	void (*hapd_deinit)(void *priv);
+
+	/**
+	 * set_8021x - enable/disable IEEE 802.1X support
+	 * @ifname: Interface name (for multi-SSID/VLAN support)
+	 * @priv: driver private data
+	 * @enabled: 1 = enable, 0 = disable
+	 *
+	 * Returns: 0 on success, -1 on failure
+	 *
+	 * Configure the kernel driver to enable/disable 802.1X support.
+	 * This may be an empty function if 802.1X support is always enabled.
+	 */
+	int (*set_ieee8021x)(const char *ifname, void *priv, int enabled);
+
+	/**
+	 * set_privacy - enable/disable privacy
+	 * @priv: driver private data
+	 * @enabled: 1 = privacy enabled, 0 = disabled
+	 *
+	 * Return: 0 on success, -1 on failure
+	 *
+	 * Configure privacy.
+	 */
+	int (*set_privacy)(const char *ifname, void *priv, int enabled);
+
+	int (*hapd_set_key)(const char *ifname, void *priv, wpa_alg alg,
+			    const u8 *addr, int key_idx, int set_tx,
+			    const u8 *seq, size_t seq_len,
+			    const u8 *key, size_t key_len);
+	int (*get_seqnum)(const char *ifname, void *priv, const u8 *addr,
+			  int idx, u8 *seq);
+	int (*get_seqnum_igtk)(const char *ifname, void *priv, const u8 *addr,
+			       int idx, u8 *seq);
+	int (*flush)(void *priv);
+	int (*set_generic_elem)(const char *ifname, void *priv, const u8 *elem,
+				size_t elem_len);
+
+	int (*read_sta_data)(void *priv, struct hostap_sta_driver_data *data,
+			     const u8 *addr);
+	int (*hapd_send_eapol)(void *priv, const u8 *addr, const u8 *data,
+			       size_t data_len, int encrypt,
+			       const u8 *own_addr);
+	int (*sta_deauth)(void *priv, const u8 *addr, int reason);
+	int (*sta_disassoc)(void *priv, const u8 *addr, int reason);
+	int (*sta_remove)(void *priv, const u8 *addr);
+	int (*hapd_get_ssid)(const char *ifname, void *priv, u8 *buf, int len);
+	int (*hapd_set_ssid)(const char *ifname, void *priv, const u8 *buf,
+			     int len);
+	int (*hapd_set_countermeasures)(void *priv, int enabled);
+	int (*send_mgmt_frame)(void *priv, const void *msg, size_t len,
+			       int flags);
+	int (*sta_add)(const char *ifname, void *priv,
+		       struct hostapd_sta_add_params *params);
+	int (*get_inact_sec)(void *priv, const u8 *addr);
+	int (*sta_clear_stats)(void *priv, const u8 *addr);
+
+	int (*set_freq)(void *priv, struct hostapd_freq_params *freq);
+	int (*set_rts)(void *priv, int rts);
+	int (*set_frag)(void *priv, int frag);
+	int (*set_retry)(void *priv, int short_retry, int long_retry);
+
+	int (*sta_set_flags)(void *priv, const u8 *addr,
+			     int total_flags, int flags_or, int flags_and);
+	int (*set_rate_sets)(void *priv, int *supp_rates, int *basic_rates,
+			     int mode);
+	int (*hapd_set_country)(void *priv, const char *country);
+	int (*set_ieee80211d)(void *priv, int enabled);
+	int (*hapd_set_beacon)(const char *ifname, void *priv,
+			       const u8 *head, size_t head_len,
+			       const u8 *tail, size_t tail_len,
+			       int dtim_period);
+
+	/* Configure internal bridge:
+	 * 0 = disabled, i.e., client separation is enabled (no bridging of
+	 *     packets between associated STAs
+	 * 1 = enabled, i.e., bridge packets between associated STAs (default)
+	 */
+	int (*set_internal_bridge)(void *priv, int value);
+	int (*hapd_set_beacon_int)(void *priv, int value);
+	/* Configure broadcast SSID mode:
+	 * 0 = include SSID in Beacon frames and reply to Probe Request frames
+	 *     that use broadcast SSID
+	 * 1 = hide SSID from Beacon frames and ignore Probe Request frames for
+	 *     broadcast SSID
+	 */
+	int (*set_broadcast_ssid)(void *priv, int value);
+	int (*set_cts_protect)(void *priv, int value);
+	int (*set_preamble)(void *priv, int value);
+	int (*set_short_slot_time)(void *priv, int value);
+	int (*set_tx_queue_params)(void *priv, int queue, int aifs, int cw_min,
+				   int cw_max, int burst_time);
+	int (*bss_add)(void *priv, const char *ifname, const u8 *bssid);
+	int (*bss_remove)(void *priv, const char *ifname);
+	int (*valid_bss_mask)(void *priv, const u8 *addr, const u8 *mask);
+	int (*passive_scan)(void *priv, int now, int our_mode_only,
+			    int interval, int _listen, int *channel,
+			    int *last_rx);
+	struct hostapd_hw_modes * (*hapd_get_hw_feature_data)(void *priv,
+							      u16 *num_modes,
+							      u16 *flags);
+	int (*if_add)(const char *iface, void *priv,
+		      enum hostapd_driver_if_type type, char *ifname,
+		      const u8 *addr);
+	int (*if_update)(void *priv, enum hostapd_driver_if_type type,
+			 char *ifname, const u8 *addr);
+	int (*if_remove)(void *priv, enum hostapd_driver_if_type type,
+			 const char *ifname, const u8 *addr);
+	int (*set_sta_vlan)(void *priv, const u8 *addr, const char *ifname,
+			    int vlan_id);
+	/**
+	 * commit - Optional commit changes handler
+	 * @priv: driver private data
+	 * Returns: 0 on success, -1 on failure
+	 *
+	 * This optional handler function can be registered if the driver
+	 * interface implementation needs to commit changes (e.g., by setting
+	 * network interface up) at the end of initial configuration. If set,
+	 * this handler will be called after initial setup has been completed.
+	 */
+	int (*commit)(void *priv);
+
+	int (*send_ether)(void *priv, const u8 *dst, const u8 *src, u16 proto,
+			  const u8 *data, size_t data_len);
+
+	int (*set_radius_acl_auth)(void *priv, const u8 *mac, int accepted, 
+				   u32 session_timeout);
+	int (*set_radius_acl_expire)(void *priv, const u8 *mac);
+
+	int (*set_ht_params)(const char *ifname, void *priv,
+			     const u8 *ht_capab, size_t ht_capab_len,
+			     const u8 *ht_oper, size_t ht_oper_len);
+
+	int (*set_wps_beacon_ie)(const char *ifname, void *priv,
+				 const u8 *ie, size_t len);
+	int (*set_wps_probe_resp_ie)(const char *ifname, void *priv,
+				     const u8 *ie, size_t len);
+
+	const struct hostapd_neighbor_bss *
+	(*get_neighbor_bss)(void *priv, size_t *num);
 };
 
 /**
@@ -1502,4 +1728,36 @@ int wpa_scan_get_max_rate(const struct wpa_scan_res *res);
 void wpa_scan_results_free(struct wpa_scan_results *res);
 void wpa_scan_sort_results(struct wpa_scan_results *res);
 
+/* hostapd functions for driver wrappers */
+
+struct sta_info;
+
+void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
+			   int reassoc);
+void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr,
+		       const u8 *buf, size_t len, int ack);
+void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd, const u8 *addr);
+int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
+			const u8 *ie, size_t ielen);
+void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr);
+void hostapd_eapol_receive(struct hostapd_data *hapd, const u8 *sa,
+			   const u8 *buf, size_t len);
+
+struct hostapd_frame_info {
+	u32 phytype;
+	u32 channel;
+	u32 datarate;
+	u32 ssi_signal;
+
+	unsigned int passive_scan:1;
+};
+
+void hostapd_mgmt_rx(struct hostapd_data *hapd, u8 *buf, size_t len,
+		     u16 stype, struct hostapd_frame_info *fi);
+void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, u8 *buf, size_t len,
+			u16 stype, int ok);
+void hostapd_michael_mic_failure(struct hostapd_data *hapd, const u8 *addr);
+struct hostapd_data * hostapd_sta_get_bss(struct hostapd_data *hapd,
+					  const u8 *addr);
+
 #endif /* DRIVER_H */

+ 10 - 9
hostapd/driver_atheros.c → src/drivers/driver_atheros.c

@@ -58,14 +58,15 @@
 
 #include "wireless_copy.h"
 
-#include "hostapd.h"
-#include "config.h"
+#include "../hostapd/hostapd.h"
+#include "../hostapd/config.h"
+#include "../hostapd/sta_flags.h"
 #include "driver.h"
 #include "eloop.h"
 #include "priv_netlink.h"
 #include "l2_packet/l2_packet.h"
 
-#include "wps_hostapd.h"
+#include "../hostapd/wps_hostapd.h"
 #include "ieee802_11_defs.h"
 
 
@@ -1315,23 +1316,23 @@ madwifi_commit(void *priv)
 	return madwifi_set_iface_flags(priv, 1);
 }
 
-const struct hapd_driver_ops wpa_driver_atheros_ops = {
+const struct wpa_driver_ops wpa_driver_atheros_ops = {
 	.name			= "atheros",
-	.init			= madwifi_init,
+	.hapd_init		= madwifi_init,
 	.deinit			= madwifi_deinit,
 	.set_ieee8021x		= madwifi_set_ieee8021x,
 	.set_privacy		= madwifi_set_privacy,
-	.set_key		= madwifi_set_key,
+	.hapd_set_key		= madwifi_set_key,
 	.get_seqnum		= madwifi_get_seqnum,
 	.flush			= madwifi_flush,
 	.set_generic_elem	= madwifi_set_opt_ie,
 	.sta_set_flags		= madwifi_sta_set_flags,
 	.read_sta_data		= madwifi_read_sta_driver_data,
-	.send_eapol		= madwifi_send_eapol,
+	.hapd_send_eapol	= madwifi_send_eapol,
 	.sta_disassoc		= madwifi_sta_disassoc,
 	.sta_deauth		= madwifi_sta_deauth,
-	.set_ssid		= madwifi_set_ssid,
-	.get_ssid		= madwifi_get_ssid,
+	.hapd_set_ssid		= madwifi_set_ssid,
+	.hapd_get_ssid		= madwifi_get_ssid,
 	.set_countermeasures	= madwifi_set_countermeasures,
 	.sta_clear_stats	= madwifi_sta_clear_stats,
 	.commit			= madwifi_commit,

+ 749 - 0
src/drivers/driver_bsd.c

@@ -1,6 +1,7 @@
 /*
  * WPA Supplicant - driver interaction with BSD net80211 layer
  * Copyright (c) 2004, Sam Leffler <sam@errno.com>
+ * Copyright (c) 2004, 2Wire, Inc
  *
  * 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
@@ -33,6 +34,752 @@
 #include <net80211/ieee80211_crypto.h>
 #include <net80211/ieee80211_ioctl.h>
 
+/*
+ * Avoid conflicts with hostapd definitions by undefining couple of defines
+ * from net80211 header files.
+ */
+#undef RSN_VERSION
+#undef WPA_VERSION
+#undef WPA_OUI_TYPE
+
+
+#ifdef HOSTAPD
+
+#include "l2_packet/l2_packet.h"
+#include "../../hostapd/hostapd.h"
+#include "../../hostapd/config.h"
+#include "../../hostapd/eapol_sm.h"
+
+struct bsd_driver_data {
+	struct hostapd_data *hapd;		/* back pointer */
+
+	char	iface[IFNAMSIZ + 1];
+	struct l2_packet_data *sock_xmit;	/* raw packet xmit socket */
+	int	ioctl_sock;			/* socket for ioctl() use */
+	int	wext_sock;			/* socket for wireless events */
+};
+
+static int bsd_sta_deauth(void *priv, const u8 *addr, int reason_code);
+
+static int
+set80211var(struct bsd_driver_data *drv, int op, const void *arg, int arg_len)
+{
+	struct ieee80211req ireq;
+
+	memset(&ireq, 0, sizeof(ireq));
+	os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
+	ireq.i_type = op;
+	ireq.i_len = arg_len;
+	ireq.i_data = (void *) arg;
+
+	if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
+		perror("ioctl[SIOCS80211]");
+		return -1;
+	}
+	return 0;
+}
+
+static int
+get80211var(struct bsd_driver_data *drv, int op, void *arg, int arg_len)
+{
+	struct ieee80211req ireq;
+
+	memset(&ireq, 0, sizeof(ireq));
+	os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
+	ireq.i_type = op;
+	ireq.i_len = arg_len;
+	ireq.i_data = arg;
+
+	if (ioctl(drv->ioctl_sock, SIOCG80211, &ireq) < 0) {
+		perror("ioctl[SIOCG80211]");
+		return -1;
+	}
+	return ireq.i_len;
+}
+
+static int
+set80211param(struct bsd_driver_data *drv, int op, int arg)
+{
+	struct ieee80211req ireq;
+
+	memset(&ireq, 0, sizeof(ireq));
+	os_strlcpy(ireq.i_name, drv->iface, IFNAMSIZ);
+	ireq.i_type = op;
+	ireq.i_val = arg;
+
+	if (ioctl(drv->ioctl_sock, SIOCS80211, &ireq) < 0) {
+		perror("ioctl[SIOCS80211]");
+		return -1;
+	}
+	return 0;
+}
+
+static const char *
+ether_sprintf(const u8 *addr)
+{
+	static char buf[sizeof(MACSTR)];
+
+	if (addr != NULL)
+		snprintf(buf, sizeof(buf), MACSTR, MAC2STR(addr));
+	else
+		snprintf(buf, sizeof(buf), MACSTR, 0,0,0,0,0,0);
+	return buf;
+}
+
+/*
+ * Configure WPA parameters.
+ */
+static int
+bsd_configure_wpa(struct bsd_driver_data *drv)
+{
+	static const char *ciphernames[] =
+		{ "WEP", "TKIP", "AES-OCB", "AES-CCM", "CKIP", "NONE" };
+	struct hostapd_data *hapd = drv->hapd;
+	struct hostapd_bss_config *conf = hapd->conf;
+	int v;
+
+	switch (conf->wpa_group) {
+	case WPA_CIPHER_CCMP:
+		v = IEEE80211_CIPHER_AES_CCM;
+		break;
+	case WPA_CIPHER_TKIP:
+		v = IEEE80211_CIPHER_TKIP;
+		break;
+	case WPA_CIPHER_WEP104:
+		v = IEEE80211_CIPHER_WEP;
+		break;
+	case WPA_CIPHER_WEP40:
+		v = IEEE80211_CIPHER_WEP;
+		break;
+	case WPA_CIPHER_NONE:
+		v = IEEE80211_CIPHER_NONE;
+		break;
+	default:
+		printf("Unknown group key cipher %u\n",
+			conf->wpa_group);
+		return -1;
+	}
+	wpa_printf(MSG_DEBUG, "%s: group key cipher=%s (%u)",
+		   __func__, ciphernames[v], v);
+	if (set80211param(drv, IEEE80211_IOC_MCASTCIPHER, v)) {
+		printf("Unable to set group key cipher to %u (%s)\n",
+			v, ciphernames[v]);
+		return -1;
+	}
+	if (v == IEEE80211_CIPHER_WEP) {
+		/* key length is done only for specific ciphers */
+		v = (conf->wpa_group == WPA_CIPHER_WEP104 ? 13 : 5);
+		if (set80211param(drv, IEEE80211_IOC_MCASTKEYLEN, v)) {
+			printf("Unable to set group key length to %u\n", v);
+			return -1;
+		}
+	}
+
+	v = 0;
+	if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
+		v |= 1<<IEEE80211_CIPHER_AES_CCM;
+	if (conf->wpa_pairwise & WPA_CIPHER_TKIP)
+		v |= 1<<IEEE80211_CIPHER_TKIP;
+	if (conf->wpa_pairwise & WPA_CIPHER_NONE)
+		v |= 1<<IEEE80211_CIPHER_NONE;
+	wpa_printf(MSG_DEBUG, "%s: pairwise key ciphers=0x%x", __func__, v);
+	if (set80211param(drv, IEEE80211_IOC_UCASTCIPHERS, v)) {
+		printf("Unable to set pairwise key ciphers to 0x%x\n", v);
+		return -1;
+	}
+
+	wpa_printf(MSG_DEBUG, "%s: key management algorithms=0x%x",
+		   __func__, conf->wpa_key_mgmt);
+	if (set80211param(drv, IEEE80211_IOC_KEYMGTALGS, conf->wpa_key_mgmt)) {
+		printf("Unable to set key management algorithms to 0x%x\n",
+			conf->wpa_key_mgmt);
+		return -1;
+	}
+
+	v = 0;
+	if (conf->rsn_preauth)
+		v |= BIT(0);
+	wpa_printf(MSG_DEBUG, "%s: rsn capabilities=0x%x",
+		   __func__, conf->rsn_preauth);
+	if (set80211param(drv, IEEE80211_IOC_RSNCAPS, v)) {
+		printf("Unable to set RSN capabilities to 0x%x\n", v);
+		return -1;
+	}
+
+	wpa_printf(MSG_DEBUG, "%s: enable WPA= 0x%x", __func__, conf->wpa);
+	if (set80211param(drv, IEEE80211_IOC_WPA, conf->wpa)) {
+		printf("Unable to set WPA to %u\n", conf->wpa);
+		return -1;
+	}
+	return 0;
+}
+
+
+static int
+bsd_set_iface_flags(void *priv, int dev_up)
+{
+	struct bsd_driver_data *drv = priv;
+	struct ifreq ifr;
+
+	wpa_printf(MSG_DEBUG, "%s: dev_up=%d", __func__, dev_up);
+
+	if (drv->ioctl_sock < 0)
+		return -1;
+
+	memset(&ifr, 0, sizeof(ifr));
+	os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
+
+	if (ioctl(drv->ioctl_sock, SIOCGIFFLAGS, &ifr) != 0) {
+		perror("ioctl[SIOCGIFFLAGS]");
+		return -1;
+	}
+
+	if (dev_up)
+		ifr.ifr_flags |= IFF_UP;
+	else
+		ifr.ifr_flags &= ~IFF_UP;
+
+	if (ioctl(drv->ioctl_sock, SIOCSIFFLAGS, &ifr) != 0) {
+		perror("ioctl[SIOCSIFFLAGS]");
+		return -1;
+	}
+
+	if (dev_up) {
+		memset(&ifr, 0, sizeof(ifr));
+		os_strlcpy(ifr.ifr_name, drv->iface, IFNAMSIZ);
+		ifr.ifr_mtu = HOSTAPD_MTU;
+		if (ioctl(drv->ioctl_sock, SIOCSIFMTU, &ifr) != 0) {
+			perror("ioctl[SIOCSIFMTU]");
+			printf("Setting MTU failed - trying to survive with "
+			       "current value\n");
+		}
+	}
+
+	return 0;
+}
+
+static int
+bsd_set_ieee8021x(const char *ifname, void *priv, int enabled)
+{
+	struct bsd_driver_data *drv = priv;
+	struct hostapd_data *hapd = drv->hapd;
+	struct hostapd_bss_config *conf = hapd->conf;
+
+	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
+
+	if (!enabled) {
+		/* XXX restore state */
+		return set80211param(priv, IEEE80211_IOC_AUTHMODE,
+			IEEE80211_AUTH_AUTO);
+	}
+	if (!conf->wpa && !conf->ieee802_1x) {
+		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
+			HOSTAPD_LEVEL_WARNING, "No 802.1X or WPA enabled!");
+		return -1;
+	}
+	if (conf->wpa && bsd_configure_wpa(drv) != 0) {
+		hostapd_logger(hapd, NULL, HOSTAPD_MODULE_DRIVER,
+			HOSTAPD_LEVEL_WARNING, "Error configuring WPA state!");
+		return -1;
+	}
+	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!");
+		return -1;
+	}
+	return bsd_set_iface_flags(priv, 1);
+}
+
+static int
+bsd_set_privacy(const char *ifname, void *priv, int enabled)
+{
+	struct bsd_driver_data *drv = priv;
+
+	wpa_printf(MSG_DEBUG, "%s: enabled=%d", __func__, enabled);
+
+	return set80211param(drv, IEEE80211_IOC_PRIVACY, enabled);
+}
+
+static int
+bsd_set_sta_authorized(void *priv, const u8 *addr, int authorized)
+{
+	struct bsd_driver_data *drv = priv;
+	struct ieee80211req_mlme mlme;
+
+	wpa_printf(MSG_DEBUG, "%s: addr=%s authorized=%d",
+		   __func__, ether_sprintf(addr), authorized);
+
+	if (authorized)
+		mlme.im_op = IEEE80211_MLME_AUTHORIZE;
+	else
+		mlme.im_op = IEEE80211_MLME_UNAUTHORIZE;
+	mlme.im_reason = 0;
+	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
+}
+
+static int
+bsd_sta_set_flags(void *priv, const u8 *addr, int total_flags, int flags_or,
+		  int flags_and)
+{
+	/* For now, only support setting Authorized flag */
+	if (flags_or & WLAN_STA_AUTHORIZED)
+		return bsd_set_sta_authorized(priv, addr, 1);
+	if (!(flags_and & WLAN_STA_AUTHORIZED))
+		return bsd_set_sta_authorized(priv, addr, 0);
+	return 0;
+}
+
+static int
+bsd_del_key(void *priv, const u8 *addr, int key_idx)
+{
+	struct bsd_driver_data *drv = priv;
+	struct ieee80211req_del_key wk;
+
+	wpa_printf(MSG_DEBUG, "%s: addr=%s key_idx=%d",
+		   __func__, ether_sprintf(addr), key_idx);
+
+	memset(&wk, 0, sizeof(wk));
+	if (addr != NULL) {
+		memcpy(wk.idk_macaddr, addr, IEEE80211_ADDR_LEN);
+		wk.idk_keyix = (u_int8_t) IEEE80211_KEYIX_NONE;	/* XXX */
+	} else {
+		wk.idk_keyix = key_idx;
+	}
+
+	return set80211var(drv, IEEE80211_IOC_DELKEY, &wk, sizeof(wk));
+}
+
+static int
+bsd_set_key(const char *ifname, void *priv, wpa_alg alg,
+	    const u8 *addr, int key_idx, int set_tx, const u8 *seq,
+	    size_t seq_len, const u8 *key, size_t key_len)
+{
+	struct bsd_driver_data *drv = priv;
+	struct ieee80211req_key wk;
+	u_int8_t cipher;
+
+	if (alg == WPA_ALG_NONE)
+		return bsd_del_key(drv, addr, key_idx);
+
+	wpa_printf(MSG_DEBUG, "%s: alg=%d addr=%s key_idx=%d",
+		   __func__, alg, ether_sprintf(addr), key_idx);
+
+	if (alg == WPA_ALG_WEP)
+		cipher = IEEE80211_CIPHER_WEP;
+	else if (alg == WPA_ALG_TKIP)
+		cipher = IEEE80211_CIPHER_TKIP;
+	else if (alg == WPA_ALG_CCMP)
+		cipher = IEEE80211_CIPHER_AES_CCM;
+	else {
+		printf("%s: unknown/unsupported algorithm %d\n",
+			__func__, alg);
+		return -1;
+	}
+
+	if (key_len > sizeof(wk.ik_keydata)) {
+		printf("%s: key length %d too big\n", __func__, key_len);
+		return -3;
+	}
+
+	memset(&wk, 0, sizeof(wk));
+	wk.ik_type = cipher;
+	wk.ik_flags = IEEE80211_KEY_RECV | IEEE80211_KEY_XMIT;
+	if (addr == NULL) {
+		memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
+		wk.ik_keyix = key_idx;
+		wk.ik_flags |= IEEE80211_KEY_DEFAULT;
+	} else {
+		memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
+		wk.ik_keyix = IEEE80211_KEYIX_NONE;
+	}
+	wk.ik_keylen = key_len;
+	memcpy(wk.ik_keydata, key, key_len);
+
+	return set80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk));
+}
+
+
+static int
+bsd_get_seqnum(const char *ifname, void *priv, const u8 *addr, int idx,
+	       u8 *seq)
+{
+	struct bsd_driver_data *drv = priv;
+	struct ieee80211req_key wk;
+
+	wpa_printf(MSG_DEBUG, "%s: addr=%s idx=%d",
+		   __func__, ether_sprintf(addr), idx);
+
+	memset(&wk, 0, sizeof(wk));
+	if (addr == NULL)
+		memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
+	else
+		memcpy(wk.ik_macaddr, addr, IEEE80211_ADDR_LEN);
+	wk.ik_keyix = idx;
+
+	if (get80211var(drv, IEEE80211_IOC_WPAKEY, &wk, sizeof(wk)) < 0) {
+		printf("Failed to get encryption.\n");
+		return -1;
+	}
+
+#ifdef WORDS_BIGENDIAN
+	{
+		/*
+		 * wk.ik_keytsc is in host byte order (big endian), need to
+		 * swap it to match with the byte order used in WPA.
+		 */
+		int i;
+		u8 tmp[WPA_KEY_RSC_LEN];
+		memcpy(tmp, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
+		for (i = 0; i < WPA_KEY_RSC_LEN; i++) {
+			seq[i] = tmp[WPA_KEY_RSC_LEN - i - 1];
+		}
+	}
+#else /* WORDS_BIGENDIAN */
+	memcpy(seq, &wk.ik_keytsc, sizeof(wk.ik_keytsc));
+#endif /* WORDS_BIGENDIAN */
+	return 0;
+}
+
+
+static int 
+bsd_flush(void *priv)
+{
+	u8 allsta[IEEE80211_ADDR_LEN];
+
+	memset(allsta, 0xff, IEEE80211_ADDR_LEN);
+	return bsd_sta_deauth(priv, allsta, IEEE80211_REASON_AUTH_LEAVE);
+}
+
+
+static int
+bsd_read_sta_driver_data(void *priv, struct hostap_sta_driver_data *data,
+			 const u8 *addr)
+{
+	struct bsd_driver_data *drv = priv;
+	struct ieee80211req_sta_stats stats;
+
+	memcpy(stats.is_u.macaddr, addr, IEEE80211_ADDR_LEN);
+	if (get80211var(drv, IEEE80211_IOC_STA_STATS, &stats, sizeof(stats)) > 0) {
+		/* XXX? do packets counts include non-data frames? */
+		data->rx_packets = stats.is_stats.ns_rx_data;
+		data->rx_bytes = stats.is_stats.ns_rx_bytes;
+		data->tx_packets = stats.is_stats.ns_tx_data;
+		data->tx_bytes = stats.is_stats.ns_tx_bytes;
+	}
+	return 0;
+}
+
+static int
+bsd_set_opt_ie(const char *ifname, void *priv, const u8 *ie, size_t ie_len)
+{
+	/*
+	 * Do nothing; we setup parameters at startup that define the
+	 * contents of the beacon information element.
+	 */
+	return 0;
+}
+
+static int
+bsd_sta_deauth(void *priv, const u8 *addr, int reason_code)
+{
+	struct bsd_driver_data *drv = priv;
+	struct ieee80211req_mlme mlme;
+
+	wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
+		   __func__, ether_sprintf(addr), reason_code);
+
+	mlme.im_op = IEEE80211_MLME_DEAUTH;
+	mlme.im_reason = reason_code;
+	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
+}
+
+static int
+bsd_sta_disassoc(void *priv, const u8 *addr, int reason_code)
+{
+	struct bsd_driver_data *drv = priv;
+	struct ieee80211req_mlme mlme;
+
+	wpa_printf(MSG_DEBUG, "%s: addr=%s reason_code=%d",
+		   __func__, ether_sprintf(addr), reason_code);
+
+	mlme.im_op = IEEE80211_MLME_DISASSOC;
+	mlme.im_reason = reason_code;
+	memcpy(mlme.im_macaddr, addr, IEEE80211_ADDR_LEN);
+	return set80211var(drv, IEEE80211_IOC_MLME, &mlme, sizeof(mlme));
+}
+
+static int
+bsd_new_sta(struct bsd_driver_data *drv, u8 addr[IEEE80211_ADDR_LEN])
+{
+	struct hostapd_data *hapd = drv->hapd;
+	struct ieee80211req_wpaie ie;
+	int ielen = 0;
+	u8 *iebuf = NULL;
+
+	/*
+	 * Fetch and validate any negotiated WPA/RSN parameters.
+	 */
+	memset(&ie, 0, sizeof(ie));
+	memcpy(ie.wpa_macaddr, addr, IEEE80211_ADDR_LEN);
+	if (get80211var(drv, IEEE80211_IOC_WPAIE, &ie, sizeof(ie)) < 0) {
+		printf("Failed to get WPA/RSN information element.\n");
+		goto no_ie;
+	}
+	iebuf = ie.wpa_ie;
+	ielen = ie.wpa_ie[1];
+	if (ielen == 0)
+		iebuf = NULL;
+	else
+		ielen += 2;
+
+no_ie:
+	return hostapd_notif_assoc(hapd, addr, iebuf, ielen);
+}
+
+#include <net/route.h>
+#include <net80211/ieee80211_freebsd.h>
+
+static void
+bsd_wireless_event_receive(int sock, void *ctx, void *sock_ctx)
+{
+	struct bsd_driver_data *drv = ctx;
+	struct hostapd_data *hapd = drv->hapd;
+	char buf[2048];
+	struct if_announcemsghdr *ifan;
+	struct rt_msghdr *rtm;
+	struct ieee80211_michael_event *mic;
+	struct ieee80211_join_event *join;
+	struct ieee80211_leave_event *leave;
+	int n;
+
+	n = read(sock, buf, sizeof(buf));
+	if (n < 0) {
+		if (errno != EINTR && errno != EAGAIN)
+			perror("read(PF_ROUTE)");
+		return;
+	}
+
+	rtm = (struct rt_msghdr *) buf;
+	if (rtm->rtm_version != RTM_VERSION) {
+		wpa_printf(MSG_DEBUG, "Routing message version %d not "
+			"understood\n", rtm->rtm_version);
+		return;
+	}
+	ifan = (struct if_announcemsghdr *) rtm;
+	switch (rtm->rtm_type) {
+	case RTM_IEEE80211:
+		switch (ifan->ifan_what) {
+		case RTM_IEEE80211_ASSOC:
+		case RTM_IEEE80211_REASSOC:
+		case RTM_IEEE80211_DISASSOC:
+		case RTM_IEEE80211_SCAN:
+			break;
+		case RTM_IEEE80211_LEAVE:
+			leave = (struct ieee80211_leave_event *) &ifan[1];
+			hostapd_notif_disassoc(drv->hapd, leave->iev_addr);
+			break;
+		case RTM_IEEE80211_JOIN:
+#ifdef RTM_IEEE80211_REJOIN
+		case RTM_IEEE80211_REJOIN:
+#endif
+			join = (struct ieee80211_join_event *) &ifan[1];
+			bsd_new_sta(drv, join->iev_addr);
+			break;
+		case RTM_IEEE80211_REPLAY:
+			/* ignore */
+			break;
+		case RTM_IEEE80211_MICHAEL:
+			mic = (struct ieee80211_michael_event *) &ifan[1];
+			wpa_printf(MSG_DEBUG,
+				"Michael MIC failure wireless event: "
+				"keyix=%u src_addr=" MACSTR, mic->iev_keyix,
+				MAC2STR(mic->iev_src));
+			hostapd_michael_mic_failure(hapd, mic->iev_src);
+			break;
+		}
+		break;
+	}
+}
+
+static int
+bsd_wireless_event_init(struct bsd_driver_data *drv)
+{
+	int s;
+
+	drv->wext_sock = -1;
+
+	s = socket(PF_ROUTE, SOCK_RAW, 0);
+	if (s < 0) {
+		perror("socket(PF_ROUTE,SOCK_RAW)");
+		return -1;
+	}
+	eloop_register_read_sock(s, bsd_wireless_event_receive, drv, NULL);
+	drv->wext_sock = s;
+
+	return 0;
+}
+
+static void
+bsd_wireless_event_deinit(struct bsd_driver_data *drv)
+{
+	if (drv->wext_sock < 0)
+		return;
+	eloop_unregister_read_sock(drv->wext_sock);
+	close(drv->wext_sock);
+}
+
+
+static int
+bsd_send_eapol(void *priv, const u8 *addr, const u8 *data, size_t data_len,
+	       int encrypt, const u8 *own_addr)
+{
+	struct bsd_driver_data *drv = priv;
+	unsigned char buf[3000];
+	unsigned char *bp = buf;
+	struct l2_ethhdr *eth;
+	size_t len;
+	int status;
+
+	/*
+	 * Prepend the Etherent header.  If the caller left us
+	 * space at the front we could just insert it but since
+	 * we don't know we copy to a local buffer.  Given the frequency
+	 * and size of frames this probably doesn't matter.
+	 */
+	len = data_len + sizeof(struct l2_ethhdr);
+	if (len > sizeof(buf)) {
+		bp = malloc(len);
+		if (bp == NULL) {
+			printf("EAPOL frame discarded, cannot malloc temp "
+				"buffer of size %u!\n", len);
+			return -1;
+		}
+	}
+	eth = (struct l2_ethhdr *) bp;
+	memcpy(eth->h_dest, addr, ETH_ALEN);
+	memcpy(eth->h_source, own_addr, ETH_ALEN);
+	eth->h_proto = htons(ETH_P_EAPOL);
+	memcpy(eth+1, data, data_len);
+
+	wpa_hexdump(MSG_MSGDUMP, "TX EAPOL", bp, len);
+
+	status = l2_packet_send(drv->sock_xmit, addr, ETH_P_EAPOL, bp, len);
+
+	if (bp != buf)
+		free(bp);
+	return status;
+}
+
+static void
+handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
+{
+	struct bsd_driver_data *drv = ctx;
+	hostapd_eapol_receive(drv->hapd, src_addr,
+			      buf + sizeof(struct l2_ethhdr),
+			      len - sizeof(struct l2_ethhdr));
+}
+
+static int
+bsd_get_ssid(const char *ifname, void *priv, u8 *buf, int len)
+{
+	struct bsd_driver_data *drv = priv;
+	int ssid_len = get80211var(drv, IEEE80211_IOC_SSID, buf, len);
+
+	wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"", __func__, ssid_len, buf);
+
+	return ssid_len;
+}
+
+static int
+bsd_set_ssid(const char *ifname, void *priv, const u8 *buf, int len)
+{
+	struct bsd_driver_data *drv = priv;
+
+	wpa_printf(MSG_DEBUG, "%s: ssid=\"%.*s\"", __func__, len, buf);
+
+	return set80211var(drv, IEEE80211_IOC_SSID, buf, len);
+}
+
+static void *
+bsd_init(struct hostapd_data *hapd)
+{
+	struct bsd_driver_data *drv;
+
+	drv = os_zalloc(sizeof(struct bsd_driver_data));
+	if (drv == NULL) {
+		printf("Could not allocate memory for bsd driver data\n");
+		goto bad;
+	}
+
+	drv->hapd = hapd;
+	drv->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
+	if (drv->ioctl_sock < 0) {
+		perror("socket[PF_INET,SOCK_DGRAM]");
+		goto bad;
+	}
+	memcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
+
+	drv->sock_xmit = l2_packet_init(drv->iface, NULL, ETH_P_EAPOL,
+					handle_read, drv, 1);
+	if (drv->sock_xmit == NULL)
+		goto bad;
+	if (l2_packet_get_own_addr(drv->sock_xmit, hapd->own_addr))
+		goto bad;
+
+	bsd_set_iface_flags(drv, 0);	/* mark down during setup */
+	if (bsd_wireless_event_init(drv))
+		goto bad;
+
+	return drv;
+bad:
+	if (drv->sock_xmit != NULL)
+		l2_packet_deinit(drv->sock_xmit);
+	if (drv->ioctl_sock >= 0)
+		close(drv->ioctl_sock);
+	if (drv != NULL)
+		free(drv);
+	return NULL;
+}
+
+
+static void
+bsd_deinit(void *priv)
+{
+	struct bsd_driver_data *drv = priv;
+
+	bsd_wireless_event_deinit(drv);
+	(void) bsd_set_iface_flags(drv, 0);
+	if (drv->ioctl_sock >= 0)
+		close(drv->ioctl_sock);
+	if (drv->sock_xmit != NULL)
+		l2_packet_deinit(drv->sock_xmit);
+	free(drv);
+}
+
+const struct wpa_driver_ops wpa_driver_bsd_ops = {
+	.name			= "bsd",
+	.hapd_init		= bsd_init,
+	.hapd_deinit		= bsd_deinit,
+	.set_ieee8021x		= bsd_set_ieee8021x,
+	.set_privacy		= bsd_set_privacy,
+	.hapd_set_key		= bsd_set_key,
+	.get_seqnum		= bsd_get_seqnum,
+	.flush			= bsd_flush,
+	.set_generic_elem	= bsd_set_opt_ie,
+	.sta_set_flags		= bsd_sta_set_flags,
+	.read_sta_data		= bsd_read_sta_driver_data,
+	.hapd_send_eapol	= bsd_send_eapol,
+	.sta_disassoc		= bsd_sta_disassoc,
+	.sta_deauth		= bsd_sta_deauth,
+	.hapd_set_ssid		= bsd_set_ssid,
+	.hapd_get_ssid		= bsd_get_ssid,
+};
+
+#else /* HOSTAPD */
+
 struct wpa_driver_bsd_data {
 	int	sock;			/* open socket for 802.11 ioctls */
 	int	route;			/* routing socket for events */
@@ -798,3 +1545,5 @@ const struct wpa_driver_ops wpa_driver_bsd_ops = {
 	.associate		= wpa_driver_bsd_associate,
 	.set_auth_alg		= wpa_driver_bsd_set_auth_alg,
 };
+
+#endif /* HOSTAPD */

File diff suppressed because it is too large
+ 1200 - 1
src/drivers/driver_hostap.c


+ 67 - 4
src/drivers/driver_hostap.h

@@ -1,6 +1,6 @@
 /*
- * WPA Supplicant - driver interaction with Linux Host AP driver
- * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
+ * Driver interaction with Linux Host AP driver
+ * Copyright (c) 2002-2006, 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
@@ -15,10 +15,32 @@
 #ifndef HOSTAP_DRIVER_H
 #define HOSTAP_DRIVER_H
 
+/* netdevice private ioctls (used, e.g., with iwpriv from user space) */
+
+/* New wireless extensions API - SET/GET convention (even ioctl numbers are
+ * root only)
+ */
 #define PRISM2_IOCTL_PRISM2_PARAM (SIOCIWFIRSTPRIV + 0)
+#define PRISM2_IOCTL_GET_PRISM2_PARAM (SIOCIWFIRSTPRIV + 1)
+#define PRISM2_IOCTL_WRITEMIF (SIOCIWFIRSTPRIV + 2)
+#define PRISM2_IOCTL_READMIF (SIOCIWFIRSTPRIV + 3)
+#define PRISM2_IOCTL_MONITOR (SIOCIWFIRSTPRIV + 4)
 #define PRISM2_IOCTL_RESET (SIOCIWFIRSTPRIV + 6)
+#define PRISM2_IOCTL_INQUIRE (SIOCIWFIRSTPRIV + 8)
+#define PRISM2_IOCTL_WDS_ADD (SIOCIWFIRSTPRIV + 10)
+#define PRISM2_IOCTL_WDS_DEL (SIOCIWFIRSTPRIV + 12)
+#define PRISM2_IOCTL_SET_RID_WORD (SIOCIWFIRSTPRIV + 14)
+#define PRISM2_IOCTL_MACCMD (SIOCIWFIRSTPRIV + 16)
+#define PRISM2_IOCTL_ADDMAC (SIOCIWFIRSTPRIV + 18)
+#define PRISM2_IOCTL_DELMAC (SIOCIWFIRSTPRIV + 20)
+#define PRISM2_IOCTL_KICKMAC (SIOCIWFIRSTPRIV + 22)
+
+/* following are not in SIOCGIWPRIV list; check permission in the driver code
+ */
+#define PRISM2_IOCTL_DOWNLOAD (SIOCDEVPRIVATE + 13)
 #define PRISM2_IOCTL_HOSTAPD (SIOCDEVPRIVATE + 14)
 
+
 /* PRISM2_IOCTL_PRISM2_PARAM ioctl() subtypes: */
 enum {
 	/* PRISM2_PARAM_PTYPE = 1, */ /* REMOVED 2003-10-22 */
@@ -63,6 +85,47 @@ enum {
 	PRISM2_PARAM_SCAN_CHANNEL_MASK = 40,
 };
 
+enum { HOSTAP_ANTSEL_DO_NOT_TOUCH = 0, HOSTAP_ANTSEL_DIVERSITY = 1,
+       HOSTAP_ANTSEL_LOW = 2, HOSTAP_ANTSEL_HIGH = 3 };
+
+
+/* PRISM2_IOCTL_MACCMD ioctl() subcommands: */
+enum { AP_MAC_CMD_POLICY_OPEN = 0, AP_MAC_CMD_POLICY_ALLOW = 1,
+       AP_MAC_CMD_POLICY_DENY = 2, AP_MAC_CMD_FLUSH = 3,
+       AP_MAC_CMD_KICKALL = 4 };
+
+
+/* PRISM2_IOCTL_DOWNLOAD ioctl() dl_cmd: */
+enum {
+	PRISM2_DOWNLOAD_VOLATILE = 1 /* RAM */,
+	/* Note! Old versions of prism2_srec have a fatal error in CRC-16
+	 * calculation, which will corrupt all non-volatile downloads.
+	 * PRISM2_DOWNLOAD_NON_VOLATILE used to be 2, but it is now 3 to
+	 * prevent use of old versions of prism2_srec for non-volatile
+	 * download. */
+	PRISM2_DOWNLOAD_NON_VOLATILE = 3 /* FLASH */,
+	PRISM2_DOWNLOAD_VOLATILE_GENESIS = 4 /* RAM in Genesis mode */,
+	/* Persistent versions of volatile download commands (keep firmware
+	 * data in memory and automatically re-download after hw_reset */
+	PRISM2_DOWNLOAD_VOLATILE_PERSISTENT = 5,
+	PRISM2_DOWNLOAD_VOLATILE_GENESIS_PERSISTENT = 6,
+};
+
+struct prism2_download_param {
+	u32 dl_cmd;
+	u32 start_addr;
+	u32 num_areas;
+	struct prism2_download_area {
+		u32 addr; /* wlan card address */
+		u32 len;
+		caddr_t ptr; /* pointer to data in user space */
+	} data[0];
+};
+
+#define PRISM2_MAX_DOWNLOAD_AREA_LEN 131072
+#define PRISM2_MAX_DOWNLOAD_LEN 262144
+
+
 /* PRISM2_IOCTL_HOSTAPD ioctl() cmd: */
 enum {
 	PRISM2_HOSTAPD_FLUSH = 1,
@@ -140,8 +203,8 @@ struct prism2_hostapd_param {
 	} u;
 };
 
-#define HOSTAP_CRYPT_FLAG_SET_TX_KEY 0x01
-#define HOSTAP_CRYPT_FLAG_PERMANENT 0x02
+#define HOSTAP_CRYPT_FLAG_SET_TX_KEY BIT(0)
+#define HOSTAP_CRYPT_FLAG_PERMANENT BIT(1)
 
 #define HOSTAP_CRYPT_ERR_UNKNOWN_ALG 2
 #define HOSTAP_CRYPT_ERR_UNKNOWN_ADDR 3

File diff suppressed because it is too large
+ 1338 - 1
src/drivers/driver_madwifi.c


+ 53 - 1
src/drivers/driver_ndis.c

@@ -3217,5 +3217,57 @@ const struct wpa_driver_ops wpa_driver_ndis_ops = {
 	NULL /* scan2 */,
 	NULL /* authenticate */,
 	NULL /* set_beacon */,
-	NULL /* set_beacon_int */
+	NULL /* set_beacon_int */,
+	NULL /* set_ieee8021x */,
+	NULL /* set_privacy */,
+	NULL /* hapd_set_key */,
+	NULL /* get_seqnum */,
+	NULL /* get_seqnum_igtk */,
+	NULL /* flush */,
+	NULL /* set_generic_elem */,
+	NULL /* read_sta_data */,
+	NULL /* hapd_send_eapol */,
+	NULL /* sta_deauth */,
+	NULL /* sta_disassoc */,
+	NULL /* sta_remove */,
+	NULL /* hapd_get_ssid */,
+	NULL /* hapd_set_ssid */,
+	NULL /* hapd_set_countermeasures */,
+	NULL /* send_mgmt_frame */,
+	NULL /* sta_add */,
+	NULL /* get_inact_sec */,
+	NULL /* sta_clear_stats */,
+	NULL /* set_freq */,
+	NULL /* set_rts */,
+	NULL /* set_frag */,
+	NULL /* set_retry */,
+	NULL /* sta_set_flags */,
+	NULL /* set_rate_sets */,
+	NULL /* hapd_set_country */,
+	NULL /* set_ieee80211d */,
+	NULL /* hapd_set_beacon */,
+	NULL /* set_internal_bridge */,
+	NULL /* hapd_set_beacon_int */,
+	NULL /* set_broadcast_ssid */,
+	NULL /* set_cts_protect */,
+	NULL /* set_preamble */,
+	NULL /* set_short_slot_time */,
+	NULL /* set_tx_queue_params */,
+	NULL /* bss_add */,
+	NULL /* bss_remove */,
+	NULL /* valid_bss_mask */,
+	NULL /* passive_scan */,
+	NULL /* hapd_get_hw_feature_data */,
+	NULL /* if_add */,
+	NULL /* if_update */,
+	NULL /* if_remove */,
+	NULL /* set_sta_vlan */,
+	NULL /* commit */,
+	NULL /* send_ether */,
+	NULL /* set_radius_acl_auth */,
+	NULL /* set_radius_acl_expire */,
+	NULL /* set_ht_params */,
+	NULL /* set_wps_beacon_ie */,
+	NULL /* set_wps_probe_resp_ie */,
+	NULL /* get_neighbor_bss */
 };

File diff suppressed because it is too large
+ 2893 - 5
src/drivers/driver_nl80211.c


+ 4 - 4
hostapd/driver_none.c → src/drivers/driver_none.c

@@ -14,7 +14,7 @@
 
 #include "includes.h"
 
-#include "hostapd.h"
+#include "../hostapd/hostapd.h"
 #include "driver.h"
 
 
@@ -54,9 +54,9 @@ static int none_driver_send_ether(void *priv, const u8 *dst, const u8 *src,
 }
 
 
-const struct hapd_driver_ops wpa_driver_none_ops = {
+const struct wpa_driver_ops wpa_driver_none_ops = {
 	.name = "none",
-	.init = none_driver_init,
-	.deinit = none_driver_deinit,
+	.hapd_init = none_driver_init,
+	.hapd_deinit = none_driver_deinit,
 	.send_ether = none_driver_send_ether,
 };

File diff suppressed because it is too large
+ 1051 - 1
src/drivers/driver_prism54.c


+ 54 - 2
src/drivers/driver_privsep.c

@@ -813,11 +813,63 @@ struct wpa_driver_ops wpa_driver_privsep_ops = {
 	NULL /* scan2 */,
 	NULL /* authenticate */,
 	NULL /* set_beacon */,
-	NULL /* set_beacon_int */
+	NULL /* set_beacon_int */,
+	NULL /* set_ieee8021x */,
+	NULL /* set_privacy */,
+	NULL /* hapd_set_key */,
+	NULL /* get_seqnum */,
+	NULL /* get_seqnum_igtk */,
+	NULL /* flush */,
+	NULL /* set_generic_elem */,
+	NULL /* read_sta_data */,
+	NULL /* hapd_send_eapol */,
+	NULL /* sta_deauth */,
+	NULL /* sta_disassoc */,
+	NULL /* sta_remove */,
+	NULL /* hapd_get_ssid */,
+	NULL /* hapd_set_ssid */,
+	NULL /* hapd_set_countermeasures */,
+	NULL /* send_mgmt_frame */,
+	NULL /* sta_add */,
+	NULL /* get_inact_sec */,
+	NULL /* sta_clear_stats */,
+	NULL /* set_freq */,
+	NULL /* set_rts */,
+	NULL /* set_frag */,
+	NULL /* set_retry */,
+	NULL /* sta_set_flags */,
+	NULL /* set_rate_sets */,
+	NULL /* hapd_set_country */,
+	NULL /* set_ieee80211d */,
+	NULL /* hapd_set_beacon */,
+	NULL /* set_internal_bridge */,
+	NULL /* hapd_set_beacon_int */,
+	NULL /* set_broadcast_ssid */,
+	NULL /* set_cts_protect */,
+	NULL /* set_preamble */,
+	NULL /* set_short_slot_time */,
+	NULL /* set_tx_queue_params */,
+	NULL /* bss_add */,
+	NULL /* bss_remove */,
+	NULL /* valid_bss_mask */,
+	NULL /* passive_scan */,
+	NULL /* hapd_get_hw_feature_data */,
+	NULL /* if_add */,
+	NULL /* if_update */,
+	NULL /* if_remove */,
+	NULL /* set_sta_vlan */,
+	NULL /* commit */,
+	NULL /* send_ether */,
+	NULL /* set_radius_acl_auth */,
+	NULL /* set_radius_acl_expire */,
+	NULL /* set_ht_params */,
+	NULL /* set_wps_beacon_ie */,
+	NULL /* set_wps_probe_resp_ie */,
+	NULL /* get_neighbor_bss */
 };
 
 
-struct wpa_driver_ops *wpa_supplicant_drivers[] =
+struct wpa_driver_ops *wpa_drivers[] =
 {
 	&wpa_driver_privsep_ops,
 	NULL

File diff suppressed because it is too large
+ 1210 - 1
src/drivers/driver_test.c


+ 348 - 5
src/drivers/driver_wired.c

@@ -1,6 +1,7 @@
 /*
  * WPA Supplicant - wired Ethernet driver interface
  * Copyright (c) 2005-2007, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004, Gunter Burchardt <tira@isx.de>
  *
  * 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
@@ -17,6 +18,8 @@
 #include <net/if.h>
 #ifdef __linux__
 #include <netpacket/packet.h>
+#include <net/if_arp.h>
+#include <net/if.h>
 #endif /* __linux__ */
 #ifdef __FreeBSD__
 #include <net/if_dl.h>
@@ -25,19 +28,352 @@
 #include "common.h"
 #include "driver.h"
 
+#ifdef HOSTAPD
+#include "eloop.h"
+#include "../../hostapd/hostapd.h"
+#include "../../hostapd/config.h"
+#include "../../hostapd/sta_info.h"
+#include "../../hostapd/accounting.h"
+#endif /* HOSTAPD */
 
 static const u8 pae_group_addr[ETH_ALEN] =
 { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 };
 
 
 struct wpa_driver_wired_data {
+#ifdef HOSTAPD
+	struct hostapd_data *hapd;
+	char iface[IFNAMSIZ + 1];
+
+	int sock; /* raw packet socket for driver access */
+	int dhcp_sock; /* socket for dhcp packets */
+	int use_pae_group_addr;
+#else /* HOSTAPD */
 	void *ctx;
 	int pf_sock;
 	char ifname[IFNAMSIZ + 1];
 	int membership, multi, iff_allmulti, iff_up;
+#endif /* HOSTAPD */
+};
+
+
+#ifdef HOSTAPD
+
+/* TODO: detecting new devices should eventually be changed from using DHCP
+ * snooping to trigger on any packet from a new layer 2 MAC address, e.g.,
+ * based on ebtables, etc. */
+
+struct dhcp_message {
+	u_int8_t op;
+	u_int8_t htype;
+	u_int8_t hlen;
+	u_int8_t hops;
+	u_int32_t xid;
+	u_int16_t secs;
+	u_int16_t flags;
+	u_int32_t ciaddr;
+	u_int32_t yiaddr;
+	u_int32_t siaddr;
+	u_int32_t giaddr;
+	u_int8_t chaddr[16];
+	u_int8_t sname[64];
+	u_int8_t file[128];
+	u_int32_t cookie;
+	u_int8_t options[308]; /* 312 - cookie */
 };
 
 
+static void wired_possible_new_sta(struct hostapd_data *hapd, u8 *addr)
+{
+	struct sta_info *sta;
+
+	sta = ap_get_sta(hapd, addr);
+	if (sta)
+		return;
+
+	wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
+		   " - adding a new STA", MAC2STR(addr));
+	sta = ap_sta_add(hapd, addr);
+	if (sta) {
+		hostapd_new_assoc_sta(hapd, sta, 0);
+	} else {
+		wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
+			   MAC2STR(addr));
+	}
+}
+
+
+static void handle_data(struct hostapd_data *hapd, unsigned char *buf,
+			size_t len)
+{
+	struct ieee8023_hdr *hdr;
+	u8 *pos, *sa;
+	size_t left;
+
+	/* must contain at least ieee8023_hdr 6 byte source, 6 byte dest,
+	 * 2 byte ethertype */
+	if (len < 14) {
+		wpa_printf(MSG_MSGDUMP, "handle_data: too short (%lu)",
+			   (unsigned long) len);
+		return;
+	}
+
+	hdr = (struct ieee8023_hdr *) buf;
+
+	switch (ntohs(hdr->ethertype)) {
+		case ETH_P_PAE:
+			wpa_printf(MSG_MSGDUMP, "Received EAPOL packet");
+			sa = hdr->src;
+			wired_possible_new_sta(hapd, sa);
+
+			pos = (u8 *) (hdr + 1);
+			left = len - sizeof(*hdr);
+
+			hostapd_eapol_receive(hapd, sa, pos, left);
+		break;
+
+	default:
+		wpa_printf(MSG_DEBUG, "Unknown ethertype 0x%04x in data frame",
+			   ntohs(hdr->ethertype));
+		break;
+	}
+}
+
+
+static void handle_read(int sock, void *eloop_ctx, void *sock_ctx)
+{
+	struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx;
+	int len;
+	unsigned char buf[3000];
+
+	len = recv(sock, buf, sizeof(buf), 0);
+	if (len < 0) {
+		perror("recv");
+		return;
+	}
+
+	handle_data(hapd, buf, len);
+}
+
+
+static void handle_dhcp(int sock, void *eloop_ctx, void *sock_ctx)
+{
+	struct hostapd_data *hapd = (struct hostapd_data *) eloop_ctx;
+	int len;
+	unsigned char buf[3000];
+	struct dhcp_message *msg;
+	u8 *mac_address;
+
+	len = recv(sock, buf, sizeof(buf), 0);
+	if (len < 0) {
+		perror("recv");
+		return;
+	}
+
+	/* must contain at least dhcp_message->chaddr */
+	if (len < 44) {
+		wpa_printf(MSG_MSGDUMP, "handle_dhcp: too short (%d)", len);
+		return;
+	}
+
+	msg = (struct dhcp_message *) buf;
+	mac_address = (u8 *) &(msg->chaddr);
+
+	wpa_printf(MSG_MSGDUMP, "Got DHCP broadcast packet from " MACSTR,
+		   MAC2STR(mac_address));
+
+	wired_possible_new_sta(hapd, mac_address);
+}
+
+
+static int wired_init_sockets(struct wpa_driver_wired_data *drv)
+{
+	struct hostapd_data *hapd = drv->hapd;
+	struct ifreq ifr;
+	struct sockaddr_ll addr;
+	struct sockaddr_in addr2;
+	struct packet_mreq mreq;
+	int n = 1;
+
+	drv->sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_PAE));
+	if (drv->sock < 0) {
+		perror("socket[PF_PACKET,SOCK_RAW]");
+		return -1;
+	}
+
+	if (eloop_register_read_sock(drv->sock, handle_read, hapd, NULL)) {
+		printf("Could not register read socket\n");
+		return -1;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
+	if (ioctl(drv->sock, SIOCGIFINDEX, &ifr) != 0) {
+		perror("ioctl(SIOCGIFINDEX)");
+		return -1;
+	}
+
+	memset(&addr, 0, sizeof(addr));
+	addr.sll_family = AF_PACKET;
+	addr.sll_ifindex = ifr.ifr_ifindex;
+	wpa_printf(MSG_DEBUG, "Opening raw packet socket for ifindex %d",
+		   addr.sll_ifindex);
+
+	if (bind(drv->sock, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+		perror("bind");
+		return -1;
+	}
+
+	/* filter multicast address */
+	memset(&mreq, 0, sizeof(mreq));
+	mreq.mr_ifindex = ifr.ifr_ifindex;
+	mreq.mr_type = PACKET_MR_MULTICAST;
+	mreq.mr_alen = 6;
+	memcpy(mreq.mr_address, pae_group_addr, mreq.mr_alen);
+
+	if (setsockopt(drv->sock, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq,
+		       sizeof(mreq)) < 0) {
+		perror("setsockopt[SOL_SOCKET,PACKET_ADD_MEMBERSHIP]");
+		return -1;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	os_strlcpy(ifr.ifr_name, drv->iface, sizeof(ifr.ifr_name));
+	if (ioctl(drv->sock, SIOCGIFHWADDR, &ifr) != 0) {
+		perror("ioctl(SIOCGIFHWADDR)");
+		return -1;
+	}
+
+	if (ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
+		printf("Invalid HW-addr family 0x%04x\n",
+		       ifr.ifr_hwaddr.sa_family);
+		return -1;
+	}
+	memcpy(hapd->own_addr, ifr.ifr_hwaddr.sa_data, ETH_ALEN);
+
+	/* setup dhcp listen socket for sta detection */
+	if ((drv->dhcp_sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+		perror("socket call failed for dhcp");
+		return -1;
+	}
+
+	if (eloop_register_read_sock(drv->dhcp_sock, handle_dhcp, hapd, NULL))
+	{
+		printf("Could not register read socket\n");
+		return -1;
+	}
+
+	memset(&addr2, 0, sizeof(addr2));
+	addr2.sin_family = AF_INET;
+	addr2.sin_port = htons(67);
+	addr2.sin_addr.s_addr = INADDR_ANY;
+
+	if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_REUSEADDR, (char *) &n,
+		       sizeof(n)) == -1) {
+		perror("setsockopt[SOL_SOCKET,SO_REUSEADDR]");
+		return -1;
+	}
+	if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BROADCAST, (char *) &n,
+		       sizeof(n)) == -1) {
+		perror("setsockopt[SOL_SOCKET,SO_BROADCAST]");
+		return -1;
+	}
+
+	memset(&ifr, 0, sizeof(ifr));
+	os_strlcpy(ifr.ifr_ifrn.ifrn_name, drv->iface, IFNAMSIZ);
+	if (setsockopt(drv->dhcp_sock, SOL_SOCKET, SO_BINDTODEVICE,
+		       (char *) &ifr, sizeof(ifr)) < 0) {
+		perror("setsockopt[SOL_SOCKET,SO_BINDTODEVICE]");
+		return -1;
+	}
+
+	if (bind(drv->dhcp_sock, (struct sockaddr *) &addr2,
+		 sizeof(struct sockaddr)) == -1) {
+		perror("bind");
+		return -1;
+	}
+
+	return 0;
+}
+
+
+static int wired_send_eapol(void *priv, const u8 *addr,
+			    const u8 *data, size_t data_len, int encrypt,
+			    const u8 *own_addr)
+{
+	struct wpa_driver_wired_data *drv = priv;
+	struct ieee8023_hdr *hdr;
+	size_t len;
+	u8 *pos;
+	int res;
+
+	len = sizeof(*hdr) + data_len;
+	hdr = os_zalloc(len);
+	if (hdr == NULL) {
+		printf("malloc() failed for wired_send_eapol(len=%lu)\n",
+		       (unsigned long) len);
+		return -1;
+	}
+
+	memcpy(hdr->dest, drv->use_pae_group_addr ? pae_group_addr : addr,
+	       ETH_ALEN);
+	memcpy(hdr->src, own_addr, ETH_ALEN);
+	hdr->ethertype = htons(ETH_P_PAE);
+
+	pos = (u8 *) (hdr + 1);
+	memcpy(pos, data, data_len);
+
+	res = send(drv->sock, (u8 *) hdr, len, 0);
+	free(hdr);
+
+	if (res < 0) {
+		perror("wired_send_eapol: send");
+		printf("wired_send_eapol - packet len: %lu - failed\n",
+		       (unsigned long) len);
+	}
+
+	return res;
+}
+
+
+static void * wired_driver_hapd_init(struct hostapd_data *hapd)
+{
+	struct wpa_driver_wired_data *drv;
+
+	drv = os_zalloc(sizeof(struct wpa_driver_wired_data));
+	if (drv == NULL) {
+		printf("Could not allocate memory for wired driver data\n");
+		return NULL;
+	}
+
+	drv->hapd = hapd;
+	os_strlcpy(drv->iface, hapd->conf->iface, sizeof(drv->iface));
+	drv->use_pae_group_addr = hapd->conf->use_pae_group_addr;
+
+	if (wired_init_sockets(drv)) {
+		free(drv);
+		return NULL;
+	}
+
+	return drv;
+}
+
+
+static void wired_driver_hapd_deinit(void *priv)
+{
+	struct wpa_driver_wired_data *drv = priv;
+
+	if (drv->sock >= 0)
+		close(drv->sock);
+
+	if (drv->dhcp_sock >= 0)
+		close(drv->dhcp_sock);
+
+	free(drv);
+}
+
+#else /* HOSTAPD */
+
 static int wpa_driver_wired_get_ssid(void *priv, u8 *ssid)
 {
 	ssid[0] = 0;
@@ -136,7 +472,7 @@ static int wpa_driver_wired_multi(const char *ifname, const u8 *addr, int add)
 		dlp->sdl_nlen = 0;
 		dlp->sdl_alen = ETH_ALEN;
 		dlp->sdl_slen = 0;
-		os_memcpy(LLADDR(dlp), addr, ETH_ALEN); 
+		os_memcpy(LLADDR(dlp), addr, ETH_ALEN);
 	}
 #endif /* __FreeBSD__ */
 
@@ -194,9 +530,9 @@ static void * wpa_driver_wired_init(void *ctx, const char *ifname)
 	if (drv->pf_sock < 0)
 		perror("socket(PF_PACKET)");
 #else /* __linux__ */
-	drv->pf_sock = -1;       
+	drv->pf_sock = -1;
 #endif /* __linux__ */
-	
+
 	if (wpa_driver_wired_get_ifflags(ifname, &flags) == 0 &&
 	    !(flags & IFF_UP) &&
 	    wpa_driver_wired_set_ifflags(ifname, flags | IFF_UP) == 0) {
@@ -270,17 +606,24 @@ static void wpa_driver_wired_deinit(void *priv)
 
 	if (drv->pf_sock != -1)
 		close(drv->pf_sock);
-	
+
 	os_free(drv);
 }
+#endif /* HOSTAPD */
 
 
 const struct wpa_driver_ops wpa_driver_wired_ops = {
 	.name = "wired",
-	.desc = "wpa_supplicant wired Ethernet driver",
+	.desc = "Wired Ethernet driver",
+#ifdef HOSTAPD
+	.hapd_init = wired_driver_hapd_init,
+	.hapd_deinit = wired_driver_hapd_deinit,
+	.hapd_send_eapol = wired_send_eapol,
+#else /* HOSTAPD */
 	.get_ssid = wpa_driver_wired_get_ssid,
 	.get_bssid = wpa_driver_wired_get_bssid,
 	.get_capa = wpa_driver_wired_get_capa,
 	.init = wpa_driver_wired_init,
 	.deinit = wpa_driver_wired_deinit,
+#endif /* HOSTAPD */
 };

+ 20 - 2
src/drivers/drivers.c

@@ -1,5 +1,5 @@
 /*
- * WPA Supplicant / driver interface list
+ * Driver interface list
  * Copyright (c) 2004-2005, Jouni Malinen <j@w1.fi>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -74,9 +74,18 @@ extern struct wpa_driver_ops wpa_driver_iphone_ops; /* driver_iphone.m */
 /* driver_roboswitch.c */
 extern struct wpa_driver_ops wpa_driver_roboswitch_ops;
 #endif /* CONFIG_DRIVER_ROBOSWITCH */
+#ifdef CONFIG_DRIVER_ATHEROS
+extern struct wpa_driver_ops wpa_driver_atheros_ops; /* driver_atheros.c */
+#endif /* CONFIG_DRIVER_ATHEROS */
+#ifdef CONFIG_DRIVER_NONE
+extern struct wpa_driver_ops wpa_driver_none_ops; /* driver_none.c */
+#endif /* CONFIG_DRIVER_NONE */
+#ifdef CONFIG_AP
+extern struct wpa_driver_ops ap_driver_ops; /* wpa_supplicant/ap.c */
+#endif /* CONFIG_AP */
 
 
-struct wpa_driver_ops *wpa_supplicant_drivers[] =
+struct wpa_driver_ops *wpa_drivers[] =
 {
 #ifdef CONFIG_DRIVER_WEXT
 	&wpa_driver_wext_ops,
@@ -135,5 +144,14 @@ struct wpa_driver_ops *wpa_supplicant_drivers[] =
 #ifdef CONFIG_DRIVER_ROBOSWITCH
 	&wpa_driver_roboswitch_ops,
 #endif /* CONFIG_DRIVER_ROBOSWITCH */
+#ifdef CONFIG_DRIVER_ATHEROS
+	&wpa_driver_atheros_ops,
+#endif /* CONFIG_DRIVER_ATHEROS */
+#ifdef CONFIG_DRIVER_NONE
+	&wpa_driver_none_ops,
+#endif /* CONFIG_DRIVER_NONE */
+#ifdef CONFIG_AP
+	&ap_driver_ops,
+#endif /* CONFIG_AP */
 	NULL
 };

+ 0 - 0
hostapd/prism54.h → src/drivers/prism54.h


+ 20 - 13
wpa_supplicant/ap.c

@@ -18,7 +18,6 @@
 #include "common.h"
 #include "../hostapd/hostapd.h"
 #include "../hostapd/config.h"
-#include "../hostapd/driver.h"
 #ifdef NEED_MLME
 #include "../hostapd/ieee802_11.h"
 #endif /* NEED_MLME */
@@ -245,13 +244,13 @@ static struct hostapd_hw_modes *ap_driver_get_hw_feature_data(void *priv,
 }
 
 
-static struct hapd_driver_ops ap_driver_ops =
+struct wpa_driver_ops ap_driver_ops =
 {
 	.name = "wpa_supplicant",
-	.init = ap_driver_init,
-	.deinit = ap_driver_deinit,
+	.hapd_init = ap_driver_init,
+	.hapd_deinit = ap_driver_deinit,
 	.send_ether = ap_driver_send_ether,
-	.set_key = ap_driver_set_key,
+	.hapd_set_key = ap_driver_set_key,
 	.get_seqnum = ap_driver_get_seqnum,
 	.flush = ap_driver_flush,
 	.read_sta_data = ap_driver_read_sta_data,
@@ -263,27 +262,35 @@ static struct hapd_driver_ops ap_driver_ops =
 	.sta_add = ap_driver_sta_add,
 	.get_inact_sec = ap_driver_get_inact_sec,
 	.set_freq = ap_driver_set_freq,
-	.set_beacon = ap_driver_set_beacon,
-	.set_beacon_int = ap_driver_set_beacon_int,
+	.hapd_set_beacon = ap_driver_set_beacon,
+	.hapd_set_beacon_int = ap_driver_set_beacon_int,
 	.set_cts_protect = ap_driver_set_cts_protect,
 	.set_preamble = ap_driver_set_preamble,
 	.set_short_slot_time = ap_driver_set_short_slot_time,
 	.set_tx_queue_params = ap_driver_set_tx_queue_params,
-	.get_hw_feature_data = ap_driver_get_hw_feature_data,
+	.hapd_get_hw_feature_data = ap_driver_get_hw_feature_data,
 };
 
-struct hapd_driver_ops *hostapd_drivers[] =
-{
-	&ap_driver_ops,
-	NULL
-};
 
+extern struct wpa_driver_ops *wpa_drivers[];
 
 static int wpa_supplicant_conf_ap(struct wpa_supplicant *wpa_s,
 				  struct wpa_ssid *ssid,
 				  struct hostapd_config *conf)
 {
 	struct hostapd_bss_config *bss = &conf->bss[0];
+	int j;
+
+	for (j = 0; wpa_drivers[j]; j++) {
+		if (os_strcmp("wpa_supplicant", wpa_drivers[j]->name) == 0) {
+			conf->driver = wpa_drivers[j];
+			break;
+		}
+	}
+	if (conf->driver == NULL) {
+		wpa_printf(MSG_ERROR, "No AP driver ops found");
+		return -1;
+	}
 
 	os_strlcpy(bss->iface, wpa_s->ifname, sizeof(bss->iface));
 

+ 3 - 3
wpa_supplicant/ctrl_iface.c

@@ -32,7 +32,7 @@
 #include "wps/wps.h"
 #include "ibss_rsn.h"
 
-extern struct wpa_driver_ops *wpa_supplicant_drivers[];
+extern struct wpa_driver_ops *wpa_drivers[];
 
 static int wpa_supplicant_global_iface_list(struct wpa_global *global,
 					    char *buf, int len);
@@ -1825,8 +1825,8 @@ static int wpa_supplicant_global_iface_list(struct wpa_global *global,
 	struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
 	char *pos, *end;
 
-	for (i = 0; wpa_supplicant_drivers[i]; i++) {
-		struct wpa_driver_ops *drv = wpa_supplicant_drivers[i];
+	for (i = 0; wpa_drivers[i]; i++) {
+		struct wpa_driver_ops *drv = wpa_drivers[i];
 		if (drv->get_interfaces == NULL)
 			continue;
 		tmp = drv->get_interfaces(global->drv_priv);

+ 1 - 1
wpa_supplicant/eapol_test.c

@@ -35,7 +35,7 @@
 extern int wpa_debug_level;
 extern int wpa_debug_show_keys;
 
-struct wpa_driver_ops *wpa_supplicant_drivers[] = { NULL };
+struct wpa_driver_ops *wpa_drivers[] = { NULL };
 
 
 struct extra_radius_attr {

+ 5 - 6
wpa_supplicant/main.c

@@ -21,7 +21,7 @@
 #include "wpa_supplicant_i.h"
 #include "driver_i.h"
 
-extern struct wpa_driver_ops *wpa_supplicant_drivers[];
+extern struct wpa_driver_ops *wpa_drivers[];
 
 
 static void usage(void)
@@ -41,10 +41,10 @@ static void usage(void)
 	       "drivers:\n",
 	       wpa_supplicant_version, wpa_supplicant_license);
 
-	for (i = 0; wpa_supplicant_drivers[i]; i++) {
+	for (i = 0; wpa_drivers[i]; i++) {
 		printf("  %s = %s\n",
-		       wpa_supplicant_drivers[i]->name,
-		       wpa_supplicant_drivers[i]->desc);
+		       wpa_drivers[i]->name,
+		       wpa_drivers[i]->desc);
 	}
 
 #ifndef CONFIG_NO_STDOUT_DEBUG
@@ -79,8 +79,7 @@ static void usage(void)
 
 	printf("example:\n"
 	       "  wpa_supplicant -D%s -iwlan0 -c/etc/wpa_supplicant.conf\n",
-	       wpa_supplicant_drivers[i] ?
-		   wpa_supplicant_drivers[i]->name : "wext");
+	       wpa_drivers[i] ? wpa_drivers[i]->name : "wext");
 #endif /* CONFIG_NO_STDOUT_DEBUG */
 }
 

+ 2 - 1
wpa_supplicant/preauth_test.c

@@ -30,12 +30,13 @@
 #include "pcsc_funcs.h"
 #include "preauth.h"
 #include "pmksa_cache.h"
+#include "drivers/driver.h"
 
 
 extern int wpa_debug_level;
 extern int wpa_debug_show_keys;
 
-struct wpa_driver_ops *wpa_supplicant_drivers[] = { NULL };
+struct wpa_driver_ops *wpa_drivers[] = { NULL };
 
 
 struct preauth_test_data {

+ 4 - 4
wpa_supplicant/wpa_priv.c

@@ -692,7 +692,7 @@ static void wpa_priv_interface_deinit(struct wpa_priv_interface *iface)
 }
 
 
-extern struct wpa_driver_ops *wpa_supplicant_drivers[];
+extern struct wpa_driver_ops *wpa_drivers[];
 
 static struct wpa_priv_interface *
 wpa_priv_interface_init(const char *dir, const char *params)
@@ -721,10 +721,10 @@ wpa_priv_interface_init(const char *dir, const char *params)
 	os_memcpy(iface->driver_name, params, len);
 	iface->driver_name[len] = '\0';
 
-	for (i = 0; wpa_supplicant_drivers[i]; i++) {
+	for (i = 0; wpa_drivers[i]; i++) {
 		if (os_strcmp(iface->driver_name,
-			      wpa_supplicant_drivers[i]->name) == 0) {
-			iface->driver = wpa_supplicant_drivers[i];
+			      wpa_drivers[i]->name) == 0) {
+			iface->driver = wpa_drivers[i];
 			break;
 		}
 	}

+ 14 - 14
wpa_supplicant/wpa_supplicant.c

@@ -114,7 +114,7 @@ const char *wpa_supplicant_full_license5 =
 extern int wpa_debug_level;
 extern int wpa_debug_show_keys;
 extern int wpa_debug_timestamp;
-extern struct wpa_driver_ops *wpa_supplicant_drivers[];
+extern struct wpa_driver_ops *wpa_drivers[];
 
 /* Configure default/group WEP keys for static WEP */
 static int wpa_set_wep_keys(struct wpa_supplicant *wpa_s,
@@ -1533,7 +1533,7 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
 	if (wpa_s == NULL)
 		return -1;
 
-	if (wpa_supplicant_drivers[0] == NULL) {
+	if (wpa_drivers[0] == NULL) {
 		wpa_printf(MSG_ERROR, "No driver interfaces build into "
 			   "wpa_supplicant.");
 		return -1;
@@ -1541,7 +1541,7 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
 
 	if (name == NULL) {
 		/* default to first driver in the list */
-		wpa_s->driver = wpa_supplicant_drivers[0];
+		wpa_s->driver = wpa_drivers[0];
 		return 0;
 	}
 
@@ -1550,11 +1550,11 @@ static int wpa_supplicant_set_driver(struct wpa_supplicant *wpa_s,
 		len = pos - name;
 	else
 		len = os_strlen(name);
-	for (i = 0; wpa_supplicant_drivers[i]; i++) {
-		if (os_strlen(wpa_supplicant_drivers[i]->name) == len &&
-		    os_strncmp(name, wpa_supplicant_drivers[i]->name, len) ==
+	for (i = 0; wpa_drivers[i]; i++) {
+		if (os_strlen(wpa_drivers[i]->name) == len &&
+		    os_strncmp(name, wpa_drivers[i]->name, len) ==
 		    0) {
-			wpa_s->driver = wpa_supplicant_drivers[i];
+			wpa_s->driver = wpa_drivers[i];
 			return 0;
 		}
 	}
@@ -2159,7 +2159,7 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
 		}
 	}
 
-	for (i = 0; wpa_supplicant_drivers[i]; i++)
+	for (i = 0; wpa_drivers[i]; i++)
 		global->drv_count++;
 	if (global->drv_count == 0) {
 		wpa_printf(MSG_ERROR, "No drivers enabled");
@@ -2171,13 +2171,13 @@ struct wpa_global * wpa_supplicant_init(struct wpa_params *params)
 		wpa_supplicant_deinit(global);
 		return NULL;
 	}
-	for (i = 0; wpa_supplicant_drivers[i]; i++) {
-		if (!wpa_supplicant_drivers[i]->global_init)
+	for (i = 0; wpa_drivers[i]; i++) {
+		if (!wpa_drivers[i]->global_init)
 			continue;
-		global->drv_priv[i] = wpa_supplicant_drivers[i]->global_init();
+		global->drv_priv[i] = wpa_drivers[i]->global_init();
 		if (global->drv_priv[i] == NULL) {
 			wpa_printf(MSG_ERROR, "Failed to initialize driver "
-				   "'%s'", wpa_supplicant_drivers[i]->name);
+				   "'%s'", wpa_drivers[i]->name);
 			wpa_supplicant_deinit(global);
 			return NULL;
 		}
@@ -2244,10 +2244,10 @@ void wpa_supplicant_deinit(struct wpa_global *global)
 
 	eap_peer_unregister_methods();
 
-	for (i = 0; wpa_supplicant_drivers[i] && global->drv_priv; i++) {
+	for (i = 0; wpa_drivers[i] && global->drv_priv; i++) {
 		if (!global->drv_priv[i])
 			continue;
-		wpa_supplicant_drivers[i]->global_deinit(global->drv_priv[i]);
+		wpa_drivers[i]->global_deinit(global->drv_priv[i]);
 	}
 	os_free(global->drv_priv);
 

Some files were not shown because too many files changed in this diff