From: James Prestwood <prestwoj@gmail.com>
To: iwd@lists.01.org
Subject: [PATCH 6/6] rrm: add packed struct for beacon reports
Date: Wed, 20 Nov 2019 09:25:59 -0800 [thread overview]
Message-ID: <20191120172559.21029-6-prestwoj@gmail.com> (raw)
In-Reply-To: <20191120172559.21029-1-prestwoj@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 3202 bytes --]
build_report_for_bss was refactored to use this packed structure rather
than l_put_* APIs.
---
src/rrm.c | 66 ++++++++++++++++++++++++++++++++++---------------------
1 file changed, 41 insertions(+), 25 deletions(-)
diff --git a/src/rrm.c b/src/rrm.c
index a231f7e9..adf55252 100644
--- a/src/rrm.c
+++ b/src/rrm.c
@@ -121,6 +121,21 @@ struct rrm_state {
uint64_t last_request;
};
+/* 802.11, Section 9.4.2.22.7 */
+struct rrm_beacon_report {
+ uint8_t oper_class;
+ uint8_t channel;
+ __le64 scan_start_time;
+ __le16 duration;
+ uint8_t frame_info;
+ uint8_t rcpi;
+ uint8_t rsni;
+ uint8_t bssid[6];
+ uint8_t antenna_id;
+ __le32 parent_tsf;
+ uint8_t subelements[0];
+} __attribute__ ((packed));
+
static struct l_queue *states;
static struct l_genl_family *nl80211;
static uint32_t netdev_watch;
@@ -224,6 +239,17 @@ static void rrm_build_measurement_report(struct rrm_request_info *info,
memcpy(to, report, report_len);
}
+/* 802.11 Table 9-154 */
+static uint8_t mdb_to_rcpi(int32_t mdb)
+{
+ if (mdb <= 10950)
+ return 0;
+ else if (mdb >= -10950 && mdb < 0)
+ return ((uint8_t)((2 * (mdb + 11000)) / 100));
+ else
+ return 220;
+}
+
/*
* 802.11-2016 11.11.9.1 Beacon report
*
@@ -245,38 +271,28 @@ static size_t build_report_for_bss(struct rrm_beacon_req_info *beacon,
struct scan_bss *bss,
uint8_t *to)
{
- uint8_t *start = to;
-
- *to++ = beacon->oper_class;
- *to++ = scan_freq_to_channel(bss->frequency, NULL);
- l_put_le64(bss->start_time_tsf, to);
- to += 8;
- l_put_le16(beacon->duration, to);
- to += 2;
- *to++ = rrm_phy_type(bss);
-
- /* 802.11 Table 9-154 - RCPI values */
- if (bss->signal_strength < -10950)
- *to++ = 0;
- else if (bss->signal_strength >= -10950 && bss->signal_strength < 0)
- *to++ = (uint8_t)((2 * (bss->signal_strength + 11000)) / 100);
- else
- *to++ = 220;
+ struct rrm_beacon_report *report = (struct rrm_beacon_report *) to;
+
+ report->oper_class = beacon->oper_class;
+ report->channel = scan_freq_to_channel(bss->frequency, NULL);
+ report->scan_start_time = bss->start_time_tsf;
+ report->duration = beacon->duration;
+ report->frame_info = rrm_phy_type(bss);
+ report->rcpi = mdb_to_rcpi(bss->signal_strength);
/* RSNI not available (could get this from GET_SURVEY) */
- *to++ = 255;
- memcpy(to, bss->addr, 6);
- to += 6;
- /* Antenna identifier unknown */
- *to++ = 0;
+ report->rsni = 255;
+ memcpy(report->bssid, bss->addr, 6);
+
+ report->antenna_id = 0;
+
/*
* 802.11 9.4.2.22.7 Beacon report
*
* "The Parent TSF field contains the lower 4 octets of the measuring
* STA’s TSF timer value"
*/
- l_put_le32((uint32_t)(bss->parent_tsf & 0xffffffff), to);
- to += 4;
+ report->parent_tsf = (uint32_t)bss->parent_tsf;
/*
* TODO: Support optional subelements
@@ -284,7 +300,7 @@ static size_t build_report_for_bss(struct rrm_beacon_req_info *beacon,
* (see "TODO: Support Reported Frame Body..." below)
*/
- return to - start;
+ return sizeof(struct rrm_beacon_report);
}
static bool bss_in_request_range(struct rrm_beacon_req_info *beacon,
--
2.17.1
prev parent reply other threads:[~2019-11-20 17:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-20 17:25 [PATCH 1/6] monitor: print START_TIME_TSF/BSSID values James Prestwood
2019-11-20 17:25 ` [PATCH 2/6] scan: parse parent TSF value in scan results James Prestwood
2019-11-20 17:25 ` [PATCH 3/6] rrm: include actual parent TSF value James Prestwood
2019-11-20 17:25 ` [PATCH 4/6] scan: parse the scan start time James Prestwood
2019-11-20 17:25 ` [PATCH 5/6] rrm: include actual scan start time in report James Prestwood
2019-11-20 17:25 ` James Prestwood [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191120172559.21029-6-prestwoj@gmail.com \
--to=prestwoj@gmail.com \
--cc=iwd@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox