software/drivers/sd8887/src/wlan/mlan/mlan_11h.c
/**
 *  @brief Retrieve a randomly selected starting channel if needed for 11h
 *
 *  If 11h is enabled and 5GHz band is selected in band_config
 *    return a random channel in A band, else one from BG band.
 *
 *  @param priv          Private driver information structure
 *  @param uap_band_cfg  Private driver information structure
 *
 *  @return      Starting channel
 */
@brief Retrieve a randomly selected starting channel if needed for 11h
If 11h is enabled and 5GHz band is selected in band_config
return a random channel in A band, else one from BG band.

@param priv          Private driver information structure
@param uap_band_cfg  Private driver information structure

@return      Starting channel
@brief Retrieve a randomly selected starting channel if needed for 11h If 11h is enabled and 5GHz band is selected in band_config return a random channel in A band else one from BG band . @param priv Private driver information structure @param uap_band_cfg Private driver information structure @return Starting channel
static t_u8
wlan_11h_get_uap_start_channel(mlan_private *priv, Band_Config_t uap_band_cfg)
{
	t_u8 start_chn;
	mlan_adapter *adapter = priv->adapter;
	t_u32 region;
	t_u32 rand_entry;
	region_chan_t *chn_tbl;
	t_u8 rand_tries = 0;
	ENTER();
	start_chn = DEFAULT_AD_HOC_CHANNEL;
	if (uap_band_cfg.chanBand == BAND_5GHZ) {
		start_chn = DEFAULT_AD_HOC_CHANNEL_A;
		if (wlan_11h_is_enabled(priv)) {
			for (region = 0; (region < MAX_REGION_CHANNEL_NUM);
			     region++) {
				chn_tbl = &adapter->region_channel[region];
				if (chn_tbl->valid
				    && chn_tbl->region == adapter->region_code
				    && chn_tbl->band & BAND_A) {
					rand_entry =
						wlan_11h_get_random_num(adapter)
						% chn_tbl->num_cfp;
					start_chn =
						(t_u8)chn_tbl->pcfp[rand_entry].
						channel;
					while ((!wlan_11h_is_chan_band_valid
						(&chn_tbl->pcfp[rand_entry],
						 uap_band_cfg) ||
						wlan_11h_is_channel_under_nop
						(adapter, start_chn) ||
						((adapter->state_rdh.stage ==
						  RDH_GET_INFO_CHANNEL) &&
						 wlan_11h_radar_detect_required
						 (priv, start_chn))) &&
					       (++rand_tries <
						chn_tbl->num_cfp)) {
						rand_entry++;
						rand_entry =
							rand_entry %
							chn_tbl->num_cfp;
						start_chn =
							(t_u8)chn_tbl->
							pcfp[rand_entry].
							channel;
						PRINTM(MINFO,
						       "start chan=%d rand_entry=%d\n",
						       start_chn, rand_entry);
					}
					if (rand_tries == chn_tbl->num_cfp) {
						PRINTM(MERROR,
						       "Failed to get UAP start channel\n");
						start_chn = 0;
					}
				}
			}
		}
	}
	PRINTM(MCMD_D, "11h: UAP Get Start Channel %d\n", start_chn);
	LEAVE();
	return start_chn;
}
static t_u8 wlan_11h_get_uap_start_channel ( mlan_private * priv , Band_Config_t uap_band_cfg ) { t_u8 start_chn ; mlan_adapter * adapter = priv -> adapter ; t_u32 region ; t_u32 rand_entry ; region_chan_t * chn_tbl ; t_u8 rand_tries = 0 ; ENTER ( ) ; start_chn = DEFAULT_AD_HOC_CHANNEL ; if ( uap_band_cfg . chanBand == BAND_5GHZ ) { start_chn = DEFAULT_AD_HOC_CHANNEL_A ; if ( wlan_11h_is_enabled ( priv ) ) { for ( region = 0 ; ( region < MAX_REGION_CHANNEL_NUM ) ; region ++ ) { chn_tbl = & adapter -> region_channel [ region ] ; if ( chn_tbl -> valid && chn_tbl -> region == adapter -> region_code && chn_tbl -> band & BAND_A ) { rand_entry = wlan_11h_get_random_num ( adapter ) % chn_tbl -> num_cfp ; start_chn = ( t_u8 ) chn_tbl -> pcfp [ rand_entry ] . channel ; while ( ( ! wlan_11h_is_chan_band_valid ( & chn_tbl -> pcfp [ rand_entry ] , uap_band_cfg ) || wlan_11h_is_channel_under_nop ( adapter , start_chn ) || ( ( adapter -> state_rdh . stage == RDH_GET_INFO_CHANNEL ) && wlan_11h_radar_detect_required ( priv , start_chn ) ) ) && ( ++ rand_tries < chn_tbl -> num_cfp ) ) { rand_entry ++ ; rand_entry = rand_entry % chn_tbl -> num_cfp ; start_chn = ( t_u8 ) chn_tbl -> pcfp [ rand_entry ] . channel ; PRINTM ( MINFO , " \n " , start_chn , rand_entry ) ; } if ( rand_tries == chn_tbl -> num_cfp ) { PRINTM ( MERROR , " \n " ) ; start_chn = 0 ; } } } } } PRINTM ( MCMD_D , " \n " , start_chn ) ; LEAVE ( ) ; return start_chn ; }
@brief Retrieve a randomly selected starting channel if needed for 11h
  If 11h is enabled and 5GHz band is selected in band_config
    return a random channel in A band, else one from BG band.
@brief Retrieve a randomly selected starting channel if needed for 11h If 11h is enabled and 5GHz band is selected in band_config return a random channel in A band else one from BG band .
/*TODO:  right now mostly a copy of wlan_11h_get_adhoc_start_channel.
	 *       Improve to be more specfic to UAP, e.g.
	 *       1. take into account COUNTRY_CODE -> region_code
	 *       2. check domain_info for value channels
	 */ /*
	 * Set start_chn to the Default.
	 * Used if 11h is disabled or the band
	 * does not require 11h support.
	 */ /*
	 * Check that we are looking for a channel in the A Band
	 */ /*
		 * Set default to the A Band default.
		 * Used if random selection fails
		 * or if 11h is not enabled
		 */ /*
		 * Check that 11h is enabled in the driver
		 */ /*
			 * Search the region_channel tables for a channel table
			 * that is marked for the A Band.
			 */ /* Check if table is valid and marked for A Band */ /*
					 * Set the start channel.  Get a random
					 * number and use it to pick an entry
					 * in the table between 0 and the number
					 * of channels in the table (NumCFP).
					 */ /* Loop until a non-dfs channel is found with compatible band
					 * bounded by chn_tbl->num_cfp entries in the channel table
					 */