wpa_supplicant.service configuration on TX1 (and TX2)

We are trying to get wpa_supplicant to run as a service by creating one at /etc/systemd/system/wpa_supplicant.service but it isn’t working so far. Can someone take a look at how we’ve got it configured and spot any error?

We are trying to avoid using network-manager and rc-local. This is on Ubuntu 16.04, kernel 28.2, and the example here is with TX1 although we’re also needing this for TX2.

What happens is that it does not work at boot time, but if I run it from the command line after, it connects. Here are the outputs from checking the service status:

nvidia@tegra-ubuntu:~$ sudo systemctl status wpa_supplicant.service
● wpa_supplicant.service - WPA supplicant
   Loaded: loaded (/etc/systemd/system/wpa_supplicant.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2019-05-26 14:30:00 EDT; 21s ago
  Process: 378 ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant.conf -i wlan0 -D nl80211 (code=exited, status=2$
 Main PID: 378 (code=exited, status=255)

May 26 14:29:59 tegra-ubuntu systemd[1]: Starting WPA supplicant...
May 26 14:30:00 tegra-ubuntu systemd[1]: wpa_supplicant.service: Main process exited, code=exited, status=255/n/a
May 26 14:30:00 tegra-ubuntu systemd[1]: Failed to start WPA supplicant.
May 26 14:30:00 tegra-ubuntu systemd[1]: wpa_supplicant.service: Unit entered failed state.
May 26 14:30:00 tegra-ubuntu systemd[1]: wpa_supplicant.service: Failed with result 'exit-code'.
nvidia@tegra-ubuntu:~$ sudo systemctl start wpa_supplicant.service
nvidia@tegra-ubuntu:~$ sudo systemctl status wpa_supplicant.service
● wpa_supplicant.service - WPA supplicant
   Loaded: loaded (/etc/systemd/system/wpa_supplicant.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-05-26 14:30:36 EDT; 34s ago
 Main PID: 1678 (wpa_supplicant)
      CPU: 115ms
   CGroup: /system.slice/wpa_supplicant.service
           └─1678 /sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant.conf -i wlan0 -D nl80211

May 26 14:30:36 tegra-ubuntu systemd[1]: Starting WPA supplicant...
May 26 14:30:36 tegra-ubuntu wpa_supplicant[1678]: Successfully initialized wpa_supplicant
May 26 14:30:36 tegra-ubuntu systemd[1]: Started WPA supplicant.
May 26 14:30:36 tegra-ubuntu wpa_supplicant[1678]: dbus: wpa_dbus_get_object_properties: failed to get object properties: (none) none
May 26 14:30:36 tegra-ubuntu wpa_supplicant[1678]: dbus: Failed to construct signal
May 26 14:30:36 tegra-ubuntu wpa_supplicant[1678]: Could not read interface p2p-dev-wlan0 flags: No such device
May 26 14:30:37 tegra-ubuntu wpa_supplicant[1678]: wlan0: Trying to associate with 0c:b6:d2:dc:16:64 (SSID='Spirinet' freq=2462 MHz)
May 26 14:30:38 tegra-ubuntu wpa_supplicant[1678]: wlan0: Associated with 0c:b6:d2:dc:16:64
May 26 14:30:38 tegra-ubuntu wpa_supplicant[1678]: wlan0: WPA: Key negotiation completed with 0c:b6:d2:dc:16:64 [PTK=CCMP GTK=TKIP]
May 26 14:30:38 tegra-ubuntu wpa_supplicant[1678]: wlan0: CTRL-EVENT-CONNECTED - Connection to 0c:b6:d2:dc:16:64 completed [id=0 id_str=]

FInally, here is the file at /etc/systemd/system/wpa_supplicant.service:

[Unit]
Description=WPA supplicant
Before=network.target
Wants=network.target

[Service]
Type=dbus
BusName=fi.epitest.hostap.WPASupplicant
ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant.conf -i wlan0 -D nl80211

[Install]
WantedBy=multi-user.target
Alias=dbus-fi.epitest.hostap.WPASupplicant.service

I have no way of testing, but one thought is that some prerequisite is missing (e.g., firmware missing because it isn’t loaded, and it isn’t loaded due to a missing startup action normally done by NM). If you look at “/etc/systemd/system/” you will find a number of examples of customization of systemd. Several of those have a “.wants”. The non-customized standard “.wants” can be found via:

find /lib/systemd/system -name '*.wants*'

Consider that if the wanted precondition prior to starting service wants something which is not itself a systemd service, then you might have to be creative. An interesting example is “local-fs.target.wants/systemd-remount-fs.service”, where it lists as a precondition the existence of “/etc/fstab”. You might be able to come up with something as simple as an indication that firmware was loaded by a file existing (that’s a contrived example for illustration…I don’t know if firmware loading is the issue, nor if some file existence could verify…though quite possibly a file in “/sys” could serve that purpose).

And of course if you have a way to manually get this up using command line without NM you’re way ahead because you can figure out what that command line requires (to be part of “wants”) when manually setting up on a system which has never had the particular hardware.

PS: I also am not a fan of NM, but it may still be the easiest starting point.

That was helpful to look at. I copied some of the lines in NetworkManager.service, and now my wpa_supplicant.service works, although it doesn’t work the first time during boot-up. I still see:

nvidia@tegra-ubuntu:~$ sudo systemctl status wpa_supplicant.service
● wpa_supplicant.service - WPA supplicant
   Loaded: loaded (/etc/systemd/system/wpa_supplicant.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2016-02-11 11:37:35 EST; 21s ago
 Main PID: 561 (wpa_supplicant)
      CPU: 215ms
   CGroup: /system.slice/wpa_supplicant.service
           └─561 /sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant.conf -i wlan0 -D nl80211

Feb 11 11:37:35 tegra-ubuntu systemd[1]: Started WPA supplicant.
Feb 11 11:37:35 tegra-ubuntu wpa_supplicant[561]: Successfully initialized wpa_supplicant
Feb 11 11:37:36 tegra-ubuntu wpa_supplicant[561]: dbus: wpa_dbus_get_object_properties: failed to get object properties: (none) none
Feb 11 11:37:36 tegra-ubuntu wpa_supplicant[561]: dbus: Failed to construct signal
Feb 11 11:37:36 tegra-ubuntu wpa_supplicant[561]: Could not read interface p2p-dev-wlan0 flags: No such device
Feb 11 11:37:36 tegra-ubuntu wpa_supplicant[561]: p2p-dev-wlan0: CTRL-EVENT-REGDOM-CHANGE init=CORE type=WORLD
Feb 11 11:37:38 tegra-ubuntu wpa_supplicant[561]: wlan0: Trying to associate with 0c:b6:d2:dc:16:64 (SSID='Spirinet' freq=2462 MHz)
Feb 11 11:37:38 tegra-ubuntu wpa_supplicant[561]: wlan0: Associated with 0c:b6:d2:dc:16:64
Feb 11 11:37:38 tegra-ubuntu wpa_supplicant[561]: wlan0: WPA: Key negotiation completed with 0c:b6:d2:dc:16:64 [PTK=CCMP GTK=TKIP]
Feb 11 11:37:38 tegra-ubuntu wpa_supplicant[561]: wlan0: CTRL-EVENT-CONNECTED - Connection to 0c:b6:d2:dc:16:64 completed [id=0 id_str=]

So it works, but if anyone has a guess as to how to make it succeed without error during boot-up, I’m all ears. For the record, the service file now looks like this:

[Unit]
Description=WPA supplicant
Wants=network.target
After=network-pre.target dbus.service
Before=network.target

[Service]
Type=dbus
BusName=fi.epitest.hostap.WPASupplicant
ExecStart=/sbin/wpa_supplicant -u -s -c /etc/wpa_supplicant.conf -i wlan0 -D nl80211
Restart=on-failure

[Install]
WantedBy=multi-user.target
Alias=dbus-fi.epitest.hostap.WPASupplicant.service

I don’t personally know the answer, but it seems network.target is not the only “Before”…it could be you need a second “wants”. I see mention of dbus (distributed messaging which requires permissions), which is often related to a login, but not always. Perhaps the command itself works when manually running because the user is logged in (which causes dbus permissions to activate). If this is the case I won’t be able to answer, but someone knowing more about dbus during boot and how it relates to firmware could possibly spot the culprit.