2007-10-05 20:56:15 +03:00
|
|
|
#!/bin/sh
|
|
|
|
append DRIVERS "mac80211"
|
|
|
|
|
2009-10-02 18:18:44 +03:00
|
|
|
find_mac80211_phy() {
|
|
|
|
config_get device "$1"
|
|
|
|
|
|
|
|
local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
|
|
|
|
config_get phy "$device" phy
|
|
|
|
[ -z "$phy" -a -n "$macaddr" ] && {
|
2009-10-02 22:16:16 +03:00
|
|
|
for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
|
2009-10-02 18:18:44 +03:00
|
|
|
[ "$macaddr" = "$(cat /sys/class/ieee80211/${phy}/macaddress)" ] || continue
|
|
|
|
config_set "$device" phy "$phy"
|
|
|
|
break
|
|
|
|
done
|
|
|
|
config_get phy "$device" phy
|
|
|
|
}
|
|
|
|
[ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || {
|
|
|
|
echo "PHY for wifi device $1 not found"
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
[ -z "$macaddr" ] && {
|
|
|
|
config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
scan_mac80211() {
|
|
|
|
local device="$1"
|
2009-06-30 00:13:10 +03:00
|
|
|
local adhoc sta ap monitor mesh
|
2009-01-28 17:47:28 +02:00
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
config_get vifs "$device" vifs
|
|
|
|
for vif in $vifs; do
|
|
|
|
config_get mode "$vif" mode
|
|
|
|
case "$mode" in
|
2009-02-26 16:53:03 +02:00
|
|
|
adhoc|sta|ap|monitor|mesh)
|
2007-10-05 20:56:15 +03:00
|
|
|
append $mode "$vif"
|
|
|
|
;;
|
|
|
|
*) echo "$device($vif): Invalid mode, ignored."; continue;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2009-06-30 00:13:10 +03:00
|
|
|
config_set "$device" vifs "${ap:+$ap }${adhoc:+$adhoc }${sta:+$sta }${monitor:+$monitor }${mesh:+$mesh}"
|
2007-10-05 20:56:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
disable_mac80211() (
|
|
|
|
local device="$1"
|
|
|
|
|
2009-10-02 18:18:44 +03:00
|
|
|
find_mac80211_phy "$device" || return 0
|
|
|
|
config_get phy "$device" phy
|
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
set_wifi_down "$device"
|
|
|
|
# kill all running hostapd and wpa_supplicant processes that
|
2009-01-28 17:47:28 +02:00
|
|
|
# are running on atheros/mac80211 vifs
|
2007-10-05 20:56:15 +03:00
|
|
|
for pid in `pidof hostapd wpa_supplicant`; do
|
|
|
|
grep wlan /proc/$pid/cmdline >/dev/null && \
|
|
|
|
kill $pid
|
|
|
|
done
|
2009-01-28 17:47:28 +02:00
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
include /lib/network
|
2009-10-02 22:16:16 +03:00
|
|
|
for wdev in $(ls /sys/class/ieee80211/${phy}/device/net 2>/dev/null); do
|
2009-10-02 18:18:44 +03:00
|
|
|
ifconfig "$wdev" down 2>/dev/null
|
|
|
|
unbridge "$dev"
|
|
|
|
iw dev "$wdev" del
|
2007-10-05 20:56:15 +03:00
|
|
|
done
|
2009-10-02 18:18:44 +03:00
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
return 0
|
|
|
|
)
|
2009-10-11 03:36:23 +03:00
|
|
|
get_freq() {
|
|
|
|
local phy="$1"
|
2009-10-11 04:01:12 +03:00
|
|
|
local chan="$2"
|
|
|
|
iw "$phy" info | grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}'
|
2009-10-11 03:36:23 +03:00
|
|
|
}
|
2007-10-05 20:56:15 +03:00
|
|
|
enable_mac80211() {
|
|
|
|
local device="$1"
|
|
|
|
config_get channel "$device" channel
|
|
|
|
config_get vifs "$device" vifs
|
2009-01-31 18:09:39 +02:00
|
|
|
config_get txpower "$device" txpower
|
2009-12-05 19:12:51 +02:00
|
|
|
config_get country "$device" country
|
2010-01-15 03:16:52 +02:00
|
|
|
config_get distance "$device" distance
|
2009-10-02 18:18:44 +03:00
|
|
|
find_mac80211_phy "$device" || return 0
|
|
|
|
config_get phy "$device" phy
|
|
|
|
local i=0
|
2009-10-11 04:01:12 +03:00
|
|
|
fixed=""
|
2009-01-28 17:47:28 +02:00
|
|
|
|
2009-12-05 19:12:51 +02:00
|
|
|
[ -n "$country" ] && iw reg set "$country"
|
2009-10-11 04:01:12 +03:00
|
|
|
[ "$channel" = "auto" -o "$channel" = "0" ] || {
|
|
|
|
fixed=1
|
|
|
|
}
|
|
|
|
|
2010-01-15 03:16:52 +02:00
|
|
|
[ -n "$distance" ] && iw phy "$phy" set distance "$distance"
|
|
|
|
|
2009-10-11 04:01:12 +03:00
|
|
|
export channel fixed
|
2009-10-11 03:36:23 +03:00
|
|
|
# convert channel to frequency
|
2009-10-11 04:01:12 +03:00
|
|
|
local freq="$(get_freq "$phy" "${fixed:+$channel}")"
|
2009-10-11 03:36:23 +03:00
|
|
|
|
2009-03-27 23:14:59 +02:00
|
|
|
wifi_fixup_hwmode "$device" "g"
|
2007-10-05 20:56:15 +03:00
|
|
|
for vif in $vifs; do
|
2009-10-02 18:18:44 +03:00
|
|
|
while [ -d "/sys/class/net/wlan$i" ]; do
|
|
|
|
i=$(($i + 1))
|
|
|
|
done
|
2009-01-28 17:47:28 +02:00
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
config_get ifname "$vif" ifname
|
2009-10-02 18:18:44 +03:00
|
|
|
[ -n "$ifname" ] || {
|
|
|
|
ifname="wlan$i"
|
2007-10-05 20:56:15 +03:00
|
|
|
}
|
2009-10-02 22:16:16 +03:00
|
|
|
config_set "$vif" ifname "$ifname"
|
2009-01-28 17:47:28 +02:00
|
|
|
|
2009-10-02 18:18:44 +03:00
|
|
|
config_get enc "$vif" encryption
|
|
|
|
config_get mode "$vif" mode
|
|
|
|
config_get ssid "$vif" ssid
|
2009-11-10 21:27:19 +02:00
|
|
|
config_get_bool wds "$vif" wds 0
|
2007-10-05 20:56:15 +03:00
|
|
|
|
2009-10-02 18:18:44 +03:00
|
|
|
# It is far easier to delete and create the desired interface
|
2007-10-05 20:56:15 +03:00
|
|
|
case "$mode" in
|
|
|
|
adhoc)
|
2009-10-02 18:18:44 +03:00
|
|
|
iw phy "$phy" interface add "$ifname" type adhoc
|
|
|
|
;;
|
|
|
|
ap)
|
|
|
|
# Hostapd will handle recreating the interface and
|
|
|
|
# it's accompanying monitor
|
|
|
|
iw phy "$phy" interface add "$ifname" type managed
|
|
|
|
;;
|
|
|
|
mesh)
|
|
|
|
config_get mesh_id "$vif" mesh_id
|
|
|
|
iw phy "$phy" interface add "$ifname" type mp mesh_id "$mesh_id"
|
|
|
|
;;
|
|
|
|
monitor)
|
|
|
|
iw phy "$phy" interface add "$ifname" type monitor
|
|
|
|
;;
|
|
|
|
sta)
|
2009-11-10 21:27:19 +02:00
|
|
|
local wdsflag
|
2009-11-29 15:56:41 +02:00
|
|
|
[ "$wds" -gt 0 ] && wdsflag="4addr on"
|
2009-11-10 21:27:19 +02:00
|
|
|
iw phy "$phy" interface add "$ifname" type managed $wdsflag
|
2009-11-11 18:59:36 +02:00
|
|
|
config_get_bool powersave "$vif" powersave 0
|
|
|
|
[ "$powersave" -gt 0 ] && powersave="on" || powersave="off"
|
|
|
|
iwconfig "$ifname" power "$powersave"
|
2007-10-05 20:56:15 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2009-10-02 18:18:44 +03:00
|
|
|
# All interfaces must have unique mac addresses
|
2009-11-28 20:00:53 +02:00
|
|
|
# which can either be explicitly set in the device
|
2009-10-02 18:18:44 +03:00
|
|
|
# section, or automatically generated
|
|
|
|
config_get macaddr "$device" macaddr
|
|
|
|
local mac_1="${macaddr%%:*}"
|
|
|
|
local mac_2="${macaddr#*:}"
|
|
|
|
|
|
|
|
config_get vif_mac "$vif" macaddr
|
|
|
|
[ -n "$vif_mac" ] || {
|
2009-11-28 20:00:53 +02:00
|
|
|
if [ "$i" -gt 0 ]; then
|
2009-10-02 18:18:44 +03:00
|
|
|
offset="$(( 2 + $i * 4 ))"
|
|
|
|
else
|
|
|
|
offset="0"
|
|
|
|
fi
|
2009-12-24 13:05:04 +02:00
|
|
|
vif_mac="$( printf %02x $((0x$mac_1 + $offset)) ):$mac_2"
|
2009-10-02 18:18:44 +03:00
|
|
|
}
|
|
|
|
ifconfig "$ifname" hw ether "$vif_mac"
|
|
|
|
|
|
|
|
# We attempt to set teh channel for all interfaces, although
|
|
|
|
# mac80211 may not support it or the driver might not yet
|
2009-10-11 18:06:12 +03:00
|
|
|
[ -n "$fixed" -a -n "$channel" ] && iw dev "$ifname" set channel "$channel"
|
2009-10-02 18:18:44 +03:00
|
|
|
|
|
|
|
local key keystring
|
|
|
|
|
|
|
|
# Valid values are:
|
|
|
|
# wpa / wep / none
|
|
|
|
#
|
|
|
|
# !! ap !!
|
|
|
|
#
|
|
|
|
# ALL ap functionality will be passed to hostapd
|
|
|
|
#
|
|
|
|
# !! mesh / adhoc / station !!
|
|
|
|
# none -> NO encryption
|
|
|
|
#
|
|
|
|
# wep + keymgmt = '' -> we use iw to connect to the
|
2009-11-28 20:00:53 +02:00
|
|
|
# network.
|
2009-10-02 18:18:44 +03:00
|
|
|
#
|
|
|
|
# wep + keymgmt = 'NONE' -> wpa_supplicant will be
|
|
|
|
# configured to handle the wep connection
|
|
|
|
if [ ! "$mode" = "ap" ]; then
|
|
|
|
case "$enc" in
|
2010-01-13 20:39:44 +02:00
|
|
|
*wep*)
|
2009-10-02 18:18:44 +03:00
|
|
|
config_get keymgmt "$vif" keymgmt
|
2010-01-13 20:39:44 +02:00
|
|
|
if [ -z "$keymgmt" ]; then
|
|
|
|
config_get key "$vif" key
|
|
|
|
key="${key:-1}"
|
|
|
|
case "$key" in
|
|
|
|
[1234])
|
|
|
|
for idx in 1 2 3 4; do
|
|
|
|
local zidx
|
|
|
|
zidx=$(($idx - 1))
|
|
|
|
config_get ckey "$vif" "key${idx}"
|
|
|
|
if [ -n "$ckey" ]; then
|
|
|
|
[ $idx -eq $key ] && zidx="d:${zidx}"
|
|
|
|
append keystring "${zidx}:$(prepare_key_wep "$ckey")"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
keystring="d:0:$(prepare_key_wep "$key")"
|
|
|
|
;;
|
|
|
|
esac
|
2009-10-02 18:18:44 +03:00
|
|
|
fi
|
|
|
|
;;
|
2010-01-13 20:39:44 +02:00
|
|
|
*psk*|*wpa*)
|
2009-10-02 18:18:44 +03:00
|
|
|
config_get key "$vif" key
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
# txpower is not yet implemented in iw
|
2009-01-31 18:09:39 +02:00
|
|
|
config_get vif_txpower "$vif" txpower
|
|
|
|
# use vif_txpower (from wifi-iface) to override txpower (from
|
|
|
|
# wifi-device) if the latter doesn't exist
|
|
|
|
txpower="${txpower:-$vif_txpower}"
|
|
|
|
[ -z "$txpower" ] || iwconfig "$ifname" txpower "${txpower%%.*}"
|
2007-10-05 20:56:15 +03:00
|
|
|
|
|
|
|
config_get frag "$vif" frag
|
|
|
|
if [ -n "$frag" ]; then
|
2009-10-02 18:18:44 +03:00
|
|
|
iw phy "$phy" set frag "${frag%%.*}"
|
2007-10-05 20:56:15 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
config_get rts "$vif" rts
|
|
|
|
if [ -n "$rts" ]; then
|
2009-12-09 19:22:25 +02:00
|
|
|
iw phy "$phy" set rts "${rts%%.*}"
|
2007-10-05 20:56:15 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
ifconfig "$ifname" up
|
|
|
|
|
|
|
|
local net_cfg bridge
|
|
|
|
net_cfg="$(find_net_config "$vif")"
|
|
|
|
[ -z "$net_cfg" ] || {
|
|
|
|
bridge="$(bridge_interface "$net_cfg")"
|
|
|
|
config_set "$vif" bridge "$bridge"
|
|
|
|
start_net "$ifname" "$net_cfg"
|
|
|
|
}
|
2009-10-02 18:18:44 +03:00
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
set_wifi_up "$vif" "$ifname"
|
|
|
|
case "$mode" in
|
|
|
|
ap)
|
|
|
|
if eval "type hostapd_setup_vif" 2>/dev/null >/dev/null; then
|
2008-02-17 15:29:22 +02:00
|
|
|
hostapd_setup_vif "$vif" nl80211 || {
|
|
|
|
echo "enable_mac80211($device): Failed to set up wpa for interface $ifname" >&2
|
2007-10-05 20:56:15 +03:00
|
|
|
# make sure this wifi interface won't accidentally stay open without encryption
|
|
|
|
ifconfig "$ifname" down
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
;;
|
2009-10-11 03:36:23 +03:00
|
|
|
adhoc)
|
|
|
|
config_get bssid "$vif" bssid
|
2009-10-11 04:01:12 +03:00
|
|
|
iw dev "$ifname" ibss join "$ssid" $freq ${fixed:+fixed-freq} $bssid
|
2009-10-11 03:36:23 +03:00
|
|
|
;;
|
|
|
|
sta|mesh)
|
2009-10-11 04:05:17 +03:00
|
|
|
config_get bssid "$vif" bssid
|
2009-11-28 20:00:53 +02:00
|
|
|
case "$enc" in
|
2010-01-13 20:39:44 +02:00
|
|
|
*wep*)
|
|
|
|
if [ -z "$keymgmt" ]; then
|
2009-10-02 18:18:44 +03:00
|
|
|
[ -n "$keystring" ] &&
|
2010-01-13 20:39:44 +02:00
|
|
|
iw dev "$ifname" connect "$ssid" ${fixed:+$freq} $bssid key $keystring
|
2009-10-02 18:18:44 +03:00
|
|
|
else
|
|
|
|
if eval "type wpa_supplicant_setup_vif" 2>/dev/null >/dev/null; then
|
|
|
|
wpa_supplicant_setup_vif "$vif" wext || {
|
|
|
|
echo "enable_mac80211($device): Failed to set up wpa_supplicant for interface $ifname" >&2
|
|
|
|
# make sure this wifi interface won't accidentally stay open without encryption
|
|
|
|
ifconfig "$ifname" down
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
2009-12-05 17:08:25 +02:00
|
|
|
*wpa*|*psk*)
|
2009-11-10 21:27:13 +02:00
|
|
|
config_get key "$vif" key
|
2009-10-02 18:18:44 +03:00
|
|
|
if eval "type wpa_supplicant_setup_vif" 2>/dev/null >/dev/null; then
|
|
|
|
wpa_supplicant_setup_vif "$vif" wext || {
|
|
|
|
echo "enable_mac80211($device): Failed to set up wpa_supplicant for interface $ifname" >&2
|
|
|
|
# make sure this wifi interface won't accidentally stay open without encryption
|
|
|
|
ifconfig "$ifname" down
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
;;
|
2009-10-11 04:05:17 +03:00
|
|
|
*)
|
|
|
|
iw dev "$ifname" connect "$ssid" ${fixed:+$freq} $bssid
|
|
|
|
;;
|
2009-10-02 18:18:44 +03:00
|
|
|
esac
|
|
|
|
|
2009-02-26 16:53:03 +02:00
|
|
|
;;
|
2007-10-05 20:56:15 +03:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-10-02 18:18:44 +03:00
|
|
|
check_device() {
|
|
|
|
config_get phy "$1" phy
|
|
|
|
[ -z "$phy" ] && {
|
2009-12-22 23:45:08 +02:00
|
|
|
find_mac80211_phy "$1" >/dev/null || return 0
|
2009-10-02 18:18:44 +03:00
|
|
|
config_get phy "$1" phy
|
|
|
|
}
|
|
|
|
[ "$phy" = "$dev" ] && found=1
|
|
|
|
}
|
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
detect_mac80211() {
|
2009-10-02 18:18:44 +03:00
|
|
|
devidx=0
|
|
|
|
config_load wireless
|
2009-11-28 20:00:59 +02:00
|
|
|
while :; do
|
2009-12-03 20:35:31 +02:00
|
|
|
config_get type "radio$devidx" type
|
2009-11-28 20:00:59 +02:00
|
|
|
[ -n "$type" ] || break
|
|
|
|
devidx=$(($devidx + 1))
|
|
|
|
done
|
2009-10-02 18:18:44 +03:00
|
|
|
for dev in $(ls /sys/class/ieee80211); do
|
|
|
|
found=0
|
|
|
|
config_foreach check_device wifi-device
|
|
|
|
[ "$found" -gt 0 ] && continue
|
|
|
|
|
2009-10-02 22:41:04 +03:00
|
|
|
mode_11n=""
|
|
|
|
mode_band="g"
|
2009-11-27 23:21:10 +02:00
|
|
|
channel="5"
|
2009-11-09 02:58:39 +02:00
|
|
|
ht_cap=0
|
2010-01-15 04:55:29 +02:00
|
|
|
for cap in $(iw phy "$dev" info | grep 'Capabilities:' | cut -d: -f2); do
|
2009-11-09 02:58:39 +02:00
|
|
|
ht_cap="$(($ht_cap | $cap))"
|
|
|
|
done
|
2009-11-04 23:53:49 +02:00
|
|
|
ht_capab="";
|
2009-11-09 02:58:39 +02:00
|
|
|
[ "$ht_cap" -gt 0 ] && {
|
2009-11-04 23:53:49 +02:00
|
|
|
mode_11n="n"
|
|
|
|
list=" list ht_capab"
|
2009-11-27 23:21:28 +02:00
|
|
|
[ "$(($ht_cap & 1))" -eq 1 ] && append ht_capab "$list LDPC" "$N"
|
2009-11-04 23:53:49 +02:00
|
|
|
[ "$(($ht_cap & 2))" -eq 2 ] && append ht_capab "$list HT40-" "$N"
|
|
|
|
[ "$(($ht_cap & 32))" -eq 32 ] && append ht_capab "$list SHORT-GI-20" "$N"
|
|
|
|
[ "$(($ht_cap & 64))" -eq 64 ] && append ht_capab "$list SHORT-GI-40" "$N"
|
|
|
|
[ "$(($ht_cap & 4096))" -eq 4096 ] && append ht_capab "$list DSSS_CCK-40" "$N"
|
|
|
|
}
|
2009-11-28 15:49:14 +02:00
|
|
|
iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; }
|
2009-10-02 18:18:44 +03:00
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
cat <<EOF
|
2009-12-03 20:35:31 +02:00
|
|
|
config wifi-device radio$devidx
|
2007-10-05 20:56:15 +03:00
|
|
|
option type mac80211
|
2009-11-27 23:21:10 +02:00
|
|
|
option channel ${channel}
|
2009-10-02 18:18:44 +03:00
|
|
|
option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)
|
2009-10-02 22:41:04 +03:00
|
|
|
option hwmode 11${mode_11n}${mode_band}
|
2007-10-05 20:56:15 +03:00
|
|
|
# REMOVE THIS LINE TO ENABLE WIFI:
|
|
|
|
option disabled 1
|
2009-11-04 23:53:49 +02:00
|
|
|
$ht_capab
|
2007-10-05 20:56:15 +03:00
|
|
|
|
|
|
|
config wifi-iface
|
2009-12-03 20:35:31 +02:00
|
|
|
option device radio$devidx
|
2009-10-02 18:18:44 +03:00
|
|
|
option network lan
|
|
|
|
option mode ap
|
|
|
|
option ssid OpenWrt
|
2007-10-05 20:56:15 +03:00
|
|
|
option encryption none
|
2009-10-02 18:18:44 +03:00
|
|
|
|
2007-10-05 20:56:15 +03:00
|
|
|
EOF
|
2009-11-28 20:00:59 +02:00
|
|
|
devidx=$(($devidx + 1))
|
2007-10-05 20:56:15 +03:00
|
|
|
done
|
|
|
|
}
|
2009-10-02 18:18:44 +03:00
|
|
|
|