Post by @rqm

On #OpenBSD when connected to the WiFi mesh at home (eero) and move from room to room the connection gets dropped. My workaround is to do a card reset (ifconfing up / down / netstart) and let it reassociate but is there a "proper" solution this? (card is `bwfm`) Same SSID broadcasted by many BSSID's, both 2.4 and 5ghz.

Replying to @rqm
Stefan Sperling
@stsp @bsd.network

@rqm It looks like the device can send roaming events (BWFM_E_ROAM) but the driver ignores them and doesn't enable this feature.

Replying to @stsp@bsd.network

@stsp@bsd.network I had a glance at the drivers in Linux and BSD and this is way beyond me. I see you worked on roaming stuff in qw{z,x} recently; would it be possible to lift into bwfm whatever you implemented? Or is the behaviour / code just too different?

Replying to @rqm
Stefan Sperling
@stsp @bsd.network

@rqm it is entirely different because the broadcom devices run their own WiFi stack internally. The net80211 code is barely involved

Replying to @stsp@bsd.network
Stefan Sperling
@stsp @bsd.network
Public en edited

@rqm What you probably need to do is go into bwfm_rx_event_cb() and add cases for BWFM_E_ROAM_PREP and BWFM_E_ROAM (see bwfmreg.h for where these macros come from).

I guess these events are letting the driver know which AP / channel the device has switched to. Linux updates its wifi-stack data structures in bcrmfmac/cfg80211.c:brcmf_bss_roaming_done() by reading info from the E_ROAM device event data structure.

Another piece of the puzzle is making sure that such events get generated. Linux seems to be doing this in brcmf_dongle_roam() (in the same file) by setting the "bcn_timeout" device parameter to a magic value named something_ROAM_ON in their code. In bwfm we don't set this parameter yet, at least I cannot find it with a simple grep.

Not sure if this is the complete picture. If you can get to the point where you see an event fire in a printf, you're basically done with the hardest part already.

Replying to @stsp@bsd.network
Stefan Sperling
@stsp @bsd.network

@rqm There is also a "roam_off" parameter being set to "on" or "off" just a few lines below the "bcn_timeout" one.

Replying to @stsp@bsd.network
Stefan Sperling
@stsp @bsd.network
Public en edited

@rqm This device just takes commands as strings, like a shell. Can't be that hard?

Replying to @stsp@bsd.network

@stsp@bsd.network Looking at the code I am wondering whether adding BWFM_E_ROAMING to the _E_DEAUTH/E_DISASSOC fallthrough might be a simple hack? Let it start scanning?

Replying to @rqm
Stefan Sperling
@stsp @bsd.network

@rqm It would work as a proof of concept of processing the roaming event. Avoiding the scan loop is the end goal because that way the link stays up and connections don't die.

Replying to @stsp@bsd.network
Stefan Sperling
@stsp @bsd.network

@rqm In case it helps, here is a port of the function which enables roaming on Linux which you can drop into bwfm.c as a starting point: liam.stsp.name/files/bwfm_dong

Replying to @stsp@bsd.network

@stsp@bsd.network Thank you! Was just reading this actually. If you don't mind being a rubber ducky, this is what I think the code does and how it could be implemented:

  1. Card is told to set "roam_off" to "false" (because double negatives are so logical) to turn on roaming mode. on BSD this is done via bwfm_fwvar_set_data() and bwfm_fwvar_set_int().
  2. Then specify a roaming trigger and delta -- these are signal strength values, looking at the other files in the linux kernel, set somewhere around -75 i think (Linux sources have these); these values could be defined in bwfmreg.h I guess.

Linux seems to do this as part of the setup process. ¹ It looks to me like the place to call this on OpenBSD would be in bwfm_newstate() around bwfm.c:2944 just bwfore the switch()? (If not, there, where?)

Then,
3) Handle the roaming event; I think this can be handled either like BWFM_E_ASSOC or BWFM_E_AUTH. Linux checks for the _E_AUTH message and for _E_STATUS_SUCCESS, then
4) calls bwfm_dongle_roaming_done(). Through this the connection details are updated and reported. Not sure how this is done on the BSD side?

Is this vaguely correct in your eyes?

--
¹ https://github.com/torvalds/linux/blob/d0f871bfb831705d9f55479f5b2b40f636ea7b16/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c#L8028

Replying to @rqm
Stefan Sperling
@stsp @bsd.network
Public en edited

@rqm Yes, vaguely correct indeed. Enabling roaming should be done when the interface comes up (bwfm_init or something like that, called from bwfm_ioctl when the interface flags change such that UP gets set). The newstate handler is too late for this because it handles run-time state changes while the interface is up.

Roaming should only be enabled in client mode (ic->ic_opmode == IEEE80211_M_STA) but you don't really need to worry about such details during the first step.

Replying to @stsp@bsd.network

@stsp@bsd.network Here's where I got to. Kernel build fails tho because of something complaining in pipex.o. (I am fetching -current from cvs as I'm on -current).

https://git.sr.ht/~rqm/bwfm-hack/tree/main/item/bwfm.diff