2 append DRIVERS
"mac80211"
7 local macaddr
="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
8 config_get phy
"$device" phy
9 [ -z "$phy" -a -n "$macaddr" ] && {
10 for phy
in $
(ls /sys
/class
/ieee80211
2>/dev
/null
); do
11 [ "$macaddr" = "$(cat /sys/class/ieee80211/${phy}/macaddress)" ] ||
continue
12 config_set
"$device" phy
"$phy"
15 config_get phy
"$device" phy
17 [ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] ||
{
18 echo "PHY for wifi device $1 not found"
21 [ -z "$macaddr" ] && {
22 config_set
"$device" macaddr
"$(cat /sys/class/ieee80211/${phy}/macaddress)"
29 local adhoc sta ap monitor mesh
31 config_get vifs
"$device" vifs
33 config_get mode
"$vif" mode
35 adhoc|sta|ap|monitor|mesh
)
38 *) echo "$device($vif): Invalid mode, ignored."; continue;;
42 config_set
"$device" vifs
"${ap:+$ap }${adhoc:+$adhoc }${sta:+$sta }${monitor:+$monitor }${mesh:+$mesh}"
49 find_mac80211_phy
"$device" ||
return 0
50 config_get phy
"$device" phy
52 set_wifi_down
"$device"
53 # kill all running hostapd and wpa_supplicant processes that
54 # are running on atheros/mac80211 vifs
55 for pid
in `pidof hostapd wpa_supplicant`; do
56 grep wlan
/proc
/$pid/cmdline
>/dev
/null
&& \
61 for wdev
in $
(ls /sys
/class
/ieee80211
/${phy}/device
/net
2>/dev
/null
); do
62 ifconfig
"$wdev" down
2>/dev
/null
72 iw
"$phy" info |
grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
76 config_get channel "$device" channel
77 config_get vifs "$device" vifs
78 config_get txpower "$device" txpower
79 find_mac80211_phy "$device" || return 0
80 config_get phy "$device" phy
84 [ "$channel" = "auto
" -o "$channel" = "0" ] || {
89 # convert channel to frequency
90 local freq="$
(get_freq
"$phy" "${fixed:+$channel}")"
92 wifi_fixup_hwmode "$device" "g
"
94 while [ -d "/sys
/class
/net
/wlan
$i" ]; do
98 config_get ifname "$vif" ifname
102 config_set "$vif" ifname "$ifname"
104 config_get enc "$vif" encryption
105 config_get mode "$vif" mode
106 config_get ssid "$vif" ssid
107 config_get_bool wds "$vif" wds 0
109 # It is far easier to delete and create the desired interface
112 iw phy "$phy" interface add "$ifname" type adhoc
115 # Hostapd will handle recreating the interface and
116 # it's accompanying monitor
117 iw phy "$phy" interface add "$ifname" type managed
120 config_get mesh_id "$vif" mesh_id
121 iw phy "$phy" interface add "$ifname" type mp mesh_id "$mesh_id"
124 iw phy "$phy" interface add "$ifname" type monitor
128 [ "$wds" -gt 0 ] && wdsflag="4addr on
"
129 iw phy "$phy" interface add "$ifname" type managed $wdsflag
130 config_get_bool powersave "$vif" powersave 0
131 [ "$powersave" -gt 0 ] && powersave="on
" || powersave="off
"
132 iwconfig "$ifname" power "$powersave"
136 # All interfaces must have unique mac addresses
137 # which can either be explicitly set in the device
138 # section, or automatically generated
139 config_get macaddr "$device" macaddr
140 local mac_1="${macaddr%%:*}"
141 local mac_2="${macaddr#*:}"
143 config_get vif_mac "$vif" macaddr
144 [ -n "$vif_mac" ] || {
145 if [ "$i" -gt 0 ]; then
146 offset="$
(( 2 + $i * 4 ))"
150 vif_mac="$
( printf %02x $
(($mac_1 + $offset)) ):$mac_2"
152 ifconfig "$ifname" hw ether "$vif_mac"
154 # We attempt to set teh channel for all interfaces, although
155 # mac80211 may not support it or the driver might not yet
156 [ -n "$fixed" -a -n "$channel" ] && iw dev "$ifname" set channel "$channel"
165 # ALL ap functionality will be passed to hostapd
167 # !! mesh / adhoc / station !!
168 # none -> NO encryption
170 # wep + keymgmt = '' -> we use iw to connect to the
173 # wep + keymgmt = 'NONE' -> wpa_supplicant will be
174 # configured to handle the wep connection
175 if [ ! "$mode" = "ap
" ]; then
178 config_get keymgmt "$vif" keymgmt
179 if [ -e "$keymgmt" ]; then
180 for idx in 1 2 3 4; do
183 config_get key "$vif" "key
${idx}"
184 if [ -n "$key" ]; then
185 append keystring "${zidx}:${key} "
191 config_get key "$vif" key
196 # txpower is not yet implemented in iw
197 config_get vif_txpower "$vif" txpower
198 # use vif_txpower (from wifi-iface) to override txpower (from
199 # wifi-device) if the latter doesn't exist
200 txpower="${txpower:-$vif_txpower}"
201 [ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
203 config_get frag "$vif" frag
204 if [ -n "$frag" ]; then
205 iw phy "$phy" set frag "${frag%%.*}"
208 config_get rts "$vif" rts
209 if [ -n "$rts" ]; then
210 iw phy "$phy" set rts "${frag%%.*}"
213 ifconfig "$ifname" up
216 net_cfg="$
(find_net_config
"$vif")"
217 [ -z "$net_cfg" ] || {
218 bridge="$
(bridge_interface
"$net_cfg")"
219 config_set "$vif" bridge "$bridge"
220 start_net "$ifname" "$net_cfg"
223 set_wifi_up "$vif" "$ifname"
226 if eval "type hostapd_setup_vif
" 2>/dev/null >/dev/null; then
227 hostapd_setup_vif "$vif" nl80211 || {
228 echo "enable_mac80211
($device): Failed to
set up wpa
for interface
$ifname" >&2
229 # make sure this wifi interface won't accidentally stay open without encryption
230 ifconfig "$ifname" down
236 config_get bssid "$vif" bssid
237 iw dev "$ifname" ibss join "$ssid" $freq ${fixed:+fixed-freq} $bssid
240 config_get bssid "$vif" bssid
243 if [ -e "$keymgmt" ]; then
244 [ -n "$keystring" ] &&
245 iw dev "$ifname" connect "$ssid" ${fixed:+$freq} $bssid key "$keystring"
247 if eval "type wpa_supplicant_setup_vif
" 2>/dev/null >/dev/null; then
248 wpa_supplicant_setup_vif "$vif" wext || {
249 echo "enable_mac80211
($device): Failed to
set up wpa_supplicant
for interface
$ifname" >&2
250 # make sure this wifi interface won't accidentally stay open without encryption
251 ifconfig "$ifname" down
258 config_get key "$vif" key
259 if eval "type wpa_supplicant_setup_vif
" 2>/dev/null >/dev/null; then
260 wpa_supplicant_setup_vif "$vif" wext || {
261 echo "enable_mac80211
($device): Failed to
set up wpa_supplicant
for interface
$ifname" >&2
262 # make sure this wifi interface won't accidentally stay open without encryption
263 ifconfig "$ifname" down
269 iw dev "$ifname" connect "$ssid" ${fixed:+$freq} $bssid
280 config_get phy "$1" phy
282 find_mac80211_phy "$1" || return 0
283 config_get phy "$1" phy
285 [ "$phy" = "$dev" ] && found=1
292 config_get type "radio
$devidx" type
293 [ -n "$type" ] || break
294 devidx=$(($devidx + 1))
296 for dev in $(ls /sys/class/ieee80211); do
298 config_foreach check_device wifi-device
299 [ "$found" -gt 0 ] && continue
305 for cap in $(iw phy "$dev" info | grep 'HT capabilities' | cut -d: -f2); do
306 ht_cap="$
(($ht_cap |
$cap))"
309 [ "$ht_cap" -gt 0 ] && {
311 list=" list ht_capab
"
312 [ "$
(($ht_cap & 1))" -eq 1 ] && append ht_capab "$list LDPC
" "$N"
313 [ "$
(($ht_cap & 2))" -eq 2 ] && append ht_capab "$list HT40-
" "$N"
314 [ "$
(($ht_cap & 32))" -eq 32 ] && append ht_capab "$list SHORT-GI-20
" "$N"
315 [ "$
(($ht_cap & 64))" -eq 64 ] && append ht_capab "$list SHORT-GI-40
" "$N"
316 [ "$
(($ht_cap & 4096))" -eq 4096 ] && append ht_capab "$list DSSS_CCK-40
" "$N"
318 iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a
"; channel="36"; }
321 config wifi-device radio$devidx
323 option channel ${channel}
324 option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
325 option hwmode 11${mode_11n}${mode_band}
326 # REMOVE THIS LINE TO ENABLE WIFI:
331 option device radio$devidx
335 option encryption none
338 devidx=$(($devidx + 1))