From patchwork Mon Jul 29 09:19:11 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Kazior X-Patchwork-Id: 262704 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 A16D32C0092 for ; Mon, 29 Jul 2013 19:54:04 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 9DE8717CA21; Mon, 29 Jul 2013 05:54:02 -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 GLV6Yoze2cKv; Mon, 29 Jul 2013 05:54:02 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id 8350C17CADB; Mon, 29 Jul 2013 05:53:55 -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 812B517C93D for ; Mon, 29 Jul 2013 05:40:18 -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 7vmXoMGTlLgS for ; Mon, 29 Jul 2013 05:40:12 -0400 (EDT) Received: from ebb06.tieto.com (ebb06.tieto.com [131.207.168.38]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "ebb06.tieto.com", Issuer "VeriSign Class 3 Secure Server CA - G3" (not verified)) by maxx.maxx.shmoo.com (Postfix) with ESMTPS id 4E16017CADB for ; Mon, 29 Jul 2013 05:20:53 -0400 (EDT) X-AuditID: 83cfa826-b7f958e000001030-75-51f633f3b5c4 Received: from FIHGA-EXHUB01.eu.tieto.com ( [131.207.136.34]) by ebb06.tieto.com (SMTP Mailer) with SMTP id 58.C0.04144.3F336F15; Mon, 29 Jul 2013 12:20:51 +0300 (EEST) Received: from uw001058.eu.tieto.com (10.28.19.57) by inbound.tieto.com (131.207.136.49) with Microsoft SMTP Server id 8.3.298.1; Mon, 29 Jul 2013 12:20:50 +0300 From: Michal Kazior To: Subject: [RFC v2 1/4] hostapd: Split up channel checking into helpers Date: Mon, 29 Jul 2013 11:19:11 +0200 Message-ID: <1375089554-5885-2-git-send-email-michal.kazior@tieto.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1375089554-5885-1-git-send-email-michal.kazior@tieto.com> References: <1374750707-8187-1-git-send-email-michal.kazior@tieto.com> <1375089554-5885-1-git-send-email-michal.kazior@tieto.com> MIME-Version: 1.0 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAIsWRmVeSWpSXmKPExsXSfL5DSfez8bdAg82vJC0WNT1gsvi29QGb A5PH55l32Tx2n9rHEsAUxWWTkpqTWZZapG+XwJXx9vUj9oI/RhV3u60bGC+odTFyckgImEhs mbmfEcIWk7hwbz1bFyMXh5DAKkaJ1mdn2SGcpYwSp6f0g1WxCehKvGo8ywpiiwjISLzc/IsF xGYW0JZof3MdKM7BISzgKjFhviRImEVAVeLyjN3sIDavgJvE+n2PWEBKJAQUJOZMsgEJcwq4 SyxoOcEEsaqZUeLlvPUsEPWCEidnPoEaLyFx8MULZhBbSEBF4uD6/cwTGAVmISmbhaRsASPT Kkb+1KQkAzO9kszUkny95PzcTYzggFuhtoPx2QOpQ4wCHIxKPLwvPb8ECrEmlhVX5h5ilORg UhLlPWr0LVCILyk/pTIjsTgjvqg0J7X4EKMEB7OSCC+H0ddAId6UxMqq1KJ8mJQ0B4uSOK/R +nuBQgLpiSWp2ampBalFMFkZDg4lCd7JIEMFi1LTUyvSMnNKENJMHJwgw3mAhr8CqeEtLkjM Lc5Mh8ifYlSUEuctBEkIgCQySvPgemEJ4RWjONArwrxVIFU8wGQC1/0KaDAT0ODdKmCDSxIR UlINjCtmPO6c4/TbrunrElZv7+iyFq2TYlP/2X2Jkvrqxcri9PR2d2uMpG+pLGMo16bcpKrX 4tN1t3+Z4BY0r+PT5ZyyYDvGOzW+m9qqo67K8+36aF268PL6GRc92H0/ec6rf3Qv2UpKgJvl jQkfP59VxPLkYgPVXUuDFFjOy33+sCj49V6joLmXlFiKMxINtZiLihMBJ6wq6eMCAAA= 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: , Sender: hostap-bounces@lists.shmoo.com Errors-To: hostap-bounces@lists.shmoo.com This splits up the channel checking upon initialization into a few helpers. This should make this a bit easier to follow. This also paves the way for some initial ACS entry code. Signed-hostap: Michal Kazior --- src/ap/hostapd.h | 5 ++ src/ap/hw_features.c | 162 +++++++++++++++++++++++++++----------------------- 2 files changed, 94 insertions(+), 73 deletions(-) diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 75d9c66..c0b1306 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -47,6 +47,11 @@ struct hapd_interfaces { struct hostapd_dynamic_iface **dynamic_iface; }; +enum hostapd_chan_status { + HOSTAPD_CHAN_VALID = 0, /* channel is ready */ + HOSTAPD_CHAN_INVALID = 1, /* no usable channel found */ + HOSTAPD_CHAN_ACS = 2, /* ACS work being performed */ +}; struct hostapd_probereq_cb { int (*cb)(void *ctx, const u8 *sa, const u8 *da, const u8 *bssid, diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c index 37112bd..424229b 100644 --- a/src/ap/hw_features.c +++ b/src/ap/hw_features.c @@ -634,6 +634,87 @@ int hostapd_check_ht_capab(struct hostapd_iface *iface) } +static int hostapd_is_usable_chan(struct hostapd_iface *iface, + int channel, int primary) +{ + int i; + struct hostapd_channel_data *chan; + + for (i = 0; i < iface->current_mode->num_channels; i++) { + chan = &iface->current_mode->channels[i]; + if (chan->chan == iface->conf->channel) { + if (chan->flag & HOSTAPD_CHAN_DISABLED) { + wpa_printf(MSG_ERROR, + "%schannel [%i] (%i) is disabled for " + "use in AP mode, flags: 0x%x%s%s%s", + primary ? "" : + "Configured HT40 secondary", + i, chan->chan, chan->flag, + chan->flag & HOSTAPD_CHAN_NO_IBSS ? + " NO-IBSS" : "", + chan->flag & + HOSTAPD_CHAN_PASSIVE_SCAN ? + " PASSIVE-SCAN" : "", + chan->flag & HOSTAPD_CHAN_RADAR ? + " RADAR" : ""); + } else { + return 1; + } + } + } + + return 0; +} + + +static int hostapd_is_usable_chans(struct hostapd_iface *iface) +{ + if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1)) + return 0; + + if (!iface->conf->secondary_channel) + return 1; + + if (!hostapd_is_usable_chan(iface, iface->conf->secondary_channel, 0)) + return 0; + + return 1; +} + + +static enum hostapd_chan_status +hostapd_check_chans(struct hostapd_iface *iface) +{ + if (iface->conf->channel) { + if (hostapd_is_usable_chans(iface)) + return HOSTAPD_CHAN_VALID; + else + return HOSTAPD_CHAN_INVALID; + } + + /* + * The user set channel=0 which is used to trigger ACS, + * which we do not yet support. + */ + return HOSTAPD_CHAN_INVALID; +} + +static void hostapd_notify_bad_chans(struct hostapd_iface *iface) +{ + hostapd_logger(iface->bss[0], NULL, + HOSTAPD_MODULE_IEEE80211, + HOSTAPD_LEVEL_WARNING, + "Configured channel (%d) not found from the " + "channel list of current mode (%d) %s", + iface->conf->channel, + iface->current_mode->mode, + hostapd_hw_mode_txt(iface->current_mode->mode)); + hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, + HOSTAPD_LEVEL_WARNING, + "Hardware does not support configured channel"); +} + + /** * hostapd_select_hw_mode - Select the hardware mode * @iface: Pointer to interface data. @@ -644,7 +725,7 @@ int hostapd_check_ht_capab(struct hostapd_iface *iface) */ int hostapd_select_hw_mode(struct hostapd_iface *iface) { - int i, j, ok; + int i; if (iface->num_hw_features < 1) return -1; @@ -669,80 +750,15 @@ int hostapd_select_hw_mode(struct hostapd_iface *iface) return -2; } - ok = 0; - for (j = 0; j < iface->current_mode->num_channels; j++) { - struct hostapd_channel_data *chan = - &iface->current_mode->channels[j]; - if (chan->chan == iface->conf->channel) { - if (chan->flag & HOSTAPD_CHAN_DISABLED) { - wpa_printf(MSG_ERROR, - "channel [%i] (%i) is disabled for " - "use in AP mode, flags: 0x%x%s%s%s", - j, chan->chan, chan->flag, - chan->flag & HOSTAPD_CHAN_NO_IBSS ? - " NO-IBSS" : "", - chan->flag & - HOSTAPD_CHAN_PASSIVE_SCAN ? - " PASSIVE-SCAN" : "", - chan->flag & HOSTAPD_CHAN_RADAR ? - " RADAR" : ""); - } else { - ok = 1; - break; - } - } - } - if (ok && iface->conf->secondary_channel) { - int sec_ok = 0; - int sec_chan = iface->conf->channel + - iface->conf->secondary_channel * 4; - for (j = 0; j < iface->current_mode->num_channels; j++) { - struct hostapd_channel_data *chan = - &iface->current_mode->channels[j]; - if (!(chan->flag & HOSTAPD_CHAN_DISABLED) && - (chan->chan == sec_chan)) { - sec_ok = 1; - break; - } - } - if (!sec_ok) { - hostapd_logger(iface->bss[0], NULL, - HOSTAPD_MODULE_IEEE80211, - HOSTAPD_LEVEL_WARNING, - "Configured HT40 secondary channel " - "(%d) not found from the channel list " - "of current mode (%d) %s", - sec_chan, iface->current_mode->mode, - hostapd_hw_mode_txt( - iface->current_mode->mode)); - ok = 0; - } - } - if (iface->conf->channel == 0) { - /* TODO: could request a scan of neighboring BSSes and select - * the channel automatically */ - wpa_printf(MSG_ERROR, "Channel not configured " - "(hw_mode/channel in hostapd.conf)"); + switch (hostapd_check_chans(iface)) { + case HOSTAPD_CHAN_VALID: + return 0; + case HOSTAPD_CHAN_ACS: /* ACS not supported yet */ + case HOSTAPD_CHAN_INVALID: + default: + hostapd_notify_bad_chans(iface); return -3; } - if (ok == 0 && iface->conf->channel != 0) { - hostapd_logger(iface->bss[0], NULL, - HOSTAPD_MODULE_IEEE80211, - HOSTAPD_LEVEL_WARNING, - "Configured channel (%d) not found from the " - "channel list of current mode (%d) %s", - iface->conf->channel, - iface->current_mode->mode, - hostapd_hw_mode_txt(iface->current_mode->mode)); - iface->current_mode = NULL; - } - - if (iface->current_mode == NULL) { - hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, - HOSTAPD_LEVEL_WARNING, - "Hardware does not support configured channel"); - return -4; - } return 0; }