From patchwork Mon Oct 7 06:30:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janusz.Dziedzic@tieto.com X-Patchwork-Id: 280928 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 2A6F92C00C7 for ; Mon, 7 Oct 2013 17:31:03 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id CF0869D21A; Mon, 7 Oct 2013 02:30:56 -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 lqow0erwP6bc; Mon, 7 Oct 2013 02:30:56 -0400 (EDT) Received: from maxx.shmoo.com (localhost [127.0.0.1]) by maxx.maxx.shmoo.com (Postfix) with ESMTP id C461A9D21B; Mon, 7 Oct 2013 02:30:44 -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 F1A4A9C34F for ; Mon, 7 Oct 2013 02:30:40 -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 MenB3RlQ5hIa for ; Mon, 7 Oct 2013 02:30:36 -0400 (EDT) Received: from mail-ea0-f173.google.com (mail-ea0-f173.google.com [209.85.215.173]) (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 B015B9D218 for ; Mon, 7 Oct 2013 02:30:35 -0400 (EDT) Received: by mail-ea0-f173.google.com with SMTP id g10so2991302eak.18 for ; Sun, 06 Oct 2013 23:30:34 -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=zTDjvO7VEh4sBBL2L4cynOk/Bhc6J6Eh+Lhp6x0SUZk=; b=mex6lRNvUYCXBdQDMkL3HZdWyUndqveSwWjYaC1RzBkBpVVUkHEWzXNJfOUB/WUYdV YuiNKdEWWshlkKr2YPj+jdmD5yim/ek/4aXRAR5EIaW8DPCicGzRfILilVojL52gSZox DbjTrspG9Rq0GfbSSODmjwKzu1eWPuBT+BzBc= 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=zTDjvO7VEh4sBBL2L4cynOk/Bhc6J6Eh+Lhp6x0SUZk=; b=NbZobFDMpZPskiZao+4Kb554h0vdMFWy29ileWLzTWgGGu5oRWE14geyKjZjM1+p83 jPPREQrgB7dPjMokyBKZpj1akfuSn9Pf6h5WeMOLuWSQjd/jVqOa33cQnxKrg1B3aeHj ATXZv9QwhUxYtHSdm4PEA+4ppX5LYz3/z/6e23E7LuSKO6Oc3963nyOtop9kVy8+hJUi XfdwCu6PkLvQyXs79O6RxSoHDifmFByGAGcwSvMf0SDilQM5k5LlwCq89ASYS7EQpM6v fmDpG7flU8QPN+8PXrA47/qu0stFqgoFqBODYhDydXr/9/kRHxHQozJ3rSvk5MrmkwvN r87w== X-Gm-Message-State: ALoCoQnKcdfhAfTCelQbIDAMI9UCfDdJh9SO/T+MGvsrYbEt61avIFhe4cXWEgEQwe4N1oU5vx7wyJuK/4YdGCmkrYeJK0n7eVe0dkX/QgHUJaGesnrTmgo= X-Received: by 10.15.76.196 with SMTP id n44mr529626eey.66.1381127434504; Sun, 06 Oct 2013 23:30:34 -0700 (PDT) Received: from localhost.localdomain ([91.198.246.8]) by mx.google.com with ESMTPSA id m54sm59432467eex.2.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 06 Oct 2013 23:30:33 -0700 (PDT) From: Janusz Dziedzic To: hostap@lists.shmoo.com Subject: [PATCH v2 2/3] hostapd: move DFS code to dfs.c/dfs.h Date: Mon, 7 Oct 2013 08:30:08 +0200 Message-Id: <1381127409-2835-2-git-send-email-janusz.dziedzic@tieto.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1381127409-2835-1-git-send-email-janusz.dziedzic@tieto.com> References: <1381127409-2835-1-git-send-email-janusz.dziedzic@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 Move DFS code to dfs.c and dfs.h files. Signed-hostap: Janusz Dziedzic --- hostapd/Makefile | 1 + src/ap/dfs.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++ src/ap/dfs.h | 15 +++++ src/ap/drv_callbacks.c | 2 +- src/ap/hostapd.c | 60 +------------------ src/ap/hostapd.h | 2 - src/ap/ieee802_11.c | 73 ------------------------ src/ap/ieee802_11.h | 4 +- wpa_supplicant/Makefile | 1 + 9 files changed, 166 insertions(+), 138 deletions(-) create mode 100644 src/ap/dfs.c create mode 100644 src/ap/dfs.h diff --git a/hostapd/Makefile b/hostapd/Makefile index fda4e4e..be80dab 100644 --- a/hostapd/Makefile +++ b/hostapd/Makefile @@ -54,6 +54,7 @@ OBJS += ../src/ap/preauth_auth.o OBJS += ../src/ap/pmksa_cache_auth.o OBJS += ../src/ap/ieee802_11_shared.o OBJS += ../src/ap/beacon.o +OBJS += ../src/ap/dfs.o OBJS_c = hostapd_cli.o ../src/common/wpa_ctrl.o ../src/utils/os_$(CONFIG_OS).o diff --git a/src/ap/dfs.c b/src/ap/dfs.c new file mode 100644 index 0000000..3388967 --- /dev/null +++ b/src/ap/dfs.c @@ -0,0 +1,146 @@ +/* + * DFS - Dynamic Frequency Selection + * Copyright (c) 2002-2013, Jouni Malinen + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ + +#include "utils/includes.h" +#include "utils/common.h" +#include "common/ieee802_11_defs.h" +#include "hostapd.h" +#include "ap_drv_ops.h" +#include "drivers/driver.h" + +static int hostapd_dfs_find_channel(struct hostapd_data *hapd, + struct hostapd_channel_data **ret_chan, + int idx) +{ + struct hostapd_hw_modes *mode; + struct hostapd_channel_data *chan; + int i, channel_idx = 0; + + mode = hapd->iface->current_mode; + + for (i = 0; i < mode->num_channels; i++) { + chan = &mode->channels[i]; + + if (chan->flag & HOSTAPD_CHAN_DISABLED) + continue; + + if (chan->flag & HOSTAPD_CHAN_RADAR && + chan->flag & HOSTAPD_CHAN_DFS_UNAVAILABLE) + continue; + + if (ret_chan && idx == channel_idx) { + wpa_printf(MSG_DEBUG, "Selected ch. #%d", chan->chan); + *ret_chan = chan; + return idx; + } + channel_idx++; + } + return channel_idx; +} + +struct hostapd_channel_data * hostapd_dfs_get_valid_channel( + struct hostapd_data *hapd) +{ + struct hostapd_hw_modes *mode; + struct hostapd_channel_data *chan = NULL; + int channel_idx, new_channel_idx; + u32 _rand; + + wpa_printf(MSG_DEBUG, "DFS: Selecting random channel"); + + if (hapd->iface->current_mode == NULL) + return NULL; + + mode = hapd->iface->current_mode; + if (mode->mode != HOSTAPD_MODE_IEEE80211A) + return NULL; + + /* get random available channel */ + channel_idx = hostapd_dfs_find_channel(hapd, NULL, 0); + if (channel_idx > 0) { + os_get_random((u8 *) &_rand, sizeof(_rand)); + new_channel_idx = _rand % channel_idx; + hostapd_dfs_find_channel(hapd, &chan, new_channel_idx); + }; + + return chan; +} + +int ieee802_11_set_dfs_state(struct hostapd_data *hapd, int freq, u32 state) +{ + struct hostapd_hw_modes *mode; + struct hostapd_channel_data *chan = NULL; + int i; + + mode = hapd->iface->current_mode; + if (mode == NULL) + return 0; + + if (mode->mode != HOSTAPD_MODE_IEEE80211A) { + wpa_printf(MSG_WARNING, "current_mode != IEEE80211A"); + return 0; + } + + for (i = 0; i < hapd->iface->current_mode->num_channels; i++) { + chan = &hapd->iface->current_mode->channels[i]; + if (chan->freq == freq) { + if (chan->flag & HOSTAPD_CHAN_RADAR) { + chan->flag &= ~HOSTAPD_CHAN_DFS_MASK; + chan->flag |= state; + return 1; /* Channel found */ + } + } + } + wpa_printf(MSG_WARNING, "Can't set DFS state for freq %d MHz", freq); + return 0; +} + +int ieee802_11_complete_cac(struct hostapd_data *hapd, int success, int freq) +{ + struct hostapd_channel_data *channel; + int err = 1; + + if (success) { + /* Complete iface/ap configuration */ + ieee802_11_set_dfs_state(hapd, freq, HOSTAPD_CHAN_DFS_AVAILABLE); + hostapd_setup_interface_complete(hapd->iface, 0); + } else { + /* Switch to new channel */ + ieee802_11_set_dfs_state(hapd, freq, HOSTAPD_CHAN_DFS_UNAVAILABLE); + channel = hostapd_dfs_get_valid_channel(hapd); + if (channel) { + hapd->iconf->channel = channel->chan; + hapd->iface->freq = channel->freq; + err = 0; + } else + wpa_printf(MSG_ERROR, "No valid channel available"); + + hostapd_setup_interface_complete(hapd->iface, err); + } + + return 0; +} + +int ieee802_11_start_channel_switch(struct hostapd_data *hapd) +{ + struct hostapd_channel_data *channel; + wpa_printf(MSG_DEBUG, "%s called\n", __func__); + int err = 1; + + channel = hostapd_dfs_get_valid_channel(hapd); + if (channel) { + hapd->iconf->channel = channel->chan; + hapd->iface->freq = channel->freq; + err = 0; + } + + hapd->driver->stop_ap(hapd->drv_priv); + + hostapd_setup_interface_complete(hapd->iface, err); + return 0; +} diff --git a/src/ap/dfs.h b/src/ap/dfs.h new file mode 100644 index 0000000..c723726 --- /dev/null +++ b/src/ap/dfs.h @@ -0,0 +1,15 @@ +/* + * DFS - Dynamic Frequency Selection + * Copyright (c) 2002-2013, Jouni Malinen + * + * This software may be distributed under the terms of the BSD license. + * See README for more details. + */ +#ifndef DFS_H +#define DFS_H +struct hostapd_channel_data * hostapd_dfs_get_valid_channel( + struct hostapd_data *hapd); +int ieee802_11_complete_cac(struct hostapd_data *hapd, int success, int freq); +int ieee802_11_set_dfs_state(struct hostapd_data *hapd, int freq, u32 state); +int ieee802_11_start_channel_switch(struct hostapd_data *hapd); +#endif /* DFS_H */ diff --git a/src/ap/drv_callbacks.c b/src/ap/drv_callbacks.c index 68c12d2..1a083c0 100644 --- a/src/ap/drv_callbacks.c +++ b/src/ap/drv_callbacks.c @@ -29,7 +29,7 @@ #include "ap_drv_ops.h" #include "ap_config.h" #include "hw_features.h" - +#include "dfs.h" int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr, const u8 *req_ies, size_t req_ies_len, int reassoc) diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 37379f8..589f64f 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -32,7 +32,7 @@ #include "ap_config.h" #include "p2p_hostapd.h" #include "gas_serv.h" - +#include "dfs.h" static int hostapd_flush_old_stations(struct hostapd_data *hapd, u16 reason); static int hostapd_setup_encryption(char *iface, struct hostapd_data *hapd); @@ -1519,61 +1519,3 @@ void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta, eloop_register_timeout(hapd->conf->ap_max_inactivity, 0, ap_handle_timer, hapd, sta); } - -static int hostapd_dfs_find_channel(struct hostapd_data *hapd, - struct hostapd_channel_data **ret_chan, - int idx) -{ - struct hostapd_hw_modes *mode; - struct hostapd_channel_data *chan; - int i, channel_idx = 0; - - mode = hapd->iface->current_mode; - - for (i = 0; i < mode->num_channels; i++) { - chan = &mode->channels[i]; - - if (chan->flag & HOSTAPD_CHAN_DISABLED) - continue; - - if (chan->flag & HOSTAPD_CHAN_RADAR && - chan->flag & HOSTAPD_CHAN_DFS_UNAVAILABLE) - continue; - - if (ret_chan && idx == channel_idx) { - wpa_printf(MSG_DEBUG, "Selected ch. #%d", chan->chan); - *ret_chan = chan; - return idx; - } - channel_idx++; - } - return channel_idx; -} - -struct hostapd_channel_data * hostapd_dfs_get_valid_channel( - struct hostapd_data *hapd) -{ - struct hostapd_hw_modes *mode; - struct hostapd_channel_data *chan = NULL; - int channel_idx, new_channel_idx; - u32 _rand; - - wpa_printf(MSG_DEBUG, "DFS: Selecting random channel"); - - if (hapd->iface->current_mode == NULL) - return NULL; - - mode = hapd->iface->current_mode; - if (mode->mode != HOSTAPD_MODE_IEEE80211A) - return NULL; - - /* get random available channel */ - channel_idx = hostapd_dfs_find_channel(hapd, NULL, 0); - if (channel_idx > 0) { - os_get_random((u8 *) &_rand, sizeof(_rand)); - new_channel_idx = _rand % channel_idx; - hostapd_dfs_find_channel(hapd, &chan, new_channel_idx); - }; - - return chan; -} diff --git a/src/ap/hostapd.h b/src/ap/hostapd.h index 379dd8d..dbf1b52 100644 --- a/src/ap/hostapd.h +++ b/src/ap/hostapd.h @@ -380,6 +380,4 @@ const struct hostapd_eap_user * hostapd_get_eap_user(struct hostapd_data *hapd, const u8 *identity, size_t identity_len, int phase2); -struct hostapd_channel_data * hostapd_dfs_get_valid_channel( - struct hostapd_data *hapd); #endif /* HOSTAPD_H */ diff --git a/src/ap/ieee802_11.c b/src/ap/ieee802_11.c index 52bb5d0..781f826 100644 --- a/src/ap/ieee802_11.c +++ b/src/ap/ieee802_11.c @@ -2239,78 +2239,5 @@ void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); } -int ieee802_11_set_dfs_state(struct hostapd_data *hapd, int freq, u32 state) -{ - struct hostapd_hw_modes *mode; - struct hostapd_channel_data *chan = NULL; - int i; - - mode = hapd->iface->current_mode; - if (mode == NULL) - return 0; - - if (mode->mode != HOSTAPD_MODE_IEEE80211A) { - wpa_printf(MSG_WARNING, "current_mode != IEEE80211A"); - return 0; - } - - for (i = 0; i < hapd->iface->current_mode->num_channels; i++) { - chan = &hapd->iface->current_mode->channels[i]; - if (chan->freq == freq) { - if (chan->flag & HOSTAPD_CHAN_RADAR) { - chan->flag &= ~HOSTAPD_CHAN_DFS_MASK; - chan->flag |= state; - return 1; /* Channel found */ - } - } - } - wpa_printf(MSG_WARNING, "Can't set DFS state for freq %d MHz", freq); - return 0; -} - -int ieee802_11_complete_cac(struct hostapd_data *hapd, int success, int freq) -{ - struct hostapd_channel_data *channel; - int err = 1; - - if (success) { - /* Complete iface/ap configuration */ - ieee802_11_set_dfs_state(hapd, freq, HOSTAPD_CHAN_DFS_AVAILABLE); - hostapd_setup_interface_complete(hapd->iface, 0); - } else { - /* Switch to new channel */ - ieee802_11_set_dfs_state(hapd, freq, HOSTAPD_CHAN_DFS_UNAVAILABLE); - channel = hostapd_dfs_get_valid_channel(hapd); - if (channel) { - hapd->iconf->channel = channel->chan; - hapd->iface->freq = channel->freq; - err = 0; - } else - wpa_printf(MSG_ERROR, "No valid channel available"); - - hostapd_setup_interface_complete(hapd->iface, err); - } - - return 0; -} - -int ieee802_11_start_channel_switch(struct hostapd_data *hapd) -{ - struct hostapd_channel_data *channel; - wpa_printf(MSG_DEBUG, "%s called\n", __func__); - int err = 1; - - channel = hostapd_dfs_get_valid_channel(hapd); - if (channel) { - hapd->iconf->channel = channel->chan; - hapd->iface->freq = channel->freq; - err = 0; - } - - hapd->driver->stop_ap(hapd->drv_priv); - - hostapd_setup_interface_complete(hapd->iface, err); - return 0; -} #endif /* CONFIG_NATIVE_WINDOWS */ diff --git a/src/ap/ieee802_11.h b/src/ap/ieee802_11.h index 358edfd..2aab56d 100644 --- a/src/ap/ieee802_11.h +++ b/src/ap/ieee802_11.h @@ -80,7 +80,5 @@ u8 * hostapd_eid_time_zone(struct hostapd_data *hapd, u8 *eid); int hostapd_update_time_adv(struct hostapd_data *hapd); void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr); u8 * hostapd_eid_bss_max_idle_period(struct hostapd_data *hapd, u8 *eid); -int ieee802_11_complete_cac(struct hostapd_data *hapd, int success, int freq); -int ieee802_11_set_dfs_state(struct hostapd_data *hapd, int freq, u32 state); -int ieee802_11_start_channel_switch(struct hostapd_data *hapd); + #endif /* IEEE802_11_H */ diff --git a/wpa_supplicant/Makefile b/wpa_supplicant/Makefile index 5698619..82449c2 100644 --- a/wpa_supplicant/Makefile +++ b/wpa_supplicant/Makefile @@ -748,6 +748,7 @@ OBJS += ../src/ap/drv_callbacks.o OBJS += ../src/ap/ap_drv_ops.o OBJS += ../src/ap/beacon.o OBJS += ../src/ap/eap_user_db.o +OBJS += ../src/ap/dfs.o ifdef CONFIG_IEEE80211N OBJS += ../src/ap/ieee802_11_ht.o endif