libnl/nl80211 equivalent of iw_set_ext
libnl/nl80211 equivalent of iw_set_ext
当我意识到它被弃用并且大多数应用程序使用nl80211时,我开始编写使用iwconfig/ioctl处理wifi卡的代码。我开始阅读它的源代码,但没有文档,代码有点复杂。我如何使用nl80211或libl做一些简单的事情,比如扫描、关闭/打开、设置卡片模式?这是我从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);
}
}
是否有iw_get_ext的等效设置/获取wifi接口或任何api与简单的功能,如"set_mode"或"power_off"?
我使用以下步骤扫描netlink
- 准备并执行NL80211_CMD_TRIGGER_SCAN
-
准备并执行NL80211_CMD_GET_SCAN
与NL80211_CMD_GET_SCAN一起注册回调。在回调中,原始数据被解析为BSS。IE被解析为。查看nl80211.h中NL80211_BSS_MAX, NL80211_ATTR_MAX的枚举
检查每个netlink调用的返回值,然后再进行下一步。
代码片段:
nl_sock* socket = nl_socket_alloc();
genl_connect(socket);
struct nl_msg* msg = nlmsg_alloc();
int driverId = genl_ctrl_resolve(socket, "nl80211");
genlmsg_put(msg, 0, 0, driverId, 0, 0, NL80211_CMD_TRIGGER_SCAN, 0);
和取:
genlmsg_put(msg, 0, 0, driverId, 0, NLM_F_DUMP, NL80211_CMD_GET_SCAN, 0);
nl_socket_modify_cb(socket, NL_CB_VALID, NL_CB_CUSTOM, onScanResult, null);
我的回调开始于:
struct genlmsghdr* msgHeader = (genlmsghdr*)nlmsg_data(nlmsg_hdr(msg));
struct nlattr* attributes[NL80211_ATTR_MAX + 1];
struct nlattr* bss[NL80211_BSS_MAX + 1];
if(nla_parse(attributes, NL80211_ATTR_MAX, genlmsg_attrdata(msgHeader, 0), genlmsg_attrlen(msgHeader, 0), NULL) == 0)
{
// Read the attributes
// and check for NL80211_ATTR_BSS != 0
}
我在NL80211_BSS_INFORMATION_ELEMENTS中找到了大多数扫描结果。
if (nla_parse_nested(bss, NL80211_BSS_MAX, attributes[NL80211_ATTR_BSS], bss_policy) == 0)
{ /* read the bss attributes */ }
参见NL80211_BSS_INFORMATION_ELEMENTS from nl80211.h and
但是我没有检查WEP隐私。检查WPA或WPA2很容易,因为有一个额外的IE元素ID 48 (Śee IEEE标准802.11 2012,章节8.4.2,免费下载从IEEE侧)
相关文章:
- 为什么我无法更改"set<set>"循环中的值<int>
- 对于set上的循环-获取next元素迭代器
- SampleConsensusPrerejective(ext.RANSAC)是如何真正工作的
- 在声明中合并两个常量"std::set"(不是在运行时)
- 有没有办法对std::unordered_set、std::unrdered_map、std::set、std::map
- 将 std::set 与基于键的比较器一起使用
- 如何使用set实现无序数据结构?
- 使用运算符调用 void 函数时出错<set>
- 修改"std::set"中用户定义类型的值
- 生成提升::hana::set 的常量表达式问题
- 如何在构造函数参数中初始化"std::set"?
- 如何使用 lower_bound/upper_bound 从 std::set 获取索引号?
- 如何在 C++ 中转发声明 std::set?
- 重构使用动态强制转换的 std::set 的比较运算符
- set::find 查找不存在的元素
- 为什么 std::set.erase(first, last) 会影响从中获取 (first, last) 的容器?
- 将 std:set<int32_t> 复制到 std::set <uint32_t>的好方法
- 错误 C2676:std::set::const_iterator 没有运算符 + 函数?
- std::set 是否将对象连续存储在内存中?
- 是否有一个 std::set 函数来确定不超过数字 x 的最大元素?