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
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 \
16 wpa_supplicant_conf="$x"
21 : ${wpa_supplicant_conf:=/etc/wpa_supplicant.conf}
23 wpa_supplicant_ctrldir()
27 dir=$(key_get_value "[[:space:]]*ctrl_interface=" \
28 "$wpa_supplicant_conf")
33 dir=${dir%%[[:space:]]GROUP=*}
40 wpa_supplicant_start()
44 # If the carrier is up, don't bother checking anything
45 [ "$ifcarrier" = "up" ] && return 0
48 if [ ! -s "$wpa_supplicant_conf" ]; then
50 "$wpa_supplicant_conf does not exist"
51 syslog warn "not interacting with wpa_supplicant(8)"
54 dir=$(wpa_supplicant_ctrldir)
55 if [ -z "$dir" ]; then
57 "ctrl_interface not defined in $wpa_supplicant_conf"
58 syslog warn "not interacting with wpa_supplicant(8)"
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" \
68 if [ $errn != 0 ]; then
69 syslog err "failed to start wpa_supplicant"
75 wpa_supplicant_reconfigure()
79 dir=$(wpa_supplicant_ctrldir)
80 [ -z "$dir" ] && return 1
81 if ! wpa_cli -p "$dir" -i "$interface" status >/dev/null 2>&1; then
85 syslog info "reconfiguring wpa_supplicant"
86 err=$(wpa_cli -p "$dir" -i "$interface" reconfigure 2>&1)
88 if [ $errn != 0 ]; then
89 syslog err "failed to reconfigure wpa_supplicant"
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)
105 if [ $errn != 0 ]; then
106 syslog err "failed to start wpa_supplicant"
112 if [ "$ifwireless" = "1" ] && \
113 type wpa_supplicant >/dev/null 2>&1 && \
114 type wpa_cli >/dev/null 2>&1
117 PREINIT) wpa_supplicant_start;;
118 RECONFIGURE) wpa_supplicant_reconfigure;;
119 DEPARTED) wpa_supplicant_stop;;