Use a shared helper function for merging supported rate lists

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-08-19 17:52:41 +03:00
parent a2f94dbe62
commit 3489cfb09c
4 changed files with 47 additions and 41 deletions

View file

@ -251,23 +251,9 @@ void ap_list_process_beacon(struct hostapd_iface *iface,
ap->ssid_len = len; ap->ssid_len = len;
} }
os_memset(ap->supported_rates, 0, WLAN_SUPP_RATES_MAX); merge_byte_arrays(ap->supported_rates, WLAN_SUPP_RATES_MAX,
len = 0; elems->supp_rates, elems->supp_rates_len,
if (elems->supp_rates) { elems->ext_supp_rates, elems->ext_supp_rates_len);
len = elems->supp_rates_len;
if (len > WLAN_SUPP_RATES_MAX)
len = WLAN_SUPP_RATES_MAX;
os_memcpy(ap->supported_rates, elems->supp_rates, len);
}
if (elems->ext_supp_rates) {
int len2;
if (len + elems->ext_supp_rates_len > WLAN_SUPP_RATES_MAX)
len2 = WLAN_SUPP_RATES_MAX - len;
else
len2 = elems->ext_supp_rates_len;
os_memcpy(ap->supported_rates + len, elems->ext_supp_rates,
len2);
}
ap->wpa = elems->wpa_ie != NULL; ap->wpa = elems->wpa_ie != NULL;

View file

@ -586,35 +586,20 @@ static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta,
return WLAN_STATUS_UNSPECIFIED_FAILURE; return WLAN_STATUS_UNSPECIFIED_FAILURE;
} }
if (elems->supp_rates_len > sizeof(sta->supported_rates)) { if (elems->supp_rates_len + elems->ext_supp_rates_len >
sizeof(sta->supported_rates)) {
hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG, HOSTAPD_LEVEL_DEBUG,
"Invalid supported rates element length %d", "Invalid supported rates element length %d+%d",
elems->supp_rates_len); elems->supp_rates_len,
elems->ext_supp_rates_len);
return WLAN_STATUS_UNSPECIFIED_FAILURE; return WLAN_STATUS_UNSPECIFIED_FAILURE;
} }
os_memset(sta->supported_rates, 0, sizeof(sta->supported_rates)); sta->supported_rates_len = merge_byte_arrays(
os_memcpy(sta->supported_rates, elems->supp_rates, sta->supported_rates, sizeof(sta->supported_rates),
elems->supp_rates_len); elems->supp_rates, elems->supp_rates_len,
sta->supported_rates_len = elems->supp_rates_len; elems->ext_supp_rates, elems->ext_supp_rates_len);
if (elems->ext_supp_rates) {
if (elems->supp_rates_len + elems->ext_supp_rates_len >
sizeof(sta->supported_rates)) {
hostapd_logger(hapd, sta->addr,
HOSTAPD_MODULE_IEEE80211,
HOSTAPD_LEVEL_DEBUG,
"Invalid supported rates element length"
" %d+%d", elems->supp_rates_len,
elems->ext_supp_rates_len);
return WLAN_STATUS_UNSPECIFIED_FAILURE;
}
os_memcpy(sta->supported_rates + elems->supp_rates_len,
elems->ext_supp_rates, elems->ext_supp_rates_len);
sta->supported_rates_len += elems->ext_supp_rates_len;
}
return WLAN_STATUS_SUCCESS; return WLAN_STATUS_SUCCESS;
} }

View file

@ -578,3 +578,35 @@ int is_hex(const u8 *data, size_t len)
} }
return 0; return 0;
} }
size_t merge_byte_arrays(u8 *res, size_t res_len,
const u8 *src1, size_t src1_len,
const u8 *src2, size_t src2_len)
{
size_t len = 0;
os_memset(res, 0, res_len);
if (src1) {
if (src1_len >= res_len) {
os_memcpy(res, src1, res_len);
return res_len;
}
os_memcpy(res, src1, src1_len);
len += src1_len;
}
if (src2) {
if (len + src2_len >= res_len) {
os_memcpy(res + len, src2, res_len - len);
return res_len;
}
os_memcpy(res + len, src2, src2_len);
len += src2_len;
}
return len;
}

View file

@ -448,6 +448,9 @@ const char * wpa_ssid_txt(const u8 *ssid, size_t ssid_len);
char * wpa_config_parse_string(const char *value, size_t *len); char * wpa_config_parse_string(const char *value, size_t *len);
int is_hex(const u8 *data, size_t len); int is_hex(const u8 *data, size_t len);
size_t merge_byte_arrays(u8 *res, size_t res_len,
const u8 *src1, size_t src1_len,
const u8 *src2, size_t src2_len);
static inline int is_zero_ether_addr(const u8 *a) static inline int is_zero_ether_addr(const u8 *a)
{ {