Trigger script when WiFi AP interface is up and usable

I feel like I am missing something very obvious here. I want to run a script when my WiFi AP (and also mesh for that matter) devices are up and configured. All the wifi-ifaces on my router are bridged with the br-lan bridge with the option option network 'lan'.

I have multiple scripts on my router, that turn WiFi on or off based on certain events like WAN connection state, VPN state etc, time-based trigger etc. Also, the WiFi is sometimes toggled with a hardware button on the router.

I want to "listen" to the event of the WiFi radio being up and hostapd completed with the configuration, so that I can set certain options on the device using iw commands. (I cannot set these options in /etc/config/wireless because hostapd doesn't support them)

What I've tried

  • Adding a script to /etc/hotplug.d/iface and /etc/hotplug.d/ieee80211 - both do not recieve any event when the WiFi AP devices go up or down, probably because they are all "ports" of the bridge interface and devices part of a bridge do not invoke hotplug

  • Using the procd interface triggers in an init.d script - Doesn't recieve any event either, probably due to the same reason as above.

  • Time-triggerred cron job - Not a reliable option because sometimes the time trigger runs after the wifi interfaces are already up and client devices have already scanned and connected to the router before the custom settings get applied.

Using ubus monitor, I have seen that there are changes that occur in the network.wireless and hostapd objects when WiFi devices go up/down, but haven't been able to find anyway to use those change events to trigger a script. (Either that is not simply possible or the documentation for it is just missing)

Try monitoring the network related events.

cat << "EOF" > /etc/hotplug.d/net/99-logger
logger -t hotplug.net $(env)
EOF
logread -f -e hotplug.net
3 Likes

Thank you for the reply, I had never tried the net hotplug.

I am now able to trigger my script, I get the following environment vars in my script:

  • ACTION: add/remove when interface goes up/down
  • DEVICENAME and INTERFACE: both contain the name of the wireless interface (ifname defined in /etc/config/wireless or autogenerated wlanX(-Y))
  • DEVPATH: <radio-device-sysfs-path>/net/<ifname>
  • DEVTYPE: wlan
  • IFINDEX: same as the value of ifindex in the output of iw dev / iw dev <ifname> info

As expected, there are no additional events produced when the AP or mesh WiFi interfaces connect to other devices, because they are added to bridge only once.


Update: Although unrelated to the question, for anyone trying to configure 802.11s WiFi mesh interface parameters with iw command after the interface is up, it will work only if the mesh is connected to peer device(s) at the time of executing the commands. Also, when all peer devices disconnect, all settings are reset and can be applied only after at least one device is connected. In conclusion, configuring mesh interface parameters using net hotplug is a bad idea, probably one should use something like mesh11sd for this purpose.

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.