Page MenuHomeFreeBSD

[WIP] net80211: use uint16_t for rssi
AcceptedPublic

Authored by bz on Jun 19 2025, 1:19 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Oct 8, 11:04 AM
Unknown Object (File)
Tue, Oct 7, 3:08 PM
Unknown Object (File)
Tue, Sep 30, 8:02 PM
Unknown Object (File)
Fri, Sep 26, 4:07 AM
Unknown Object (File)
Thu, Sep 25, 9:04 PM
Unknown Object (File)
Wed, Sep 17, 5:02 AM
Unknown Object (File)
Sep 13 2025, 8:04 PM
Unknown Object (File)
Sep 13 2025, 5:24 AM

Details

Reviewers
adrian
Summary

net80211 keeps the rssi value in 0.5bm relative to the noise floor
internally (see comment in ieee80211_node.h). While in many places
there was an 'int' as function argument to pass the internal rssi
value, in other places including structs we used int8_t.

The problem with int8_t is:
assume a noise floor "nf" of -127, assume a signal level of -21,
and then do the net80211 internal maths:

int8_t rssi8 = -21; => nf -127 rssi -21
rssi8 -= -127; => nf -127 rssi 106
rssi8 *= 2; => nf -127 rssi -44

Now doing the reverse (rssi / 2) + nf: (-44 / 2) + -127
will depending on how you print it give 107 or -149 and neither
is -21. The problem is that we have a double wrap-around.

Use int16_t instead for the entire storage which will do the
right thing avoiding any double-wrap-arounds:
nf -127 rssi -21
nf -127 rssi 106
nf -127 rssi 212, which results in S:N -21:-127
as 212 / 2 = 106 + -127 = -21.

I have separate patches for iwx(4) and linuxkpi_wlan(4) as those
triggered me looking into this while looking at scan results.
And for the first time ifconfig would give me meaningful values.

TODO: given this breaks the user space reporting need to resort
the struct layouts as well as they are no longer dword packed.
TODO: should we have an internal type defined for rssi05?

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Fixes: ??? (was not correct for user space in ages/ever?)

Test Plan

See when to finish the TODOs and get it in before 15.0.
Someone see if my maths are to simple and I got it wrong?

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 64970
Build 61853: arc lint + arc unit

Event Timeline

bz requested review of this revision.Jun 19 2025, 1:19 AM
emaste added inline comments.
sys/net80211/_ieee80211.h
428

Do we want to adjust this one now, rather than introducing a struct hole?

sys/net80211/_ieee80211.h
428

By "now" you mean re-sort or before 15?

I think it's ok to migrate it to int16_t. I'd migrate it to something like an net80211_rssi_t or something that we can handle opaquely, especially if we wanted to change its definition later.
(There's a lot of crazy places where it's just misused, as you've seen!)

This revision is now accepted and ready to land.Jul 31 2025, 5:08 AM
sys/net80211/_ieee80211.h
428

As part of this change I mean

sys/net80211/_ieee80211.h
428

I am still contemplating (a) if we can do this change without breakage or at least with outlook for the future; (b) allmost the other structs have gaps as well and a similar fate which I'd love to close if I get (a) sorted.