int hostapd_reload_config(struct hostapd_iface *iface) { struct hostapd_data *hapd = iface->bss[0]; struct hostapd_config *newconf, *oldconf; size_t j; if (iface->interfaces == NULL || iface->interfaces->config_read_cb == NULL) return -1; newconf = iface->interfaces->config_read_cb(iface->config_fname); if (newconf == NULL) return -1; /* * Deauthenticate all stations since the new configuration may not * allow them to use the BSS anymore. */ for (j = 0; j < iface->num_bss; j++) { hostapd_flush_old_stations(iface->bss[j], WLAN_REASON_PREV_AUTH_NOT_VALID); hostapd_broadcast_wep_clear(iface->bss[j]); #ifndef CONFIG_NO_RADIUS /* TODO: update dynamic data based on changed configuration * items (e.g., open/close sockets, etc.) */ radius_client_flush(iface->bss[j]->radius, 0); #endif /* CONFIG_NO_RADIUS */ } oldconf = hapd->iconf; iface->conf = newconf; hostapd_select_hw_mode(iface); iface->freq = hostapd_hw_get_freq(hapd, newconf->channel); if (hostapd_set_freq(hapd, newconf->hw_mode, iface->freq, newconf->channel, newconf->ieee80211n, newconf->secondary_channel)) { wpa_printf(MSG_ERROR, "Could not set channel for " "kernel driver"); } if (iface->current_mode) hostapd_prepare_rates(iface, iface->current_mode); for (j = 0; j < iface->num_bss; j++) { hapd = iface->bss[j]; hapd->iconf = newconf; hapd->conf = &newconf->bss[j]; hostapd_reload_bss(hapd); } hostapd_config_free(oldconf); 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) { #if 0 int ret = status; if (ret) goto fail; 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 (hostapd_prepare_rates(iface->bss[0], iface->current_mode)) { printf("Failed to prepare rates table.\n"); hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_WARNING, "Failed to prepare rates table."); ret = -1; goto fail; } 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) { printf("Could not set passive scanning: %s\n", strerror(ret)); ret = 0; } fail: select_hw_mode_finalize(iface, ret); #endif printf("%s, null function, iface->bss[0] may be not init.\n", __func__) ; }
/** * hostapd_select_hw_mode - Select the hardware mode * @iface: Pointer to interface data. * Returns: 0 on success, -1 on failure * * Sets up the hardware mode, channel, rates, and passive scanning * based on the configuration. */ int hostapd_select_hw_mode(struct hostapd_iface *iface) { int i, j, ok, ret; if (iface->num_hw_features < 1) return -1; iface->current_mode = NULL; for (i = 0; i < iface->num_hw_features; i++) { struct hostapd_hw_modes *mode = &iface->hw_features[i]; if (mode->mode == (int) iface->conf->hw_mode) { iface->current_mode = mode; break; } } if (iface->current_mode == NULL) { wpa_printf(MSG_ERROR, "Hardware does not support configured " "mode"); hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_WARNING, "Hardware does not support configured mode " "(%d)", (int) iface->conf->hw_mode); return -1; } 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 == iface->conf->channel)) { ok = 1; break; } } 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 -1; } 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; } return ret; }
/** * hostapd_select_hw_mode - Select the hardware mode * @iface: Pointer to interface data. * Returns: 0 on success, -1 on failure * * Sets up the hardware mode, channel, rates, and passive scanning * based on the configuration. */ int hostapd_select_hw_mode(struct hostapd_iface *iface) { int i, j, ok; if (iface->num_hw_features < 1) return -1; iface->current_mode = NULL; for (i = 0; i < iface->num_hw_features; i++) { struct hostapd_hw_modes *mode = &iface->hw_features[i]; if (mode->mode == iface->conf->hw_mode) { iface->current_mode = mode; break; } } if (iface->current_mode == NULL) { wpa_printf(MSG_ERROR, "Hardware does not support configured " "mode"); hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_WARNING, "Hardware does not support configured mode " "(%d)", (int) iface->conf->hw_mode); return -1; } 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 == iface->conf->channel)) { ok = 1; break; } } 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)"); return -1; } 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 -1; } 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; } return 0; }