From c517c30230d2deccc4520e933ae1ddd95d6bb636 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Thu, 28 May 2020 21:52:16 +0300 Subject: [PATCH] /etc/init.d/S33hostapd: enable AP interface if available --- board/common/overlay/etc/init.d/S33hostapd | 36 +++++++++++++++++++--- board/common/overlay/etc/os.conf | 1 - 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/board/common/overlay/etc/init.d/S33hostapd b/board/common/overlay/etc/init.d/S33hostapd index dad69d736a..f825d68862 100755 --- a/board/common/overlay/etc/init.d/S33hostapd +++ b/board/common/overlay/etc/init.d/S33hostapd @@ -18,7 +18,6 @@ test -x ${PROG} || exit 0 test -n "${OS_VERSION}" || source /etc/init.d/base prepare_conf ${CONF} ${SYS_CONF} ${BOOT_CONF} -test -s ${CONF} || exit 0 test -s ${WATCH_CONF} && source ${WATCH_CONF} @@ -38,7 +37,23 @@ watch() { done } -start() { +prepare_ap_iface() { + # Only prepare AP interfaces of format "apX" + if ! [[ "${OS_AP}" =~ ap([[:digit:]]) ]]; then + return + fi + + wlan_iface=wlan${BASH_REMATCH[1]} + if ! iw dev ${wlan_iface} info &>/dev/null; then + return # No wlan interface + fi + + msg_begin "Preparing AP interface" + iw dev ${wlan_interface} interface add ${OS_AP} type __ap &>/dev/null + test $? == 0 && msg_done || msg_fail +} + +start_hostapd() { msg_begin "Starting hostapd" # wait up to 5 seconds for interface @@ -65,13 +80,27 @@ start() { test -n "${module}" && msg_done "done (${module})"|| msg_done } -stop() { +stop_hostapd() { msg_begin "Stopping hostpad" killall hostapd &>/dev/null ps | grep hostapd | grep -v $$ | grep -v grep | tr -s ' ' | sed -e 's/^\s//' | cut -d ' ' -f 1 | xargs -r kill msg_done } +start() { + prepare_ap_iface + + if [[ -s ${CONF} ]]; then + start_hostapd + fi +} + +stop() { + if [[ -s ${CONF} ]]; then + stop_hostapd + fi +} + case "$1" in start) start @@ -90,4 +119,3 @@ case "$1" in echo "Usage: $0 {start|stop|restart}" exit 1 esac - diff --git a/board/common/overlay/etc/os.conf b/board/common/overlay/etc/os.conf index d9b0361c35..f56adce473 100644 --- a/board/common/overlay/etc/os.conf +++ b/board/common/overlay/etc/os.conf @@ -10,4 +10,3 @@ OS_FIRMWARE_METHOD="github" OS_FIRMWARE_REPO="ccrisan/thingos" OS_FIRMWARE_USERNAME="" OS_FIRMWARE_PASSWORD="" -