Ad-hoc Wifi in Android

Suppose you want one Android phone to connect to another. Unfortunately, the WifiManager in stock Android ignores ad-hoc networks. There are a couple ways around this:

  • One is to modify the Android framework to support ad-hoc networks (I recall seeing some custom ROM for Samsung Moment that had this).
  • Another is to manually configure the wpa_supplicant to connect to an ad-hoc network.
  • Yet another one is to patch the wpa_supplicant to pretend that ad-hoc networks are regular access points. This was my method.

The original purpose of this patch was to enable an Android device tether to another Android phone using Barnacle Wifi Tether.

ad-hoc support in wpa_supplicant

At this time, Android does not support ad-hoc networks. That is, ad-hoc (IBSS) entries are filtered out from the scan results reported by the wpa_supplicant.

To add ad-hoc network support one could augment the WifiStateTracker to not filter IBSS entries out and set the wpa_supplicant in AP_SCAN 2 mode to establish new IBSS instead of associating with a scanned one. That would require fiddling with the Java framework on the phone.

A more crazy way to do this is to augment the wpa_supplicant to masquerade ad- hoc networks as regular infrastructure access points (APs). This makes changes only to the wpa_supplicant and allows a drop in replacement on rooted phones.

Necessary Changes

The patch below modifies the wpa_supplicant code in the external/wpa_supplicant AOSP repo to make ad-hoc networks appear as regular APs with a (*) prefix.

The patch:

  • removes the [IBSS] flag from scan results,
  • masquerades and demasquerades ad-hoc ssid with (*) prefix
  • sets mode 1 (ad-hoc) if the ssid is for IBSS
  • permits the supplicant to select an IBSS when associating to a given ssid


I've shared some thoughts on the future of ad-hoc in here

blog comments powered by Disqus