]> git.ipfire.org Git - thirdparty/iw.git/commitdiff
display noise level from survey data
authorHolger Schurig <holgerschurig@gmail.com>
Wed, 11 Nov 2009 10:36:34 +0000 (11:36 +0100)
committerJohannes Berg <johannes@sipsolutions.net>
Mon, 16 Nov 2009 18:54:36 +0000 (19:54 +0100)
Sample output:

Survey data from wlan0
        frequency:      2412 MHz
        noise:          -92 dBm

Signed-off-by: Holger Schurig <holgerschurig@gmail.com>
Makefile
survey.c [new file with mode: 0644]

index 1174130f21fdf74cf2047db8668fe4bc60b213de..2a6fc9a51599ae4413f46f67f4e63864d2b0bbb5 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -15,7 +15,7 @@ CFLAGS ?= -O2 -g
 CFLAGS += -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration
 
 OBJS = iw.o genl.o event.o info.o phy.o \
-       interface.o ibss.o station.o util.o \
+       interface.o ibss.o station.o survey.o util.o \
        mesh.o mpath.o scan.o reg.o version.o \
        reason.o status.o connect.o link.o
 OBJS += sections.o
diff --git a/survey.c b/survey.c
new file mode 100644 (file)
index 0000000..f9f2508
--- /dev/null
+++ b/survey.c
@@ -0,0 +1,66 @@
+#include <net/if.h>
+#include <errno.h>
+#include <string.h>
+
+#include <netlink/genl/genl.h>
+#include <netlink/genl/family.h>
+#include <netlink/genl/ctrl.h>
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+#include "nl80211.h"
+#include "iw.h"
+
+SECTION(survey);
+
+static int print_survey_handler(struct nl_msg *msg, void *arg)
+{
+       struct nlattr *tb[NL80211_ATTR_MAX + 1];
+       struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
+       struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
+       char dev[20];
+
+       static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
+               [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
+               [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
+       };
+
+       nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
+                 genlmsg_attrlen(gnlh, 0), NULL);
+
+       if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev);
+       printf("Survey data from %s\n", dev);
+
+       if (!tb[NL80211_ATTR_SURVEY_INFO]) {
+               fprintf(stderr, "survey data missing!\n");
+               return NL_SKIP;
+       }
+
+       if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
+                            tb[NL80211_ATTR_SURVEY_INFO],
+                            survey_policy)) {
+               fprintf(stderr, "failed to parse nested attributes!\n");
+               return NL_SKIP;
+       }
+
+       if (sinfo[NL80211_SURVEY_INFO_FREQUENCY])
+               printf("\tfrequency:\t%u MHz\n",
+                       nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]));
+       if (sinfo[NL80211_SURVEY_INFO_NOISE])
+               printf("\tnoise:\t\t%d dBm\n",
+                       (int8_t)nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]));
+       return NL_SKIP;
+}
+
+static int handle_survey_dump(struct nl80211_state *state,
+                              struct nl_cb *cb,
+                              struct nl_msg *msg,
+                              int argc, char **argv)
+{
+       nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_survey_handler, NULL);
+       return 0;
+}
+COMMAND(survey, dump, NULL,
+       NL80211_CMD_GET_SURVEY, NLM_F_DUMP, CIB_NETDEV, handle_survey_dump,
+       "List all gathered channel survey data");
+