Remove building with NOCRYPTO option
[minix3.git] / external / bsd / dhcpcd / dist / dhcpcd-hooks / 10-wpa_supplicant
bloba3fa0e8403a770eaa6a628d62f3d2b3742c50a0b
1 # $NetBSD: 10-wpa_supplicant,v 1.6 2014/11/07 20:51:03 roy Exp $
3 # Start, reconfigure and stop wpa_supplicant per wireless interface.
4 # This is needed because wpa_supplicant lacks hotplugging of any kind
5 # and the user should not be expected to have to wire it into their system
6 # if the base system doesn't do this itself.
8 if [ -z "$wpa_supplicant_conf" ]; then
9         for x in \
10                 /etc/wpa_supplicant/wpa_supplicant-"$interface".conf \
11                 /etc/wpa_supplicant/wpa_supplicant.conf \
12                 /etc/wpa_supplicant-"$interface".conf \
13                 /etc/wpa_supplicant.conf \
14         ; do
15                 if [ -s "$x" ]; then
16                         wpa_supplicant_conf="$x"
17                         break
18                 fi
19         done
21 : ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf}
23 wpa_supplicant_ctrldir()
25         local dir
27         dir=$(key_get_value "[[:space:]]*ctrl_interface=" \
28                 "$wpa_supplicant_conf")
29         dir=$(trim "$dir")
30         case "$dir" in
31         DIR=*)
32                 dir=${dir##DIR=}
33                 dir=${dir%%[[:space:]]GROUP=*}
34                 dir=$(trim "$dir")
35                 ;;
36         esac
37         printf %s "$dir"
40 wpa_supplicant_start()
42         local dir err errn
44         # If the carrier is up, don't bother checking anything
45         [ "$ifcarrier" = "up" ] && return 0
47         # Pre flight checks
48         if [ ! -s "$wpa_supplicant_conf" ]; then
49                 syslog warn \
50                         "$wpa_supplicant_conf does not exist"
51                 syslog warn "not interacting with wpa_supplicant(8)"
52                 return 1
53         fi
54         dir=$(wpa_supplicant_ctrldir)
55         if [ -z "$dir" ]; then
56                 syslog warn \
57                         "ctrl_interface not defined in $wpa_supplicant_conf"
58                 syslog warn "not interacting with wpa_supplicant(8)"
59                 return 1
60         fi
62         wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 && return 0
63         syslog info "starting wpa_supplicant"
64         driver=${wpa_supplicant_driver:+-D}$wpa_supplicant_driver
65         err=$(wpa_supplicant -B -c"$wpa_supplicant_conf" -i"$interface" \
66             "$driver" 2>&1)
67         errn=$?
68         if [ $errn != 0 ]; then
69                 syslog err "failed to start wpa_supplicant"
70                 syslog err "$err"
71         fi
72         return $errn
75 wpa_supplicant_reconfigure()
77         local dir err errn
79         dir=$(wpa_supplicant_ctrldir)
80         [ -z "$dir" ] && return 1
81         if ! wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1; then
82                 wpa_supplicant_start
83                 return $?
84         fi
85         syslog info "reconfiguring wpa_supplicant"
86         err=$(wpa_cli -p "$dir" -i "$interface" reconfigure 2>&1)
87         errn=$?
88         if [ $errn != 0 ]; then
89                 syslog err "failed to reconfigure wpa_supplicant"
90                 syslog err "$err"
91         fi
92         return $errn
95 wpa_supplicant_stop()
97         local dir err errn
99         dir=$(wpa_supplicant_ctrldir)
100         [ -z "$dir" ] && return 1
101         wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1 || return 0
102         syslog info "stopping wpa_supplicant"
103         err=$(wpa_cli -i"$interface" terminate 2>&1)
104         errn=$?
105         if [ $errn != 0 ]; then
106                 syslog err "failed to start wpa_supplicant"
107                 syslog err "$err"
108         fi
109         return $errn
112 if [ "$ifwireless" = "1" ] && \
113     type wpa_supplicant >/dev/null 2>&1 && \
114     type wpa_cli >/dev/null 2>&1
115 then
116         case "$reason" in
117         PREINIT)        wpa_supplicant_start;;
118         RECONFIGURE)    wpa_supplicant_reconfigure;;
119         DEPARTED)       wpa_supplicant_stop;;
120         esac