create_ap

create a nat-ed wifi ap
git clone git://git.2f30.org/create_ap.git
Log | Files | Refs | LICENSE

commit 64790ff5f2a5ce83006aa967c637e27826812784
parent 258fbc1f946c2a48e460af2be0e560e4af126788
Author: oblique <psyberbits@gmail.com>
Date:   Thu Aug 28 01:00:33 +0300

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

Diffstat:
create_ap | 37+++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+), 0 deletions(-)
diff --git a/create_ap b/create_ap @@ -76,6 +76,41 @@ version_cmp() { 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() { 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." fi +can_transmit_to_channel ${WIFI_IFACE} ${CHANNEL} || die "Your adapter can not transmit to channel $CHANNEL." + networkmanager_add_unmanaged ${WIFI_IFACE} [[ $HIDDEN -eq 1 ]] && echo "Access Point's SSID is hidden!"