summaryrefslogtreecommitdiffstats
path: root/src/lib/rfkill
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/rfkill')
-rw-r--r--src/lib/rfkill37
1 files changed, 24 insertions, 13 deletions
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") ))'