]> git.ipfire.org Git - thirdparty/iw.git/blame - info.c
add note to readme about maintenance, patch sending
[thirdparty/iw.git] / info.c
CommitLineData
79f99b9a 1#include <errno.h>
2ef1be68
JB
2#include <net/if.h>
3
79f99b9a
JB
4#include <netlink/genl/genl.h>
5#include <netlink/genl/family.h>
6#include <netlink/genl/ctrl.h>
7#include <netlink/msg.h>
8#include <netlink/attr.h>
79f99b9a 9
f408e01b 10#include "nl80211.h"
79f99b9a
JB
11#include "iw.h"
12
13static void print_flag(const char *name, int *open)
14{
15 if (!*open)
16 printf(" (");
17 else
18 printf(", ");
19 printf(name);
20 *open = 1;
21}
22
23static int print_phy_handler(struct nl_msg *msg, void *arg)
24{
25 struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
26 struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
27
28 struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1];
29
30 struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1];
31 static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = {
32 [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 },
33 [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG },
34 [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG },
35 [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG },
36 [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG },
37 };
38
39 struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1];
40 static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = {
41 [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 },
42 [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG },
43 };
44
45 struct nlattr *nl_band;
46 struct nlattr *nl_freq;
47 struct nlattr *nl_rate;
6367e71a 48 struct nlattr *nl_mode;
79f99b9a 49 int bandidx = 1;
6367e71a 50 int rem_band, rem_freq, rem_rate, rem_mode;
79f99b9a
JB
51 int open;
52
53 nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
54 genlmsg_attrlen(gnlh, 0), NULL);
55
56 if (!tb_msg[NL80211_ATTR_WIPHY_BANDS])
57 return NL_SKIP;
58
d631650b
JB
59 if (tb_msg[NL80211_ATTR_WIPHY_NAME])
60 printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME]));
61
79f99b9a 62 nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) {
d631650b 63 printf("\tBand %d:\n", bandidx);
79f99b9a
JB
64 bandidx++;
65
66 nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band),
67 nla_len(nl_band), NULL);
68
3dd781cc
JB
69#ifdef NL80211_BAND_ATTR_HT_CAPA
70 if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) {
71 unsigned short cap = nla_get_u16(tb_band[NL80211_BAND_ATTR_HT_CAPA]);
72#define PCOM(fmt, args...) do { printf("\t\t\t * " fmt "\n", ##args); } while (0)
73#define PBCOM(bit, args...) if (cap & (bit)) PCOM(args)
74 printf("\t\tHT capabilities: 0x%.4x\n", cap);
75 PBCOM(0x0001, "LPDC coding");
76 if (cap & 0x0002)
77 PCOM("20/40 MHz operation");
78 else
79 PCOM("20 MHz operation");
80 switch ((cap & 0x000c) >> 2) {
81 case 0:
82 PCOM("static SM PS");
83 break;
84 case 1:
85 PCOM("dynamic SM PS");
86 break;
87 case 2:
88 PCOM("reserved SM PS");
89 break;
90 case 3:
91 PCOM("SM PS disabled");
92 break;
93 }
94 PBCOM(0x0010, "HT-greenfield");
95 PBCOM(0x0020, "20 MHz short GI");
96 PBCOM(0x0040, "40 MHz short GI");
97 PBCOM(0x0080, "TX STBC");
98 if (cap & 0x300)
99 PCOM("RX STBC %d streams", (cap & 0x0300) >> 8);
100 PBCOM(0x0400, "HT-delayed block-ack");
101 PCOM("max A-MSDU len %d", 0xeff + ((cap & 0x0800) << 1));
102 PBCOM(0x1000, "DSSS/CCK 40 MHz");
103 PBCOM(0x2000, "PSMP support");
104 PBCOM(0x4000, "40 MHz intolerant");
105 PBCOM(0x8000, "L-SIG TXOP protection support");
106 }
107 if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) {
108 unsigned char factor = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]);
109 printf("\t\tHT A-MPDU factor: 0x%.4x (%d bytes)\n", factor, (1<<(13+factor))-1);
110 }
111 if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) {
112 unsigned char dens = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]);
113 printf("\t\tHT A-MPDU density: 0x%.4x (", dens);
114 switch (dens) {
115 case 0:
116 printf("no restriction)\n");
117 break;
118 case 1:
119 printf("1/4 usec)\n");
120 break;
121 case 2:
122 printf("1/2 usec)\n");
123 break;
124 default:
125 printf("%d usec)\n", 1<<(dens - 3));
126 }
127 }
128 if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] &&
129 nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16) {
130 unsigned char *mcs = nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]);
131 printf("\t\tHT MCS set: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n",
132 mcs[0], mcs[1], mcs[2], mcs[3], mcs[4], mcs[5], mcs[6], mcs[7],
133 mcs[8], mcs[9], mcs[10], mcs[11], mcs[12], mcs[13], mcs[14], mcs[15]);
134 }
135#endif
136
d631650b 137 printf("\t\tFrequencies:\n");
79f99b9a
JB
138
139 nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) {
140 nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq),
141 nla_len(nl_freq), freq_policy);
142 if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ])
143 continue;
d631650b 144 printf("\t\t\t* %d MHz", nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ]));
79f99b9a
JB
145 open = 0;
146 if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED])
147 print_flag("disabled", &open);
148 if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN])
149 print_flag("passive scanning", &open);
150 if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS])
151 print_flag("no IBSS", &open);
152 if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR])
153 print_flag("radar detection", &open);
154 if (open)
155 printf(")");
156 printf("\n");
157 }
158
d631650b 159 printf("\t\tBitrates:\n");
79f99b9a
JB
160
161 nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) {
162 nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate),
163 nla_len(nl_rate), rate_policy);
164 if (!tb_rate[NL80211_BITRATE_ATTR_RATE])
165 continue;
d631650b 166 printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE]));
79f99b9a
JB
167 open = 0;
168 if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE])
169 print_flag("short preamble supported", &open);
170 if (open)
171 printf(")");
172 printf("\n");
173 }
174 }
175
6367e71a
JB
176 if (!tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES])
177 return NL_SKIP;
178
d631650b 179 printf("\tSupported interface modes:\n");
541ef425 180 nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode)
d631650b 181 printf("\t\t * %s\n", iftype_name(nl_mode->nla_type));
6367e71a 182
79f99b9a
JB
183 return NL_SKIP;
184}
185
70391ccf 186static int handle_info(struct nl_cb *cb,
d631650b
JB
187 struct nl_msg *msg,
188 int argc, char **argv)
79f99b9a 189{
79f99b9a 190 nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL);
79f99b9a 191
70391ccf 192 return 0;
79f99b9a 193}
d631650b
JB
194TOPLEVEL(info, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_PHY, handle_info);
195TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info);