Search code examples
androidandroid-wifi

Flag Wifi as mobile hotspot based on its name from code


Situation

  • I have an android tablet connecting to an onboard unit (OBU) an a car via WiFi.
  • The OBU has SIM card providing access to internet.
  • The apps on the tablet communicate with server via the internet provided by the OBU.
  • So, basically the OBU serves as mobile hotspot for the tablet.

Problem

  • The tablet performs updates that consume lot of data because it thinks it on Wifi
  • This leads to depleting of the data limit available to the SIM card
  • This leads to failure of the whole solution
  • ... or extra costs for each additional MB (over the limit) of transferred data

Facts

Goal

  • To flag a Wifi network as mobile hotspot from android code based on its SSID

Any ideas?


Solution

  • WiFis don't reliably identify themselves as mobile hotspots. Basically, a hotspot tells you nothing about how it's connected to the Internet, so there isn't a clean way of telling. The hotspot's upstream connection could be anything out of the following:

    • a residential (DSL, cable, fiber) Internet connection
    • a mobile data connection
    • a captive portal, which requires authentication on a dedicated web page before you are allowed on the Internet
    • a corporate network, requiring you to use a proxy server for Web access and blocking most non-HTTP[s] services
    • an isolated network with no Internet connectivity at all.

    (How to detect if you're connected to one of the latter three is described here).

    Radiobeacon (licensed under AGPLv3) has an approach to detect mobile hotspots. (The idea here is somewhat different, as the app georeferences hotspots to use for position tracking, and thus needs to filter out hotspots whose position is likely to change – but those tend to be on mobile data connections, so you should get a good hit rate from them.)

    By SSID

    This is one of the two methods employed by Radiobeacon. Examine the SSID for patterns that are commonly used in mobile hotspots (strings such as Android, mobile, iPhone and the like). Of course, anyone could use that in their non-mobile hotspot (people do get creative about their SSID names), so there's both a false acceptance and false rejection rate to consider.

    By BSSID

    The other method employed by Radiobeacon: Look at the BSSID (the hardware address of the hotspot). The BSSID is a hexadecimal string of the form 00:60:0d:c0:ff:ee, of which the first half identifies the manufacturer of the chip. Some chips are used mainly in mobile equipment while others are used in fixed equipment, thus some prefixes indicate a mobile hotspot. A few prefixes will already help you filter out all iPhones. Still, there may be prefixes that are found in both mobile and fixed equipment, and we're not even talking about home routers which have a mobile data connection as their upstream link.

    For both these examples, visit the Radiobeacon link for the code containing the blacklists. They have been obtained by trial and error, may be far from complete or even contain errors – but they may serve as a starting point.

    Using WiFi Location Services

    As a third method, you can also try looking up the geographic coordinates for the BSSID through a service such as Mozilla Location Service. There are a handful of other, smaller providers out there, plus the services offered by Google and Apple, but the last two are probably not legal to use for that purpose.

    Though I don't really know the details of how these service handle mobile WiFis, they will need to do take some precaution to prevent using these to establish the user's location. The may eliminate hotspots from the database if they move around too frequently, or give them a low confidence interval, or just keep them in the database and leave it up to the consumer to decide which BSSID-location tuples to use for establishing their location.

    If they go for one of the first two approaches, then getting a position with a high confidence (up to 2000m, which is the typical range of a WiFi) is a sign that you're on a fixed WiFi. If they go for the last approach, you will additionally need to establish your position by means of GPS or cell lookup. If that is far away from the WiFi's location (something beyond 4000 meters), that indicates a mobile hotspot.

    By External IP Address

    A fourth approach you could look into is to determine your external IP address (not the one assigned to your device but the one that your communication peers would see as the originating Internet address), and matching that against a list of Internet providers. You'll need to research that a bit:

    • how to determine your external IP address – it's easiest if you can just set up your own web service that echoes the IP address back to the requester
    • how to find out from the IP address whether it belongs to a mobile carrier – reverse DNS lookup may shed some more light on that.

    Again, there is a chance of carriers using the same IP address pool for both mobile and fixed data customers.

    In conclusion

    All approaches mentioned here may give false negatives or false positives. You will probably want to combine he result of all four methods into a likelihood that you're on a mobile data connection, and avoid moving large amounts of data if the likelihood exceeds a certain threshold.