summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Rayner <james@archlinux.org>2009-09-25 13:41:28 +0200
committerJames Rayner <james@archlinux.org>2009-09-25 13:41:28 +0200
commitc1fe0e013363e5d8a3b0cc650bcb5076857de6c3 (patch)
treeb4644ba057122c318c28c35a443fa77ffeb6ed42
parentf977693a8879e4309aacc2982d9d948d50690185 (diff)
downloadnetctl-c1fe0e013363e5d8a3b0cc650bcb5076857de6c3.tar.gz
netctl-c1fe0e013363e5d8a3b0cc650bcb5076857de6c3.tar.xz
Integrate netcfg into autowifi
This is implemented almost entirely as suggested by Thomas, and it depends on autowifi which is his work. autowifi-netcfg provides proper roaming and automatic wireless though wpa_supplicant. To run, use autowifi-netcfg $interface
-rwxr-xr-xautowifi/autowifi-netcfg78
-rwxr-xr-xautowifi/autowifi-netcfg-action54
2 files changed, 132 insertions, 0 deletions
diff --git a/autowifi/autowifi-netcfg b/autowifi/autowifi-netcfg
new file mode 100755
index 0000000..89850ff
--- /dev/null
+++ b/autowifi/autowifi-netcfg
@@ -0,0 +1,78 @@
+
+. /usr/lib/network/network
+. /usr/lib/network/8021x
+. /usr/lib/network/wireless
+
+interface=$1; shift
+
+AUTOWIFI="/home/iphitus/netcfg/autowifi/autowifi/autowifi-wpactrl/autowifi"
+ACTION_SCRIPT="/home/iphitus/netcfg/autowifi/autowifi-netcfg-action"
+PIDFILE="/var/run/wpa_supplicant_${interface}.pid"
+EXTRA_AUTOWIFI_OPTIONS="$*"
+
+if [[ -z $interface ]]; then
+ echo "No interface specified"
+ exit 1
+fi
+
+# Load interface specific config
+[[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface"
+
+if [[ -n "$RFKILL" ]]; then # Enable radio if necessary
+ set_rf_state "$interface" up || exit $?
+fi
+
+WPA_CONF="$(make_wpa_config $interface)"
+
+for profile in $(list_profiles); do
+ echo $profile
+ (
+ load_profile $profile
+
+ [[ $CONNECTION != "wireless" ]] && exit 1
+ [[ $INTERFACE != $interface ]] && exit 1
+
+ case $SECURITY in
+ wep)
+ if [[ ${KEY:0:2} == "s:" ]]; then # TODO: does wpa_supplicant handle this as expected?
+ config="ssid=\"$ESSID\" \nkey_mgmt=NONE \nwep_key0=\"${KEY:2}\" \nwep_tx_keyidx=0"
+ else
+ config="ssid=\"$ESSID\" \nkey_mgmt=NONE \nwep_key0=$KEY \nwep_tx_keyidx=0"
+ fi
+ ;;
+ none)
+ config="ssid=\"$ESSID\" \nkey_mgmt=NONE"
+ ;;
+ wpa)
+ if [[ "${#KEY}" -eq 64 ]]; then
+ config="ssid=\"$ESSID\" \npsk=$KEY"
+ else
+ config="ssid=\"$ESSID\" \npsk=\"$KEY\""
+ fi
+ ;;
+ wpa-configsection)
+ echo -e "$CONFIGSECTION">> "$WPA_CONF"
+ ;;
+ *)
+ continue
+ ;;
+ esac
+
+ echo -e "network={ \n$config \nid_str=\"$profile\" \n}" >> $WPA_CONF
+ )
+done
+
+
+[[ -z $WPA_DRIVER ]] && WPA_DRIVER="wext"
+
+# Kill any existing wpa_supplicant on this interface
+stop_wpa "$interface"
+
+if start_wpa $interface $WPA_CONF $WPA_DRIVER $WPA_OPTS; then
+ if $AUTOWIFI -i ${interface} -P {PIDFILE} -a ${ACTION_SCRIPT} ${EXTRA_AUTOWIFI_OPTIONS}; then
+ exit 0
+ fi
+fi
+
+exit 1
+
diff --git a/autowifi/autowifi-netcfg-action b/autowifi/autowifi-netcfg-action
new file mode 100755
index 0000000..f273b3b
--- /dev/null
+++ b/autowifi/autowifi-netcfg-action
@@ -0,0 +1,54 @@
+#! /bin/bash
+
+interface=$1
+ssid=$2
+profile=$3
+action=$4
+
+. /usr/lib/network/network
+[[ $profile ]] && load_profile "$profile"
+
+case $action in
+ CONNECT)
+ if [[ -z $profile ]]; then
+ dhcpcd $interface
+ exit $?
+ fi
+ if ! $CONN_DIR/ethernet up "$profile"; then
+ exit 1 # what to do if fail?
+ fi
+
+ set_profile up "$profile"
+
+ if ! ( eval $POST_UP ); then # JP: sandbox the eval
+ # failing POST_UP will take interface down
+ "$CONN_DIR/$ethernet" down "$profile"
+ exit 1
+ fi
+ ;;
+ DISCONNECT)
+ if [[ -z $profile ]]; then
+ dhcpcd -k $interface
+ exit $?
+ fi
+ if ! ( eval $PRE_DOWN ); then # JP: sandbox the eval
+ exit 1
+ fi
+ if ! "$CONN_DIR/ethernet" down "$profile"; then
+ exit 1
+ fi
+ if ! ( eval $POST_DOWN ); then # JP: sandbox the eval
+ exit 1
+ fi
+ set_profile down "$profile"
+ ;;
+ LOST|REESTABLISHED)
+ # Not handled.
+ exit 0
+ ;;
+ *)
+ # ???
+ exit 1
+ ;;
+esac
+