Skip to content

Commit 927637e

Browse files
lukas-mbagSuperQ
andauthored
feat: add signal strength attributes to BSS struct (#136)
* feat: add signal strength attributes to BSS struct and update tests * Update wifi.go Co-authored-by: Ben Kochie <[email protected]> * fix: update signal strength parsing to use correct types --------- Co-authored-by: Ben Kochie <[email protected]>
1 parent 4f77dae commit 927637e

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

client_linux.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,12 @@ func (b *BSS) parseAttributes(attrs []netlink.Attribute) error {
636636
// NOTE: BSSStatus copies the ordering of nl80211's BSS status
637637
// constants. This may not be the case on other operating systems.
638638
b.Status = BSSStatus(nlenc.Uint32(a.Data))
639+
case unix.NL80211_BSS_SIGNAL_MBM:
640+
// * @NL80211_BSS_SIGNAL_MBM: signal strength in mBm (100*dBm)
641+
b.Signal = nlenc.Int32(a.Data)
642+
case unix.NL80211_BSS_SIGNAL_UNSPEC:
643+
// * @NL80211_BSS_SIGNAL_UNSPEC: signal strength in unspecified units (usually percent)
644+
b.SignalUnspecified = nlenc.Uint32(a.Data)
639645
case unix.NL80211_BSS_INFORMATION_ELEMENTS:
640646
ies, err := parseIEs(a.Data)
641647
if err != nil {

client_linux_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,14 @@ func TestLinux_clientBSSOKSkipMissingStatus(t *testing.T) {
181181

182182
func TestLinux_clientBSSOK(t *testing.T) {
183183
want := &BSS{
184-
SSID: "Hello, 世界",
185-
BSSID: net.HardwareAddr{0x00, 0x11, 0x22, 0x33, 0x44, 0x55},
186-
Frequency: 2492,
187-
BeaconInterval: 100 * 1024 * time.Microsecond,
188-
LastSeen: 10 * time.Second,
189-
Status: BSSStatusAssociated,
184+
SSID: "Hello, 世界",
185+
BSSID: net.HardwareAddr{0x00, 0x11, 0x22, 0x33, 0x44, 0x55},
186+
Frequency: 2492,
187+
BeaconInterval: 100 * 1024 * time.Microsecond,
188+
LastSeen: 10 * time.Second,
189+
Status: BSSStatusAssociated,
190+
Signal: -5700,
191+
SignalUnspecified: 80,
190192
}
191193

192194
ifi := &Interface{
@@ -471,6 +473,8 @@ func (b *BSS) attributes() []netlink.Attribute {
471473
{Type: unix.NL80211_BSS_BEACON_INTERVAL, Data: nlenc.Uint16Bytes(uint16(b.BeaconInterval / 1024 / time.Microsecond))},
472474
{Type: unix.NL80211_BSS_SEEN_MS_AGO, Data: nlenc.Uint32Bytes(uint32(b.LastSeen / time.Millisecond))},
473475
{Type: unix.NL80211_BSS_STATUS, Data: nlenc.Uint32Bytes(uint32(b.Status))},
476+
{Type: unix.NL80211_BSS_SIGNAL_MBM, Data: nlenc.Int32Bytes(int32(b.Signal))},
477+
{Type: unix.NL80211_BSS_SIGNAL_UNSPEC, Data: nlenc.Uint32Bytes(uint32(b.SignalUnspecified))},
474478
{
475479
Type: unix.NL80211_BSS_INFORMATION_ELEMENTS,
476480
Data: marshalIEs([]ie{{

wifi.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,12 @@ type BSS struct {
247247
// Status: The status of the client within the BSS.
248248
Status BSSStatus
249249

250+
// Signal: The signal strength of the BSS, in mBm (divide by 100 to get dBm).
251+
Signal int32
252+
253+
// SignalUnspecified: The signal strength of the BSS, in percent.
254+
SignalUnspecified uint32
255+
250256
// Load: The load element of the BSS (contains StationCount, ChannelUtilization and AvailableAdmissionCapacity).
251257
Load BSSLoad
252258

0 commit comments

Comments
 (0)