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 config_get channel
"$device" channel
73 config_get vifs
"$device" vifs
74 config_get txpower
"$device" txpower
75 find_mac80211_phy
"$device" ||
return 0
76 config_get phy
"$device" phy
79 wifi_fixup_hwmode
"$device" "g"
81 while [ -d "/sys/class/net/wlan$i" ]; do
85 config_get ifname
"$vif" ifname
89 config_set
"$vif" ifname
"$ifname"
91 config_get enc
"$vif" encryption
92 config_get mode
"$vif" mode
93 config_get ssid
"$vif" ssid
95 # It is far easier to delete and create the desired interface
98 iw phy
"$phy" interface add
"$ifname" type adhoc
101 # Hostapd will handle recreating the interface and
102 # it's accompanying monitor
103 iw phy
"$phy" interface add
"$ifname" type managed
106 config_get mesh_id
"$vif" mesh_id
107 iw phy
"$phy" interface add
"$ifname" type mp mesh_id
"$mesh_id"
110 iw phy
"$phy" interface add
"$ifname" type monitor
113 iw phy
"$phy" interface add
"$ifname" type managed
117 # All interfaces must have unique mac addresses
118 # which can either be explicitly set in the device
119 # section, or automatically generated
120 config_get macaddr
"$device" macaddr
121 local mac_1
="${macaddr%%:*}"
122 local mac_2
="${macaddr#*:}"
124 config_get vif_mac
"$vif" macaddr
125 [ -n "$vif_mac" ] ||
{
126 if [ "$i" -gt 0 ]; then
127 offset
="$(( 2 + $i * 4 ))"
131 vif_mac
="$( printf %02x $(($mac_1 + $offset)) ):$mac_2"
133 ifconfig
"$ifname" hw ether
"$vif_mac"
135 # We attempt to set teh channel for all interfaces, although
136 # mac80211 may not support it or the driver might not yet
137 iw dev
"$ifname" set channel
"$channel"
146 # ALL ap functionality will be passed to hostapd
148 # !! mesh / adhoc / station !!
149 # none -> NO encryption
151 # wep + keymgmt = '' -> we use iw to connect to the
154 # wep + keymgmt = 'NONE' -> wpa_supplicant will be
155 # configured to handle the wep connection
156 if [ ! "$mode" = "ap" ]; then
159 config_get keymgmt
"$vif" keymgmt
160 if [ -e "$keymgmt" ]; then
161 for idx
in 1 2 3 4; do
164 config_get key
"$vif" "key${idx}"
165 if [ -n "$key" ]; then
166 append keystring
"${zidx}:${key} "
172 config_get key
"$vif" key
177 # txpower is not yet implemented in iw
178 config_get vif_txpower
"$vif" txpower
179 # use vif_txpower (from wifi-iface) to override txpower (from
180 # wifi-device) if the latter doesn't exist
181 txpower
="${txpower:-$vif_txpower}"
182 [ -z "$txpower" ] || iwconfig
"$ifname" txpower
"${txpower%%.*}"
184 config_get frag
"$vif" frag
185 if [ -n "$frag" ]; then
186 iw phy
"$phy" set frag
"${frag%%.*}"
189 config_get rts
"$vif" rts
190 if [ -n "$rts" ]; then
191 iw phy
"$phy" set rts
"${frag%%.*}"
194 ifconfig
"$ifname" up
197 net_cfg
="$(find_net_config "$vif")"
198 [ -z "$net_cfg" ] ||
{
199 bridge
="$(bridge_interface "$net_cfg")"
200 config_set
"$vif" bridge
"$bridge"
201 start_net
"$ifname" "$net_cfg"
204 set_wifi_up
"$vif" "$ifname"
207 if eval "type hostapd_setup_vif" 2>/dev
/null
>/dev
/null
; then
208 hostapd_setup_vif
"$vif" nl80211 ||
{
209 echo "enable_mac80211($device): Failed to set up wpa for interface $ifname" >&2
210 # make sure this wifi interface won't accidentally stay open without encryption
211 ifconfig
"$ifname" down
217 # Fixup... sometimes you have to scan to get beaconing going
218 iw dev
"$ifname" scan
&> /dev
/null
221 if [ -e "$keymgmt" ]; then
222 [ -n "$keystring" ] &&
223 iw dev
"$ifname" connect
"$ssid" key
"$keystring"
225 if eval "type wpa_supplicant_setup_vif" 2>/dev
/null
>/dev
/null
; then
226 wpa_supplicant_setup_vif
"$vif" wext ||
{
227 echo "enable_mac80211($device): Failed to set up wpa_supplicant for interface $ifname" >&2
228 # make sure this wifi interface won't accidentally stay open without encryption
229 ifconfig
"$ifname" down
236 if eval "type wpa_supplicant_setup_vif" 2>/dev
/null
>/dev
/null
; then
237 wpa_supplicant_setup_vif
"$vif" wext ||
{
238 echo "enable_mac80211($device): Failed to set up wpa_supplicant for interface $ifname" >&2
239 # make sure this wifi interface won't accidentally stay open without encryption
240 ifconfig
"$ifname" down
254 config_get phy
"$1" phy
256 find_mac80211_phy
"$1" ||
return 0
257 config_get phy
"$1" phy
259 [ "$phy" = "$dev" ] && found
=1
265 for dev
in $
(ls /sys
/class
/ieee80211
); do
267 config_foreach check_device wifi-device
268 [ "$found" -gt 0 ] && continue
271 config_get
type "wifi$devidx" type
272 [ -n "$type" ] ||
break
273 devidx
=$
(($devidx + 1))
277 config wifi-device wifi$devidx
280 option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
281 # REMOVE THIS LINE TO ENABLE WIFI:
285 option device wifi$devidx
289 option encryption none