Skip to content

Commit

Permalink
Add signal strength average to StationInfo struct
Browse files Browse the repository at this point in the history
And precise that Signal is the signal strength of the last received PPDU.
  • Loading branch information
n-peugnet committed Feb 23, 2024
1 parent 8e4abbc commit c75d970
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions client_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func TestLinux_clientStationInfoOK(t *testing.T) {
ReceivedPackets: 10,
TransmittedPackets: 20,
Signal: -50,
SignalAverage: -53,
TransmitRetries: 5,
TransmitFailed: 2,
BeaconLoss: 3,
Expand All @@ -291,6 +292,7 @@ func TestLinux_clientStationInfoOK(t *testing.T) {
ReceivedPackets: 20,
TransmittedPackets: 40,
Signal: -25,
SignalAverage: -27,
TransmitRetries: 10,
TransmitFailed: 4,
BeaconLoss: 6,
Expand Down Expand Up @@ -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))},
Expand Down
5 changes: 4 additions & 1 deletion wifi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c75d970

Please sign in to comment.