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 config_get country "$device" country
80 config_get distance "$device" distance
81 find_mac80211_phy "$device" || return 0
82 config_get phy "$device" phy
87 [ -n "$country" ] && iw reg set "$country"
88 [ "$channel" = "auto
" -o "$channel" = "0" ] || {
92 [ -n "$distance" ] && iw phy "$phy" set distance "$distance"
95 # convert channel to frequency
96 local freq="$
(get_freq
"$phy" "${fixed:+$channel}")"
98 wifi_fixup_hwmode "$device" "g
"
100 while [ -d "/sys
/class
/net
/wlan
$i" ]; do
104 config_get ifname "$vif" ifname
105 [ -n "$ifname" ] || {
108 config_set "$vif" ifname "$ifname"
110 config_get enc "$vif" encryption
111 config_get mode "$vif" mode
112 config_get ssid "$vif" ssid
113 config_get_bool wds "$vif" wds 0
115 # It is far easier to delete and create the desired interface
118 iw phy "$phy" interface add "$ifname" type adhoc
121 # Hostapd will handle recreating the interface and
122 # it's accompanying monitor
123 iw phy "$phy" interface add "$ifname" type managed
126 config_get mesh_id "$vif" mesh_id
127 iw phy "$phy" interface add "$ifname" type mp mesh_id "$mesh_id"
130 iw phy "$phy" interface add "$ifname" type monitor
134 [ "$wds" -gt 0 ] && wdsflag="4addr on
"
135 iw phy "$phy" interface add "$ifname" type managed $wdsflag
136 config_get_bool powersave "$vif" powersave 0
137 [ "$powersave" -gt 0 ] && powersave="on
" || powersave="off
"
138 iwconfig "$ifname" power "$powersave"
142 # All interfaces must have unique mac addresses
143 # which can either be explicitly set in the device
144 # section, or automatically generated
145 config_get macaddr "$device" macaddr
146 local mac_1="${macaddr%%:*}"
147 local mac_2="${macaddr#*:}"
149 config_get vif_mac "$vif" macaddr
150 [ -n "$vif_mac" ] || {
151 if [ "$macidx" -gt 0 ]; then
152 offset="$
(( 2 + $macidx * 4 ))"
156 vif_mac="$
( printf %02x $
((0x
$mac_1 + $offset)) ):$mac_2"
157 macidx="$
(($macidx + 1))"
159 ifconfig "$ifname" hw ether "$vif_mac"
161 # We attempt to set teh channel for all interfaces, although
162 # mac80211 may not support it or the driver might not yet
163 [ -n "$fixed" -a -n "$channel" ] && iw dev "$ifname" set channel "$channel"
172 # ALL ap functionality will be passed to hostapd
174 # !! mesh / adhoc / station !!
175 # none -> NO encryption
177 # wep + keymgmt = '' -> we use iw to connect to the
180 # wep + keymgmt = 'NONE' -> wpa_supplicant will be
181 # configured to handle the wep connection
182 if [ ! "$mode" = "ap
" ]; then
185 config_get keymgmt "$vif" keymgmt
186 if [ -z "$keymgmt" ]; then
187 config_get key "$vif" key
191 for idx in 1 2 3 4; do
194 config_get ckey "$vif" "key
${idx}"
195 if [ -n "$ckey" ]; then
196 [ $idx -eq $key ] && zidx="d
:${zidx}"
197 append keystring "${zidx}:$
(prepare_key_wep
"$ckey")"
202 keystring="d
:0:$
(prepare_key_wep
"$key")"
208 config_get key "$vif" key
213 # txpower is not yet implemented in iw
214 config_get vif_txpower "$vif" txpower
215 # use vif_txpower (from wifi-iface) to override txpower (from
216 # wifi-device) if the latter doesn't exist
217 txpower="${txpower:-$vif_txpower}"
218 [ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
220 config_get frag "$vif" frag
221 if [ -n "$frag" ]; then
222 iw phy "$phy" set frag "${frag%%.*}"
225 config_get rts "$vif" rts
226 if [ -n "$rts" ]; then
227 iw phy "$phy" set rts "${rts%%.*}"
230 ifconfig "$ifname" up
233 net_cfg="$
(find_net_config
"$vif")"
234 [ -z "$net_cfg" ] || {
235 bridge="$
(bridge_interface
"$net_cfg")"
236 config_set "$vif" bridge "$bridge"
237 start_net "$ifname" "$net_cfg"
240 set_wifi_up "$vif" "$ifname"
243 if eval "type hostapd_setup_vif
" 2>/dev/null >/dev/null; then
244 hostapd_setup_vif "$vif" nl80211 || {
245 echo "enable_mac80211
($device): Failed to
set up wpa
for interface
$ifname" >&2
246 # make sure this wifi interface won't accidentally stay open without encryption
247 ifconfig "$ifname" down
253 config_get bssid "$vif" bssid
254 iw dev "$ifname" ibss join "$ssid" $freq ${fixed:+fixed-freq} $bssid
257 config_get bssid "$vif" bssid
260 if [ -z "$keymgmt" ]; then
261 [ -n "$keystring" ] &&
262 iw dev "$ifname" connect "$ssid" ${fixed:+$freq} $bssid key $keystring
264 if eval "type wpa_supplicant_setup_vif
" 2>/dev/null >/dev/null; then
265 wpa_supplicant_setup_vif "$vif" wext || {
266 echo "enable_mac80211
($device): Failed to
set up wpa_supplicant
for interface
$ifname" >&2
267 # make sure this wifi interface won't accidentally stay open without encryption
268 ifconfig "$ifname" down
275 config_get key "$vif" key
276 if eval "type wpa_supplicant_setup_vif
" 2>/dev/null >/dev/null; then
277 wpa_supplicant_setup_vif "$vif" wext || {
278 echo "enable_mac80211
($device): Failed to
set up wpa_supplicant
for interface
$ifname" >&2
279 # make sure this wifi interface won't accidentally stay open without encryption
280 ifconfig "$ifname" down
286 iw dev "$ifname" connect "$ssid" ${fixed:+$freq} $bssid
297 config_get phy "$1" phy
299 find_mac80211_phy "$1" >/dev/null || return 0
300 config_get phy "$1" phy
302 [ "$phy" = "$dev" ] && found=1
309 config_get type "radio
$devidx" type
310 [ -n "$type" ] || break
311 devidx=$(($devidx + 1))
313 for dev in $(ls /sys/class/ieee80211); do
315 config_foreach check_device wifi-device
316 [ "$found" -gt 0 ] && continue
322 for cap in $(iw phy "$dev" info | grep 'Capabilities:' | cut -d: -f2); do
323 ht_cap="$
(($ht_cap |
$cap))"
326 [ "$ht_cap" -gt 0 ] && {
328 list=" list ht_capab
"
329 [ "$
(($ht_cap & 1))" -eq 1 ] && append ht_capab "$list LDPC
" "$N"
330 [ "$
(($ht_cap & 2))" -eq 2 ] && append ht_capab "$list HT40-
" "$N"
331 [ "$
(($ht_cap & 32))" -eq 32 ] && append ht_capab "$list SHORT-GI-20
" "$N"
332 [ "$
(($ht_cap & 64))" -eq 64 ] && append ht_capab "$list SHORT-GI-40
" "$N"
333 [ "$
(($ht_cap & 4096))" -eq 4096 ] && append ht_capab "$list DSSS_CCK-40
" "$N"
335 iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a
"; channel="36"; }
338 config wifi-device radio$devidx
340 option channel ${channel}
341 option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
342 option hwmode 11${mode_11n}${mode_band}
343 # REMOVE THIS LINE TO ENABLE WIFI:
348 option device radio$devidx
352 option encryption none
355 devidx=$(($devidx + 1))