From patchwork Fri Nov 4 10:37:57 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 123593 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 DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "maxx.shmoo.com", Issuer "CA Cert Signing Authority" (not verified)) by ozlabs.org (Postfix) with ESMTPS id CEB6BB6F0E for ; Fri, 4 Nov 2011 21:41:54 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 813B917C062; Fri, 4 Nov 2011 06:41:52 -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 0vCwQ-3tWN7f; Fri, 4 Nov 2011 06:41:52 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 6DEDE9D30E; Fri, 4 Nov 2011 06:40:18 -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 2E10C17C01A for ; Fri, 4 Nov 2011 06:40:17 -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 vGI0F848g3Tv for ; Fri, 4 Nov 2011 06:40:12 -0400 (EDT) Received: from sipsolutions.net (he.sipsolutions.net [78.46.109.217]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id A129C9D2D2 for ; Fri, 4 Nov 2011 06:39:32 -0400 (EDT) Received: by sipsolutions.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.77) (envelope-from ) id 1RMHBL-0001H8-KR for hostap@lists.shmoo.com; Fri, 04 Nov 2011 11:39:31 +0100 Message-Id: <20111104103810.324394160@sipsolutions.net> User-Agent: quilt/0.48-1 Date: Fri, 04 Nov 2011 11:37:57 +0100 From: Johannes Berg To: hostap@lists.shmoo.com Subject: [PATCH 08/18] driver_nl80211: move AP SME setup to mode change References: <20111104103749.617144560@sipsolutions.net> Content-Disposition: inline; filename=0008-driver_nl80211-move-AP-SME-setup-to-mode-change.patch Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 X-BeenThere: hostap@lists.shmoo.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: HostAP Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com From: Johannes Berg Signed-hostap: Johannes Berg --- src/drivers/driver_nl80211.c | 84 ++++++++++++++++++++++++++--------------- 1 files changed, 53 insertions(+), 31 deletions(-) diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c index 9362c59..31fd147 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -242,6 +242,7 @@ struct wpa_driver_nl80211_data { int monitor_sock; int monitor_ifidx; + int monitor_refcount; unsigned int disabled_11b_rates:1; unsigned int pending_remain_on_chan:1; @@ -5148,6 +5149,10 @@ static int add_monitor_filter(int s) static void nl80211_remove_monitor_interface( struct wpa_driver_nl80211_data *drv) { + drv->monitor_refcount--; + if (drv->monitor_refcount > 0) + return; + if (drv->monitor_ifidx >= 0) { nl80211_remove_iface(drv, drv->monitor_ifidx); drv->monitor_ifidx = -1; @@ -5168,6 +5173,11 @@ nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) int optval; socklen_t optlen; + if (drv->monitor_ifidx > 0) { + drv->monitor_refcount++; + return 0; + } + if (os_strncmp(drv->first_bss.ifname, "p2p-", 4) == 0) { /* * P2P interface name is of the format p2p-%s-%d. For monitor @@ -5246,6 +5256,38 @@ nl80211_create_monitor_interface(struct wpa_driver_nl80211_data *drv) } +static int nl80211_setup_ap(struct i802_bss *bss) +{ + struct wpa_driver_nl80211_data *drv = bss->drv; + + if (!drv->device_ap_sme && + nl80211_create_monitor_interface(drv) && + !drv->device_ap_sme) + return -1; + + if (drv->device_ap_sme && + wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { + wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " + "Probe Request frame reporting in AP mode"); + /* Try to survive without this */ + } + + return 0; +} + + +static void nl80211_teardown_ap(struct i802_bss *bss) +{ + struct wpa_driver_nl80211_data *drv = bss->drv; + + if (drv->device_ap_sme) + wpa_driver_nl80211_probe_req_report(bss, 0); + else + nl80211_remove_monitor_interface(drv); + bss->beacon_set = 0; +} + + static int nl80211_send_eapol_data(struct i802_bss *bss, const u8 *addr, const u8 *data, size_t data_len) @@ -5417,15 +5459,6 @@ static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, return -1; } - if (drv->device_ap_sme) { - if (wpa_driver_nl80211_probe_req_report(&drv->first_bss, 1) < 0) - { - wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " - "Probe Request frame reporting in AP mode"); - /* Try to survive without this */ - } - } - drv->ap_oper_freq = params->freq; return 0; @@ -5976,33 +6009,22 @@ static int wpa_driver_nl80211_set_mode(struct i802_bss *bss, } done: - if (!ret && is_ap_interface(nlmode)) { + if (ret) { + wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " + "from %d failed", nlmode, drv->nlmode); + return ret; + } + + if (is_ap_interface(nlmode)) { /* Setup additional AP mode functionality if needed */ - if (!drv->device_ap_sme && drv->monitor_ifidx < 0 && - nl80211_create_monitor_interface(drv) && - !drv->device_ap_sme) + if (nl80211_setup_ap(bss)) return -1; - } else if (!ret && !is_ap_interface(nlmode)) { + } else if (was_ap) { /* Remove additional AP mode functionality */ - if (was_ap && drv->device_ap_sme) - wpa_driver_nl80211_probe_req_report(bss, 0); - nl80211_remove_monitor_interface(drv); - bss->beacon_set = 0; - } - - if (!ret && is_p2p_interface(drv->nlmode)) { - nl80211_disable_11b_rates(drv, drv->ifindex, 1); - drv->disabled_11b_rates = 1; - } else if (!ret && drv->disabled_11b_rates) { - nl80211_disable_11b_rates(drv, drv->ifindex, 0); - drv->disabled_11b_rates = 0; + nl80211_teardown_ap(bss); } - if (ret) - wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " - "from %d failed", nlmode, drv->nlmode); - - return ret; + return 0; }