From c75d9704a5d38f86c78d34e29c49a6f595d26809 Mon Sep 17 00:00:00 2001 From: Nicolas Peugnet Date: Fri, 23 Feb 2024 16:29:16 +0100 Subject: [PATCH] Add signal strength average to StationInfo struct And precise that Signal is the signal strength of the last received PPDU. --- client_linux.go | 2 ++ client_linux_test.go | 3 +++ wifi.go | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/client_linux.go b/client_linux.go index 805d091..96216c3 100644 --- a/client_linux.go +++ b/client_linux.go @@ -443,6 +443,8 @@ func (info *StationInfo) parseAttributes(attrs []netlink.Attribute) error { // * @NL80211_STA_INFO_SIGNAL: signal strength of last received PPDU (u8, dBm) // Should just be cast to int8, see code here: https://git.kernel.org/pub/scm/linux/kernel/git/jberg/iw.git/tree/station.c#n378 info.Signal = int(int8(a.Data[0])) + case unix.NL80211_STA_INFO_SIGNAL_AVG: + info.SignalAverage = int(int8(a.Data[0])) case unix.NL80211_STA_INFO_RX_PACKETS: info.ReceivedPackets = int(nlenc.Uint32(a.Data)) case unix.NL80211_STA_INFO_TX_PACKETS: diff --git a/client_linux_test.go b/client_linux_test.go index e23cb42..f5bec03 100644 --- a/client_linux_test.go +++ b/client_linux_test.go @@ -276,6 +276,7 @@ func TestLinux_clientStationInfoOK(t *testing.T) { ReceivedPackets: 10, TransmittedPackets: 20, Signal: -50, + SignalAverage: -53, TransmitRetries: 5, TransmitFailed: 2, BeaconLoss: 3, @@ -291,6 +292,7 @@ func TestLinux_clientStationInfoOK(t *testing.T) { ReceivedPackets: 20, TransmittedPackets: 40, Signal: -25, + SignalAverage: -27, TransmitRetries: 10, TransmitFailed: 4, BeaconLoss: 6, @@ -493,6 +495,7 @@ func (s *StationInfo) attributes() []netlink.Attribute { {Type: unix.NL80211_STA_INFO_TX_BYTES, Data: nlenc.Uint32Bytes(uint32(s.TransmittedBytes))}, {Type: unix.NL80211_STA_INFO_TX_BYTES64, Data: nlenc.Uint64Bytes(uint64(s.TransmittedBytes))}, {Type: unix.NL80211_STA_INFO_SIGNAL, Data: []byte{byte(int8(s.Signal))}}, + {Type: unix.NL80211_STA_INFO_SIGNAL_AVG, Data: []byte{byte(int8(s.SignalAverage))}}, {Type: unix.NL80211_STA_INFO_RX_PACKETS, Data: nlenc.Uint32Bytes(uint32(s.ReceivedPackets))}, {Type: unix.NL80211_STA_INFO_TX_PACKETS, Data: nlenc.Uint32Bytes(uint32(s.TransmittedPackets))}, {Type: unix.NL80211_STA_INFO_TX_RETRIES, Data: nlenc.Uint32Bytes(uint32(s.TransmitRetries))}, diff --git a/wifi.go b/wifi.go index ac1155f..56b1cd0 100644 --- a/wifi.go +++ b/wifi.go @@ -153,9 +153,12 @@ type StationInfo struct { // The current data transmit bitrate, in bits/second. TransmitBitrate int - // The signal strength of this station's connection, in dBm. + // The signal strength of the last received PPDU, in dBm. Signal int + // The average signal strength, in dBm. + SignalAverage int + // The number of times the station has had to retry while sending a packet. TransmitRetries int