All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values
@ 2019-11-20 17:31 James Prestwood
  2019-11-20 17:31 ` [PATCH v2 2/6] scan: fix parent TSF parsing James Prestwood
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: James Prestwood @ 2019-11-20 17:31 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

---
 monitor/nlmon.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/monitor/nlmon.c b/monitor/nlmon.c
index 94d16979..4c0e045f 100644
--- a/monitor/nlmon.c
+++ b/monitor/nlmon.c
@@ -5578,6 +5578,10 @@ static const struct attr_entry attr_table[] = {
 			"FTM Responder" },
 	{ NL80211_ATTR_FTM_RESPONDER_STATS,
 			"FTM Responder Stats" },
+	{ NL80211_ATTR_SCAN_START_TIME_TSF,
+			"Scan Start Time", ATTR_U64 },
+	{ NL80211_ATTR_SCAN_START_TIME_TSF_BSSID,
+			"Scan Start Time BSSID", ATTR_ADDRESS },
 	{ }
 };
 
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/6] scan: fix parent TSF parsing
  2019-11-20 17:31 [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values James Prestwood
@ 2019-11-20 17:31 ` James Prestwood
  2019-11-20 17:31 ` [PATCH v2 3/6] rrm: include actual parent TSF value James Prestwood
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: James Prestwood @ 2019-11-20 17:31 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 752 bytes --]

The value coming from the kernel is in the same endianness as IWD, so
just parse it as a u64 rather than le64.
---
 src/scan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

-v2:
 * Changed the commit description to match what was being changed. This
   commit description somehow got duplicated from a previously upstreamed
   commit adding parent TSF parsing

diff --git a/src/scan.c b/src/scan.c
index e74a69c1..e007ce5d 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -1076,7 +1076,7 @@ static struct scan_bss *scan_parse_attr_bss(struct l_genl_attr *attr)
 			if (len != sizeof(uint64_t))
 				goto fail;
 
-			bss->parent_tsf = l_get_le64(data);
+			bss->parent_tsf = l_get_u64(data);
 			break;
 		}
 	}
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/6] rrm: include actual parent TSF value
  2019-11-20 17:31 [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values James Prestwood
  2019-11-20 17:31 ` [PATCH v2 2/6] scan: fix parent TSF parsing James Prestwood
@ 2019-11-20 17:31 ` James Prestwood
  2019-11-20 17:31 ` [PATCH v2 4/6] scan: parse the scan start time James Prestwood
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: James Prestwood @ 2019-11-20 17:31 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 703 bytes --]

If the scan results included a parent TSF value use it.
---
 src/rrm.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/rrm.c b/src/rrm.c
index 73cf01f2..2b0a22fb 100644
--- a/src/rrm.c
+++ b/src/rrm.c
@@ -270,8 +270,13 @@ static size_t build_report_for_bss(struct rrm_beacon_req_info *beacon,
 	to += 6;
 	/* Antenna identifier unknown */
 	*to++ = 0;
-	/* Parent TSF - zero */
-	memset(to, 0, 4);
+	/*
+	 * 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;
 
 	/*
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 4/6] scan: parse the scan start time
  2019-11-20 17:31 [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values James Prestwood
  2019-11-20 17:31 ` [PATCH v2 2/6] scan: fix parent TSF parsing James Prestwood
  2019-11-20 17:31 ` [PATCH v2 3/6] rrm: include actual parent TSF value James Prestwood
@ 2019-11-20 17:31 ` James Prestwood
  2019-11-21  2:21   ` Denis Kenzior
  2019-11-20 17:31 ` [PATCH v2 5/6] rrm: include actual scan start time in report James Prestwood
                   ` (2 subsequent siblings)
  5 siblings, 1 reply; 8+ messages in thread
From: James Prestwood @ 2019-11-20 17:31 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 2304 bytes --]

The kernel sends NL80211_ATTR_SCAN_START_TIME_TSF with CMD_TRIGGER and
RRM requires this value for beacon measurement reports. Since this
value is sent with CMD_TRIGGER we have to store it in the scan_context
and set it into the scan_bss when the scan finishes.
---
 src/scan.c | 13 +++++++++++++
 src/scan.h |  1 +
 2 files changed, 14 insertions(+)

diff --git a/src/scan.c b/src/scan.c
index e007ce5d..52ed102c 100644
--- a/src/scan.c
+++ b/src/scan.c
@@ -91,6 +91,9 @@ struct scan_context {
 	unsigned int start_cmd_id;
 	/* Non-zero if GET_SCAN is still running */
 	unsigned int get_scan_cmd_id;
+
+	/* The time the current scan was started. Reported in TRIGGER_SCAN */
+	uint64_t start_time_tsf;
 	/*
 	 * Whether the top request in the queue has triggered the current
 	 * scan.  May be set and cleared multiple times during a single
@@ -1312,6 +1315,7 @@ static void get_scan_callback(struct l_genl_msg *msg, void *user_data)
 	}
 
 	bss->time_stamp = results->time_stamp;
+	bss->start_time_tsf = sc->start_time_tsf;
 
 	scan_bss_compute_rank(bss);
 	l_queue_insert(results->bss_list, bss, scan_bss_rank_compare, NULL);
@@ -1439,6 +1443,7 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
 	uint32_t wiphy_id;
 	struct scan_context *sc;
 	bool active_scan = false;
+	uint64_t start_time_tsf = 0;
 
 	cmd = l_genl_msg_get_command(msg);
 
@@ -1461,6 +1466,12 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
 		case NL80211_ATTR_SCAN_SSIDS:
 			active_scan = true;
 			break;
+		case NL80211_ATTR_SCAN_START_TIME_TSF:
+			if (len != sizeof(uint64_t))
+				return;
+
+			start_time_tsf = l_get_u64(data);
+			break;
 		}
 	}
 
@@ -1543,6 +1554,8 @@ static void scan_notify(struct l_genl_msg *msg, void *user_data)
 		else
 			sc->state = SCAN_STATE_PASSIVE;
 
+		sc->start_time_tsf = start_time_tsf;
+
 		break;
 
 	case NL80211_CMD_SCAN_ABORTED:
diff --git a/src/scan.h b/src/scan.h
index 8fc2aa56..fcbbe285 100644
--- a/src/scan.h
+++ b/src/scan.h
@@ -67,6 +67,7 @@ struct scan_bss {
 	uint8_t hessid[6];
 	uint8_t *rc_ie;		/* Roaming consortium IE */
 	uint8_t hs20_version;
+	uint64_t start_time_tsf;
 	uint64_t parent_tsf;
 	bool mde_present : 1;
 	bool cc_present : 1;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 5/6] rrm: include actual scan start time in report
  2019-11-20 17:31 [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values James Prestwood
                   ` (2 preceding siblings ...)
  2019-11-20 17:31 ` [PATCH v2 4/6] scan: parse the scan start time James Prestwood
@ 2019-11-20 17:31 ` James Prestwood
  2019-11-20 17:31 ` [PATCH v2 6/6] rrm: add packed struct for beacon reports James Prestwood
  2019-11-21  2:15 ` [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values Denis Kenzior
  5 siblings, 0 replies; 8+ messages in thread
From: James Prestwood @ 2019-11-20 17:31 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 520 bytes --]

---
 src/rrm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/rrm.c b/src/rrm.c
index 2b0a22fb..a231f7e9 100644
--- a/src/rrm.c
+++ b/src/rrm.c
@@ -249,8 +249,7 @@ static size_t build_report_for_bss(struct rrm_beacon_req_info *beacon,
 
 	*to++ = beacon->oper_class;
 	*to++ = scan_freq_to_channel(bss->frequency, NULL);
-	/* skip start time */
-	memset(to, 0, 8);
+	l_put_le64(bss->start_time_tsf, to);
 	to += 8;
 	l_put_le16(beacon->duration, to);
 	to += 2;
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 6/6] rrm: add packed struct for beacon reports
  2019-11-20 17:31 [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values James Prestwood
                   ` (3 preceding siblings ...)
  2019-11-20 17:31 ` [PATCH v2 5/6] rrm: include actual scan start time in report James Prestwood
@ 2019-11-20 17:31 ` James Prestwood
  2019-11-21  2:15 ` [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values Denis Kenzior
  5 siblings, 0 replies; 8+ messages in thread
From: James Prestwood @ 2019-11-20 17:31 UTC (permalink / raw)
  To: iwd

[-- 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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values
  2019-11-20 17:31 [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values James Prestwood
                   ` (4 preceding siblings ...)
  2019-11-20 17:31 ` [PATCH v2 6/6] rrm: add packed struct for beacon reports James Prestwood
@ 2019-11-21  2:15 ` Denis Kenzior
  5 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2019-11-21  2:15 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 189 bytes --]

Hi James,

On 11/20/19 11:31 AM, James Prestwood wrote:
> ---
>   monitor/nlmon.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 

Patches 1-3 applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 4/6] scan: parse the scan start time
  2019-11-20 17:31 ` [PATCH v2 4/6] scan: parse the scan start time James Prestwood
@ 2019-11-21  2:21   ` Denis Kenzior
  0 siblings, 0 replies; 8+ messages in thread
From: Denis Kenzior @ 2019-11-21  2:21 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 806 bytes --]

Hi James,

On 11/20/19 11:31 AM, James Prestwood wrote:
> The kernel sends NL80211_ATTR_SCAN_START_TIME_TSF with CMD_TRIGGER and
> RRM requires this value for beacon measurement reports. Since this
> value is sent with CMD_TRIGGER we have to store it in the scan_context
> and set it into the scan_bss when the scan finishes.

That seems rather expensive?  To store an 8 byte value in all the bsses 
that really belongs in the trigger callback?  Perhaps we should just 
pass it in as an additional argument.

Or since we have the scan_request id, perhaps it should be obtainable 
using that?  E.g. something like:

uint64_t scan_get_triggered_time(uint32_t id);

> ---
>   src/scan.c | 13 +++++++++++++
>   src/scan.h |  1 +
>   2 files changed, 14 insertions(+)
> 

Regards,
-Denis

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-11-21  2:21 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 17:31 [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values James Prestwood
2019-11-20 17:31 ` [PATCH v2 2/6] scan: fix parent TSF parsing James Prestwood
2019-11-20 17:31 ` [PATCH v2 3/6] rrm: include actual parent TSF value James Prestwood
2019-11-20 17:31 ` [PATCH v2 4/6] scan: parse the scan start time James Prestwood
2019-11-21  2:21   ` Denis Kenzior
2019-11-20 17:31 ` [PATCH v2 5/6] rrm: include actual scan start time in report James Prestwood
2019-11-20 17:31 ` [PATCH v2 6/6] rrm: add packed struct for beacon reports James Prestwood
2019-11-21  2:15 ` [PATCH v2 1/6] monitor: print START_TIME_TSF/BSSID values Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.