尝试使用nl80211时libnl'无效参数(-22)

时间:2014-06-18 15:41:39

标签: c linux-kernel wireless netlink

我试图延长' 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");

除了头文件本身之外,我无法通过netlink找到nl80211的任何好文档或它的用法。我不是 确定我是否根据规范构建了嵌套消息,并且使用U16作为属性是一个有根据的猜测(在匹配的cfg80211中它们是uint_16)。

根据我对netlink的理解,我的消息汇编应该是正确的,但由于我收到错误,我可能错了...... 有没有人有nl80211及其用法的良好文档?有谁能发现我的问题?

1 个答案:

答案 0 :(得分:1)

从netlink套接字另一端的内核代码(在linux / net / wireless / nl80211.c中 - 我使用的是3.13.0-30),似乎有几个原因你可以得到一个&# 34;无效的论证&#34; (-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和NL80211_TXQ_ATTR_CWMAX)是u16。

相关问题