* hostapd / Hardware feature query and different modes
* Copyright 2002-2003, Instant802 Networks, Inc.
* Copyright 2005-2006, Devicescape Software, Inc.
+ * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include "hostapd.h"
#include "hw_features.h"
-#include "driver.h"
+#include "driver_i.h"
#include "config.h"
-#include "eloop.h"
void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
continue;
wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
- "chan=%d freq=%d MHz",
+ "chan=%d freq=%d MHz max_tx_power=%d dBm",
feature->mode,
feature->channels[j].chan,
- feature->channels[j].freq);
+ feature->channels[j].freq,
+ feature->channels[j].max_tx_power);
}
}
}
-static void select_hw_mode_start(void *eloop_data, void *user_ctx);
-static void select_hw_mode2_handler(void *eloop_data, void *user_ctx);
-
-/**
- * select_hw_mode_finalize - Finish select HW mode & call the callback
- * @iface: Pointer to interface data.
- * @status: Status of the select HW mode (0 on success; -1 on failure).
- * Returns: 0 on success; -1 on failure (e.g., was not in progress).
- */
-static int select_hw_mode_finalize(struct hostapd_iface *iface, int status)
-{
- hostapd_iface_cb cb;
-
- if (!iface->hw_mode_sel_cb)
- return -1;
-
- eloop_cancel_timeout(select_hw_mode_start, iface, NULL);
- eloop_cancel_timeout(select_hw_mode2_handler, iface, NULL);
-
- cb = iface->hw_mode_sel_cb;
-
- iface->hw_mode_sel_cb = NULL;
-
- cb(iface, status);
-
- return 0;
-}
-
-
-/**
- * select_hw_mode2 - Select the hardware mode (part 2)
- * @iface: Pointer to interface data.
- * @status: Status of auto chanel selection.
- *
- * Setup the rates and passive scanning based on the configuration.
- */
-static void select_hw_mode2(struct hostapd_iface *iface, int status)
+#ifdef CONFIG_IEEE80211N
+static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
{
- int ret = status;
- if (ret)
- goto fail;
+ int sec_chan, ok, j, first;
+ int allowed[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
+ 184, 192 };
+ size_t k;
- if (iface->current_mode == NULL) {
- hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_WARNING,
- "Hardware does not support configured channel");
- ret = -1;
- goto fail;
- }
+ if (!iface->conf->secondary_channel)
+ return 1; /* HT40 not used */
- if (hostapd_prepare_rates(iface->bss[0], iface->current_mode)) {
- wpa_printf(MSG_ERROR, "Failed to prepare rates table.");
- hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
- HOSTAPD_LEVEL_WARNING,
- "Failed to prepare rates table.");
- ret = -1;
- goto fail;
- }
+ sec_chan = iface->conf->channel + iface->conf->secondary_channel * 4;
+ wpa_printf(MSG_DEBUG, "HT40: control channel: %d "
+ "secondary channel: %d",
+ iface->conf->channel, sec_chan);
- ret = hostapd_passive_scan(iface->bss[0], 0,
- iface->conf->passive_scan_mode,
- iface->conf->passive_scan_interval,
- iface->conf->passive_scan_listen,
- NULL, NULL);
- if (ret) {
- if (ret == -1) {
- wpa_printf(MSG_DEBUG, "Passive scanning not "
- "supported");
- } else {
- wpa_printf(MSG_ERROR, "Could not set passive "
- "scanning: %s", strerror(ret));
+ /* Verify that HT40 secondary channel is an allowed 20 MHz
+ * channel */
+ ok = 0;
+ 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) {
+ ok = 1;
+ break;
}
- ret = 0;
+ }
+ if (!ok) {
+ wpa_printf(MSG_ERROR, "HT40 secondary channel %d not allowed",
+ sec_chan);
+ return 0;
}
-fail:
- select_hw_mode_finalize(iface, ret);
-}
+ /*
+ * Verify that HT40 primary,secondary channel pair is allowed per
+ * IEEE 802.11n Annex J. This is only needed for 5 GHz band since
+ * 2.4 GHz rules allow all cases where the secondary channel fits into
+ * the list of allowed channels (already checked above).
+ */
+ if (iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A)
+ return 1;
+ if (iface->conf->secondary_channel > 0)
+ first = iface->conf->channel;
+ else
+ first = sec_chan;
-/**
- * select_hw_mode2_handler - Calls select_hw_mode2 when auto chan isn't used
- * @eloop_data: Stores the struct hostapd_iface * for the interface.
- * @user_ctx: Unused.
- */
-static void select_hw_mode2_handler(void *eloop_data, void *user_ctx)
-{
- struct hostapd_iface *iface = eloop_data;
+ ok = 0;
+ for (k = 0; k < sizeof(allowed) / sizeof(allowed[0]); k++) {
+ if (first == allowed[k]) {
+ ok = 1;
+ break;
+ }
+ }
+ if (!ok) {
+ wpa_printf(MSG_ERROR, "HT40 channel pair (%d, %d) not allowed",
+ iface->conf->channel,
+ iface->conf->secondary_channel);
+ return 0;
+ }
- select_hw_mode2(iface, 0);
+ return 1;
}
+#endif /* CONFIG_IEEE80211N */
/**
- * select_hw_mode1 - Select the hardware mode (part 1)
+ * hostapd_select_hw_mode - Select the hardware mode
* @iface: Pointer to interface data.
- * Returns: 0 on success; -1 on failure.
+ * Returns: 0 on success, -1 on failure
*
- * Setup the hardware mode and channel based on the configuration.
- * Schedules select_hw_mode2() to be called immediately or after automatic
- * channel selection takes place.
+ * Sets up the hardware mode, channel, rates, and passive scanning
+ * based on the configuration.
*/
-static int select_hw_mode1(struct hostapd_iface *iface)
+int hostapd_select_hw_mode(struct hostapd_iface *iface)
{
- int i, j, ok;
+ int i, j, ok, ret;
if (iface->num_hw_features < 1)
return -1;
iface->current_mode = NULL;
}
- /*
- * Calls select_hw_mode2() via a handler, so that the function is
- * always executed from eloop.
- */
- eloop_register_timeout(0, 0, select_hw_mode2_handler, iface, NULL);
- return 0;
-}
-
-
-/**
- * select_hw_mode_start - Handler to start select HW mode
- * @eloop_data: Stores the struct hostapd_iface * for the interface.
- * @user_ctx: Unused.
- *
- * An eloop handler is used so that all errors can be processed by the
- * callback without introducing stack recursion.
- */
-static void select_hw_mode_start(void *eloop_data, void *user_ctx)
-{
- struct hostapd_iface *iface = (struct hostapd_iface *)eloop_data;
-
- int ret;
-
- ret = select_hw_mode1(iface);
- if (ret)
- select_hw_mode_finalize(iface, ret);
-}
-
-
-/**
- * hostapd_select_hw_mode_start - Start selection of the hardware mode
- * @iface: Pointer to interface data.
- * @cb: The function to callback when done.
- * Returns: 0 if it starts successfully; cb will be called when done.
- * -1 on failure; cb will not be called.
- *
- * Sets up the hardware mode, channel, rates, and passive scanning
- * based on the configuration.
- */
-int hostapd_select_hw_mode_start(struct hostapd_iface *iface,
- hostapd_iface_cb cb)
-{
- if (iface->hw_mode_sel_cb) {
- wpa_printf(MSG_DEBUG,
- "%s: Hardware mode select already in progress.",
- iface->bss[0]->conf->iface);
+ if (iface->current_mode == NULL) {
+ hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_WARNING,
+ "Hardware does not support configured channel");
return -1;
}
- iface->hw_mode_sel_cb = cb;
-
- eloop_register_timeout(0, 0, select_hw_mode_start, iface, NULL);
+#ifdef CONFIG_IEEE80211N
+ if (!ieee80211n_allowed_ht40_channel_pair(iface))
+ return -1;
+#endif /* CONFIG_IEEE80211N */
- return 0;
-}
+ if (hostapd_prepare_rates(iface->bss[0], iface->current_mode)) {
+ wpa_printf(MSG_ERROR, "Failed to prepare rates table.");
+ hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
+ HOSTAPD_LEVEL_WARNING,
+ "Failed to prepare rates table.");
+ return -1;
+ }
+ ret = hostapd_passive_scan(iface->bss[0], 0,
+ iface->conf->passive_scan_mode,
+ iface->conf->passive_scan_interval,
+ iface->conf->passive_scan_listen,
+ NULL, NULL);
+ if (ret) {
+ if (ret == -1) {
+ wpa_printf(MSG_DEBUG, "Passive scanning not "
+ "supported");
+ } else {
+ wpa_printf(MSG_ERROR, "Could not set passive "
+ "scanning: %s", strerror(ret));
+ }
+ ret = 0;
+ }
-/**
- * hostapd_auto_chan_select_stop - Stops automatic channel selection
- * @iface: Pointer to interface data.
- * Returns: 0 if successfully stopped;
- * -1 on failure (i.e., was not in progress)
- */
-int hostapd_select_hw_mode_stop(struct hostapd_iface *iface)
-{
- return select_hw_mode_finalize(iface, -1);
+ return ret;
}