[PATCH v2] wext: handle mode switches correctly for mac80211

Dan Williams dcbw
Fri Aug 29 09:57:49 PDT 2008

On Wed, 2008-06-04 at 21:02 +0300, Jouni Malinen wrote:
> On Wed, Jun 04, 2008 at 01:36:23PM -0400, Dan Williams wrote:
> > Since mac80211 requires that the device be !IFF_UP to change the mode
> > (and I think the old prism54 fullmac driver does too), do that.  This
> > shouldn't harm fullmac devices since they can handle mode switches on
> > the fly and usually don't care about up/down that much.
> Thanks! Applied.

A bug just got reported as a result of this for mac80211 drivers.


The basic problem is that since taking the device down clears the keys
from the driver on many mac80211-based cards, and since the mode gets
set _after_ the keys have been set in the driver, the keys get cleared
on a mode switch and the resulting association is wrong.  The report is
about ad-hoc mode specifically, but this could happen when switching
from adhoc back to managed mode.

Fabrice suggested using WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC for the
driver, but it seems to me that setting the mode as _early_ as possible
is the best thing to do.  Perhaps create another driver hook for
set_mode and call that (if needed) very early in
wpa_supplicant_associate() around line 924:

	/* Starting new association, so clear the possibly used WPA IE from the
	 * previous association. */
	wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);

+	wpa_drv_set_mode(wpa_s, ssid->mode);

#ifdef IEEE8021X_EAPOL
	if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
		if (ssid->leap) {

I can't think of a reason why setting the mode first isn't the right
thing to do in the first place.  Thoughts?  I'll cook up a patch for
this if it sounds OK.


More information about the Hostap mailing list