]> git.ipfire.org Git - thirdparty/iw.git/blob - util.c
iw: add support for 5 and 10 MHz channels in IBSS mode
[thirdparty/iw.git] / util.c
1 #include <ctype.h>
2 #include <netlink/attr.h>
3 #include <errno.h>
4 #include <stdbool.h>
5 #include "iw.h"
6 #include "nl80211.h"
7
8 void mac_addr_n2a(char *mac_addr, unsigned char *arg)
9 {
10 int i, l;
11
12 l = 0;
13 for (i = 0; i < ETH_ALEN ; i++) {
14 if (i == 0) {
15 sprintf(mac_addr+l, "%02x", arg[i]);
16 l += 2;
17 } else {
18 sprintf(mac_addr+l, ":%02x", arg[i]);
19 l += 3;
20 }
21 }
22 }
23
24 int mac_addr_a2n(unsigned char *mac_addr, char *arg)
25 {
26 int i;
27
28 for (i = 0; i < ETH_ALEN ; i++) {
29 int temp;
30 char *cp = strchr(arg, ':');
31 if (cp) {
32 *cp = 0;
33 cp++;
34 }
35 if (sscanf(arg, "%x", &temp) != 1)
36 return -1;
37 if (temp < 0 || temp > 255)
38 return -1;
39
40 mac_addr[i] = temp;
41 if (!cp)
42 break;
43 arg = cp;
44 }
45 if (i < ETH_ALEN - 1)
46 return -1;
47
48 return 0;
49 }
50
51 int parse_hex_mask(char *hexmask, unsigned char **result, size_t *result_len,
52 unsigned char **mask)
53 {
54 size_t len = strlen(hexmask) / 2;
55 unsigned char *result_val;
56 unsigned char *result_mask = NULL;
57
58 int pos = 0;
59
60 *result_len = 0;
61
62 result_val = calloc(len + 2, 1);
63 if (!result_val)
64 goto error;
65 *result = result_val;
66 if (mask) {
67 result_mask = calloc(DIV_ROUND_UP(len, 8) + 2, 1);
68 if (!result_mask)
69 goto error;
70 *mask = result_mask;
71 }
72
73 while (1) {
74 char *cp = strchr(hexmask, ':');
75 if (cp) {
76 *cp = 0;
77 cp++;
78 }
79
80 if (result_mask && (strcmp(hexmask, "-") == 0 ||
81 strcmp(hexmask, "xx") == 0 ||
82 strcmp(hexmask, "--") == 0)) {
83 /* skip this byte and leave mask bit unset */
84 } else {
85 int temp, mask_pos;
86 char *end;
87
88 temp = strtoul(hexmask, &end, 16);
89 if (*end)
90 goto error;
91 if (temp < 0 || temp > 255)
92 goto error;
93 result_val[pos] = temp;
94
95 mask_pos = pos / 8;
96 if (result_mask)
97 result_mask[mask_pos] |= 1 << (pos % 8);
98 }
99
100 (*result_len)++;
101 pos++;
102
103 if (!cp)
104 break;
105 hexmask = cp;
106 }
107
108 return 0;
109 error:
110 free(result_val);
111 free(result_mask);
112 return -1;
113 }
114
115 unsigned char *parse_hex(char *hex, size_t *outlen)
116 {
117 unsigned char *result;
118
119 if (parse_hex_mask(hex, &result, outlen, NULL))
120 return NULL;
121 return result;
122 }
123
124 static const char *ifmodes[NL80211_IFTYPE_MAX + 1] = {
125 "unspecified",
126 "IBSS",
127 "managed",
128 "AP",
129 "AP/VLAN",
130 "WDS",
131 "monitor",
132 "mesh point",
133 "P2P-client",
134 "P2P-GO",
135 "P2P-device",
136 };
137
138 static char modebuf[100];
139
140 const char *iftype_name(enum nl80211_iftype iftype)
141 {
142 if (iftype <= NL80211_IFTYPE_MAX && ifmodes[iftype])
143 return ifmodes[iftype];
144 sprintf(modebuf, "Unknown mode (%d)", iftype);
145 return modebuf;
146 }
147
148 static const char *commands[NL80211_CMD_MAX + 1] = {
149 /*
150 * sed 's/^\tNL80211_CMD_//;t n;d;:n s%^\([^=]*\),.*%\t[NL80211_CMD_\1] = \"\L\1\",%;t;d' nl80211.h
151 */
152 [NL80211_CMD_UNSPEC] = "unspec",
153 [NL80211_CMD_GET_WIPHY] = "get_wiphy",
154 [NL80211_CMD_SET_WIPHY] = "set_wiphy",
155 [NL80211_CMD_NEW_WIPHY] = "new_wiphy",
156 [NL80211_CMD_DEL_WIPHY] = "del_wiphy",
157 [NL80211_CMD_GET_INTERFACE] = "get_interface",
158 [NL80211_CMD_SET_INTERFACE] = "set_interface",
159 [NL80211_CMD_NEW_INTERFACE] = "new_interface",
160 [NL80211_CMD_DEL_INTERFACE] = "del_interface",
161 [NL80211_CMD_GET_KEY] = "get_key",
162 [NL80211_CMD_SET_KEY] = "set_key",
163 [NL80211_CMD_NEW_KEY] = "new_key",
164 [NL80211_CMD_DEL_KEY] = "del_key",
165 [NL80211_CMD_GET_BEACON] = "get_beacon",
166 [NL80211_CMD_SET_BEACON] = "set_beacon",
167 [NL80211_CMD_START_AP] = "start_ap",
168 [NL80211_CMD_STOP_AP] = "stop_ap",
169 [NL80211_CMD_GET_STATION] = "get_station",
170 [NL80211_CMD_SET_STATION] = "set_station",
171 [NL80211_CMD_NEW_STATION] = "new_station",
172 [NL80211_CMD_DEL_STATION] = "del_station",
173 [NL80211_CMD_GET_MPATH] = "get_mpath",
174 [NL80211_CMD_SET_MPATH] = "set_mpath",
175 [NL80211_CMD_NEW_MPATH] = "new_mpath",
176 [NL80211_CMD_DEL_MPATH] = "del_mpath",
177 [NL80211_CMD_SET_BSS] = "set_bss",
178 [NL80211_CMD_SET_REG] = "set_reg",
179 [NL80211_CMD_REQ_SET_REG] = "req_set_reg",
180 [NL80211_CMD_GET_MESH_CONFIG] = "get_mesh_config",
181 [NL80211_CMD_SET_MESH_CONFIG] = "set_mesh_config",
182 [NL80211_CMD_GET_REG] = "get_reg",
183 [NL80211_CMD_GET_SCAN] = "get_scan",
184 [NL80211_CMD_TRIGGER_SCAN] = "trigger_scan",
185 [NL80211_CMD_NEW_SCAN_RESULTS] = "new_scan_results",
186 [NL80211_CMD_SCAN_ABORTED] = "scan_aborted",
187 [NL80211_CMD_REG_CHANGE] = "reg_change",
188 [NL80211_CMD_AUTHENTICATE] = "authenticate",
189 [NL80211_CMD_ASSOCIATE] = "associate",
190 [NL80211_CMD_DEAUTHENTICATE] = "deauthenticate",
191 [NL80211_CMD_DISASSOCIATE] = "disassociate",
192 [NL80211_CMD_MICHAEL_MIC_FAILURE] = "michael_mic_failure",
193 [NL80211_CMD_REG_BEACON_HINT] = "reg_beacon_hint",
194 [NL80211_CMD_JOIN_IBSS] = "join_ibss",
195 [NL80211_CMD_LEAVE_IBSS] = "leave_ibss",
196 [NL80211_CMD_TESTMODE] = "testmode",
197 [NL80211_CMD_CONNECT] = "connect",
198 [NL80211_CMD_ROAM] = "roam",
199 [NL80211_CMD_DISCONNECT] = "disconnect",
200 [NL80211_CMD_SET_WIPHY_NETNS] = "set_wiphy_netns",
201 [NL80211_CMD_GET_SURVEY] = "get_survey",
202 [NL80211_CMD_NEW_SURVEY_RESULTS] = "new_survey_results",
203 [NL80211_CMD_SET_PMKSA] = "set_pmksa",
204 [NL80211_CMD_DEL_PMKSA] = "del_pmksa",
205 [NL80211_CMD_FLUSH_PMKSA] = "flush_pmksa",
206 [NL80211_CMD_REMAIN_ON_CHANNEL] = "remain_on_channel",
207 [NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL] = "cancel_remain_on_channel",
208 [NL80211_CMD_SET_TX_BITRATE_MASK] = "set_tx_bitrate_mask",
209 [NL80211_CMD_REGISTER_FRAME] = "register_frame",
210 [NL80211_CMD_FRAME] = "frame",
211 [NL80211_CMD_FRAME_TX_STATUS] = "frame_tx_status",
212 [NL80211_CMD_SET_POWER_SAVE] = "set_power_save",
213 [NL80211_CMD_GET_POWER_SAVE] = "get_power_save",
214 [NL80211_CMD_SET_CQM] = "set_cqm",
215 [NL80211_CMD_NOTIFY_CQM] = "notify_cqm",
216 [NL80211_CMD_SET_CHANNEL] = "set_channel",
217 [NL80211_CMD_SET_WDS_PEER] = "set_wds_peer",
218 [NL80211_CMD_FRAME_WAIT_CANCEL] = "frame_wait_cancel",
219 [NL80211_CMD_JOIN_MESH] = "join_mesh",
220 [NL80211_CMD_LEAVE_MESH] = "leave_mesh",
221 [NL80211_CMD_UNPROT_DEAUTHENTICATE] = "unprot_deauthenticate",
222 [NL80211_CMD_UNPROT_DISASSOCIATE] = "unprot_disassociate",
223 [NL80211_CMD_NEW_PEER_CANDIDATE] = "new_peer_candidate",
224 [NL80211_CMD_GET_WOWLAN] = "get_wowlan",
225 [NL80211_CMD_SET_WOWLAN] = "set_wowlan",
226 [NL80211_CMD_START_SCHED_SCAN] = "start_sched_scan",
227 [NL80211_CMD_STOP_SCHED_SCAN] = "stop_sched_scan",
228 [NL80211_CMD_SCHED_SCAN_RESULTS] = "sched_scan_results",
229 [NL80211_CMD_SCHED_SCAN_STOPPED] = "sched_scan_stopped",
230 [NL80211_CMD_SET_REKEY_OFFLOAD] = "set_rekey_offload",
231 [NL80211_CMD_PMKSA_CANDIDATE] = "pmksa_candidate",
232 [NL80211_CMD_TDLS_OPER] = "tdls_oper",
233 [NL80211_CMD_TDLS_MGMT] = "tdls_mgmt",
234 [NL80211_CMD_UNEXPECTED_FRAME] = "unexpected_frame",
235 [NL80211_CMD_PROBE_CLIENT] = "probe_client",
236 [NL80211_CMD_REGISTER_BEACONS] = "register_beacons",
237 [NL80211_CMD_UNEXPECTED_4ADDR_FRAME] = "unexpected_4addr_frame",
238 [NL80211_CMD_SET_NOACK_MAP] = "set_noack_map",
239 [NL80211_CMD_CH_SWITCH_NOTIFY] = "ch_switch_notify",
240 [NL80211_CMD_START_P2P_DEVICE] = "start_p2p_device",
241 [NL80211_CMD_STOP_P2P_DEVICE] = "stop_p2p_device",
242 [NL80211_CMD_CONN_FAILED] = "conn_failed",
243 [NL80211_CMD_SET_MCAST_RATE] = "set_mcast_rate",
244 [NL80211_CMD_SET_MAC_ACL] = "set_mac_acl",
245 [NL80211_CMD_RADAR_DETECT] = "radar_detect",
246 [NL80211_CMD_GET_PROTOCOL_FEATURES] = "get_protocol_features",
247 [NL80211_CMD_UPDATE_FT_IES] = "update_ft_ies",
248 [NL80211_CMD_FT_EVENT] = "ft_event",
249 [NL80211_CMD_CRIT_PROTOCOL_START] = "crit_protocol_start",
250 [NL80211_CMD_CRIT_PROTOCOL_STOP] = "crit_protocol_stop",
251 };
252
253 static char cmdbuf[100];
254
255 const char *command_name(enum nl80211_commands cmd)
256 {
257 if (cmd <= NL80211_CMD_MAX && commands[cmd])
258 return commands[cmd];
259 sprintf(cmdbuf, "Unknown command (%d)", cmd);
260 return cmdbuf;
261 }
262
263 int ieee80211_channel_to_frequency(int chan, enum nl80211_band band)
264 {
265 /* see 802.11 17.3.8.3.2 and Annex J
266 * there are overlapping channel numbers in 5GHz and 2GHz bands */
267 if (chan <= 0)
268 return 0; /* not supported */
269 switch (band) {
270 case NL80211_BAND_2GHZ:
271 if (chan == 14)
272 return 2484;
273 else if (chan < 14)
274 return 2407 + chan * 5;
275 break;
276 case NL80211_BAND_5GHZ:
277 if (chan >= 182 && chan <= 196)
278 return 4000 + chan * 5;
279 else
280 return 5000 + chan * 5;
281 break;
282 case NL80211_BAND_60GHZ:
283 if (chan < 5)
284 return 56160 + chan * 2160;
285 break;
286 default:
287 ;
288 }
289 return 0; /* not supported */
290 }
291
292 int ieee80211_frequency_to_channel(int freq)
293 {
294 /* see 802.11-2007 17.3.8.3.2 and Annex J */
295 if (freq == 2484)
296 return 14;
297 else if (freq < 2484)
298 return (freq - 2407) / 5;
299 else if (freq >= 4910 && freq <= 4980)
300 return (freq - 4000) / 5;
301 else if (freq <= 45000) /* DMG band lower limit */
302 return (freq - 5000) / 5;
303 else if (freq >= 58320 && freq <= 64800)
304 return (freq - 56160) / 2160;
305 else
306 return 0;
307 }
308
309 void print_ssid_escaped(const uint8_t len, const uint8_t *data)
310 {
311 int i;
312
313 for (i = 0; i < len; i++) {
314 if (isprint(data[i]) && data[i] != ' ' && data[i] != '\\')
315 printf("%c", data[i]);
316 else if (data[i] == ' ' &&
317 (i != 0 && i != len -1))
318 printf(" ");
319 else
320 printf("\\x%.2x", data[i]);
321 }
322 }
323
324 static int hex2num(char digit)
325 {
326 if (!isxdigit(digit))
327 return -1;
328 if (isdigit(digit))
329 return digit - '0';
330 return tolower(digit) - 'a' + 10;
331 }
332
333 static int hex2byte(char *hex)
334 {
335 int d1, d2;
336
337 d1 = hex2num(hex[0]);
338 if (d1 < 0)
339 return -1;
340 d2 = hex2num(hex[1]);
341 if (d2 < 0)
342 return -1;
343 return (d1 << 4) | d2;
344 }
345
346 static char *hex2bin(char *hex, char *buf)
347 {
348 char *result = buf;
349 int d;
350
351 while (hex[0]) {
352 d = hex2byte(hex);
353 if (d < 0)
354 return NULL;
355 buf[0] = d;
356 buf++;
357 hex += 2;
358 }
359
360 return result;
361 }
362
363 int parse_keys(struct nl_msg *msg, char **argv, int argc)
364 {
365 struct nlattr *keys;
366 int i = 0;
367 bool have_default = false;
368 char keybuf[13];
369
370 if (!argc)
371 return 1;
372
373 NLA_PUT_FLAG(msg, NL80211_ATTR_PRIVACY);
374
375 keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
376 if (!keys)
377 return -ENOBUFS;
378
379 do {
380 char *arg = *argv;
381 int pos = 0, keylen;
382 struct nlattr *key = nla_nest_start(msg, ++i);
383 char *keydata;
384
385 if (!key)
386 return -ENOBUFS;
387
388 if (arg[pos] == 'd') {
389 NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT);
390 pos++;
391 if (arg[pos] == ':')
392 pos++;
393 have_default = true;
394 }
395
396 if (!isdigit(arg[pos]))
397 goto explain;
398 NLA_PUT_U8(msg, NL80211_KEY_IDX, arg[pos++] - '0');
399 if (arg[pos++] != ':')
400 goto explain;
401 keydata = arg + pos;
402 switch (strlen(keydata)) {
403 case 10:
404 keydata = hex2bin(keydata, keybuf);
405 case 5:
406 NLA_PUT_U32(msg, NL80211_KEY_CIPHER, 0x000FAC01);
407 keylen = 5;
408 break;
409 case 26:
410 keydata = hex2bin(keydata, keybuf);
411 case 13:
412 NLA_PUT_U32(msg, NL80211_KEY_CIPHER, 0x000FAC05);
413 keylen = 13;
414 break;
415 default:
416 goto explain;
417 }
418
419 if (!keydata)
420 goto explain;
421
422 NLA_PUT(msg, NL80211_KEY_DATA, keylen, keydata);
423
424 argv++;
425 argc--;
426
427 /* one key should be TX key */
428 if (!have_default && !argc)
429 NLA_PUT_FLAG(msg, NL80211_KEY_DEFAULT);
430
431 nla_nest_end(msg, key);
432 } while (argc);
433
434 nla_nest_end(msg, keys);
435
436 return 0;
437 nla_put_failure:
438 return -ENOBUFS;
439 explain:
440 fprintf(stderr, "key must be [d:]index:data where\n"
441 " 'd:' means default (transmit) key\n"
442 " 'index:' is a single digit (0-3)\n"
443 " 'data' must be 5 or 13 ascii chars\n"
444 " or 10 or 26 hex digits\n"
445 "for example: d:2:6162636465 is the same as d:2:abcde\n");
446 return 2;
447 }
448
449 static void print_mcs_index(const __u8 *mcs)
450 {
451 int mcs_bit, prev_bit = -2, prev_cont = 0;
452
453 for (mcs_bit = 0; mcs_bit <= 76; mcs_bit++) {
454 unsigned int mcs_octet = mcs_bit/8;
455 unsigned int MCS_RATE_BIT = 1 << mcs_bit % 8;
456 bool mcs_rate_idx_set;
457
458 mcs_rate_idx_set = !!(mcs[mcs_octet] & MCS_RATE_BIT);
459
460 if (!mcs_rate_idx_set)
461 continue;
462
463 if (prev_bit != mcs_bit - 1) {
464 if (prev_bit != -2)
465 printf("%d, ", prev_bit);
466 else
467 printf(" ");
468 printf("%d", mcs_bit);
469 prev_cont = 0;
470 } else if (!prev_cont) {
471 printf("-");
472 prev_cont = 1;
473 }
474
475 prev_bit = mcs_bit;
476 }
477
478 if (prev_cont)
479 printf("%d", prev_bit);
480 printf("\n");
481 }
482
483 /*
484 * There are only 4 possible values, we just use a case instead of computing it,
485 * but technically this can also be computed through the formula:
486 *
487 * Max AMPDU length = (2 ^ (13 + exponent)) - 1 bytes
488 */
489 static __u32 compute_ampdu_length(__u8 exponent)
490 {
491 switch (exponent) {
492 case 0: return 8191; /* (2 ^(13 + 0)) -1 */
493 case 1: return 16383; /* (2 ^(13 + 1)) -1 */
494 case 2: return 32767; /* (2 ^(13 + 2)) -1 */
495 case 3: return 65535; /* (2 ^(13 + 3)) -1 */
496 default: return 0;
497 }
498 }
499
500 static const char *print_ampdu_space(__u8 space)
501 {
502 switch (space) {
503 case 0: return "No restriction";
504 case 1: return "1/4 usec";
505 case 2: return "1/2 usec";
506 case 3: return "1 usec";
507 case 4: return "2 usec";
508 case 5: return "4 usec";
509 case 6: return "8 usec";
510 case 7: return "16 usec";
511 default:
512 return "BUG (spacing more than 3 bits!)";
513 }
514 }
515
516 void print_ampdu_length(__u8 exponent)
517 {
518 __u32 max_ampdu_length;
519
520 max_ampdu_length = compute_ampdu_length(exponent);
521
522 if (max_ampdu_length) {
523 printf("\t\tMaximum RX AMPDU length %d bytes (exponent: 0x0%02x)\n",
524 max_ampdu_length, exponent);
525 } else {
526 printf("\t\tMaximum RX AMPDU length: unrecognized bytes "
527 "(exponent: %d)\n", exponent);
528 }
529 }
530
531 void print_ampdu_spacing(__u8 spacing)
532 {
533 printf("\t\tMinimum RX AMPDU time spacing: %s (0x%02x)\n",
534 print_ampdu_space(spacing), spacing);
535 }
536
537 void print_ht_capability(__u16 cap)
538 {
539 #define PRINT_HT_CAP(_cond, _str) \
540 do { \
541 if (_cond) \
542 printf("\t\t\t" _str "\n"); \
543 } while (0)
544
545 printf("\t\tCapabilities: 0x%02x\n", cap);
546
547 PRINT_HT_CAP((cap & BIT(0)), "RX LDPC");
548 PRINT_HT_CAP((cap & BIT(1)), "HT20/HT40");
549 PRINT_HT_CAP(!(cap & BIT(1)), "HT20");
550
551 PRINT_HT_CAP(((cap >> 2) & 0x3) == 0, "Static SM Power Save");
552 PRINT_HT_CAP(((cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
553 PRINT_HT_CAP(((cap >> 2) & 0x3) == 3, "SM Power Save disabled");
554
555 PRINT_HT_CAP((cap & BIT(4)), "RX Greenfield");
556 PRINT_HT_CAP((cap & BIT(5)), "RX HT20 SGI");
557 PRINT_HT_CAP((cap & BIT(6)), "RX HT40 SGI");
558 PRINT_HT_CAP((cap & BIT(7)), "TX STBC");
559
560 PRINT_HT_CAP(((cap >> 8) & 0x3) == 0, "No RX STBC");
561 PRINT_HT_CAP(((cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
562 PRINT_HT_CAP(((cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
563 PRINT_HT_CAP(((cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
564
565 PRINT_HT_CAP((cap & BIT(10)), "HT Delayed Block Ack");
566
567 PRINT_HT_CAP(!(cap & BIT(11)), "Max AMSDU length: 3839 bytes");
568 PRINT_HT_CAP((cap & BIT(11)), "Max AMSDU length: 7935 bytes");
569
570 /*
571 * For beacons and probe response this would mean the BSS
572 * does or does not allow the usage of DSSS/CCK HT40.
573 * Otherwise it means the STA does or does not use
574 * DSSS/CCK HT40.
575 */
576 PRINT_HT_CAP((cap & BIT(12)), "DSSS/CCK HT40");
577 PRINT_HT_CAP(!(cap & BIT(12)), "No DSSS/CCK HT40");
578
579 /* BIT(13) is reserved */
580
581 PRINT_HT_CAP((cap & BIT(14)), "40 MHz Intolerant");
582
583 PRINT_HT_CAP((cap & BIT(15)), "L-SIG TXOP protection");
584 #undef PRINT_HT_CAP
585 }
586
587 void print_ht_mcs(const __u8 *mcs)
588 {
589 /* As defined in 7.3.2.57.4 Supported MCS Set field */
590 unsigned int tx_max_num_spatial_streams, max_rx_supp_data_rate;
591 bool tx_mcs_set_defined, tx_mcs_set_equal, tx_unequal_modulation;
592
593 max_rx_supp_data_rate = (mcs[10] & ((mcs[11] & 0x3) << 8));
594 tx_mcs_set_defined = !!(mcs[12] & (1 << 0));
595 tx_mcs_set_equal = !(mcs[12] & (1 << 1));
596 tx_max_num_spatial_streams = ((mcs[12] >> 2) & 3) + 1;
597 tx_unequal_modulation = !!(mcs[12] & (1 << 4));
598
599 if (max_rx_supp_data_rate)
600 printf("\t\tHT Max RX data rate: %d Mbps\n", max_rx_supp_data_rate);
601 /* XXX: else see 9.6.0e.5.3 how to get this I think */
602
603 if (tx_mcs_set_defined) {
604 if (tx_mcs_set_equal) {
605 printf("\t\tHT TX/RX MCS rate indexes supported:");
606 print_mcs_index(mcs);
607 } else {
608 printf("\t\tHT RX MCS rate indexes supported:");
609 print_mcs_index(mcs);
610
611 if (tx_unequal_modulation)
612 printf("\t\tTX unequal modulation supported\n");
613 else
614 printf("\t\tTX unequal modulation not supported\n");
615
616 printf("\t\tHT TX Max spatial streams: %d\n",
617 tx_max_num_spatial_streams);
618
619 printf("\t\tHT TX MCS rate indexes supported may differ\n");
620 }
621 } else {
622 printf("\t\tHT RX MCS rate indexes supported:");
623 print_mcs_index(mcs);
624 printf("\t\tHT TX MCS rate indexes are undefined\n");
625 }
626 }
627
628 void print_vht_info(__u32 capa, const __u8 *mcs)
629 {
630 __u16 tmp;
631 int i;
632
633 printf("\t\tVHT Capabilities (0x%.8x):\n", capa);
634
635 #define PRINT_VHT_CAPA(_bit, _str) \
636 do { \
637 if (capa & BIT(_bit)) \
638 printf("\t\t\t" _str "\n"); \
639 } while (0)
640
641 printf("\t\t\tMax MPDU length: ");
642 switch (capa & 3) {
643 case 0: printf("3895\n"); break;
644 case 1: printf("7991\n"); break;
645 case 2: printf("11454\n"); break;
646 case 3: printf("(reserved)\n");
647 }
648 printf("\t\t\tSupported Channel Width: ");
649 switch ((capa >> 2) & 3) {
650 case 0: printf("neither 160 nor 80+80\n"); break;
651 case 1: printf("160 MHz\n"); break;
652 case 2: printf("160 MHz, 80+80 MHz\n"); break;
653 case 3: printf("(reserved)\n");
654 }
655 PRINT_VHT_CAPA(4, "RX LDPC");
656 PRINT_VHT_CAPA(5, "short GI (80 MHz)");
657 PRINT_VHT_CAPA(6, "short GI (160/80+80 MHz)");
658 PRINT_VHT_CAPA(7, "TX STBC");
659 /* RX STBC */
660 PRINT_VHT_CAPA(11, "SU Beamformer");
661 PRINT_VHT_CAPA(12, "SU Beamformee");
662 /* compressed steering */
663 /* # of sounding dimensions */
664 PRINT_VHT_CAPA(19, "MU Beamformer");
665 PRINT_VHT_CAPA(20, "MU Beamformee");
666 PRINT_VHT_CAPA(21, "VHT TXOP PS");
667 PRINT_VHT_CAPA(22, "+HTC-VHT");
668 /* max A-MPDU */
669 /* VHT link adaptation */
670 PRINT_VHT_CAPA(29, "RX antenna pattern consistency");
671 PRINT_VHT_CAPA(30, "TX antenna pattern consistency");
672
673 printf("\t\tVHT RX MCS set:\n");
674 tmp = mcs[0] | (mcs[1] << 8);
675 for (i = 1; i <= 8; i++) {
676 printf("\t\t\t%d streams: ", i);
677 switch ((tmp >> ((i-1)*2) ) & 3) {
678 case 0: printf("MCS 0-7\n"); break;
679 case 1: printf("MCS 0-8\n"); break;
680 case 2: printf("MCS 0-9\n"); break;
681 case 3: printf("not supported\n"); break;
682 }
683 }
684 tmp = mcs[2] | (mcs[3] << 8);
685 printf("\t\tVHT RX highest supported: %d Mbps\n", tmp & 0x1fff);
686
687 printf("\t\tVHT TX MCS set:\n");
688 tmp = mcs[4] | (mcs[5] << 8);
689 for (i = 1; i <= 8; i++) {
690 printf("\t\t\t%d streams: ", i);
691 switch ((tmp >> ((i-1)*2) ) & 3) {
692 case 0: printf("MCS 0-7\n"); break;
693 case 1: printf("MCS 0-8\n"); break;
694 case 2: printf("MCS 0-9\n"); break;
695 case 3: printf("not supported\n"); break;
696 }
697 }
698 tmp = mcs[6] | (mcs[7] << 8);
699 printf("\t\tVHT TX highest supported: %d Mbps\n", tmp & 0x1fff);
700 }