Commit 755c8d5a authored by Jouke Witteveen's avatar Jouke Witteveen
Browse files

Minor rfkill refactorization

Testing whether transmission is blocked at all is now possible through

    [[ -n $(rf_status "$Interface" "$RFKill") ]]
parent ab895302
......@@ -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
}
......
......@@ -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") ))'
......
......@@ -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
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment