6

I have an Android tablet that has no SIM card and no cellular connection. Is it possible to set it up as a discoverable WiFi access point? I know when you have a cellular connection you can set up tethering and have an id and password that can be discovered by other devices. Is it possible to do this without any cellular connection?

I don't actually need internet access at all. All I'm looking for is to set up a small WiFi LAN between an Android tablet and a small device running Debian Linux.

6
  • Not without root and dual band WiFi... Is your tablet rooted? If so, then there are some router apps you can use. You can connect the tablet to the Internet via 2.4 or 5.2 Ghz, then use the other frequency to allow other devices to connect to it. Note that doing this is extremely inefficient and often will significantly cut-down bandwidth. It is usually better to get an older dual band router that has open source ROM's available such as Tomato or OpenWRT and set that up to act as a WiFi to WiFi router.
    – acejavelin
    Jul 22, 2019 at 21:56
  • Thanks for the reply. I don't actually need internet access at all. All I'm looking for is to set up a small wifi LAN between an android tablet and a small device running Debian Linux. The tablet has to be visible to the device and I would ideally like to send and receive data over a wifi connection. I have absolutely no idea if this is even possible. I thought I might as well ask.
    – K. Rawls
    Jul 23, 2019 at 22:41
  • I don't think you need root. S10e does this automatically out of the box with mobile hotspot (presumably because it has two wifi antennae). Jul 23, 2019 at 23:35
  • @Turkeyphant Perhaps the S10 does, but this is not an Android feature, it is something Samsung added. I have yet to see another device do this.
    – acejavelin
    Jul 25, 2019 at 1:47
  • Does the tablet have the hotspot, tethering, or internet connection sharing options in the settings? If so, it may be possible to just turn it on even without a mobile data connection, if the settings are not there, the OEM probably didn't build the options into the ROM.
    – acejavelin
    Jul 25, 2019 at 1:49

2 Answers 2

3

If you have root access and don't mind working on CLI, a shorter version of script used for How to use Android in Wi-Fi repeater mode? can be used to create a hotspot network provided that your WiFi interface supports AP mode:

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

# this scripts creates a hotspot network

[ "$(id -u)" = 0 ] || { echo 'Not running as root!' >&2; exit 1; }

# check required binaries are on PATH
for bin in iw ip iptables hostapd dnsmasq
do
    ! which $bin >/dev/null || continue
    echo "$bin not found." >&2
    exit 1
done

####################
# define variables #
####################
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 (check with 'lshw' or 'ip link show')
AP_INTERFACE=${WIFI_INTERFACE}-AP
DIR=/data/local/tmp/$AP_INTERFACE
SUBNET=192.168.43
IP=${SUBNET}.1

##########################
# start / stop tethering #
##########################
STOP()
(
    echo 'Cleaning up...'

    # don't print error messages
    exec >/dev/null 2>&1

    # hope there are no other instances of same daemons
    pkill -15 hostapd
    pkill -15 wpa_supplicant
    pkill -15 dnsmasq
    # remove RPDB rule and iptables rule
    ip rule del lookup main
    iptables -D INPUT -i $AP_INTERFACE -p udp -m udp --dport 67 -j ACCEPT
    # delete AP interface
    iw $AP_INTERFACE del
    rm -rf $DIR
)

if [ "$1" = stop ]
then
    STOP || true
    exit
elif [ "$1" != start ]
then
    echo 'Usage:' >&2
    printf '\t%s\n' "$(basename "$0") start|stop" >&2
    exit 1
fi

################
# basic checks #
################
if ! iw phy | grep -A10 'Supported interface modes:' | grep -q '\*[ ]*AP'
then
    echo 'AP mode not supported.' >&2
    exit 1
fi

if ! iw dev $WIFI_INTERFACE link | grep -q '^Not connected'
then
    echo 'First disconnect form Wi-Fi.' >&2
    exit 1
fi

##########################
# stop running instances #
##########################
STOP || true

#####################################
# create virtual wireless interface #
#####################################
if ! iw dev $WIFI_INTERFACE interface add $AP_INTERFACE type __ap
then
    echo "Couldn't create AP interface." >&2
    exit 1
fi

#####################################
# configure newly created interface #
#####################################
echo 'Configuring network...'

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

# Android doesn't look up into main table by default
ip rule add lookup main

#######################
# access point daemon #
#######################
# create configuration file
mkdir -p "$DIR"
cat <<-EOF >$DIR/hostapd.conf
    # network name
    ssid=$SSID
    # passphrase to use for protected access
    wpa_passphrase=$PASSCODE

    # network interface to listen on
    interface=$AP_INTERFACE
    # wi-fi driver
    driver=nl80211

    # set operation mode, 'g' for 2.4GHz band
    hw_mode=g
    # WLAN frequency channel to use
    channel=1

    # key management protocol; use pre-share key
    wpa_key_mgmt=WPA-PSK
    # enforce WPA2
    wpa=2
EOF

echo 'Starting hostapd...'
hostapd -B $DIR/hostapd.conf

################################################
# run a dhcp server to assign IP's dynamically #
################################################
# create configuration file
cat <<-EOF >$DIR/dnsmasq.conf
    # we dont want DNS server, only DHCP
    port=0

    # nameservers to be sent to clients
    dhcp-option=6,1.1.1.1,1.0.0.1

    # range of IPs to make available to wlan devices and when to renew IP
    dhcp-range=$IP,${SUBNET}.254,24h
    # where to save leases
    dhcp-leasefile=$DIR/dnsmasq.leases

    # respond to requests from a different IP broadcast subnet
    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

echo 'Starting DHCP server...'
dnsmasq -C $DIR/dnsmasq.conf </dev/null

echo Done.

Now you can connect to Access Point MyAP using key foobarfoobar.

wpa_supplicant can also be used in place of hostapd for simple cases like ours, but the one shipped with Android doesn't seem to work. You need to compile binary from source, or try this one. Configuration is even simpler:

...

#######################
# access point daemon #
#######################
# create configuration file
mkdir -p $DIR/wpa_supplicant
cat <<-EOF >$DIR/wpa_supplicant.conf
    ctrl_interface=$DIR/wpa_supplicant

    network={
        ssid="MyAP"
        psk="foobarfoobar"

        # force create AP network
        ap_scan=2

        # key management protocol; use pre-share key
        key_mgmt=WPA-PSK
        # enforce WPA2
        proto=RSA

        # set mode to AP
        mode=2

        # channel frequency
        frequency=2412
    }
EOF

echo 'Starting wpa_supplicant in AP mode...'
wpa_supplicant -B -D nl80211 -i $AP_INTERFACE -c $DIR/wpa_supplicant.conf

...
  • hostapd, wpa_supplicant and dnsmasq all are part of AOSP. hostapd is used for wireless tethering, wpa_supplicant for WiFi connections and dnsmasq as DHCP/DNS server (up to Pie).
  • dnsmasq isn't necessary if you prefer static IP configuration.
  • If your device doesn't contain hostapd binary, you can get one from some other device or compile from source, or try this one.
  • For more configuration options, see hostapd.conf, dnsmasq.conf and wpa_supplicant.conf. See WiFi channels detail here.
  • Also make sure both hostapd (runs with UID 1010 AID_WIFI) and dnsmasq (drops to UID 9999 AID_NOBODY) are able to make outbound connections through firewall.
  • SELinux may also cause problems with this manual setup, so set permissive for testing purpose or define policy rules.
  • Since you don't intend to use internet, there is no need to configure NAT and packet forwarding.

PS:

In case if you have cellular connection, the only extra thing to be done is internet sharing. For extra steps see How to create a WiFi hotspot from the terminal?

5
  • I tried the run the above script. It exits with "hostapd not found" however using find this three are returnded. /data/vendor/wifi/hostapd /sbin/.magisk/mirror/data/vendor/wifi/hostapd /system/vendor/bin/hw/hostapd. Should i install the one provided above, and how should i install it, As zip in TWRP? Excuse my ignorance.
    – kocjs
    Feb 2, 2021 at 15:09
  • @kocj use any of the both binaries already available on your device. If they don't work, download the ZIP file, extract the hostapd binary, and place on your PATH. Feb 2, 2021 at 21:10
  • @Ifran lativ if i copy the /system/vendor/bin/hw/hostapd to /system/bin the script runs till ++ hostapd -B /data/local/tmp/wlan0-AP/hostapd.conf if i use the one provided above the output of the script is one more line ./hotspot: line 131: /system/bin/hostapd: cannot execute binary file: Exec format error. what do i do wrong.
    – kocjs
    Feb 3, 2021 at 7:15
  • Ok, if figured out my testing device is not aarch64 but armeabi-v7a,armeabi. This might be the reason for Exec format error
    – kocjs
    Feb 3, 2021 at 11:18
  • @kocj correct. More details on architecture in this answer: android.stackexchange.com/a/208132/218526 Feb 3, 2021 at 12:44
1

If you don't need internet access and just a local network, why not just use WiFi Direct?

You should be able to access this through Settings > WiFi and set up an ad-hoc network between your tablet and Debian device.

2
  • Unfortunately the Debian device is not discoverable, i.e. it doesn't show up when you try to do a wifi direct connection. I think my only option at this point is to get a cellular device and try to establish a network with a hotspot.
    – K. Rawls
    Jul 26, 2019 at 18:10
  • Are you sure that the Debian device is working with Wifi Direct or could it be an issue with that? Jul 27, 2019 at 20:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .