2 #include <netlink/attr.h>
8 void mac_addr_n2a(char *mac_addr
, const unsigned char *arg
)
13 for (i
= 0; i
< ETH_ALEN
; i
++) {
15 sprintf(mac_addr
+l
, "%02x", arg
[i
]);
18 sprintf(mac_addr
+l
, ":%02x", arg
[i
]);
24 int mac_addr_a2n(unsigned char *mac_addr
, char *arg
)
28 for (i
= 0; i
< ETH_ALEN
; i
++) {
30 char *cp
= strchr(arg
, ':');
35 if (sscanf(arg
, "%x", &temp
) != 1)
37 if (temp
< 0 || temp
> 255)
51 int parse_hex_mask(char *hexmask
, unsigned char **result
, size_t *result_len
,
54 size_t len
= strlen(hexmask
) / 2;
55 unsigned char *result_val
;
56 unsigned char *result_mask
= NULL
;
62 result_val
= calloc(len
+ 2, 1);
67 result_mask
= calloc(DIV_ROUND_UP(len
, 8) + 2, 1);
74 char *cp
= strchr(hexmask
, ':');
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 */
88 temp
= strtoul(hexmask
, &end
, 16);
91 if (temp
< 0 || temp
> 255)
93 result_val
[pos
] = temp
;
97 result_mask
[mask_pos
] |= 1 << (pos
% 8);
115 unsigned char *parse_hex(char *hex
, size_t *outlen
)
117 unsigned char *result
;
119 if (parse_hex_mask(hex
, &result
, outlen
, NULL
))
124 static const char *ifmodes
[NL80211_IFTYPE_MAX
+ 1] = {
136 "outside context of a BSS",
140 static char modebuf
[100];
142 const char *iftype_name(enum nl80211_iftype iftype
)
144 if (iftype
<= NL80211_IFTYPE_MAX
&& ifmodes
[iftype
])
145 return ifmodes
[iftype
];
146 sprintf(modebuf
, "Unknown mode (%d)", iftype
);
150 static const char *commands
[NL80211_CMD_MAX
+ 1] = {
151 #include "nl80211-commands.inc"
154 static char cmdbuf
[100];
156 const char *command_name(enum nl80211_commands cmd
)
158 if (cmd
<= NL80211_CMD_MAX
&& commands
[cmd
])
159 return commands
[cmd
];
160 sprintf(cmdbuf
, "Unknown command (%d)", cmd
);
164 int ieee80211_channel_to_frequency(int chan
, enum nl80211_band band
)
166 /* see 802.11 17.3.8.3.2 and Annex J
167 * there are overlapping channel numbers in 5GHz and 2GHz bands */
169 return 0; /* not supported */
171 case NL80211_BAND_2GHZ
:
175 return 2407 + chan
* 5;
177 case NL80211_BAND_5GHZ
:
178 if (chan
>= 182 && chan
<= 196)
179 return 4000 + chan
* 5;
181 return 5000 + chan
* 5;
183 case NL80211_BAND_60GHZ
:
185 return 56160 + chan
* 2160;
190 return 0; /* not supported */
193 int ieee80211_frequency_to_channel(int freq
)
195 /* see 802.11-2007 17.3.8.3.2 and Annex J */
198 else if (freq
< 2484)
199 return (freq
- 2407) / 5;
200 else if (freq
>= 4910 && freq
<= 4980)
201 return (freq
- 4000) / 5;
202 else if (freq
<= 45000) /* DMG band lower limit */
203 return (freq
- 5000) / 5;
204 else if (freq
>= 58320 && freq
<= 64800)
205 return (freq
- 56160) / 2160;
210 void print_ssid_escaped(const uint8_t len
, const uint8_t *data
)
214 for (i
= 0; i
< len
; i
++) {
215 if (isprint(data
[i
]) && data
[i
] != ' ' && data
[i
] != '\\')
216 printf("%c", data
[i
]);
217 else if (data
[i
] == ' ' &&
218 (i
!= 0 && i
!= len
-1))
221 printf("\\x%.2x", data
[i
]);
225 static int hex2num(char digit
)
227 if (!isxdigit(digit
))
231 return tolower(digit
) - 'a' + 10;
234 static int hex2byte(const char *hex
)
238 d1
= hex2num(hex
[0]);
241 d2
= hex2num(hex
[1]);
244 return (d1
<< 4) | d2
;
247 char *hex2bin(const char *hex
, char *buf
)
264 static int parse_akm_suite(const char *cipher_str
)
267 if (!strcmp(cipher_str
, "PSK"))
269 if (!strcmp(cipher_str
, "FT/PSK"))
271 if (!strcmp(cipher_str
, "PSK/SHA-256"))
276 static int parse_cipher_suite(const char *cipher_str
)
279 if (!strcmp(cipher_str
, "TKIP"))
281 if (!strcmp(cipher_str
, "CCMP") || !strcmp(cipher_str
, "CCMP-128"))
283 if (!strcmp(cipher_str
, "GCMP") || !strcmp(cipher_str
, "GCMP-128"))
285 if (!strcmp(cipher_str
, "GCMP-256"))
287 if (!strcmp(cipher_str
, "CCMP-256"))
292 int parse_keys(struct nl_msg
*msg
, char **argv
[], int *argc
)
296 bool have_default
= false;
304 if (!memcmp(&arg
[pos
], "psk", 3)) {
306 int cipher_suite
, akm_suite
;
316 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, NL80211_WPA_VERSION_2
);
318 if (strlen(&arg
[pos
]) != (sizeof(psk_keybuf
) * 2) || !hex2bin(&arg
[pos
], psk_keybuf
)) {
323 NLA_PUT(msg
, NL80211_ATTR_PMK
, 32, psk_keybuf
);
324 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, NL80211_AUTHTYPE_OPEN_SYSTEM
);
330 akm_suite
= parse_akm_suite(arg
);
334 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, akm_suite
);
340 cipher_suite
= parse_cipher_suite(arg
);
341 if (cipher_suite
< 0)
344 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher_suite
);
350 cipher_suite
= parse_cipher_suite(arg
);
351 if (cipher_suite
< 0)
354 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher_suite
);
361 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
363 keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
369 struct nlattr
*key
= nla_nest_start(msg
, ++i
);
378 if (arg
[pos
] == 'd') {
379 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
386 if (!isdigit(arg
[pos
]))
388 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, arg
[pos
++] - '0');
389 if (arg
[pos
++] != ':')
392 switch (strlen(keydata
)) {
394 keydata
= hex2bin(keydata
, keybuf
);
397 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, 0x000FAC01);
401 keydata
= hex2bin(keydata
, keybuf
);
404 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, 0x000FAC05);
414 NLA_PUT(msg
, NL80211_KEY_DATA
, keylen
, keydata
);
419 /* one key should be TX key */
420 if (!have_default
&& !*argc
)
421 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
423 nla_nest_end(msg
, key
);
426 nla_nest_end(msg
, keys
);
432 fprintf(stderr
, "key must be [d:]index:data where\n"
433 " 'd:' means default (transmit) key\n"
434 " 'index:' is a single digit (0-3)\n"
435 " 'data' must be 5 or 13 ascii chars\n"
436 " or 10 or 26 hex digits\n"
437 "for example: d:2:6162636465 is the same as d:2:abcde\n"
438 "or psk:data <AKM Suite> <pairwise CIPHER> <groupwise CIPHER> where\n"
439 " 'data' is the PSK (output of wpa_passphrase and the CIPHER can be CCMP or GCMP\n"
440 "for example: psk:0123456789abcdef PSK CCMP CCMP\n"
441 "The allowed AKM suites are PSK, FT/PSK, PSK/SHA-256\n"
442 "The allowed Cipher suites are TKIP, CCMP, GCMP, GCMP-256, CCMP-256\n");
446 enum nl80211_chan_width
str_to_bw(const char *str
)
448 static const struct {
452 { .name
= "5", .val
= NL80211_CHAN_WIDTH_5
, },
453 { .name
= "10", .val
= NL80211_CHAN_WIDTH_10
, },
454 { .name
= "20", .val
= NL80211_CHAN_WIDTH_20
, },
455 { .name
= "40", .val
= NL80211_CHAN_WIDTH_40
, },
456 { .name
= "80", .val
= NL80211_CHAN_WIDTH_80
, },
457 { .name
= "80+80", .val
= NL80211_CHAN_WIDTH_80P80
, },
458 { .name
= "160", .val
= NL80211_CHAN_WIDTH_160
, },
462 for (i
= 0; i
< ARRAY_SIZE(bwmap
); i
++) {
463 if (strcasecmp(bwmap
[i
].name
, str
) == 0)
467 return NL80211_CHAN_WIDTH_20_NOHT
;
470 static int parse_freqs(struct chandef
*chandef
, int argc
, char **argv
,
475 bool need_cf1
= false, need_cf2
= false;
480 chandef
->width
= str_to_bw(argv
[0]);
482 switch (chandef
->width
) {
483 case NL80211_CHAN_WIDTH_20_NOHT
:
484 /* First argument was not understood, give up gracefully. */
486 case NL80211_CHAN_WIDTH_20
:
487 case NL80211_CHAN_WIDTH_5
:
488 case NL80211_CHAN_WIDTH_10
:
490 case NL80211_CHAN_WIDTH_80P80
:
493 case NL80211_CHAN_WIDTH_40
:
494 case NL80211_CHAN_WIDTH_80
:
495 case NL80211_CHAN_WIDTH_160
:
511 freq
= strtoul(argv
[1], &end
, 10);
516 chandef
->center_freq1
= freq
;
527 freq
= strtoul(argv
[2], &end
, 10);
530 chandef
->center_freq2
= freq
;
539 * parse_freqchan - Parse frequency or channel definition
541 * @chandef: chandef structure to be filled in
542 * @chan: Boolean whether to parse a channel or frequency based specifier
543 * @argc: Number of arguments
544 * @argv: Array of string arguments
545 * @parsed: Pointer to return the number of used arguments, or NULL to error
546 * out if any argument is left unused.
548 * The given chandef structure will be filled in from the command line
549 * arguments. argc/argv will be updated so that further arguments from the
550 * command line can be parsed.
552 * Note that despite the fact that the function knows how many center freqs
553 * are needed, there's an ambiguity if the next argument after this is an
554 * integer argument, since the valid channel width values are interpreted
555 * as such, rather than a following argument. This can be avoided by the
556 * user by giving "NOHT" instead.
558 * The working specifier if chan is set are:
559 * <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]
561 * And if frequency is set:
562 * <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]
563 * <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]
565 * If the mode/channel width is not given the NOHT is assumed.
567 * Return: Number of used arguments, zero or negative error number otherwise
569 int parse_freqchan(struct chandef
*chandef
, bool chan
, int argc
, char **argv
,
573 static const struct chanmode chanmode
[] = {
575 .width
= NL80211_CHAN_WIDTH_20
,
577 .chantype
= NL80211_CHAN_HT20
},
579 .width
= NL80211_CHAN_WIDTH_40
,
581 .chantype
= NL80211_CHAN_HT40PLUS
},
583 .width
= NL80211_CHAN_WIDTH_40
,
585 .chantype
= NL80211_CHAN_HT40MINUS
},
587 .width
= NL80211_CHAN_WIDTH_20_NOHT
,
589 .chantype
= NL80211_CHAN_NO_HT
},
591 .width
= NL80211_CHAN_WIDTH_5
,
595 .width
= NL80211_CHAN_WIDTH_10
,
599 .width
= NL80211_CHAN_WIDTH_80
,
603 const struct chanmode
*chanmode_selected
= NULL
;
614 freq
= strtoul(argv
[0], &end
, 10);
622 memset(chandef
, 0, sizeof(struct chandef
));
625 enum nl80211_band band
;
627 band
= freq
<= 14 ? NL80211_BAND_2GHZ
: NL80211_BAND_5GHZ
;
628 freq
= ieee80211_channel_to_frequency(freq
, band
);
630 chandef
->control_freq
= freq
;
631 /* Assume 20MHz NOHT channel for now. */
632 chandef
->center_freq1
= freq
;
634 /* Try to parse HT mode definitions */
636 for (i
= 0; i
< ARRAY_SIZE(chanmode
); i
++) {
637 if (strcasecmp(chanmode
[i
].name
, argv
[1]) == 0) {
638 chanmode_selected
= &chanmode
[i
];
645 /* channel mode given, use it and return. */
646 if (chanmode_selected
) {
647 chandef
->center_freq1
= get_cf1(chanmode_selected
, freq
);
648 chandef
->width
= chanmode_selected
->width
;
652 /* This was a only a channel definition, nothing further may follow. */
656 res
= parse_freqs(chandef
, argc
- 1, argv
+ 1, &_parsed
);
659 /* Error out if parsed is NULL. */
660 if (!parsed
&& _parsed
!= argc
)
669 int put_chandef(struct nl_msg
*msg
, struct chandef
*chandef
)
671 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chandef
->control_freq
);
672 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
);
674 switch (chandef
->width
) {
675 case NL80211_CHAN_WIDTH_20_NOHT
:
677 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
680 case NL80211_CHAN_WIDTH_20
:
682 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
685 case NL80211_CHAN_WIDTH_40
:
686 if (chandef
->control_freq
> chandef
->center_freq1
)
688 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
689 NL80211_CHAN_HT40MINUS
);
692 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
693 NL80211_CHAN_HT40PLUS
);
699 if (chandef
->center_freq1
)
701 NL80211_ATTR_CENTER_FREQ1
,
702 chandef
->center_freq1
);
704 if (chandef
->center_freq2
)
706 NL80211_ATTR_CENTER_FREQ2
,
707 chandef
->center_freq2
);
715 static void print_mcs_index(const __u8
*mcs
)
717 int mcs_bit
, prev_bit
= -2, prev_cont
= 0;
719 for (mcs_bit
= 0; mcs_bit
<= 76; mcs_bit
++) {
720 unsigned int mcs_octet
= mcs_bit
/8;
721 unsigned int MCS_RATE_BIT
= 1 << mcs_bit
% 8;
722 bool mcs_rate_idx_set
;
724 mcs_rate_idx_set
= !!(mcs
[mcs_octet
] & MCS_RATE_BIT
);
726 if (!mcs_rate_idx_set
)
729 if (prev_bit
!= mcs_bit
- 1) {
731 printf("%d, ", prev_bit
);
734 printf("%d", mcs_bit
);
736 } else if (!prev_cont
) {
745 printf("%d", prev_bit
);
750 * There are only 4 possible values, we just use a case instead of computing it,
751 * but technically this can also be computed through the formula:
753 * Max AMPDU length = (2 ^ (13 + exponent)) - 1 bytes
755 static __u32
compute_ampdu_length(__u8 exponent
)
758 case 0: return 8191; /* (2 ^(13 + 0)) -1 */
759 case 1: return 16383; /* (2 ^(13 + 1)) -1 */
760 case 2: return 32767; /* (2 ^(13 + 2)) -1 */
761 case 3: return 65535; /* (2 ^(13 + 3)) -1 */
766 static const char *print_ampdu_space(__u8 space
)
769 case 0: return "No restriction";
770 case 1: return "1/4 usec";
771 case 2: return "1/2 usec";
772 case 3: return "1 usec";
773 case 4: return "2 usec";
774 case 5: return "4 usec";
775 case 6: return "8 usec";
776 case 7: return "16 usec";
778 return "BUG (spacing more than 3 bits!)";
782 void print_ampdu_length(__u8 exponent
)
784 __u32 max_ampdu_length
;
786 max_ampdu_length
= compute_ampdu_length(exponent
);
788 if (max_ampdu_length
) {
789 printf("\t\tMaximum RX AMPDU length %d bytes (exponent: 0x0%02x)\n",
790 max_ampdu_length
, exponent
);
792 printf("\t\tMaximum RX AMPDU length: unrecognized bytes "
793 "(exponent: %d)\n", exponent
);
797 void print_ampdu_spacing(__u8 spacing
)
799 printf("\t\tMinimum RX AMPDU time spacing: %s (0x%02x)\n",
800 print_ampdu_space(spacing
), spacing
);
803 void print_ht_capability(__u16 cap
)
805 #define PRINT_HT_CAP(_cond, _str) \
808 printf("\t\t\t" _str "\n"); \
811 printf("\t\tCapabilities: 0x%02x\n", cap
);
813 PRINT_HT_CAP((cap
& BIT(0)), "RX LDPC");
814 PRINT_HT_CAP((cap
& BIT(1)), "HT20/HT40");
815 PRINT_HT_CAP(!(cap
& BIT(1)), "HT20");
817 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 0, "Static SM Power Save");
818 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 1, "Dynamic SM Power Save");
819 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 3, "SM Power Save disabled");
821 PRINT_HT_CAP((cap
& BIT(4)), "RX Greenfield");
822 PRINT_HT_CAP((cap
& BIT(5)), "RX HT20 SGI");
823 PRINT_HT_CAP((cap
& BIT(6)), "RX HT40 SGI");
824 PRINT_HT_CAP((cap
& BIT(7)), "TX STBC");
826 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 0, "No RX STBC");
827 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 1, "RX STBC 1-stream");
828 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 2, "RX STBC 2-streams");
829 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 3, "RX STBC 3-streams");
831 PRINT_HT_CAP((cap
& BIT(10)), "HT Delayed Block Ack");
833 PRINT_HT_CAP(!(cap
& BIT(11)), "Max AMSDU length: 3839 bytes");
834 PRINT_HT_CAP((cap
& BIT(11)), "Max AMSDU length: 7935 bytes");
837 * For beacons and probe response this would mean the BSS
838 * does or does not allow the usage of DSSS/CCK HT40.
839 * Otherwise it means the STA does or does not use
842 PRINT_HT_CAP((cap
& BIT(12)), "DSSS/CCK HT40");
843 PRINT_HT_CAP(!(cap
& BIT(12)), "No DSSS/CCK HT40");
845 /* BIT(13) is reserved */
847 PRINT_HT_CAP((cap
& BIT(14)), "40 MHz Intolerant");
849 PRINT_HT_CAP((cap
& BIT(15)), "L-SIG TXOP protection");
853 void print_ht_mcs(const __u8
*mcs
)
855 /* As defined in 7.3.2.57.4 Supported MCS Set field */
856 unsigned int tx_max_num_spatial_streams
, max_rx_supp_data_rate
;
857 bool tx_mcs_set_defined
, tx_mcs_set_equal
, tx_unequal_modulation
;
859 max_rx_supp_data_rate
= (mcs
[10] | ((mcs
[11] & 0x3) << 8));
860 tx_mcs_set_defined
= !!(mcs
[12] & (1 << 0));
861 tx_mcs_set_equal
= !(mcs
[12] & (1 << 1));
862 tx_max_num_spatial_streams
= ((mcs
[12] >> 2) & 3) + 1;
863 tx_unequal_modulation
= !!(mcs
[12] & (1 << 4));
865 if (max_rx_supp_data_rate
)
866 printf("\t\tHT Max RX data rate: %d Mbps\n", max_rx_supp_data_rate
);
867 /* XXX: else see 9.6.0e.5.3 how to get this I think */
869 if (tx_mcs_set_defined
) {
870 if (tx_mcs_set_equal
) {
871 printf("\t\tHT TX/RX MCS rate indexes supported:");
872 print_mcs_index(mcs
);
874 printf("\t\tHT RX MCS rate indexes supported:");
875 print_mcs_index(mcs
);
877 if (tx_unequal_modulation
)
878 printf("\t\tTX unequal modulation supported\n");
880 printf("\t\tTX unequal modulation not supported\n");
882 printf("\t\tHT TX Max spatial streams: %d\n",
883 tx_max_num_spatial_streams
);
885 printf("\t\tHT TX MCS rate indexes supported may differ\n");
888 printf("\t\tHT RX MCS rate indexes supported:");
889 print_mcs_index(mcs
);
890 printf("\t\tHT TX MCS rate indexes are undefined\n");
894 void print_vht_info(__u32 capa
, const __u8
*mcs
)
899 printf("\t\tVHT Capabilities (0x%.8x):\n", capa
);
901 #define PRINT_VHT_CAPA(_bit, _str) \
903 if (capa & BIT(_bit)) \
904 printf("\t\t\t" _str "\n"); \
907 printf("\t\t\tMax MPDU length: ");
909 case 0: printf("3895\n"); break;
910 case 1: printf("7991\n"); break;
911 case 2: printf("11454\n"); break;
912 case 3: printf("(reserved)\n");
914 printf("\t\t\tSupported Channel Width: ");
915 switch ((capa
>> 2) & 3) {
916 case 0: printf("neither 160 nor 80+80\n"); break;
917 case 1: printf("160 MHz\n"); break;
918 case 2: printf("160 MHz, 80+80 MHz\n"); break;
919 case 3: printf("(reserved)\n");
921 PRINT_VHT_CAPA(4, "RX LDPC");
922 PRINT_VHT_CAPA(5, "short GI (80 MHz)");
923 PRINT_VHT_CAPA(6, "short GI (160/80+80 MHz)");
924 PRINT_VHT_CAPA(7, "TX STBC");
926 PRINT_VHT_CAPA(11, "SU Beamformer");
927 PRINT_VHT_CAPA(12, "SU Beamformee");
928 /* compressed steering */
929 /* # of sounding dimensions */
930 PRINT_VHT_CAPA(19, "MU Beamformer");
931 PRINT_VHT_CAPA(20, "MU Beamformee");
932 PRINT_VHT_CAPA(21, "VHT TXOP PS");
933 PRINT_VHT_CAPA(22, "+HTC-VHT");
935 /* VHT link adaptation */
936 PRINT_VHT_CAPA(28, "RX antenna pattern consistency");
937 PRINT_VHT_CAPA(29, "TX antenna pattern consistency");
939 printf("\t\tVHT RX MCS set:\n");
940 tmp
= mcs
[0] | (mcs
[1] << 8);
941 for (i
= 1; i
<= 8; i
++) {
942 printf("\t\t\t%d streams: ", i
);
943 switch ((tmp
>> ((i
-1)*2) ) & 3) {
944 case 0: printf("MCS 0-7\n"); break;
945 case 1: printf("MCS 0-8\n"); break;
946 case 2: printf("MCS 0-9\n"); break;
947 case 3: printf("not supported\n"); break;
950 tmp
= mcs
[2] | (mcs
[3] << 8);
951 printf("\t\tVHT RX highest supported: %d Mbps\n", tmp
& 0x1fff);
953 printf("\t\tVHT TX MCS set:\n");
954 tmp
= mcs
[4] | (mcs
[5] << 8);
955 for (i
= 1; i
<= 8; i
++) {
956 printf("\t\t\t%d streams: ", i
);
957 switch ((tmp
>> ((i
-1)*2) ) & 3) {
958 case 0: printf("MCS 0-7\n"); break;
959 case 1: printf("MCS 0-8\n"); break;
960 case 2: printf("MCS 0-9\n"); break;
961 case 3: printf("not supported\n"); break;
964 tmp
= mcs
[6] | (mcs
[7] << 8);
965 printf("\t\tVHT TX highest supported: %d Mbps\n", tmp
& 0x1fff);
968 void print_he_info(struct nlattr
*nl_iftype
)
970 struct nlattr
*tb
[NL80211_BAND_IFTYPE_ATTR_MAX
+ 1];
971 struct nlattr
*tb_flags
[NL80211_IFTYPE_MAX
+ 1];
972 char *iftypes
[NUM_NL80211_IFTYPES
] = {
973 "Unspec", "Adhoc", "Station", "AP", "AP/VLAN", "WDS", "Monitor",
974 "Mesh", "P2P/Client", "P2P/Go", "P2P/Device", "OCB", "NAN",
976 __u16 mac_cap
[3] = { 0 };
977 __u16 phy_cap
[6] = { 0 };
978 __u16 mcs_set
[6] = { 0 };
979 __u8 ppet
[25] = { 0 };
983 #define PRINT_HE_CAP(_var, _idx, _bit, _str) \
985 if (_var[_idx] & BIT(_bit)) \
986 printf("\t\t\t\t" _str "\n"); \
989 #define PRINT_HE_CAP_MASK(_var, _idx, _shift, _mask, _str) \
991 if ((_var[_idx] >> _shift) & _mask) \
992 printf("\t\t\t\t" _str ": %d\n", (_var[_idx] >> _shift) & _mask); \
995 #define PRINT_HE_MAC_CAP(...) PRINT_HE_CAP(mac_cap, __VA_ARGS__)
996 #define PRINT_HE_MAC_CAP_MASK(...) PRINT_HE_CAP_MASK(mac_cap, __VA_ARGS__)
997 #define PRINT_HE_PHY_CAP(...) PRINT_HE_CAP(phy_cap, __VA_ARGS__)
998 #define PRINT_HE_PHY_CAP0(_idx, _bit, ...) PRINT_HE_CAP(phy_cap, _idx, _bit + 8, __VA_ARGS__)
999 #define PRINT_HE_PHY_CAP_MASK(...) PRINT_HE_CAP_MASK(phy_cap, __VA_ARGS__)
1001 nla_parse(tb
, NL80211_BAND_IFTYPE_ATTR_MAX
,
1002 nla_data(nl_iftype
), nla_len(nl_iftype
), NULL
);
1004 if (!tb
[NL80211_BAND_IFTYPE_ATTR_IFTYPES
])
1007 if (nla_parse_nested(tb_flags
, NL80211_IFTYPE_MAX
,
1008 tb
[NL80211_BAND_IFTYPE_ATTR_IFTYPES
], NULL
))
1011 printf("\t\tHE Iftypes:");
1012 for (i
= 0; i
< NUM_NL80211_IFTYPES
; i
++)
1013 if (nla_get_flag(tb_flags
[i
]) && iftypes
[i
])
1014 printf(" %s", iftypes
[i
]);
1017 if (tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC
]) {
1018 len
= nla_len(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC
]);
1019 if (len
> sizeof(mac_cap
))
1020 len
= sizeof(mac_cap
);
1022 nla_data(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC
]),
1025 printf("\t\t\tHE MAC Capabilities (0x");
1026 for (i
= 0; i
< 3; i
++)
1027 printf("%04x", mac_cap
[i
]);
1030 PRINT_HE_MAC_CAP(0, 0, "+HTC HE Supported");
1031 PRINT_HE_MAC_CAP(0, 1, "TWT Requester");
1032 PRINT_HE_MAC_CAP(0, 2, "TWT Responder");
1033 PRINT_HE_MAC_CAP_MASK(0, 3, 0x3, "Dynamic BA Fragementation Level");
1034 PRINT_HE_MAC_CAP_MASK(0, 5, 0x7, "Maximum number of MSDUS Fragments");
1035 PRINT_HE_MAC_CAP_MASK(0, 8, 0x3, "Minimum Payload size of 128 bytes");
1036 PRINT_HE_MAC_CAP_MASK(0, 10, 0x3, "Trigger Frame MAC Padding Duration");
1037 PRINT_HE_MAC_CAP_MASK(0, 12, 0x7, "Multi-TID Aggregation Support");
1039 PRINT_HE_MAC_CAP(1, 1, "All Ack");
1040 PRINT_HE_MAC_CAP(1, 2, "TRS");
1041 PRINT_HE_MAC_CAP(1, 3, "BSR");
1042 PRINT_HE_MAC_CAP(1, 4, "Broadcast TWT");
1043 PRINT_HE_MAC_CAP(1, 5, "32-bit BA Bitmap");
1044 PRINT_HE_MAC_CAP(1, 6, "MU Cascading");
1045 PRINT_HE_MAC_CAP(1, 7, "Ack-Enabled Aggregation");
1046 PRINT_HE_MAC_CAP(1, 9, "OM Control");
1047 PRINT_HE_MAC_CAP(1, 10, "OFDMA RA");
1048 PRINT_HE_MAC_CAP_MASK(1, 11, 0x3, "Maximum A-MPDU Length Exponent");
1049 PRINT_HE_MAC_CAP(1, 13, "A-MSDU Fragmentation");
1050 PRINT_HE_MAC_CAP(1, 14, "Flexible TWT Scheduling");
1051 PRINT_HE_MAC_CAP(1, 15, "RX Control Frame to MultiBSS");
1053 PRINT_HE_MAC_CAP(2, 0, "BSRP BQRP A-MPDU Aggregation");
1054 PRINT_HE_MAC_CAP(2, 1, "QTP");
1055 PRINT_HE_MAC_CAP(2, 2, "BQR");
1056 PRINT_HE_MAC_CAP(2, 3, "SRP Responder Role");
1057 PRINT_HE_MAC_CAP(2, 4, "NDP Feedback Report");
1058 PRINT_HE_MAC_CAP(2, 5, "OPS");
1059 PRINT_HE_MAC_CAP(2, 6, "A-MSDU in A-MPDU");
1060 PRINT_HE_MAC_CAP_MASK(2, 7, 7, "Multi-TID Aggregation TX");
1061 PRINT_HE_MAC_CAP(2, 10, "HE Subchannel Selective Transmission");
1062 PRINT_HE_MAC_CAP(2, 11, "UL 2x996-Tone RU");
1063 PRINT_HE_MAC_CAP(2, 12, "OM Control UL MU Data Disable RX");
1065 if (tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY
]) {
1066 len
= nla_len(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY
]);
1068 if (len
> sizeof(phy_cap
) - 1)
1069 len
= sizeof(phy_cap
) - 1;
1070 memcpy(&((__u8
*)phy_cap
)[1],
1071 nla_data(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY
]),
1074 printf("\t\t\tHE PHY Capabilities: (0x");
1075 for (i
= 0; i
< 11; i
++)
1076 printf("%02x", ((__u8
*)phy_cap
)[i
+ 1]);
1079 PRINT_HE_PHY_CAP0(0, 1, "HE40/2.4GHz");
1080 PRINT_HE_PHY_CAP0(0, 2, "HE40/HE80/5GHz");
1081 PRINT_HE_PHY_CAP0(0, 3, "HE160/5GHz");
1082 PRINT_HE_PHY_CAP0(0, 4, "HE160/HE80+80/5GHz");
1083 PRINT_HE_PHY_CAP0(0, 5, "242 tone RUs/2.4GHz");
1084 PRINT_HE_PHY_CAP0(0, 6, "242 tone RUs/5GHz");
1086 PRINT_HE_PHY_CAP_MASK(1, 0, 0xf, "Punctured Preamble RX");
1087 PRINT_HE_PHY_CAP_MASK(1, 4, 0x1, "Device Class");
1088 PRINT_HE_PHY_CAP(1, 5, "LDPC Coding in Payload");
1089 PRINT_HE_PHY_CAP(1, 6, "HE SU PPDU with 1x HE-LTF and 0.8us GI");
1090 PRINT_HE_PHY_CAP_MASK(1, 7, 0x3, "Midamble Rx Max NSTS");
1091 PRINT_HE_PHY_CAP(1, 9, "NDP with 4x HE-LTF and 3.2us GI");
1092 PRINT_HE_PHY_CAP(1, 10, "STBC Tx <= 80MHz");
1093 PRINT_HE_PHY_CAP(1, 11, "STBC Rx <= 80MHz");
1094 PRINT_HE_PHY_CAP(1, 12, "Doppler Tx");
1095 PRINT_HE_PHY_CAP(1, 13, "Doppler Rx");
1096 PRINT_HE_PHY_CAP(1, 14, "Full Bandwidth UL MU-MIMO");
1097 PRINT_HE_PHY_CAP(1, 15, "Partial Bandwidth UL MU-MIMO");
1099 PRINT_HE_PHY_CAP_MASK(2, 0, 0x3, "DCM Max Constellation");
1100 PRINT_HE_PHY_CAP_MASK(2, 2, 0x1, "DCM Max NSS Tx");
1101 PRINT_HE_PHY_CAP_MASK(2, 3, 0x3, "DCM Max Constellation Rx");
1102 PRINT_HE_PHY_CAP_MASK(2, 5, 0x1, "DCM Max NSS Rx");
1103 PRINT_HE_PHY_CAP(2, 6, "Rx HE MU PPDU from Non-AP STA");
1104 PRINT_HE_PHY_CAP(2, 7, "SU Beamformer");
1105 PRINT_HE_PHY_CAP(2, 8, "SU Beamformee");
1106 PRINT_HE_PHY_CAP(2, 9, "MU Beamformer");
1107 PRINT_HE_PHY_CAP_MASK(2, 10, 0x7, "Beamformee STS <= 80Mhz");
1108 PRINT_HE_PHY_CAP_MASK(2, 13, 0x7, "Beamformee STS > 80Mhz");
1110 PRINT_HE_PHY_CAP_MASK(3, 0, 0x7, "Sounding Dimensions <= 80Mhz");
1111 PRINT_HE_PHY_CAP_MASK(3, 3, 0x7, "Sounding Dimensions > 80Mhz");
1112 PRINT_HE_PHY_CAP(3, 6, "Ng = 16 SU Feedback");
1113 PRINT_HE_PHY_CAP(3, 7, "Ng = 16 MU Feedback");
1114 PRINT_HE_PHY_CAP(3, 8, "Codebook Size SU Feedback");
1115 PRINT_HE_PHY_CAP(3, 9, "Codebook Size MU Feedback");
1116 PRINT_HE_PHY_CAP(3, 10, "Triggered SU Beamforming Feedback");
1117 PRINT_HE_PHY_CAP(3, 11, "Triggered MU Beamforming Feedback");
1118 PRINT_HE_PHY_CAP(3, 12, "Triggered CQI Feedback");
1119 PRINT_HE_PHY_CAP(3, 13, "Partial Bandwidth Extended Range");
1120 PRINT_HE_PHY_CAP(3, 14, "Partial Bandwidth DL MU-MIMO");
1121 PRINT_HE_PHY_CAP(3, 15, "PPE Threshold Present");
1123 PRINT_HE_PHY_CAP(4, 0, "SRP-based SR");
1124 PRINT_HE_PHY_CAP(4, 1, "Power Boost Factor ar");
1125 PRINT_HE_PHY_CAP(4, 2, "HE SU PPDU & HE PPDU 4x HE-LTF 0.8us GI");
1126 PRINT_HE_PHY_CAP_MASK(4, 3, 0x7, "Max NC");
1127 PRINT_HE_PHY_CAP(4, 6, "STBC Tx > 80MHz");
1128 PRINT_HE_PHY_CAP(4, 7, "STBC Rx > 80MHz");
1129 PRINT_HE_PHY_CAP(4, 8, "HE ER SU PPDU 4x HE-LTF 0.8us GI");
1130 PRINT_HE_PHY_CAP(4, 9, "20MHz in 40MHz HE PPDU 2.4GHz");
1131 PRINT_HE_PHY_CAP(4, 10, "20MHz in 160/80+80MHz HE PPDU");
1132 PRINT_HE_PHY_CAP(4, 11, "80MHz in 160/80+80MHz HE PPDU");
1133 PRINT_HE_PHY_CAP(4, 12, "HE ER SU PPDU 1x HE-LTF 0.8us GI");
1134 PRINT_HE_PHY_CAP(4, 13, "Midamble Rx 2x & 1x HE-LTF");
1135 PRINT_HE_PHY_CAP_MASK(4, 14, 0x3, "DCM Max BW");
1137 PRINT_HE_PHY_CAP(5, 0, "Longer Than 16HE SIG-B OFDM Symbols");
1138 PRINT_HE_PHY_CAP(5, 1, "Non-Triggered CQI Feedback");
1139 PRINT_HE_PHY_CAP(5, 2, "TX 1024-QAM");
1140 PRINT_HE_PHY_CAP(5, 3, "RX 1024-QAM");
1141 PRINT_HE_PHY_CAP(5, 4, "RX Full BW SU Using HE MU PPDU with Compression SIGB");
1142 PRINT_HE_PHY_CAP(5, 5, "RX Full BW SU Using HE MU PPDU with Non-Compression SIGB");
1144 if (tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET
]) {
1145 len
= nla_len(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET
]);
1146 if (len
> sizeof(mcs_set
))
1147 len
= sizeof(mcs_set
);
1149 nla_data(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET
]),
1153 for (i
= 0; i
< 3; i
++) {
1154 __u8 phy_cap_support
[] = { BIT(1) | BIT(2), BIT(3), BIT(4) };
1155 char *bw
[] = { "<= 80", "160", "80+80" };
1158 if ((phy_cap
[0] & (phy_cap_support
[i
] << 8)) == 0)
1161 for (j
= 0; j
< 2; j
++) {
1163 printf("\t\t\tHE %s MCS and NSS set %s MHz\n", j
? "TX" : "RX", bw
[i
]);
1164 for (k
= 0; k
< 8; k
++) {
1165 __u16 mcs
= mcs_set
[(i
* 2) + j
];
1168 printf("\t\t\t\t\t %d streams: ", k
+ 1);
1170 printf("not supported\n");
1172 printf("MCS 0-%d\n", 7 + (mcs
* 2));
1179 if (tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE
]) {
1180 len
= nla_len(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE
]);
1181 if (len
> sizeof(ppet
))
1184 nla_data(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE
]),
1188 if (len
&& (phy_cap
[3] & BIT(15))) {
1191 printf("\t\t\tPPE Threshold ");
1192 for (i
= 0; i
< len
; i
++)
1194 printf("0x%02x ", ppet
[i
]);
1199 void iw_hexdump(const char *prefix
, const __u8
*buf
, size_t size
)
1203 printf("%s: ", prefix
);
1204 for (i
= 0; i
< size
; i
++) {
1205 if (i
&& i
% 16 == 0)
1206 printf("\n%s: ", prefix
);
1207 printf("%02x ", buf
[i
]);
1212 int get_cf1(const struct chanmode
*chanmode
, unsigned long freq
)
1214 unsigned int cf1
= freq
, j
;
1215 unsigned int vht80
[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
1217 switch (chanmode
->width
) {
1218 case NL80211_CHAN_WIDTH_80
:
1219 /* setup center_freq1 */
1220 for (j
= 0; j
< ARRAY_SIZE(vht80
); j
++) {
1221 if (freq
>= vht80
[j
] && freq
< vht80
[j
] + 80)
1225 if (j
== ARRAY_SIZE(vht80
))
1228 cf1
= vht80
[j
] + 30;
1231 cf1
= freq
+ chanmode
->freq1_diff
;
1238 int parse_random_mac_addr(struct nl_msg
*msg
, char *addrs
)
1240 char *a_addr
, *a_mask
, *sep
;
1241 unsigned char addr
[ETH_ALEN
], mask
[ETH_ALEN
];
1244 /* randomise all but the multicast bit */
1245 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
,
1246 "\x00\x00\x00\x00\x00\x00");
1247 NLA_PUT(msg
, NL80211_ATTR_MAC_MASK
, ETH_ALEN
,
1248 "\x01\x00\x00\x00\x00\x00");
1256 sep
= strchr(addrs
, '/');
1264 if (mac_addr_a2n(addr
, a_addr
) || mac_addr_a2n(mask
, a_mask
))
1267 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
1268 NLA_PUT(msg
, NL80211_ATTR_MAC_MASK
, ETH_ALEN
, mask
);