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
}
  • If you run the wpa_supplicant (client) and connect this to the AP you can get the current index, write the current index (frequency=XXX in /etc/wpa_supplicant_ap0.conf) and then start wpa_supplicant for your AP ? – Ephemeral Jan 6 at 18:31
  • (current index = current channel) sorry – Ephemeral Jan 6 at 20:28
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.

| improve this answer | |
  • I'll need to check this out. Seems promising! – Ákos Vandra Jan 9 at 22:17
  • I wound up writing a small script for extracting wpa_supplicant events and do the following logic there to avoid installing another application. Your answer seems to be the best option in less restricted environments. The fact that I couldn't test it is the only thing preventing me from making it as accepted – Ákos Vandra Jan 21 at 10:01
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;


| improve this answer | |
  • Problem is that I need the service network especially, if the normal network does not connect... In this case the service network would be used to set the ssid and psk for the normal network... – Ákos Vandra Jan 7 at 9:44
  • Anyways, I was hoping for a wpa_supplicant solution, I'll cook up some script I guess. – Ákos Vandra Jan 7 at 9:45
  • @ÁkosVandra, sorry I don't understand I need the service network especially – Ephemeral Jan 7 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.