title: Android 4.2.2+ Hotspot
body: <p>I hooked into the /system/bin/netd binary to log all of the commands that are sent by the Android framework when it puts up a hotspot via clicking buttons in the system settings menu. (I needed to be able to bring up the hotspot up from shell &amp; ADB without bringing up the settings menu.)</p>
  
  <p>This returned all of the commands that are used to put up the hotspot.</p>
  
  <pre><code>    interface clearaddrs wlan0 
      interface ipv6 wlan0 disable 
      resolver flushif wlan0 
      bandwidth setglobalalert 2097152 
      bandwidth setglobalalert 2097152 
      softap fwreload wlan0 AP 
      softap set wlan0 asdfa wpa2-psk 12345678 
      softap startap 
      interface getcfg wlan0 
      interface setcfg wlan0 192.168.43.1 24 running multicast broadcast up 
      tether interface add wlan0 
      ipfwd enable 
      tether start 192.168.42.2 192.168.42.254 192.168.43.2 192.168.43.254 192.168.44.2 192.168.44.254 192.168.45.2 192.168.45.254 192.168.46.2 192.168.46.254 192.168.47.2 192.168.47.254 192.168.48.2 192.168.48.254 
      tether dns set 8.8.8.8 8.8.4.4
  </code></pre>
  
  <p>Seems OK.</p>
  
  <p>When I issue those commands through /system/bin/ndc from shell, nothing returns an error and claims that it succeeded. Great. Fantastic. Wonderful.</p>
  
  <pre><code>    200 0 Interface IP addresses cleared
      200 0 IPv6 state changed
      200 0 Resolver command succeeded
      200 0 Bandwidth command succeeeded
      200 0 Bandwidth command succeeeded
      200 0 Softap operation succeeded
      200 0 Softap operation succeeded
      600 Iface linkstate wlan0 down
      600 Iface linkstate wlan0 down
      200 0 Softap operation succeeded
      213 0 44:33:4c:3d:98:dc 0.0.0.0 0 down broadcast multicast
      200 0 Interface configuration set
      200 0 Tether operation succeeded
      200 0 ipfwd operation succeeded
      200 0 Tether operation succeeded
      200 0 Tether operation succeeded
  </code></pre>
  
  <p>Super! Except for the little trivial fact that the hotspot cannot be seen afterwards and it doesn't even kick me off the wireless connection, so obviously I am missing something. </p>
  
  <p>It might be useful to note that in Android 4.1.1 the following works (as expected), but in 4.2.2 it does not; I have tried endless combinations of the logged commands and the 4.1.1 commands to very little avail.</p>
  
  <pre><code>    softap stopap
      softap stop wlan0
      softap fwreload ap0 AP
      softap start wlan0 
      softap set wlan0 ap0 SSID wpa2-psk 12345678 11 0 8
      softap startap
      interface setcfg ap0 192.168.2.254 255.255.255.0 up
  </code></pre>
  
  <p>Here is what happens when the hotspot is taken down via the system settings menu, maybe it will be helpful:</p>
  
  <pre><code>    interface getcfg wlan0 
      interface setcfg wlan0 0.0.0.0 0 running multicast broadcast up 
      tether interface remove wlan0 
      tether stop 
      ipfwd disable 
      softap stopap 
      softap fwreload wlan0 STA 
      softap fwreload wlan0 STA 
      interface getcfg wlan0 
      interface setcfg wlan0 0.0.0.0 0 multicast broadcast down 
      interface ipv6privacyextensions wlan0 enable 
      interface getcfg p2p0 
      interface setcfg p2p0 0.0.0.0 0 multicast broadcast up 
      interface ipv6 wlan0 enable 
      interface route add wlan0 default 192.168.2.254 32 0.0.0.0 
      interface route add wlan0 default 0.0.0.0 0 192.168.2.254 
      resolver flushif wlan0 
      interface route add wlan0 default 192.168.2.254 32 0.0.0.0 
      bandwidth setglobalalert 2097152 
      interface route add wlan0 default 0.0.0.0 0 192.168.2.254 
      bandwidth setglobalalert 2097152
  </code></pre>
  
  <p>This is what is logged during system startup before any user input is possible:</p>
  
  <pre><code>    interface list 
      interface getcfg eth0 
      interface ipv6 wlan0 disable 
      interface list 
      bandwidth enable 
      softap fwreload wlan0 STA 
      firewall disable 
      interface getcfg wlan0 
      interface setcfg wlan0 0.0.0.0 0 multicast broadcast down 
      interface ipv6privacyextensions wlan0 enable 
      bandwidth setglobalalert 2097152 
      firewall disable 
      interface setthrottle rmnet0 -1 -1 
      interface getcfg p2p0 
      interface setcfg p2p0 0.0.0.0 0 multicast broadcast up 
      interface ipv6 wlan0 enable 
      resolver setifdns wlan0 192.168.2.254 
      resolver setdefaultif wlan0 
      interface route add wlan0 default 192.168.2.254 32 0.0.0.0 
      interface route add wlan0 default 0.0.0.0 0 192.168.2.254 
      resolver flushif wlan0 
      interface route add wlan0 default 192.168.2.254 32 0.0.0.0 
      interface route add wlan0 default 0.0.0.0 0 192.168.2.254
  </code></pre>
  
  <p>The only thing I do know for sure is that I can trigger the hotspot to come up in 4.4.3 when I issue commands to netd prior to the bootanimation completion. </p>
  
  <p>Where did I go wrong?</p>