Reputation: 850
I tried to extend the 'iw' utility to allow it to set the maximum and minimum size of the 802.11 contention window. But I'm always getting a 'invalid argument (-22)' returned.
I edited phy.c of the iw-3.15 source and appended
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");
I couldn't find any good documentation of nl80211 or it's usage through netlink except the header file itself. I am not sure if I contruct the nested message according to specification and using U16 for the attributes are an educated guess (they are uint_16 in the matching cfg80211).
From my understanding of netlink my message assembly should be correct, but since I get an error I'm probably wrong... Does anyone have a good documentation for nl80211 and its usage? Can anyone spot my problem?
Upvotes: 0
Views: 2018
Reputation: 26
From the kernel code on the other end of the netlink socket (in linux/net/wireless/nl80211.c - I am using 3.13.0-30), it seems there are a few reasons you can get an "invalid argument" (-EINVAL) response.
Firstly, you need to give it a valid interface and the device needs to be in AP or P2P_GO mode. You also need to provide all the TXQ params, not just contention window values. See the nl80211_set_wiphy() and parse_txq_params() functions in nl80211.c if you want to see exactly how your message is being handled.
You do appear to be using the correct types for the parameters though: NL80211_TXQ_ATTR_QUEUE/NL80211_TXQ_ATTR_AC (depending on version) and NL80211_TXQ_ATTR_AIFS are u8, and the other three (NL80211_TXQ_ATTR_TXOP, NL80211_TXQ_ATTR_CWMIN and NL80211_TXQ_ATTR_CWMAX) are u16.
Upvotes: 1