developer | 4e0da23 | 2022-05-09 13:05:53 +0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | |
| 4 | WPA_SUP_BIN="/usr/sbin/wpa_supplicant" |
| 5 | WPA_SUP_PNAME="wpa_supplicant" |
| 6 | WPA_SUP_PIDFILE="/var/run/wpa_supplicant.$IFACE.pid" |
| 7 | WPA_COMMON_CTRL_IFACE="/var/run/wpa_supplicant" |
| 8 | WPA_SUP_OPTIONS="-B -P $WPA_SUP_PIDFILE -i $IFACE" |
| 9 | |
| 10 | VERBOSITY=0 |
| 11 | |
| 12 | |
| 13 | if [ -s "$IF_WPA_CONF" ]; then |
| 14 | WPA_SUP_CONF="-c $IF_WPA_CONF" |
| 15 | else |
| 16 | exit 0 |
| 17 | fi |
| 18 | |
| 19 | if [ ! -x "$WPA_SUP_BIN" ]; then |
| 20 | |
| 21 | if [ "$VERBOSITY" = "1" ]; then |
| 22 | echo "$WPA_SUP_PNAME: binaries not executable or missing from $WPA_SUP_BIN" |
| 23 | fi |
| 24 | |
| 25 | exit 1 |
| 26 | fi |
| 27 | |
| 28 | if [ "$MODE" = "start" ] ; then |
| 29 | # driver type of interface, defaults to wext when undefined |
| 30 | if [ -s "/etc/wpa_supplicant/driver.$IFACE" ]; then |
| 31 | IF_WPA_DRIVER=$(cat "/etc/wpa_supplicant/driver.$IFACE") |
| 32 | elif [ -z "$IF_WPA_DRIVER" ]; then |
| 33 | |
| 34 | if [ "$VERBOSITY" = "1" ]; then |
| 35 | echo "$WPA_SUP_PNAME: wpa-driver not provided, using \"wext\"" |
| 36 | fi |
| 37 | |
| 38 | IF_WPA_DRIVER="wext" |
| 39 | fi |
| 40 | |
| 41 | # if we have passed the criteria, start wpa_supplicant |
| 42 | if [ -n "$WPA_SUP_CONF" ]; then |
| 43 | |
| 44 | if [ "$VERBOSITY" = "1" ]; then |
| 45 | echo "$WPA_SUP_PNAME: $WPA_SUP_BIN $WPA_SUP_OPTIONS $WPA_SUP_CONF -D $IF_WPA_DRIVER" |
| 46 | fi |
| 47 | |
| 48 | start-stop-daemon --start --quiet \ |
| 49 | --name $WPA_SUP_PNAME --startas $WPA_SUP_BIN --pidfile $WPA_SUP_PIDFILE \ |
| 50 | -- $WPA_SUP_OPTIONS $WPA_SUP_CONF -D $IF_WPA_DRIVER |
| 51 | fi |
| 52 | |
| 53 | # if the interface socket exists, then wpa_supplicant was invoked successfully |
| 54 | if [ -S "$WPA_COMMON_CTRL_IFACE/$IFACE" ]; then |
| 55 | |
| 56 | if [ "$VERBOSITY" = "1" ]; then |
| 57 | echo "$WPA_SUP_PNAME: ctrl_interface socket located at $WPA_COMMON_CTRL_IFACE/$IFACE" |
| 58 | fi |
| 59 | |
| 60 | exit 0 |
| 61 | |
| 62 | fi |
| 63 | |
| 64 | elif [ "$MODE" = "stop" ]; then |
| 65 | |
| 66 | if [ -f "$WPA_SUP_PIDFILE" ]; then |
| 67 | |
| 68 | if [ "$VERBOSITY" = "1" ]; then |
| 69 | echo "$WPA_SUP_PNAME: terminating $WPA_SUP_PNAME daemon" |
| 70 | fi |
| 71 | |
| 72 | start-stop-daemon --stop --quiet \ |
| 73 | --name $WPA_SUP_PNAME --pidfile $WPA_SUP_PIDFILE |
| 74 | |
| 75 | if [ -S "$WPA_COMMON_CTRL_IFACE/$IFACE" ]; then |
| 76 | rm -f $WPA_COMMON_CTRL_IFACE/$IFACE |
| 77 | fi |
| 78 | |
| 79 | if [ -f "$WPA_SUP_PIDFILE" ]; then |
| 80 | rm -f $WPA_SUP_PIDFILE |
| 81 | fi |
| 82 | fi |
| 83 | |
| 84 | fi |
| 85 | |
| 86 | exit 0 |