esp_wifi:BDSA related patch updates

This commit is contained in:
Shreyas Sheth
2022-10-10 15:22:48 +05:30
parent fbbb937b06
commit bd55b8b72e
7 changed files with 218 additions and 20 deletions

View File

@@ -750,8 +750,22 @@ static int wpa_supplicant_install_ptk(struct wpa_sm *sm, enum key_flag key_flag)
int keylen;
enum wpa_alg alg;
if (sm->ptk.installed) {
wpa_printf(MSG_DEBUG, "WPA: Do not re-install same PTK to the driver");
return 0;
}
wpa_printf(MSG_DEBUG, "WPA: Installing PTK to the driver.\n");
if (sm->pairwise_cipher == WPA_CIPHER_NONE) {
wpa_printf(MSG_DEBUG, "WPA: Pairwise Cipher Suite: NONE - do not use pairwise keys");
return 0;
}
if (!wpa_cipher_valid_pairwise(sm->pairwise_cipher)) {
wpa_printf(MSG_DEBUG, "WPA: Unsupported pairwise cipher %d", sm->pairwise_cipher);
return -1;
}
alg = wpa_cipher_to_alg(sm->pairwise_cipher);
keylen = wpa_cipher_key_len(sm->pairwise_cipher);
@@ -770,6 +784,8 @@ static int wpa_supplicant_install_ptk(struct wpa_sm *sm, enum key_flag key_flag)
return -1;
}
sm->ptk.installed = 1;
if (sm->wpa_ptk_rekey) {
eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL);
eloop_register_timeout(sm->wpa_ptk_rekey, 0, wpa_sm_rekey_ptk,
@@ -856,7 +872,9 @@ static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
wpa_hexdump(MSG_DEBUG, "WPA: Group Key", gd->gtk, gd->gtk_len);
/* Detect possible key reinstallation */
if (wpa_supplicant_gtk_in_use(sm, &(sm->gd))) {
if ((sm->gtk.gtk_len == (size_t) gd->gtk_len &&
os_memcmp(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len) == 0) ||
wpa_supplicant_gtk_in_use(sm, &(sm->gd))) {
wpa_printf(MSG_DEBUG,
"WPA: Not reinstalling already in-use GTK to the driver (keyidx=%d tx=%d len=%d)",
gd->keyidx, gd->tx, gd->gtk_len);
@@ -892,6 +910,8 @@ static int wpa_supplicant_install_gtk(struct wpa_sm *sm,
gd->alg, gd->gtk_len, gd->keyidx);
return -1;
}
sm->gtk.gtk_len = gd->gtk_len;
os_memcpy(sm->gtk.gtk, gd->gtk, sm->gtk.gtk_len);
return 0;
}
@@ -988,6 +1008,44 @@ int wpa_supplicant_pairwise_gtk(struct wpa_sm *sm,
return 0;
}
#ifdef CONFIG_IEEE80211W
static int wpa_supplicant_install_igtk(struct wpa_sm *sm,
const wifi_wpa_igtk_t *igtk)
{
size_t len = wpa_cipher_key_len(sm->mgmt_group_cipher);
u16 keyidx = WPA_GET_LE16(igtk->keyid);
/* Detect possible key reinstallation */
if (sm->igtk.igtk_len == len &&
os_memcmp(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len) == 0) {
wpa_printf(MSG_DEBUG,
"WPA: Not reinstalling already in-use IGTK to the driver (keyidx=%d)",
keyidx);
return 0;
}
wpa_printf(MSG_DEBUG,
"WPA: IGTK keyid %d pn %02x%02x%02x%02x%02x%02x",
keyidx, MAC2STR(igtk->pn));
wpa_hexdump_key(MSG_DEBUG, "WPA: IGTK", igtk->igtk, len);
if (keyidx > 4095) {
wpa_printf(MSG_WARNING,
"WPA: Invalid IGTK KeyID %d", keyidx);
return -1;
}
if (esp_wifi_set_igtk_internal(WIFI_IF_STA, igtk) < 0) {
wpa_printf(MSG_WARNING,
"WPA: Failed to configure IGTK to the driver");
return -1;
}
sm->igtk.igtk_len = len;
os_memcpy(sm->igtk.igtk, igtk->igtk, sm->igtk.igtk_len);
return 0;
}
#endif /* CONFIG_IEEE80211W */
#ifdef DEBUG_PRINT
void wpa_report_ie_mismatch(struct wpa_sm *sm,
const char *reason, const u8 *src_addr,
@@ -1047,7 +1105,6 @@ static int ieee80211w_set_keys(struct wpa_sm *sm,
if (ie->igtk) {
const wifi_wpa_igtk_t *igtk;
uint16_t keyidx;
#define WPA_IGTK_KDE_PREFIX_LEN (2 + 6)
len = wpa_cipher_key_len(sm->mgmt_group_cipher);
if (ie->igtk_len != WPA_IGTK_KDE_PREFIX_LEN + len) {
@@ -1055,12 +1112,9 @@ static int ieee80211w_set_keys(struct wpa_sm *sm,
}
igtk = (const wifi_wpa_igtk_t*)ie->igtk;
keyidx = WPA_GET_LE16(igtk->keyid);
if (keyidx > 4095) {
if (wpa_supplicant_install_igtk(sm, igtk) < 0) {
return -1;
}
wpa_printf(MSG_DEBUG, "WPA: Installing IGTK to the driver.\n");
return esp_wifi_set_igtk_internal(WIFI_IF_STA, igtk);
}
#endif
return 0;
@@ -2237,11 +2291,90 @@ void wpa_sm_deinit(void)
os_free(sm->ap_rsnxe);
sm->ap_rsnxe = NULL;
os_free(sm->assoc_rsnxe);
wpa_sm_drop_sa(sm);
sm->assoc_rsnxe = NULL;
}
#ifdef ESP_SUPPLICANT
/**
* wpa_sm_notify_assoc - Notify WPA state machine about association
* @sm: Pointer to WPA state machine data from wpa_sm_init()
* @bssid: The BSSID of the new association
*
* This function is called to let WPA state machine know that the connection
* was established.
*/
void wpa_sm_notify_assoc(struct wpa_sm *sm, const u8 *bssid)
{
int clear_keys = 1;
if (sm == NULL)
return;
wpa_printf(MSG_DEBUG,
"WPA: Association event - clear replay counter");
os_memcpy(sm->bssid, bssid, ETH_ALEN);
os_memset(sm->rx_replay_counter, 0, WPA_REPLAY_COUNTER_LEN);
sm->rx_replay_counter_set = 0;
sm->renew_snonce = 1;
#ifdef CONFIG_IEEE80211R
if (wpa_ft_is_completed(sm)) {
/*
* Clear portValid to kick EAPOL state machine to re-enter
* AUTHENTICATED state to get the EAPOL port Authorized.
*/
wpa_supplicant_key_neg_complete(sm, sm->bssid, 1);
/* Prepare for the next transition */
wpa_ft_prepare_auth_request(sm, NULL);
clear_keys = 0;
sm->ft_protocol = 1;
} else {
sm->ft_protocol = 0;
}
#endif /* CONFIG_IEEE80211R */
if (clear_keys) {
/*
* IEEE 802.11, 8.4.10: Delete PTK SA on (re)association if
* this is not part of a Fast BSS Transition.
*/
wpa_printf(MSG_DEBUG, "WPA: Clear old PTK");
sm->ptk_set = 0;
os_memset(&sm->ptk, 0, sizeof(sm->ptk));
sm->tptk_set = 0;
os_memset(&sm->tptk, 0, sizeof(sm->tptk));
os_memset(&sm->gtk, 0, sizeof(sm->gtk));
os_memset(&sm->igtk, 0, sizeof(sm->igtk));
}
}
/**
* wpa_sm_notify_disassoc - Notify WPA state machine about disassociation
* @sm: Pointer to WPA state machine data from wpa_sm_init()
*
* This function is called to let WPA state machine know that the connection
* was lost. This will abort any existing pre-authentication session.
*/
void wpa_sm_notify_disassoc(struct wpa_sm *sm)
{
eloop_cancel_timeout(wpa_sm_rekey_ptk, sm, NULL);
pmksa_cache_clear_current(sm);
#ifdef CONFIG_IEEE80211R
sm->ft_reassoc_completed = 0;
sm->ft_protocol = 0;
#endif /* CONFIG_IEEE80211R */
/* Keys are not needed in the WPA state machine anymore */
wpa_sm_drop_sa(sm);
os_memset(sm->bssid, 0, ETH_ALEN);
}
void wpa_set_profile(u32 wpa_proto, u8 auth_mode)
{
struct wpa_sm *sm = &gWpaSm;
@@ -2702,6 +2835,18 @@ int wpa_sm_set_assoc_rsnxe(struct wpa_sm *sm, const u8 *ie, size_t len)
return 0;
}
void wpa_sm_drop_sa(struct wpa_sm *sm)
{
wpa_printf(MSG_DEBUG, "WPA: Clear old PMK and PTK");
sm->ptk_set = 0;
sm->tptk_set = 0;
sm->pmk_len = 0;
os_memset(&sm->ptk, 0, sizeof(sm->ptk));
os_memset(&sm->tptk, 0, sizeof(sm->tptk));
os_memset(&sm->gtk, 0, sizeof(sm->gtk));
os_memset(&sm->igtk, 0, sizeof(sm->igtk));
}
#ifdef CONFIG_OWE_STA
struct wpabuf *owe_build_assoc_req(struct wpa_sm *sm, u16 group)
{