wpa_supplicant: Refactor wpas_rrm_build_lci_report()
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@intel.com>
This commit is contained in:
parent
e1b96e1126
commit
3c716fdbd7
1 changed files with 46 additions and 32 deletions
|
@ -298,35 +298,35 @@ 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,
|
static int
|
||||||
const u8 *request, size_t len,
|
wpas_rrm_build_lci_report(struct wpa_supplicant *wpa_s,
|
||||||
struct wpabuf *report)
|
const struct rrm_measurement_request_element *req,
|
||||||
|
struct wpabuf **buf)
|
||||||
{
|
{
|
||||||
u8 token, type, subject;
|
u8 subject;
|
||||||
u16 max_age = 0;
|
u16 max_age = 0;
|
||||||
struct os_reltime t, diff;
|
struct os_reltime t, diff;
|
||||||
unsigned long diff_l;
|
unsigned long diff_l;
|
||||||
u8 *ptoken;
|
|
||||||
const u8 *subelem;
|
const u8 *subelem;
|
||||||
|
const u8 *request = req->variable;
|
||||||
|
size_t len = req->len - 3;
|
||||||
|
|
||||||
if (!wpa_s->lci || len < 3 + 4)
|
if (len < 4)
|
||||||
return report;
|
return -1;
|
||||||
|
|
||||||
|
if (!wpa_s->lci)
|
||||||
|
goto reject;
|
||||||
|
|
||||||
token = *request++;
|
|
||||||
/* Measurement request mode isn't used */
|
|
||||||
request++;
|
|
||||||
type = *request++;
|
|
||||||
subject = *request++;
|
subject = *request++;
|
||||||
len -= 4;
|
len--;
|
||||||
|
|
||||||
wpa_printf(MSG_DEBUG,
|
wpa_printf(MSG_DEBUG, "Measurement request location subject=%u",
|
||||||
"Measurement request token %u type %u location subject %u",
|
subject);
|
||||||
token, type, subject);
|
|
||||||
|
|
||||||
if (type != MEASURE_TYPE_LCI || subject != LOCATION_SUBJECT_REMOTE) {
|
if (subject != LOCATION_SUBJECT_REMOTE) {
|
||||||
wpa_printf(MSG_INFO,
|
wpa_printf(MSG_INFO,
|
||||||
"Not building LCI report - bad type or location subject");
|
"Not building LCI report - bad location subject");
|
||||||
return report;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Subelements are formatted exactly like elements */
|
/* Subelements are formatted exactly like elements */
|
||||||
|
@ -335,26 +335,42 @@ static struct wpabuf * wpas_rrm_build_lci_report(struct wpa_supplicant *wpa_s,
|
||||||
max_age = WPA_GET_LE16(subelem + 2);
|
max_age = WPA_GET_LE16(subelem + 2);
|
||||||
|
|
||||||
if (os_get_reltime(&t))
|
if (os_get_reltime(&t))
|
||||||
return report;
|
goto reject;
|
||||||
|
|
||||||
os_reltime_sub(&t, &wpa_s->lci_time, &diff);
|
os_reltime_sub(&t, &wpa_s->lci_time, &diff);
|
||||||
/* LCI age is calculated in 10th of a second units. */
|
/* LCI age is calculated in 10th of a second units. */
|
||||||
diff_l = diff.sec * 10 + diff.usec / 100000;
|
diff_l = diff.sec * 10 + diff.usec / 100000;
|
||||||
|
|
||||||
if (max_age != 0xffff && max_age < diff_l)
|
if (max_age != 0xffff && max_age < diff_l)
|
||||||
return report;
|
goto reject;
|
||||||
|
|
||||||
if (wpabuf_resize(&report, 2 + wpabuf_len(wpa_s->lci)))
|
if (wpabuf_resize(buf, 5 + wpabuf_len(wpa_s->lci)))
|
||||||
return report;
|
return -1;
|
||||||
|
|
||||||
wpabuf_put_u8(report, WLAN_EID_MEASURE_REPORT);
|
if (wpas_rrm_report_elem(*buf, req->token,
|
||||||
wpabuf_put_u8(report, wpabuf_len(wpa_s->lci));
|
MEASUREMENT_REPORT_MODE_ACCEPT, req->type,
|
||||||
/* We'll override user's measurement token */
|
wpabuf_head_u8(wpa_s->lci),
|
||||||
ptoken = wpabuf_put(report, 0);
|
wpabuf_len(wpa_s->lci)) < 0) {
|
||||||
wpabuf_put_buf(report, wpa_s->lci);
|
wpa_printf(MSG_DEBUG, "Failed to add LCI report element");
|
||||||
*ptoken = token;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return report;
|
return 0;
|
||||||
|
|
||||||
|
reject:
|
||||||
|
if (wpabuf_resize(buf, sizeof(struct rrm_measurement_report_element))) {
|
||||||
|
wpa_printf(MSG_DEBUG, "RRM: Memory allocation failed");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -432,9 +448,7 @@ wpas_rrm_handle_msr_req_element(
|
||||||
|
|
||||||
switch (req->type) {
|
switch (req->type) {
|
||||||
case MEASURE_TYPE_LCI:
|
case MEASURE_TYPE_LCI:
|
||||||
*buf = wpas_rrm_build_lci_report(wpa_s, &req->token, req->len,
|
return wpas_rrm_build_lci_report(wpa_s, req, buf);
|
||||||
*buf);
|
|
||||||
return 0;
|
|
||||||
default:
|
default:
|
||||||
wpa_printf(MSG_INFO,
|
wpa_printf(MSG_INFO,
|
||||||
"RRM: Unsupported radio measurement type %u",
|
"RRM: Unsupported radio measurement type %u",
|
||||||
|
|
Loading…
Reference in a new issue