create_ap

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

commit 488f84e14fd4115b1a9a77f3f190c9e75203d2a5
parent 034545483cf7c75ca2ab4583fbb2b030a57bab82
Author: oblique <psyberbits@gmail.com>
Date:   Wed, 10 Sep 2014 23:05:07 +0300

rename virt. interface if it was renamed by udev at creation

fix #16

Diffstat:
Mcreate_ap | 34+++++++++++++++++++++++++++++++++-
1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/create_ap b/create_ap @@ -102,7 +102,7 @@ is_bridge_interface() { get_phy_device() { for x in /sys/class/ieee80211/*; do - [[ ! -d "$x" ]] && continue + [[ ! -e "$x" ]] && continue if [[ "${x##*/}" = "$1" ]]; then echo $1 return 0 @@ -118,6 +118,23 @@ get_phy_device() { return 1 } +get_virt_interfaces() { + PHY=$(get_phy_device "$1") + + if [[ -e "/sys/class/ieee80211/${PHY}/device/net/" ]]; then + for x in /sys/class/ieee80211/${PHY}/device/net/*; do + [[ ! -e "$x" ]] && continue + echo ${x##*/} + done + return + fi + + for x in /sys/class/ieee80211/${PHY}/device/net:*; do + [[ ! -e "$x" ]] && continue + echo ${x##*:} + done +} + get_adapter_info() { PHY=$(get_phy_device "$1") [[ $? -ne 0 ]] && return 1 @@ -659,8 +676,23 @@ if [[ $NO_VIRT -eq 0 ]]; then VIRTDIEMSG="Maybe your WiFi adapter does not fully support virtual interfaces. Try again with --no-virt." echo -n "Creating a virtual WiFi interface... " + iw dev ${VWIFI_IFACE} del > /dev/null 2>&1 + VIRT_IFACES=" $(get_virt_interfaces ${WIFI_IFACE}) " if iw dev ${WIFI_IFACE} interface add ${VWIFI_IFACE} type __ap; then + # some distributions (such as Ubuntu) have udev rules that they rename + # the new virtual interface. in this case, forcefully rename it back + # to the name we want + if ! is_wifi_interface ${VWIFI_IFACE}; then + for x in $(get_virt_interfaces ${WIFI_IFACE}); do + if [[ "$VIRT_IFACES" != *\ ${x}\ * ]]; then + ip link set dev $x down || die + ip link set dev $x name $VWIFI_IFACE || die + break + fi + done + fi + # now we can call networkmanager_wait_until_unmanaged networkmanager_is_running && [[ $NM_OLDER_VERSION -eq 0 ]] && networkmanager_wait_until_unmanaged ${VWIFI_IFACE} echo "${VWIFI_IFACE} created."