3

I would like to extend a WiFi signal. I could buy a WiFi repeater, but a much cheaper solution would be using an older Android 4 device, which I own and don't use. The Android device is capable of creating a WiFi AP. So if I bought an external WiFi USB adapter for it, with a large antenna used as the receiver and the Android device itself as the AP, I could bridge the network.

The hardware should be possible. But how about the Android software? Will there be any issues, or any considerations I need to take note of?

  • There are several wifi tethering apps, some even don't need rooting. Guess where you can search. – ott-- Jan 8 '13 at 12:33
  • @ott-- you misread the Q probably, this isn't solely about creating an AP, it's about a wifi-to-wifi bridge/repeater mode using an additional external USB wifi dongle. There's no app on play... – ce4 Jan 9 '13 at 1:48
  • @ce4 Indeed, I was thinking of a repeater, but I learned that this is not possible. – ott-- Jan 10 '13 at 10:52
  • Many new phones now have it as a regular feature. The Redmi note 5 pro and even the Samsung A9 have it as an inbuilt feature. – Manish Jan 7 at 21:50
4

That's not worth the trouble.

It's not supported out of the box by Android and you would have to (re)compile and configure and script many things. The dedicated router is the more reasonable and stable solution (and it's also cheap).

Reasons are the following. You would need:

  • USB host support
  • finding a USB wifi module that's supported by linux
  • Compile a kernel module or a new kernel (to support the USB module)
  • bridge utilities (maybe), bridge module in linux
  • a working wpa_supplicant binary for the new USB dongle
  • time
  • 17EUR+ costs (Wifi USB dongle (starting around 12EUR) + USB OTG cable (5EUR))

In contrast to this the cheapest repeater-mode wifi router I found on Amazon was 18EUR and requires null additional fiddling (plus has a better antenna).

1

Bluetooth tethering might also be a solution.

That truly works out of the box on Android 3.0+ (and with 3rd party apps on 2.2+). It'll be just fine if you can tolerate the low data rate (BT 2.0 offers 2.1MBit data rate) and the distance between phone + bluetooth-tether client is not too far. In this mode the wifi operates normally and the 2nd (client) connection is done via bluetooth PAN profile, look here for more info:

https://android.stackexchange.com/a/24211/15713

I have done this in blind spotted hotel rooms: put the phone in a good spot and then BT tether.

1

WI-FI REPEATER MODE ON ANDROID

Using wi-fi and hotspot at the same time is not a standard feature introduced in stock Android or custom ROM's so far (AFAIK). There are apps that makes it possible using Wi-Fi Direct. However you can do this manually too if you are comfortable with commandline usage. Even a USB Wi-Fi dongle is not needed if managed and AP modes are supported simultaneously by wireless chip.

WHAT'S NEEDED

  • Rooted device
  • Device must support nl80211 driver

    All newer devices with Qualcomm MSM chipset support this AFAIK e.g. Xiaomi's Redmi Note 4 (mido) built with MSM8953.

    Kernel must also support this driver. To confirm:

    ~# zcat /proc/config.gz | grep CONFIG_CFG80211
    CONFIG_CFG80211=y
    
    ~# lshw | grep wireless=
           configuration: broadcast=yes driver=wcnss_wlan multicast=yes wireless=Qcom:802.11n
    
  • Device must support managed mode and AP mode at the same time.

    ~# iw phy | grep -iA2 'valid interface combinations'
            valid interface combinations:
             * #{ managed } <= 3, #{ IBSS, AP } <= 1, #{ P2P-client, P2P-GO } <= 1,
               total <= 3, #channels <= 1
    

    This means that your wireless chip supports creating at maximum 3 interfaces, one of which can be in AP mode, with others being in managed or P2P mode, and at maximum 1 channel is supported. If channels value is 2, you can operate both interfaces on different channels. However using same channel is recommended to avoid interference.

    Standard wi-fi interface on Android devices (usually wlan0) is always run in managed mode. We are going to create a virtual wireless interface to be run in AP mode.

  • Linux tools: iw, ip, iptables, hostapd, dnsmasq etc.

    You can also use wpa_supplicant in place of hostapd with slightly different configuration.

    Usually these binaries come bundled with Android. However there are modifications by Google and vendors to make these tools fit for Android needs. So they may not behave as standard Linux tools and in rare cases you might need to compile them from source.

    Wireless tools should be newer enough to have support for driver nl80211.

  • Terminal emulator (Termux is a good one)

STEPS:

For ease of use, I have summarized all steps in a shell script with brief explanation. You can put this on your $PATH e.g. /system/bin/android_ap and execute it directly: ~# android_ap start. A Custom Quick Settings Tile can also be created for ease of use.

#!/system/bin/sh
set -e
#set -x

[ "$(id -u)" != 0 ] && echo 'Not running as root!' && exit

SSID=MyAP                           # set this to your desired string (avoid spaces and non-ascii characters)
PASSCODE=foobarfoobar               # set this to your desired string (8 to 63 characters)
WIFI_INTERFACE=wlan0                # set this according to your device (lshw | grep -A10 Wireless | grep 'logical name')
SUBNET=192.168.42                   # must be different than WIFI_INTERFACE
AP_INTERFACE=${WIFI_INTERFACE}-AP
IP=${SUBNET}.1
DIR=/data/local/tmp/$AP_INTERFACE

USAGE()
{
    echo 'Usage:'
    printf '\t%s\n' "$(basename "$0") start|stop"
    exit
}

STOP() {
    # hope there are no other instances of same daemons
    pkill -15 hostapd dnsmasq
    # remove iptables rules
    iptables -D INPUT -i $AP_INTERFACE -p udp -m udp --dport 67 -j ACCEPT
    iptables -t nat -D POSTROUTING -s ${SUBNET}.0/24 ! -o $AP_INTERFACE -j MASQUERADE
    iptables -D FORWARD -i $AP_INTERFACE -s ${IP}/24 -j ACCEPT
    iptables -D FORWARD -i $WIFI_INTERFACE -d ${SUBNET}.0/24 -j ACCEPT
    # delete AP interface
    ip link show | grep "${AP_INTERFACE}:" && iw $AP_INTERFACE del
    rm -rf $DIR
} >/dev/null 2>&1

CHECKS()
{
    for binary in iw ip iptables hostapd dnsmasq; do
        which $binary >/dev/null && continue
        exit
    done

    # this check is necessary if need to use single channel
    if iw dev $WIFI_INTERFACE link | grep -q '^Not connected'
    then
        echo 'First connect to Wi-Fi for internet sharing.'
        exit
    fi

    if ! iw phy | grep -iqE '{.*managed.*AP.*}' && ! iw phy | grep -iqE '{.*AP.*managed.*}'
    then
        echo 'AP mode not supported.'
        exit
    fi
}

CREATE_AP()
{
    if ! iw dev $WIFI_INTERFACE interface add $AP_INTERFACE type __ap
    then
        echo "Couldn't create AP."  # :(
        exit
    fi
}

FIND_CHANNEL()
{
    # find what channel wi-fi is using
    CHANNEL="$(iw $WIFI_INTERFACE scan | grep -C5 "$(iw $WIFI_INTERFACE link | grep SSID | cut -d: -f2-)" | grep -i channel | tail -c3)"
    if [ -z "$CHANNEL" ]
    then
        echo  "Couldn't find channel info. Are you are connected to Wi-Fi?"
        STOP
        exit
    fi

    # if more than 1 channels are supported, use any frequency
    [ ! -z "$CHANNEL" ] || CHANNEL=11
}

ADD_IP_ROUTE()
{
    # activate the interface and add IP
    ip link set up dev $AP_INTERFACE
    ip addr add ${IP}/24 broadcast ${SUBNET}.255 dev $AP_INTERFACE

    # routing table 97 needs to be put necessarily on Android
    # because in main table, route for $WIFI_INTERFACE takes priority (ip route show)
    # and all traffic goes there ignoring $AP_INTERFACE
    ip route add ${SUBNET}.0/24 dev $AP_INTERFACE table 97
}

HOSTAPD_CONFIG()
{
    mkdir -p "$DIR"
    cat <<-EOF >$DIR/hostapd.conf
        # network name
        ssid=$SSID
        # network interface to listen on
        interface=$AP_INTERFACE
        # wi-fi driver
        driver=nl80211
        # WLAN channel to use
        channel=$CHANNEL
        # ser operation mode, what frequency to use
        hw_mode=g
        # enforce Wireless Protected Access (WPA)
        wpa=2
        # passphrase to use for protected access
        wpa_passphrase=$PASSCODE
        # WPA protocol
        wpa_key_mgmt=WPA-PSK
    EOF

    # you can tune other parameters such as mtu, beacon_int, ieee80211n, wowlan_triggers (if supported)
    # for better performace and options such as *_pairwise for better security
}

INTERNET_SHARE()
{
    # allow IP forwarding
    echo 1 >/proc/sys/net/ipv4/ip_forward
    # route and allow forwrding through firewall
    iptables -t nat -I POSTROUTING -s ${SUBNET}.0/24 ! -o $AP_INTERFACE -j MASQUERADE
    iptables -I FORWARD -i $AP_INTERFACE -s ${IP}/24 -j ACCEPT
    iptables -I FORWARD -i $WIFI_INTERFACE -d ${SUBNET}.0/24 -j ACCEPT
}

DHCP_SERVER()
{
    # configuration
    cat <<-EOF >$DIR/dnsmasq.conf
        # we dont want DNS server, only DHCP
        port=0
        # only listen on AP interface
        interface=$AP_INTERFACE
        listen-address=$IP

        #bind-interfaces

        # range of IPs to make available to wlan devices andwhen to renew IP
        dhcp-range=$IP,${SUBNET}.254,24h
        # where to save leases
        dhcp-leasefile=$DIR/dnsmasq.leases
        # set default gateway
        dhcp-option-force=option:router,$IP
        # add OpenDNS servers for DNS lookup to announce
        dhcp-option-force=option:dns-server,208.67.220.220,208.67.222.222

        #dhcp-option-force=option:mtu,1500

        # respond to a client who is requesting from a different IP broadcast subnet
        # or requesting an out of range / occupied IP
        # or requesting an IP from expired lease of previous sessions
        # or obtained from some other server which is offline now
        dhcp-authoritative
        # don't look for any hosts file and resolv file
        no-hosts
        no-resolv
    EOF

    # open listening port
    iptables -I INPUT -i $AP_INTERFACE -p udp -m udp --dport 67 -j ACCEPT

    # start dhcp server
    dnsmasq -C $DIR/dnsmasq.conf
}

if [ "$1" = stop ]
then
    STOP || true
    exit
fi

[ "$1" = start ] || USAGE

# basic check
CHECKS
# stop running instances
STOP || true
# create virtual wireless interface
CREATE_AP
# find channed already used ny wi-fi
FIND_CHANNEL
# configre newly created interface
ADD_IP_ROUTE
# configure acces point daemon
HOSTAPD_CONFIG
# start hostapd
hostapd -B $DIR/hostapd.conf
# share internet from Wi-Fi to AP
INTERNET_SHARE
# run a dhcp server to assign IP's dynamically
# otherwise assign a static IP to connected device in subnet range (2 to 254)
DHCP_SERVER

echo Done.

SOURCES:

0

It needs two android devices. First device (which is connected to wifi AP) enables bluetooth tethering and second device connect to the first device through bluetooth tethering. And enables wifi-hotspot on second device and uses the second device as wifi bridge. Then you can use old android device as a wifi bridge without any additional device and s/w.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.