nakato / nixos-bpir3-example

MIT License
24 stars 5 forks source link

Cannot get wifi to work #5

Closed ghostbuster91 closed 1 year ago

ghostbuster91 commented 1 year ago

Hi,

Have you managed to get the wifi working?

I tried first with wpa_supplicant, but the iwconfig was showing:

> iwconfig                                                                                                            
lo        no wireless extensions.
eth0      no wireless extensions.
eth1     no wireless extensions.
wan       no wireless extensions.
lan0      no wireless extensions.
lan1      no wireless extensions.
lan2      no wireless extensions.
lan3      no wireless extensions.
lan4      no wireless extensions.
wlan0     no wireless extensions.
wlan1     no wireless extensions.
br0       no wireless extensions.

Here is a relevant section of my configuration for supplicant:

   wireless = {
      enable = true;
      userControlled.group = "network";
      interfaces = [ "wlan0" "wlan1" ];
      networks = {
        echelon = {
         # SSID with no spaces or special characters
         psk = "abcdefgh"; # (password will be written to /nix/store!)
        };

      };
     };

Then I learned that for bridging wlan interfaces with eth I will need to use hostapd anyway. I tried to get it running using following configuration:

 services.hostapd = {
   enable = true;
   interface = "wlan0"; # 2.4
   ssid="bpir3wifi";
   hwMode="g";
   driver="nl80211";
   group="network";
   countryCode="PL";
   logLevel=0;
 };

but it always fail with not very verbose error:

Jun 16 00:18:17 bpir3 systemd[1]: Started hostapd wireless AP.
Jun 16 00:18:17 bpir3 hostapd[7227]: 1 errors found in configuration file '/nix/store/9bhygzp6ma5sa63bh0fbk9npj0mph92n-hostapd.>
Jun 16 00:18:17 bpir3 hostapd[7227]: Failed to set up interface with /nix/store/9bhygzp6ma5sa63bh0fbk9npj0mph92n-hostapd.conf
Jun 16 00:18:17 bpir3 hostapd[7227]: Failed to initialize interface
Jun 16 00:18:17 bpir3 systemd[1]: hostapd.service: Main process exited, code=exited, status=1/FAILURE
Jun 16 00:18:17 bpir3 systemd[1]: hostapd.service: Failed with result 'exit-code'.
Jun 16 00:18:17 bpir3 systemd[1]: hostapd.service: Scheduled restart job, restart counter is at 5.
Jun 16 00:18:17 bpir3 systemd[1]: Stopped hostapd wireless AP.
Jun 16 00:18:17 bpir3 systemd[1]: hostapd.service: Start request repeated too quickly.
Jun 16 00:18:17 bpir3 systemd[1]: hostapd.service: Failed with result 'exit-code'.
Jun 16 00:18:17 bpir3 systemd[1]: Failed to start hostapd wireless AP.

The generated hostapd file looks as follows:

interface=wlan0
driver=nl80211
ssid=bpir3wifi
hw_mode=g
channel=7
ieee80211n=1
ieee80211ac=1
country_code=PL
ieee80211d=1

# logging (debug level)
logger_syslog=-1
logger_syslog_level=0
logger_stdout=-1
logger_stdout_level=0

ctrl_interface=/run/hostapd
ctrl_interface_group=network

wpa=2
wpa_pairwise=CCMP
wpa_passphrase=my_sekret

I also tried using different drivers - mt76 but it always claims that

: Line 2: invalid/unknown driver 'mt76'

lshw reports that the driver is: driver=mt7986-wmac but switching to it doesn't change anything

lsmod reports that module mt76 was loaded correctly:

❯ lsmod                                                                                                               00:32:34
Module                  Size  Used by
8021q                  28672  0
garp                   16384  1 8021q
mrp                    20480  1 8021q
crct10dif_ce           12288  1
xt_LOG                 12288  2
nf_log_syslog          16384  2
xt_tcpudp              12288  0
nft_compat             16384  2
sch_fq_codel           16384  17
nf_tables             225280  21 nft_compat
libcrc32c              12288  1 nf_tables
nfnetlink              20480  2 nft_compat,nf_tables
tun                    57344  0
tap                    28672  0
macvlan                28672  0
fuse                  135168  1
ip_tables              32768  0
x_tables               40960  4 nft_compat,xt_LOG,xt_tcpudp,ip_tables
mt7915e               155648  0
mt76_connac_lib        65536  1 mt7915e
mt76                   86016  2 mt7915e,mt76_connac_lib
mac80211              557056  3 mt76,mt7915e,mt76_connac_lib
libarc4                12288  1 mac80211
cfg80211              389120  4 mt76,mt7915e,mac80211,mt76_connac_lib

Last but not least I found this comment: https://github.com/nakato/nixos-bpir3-example/blob/main/bpir3-dts/mt7986a-bananapi-bpi-r3-wirless.dts#L11

So is there anything that we can do about it?

ghostbuster91 commented 1 year ago

btw @lorenz on bananaPi forum said that it had wifi working: https://forum.banana-pi.org/t/nixos-on-banana-pi-bpi-r3/15472/40?u=ghostbuster91

nakato commented 1 year ago

Have you managed to get the wifi working?

It does work.

iwconfig

You'll want to replace that with the iw command. iwconfig only supports the "WEXT" protocol, while iw supports the WEXT replacement, nl80211.

Details on WEXT abandonment

I didn't configure the kernel with CONFIG_CFG80211_WEXT, which is a compatibility shim, so that's why iwconfig doesn't provide any output whatsoever. Enable this option if you need old userspace for wireless extensions with cfg80211-based drivers.

Run iw phy to see details about the interfaces.

services.hostapd

I get the feeling nobody's using that in any serious use-case, the configuration of a 5GHz AP is much more complicated than it allows for, and the configuration it produces might violate local laws.

It also provides no method to set reduced power constraints on the interfaces, which would be necessary for a proper configuration.

The generated hostapd file looks as follows:

lib.generators.toKeyValue would be very useful for generating a config file in a key-value format such as that.

1 errors found in configuration file

ieee80211ac=1 is only supported in the 5GHz operation mode, so that's probably the cause of the error.

I also tried using different drivers

nl80211 is the correct driver for userspace to configure the mt76 devices.

mt7986a-bananapi-bpi-r3-wirless.dts#L11 So is there anything that we can do about it?

That comment is stating why that devicetree overlay exists and is required. Upstream doesn't want to include a blob of binary into the device tree

Ouch! This looks like firmware unrolled in a devicetree property - that can't be right. ref

The driver maintainers don't want to enable it to be loadable from a file for valid reasons either.

Most devices would embed this into the devices flash storage and load it from there, but it doesn't exist there.

ghostbuster91 commented 1 year ago

You'll want to replace that with the iw command. iwconfig only supports the "WEXT" protocol, while iw supports the WEXT replacement, nl80211.

Details on WEXT abandonment

Once again, thank you very much for including these additional details, it helps a lot!

ieee80211ac=1 is only supported in the 5GHz operation mode, so that's probably the cause of the error.

The problem was that this parameter was hardcoded in the hostapd config - https://github.com/NixOS/nixpkgs/blob/nixos-23.05/nixos/modules/services/networking/hostapd.nix#L24 so it wasne't easily changeable.

I get the feeling nobody's using that in any serious use-case, the configuration of a 5GHz AP is much more complicated than it allows for, and the configuration it produces might violate local laws.

I reached out to folks from nixos-networking matrix and they recommended me to checkout hostapd module from this PR: https://github.com/NixOS/nixpkgs/pull/222536

Using that PR solved all problems regarding wifi. Here is my current network configuration using networkd and hostapd if you would like to take a look: https://github.com/ghostbuster91/nixos-bpir3-example/blob/main/nixos/network.nix#L98

That comment is stating why that devicetree overlay exists and is required. Upstream doesn't want to include a blob of binary into the device tree

Ouch! This looks like firmware unrolled in a devicetree property - that can't be right. ref

The driver maintainers don't want to enable it to be loadable from a file for valid reasons either.

Most devices would embed this into the devices flash storage and load it from there, but it doesn't exist there.

Ok, now it all makes sense, thanks!