[PATCH] Provide the information whether the WPA/RSN EAPOL-Key message sent or failed

Avichal Agarwal avichal.aatsamsung.com
Thu Aug 27 21:04:12 PDT 2015


This patch provide the exact information whether WPA/RSN EAPOL-Key message sent
successfully or failed. Now wpa_eapol_key_send will return 0 on success and -1 on failure.

Signed-off-by: Avichal Agarwal <avichal.a at samsung.com>
Signed-off-by: Purushottam Kushwaha <p.kushwaha at samsung.com>
Signed-off-by: Jijo Jacob <jijo.jacob at samsung.com>
---
 src/rsn_supp/peerkey.c |   32 +++++++++++++++++---------------
 src/rsn_supp/wpa.c     |   23 ++++++++++++-----------
 src/rsn_supp/wpa_i.h   |    2 +-
 3 files changed, 30 insertions(+), 27 deletions(-)

diff --git a/src/rsn_supp/peerkey.c b/src/rsn_supp/peerkey.c
index 79764d9..8d74744 100644
--- a/src/rsn_supp/peerkey.c
+++ b/src/rsn_supp/peerkey.c
@@ -114,10 +114,10 @@ static int wpa_supplicant_send_smk_error(struct wpa_sm *sm, const u8 *dst,
 			   "(mui %d error_type %d)", mui, error_type);
 	}
 
-	wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, dst,
+	return wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, dst,
 			   ETH_P_EAPOL, rbuf, rlen, err192->key_mic);
 
-	return 0;
+
 }
 
 
@@ -168,10 +168,10 @@ static int wpa_supplicant_send_smk_m3(struct wpa_sm *sm,
 	wpa_add_kde(pos, RSN_KEY_DATA_NONCE, peerkey->inonce, WPA_NONCE_LEN);
 
 	wpa_printf(MSG_DEBUG, "RSN: Sending EAPOL-Key SMK M3");
-	wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, src_addr,
+	return wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, src_addr,
 			   ETH_P_EAPOL, rbuf, rlen, reply192->key_mic);
 
-	return 0;
+
 }
 
 
@@ -319,7 +319,7 @@ static void rsn_smkid(const u8 *smk, const u8 *pnonce, const u8 *mac_p,
 }
 
 
-static void wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
+static int wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
 					   struct wpa_peerkey *peerkey)
 {
 	size_t mlen;
@@ -334,7 +334,7 @@ static void wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
 				  sizeof(*msg) + kde_len, &mlen,
 				  (void *) &msg);
 	if (mbuf == NULL)
-		return;
+		return -1 ;
 
 	msg->type = EAPOL_KEY_TYPE_RSN;
 
@@ -363,7 +363,7 @@ static void wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
 		wpa_msg(sm->ctx->msg_ctx, MSG_WARNING,
 			"RSN: Failed to get random data for INonce (STK)");
 		os_free(mbuf);
-		return;
+		return -1;
 	}
 	wpa_hexdump(MSG_DEBUG, "RSN: INonce for STK 4-Way Handshake",
 		    peerkey->inonce, WPA_NONCE_LEN);
@@ -371,12 +371,12 @@ static void wpa_supplicant_send_stk_1_of_4(struct wpa_sm *sm,
 
 	wpa_printf(MSG_DEBUG, "RSN: Sending EAPOL-Key STK 1/4 to " MACSTR,
 		   MAC2STR(peerkey->addr));
-	wpa_eapol_key_send(sm, NULL, 0, ver, peerkey->addr, ETH_P_EAPOL,
+	return wpa_eapol_key_send(sm, NULL, 0, ver, peerkey->addr, ETH_P_EAPOL,
 			   mbuf, mlen, NULL);
 }
 
 
-static void wpa_supplicant_send_stk_3_of_4(struct wpa_sm *sm,
+static int  wpa_supplicant_send_stk_3_of_4(struct wpa_sm *sm,
 					   struct wpa_peerkey *peerkey)
 {
 	size_t mlen;
@@ -393,7 +393,7 @@ static void wpa_supplicant_send_stk_3_of_4(struct wpa_sm *sm,
 				  sizeof(*msg) + kde_len, &mlen,
 				  (void *) &msg);
 	if (mbuf == NULL)
-		return;
+		return -1 ;
 
 	msg->type = EAPOL_KEY_TYPE_RSN;
 
@@ -426,7 +426,7 @@ static void wpa_supplicant_send_stk_3_of_4(struct wpa_sm *sm,
 
 	wpa_printf(MSG_DEBUG, "RSN: Sending EAPOL-Key STK 3/4 to " MACSTR,
 		   MAC2STR(peerkey->addr));
-	wpa_eapol_key_send(sm, peerkey->stk.kck, peerkey->stk.kck_len, ver,
+	return wpa_eapol_key_send(sm, peerkey->stk.kck, peerkey->stk.kck_len, ver,
 			   peerkey->addr, ETH_P_EAPOL, mbuf, mlen,
 			   msg->key_mic);
 }
@@ -517,6 +517,7 @@ static int wpa_supplicant_process_smk_m45(
 	struct wpa_peerkey *peerkey;
 	struct wpa_eapol_ie_parse kde;
 	u32 lifetime;
+	int ret=0;
 
 	if (!sm->peerkey_enabled || sm->proto != WPA_PROTO_RSN) {
 		wpa_printf(MSG_DEBUG, "RSN: SMK handshake not allowed for "
@@ -577,7 +578,7 @@ static int wpa_supplicant_process_smk_m45(
 		rsn_smkid(peerkey->smk, peerkey->pnonce, peerkey->addr,
 			  peerkey->inonce, sm->own_addr, peerkey->smkid,
 			  peerkey->akmp);
-		wpa_supplicant_send_stk_1_of_4(sm, peerkey);
+		ret = wpa_supplicant_send_stk_1_of_4(sm, peerkey);
 	} else {
 		rsn_smkid(peerkey->smk, peerkey->pnonce, sm->own_addr,
 			  peerkey->inonce, peerkey->addr, peerkey->smkid,
@@ -585,7 +586,7 @@ static int wpa_supplicant_process_smk_m45(
 	}
 	wpa_hexdump(MSG_DEBUG, "RSN: SMKID", peerkey->smkid, PMKID_LEN);
 
-	return 0;
+	return ret;
 }
 
 
@@ -988,6 +989,7 @@ int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
 	struct rsn_ie_hdr *hdr;
 	struct wpa_peerkey *peerkey;
 	struct wpa_ie_data ie;
+	int ret =0;
 
 	if (sm->proto != WPA_PROTO_RSN || !sm->ptk_set || !sm->peerkey_enabled)
 		return -1;
@@ -1084,13 +1086,13 @@ int wpa_sm_stkstart(struct wpa_sm *sm, const u8 *peer)
 
 	wpa_printf(MSG_INFO, "RSN: Sending EAPOL-Key SMK M1 Request (peer "
 		   MACSTR ")", MAC2STR(peer));
-	wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, bssid,
+	ret = wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, bssid,
 			   ETH_P_EAPOL, rbuf, rlen, req->key_mic);
 
 	peerkey->next = sm->peerkey;
 	sm->peerkey = peerkey;
 
-	return 0;
+	return ret;
 }
 
 
diff --git a/src/rsn_supp/wpa.c b/src/rsn_supp/wpa.c
index 52c01b8..4890e48 100644
--- a/src/rsn_supp/wpa.c
+++ b/src/rsn_supp/wpa.c
@@ -34,11 +34,13 @@
  * @msg: EAPOL-Key message
  * @msg_len: Length of message
  * @key_mic: Pointer to the buffer to which the EAPOL-Key MIC is written
+ * Returns: >=0 on success, <0 on failure
  */
-void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck, size_t kck_len,
-			int ver, const u8 *dest, u16 proto,
-			u8 *msg, size_t msg_len, u8 *key_mic)
+int wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck, size_t kck_len,
+		       int ver, const u8 *dest, u16 proto,
+		       u8 *msg, size_t msg_len, u8 *key_mic)
 {
+	int ret = -1;
 	size_t mic_len = wpa_mic_len(sm->key_mgmt);
 
 	if (is_zero_ether_addr(dest) && is_zero_ether_addr(sm->bssid)) {
@@ -65,14 +67,16 @@ void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck, size_t kck_len,
 			"WPA: Failed to generate EAPOL-Key version %d key_mgmt 0x%x MIC",
 			ver, sm->key_mgmt);
 		goto out;
+
 	}
 	wpa_hexdump_key(MSG_DEBUG, "WPA: KCK", kck, kck_len);
 	wpa_hexdump(MSG_DEBUG, "WPA: Derived Key MIC", key_mic, mic_len);
 	wpa_hexdump(MSG_MSGDUMP, "WPA: TX EAPOL-Key", msg, msg_len);
-	wpa_sm_ether_send(sm, dest, proto, msg, msg_len);
+	ret = wpa_sm_ether_send(sm, dest, proto, msg, msg_len);
 	eapol_sm_notify_tx_eapol_key(sm->eapol);
 out:
 	os_free(msg);
+	return ret;
 }
 
 
@@ -409,10 +413,10 @@ int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
 	os_memcpy(reply->key_nonce, nonce, WPA_NONCE_LEN);
 
 	wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 2/4");
-	wpa_eapol_key_send(sm, ptk->kck, ptk->kck_len, ver, dst, ETH_P_EAPOL,
+	return wpa_eapol_key_send(sm, ptk->kck, ptk->kck_len, ver, dst, ETH_P_EAPOL,
 			   rbuf, rlen, key_mic);
 
-	return 0;
+
 }
 
 
@@ -1126,10 +1130,9 @@ int wpa_supplicant_send_4_of_4(struct wpa_sm *sm, const unsigned char *dst,
 		WPA_PUT_BE16(reply->key_data_length, 0);
 
 	wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 4/4");
-	wpa_eapol_key_send(sm, ptk->kck, ptk->kck_len, ver, dst, ETH_P_EAPOL,
+	return wpa_eapol_key_send(sm, ptk->kck, ptk->kck_len, ver, dst, ETH_P_EAPOL,
 			   rbuf, rlen, key_mic);
 
-	return 0;
 }
 
 
@@ -1437,10 +1440,8 @@ static int wpa_supplicant_send_2_of_2(struct wpa_sm *sm,
 		WPA_PUT_BE16(reply->key_data_length, 0);
 
 	wpa_dbg(sm->ctx->msg_ctx, MSG_DEBUG, "WPA: Sending EAPOL-Key 2/2");
-	wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, sm->bssid,
+	return wpa_eapol_key_send(sm, sm->ptk.kck, sm->ptk.kck_len, ver, sm->bssid,
 			   ETH_P_EAPOL, rbuf, rlen, key_mic);
-
-	return 0;
 }
 
 
diff --git a/src/rsn_supp/wpa_i.h b/src/rsn_supp/wpa_i.h
index 965a9c1..5101fba 100644
--- a/src/rsn_supp/wpa_i.h
+++ b/src/rsn_supp/wpa_i.h
@@ -349,7 +349,7 @@ static inline int wpa_sm_key_mgmt_set_pmk(struct wpa_sm *sm,
 	return sm->ctx->key_mgmt_set_pmk(sm->ctx->ctx, pmk, pmk_len);
 }
 
-void wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck, size_t kck_len,
+int wpa_eapol_key_send(struct wpa_sm *sm, const u8 *kck, size_t kck_len,
 			int ver, const u8 *dest, u16 proto,
 			u8 *msg, size_t msg_len, u8 *key_mic);
 int wpa_supplicant_send_2_of_4(struct wpa_sm *sm, const unsigned char *dst,
-- 
1.7.9.5




More information about the Hostap mailing list