[PATCH 07/15] wpa_supplicant: Refactor wpas_rrm_build_lci_report()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Avraham Stern <avraham.stern@xxxxxxxxx>

1. Change the return type to reflect whether building the report
   succeeded or failed.
2. Change argument type to rrm_measurement_request_element instead
   of raw packet data to ease processing the request.
3. Use already existing function to create the measurement report
   and add it to the report buffer.

Signed-off-by: Avraham Stern <avraham.stern@xxxxxxxxx>
---
 wpa_supplicant/rrm.c | 77 +++++++++++++++++++++++++++++++---------------------
 1 file changed, 46 insertions(+), 31 deletions(-)

diff --git a/wpa_supplicant/rrm.c b/wpa_supplicant/rrm.c
index 584b1c4..696dd26 100644
--- a/wpa_supplicant/rrm.c
+++ b/wpa_supplicant/rrm.c
@@ -297,34 +297,34 @@ static int wpas_rrm_report_elem(struct wpabuf *buf, u8 token, u8 mode, u8 type,
 }
 
 
-static struct wpabuf * wpas_rrm_build_lci_report(struct wpa_supplicant *wpa_s,
-						 const u8 *request, size_t len,
-						 struct wpabuf *report)
+static int
+wpas_rrm_build_lci_report(struct wpa_supplicant *wpa_s,
+			  struct rrm_measurement_request_element *req,
+			  struct wpabuf **buf)
 {
-	u8 token, type, subject;
+	u8 subject;
 	u16 max_age = 0;
 	struct os_reltime t, diff;
 	unsigned long diff_l;
-	u8 *ptoken;
 	const u8 *subelem;
+	const u8 *request = req->variable;
+	size_t len = req->len - 3;
+
+	if (len < 4)
+		return -1;
 
-	if (!wpa_s->lci || len < 3 + 4)
-		return report;
+	if (!wpa_s->lci)
+		goto reject;
 
-	token = *request++;
-	/* Measurement request mode isn't used */
-	request++;
-	type = *request++;
 	subject = *request++;
 
-	wpa_printf(MSG_DEBUG,
-		   "Measurement request token %u type %u location subject %u",
-		   token, type, subject);
+	wpa_printf(MSG_DEBUG, "Measurement request location subject=%d",
+		   subject);
 
-	if (type != MEASURE_TYPE_LCI || subject != LOCATION_SUBJECT_REMOTE) {
+	if (subject != LOCATION_SUBJECT_REMOTE) {
 		wpa_printf(MSG_INFO,
-			   "Not building LCI report - bad type or location subject");
-		return report;
+			   "Not building LCI report - bad location subject");
+		return 0;
 	}
 
 	/* Subelements are formatted exactly like elements */
@@ -333,26 +333,43 @@ static struct wpabuf * wpas_rrm_build_lci_report(struct wpa_supplicant *wpa_s,
 		max_age = WPA_GET_LE16(subelem + 2);
 
 	if (os_get_reltime(&t))
-		return report;
+		goto reject;
 
 	os_reltime_sub(&t, &wpa_s->lci_time, &diff);
 	/* LCI age is calculated in 10th of a second units. */
 	diff_l = diff.sec * 10 + diff.usec / 100000;
 
 	if (max_age != 0xffff && max_age < diff_l)
-		return report;
+		goto reject;
+
+	if (wpabuf_resize(buf, 2 + wpabuf_len(wpa_s->lci)))
+		return -1;
+
+	if (wpas_rrm_report_elem(*buf, req->token,
+				 MEASUREMENT_REPORT_MODE_ACCEPT, req->type,
+				 wpabuf_head_u8(wpa_s->lci),
+				 wpabuf_len(wpa_s->lci)) < 0) {
+		wpa_printf(MSG_DEBUG, "Failed to add LCI report element");
+		return -1;
+	}
+
+	return 0;
 
-	if (wpabuf_resize(&report, 2 + wpabuf_len(wpa_s->lci)))
-		return report;
+reject:
+	if (wpabuf_resize(buf, sizeof(struct rrm_measurement_report_element))) {
+		wpa_printf(MSG_DEBUG,
+			   "RRM: Memory allocation failed");
+		return -1;
+	}
 
-	wpabuf_put_u8(report, WLAN_EID_MEASURE_REPORT);
-	wpabuf_put_u8(report, wpabuf_len(wpa_s->lci));
-	/* We'll override user's measurement token */
-	ptoken = wpabuf_put(report, 0);
-	wpabuf_put_buf(report, wpa_s->lci);
-	*ptoken = token;
+	if (wpas_rrm_report_elem(*buf, req->token,
+				 MEASUREMENT_REPORT_MODE_REJECT_INCAPABLE,
+				 req->type, NULL, 0) < 0) {
+		wpa_printf(MSG_DEBUG, "RRM: Failed to add report element");
+		return -1;
+	}
 
-	return report;
+	return 0;
 }
 
 
@@ -382,9 +399,7 @@ wpas_rrm_handle_msr_req_element(struct wpa_supplicant *wpa_s,
 
 	switch (req->type) {
 	case MEASURE_TYPE_LCI:
-		*buf = wpas_rrm_build_lci_report(wpa_s, &req->token, req->len,
-						 *buf);
-		return 0;
+		return wpas_rrm_build_lci_report(wpa_s, req, buf);
 	default:
 		wpa_printf(MSG_INFO,
 			   "RRM: unsupported radio measurement type %hhu",
-- 
1.9.1


_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap



[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux