From patchwork Thu Jun 26 20:13:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christopher Wiley X-Patchwork-Id: 364709 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from maxx.maxx.shmoo.com (maxx.shmoo.com [205.134.188.171]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id ADA5F1400B5 for ; Fri, 27 Jun 2014 06:14:31 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 0E0159C217; Thu, 26 Jun 2014 16:14:26 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id xLaynspFwotY; Thu, 26 Jun 2014 16:14:25 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 3234017C030; Thu, 26 Jun 2014 16:14:05 -0400 (EDT) X-Original-To: mailman-post+hostap@maxx.shmoo.com Delivered-To: mailman-post+hostap@maxx.shmoo.com Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 1BD889C217 for ; Thu, 26 Jun 2014 16:14:04 -0400 (EDT) X-Virus-Scanned: amavisd-new at maxx.shmoo.com Received: from maxx.maxx.shmoo.com ([127.0.0.1]) by localhost (maxx.shmoo.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aHtG4WaVN5Z2 for ; Thu, 26 Jun 2014 16:13:57 -0400 (EDT) Received: from mail-oa0-f73.google.com (mail-oa0-f73.google.com [209.85.219.73]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id BEDD59C230 for ; Thu, 26 Jun 2014 16:13:42 -0400 (EDT) Received: by mail-oa0-f73.google.com with SMTP id eb12so911536oac.4 for ; Thu, 26 Jun 2014 13:13:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fe9E52FdBw/yAuU+1T4qH6hAdXOQEigPaNqUdYs1Mao=; b=kUATTPbDCCHX5mQW1Q4xpNbE2CBKyFjXD+882gLf0LhXZbUavur+hbJtWZMUQbLfyn 7dVtmHLDphciIHJbVdheo+nKMkxaoAbyVFQIL+M8LIx7s0Lk89VzZit6dDYDPAw6i/cC eSri+zMND4BBkhZADDIPbGaz/QTHTGdovyPdO0C7j9l8MDxzYxy+VP2VULN8iWulBJqe kL7IjYaaXUma4+2h4RpmUS14mYEiCcPf2FK574uH4x0DnAoUDm2FQXivnY7SPJqIdxNQ MKssjp1R6lfYt6zfV/g2lkaoS+wkltChVzyftFYg6YEUfuenNG6ypO/bNfip7adzuO3i 4WmA== X-Gm-Message-State: ALoCoQlVWtvRNAghbQzqkv7EU+ZAdN00dqTpXdRUazwDnCPtDRDYlXxU8wGXG3MkmQZFKNxzCFX9 X-Received: by 10.50.41.3 with SMTP id b3mr136893igl.0.1403813621794; Thu, 26 Jun 2014 13:13:41 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id j43si629520yhh.5.2014.06.26.13.13.41 for (version=TLSv1.1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Jun 2014 13:13:41 -0700 (PDT) Received: from mintyfresh.mtv.corp.google.com (mintyfresh.mtv.corp.google.com [172.22.73.124]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 9FF5D5A46FF; Thu, 26 Jun 2014 13:13:41 -0700 (PDT) Received: by mintyfresh.mtv.corp.google.com (Postfix, from userid 55395) id 4A6B51005C0; Thu, 26 Jun 2014 13:13:41 -0700 (PDT) From: Christopher Wiley To: hostap@lists.shmoo.com Subject: [PATCH 1/2] Refactor nl80211 mode switch logic Date: Thu, 26 Jun 2014 13:13:06 -0700 Message-Id: <1403813587-13731-1-git-send-email-wiley@chromium.org> X-Mailer: git-send-email 2.0.0.526.g5318336 X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.11 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com In preparation for another wrinkle around switching into IBSS mode, refactor existing mode switch logic for simplicity at the expense of some brevity. Signed-off-by: Christopher Wiley --- src/drivers/driver_nl80211.c | 45 ++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index c154ec2..0f4b37c 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -9043,18 +9043,19 @@ static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, int i; int was_ap = is_ap_interface(drv->nlmode); int res; + int mode_switch_res; - res = nl80211_set_mode(drv, drv->ifindex, nlmode); - if (res && nlmode == nl80211_get_ifmode(bss)) - res = 0; + mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); + if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) + mode_switch_res = 0; - if (res == 0) { + if (mode_switch_res == 0) { drv->nlmode = nlmode; ret = 0; goto done; } - if (res == -ENODEV) + if (mode_switch_res == -ENODEV) return -1; if (nlmode == drv->nlmode) { @@ -9071,24 +9072,24 @@ static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " "interface down"); for (i = 0; i < 10; i++) { + os_sleep(0, 100000); res = i802_set_iface_flags(bss, 0); if (res == -EACCES || res == -ENODEV) break; - if (res == 0) { - /* Try to set the mode again while the interface is - * down */ - ret = nl80211_set_mode(drv, drv->ifindex, nlmode); - if (ret == -EACCES) - break; - res = i802_set_iface_flags(bss, 1); - if (res && !ret) - ret = -1; - else if (ret != -EBUSY) - break; - } else + if (res != 0) { wpa_printf(MSG_DEBUG, "nl80211: Failed to set " "interface down"); - os_sleep(0, 100000); + continue; + } + /* Try to set the mode again while the interface is down */ + mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); + if (mode_switch_res == -EBUSY) { + wpa_printf(MSG_DEBUG, "nl80211: Delaying mode set " + "while interface going down."); + continue; + } + ret = mode_switch_res; + break; } if (!ret) { @@ -9098,6 +9099,14 @@ static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, drv->ignore_if_down_event = 1; } + /* Bring the interface back up */ + res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); + if (res != 0) { + wpa_printf(MSG_DEBUG, "nl80211: Failed to set " + "interface up after switching mode."); + ret = -1; + } + done: if (ret) { wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "