From 60fb4c92b6b0d1582d31e02167b90b424185f3a2 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Wed, 30 Oct 2019 16:57:22 +0100 Subject: hostapd: add ubus reload Add ubus interface to hostapd and wpa_supplicant to allow dynamically reloading wiface configuration without having to restart the hostapd process. As a consequence, both hostapd and wpa_supplicant are now started persistently on boot for each wifi device in the system and then receive ubus calls adding, modifying or removing interface configuration. At a later stage it would be desirable to reduce the services to one single instance managing all radios. Signed-off-by: John Crispin Signed-off-by: Daniel Golle --- .../network/services/hostapd/files/hostapd.hotplug | 14 ++++++++++++ package/network/services/hostapd/files/hostapd.sh | 25 +++++++++++----------- 2 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 package/network/services/hostapd/files/hostapd.hotplug (limited to 'package/network/services/hostapd/files') diff --git a/package/network/services/hostapd/files/hostapd.hotplug b/package/network/services/hostapd/files/hostapd.hotplug new file mode 100644 index 0000000000..d568b3c85a --- /dev/null +++ b/package/network/services/hostapd/files/hostapd.hotplug @@ -0,0 +1,14 @@ +#!/bin/sh + +[ ${ACTION} = "remove" -a -n "${DEVICENAME}" ] && { + kill $(cat /var/run/hostapd-${DEVICENAME}.pid) + rm -rf /var/run/hostapd-${DEVICENAME}.pid /var/run/hostapd-${DEVICENAME}/ + kill $(cat /var/run/wpa_supplicant-${DEVICENAME}.pid) + rm -rf /var/run/wpa_supplicant-${DEVICENAME}.pid /var/run/wpa_supplicant-${DEVICENAME}/ +} + +[ ${ACTION} = "add" -a -n "${DEVICENAME}" ] && { + /usr/sbin/hostapd -s -n ${DEVICENAME} -P /var/run/hostapd-${DEVICENAME}.pid -g /var/run/hostapd-${DEVICENAME}/global -B & + mkdir -p /var/run/wpa_supplicant-${DEVICENAME} + /usr/sbin/wpa_supplicant -s -n ${DEVICENAME} -P /var/run/wpa_supplicant-${DEVICENAME}.pid -g /var/run/wpa_supplicant-${DEVICENAME}/global -B & +} diff --git a/package/network/services/hostapd/files/hostapd.sh b/package/network/services/hostapd/files/hostapd.sh index 3c1504ca60..f03b98ff85 100644 --- a/package/network/services/hostapd/files/hostapd.sh +++ b/package/network/services/hostapd/files/hostapd.sh @@ -254,7 +254,7 @@ hostapd_set_bss_options() { wireless_vif_parse_encryption - local bss_conf + local bss_conf bss_md5sum local wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wpa_key_mgmt json_get_vars \ @@ -627,6 +627,9 @@ hostapd_set_bss_options() { } } + bss_md5sum=$(echo $bss_conf | md5sum | cut -d" " -f1) + append bss_conf "config_id=$bss_md5sum" "$N" + append "$var" "$bss_conf" "$N" return 0 } @@ -950,21 +953,19 @@ EOF } wpa_supplicant_run() { - local ifname="$1"; shift + local ifname="$1" + local hostapd_ctrl="$2" _wpa_supplicant_common "$ifname" - /usr/sbin/wpa_supplicant -B -s \ - ${network_bridge:+-b $network_bridge} \ - -P "/var/run/wpa_supplicant-${ifname}.pid" \ - -D ${_w_driver:-wext} \ - -i "$ifname" \ - -c "$_config" \ - -C "$_rpath" \ - "$@" + ubus call wpa_supplicant.$phy config_add "{ \ + \"driver\": \"${_w_driver:-wext}\", \"ctrl\": \"$_rpath\", \ + \"iface\": \"$ifname\", \"config\": \"$_config\" \ + ${network_bridge:+, \"bridge\": \"$network_bridge\"} \ + ${hostapd_ctrl:+, \"hostapd_ctrl\": \"$hostapd_ctrl\"} \ + }" ret="$?" - wireless_add_process "$(cat "/var/run/wpa_supplicant-${ifname}.pid")" /usr/sbin/wpa_supplicant 1 [ "$ret" != 0 ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED @@ -972,5 +973,5 @@ wpa_supplicant_run() { } hostapd_common_cleanup() { - killall hostapd wpa_supplicant meshd-nl80211 + killall meshd-nl80211 } -- cgit v1.2.3