我尝试扩展“iw”实用程序以允许它设置 802.11 争用窗口的最大和最小大小。但我总是收到“无效参数 (-22)”返回。
我编辑了 iw-3.15 源代码的 phy.c 并附加了
static int handle_txq(struct nl80211_state *state,
struct nl_cb *cb,
struct nl_msg *msg,
int argc, char **argv,
enum id_input id)
{
unsigned int cw_min, cw_max;
printf("HANDLE TXQ");
if (argc != 2)
return 1;
cw_min = atoi(argv[0]);
cw_max = atoi(argv[1]);
printf("setting contention window to: %d - %d\n",cw_min,cw_max);
//create nested txq array
struct nlattr *nested;
nested = nla_nest_start(msg,NL80211_ATTR_WIPHY_TXQ_PARAMS);
NLA_PUT_U16(msg,NL80211_TXQ_ATTR_CWMIN,cw_min);
NLA_PUT_U16(msg,NL80211_TXQ_ATTR_CWMAX,cw_max);
nla_nest_end(msg,nested);
return 0;
nla_put_failure:
return -ENOBUFS;
}
COMMAND(set, txq, "<cw_min> <cw_max>",
NL80211_CMD_SET_WIPHY, 0, CIB_NETDEV, handle_txq,
"Set contention window minimum and maximum size.\n"
"Valid values: 1 - 32767 in the form 2^n-1");
COMMAND(set, txq, "<cw_min> <cw_max>",
NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_txq,
"Set contention window minimum and maximum size.\n"
"Valid values: 1 - 32767 in the form 2^n-1");
除了头文件本身之外,我找不到任何关于 nl80211 的好的文档或者它通过 netlink 的用法。我不是 确保我根据规范构造嵌套消息并使用 U16 作为属性是有根据的猜测(它们在匹配的 cfg80211 中是 uint_16)。
根据我对 netlink 的理解,我的消息汇编应该是正确的,但由于我收到错误,我可能是错的...... 有人有 nl80211 及其用法的好文档吗?谁能发现我的问题吗?
最佳答案
从 netlink 套接字另一端的内核代码(在 linux/net/wireless/nl80211.c 中 - 我使用的是 3.13.0-30)来看,似乎有几个原因可以导致“无效”参数”(-EINVAL)响应。
首先,您需要给它一个有效的接口(interface),并且设备需要处于AP或P2P_GO模式。您还需要提供所有 TXQ 参数,而不仅仅是争用窗口值。如果您想准确了解消息的处理方式,请参阅 nl80211.c 中的 nl80211_set_wiphy() 和 parse_txq_params() 函数。
不过,您似乎确实使用了正确的参数类型:NL80211_TXQ_ATTR_QUEUE/NL80211_TXQ_ATTR_AC(取决于版本)和NL80211_TXQ_ATTR_AIFS是u8,其他三个(NL80211_TXQ_ATTR_TXOP、NL80211_TXQ_ATTR_CWMIN和NL80211_TX Q_ATTR_CWMAX) 为 u16。
关于c - libnl '尝试使用 nl80211 时参数无效(-22),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24289775/