]> git.ipfire.org Git - thirdparty/iw.git/blob - cqm.c
iw: Add support for connection quality monitor configuation
[thirdparty/iw.git] / cqm.c
1 #include <errno.h>
2
3 #include <netlink/genl/genl.h>
4 #include <netlink/genl/family.h>
5 #include <netlink/genl/ctrl.h>
6 #include <netlink/msg.h>
7 #include <netlink/attr.h>
8
9 #include "nl80211.h"
10 #include "iw.h"
11
12 static int iw_cqm_rssi(struct nl80211_state *state, struct nl_cb *cb,
13 struct nl_msg *msg, int argc, char **argv)
14 {
15 struct nl_msg *cqm = NULL;
16 int thold = 0;
17 int hyst = 0;
18 int ret = -ENOSPC;
19
20 /* get the required args */
21 if (argc < 1 || argc > 2)
22 return 1;
23
24 if (strcmp(argv[0], "off")) {
25 thold = atoi(argv[0]);
26
27 if (thold == 0)
28 return -EINVAL;
29
30 if (argc == 2)
31 hyst = atoi(argv[1]);
32 }
33
34 /* connection quality monitor attributes */
35 cqm = nlmsg_alloc();
36
37 NLA_PUT_U32(cqm, NL80211_ATTR_CQM_RSSI_THOLD, thold);
38 NLA_PUT_U32(cqm, NL80211_ATTR_CQM_RSSI_HYST, hyst);
39
40 nla_put_nested(msg, NL80211_ATTR_CQM, cqm);
41 ret = 0;
42
43 nla_put_failure:
44 nlmsg_free(cqm);
45 return ret;
46 }
47
48 TOPLEVEL(cqm, "",
49 0, 0, CIB_NETDEV, NULL,
50 "Configure the WLAN connection quality monitor.\n");
51
52 COMMAND(cqm, rssi, "<threshold|off> [<hysteresis>]",
53 NL80211_CMD_SET_CQM, 0, CIB_NETDEV, iw_cqm_rssi,
54 "Set connection quality monitor RSSI threshold.\n");