Commit 6685d109 authored by Yogesh Ashok Powar's avatar Yogesh Ashok Powar Committed by John W. Linville

mwifiex: merge functions to derive cfp by chan & freq in one

There exist different functions with very long names
to derive the channel frequency and power tripplet
based on band and channel/freq.
Signed-off-by: default avatarYogesh Ashok Powar <yogeshp@marvell.com>
Signed-off-by: default avatarBing Zhao <bzhao@marvell.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent 985d68a3
...@@ -169,85 +169,59 @@ u32 mwifiex_get_active_data_rates(struct mwifiex_private *priv, u8 *rates) ...@@ -169,85 +169,59 @@ u32 mwifiex_get_active_data_rates(struct mwifiex_private *priv, u8 *rates)
/* /*
* This function locates the Channel-Frequency-Power triplet based upon * This function locates the Channel-Frequency-Power triplet based upon
* band and channel parameters. * band and channel/frequency parameters.
*/ */
struct mwifiex_chan_freq_power * struct mwifiex_chan_freq_power *
mwifiex_get_cfp_by_band_and_channel_from_cfg80211(struct mwifiex_private mwifiex_get_cfp(struct mwifiex_private *priv, u8 band, u16 channel, u32 freq)
*priv, u8 band, u16 channel)
{ {
struct mwifiex_chan_freq_power *cfp = NULL; struct mwifiex_chan_freq_power *cfp = NULL;
struct ieee80211_supported_band *sband; struct ieee80211_supported_band *sband;
struct ieee80211_channel *ch; struct ieee80211_channel *ch = NULL;
int i; int i;
if (!channel && !freq)
return cfp;
if (mwifiex_band_to_radio_type(band) == HostCmd_SCAN_RADIO_TYPE_BG) if (mwifiex_band_to_radio_type(band) == HostCmd_SCAN_RADIO_TYPE_BG)
sband = priv->wdev->wiphy->bands[IEEE80211_BAND_2GHZ]; sband = priv->wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
else else
sband = priv->wdev->wiphy->bands[IEEE80211_BAND_5GHZ]; sband = priv->wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
if (!sband) { if (!sband) {
dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d" dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d\n",
" & channel %d\n", __func__, band, channel); __func__, band);
return cfp; return cfp;
} }
for (i = 0; i < sband->n_channels; i++) { for (i = 0; i < sband->n_channels; i++) {
ch = &sband->channels[i]; ch = &sband->channels[i];
if (((ch->hw_value == channel) ||
(channel == FIRST_VALID_CHANNEL)) if (ch->flags & IEEE80211_CHAN_DISABLED)
&& !(ch->flags & IEEE80211_CHAN_DISABLED)) { continue;
priv->cfp.channel = channel;
priv->cfp.freq = ch->center_freq; if (freq) {
priv->cfp.max_tx_power = ch->max_power; if (ch->center_freq == freq)
cfp = &priv->cfp; break;
} else {
/* find by valid channel*/
if (ch->hw_value == channel ||
channel == FIRST_VALID_CHANNEL)
break; break;
} }
} }
if (i == sband->n_channels) if (i == sband->n_channels) {
dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d"
" & channel %d\n", __func__, band, channel);
return cfp;
}
/*
* This function locates the Channel-Frequency-Power triplet based upon
* band and frequency parameters.
*/
struct mwifiex_chan_freq_power *
mwifiex_get_cfp_by_band_and_freq_from_cfg80211(struct mwifiex_private *priv,
u8 band, u32 freq)
{
struct mwifiex_chan_freq_power *cfp = NULL;
struct ieee80211_supported_band *sband;
struct ieee80211_channel *ch;
int i;
if (mwifiex_band_to_radio_type(band) == HostCmd_SCAN_RADIO_TYPE_BG)
sband = priv->wdev->wiphy->bands[IEEE80211_BAND_2GHZ];
else
sband = priv->wdev->wiphy->bands[IEEE80211_BAND_5GHZ];
if (!sband) {
dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d" dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d"
" & freq %d\n", __func__, band, freq); " & channel=%d freq=%d\n", __func__, band, channel,
freq);
} else {
if (!ch)
return cfp; return cfp;
}
for (i = 0; i < sband->n_channels; i++) {
ch = &sband->channels[i];
if ((ch->center_freq == freq) &&
!(ch->flags & IEEE80211_CHAN_DISABLED)) {
priv->cfp.channel = ch->hw_value; priv->cfp.channel = ch->hw_value;
priv->cfp.freq = freq; priv->cfp.freq = ch->center_freq;
priv->cfp.max_tx_power = ch->max_power; priv->cfp.max_tx_power = ch->max_power;
cfp = &priv->cfp; cfp = &priv->cfp;
break;
} }
}
if (i == sband->n_channels)
dev_err(priv->adapter->dev, "%s: cannot find cfp by band %d"
" & freq %d\n", __func__, band, freq);
return cfp; return cfp;
} }
......
...@@ -777,12 +777,11 @@ mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv, ...@@ -777,12 +777,11 @@ mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID; adhoc_start->phy_param_set.ds_param_set.element_id = DS_PARA_IE_ID;
adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN; adhoc_start->phy_param_set.ds_param_set.len = DS_PARA_IE_LEN;
if (!mwifiex_get_cfp_by_band_and_channel_from_cfg80211 if (!mwifiex_get_cfp(priv, adapter->adhoc_start_band,
(priv, adapter->adhoc_start_band, (u16) (u16) priv->adhoc_channel, 0)) {
priv->adhoc_channel)) {
struct mwifiex_chan_freq_power *cfp; struct mwifiex_chan_freq_power *cfp;
cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv, cfp = mwifiex_get_cfp(priv, adapter->adhoc_start_band,
adapter->adhoc_start_band, FIRST_VALID_CHANNEL); FIRST_VALID_CHANNEL, 0);
if (cfp) if (cfp)
priv->adhoc_channel = (u8) cfp->channel; priv->adhoc_channel = (u8) cfp->channel;
} }
......
...@@ -771,13 +771,8 @@ int mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv, ...@@ -771,13 +771,8 @@ int mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv, int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
struct host_cmd_ds_command *resp); struct host_cmd_ds_command *resp);
int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd); int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd);
struct mwifiex_chan_freq_power * struct mwifiex_chan_freq_power *mwifiex_get_cfp(struct mwifiex_private *priv,
mwifiex_get_cfp_by_band_and_channel_from_cfg80211( u8 band, u16 channel, u32 freq);
struct mwifiex_private *priv,
u8 band, u16 channel);
struct mwifiex_chan_freq_power *mwifiex_get_cfp_by_band_and_freq_from_cfg80211(
struct mwifiex_private *priv,
u8 band, u32 freq);
u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv, u8 index, u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv, u8 index,
u8 ht_info); u8 ht_info);
u32 mwifiex_find_freq_from_band_chan(u8, u8); u32 mwifiex_find_freq_from_band_chan(u8, u8);
......
...@@ -1434,8 +1434,8 @@ int mwifiex_check_network_compatibility(struct mwifiex_private *priv, ...@@ -1434,8 +1434,8 @@ int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
if (!bss_desc) if (!bss_desc)
return -1; return -1;
if ((mwifiex_get_cfp_by_band_and_channel_from_cfg80211(priv, if ((mwifiex_get_cfp(priv, (u8) bss_desc->bss_band,
(u8) bss_desc->bss_band, (u16) bss_desc->channel))) { (u16) bss_desc->channel, 0))) {
switch (priv->bss_mode) { switch (priv->bss_mode) {
case NL80211_IFTYPE_STATION: case NL80211_IFTYPE_STATION:
case NL80211_IFTYPE_ADHOC: case NL80211_IFTYPE_ADHOC:
...@@ -1625,7 +1625,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv, ...@@ -1625,7 +1625,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
s32 rssi; s32 rssi;
const u8 *ie_buf; const u8 *ie_buf;
size_t ie_len; size_t ie_len;
int channel = -1; u16 channel = 0;
u64 network_tsf = 0; u64 network_tsf = 0;
u16 beacon_size = 0; u16 beacon_size = 0;
u32 curr_bcn_bytes; u32 curr_bcn_bytes;
...@@ -1723,7 +1723,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv, ...@@ -1723,7 +1723,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
&tsf_tlv->tsf_data[idx * TSF_DATA_SIZE], &tsf_tlv->tsf_data[idx * TSF_DATA_SIZE],
sizeof(network_tsf)); sizeof(network_tsf));
if (channel != -1) { if (channel) {
struct ieee80211_channel *chan; struct ieee80211_channel *chan;
u8 band; u8 band;
...@@ -1736,8 +1736,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv, ...@@ -1736,8 +1736,7 @@ int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
& (BIT(0) | BIT(1))); & (BIT(0) | BIT(1)));
} }
cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211( cfp = mwifiex_get_cfp(priv, band, channel, 0);
priv, (u8)band, (u16)channel);
freq = cfp ? cfp->freq : 0; freq = cfp ? cfp->freq : 0;
......
...@@ -529,11 +529,10 @@ int mwifiex_bss_set_channel(struct mwifiex_private *priv, ...@@ -529,11 +529,10 @@ int mwifiex_bss_set_channel(struct mwifiex_private *priv,
adapter->adhoc_start_band = BAND_G | BAND_B; adapter->adhoc_start_band = BAND_G | BAND_B;
if (chan->channel) { if (chan->channel) {
if (chan->channel <= MAX_CHANNEL_BAND_BG) if (chan->channel <= MAX_CHANNEL_BAND_BG)
cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211 cfp = mwifiex_get_cfp(priv, 0, (u16) chan->channel, 0);
(priv, 0, (u16) chan->channel);
if (!cfp) { if (!cfp) {
cfp = mwifiex_get_cfp_by_band_and_channel_from_cfg80211 cfp = mwifiex_get_cfp(priv, BAND_A,
(priv, BAND_A, (u16) chan->channel); (u16) chan->channel, 0);
if (cfp) { if (cfp) {
if (adapter->adhoc_11n_enabled) if (adapter->adhoc_11n_enabled)
adapter->adhoc_start_band = BAND_A adapter->adhoc_start_band = BAND_A
...@@ -544,11 +543,9 @@ int mwifiex_bss_set_channel(struct mwifiex_private *priv, ...@@ -544,11 +543,9 @@ int mwifiex_bss_set_channel(struct mwifiex_private *priv,
} }
} else { } else {
if (chan->freq <= MAX_FREQUENCY_BAND_BG) if (chan->freq <= MAX_FREQUENCY_BAND_BG)
cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211( cfp = mwifiex_get_cfp(priv, 0, 0, chan->freq);
priv, 0, chan->freq);
if (!cfp) { if (!cfp) {
cfp = mwifiex_get_cfp_by_band_and_freq_from_cfg80211 cfp = mwifiex_get_cfp(priv, BAND_A, 0, chan->freq);
(priv, BAND_A, chan->freq);
if (cfp) { if (cfp) {
if (adapter->adhoc_11n_enabled) if (adapter->adhoc_11n_enabled)
adapter->adhoc_start_band = BAND_A adapter->adhoc_start_band = BAND_A
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment