nl80211: Use helper function for phy_info_handler()
This allows one level of indentation to be removed by using a helper function to process each wiphy band. Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
parent
5f43910727
commit
3cfcad1bb1
1 changed files with 205 additions and 190 deletions
|
@ -5003,14 +5003,9 @@ struct phy_info_arg {
|
|||
int last_mode, last_chan_idx;
|
||||
};
|
||||
|
||||
static int phy_info_handler(struct nl_msg *msg, void *arg)
|
||||
static int phy_info_band(struct phy_info_arg *phy_info, struct nlattr *nl_band)
|
||||
{
|
||||
struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
|
||||
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
|
||||
struct phy_info_arg *phy_info = arg;
|
||||
|
||||
struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
|
||||
|
||||
struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
|
||||
static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
|
||||
[NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
|
||||
|
@ -5020,27 +5015,18 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
[NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
|
||||
[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 },
|
||||
};
|
||||
|
||||
struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
|
||||
static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
|
||||
[NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
|
||||
[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
|
||||
[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] =
|
||||
{ .type = NLA_FLAG },
|
||||
};
|
||||
|
||||
struct nlattr *nl_band;
|
||||
struct nlattr *nl_freq;
|
||||
struct nlattr *nl_rate;
|
||||
int rem_band, rem_freq, rem_rate;
|
||||
int rem_freq, rem_rate;
|
||||
struct hostapd_hw_modes *mode;
|
||||
int idx;
|
||||
|
||||
nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
|
||||
genlmsg_attrlen(gnlh, 0), NULL);
|
||||
|
||||
if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
|
||||
return NL_SKIP;
|
||||
|
||||
nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
|
||||
if (phy_info->last_mode != nl_band->nla_type) {
|
||||
mode = os_realloc_array(phy_info->modes,
|
||||
*phy_info->num_modes + 1,
|
||||
|
@ -5069,14 +5055,12 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
|
||||
if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) {
|
||||
mode->a_mpdu_params |= nla_get_u8(
|
||||
tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) &
|
||||
0x03;
|
||||
tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) & 0x03;
|
||||
}
|
||||
|
||||
if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) {
|
||||
mode->a_mpdu_params |= nla_get_u8(
|
||||
tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) <<
|
||||
2;
|
||||
tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) << 2;
|
||||
}
|
||||
|
||||
if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] &&
|
||||
|
@ -5101,10 +5085,11 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
if (tb_band[NL80211_BAND_ATTR_FREQS]) {
|
||||
int new_channels = 0;
|
||||
struct hostapd_channel_data *channel;
|
||||
nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
|
||||
nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS],
|
||||
rem_freq) {
|
||||
nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
|
||||
nla_data(nl_freq),
|
||||
nla_len(nl_freq), freq_policy);
|
||||
nla_data(nl_freq), nla_len(nl_freq),
|
||||
freq_policy);
|
||||
if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
|
||||
continue;
|
||||
new_channels++;
|
||||
|
@ -5113,7 +5098,6 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
channel = os_realloc_array(mode->channels,
|
||||
mode->num_channels + new_channels,
|
||||
sizeof(struct hostapd_channel_data));
|
||||
|
||||
if (!channel)
|
||||
return NL_SKIP;
|
||||
|
||||
|
@ -5122,14 +5106,16 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
|
||||
idx = phy_info->last_chan_idx;
|
||||
|
||||
nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
|
||||
nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS],
|
||||
rem_freq) {
|
||||
nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX,
|
||||
nla_data(nl_freq),
|
||||
nla_len(nl_freq), freq_policy);
|
||||
nla_data(nl_freq), nla_len(nl_freq),
|
||||
freq_policy);
|
||||
if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
|
||||
continue;
|
||||
|
||||
mode->channels[idx].freq = nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
|
||||
mode->channels[idx].freq = nla_get_u32(
|
||||
tb_freq[NL80211_FREQUENCY_ATTR_FREQ]);
|
||||
mode->channels[idx].flag = 0;
|
||||
|
||||
/* mode is not set */
|
||||
|
@ -5176,8 +5162,7 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
mode->channels[idx].flag |=
|
||||
HOSTAPD_CHAN_NO_IBSS;
|
||||
if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
|
||||
mode->channels[idx].flag |=
|
||||
HOSTAPD_CHAN_RADAR;
|
||||
mode->channels[idx].flag |= HOSTAPD_CHAN_RADAR;
|
||||
|
||||
if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] &&
|
||||
!tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
|
||||
|
@ -5190,9 +5175,11 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
}
|
||||
|
||||
if (tb_band[NL80211_BAND_ATTR_RATES]) {
|
||||
nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
|
||||
nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
|
||||
nla_len(nl_rate), rate_policy);
|
||||
nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES],
|
||||
rem_rate) {
|
||||
nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
|
||||
nla_data(nl_rate), nla_len(nl_rate),
|
||||
rate_policy);
|
||||
if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
|
||||
continue;
|
||||
mode->num_rates++;
|
||||
|
@ -5204,12 +5191,15 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
|
||||
idx = 0;
|
||||
|
||||
nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
|
||||
nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
|
||||
nla_len(nl_rate), rate_policy);
|
||||
nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES],
|
||||
rem_rate) {
|
||||
nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX,
|
||||
nla_data(nl_rate), nla_len(nl_rate),
|
||||
rate_policy);
|
||||
if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
|
||||
continue;
|
||||
mode->rates[idx] = nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]);
|
||||
mode->rates[idx] = nla_get_u32(
|
||||
tb_rate[NL80211_BITRATE_ATTR_RATE]);
|
||||
|
||||
/* crude heuristic */
|
||||
if (mode->mode == HOSTAPD_MODE_IEEE80211B &&
|
||||
|
@ -5219,11 +5209,36 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
|
|||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
return NL_OK;
|
||||
}
|
||||
|
||||
|
||||
static int phy_info_handler(struct nl_msg *msg, void *arg)
|
||||
{
|
||||
struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
|
||||
struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
|
||||
struct phy_info_arg *phy_info = arg;
|
||||
struct nlattr *nl_band;
|
||||
int rem_band;
|
||||
|
||||
nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
|
||||
genlmsg_attrlen(gnlh, 0), NULL);
|
||||
|
||||
if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
|
||||
return NL_SKIP;
|
||||
|
||||
nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band)
|
||||
{
|
||||
int res = phy_info_band(phy_info, nl_band);
|
||||
if (res != NL_OK)
|
||||
return res;
|
||||
}
|
||||
|
||||
return NL_SKIP;
|
||||
}
|
||||
|
||||
|
||||
static struct hostapd_hw_modes *
|
||||
wpa_driver_nl80211_add_11b(struct hostapd_hw_modes *modes, u16 *num_modes)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue