contrib/hostapd/hostapd/hw_features.c
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 (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;
	}

#ifdef CONFIG_IEEE80211N
	if (!ieee80211n_allowed_ht40_channel_pair(iface))
		return -1;
	if (!ieee80211n_supported_ht_capab(iface))
		return -1;
#endif /* CONFIG_IEEE80211N */

	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.
 */
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.
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 (iface->conf->channel == 0) {
		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;
	}
#ifdef CONFIG_IEEE80211N
	if (!ieee80211n_allowed_ht40_channel_pair(iface))
		return -1;
	if (!ieee80211n_supported_ht_capab(iface))
		return -1;
#endif 
	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;
}
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 , " " " " ) ; hostapd_logger ( iface -> bss [ 0 ] , NULL , HOSTAPD_MODULE_IEEE80211 , HOSTAPD_LEVEL_WARNING , " " " " , ( 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 ) { wpa_printf ( MSG_ERROR , " " " " ) ; return -1 ; } if ( ok == 0 && iface -> conf -> channel != 0 ) { hostapd_logger ( iface -> bss [ 0 ] , NULL , HOSTAPD_MODULE_IEEE80211 , HOSTAPD_LEVEL_WARNING , " " " " , 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 , " " ) ; return -1 ; } #ifdef CONFIG_IEEE80211N if ( ! ieee80211n_allowed_ht40_channel_pair ( iface ) ) return -1 ; if ( ! ieee80211n_supported_ht_capab ( iface ) ) return -1 ; #endif if ( hostapd_prepare_rates ( iface -> bss [ 0 ] , iface -> current_mode ) ) { wpa_printf ( MSG_ERROR , " " ) ; hostapd_logger ( iface -> bss [ 0 ] , NULL , HOSTAPD_MODULE_IEEE80211 , HOSTAPD_LEVEL_WARNING , " " ) ; 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 , " " " " ) ; } else { wpa_printf ( MSG_ERROR , " " " " , strerror ( ret ) ) ; } ret = 0 ; } return ret ; }
hostapd_select_hw_mode - Select the hardware mode
 @iface: Pointer to interface data.
hostapd_select_hw_mode - Select the hardware mode @iface : Pointer to interface data .
/* TODO: could request a scan of neighboring BSSes and select
		 * the channel automatically */ /* CONFIG_IEEE80211N */