1

I'm working with a raspberry pi zero w with a stripped down distro - NARD, and I would like to use two virtual wireless interfaces, one running in AP mode (service network) and the other connecting to a wireless network.

The chip supports this, but ONLY if they are on the same channel. I've been pulling my hair out over this for the last couple of months, because it was only connecting to SOME (read - those on channel 6) networks due to this...

My question would be if wpa_supplicant is capable of setting the channel of the ap0 interface based on which channel the wlan0 interface wishes to connect to? Simply removing the frequency stanza from the configuration of the ap0 interface makes it choose one automatically, but does not sync to the one used by the wlan0 interface.

My current setup looks like this:

/usr/sbin/wpa_supplicant -i ap0 -c /etc/wpa_supplicant_ap0.conf -D nl80211 -N -i wlan0 -c /etc/wpa_supplicant.conf -D nl80211 -P /var/run/wpa_supplicant.pid -B -s

/etc/wpa_supplicant_ap0.conf

ctrl_interface=/var/run/wpa_supplicant

# Scan for accesspoints regularly
ap_scan=1
autoscan=periodic:120
ignore_old_scan_res=1
bgscan="simple:60:-45:240"

# Enable Protected Management Frames
pmf=1

network={
    ssid="<snip>-setup"
    mode=2
    key_mgmt=WPA-PSK
    psk="<snip>"
    frequency=2437
}

/etc/wpa_supplicant.conf

ctrl_interface=/var/run/wpa_supplicant
update_config=1
pmf=1
ignore_old_scan_res=1
bgscan="simple:60:-45:240"
autoscan=periodic:120

network={
    ssid="<snip>"
    psk="<snip>"
    priority=10
    ap_max_inactivity=60
}

network={
    ssid="<snip>"
    psk="<snip>"
    priority=20
    ap_max_inactivity=60
}

2 Answers2

2

With setting up an Access point as WiFi router/repeater, optional with bridge I run into the same problem with the common channel of ap0 and wlan0 and could not get it to run with wpa_supplicant for the access point. So I decided to use hostapd. It is able to follow the channel for ap0 from wlan0 automagically. You may have a look at Step 2: install hostapd for the access point in the linked tutorial to get some ideas. Maybe there are also some useful hints in section ♦ Details.

Ingo
  • 42,961
  • 20
  • 87
  • 207
1

I think something like this should work. All this commands can be in an uniq bash shell script using sudo for execution :

#!/bin/bash    

# 1- Connect your client

cat << EOF > /etc/wpa_supplicant_ap0.conf
ctrl_interface=/var/run/wpa_supplicant
update_config=1
pmf=1
ignore_old_scan_res=1
bgscan="simple:60:-45:240"
autoscan=periodic:120

network={
    ssid="<snip>"
    psk="<snip>"
    priority=10
    ap_max_inactivity=60
}

network={
    ssid="<snip>"
    psk="<snip>"
    priority=20
    ap_max_inactivity=60
}
EOF

/usr/sbin/wpa_supplicant -D nl80211 -N -i wlan0 -c /etc/wpa_supplicant.conf -D nl80211 -P /var/run/wpa_supplicant.pid -B -s


# 2- Wait while your client is not connected ...

MAXTRY=5;
N=0; 
ERR=0;
while :
do
    if [ $N -eq $MAXTRY ];then
        ERR=1;
        break;
    fi;

    # Get association state
    STATUS=$(iwconfig wlan0| grep -o "<snip>")
    if [ ! -z "${STATUS}" ];then
        # associated
        break;
    else
        echo "[$(($N+1))/$MAXTRY] Client not connected on wlan0, next check in 1sec."
        ((N++));
        sleep 1;
    fi;
done;

if [ $ERR -eq 1 ];then
    echo "The client cannot connect to the AP after $MAXTRY tries, good bye !"
    exit 1;
fi;

# 3- Get the current channel

CHAN=$(iw wlan0 info |grep -o "([^ ]*"|tr -d '(')|head -n1) # CHAN contain the client current channel
echo "Client frequency channel found : $CHAN MHz"

# 4- Create AP conf. with current client channel.

cat << EOF > /etc/wpa_supplicant_ap0.conf
ctrl_interface=/var/run/wpa_supplicant

ap_scan=1
autoscan=periodic:120
ignore_old_scan_res=1
bgscan="simple:60:-45:240"
pmf=1
network={
    ssid="<snip>-setup"
    mode=2
    key_mgmt=WPA-PSK
    psk="<snip>"
    frequency=$CHAN
}
EOF

# 5- Start the WAP.

/usr/sbin/wpa_supplicant -D nl80211 -N -i ap0 -c /etc/wpa_supplicant_ap0.conf -D nl80211 -P /var/run/wpa_supplicant.pid -B -s

echo "Finish";
exit 0;


goldilocks
  • 60,325
  • 17
  • 117
  • 234
Ephemeral
  • 2,167
  • 1
  • 8
  • 19