]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
nl80211: Try mode changes multiple times to avoid some races
authorJouni Malinen <jouni.malinen@atheros.com>
Sun, 18 Jul 2010 21:30:24 +0000 (14:30 -0700)
committerJouni Malinen <j@w1.fi>
Wed, 11 Aug 2010 15:01:37 +0000 (18:01 +0300)
cfg80211/mac80211 seems to be unwilling to change interface mode in
some cases. Make these less likely to cause problems by trying the
changes up to 10 times with 100 msec intervals.

src/drivers/driver_nl80211.c

index 9c02f7d9a16b2733b0ecd724a219183f46b1a7db..8b2c2795f0022bf1f76e5faa5923e2d24c81950d 100644 (file)
@@ -4069,6 +4069,7 @@ static int wpa_driver_nl80211_set_mode(void *priv, int mode)
        struct wpa_driver_nl80211_data *drv = bss->drv;
        int ret = -1;
        int nlmode;
+       int i;
 
        switch (mode) {
        case 0:
@@ -4101,11 +4102,23 @@ static int wpa_driver_nl80211_set_mode(void *priv, int mode)
         * take the device down, try to set the mode again, and bring the
         * device back up.
         */
-       if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0) == 0) {
-               /* Try to set the mode again while the interface is down */
-               ret = nl80211_set_mode(drv, drv->ifindex, nlmode);
-               if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 1))
-                       ret = -1;
+       wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
+                  "interface down");
+       for (i = 0; i < 10; i++) {
+               if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname, 0) ==
+                   0) {
+                       /* Try to set the mode again while the interface is
+                        * down */
+                       ret = nl80211_set_mode(drv, drv->ifindex, nlmode);
+                       if (linux_set_iface_flags(drv->ioctl_sock, bss->ifname,
+                                                 1))
+                               ret = -1;
+                       if (!ret)
+                               break;
+               } else
+                       wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
+                                  "interface down");
+               os_sleep(0, 100000);
        }
 
        if (!ret) {