2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
25 eval $
(/usr
/local
/bin
/readhash
/var
/ipfire
/ethernet
/settings
)
27 WIRELESS_CONFIG
="/var/ipfire/ethernet/wireless"
29 function device_is_wireless
() {
32 if [ -d "/sys/class/net/${device}/wireless" ]; then
39 function wpa_supplicant_make_config
() {
44 # Check if device is wireless.
45 local wireless
="false"
46 if device_is_wireless
${device}; then
50 # Write a configuration file header.
53 echo "# THIS FILE IS AUTOMATICALLY GENERATED AND"
54 echo "# ANY CUSTOM CHANGES WILL BE OVERWRITTEN!"
57 echo "ctrl_interface=/var/run/wpa_supplicant"
64 while IFS
="," read -ra line
; do
65 # Skip commented lines.
66 [ "${line:0:1}" = "#" ] && continue
68 # Skip disabled entries.
69 [ "${line[2]}" = "on" ] ||
continue
71 wpa_supplicant_config_line \
73 --wireless="${wireless}" \
75 --wpa-mode="${line[4]}" \
78 --priority="${line[7]}" \
79 --auth-mode="${line[8]}" \
80 --anonymous-identity="${line[9]}" \
81 --identity="${line[10]}" \
82 --password="${line[11]}"
84 items
=$
(( ${items} + 1 ))
86 done < ${WIRELESS_CONFIG}
88 # Return exit code 2, when there are no entries in the
90 if [ "${items}" = "0" ]; then
97 function wpa_supplicant_config_line
() {
103 local anonymous_identity
118 local wireless
="true"
121 while [ $# -gt 0 ]; do
123 --anonymous-identity=*)
124 anonymous_identity
=${1#--anonymous-identity=}
127 auth_mode
=${1#--auth-mode=}
130 identity
=${1#--identity=}
136 password
=${1#--password=}
139 priority
=${1#--priority=}
148 wireless
=${1#--wireless=}
151 wpa_mode
=${1#--wpa-mode=}
159 key_mgmt
="WPA-EAP-SHA256 WPA-EAP"
169 key_mgmt
="WPA-PSK-SHA256 WPA-PSK"
174 key_mgmt
="WPA-PSK-SHA256 WPA-PSK"
194 if [ "${mode}" = "EAP" -o "${mode}" = "WPA" -o "${mode}" = "WPA2" ]; then
195 case "${wpa_mode}" in
218 if [ -n "${ssid}" ]; then
219 echo " ssid=\"${ssid}\""
221 if [ "${wireless}" = "true" ]; then
224 if [ -n "${auth_alg}" ]; then
225 echo " auth_alg=${auth_alg}"
227 if [ -n "${key_mgmt}" ]; then
228 echo " key_mgmt=${key_mgmt}"
230 if [ -n "${psk}" ]; then
231 if [ "${key_mgmt}" = "SAE" ]; then
232 echo " sae_password=\"${psk}\""
234 echo " psk=\"${psk}\""
237 if [ -n "${wep_tx_keyidx}" ]; then
238 echo " wep_tx_keyidx=${wep_tx_keyidx}"
240 if [ -n "${wep_key0}" ]; then
241 echo " wep_key0=\"${wep_key0}\""
243 if [ -n "${proto}" ]; then
244 echo " proto=${proto}"
246 if [ -n "${pairwise}" -a -n "${group}" ]; then
247 echo " pairwise=${pairwise}"
248 echo " group=${group}"
250 if [ -n "${priority}" ]; then
251 echo " priority=${priority}"
253 if [ -n "${ieee80211w}" ]; then
254 echo " ieee80211w=${ieee80211w}"
258 if [ "${mode}" = "EAP" ]; then
259 if [ -n "${auth_mode}" ]; then
260 echo " eap=${auth_mode}"
262 echo " eap=PEAP TTLS"
265 if [ "${auth_mode}" = "TTLS" -a -n "${anonymous_identity}" ]; then
266 echo " anonymous_identity=\"${anonymous_identity}\""
269 if [ -n "${identity}" -a -n "${password}" ]; then
270 echo " identity=\"${identity}\""
271 echo " password=\"${password}\""
280 function wpa_supplicant_start
() {
282 local config
="/etc/wpa_supplicant.conf"
284 # Write configuration file.
285 wpa_supplicant_make_config
${device} ${config}
286 [ $?
-eq 0 ] ||
return 0
288 # Build wpa_supplicant command line.
289 local wpa_suppl_cmd
="wpa_supplicant -B -qqq -i${device} -c${config}"
291 if ! device_is_wireless
${device}; then
292 wpa_suppl_cmd
="${wpa_suppl_cmd} -Dwired"
296 boot_mesg
"Starting wireless client on ${RED_DEV}..."
297 loadproc
${wpa_suppl_cmd}
299 # Run wpa_cli to handle reconnection events.
300 boot_mesg
"Starting wireless event handler on ${RED_DEV}..."
301 wpa_cli
-B -a /etc
/rc.d
/init.d
/networking
/wpa_supplicant.exe
304 function wpa_supplicant_stop
() {
305 boot_mesg
"Stopping wireless event handler on ${RED_DEV}..."
308 # wpa_cli does not send a disconnect event when get stopped.
309 # So we manually have to send it to the wpa_supplicant.exe.
310 /etc
/rc.d
/init.d
/networking
/wpa_supplicant.exe
"${RED_DEV}" DISCONNECTED
312 boot_mesg
"Stopping wireless client on ${RED_DEV}..."
313 killproc wpa_supplicant
315 # Tidy up /tmp directory.
316 rm -f /tmp
/wpa_ctrl_
*
321 if [ -n "${RED_DEV}" ] && device_is_wireless
${RED_DEV}; then
322 wpa_supplicant_start
${RED_DEV}
327 if [ -n "${RED_DEV}" ] && device_is_wireless
${RED_DEV}; then
339 statusproc wpa_supplicant
343 echo "Usage: ${0} {start|stop|restart|status}"