diff options
-rw-r--r-- | src/rfkill | 46 |
1 files changed, 16 insertions, 30 deletions
@@ -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 } |