Bug 277356 - iwlwifi(4): unable to associate to AP if set `ether random` (LinuxKPI 802.11 compat code problem?)
Summary: iwlwifi(4): unable to associate to AP if set `ether random` (LinuxKPI 802.11 ...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: wireless (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Bjoern A. Zeeb
URL:
Keywords:
Depends on:
Blocks: 802.11, LinuxKPI
  Show dependency treegraph
 
Reported: 2024-02-27 14:45 UTC by Li-Wen Hsu
Modified: 2024-09-30 13:22 UTC (History)
2 users (show)

See Also:
bz: mfc-stable13?


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Li-Wen Hsu freebsd_committer freebsd_triage 2024-02-27 14:45:48 UTC
I'm using following script to setup wifi:

```
ifconfig wlan create wlandev iwlwifi0
ifconfig wlan0 ether random
ifconfig wlan0 country TW
ifconfig wlan0 up

/usr/sbin/wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -Bs -Dbsd -ddd

/sbin/dhclient wlan0
```

It works with iwm(4) but cannot associate to AP with wilwifi(4).  After more tests, it seems that if I comment out the `ether random` line then the associating is fine.

I'll try to provide more information, but file a ticket as a placeholder.
Comment 1 Cheng Cui freebsd_committer freebsd_triage 2024-02-27 14:48:14 UTC
Thanks for reporting this.
Comment 2 Bjoern A. Zeeb freebsd_committer freebsd_triage 2024-02-27 20:28:49 UTC
(In reply to Li-Wen Hsu from comment #0)

I didn't even know we had that feature in ifconfig.

Given the order you are running this I wouldn't know why it shouldn't work.
Do you get any logging from iwlwifi?
Given you do start wpa_supplicant with lots of debugging, what does it think?  Any specific errors there?

Alternatively before you do the ifconfig wlan0 up/start wpa_supplicant, can you in a 2nd terminal start

ifconfig -v wlan0  > /var/tmp/iwlwifi.txt
tcpdump -ln -s0 -e -vvv -i wlan0 -y IEEE802_11_RADIO -w /var/tmp/iwlwifi.pcap

and send bz/cc the two files so we can have a peak.   Or maybe you already see something yourself if you open it in wireshark.
Comment 3 Bjoern A. Zeeb freebsd_committer freebsd_triage 2024-06-14 20:10:50 UTC
(In reply to Li-Wen Hsu from comment #0)

Hi Li-Wen,

has the behavior changed recently?   Can you try any of main or the stable branches after the commits today?
Comment 4 Bjoern A. Zeeb freebsd_committer freebsd_triage 2024-06-14 20:17:09 UTC
And as a note to myself:

We do
        memcpy(vif->addr, mac, IEEE80211_ADDR_LEN);
in vap_create() but we likely do not synch it again afterwards.  So that could be the problem.

We likely should re-synch all that state (or what is needed) when coming out of INIT before going into SCAN (as scan also may depend on that addr).

We should also go and see if we can implement the equivalent of NL80211_SCAN_FLAG_RANDOM_ADDR which most LinuxKPI based drivers would honor.
Comment 5 Bjoern A. Zeeb freebsd_committer freebsd_triage 2024-06-18 15:25:18 UTC
I looked into this last night -- more by accident due to another net80211 bug report in my inbox.

(1) ieee80211_ioctl()
 ->  SIOCSIFFLAGS
   -> we update iv_myaddr;  we need to make this an accessor function which we can also hook into for LinuxKPI or do a similar check when going through the state...

```
                        NET_EPOCH_ENTER(et);
                        if (ifp->if_ioctl == ieee80211_ioctl &&
                            (ifp->if_flags & IFF_UP) == 0 &&
                            !IEEE80211_ADDR_EQ(vap->iv_myaddr, IF_LLADDR(ifp)))
                                IEEE80211_ADDR_COPY(vap->iv_myaddr,
                                    IF_LLADDR(ifp));
                        NET_EPOCH_EXIT(et);
```

(2) Interestingly we have such a function:  wlan_iflladdr() which is triggered by
                wlan_ifllevent = EVENTHANDLER_REGISTER(iflladdr_event,
                    wlan_iflladdr, NULL, EVENTHANDLER_PRI_ANY);
    Makes me wonder if wlan_iflladdr() is missing an epoch ...  *sigH*


(3) + (4) In addition ieee80211_vap_setup() and ieee80211_vap_attach() both also copy the address (the former from the ic, the latter from the ifp), which seems odd as we normally call both from "driver"_vap_create().  Both of them should run before the interface can come UP, so those are one-time-static.

Leaves us with (1) and (2) which should probably become some generic net80211 function filled by OS-dependent code and then we can have 1 place to catch but given we can hook into the eventhandler too .. we can probably save us the effort.
Comment 6 Bjoern A. Zeeb freebsd_committer freebsd_triage 2024-07-25 08:10:04 UTC
I posted a review here:
https://reviews.freebsd.org/D46121

Can you try this?
Comment 7 Li-Wen Hsu freebsd_committer freebsd_triage 2024-07-25 18:31:12 UTC
(In reply to Bjoern A. Zeeb from comment #6)
I've tested this with my AX210/AX1675* and confirm it works. Thanks!
Comment 8 commit-hook freebsd_committer freebsd_triage 2024-07-25 18:44:12 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=4aff4048f5b1b6ab0b905726853ba6083e37cc37

commit 4aff4048f5b1b6ab0b905726853ba6083e37cc37
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-07-25 07:53:32 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-07-25 18:42:26 +0000

    LinuxKPI: 802.11: support manual lladdr changes

    Allow a user to change the "ether" address by ifconfig while a VAP is
    not UP.  Compared to net80211 (given we have no callback) we register
    an eventhandler per-vif (a global one would force us to use hacks to
    derive if a vap is indeed also a lkpi_80211 vif).

    Sponsored by:   The FreeBSD Foundation
    PR:             277356
    Tested by:      lwhsu
    MFC after:      3 days
    Differential Revision: https://reviews.freebsd.org/D46121

 sys/compat/linuxkpi/common/src/linux_80211.c | 30 ++++++++++++++++++++++++++++
 sys/compat/linuxkpi/common/src/linux_80211.h |  1 +
 2 files changed, 31 insertions(+)
Comment 9 commit-hook freebsd_committer freebsd_triage 2024-09-28 10:39:27 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=314069ff8c35ff4f2824746b6301da7fe5b48f4e

commit 314069ff8c35ff4f2824746b6301da7fe5b48f4e
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-07-25 07:53:32 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-09-28 10:35:13 +0000

    LinuxKPI: 802.11: support manual lladdr changes

    Allow a user to change the "ether" address by ifconfig while a VAP is
    not UP.  Compared to net80211 (given we have no callback) we register
    an eventhandler per-vif (a global one would force us to use hacks to
    derive if a vap is indeed also a lkpi_80211 vif).

    Sponsored by:   The FreeBSD Foundation
    PR:             277356
    Tested by:      lwhsu
    Differential Revision: https://reviews.freebsd.org/D46121

    (cherry picked from commit 4aff4048f5b1b6ab0b905726853ba6083e37cc37)

 sys/compat/linuxkpi/common/src/linux_80211.c | 30 ++++++++++++++++++++++++++++
 sys/compat/linuxkpi/common/src/linux_80211.h |  1 +
 2 files changed, 31 insertions(+)
Comment 10 commit-hook freebsd_committer freebsd_triage 2024-09-30 13:21:03 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=335a234d72be2a042e60ddd93a2644ffdc27e515

commit 335a234d72be2a042e60ddd93a2644ffdc27e515
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2024-07-25 07:53:32 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2024-09-30 12:19:05 +0000

    LinuxKPI: 802.11: support manual lladdr changes

    Allow a user to change the "ether" address by ifconfig while a VAP is
    not UP.  Compared to net80211 (given we have no callback) we register
    an eventhandler per-vif (a global one would force us to use hacks to
    derive if a vap is indeed also a lkpi_80211 vif).

    Sponsored by:   The FreeBSD Foundation
    PR:             277356
    Tested by:      lwhsu
    Differential Revision: https://reviews.freebsd.org/D46121

    (cherry picked from commit 4aff4048f5b1b6ab0b905726853ba6083e37cc37)

 sys/compat/linuxkpi/common/src/linux_80211.c | 30 ++++++++++++++++++++++++++++
 sys/compat/linuxkpi/common/src/linux_80211.h |  1 +
 2 files changed, 31 insertions(+)