All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] wcn36xx: Add RX frame SNR as a source of system entropy
@ 2022-09-13 17:42 Bryan O'Donoghue
  2022-09-14 12:53 ` Loic Poulain
  0 siblings, 1 reply; 3+ messages in thread
From: Bryan O'Donoghue @ 2022-09-13 17:42 UTC (permalink / raw)
  To: loic.poulain, kvalo, davem, edumazet, kuba, pabeni
  Cc: wcn36xx, linux-wireless, netdev, bryan.odonoghue, Jason A . Donenfeld

The signal-to-noise-ratio of a received frame is a representation of noise
in a given received frame.

RSSI - received signal strength indication can appear pretty static
frame-to-frame but noise will "bounce around" more depending on the EM
environment, temperature or placement of obstacles between the transmitter
and receiver.

Other WiFi drivers offer up the noise component of the FFT as an entropy
source for the random pool i.e.

Commit: 2aa56cca3571 ("ath9k: Mix the received FFT bins to the random pool")

I attended Jason's talk on sources of randomness at Plumbers and it occured
to me that SNR is a reasonable candidate to add.

Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 drivers/net/wireless/ath/wcn36xx/txrx.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/wireless/ath/wcn36xx/txrx.c b/drivers/net/wireless/ath/wcn36xx/txrx.c
index 8da3955995b6e..f3b77d7ffebe4 100644
--- a/drivers/net/wireless/ath/wcn36xx/txrx.c
+++ b/drivers/net/wireless/ath/wcn36xx/txrx.c
@@ -16,6 +16,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/random.h>
 #include "txrx.h"
 
 static inline int get_rssi0(struct wcn36xx_rx_bd *bd)
@@ -297,6 +298,8 @@ static void wcn36xx_update_survey(struct wcn36xx *wcn, int rssi, int snr,
 	wcn->chan_survey[idx].rssi = rssi;
 	wcn->chan_survey[idx].snr = snr;
 	spin_unlock(&wcn->survey_lock);
+
+	add_device_randomness(&snr, sizeof(int));
 }
 
 int wcn36xx_rx_skb(struct wcn36xx *wcn, struct sk_buff *skb)
-- 
2.37.3


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

* Re: [PATCH] wcn36xx: Add RX frame SNR as a source of system entropy
  2022-09-13 17:42 [PATCH] wcn36xx: Add RX frame SNR as a source of system entropy Bryan O'Donoghue
@ 2022-09-14 12:53 ` Loic Poulain
  2022-09-14 20:38   ` Bryan O'Donoghue
  0 siblings, 1 reply; 3+ messages in thread
From: Loic Poulain @ 2022-09-14 12:53 UTC (permalink / raw)
  To: Bryan O'Donoghue
  Cc: kvalo, davem, edumazet, kuba, pabeni, wcn36xx, linux-wireless,
	netdev, Jason A . Donenfeld

Hi Bryan,

On Tue, 13 Sept 2022 at 19:42, Bryan O'Donoghue
<bryan.odonoghue@linaro.org> wrote:
>
> The signal-to-noise-ratio of a received frame is a representation of noise
> in a given received frame.
>
> RSSI - received signal strength indication can appear pretty static
> frame-to-frame but noise will "bounce around" more depending on the EM
> environment, temperature or placement of obstacles between the transmitter
> and receiver.
>
> Other WiFi drivers offer up the noise component of the FFT as an entropy
> source for the random pool i.e.
>
> Commit: 2aa56cca3571 ("ath9k: Mix the received FFT bins to the random pool")
>
> I attended Jason's talk on sources of randomness at Plumbers and it occured
> to me that SNR is a reasonable candidate to add.
>
> Cc: Jason A. Donenfeld <Jason@zx2c4.com>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>  drivers/net/wireless/ath/wcn36xx/txrx.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/drivers/net/wireless/ath/wcn36xx/txrx.c b/drivers/net/wireless/ath/wcn36xx/txrx.c
> index 8da3955995b6e..f3b77d7ffebe4 100644
> --- a/drivers/net/wireless/ath/wcn36xx/txrx.c
> +++ b/drivers/net/wireless/ath/wcn36xx/txrx.c
> @@ -16,6 +16,7 @@
>
>  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>
> +#include <linux/random.h>
>  #include "txrx.h"
>
>  static inline int get_rssi0(struct wcn36xx_rx_bd *bd)
> @@ -297,6 +298,8 @@ static void wcn36xx_update_survey(struct wcn36xx *wcn, int rssi, int snr,
>         wcn->chan_survey[idx].rssi = rssi;
>         wcn->chan_survey[idx].snr = snr;
>         spin_unlock(&wcn->survey_lock);
> +
> +       add_device_randomness(&snr, sizeof(int));

We store the SNR in an integer, but isn't it reported as u8 (or s8) by
the firmware? So maybe we should just inject the LSByte since the upper
ones will always be 0?



>  }
>
>  int wcn36xx_rx_skb(struct wcn36xx *wcn, struct sk_buff *skb)
> --
> 2.37.3
>

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

* Re: [PATCH] wcn36xx: Add RX frame SNR as a source of system entropy
  2022-09-14 12:53 ` Loic Poulain
@ 2022-09-14 20:38   ` Bryan O'Donoghue
  0 siblings, 0 replies; 3+ messages in thread
From: Bryan O'Donoghue @ 2022-09-14 20:38 UTC (permalink / raw)
  To: Loic Poulain
  Cc: kvalo, davem, edumazet, kuba, pabeni, wcn36xx, linux-wireless,
	netdev, Jason A . Donenfeld

On 14/09/2022 13:53, Loic Poulain wrote:
> Hi Bryan,
> 
> On Tue, 13 Sept 2022 at 19:42, Bryan O'Donoghue
> <bryan.odonoghue@linaro.org> wrote:
>>
>> The signal-to-noise-ratio of a received frame is a representation of noise
>> in a given received frame.
>>
>> RSSI - received signal strength indication can appear pretty static
>> frame-to-frame but noise will "bounce around" more depending on the EM
>> environment, temperature or placement of obstacles between the transmitter
>> and receiver.
>>
>> Other WiFi drivers offer up the noise component of the FFT as an entropy
>> source for the random pool i.e.
>>
>> Commit: 2aa56cca3571 ("ath9k: Mix the received FFT bins to the random pool")
>>
>> I attended Jason's talk on sources of randomness at Plumbers and it occured
>> to me that SNR is a reasonable candidate to add.
>>
>> Cc: Jason A. Donenfeld <Jason@zx2c4.com>
>> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
>> ---
>>   drivers/net/wireless/ath/wcn36xx/txrx.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/net/wireless/ath/wcn36xx/txrx.c b/drivers/net/wireless/ath/wcn36xx/txrx.c
>> index 8da3955995b6e..f3b77d7ffebe4 100644
>> --- a/drivers/net/wireless/ath/wcn36xx/txrx.c
>> +++ b/drivers/net/wireless/ath/wcn36xx/txrx.c
>> @@ -16,6 +16,7 @@
>>
>>   #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
>>
>> +#include <linux/random.h>
>>   #include "txrx.h"
>>
>>   static inline int get_rssi0(struct wcn36xx_rx_bd *bd)
>> @@ -297,6 +298,8 @@ static void wcn36xx_update_survey(struct wcn36xx *wcn, int rssi, int snr,
>>          wcn->chan_survey[idx].rssi = rssi;
>>          wcn->chan_survey[idx].snr = snr;
>>          spin_unlock(&wcn->survey_lock);
>> +
>> +       add_device_randomness(&snr, sizeof(int));
> 
> We store the SNR in an integer, but isn't it reported as u8 (or s8) by
> the firmware? So maybe we should just inject the LSByte since the upper
> ones will always be 0?

sizeof(s8) makes sense to me, also I can massage the commit text a bit, 
it doesn't scan well on a second reading

---
bod


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

end of thread, other threads:[~2022-09-14 20:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-13 17:42 [PATCH] wcn36xx: Add RX frame SNR as a source of system entropy Bryan O'Donoghue
2022-09-14 12:53 ` Loic Poulain
2022-09-14 20:38   ` Bryan O'Donoghue

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.