From 50904372363165db42fdc100d02fed3229fb2936 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Mon, 5 Nov 2007 06:13:07 +0000 Subject: [PATCH] Change wpa_supplicant to down the interface at the start of the init routine. wpa_supplicant expects that it has exclusive access to the net80211 state so when its starts poking in the WEP/WPA settings and the card is already scanning it can cause net80211 to try and associate incorrectly with a protected AP. This is an inconvenience for firmware based cards such as iwi where it can be sent an auth instruction with incomplete security info and cause a firmware error. Remove the 'ifconfig up' from network.subr since wpa_supplicant will immediately down the interface again. Reported by: Guy Helmer (and others) Reviewed by: sam, brooks, avatar MFC after: 3 days --- etc/network.subr | 3 --- usr.sbin/wpa/wpa_supplicant/driver_freebsd.c | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/etc/network.subr b/etc/network.subr index 51173c540cd1..a98954bcc72f 100644 --- a/etc/network.subr +++ b/etc/network.subr @@ -49,9 +49,6 @@ ifconfig_up() fi if wpaif $1; then - if [ $_cfg -ne 0 ] ; then - ifconfig $1 up - fi /etc/rc.d/wpa_supplicant start $1 _cfg=0 # XXX: not sure this should count fi diff --git a/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c b/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c index cf9d86a5d2a4..7769a8ed04ce 100644 --- a/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c +++ b/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c @@ -687,6 +687,7 @@ wpa_driver_bsd_init(void *ctx, const char *ifname) #define GETPARAM(drv, param, v) \ (((v) = get80211param(drv, param)) != -1) struct wpa_driver_bsd_data *drv; + int flags; drv = malloc(sizeof(*drv)); if (drv == NULL) @@ -707,15 +708,23 @@ wpa_driver_bsd_init(void *ctx, const char *ifname) drv->sock = socket(PF_INET, SOCK_DGRAM, 0); if (drv->sock < 0) goto fail1; + drv->ctx = ctx; + strncpy(drv->ifname, ifname, sizeof(drv->ifname)); + + /* + * Mark the interface as down to ensure wpa_supplicant has exclusive + * access to the net80211 state machine, do this before opening the + * route socket to avoid a false event that the interface disappeared. + */ + if (getifflags(drv, &flags) == 0) + (void) setifflags(drv, flags &~ IFF_UP); + drv->route = socket(PF_ROUTE, SOCK_RAW, 0); if (drv->route < 0) goto fail; eloop_register_read_sock(drv->route, wpa_driver_bsd_event_receive, ctx, drv); - drv->ctx = ctx; - strncpy(drv->ifname, ifname, sizeof(drv->ifname)); - if (!GETPARAM(drv, IEEE80211_IOC_ROAMING, drv->prev_roaming)) { wpa_printf(MSG_DEBUG, "%s: failed to get roaming state: %s", __func__, strerror(errno));