diff mbox series

[3/4] wpa_supplicant: add support for pre-auth rx over driver event

Message ID 20200113113735.32182-4-markus.theil@tu-ilmenau.de
State Changes Requested
Headers show
Series Handle pre-auth over nl80211 control port | expand

Commit Message

Markus Theil Jan. 13, 2020, 11:37 a.m. UTC
This patch enables wpa_supplicant to receive pre-auth frames
over nl80211.

Signed-off-by: Markus Theil <markus.theil@tu-ilmenau.de>
---
 src/rsn_supp/preauth.c            |  4 ++--
 src/rsn_supp/preauth.h            |  7 +++++++
 wpa_supplicant/events.c           |  5 +++++
 wpa_supplicant/wpa_supplicant.c   | 28 ++++++++++++++++++++++++++++
 wpa_supplicant/wpa_supplicant_i.h |  2 ++
 5 files changed, 44 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/rsn_supp/preauth.c b/src/rsn_supp/preauth.c
index a7ca2ed8b..f90da68c9 100644
--- a/src/rsn_supp/preauth.c
+++ b/src/rsn_supp/preauth.c
@@ -58,8 +58,8 @@  static int rsn_preauth_key_mgmt(int akmp)
 }
 
 
-static void rsn_preauth_receive(void *ctx, const u8 *src_addr,
-				const u8 *buf, size_t len)
+void rsn_preauth_receive(void *ctx, const u8 *src_addr,
+			 const u8 *buf, size_t len)
 {
 	struct wpa_sm *sm = ctx;
 
diff --git a/src/rsn_supp/preauth.h b/src/rsn_supp/preauth.h
index 8caf3ee56..992ba86fc 100644
--- a/src/rsn_supp/preauth.h
+++ b/src/rsn_supp/preauth.h
@@ -14,6 +14,8 @@  struct wpa_scan_results;
 #if defined(IEEE8021X_EAPOL) && !defined(CONFIG_NO_WPA)
 
 void pmksa_candidate_free(struct wpa_sm *sm);
+void rsn_preauth_receive(void *ctx, const u8 *src_addr,
+			 const u8 *buf, size_t len);
 int rsn_preauth_init(struct wpa_sm *sm, const u8 *dst,
 		     struct eap_peer_config *eap_conf);
 void rsn_preauth_deinit(struct wpa_sm *sm);
@@ -33,6 +35,11 @@  static inline void pmksa_candidate_free(struct wpa_sm *sm)
 {
 }
 
+static inline void rsn_preauth_receive(void *ctx, const u8 *src_addr,
+				       const u8 *buf, size_t len)
+{
+}
+
 static inline void rsn_preauth_candidate_process(struct wpa_sm *sm)
 {
 }
diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c
index 90138c60d..ef2492b63 100644
--- a/wpa_supplicant/events.c
+++ b/wpa_supplicant/events.c
@@ -4872,6 +4872,11 @@  void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
 					data->eapol_rx.data,
 					data->eapol_rx.data_len);
 		break;
+	case EVENT_RSN_PREAUTH_RX:
+		wpa_supplicant_rx_rsn_preauth(wpa_s, data->rsn_preauth_rx.src,
+					data->rsn_preauth_rx.data,
+					data->rsn_preauth_rx.data_len);
+		break;
 	case EVENT_SIGNAL_CHANGE:
 		wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE
 			"above=%d signal=%d noise=%d txrate=%d",
diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c
index 9f3d6ef60..bd617d454 100644
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
@@ -4657,6 +4657,34 @@  void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
 	}
 }
 
+/**
+ * wpa_supplicant_rx_rsn_preauth - Deliver a received PREAUTH frame to
+ * wpa_supplicant
+ * @ctx: Context pointer (wpa_s); this is the ctx variable registered
+ *	with struct wpa_driver_ops::init()
+ * @src_addr: Source address of the PREAUTH frame
+ * @buf: EAPOL data starting from the PREAUTH header (i.e., no Ethernet header)
+ * @len: Length of the PREAUTH data
+ *
+ * This function is called for each received PREAUTH frame. Most driver
+ * interfaces rely on more generic OS mechanism for receiving frames through
+ * l2_packet, but if such a mechanism is not available, the driver wrapper may
+ * take care of received PREAUTH frames and deliver them to the core supplicant
+ * code by calling this function.
+ */
+void wpa_supplicant_rx_rsn_preauth(void *ctx, const u8 *src_addr,
+				   const u8 *buf, size_t len)
+{
+	struct wpa_supplicant *wpa_s = ctx;
+
+	wpa_dbg(wpa_s, MSG_DEBUG, "RX RSN PREAUTH from " MACSTR, MAC2STR(src_addr));
+	wpa_hexdump(MSG_MSGDUMP, "RX RSN PREAUTH", buf, len);
+
+	if (wpa_s->wpa) {
+		rsn_preauth_receive(wpa_s->wpa, src_addr, buf, len);
+	}
+}
+
 
 int wpa_supplicant_update_mac_addr(struct wpa_supplicant *wpa_s)
 {
diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h
index 7ab6ca377..397aedab0 100644
--- a/wpa_supplicant/wpa_supplicant_i.h
+++ b/wpa_supplicant/wpa_supplicant_i.h
@@ -1372,6 +1372,8 @@  int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s,
 void wpa_supplicant_terminate_proc(struct wpa_global *global);
 void wpa_supplicant_rx_eapol(void *ctx, const u8 *src_addr,
 			     const u8 *buf, size_t len);
+void wpa_supplicant_rx_rsn_preauth(void *ctx, const u8 *src_addr,
+				   const u8 *buf, size_t len);
 void wpa_supplicant_update_config(struct wpa_supplicant *wpa_s);
 void wpa_supplicant_clear_status(struct wpa_supplicant *wpa_s);
 void wpas_connection_failed(struct wpa_supplicant *wpa_s, const u8 *bssid);