0

Our goal was to create an AP mode on a Raspberry Pi easily, so we could connect to it from outside, connect to a webserver, send form details about the WiFi network, and then connect to that WiFi network. Another specification was that if the network goes away (so there is no more connection), this AP mode should start again. Also, we want to be able to maintain the Raspberry Pi in both AP mode and STA mode, so if the connection is unsuccessful we do not have to shut down the AP, only when we successfully connect to the WiFi.

For this use case, after setting up an ap0 virtual interface on the Pi in NetworkManager and configuring a connection for it, we just listen in a dispatcher event and conditionally turn the AP WiFi network on and off. It worked fine until I found an error when I manually modified the script at runtime (I know maybe I shouldn't do that but bear with me). The whole phy0 interface basically crashed, and it created phy1, removing my ap0 virtual interface. The funny thing is, rebooting did not solve this. I had a udev rule in place that was supposed to create the ap0 interface, but it could not, it just crashed.

After running iw dev, I found that a P2P-device connection called Unnamed/non-netdev interface, which I think was not there before, had been created. After further investigation, I found that the WiFi card cannot hold more than two interfaces at once, so it cannot hold both the P2P interface and ap0, so it crashes (at least that is my theory). I discovered that in the NetworkManager config and wpa_supplicant config you can turn off the P2P interface, so that should work, right?

After I wrote the config in both places, removed the udev rule, and tried again, it still failed. The only thing that solves this is reinstalling the whole NetworkManager, then it works again with my script, and the dispatcher also works.

I do not know what causes this, and I would like to know, so I can explain what the issue is and confidently say that it will not happen randomly at runtime, and maybe I can figure out a way on how to fix it without reinstalling the whole Network-manager.

I would like to add that: it's entirely possible that it's a completely different cause of error and I have no clue, the main part is that NetworkManager doesn't let me creating a new interface so something is definitely wrong.

So exactly what I tried: Modify the networkManager config so it includes this:

[device] wifi.p2p_disabled=1

Modify the wpa supplicant so it inlcudes this: p2p_disabled=1

After restarting the wpa supplicant it was gone, but after a little bit of time it got created again automatically. Maybe it's a different error so I also provide the dispatcher script here:

#!/bin/bash
# Lock file
LOCK_FILE="/tmp/ap_failover.lock"
AP_NAME="PiAP"
COOLDOWN=5
LOG_FILE="/var/log/pi_ap_failover.log"
log() {
    echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
}
exec 200>"$LOCK_FILE"
if ! flock -n 200; then
    log "$(date '+%Y-%m-%d %H:%M:%S') - [LOCK] Another instance already running, exiting." >> "$LOG_FILE"
    exit 0
fi
LAST_ACTION_FILE="/tmp/ap_failover_last_action"
if [[ -f "$LAST_ACTION_FILE" ]]; then
    LAST_ACTION=$(cat "$LAST_ACTION_FILE")
    NOW=$(date +%s)
    if (( NOW - LAST_ACTION < COOLDOWN )); then
        log "Cooldown active, skipping actions."
        exit 0
    fi
fi
date +%s > "$LAST_ACTION_FILE"
ACTIVE_CONN=$(
    nmcli -t -f NAME,DEVICE con show --active \
        | grep -v "$AP_NAME" \
        | grep -vE "^(lo|docker0|veth|br-|virbr)" \
        | cut -d: -f1
)
if [[ -n "$ACTIVE_CONN" ]]; then
    log "[INFO] Active connection detected ($ACTIVE_CONN)"
    if nmcli con show --active | grep -q "$AP_NAME"; then
        log "[ACTION] Disabling AP..."
        nmcli con down "$AP_NAME"
    else
        log "[INFO] AP not active, nothing to do."
    fi
else
    log "[INFO] No active network connections"
    if ! nmcli con show --active | grep -q "$AP_NAME"; then
        log "[ACTION] Enabling AP..."
        nmcli con up "$AP_NAME"
    else
        log "[INFO] AP already active"
    fi
fi

I hope someone can help thank you in advance :)

Update I hadnt posted what gets created so here it is the iw dev

 Unnamed/non-netdev interface
                wdev 0x5
                addr ba:27:eb:1d:fd:8c
                type P2P-device
                txpower 31.00 dBm
        Interface wlan0
                ifindex 3
                wdev 0x1
                addr b8:27:eb:1d:fd:8c
                ssid wifi-network-name
                type managed
                channel 36 (5180 MHz), width: 80 MHz, center1: 5210 MHz
                txpower 31.00 dBm

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.