systemd: how to selectively disable wpa_supplicant for a specific WLAN interface?

20,257

Solution 1

Use the "nohook wpa_supplicant" option in /etc/dhcpcd.conf. If you don't want wpa_supplicant for wlan0 this would be:

interface wlan0
        nohook wpa_supplicant

Solution 2

I had the same problem. @Nproject found a nice solution. But you don't have to modify each of this procedures. Simply go to the end of the file Nproject mentioned (/lib/dhcpcd/dhcpcd-hooks/10-wpa_supplicant) and modify the following if clause:

ORIGINAL

if [ "$ifwireless" = "1" ] && \
    type wpa_supplicant >/dev/null 2>&1 && \
    type wpa_cli >/dev/null 2>&1
then
        case "$reason" in
        PREINIT)        wpa_supplicant_start;;
        RECONFIGURE)    wpa_supplicant_reconfigure;;
        DEPARTED)       wpa_supplicant_stop;;
        esac
fi

Add [ "$interface" != "TheInterfaceWPASupplicantShouldBeDisabledOn" ] in this way:

MODIFIED

if [ "$ifwireless" = "1" ] && [ "$interface" != "TheInterfaceWPASupplicantShouldBeDisabledOn" ]  && \
    type wpa_supplicant >/dev/null 2>&1 && \
    type wpa_cli >/dev/null 2>&1
then
        case "$reason" in
        PREINIT)        wpa_supplicant_start;;
        RECONFIGURE)    wpa_supplicant_reconfigure;;
        DEPARTED)       wpa_supplicant_stop;;
        esac
fi

Additionally this will prevent the Network Manager (GUI) in your taskbar to show up this interface.

Solution 3

[EDIT: Look at @rweisse answer for a better way to do it]

I had the exact same problem on my raspberry pi.

What i found is that both wpa_supplicant@wlan0 and wpa_supplicant@wlan1 (I have two wlan interfaces) and wpa_supplicant.service were disabled.

I managed to find (On raspbian at least, i don't know how it is on other debian releases) that dhcpcd is responsible for wpa_supplicant start.

Under /lib/dhcpcd/dhcpcd-hooks, there is a file named "10-wpa-supplicant", in which you can find start/reconfigure/stop procedures for wpa_supplicant.

In this file i simply added condition on the $interface being processed. For each PROCEDURE_NAME (start/stop/reconfigure):

PROCEDURE_NAME( )
    if [ "$interface" != "TheInterfaceWPASupplicantShouldBeDisabledOn" ] then
        Code of the prodecure
    else
        return 0
    fi

After that, i restarted the dhcpcd service with

systemctl restart dhcpcd

Now the InterfaceWPASupplicantShouldBeDisabledOn is no longer a problem using hostapd. This solution is kinda brutal, as i don't think this is supposed to be done like so, but i was not able to find any manual on how to do this another way.

Hope this helps.

Share:
20,257

Related videos on Youtube

TheDiveO
Author by

TheDiveO

Lorem ipsum superbus esse semper latinum labere.

Updated on September 18, 2022

Comments

  • TheDiveO
    TheDiveO almost 2 years

    On a Linux system with systemd and networkd I need to operate a WLAN access point on one WLAN interface, while operating further (hotplug) WLAN interfaces in normal station ("client") mode.

    As it turns out, wpa_supplicant.service goes live on all my WLAN interfaces, which would be fine, if only all these WLAN interfaces would operate in station/client mode. However, while wpa_supplicant.service serves a WLAN interface, it's not possible (anymore?) that hostapd.service operates that WLAN interface in AP access point mode.

    So I want to disable wpa_supplicant.service for a specific interface only, say wls35u2. My idea was to have a [email protected] unit that I can selectively disable, but to leave wpa_supplicant.service enabled. However, this does not seem to work or I'm doing something wrong in the [email protected].

    So, how can I disable the WPA supplicant service on a specific interface only without globally disabling it?