From patchwork Tue Oct 29 14:00:31 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kazior X-Patchwork-Id: 286857 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 AA5942C035D for ; Wed, 30 Oct 2013 01:03:55 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 830989D23F; Tue, 29 Oct 2013 10:03:50 -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 W7y-TH3W8QNE; Tue, 29 Oct 2013 10:03:50 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 950979C15B; Tue, 29 Oct 2013 10:03:32 -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 99C299C0E6 for ; Tue, 29 Oct 2013 10:03:30 -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 PfAcoZrugTT1 for ; Tue, 29 Oct 2013 10:03:25 -0400 (EDT) Received: from mail-ee0-f51.google.com (mail-ee0-f51.google.com [74.125.83.51]) (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 02C049C126 for ; Tue, 29 Oct 2013 10:03:24 -0400 (EDT) Received: by mail-ee0-f51.google.com with SMTP id d41so4075313eek.24 for ; Tue, 29 Oct 2013 07:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tieto.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=P8qG34cVrhysgAtbMcbTs3zojHFhmJ/sDvzQnwpZAr4=; b=zt3+9fVLfImx5V56ZbMn+WQJBTi7z1ZR79jTd73rDxTAQcXaCamjqrXeAWJdQnoiLj 1m8vjE8dktayEYnnb34VLN8kUsekn8WxvUhUCljPU8LzDVNmSiI0X0aymIFBAe1zxwyp JMDl3dotQ1QmtxvRF6DzcSc+brnE4YCmMLa2U= 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:in-reply-to :references; bh=P8qG34cVrhysgAtbMcbTs3zojHFhmJ/sDvzQnwpZAr4=; b=OG6Yyc3w3sEKVKxFbqnS2H3vJ7CMLgckBFAwCDbO0Cptq9J6qtx2hWERiULbC7OICA 5UOKhjvlUF1GI423xEESKkVKrywM1w5v6jiPKpKp/L2pXRZdAae7z35ysMideBiaNfUG NugsMPr9BeujhpRN0sIpSuZ12AblSraeI7V1EBV79e86C+fdsxtdFaOTJtSzLT+bpq3i A3eWeh3KRW6SX1bFo+L+SOL/gvDE7a617gAz6nS2ROqNIxAhe5EEs3zJwdNGhUEr8qAl jDaxajBSlkcFxA6fI4zT33dylMpA9o2sjXOnf5bi5KtfBlhhtWVUY3Cnl2egvpznjzrZ hyLQ== X-Gm-Message-State: ALoCoQnjzLxtthUE9utED6COmoRqDAVFnQZVZ2uwDJ8Bb0916I/r3DBaRxdgqKjEs7Qu/ebgNz2Bs7E0Wz9IpyumnnI/W4rpBE39UJK6yH0xPpzvs78Wutg= X-Received: by 10.15.68.198 with SMTP id w46mr2837319eex.108.1383055403913; Tue, 29 Oct 2013 07:03:23 -0700 (PDT) Received: from localhost.localdomain ([91.198.246.8]) by mx.google.com with ESMTPSA id e13sm70708371eeu.4.2013.10.29.07.03.23 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Oct 2013 07:03:23 -0700 (PDT) From: Michal Kazior To: hostap@lists.shmoo.com Subject: [PATCH 1/4] hostapd: DFS: fix HT40/VHT calcuation Date: Tue, 29 Oct 2013 15:00:31 +0100 Message-Id: <1383055234-23177-2-git-send-email-michal.kazior@tieto.com> X-Mailer: git-send-email 1.8.4.rc3 In-Reply-To: <1383055234-23177-1-git-send-email-michal.kazior@tieto.com> References: <1383055234-23177-1-git-send-email-michal.kazior@tieto.com> X-DomainID: tieto.com Cc: j@w1.fi 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 Decouple HT/VHT offset/center-freq calculations from channel lookup. This will be necessary for further improvements on the DFS codebase. Signed-hostap: Michal Kazior --- src/ap/dfs.c | 96 +++++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 30 deletions(-) diff --git a/src/ap/dfs.c b/src/ap/dfs.c index a30861f..6a16306 100644 --- a/src/ap/dfs.c +++ b/src/ap/dfs.c @@ -94,6 +94,13 @@ static int dfs_is_chan_allowed(struct hostapd_channel_data *chan, int n_chans) } +/* + * The function assumes HT40+ operation. + * Make sure to adjust the following variables after calling this: + * - hapd->secondary_channel + * - hapd->vht_oper_centr_freq_seg0_idx + * - hapd->vht_oper_centr_freq_seg1_idx + */ static int dfs_find_channel(struct hostapd_data *hapd, struct hostapd_channel_data **ret_chan, int idx) @@ -126,9 +133,6 @@ static int dfs_find_channel(struct hostapd_data *hapd, } if (j != n_chans) continue; - - /* Set HT40+ */ - hapd->iconf->secondary_channel = 1; } if (ret_chan && idx == channel_idx) { @@ -144,7 +148,9 @@ static int dfs_find_channel(struct hostapd_data *hapd, static void dfs_adjust_vht_center_freq(struct hostapd_data *hapd, - struct hostapd_channel_data *chan) + struct hostapd_channel_data *chan, + u8 *vht_oper_centr_freq_seg0_idx, + u8 *vht_oper_centr_freq_seg1_idx) { if (!hapd->iconf->ieee80211ac) return; @@ -152,31 +158,31 @@ static void dfs_adjust_vht_center_freq(struct hostapd_data *hapd, if (!chan) return; + *vht_oper_centr_freq_seg1_idx = 0; + switch (hapd->iconf->vht_oper_chwidth) { case VHT_CHANWIDTH_USE_HT: if (hapd->iconf->secondary_channel == 1) - hapd->iconf->vht_oper_centr_freq_seg0_idx = - chan->chan + 2; + *vht_oper_centr_freq_seg0_idx = chan->chan + 2; else if (hapd->iconf->secondary_channel == -1) - hapd->iconf->vht_oper_centr_freq_seg0_idx = - chan->chan - 2; + *vht_oper_centr_freq_seg0_idx = chan->chan - 2; else - hapd->iconf->vht_oper_centr_freq_seg0_idx = chan->chan; + *vht_oper_centr_freq_seg0_idx = chan->chan; break; case VHT_CHANWIDTH_80MHZ: - hapd->iconf->vht_oper_centr_freq_seg0_idx = chan->chan + 6; + *vht_oper_centr_freq_seg0_idx = chan->chan + 6; break; case VHT_CHANWIDTH_160MHZ: - hapd->iconf->vht_oper_centr_freq_seg0_idx = - chan->chan + 14; + *vht_oper_centr_freq_seg0_idx = chan->chan + 14; break; default: wpa_printf(MSG_INFO, "DFS only VHT20/40/80/160 is supported now"); break; } - wpa_printf(MSG_DEBUG, "DFS adjusting VHT center frequency: %d", - hapd->iconf->vht_oper_centr_freq_seg0_idx); + wpa_printf(MSG_DEBUG, "DFS adjusting VHT center frequency: %d, %d", + *vht_oper_centr_freq_seg0_idx, + *vht_oper_centr_freq_seg1_idx); } @@ -295,12 +301,16 @@ static int dfs_check_chans_unavailable(struct hostapd_data *hapd, } -static struct hostapd_channel_data * dfs_get_valid_channel( - struct hostapd_data *hapd) +static struct hostapd_channel_data * +dfs_get_valid_channel(struct hostapd_data *hapd, + int *secondary_channel, + u8 *vht_oper_centr_freq_seg0_idx, + u8 *vht_oper_centr_freq_seg1_idx) { struct hostapd_hw_modes *mode; struct hostapd_channel_data *chan = NULL; - int channel_idx, new_channel_idx; + int num_available_chandefs; + int chan_idx; u32 _rand; wpa_printf(MSG_DEBUG, "DFS: Selecting random channel"); @@ -312,16 +322,24 @@ static struct hostapd_channel_data * dfs_get_valid_channel( if (mode->mode != HOSTAPD_MODE_IEEE80211A) return NULL; - /* get random available channel */ - channel_idx = dfs_find_channel(hapd, NULL, 0); - if (channel_idx > 0) { - os_get_random((u8 *) &_rand, sizeof(_rand)); - new_channel_idx = _rand % channel_idx; - dfs_find_channel(hapd, &chan, new_channel_idx); - } + /* Get the count first */ + num_available_chandefs = dfs_find_channel(hapd, NULL, 0); + if (num_available_chandefs == 0) + return NULL; - /* VHT */ - dfs_adjust_vht_center_freq(hapd, chan); + os_get_random((u8 *) &_rand, sizeof(_rand)); + chan_idx = _rand % num_available_chandefs; + dfs_find_channel(hapd, &chan, chan_idx); + + /* dfs_find_channel() calculations assume HT40+ */ + if (hapd->iconf->secondary_channel) + *secondary_channel = 1; + else + *secondary_channel = 0; + + dfs_adjust_vht_center_freq(hapd, chan, + vht_oper_centr_freq_seg0_idx, + vht_oper_centr_freq_seg1_idx); return chan; } @@ -513,13 +531,20 @@ int hostapd_handle_dfs(struct hostapd_data *hapd) wpa_printf(MSG_DEBUG, "DFS %d chans unavailable - choose other channel: %s", res, res ? "yes": "no"); if (res) { - channel = dfs_get_valid_channel(hapd); + int sec; + u8 cf1, cf2; + + channel = dfs_get_valid_channel(hapd, &sec, &cf1, &cf2); if (!channel) { wpa_printf(MSG_ERROR, "could not get valid channel"); return -1; } - hapd->iconf->channel = channel->chan; + hapd->iface->freq = channel->freq; + hapd->iconf->channel = channel->chan; + hapd->iconf->secondary_channel = sec; + hapd->iconf->vht_oper_centr_freq_seg0_idx = cf1; + hapd->iconf->vht_oper_centr_freq_seg1_idx = cf2; } } while (res); @@ -563,13 +588,24 @@ static int hostapd_dfs_start_channel_switch(struct hostapd_data *hapd) { struct hostapd_channel_data *channel; int err = 1; + int secondary_channel; + u8 vht_oper_centr_freq_seg0_idx; + u8 vht_oper_centr_freq_seg1_idx; wpa_printf(MSG_DEBUG, "%s called", __func__); - channel = dfs_get_valid_channel(hapd); + channel = dfs_get_valid_channel(hapd, &secondary_channel, + &vht_oper_centr_freq_seg0_idx, + &vht_oper_centr_freq_seg1_idx); if (channel) { hapd->iconf->channel = channel->chan; - hapd->iface->freq = channel->freq; + hapd->iconf->secondary_channel = secondary_channel; + hapd->iconf->vht_oper_centr_freq_seg0_idx = + vht_oper_centr_freq_seg0_idx; + hapd->iconf->vht_oper_centr_freq_seg1_idx = + vht_oper_centr_freq_seg1_idx; err = 0; + } else { + wpa_printf(MSG_ERROR, "No valid channel available"); } if (!hapd->cac_started) {