]> git.ipfire.org Git - people/ms/network.git/blob - src/functions/functions.wpa_supplicant
hotplug: Do not attempt to remove the special ip6gre0 device
[people/ms/network.git] / src / functions / functions.wpa_supplicant
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
22 WPA_SUPPLICANT_SOCKET_DIR="${RUN_DIR}/wpa_supplicant/ctrl"
23
24 wpa_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
31 local country="$(wireless_get_reg_domain)"
32 if isset country; then
33 print "country=${country}"
34 fi
35 print
36
37 print "# Privacy"
38
39 # Use a random MAC address for any pre-association
40 # operations like scanning or ANQP
41 print "preassoc_mac_addr=1"
42
43 print # end of header
44 }
45
46 wpa_supplicant_config_destroy() {
47 local device="${1}"
48 assert isset device
49
50 file_delete "${WPA_SUPPLICANT_CONF_DIR}/${device}.conf"
51 }
52
53 wpa_supplicant_start() {
54 local device=${1}
55 assert isset device
56
57 service_start "wpa_supplicant@${device}.service"
58 }
59
60 wpa_supplicant_stop() {
61 local device=${1}
62 assert isset device
63
64 service_stop "wpa_supplicant@${device}.service"
65 }
66
67 wpa_supplicant_client() {
68 local device=${1}
69 assert isset device
70 shift
71
72 local cmd="$@"
73 assert isset cmd
74
75 # Run the command and return the output.
76 cmd wpa_cli -p${WPA_SUPPLICANT_SOCKET_DIR} -i${device} ${cmd}
77 }
78
79 wpa_cli_status() {
80 local device=${1}
81 assert isset device
82
83 wpa_supplicant_client ${device} status verbose
84 }
85
86 wpa_cli_status_get() {
87 local device=${1}
88 assert isset device
89
90 local arg=${2}
91 assert isset arg
92
93 local line key
94 while read -r line; do
95 key=$(cli_get_key ${line})
96
97 if [ "${key}" = "${arg}" ]; then
98 cli_get_val "${line}"
99 return ${EXIT_OK}
100 fi
101 done <<< "$(wpa_cli_status ${device})"
102
103 return ${EXIT_ERROR}
104 }
105
106 wpa_cli_bss() {
107 local device=${1}
108 assert isset device
109
110 local bss=${2}
111 assert isset bss
112
113 wpa_supplicant_client ${device} bss ${bss}
114 }
115
116 wpa_cli_bss_get() {
117 local device=${1}
118 assert isset device
119
120 local bss=${2}
121 assert isset bss
122
123 local arg=${3}
124 assert isset arg
125
126 local line key
127 while read -r line; do
128 key=$(cli_get_key ${line})
129
130 if [ "${key}" = "${arg}" ]; then
131 cli_get_val "${line}"
132 return ${EXIT_OK}
133 fi
134 done <<< "$(wpa_cli_bss ${device} ${bss})"
135
136 return ${EXIT_ERROR}
137 }
138
139 wpa_cli_bss_get_frequency() {
140 local device=${1}
141 assert isset device
142
143 local bssid=${2}
144 assert isset bssid
145
146 wpa_cli_bss_get ${device} ${bssid} freq
147 }
148
149 wpa_cli_bss_get_noise() {
150 local device=${1}
151 assert isset device
152
153 local bssid=${2}
154 assert isset bssid
155
156 wpa_cli_bss_get ${device} ${bssid} noise
157 }
158
159 wpa_cli_bss_get_quality() {
160 local device=${1}
161 assert isset device
162
163 local bssid=${2}
164 assert isset bssid
165
166 local quality=$(wpa_cli_bss_get ${device} ${bssid} qual)
167
168 # Convert to percent
169 print $(( ${quality} * 100 / 70 ))
170 }
171
172 wpa_cli_bss_get_flags() {
173 local device=${1}
174 assert isset device
175
176 local bssid=${2}
177 assert isset bssid
178
179 wpa_cli_bss_get ${device} ${bssid} flags
180 }