Project:
IPFire
Code Location:
git://git.ipfire.org/network.gitmaster
/
functions.wireless
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash ############################################################################### # # # IPFire.org - A linux based firewall # # Copyright (C) 2012 IPFire Network Development Team # # # # This program is free software: you can redistribute it and/or modify # # it under the terms of the GNU General Public License as published by # # the Free Software Foundation, either version 3 of the License, or # # (at your option) any later version. # # # # This program is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU General Public License for more details. # # # # You should have received a copy of the GNU General Public License # # along with this program. If not, see <http://www.gnu.org/licenses/>. # # # ############################################################################### function wireless_create() { local device=${1} assert isset device shift local address local phy local type="managed" while [ $# -gt 0 ]; do case "${1}" in --address=*) address=$(cli_get_val ${1}) ;; --phy=*) phy=$(cli_get_val ${1}) phy=$(phy_get ${phy}) ;; --type=*) type=$(cli_get_val ${1}) # ap --> __ap [ "${type}" = "ap" ] && type="__ap" ;; *) error "Unrecognized argument: ${1}" return ${EXIT_ERROR} ;; esac shift done assert isoneof type ibss managed __ap assert phy_exists ${phy} isset address || address=$(mac_generate) cmd_quiet iw phy ${phy} interface add ${device} type ${type} local ret=$? if [ ${ret} -eq ${EXIT_OK} ]; then log DEBUG "created wireless device '${device}' (${type})" if isset address; then device_set_address ${device} ${address} fi else log ERROR "could not create wireless device '${device}' (${type}): ${ret}" fi return ${ret} } function wireless_remove() { local device=${1} assert isset device if ! device_exists ${device}; then return ${EXIT_OK} fi # Tear down the device (if necessary). device_set_down ${device} # Remove it. cmd_quiet iw dev ${device} del local ret=$? if [ ${ret} -eq ${EXIT_OK} ]; then log DEBUG "removed wireless device '${device}'" else log ERROR "could not remove wireless device '${device}': ${ret}" fi return ${ret} } function wireless_channel_to_frequency() { # http://en.wikipedia.org/wiki/List_of_WLAN_channels local channel=${1} assert isset channel # Channel number must be positive. assert [ "${channel}" -gt 0 ] # 2.4 GHz band case "${channel}" in [123456789]|1[0123]) print "$(( 2407 + (${channel} * 5)))" return ${EXIT_OK} ;; 14) print "2484" return ${EXIT_OK} ;; esac # 5 GHz band case "${channel}" in 3[68]|4[02468]|5[26]|6[04]|10[048]|11[26]|12[048]|13[26]|14[09]|15[37]|16[15]) print "$(( 5000 + (${channel} * 5)))" return ${EXIT_OK} ;; esac return ${EXIT_ERROR} } function wireless_set_channel() { local device=${1} assert isset device local channel=${2} assert isset channel device_exists ${device} || return ${EXIT_ERROR} cmd_quiet iw dev ${device} set channel ${channel} } function wireless_ibss_join() { local device=${1} assert isset device shift local bssid local essid local frequency while [ $# -gt 0 ]; do case "${1}" in --bssid=*) bssid="$(cli_get_val ${1})" ;; --essid=*) essid="$(cli_get_val ${1})" ;; --channel=*) local channel="$(cli_get_val ${1})" # Save the frequency of the channel instead # of the channel itself. if isset channel; then frequency="$(wireless_channel_to_frequency ${channel})" fi ;; esac shift done # Check input. assert ismac bssid assert isset essid assert isinteger frequency # Set device up. device_set_up "${device}" log INFO "${device} joining ibss network: ${essid} (${bssid})" cmd_quiet iw dev "${device}" ibss join "${essid}" \ "${frequency}" fixed-freq "${bssid}" } function wireless_ibss_leave() { local device=${1} assert isset device log INFO "${device} leaving ibss network" cmd_quiet iw dev "${device}" ibss leave }
