From 755c8d5afdaca08ca1732765f30370f752259d4b Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Mon, 21 Oct 2013 23:37:20 +0200 Subject: Minor rfkill refactorization Testing whether transmission is blocked at all is now possible through [[ -n $(rf_status "$Interface" "$RFKill") ]] --- src/lib/connections/wireless | 4 ++-- src/lib/rfkill | 37 ++++++++++++++++++++++++------------- src/netctl-auto | 4 ++-- 3 files changed, 28 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/lib/connections/wireless b/src/lib/connections/wireless index 870af51..88ca3e3 100644 --- a/src/lib/connections/wireless +++ b/src/lib/connections/wireless @@ -19,7 +19,7 @@ wireless_up() { : ${TimeoutWPA:=15} if [[ $RFKill ]]; then - enable_rf "$Interface" "$RFKill" || return 1 + rf_enable "$Interface" "$RFKill" || return 1 fi # Kill any lingering WPA supplicants @@ -73,7 +73,7 @@ wireless_down() { wpa_stop "$Interface" bring_interface_down "$Interface" || return 1 if [[ $RFKill ]]; then - disable_rf "$Interface" "$RFKill" + rf_disable "$Interface" "$RFKill" fi } diff --git a/src/lib/rfkill b/src/lib/rfkill index e388f08..3f841f3 100644 --- a/src/lib/rfkill +++ b/src/lib/rfkill @@ -4,7 +4,7 @@ ## Determine the system interface of an rfkill device # $1: interface name # $2: rfkill name -get_rf_path() { +rf_get_path() { local interface=$1 rfkill_name=${2:-auto} path if [[ $rfkill_name == "auto" ]]; then @@ -26,33 +26,44 @@ get_rf_path() { return 1 } -## Unblock transmission through a wireless device +## Determine the blocking status of an rfkill device # $1: interface name # $2: rfkill name -enable_rf() { - local interface=$1 rfkill=$2 path hard soft +rf_status() { + local path + path=$(rf_get_path "$@") || return 1 - path=$(get_rf_path "$interface" "$rfkill") || return 1 - read hard < "$path/hard" - read soft < "$path/soft" + if (( $(< "$path/hard" ) )); then + echo "hard" + elif (( $(< "$path/soft" ) )); then + echo "soft" + fi +} - if (( hard )); then +## Unblock transmission through a wireless device +# $1: interface name +# $2: rfkill name +rf_enable() { + case $(rf_status "$@") in + hard) report_error "Transmission is hard-blocked on interface '$interface'" return 1 - elif (( soft )); then + ;; + soft) report_debug "$FUNCNAME: echo 0 > '$path/soft'" echo 0 > "$path/soft" timeout_wait 1 '(( ! $(< "$path/soft") ))' - fi + ;; + esac } ## Block transmission through a wireless device # $1: interface name # $2: rfkill name -disable_rf() { - local interface=$1 rfkill=$2 path +rf_disable() { + local path + path=$(rf_get_path "$@") || return 1 - path=$(get_rf_path "$interface" "$rfkill") || return 1 report_debug "$FUNCNAME: echo 1 > '$path/soft'" echo 1 > "$path/soft" timeout_wait 1 '(( $(< "$path/soft") ))' diff --git a/src/netctl-auto b/src/netctl-auto index 7519325..5cf104b 100755 --- a/src/netctl-auto +++ b/src/netctl-auto @@ -177,7 +177,7 @@ start() { source "$PROFILE_DIR/interfaces/$interface" fi if [[ $RFKill ]]; then - enable_rf "$interface" "$RFKill" || return 1 + rf_enable "$interface" "$RFKill" || return 1 fi @@ -227,7 +227,7 @@ stop() { fi timeout_wait 1 '! wpa_is_active "$interface"' || wpa_stop "$interface" ip link set dev "$interface" down - [[ $RFKill ]] && disable_rf "$interface" "$RFKill" + [[ $RFKill ]] && rf_disable "$interface" "$RFKill" return 0 } -- cgit v1.2.3-24-g4f1b