summaryrefslogtreecommitdiffstats
path: root/src/wireless
diff options
context:
space:
mode:
authorJames Rayner <james@archlinux.org>2009-09-07 14:29:56 +0200
committerJames Rayner <james@archlinux.org>2009-09-07 14:29:56 +0200
commit820d9295b51e427f3e17c9e83227a127ef9b7631 (patch)
tree7e33c460e11590348dd1312b3168dd83789212a9 /src/wireless
parent24d48b93ab76e255145edf097ebcb84ba70d5cb1 (diff)
downloadnetctl-820d9295b51e427f3e17c9e83227a127ef9b7631.tar.gz
netctl-820d9295b51e427f3e17c9e83227a127ef9b7631.tar.xz
Rework rfkill into re-usable functions
Diffstat (limited to 'src/wireless')
-rw-r--r--src/wireless56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/wireless b/src/wireless
index f63f7e1..4e66bfa 100644
--- a/src/wireless
+++ b/src/wireless
@@ -166,5 +166,61 @@ wpa_supplicant_scan_info() {
return 0
}
+set_rf_state() {
+ local INTERFACE=$1 state=$2 PROFILE=$3
+
+ source $IFACE_DIR/$INTERFACE
+ [[ $PROFILE ]] && source $PROFILE_DIR/$PROFILE # profile overrides
+ [[ $RFKILL == "hard" ]] && report_fail "Cannot set state on hardware rfkill switch"
+ path=$(get_rf_path $INTERFACE $RFKILL_NAME)
+ case $state in
+ up)
+ echo 1 > $path/state
+ ;;
+ down)
+ echo 0 > $path/state
+ ;;
+ esac
+}
+
+get_rf_path() {
+ local INTERFACE=$1 RFKILL_NAME=$2
+
+ if [[ $RFKILL_NAME ]]; then
+ for path in /sys/class/rfkill/*; do
+ if [[ "$(cat $path/name)" == $RFKILL_NAME ]]; then
+ echo $path
+ return 0
+ fi
+ done
+ report_fail "no rfkill switch with name $RFKILL_NAME"
+ else
+ path=/sys/class/net/$INTERFACE/rfkill
+ if [[ -d $path ]]; then
+ echo $path
+ return 0
+ fi
+ report_fail "no rfkill switch available on interface $INTERFACE"
+ fi
+}
+
+get_rf_state() {
+ local INTERFACE=$1 PROFILE=$2
+ source $IFACE_DIR/$INTERFACE
+ [[ $PROFILE ]] && source $PROFILE_DIR/$PROFILE # profile overrides
+ path=$(get_rf_path $INTERFACE $RFKILL_NAME)
+ state=$(cat $path/state)
+
+ case $state in
+ 0)
+ echo "disabled";;
+ 1)
+ echo "enabled";;
+ *)
+ echo $state;;
+ esac
+}
+
+
# vim: set ts=4 et sw=4 ft=sh: