From 8de507b99b78766a567935c59bc81e310667b163 Mon Sep 17 00:00:00 2001 From: Jouke Witteveen Date: Fri, 12 Oct 2012 14:02:04 +0200 Subject: Update rfkill implementation Implement the current kernel ABI and support sysfs paths encountered on current systems. --- src/rfkill | 46 ++++++++++++++++------------------------------ 1 file 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 } -- cgit v1.2.3-24-g4f1b