summaryrefslogtreecommitdiffstats
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
parent24d48b93ab76e255145edf097ebcb84ba70d5cb1 (diff)
downloadnetctl-820d9295b51e427f3e17c9e83227a127ef9b7631.tar.gz
netctl-820d9295b51e427f3e17c9e83227a127ef9b7631.tar.xz
Rework rfkill into re-usable functions
-rw-r--r--src-wireless/netcfg-auto-wireless10
-rw-r--r--src/connections/ethernet19
-rw-r--r--src/connections/wireless73
-rw-r--r--src/wireless56
4 files changed, 82 insertions, 76 deletions
diff --git a/src-wireless/netcfg-auto-wireless b/src-wireless/netcfg-auto-wireless
index 5bf0e5a..e83f55b 100644
--- a/src-wireless/netcfg-auto-wireless
+++ b/src-wireless/netcfg-auto-wireless
@@ -11,6 +11,12 @@ wifi_auto()
{
local interface="$1"
report_try "Scanning for networks"
+ source $IFACE_DIR/$interface
+
+ if [[ $RFKILL ]]; then
+ set_rf_state $interface up
+ fi
+
set_interface up "$interface" # uses iproute methods---is it there any value to providing option to use ifconfig?
networks="$(list_networks $interface)"
@@ -60,7 +66,7 @@ wifi_auto()
done < <(list_profiles) # avoid subshell we'd get by piping list_profiles to while read
done < "$networks" # avoid subshell; list_networks returns name of a tmp file
rm -f "$networks" # shouldn't we delete the tmp file?
-
+
if [[ -n "$found_profile" ]]; then
report_success
if profile_up "$found_profile" "$found_essid"; then # JP: now we pass literal essid to profile_up as $2
@@ -73,7 +79,7 @@ wifi_auto()
set_interface forcedown "$interface"
exit_fail "No profiles matched the local networks."
fi
-
+
}
if [[ $(id -u) -ne 0 ]]; then
diff --git a/src/connections/ethernet b/src/connections/ethernet
index dd07667..5414c69 100644
--- a/src/connections/ethernet
+++ b/src/connections/ethernet
@@ -9,7 +9,7 @@ ethernet_up() {
report_fail "interface $INTERFACE does not exist"
return 1
fi
- fi
+ fi
report_debug ethernet_up ifup
set_interface up-old "$INTERFACE"
@@ -20,7 +20,7 @@ ethernet_up() {
return 1
fi
- if checkyesno "${AUTH8021X:-no}"; then
+ if checkyesno "${AUTH8021X:-no}"; then
. "$SUBR_DIR/8021x"
[[ -z "$WPA_CONF" ]] && WPA_CONF="/etc/wpa_supplicant.conf"
[[ -z "$WPA_OPTS" ]] && WPA_OPTS="-Dwired"
@@ -35,7 +35,7 @@ ethernet_up() {
set_interface forcedown-old "$INTERFACE"
report_fail "WPA Authentication/Association Failed"
return 1
- fi
+ fi
fi
case "$IP" in
@@ -48,7 +48,7 @@ ethernet_up() {
return 1
fi
else
- # Clear remaining pid files.
+ # Clear remaining pid files.
rm -f "/var/run/dhcpcd-$INTERFACE".{pid,cache} >/dev/null 2>&1
# If using own dns, tell dhcpcd to NOT replace resolv.conf
[[ -n "$DNS1" || -n "$DNS" ]] && DHCP_OPTIONS="-C resolv.conf $DHCP_OPTIONS"
@@ -58,10 +58,10 @@ ethernet_up() {
if [[ "$PIPESTATUS" -ne 0 ]]; then
report_fail "DHCP IP lease attempt failed."
return 1
- fi
+ fi
fi
if [[ -n "$IFOPTS" ]]; then
- report_debug ethernet_up ifup $IFOPTS
+ report_debug ethernet_up ifup $IFOPTS
ifconfig "$INTERFACE" $IFOPTS
fi
;;
@@ -82,7 +82,7 @@ ethernet_up() {
set_interface forcedown-old "$INTERFACE"
report_fail "Adding gateway $GATEWAY failed."
return 1
- fi
+ fi
fi
;;
*)
@@ -103,7 +103,7 @@ ethernet_up() {
# Generate a new resolv.conf
if [[ -n "$DNS1" || -n "$DNS" ]]; then
- : >/etc/resolv.conf
+ : >/etc/resolv.conf
[[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf
[[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf
[[ -n "$DNS1" ]] && echo "nameserver $DNS1" >>/etc/resolv.conf
@@ -141,7 +141,7 @@ ethernet_down() {
fi
;;
esac
-
+
report_debug ethernet_down ifdown
# ignore quirk nodown---is that appropriate?
# this adds a flush call as well---is that appropriate?
@@ -158,3 +158,4 @@ ethernet_status() {
ethernet_$1 "$2"
exit $?
# vim: set ts=4 et sw=4:
+
diff --git a/src/connections/wireless b/src/connections/wireless
index 1874b55..29e4112 100644
--- a/src/connections/wireless
+++ b/src/connections/wireless
@@ -2,18 +2,6 @@
. /usr/lib/network/network
-rfkill_from_name() {
- local name=$1
- for rfkill in /sys/class/rfkill/*; do
- if [[ "$(cat $rfkill/name)" == $name ]]; then
- echo $rfkill
- return 0
- fi
- done
- echo "none"
- return 1
-}
-
wireless_up() {
load_profile "$1"
@@ -22,41 +10,15 @@ wireless_up() {
. "$SUBR_DIR/8021x"
. "$SUBR_DIR/wireless"
-
- # Handle wireless kill switches
if [[ $RFKILL ]]; then
- report_debug "rfkill support enabled: $RFKILL"
- if [[ -n "$RFKILL_NAME" ]]; then
- path=$(rfkill_from_name $RFKILL_NAME)
- if [[ $? -ne 0 ]]; then
- report_fail "no rfkill switch with the name $RFKILL_NAME";
- fi
- else
- path=/sys/class/net/$INTERFACE/rfkill
- if [[ ! -d $path ]]; then
- report_fail "no rfkill switch available on interface $INTERFACE"
+ if [[ ! $(get_rf_state $INTERFACE) == "up" ]]; then
+ if [[ $RFKILL == "soft" ]]; then
+ set_rf_state $INTERFACE up
+ sleep 1
+ else
+ report_fail "radio is disabled on $INTERFACE"
fi
fi
-
-
- case $RFKILL in
- soft)
- echo 1 > ${path}/state # Soft switch, so enable
- sleep 1
- report_debug "Enabled RFKILL on $path"
- ;;
- hard)
- state=$(cat ${path}/state)
- case $state in
- 0)
- report_fail "Card disabled";;
- 1)
- true;;
- *)
- report_fail "Unknown state: $state";;
- esac
- ;;
- esac
fi
# Check if interface exists
@@ -252,30 +214,11 @@ wireless_down() {
# this adds a flush call as well---is that appropriate?
set_interface down-old "$INTERFACE"
- # If rfkill is specified, disable device.
- if [[ -n "$RFKILL_NAME" ]]; then
- path=$(rfkill_from_name "$RFKILL_NAME")
- if [[ $? -ne 0 ]]; then
- report_fail "no rfkill switch with the name $RFKILL_NAME";
- fi
- echo 0 > "${path}/state"
- fi
-
# Handle wireless kill switches
# Any reason why a hardware switch should be considered on interface down?
if [[ $RFKILL == "soft" ]]; then
- if [[ -n $RFKILL_NAME ]]; then
- path=$(rfkill_from_name $RFKILL_NAME)
- if [[ $? -ne 0 ]]; then
- report_fail "no rfkill switch with the name $RFKILL_NAME";
- fi
- else
- path=/sys/class/net/$INTERFACE/rfkill
- if [[ ! -d $path ]]; then
- report_fail "no rfkill switch available on interface $INTERFACE"
- fi
- fi
- echo 0 > ${path}/state # Soft switch, so disable
+ . "$SUBR_DIR/wireless"
+ set_rf_state $INTERFACE down
fi
}
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: