summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJouke Witteveen <j.witteveen@gmail.com>2012-10-12 14:02:04 +0200
committerJouke Witteveen <j.witteveen@gmail.com>2012-10-13 22:23:49 +0200
commit8de507b99b78766a567935c59bc81e310667b163 (patch)
tree1cdcb13f0857a2f6772cf7a69186c6b0f6eec5af
parent186e931130623eae0c5ef4dc69c6672a74178e39 (diff)
downloadnetctl-8de507b99b78766a567935c59bc81e310667b163.tar.gz
netctl-8de507b99b78766a567935c59bc81e310667b163.tar.xz
Update rfkill implementation
Implement the current kernel ABI and support sysfs paths encountered on current systems.
-rw-r--r--src/rfkill46
1 files changed, 16 insertions, 30 deletions
diff --git a/src/rfkill b/src/rfkill
index 12e1832..1832dc1 100644
--- a/src/rfkill
+++ b/src/rfkill
@@ -8,10 +8,10 @@ set_rf_state() {
local path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1
case "$state" in
enabled)
- echo 1 > "$path/state"
+ echo 0 > "$path/soft"
;;
disabled)
- echo 0 > "$path/state"
+ echo 1 > "$path/soft"
;;
esac
}
@@ -28,8 +28,8 @@ get_rf_path() {
done
report_fail "no rfkill switch with name $RFKILL_NAME"
else
- path="/sys/class/net/$INTERFACE/rfkill"
- if [[ -d "$path" ]]; then
+ path=$(find -L "/sys/class/net/$INTERFACE/" -maxdepth 2 -type d -name "rfkill*" 2> /dev/null | head -n 1)
+ if [[ -n "$path" ]]; then
echo "$path"
return 0
fi
@@ -38,35 +38,21 @@ get_rf_path() {
return 1
}
-get_rf_state() {
- local INTERFACE="$1" PROFILE="$2" path state
-
- path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1
- read state < "$path/state"
-
- case "$state" in
- 0|2)
- echo "disabled";;
- 1)
- echo "enabled";;
- *)
- echo "$state";;
- esac
-}
-
enable_rf() {
- local INTERFACE="$1" RFKILL="$2" RFKILL_NAME="$3"
+ local INTERFACE="$1" RFKILL="$2" RFKILL_NAME="$3" path hard soft
+
# Enable rfkill if necessary, or fail if it is hardware
if [[ -n "$RFKILL" ]]; then
- local state=$(get_rf_state "$INTERFACE") || return 1
- if [[ "$state" != "enabled" ]]; then
- if [[ "$RFKILL" == "soft" ]]; then
- set_rf_state "$INTERFACE" enabled $RFKILL_NAME
- sleep 1
- else
- report_fail "radio is disabled on $INTERFACE"
- return 1
- fi
+ path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1
+ read hard < "$path/hard"
+ read soft < "$path/soft"
+
+ if (( hard )); then
+ report_fail "radio is disabled on $INTERFACE"
+ return 1
+ elif (( soft )); then
+ set_rf_state "$INTERFACE" enabled "$RFKILL_NAME" || return 1
+ timeout_wait 1 "(( ! \$(< \"$path/soft\") ))"
fi
fi
}