I got a broken Nexus-7 and wanted to use it as a router up at DebtRidge. I wanted it to come up as a wifi hotspot automatically when booted. This means the ‘hostapd’ daemon needs to be started automatically. So here’s what I did.
- Unlock the bootloader
- Root the tablet and install SuperSU
- install busybox
- install init.d
The above is outside the scope of this article. There’s already lots of fine articles that tell you how to do all that.
Once you can get a terminal prompt or adb shell and su, you can proceed.
- setup the Wifi hotspot in Settings. This will generate a file called /data/misc/wifi/hostapd.conf. It looks something like this:
interface=wlan0 driver=nl80211 ctrl_interface=/data/misc/wifi/hostapd ssid=drgate channel=6 ieee80211n=1 hw_mode=g ignore_broadcast_ssid=0 wpa=2 rsn_pairwise=CCMP wpa_psk=115dfdf3a3c63c3692b5cfaf0ad73234e89a1e7b70037fd5cfcdcd2d608a6bc9
Since init.d is run in /data/install-recovery-2.sh, it runs too early in the boot process for hostapd to start. Another issue is that hostapd won’t run if Wifi is enabled. However, if Wifi hasn’t been enabled, the wlan driver isn’t loaded and hostapd isn’t able to bind to wlan0 because it doesn’t exist. So I had to find a way to load the wifi drivers so that hostapd would come up.
I discovered that I can run “svc wifi enable” to install the drivers and bring up the wlan0 interface. Then “svc wifi disable” would bring down the wlan0 interface but leave the drivers installed. At this point, hostapd was perfectly happy.
So to bring this all together, I needed a script that could be launched at boot time that would delay the starting to hostapd until later in the boot process. Here’s what I did.
su mount -o rw,remount /system cd /system/etc/init.d cat > 50hostapd #!/system/bin/sh /data/start_hostapd.sh & ^D chmod 755 50hostapd
Now install the following script as /data/start_hostapd.sh:
#!/system/bin/sh while true; do su -c svc wifi enable sleep 1 netcfg | grep wlan0 && break sleep 10 done su -c svc wifi disable sleep 2 /system/bin/hostapd -e /data/misc/wifi/entropy.bin /data/misc/wifi/hostapd.conf &
chmod 755 /data/start_hostapd.sh
and you should be good to go.
root@deb:/ # ps | grep hostapd wifi 1282 1 2416 1000 c0138fe4 b6ee46d8 S /system/bin/hostapd