2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2012 IPFire Network Development Team #
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 ###############################################################################
22 # Sets the global wireless country code. Default is 00 = world.
23 WIRELESS_REGULATORY_DOMAIN
="00"
24 NETWORK_CONFIG_FILE_PARAMS
="${NETWORK_CONFIG_FILE_PARAMS} WIRELESS_REGULATORY_DOMAIN"
26 init_register wireless_init_reg_domain
28 function wireless_create
() {
37 while [ $# -gt 0 ]; do
40 address
=$
(cli_get_val
${1})
43 phy
=$
(cli_get_val
${1})
47 type=$
(cli_get_val
${1})
50 [ "${type}" = "ap" ] && type="__ap"
53 error
"Unrecognized argument: ${1}"
60 assert isoneof
type ibss managed __ap
61 assert phy_exists
${phy}
62 isset address || address
=$
(mac_generate
)
64 cmd_quiet iw phy
${phy} interface add ${device} type ${type}
67 if [ ${ret} -eq ${EXIT_OK} ]; then
68 log DEBUG
"created wireless device '${device}' (${type})"
70 if isset address
; then
71 device_set_address
${device} ${address}
74 log ERROR
"could not create wireless device '${device}' (${type}): ${ret}"
80 function wireless_remove
() {
84 if ! device_exists
${device}; then
88 # Tear down the device (if necessary).
89 device_set_down
${device}
92 cmd_quiet iw dev
${device} del
95 if [ ${ret} -eq ${EXIT_OK} ]; then
96 log DEBUG
"removed wireless device '${device}'"
98 log ERROR
"could not remove wireless device '${device}': ${ret}"
104 function wireless_get_reg_domain
() {
105 # Returns the country code for the wireless device.
106 # Defaults to 00 = world if unset.
107 print
"${WIRELESS_REGULATORY_DOMAIN:-00}"
110 function wireless_init_reg_domain
() {
111 local country_code
="$(wireless_get_reg_domain)"
113 wireless_set_reg_domain
"${country_code}"
116 function wireless_set_reg_domain
() {
117 local country_code
="${1}"
118 assert isset country_code
120 # Before the wireless reg domain is set, it helps to reset to 00 first.
121 iw reg
set 00 &>/dev
/null
123 log INFO
"Setting wireless regulatory domain country to '${country_code}'"
124 iw reg
set "${country_code}"
127 function wireless_channel_to_frequency
() {
128 # http://en.wikipedia.org/wiki/List_of_WLAN_channels
133 # Channel number must be positive.
134 assert
[ "${channel}" -gt 0 ]
139 print
"$(( 2407 + (${channel} * 5)))"
150 3[68]|
4[02468]|
5[26]|
6[04]|
10[048]|
11[26]|
12[048]|
13[26]|
14[09]|
15[37]|
16[15])
151 print
"$(( 5000 + (${channel} * 5)))"
159 function wireless_set_channel
() {
166 device_exists
${device} ||
return ${EXIT_ERROR}
168 cmd_quiet iw dev
${device} set channel
${channel}
171 function wireless_ibss_join
() {
180 while [ $# -gt 0 ]; do
183 bssid
="$(cli_get_val ${1})"
186 essid
="$(cli_get_val ${1})"
189 local channel
="$(cli_get_val ${1})"
191 # Save the frequency of the channel instead
192 # of the channel itself.
193 if isset channel
; then
194 frequency
="$(wireless_channel_to_frequency ${channel})"
204 assert isinteger frequency
207 device_set_up
"${device}"
209 log INFO
"${device} joining ibss network: ${essid} (${bssid})"
210 cmd_quiet iw dev
"${device}" ibss
join "${essid}" \
211 "${frequency}" fixed-freq
"${bssid}"
214 function wireless_ibss_leave
() {
218 log INFO
"${device} leaving ibss network"
219 cmd_quiet iw dev
"${device}" ibss leave
222 function wireless_is_radar_frequency
() {
223 local frequency
="${1}"
224 assert isset frequency
226 [[ ${frequency} -ge 5260 ]] && [[ ${frequency} -le 5700 ]]