Commit d8b7ce43 authored by James Rayner's avatar James Rayner
Browse files

Added initial rfkill support

 Added some extra debug points
 Directed debug out to stderr, as debug messages were being used as
output from find_essid.
parent 0803c7a8
...@@ -22,14 +22,41 @@ wireless_up() { ...@@ -22,14 +22,41 @@ wireless_up() {
. "$SUBR_DIR/8021x" . "$SUBR_DIR/8021x"
. "$SUBR_DIR/wireless" . "$SUBR_DIR/wireless"
# If rfkill is specified, enable device.
if [[ -n "$RFKILL_NAME" ]]; then # Handle wireless kill switches
path=$(rfkill_from_name $RFKILL_NAME) if [[ $RFKILL ]]; then
if [[ $? -ne 0 ]]; then report_debug "rfkill support enabled: $RFKILL"
report_fail "no rfkill switch with the name $RFKILL_NAME"; if [[ -n "$RFKILL_NAME" ]]; then
fi path=$(rfkill_from_name $RFKILL_NAME)
echo 1 > ${path}/state if [[ $? -ne 0 ]]; then
sleep 1 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
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 fi
# Check if interface exists # Check if interface exists
...@@ -38,12 +65,12 @@ wireless_up() { ...@@ -38,12 +65,12 @@ wireless_up() {
report_fail "interface $INTERFACE does not exist" report_fail "interface $INTERFACE does not exist"
return 1 return 1
fi fi
fi fi
# Kill any lingering wpa_supplicants. # Kill any lingering wpa_supplicants.
report_debug wireless_up stop_wpa "$INTERFACE" report_debug wireless_up stop_wpa "$INTERFACE"
stop_wpa "$INTERFACE" stop_wpa "$INTERFACE"
# Most drivers (mac80211) need mode set before device is brought up # Most drivers (mac80211) need mode set before device is brought up
# Drivers generally default to managed, but set this to be sure. # Drivers generally default to managed, but set this to be sure.
if [[ $(iwgetid -sm "$INTERFACE") -ne Managed ]]; then if [[ $(iwgetid -sm "$INTERFACE") -ne Managed ]]; then
...@@ -66,7 +93,7 @@ wireless_up() { ...@@ -66,7 +93,7 @@ wireless_up() {
eval "iwconfig \"$INTERFACE\" mode managed essid \"$ESSID\"" eval "iwconfig \"$INTERFACE\" mode managed essid \"$ESSID\""
fi fi
fi fi
if checkyesno "${SCAN:-no}"; then if checkyesno "${SCAN:-no}"; then
report_debug wireless_up scanning report_debug wireless_up scanning
local OLDESSID="$ESSID" local OLDESSID="$ESSID"
...@@ -79,12 +106,12 @@ wireless_up() { ...@@ -79,12 +106,12 @@ wireless_up() {
if [[ $? -gt 0 ]]; then if [[ $? -gt 0 ]]; then
report_fail "Wireless network \"$OLDESSID\" not present." report_fail "Wireless network \"$OLDESSID\" not present."
return 1 return 1
fi fi
fi fi
# Manually set iwconfig options # Manually set iwconfig options
if [[ -n "$IWCONFIG" ]]; then if [[ -n "$IWCONFIG" ]]; then
report_debug wireless_up iwconfig "$INTERFACE" $IWCONFIG report_debug wireless_up iwconfig "$INTERFACE" $IWCONFIG
iwconfig "$INTERFACE" $IWCONFIG iwconfig "$INTERFACE" $IWCONFIG
fi fi
...@@ -109,13 +136,13 @@ wireless_up() { ...@@ -109,13 +136,13 @@ wireless_up() {
fi fi
fi fi
fi fi
if quirk "predown"; then # madwifi FS#10585 if quirk "predown"; then # madwifi FS#10585
# ignore quirk nodown---is that appropriate? # ignore quirk nodown---is that appropriate?
# this adds a flush call as well---is that appropriate? # this adds a flush call as well---is that appropriate?
set_interface forcedown-old "$INTERFACE" set_interface forcedown-old "$INTERFACE"
fi fi
report_debug wireless_up iwconfig "$INTERFACE" $WEP_OPTS report_debug wireless_up iwconfig "$INTERFACE" $WEP_OPTS
# JP: I don't understand why this needs to be an eval. What's wrong with just: # JP: I don't understand why this needs to be an eval. What's wrong with just:
# iwconfig "$INTERFACE" $WEP_OPTS # iwconfig "$INTERFACE" $WEP_OPTS
...@@ -127,13 +154,13 @@ wireless_up() { ...@@ -127,13 +154,13 @@ wireless_up() {
if quirk "predown"; then # madwifi FS#10585 if quirk "predown"; then # madwifi FS#10585
set_interface up-old "$INTERFACE" set_interface up-old "$INTERFACE"
fi fi
report_debug ethernet_up wep_check report_debug ethernet_up wep_check
if ! wep_check "$INTERFACE" "$TIMEOUT"; then if ! wep_check "$INTERFACE" "$TIMEOUT"; then
report_fail "WEP Association Failed" report_fail "WEP Association Failed"
return 1 return 1
fi fi
;; ;;
wpa) wpa)
# Quirk for broken drivers... http://bbs.archlinux.org/viewtopic.php?id=36384 # Quirk for broken drivers... http://bbs.archlinux.org/viewtopic.php?id=36384
...@@ -148,14 +175,14 @@ wireless_up() { ...@@ -148,14 +175,14 @@ wireless_up() {
eval "iwconfig \"$INTERFACE\" essid \"$ESSID\"" eval "iwconfig \"$INTERFACE\" essid \"$ESSID\""
fi fi
fi fi
local WPA_CONF="${TMPDIR:-/tmp}/wpa.${1// /}" # substitute spaces out local WPA_CONF="${TMPDIR:-/tmp}/wpa.${1// /}" # substitute spaces out
# make empty tmp dir with correct permissions, rename it # make empty tmp dir with correct permissions, rename it
rm -rf "$WPA_CONF" rm -rf "$WPA_CONF"
mv -f $(mktemp -d) "$WPA_CONF" || return 1 mv -f $(mktemp -d) "$WPA_CONF" || return 1
echo "ctrl_interface=/var/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=/var/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" echo "ctrl_interface_group=${WPA_GROUP:-wheel}" >> "$WPA_CONF/wpa.conf"
# Generate configuration # Generate configuration
if [[ "${#KEY}" -eq 64 ]]; then if [[ "${#KEY}" -eq 64 ]]; then
echo -e "network={ \nssid=\"$ESSID\" \npsk=$KEY \n}">> "$WPA_CONF/wpa.conf" echo -e "network={ \nssid=\"$ESSID\" \npsk=$KEY \n}">> "$WPA_CONF/wpa.conf"
...@@ -194,9 +221,9 @@ wireless_up() { ...@@ -194,9 +221,9 @@ wireless_up() {
report_fail "WPA Authentication/Association Failed" report_fail "WPA Authentication/Association Failed"
return 1 return 1
fi fi
;; ;;
esac esac
conn=ethernet conn=ethernet
checkyesno "${IPROUTE:-no}" && conn=ethernet-iproute checkyesno "${IPROUTE:-no}" && conn=ethernet-iproute
if ! "$CONN_DIR/$conn" up "$1"; then if ! "$CONN_DIR/$conn" up "$1"; then
...@@ -204,7 +231,7 @@ wireless_up() { ...@@ -204,7 +231,7 @@ wireless_up() {
return 1 return 1
fi fi
} }
# wireless_down PROFILE [ LEAVE ifconfig up? default no ] # wireless_down PROFILE [ LEAVE ifconfig up? default no ]
wireless_down() { wireless_down() {
local PROFILE="$1" NOETHERNETDOWN="$2" local PROFILE="$1" NOETHERNETDOWN="$2"
...@@ -217,23 +244,39 @@ wireless_down() { ...@@ -217,23 +244,39 @@ wireless_down() {
fi fi
report_debug wireless_down stop_wpa "$INTERFACE" report_debug wireless_down stop_wpa "$INTERFACE"
stop_wpa "$INTERFACE" stop_wpa "$INTERFACE"
[[ "$SECURITY" == "wpa" ]] && rm -rf "${TMPDIR:-/tmp}/wpa.${PROFILE// /}" # remove tmp wpa config [[ "$SECURITY" == "wpa" ]] && rm -rf "${TMPDIR:-/tmp}/wpa.${PROFILE// /}" # remove tmp wpa config
report_debug wireless_down iwconfig "$INTERFACE" essid off key off report_debug wireless_down iwconfig "$INTERFACE" essid off key off
iwconfig "$INTERFACE" essid off key off &> /dev/null iwconfig "$INTERFACE" essid off key off &> /dev/null
# respects quirk nodown---is that appropriate? # respects quirk nodown---is that appropriate?
# wasn't this already called in ethernet_down? but does the call there respect quirk nodown? # wasn't this already called in ethernet_down? but does the call there respect quirk nodown?
# this adds a flush call as well---is that appropriate? # this adds a flush call as well---is that appropriate?
set_interface down-old "$INTERFACE" set_interface down-old "$INTERFACE"
# If rfkill is specified, disable device. # If rfkill is specified, disable device.
if [[ -n "$RFKILL_NAME" ]]; then if [[ -n "$RFKILL_NAME" ]]; then
path=$(rfkill_from_name "$RFKILL_NAME") path=$(rfkill_from_name "$RFKILL_NAME")
if [[ $? -ne 0 ]]; then if [[ $? -ne 0 ]]; then
report_fail "no rfkill switch with the name $RFKILL_NAME"; report_fail "no rfkill switch with the name $RFKILL_NAME";
fi fi
echo 0 > "${path}/state" echo 0 > "${path}/state"
fi 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
fi
} }
# Returns status of profile - is it still functional? # Returns status of profile - is it still functional?
...@@ -250,3 +293,4 @@ wireless_status() { ...@@ -250,3 +293,4 @@ wireless_status() {
wireless_$1 "$2" "$3" wireless_$1 "$2" "$3"
exit $? exit $?
# vim: set ts=4 et sw=4: # vim: set ts=4 et sw=4:
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
PROFILE_DIR="/etc/network.d/" PROFILE_DIR="/etc/network.d/"
HOOKS_DIR="/usr/lib/network/hooks/" HOOKS_DIR="/usr/lib/network/hooks/"
USERHOOKS_DIR="$PROFILE_DIR/hooks/" USERHOOKS_DIR="$PROFILE_DIR/hooks/"
IFACE_DIR="$PROFILE/interfaces/" IFACE_DIR="$PROFILE_DIR/interfaces/"
SUBR_DIR="/usr/lib/network/" SUBR_DIR="/usr/lib/network/"
CONN_DIR="${SUBR_DIR}/connections/" CONN_DIR="${SUBR_DIR}/connections/"
STATE_DIR="/var/run/network/" STATE_DIR="/var/run/network/"
...@@ -35,7 +35,7 @@ function report_notify { ...@@ -35,7 +35,7 @@ function report_notify {
} }
function report_debug { function report_debug {
checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" checkyesno "$NETCFG_DEBUG" && echo "DEBUG: $*" >&2
} }
function report_try { function report_try {
...@@ -121,4 +121,3 @@ function load_hooks() { ...@@ -121,4 +121,3 @@ function load_hooks() {
load_hooks load_hooks
...@@ -13,12 +13,15 @@ load_profile() ...@@ -13,12 +13,15 @@ load_profile()
report_fail "Profile \"$1\" does not exist" report_fail "Profile \"$1\" does not exist"
return 1 return 1
fi fi
report_debug "Loading profile $1"
. "$PROFILE_DIR/$1" . "$PROFILE_DIR/$1"
report_debug "Configuring interface $INTERFACE"
if [[ -z "$INTERFACE" ]]; then if [[ -z "$INTERFACE" ]]; then
report_fail "Profile missing an interface to configure" report_fail "Profile missing an interface to configure"
return 1 return 1
fi fi
if [[ -f "$IFACE_DIR/$INTERFACE" ]]; then if [[ -f "$IFACE_DIR/$INTERFACE" ]]; then
report_debug "Interface level configuration enabled: $IFACE_DIR/$INTERFACE"
. "$IFACE_DIR/$INTERFACE" . "$IFACE_DIR/$INTERFACE"
. "$PROFILE_DIR/$1" # we want profile settings to override, so need to source profile again . "$PROFILE_DIR/$1" # we want profile settings to override, so need to source profile again
fi fi
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment