Convert RSN pre-authentication to use struct dl_list
This commit is contained in:
parent
1ce77dcc66
commit
c5b26e33c1
3 changed files with 33 additions and 43 deletions
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* WPA Supplicant - RSN pre-authentication
|
* RSN pre-authentication (supplicant)
|
||||||
* Copyright (c) 2003-2009, Jouni Malinen <j@w1.fi>
|
* Copyright (c) 2003-2010, Jouni Malinen <j@w1.fi>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
|
|
||||||
|
|
||||||
struct rsn_pmksa_candidate {
|
struct rsn_pmksa_candidate {
|
||||||
struct rsn_pmksa_candidate *next;
|
struct dl_list list;
|
||||||
u8 bssid[ETH_ALEN];
|
u8 bssid[ETH_ALEN];
|
||||||
int priority;
|
int priority;
|
||||||
};
|
};
|
||||||
|
@ -43,18 +43,14 @@ struct rsn_pmksa_candidate {
|
||||||
*/
|
*/
|
||||||
void pmksa_candidate_free(struct wpa_sm *sm)
|
void pmksa_candidate_free(struct wpa_sm *sm)
|
||||||
{
|
{
|
||||||
struct rsn_pmksa_candidate *entry, *prev;
|
struct rsn_pmksa_candidate *entry, *n;
|
||||||
|
|
||||||
if (sm == NULL)
|
if (sm == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
entry = sm->pmksa_candidates;
|
dl_list_for_each_safe(entry, n, &sm->pmksa_candidates,
|
||||||
sm->pmksa_candidates = NULL;
|
struct rsn_pmksa_candidate, list)
|
||||||
while (entry) {
|
os_free(entry);
|
||||||
prev = entry;
|
|
||||||
entry = entry->next;
|
|
||||||
os_free(prev);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -292,9 +288,9 @@ void rsn_preauth_deinit(struct wpa_sm *sm)
|
||||||
*/
|
*/
|
||||||
void rsn_preauth_candidate_process(struct wpa_sm *sm)
|
void rsn_preauth_candidate_process(struct wpa_sm *sm)
|
||||||
{
|
{
|
||||||
struct rsn_pmksa_candidate *candidate;
|
struct rsn_pmksa_candidate *candidate, *n;
|
||||||
|
|
||||||
if (sm->pmksa_candidates == NULL)
|
if (dl_list_empty(&sm->pmksa_candidates))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* TODO: drop priority for old candidate entries */
|
/* TODO: drop priority for old candidate entries */
|
||||||
|
@ -311,9 +307,9 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
|
||||||
return; /* invalid state for new pre-auth */
|
return; /* invalid state for new pre-auth */
|
||||||
}
|
}
|
||||||
|
|
||||||
while (sm->pmksa_candidates) {
|
dl_list_for_each_safe(candidate, n, &sm->pmksa_candidates,
|
||||||
|
struct rsn_pmksa_candidate, list) {
|
||||||
struct rsn_pmksa_cache_entry *p = NULL;
|
struct rsn_pmksa_cache_entry *p = NULL;
|
||||||
candidate = sm->pmksa_candidates;
|
|
||||||
p = pmksa_cache_get(sm->pmksa, candidate->bssid, NULL);
|
p = pmksa_cache_get(sm->pmksa, candidate->bssid, NULL);
|
||||||
if (os_memcmp(sm->bssid, candidate->bssid, ETH_ALEN) != 0 &&
|
if (os_memcmp(sm->bssid, candidate->bssid, ETH_ALEN) != 0 &&
|
||||||
(p == NULL || p->opportunistic)) {
|
(p == NULL || p->opportunistic)) {
|
||||||
|
@ -321,7 +317,7 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
|
||||||
"candidate " MACSTR
|
"candidate " MACSTR
|
||||||
" selected for pre-authentication",
|
" selected for pre-authentication",
|
||||||
MAC2STR(candidate->bssid));
|
MAC2STR(candidate->bssid));
|
||||||
sm->pmksa_candidates = candidate->next;
|
dl_list_del(&candidate->list);
|
||||||
rsn_preauth_init(sm, candidate->bssid,
|
rsn_preauth_init(sm, candidate->bssid,
|
||||||
sm->eap_conf_ctx);
|
sm->eap_conf_ctx);
|
||||||
os_free(candidate);
|
os_free(candidate);
|
||||||
|
@ -336,7 +332,7 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
|
||||||
wpa_sm_add_pmkid(sm, candidate->bssid, p->pmkid);
|
wpa_sm_add_pmkid(sm, candidate->bssid, p->pmkid);
|
||||||
}
|
}
|
||||||
|
|
||||||
sm->pmksa_candidates = candidate->next;
|
dl_list_del(&candidate->list);
|
||||||
os_free(candidate);
|
os_free(candidate);
|
||||||
}
|
}
|
||||||
wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: no more pending PMKSA "
|
wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: no more pending PMKSA "
|
||||||
|
@ -358,7 +354,7 @@ void rsn_preauth_candidate_process(struct wpa_sm *sm)
|
||||||
void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
|
void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
|
||||||
int prio, int preauth)
|
int prio, int preauth)
|
||||||
{
|
{
|
||||||
struct rsn_pmksa_candidate *cand, *prev, *pos;
|
struct rsn_pmksa_candidate *cand, *pos;
|
||||||
|
|
||||||
if (sm->network_ctx && sm->proactive_key_caching)
|
if (sm->network_ctx && sm->proactive_key_caching)
|
||||||
pmksa_cache_get_opportunistic(sm->pmksa, sm->network_ctx,
|
pmksa_cache_get_opportunistic(sm->pmksa, sm->network_ctx,
|
||||||
|
@ -372,18 +368,13 @@ void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
|
||||||
|
|
||||||
/* If BSSID already on candidate list, update the priority of the old
|
/* If BSSID already on candidate list, update the priority of the old
|
||||||
* entry. Do not override priority based on normal scan results. */
|
* entry. Do not override priority based on normal scan results. */
|
||||||
prev = NULL;
|
cand = NULL;
|
||||||
cand = sm->pmksa_candidates;
|
dl_list_for_each(pos, &sm->pmksa_candidates,
|
||||||
while (cand) {
|
struct rsn_pmksa_candidate, list) {
|
||||||
if (os_memcmp(cand->bssid, bssid, ETH_ALEN) == 0) {
|
if (os_memcmp(pos->bssid, bssid, ETH_ALEN) == 0) {
|
||||||
if (prev)
|
cand = pos;
|
||||||
prev->next = cand->next;
|
|
||||||
else
|
|
||||||
sm->pmksa_candidates = cand->next;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prev = cand;
|
|
||||||
cand = cand->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cand) {
|
if (cand) {
|
||||||
|
@ -399,19 +390,16 @@ void pmksa_candidate_add(struct wpa_sm *sm, const u8 *bssid,
|
||||||
|
|
||||||
/* Add candidate to the list; order by increasing priority value. i.e.,
|
/* Add candidate to the list; order by increasing priority value. i.e.,
|
||||||
* highest priority (smallest value) first. */
|
* highest priority (smallest value) first. */
|
||||||
prev = NULL;
|
dl_list_for_each(pos, &sm->pmksa_candidates,
|
||||||
pos = sm->pmksa_candidates;
|
struct rsn_pmksa_candidate, list) {
|
||||||
while (pos) {
|
if (cand->priority <= pos->priority) {
|
||||||
if (cand->priority <= pos->priority)
|
dl_list_add(pos->list.prev, &cand->list);
|
||||||
|
cand = NULL;
|
||||||
break;
|
break;
|
||||||
prev = pos;
|
}
|
||||||
pos = pos->next;
|
|
||||||
}
|
}
|
||||||
cand->next = pos;
|
if (cand)
|
||||||
if (prev)
|
dl_list_add_tail(&sm->pmksa_candidates, &cand->list);
|
||||||
prev->next = cand;
|
|
||||||
else
|
|
||||||
sm->pmksa_candidates = cand;
|
|
||||||
|
|
||||||
wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: added PMKSA cache "
|
wpa_msg(sm->ctx->msg_ctx, MSG_DEBUG, "RSN: added PMKSA cache "
|
||||||
"candidate " MACSTR " prio %d", MAC2STR(bssid), prio);
|
"candidate " MACSTR " prio %d", MAC2STR(bssid), prio);
|
||||||
|
|
|
@ -1809,6 +1809,7 @@ struct wpa_sm * wpa_sm_init(struct wpa_sm_ctx *ctx)
|
||||||
sm = os_zalloc(sizeof(*sm));
|
sm = os_zalloc(sizeof(*sm));
|
||||||
if (sm == NULL)
|
if (sm == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
dl_list_init(&sm->pmksa_candidates);
|
||||||
sm->renew_snonce = 1;
|
sm->renew_snonce = 1;
|
||||||
sm->ctx = ctx;
|
sm->ctx = ctx;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* wpa_supplicant - Internal WPA state machine definitions
|
* Internal WPA/RSN supplicant state machine definitions
|
||||||
* Copyright (c) 2004-2007, Jouni Malinen <j@w1.fi>
|
* Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License version 2 as
|
* it under the terms of the GNU General Public License version 2 as
|
||||||
|
@ -15,7 +15,8 @@
|
||||||
#ifndef WPA_I_H
|
#ifndef WPA_I_H
|
||||||
#define WPA_I_H
|
#define WPA_I_H
|
||||||
|
|
||||||
struct rsn_pmksa_candidate;
|
#include "utils/list.h"
|
||||||
|
|
||||||
struct wpa_peerkey;
|
struct wpa_peerkey;
|
||||||
struct wpa_eapol_key;
|
struct wpa_eapol_key;
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ struct wpa_sm {
|
||||||
|
|
||||||
struct rsn_pmksa_cache *pmksa; /* PMKSA cache */
|
struct rsn_pmksa_cache *pmksa; /* PMKSA cache */
|
||||||
struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */
|
struct rsn_pmksa_cache_entry *cur_pmksa; /* current PMKSA entry */
|
||||||
struct rsn_pmksa_candidate *pmksa_candidates;
|
struct dl_list pmksa_candidates;
|
||||||
|
|
||||||
struct l2_packet_data *l2_preauth;
|
struct l2_packet_data *l2_preauth;
|
||||||
struct l2_packet_data *l2_preauth_br;
|
struct l2_packet_data *l2_preauth_br;
|
||||||
|
|
Loading…
Reference in a new issue