aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2005-06-26 02:32:43 (GMT)
committerJouni Malinen <j@w1.fi>2005-06-26 02:32:43 (GMT)
commitbcdc77278e62f826df5668b1925868507f9ef140 (patch)
tree3b51f7c872eca8b39a62a1c043a848ee395c27b8
parente7cc641aea2cf073d945651105b972ba5a3e34c9 (diff)
downloadhostap-history-bcdc77278e62f826df5668b1925868507f9ef140.zip
hostap-history-bcdc77278e62f826df5668b1925868507f9ef140.tar.gz
hostap-history-bcdc77278e62f826df5668b1925868507f9ef140.tar.bz2
Moved assoc_wpa_ie from struct wpa_supplicant into struct wpa_sm and
the related processing from wpa_supplicant.c to wpa.c.
-rw-r--r--wpa_supplicant/events.c22
-rw-r--r--wpa_supplicant/wpa.c105
-rw-r--r--wpa_supplicant/wpa.h6
-rw-r--r--wpa_supplicant/wpa_i.h3
-rw-r--r--wpa_supplicant/wpa_supplicant.c33
-rw-r--r--wpa_supplicant/wpa_supplicant_i.h2
6 files changed, 117 insertions, 54 deletions
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index b191384..26065d7 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -100,8 +100,7 @@ static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s)
struct wpa_ie_data ie;
int i, pmksa_set = -1;
- if (wpa_parse_wpa_ie(wpa_s->assoc_wpa_ie, wpa_s->assoc_wpa_ie_len,
- &ie) < 0 ||
+ if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 ||
ie.pmkid == NULL)
return;
@@ -386,7 +385,7 @@ static void wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s)
static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
union wpa_event_data *data)
{
- int l, len;
+ int l, len, found = 0;
u8 *p;
wpa_printf(MSG_DEBUG, "Association info event");
@@ -394,11 +393,6 @@ static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
data->assoc_info.req_ies_len);
wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies,
data->assoc_info.resp_ies_len);
- if (wpa_s->assoc_wpa_ie) {
- free(wpa_s->assoc_wpa_ie);
- wpa_s->assoc_wpa_ie = NULL;
- wpa_s->assoc_wpa_ie_len = 0;
- }
p = data->assoc_info.req_ies;
l = data->assoc_info.req_ies_len;
@@ -414,20 +408,17 @@ static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
if ((p[0] == GENERIC_INFO_ELEM && p[1] >= 6 &&
(memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) ||
(p[0] == RSN_INFO_ELEM && p[1] >= 2)) {
- wpa_s->assoc_wpa_ie = malloc(len);
- if (wpa_s->assoc_wpa_ie == NULL)
+ if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len))
break;
- wpa_s->assoc_wpa_ie_len = len;
- memcpy(wpa_s->assoc_wpa_ie, p, len);
- wpa_hexdump(MSG_DEBUG, "assoc_wpa_ie",
- wpa_s->assoc_wpa_ie,
- wpa_s->assoc_wpa_ie_len);
+ found = 1;
wpa_find_assoc_pmkid(wpa_s);
break;
}
l -= len;
p += len;
}
+ if (!found && data->assoc_info.req_ies)
+ wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
/* WPA/RSN IE from Beacon/ProbeResp */
free(wpa_s->ap_wpa_ie);
@@ -472,7 +463,6 @@ static void wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s,
l -= len;
p += len;
}
-
}
diff --git a/wpa_supplicant/wpa.c b/wpa_supplicant/wpa.c
index b8bd635..a7c175b 100644
--- a/wpa_supplicant/wpa.c
+++ b/wpa_supplicant/wpa.c
@@ -641,7 +641,7 @@ static int wpa_gen_wpa_ie_rsn(u8 *rsn_ie, size_t rsn_ie_len,
* @wpa_ie_len: Maximum length of the generated WPA/RSN IE
* Returns: Length of the generated WPA/RSN IE or -1 on failure
*/
-int wpa_gen_wpa_ie(struct wpa_sm *sm, u8 *wpa_ie, size_t wpa_ie_len)
+static int wpa_gen_wpa_ie(struct wpa_sm *sm, u8 *wpa_ie, size_t wpa_ie_len)
{
if (sm->proto == WPA_PROTO_RSN)
return wpa_gen_wpa_ie_rsn(wpa_ie, wpa_ie_len,
@@ -997,21 +997,20 @@ static int wpa_supplicant_send_2_of_4(struct wpa_sm *sm,
const struct wpa_eapol_key *key,
int ver)
{
- struct wpa_supplicant *wpa_s = sm->ctx;
size_t rlen;
struct wpa_eapol_key *reply;
struct wpa_ptk *ptk;
u8 buf[8], *rbuf, *wpa_ie;
int wpa_ie_len;
- if (wpa_s->assoc_wpa_ie == NULL) {
+ if (sm->assoc_wpa_ie == NULL) {
wpa_printf(MSG_WARNING, "WPA: No assoc_wpa_ie set - cannot "
"generate msg 2/4");
return -1;
}
- wpa_ie = wpa_s->assoc_wpa_ie;
- wpa_ie_len = wpa_s->assoc_wpa_ie_len;
+ wpa_ie = sm->assoc_wpa_ie;
+ wpa_ie_len = sm->assoc_wpa_ie_len;
wpa_hexdump(MSG_DEBUG, "WPA: WPA IE for msg 2/4", wpa_ie, wpa_ie_len);
rbuf = wpa_alloc_eapol(sm->ctx, src_addr, ETH_P_EAPOL,
@@ -2191,6 +2190,7 @@ struct wpa_sm * wpa_sm_init(void *ctx)
void wpa_sm_deinit(struct wpa_sm *sm)
{
eloop_cancel_timeout(wpa_sm_start_preauth, sm, 0);
+ free(sm->assoc_wpa_ie);
free(sm);
}
@@ -2462,3 +2462,98 @@ int wpa_sm_get_status(struct wpa_sm *sm, char *buf, size_t buflen,
wpa_key_mgmt_txt(sm->key_mgmt, sm->proto));
return pos - buf;
}
+
+
+/**
+ * wpa_sm_set_assoc_wpa_ie_default - Generate own WPA/RSN IE from configuration
+ * @sm: Pointer to WPA state machine data from wpa_sm_init()
+ * @wpa_ie: Pointer to buffer for WPA/RSN IE
+ * @wpa_ie_len: Pointer to the length of the wpa_ie buffer
+ * Returns: 0 on success, -1 on failure
+ *
+ * Inform WPA state machine about the WPA/RSN IE used in (Re)Association
+ * Request frame. The IE will be used to override the default value generated
+ * with wpa_sm_set_assoc_wpa_ie_default().
+ */
+int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie,
+ size_t *wpa_ie_len)
+{
+ if (sm == NULL)
+ return -1;
+
+ *wpa_ie_len = wpa_gen_wpa_ie(sm, wpa_ie, *wpa_ie_len);
+ if (*wpa_ie_len < 0)
+ return -1;
+
+ wpa_hexdump(MSG_DEBUG, "WPA: Set own WPA IE default",
+ wpa_ie, *wpa_ie_len);
+
+ if (sm->assoc_wpa_ie == NULL) {
+ /*
+ * Make a copy of the WPA/RSN IE so that 4-Way Handshake gets
+ * the correct version of the IE even if PMKSA caching is
+ * aborted (which would remove PMKID from IE generation).
+ */
+ sm->assoc_wpa_ie = malloc(*wpa_ie_len);
+ if (sm->assoc_wpa_ie == NULL)
+ return -1;
+
+ memcpy(sm->assoc_wpa_ie, wpa_ie, *wpa_ie_len);
+ sm->assoc_wpa_ie_len = *wpa_ie_len;
+ }
+
+ return 0;
+}
+
+
+/**
+ * wpa_sm_set_assoc_wpa_ie - Set own WPA/RSN IE from (Re)AssocReq
+ * @sm: Pointer to WPA state machine data from wpa_sm_init()
+ * @ie: Pointer to IE data (starting from id)
+ * @len: IE length
+ * Returns: 0 on success, -1 on failure
+ *
+ * Inform WPA state machine about the WPA/RSN IE used in (Re)Association
+ * Request frame. The IE will be used to override the default value generated
+ * with wpa_sm_set_assoc_wpa_ie_default().
+ */
+int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len)
+{
+ if (sm == NULL)
+ return -1;
+
+ free(sm->assoc_wpa_ie);
+ if (ie == NULL) {
+ wpa_printf(MSG_DEBUG, "WPA: clearing own WPA/RSN IE");
+ sm->assoc_wpa_ie = NULL;
+ sm->assoc_wpa_ie_len = 0;
+ } else {
+ wpa_hexdump(MSG_DEBUG, "WPA: set own WPA/RSN IE", ie, len);
+ sm->assoc_wpa_ie = malloc(len);
+ if (sm->assoc_wpa_ie == NULL)
+ return -1;
+
+ memcpy(sm->assoc_wpa_ie, ie, len);
+ sm->assoc_wpa_ie_len = len;
+ }
+
+ return 0;
+}
+
+
+/**
+ * wpa_sm_parse_own_wpa_ie - Parse own WPA/RSN IE
+ * @sm: Pointer to WPA state machine data from wpa_sm_init()
+ * @data: Pointer to data area for parsing results
+ * Returns: 0 on success, -1 on failure
+ *
+ * Parse the contents of the own WPA or RSN IE from (Re)AssocReq and write the
+ * parsed data into data.
+ */
+int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data)
+{
+ if (sm == NULL || sm->assoc_wpa_ie == NULL ||
+ wpa_parse_wpa_ie(sm->assoc_wpa_ie, sm->assoc_wpa_ie_len, data))
+ return -1;
+ return 0;
+}
diff --git a/wpa_supplicant/wpa.h b/wpa_supplicant/wpa.h
index 8bf0b98..70f45c1 100644
--- a/wpa_supplicant/wpa.h
+++ b/wpa_supplicant/wpa.h
@@ -144,6 +144,9 @@ void wpa_sm_set_config(struct wpa_sm *sm, struct wpa_ssid *config);
void wpa_sm_set_own_addr(struct wpa_sm *sm, const u8 *addr);
void wpa_sm_set_ifname(struct wpa_sm *sm, const char *ifname);
void wpa_sm_set_eapol(struct wpa_sm *sm, struct eapol_sm *eapol);
+int wpa_sm_set_assoc_wpa_ie(struct wpa_sm *sm, const u8 *ie, size_t len);
+int wpa_sm_set_assoc_wpa_ie_default(struct wpa_sm *sm, u8 *wpa_ie,
+ size_t *wpa_ie_len);
int wpa_sm_get_mib(struct wpa_sm *sm, char *buf, size_t buflen);
enum wpa_sm_conf_params {
@@ -180,9 +183,8 @@ struct wpa_ie_data {
int wpa_parse_wpa_ie(const u8 *wpa_ie, size_t wpa_ie_len,
struct wpa_ie_data *data);
-int wpa_gen_wpa_ie(struct wpa_sm *sm, u8 *wpa_ie, size_t wpa_ie_len);
-
int wpa_sm_rx_eapol(struct wpa_sm *sm, const unsigned char *src_addr,
unsigned char *buf, size_t len);
+int wpa_sm_parse_own_wpa_ie(struct wpa_sm *sm, struct wpa_ie_data *data);
#endif /* WPA_H */
diff --git a/wpa_supplicant/wpa_i.h b/wpa_supplicant/wpa_i.h
index 017d7e9..cf208f1 100644
--- a/wpa_supplicant/wpa_i.h
+++ b/wpa_supplicant/wpa_i.h
@@ -95,6 +95,9 @@ struct wpa_sm {
unsigned int pairwise_cipher;
unsigned int group_cipher;
unsigned int key_mgmt;
+
+ u8 *assoc_wpa_ie; /* Own WPA/RSN IE from (Re)AssocReq */
+ size_t assoc_wpa_ie_len;
};
#endif /* WPA_I_H */
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 870ae18..325f698 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -546,9 +546,7 @@ void wpa_supplicant_set_non_wpa_policy(struct wpa_supplicant *wpa_s,
free(wpa_s->ap_rsn_ie);
wpa_s->ap_rsn_ie = NULL;
wpa_s->ap_rsn_ie_len = 0;
- free(wpa_s->assoc_wpa_ie);
- wpa_s->assoc_wpa_ie = NULL;
- wpa_s->assoc_wpa_ie_len = 0;
+ wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
wpa_s->pairwise_cipher = WPA_CIPHER_NONE;
wpa_s->group_cipher = WPA_CIPHER_NONE;
@@ -588,9 +586,6 @@ static void wpa_supplicant_cleanup(struct wpa_supplicant *wpa_s)
wpa_s->conf = NULL;
}
- free(wpa_s->assoc_wpa_ie);
- wpa_s->assoc_wpa_ie = NULL;
-
free(wpa_s->ap_wpa_ie);
wpa_s->ap_wpa_ie = NULL;
free(wpa_s->ap_rsn_ie);
@@ -887,11 +882,7 @@ static wpa_key_mgmt key_mgmt2driver(int key_mgmt)
static int wpa_supplicant_suites_from_ai(struct wpa_supplicant *wpa_s,
struct wpa_ssid *ssid,
struct wpa_ie_data *ie) {
- if (wpa_s->assoc_wpa_ie == NULL)
- return -1;
-
- if (wpa_parse_wpa_ie(wpa_s->assoc_wpa_ie, wpa_s->assoc_wpa_ie_len,
- ie)) {
+ if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, ie)) {
wpa_msg(wpa_s, MSG_INFO, "WPA: Failed to parse WPA IE from "
"association info");
return -1;
@@ -1051,24 +1042,10 @@ int wpa_supplicant_set_suites(struct wpa_supplicant *wpa_s,
wpa_s->pairwise_cipher);
wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher);
- *wpa_ie_len = wpa_gen_wpa_ie(wpa_s->wpa, wpa_ie, *wpa_ie_len);
- if (*wpa_ie_len < 0) {
+ if (wpa_sm_set_assoc_wpa_ie_default(wpa_s->wpa, wpa_ie, wpa_ie_len)) {
wpa_printf(MSG_WARNING, "WPA: Failed to generate WPA IE.");
return -1;
}
- wpa_hexdump(MSG_DEBUG, "WPA: Own WPA IE", wpa_ie, *wpa_ie_len);
- if (wpa_s->assoc_wpa_ie == NULL) {
- /*
- * Make a copy of the WPA/RSN IE so that 4-Way Handshake gets
- * the correct version of the IE even if PMKSA caching is
- * aborted (which would remove PMKID from IE generation).
- */
- wpa_s->assoc_wpa_ie = malloc(*wpa_ie_len);
- if (wpa_s->assoc_wpa_ie) {
- memcpy(wpa_s->assoc_wpa_ie, wpa_ie, *wpa_ie_len);
- wpa_s->assoc_wpa_ie_len = *wpa_ie_len;
- }
- }
if (ssid->key_mgmt & WPA_KEY_MGMT_PSK)
wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN);
@@ -1106,9 +1083,7 @@ void wpa_supplicant_associate(struct wpa_supplicant *wpa_s,
/* Starting new association, so clear the possibly used WPA IE from the
* previous association. */
- free(wpa_s->assoc_wpa_ie);
- wpa_s->assoc_wpa_ie = NULL;
- wpa_s->assoc_wpa_ie_len = 0;
+ wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0);
if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
if (ssid->leap) {
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 2b02a25..9490781 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -60,8 +60,6 @@ struct wpa_supplicant {
struct wpa_ssid *current_ssid;
u8 *ap_wpa_ie, *ap_rsn_ie;
size_t ap_wpa_ie_len, ap_rsn_ie_len;
- u8 *assoc_wpa_ie;
- size_t assoc_wpa_ie_len;
/* Selected configuration (based on Beacon/ProbeResp WPA IE) */
int pairwise_cipher;