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 function wireless_create
() {
35 while [ $# -gt 0 ]; do
38 address
=$
(cli_get_val
${1})
41 phy
=$
(cli_get_val
${1})
45 type=$
(cli_get_val
${1})
48 [ "${type}" = "ap" ] && type="__ap"
51 error
"Unrecognized argument: ${1}"
58 assert isoneof
type ibss managed __ap
59 assert phy_exists
${phy}
60 isset address || address
=$
(mac_generate
)
62 cmd_quiet iw phy
${phy} interface add ${device} type ${type}
65 if [ ${ret} -eq ${EXIT_OK} ]; then
66 log DEBUG
"created wireless device '${device}' (${type})"
68 if isset address
; then
69 device_set_address
${device} ${address}
72 log ERROR
"could not create wireless device '${device}' (${type}): ${ret}"
78 function wireless_remove
() {
82 if ! device_exists
${device}; then
86 # Tear down the device (if necessary).
87 device_set_down
${device}
90 cmd_quiet iw dev
${device} del
93 if [ ${ret} -eq ${EXIT_OK} ]; then
94 log DEBUG
"removed wireless device '${device}'"
96 log ERROR
"could not remove wireless device '${device}': ${ret}"
102 function wireless_get_reg_domain
() {
103 # Returns the country code for the wireless device.
104 # Defaults to 00 = world if unset.
105 print
"${WIRELESS_REGULATORY_DOMAIN:-00}"
108 function wireless_init_reg_domain
() {
109 local country_code
="$(wireless_get_reg_domain)"
111 wireless_set_reg_domain
"${country_code}" --no-reset
114 function wireless_set_reg_domain
() {
118 while [ $# -gt 0 ]; do
124 log ERROR
"Ignoring invalid option: ${1}"
133 assert isset country_code
135 # Before the wireless reg domain is set, it helps to reset to 00 first.
136 if enabled
reset; then
137 iw reg
set 00 &>/dev
/null
140 log INFO
"Setting wireless regulatory domain country to '${country_code}'"
141 iw reg
set "${country_code}"
144 function wireless_channel_to_frequency
() {
145 # http://en.wikipedia.org/wiki/List_of_WLAN_channels
150 # Channel number must be positive.
151 assert
[ "${channel}" -gt 0 ]
156 print
"$(( 2407 + (${channel} * 5)))"
167 3[68]|
4[02468]|
5[26]|
6[04]|
10[048]|
11[26]|
12[048]|
13[26]|
14[09]|
15[37]|
16[15])
168 print
"$(( 5000 + (${channel} * 5)))"
176 function wireless_set_channel
() {
183 device_exists
${device} ||
return ${EXIT_ERROR}
185 cmd_quiet iw dev
${device} set channel
${channel}
188 function wireless_ibss_join
() {
197 while [ $# -gt 0 ]; do
200 bssid
="$(cli_get_val ${1})"
203 essid
="$(cli_get_val ${1})"
206 local channel
="$(cli_get_val ${1})"
208 # Save the frequency of the channel instead
209 # of the channel itself.
210 if isset channel
; then
211 frequency
="$(wireless_channel_to_frequency ${channel})"
221 assert isinteger frequency
224 device_set_up
"${device}"
226 log INFO
"${device} joining ibss network: ${essid} (${bssid})"
227 cmd_quiet iw dev
"${device}" ibss
join "${essid}" \
228 "${frequency}" fixed-freq
"${bssid}"
231 function wireless_ibss_leave
() {
235 log INFO
"${device} leaving ibss network"
236 cmd_quiet iw dev
"${device}" ibss leave
239 function wireless_is_radar_frequency
() {
240 local frequency
="${1}"
241 assert isset frequency
243 [[ ${frequency} -ge 5260 ]] && [[ ${frequency} -le 5700 ]]