]> git.ipfire.org Git - people/stevee/network.git/blame - src/functions/functions.wpa_supplicant
wpa_supplicant: Drop complicated config generation function
[people/stevee/network.git] / src / functions / functions.wpa_supplicant
CommitLineData
6d4eec4c
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2012 IPFire Network Development Team #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
22a61046
MT
22WPA_SUPPLICANT_SOCKET_DIR="${RUN_DIR}/wpa_supplicant/ctrl"
23
f1b49125
MT
24wpa_supplicant_config_header() {
25 config_header "WPA supplicant configuration file"
26
27 # Set control socket directory.
28 print "ctrl_interface=${WPA_SUPPLICANT_SOCKET_DIR}"
29
30 # Honour country
b7ab3b4f 31 local country="$(wireless_get_reg_domain)"
f1b49125
MT
32 if isset country; then
33 print "country=${country}"
34 fi
35
36 print # end of header
37}
38
02807ad2
MT
39wpa_supplicant_config_destroy() {
40 local device="${1}"
41 assert isset device
42
231bce76 43 file_delete "${WPA_SUPPLICANT_CONF_DIR}/${device}.conf"
6d4eec4c
MT
44}
45
1c6a4e30 46wpa_supplicant_start() {
6d4eec4c 47 local device=${1}
22a61046 48 assert isset device
6d4eec4c 49
22a61046
MT
50 service_start "wpa_supplicant@${device}.service"
51}
6d4eec4c 52
1c6a4e30 53wpa_supplicant_stop() {
22a61046
MT
54 local device=${1}
55 assert isset device
6d4eec4c 56
22a61046
MT
57 service_stop "wpa_supplicant@${device}.service"
58}
59
1c6a4e30 60wpa_supplicant_client() {
22a61046
MT
61 local device=${1}
62 assert isset device
63 shift
6d4eec4c 64
22a61046
MT
65 local cmd="$@"
66 assert isset cmd
67
68 # Run the command and return the output.
69 cmd wpa_cli -p${WPA_SUPPLICANT_SOCKET_DIR} -i${device} ${cmd}
6d4eec4c
MT
70}
71
1c6a4e30 72wpa_cli_status() {
6d4eec4c 73 local device=${1}
22a61046
MT
74 assert isset device
75
76 wpa_supplicant_client ${device} status verbose
77}
6d4eec4c 78
1c6a4e30 79wpa_cli_status_get() {
22a61046 80 local device=${1}
6d4eec4c
MT
81 assert isset device
82
22a61046
MT
83 local arg=${2}
84 assert isset arg
6d4eec4c 85
22a61046
MT
86 local line key
87 while read -r line; do
88 key=$(cli_get_key ${line})
6d4eec4c 89
22a61046
MT
90 if [ "${key}" = "${arg}" ]; then
91 cli_get_val "${line}"
92 return ${EXIT_OK}
93 fi
94 done <<< "$(wpa_cli_status ${device})"
95
96 return ${EXIT_ERROR}
6d4eec4c
MT
97}
98
1c6a4e30 99wpa_cli_bss() {
6d4eec4c 100 local device=${1}
22a61046
MT
101 assert isset device
102
103 local bss=${2}
104 assert isset bss
6d4eec4c 105
22a61046
MT
106 wpa_supplicant_client ${device} bss ${bss}
107}
108
1c6a4e30 109wpa_cli_bss_get() {
22a61046 110 local device=${1}
6d4eec4c
MT
111 assert isset device
112
22a61046
MT
113 local bss=${2}
114 assert isset bss
6d4eec4c 115
22a61046
MT
116 local arg=${3}
117 assert isset arg
6d4eec4c 118
22a61046
MT
119 local line key
120 while read -r line; do
121 key=$(cli_get_key ${line})
122
123 if [ "${key}" = "${arg}" ]; then
124 cli_get_val "${line}"
125 return ${EXIT_OK}
126 fi
127 done <<< "$(wpa_cli_bss ${device} ${bss})"
128
129 return ${EXIT_ERROR}
6d4eec4c
MT
130}
131
1c6a4e30 132wpa_cli_bss_get_frequency() {
6d4eec4c 133 local device=${1}
6d4eec4c
MT
134 assert isset device
135
22a61046
MT
136 local bssid=${2}
137 assert isset bssid
6d4eec4c 138
22a61046
MT
139 wpa_cli_bss_get ${device} ${bssid} freq
140}
6d4eec4c 141
1c6a4e30 142wpa_cli_bss_get_noise() {
22a61046
MT
143 local device=${1}
144 assert isset device
145
146 local bssid=${2}
147 assert isset bssid
148
149 wpa_cli_bss_get ${device} ${bssid} noise
6d4eec4c
MT
150}
151
1c6a4e30 152wpa_cli_bss_get_quality() {
22a61046
MT
153 local device=${1}
154 assert isset device
6d4eec4c 155
22a61046
MT
156 local bssid=${2}
157 assert isset bssid
158
324c09bc
MT
159 local quality=$(wpa_cli_bss_get ${device} ${bssid} qual)
160
161 # Convert to percent
162 print $(( ${quality} * 100 / 70 ))
6d4eec4c
MT
163}
164
1c6a4e30 165wpa_cli_bss_get_flags() {
22a61046
MT
166 local device=${1}
167 assert isset device
168
169 local bssid=${2}
170 assert isset bssid
6d4eec4c 171
22a61046 172 wpa_cli_bss_get ${device} ${bssid} flags
6d4eec4c 173}