Juuso Oikarinen | 7988b22 | 2010-03-26 07:46:19 +0200 | [diff] [blame] | 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 | |
Sunil Ravi | 44e0e58 | 2022-03-05 11:09:09 -0800 | [diff] [blame] | 12 | static int iw_cqm_rssi(struct nl80211_state *state, |
Johannes Berg | 05514f9 | 2012-07-19 11:50:50 +0200 | [diff] [blame] | 13 | struct nl_msg *msg, int argc, char **argv, |
| 14 | enum id_input id) |
Juuso Oikarinen | 7988b22 | 2010-03-26 07:46:19 +0200 | [diff] [blame] | 15 | { |
| 16 | struct nl_msg *cqm = NULL; |
| 17 | int thold = 0; |
| 18 | int hyst = 0; |
| 19 | int ret = -ENOSPC; |
| 20 | |
| 21 | /* get the required args */ |
| 22 | if (argc < 1 || argc > 2) |
| 23 | return 1; |
| 24 | |
| 25 | if (strcmp(argv[0], "off")) { |
| 26 | thold = atoi(argv[0]); |
| 27 | |
| 28 | if (thold == 0) |
| 29 | return -EINVAL; |
| 30 | |
| 31 | if (argc == 2) |
| 32 | hyst = atoi(argv[1]); |
| 33 | } |
| 34 | |
| 35 | /* connection quality monitor attributes */ |
| 36 | cqm = nlmsg_alloc(); |
Sunil Ravi | 44e0e58 | 2022-03-05 11:09:09 -0800 | [diff] [blame] | 37 | if (!cqm) |
| 38 | return -ENOMEM; |
Juuso Oikarinen | 7988b22 | 2010-03-26 07:46:19 +0200 | [diff] [blame] | 39 | |
| 40 | NLA_PUT_U32(cqm, NL80211_ATTR_CQM_RSSI_THOLD, thold); |
| 41 | NLA_PUT_U32(cqm, NL80211_ATTR_CQM_RSSI_HYST, hyst); |
| 42 | |
| 43 | nla_put_nested(msg, NL80211_ATTR_CQM, cqm); |
| 44 | ret = 0; |
| 45 | |
| 46 | nla_put_failure: |
| 47 | nlmsg_free(cqm); |
| 48 | return ret; |
| 49 | } |
| 50 | |
| 51 | TOPLEVEL(cqm, "", |
| 52 | 0, 0, CIB_NETDEV, NULL, |
| 53 | "Configure the WLAN connection quality monitor.\n"); |
| 54 | |
| 55 | COMMAND(cqm, rssi, "<threshold|off> [<hysteresis>]", |
| 56 | NL80211_CMD_SET_CQM, 0, CIB_NETDEV, iw_cqm_rssi, |
| 57 | "Set connection quality monitor RSSI threshold.\n"); |