]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Add a wpa_supplicant hook script.
authorRoy Marples <roy@marples.name>
Fri, 7 Jun 2013 20:03:28 +0000 (20:03 +0000)
committerRoy Marples <roy@marples.name>
Fri, 7 Jun 2013 20:03:28 +0000 (20:03 +0000)
This script starts wpa_supplicant on a wireless interface if not
already running and /etc/wpa_supplicant.conf exists, stops it
when the interface departs and sends wpa_supplicant a reconfigure
command.

If dhcpcd is running in master mode, you can use `dhcpcd -n eth0'
it instruct wpa_supplicant to reload its configuration file.

README
dhcpcd-hooks/10-wpa_supplicant [new file with mode: 0644]
dhcpcd-hooks/Makefile
dhcpcd-run-hooks.8.in
dhcpcd.8.in
dhcpcd.c

diff --git a/README b/README
index 2ef4c9b31f000b3cebe30f48ec9de08b58995de1..467107cf1780a22ce3851de6ed80829f2e7747b4 100644 (file)
--- a/README
+++ b/README
@@ -54,8 +54,8 @@ the binary has to run on older versions which lack support, such as getline.
 Hooks
 -----
 Not all the hooks in dhcpcd-hooks are installed by default.
-By default we install 01-test, 10-mtu, 20-resolv.conf,
-29-lookup-hostname and 30-hostname.
+By default we install 01-test, 02-dump, 10-mtu, 10-wpa_supplicant,
+15-timezone, 20-resolv.conf, 29-lookup-hostname and 30-hostname.
 The default dhcpcd.conf disables the lookup-hostname hook by default.
 The configure program attempts to find hooks for systems you have installed.
 To add more simply
diff --git a/dhcpcd-hooks/10-wpa_supplicant b/dhcpcd-hooks/10-wpa_supplicant
new file mode 100644 (file)
index 0000000..18c889f
--- /dev/null
@@ -0,0 +1,63 @@
+# Start and stop wpa_supplicant per wireless interface.
+# This is needed because wpa_supplicant lacks hotplugging of any kind
+# and the user should not be expected to have to wire it into their system
+# if the base system doesn't do this itself.
+
+: ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf}
+
+wpa_supplicant_start()
+{
+       local err errn
+
+       wpa_cli -i "$interface" status >/dev/null 2>&1 && return 0
+       syslog info "starting wpa_supplicant"
+       err=$(wpa_supplicant -B -c"$wpa_supplicant_conf" -i"$interface" 2>&1)
+       errn=$?
+       if [ $errn != 0 ]; then
+               syslog err "failed to start wpa_supplicant"
+               syslog err "$err"
+       fi
+       return $errn
+}
+
+wpa_supplicant_reconfigure()
+{
+       local err errn
+
+       wpa_cli -i "$interface" status >/dev/null 2>&1 || return 0
+       syslog info "reconfiguring wpa_supplicant"
+       err=$(wpa_cli -i"$interface" reconfigure 2>&1)
+       errn=$?
+       if [ $errn != 0 ]; then
+               syslog err "failed to reconfigure wpa_supplicant"
+               syslog err "$err"
+       fi
+       return $errn
+}
+
+wpa_supplicant_stop()
+{
+       local err errn
+
+       wpa_cli -i "$interface" status >/dev/null 2>&1 || return 0
+       syslog info "stopping wpa_supplicant"
+       err=$(wpa_cli -i"$interface" terminate 2>&1)
+       errn=$?
+       if [ $errn != 0 ]; then
+               syslog err "failed to start wpa_supplicant"
+               syslog err "$err"
+       fi
+       return $errn
+}
+       
+
+if [ "$ifwireless" = "1" -a -s "$wpa_supplicant_conf" ] && \
+    type wpa_supplicant >/dev/null 2>&1 && \
+    type wpa_cli >/dev/null 2>&1
+then
+       case "$reason" in
+       PREINIT)        wpa_supplicant_start;;
+       RECONFIGURE)    wpa_supplicant_reconfigure;;
+       DEPARTED)       wpa_supplicant_stop;;
+       esac
+fi
index acd1c182405720d2406a8c68ca893bd17381cf83..cf215c8a6a3a5d5f8f4b92c355c5ad258d14618f 100644 (file)
@@ -4,7 +4,7 @@ include ${TOP}/config.mk
 
 SCRIPTSDIR=    ${LIBEXECDIR}/dhcpcd-hooks
 SCRIPTS=       01-test 02-dump
-SCRIPTS+=      10-mtu 15-timezone 20-resolv.conf
+SCRIPTS+=      10-mtu 10-wpa_supplicant 15-timezone 20-resolv.conf
 SCRIPTS+=      29-lookup-hostname 30-hostname
 SCRIPTS+=      ${HOOKSCRIPTS}
 
index c8aca105bdc0c78a158e2705dee2c7de171d0d95..8d1b746427dfc2f3270cb853c80ba4bb8948123c 100644 (file)
@@ -75,8 +75,6 @@ dhcpcd is starting up and any pre-initialisation should be done.
 .It Dv CARRIER
 dhcpcd has detected the carrier is up.
 This is generally just a notification and no action need be taken.
-.It Dv DEPARTED
-The interface has been removed.
 .It Dv INFORM | Dv INFORM6
 dhcpcd informed a DHCP server about it's address and obtained other
 configuration details.
@@ -102,6 +100,8 @@ dhcpcd's lease or state expired and it failed to obtain a new one.
 .It Dv NAK
 dhcpcd received a NAK from the DHCP server.
 This should be treated as EXPIRE.
+.It Dv RECONFIGURE
+dhcpcd has been instructed to reconfigure an interface.
 .It Dv NOCARRIER
 dhcpcd lost the carrier.
 The cable may have been unplugged or association to the wireless point lost.
@@ -112,6 +112,8 @@ means it cannot work as a DHCP or ZeroConf client.
 Static configuration and DHCP INFORM is still allowed.
 .It Dv STOP | Dv STOP6
 dhcpcd stopped running on the interface.
+.It Dv DEPARTED
+The interface has been removed.
 .It Dv DUMP
 dhcpcd has been asked to dump the last lease for the interface.
 .It Dv TEST
index 3bfec7a7eb5a01d3dc1b3d21268f5dbc68446eb7..355277d1e55e7287e2e93b5c3212d55d2492d330 100644 (file)
@@ -171,7 +171,7 @@ changes the routes to use the interface with the same route and the lowest
 metric.
 See options below for controlling which interfaces we allow and deny through
 the use of patterns.
-.Ss Hooking into DHCP events
+.Ss Hooking into events
 .Nm
 runs
 .Pa @SCRIPT@ ,
@@ -184,6 +184,8 @@ in a lexical order.
 The default installation supplies the scripts
 .Pa 01-test ,
 .Pa 10-mtu ,
+.Pa 10-wpa_supplicant ,
+.Pa 15-timezone ,
 .Pa 20-resolv.conf
 and
 .Pa 30-hostname .
index 25e98072ca13b1d35e8189e5a68d5bf10d48c6f5..f9d53a7f84d369332894f81bc1d962b8c6d6e06e 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -617,6 +617,7 @@ if_reboot(struct interface *ifp, int argc, char **argv)
        int oldopts;
 
        oldopts = ifp->options->options;
+       script_runreason(ifp, "RECONFIGURE");
        configure_interface(ifp, argc, argv);
        dhcp_reboot_newopts(ifp, oldopts);
        dhcp6_reboot(ifp);