diff options
author | Rémy Oudompheng <remy@archlinux.org> | 2011-06-19 20:15:24 +0200 |
---|---|---|
committer | Rémy Oudompheng <remy@archlinux.org> | 2011-06-19 20:15:24 +0200 |
commit | b07b4b0d7f9522523fb83a4aeacc9b54f4367410 (patch) | |
tree | 0c94d6201f53578c60369e0ce261b8777442c138 | |
parent | 9bc6048581da6278fb1803df5baa3ae8f2c73cd8 (diff) | |
parent | decaf8ae76a79d1828a36d08c1bf44d915969e63 (diff) | |
download | netctl-b07b4b0d7f9522523fb83a4aeacc9b54f4367410.tar.gz netctl-b07b4b0d7f9522523fb83a4aeacc9b54f4367410.tar.xz |
Merge branch 'no-iwconfig'
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | docs/wireless | 2 | ||||
-rw-r--r-- | src-wireless/netcfg-auto-wireless | 3 | ||||
-rw-r--r-- | src/8021x | 125 | ||||
-rw-r--r-- | src/connections/wireless | 133 | ||||
-rw-r--r-- | src/rfkill | 75 | ||||
-rw-r--r-- | src/wireless | 193 | ||||
-rwxr-xr-x | wpa_actiond/netcfg-wpa_actiond | 4 |
8 files changed, 249 insertions, 288 deletions
@@ -15,7 +15,7 @@ install: install -m644 src/iftab $(DESTDIR)/etc/iftab install -m644 man/*.8 $(DESTDIR)/usr/share/man/man8 # Libs - install -m644 src/{network,wireless,8021x,globals} $(DESTDIR)/usr/lib/network + install -m644 src/{network,rfkill,8021x,globals} $(DESTDIR)/usr/lib/network install -m755 src/connections/* ${DESTDIR}/usr/lib/network/connections ln -s ethernet $(DESTDIR)/usr/lib/network/connections/ethernet-iproute # Hooks diff --git a/docs/wireless b/docs/wireless index bf5ca19..2e466c7 100644 --- a/docs/wireless +++ b/docs/wireless @@ -10,7 +10,7 @@ This connection method uses wpa_supplicant to configure a wireless network conn INTERFACE (required) : The wireless interface to configure SECURITY (required for security of 'wep', 'wpa', 'wpa-configsection' or 'wpa-config') -: One of 'wpa', 'wep', 'none', 'wpa-configsection' or 'wpa-config'. Defaults to 'none'. Old iwconfig based configuration code can be used with 'wep-old' and 'none-old'. +: One of 'wpa', 'wep', 'none', 'wpa-configsection' or 'wpa-config'. Defaults to 'none'. KEY (required for SECURITY of 'wpa' or 'wep' only) : Wireless encryption key. ESSID (this or AP is required) diff --git a/src-wireless/netcfg-auto-wireless b/src-wireless/netcfg-auto-wireless index 3215d5c..b915272 100644 --- a/src-wireless/netcfg-auto-wireless +++ b/src-wireless/netcfg-auto-wireless @@ -2,7 +2,8 @@ # Originally contributed by Neuro: http://bbs.archlinux.org/viewtopic.php?pid=278148#p278148 . /usr/lib/network/network -. /usr/lib/network/wireless +. $SUBR_DIR/rfkill +. $SUBR_DIR/8021x # wifi_auto # autoconnect wireless interface @@ -1,3 +1,5 @@ +WPA_CLI="wpa_cli -p /run/wpa_supplicant" + # Uses wpa_supplicant to check for association to a network # wpa_check interface [timeout] wpa_check() @@ -8,9 +10,9 @@ wpa_check() while [[ $timeout -lt "$TIMEOUT" ]]; do ( # Sometimes wpa_supplicant isn't ready so silence errors for 2s only to avoid hiding real errors if [[ $timeout -lt 2 ]]; then - eval $(wpa_cli -p /run/wpa_supplicant -i "$INTERFACE" status 2> /dev/null | fgrep "wpa_state=") + eval $($WPA_CLI -i "$INTERFACE" status 2> /dev/null | fgrep "wpa_state=") else - eval $(wpa_cli -p /run/wpa_supplicant -i "$INTERFACE" status | fgrep "wpa_state=") + eval $($WPA_CLI -i "$INTERFACE" status | fgrep "wpa_state=") fi [[ "$wpa_state" = "$CONDITION" ]] ) && return 0 @@ -40,7 +42,7 @@ start_wpa() stop_wpa() { - wpa_cli -p /run/wpa_supplicant -i "$1" terminate &> /dev/null + $WPA_CLI -i "$1" terminate &> /dev/null sleep 1 # JP: need this else the file tends to disappear after [[ -f ... ]] but before cat... # see <http://bbs.archlinux.org/viewtopic.php?pid=515667#p515667> if [[ -f "/run/wpa_supplicant_$1.pid" ]]; then @@ -48,14 +50,125 @@ stop_wpa() fi } +wpa_reconfigure() { + local INTERFACE=$1 + $WPA_CLI -i "$INTERFACE" reconfigure + return $? +} + +wpa_check_current_essid() { + # usage: wpa_check_current_essid $interface $essid + # check that wpa_supplicant is connected to the right essid + local INTERFACE=$1 ESSID=$2 status + status=$($WPA_CLI -i "$INTERFACE" status | grep "^ssid=") + if (( $? == 0 )) && [[ "$status" == "ssid=$ESSID" ]]; then + return 0 + else + return 1 + fi +} + +wpa_find_essid() { + # usage: wpa_find_essid $INTERFACE $ESSID + # look for existence of a given essid. Assumes wpa_supplicant is + # running + result=$(wpa_supplicant_scan_and_find "$1" 5 "$2") + ret=$? + echo $result + report_debug wpa_find_essid "\"$result\"" + return $ret +} + +wpa_find_ap() { + # usage: wpa_find_essid $INTERFACE $ESSID + # look for existence of a given essid. Assumes wpa_supplicant is + # running + bssid=${2,,} # set to lowercase + result=$(wpa_supplicant_scan_and_find "$1" 1 "$bssid") + ret=$? + echo $result + report_debug wpa_find_ap "\"$result\"" + return $ret +} + +wpa_supplicant_scan_and_find() { + #usage: wpa_supplicant_scan_and_find $INTERFACE $FIELD $ITEM + # field = 1 for bssid, 5 for essid + # item = string to lookup + local INTERFACE="$1" FIELD="$2" ITEM="$3" RETRIES=5 try scan_ok + scan_ok=0 + $WPA_CLI -i "$INTERFACE" scan &> /dev/null + for ((try=0; try < $RETRIES; try++)); do + local found + sleep 2 + found=$($WPA_CLI -i "$INTERFACE" scan_results | tail -n+2 | cut -f ${FIELD} | grep -F -x -m 1 "${ITEM}") + (( $? == 0 )) && scan_ok=1 + + # ITEM has been found, echo it + if [[ -n "$found" ]]; then + echo "$found" + return 0 + fi + $WPA_CLI -i "$INTERFACE" scan &> /dev/null + done + if (( $scan_ok != 1 )); then + report_debug wpa_supplicant_scan_and_find "unable to retrieve scan results" + fi + return 1 +} + +# Return a filename containing a list of network APs and ESSIDs found (sorted by decreasing signal strength) +# list_networks interface +list_networks() { + wpa_supplicant_scan_info "$1" 1,5 +} + +wpa_supplicant_scan_info() { + local INTERFACE="$1" fields="$2" essids + # temp file used, as keeping ESSID's with spaces in their name in arrays + # is hard, obscure and kinda nasty. This is simpler and clearer. + + [[ -z "$INTERFACE" ]] && return 1 + essids=$(mktemp --tmpdir essid.XXXXXXXX) + + wpa_supplicant -B -i"$INTERFACE" -Dnl80211,wext -C/run/wpa_supplicant -P/run/wpa_supplicant.pid || return 1 + $WPA_CLI -i "$INTERFACE" scan &> /dev/null + sleep 2.5 + $WPA_CLI -i "$INTERFACE" scan_results | + grep -v "^Selected" | + grep -v "^bssid" | + sort -rn -k3 | + sort -u -k5 | + sort -rn -k3 | + cut -f"$fields" > "$essids" + + # Fields are tab delimited + # Remove extraneous output from wpa_cli + # Sort by strength + # Remove duplicates + # Re-sort by strength as the removal disorders the list + # Cut to the AP/essid fields only + + kill "$(cat /run/wpa_supplicant.pid)" + + # File of 0 length, ie. no ssid's. + if [[ ! -s "$essids" ]]; then + rm -f "$essids" + return 1 + fi + + echo $essids + return 0 +} + # Requires already loaded profile make_wpa_config_file() { local interface=$1 - local WPA_CONF="${TMPDIR:-/tmp}/wpa.${interface}" # substitute spaces out + local WPA_CONF="$STATE_DIR/wpa.${interface}" # substitute spaces out # make empty tmp dir with correct permissions, rename it rm -rf "$WPA_CONF" - mv -f "$(mktemp -d)" "$WPA_CONF" || return 1 + mv -f "$(mktemp -d --tmpdir=$STATE_DIR)" "$WPA_CONF" || return 1 echo "ctrl_interface=/run/wpa_supplicant" >> "$WPA_CONF/wpa.conf" # we know $WPA_CONF now has no spaces, but it may have other nasty chars, so still needs to be quoted echo "ctrl_interface_group=${WPA_GROUP:-wheel}" >> "$WPA_CONF/wpa.conf" [[ $WPA_COUNTRY ]] && echo "country=$WPA_COUNTRY" >> "$WPA_CONF/wpa.conf" @@ -110,5 +223,5 @@ make_wpa_config() { fi } -# vim: ft=sh ts=4 et sw=4: +# vim: ft=sh ts=4 et sw=4 tw=0: diff --git a/src/connections/wireless b/src/connections/wireless index d93a672..7bb35ea 100644 --- a/src/connections/wireless +++ b/src/connections/wireless @@ -1,53 +1,21 @@ #! /bin/bash . /usr/lib/network/network . $SUBR_DIR/8021x -. $SUBR_DIR/wireless - - -iwconfig_up() { - - quirk prescan && iwlist "$INTERFACE" scan &> /dev/null # bcm43xx - - # 'none' uses iwconfig like wep. Use sane default if WEP_OPTS="" - if [[ -z "$WEP_OPTS" ]]; then - if [[ "$SECURITY" = "wep-old" ]]; then - if [[ -n "$AP" ]]; then - WEP_OPTS="ap \"$AP\" key $KEY" - else - WEP_OPTS="essid \"$ESSID\" key $KEY" - fi - elif [[ "$SECURITY" = "none-old" ]]; then - if [[ -n "$AP" ]]; then - WEP_OPTS="ap \"$AP\"" - else - WEP_OPTS="essid \"$ESSID\"" - fi - fi - fi - - quirk "predown" && bring_interface down "$INTERFACE" # madwifi FS#10585 - - report_debug wireless_up iwconfig "$INTERFACE" $WEP_OPTS - - if ! iwconfig "$INTERFACE" $WEP_OPTS; then - report_fail "Could not set wireless configuration." - return 1 - fi - - quirk "predown" && bring_interface up "$INTERFACE" # madwifi FS#10585 - - report_debug ethernet_up wep_check - if ! wep_check "$INTERFACE" "$TIMEOUT"; then - report_fail "WEP Association Failed" - return 1 - fi -} +. $SUBR_DIR/rfkill wireless_up() { PROFILE="$1" load_profile "$PROFILE" + # Default settings + SECURITY=${SECURITY:-none} + if [[ "$SECURITY" != "${SECURITY%-old}" ]]; then + report_warn "SECURITY=none-old, wep-old are deprecated, please use none, wep instead!" + SECURITY=${SECURITY%-old} + fi + WPA_DRIVER=${WPA_DRIVER:-nl80211,wext} + enable_rf $INTERFACE $RFKILL $RFKILL_NAME || return 1 # Check if interface exists @@ -57,69 +25,71 @@ wireless_up() { report_debug wireless_up stop_wpa "$INTERFACE" stop_wpa "$INTERFACE" - # Most drivers (mac80211) need mode set before device is brought up - if [[ $(iwgetid -sm "$INTERFACE") -ne Managed ]]; then - report_debug wireless_up iwconfig "$INTERFACE" mode managed - iwconfig "$INTERFACE" mode managed + # Start wpa_supplicant + if [ "$SECURITY" = "wpa-config" ]; then + WPA_CONF="${WPA_CONF:-/etc/wpa_supplicant.conf}" + else + WPA_CONF=$(make_wpa_config_file $INTERFACE) + fi + report_debug wireless_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS" + if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then + report_fail "wpa_supplicant did not start, possible configuration error" + return 1 fi - - report_debug wireless_up ifup - bring_interface up "$INTERFACE" || return 1 # Scan for network's existence first if checkyesno "${SCAN:-no}"; then report_debug wireless_up scanning local OLDESSID="$ESSID" if [[ -n "$AP" ]]; then - ESSID=$(find_ap "$INTERFACE" "$AP") + ESSID=$(wpa_find_ap "$INTERFACE" "$AP") else - ESSID=$(find_essid "$INTERFACE" "$ESSID") + ESSID=$(wpa_find_essid "$INTERFACE" "$ESSID") fi if [[ $? -gt 0 ]]; then report_fail "Wireless network \"$OLDESSID\" not present." + report_debug wireless_up stop_wpa "$INTERFACE" + stop_wpa "$INTERFACE" return 1 fi fi - # Manually set iwconfig options + # Manually set iwconfig options (DEPRECATED) if [[ -n "$IWCONFIG" ]]; then + report_warn "The use of IWCONFIG option is deprecated." report_debug wireless_up iwconfig "$INTERFACE" $IWCONFIG iwconfig "$INTERFACE" $IWCONFIG fi - # Set to 'none' if not set - [[ -z "$SECURITY" ]] && SECURITY="none" - + # Build configuration file case "$SECURITY" in - *-old) - report_debug "Using older iwconfig based path" - iwconfig_up || return 1 - ;; wpa-config) - [[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf" # defaults ;; none|wep|wpa|wpa-configsection) - WPA_CONF="$(make_wpa_config_file $INTERFACE)" - echo -e "network={ \n$(make_wpa_config) \n}">> "$WPA_CONF" + echo -e "network={ \n$(make_wpa_config) \n}" >> "$WPA_CONF" + report_debug wireless_up "Configuration generated at $WPA_CONF" + report_debug wireless_up wpa_reconfigure "$INTERFACE" + if ! wpa_reconfigure "$INTERFACE"; then + report_fail "WPA configuration failed!" + stop_wpa "$INTERFACE" + return 1 + fi ;; *) report_fail "Invalid SECURITY setting: $SECURITY" ;; esac - if [[ ${SECURITY:(-4)} != "-old" ]]; then - report_debug wireless_up "Configuration generated at $WPA_CONF" - [[ -z "$WPA_DRIVER" ]] && WPA_DRIVER="nl80211,wext" - report_debug wireless_up start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS" - if ! start_wpa "$INTERFACE" "$WPA_CONF" "$WPA_DRIVER" "$WPA_OPTS"; then - report_fail "wpa_supplicant did not start, possible configuration error" - return 1 - fi - report_debug wireless_up wpa_check - if ! wpa_check "$INTERFACE" "$TIMEOUT"; then - report_fail "WPA Authentication/Association Failed" - return 1 - fi + # Bring interface up after starting wpa_supplicant + # This is important since cards such as iwl3945 do not support + # mode switching when they are already up. + report_debug wireless_up ifup + bring_interface up "$INTERFACE" || return 1 + + report_debug wireless_up wpa_check + if ! wpa_check "$INTERFACE" "$TIMEOUT"; then + report_fail "WPA Authentication/Association Failed" + return 1 fi if ! "$CONN_DIR/ethernet" up "$PROFILE"; then @@ -135,14 +105,9 @@ wireless_down() { "$CONN_DIR/ethernet" down "$PROFILE" - if [[ ${SECURITY:(-4)} == "-old" ]]; then - report_debug wireless_down iwconfig "$INTERFACE" essid off key off - iwconfig "$INTERFACE" essid off key off &> /dev/null - else - report_debug wireless_down stop_wpa "$INTERFACE" - stop_wpa "$INTERFACE" - rm -rf "${TMPDIR:-/tmp}/wpa.$INTERFACE" - fi + report_debug wireless_down stop_wpa "$INTERFACE" + stop_wpa "$INTERFACE" + rm -rf "$STATE_DIR/wpa.$INTERFACE" bring_interface down "$INTERFACE" @@ -157,7 +122,7 @@ wireless_down() { # Returns status of profile - is it still functional? wireless_status() { load_profile "$1" - if [[ "$(iwgetid -r)" -ne "$ESSID" ]]; then + if ! wpa_check_current_essid "$INTERFACE" "$ESSID"; then return 1 elif ! ip link show dev "$INTERFACE" | fgrep -q "state UP"; then return 1 @@ -168,5 +133,5 @@ wireless_status() { wireless_$1 "$2" "$3" exit $? -# vim: ft=sh ts=4 et sw=4: +# vim: ft=sh ts=4 et sw=4 tw=0: diff --git a/src/rfkill b/src/rfkill new file mode 100644 index 0000000..d61703d --- /dev/null +++ b/src/rfkill @@ -0,0 +1,75 @@ +set_rf_state() { + local INTERFACE="$1" state="$2" RFKILL_NAME="$3" + + if [[ "$RFKILL" == "hard" ]]; then + report_fail "Cannot set state on hardware rfkill switch" + return 1 + fi + local path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1 + case "$state" in + enabled) + echo 1 > "$path/state" + ;; + disabled) + echo 0 > "$path/state" + ;; + esac +} + +get_rf_path() { + local INTERFACE="$1" RFKILL_NAME="$2" path + + if [[ -n "$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 + return 1 +} + +get_rf_state() { + local INTERFACE="$1" PROFILE="$2" path state + + path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1 + state=$(cat "$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" + # 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 + fi + fi +} + +# vim: ft=sh ts=4 et sw=4: + diff --git a/src/wireless b/src/wireless deleted file mode 100644 index 71713e7..0000000 --- a/src/wireless +++ /dev/null @@ -1,193 +0,0 @@ -# Uses wireless_tools, to check for association to a network. -# wep_check interface [timeout] -wep_check() -{ - local INTERFACE="$1" TIMEOUT="${2:-15}" timeout=0 bssid - - while [[ $timeout -lt "$TIMEOUT" ]]; do - bssid=$(iwgetid "$INTERFACE" -ra) - [[ -n "$bssid" && "$bssid" != "00:00:00:00:00:00" ]] && return 0 - sleep 1 - let timeout++ - done - return 1 -} - -# Check if a particular network is within range -# find_essid interface essid connection -find_essid() { - local INTERFACE="$1" ESSID="$2" RETRIES=10 try=0 res scanned - while [[ "$try" -lt "$RETRIES" ]]; do - sleep 0.5 - let try++ - found=$( - res=$(iwlist "$INTERFACE" scan 2>/dev/null) - [[ -z "$res" ]] && exit 1 - # if results were non-null, process them and exit 0 - echo "$res" | sed -nr 's/^\s+ESSID:"([^"]*)"$/\1/p' | fgrep -xm1 "$ESSID" - ) && { - scanned=1 - report_debug find_essid "\"$found\"" - # we only bother with at most 5 successful scans - if (( try < RETRIES-4 )); then try=$((RETRIES-4)); fi - } - if [[ -n "$found" ]]; then - echo "$found" # JP: echo literal ESSID - return 0 # network found - fi - done - if [[ "$scanned" -ne 1 ]]; then - report_debug find_essid "unable to scan" - fi - return 1 -} - -# Check if a particular network is within range -# find_ap interface ap -find_ap() { - local INTERFACE="$1" ap=$(echo "$2" | tr 'abcdef' 'ABCDEF') RETRIES=10 try=0 res scanned - while [[ "$try" -lt "$RETRIES" ]]; do - sleep 0.5 - let try++ - found=$( - res=$(iwlist "$INTERFACE" scan 2> /dev/null) - [[ -z "$res" ]] && exit 1 - # if results were non-null, process them and exit 0 - echo "$res" | sed -nr '/^\s+Cell .. - Address: ([[:xdigit:]:]+)$/ { s//\1/; N; s/(.*)\n\s+ESSID:"([^"]*)"$/\1\t\2/p }' \ - | egrep -m1 "^$ap\t" - ) && { - scanned=1 - report_debug find_ap "\"$found\"" - # we only bother with at most 5 successful scans - if (( try < RETRIES-4 )); then try=$((RETRIES-4)); fi - } - if [[ -n "$found" ]]; then - echo "$found" | cut -f2 # JP: echo literal ESSID - return 0 - fi - done - if [[ "$scanned" -ne 1 ]]; then - report_debug find_ap "unable to scan" - fi - return 1 -} - -# Return a filename containing a list of network APs and ESSIDs found (sorted by decreasing signal strength) -# list_networks interface -list_networks() { - wpa_supplicant_scan_info "$1" 1,5 -} - -wpa_supplicant_scan_info() { - local INTERFACE="$1" fields="$2" essids - # temp file used, as keeping ESSID's with spaces in their name in arrays - # is hard, obscure and kinda nasty. This is simpler and clearer. - - [[ -z "$INTERFACE" ]] && return 1 - essids=$(mktemp --tmpdir essid.XXXXXXXX) - - wpa_supplicant -B -i"$INTERFACE" -Dnl80211,wext -C/run/wpa_supplicant -P/run/wpa_supplicant.pid || return 1 - wpa_cli -p /run/wpa_supplicant -i "$INTERFACE" scan &> /dev/null - sleep 2.5 - wpa_cli -p /run/wpa_supplicant -i "$INTERFACE" scan_results | - grep -v "^Selected" | - grep -v "^bssid" | - sort -rn -k3 | - sort -u -k5 | - sort -rn -k3 | - cut -f"$fields" > "$essids" - - # Fields are tab delimited - # Remove extraneous output from wpa_cli - # Sort by strength - # Remove duplicates - # Re-sort by strength as the removal disorders the list - # Cut to the AP/essid fields only - - kill "$(cat /run/wpa_supplicant.pid)" - - # File of 0 length, ie. no ssid's. - if [[ ! -s "$essids" ]]; then - rm -f "$essids" - return 1 - fi - - echo $essids - return 0 -} - -set_rf_state() { - local INTERFACE="$1" state="$2" RFKILL_NAME="$3" - - if [[ "$RFKILL" == "hard" ]]; then - report_fail "Cannot set state on hardware rfkill switch" - return 1 - fi - local path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1 - case "$state" in - enabled) - echo 1 > "$path/state" - ;; - disabled) - echo 0 > "$path/state" - ;; - esac -} - -get_rf_path() { - local INTERFACE="$1" RFKILL_NAME="$2" path - - if [[ -n "$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 - return 1 -} - -get_rf_state() { - local INTERFACE="$1" PROFILE="$2" path state - - path=$(get_rf_path "$INTERFACE" "$RFKILL_NAME") || return 1 - state=$(cat "$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" - # 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 - fi - fi -} - -# vim: ft=sh ts=4 et sw=4: - diff --git a/wpa_actiond/netcfg-wpa_actiond b/wpa_actiond/netcfg-wpa_actiond index 0e38518..e1b584a 100755 --- a/wpa_actiond/netcfg-wpa_actiond +++ b/wpa_actiond/netcfg-wpa_actiond @@ -1,7 +1,7 @@ #! /bin/bash . /usr/lib/network/network -. /usr/lib/network/8021x -. /usr/lib/network/wireless +. $SUBR_DIR/8021x +. $SUBR_DIR/rfkill AUTOWIFI="/usr/sbin/wpa_actiond" ACTION_SCRIPT="/usr/bin/netcfg-wpa_actiond-action" |