libnl
libnl copied to clipboard
How to check the NL80211_ATTR_SUPPORTED_IFTYPES attribute?
I am trying to use Python to determine whether a wireless card supports AP mode. I started with example_show_wifi_interface.py, and I thought I would be able to add a bit of code like this to the callback() function right before it prints:
if tb[nl80211.NL80211_ATTR_SUPPORTED_IFTYPES]:
iftypes = nla_get_u32(tb[NL80211_ATTR_SUPPORTED_IFTYPES])
rem = c_int()
ap_mode = False
for subattr in nla_for_each_nested(tb[iftypes], rem):
if subattr == nl80211.NL80211_IFTYPE_AP:
ap_mode = True
break
table.table_data.append(['Supports AP mode', str(ap_mode)])
else:
print("Couldn't get attribute NL80211_ATTR_SUPPORTED_IFTYPES")
However, tb[nl80211.NL80211_ATTR_SUPPORTED_IFTYPES] is evaluating to None, and I don't know why, or even where to start looking for the right path forward. My first thought was to try to read some C code that uses the nl80211 library and model my Python on that, but the only thing I discovered was that I'm not enough of a C programmer to understand how iw is working internally :).
What am I doing wrong?
Usually when items in tb evaluate to None it means that the kernel/driver did not have that data to populate the dictionary with.
This library is really designed for people already familiar with the C libnl library, or more specifically, I wrote this library so I could use existing (though rare) examples of the C libnl library out on the internet.
What I would do in this case is first check if iw shows your wireless adapter does in fact support AP mode (I'm sure there's a command line option for it, been a while since I worked on this library). If it does, then I would look into its source code and try and figure out what command is sent to the kernel that produces the data you're looking for. It's possible NL80211_CMD_GET_INTERFACE doesn't cause the kernel to give you this information, maybe there's another command? Unfortunately there is no way around having to go through iw's code ;)
Sorry I can't be of much help, I haven't worked with libnl for a few months since starting my new job. I'm hoping to resume working on/with it but I'm not sure when that will be.
Ah, sorry, probably should have included that - iw does show the adapter as supporting AP mode.
Supported interface modes:
* IBSS
* managed
* AP
* AP/VLAN
* WDS
* monitor
* mesh point
Based on my understanding of nl80211 though, I thought NL80211_ATTR_SUPPORTED_IFTYPES would return the modes it does support, even if AP mode isn't one of them? I'll keep digging in iw's source as I have the time though. Thanks for the reply.