Re: [PATCH v4 1/2] cfg80211: add peer measurement with FTM initiator API

2018-10-17 Thread Johannes Berg
On Wed, 2018-10-17 at 14:52 +0300, Lior David wrote:
> 
> On 10/16/2018 12:30 PM, Johannes Berg wrote:
> 
> [...]
> > + * @rtt_avg: average of RTTs measured (must have either this or @dist_avg)
> > + * @rtt_variance: variance of RTTs measured (note that standard deviation 
> > is
> > + * the square root of the variance)
> > + * @rtt_spread: spread of the RTTs measured
> > + * @dist_avg: average of distances (mm) measured
> > + * (must have either this or @rtt_avg)
> > + * @dist_variance: variance of distances measured (see also @rtt_variance)
> > + * @dist_spread: spread of distances measured (see also @rtt_spread)
> 
> I don't remember much from my statistics class, can you please provide some
> details about the variance and spread fields? Alternatively I can look at the
> first driver implementation for reference, unless it is calculated by FW :-)

It can only be calculated by firmware, unless the firmware reports all
measurements.

Spread here is just "highest value - lowest value.

Variance is a more complicated measure of the distribution... What do
you want to know? Here we have a finite set of values, so 

https://en.wikipedia.org/wiki/Variance#Population_variance

> > + * @partial: indicates that this is a partial result for this type
> > + * @final: if reporting partial results, mark this as the last one
> 
> Maybe it is enough to have just the "final" bit? I mean if final bit is clear
> doesn't this imply the result is partial since more results will follow?

Hmm, good point.

> > +/**
> > + * struct cfg80211_pmsr_capabilities - cfg80211 peer measurement 
> > capabilities
> > + * @max_peers: maximum number of peers in a single measurement
> > + * @report_ap_tsf: can report assoc AP's TSF for radio resource measurement
> > + * @randomize_mac_addr: can randomize MAC address for measurement
> > + * @ftm.supported: FTM measurement is supported
> > + * @ftm.asap: ASAP-mode is supported
> > + * @ftm.non_asap: non-ASAP-mode is supported
> > + * @ftm.request_lci: can request LCI data
> > + * @ftm.request_civicloc: can request civic location data
> > + * @ftm.preambles: bitmap of preambles supported (&enum nl80211_preamble)
> > + * @ftm.bandwidths: bitmap of bandwidths supported (&enum 
> > nl80211_chan_width)
> 
> Consider adding ftm.max_bursts (or max_bursts_exponent) 

Ok.

> and
> ftm.max_measurements_per_burst (is this the same as frames_per_burst?). For
> example in our implementation we can't do more than 6 measurements per burst
> because of resource limitations.

I guess measurements per burst are frames per burst? I'm not counting 4x
the frames because those are exchanged.

The spec says "FTMs per Burst", so perhaps I should align with that.

I suppose we can add that.

> Ok I see variance and spread are better documented here, maybe move the units
> information to the above structure definitions?

Well, they may seem above - but I thought it was more important to
document it better in the userspace API.

> > +/* multicast groups */
> > +enum nl80211_multicast_groups {
> > +   NL80211_MCGRP_CONFIG,
> > +   NL80211_MCGRP_SCAN,
> > +   NL80211_MCGRP_REGULATORY,
> > +   NL80211_MCGRP_MLME,
> > +   NL80211_MCGRP_VENDOR,
> > +   NL80211_MCGRP_NAN,
> > +   NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
> > +};
> > +
> 
> Are these changes needed anymore since you don't send results as multicast?

No, good point.

johannes



Re: [PATCH v4 1/2] cfg80211: add peer measurement with FTM initiator API

2018-10-17 Thread Lior David



On 10/16/2018 12:30 PM, Johannes Berg wrote:

[...]
> + * @rtt_avg: average of RTTs measured (must have either this or @dist_avg)
> + * @rtt_variance: variance of RTTs measured (note that standard deviation is
> + *   the square root of the variance)
> + * @rtt_spread: spread of the RTTs measured
> + * @dist_avg: average of distances (mm) measured
> + *   (must have either this or @rtt_avg)
> + * @dist_variance: variance of distances measured (see also @rtt_variance)
> + * @dist_spread: spread of distances measured (see also @rtt_spread)
I don't remember much from my statistics class, can you please provide some
details about the variance and spread fields? Alternatively I can look at the
first driver implementation for reference, unless it is calculated by FW :-)


> +
> +/**
> + * struct cfg80211_pmsr_result - peer measurement result
> + * @addr: address of the peer
> + * @host_time: host time (use ktime_get_boottime() adjust to the time when 
> the
> + *   measurement was made)
> + * @ap_tsf: AP's TSF at measurement time
> + * @status: status of the measurement
> + * @partial: indicates that this is a partial result for this type
> + * @final: if reporting partial results, mark this as the last one
Maybe it is enough to have just the "final" bit? I mean if final bit is clear
doesn't this imply the result is partial since more results will follow?

[...]

>  /*
> @@ -3863,6 +4055,33 @@ struct wiphy_iftype_ext_capab {
>   u8 extended_capabilities_len;
>  };
>  
> +/**
> + * struct cfg80211_pmsr_capabilities - cfg80211 peer measurement capabilities
> + * @max_peers: maximum number of peers in a single measurement
> + * @report_ap_tsf: can report assoc AP's TSF for radio resource measurement
> + * @randomize_mac_addr: can randomize MAC address for measurement
> + * @ftm.supported: FTM measurement is supported
> + * @ftm.asap: ASAP-mode is supported
> + * @ftm.non_asap: non-ASAP-mode is supported
> + * @ftm.request_lci: can request LCI data
> + * @ftm.request_civicloc: can request civic location data
> + * @ftm.preambles: bitmap of preambles supported (&enum nl80211_preamble)
> + * @ftm.bandwidths: bitmap of bandwidths supported (&enum nl80211_chan_width)
Consider adding ftm.max_bursts (or max_bursts_exponent) and
ftm.max_measurements_per_burst (is this the same as frames_per_burst?). For
example in our implementation we can't do more than 6 measurements per burst
because of resource limitations.

> +
> +/**
> + * enum nl80211_peer_measurement_ftm_resp - FTM response attributes
> + * @__NL80211_PMSR_FTM_RESP_ATTR_INVALID: invalid
> + *
> + * @NL80211_PMSR_FTM_RESP_ATTR_FAIL_REASON: FTM-specific failure reason
> + *   (u32, optional)
> + * @NL80211_PMSR_FTM_RESP_ATTR_BURST_INDEX: optional, if bursts are reported
> + *   as separate results then it will be the burst index 0...(N-1) and
> + *   the top level will indicate partial results (u32)
> + * @NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_ATTEMPTS: number of FTM Request 
> frames
> + *   transmitted (u32, optional)
> + * @NL80211_PMSR_FTM_RESP_ATTR_NUM_FTMR_SUCCESSES: number of FTM Request 
> frames
> + *   that were acknowleged (u32, optional)
> + * @NL80211_PMSR_FTM_RESP_ATTR_BUSY_RETRY_TIME: retry time received from the
> + *   busy peer (u32, seconds)
> + * @NL80211_PMSR_FTM_RESP_ATTR_NUM_BURSTS_EXP: actual number of bursts 
> exponent
> + *   used by the responder (similar to request, u8)
> + * @NL80211_PMSR_FTM_RESP_ATTR_BURST_DURATION: actual burst duration used by
> + *   the responder (similar to request, u8)
> + * @NL80211_PMSR_FTM_RESP_ATTR_FRAMES_PER_BURST: actual frames per burst used
> + *   by the responder (similar to request, u8)
> + * @NL80211_PMSR_FTM_RESP_ATTR_RSSI_AVG: average RSSI across all FTM action
> + *   frames (optional, s32, 1/2 dBm)
> + * @NL80211_PMSR_FTM_RESP_ATTR_RSSI_SPREAD: RSSI spread across all FTM action
> + *   frames (optional, s32, 1/2 dBm)
> + * @NL80211_PMSR_FTM_RESP_ATTR_TX_RATE: bitrate we used for the response to 
> the
> + *   FTM action frame (optional, nested, using &enum nl80211_rate_info
> + *   attributes)
> + * @NL80211_PMSR_FTM_RESP_ATTR_RX_RATE: bitrate the responder used for the 
> FTM
> + *   action frame (optional, nested, using &enum nl80211_rate_info attrs)
> + * @NL80211_PMSR_FTM_RESP_ATTR_RTT_AVG: average RTT (s64, picoseconds, 
> optional
> + *   but one of RTT/DIST must be present)
> + * @NL80211_PMSR_FTM_RESP_ATTR_RTT_VARIANCE: RTT variance (u64, ps^2, note 
> that
> + *   standard deviation is the square root of variance, optional)
> + * @NL80211_PMSR_FTM_RESP_ATTR_RTT_SPREAD: RTT spread (u64, picoseconds,
> + *   optional)
> + * @NL80211_PMSR_FTM_RESP_ATTR_DIST_AVG: average distance (s64, mm, optional
> + *   but one of RTT/DIST must be present)
> + * @NL80211_PMSR_FTM_RESP_ATTR_DIST_VARIANCE: distance variance (u64, mm^2, 
> note
> + *   that standard deviation is the square root of variance, optional)
> + * @NL80211_PMSR_FTM_RESP_ATTR_DIST_SPREAD: distance spread (u64, mm, 
> optional)
Ok

[PATCH v4 1/2] cfg80211: add peer measurement with FTM initiator API

2018-10-16 Thread Johannes Berg
From: Johannes Berg 

Add a new "peer measurement" API, that can be used to measure
certain things related to a peer. Right now, only implement
FTM (flight time measurement) over it, but the idea is that
it'll be extensible to also support measuring the necessary
things to calculate e.g. angle-of-arrival for WiGig.

The API is structured to have a generic list of peers and
channels to measure with/on, and then for each of those a
set of measurements (again, only FTM right now) to perform.

Results are sent to the requesting socket, including a final
complete message.

Closing the controlling netlink socket will abort a running
measurement.

Signed-off-by: Johannes Berg 
---
v3:
 - add a bit to report "final" for partial results
 - remove list keeping etc. and just unicast out the results
   to the requester (big code reduction ...)
 - also send complete message unicast, and as a result
   remove the multicast group
 - separate out struct cfg80211_pmsr_ftm_request_peer
   from struct cfg80211_pmsr_request_peer
 - document timeout == 0 if no timeout
 - disallow setting timeout nl80211 attribute to 0,
   must not include attribute for no timeout
 - make MAC address randomization optional
 - change num bursts exponent default to 0 (1 burst, rather
   rather than the old default of 15==don't care)

v4:
 - clarify NL80211_ATTR_TIMEOUT documentation
---
 include/net/cfg80211.h   | 255 
 include/uapi/linux/nl80211.h | 412 +
 net/wireless/Makefile|   1 +
 net/wireless/core.c  |  33 ++
 net/wireless/core.h  |   4 +
 net/wireless/nl80211.c   | 200 +---
 net/wireless/nl80211.h   |  41 +++
 net/wireless/pmsr.c  | 576 +++
 net/wireless/rdev-ops.h  |  25 ++
 net/wireless/trace.h |  68 +
 10 files changed, 1581 insertions(+), 34 deletions(-)
 create mode 100644 net/wireless/pmsr.c

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 1fa41b7a1be3..69b34b8e22ea 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -2848,6 +2848,191 @@ struct cfg80211_ftm_responder_stats {
u32 out_of_window_triggers_num;
 };
 
+/**
+ * struct cfg80211_pmsr_ftm_result - FTM result
+ * @failure_reason: if this measurement failed (PMSR status is
+ * %NL80211_PMSR_STATUS_FAILURE), this gives a more precise
+ * reason than just "failure"
+ * @burst_index: if reporting partial results, this is the index
+ * in [0 .. num_bursts-1] of the burst that's being reported
+ * @num_ftmr_attempts: number of FTM request frames transmitted
+ * @num_ftmr_successes: number of FTM request frames acked
+ * @busy_retry_time: if failure_reason is %NL80211_PMSR_FTM_FAILURE_PEER_BUSY,
+ * fill this to indicate in how many seconds a retry is deemed possible
+ * by the responder
+ * @num_bursts_exp: actual number of bursts exponent negotiated
+ * @burst_duration: actual burst duration negotiated
+ * @frames_per_burst: actual frames per burst negotiated
+ * @lci_len: length of LCI information (if present)
+ * @civicloc_len: length of civic location information (if present)
+ * @lci: LCI data (may be %NULL)
+ * @civicloc: civic location data (may be %NULL)
+ * @rssi_avg: average RSSI over FTM action frames reported
+ * @rssi_spread: spread of the RSSI over FTM action frames reported
+ * @tx_rate: bitrate for transmitted FTM action frame response
+ * @rx_rate: bitrate of received FTM action frame
+ * @rtt_avg: average of RTTs measured (must have either this or @dist_avg)
+ * @rtt_variance: variance of RTTs measured (note that standard deviation is
+ * the square root of the variance)
+ * @rtt_spread: spread of the RTTs measured
+ * @dist_avg: average of distances (mm) measured
+ * (must have either this or @rtt_avg)
+ * @dist_variance: variance of distances measured (see also @rtt_variance)
+ * @dist_spread: spread of distances measured (see also @rtt_spread)
+ * @num_ftmr_attempts_valid: @num_ftmr_attempts is valid
+ * @num_ftmr_successes_valid: @num_ftmr_successes is valid
+ * @rssi_avg_valid: @rssi_avg is valid
+ * @rssi_spread_valid: @rssi_spread is valid
+ * @tx_rate_valid: @tx_rate is valid
+ * @rx_rate_valid: @rx_rate is valid
+ * @rtt_avg_valid: @rtt_avg is valid
+ * @rtt_variance_valid: @rtt_variance is valid
+ * @rtt_spread_valid: @rtt_spread is valid
+ * @dist_avg_valid: @dist_avg is valid
+ * @dist_variance_valid: @dist_variance is valid
+ * @dist_spread_valid: @dist_spread is valid
+ */
+struct cfg80211_pmsr_ftm_result {
+   const u8 *lci;
+   const u8 *civicloc;
+   unsigned int lci_len;
+   unsigned int civicloc_len;
+   enum nl80211_peer_measurement_ftm_failure_reasons failure_reason;
+   u32 num_ftmr_attempts, num_ftmr_successes;
+   s16 burst_index;
+   u8 busy_retry_time;
+   u8 num_bursts_exp;
+   u8 burst_duration;
+   u8 frames_per_burst;
+   s32 rssi_avg;
+   s32 rssi_spread;
+   struct rate_i