Remove struct hostapd_rate_data from driver API

In addition to the bitrate, the only other variable in this structure
is used internally in hostapd. Move this structure into hostapd.h and
make the driver API use simpler data structure (array of bitrates).
This commit is contained in:
Jouni Malinen 2009-12-09 21:57:50 +02:00
parent 217e7eeaf0
commit fb7842aa51
8 changed files with 38 additions and 46 deletions

View file

@ -31,6 +31,14 @@ struct hostapd_probereq_cb {
void *ctx;
};
#define HOSTAPD_RATE_BASIC 0x00000001
struct hostapd_rate_data {
int rate; /* rate in 100 kbps */
int flags; /* HOSTAPD_RATE_ flags */
};
/**
* struct hostapd_data - hostapd per-BSS data structure
*/

View file

@ -135,7 +135,7 @@ static int hostapd_prepare_rates(struct hostapd_data *hapd,
hapd->iface->num_rates = 0;
hapd->iface->current_rates =
os_malloc(mode->num_rates * sizeof(struct hostapd_rate_data));
os_zalloc(mode->num_rates * sizeof(struct hostapd_rate_data));
if (!hapd->iface->current_rates) {
wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
"table.");
@ -147,17 +147,15 @@ static int hostapd_prepare_rates(struct hostapd_data *hapd,
if (hapd->iconf->supported_rates &&
!hostapd_rate_found(hapd->iconf->supported_rates,
mode->rates[i].rate))
mode->rates[i]))
continue;
rate = &hapd->iface->current_rates[hapd->iface->num_rates];
os_memcpy(rate, &mode->rates[i],
sizeof(struct hostapd_rate_data));
rate->rate = mode->rates[i];
if (hostapd_rate_found(basic_rates, rate->rate)) {
rate->flags |= HOSTAPD_RATE_BASIC;
num_basic_rates++;
} else
rate->flags &= ~HOSTAPD_RATE_BASIC;
}
wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
hapd->iface->num_rates, rate->rate, rate->flags);
hapd->iface->num_rates++;

View file

@ -31,19 +31,12 @@ struct hostapd_channel_data {
u8 max_tx_power; /* maximum transmit power in dBm */
};
#define HOSTAPD_RATE_BASIC 0x00000002
struct hostapd_rate_data {
int rate; /* rate in 100 kbps */
int flags; /* HOSTAPD_RATE_ flags for internal use */
};
struct hostapd_hw_modes {
hostapd_hw_mode mode;
int num_channels;
struct hostapd_channel_data *channels;
int num_rates;
struct hostapd_rate_data *rates;
int *rates; /* array of rates in 100 kbps units */
u16 ht_capab;
u8 mcs_set[16];
u8 a_mpdu_params;

View file

@ -1193,7 +1193,7 @@ static struct hostapd_hw_modes * hostap_get_hw_feature_data(void *priv,
mode->num_rates = 4;
clen = mode->num_channels * sizeof(struct hostapd_channel_data);
rlen = mode->num_rates * sizeof(struct hostapd_rate_data);
rlen = mode->num_rates * sizeof(int);
mode->channels = os_zalloc(clen);
mode->rates = os_zalloc(rlen);
@ -1212,10 +1212,10 @@ static struct hostapd_hw_modes * hostap_get_hw_feature_data(void *priv,
mode->channels[i].flag = HOSTAPD_CHAN_DISABLED;
}
mode->rates[0].rate = 10;
mode->rates[1].rate = 20;
mode->rates[2].rate = 55;
mode->rates[3].rate = 110;
mode->rates[0] = 10;
mode->rates[1] = 20;
mode->rates[2] = 55;
mode->rates[3] = 110;
return mode;
}

View file

@ -2376,7 +2376,7 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
mode->num_rates++;
}
mode->rates = calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
mode->rates = calloc(mode->num_rates, sizeof(int));
if (!mode->rates)
return NL_SKIP;
@ -2387,11 +2387,11 @@ static int phy_info_handler(struct nl_msg *msg, void *arg)
nla_len(nl_rate), rate_policy);
if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
continue;
mode->rates[idx].rate = 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 &&
mode->rates[idx].rate > 200)
mode->rates[idx] > 200)
mode->mode = HOSTAPD_MODE_IEEE80211G;
idx++;
@ -2444,7 +2444,7 @@ wpa_driver_nl80211_add_11b(struct hostapd_hw_modes *modes, u16 *num_modes)
mode11g->num_channels * sizeof(struct hostapd_channel_data));
mode->num_rates = 0;
mode->rates = os_malloc(4 * sizeof(struct hostapd_rate_data));
mode->rates = os_malloc(4 * sizeof(int));
if (mode->rates == NULL) {
os_free(mode->channels);
(*num_modes)--;
@ -2452,10 +2452,8 @@ wpa_driver_nl80211_add_11b(struct hostapd_hw_modes *modes, u16 *num_modes)
}
for (i = 0; i < mode11g->num_rates; i++) {
if (mode11g->rates[i].rate != 10 &&
mode11g->rates[i].rate != 20 &&
mode11g->rates[i].rate != 55 &&
mode11g->rates[i].rate != 110)
if (mode11g->rates[i] != 10 && mode11g->rates[i] != 20 &&
mode11g->rates[i] != 55 && mode11g->rates[i] != 110)
continue;
mode->rates[mode->num_rates] = mode11g->rates[i];
mode->num_rates++;

View file

@ -2413,37 +2413,37 @@ wpa_driver_test_get_hw_feature_data(void *priv, u16 *num_modes, u16 *flags)
modes[0].num_channels = 1;
modes[0].num_rates = 1;
modes[0].channels = os_zalloc(sizeof(struct hostapd_channel_data));
modes[0].rates = os_zalloc(sizeof(struct hostapd_rate_data));
modes[0].rates = os_zalloc(sizeof(int));
if (modes[0].channels == NULL || modes[0].rates == NULL)
goto fail;
modes[0].channels[0].chan = 1;
modes[0].channels[0].freq = 2412;
modes[0].channels[0].flag = 0;
modes[0].rates[0].rate = 10;
modes[0].rates[0] = 10;
modes[1].mode = HOSTAPD_MODE_IEEE80211B;
modes[1].num_channels = 1;
modes[1].num_rates = 1;
modes[1].channels = os_zalloc(sizeof(struct hostapd_channel_data));
modes[1].rates = os_zalloc(sizeof(struct hostapd_rate_data));
modes[1].rates = os_zalloc(sizeof(int));
if (modes[1].channels == NULL || modes[1].rates == NULL)
goto fail;
modes[1].channels[0].chan = 1;
modes[1].channels[0].freq = 2412;
modes[1].channels[0].flag = 0;
modes[1].rates[0].rate = 10;
modes[1].rates[0] = 10;
modes[2].mode = HOSTAPD_MODE_IEEE80211A;
modes[2].num_channels = 1;
modes[2].num_rates = 1;
modes[2].channels = os_zalloc(sizeof(struct hostapd_channel_data));
modes[2].rates = os_zalloc(sizeof(struct hostapd_rate_data));
modes[2].rates = os_zalloc(sizeof(int));
if (modes[2].channels == NULL || modes[2].rates == NULL)
goto fail;
modes[2].channels[0].chan = 60;
modes[2].channels[0].freq = 5300;
modes[2].channels[0].flag = 0;
modes[2].rates[0].rate = 60;
modes[2].rates[0] = 60;
return modes;

View file

@ -391,20 +391,16 @@ static void ieee80211_send_assoc(struct wpa_supplicant *wpa_s)
blen += len + 2;
*pos++ = WLAN_EID_SUPP_RATES;
*pos++ = len;
for (i = 0; i < len; i++) {
int rate = wpa_s->mlme.curr_rates[i].rate;
*pos++ = (u8) (rate / 5);
}
for (i = 0; i < len; i++)
*pos++ = (u8) (wpa_s->mlme.curr_rates[i] / 5);
if (wpa_s->mlme.num_curr_rates > len) {
pos = buf + blen;
blen += wpa_s->mlme.num_curr_rates - len + 2;
*pos++ = WLAN_EID_EXT_SUPP_RATES;
*pos++ = wpa_s->mlme.num_curr_rates - len;
for (i = len; i < wpa_s->mlme.num_curr_rates; i++) {
int rate = wpa_s->mlme.curr_rates[i].rate;
*pos++ = (u8) (rate / 5);
}
for (i = len; i < wpa_s->mlme.num_curr_rates; i++)
*pos++ = (u8) (wpa_s->mlme.curr_rates[i] / 5);
}
if (wpa_s->mlme.extra_ie && wpa_s->mlme.auth_alg != WLAN_AUTH_FT) {
@ -671,7 +667,6 @@ static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
supp_rates[0] = WLAN_EID_SUPP_RATES;
supp_rates[1] = 0;
for (i = 0; i < wpa_s->mlme.num_curr_rates; i++) {
struct hostapd_rate_data *rate = &wpa_s->mlme.curr_rates[i];
if (esupp_rates) {
pos = buf + len;
len++;
@ -687,7 +682,7 @@ static void ieee80211_send_probe_req(struct wpa_supplicant *wpa_s,
len++;
supp_rates[1]++;
}
*pos++ = rate->rate / 5;
*pos++ = wpa_s->mlme.curr_rates[i] / 5;
}
if (wpa_s->mlme.extra_probe_ie) {
@ -2399,7 +2394,7 @@ static int ieee80211_sta_join_ibss(struct wpa_supplicant *wpa_s,
if (local->conf.phymode == MODE_ATHEROS_TURBO)
rate *= 2;
for (j = 0; j < local->num_curr_rates; j++)
if (local->curr_rates[j].rate == rate)
if (local->curr_rates[j] == rate)
rates |= BIT(j);
}
wpa_s->mlme.supp_rates_bits = rates;
@ -2468,7 +2463,7 @@ static int ieee80211_sta_create_ibss(struct wpa_supplicant *wpa_s)
pos = bss->supp_rates;
#if 0 /* FIX */
for (i = 0; i < local->num_curr_rates; i++) {
int rate = local->curr_rates[i].rate;
int rate = local->curr_rates[i];
if (local->conf.phymode == MODE_ATHEROS_TURBO)
rate /= 2;
*pos++ = (u8) (rate / 5);

View file

@ -275,7 +275,7 @@ struct wpa_client_mlme {
unsigned int hw_modes; /* bitfield of allowed hardware modes;
* (1 << HOSTAPD_MODE_*) */
int num_curr_rates;
struct hostapd_rate_data *curr_rates;
int *curr_rates;
int freq; /* The current frequency in MHz */
int channel; /* The current IEEE 802.11 channel number */