mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-25 09:39:25 +01:00
eapol: Remove user_data from __eapol_rx_packet args
Instead of passing the user_data parameter in every __eapol_rx_packet call to be used by EAPOL in all tx_packet calls, add eapol_sm_set_tx_user_data function that sets the value of user_data for all subsequent tx_packet calls. This way tx_packet can be called from places that are not necessarily inside an __eapol_rx_packet call.
This commit is contained in:
parent
ef9b6f41ce
commit
2bccb7e7dc
29
src/eapol.c
29
src/eapol.c
@ -599,6 +599,7 @@ struct eapol_sm {
|
||||
uint8_t anonce[32];
|
||||
uint8_t ptk[64];
|
||||
void *user_data;
|
||||
void *tx_user_data;
|
||||
struct l_timeout *timeout;
|
||||
bool have_snonce:1;
|
||||
bool have_replay:1;
|
||||
@ -725,6 +726,11 @@ void eapol_sm_set_user_data(struct eapol_sm *sm, void *user_data)
|
||||
sm->user_data = user_data;
|
||||
}
|
||||
|
||||
void eapol_sm_set_tx_user_data(struct eapol_sm *sm, void *user_data)
|
||||
{
|
||||
sm->tx_user_data = user_data;
|
||||
}
|
||||
|
||||
static bool eapol_sm_ifindex_match(void *data, void *user_data)
|
||||
{
|
||||
struct eapol_sm *sm = data;
|
||||
@ -771,8 +777,7 @@ void eapol_start(uint32_t ifindex, struct eapol_sm *sm)
|
||||
}
|
||||
|
||||
static void eapol_handle_ptk_1_of_4(uint32_t ifindex, struct eapol_sm *sm,
|
||||
const struct eapol_key *ek,
|
||||
void *user_data)
|
||||
const struct eapol_key *ek)
|
||||
{
|
||||
struct crypto_ptk *ptk = (struct crypto_ptk *) sm->ptk;
|
||||
struct eapol_key *step2;
|
||||
@ -815,7 +820,7 @@ static void eapol_handle_ptk_1_of_4(uint32_t ifindex, struct eapol_sm *sm,
|
||||
|
||||
memcpy(step2->key_mic_data, mic, sizeof(mic));
|
||||
tx_packet(ifindex, sm->aa, sm->spa,
|
||||
(struct eapol_frame *) step2, user_data);
|
||||
(struct eapol_frame *) step2, sm->tx_user_data);
|
||||
l_free(step2);
|
||||
|
||||
l_timeout_remove(sm->timeout);
|
||||
@ -994,8 +999,7 @@ static void eapol_handle_ptk_3_of_4(uint32_t ifindex,
|
||||
struct eapol_sm *sm,
|
||||
const struct eapol_key *ek,
|
||||
const uint8_t *decrypted_key_data,
|
||||
size_t decrypted_key_data_size,
|
||||
void *user_data)
|
||||
size_t decrypted_key_data_size)
|
||||
{
|
||||
struct crypto_ptk *ptk = (struct crypto_ptk *) sm->ptk;
|
||||
struct eapol_key *step4;
|
||||
@ -1142,7 +1146,7 @@ static void eapol_handle_ptk_3_of_4(uint32_t ifindex,
|
||||
|
||||
memcpy(step4->key_mic_data, mic, sizeof(mic));
|
||||
tx_packet(ifindex, sm->aa, sm->spa,
|
||||
(struct eapol_frame *) step4, user_data);
|
||||
(struct eapol_frame *) step4, sm->tx_user_data);
|
||||
|
||||
sm->ptk_complete = true;
|
||||
|
||||
@ -1168,8 +1172,7 @@ static void eapol_handle_gtk_1_of_2(uint32_t ifindex,
|
||||
struct eapol_sm *sm,
|
||||
const struct eapol_key *ek,
|
||||
const uint8_t *decrypted_key_data,
|
||||
size_t decrypted_key_data_size,
|
||||
void *user_data)
|
||||
size_t decrypted_key_data_size)
|
||||
{
|
||||
struct crypto_ptk *ptk = (struct crypto_ptk *) sm->ptk;
|
||||
struct eapol_key *step2;
|
||||
@ -1222,7 +1225,7 @@ static void eapol_handle_gtk_1_of_2(uint32_t ifindex,
|
||||
|
||||
memcpy(step2->key_mic_data, mic, sizeof(mic));
|
||||
tx_packet(ifindex, sm->aa, sm->spa,
|
||||
(struct eapol_frame *) step2, user_data);
|
||||
(struct eapol_frame *) step2, sm->tx_user_data);
|
||||
|
||||
if (install_gtk) {
|
||||
uint32_t cipher =
|
||||
@ -1263,7 +1266,7 @@ static struct eapol_sm *eapol_find_sm(uint32_t ifindex,
|
||||
}
|
||||
|
||||
void __eapol_rx_packet(uint32_t ifindex, const uint8_t *spa, const uint8_t *aa,
|
||||
const uint8_t *frame, size_t len, void *user_data)
|
||||
const uint8_t *frame, size_t len)
|
||||
{
|
||||
const struct eapol_key *ek;
|
||||
struct eapol_sm *sm;
|
||||
@ -1341,13 +1344,13 @@ void __eapol_rx_packet(uint32_t ifindex, const uint8_t *spa, const uint8_t *aa,
|
||||
|
||||
eapol_handle_gtk_1_of_2(ifindex, sm, ek,
|
||||
decrypted_key_data,
|
||||
key_data_len, user_data);
|
||||
key_data_len);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* If no MIC, then assume packet 1, otherwise packet 3 */
|
||||
if (!ek->key_mic)
|
||||
eapol_handle_ptk_1_of_4(ifindex, sm, ek, user_data);
|
||||
eapol_handle_ptk_1_of_4(ifindex, sm, ek);
|
||||
else {
|
||||
if (sm->ptk_complete)
|
||||
goto done;
|
||||
@ -1357,7 +1360,7 @@ void __eapol_rx_packet(uint32_t ifindex, const uint8_t *spa, const uint8_t *aa,
|
||||
|
||||
eapol_handle_ptk_3_of_4(ifindex, sm, ek,
|
||||
decrypted_key_data ?: ek->key_data,
|
||||
key_data_len, user_data);
|
||||
key_data_len);
|
||||
}
|
||||
|
||||
done:
|
||||
|
@ -160,8 +160,7 @@ struct eapol_key *eapol_create_gtk_2_of_2(
|
||||
bool is_wpa, uint8_t wpa_key_id);
|
||||
|
||||
void __eapol_rx_packet(uint32_t ifindex, const uint8_t *spa, const uint8_t *aa,
|
||||
const uint8_t *frame, size_t len,
|
||||
void *user_data);
|
||||
const uint8_t *frame, size_t len);
|
||||
|
||||
void __eapol_set_tx_packet_func(eapol_tx_packet_func_t func);
|
||||
void __eapol_set_get_nonce_func(eapol_get_nonce_func_t func);
|
||||
@ -185,6 +184,7 @@ void eapol_sm_set_ap_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie,
|
||||
bool eapol_sm_set_own_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie,
|
||||
size_t len);
|
||||
void eapol_sm_set_user_data(struct eapol_sm *sm, void *user_data);
|
||||
void eapol_sm_set_tx_user_data(struct eapol_sm *sm, void *user_data);
|
||||
struct l_io *eapol_open_pae(uint32_t index);
|
||||
|
||||
void eapol_start(uint32_t ifindex, struct eapol_sm *sm);
|
||||
|
@ -130,7 +130,7 @@ static bool eapol_read(struct l_io *io, void *user_data)
|
||||
}
|
||||
|
||||
__eapol_rx_packet(netdev->index, netdev->addr, sll.sll_addr,
|
||||
frame, bytes, L_INT_TO_PTR(fd));
|
||||
frame, bytes);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -1461,6 +1461,8 @@ static void mlme_associate_cmd(struct netdev *netdev)
|
||||
eapol_sm_set_authenticator_address(sm, bss->addr);
|
||||
eapol_sm_set_supplicant_address(sm, netdev->addr);
|
||||
eapol_sm_set_user_data(sm, netdev);
|
||||
eapol_sm_set_tx_user_data(sm,
|
||||
L_INT_TO_PTR(l_io_get_fd(netdev->eapol_io)));
|
||||
eapol_start(netdev->index, sm);
|
||||
|
||||
msg_append_attr(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
|
||||
|
@ -1750,12 +1750,12 @@ static void eapol_sm_test_ptk(const void *data)
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step2);
|
||||
__eapol_rx_packet(1, spa, aa, eapol_key_data_3,
|
||||
sizeof(eapol_key_data_3), NULL);
|
||||
sizeof(eapol_key_data_3));
|
||||
assert(verify_step2_called);
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step4);
|
||||
__eapol_rx_packet(1, spa, aa, eapol_key_data_5,
|
||||
sizeof(eapol_key_data_5), NULL);
|
||||
sizeof(eapol_key_data_5));
|
||||
assert(verify_step4_called);
|
||||
|
||||
eapol_exit();
|
||||
@ -1810,17 +1810,17 @@ static void eapol_sm_test_wpa2_ptk_gtk(const void *data)
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step2);
|
||||
__eapol_rx_packet(1, spa, aa, eapol_key_data_7,
|
||||
sizeof(eapol_key_data_7), NULL);
|
||||
sizeof(eapol_key_data_7));
|
||||
assert(verify_step2_called);
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step4);
|
||||
__eapol_rx_packet(1, spa, aa, eapol_key_data_9,
|
||||
sizeof(eapol_key_data_9), NULL);
|
||||
sizeof(eapol_key_data_9));
|
||||
assert(verify_step4_called);
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step2_gtk);
|
||||
__eapol_rx_packet(1, spa, aa, eapol_key_data_11,
|
||||
sizeof(eapol_key_data_11), NULL);
|
||||
sizeof(eapol_key_data_11));
|
||||
assert(verify_gtk_step2_called);
|
||||
|
||||
eapol_exit();
|
||||
@ -1873,17 +1873,17 @@ static void eapol_sm_test_wpa_ptk_gtk(const void *data)
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step2);
|
||||
__eapol_rx_packet(1, sta_address, ap_address, eapol_key_data_13,
|
||||
sizeof(eapol_key_data_13), NULL);
|
||||
sizeof(eapol_key_data_13));
|
||||
assert(verify_step2_called);
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step4);
|
||||
__eapol_rx_packet(1, sta_address, ap_address, eapol_key_data_15,
|
||||
sizeof(eapol_key_data_15), NULL);
|
||||
sizeof(eapol_key_data_15));
|
||||
assert(verify_step4_called);
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step2_gtk);
|
||||
__eapol_rx_packet(1, sta_address, ap_address, eapol_key_data_17,
|
||||
sizeof(eapol_key_data_17), NULL);
|
||||
sizeof(eapol_key_data_17));
|
||||
assert(verify_gtk_step2_called);
|
||||
|
||||
eapol_exit();
|
||||
@ -1937,17 +1937,17 @@ static void eapol_sm_test_wpa_ptk_gtk_2(const void *data)
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step2);
|
||||
__eapol_rx_packet(1, sta_address, ap_address, eapol_key_data_19,
|
||||
sizeof(eapol_key_data_19), NULL);
|
||||
sizeof(eapol_key_data_19));
|
||||
assert(verify_step2_called);
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step4);
|
||||
__eapol_rx_packet(1, sta_address, ap_address, eapol_key_data_21,
|
||||
sizeof(eapol_key_data_21), NULL);
|
||||
sizeof(eapol_key_data_21));
|
||||
assert(verify_step4_called);
|
||||
|
||||
__eapol_set_tx_packet_func(verify_step2_gtk);
|
||||
__eapol_rx_packet(1, sta_address, ap_address, eapol_key_data_23,
|
||||
sizeof(eapol_key_data_23), NULL);
|
||||
sizeof(eapol_key_data_23));
|
||||
assert(verify_gtk_step2_called);
|
||||
|
||||
eapol_exit();
|
||||
|
Loading…
Reference in New Issue
Block a user