[PATCH v2 2/3] hostapd: move DFS code to dfs.c/dfs.h

Janusz Dziedzic janusz.dziedzic
Sun Oct 6 23:30:08 PDT 2013


Move DFS code to dfs.c and dfs.h files.

Signed-hostap: Janusz Dziedzic <janusz.dziedzic at tieto.com>
---
 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 <j at w1.fi>
+ *
+ * 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 <j at w1.fi>
+ *
+ * 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
-- 
1.7.9.5




More information about the Hostap mailing list