Check in `iw phy phyX info' if we can transmit to the selected channel

This commit is contained in:
oblique 2014-08-28 01:00:33 +03:00
parent 258fbc1f94
commit 64790ff5f2

View File

@ -76,6 +76,41 @@ version_cmp() {
return 0 return 0
} }
get_phy_device() {
for x in /sys/class/ieee80211/*; do
[[ ! -d "$x" ]] && continue
if [[ "${x##*/}" = "$1" ]]; then
echo $1
return 0
elif [[ -e "$x/device/net/$1" ]]; then
echo ${x##*/}
return 0
elif [[ -e "$x/device/net:$1" ]]; then
echo ${x##*/}
return 0
fi
done
echo "Failed to get phy interface" >&2
return 1
}
get_adapter_info() {
PHY=$(get_phy_device "$1")
[[ $? -ne 0 ]] && return 1
iw phy $PHY info
}
can_transmit_to_channel() {
IFACE=$1
CHANNEL=$2
CHANNEL_INFO=$(get_adapter_info ${IFACE} | grep "MHz \[${CHANNEL}\]")
[[ -z "${CHANNEL_INFO}" ]] && return 1
[[ "${CHANNEL_INFO}" == *no\ IR* ]] && return 1
[[ "${CHANNEL_INFO}" == *disabled* ]] && return 1
return 0
}
get_macaddr() { get_macaddr() {
ip link show "$1" | grep ether | grep -Eo '([0-9a-f]{2}:){5}[0-9a-f]{2}[[:space:]]' | tr -d '[[:space:]]' ip link show "$1" | grep ether | grep -Eo '([0-9a-f]{2}:){5}[0-9a-f]{2}[[:space:]]' | tr -d '[[:space:]]'
} }
@ -426,6 +461,8 @@ else
[[ "$WIFI_IFACE" == "$INTERNET_IFACE" ]] && die "You can not share your connection from the same interface if you are using --no-virt option." [[ "$WIFI_IFACE" == "$INTERNET_IFACE" ]] && die "You can not share your connection from the same interface if you are using --no-virt option."
fi fi
can_transmit_to_channel ${WIFI_IFACE} ${CHANNEL} || die "Your adapter can not transmit to channel $CHANNEL."
networkmanager_add_unmanaged ${WIFI_IFACE} networkmanager_add_unmanaged ${WIFI_IFACE}
[[ $HIDDEN -eq 1 ]] && echo "Access Point's SSID is hidden!" [[ $HIDDEN -eq 1 ]] && echo "Access Point's SSID is hidden!"