5 #include <netlink/genl/genl.h>
6 #include <netlink/genl/family.h>
7 #include <netlink/genl/ctrl.h>
8 #include <netlink/msg.h>
9 #include <netlink/attr.h>
16 static int print_survey_handler(struct nl_msg
*msg
, void *arg
)
18 struct nlattr
*tb
[NL80211_ATTR_MAX
+ 1];
19 struct genlmsghdr
*gnlh
= nlmsg_data(nlmsg_hdr(msg
));
20 struct nlattr
*sinfo
[NL80211_SURVEY_INFO_MAX
+ 1];
23 static struct nla_policy survey_policy
[NL80211_SURVEY_INFO_MAX
+ 1] = {
24 [NL80211_SURVEY_INFO_FREQUENCY
] = { .type
= NLA_U32
},
25 [NL80211_SURVEY_INFO_NOISE
] = { .type
= NLA_U8
},
28 nla_parse(tb
, NL80211_ATTR_MAX
, genlmsg_attrdata(gnlh
, 0),
29 genlmsg_attrlen(gnlh
, 0), NULL
);
31 if_indextoname(nla_get_u32(tb
[NL80211_ATTR_IFINDEX
]), dev
);
32 printf("Survey data from %s\n", dev
);
34 if (!tb
[NL80211_ATTR_SURVEY_INFO
]) {
35 fprintf(stderr
, "survey data missing!\n");
39 if (nla_parse_nested(sinfo
, NL80211_SURVEY_INFO_MAX
,
40 tb
[NL80211_ATTR_SURVEY_INFO
],
42 fprintf(stderr
, "failed to parse nested attributes!\n");
46 if (sinfo
[NL80211_SURVEY_INFO_FREQUENCY
])
47 printf("\tfrequency:\t%u MHz%s\n",
48 nla_get_u32(sinfo
[NL80211_SURVEY_INFO_FREQUENCY
]),
49 sinfo
[NL80211_SURVEY_INFO_IN_USE
] ? " [in use]" : "");
50 if (sinfo
[NL80211_SURVEY_INFO_NOISE
])
51 printf("\tnoise:\t\t%d dBm\n",
52 (int8_t)nla_get_u8(sinfo
[NL80211_SURVEY_INFO_NOISE
]));
56 static int handle_survey_dump(struct nl80211_state
*state
,
59 int argc
, char **argv
)
61 nl_cb_set(cb
, NL_CB_VALID
, NL_CB_CUSTOM
, print_survey_handler
, NULL
);
64 COMMAND(survey
, dump
, NULL
,
65 NL80211_CMD_GET_SURVEY
, NLM_F_DUMP
, CIB_NETDEV
, handle_survey_dump
,
66 "List all gathered channel survey data");