I started writing a code to handle wifi card using iwconfig/ioctl when I realised that it is depricated and most of applications uses nl80211. I started reading its source code but there is no docs and code is a bit complicated. How can I do simple things like scanning, turning off/on, setting card mode using nl80211 or libnl? This is what I started with iw:
void set_card_mode(MODE mode, std::string ifname)
{
int skfd = iw_sockets_open();
struct iwreq wrq;
wrq.u.mode = static_cast<unsigned int>(mode);
power_interface(ifname, false);
if(iw_set_ext(skfd, ifname.c_str(), SIOCSIWMODE, &wrq) < 0)
throw std::runtime_error("Can set card mode");
}
MODE get_card_mode(std::string ifname)
{
int skfd = iw_sockets_open();
struct iwreq wrq;
if (iw_get_ext (skfd, ifname.c_str(), SIOCGIWMODE, &wrq) >= 0)
{
return static_cast<MODE>(wrq.u.mode);
}
}
Is there any equivalent of iw_get_ext to set/get wifi interface or any api with simple functions like "set_mode" or "power_off"?