[PATCH 04/15] wpa_supplicant: Refactor Radio Measurement Request handling

Andrei Otcheretianski andrei.otcheretianski at intel.com
Wed Dec 28 05:06:36 PST 2016


From: Avraham Stern <avraham.stern at intel.com>

Extract the code dealing with processing the measurement request
elements to a separate function.
This will be needed for beacon report requests processing.

Signed-off-by: Avraham Stern <avraham.stern at intel.com>
---
 wpa_supplicant/rrm.c | 119 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 73 insertions(+), 46 deletions(-)

diff --git a/wpa_supplicant/rrm.c b/wpa_supplicant/rrm.c
index c63174d..e284543 100644
--- a/wpa_supplicant/rrm.c
+++ b/wpa_supplicant/rrm.c
@@ -337,44 +337,42 @@ static struct wpabuf * wpas_rrm_build_lci_report(struct wpa_supplicant *wpa_s,
 }
 
 
-void wpas_rrm_handle_radio_measurement_request(struct wpa_supplicant *wpa_s,
-					       const u8 *src,
-					       const u8 *frame, size_t len)
+static int
+wpas_rrm_handle_msr_req_element(struct wpa_supplicant *wpa_s,
+				struct rrm_measurement_request_element *req,
+				struct wpabuf **buf)
 {
-	struct wpabuf *buf, *report;
-	u8 token;
-	const u8 *end;
-
-	if (wpa_s->wpa_state != WPA_COMPLETED) {
-		wpa_printf(MSG_INFO,
-			   "RRM: Ignoring radio measurement request: Not associated");
-		return;
-	}
-
-	if (!wpa_s->rrm.rrm_used) {
-		wpa_printf(MSG_INFO,
-			   "RRM: Ignoring radio measurement request: Not RRM network");
-		return;
-	}
-
-	if (len < 3) {
+	wpa_printf(MSG_DEBUG,
+		   "Measurement request type %d token %d", req->type,
+		   req->token);
+
+	switch (req->type) {
+	case MEASURE_TYPE_LCI:
+		*buf = wpas_rrm_build_lci_report(wpa_s, &req->token, req->len,
+						 *buf);
+		break;
+	default:
 		wpa_printf(MSG_INFO,
-			   "RRM: Ignoring too short radio measurement request");
-		return;
+			   "RRM: unsupported radio measurement type %hhu",
+			   req->type);
+		break;
 	}
 
-	end = frame + len;
+	return 0;
+}
 
-	token = *frame++;
 
-	/* Ignore number of repetitions because it's not used in LCI request */
-	frame += 2;
+static struct wpabuf *
+wpas_rrm_process_msr_req_elems(struct wpa_supplicant *wpa_s, const u8 *pos,
+			       size_t len)
+{
+	struct wpabuf *buf = NULL;
 
-	report = NULL;
-	while (end - frame) {
-		struct rrm_measurement_request_element *req = (void *)frame;
+	while (len) {
+		struct rrm_measurement_request_element *req = (void *)pos;
+		int res;
 
-		if (end - frame < 2) {
+		if (len < 2) {
 			wpa_printf(MSG_DEBUG, "RRM: Truncated element");
 			goto out;
 		}
@@ -391,27 +389,58 @@ void wpas_rrm_handle_radio_measurement_request(struct wpa_supplicant *wpa_s,
 			goto out;
 		}
 
-		if (req->len + 2 > end - frame) {
+		if (req->len > len - 2) {
 			wpa_printf(MSG_DEBUG, "RRM: Element length too long");
 			goto out;
 		}
 
-		wpa_printf(MSG_DEBUG, "RRM request type: %hhu", req->type);
-
-		switch (req->type) {
-		case MEASURE_TYPE_LCI:
-			report = wpas_rrm_build_lci_report(wpa_s, frame + 2,
-							   req->len, report);
-			break;
-		default:
-			wpa_printf(MSG_INFO,
-				   "RRM: unsupported radio measurement request %hhu",
-				   req->type);
-		}
+		res = wpas_rrm_handle_msr_req_element(wpa_s, req, &buf);
+		if (res < 0)
+			goto out;
 
-		frame = frame + req->len + 2;
+		pos += req->len + 2;
+		len -= req->len + 2;
 	}
 
+	return buf;
+
+out:
+	wpabuf_free(buf);
+	return NULL;
+}
+
+
+void wpas_rrm_handle_radio_measurement_request(struct wpa_supplicant *wpa_s,
+					       const u8 *src,
+					       const u8 *frame, size_t len)
+{
+	struct wpabuf *buf, *report;
+	u8 token;
+
+	if (wpa_s->wpa_state != WPA_COMPLETED) {
+		wpa_printf(MSG_INFO,
+			   "RRM: Ignoring radio measurement request. Not associated");
+		return;
+	}
+
+	if (!wpa_s->rrm.rrm_used) {
+		wpa_printf(MSG_INFO,
+			   "RRM: Ignoring radio measurement request. Not RRM network");
+		return;
+	}
+
+	if (len < 3) {
+		wpa_printf(MSG_INFO,
+			   "RRM: Ignoring too short radio measurement request");
+		return;
+	}
+
+	token = *frame;
+
+	/* Num of repetitions is not supported */
+
+	report = wpas_rrm_process_msr_req_elems(wpa_s, frame + 3, len - 3);
+
 	if (!report)
 		return;
 
@@ -435,8 +464,6 @@ void wpas_rrm_handle_radio_measurement_request(struct wpa_supplicant *wpa_s,
 			   "RRM: Radio measurement report failed: Sending Action frame failed");
 	}
 	wpabuf_free(buf);
-
-out:
 	wpabuf_free(report);
 }
 
-- 
1.9.1




More information about the Hostap mailing list