Use a shared helper function for RSN supplicant capabilities

Avoid practically copy-pasted code for determining local RSN
capabilities.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2020-03-23 00:08:38 +02:00
parent b17b7a8e53
commit 8b63a58166
3 changed files with 20 additions and 22 deletions

View file

@ -178,7 +178,6 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
u8 *buf, *pos, *ftie_len, *ftie_pos, *fte_mic, *elem_count; u8 *buf, *pos, *ftie_len, *ftie_pos, *fte_mic, *elem_count;
struct rsn_mdie *mdie; struct rsn_mdie *mdie;
struct rsn_ie_hdr *rsnie; struct rsn_ie_hdr *rsnie;
u16 capab;
int mdie_len; int mdie_len;
u8 rsnxe[10]; u8 rsnxe[10];
size_t rsnxe_len; size_t rsnxe_len;
@ -258,16 +257,7 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
pos += RSN_SELECTOR_LEN; pos += RSN_SELECTOR_LEN;
/* RSN Capabilities */ /* RSN Capabilities */
capab = 0; WPA_PUT_LE16(pos, rsn_supp_capab(sm));
if (sm->mfp)
capab |= WPA_CAPABILITY_MFPC;
if (sm->mfp == 2)
capab |= WPA_CAPABILITY_MFPR;
if (sm->ocv)
capab |= WPA_CAPABILITY_OCVC;
if (sm->ext_key_id)
capab |= WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST;
WPA_PUT_LE16(pos, capab);
pos += 2; pos += 2;
/* PMKID Count */ /* PMKID Count */

View file

@ -105,6 +105,23 @@ static int wpa_gen_wpa_ie_wpa(u8 *wpa_ie, size_t wpa_ie_len,
} }
u16 rsn_supp_capab(struct wpa_sm *sm)
{
u16 capab = 0;
if (sm->mfp)
capab |= WPA_CAPABILITY_MFPC;
if (sm->mfp == 2)
capab |= WPA_CAPABILITY_MFPR;
if (sm->ocv)
capab |= WPA_CAPABILITY_OCVC;
if (sm->ext_key_id)
capab |= WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST;
return capab;
}
static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len, static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len,
int pairwise_cipher, int group_cipher, int pairwise_cipher, int group_cipher,
int key_mgmt, int mgmt_group_cipher, int key_mgmt, int mgmt_group_cipher,
@ -112,7 +129,6 @@ static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len,
{ {
u8 *pos; u8 *pos;
struct rsn_ie_hdr *hdr; struct rsn_ie_hdr *hdr;
u16 capab;
u32 suite; u32 suite;
if (rsn_ie_len < sizeof(*hdr) + RSN_SELECTOR_LEN + if (rsn_ie_len < sizeof(*hdr) + RSN_SELECTOR_LEN +
@ -214,16 +230,7 @@ static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len,
pos += RSN_SELECTOR_LEN; pos += RSN_SELECTOR_LEN;
/* RSN Capabilities */ /* RSN Capabilities */
capab = 0; WPA_PUT_LE16(pos, rsn_supp_capab(sm));
if (sm->mfp)
capab |= WPA_CAPABILITY_MFPC;
if (sm->mfp == 2)
capab |= WPA_CAPABILITY_MFPR;
if (sm->ocv)
capab |= WPA_CAPABILITY_OCVC;
if (sm->ext_key_id)
capab |= WPA_CAPABILITY_EXT_KEY_ID_FOR_UNICAST;
WPA_PUT_LE16(pos, capab);
pos += 2; pos += 2;
if (sm->cur_pmksa) { if (sm->cur_pmksa) {

View file

@ -13,5 +13,6 @@ struct wpa_sm;
int wpa_gen_wpa_ie(struct wpa_sm *sm, u8 *wpa_ie, size_t wpa_ie_len); int wpa_gen_wpa_ie(struct wpa_sm *sm, u8 *wpa_ie, size_t wpa_ie_len);
int wpa_gen_rsnxe(struct wpa_sm *sm, u8 *rsnxe, size_t rsnxe_len); int wpa_gen_rsnxe(struct wpa_sm *sm, u8 *rsnxe, size_t rsnxe_len);
u16 rsn_supp_capab(struct wpa_sm *sm);
#endif /* WPA_IE_H */ #endif /* WPA_IE_H */