]> git.ipfire.org Git - people/ms/network.git/blob - src/functions/functions.wpa_supplicant
7362601cda10d315f943e979037826c1f6767154
[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
36 print # end of header
37 }
38
39 wpa_supplicant_config_destroy() {
40 local device="${1}"
41 assert isset device
42
43 file_delete "${WPA_SUPPLICANT_CONF_DIR}/${device}.conf"
44 }
45
46 wpa_supplicant_start() {
47 local device=${1}
48 assert isset device
49
50 service_start "wpa_supplicant@${device}.service"
51 }
52
53 wpa_supplicant_stop() {
54 local device=${1}
55 assert isset device
56
57 service_stop "wpa_supplicant@${device}.service"
58 }
59
60 wpa_supplicant_client() {
61 local device=${1}
62 assert isset device
63 shift
64
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}
70 }
71
72 wpa_cli_status() {
73 local device=${1}
74 assert isset device
75
76 wpa_supplicant_client ${device} status verbose
77 }
78
79 wpa_cli_status_get() {
80 local device=${1}
81 assert isset device
82
83 local arg=${2}
84 assert isset arg
85
86 local line key
87 while read -r line; do
88 key=$(cli_get_key ${line})
89
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}
97 }
98
99 wpa_cli_bss() {
100 local device=${1}
101 assert isset device
102
103 local bss=${2}
104 assert isset bss
105
106 wpa_supplicant_client ${device} bss ${bss}
107 }
108
109 wpa_cli_bss_get() {
110 local device=${1}
111 assert isset device
112
113 local bss=${2}
114 assert isset bss
115
116 local arg=${3}
117 assert isset arg
118
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}
130 }
131
132 wpa_cli_bss_get_frequency() {
133 local device=${1}
134 assert isset device
135
136 local bssid=${2}
137 assert isset bssid
138
139 wpa_cli_bss_get ${device} ${bssid} freq
140 }
141
142 wpa_cli_bss_get_noise() {
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
150 }
151
152 wpa_cli_bss_get_quality() {
153 local device=${1}
154 assert isset device
155
156 local bssid=${2}
157 assert isset bssid
158
159 local quality=$(wpa_cli_bss_get ${device} ${bssid} qual)
160
161 # Convert to percent
162 print $(( ${quality} * 100 / 70 ))
163 }
164
165 wpa_cli_bss_get_flags() {
166 local device=${1}
167 assert isset device
168
169 local bssid=${2}
170 assert isset bssid
171
172 wpa_cli_bss_get ${device} ${bssid} flags
173 }