From patchwork Sat Nov 19 12:39:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Berg X-Patchwork-Id: 126570 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 07845B7235 for ; Sat, 19 Nov 2011 23:41:57 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 6AD1E9D210; Sat, 19 Nov 2011 07:41:54 -0500 (EST) 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 ecwu0BDNBcOT; Sat, 19 Nov 2011 07:41:54 -0500 (EST) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 4B07F9C229; Sat, 19 Nov 2011 07:41:17 -0500 (EST) 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 B4DB39C20B for ; Sat, 19 Nov 2011 07:41:15 -0500 (EST) 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 OMr0zVoKoTgr for ; Sat, 19 Nov 2011 07:41:12 -0500 (EST) 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 CED0C9C182 for ; Sat, 19 Nov 2011 07:41:09 -0500 (EST) Received: by sipsolutions.net with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.77) (envelope-from ) id 1RRkEG-0002cH-QN for hostap@lists.shmoo.com; Sat, 19 Nov 2011 13:41:08 +0100 Message-Id: <20111119123950.257383639@sipsolutions.net> User-Agent: quilt/0.48-1 Date: Sat, 19 Nov 2011 13:39:13 +0100 From: Johannes Berg To: hostap@lists.shmoo.com Subject: [PATCH v3 03/15] driver_nl80211: move AP SME setup to mode change References: <20111119123910.783418920@sipsolutions.net> Content-Disposition: inline; filename=0003-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 a1a379e..ccb4329 100644 --- a/src/drivers/driver_nl80211.c +++ b/src/drivers/driver_nl80211.c @@ -223,6 +223,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; @@ -5133,6 +5134,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; @@ -5153,6 +5158,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 @@ -5231,6 +5241,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) @@ -5404,15 +5446,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; @@ -5964,33 +5997,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; }