0

我尝试扩展“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 及其用法的良好文档吗?谁能发现我的问题?

4

1 回答 1

1

从 netlink 套接字另一端的内核代码(在 linux/net/wireless/nl80211.c - 我使用的是 3.13.0-30),似乎有几个原因可以获得“无效参数”( -EINVAL) 响应。

首先,您需要给它一个有效的接口,并且设备需要处于 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 和 NL8021116Q_ATTR_CW)是

于 2014-07-24T07:10:03.150 回答