Can't use hostapd with resinOS 2.0

I am broadcasting a wifi network on my RPi3 that lets users connect and configure settings on the Pi.

I am running into a weird issue with hostapd on ResinOS 2.0. The hostapd wifi access point starts up without any problems and works for a couple of minutes, but then it just stops working – existing clients are disconnected and the wifi network is no longer available.

Interestingly, resin-wifi-connect doesn’t have this same problem. I ran through your code and the only real difference I can see is that you are turning off NetworkManager.service using dbus right here. Do you think this is the culprit? If so, how do I do that? And will that make my USB cellular modem stop working?

Here are the logs from hostapd’s debug mode at the moment when the wifi stops working:

hostapd debug log
nl80211: Drv Event 20 (NL80211_CMD_DEL_STATION) received for wlan0
nl80211: Delete station 2c:f0:a2:19:92:b3
wlan0: Event DISASSOC (1) received
wlan0: STA 2c:f0:a2:19:92:b3 IEEE 802.11: disassociated
wlan0: AP-STA-DISCONNECTED 2c:f0:a2:19:92:b3
wlan0: STA 2c:f0:a2:19:92:b3 WPA: event 2 notification
wpa_driver_nl80211_set_key: ifindex=3 (wlan0) alg=0 addr=0x55b1dcc8 key_idx=0 set_tx=1 seq_len=0 key_len=0
   addr=2c:f0:a2:19:92:b3
nl80211: set_key failed; err=-100 Network is down)
WPA: 2c:f0:a2:19:92:b3 WPA_PTK entering state DISCONNECTED
WPA: 2c:f0:a2:19:92:b3 WPA_PTK entering state INITIALIZE
wpa_driver_nl80211_set_key: ifindex=3 (wlan0) alg=0 addr=0x55b1dcc8 key_idx=0 set_tx=1 seq_len=0 key_len=0
   addr=2c:f0:a2:19:92:b3
nl80211: set_key failed; err=-100 Network is down)
nl80211: Set STA flags - ifname=wlan0 addr=2c:f0:a2:19:92:b3 total_flags=0x0 flags_or=0x0 flags_and=0xfffffffe authorized=0
wlan0: STA 2c:f0:a2:19:92:b3 IEEE 802.1X: unauthorizing port
Could not set station 2c:f0:a2:19:92:b3 flags for kernel driver (errno=11).
nl80211: sta_remove -> DEL_STATION wlan0 2c:f0:a2:19:92:b3 --> -100 (Network is down)
ap_free_sta: cancel ap_handle_timer for 2c:f0:a2:19:92:b3
RTM_NEWLINK: ifi_index=3 ifname=wlan0 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1002 ()
nl80211: Interface down
wlan0: Event INTERFACE_DISABLED (29) received
Unknown event 29
nl80211: Drv Event 20 (NL80211_CMD_DEL_STATION) received for wlan0
nl80211: Delete station 00:00:00:00:00:00
wlan0: Event DISASSOC (1) received
wlan0: STA 00:00:00:00:00:00 IEEE 802.11: disassociated
Disassociation notification for unknown STA 00:00:00:00:00:00
l2_packet_receive - recvfrom: Network is down
VLAN: vlan_newlink(wlan0)
nl80211: Drv Event 16 (NL80211_CMD_STOP_AP) received for wlan0
wlan0: Event INTERFACE_UNAVAILABLE (31) received
Interface wlan0 is unavailable -- stopped
RTM_NEWLINK: ifi_index=3 ifname=wlan0 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1002 ()
VLAN: vlan_newlink(wlan0)
RTM_NEWLINK: ifi_index=3 ifname=wlan0 operstate=2 linkmode=0 ifi_family=0 ifi_flags=0x1003 ([UP])
nl80211: Own MAC address on ifindex 3 (wlan0) changed from 8e:99:96:a4:5e:93 to 3e:06:5a:49:ca:68
nl80211: Interface up
wlan0: Event INTERFACE_ENABLED (28) received
Unknown event 28
VLAN: vlan_newlink(wlan0)
nl80211: Drv Event 33 (NL80211_CMD_TRIGGER_SCAN) received for wlan0
wlan0: nl80211: Scan trigger
wlan0: Event SCAN_STARTED (49) received
Unknown event 49
RTM_NEWLINK: ifi_index=3 ifname=wlan0 wext ifi_family=0 ifi_flags=0x1003 ([UP])
nl80211: Drv Event 34 (NL80211_CMD_NEW_SCAN_RESULTS) received for wlan0
wlan0: nl80211: New scan results available
nl80211: Scan probed for SSID ''
nl80211: Scan probed for SSID 'My_Wifi_Ssid'
nl80211: Scan included frequencies: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462
wlan0: Event SCAN_RESULTS (3) received
VLAN: vlan_newlink(wlan0)

If you’d like to reproduce this, I made a minimal test case:

files to repro

Dockerfile:

FROM resin/raspberrypi3-python:3.6.0-20170308

RUN apt-get update && \
    apt-get install -y hostapd dnsmasq rng-tools \
    && rm -rf /var/lib/apt/lists/*

COPY interface /etc/network/interfaces.d/wlan0
COPY hostapd.conf /etc/hostapd/hostapd.conf
COPY dnsmasq.conf /etc/dnsmasq.conf

CMD ["hostapd", "-ddKt", "/etc/hostapd/hostapd.conf"]

interface:

# /etc/network/interfaces.d/wlan0
# configure a static IP for the wifi bridge
allow-hotplug wlan0  
iface wlan0 inet static  
    address 172.24.1.1
    netmask 255.255.255.0
    broadcast 172.24.1.255

hostapd:

# /etc/default/hostapd
DAEMON_CONF="/etc/hostapd/hostapd.conf"

hostapd.conf:

interface=wlan0
ssid=ResinWiFiTest
channel=6

dnsmasq.conf:

interface=wlan0      # Use interface wlan0
listen-address=172.24.1.1 # Explicitly specify the address to listen on
bind-interfaces      # Bind to the interface to make sure we aren't sending things elsewhere
server=8.8.8.8       # Forward DNS requests to Google DNS
domain-needed        # Don't forward short names
bogus-priv           # Never forward addresses in the non-routed address spaces
dhcp-range=172.24.1.50,172.24.1.150,2h  # Assign IP addresses between 172.24.1.50 and 172.24.1.150 with a 2 hour lease time

Hey @zain,

I don’t have much experience with the network on ResinOS 2.0 but I think my colleague @joe (maintainer of resin-wifi-connect) will be able to help you with this issue.

Hi @zain,

Don’t turn off network manager - you’ll break things :wink:

We have exactly the same setup as you, with the host NM managing our LTE connection. Here’s how we disable the NM wireless, so that hostapd can take over:

DBUS_SYSTEM_BUS_ADDRESS=unix:path=/host_run/dbus/system_bus_socket \
dbus-send --system --print-reply \
            --dest=org.freedesktop.NetworkManager \
            /org/freedesktop/NetworkManager \
            org.freedesktop.DBus.Properties.Set \
            string:"org.freedesktop.NetworkManager" \
            string:"WirelessEnabled" \
            variant:boolean:false 

If you’re going to be working with dbus / NM a lot, then I highly recommend you use this python package:

It makes life a lot easier.

3 Likes

Sorry, forgot to add you’ll most likely need to re-enable wifi from within your container straight after disabling NM wifi control:

rfkill unblock wlan

Hi @zain

I created a demo project and checked I can remain connected.

Let me know if it helps.

1 Like

I found a much easier way to set up a hotspot with Network Manager on ResinOS 2.x :slight_smile:

Just drop the below example configuration into a file inside the /boot/system-connections directory on the SD card and name it resin-hotspot, next use the Network Manager DBUS API to disable the connection called resin-wifi and enable the connection called resin-hotspot.

You will then be able to connect to the hotspot using resin-hotspot as both the SSID and password.

As a bonus this hotspot method automatically bridges the connection!

[connection]
id=resin-hotspot
uuid=36060c57-aebd-4ccf-aba4-ef75121b5f77
type=wifi
autoconnect=false
interface-name=wlan0
permissions=
secondaries=

[wifi]
band=bg
mac-address-blacklist=
mac-address-randomization=0
mode=ap
seen-bssids=
ssid=resin-hotspot

[wifi-security]
group=
key-mgmt=wpa-psk
pairwise=
proto=
psk=resin-hotspot

[ipv4]
dns-search=
method=shared

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
method=auto
2 Likes

whoa, good find joe! I will give that a shot.

And for the record, @cmoss’s recomendations worked great as well :slight_smile: thanks for the help.