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 function wireless_create
() {
31 while [ $# -gt 0 ]; do
34 address
=$
(cli_get_val
${1})
37 phy
=$
(cli_get_val
${1})
41 type=$
(cli_get_val
${1})
44 [ "${type}" = "ap" ] && type="__ap"
47 error
"Unrecognized argument: ${1}"
54 assert isoneof
type ibss managed __ap
55 assert phy_exists
${phy}
56 isset address || address
=$
(mac_generate
)
58 cmd_quiet iw phy
${phy} interface add ${device} type ${type}
61 if [ ${ret} -eq ${EXIT_OK} ]; then
62 log DEBUG
"created wireless device '${device}' (${type})"
64 if isset address
; then
65 device_set_address
${device} ${address}
68 log ERROR
"could not create wireless device '${device}' (${type}): ${ret}"
74 function wireless_remove
() {
78 if ! device_exists
${device}; then
82 # Tear down the device (if necessary).
83 device_set_down
${device}
86 cmd_quiet iw dev
${device} del
89 if [ ${ret} -eq ${EXIT_OK} ]; then
90 log DEBUG
"removed wireless device '${device}'"
92 log ERROR
"could not remove wireless device '${device}': ${ret}"
98 function wireless_channel_to_frequency
() {
99 # http://en.wikipedia.org/wiki/List_of_WLAN_channels
104 # Channel number must be positive.
105 assert
[ "${channel}" -gt 0 ]
110 print
"$(( 2407 + (${channel} * 5)))"
121 3[68]|
4[02468]|
5[26]|
6[04]|
10[048]|
11[26]|
12[048]|
13[26]|
14[09]|
15[37]|
16[15])
122 print
"$(( 5000 + (${channel} * 5)))"
130 function wireless_set_channel
() {
137 device_exists
${device} ||
return ${EXIT_ERROR}
139 cmd_quiet iw dev
${device} set channel
${channel}
142 function wireless_ibss_join
() {
151 while [ $# -gt 0 ]; do
154 bssid
="$(cli_get_val ${1})"
157 essid
="$(cli_get_val ${1})"
160 local channel
="$(cli_get_val ${1})"
162 # Save the frequency of the channel instead
163 # of the channel itself.
164 if isset channel
; then
165 frequency
="$(wireless_channel_to_frequency ${channel})"
175 assert isinteger frequency
178 device_set_up
"${device}"
180 log INFO
"${device} joining ibss network: ${essid} (${bssid})"
181 cmd_quiet iw dev
"${device}" ibss
join "${essid}" \
182 "${frequency}" fixed-freq
"${bssid}"
185 function wireless_ibss_leave
() {
189 log INFO
"${device} leaving ibss network"
190 cmd_quiet iw dev
"${device}" ibss leave
193 function wireless_is_radar_frequency
() {
194 local frequency
="${1}"
195 assert isset frequency
197 [[ ${frequency} -ge 5260 ]] && [[ ${frequency} -le 5700 ]]