Get Wi-Fi protocol (802.11a/b/g/n) programmatically
Asked Answered
T

2

19

Through WifiManager, my Android app can get a lot of details about Wi-Fi. However I fail to get protocol type like a/b/g/n. I have a client requirement to do that.

Does anyone know how to achieve that? (I don't have the option to use adb). It is to be done programmatically. I strongly believe that device and router have already negotiated protocol before they can connect. So that information is there with device. Question is, how do we get it?

Triceratops answered 23/9, 2013 at 18:0 Comment(0)
A
13

You can partially deduce the protocol from the link speed

WifiManager.getConnectionInfo().getLinkSpeed()

By Wikipedia 802.11 protocols speed table you can tell if it is 802.11b, 802.11n or 802.11ag.
802.11n and 802.11ac full link speed tables

Link speeds of protocols 802.11a and 802.11g are the same, you can distinguish between them by the used frequency (5GHz or 2.4GHz) in the scan results.

Note that protocol can change during the connection, client and access point do negotiate protocols and speeds but they agree on a list and not on one specific speed.

I don't think there is a way to distinguish between 802.11n and 802.11ac in their overlapping speeds.

Anam answered 7/1, 2014 at 11:9 Comment(3)
It appears that not all devices report speeds that correlate to the Wikipedia table, but I have yet to find a better source. For example, my EVO often shows 19, 26, 39, and 52 Mbps speeds. But it also shows 65 Mbps sometimes, which is on that table. Any ideas?Kristakristal
Nevermind -- further reading on that page shows that 802.11n speeds could be 10% lower in some situations. That must apply to the EVO but not any of my other devices.Kristakristal
@mikejeep - I guess they did not want to blow up the table, link speeds of the newer protocols 802.11n and 802.11ac have many more options. 65Mbps is a valid speed of both.Anam
L
2

I don't believe this is possible to get in a clean manner. The protocols - a, b, g, n, etc - are actually human abstractions of the MAC and physical layer in networks. These are defined as their recognizable letters if they meet certain hardware specifications, both for the device and the network device.

After doing some digging, it seems that Windows phones are able to display this information. When digging into the manner of determining the protocol on Windows, I came across the desktop explanation as well as the Visual C++ implementation via enums. It seems that even the official Windows documentation relies on vendor-provided data and enumerated values, which would lead me to believe that they need to determine hardware specifications beyond what is likely exposed in the Android API.

If you want to determine the protocol yourself, you'll need to understand the link speed as well as the frequency, modulation, and bandwidth.

TL;DR

Likely not possible unless you are working with a rooted phone and can access the hardware specs directly.

Loire answered 14/5, 2015 at 20:28 Comment(1)
Windows 10 also appears to be able to work out the protocolHerodotus

© 2022 - 2024 — McMap. All rights reserved.