Move WPA cipher information into a shared location

Try to share most of the cipher information like key and RSC lengths and
suite selector conversions, etc. in wpa_common.c to avoid having similar
code throughout the WPA implementation for handling cipher specific
behavior.

Signed-hostap: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2012-08-30 11:53:54 +03:00
parent 7b1aa4fe30
commit c3550295fb
9 changed files with 256 additions and 510 deletions

View file

@ -278,28 +278,6 @@ static void wpa_auth_pmksa_free_cb(struct rsn_pmksa_cache_entry *entry,
} }
static void wpa_group_set_key_len(struct wpa_group *group, int cipher)
{
switch (cipher) {
case WPA_CIPHER_CCMP:
group->GTK_len = 16;
break;
case WPA_CIPHER_GCMP:
group->GTK_len = 16;
break;
case WPA_CIPHER_TKIP:
group->GTK_len = 32;
break;
case WPA_CIPHER_WEP104:
group->GTK_len = 13;
break;
case WPA_CIPHER_WEP40:
group->GTK_len = 5;
break;
}
}
static int wpa_group_init_gmk_and_counter(struct wpa_authenticator *wpa_auth, static int wpa_group_init_gmk_and_counter(struct wpa_authenticator *wpa_auth,
struct wpa_group *group) struct wpa_group *group)
{ {
@ -341,8 +319,7 @@ static struct wpa_group * wpa_group_init(struct wpa_authenticator *wpa_auth,
group->GTKAuthenticator = TRUE; group->GTKAuthenticator = TRUE;
group->vlan_id = vlan_id; group->vlan_id = vlan_id;
group->GTK_len = wpa_cipher_key_len(wpa_auth->conf.wpa_group);
wpa_group_set_key_len(group, wpa_auth->conf.wpa_group);
if (random_pool_ready() != 1) { if (random_pool_ready() != 1) {
wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool " wpa_printf(MSG_INFO, "WPA: Not enough entropy in random pool "
@ -517,7 +494,7 @@ int wpa_reconfig(struct wpa_authenticator *wpa_auth,
* configuration. * configuration.
*/ */
group = wpa_auth->group; group = wpa_auth->group;
wpa_group_set_key_len(group, wpa_auth->conf.wpa_group); group->GTK_len = wpa_cipher_key_len(wpa_auth->conf.wpa_group);
group->GInit = TRUE; group->GInit = TRUE;
wpa_group_sm_step(wpa_auth, group); wpa_group_sm_step(wpa_auth, group);
group->GInit = FALSE; group->GInit = FALSE;
@ -1291,23 +1268,7 @@ void __wpa_send_eapol(struct wpa_authenticator *wpa_auth,
WPA_PUT_BE16(key->key_info, key_info); WPA_PUT_BE16(key->key_info, key_info);
alg = pairwise ? sm->pairwise : wpa_auth->conf.wpa_group; alg = pairwise ? sm->pairwise : wpa_auth->conf.wpa_group;
switch (alg) { WPA_PUT_BE16(key->key_length, wpa_cipher_key_len(alg));
case WPA_CIPHER_CCMP:
WPA_PUT_BE16(key->key_length, 16);
break;
case WPA_CIPHER_GCMP:
WPA_PUT_BE16(key->key_length, 16);
break;
case WPA_CIPHER_TKIP:
WPA_PUT_BE16(key->key_length, 32);
break;
case WPA_CIPHER_WEP40:
WPA_PUT_BE16(key->key_length, 5);
break;
case WPA_CIPHER_WEP104:
WPA_PUT_BE16(key->key_length, 13);
break;
}
if (key_info & WPA_KEY_INFO_SMK_MESSAGE) if (key_info & WPA_KEY_INFO_SMK_MESSAGE)
WPA_PUT_BE16(key->key_length, 0); WPA_PUT_BE16(key->key_length, 0);
@ -1540,24 +1501,6 @@ int wpa_auth_sm_event(struct wpa_state_machine *sm, wpa_event event)
} }
static enum wpa_alg wpa_alg_enum(int alg)
{
switch (alg) {
case WPA_CIPHER_CCMP:
return WPA_ALG_CCMP;
case WPA_CIPHER_GCMP:
return WPA_ALG_GCMP;
case WPA_CIPHER_TKIP:
return WPA_ALG_TKIP;
case WPA_CIPHER_WEP104:
case WPA_CIPHER_WEP40:
return WPA_ALG_WEP;
default:
return WPA_ALG_NONE;
}
}
SM_STATE(WPA_PTK, INITIALIZE) SM_STATE(WPA_PTK, INITIALIZE)
{ {
SM_ENTRY_MA(WPA_PTK, INITIALIZE, wpa_ptk); SM_ENTRY_MA(WPA_PTK, INITIALIZE, wpa_ptk);
@ -2097,18 +2040,8 @@ SM_STATE(WPA_PTK, PTKINITDONE)
SM_ENTRY_MA(WPA_PTK, PTKINITDONE, wpa_ptk); SM_ENTRY_MA(WPA_PTK, PTKINITDONE, wpa_ptk);
sm->EAPOLKeyReceived = FALSE; sm->EAPOLKeyReceived = FALSE;
if (sm->Pair) { if (sm->Pair) {
enum wpa_alg alg; enum wpa_alg alg = wpa_cipher_to_alg(sm->pairwise);
int klen; int klen = wpa_cipher_key_len(sm->pairwise);
if (sm->pairwise == WPA_CIPHER_TKIP) {
alg = WPA_ALG_TKIP;
klen = 32;
} else if (sm->pairwise == WPA_CIPHER_GCMP) {
alg = WPA_ALG_GCMP;
klen = 16;
} else {
alg = WPA_ALG_CCMP;
klen = 16;
}
if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0, if (wpa_auth_set_key(sm->wpa_auth, 0, alg, sm->addr, 0,
sm->PTK.tk1, klen)) { sm->PTK.tk1, klen)) {
wpa_sta_disconnect(sm->wpa_auth, sm->addr); wpa_sta_disconnect(sm->wpa_auth, sm->addr);
@ -2657,7 +2590,7 @@ static int wpa_group_config_group_keys(struct wpa_authenticator *wpa_auth,
int ret = 0; int ret = 0;
if (wpa_auth_set_key(wpa_auth, group->vlan_id, if (wpa_auth_set_key(wpa_auth, group->vlan_id,
wpa_alg_enum(wpa_auth->conf.wpa_group), wpa_cipher_to_alg(wpa_auth->conf.wpa_group),
broadcast_ether_addr, group->GN, broadcast_ether_addr, group->GN,
group->GTK[group->GN - 1], group->GTK_len) < 0) group->GTK[group->GN - 1], group->GTK_len) < 0)
ret = -1; ret = -1;
@ -2797,25 +2730,6 @@ static const char * wpa_bool_txt(int bool)
} }
static int wpa_cipher_bits(int cipher)
{
switch (cipher) {
case WPA_CIPHER_CCMP:
return 128;
case WPA_CIPHER_GCMP:
return 128;
case WPA_CIPHER_TKIP:
return 256;
case WPA_CIPHER_WEP104:
return 104;
case WPA_CIPHER_WEP40:
return 40;
default:
return 0;
}
}
#define RSN_SUITE "%02x-%02x-%02x-%d" #define RSN_SUITE "%02x-%02x-%02x-%d"
#define RSN_SUITE_ARG(s) \ #define RSN_SUITE_ARG(s) \
((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
@ -2878,7 +2792,7 @@ int wpa_get_mib(struct wpa_authenticator *wpa_auth, char *buf, size_t buflen)
!!wpa_auth->conf.wpa_strict_rekey, !!wpa_auth->conf.wpa_strict_rekey,
dot11RSNAConfigGroupUpdateCount, dot11RSNAConfigGroupUpdateCount,
dot11RSNAConfigPairwiseUpdateCount, dot11RSNAConfigPairwiseUpdateCount,
wpa_cipher_bits(wpa_auth->conf.wpa_group), wpa_cipher_key_len(wpa_auth->conf.wpa_group) * 8,
dot11RSNAConfigPMKLifetime, dot11RSNAConfigPMKLifetime,
dot11RSNAConfigPMKReauthThreshold, dot11RSNAConfigPMKReauthThreshold,
dot11RSNAConfigSATimeout, dot11RSNAConfigSATimeout,
@ -2921,31 +2835,10 @@ int wpa_get_mib_sta(struct wpa_state_machine *sm, char *buf, size_t buflen)
/* dot11RSNAStatsEntry */ /* dot11RSNAStatsEntry */
if (sm->wpa == WPA_VERSION_WPA) { pairwise = wpa_cipher_to_suite(sm->wpa == WPA_VERSION_WPA2 ?
if (sm->pairwise == WPA_CIPHER_CCMP) WPA_PROTO_RSN : WPA_PROTO_WPA,
pairwise = WPA_CIPHER_SUITE_CCMP; sm->pairwise);
else if (sm->pairwise == WPA_CIPHER_TKIP) if (pairwise == 0)
pairwise = WPA_CIPHER_SUITE_TKIP;
else if (sm->pairwise == WPA_CIPHER_WEP104)
pairwise = WPA_CIPHER_SUITE_WEP104;
else if (sm->pairwise == WPA_CIPHER_WEP40)
pairwise = WPA_CIPHER_SUITE_WEP40;
else if (sm->pairwise == WPA_CIPHER_NONE)
pairwise = WPA_CIPHER_SUITE_NONE;
} else if (sm->wpa == WPA_VERSION_WPA2) {
if (sm->pairwise == WPA_CIPHER_CCMP)
pairwise = RSN_CIPHER_SUITE_CCMP;
else if (sm->pairwise == WPA_CIPHER_GCMP)
pairwise = RSN_CIPHER_SUITE_GCMP;
else if (sm->pairwise == WPA_CIPHER_TKIP)
pairwise = RSN_CIPHER_SUITE_TKIP;
else if (sm->pairwise == WPA_CIPHER_WEP104)
pairwise = RSN_CIPHER_SUITE_WEP104;
else if (sm->pairwise == WPA_CIPHER_WEP40)
pairwise = RSN_CIPHER_SUITE_WEP40;
else if (sm->pairwise == WPA_CIPHER_NONE)
pairwise = RSN_CIPHER_SUITE_NONE;
} else
return 0; return 0;
ret = os_snprintf( ret = os_snprintf(

View file

@ -754,16 +754,9 @@ void wpa_ft_install_ptk(struct wpa_state_machine *sm)
int klen; int klen;
/* MLME-SETKEYS.request(PTK) */ /* MLME-SETKEYS.request(PTK) */
if (sm->pairwise == WPA_CIPHER_TKIP) { alg = wpa_cipher_to_alg(sm->pairwise);
alg = WPA_ALG_TKIP; klen = wpa_cipher_key_len(sm->pairwise);
klen = 32; if (!wpa_cipher_valid_pairwise(sm->pairwise)) {
} else if (sm->pairwise == WPA_CIPHER_CCMP) {
alg = WPA_ALG_CCMP;
klen = 16;
} else if (sm->pairwise == WPA_CIPHER_GCMP) {
alg = WPA_ALG_GCMP;
klen = 16;
} else {
wpa_printf(MSG_DEBUG, "FT: Unknown pairwise alg 0x%x - skip " wpa_printf(MSG_DEBUG, "FT: Unknown pairwise alg 0x%x - skip "
"PTK configuration", sm->pairwise); "PTK configuration", sm->pairwise);
return; return;

View file

@ -29,6 +29,7 @@ static int wpa_write_wpa_ie(struct wpa_auth_config *conf, u8 *buf, size_t len)
struct wpa_ie_hdr *hdr; struct wpa_ie_hdr *hdr;
int num_suites; int num_suites;
u8 *pos, *count; u8 *pos, *count;
u32 suite;
hdr = (struct wpa_ie_hdr *) buf; hdr = (struct wpa_ie_hdr *) buf;
hdr->elem_id = WLAN_EID_VENDOR_SPECIFIC; hdr->elem_id = WLAN_EID_VENDOR_SPECIFIC;
@ -36,46 +37,25 @@ static int wpa_write_wpa_ie(struct wpa_auth_config *conf, u8 *buf, size_t len)
WPA_PUT_LE16(hdr->version, WPA_VERSION); WPA_PUT_LE16(hdr->version, WPA_VERSION);
pos = (u8 *) (hdr + 1); pos = (u8 *) (hdr + 1);
if (conf->wpa_group == WPA_CIPHER_CCMP) { suite = wpa_cipher_to_suite(WPA_PROTO_WPA, conf->wpa_group);
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP); if (suite == 0) {
} else if (conf->wpa_group == WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP);
} else if (conf->wpa_group == WPA_CIPHER_WEP104) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_WEP104);
} else if (conf->wpa_group == WPA_CIPHER_WEP40) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_WEP40);
} else {
wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).", wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).",
conf->wpa_group); conf->wpa_group);
return -1; return -1;
} }
RSN_SELECTOR_PUT(pos, suite);
pos += WPA_SELECTOR_LEN; pos += WPA_SELECTOR_LEN;
num_suites = 0;
count = pos; count = pos;
pos += 2; pos += 2;
if (conf->wpa_pairwise & WPA_CIPHER_CCMP) { num_suites = wpa_cipher_put_suites(pos, conf->wpa_pairwise);
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP);
pos += WPA_SELECTOR_LEN;
num_suites++;
}
if (conf->wpa_pairwise & WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP);
pos += WPA_SELECTOR_LEN;
num_suites++;
}
if (conf->wpa_pairwise & WPA_CIPHER_NONE) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_NONE);
pos += WPA_SELECTOR_LEN;
num_suites++;
}
if (num_suites == 0) { if (num_suites == 0) {
wpa_printf(MSG_DEBUG, "Invalid pairwise cipher (%d).", wpa_printf(MSG_DEBUG, "Invalid pairwise cipher (%d).",
conf->wpa_pairwise); conf->wpa_pairwise);
return -1; return -1;
} }
pos += num_suites * WPA_SELECTOR_LEN;
WPA_PUT_LE16(count, num_suites); WPA_PUT_LE16(count, num_suites);
num_suites = 0; num_suites = 0;
@ -112,30 +92,23 @@ int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
const u8 *pmkid) const u8 *pmkid)
{ {
struct rsn_ie_hdr *hdr; struct rsn_ie_hdr *hdr;
int num_suites; int num_suites, res;
u8 *pos, *count; u8 *pos, *count;
u16 capab; u16 capab;
u32 suite;
hdr = (struct rsn_ie_hdr *) buf; hdr = (struct rsn_ie_hdr *) buf;
hdr->elem_id = WLAN_EID_RSN; hdr->elem_id = WLAN_EID_RSN;
WPA_PUT_LE16(hdr->version, RSN_VERSION); WPA_PUT_LE16(hdr->version, RSN_VERSION);
pos = (u8 *) (hdr + 1); pos = (u8 *) (hdr + 1);
if (conf->wpa_group == WPA_CIPHER_CCMP) { suite = wpa_cipher_to_suite(WPA_PROTO_RSN, conf->wpa_group);
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP); if (suite == 0) {
} else if (conf->wpa_group == WPA_CIPHER_GCMP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP);
} else if (conf->wpa_group == WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
} else if (conf->wpa_group == WPA_CIPHER_WEP104) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_WEP104);
} else if (conf->wpa_group == WPA_CIPHER_WEP40) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_WEP40);
} else {
wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).", wpa_printf(MSG_DEBUG, "Invalid group cipher (%d).",
conf->wpa_group); conf->wpa_group);
return -1; return -1;
} }
RSN_SELECTOR_PUT(pos, suite);
pos += RSN_SELECTOR_LEN; pos += RSN_SELECTOR_LEN;
num_suites = 0; num_suites = 0;
@ -150,26 +123,9 @@ int wpa_write_rsn_ie(struct wpa_auth_config *conf, u8 *buf, size_t len,
} }
#endif /* CONFIG_RSN_TESTING */ #endif /* CONFIG_RSN_TESTING */
if (conf->rsn_pairwise & WPA_CIPHER_CCMP) { res = rsn_cipher_put_suites(pos, conf->rsn_pairwise);
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP); num_suites += res;
pos += RSN_SELECTOR_LEN; pos += res * RSN_SELECTOR_LEN;
num_suites++;
}
if (conf->rsn_pairwise & WPA_CIPHER_GCMP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP);
pos += RSN_SELECTOR_LEN;
num_suites++;
}
if (conf->rsn_pairwise & WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
pos += RSN_SELECTOR_LEN;
num_suites++;
}
if (conf->rsn_pairwise & WPA_CIPHER_NONE) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NONE);
pos += RSN_SELECTOR_LEN;
num_suites++;
}
#ifdef CONFIG_RSN_TESTING #ifdef CONFIG_RSN_TESTING
if (rsn_testing) { if (rsn_testing) {
@ -457,34 +413,16 @@ int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
selector = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; selector = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X;
wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector; wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector;
selector = wpa_cipher_to_suite(WPA_PROTO_RSN,
data.pairwise_cipher);
if (!selector)
selector = RSN_CIPHER_SUITE_CCMP; selector = RSN_CIPHER_SUITE_CCMP;
if (data.pairwise_cipher & WPA_CIPHER_CCMP)
selector = RSN_CIPHER_SUITE_CCMP;
else if (data.pairwise_cipher & WPA_CIPHER_GCMP)
selector = RSN_CIPHER_SUITE_GCMP;
else if (data.pairwise_cipher & WPA_CIPHER_TKIP)
selector = RSN_CIPHER_SUITE_TKIP;
else if (data.pairwise_cipher & WPA_CIPHER_WEP104)
selector = RSN_CIPHER_SUITE_WEP104;
else if (data.pairwise_cipher & WPA_CIPHER_WEP40)
selector = RSN_CIPHER_SUITE_WEP40;
else if (data.pairwise_cipher & WPA_CIPHER_NONE)
selector = RSN_CIPHER_SUITE_NONE;
wpa_auth->dot11RSNAPairwiseCipherSelected = selector; wpa_auth->dot11RSNAPairwiseCipherSelected = selector;
selector = wpa_cipher_to_suite(WPA_PROTO_RSN,
data.group_cipher);
if (!selector)
selector = RSN_CIPHER_SUITE_CCMP; selector = RSN_CIPHER_SUITE_CCMP;
if (data.group_cipher & WPA_CIPHER_CCMP)
selector = RSN_CIPHER_SUITE_CCMP;
else if (data.group_cipher & WPA_CIPHER_GCMP)
selector = RSN_CIPHER_SUITE_GCMP;
else if (data.group_cipher & WPA_CIPHER_TKIP)
selector = RSN_CIPHER_SUITE_TKIP;
else if (data.group_cipher & WPA_CIPHER_WEP104)
selector = RSN_CIPHER_SUITE_WEP104;
else if (data.group_cipher & WPA_CIPHER_WEP40)
selector = RSN_CIPHER_SUITE_WEP40;
else if (data.group_cipher & WPA_CIPHER_NONE)
selector = RSN_CIPHER_SUITE_NONE;
wpa_auth->dot11RSNAGroupCipherSelected = selector; wpa_auth->dot11RSNAGroupCipherSelected = selector;
} else { } else {
res = wpa_parse_wpa_ie_wpa(wpa_ie, wpa_ie_len, &data); res = wpa_parse_wpa_ie_wpa(wpa_ie, wpa_ie_len, &data);
@ -496,30 +434,16 @@ int wpa_validate_wpa_ie(struct wpa_authenticator *wpa_auth,
selector = WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X; selector = WPA_AUTH_KEY_MGMT_PSK_OVER_802_1X;
wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector; wpa_auth->dot11RSNAAuthenticationSuiteSelected = selector;
selector = WPA_CIPHER_SUITE_TKIP; selector = wpa_cipher_to_suite(WPA_PROTO_WPA,
if (data.pairwise_cipher & WPA_CIPHER_CCMP) data.pairwise_cipher);
selector = WPA_CIPHER_SUITE_CCMP; if (!selector)
else if (data.pairwise_cipher & WPA_CIPHER_TKIP) selector = RSN_CIPHER_SUITE_TKIP;
selector = WPA_CIPHER_SUITE_TKIP;
else if (data.pairwise_cipher & WPA_CIPHER_WEP104)
selector = WPA_CIPHER_SUITE_WEP104;
else if (data.pairwise_cipher & WPA_CIPHER_WEP40)
selector = WPA_CIPHER_SUITE_WEP40;
else if (data.pairwise_cipher & WPA_CIPHER_NONE)
selector = WPA_CIPHER_SUITE_NONE;
wpa_auth->dot11RSNAPairwiseCipherSelected = selector; wpa_auth->dot11RSNAPairwiseCipherSelected = selector;
selector = wpa_cipher_to_suite(WPA_PROTO_WPA,
data.group_cipher);
if (!selector)
selector = WPA_CIPHER_SUITE_TKIP; selector = WPA_CIPHER_SUITE_TKIP;
if (data.group_cipher & WPA_CIPHER_CCMP)
selector = WPA_CIPHER_SUITE_CCMP;
else if (data.group_cipher & WPA_CIPHER_TKIP)
selector = WPA_CIPHER_SUITE_TKIP;
else if (data.group_cipher & WPA_CIPHER_WEP104)
selector = WPA_CIPHER_SUITE_WEP104;
else if (data.group_cipher & WPA_CIPHER_WEP40)
selector = WPA_CIPHER_SUITE_WEP40;
else if (data.group_cipher & WPA_CIPHER_NONE)
selector = WPA_CIPHER_SUITE_NONE;
wpa_auth->dot11RSNAGroupCipherSelected = selector; wpa_auth->dot11RSNAGroupCipherSelected = selector;
} }
if (res) { if (res) {

View file

@ -1073,3 +1073,138 @@ int wpa_insert_pmkid(u8 *ies, size_t ies_len, const u8 *pmkid)
return added; return added;
} }
#endif /* CONFIG_IEEE80211R */ #endif /* CONFIG_IEEE80211R */
int wpa_cipher_key_len(int cipher)
{
switch (cipher) {
case WPA_CIPHER_CCMP:
case WPA_CIPHER_GCMP:
return 16;
case WPA_CIPHER_TKIP:
return 32;
case WPA_CIPHER_WEP104:
return 13;
case WPA_CIPHER_WEP40:
return 5;
}
return 0;
}
int wpa_cipher_rsc_len(int cipher)
{
switch (cipher) {
case WPA_CIPHER_CCMP:
case WPA_CIPHER_GCMP:
case WPA_CIPHER_TKIP:
return 6;
case WPA_CIPHER_WEP104:
case WPA_CIPHER_WEP40:
return 0;
}
return 0;
}
int wpa_cipher_to_alg(int cipher)
{
switch (cipher) {
case WPA_CIPHER_CCMP:
return WPA_ALG_CCMP;
case WPA_CIPHER_GCMP:
return WPA_ALG_GCMP;
case WPA_CIPHER_TKIP:
return WPA_ALG_TKIP;
case WPA_CIPHER_WEP104:
case WPA_CIPHER_WEP40:
return WPA_ALG_WEP;
}
return WPA_ALG_NONE;
}
int wpa_cipher_valid_pairwise(int cipher)
{
return cipher == WPA_CIPHER_CCMP ||
cipher == WPA_CIPHER_GCMP ||
cipher == WPA_CIPHER_TKIP;
}
u32 wpa_cipher_to_suite(int proto, int cipher)
{
if (cipher & WPA_CIPHER_CCMP)
return (proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_CCMP : WPA_CIPHER_SUITE_CCMP);
if (cipher & WPA_CIPHER_GCMP)
return RSN_CIPHER_SUITE_GCMP;
if (cipher & WPA_CIPHER_TKIP)
return (proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_TKIP : WPA_CIPHER_SUITE_TKIP);
if (cipher & WPA_CIPHER_WEP104)
return (proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_WEP104 : WPA_CIPHER_SUITE_WEP104);
if (cipher & WPA_CIPHER_WEP40)
return (proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_WEP40 : WPA_CIPHER_SUITE_WEP40);
if (cipher & WPA_CIPHER_NONE)
return (proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_NONE : WPA_CIPHER_SUITE_NONE);
return 0;
}
int rsn_cipher_put_suites(u8 *pos, int ciphers)
{
int num_suites = 0;
if (ciphers & WPA_CIPHER_CCMP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
pos += RSN_SELECTOR_LEN;
num_suites++;
}
if (ciphers & WPA_CIPHER_GCMP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP);
pos += RSN_SELECTOR_LEN;
num_suites++;
}
if (ciphers & WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
pos += RSN_SELECTOR_LEN;
num_suites++;
}
if (ciphers & WPA_CIPHER_NONE) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NONE);
pos += RSN_SELECTOR_LEN;
num_suites++;
}
return num_suites;
}
int wpa_cipher_put_suites(u8 *pos, int ciphers)
{
int num_suites = 0;
if (ciphers & WPA_CIPHER_CCMP) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP);
pos += WPA_SELECTOR_LEN;
num_suites++;
}
if (ciphers & WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP);
pos += WPA_SELECTOR_LEN;
num_suites++;
}
if (ciphers & WPA_CIPHER_NONE) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_NONE);
pos += WPA_SELECTOR_LEN;
num_suites++;
}
return num_suites;
}

View file

@ -379,4 +379,12 @@ struct wpa_ft_ies {
int wpa_ft_parse_ies(const u8 *ies, size_t ies_len, struct wpa_ft_ies *parse); int wpa_ft_parse_ies(const u8 *ies, size_t ies_len, struct wpa_ft_ies *parse);
int wpa_cipher_key_len(int cipher);
int wpa_cipher_rsc_len(int cipher);
int wpa_cipher_to_alg(int cipher);
int wpa_cipher_valid_pairwise(int cipher);
u32 wpa_cipher_to_suite(int proto, int cipher);
int rsn_cipher_put_suites(u8 *pos, int ciphers);
int wpa_cipher_put_suites(u8 *pos, int ciphers);
#endif /* WPA_COMMON_H */ #endif /* WPA_COMMON_H */

View file

@ -270,12 +270,7 @@ static int wpa_supplicant_process_smk_m2(
/* Include only the selected cipher in pairwise cipher suite */ /* Include only the selected cipher in pairwise cipher suite */
WPA_PUT_LE16(pos, 1); WPA_PUT_LE16(pos, 1);
pos += 2; pos += 2;
if (cipher == WPA_CIPHER_CCMP) RSN_SELECTOR_PUT(pos, wpa_cipher_to_suite(WPA_PROTO_RSN, cipher));
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
else if (cipher == WPA_CIPHER_GCMP)
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP);
else if (cipher == WPA_CIPHER_TKIP)
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
pos += RSN_SELECTOR_LEN; pos += RSN_SELECTOR_LEN;
hdr->len = (pos - peerkey->rsnie_p) - 2; hdr->len = (pos - peerkey->rsnie_p) - 2;
@ -1063,22 +1058,8 @@ int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
count_pos = pos; count_pos = pos;
pos += 2; pos += 2;
count = 0; count = rsn_cipher_put_suites(pos, sm->allowed_pairwise_cipher);
if (sm->allowed_pairwise_cipher & WPA_CIPHER_CCMP) { pos += count * RSN_SELECTOR_LEN;
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
pos += RSN_SELECTOR_LEN;
count++;
}
if (sm->allowed_pairwise_cipher & WPA_CIPHER_GCMP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP);
pos += RSN_SELECTOR_LEN;
count++;
}
if (sm->allowed_pairwise_cipher & WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
pos += RSN_SELECTOR_LEN;
count++;
}
WPA_PUT_LE16(count_pos, count); WPA_PUT_LE16(count_pos, count);
hdr->len = (pos - peerkey->rsnie_i) - 2; hdr->len = (pos - peerkey->rsnie_i) - 2;

View file

@ -520,33 +520,23 @@ static int wpa_supplicant_install_ptk(struct wpa_sm *sm,
wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG,
"WPA: Installing PTK to the driver"); "WPA: Installing PTK to the driver");
switch (sm->pairwise_cipher) { if (sm->pairwise_cipher == WPA_CIPHER_NONE) {
case WPA_CIPHER_CCMP:
alg = WPA_ALG_CCMP;
keylen = 16;
rsclen = 6;
break;
case WPA_CIPHER_GCMP:
alg = WPA_ALG_GCMP;
keylen = 16;
rsclen = 6;
break;
case WPA_CIPHER_TKIP:
alg = WPA_ALG_TKIP;
keylen = 32;
rsclen = 6;
break;
case WPA_CIPHER_NONE:
wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Pairwise Cipher " wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Pairwise Cipher "
"Suite: NONE - do not use pairwise keys"); "Suite: NONE - do not use pairwise keys");
return 0; return 0;
default: }
if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) {
wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Unsupported pairwise cipher %d", "WPA: Unsupported pairwise cipher %d",
sm->pairwise_cipher); sm->pairwise_cipher);
return -1; return -1;
} }
alg = wpa_cipher_to_alg(sm->pairwise_cipher);
keylen = wpa_cipher_key_len(sm->pairwise_cipher);
rsclen = wpa_cipher_rsc_len(sm->pairwise_cipher);
if (sm->proto == WPA_PROTO_RSN) { if (sm->proto == WPA_PROTO_RSN) {
key_rsc = null_rsc; key_rsc = null_rsc;
} else { } else {
@ -579,63 +569,25 @@ static int wpa_supplicant_check_group_cipher(struct wpa_sm *sm,
int *key_rsc_len, int *key_rsc_len,
enum wpa_alg *alg) enum wpa_alg *alg)
{ {
int ret = 0; int klen;
switch (group_cipher) { *alg = wpa_cipher_to_alg(group_cipher);
case WPA_CIPHER_CCMP: if (*alg == WPA_ALG_NONE) {
if (keylen != 16 || maxkeylen < 16) {
ret = -1;
break;
}
*key_rsc_len = 6;
*alg = WPA_ALG_CCMP;
break;
case WPA_CIPHER_GCMP:
if (keylen != 16 || maxkeylen < 16) {
ret = -1;
break;
}
*key_rsc_len = 6;
*alg = WPA_ALG_GCMP;
break;
case WPA_CIPHER_TKIP:
if (keylen != 32 || maxkeylen < 32) {
ret = -1;
break;
}
*key_rsc_len = 6;
*alg = WPA_ALG_TKIP;
break;
case WPA_CIPHER_WEP104:
if (keylen != 13 || maxkeylen < 13) {
ret = -1;
break;
}
*key_rsc_len = 0;
*alg = WPA_ALG_WEP;
break;
case WPA_CIPHER_WEP40:
if (keylen != 5 || maxkeylen < 5) {
ret = -1;
break;
}
*key_rsc_len = 0;
*alg = WPA_ALG_WEP;
break;
default:
wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Unsupported Group Cipher %d", "WPA: Unsupported Group Cipher %d",
group_cipher); group_cipher);
return -1; return -1;
} }
*key_rsc_len = wpa_cipher_rsc_len(group_cipher);
if (ret < 0 ) { klen = wpa_cipher_key_len(group_cipher);
if (keylen != klen || maxkeylen < klen) {
wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Unsupported %s Group Cipher key length %d (%d)", "WPA: Unsupported %s Group Cipher key length %d (%d)",
wpa_cipher_txt(group_cipher), keylen, maxkeylen); wpa_cipher_txt(group_cipher), keylen, maxkeylen);
return -1;
} }
return 0;
return ret;
} }
@ -1135,32 +1087,13 @@ static void wpa_supplicant_process_3_of_4(struct wpa_sm *sm,
} }
keylen = WPA_GET_BE16(key->key_length); keylen = WPA_GET_BE16(key->key_length);
switch (sm->pairwise_cipher) { if (keylen != wpa_cipher_key_len(sm->pairwise_cipher)) {
case WPA_CIPHER_CCMP:
if (keylen != 16) {
wpa_msg(sm->ctx->msg_ctx, MSG_WARNING, wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Invalid CCMP key length %d (src=" MACSTR "WPA: Invalid %s key length %d (src=" MACSTR
")", keylen, MAC2STR(sm->bssid)); ")", wpa_cipher_txt(sm->pairwise_cipher), keylen,
MAC2STR(sm->bssid));
goto failed; goto failed;
} }
break;
case WPA_CIPHER_GCMP:
if (keylen != 16) {
wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Invalid GCMP key length %d (src=" MACSTR
")", keylen, MAC2STR(sm->bssid));
goto failed;
}
break;
case WPA_CIPHER_TKIP:
if (keylen != 32) {
wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
"WPA: Invalid TKIP key length %d (src=" MACSTR
")", keylen, MAC2STR(sm->bssid));
goto failed;
}
break;
}
if (wpa_supplicant_send_4_of_4(sm, sm->bssid, key, ver, key_info, if (wpa_supplicant_send_4_of_4(sm, sm->bssid, key, ver, key_info,
NULL, 0, &sm->ptk)) { NULL, 0, &sm->ptk)) {
@ -1880,25 +1813,6 @@ out:
#ifdef CONFIG_CTRL_IFACE #ifdef CONFIG_CTRL_IFACE
static int wpa_cipher_bits(int cipher)
{
switch (cipher) {
case WPA_CIPHER_CCMP:
return 128;
case WPA_CIPHER_GCMP:
return 128;
case WPA_CIPHER_TKIP:
return 256;
case WPA_CIPHER_WEP104:
return 104;
case WPA_CIPHER_WEP40:
return 40;
default:
return 0;
}
}
static u32 wpa_key_mgmt_suite(struct wpa_sm *sm) static u32 wpa_key_mgmt_suite(struct wpa_sm *sm)
{ {
switch (sm->key_mgmt) { switch (sm->key_mgmt) {
@ -1930,32 +1844,6 @@ static u32 wpa_key_mgmt_suite(struct wpa_sm *sm)
} }
static u32 wpa_cipher_suite(struct wpa_sm *sm, int cipher)
{
switch (cipher) {
case WPA_CIPHER_CCMP:
return (sm->proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_CCMP : WPA_CIPHER_SUITE_CCMP);
case WPA_CIPHER_GCMP:
return RSN_CIPHER_SUITE_GCMP;
case WPA_CIPHER_TKIP:
return (sm->proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_TKIP : WPA_CIPHER_SUITE_TKIP);
case WPA_CIPHER_WEP104:
return (sm->proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_WEP104 : WPA_CIPHER_SUITE_WEP104);
case WPA_CIPHER_WEP40:
return (sm->proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_WEP40 : WPA_CIPHER_SUITE_WEP40);
case WPA_CIPHER_NONE:
return (sm->proto == WPA_PROTO_RSN ?
RSN_CIPHER_SUITE_NONE : WPA_CIPHER_SUITE_NONE);
default:
return 0;
}
}
#define RSN_SUITE "%02x-%02x-%02x-%d" #define RSN_SUITE "%02x-%02x-%02x-%d"
#define RSN_SUITE_ARG(s) \ #define RSN_SUITE_ARG(s) \
((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
@ -2003,7 +1891,7 @@ int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
rsna ? "TRUE" : "FALSE", rsna ? "TRUE" : "FALSE",
rsna ? "TRUE" : "FALSE", rsna ? "TRUE" : "FALSE",
RSN_VERSION, RSN_VERSION,
wpa_cipher_bits(sm->group_cipher), wpa_cipher_key_len(sm->group_cipher) * 8,
sm->dot11RSNAConfigPMKLifetime, sm->dot11RSNAConfigPMKLifetime,
sm->dot11RSNAConfigPMKReauthThreshold, sm->dot11RSNAConfigPMKReauthThreshold,
sm->dot11RSNAConfigSATimeout); sm->dot11RSNAConfigSATimeout);
@ -2023,12 +1911,16 @@ int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen)
"dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n" "dot11RSNAConfigNumberOfGTKSAReplayCounters=0\n"
"dot11RSNA4WayHandshakeFailures=%u\n", "dot11RSNA4WayHandshakeFailures=%u\n",
RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)), RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)),
RSN_SUITE_ARG(wpa_cipher_suite(sm, sm->pairwise_cipher)), RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto,
RSN_SUITE_ARG(wpa_cipher_suite(sm, sm->group_cipher)), sm->pairwise_cipher)),
RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto,
sm->group_cipher)),
pmkid_txt, pmkid_txt,
RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)), RSN_SUITE_ARG(wpa_key_mgmt_suite(sm)),
RSN_SUITE_ARG(wpa_cipher_suite(sm, sm->pairwise_cipher)), RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto,
RSN_SUITE_ARG(wpa_cipher_suite(sm, sm->group_cipher)), sm->pairwise_cipher)),
RSN_SUITE_ARG(wpa_cipher_to_suite(sm->proto,
sm->group_cipher)),
sm->dot11RSNA4WayHandshakeFailures); sm->dot11RSNA4WayHandshakeFailures);
if (ret >= 0 && (size_t) ret < buflen) if (ret >= 0 && (size_t) ret < buflen)
len += ret; len += ret;
@ -2717,33 +2609,10 @@ int wpa_wnmsleep_install_key(struct wpa_sm *sm, u8 subelem_id, u8 *buf)
os_memset(&igd, 0, sizeof(igd)); os_memset(&igd, 0, sizeof(igd));
#endif /* CONFIG_IEEE80211W */ #endif /* CONFIG_IEEE80211W */
switch (sm->group_cipher) { keylen = wpa_cipher_key_len(sm->group_cipher);
case WPA_CIPHER_CCMP: gd.key_rsc_len = wpa_cipher_rsc_len(sm->group_cipher);
keylen = 16; gd.alg = wpa_cipher_to_alg(sm->group_cipher);
gd.key_rsc_len = 6; if (gd.alg == WPA_ALG_NONE) {
gd.alg = WPA_ALG_CCMP;
break;
case WPA_CIPHER_GCMP:
keylen = 16;
gd.key_rsc_len = 6;
gd.alg = WPA_ALG_GCMP;
break;
case WPA_CIPHER_TKIP:
keylen = 32;
gd.key_rsc_len = 6;
gd.alg = WPA_ALG_TKIP;
break;
case WPA_CIPHER_WEP104:
keylen = 13;
gd.key_rsc_len = 0;
gd.alg = WPA_ALG_WEP;
break;
case WPA_CIPHER_WEP40:
keylen = 5;
gd.key_rsc_len = 0;
gd.alg = WPA_ALG_WEP;
break;
default:
wpa_printf(MSG_DEBUG, "Unsupported group cipher suite"); wpa_printf(MSG_DEBUG, "Unsupported group cipher suite");
return -1; return -1;
} }

View file

@ -171,18 +171,16 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
pos = (u8 *) (rsnie + 1); pos = (u8 *) (rsnie + 1);
/* Group Suite Selector */ /* Group Suite Selector */
if (sm->group_cipher == WPA_CIPHER_CCMP) if (sm->group_cipher != WPA_CIPHER_CCMP &&
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP); sm->group_cipher != WPA_CIPHER_GCMP &&
else if (sm->group_cipher == WPA_CIPHER_GCMP) sm->group_cipher != WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP);
else if (sm->group_cipher == WPA_CIPHER_TKIP)
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
else {
wpa_printf(MSG_WARNING, "FT: Invalid group cipher (%d)", wpa_printf(MSG_WARNING, "FT: Invalid group cipher (%d)",
sm->group_cipher); sm->group_cipher);
os_free(buf); os_free(buf);
return NULL; return NULL;
} }
RSN_SELECTOR_PUT(pos, wpa_cipher_to_suite(WPA_PROTO_RSN,
sm->group_cipher));
pos += RSN_SELECTOR_LEN; pos += RSN_SELECTOR_LEN;
/* Pairwise Suite Count */ /* Pairwise Suite Count */
@ -190,18 +188,14 @@ static u8 * wpa_ft_gen_req_ies(struct wpa_sm *sm, size_t *len,
pos += 2; pos += 2;
/* Pairwise Suite List */ /* Pairwise Suite List */
if (sm->pairwise_cipher == WPA_CIPHER_CCMP) if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP);
else if (sm->pairwise_cipher == WPA_CIPHER_GCMP)
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP);
else if (sm->pairwise_cipher == WPA_CIPHER_TKIP)
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
else {
wpa_printf(MSG_WARNING, "FT: Invalid pairwise cipher (%d)", wpa_printf(MSG_WARNING, "FT: Invalid pairwise cipher (%d)",
sm->pairwise_cipher); sm->pairwise_cipher);
os_free(buf); os_free(buf);
return NULL; return NULL;
} }
RSN_SELECTOR_PUT(pos, wpa_cipher_to_suite(WPA_PROTO_RSN,
sm->pairwise_cipher));
pos += RSN_SELECTOR_LEN; pos += RSN_SELECTOR_LEN;
/* Authenticated Key Management Suite Count */ /* Authenticated Key Management Suite Count */
@ -327,25 +321,15 @@ static int wpa_ft_install_ptk(struct wpa_sm *sm, const u8 *bssid)
wpa_printf(MSG_DEBUG, "FT: Installing PTK to the driver."); wpa_printf(MSG_DEBUG, "FT: Installing PTK to the driver.");
switch (sm->pairwise_cipher) { if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) {
case WPA_CIPHER_CCMP:
alg = WPA_ALG_CCMP;
keylen = 16;
break;
case WPA_CIPHER_GCMP:
alg = WPA_ALG_GCMP;
keylen = 16;
break;
case WPA_CIPHER_TKIP:
alg = WPA_ALG_TKIP;
keylen = 32;
break;
default:
wpa_printf(MSG_WARNING, "FT: Unsupported pairwise cipher %d", wpa_printf(MSG_WARNING, "FT: Unsupported pairwise cipher %d",
sm->pairwise_cipher); sm->pairwise_cipher);
return -1; return -1;
} }
alg = wpa_cipher_to_alg(sm->pairwise_cipher);
keylen = wpa_cipher_key_len(sm->pairwise_cipher);
if (wpa_sm_set_key(sm, alg, bssid, 0, 1, null_rsc, if (wpa_sm_set_key(sm, alg, bssid, 0, 1, null_rsc,
sizeof(null_rsc), (u8 *) sm->ptk.tk1, keylen) < 0) { sizeof(null_rsc), (u8 *) sm->ptk.tk1, keylen) < 0) {
wpa_printf(MSG_WARNING, "FT: Failed to set PTK to the driver"); wpa_printf(MSG_WARNING, "FT: Failed to set PTK to the driver");
@ -579,33 +563,10 @@ static int wpa_ft_process_gtk_subelem(struct wpa_sm *sm, const u8 *gtk_elem,
return -1; return -1;
} }
switch (sm->group_cipher) { keylen = wpa_cipher_key_len(sm->group_cipher);
case WPA_CIPHER_CCMP: rsc_len = wpa_cipher_rsc_len(sm->group_cipher);
keylen = 16; alg = wpa_cipher_to_alg(sm->group_cipher);
rsc_len = 6; if (alg == WPA_ALG_NONE) {
alg = WPA_ALG_CCMP;
break;
case WPA_CIPHER_GCMP:
keylen = 16;
rsc_len = 6;
alg = WPA_ALG_GCMP;
break;
case WPA_CIPHER_TKIP:
keylen = 32;
rsc_len = 6;
alg = WPA_ALG_TKIP;
break;
case WPA_CIPHER_WEP104:
keylen = 13;
rsc_len = 0;
alg = WPA_ALG_WEP;
break;
case WPA_CIPHER_WEP40:
keylen = 5;
rsc_len = 0;
alg = WPA_ALG_WEP;
break;
default:
wpa_printf(MSG_WARNING, "WPA: Unsupported Group Cipher %d", wpa_printf(MSG_WARNING, "WPA: Unsupported Group Cipher %d",
sm->group_cipher); sm->group_cipher);
return -1; return -1;

View file

@ -41,6 +41,7 @@ static int wpa_gen_wpa_ie_wpa(u8 *wpa_ie, size_t wpa_ie_len,
{ {
u8 *pos; u8 *pos;
struct wpa_ie_hdr *hdr; struct wpa_ie_hdr *hdr;
u32 suite;
if (wpa_ie_len < sizeof(*hdr) + WPA_SELECTOR_LEN + if (wpa_ie_len < sizeof(*hdr) + WPA_SELECTOR_LEN +
2 + WPA_SELECTOR_LEN + 2 + WPA_SELECTOR_LEN) 2 + WPA_SELECTOR_LEN + 2 + WPA_SELECTOR_LEN)
@ -52,34 +53,26 @@ static int wpa_gen_wpa_ie_wpa(u8 *wpa_ie, size_t wpa_ie_len,
WPA_PUT_LE16(hdr->version, WPA_VERSION); WPA_PUT_LE16(hdr->version, WPA_VERSION);
pos = (u8 *) (hdr + 1); pos = (u8 *) (hdr + 1);
if (group_cipher == WPA_CIPHER_CCMP) { suite = wpa_cipher_to_suite(WPA_PROTO_WPA, group_cipher);
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP); if (suite == 0) {
} else if (group_cipher == WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP);
} else if (group_cipher == WPA_CIPHER_WEP104) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_WEP104);
} else if (group_cipher == WPA_CIPHER_WEP40) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_WEP40);
} else {
wpa_printf(MSG_WARNING, "Invalid group cipher (%d).", wpa_printf(MSG_WARNING, "Invalid group cipher (%d).",
group_cipher); group_cipher);
return -1; return -1;
} }
RSN_SELECTOR_PUT(pos, suite);
pos += WPA_SELECTOR_LEN; pos += WPA_SELECTOR_LEN;
*pos++ = 1; *pos++ = 1;
*pos++ = 0; *pos++ = 0;
if (pairwise_cipher == WPA_CIPHER_CCMP) { suite = wpa_cipher_to_suite(WPA_PROTO_WPA, pairwise_cipher);
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_CCMP); if (suite == 0 ||
} else if (pairwise_cipher == WPA_CIPHER_TKIP) { (!wpa_cipher_valid_pairwise(pairwise_cipher) &&
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_TKIP); pairwise_cipher != WPA_CIPHER_NONE)) {
} else if (pairwise_cipher == WPA_CIPHER_NONE) {
RSN_SELECTOR_PUT(pos, WPA_CIPHER_SUITE_NONE);
} else {
wpa_printf(MSG_WARNING, "Invalid pairwise cipher (%d).", wpa_printf(MSG_WARNING, "Invalid pairwise cipher (%d).",
pairwise_cipher); pairwise_cipher);
return -1; return -1;
} }
RSN_SELECTOR_PUT(pos, suite);
pos += WPA_SELECTOR_LEN; pos += WPA_SELECTOR_LEN;
*pos++ = 1; *pos++ = 1;
@ -116,6 +109,7 @@ 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; u16 capab;
u32 suite;
if (rsn_ie_len < sizeof(*hdr) + RSN_SELECTOR_LEN + if (rsn_ie_len < sizeof(*hdr) + RSN_SELECTOR_LEN +
2 + RSN_SELECTOR_LEN + 2 + RSN_SELECTOR_LEN + 2 + 2 + RSN_SELECTOR_LEN + 2 + RSN_SELECTOR_LEN + 2 +
@ -130,38 +124,26 @@ static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len,
WPA_PUT_LE16(hdr->version, RSN_VERSION); WPA_PUT_LE16(hdr->version, RSN_VERSION);
pos = (u8 *) (hdr + 1); pos = (u8 *) (hdr + 1);
if (group_cipher == WPA_CIPHER_CCMP) { suite = wpa_cipher_to_suite(WPA_PROTO_RSN, group_cipher);
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP); if (suite == 0) {
} else if (group_cipher == WPA_CIPHER_GCMP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP);
} else if (group_cipher == WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
} else if (group_cipher == WPA_CIPHER_WEP104) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_WEP104);
} else if (group_cipher == WPA_CIPHER_WEP40) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_WEP40);
} else {
wpa_printf(MSG_WARNING, "Invalid group cipher (%d).", wpa_printf(MSG_WARNING, "Invalid group cipher (%d).",
group_cipher); group_cipher);
return -1; return -1;
} }
RSN_SELECTOR_PUT(pos, suite);
pos += RSN_SELECTOR_LEN; pos += RSN_SELECTOR_LEN;
*pos++ = 1; *pos++ = 1;
*pos++ = 0; *pos++ = 0;
if (pairwise_cipher == WPA_CIPHER_CCMP) { suite = wpa_cipher_to_suite(WPA_PROTO_RSN, pairwise_cipher);
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_CCMP); if (suite == 0 ||
} else if (pairwise_cipher == WPA_CIPHER_GCMP) { (!wpa_cipher_valid_pairwise(pairwise_cipher) &&
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_GCMP); pairwise_cipher != WPA_CIPHER_NONE)) {
} else if (pairwise_cipher == WPA_CIPHER_TKIP) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_TKIP);
} else if (pairwise_cipher == WPA_CIPHER_NONE) {
RSN_SELECTOR_PUT(pos, RSN_CIPHER_SUITE_NONE);
} else {
wpa_printf(MSG_WARNING, "Invalid pairwise cipher (%d).", wpa_printf(MSG_WARNING, "Invalid pairwise cipher (%d).",
pairwise_cipher); pairwise_cipher);
return -1; return -1;
} }
RSN_SELECTOR_PUT(pos, suite);
pos += RSN_SELECTOR_LEN; pos += RSN_SELECTOR_LEN;
*pos++ = 1; *pos++ = 1;