Simultaneous WiFi AP and WiFi client

Hi,

I have a problem with configuration of the BananaPi-M2-Zero in two modes at the same time:

  1. WiFi AP,
  2. regular WiFi client, that would connect to some WiFi router.

I am using latest armbian that supported my board and the newest iw tool (v5.19).

The system reports that the required combination is valid (see 2nd one):

$ iw list
[...] valid interface combinations:
             * #{ managed } <= 1, #{ P2P-device } <= 1, #{ P2P-client, P2P-GO } <= 1,
               total <= 3, #channels <= 2
             * #{ managed } <= 1, #{ AP } <= 1, #{ P2P-client } <= 1, #{ P2P-device } <= 1,
               total <= 4, #channels <= 1

I successfully created AP:

   $ iw dev
    phy#0
            Interface wlan0
                    ifindex 2
                    wdev 0x1
                    addr ac:6a:a3:0e:3b:9b
                    ssid LKD-BPI
                    type AP
                    channel 1 (2412 MHz), width: 20 MHz, center1: 2412 MHz
                    txpower 31.00 dBm

but when I add the second virtual interface I receive an error:

$ sudo iw dev wlan0 interface add wlan_sta type managed
    command failed: Operation not supported (-95)

What I am doing wrong? Does anybody succeded with such configuration?

Regards,

Piotr Romaniuk

You don’t set up wlan0 as you would normally, but you first do this:

# iw dev wlan0 interface add wlan0_sta type managed addr 12:34:56:78:ab:cd  
# iw dev wlan0 interface add wlan0_ap  type managed addr 12:34:56:78:ab:ce

Then setup wlan0_sta interface and wlan_ap. Leave wlan0 alone. Also the mac addresses need to be very near to each other, see example above.

See: Software access point - ArchWiki (archlinux.org)

But I think wlan0_ap needs type ap. Maybe a typo on the webpage?

Try this instead:

# iw dev wlan0 interface add wlan0_sta type managed addr 12:34:56:78:ab:cd  
# iw dev wlan0 interface add wlan0_ap  type ap      addr 12:34:56:78:ab:ce

Hi Eric,

The first option will not work because BPi-M2-0 allows for only one managed:

pi@bananapim2zero:~$ sudo iw dev wlan0 interface add wlan0_sta type managed addr xx:xx:xx:xx:xx:xy
command failed: Device or resource busy (-16)

As the second option I have automatically created managed interface:

pi@bananapim2zero:~$ sudo iw dev
phy#0
        Interface wlan0
                ifindex 2
                wdev 0x1
                addr xx:xx:xx:xx:xx:xx
                type managed
                channel 1 (2412 MHz), width: 20 MHz, center1: 2412 MHz

but when I try to add virtual interface of AP type:

pi@bananapim2zero:~$ sudo iw dev wlan0 interface add wlan0_ap type ap addr 12:34:56:78:ab:cd
You need to run a management daemon, e.g. hostapd,
see http://wireless.kernel.org/en/users/Documentation/hostapd
for more information on how to do that.

I would like to start from no interface case, but I cannot delete that interface created automatically:

pi@bananapim2zero:~$ sudo iw dev wlan0 del
command failed: Unknown error 524 (-524)
pi@bananapim2zero:~$ sudo iw wdev 1 del
command failed: Unknown error 524 (-524)
pi@bananapim2zero:~$ sudo iw dev wlan0 interface del
command failed: Unknown error 524 (-524)
pi@bananapim2zero:~$ sudo iw wdev 1 interface del
command failed: Unknown error 524 (-524)

What is wrong?

Regards,

Piotr Romaniuk

systemctl disable hostapd

Change hostapd.conf: interface=wlan0_ap

Reboot.

Then setup wlan0_ap, (try both types?) then start hostapd:

systemctl start hostapd
sudo iw dev

Should show you are using wlan0_ap

Unfortunatelly, does not work:

$ iw dev
phy#0
        Interface wlan0
                ifindex 2
                wdev 0x1
                addr xxxx
                type managed
                channel 1 (2412 MHz), width: 20 MHz, center1: 2412 MHz

$ sudo iw dev wlan0 interface add wlan_ap type managed addr xxxy
command failed: Device or resource busy (-16)

Above is explained in syslog:

kernel: [ 1253.623044] ieee80211 phy0: brcmf_cfg80211_add_iface: iface validation failed: err=-16

$ sudo iw dev wlan0 interface add wlan_ap type ap addr xxxx
You need to run a management daemon, e.g. hostapd,
see http://wireless.kernel.org/en/users/Documentation/hostapd
for more information on how to do that.

$ sudo systemctl status hostapd
    ��● hostapd.service - LSB: Advanced IEEE 802.11 management daemon
         Loaded: loaded (/etc/init.d/hostapd; generated)
         Active: active (exited) since Mon 2022-09-12 12:06:57 UTC; 4min 25s ago
           Docs: man:systemd-sysv-generator(8)
        Process: 1250 ExecStart=/etc/init.d/hostapd start (code=exited, status=0/SUCCESS)

    Sep 12 12:06:57 bananapim2zero systemd[1]: Starting LSB: Advanced IEEE 802.11 management daemon...
    Sep 12 12:06:57 bananapim2zero hostapd[1250]:  * Starting advanced IEEE 802.11 management hostapd
    Sep 12 12:06:57 bananapim2zero hostapd[1250]:    ...fail!
    Sep 12 12:06:57 bananapim2zero systemd[1]: Started LSB: Advanced IEEE 802.11 management daemon.

My hostapd.conf looks like this:

hw_mode=g
channel=1
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
country_code=PL
wpa=2
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP
ssid=xxxx
wpa_passphrase=xxxx

Do you know what creates that wlan0 interface. I would like to change its name there to wlan0_ap, expecting that hostapd would start then on the interface with that new name.

Regards,

Piotr Romaniuk

I’m not familiar with your setup/board.

If you setup your interfaces manually, you need to disable all other networking software:

systemctl disable NetworkManager
systemctl disable hostapd
or perhapse
systemctl disable systemd-networkd
or even
systemctl disable connman
And reboot

Or perhapse even remove the ifupdown package.

It all depends on what software is installed in the first place.

IIRC mainline driver does not have this functionality and you need to add it with a patch. I already looked around, but couldn’t find any useful reference. FYI

Is this functionality in cfg80211 driver?

Regards,

Piotr Romaniuk

Eric,

on what board you succeded with that two mode configuration? What kernel/distribution you used? I am looking for some reference in kernel drivers.

Regards, Piotr Romaniuk

I was fooling around with this on a BPI-R64 quite a while ago, on Ubuntu, kernel mainline v5. It has a lot more capabilities, but in principle it is the same.

If iw reports the capabilities, this info is coming from the driver, so it should support it.

It can however be a bit more complex as it seems. For instance, the mac address needs to almost exactly match. In your case even more complex. You can only use the same channel on wlan_ap as wlan_sta. You’ll need to configure wpa_supplicant to use only the same channel as hostapd is.

The same goes for setting up a second AP (if it is supported), for instance for guest wifi. The mac address also need to almost exactly match, except for the last digit. But iw does not tell you this limitation. I still use this kind of setup, not a sta + ap combination currently.

Thank you Eric,

I will try to dig into the driver of my board to see what is there implemented and how it is far from your working case.

Regards,

Piotr Romaniuk

Hi,

I receive the information from Banana Pi manufacturer: “BPI-M2 ZERO cannot support the AP and wifi client at the same time”

Regards,

Piotr Romaniuk

Just as on the rpi zero w, if it is not supported, it doesn’t mean that isn’t possible. See

AP-STA mode - RaspAP Documentation

Thank you Eric.

You keep my hope alive :slight_smile:

I will check it for sure.

Regards,

Piotr Romaniuk

I have made a script to automate this.

Feel free to use it here https://github.com/FramingApp/BananaPi-Wifi-Positron-Armbian

It needs a few mods that I can suply for internet passthrough. If you need that let me know.

Thank you Harry, nice reference.

Regards,

Piotr Romaniuk

Hi Harry,

unfortunatelly it is not working on Rpi-W-Zero-r1.1. I started from this board because I would like to repeat others results, and then I planned to move to BPI.

I had following configuration:

  1. Raspbian buster (the instructions were for Raspbian strech)
  2. firmware: 20190114-1+rpt8 (I am aware that downgrade was recommended in one post)

Just for reference:

  1. two wifi interfaces can be created,
  2. after all steps I end with two wifi interfaces as DOWN,
  3. it is possible to bring only one of them UP and start communication, but not both

Regards,

Piotr Romaniuk

That is because that is for armbian only. I will update the instructions to make this clear.

The original description (by Albert Chaharbakhshi) is for raspbian/stretch. I read your script and the original post, then I implemented what was there described. I am afraid that different version of the system or rather version of the firmware is the source of problem.

Regards,

Piotr Romaniuk

PS
I would like to check a version without udev rule, where phases are coded in systemd services. There was a note that order of operations is crucial.

Just an update of experiments:

  1. Rpi-0-w_r1.1 - ap+sta can be configured and connected by both interfaces; it is possible to ping them; after some download wlan0 connection breaks down and cannot be recovered,
  2. Rpi-0-w-2_r1.0 - as [1] but works stable download large files via both interfaces
  3. Bpi-M2-zero - cannot obtain two interfaces UP; manufacturer claims that the chip in AP6212 module is not supporting ap+sta

I observed that two factors are critical:

  1. version of the firmware (newer is not always better)
  2. and the order of starting services.

Regards,

Piotr Romaniuk

PS

I wonder if the fixed and common channel is not a source of the problems. For example, if the wifi router decides to switch to another channel (that is different than used by AP) STA cannot find the router and connect to it again. I probably need to learn more about 802.11 in details.