]>
Commit | Line | Data |
---|---|---|
9ceb6854 HS |
1 | #include <net/if.h> |
2 | #include <errno.h> | |
3 | #include <string.h> | |
4 | ||
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> | |
10 | ||
11 | #include "nl80211.h" | |
12 | #include "iw.h" | |
13 | ||
14 | SECTION(survey); | |
15 | ||
16 | static int print_survey_handler(struct nl_msg *msg, void *arg) | |
17 | { | |
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]; | |
21 | char dev[20]; | |
22 | ||
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 }, | |
26 | }; | |
27 | ||
28 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | |
29 | genlmsg_attrlen(gnlh, 0), NULL); | |
30 | ||
31 | if_indextoname(nla_get_u32(tb[NL80211_ATTR_IFINDEX]), dev); | |
32 | printf("Survey data from %s\n", dev); | |
33 | ||
34 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | |
35 | fprintf(stderr, "survey data missing!\n"); | |
36 | return NL_SKIP; | |
37 | } | |
38 | ||
39 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | |
40 | tb[NL80211_ATTR_SURVEY_INFO], | |
41 | survey_policy)) { | |
42 | fprintf(stderr, "failed to parse nested attributes!\n"); | |
43 | return NL_SKIP; | |
44 | } | |
45 | ||
46 | if (sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | |
47 | printf("\tfrequency:\t%u MHz\n", | |
48 | nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY])); | |
49 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) | |
50 | printf("\tnoise:\t\t%d dBm\n", | |
51 | (int8_t)nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE])); | |
52 | return NL_SKIP; | |
53 | } | |
54 | ||
55 | static int handle_survey_dump(struct nl80211_state *state, | |
56 | struct nl_cb *cb, | |
57 | struct nl_msg *msg, | |
58 | int argc, char **argv) | |
59 | { | |
60 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_survey_handler, NULL); | |
61 | return 0; | |
62 | } | |
63 | COMMAND(survey, dump, NULL, | |
64 | NL80211_CMD_GET_SURVEY, NLM_F_DUMP, CIB_NETDEV, handle_survey_dump, | |
65 | "List all gathered channel survey data"); | |
66 |