summaryrefslogtreecommitdiffstats
path: root/src-wireless
diff options
context:
space:
mode:
authorJames Rayner <james@archlinux.org>2008-12-18 12:06:56 +0100
committerJames Rayner <james@archlinux.org>2008-12-18 12:06:56 +0100
commit4278b9e04952c24b14ce5eb3b5ed25885129a859 (patch)
tree9438fce666c458b6417e958baaafd75721bedf94 /src-wireless
parentd68313a616c8a4b46ae6192e966176aab3bdd49b (diff)
downloadnetctl-4278b9e04952c24b14ce5eb3b5ed25885129a859.tar.gz
netctl-4278b9e04952c24b14ce5eb3b5ed25885129a859.tar.xz
Arrange tree for future packaging
Diffstat (limited to 'src-wireless')
-rwxr-xr-xsrc-wireless/net-auto43
-rwxr-xr-xsrc-wireless/netcfg-auto-wireless58
-rwxr-xr-xsrc-wireless/wireless-dbus137
3 files changed, 238 insertions, 0 deletions
diff --git a/src-wireless/net-auto b/src-wireless/net-auto
new file mode 100755
index 0000000..add6711
--- /dev/null
+++ b/src-wireless/net-auto
@@ -0,0 +1,43 @@
+#!/bin/bash
+
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+case "$1" in
+ start)
+ # Ensure any device renaming has occurred as intended
+ for daemon in "${DAEMONS[@]}"; do
+ if [ "$daemon" = "${daemon#!}" -a "$daemon" = "net-rename" ]; then
+ if ck_daemon net-rename; then
+ /etc/rc.d/net-rename start
+ fi
+ fi
+ done
+
+ for network in ${AUTO_NETWORKS[@]}; do
+ case $network in
+ auto-*) # Automatic configuration, store type and get interface next
+ auto=$network
+ ;;
+ *) # Either interface or profile
+ if [[ "$auto" ]]; then # Auto set, so interface
+ /usr/bin/netcfg-$auto $network
+ unset auto
+ fi
+ esac
+ done
+
+ add_daemon net-auto
+ ;;
+ stop)
+ /usr/bin/netcfg2 -a
+ rm_daemon net-auto
+ ;;
+ restart)
+ $0 stop; sleep 1; $0 start
+ ;;
+ *)
+ echo "usage: $0 {start|stop|restart}"
+esac
+
+# vim: set ts=4 et sw=4:
diff --git a/src-wireless/netcfg-auto-wireless b/src-wireless/netcfg-auto-wireless
new file mode 100755
index 0000000..e5e4fc1
--- /dev/null
+++ b/src-wireless/netcfg-auto-wireless
@@ -0,0 +1,58 @@
+#! /bin/bash
+# Originally contributed by Neuro: http://bbs.archlinux.org/viewtopic.php?pid=278148#p278148
+
+. /usr/lib/network/network.subr
+. /usr/lib/network/wireless.subr
+. /etc/rc.conf
+. /etc/rc.d/functions
+
+# wifi_auto
+# autoconnect wireless interface
+# $1 - wireless interface
+wifi_auto()
+{
+ interface=$1; RETRIES=6
+ stat_busy "Scanning for networks"
+
+ ifconfig $interface up
+ networks="$(list_networks $interface)"
+
+ if [[ ! "$networks" ]]; then
+ stat_append "- No networks available."
+ stat_fail
+ exit 1
+ fi
+
+ # Loop through all the found essid's, then find a matching profile.
+ while read essid; do
+ for network in $(list_profiles); do
+ load_profile $network
+ if [[ "$CONNECTION" = "wireless" && "$essid" = "$ESSID" && "$interface" = "$INTERFACE" ]]; then
+ found=$network
+ fi
+ # Clear out any variables set by the profile
+ . /usr/lib/network/${CONNECTION}.subr
+ ${CONNECTION}_clean_scope
+ done
+ done < $networks
+
+ if [[ "$found" ]]; then
+ netcfg2 $found
+ exit $?
+ fi
+
+ stat_append "- No profiles matched the found networks"
+ stat_fail
+ exit 1
+}
+
+if [[ $(id -u) -ne 0 ]]; then
+ err "This script needs to be run with root priviledges"
+ exit 1
+fi
+if [[ -z $1 ]]; then
+ err "Please supply an interface to connect"
+ exit 1
+fi
+wifi_auto $1
+
diff --git a/src-wireless/wireless-dbus b/src-wireless/wireless-dbus
new file mode 100755
index 0000000..d954577
--- /dev/null
+++ b/src-wireless/wireless-dbus
@@ -0,0 +1,137 @@
+#! /usr/bin/env python
+import sys
+import dbus
+import shlex
+import subprocess
+from signal import SIGTERM
+from os import kill
+from time import sleep
+
+# dbus constants.
+WPAS_DBUS_SERVICE = "fi.epitest.hostap.WPASupplicant"
+WPAS_DBUS_INTERFACE = "fi.epitest.hostap.WPASupplicant"
+WPAS_DBUS_OPATH = "/fi/epitest/hostap/WPASupplicant"
+
+WPAS_DBUS_INTERFACES_INTERFACE = "fi.epitest.hostap.WPASupplicant.Interface"
+WPAS_DBUS_INTERFACES_OPATH = "/fi/epitest/hostap/WPASupplicant/Interfaces"
+WPAS_DBUS_BSSID_INTERFACE = "fi.epitest.hostap.WPASupplicant.BSSID"
+WPAS_DBUS_NETWORKS_INTERFACE = "fi.epitest.hostap.WPASupplicant.Network"
+
+def read_config(config):
+ cfg = shlex.split(open(config, "r").read())
+ options = {}
+ for line in cfg:
+ (var, delim, value) = line.partition('=')
+ if not delim:
+ raise SyntaxError, 'Bad configuration file'
+ options[var] = value
+ return options
+
+def start(profile):
+ # TODO: Add check if it's even a wireless interface
+ # Interface up...
+ try:
+ subprocess.check_call(["ifconfig", profile['INTERFACE'], "up"])
+ except CalledProcessError:
+ print " - Could not bring interface up"
+ return False
+
+ # Manually set any iwconfig options, ignoring errors
+ if profile.has_key('IWCONFIG'):
+ subprocess.call(["iwconfig", profile['INTERFACE'], profile['IWCONFIG']])
+
+
+ # Base arguments
+ args=["wpa_supplicant", "-Bu", "-P/var/run/wpa_supplicant.pid"]
+
+ try:
+ args.append(profile['WPA_OPTS'])
+ except KeyError:
+ args.append("-Dwext")
+
+ if profile['SECURITY'] == "wpa-config":
+ try:
+ args.append("-c" + profile["WPA_CONF"])
+ except KeyError:
+ args.append("-c/etc/wpa_supplicant.conf")
+ elif not profile['SECURITY'] in ['yes', 'wpa', 'wep']:
+ print " - Invalid security chosen"
+ return False
+
+ # Start wpa_supplicant
+ supplicant = subprocess.Popen(args,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
+ output = supplicant.communicate()[0]
+ if supplicant.returncode not in [255,0]:
+ print output
+ print " - Could not start wpa_supplicant"
+ return False
+
+ # Connect to wpa_supplicant
+ bus = dbus.SystemBus()
+ wpas_obj = bus.get_object(WPAS_DBUS_SERVICE, WPAS_DBUS_OPATH)
+ wpas = dbus.Interface(wpas_obj, WPAS_DBUS_INTERFACE)
+
+ # Add/Get interface path
+ try:
+ driver=profile["WPA_DRIVER"]
+ except KeyError:
+ driver="wext"
+
+ try:
+ path = wpas.getInterface("ipw0")
+ except dbus.exceptions.DBusException:
+ path = wpas.addInterface("ipw0", {"driver":dbus.String(driver,variant_level=1)})
+
+ # Get interface object
+ if_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
+ iface = dbus.Interface(if_obj, WPAS_DBUS_INTERFACES_INTERFACE);
+
+ # Connect
+ if profile['SECURITY'] in ['wpa','yes','wep']:
+ # Add+select the network
+ path = iface.addNetwork()
+ net_obj = bus.get_object(WPAS_DBUS_SERVICE, path)
+ rnet = dbus.Interface(net_obj, WPAS_DBUS_NETWORKS_INTERFACE)
+ iface.selectNetwork(rnet)
+ # Set the options
+ opts = dbus.Dictionary({"ssid": dbus.ByteArray(profile['ESSID']), "psk": dbus.String(profile['KEY'])}, signature="sv")
+ rnet.set(opts)
+
+ # Determine timeout
+ try:
+ timeout = profile["TIMEOUT"]
+ except KeyError:
+ timeout = 15
+
+ # Check for association
+ n=0
+ while n <= timeout:
+ n+=1
+ sleep(1)
+ state = iface.state()
+ if state == "COMPLETED":
+ break
+
+ if n == timeout:
+ print " - Association/Authentication failed:", state
+ return False
+
+ # Run ethernet and get an ip.
+ try:
+ subprocess.check_call(["/usr/lib/network/connections/ethernet", "up", sys.argv[2]])
+ except CalledProcessError:
+ return False
+ return True
+
+def stop(profile):
+ subprocess.call(["/usr/lib/network/connections/ethernet", "down", sys.argv[2]])
+ kill(int(open("/var/run/wpa_supplicant.pid").read()),SIGTERM)
+ return True
+
+if __name__ == "__main__":
+ profile = read_config("/etc/network.d/"+sys.argv[2])
+
+ if sys.argv[1] == "up":
+ sys.exit(not start(profile))
+ elif sys.argv[1] == "down":
+ sys.exit(not stop(profile))