aboutsummaryrefslogtreecommitdiffstats
path: root/hostapd/hostapd.c
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2008-11-21 18:39:33 (GMT)
committerJouni Malinen <j@w1.fi>2008-11-21 18:39:33 (GMT)
commitddaa83ebeb108d00cd5888497fb4139d7cd6947e (patch)
tree975f5a25d1619e88318651ea84f756d5df8b76b9 /hostapd/hostapd.c
parent2387b8c0b05c306ac723c956f3bbad885b3c807b (diff)
downloadhostap-06-ddaa83ebeb108d00cd5888497fb4139d7cd6947e.zip
hostap-06-ddaa83ebeb108d00cd5888497fb4139d7cd6947e.tar.gz
hostap-06-ddaa83ebeb108d00cd5888497fb4139d7cd6947e.tar.bz2
Remove overly complex hostapd setup sequence with n+1 callbacks
This code was originally added as a mechanism to handle long waits during channel selection and/or radar detection. It is not currently really used and makes the setup sequence nearly impossible to understand. Let's get rid of the unwanted complexity. This needs to be redesigned if it is ever needed again.
Diffstat (limited to 'hostapd/hostapd.c')
-rw-r--r--hostapd/hostapd.c295
1 files changed, 79 insertions, 216 deletions
diff --git a/hostapd/hostapd.c b/hostapd/hostapd.c
index eb9a389..d6163f8 100644
--- a/hostapd/hostapd.c
+++ b/hostapd/hostapd.c
@@ -1385,145 +1385,6 @@ static void hostapd_tx_queue_params(struct hostapd_iface *iface)
}
-/**
- * setup_interface2 - Setup (initialize) an interface (part 2)
- * @iface: Pointer to interface data.
- * Returns: 0 on success; -1 on failure.
- *
- * Flushes old stations, sets the channel, DFS parameters, encryption,
- * beacons, and WDS links based on the configuration.
- */
-static int setup_interface2(struct hostapd_iface *iface)
-{
- struct hostapd_data *hapd = iface->bss[0];
- int freq;
- size_t j;
- int ret = 0;
- u8 *prev_addr;
-
- hostapd_flush_old_stations(hapd);
- hostapd_set_privacy(hapd, 0);
-
- if (hapd->iconf->channel) {
- freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
- printf("Mode: %s Channel: %d Frequency: %d MHz\n",
- hostapd_hw_mode_txt(hapd->iconf->hw_mode),
- hapd->iconf->channel, freq);
-
- if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, freq)) {
- printf("Could not set channel for kernel driver\n");
- return -1;
- }
- }
-
- hostapd_broadcast_wep_clear(hapd);
- if (hostapd_setup_encryption(hapd->conf->iface, hapd))
- return -1;
-
- hostapd_set_beacon_int(hapd, hapd->iconf->beacon_int);
- ieee802_11_set_beacon(hapd);
-
- if (hapd->iconf->rts_threshold > -1 &&
- hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
- printf("Could not set RTS threshold for kernel driver\n");
- return -1;
- }
-
- if (hapd->iconf->fragm_threshold > -1 &&
- hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
- printf("Could not set fragmentation threshold for kernel "
- "driver\n");
- return -1;
- }
-
- prev_addr = hapd->own_addr;
-
- for (j = 0; j < iface->num_bss; j++) {
- hapd = iface->bss[j];
- if (j)
- os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
- if (hostapd_setup_bss(hapd, j == 0))
- return -1;
- if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
- prev_addr = hapd->own_addr;
- }
-
- hostapd_tx_queue_params(iface);
-
- ap_list_init(iface);
-
- if (hostapd_driver_commit(hapd) < 0) {
- wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
- "configuration", __func__);
- return -1;
- }
-
- return ret;
-}
-
-
-static void setup_interface_start(void *eloop_data, void *user_ctx);
-static void setup_interface2_handler(void *eloop_data, void *user_ctx);
-
-/**
- * setup_interface_finalize - Finish setup interface & call the callback
- * @iface: Pointer to interface data.
- * @status: Status of the setup interface (0 on success; -1 on failure).
- * Returns: 0 on success; -1 on failure (e.g., was not in progress).
- */
-static int setup_interface_finalize(struct hostapd_iface *iface, int status)
-{
- hostapd_iface_cb cb;
-
- if (!iface->setup_cb)
- return -1;
-
- eloop_cancel_timeout(setup_interface_start, iface, NULL);
- eloop_cancel_timeout(setup_interface2_handler, iface, NULL);
- hostapd_select_hw_mode_stop(iface);
-
- cb = iface->setup_cb;
-
- iface->setup_cb = NULL;
-
- cb(iface, status);
-
- return 0;
-}
-
-
-/**
- * setup_interface2_wrapper - Wrapper for setup_interface2()
- * @iface: Pointer to interface data.
- * @status: Status of the hw mode select.
- *
- * Wrapper for setup_interface2() to calls finalize function upon completion.
- */
-static void setup_interface2_wrapper(struct hostapd_iface *iface, int status)
-{
- int ret = status;
- if (ret)
- printf("Could not select hw_mode and channel. (%d)\n", ret);
- else
- ret = setup_interface2(iface);
-
- setup_interface_finalize(iface, ret);
-}
-
-
-/**
- * setup_interface2_handler - Used for immediate call of setup_interface2
- * @eloop_data: Stores the struct hostapd_iface * for the interface.
- * @user_ctx: Unused.
- */
-static void setup_interface2_handler(void *eloop_data, void *user_ctx)
-{
- struct hostapd_iface *iface = eloop_data;
-
- setup_interface2_wrapper(iface, 0);
-}
-
-
static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
size_t identity_len, int phase2,
struct eap_user *user)
@@ -1563,23 +1424,17 @@ static int hostapd_radius_get_eap_user(void *ctx, const u8 *identity,
}
-/**
- * setup_interface1 - Setup (initialize) an interface (part 1)
- * @iface: Pointer to interface data
- * Returns: 0 on success, -1 on failure
- *
- * Initializes the driver interface, validates the configuration,
- * and sets driver parameters based on the configuration.
- * Schedules setup_interface2() to be called immediately or after
- * hardware mode setup takes place.
- */
-static int setup_interface1(struct hostapd_iface *iface)
+static int setup_interface(struct hostapd_iface *iface)
{
struct hostapd_data *hapd = iface->bss[0];
struct hostapd_bss_config *conf = hapd->conf;
size_t i;
char country[4];
u8 *b = conf->bssid;
+ int freq;
+ size_t j;
+ int ret = 0;
+ u8 *prev_addr;
/*
* Initialize the driver interface and make sure that all BSSes get
@@ -1639,77 +1494,104 @@ static int setup_interface1(struct hostapd_iface *iface)
/* Not all drivers support this yet, so continue without hw
* feature data. */
} else {
- return hostapd_select_hw_mode_start(iface,
- setup_interface2_wrapper);
+ int ret = hostapd_select_hw_mode(iface);
+ if (ret < 0) {
+ printf("Could not select hw_mode and channel. (%d)\n",
+ ret);
+ return -1;
+ }
}
- eloop_register_timeout(0, 0, setup_interface2_handler, iface, NULL);
- return 0;
-}
+ hostapd_flush_old_stations(hapd);
+ hostapd_set_privacy(hapd, 0);
+ if (hapd->iconf->channel) {
+ freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
+ printf("Mode: %s Channel: %d Frequency: %d MHz\n",
+ hostapd_hw_mode_txt(hapd->iconf->hw_mode),
+ hapd->iconf->channel, freq);
-/**
- * setup_interface_start - Handler to start setup interface
- * @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 setup_interface_start(void *eloop_data, void *user_ctx)
-{
- struct hostapd_iface *iface = eloop_data;
+ if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, freq)) {
+ printf("Could not set channel for kernel driver\n");
+ return -1;
+ }
+ }
- int ret;
+ hostapd_broadcast_wep_clear(hapd);
+ if (hostapd_setup_encryption(hapd->conf->iface, hapd))
+ return -1;
+
+ hostapd_set_beacon_int(hapd, hapd->iconf->beacon_int);
+ ieee802_11_set_beacon(hapd);
+
+ if (hapd->iconf->rts_threshold > -1 &&
+ hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
+ printf("Could not set RTS threshold for kernel driver\n");
+ return -1;
+ }
+
+ if (hapd->iconf->fragm_threshold > -1 &&
+ hostapd_set_frag(hapd, hapd->iconf->fragm_threshold)) {
+ printf("Could not set fragmentation threshold for kernel "
+ "driver\n");
+ return -1;
+ }
- ret = setup_interface1(iface);
- if (ret)
- setup_interface_finalize(iface, ret);
+ prev_addr = hapd->own_addr;
+
+ for (j = 0; j < iface->num_bss; j++) {
+ hapd = iface->bss[j];
+ if (j)
+ os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
+ if (hostapd_setup_bss(hapd, j == 0))
+ return -1;
+ if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
+ prev_addr = hapd->own_addr;
+ }
+
+ hostapd_tx_queue_params(iface);
+
+ ap_list_init(iface);
+
+ if (hostapd_driver_commit(hapd) < 0) {
+ wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
+ "configuration", __func__);
+ return -1;
+ }
+
+ return ret;
}
/**
- * hostapd_setup_interface_start - Start the setup of an interface
+ * hostapd_setup_interface - Setup of an interface
* @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.
+ * Returns: 0 on success, -1 on failure
*
* Initializes the driver interface, validates the configuration,
* and sets driver parameters based on the configuration.
- * Flushes old stations, sets the channel, DFS parameters, encryption,
+ * Flushes old stations, sets the channel, encryption,
* beacons, and WDS links based on the configuration.
*/
-int hostapd_setup_interface_start(struct hostapd_iface *iface,
- hostapd_iface_cb cb)
+static int hostapd_setup_interface(struct hostapd_iface *iface)
{
- if (iface->setup_cb) {
- wpa_printf(MSG_DEBUG,
- "%s: Interface setup already in progress.\n",
+ int ret;
+
+ ret = setup_interface(iface);
+ if (ret) {
+ wpa_printf(MSG_DEBUG, "%s: Unable to setup interface.",
iface->bss[0]->conf->iface);
+ eloop_terminate();
return -1;
+ } else if (!hostapd_drv_none(iface->bss[0])) {
+ wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
+ iface->bss[0]->conf->iface);
}
- iface->setup_cb = cb;
-
- eloop_register_timeout(0, 0, setup_interface_start, iface, NULL);
-
return 0;
}
-/**
- * hostapd_setup_interace_stop - Stops the setup of an interface
- * @iface: Pointer to interface data
- * Returns: 0 if successfully stopped;
- * -1 on failure (i.e., was not in progress)
- */
-int hostapd_setup_interface_stop(struct hostapd_iface *iface)
-{
- return setup_interface_finalize(iface, -1);
-}
-
-
static void show_version(void)
{
fprintf(stderr,
@@ -1897,23 +1779,6 @@ fail:
}
-/**
- * setup_interface_done - Callback when an interface is done being setup.
- * @iface: Pointer to interface data.
- * @status: Status of the interface setup (0 on success; -1 on failure).
- */
-static void setup_interface_done(struct hostapd_iface *iface, int status)
-{
- if (status) {
- wpa_printf(MSG_DEBUG, "%s: Unable to setup interface.",
- iface->bss[0]->conf->iface);
- eloop_terminate();
- } else if (!hostapd_drv_none(iface->bss[0]))
- wpa_printf(MSG_DEBUG, "%s: Setup of interface done.",
- iface->bss[0]->conf->iface);
-}
-
-
int main(int argc, char *argv[])
{
struct hapd_interfaces interfaces;
@@ -2001,8 +1866,7 @@ int main(int argc, char *argv[])
logger_stdout_level--;
}
- ret = hostapd_setup_interface_start(interfaces.iface[i],
- setup_interface_done);
+ ret = hostapd_setup_interface(interfaces.iface[i]);
if (ret)
goto out;
@@ -2047,7 +1911,6 @@ int main(int argc, char *argv[])
for (i = 0; i < interfaces.count; i++) {
if (!interfaces.iface[i])
continue;
- hostapd_setup_interface_stop(interfaces.iface[i]);
hostapd_cleanup_iface_pre(interfaces.iface[i]);
for (j = 0; j < interfaces.iface[i]->num_bss; j++) {
struct hostapd_data *hapd =