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_6GHZ
:
184 /* see 802.11ax D6.1 27.3.23.2 */
188 return 5950 + chan
* 5;
190 case NL80211_BAND_60GHZ
:
192 return 56160 + chan
* 2160;
197 return 0; /* not supported */
200 int ieee80211_frequency_to_channel(int freq
)
202 /* see 802.11-2007 17.3.8.3.2 and Annex J */
205 /* see 802.11ax D6.1 27.3.23.2 and Annex E */
206 else if (freq
== 5935)
208 else if (freq
< 2484)
209 return (freq
- 2407) / 5;
210 else if (freq
>= 4910 && freq
<= 4980)
211 return (freq
- 4000) / 5;
212 else if (freq
< 5950)
213 return (freq
- 5000) / 5;
214 else if (freq
<= 45000) /* DMG band lower limit */
215 /* see 802.11ax D6.1 27.3.23.2 */
216 return (freq
- 5950) / 5;
217 else if (freq
>= 58320 && freq
<= 70200)
218 return (freq
- 56160) / 2160;
223 void print_ssid_escaped(const uint8_t len
, const uint8_t *data
)
227 for (i
= 0; i
< len
; i
++) {
228 if (isprint(data
[i
]) && data
[i
] != ' ' && data
[i
] != '\\')
229 printf("%c", data
[i
]);
230 else if (data
[i
] == ' ' &&
231 (i
!= 0 && i
!= len
-1))
234 printf("\\x%.2x", data
[i
]);
238 static int hex2num(char digit
)
240 if (!isxdigit(digit
))
244 return tolower(digit
) - 'a' + 10;
247 static int hex2byte(const char *hex
)
251 d1
= hex2num(hex
[0]);
254 d2
= hex2num(hex
[1]);
257 return (d1
<< 4) | d2
;
260 char *hex2bin(const char *hex
, char *buf
)
277 static int parse_akm_suite(const char *cipher_str
)
280 if (!strcmp(cipher_str
, "PSK"))
282 if (!strcmp(cipher_str
, "FT/PSK"))
284 if (!strcmp(cipher_str
, "PSK/SHA-256"))
289 static int parse_cipher_suite(const char *cipher_str
)
292 if (!strcmp(cipher_str
, "TKIP"))
294 if (!strcmp(cipher_str
, "CCMP") || !strcmp(cipher_str
, "CCMP-128"))
296 if (!strcmp(cipher_str
, "GCMP") || !strcmp(cipher_str
, "GCMP-128"))
298 if (!strcmp(cipher_str
, "GCMP-256"))
300 if (!strcmp(cipher_str
, "CCMP-256"))
305 int parse_keys(struct nl_msg
*msg
, char **argv
[], int *argc
)
309 bool have_default
= false;
317 if (!memcmp(&arg
[pos
], "psk", 3)) {
319 int cipher_suite
, akm_suite
;
329 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, NL80211_WPA_VERSION_2
);
331 if (strlen(&arg
[pos
]) != (sizeof(psk_keybuf
) * 2) || !hex2bin(&arg
[pos
], psk_keybuf
)) {
336 NLA_PUT(msg
, NL80211_ATTR_PMK
, 32, psk_keybuf
);
337 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, NL80211_AUTHTYPE_OPEN_SYSTEM
);
343 akm_suite
= parse_akm_suite(arg
);
347 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, akm_suite
);
353 cipher_suite
= parse_cipher_suite(arg
);
354 if (cipher_suite
< 0)
357 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher_suite
);
363 cipher_suite
= parse_cipher_suite(arg
);
364 if (cipher_suite
< 0)
367 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher_suite
);
374 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
376 keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
382 struct nlattr
*key
= nla_nest_start(msg
, ++i
);
391 if (arg
[pos
] == 'd') {
392 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
399 if (!isdigit(arg
[pos
]))
401 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, arg
[pos
++] - '0');
402 if (arg
[pos
++] != ':')
405 switch (strlen(keydata
)) {
407 keydata
= hex2bin(keydata
, keybuf
);
410 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, 0x000FAC01);
414 keydata
= hex2bin(keydata
, keybuf
);
417 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, 0x000FAC05);
427 NLA_PUT(msg
, NL80211_KEY_DATA
, keylen
, keydata
);
432 /* one key should be TX key */
433 if (!have_default
&& !*argc
)
434 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
436 nla_nest_end(msg
, key
);
439 nla_nest_end(msg
, keys
);
445 fprintf(stderr
, "key must be [d:]index:data where\n"
446 " 'd:' means default (transmit) key\n"
447 " 'index:' is a single digit (0-3)\n"
448 " 'data' must be 5 or 13 ascii chars\n"
449 " or 10 or 26 hex digits\n"
450 "for example: d:2:6162636465 is the same as d:2:abcde\n"
451 "or psk:data <AKM Suite> <pairwise CIPHER> <groupwise CIPHER> where\n"
452 " 'data' is the PSK (output of wpa_passphrase and the CIPHER can be CCMP or GCMP\n"
453 "for example: psk:0123456789abcdef PSK CCMP CCMP\n"
454 "The allowed AKM suites are PSK, FT/PSK, PSK/SHA-256\n"
455 "The allowed Cipher suites are TKIP, CCMP, GCMP, GCMP-256, CCMP-256\n");
459 enum nl80211_chan_width
str_to_bw(const char *str
)
461 static const struct {
465 { .name
= "5", .val
= NL80211_CHAN_WIDTH_5
, },
466 { .name
= "10", .val
= NL80211_CHAN_WIDTH_10
, },
467 { .name
= "20", .val
= NL80211_CHAN_WIDTH_20
, },
468 { .name
= "40", .val
= NL80211_CHAN_WIDTH_40
, },
469 { .name
= "80", .val
= NL80211_CHAN_WIDTH_80
, },
470 { .name
= "80+80", .val
= NL80211_CHAN_WIDTH_80P80
, },
471 { .name
= "160", .val
= NL80211_CHAN_WIDTH_160
, },
475 for (i
= 0; i
< ARRAY_SIZE(bwmap
); i
++) {
476 if (strcasecmp(bwmap
[i
].name
, str
) == 0)
480 return NL80211_CHAN_WIDTH_20_NOHT
;
483 static int parse_freqs(struct chandef
*chandef
, int argc
, char **argv
,
488 bool need_cf1
= false, need_cf2
= false;
493 chandef
->width
= str_to_bw(argv
[0]);
495 switch (chandef
->width
) {
496 case NL80211_CHAN_WIDTH_20_NOHT
:
497 /* First argument was not understood, give up gracefully. */
499 case NL80211_CHAN_WIDTH_20
:
500 case NL80211_CHAN_WIDTH_5
:
501 case NL80211_CHAN_WIDTH_10
:
503 case NL80211_CHAN_WIDTH_80P80
:
506 case NL80211_CHAN_WIDTH_40
:
507 case NL80211_CHAN_WIDTH_80
:
508 case NL80211_CHAN_WIDTH_160
:
511 case NL80211_CHAN_WIDTH_1
:
512 case NL80211_CHAN_WIDTH_2
:
513 case NL80211_CHAN_WIDTH_4
:
514 case NL80211_CHAN_WIDTH_8
:
515 case NL80211_CHAN_WIDTH_16
:
516 /* can't happen yet */
531 freq
= strtoul(argv
[1], &end
, 10);
536 chandef
->center_freq1
= freq
;
547 freq
= strtoul(argv
[2], &end
, 10);
550 chandef
->center_freq2
= freq
;
559 * parse_freqchan - Parse frequency or channel definition
561 * @chandef: chandef structure to be filled in
562 * @chan: Boolean whether to parse a channel or frequency based specifier
563 * @argc: Number of arguments
564 * @argv: Array of string arguments
565 * @parsed: Pointer to return the number of used arguments, or NULL to error
566 * out if any argument is left unused.
568 * The given chandef structure will be filled in from the command line
569 * arguments. argc/argv will be updated so that further arguments from the
570 * command line can be parsed.
572 * Note that despite the fact that the function knows how many center freqs
573 * are needed, there's an ambiguity if the next argument after this is an
574 * integer argument, since the valid channel width values are interpreted
575 * as such, rather than a following argument. This can be avoided by the
576 * user by giving "NOHT" instead.
578 * The working specifier if chan is set are:
579 * <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz]
581 * And if frequency is set:
582 * <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz|160MHz]
583 * <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]
585 * If the mode/channel width is not given the NOHT is assumed.
587 * Return: Number of used arguments, zero or negative error number otherwise
589 int parse_freqchan(struct chandef
*chandef
, bool chan
, int argc
, char **argv
,
593 static const struct chanmode chanmode
[] = {
595 .width
= NL80211_CHAN_WIDTH_20
,
597 .chantype
= NL80211_CHAN_HT20
},
599 .width
= NL80211_CHAN_WIDTH_40
,
601 .chantype
= NL80211_CHAN_HT40PLUS
},
603 .width
= NL80211_CHAN_WIDTH_40
,
605 .chantype
= NL80211_CHAN_HT40MINUS
},
607 .width
= NL80211_CHAN_WIDTH_20_NOHT
,
609 .chantype
= NL80211_CHAN_NO_HT
},
611 .width
= NL80211_CHAN_WIDTH_5
,
615 .width
= NL80211_CHAN_WIDTH_10
,
619 .width
= NL80211_CHAN_WIDTH_80
,
623 .width
= NL80211_CHAN_WIDTH_160
,
627 const struct chanmode
*chanmode_selected
= NULL
;
638 freq
= strtoul(argv
[0], &end
, 10);
646 memset(chandef
, 0, sizeof(struct chandef
));
649 enum nl80211_band band
;
651 band
= freq
<= 14 ? NL80211_BAND_2GHZ
: NL80211_BAND_5GHZ
;
652 freq
= ieee80211_channel_to_frequency(freq
, band
);
654 chandef
->control_freq
= freq
;
655 /* Assume 20MHz NOHT channel for now. */
656 chandef
->center_freq1
= freq
;
658 /* Try to parse HT mode definitions */
660 for (i
= 0; i
< ARRAY_SIZE(chanmode
); i
++) {
661 if (strcasecmp(chanmode
[i
].name
, argv
[1]) == 0) {
662 chanmode_selected
= &chanmode
[i
];
669 /* channel mode given, use it and return. */
670 if (chanmode_selected
) {
671 chandef
->center_freq1
= get_cf1(chanmode_selected
, freq
);
672 chandef
->width
= chanmode_selected
->width
;
676 /* This was a only a channel definition, nothing further may follow. */
680 res
= parse_freqs(chandef
, argc
- 1, argv
+ 1, &_parsed
);
683 /* Error out if parsed is NULL. */
684 if (!parsed
&& _parsed
!= argc
)
693 int put_chandef(struct nl_msg
*msg
, struct chandef
*chandef
)
695 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chandef
->control_freq
);
696 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
);
698 switch (chandef
->width
) {
699 case NL80211_CHAN_WIDTH_20_NOHT
:
701 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
704 case NL80211_CHAN_WIDTH_20
:
706 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
709 case NL80211_CHAN_WIDTH_40
:
710 if (chandef
->control_freq
> chandef
->center_freq1
)
712 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
713 NL80211_CHAN_HT40MINUS
);
716 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
717 NL80211_CHAN_HT40PLUS
);
723 if (chandef
->center_freq1
)
725 NL80211_ATTR_CENTER_FREQ1
,
726 chandef
->center_freq1
);
728 if (chandef
->center_freq2
)
730 NL80211_ATTR_CENTER_FREQ2
,
731 chandef
->center_freq2
);
739 static void print_mcs_index(const __u8
*mcs
)
741 int mcs_bit
, prev_bit
= -2, prev_cont
= 0;
743 for (mcs_bit
= 0; mcs_bit
<= 76; mcs_bit
++) {
744 unsigned int mcs_octet
= mcs_bit
/8;
745 unsigned int MCS_RATE_BIT
= 1 << mcs_bit
% 8;
746 bool mcs_rate_idx_set
;
748 mcs_rate_idx_set
= !!(mcs
[mcs_octet
] & MCS_RATE_BIT
);
750 if (!mcs_rate_idx_set
)
753 if (prev_bit
!= mcs_bit
- 1) {
755 printf("%d, ", prev_bit
);
758 printf("%d", mcs_bit
);
760 } else if (!prev_cont
) {
769 printf("%d", prev_bit
);
774 * There are only 4 possible values, we just use a case instead of computing it,
775 * but technically this can also be computed through the formula:
777 * Max AMPDU length = (2 ^ (13 + exponent)) - 1 bytes
779 static __u32
compute_ampdu_length(__u8 exponent
)
782 case 0: return 8191; /* (2 ^(13 + 0)) -1 */
783 case 1: return 16383; /* (2 ^(13 + 1)) -1 */
784 case 2: return 32767; /* (2 ^(13 + 2)) -1 */
785 case 3: return 65535; /* (2 ^(13 + 3)) -1 */
790 static const char *print_ampdu_space(__u8 space
)
793 case 0: return "No restriction";
794 case 1: return "1/4 usec";
795 case 2: return "1/2 usec";
796 case 3: return "1 usec";
797 case 4: return "2 usec";
798 case 5: return "4 usec";
799 case 6: return "8 usec";
800 case 7: return "16 usec";
802 return "BUG (spacing more than 3 bits!)";
806 void print_ampdu_length(__u8 exponent
)
808 __u32 max_ampdu_length
;
810 max_ampdu_length
= compute_ampdu_length(exponent
);
812 if (max_ampdu_length
) {
813 printf("\t\tMaximum RX AMPDU length %d bytes (exponent: 0x0%02x)\n",
814 max_ampdu_length
, exponent
);
816 printf("\t\tMaximum RX AMPDU length: unrecognized bytes "
817 "(exponent: %d)\n", exponent
);
821 void print_ampdu_spacing(__u8 spacing
)
823 printf("\t\tMinimum RX AMPDU time spacing: %s (0x%02x)\n",
824 print_ampdu_space(spacing
), spacing
);
827 void print_ht_capability(__u16 cap
)
829 #define PRINT_HT_CAP(_cond, _str) \
832 printf("\t\t\t" _str "\n"); \
835 printf("\t\tCapabilities: 0x%02x\n", cap
);
837 PRINT_HT_CAP((cap
& BIT(0)), "RX LDPC");
838 PRINT_HT_CAP((cap
& BIT(1)), "HT20/HT40");
839 PRINT_HT_CAP(!(cap
& BIT(1)), "HT20");
841 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 0, "Static SM Power Save");
842 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 1, "Dynamic SM Power Save");
843 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 3, "SM Power Save disabled");
845 PRINT_HT_CAP((cap
& BIT(4)), "RX Greenfield");
846 PRINT_HT_CAP((cap
& BIT(5)), "RX HT20 SGI");
847 PRINT_HT_CAP((cap
& BIT(6)), "RX HT40 SGI");
848 PRINT_HT_CAP((cap
& BIT(7)), "TX STBC");
850 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 0, "No RX STBC");
851 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 1, "RX STBC 1-stream");
852 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 2, "RX STBC 2-streams");
853 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 3, "RX STBC 3-streams");
855 PRINT_HT_CAP((cap
& BIT(10)), "HT Delayed Block Ack");
857 PRINT_HT_CAP(!(cap
& BIT(11)), "Max AMSDU length: 3839 bytes");
858 PRINT_HT_CAP((cap
& BIT(11)), "Max AMSDU length: 7935 bytes");
861 * For beacons and probe response this would mean the BSS
862 * does or does not allow the usage of DSSS/CCK HT40.
863 * Otherwise it means the STA does or does not use
866 PRINT_HT_CAP((cap
& BIT(12)), "DSSS/CCK HT40");
867 PRINT_HT_CAP(!(cap
& BIT(12)), "No DSSS/CCK HT40");
869 /* BIT(13) is reserved */
871 PRINT_HT_CAP((cap
& BIT(14)), "40 MHz Intolerant");
873 PRINT_HT_CAP((cap
& BIT(15)), "L-SIG TXOP protection");
877 void print_ht_mcs(const __u8
*mcs
)
879 /* As defined in 7.3.2.57.4 Supported MCS Set field */
880 unsigned int tx_max_num_spatial_streams
, max_rx_supp_data_rate
;
881 bool tx_mcs_set_defined
, tx_mcs_set_equal
, tx_unequal_modulation
;
883 max_rx_supp_data_rate
= (mcs
[10] | ((mcs
[11] & 0x3) << 8));
884 tx_mcs_set_defined
= !!(mcs
[12] & (1 << 0));
885 tx_mcs_set_equal
= !(mcs
[12] & (1 << 1));
886 tx_max_num_spatial_streams
= ((mcs
[12] >> 2) & 3) + 1;
887 tx_unequal_modulation
= !!(mcs
[12] & (1 << 4));
889 if (max_rx_supp_data_rate
)
890 printf("\t\tHT Max RX data rate: %d Mbps\n", max_rx_supp_data_rate
);
891 /* XXX: else see 9.6.0e.5.3 how to get this I think */
893 if (tx_mcs_set_defined
) {
894 if (tx_mcs_set_equal
) {
895 printf("\t\tHT TX/RX MCS rate indexes supported:");
896 print_mcs_index(mcs
);
898 printf("\t\tHT RX MCS rate indexes supported:");
899 print_mcs_index(mcs
);
901 if (tx_unequal_modulation
)
902 printf("\t\tTX unequal modulation supported\n");
904 printf("\t\tTX unequal modulation not supported\n");
906 printf("\t\tHT TX Max spatial streams: %d\n",
907 tx_max_num_spatial_streams
);
909 printf("\t\tHT TX MCS rate indexes supported may differ\n");
912 printf("\t\tHT RX MCS rate indexes supported:");
913 print_mcs_index(mcs
);
914 printf("\t\tHT TX MCS rate indexes are undefined\n");
918 void print_vht_info(__u32 capa
, const __u8
*mcs
)
923 printf("\t\tVHT Capabilities (0x%.8x):\n", capa
);
925 #define PRINT_VHT_CAPA(_bit, _str) \
927 if (capa & BIT(_bit)) \
928 printf("\t\t\t" _str "\n"); \
931 printf("\t\t\tMax MPDU length: ");
933 case 0: printf("3895\n"); break;
934 case 1: printf("7991\n"); break;
935 case 2: printf("11454\n"); break;
936 case 3: printf("(reserved)\n");
938 printf("\t\t\tSupported Channel Width: ");
939 switch ((capa
>> 2) & 3) {
940 case 0: printf("neither 160 nor 80+80\n"); break;
941 case 1: printf("160 MHz\n"); break;
942 case 2: printf("160 MHz, 80+80 MHz\n"); break;
943 case 3: printf("(reserved)\n");
945 PRINT_VHT_CAPA(4, "RX LDPC");
946 PRINT_VHT_CAPA(5, "short GI (80 MHz)");
947 PRINT_VHT_CAPA(6, "short GI (160/80+80 MHz)");
948 PRINT_VHT_CAPA(7, "TX STBC");
950 PRINT_VHT_CAPA(11, "SU Beamformer");
951 PRINT_VHT_CAPA(12, "SU Beamformee");
952 /* compressed steering */
953 /* # of sounding dimensions */
954 PRINT_VHT_CAPA(19, "MU Beamformer");
955 PRINT_VHT_CAPA(20, "MU Beamformee");
956 PRINT_VHT_CAPA(21, "VHT TXOP PS");
957 PRINT_VHT_CAPA(22, "+HTC-VHT");
959 /* VHT link adaptation */
960 PRINT_VHT_CAPA(28, "RX antenna pattern consistency");
961 PRINT_VHT_CAPA(29, "TX antenna pattern consistency");
963 printf("\t\tVHT RX MCS set:\n");
964 tmp
= mcs
[0] | (mcs
[1] << 8);
965 for (i
= 1; i
<= 8; i
++) {
966 printf("\t\t\t%d streams: ", i
);
967 switch ((tmp
>> ((i
-1)*2) ) & 3) {
968 case 0: printf("MCS 0-7\n"); break;
969 case 1: printf("MCS 0-8\n"); break;
970 case 2: printf("MCS 0-9\n"); break;
971 case 3: printf("not supported\n"); break;
974 tmp
= mcs
[2] | (mcs
[3] << 8);
975 printf("\t\tVHT RX highest supported: %d Mbps\n", tmp
& 0x1fff);
977 printf("\t\tVHT TX MCS set:\n");
978 tmp
= mcs
[4] | (mcs
[5] << 8);
979 for (i
= 1; i
<= 8; i
++) {
980 printf("\t\t\t%d streams: ", i
);
981 switch ((tmp
>> ((i
-1)*2) ) & 3) {
982 case 0: printf("MCS 0-7\n"); break;
983 case 1: printf("MCS 0-8\n"); break;
984 case 2: printf("MCS 0-9\n"); break;
985 case 3: printf("not supported\n"); break;
988 tmp
= mcs
[6] | (mcs
[7] << 8);
989 printf("\t\tVHT TX highest supported: %d Mbps\n", tmp
& 0x1fff);
992 static void __print_he_capa(const __u16
*mac_cap
,
993 const __u16
*phy_cap
,
994 const __u16
*mcs_set
, size_t mcs_len
,
995 const __u8
*ppet
, int ppet_len
,
1000 const char *pre
= indent
? "\t" : "";
1002 #define PRINT_HE_CAP(_var, _idx, _bit, _str) \
1004 if (_var[_idx] & BIT(_bit)) \
1005 printf("%s\t\t\t" _str "\n", pre); \
1008 #define PRINT_HE_CAP_MASK(_var, _idx, _shift, _mask, _str) \
1010 if ((_var[_idx] >> _shift) & _mask) \
1011 printf("%s\t\t\t" _str ": %d\n", pre, (_var[_idx] >> _shift) & _mask); \
1014 #define PRINT_HE_MAC_CAP(...) PRINT_HE_CAP(mac_cap, __VA_ARGS__)
1015 #define PRINT_HE_MAC_CAP_MASK(...) PRINT_HE_CAP_MASK(mac_cap, __VA_ARGS__)
1016 #define PRINT_HE_PHY_CAP(...) PRINT_HE_CAP(phy_cap, __VA_ARGS__)
1017 #define PRINT_HE_PHY_CAP0(_idx, _bit, ...) PRINT_HE_CAP(phy_cap, _idx, _bit + 8, __VA_ARGS__)
1018 #define PRINT_HE_PHY_CAP_MASK(...) PRINT_HE_CAP_MASK(phy_cap, __VA_ARGS__)
1020 printf("%s\t\tHE MAC Capabilities (0x", pre
);
1021 for (i
= 0; i
< 3; i
++)
1022 printf("%04x", mac_cap
[i
]);
1025 PRINT_HE_MAC_CAP(0, 0, "+HTC HE Supported");
1026 PRINT_HE_MAC_CAP(0, 1, "TWT Requester");
1027 PRINT_HE_MAC_CAP(0, 2, "TWT Responder");
1028 PRINT_HE_MAC_CAP_MASK(0, 3, 0x3, "Dynamic BA Fragementation Level");
1029 PRINT_HE_MAC_CAP_MASK(0, 5, 0x7, "Maximum number of MSDUS Fragments");
1030 PRINT_HE_MAC_CAP_MASK(0, 8, 0x3, "Minimum Payload size of 128 bytes");
1031 PRINT_HE_MAC_CAP_MASK(0, 10, 0x3, "Trigger Frame MAC Padding Duration");
1032 PRINT_HE_MAC_CAP_MASK(0, 12, 0x7, "Multi-TID Aggregation Support");
1034 PRINT_HE_MAC_CAP(1, 1, "All Ack");
1035 PRINT_HE_MAC_CAP(1, 2, "TRS");
1036 PRINT_HE_MAC_CAP(1, 3, "BSR");
1037 PRINT_HE_MAC_CAP(1, 4, "Broadcast TWT");
1038 PRINT_HE_MAC_CAP(1, 5, "32-bit BA Bitmap");
1039 PRINT_HE_MAC_CAP(1, 6, "MU Cascading");
1040 PRINT_HE_MAC_CAP(1, 7, "Ack-Enabled Aggregation");
1041 PRINT_HE_MAC_CAP(1, 9, "OM Control");
1042 PRINT_HE_MAC_CAP(1, 10, "OFDMA RA");
1043 PRINT_HE_MAC_CAP_MASK(1, 11, 0x3, "Maximum A-MPDU Length Exponent");
1044 PRINT_HE_MAC_CAP(1, 13, "A-MSDU Fragmentation");
1045 PRINT_HE_MAC_CAP(1, 14, "Flexible TWT Scheduling");
1046 PRINT_HE_MAC_CAP(1, 15, "RX Control Frame to MultiBSS");
1048 PRINT_HE_MAC_CAP(2, 0, "BSRP BQRP A-MPDU Aggregation");
1049 PRINT_HE_MAC_CAP(2, 1, "QTP");
1050 PRINT_HE_MAC_CAP(2, 2, "BQR");
1051 PRINT_HE_MAC_CAP(2, 3, "SRP Responder Role");
1052 PRINT_HE_MAC_CAP(2, 4, "NDP Feedback Report");
1053 PRINT_HE_MAC_CAP(2, 5, "OPS");
1054 PRINT_HE_MAC_CAP(2, 6, "A-MSDU in A-MPDU");
1055 PRINT_HE_MAC_CAP_MASK(2, 7, 7, "Multi-TID Aggregation TX");
1056 PRINT_HE_MAC_CAP(2, 10, "HE Subchannel Selective Transmission");
1057 PRINT_HE_MAC_CAP(2, 11, "UL 2x996-Tone RU");
1058 PRINT_HE_MAC_CAP(2, 12, "OM Control UL MU Data Disable RX");
1060 printf("%s\t\tHE PHY Capabilities: (0x", pre
);
1061 for (i
= 0; i
< 11; i
++)
1062 printf("%02x", ((__u8
*)phy_cap
)[i
+ 1]);
1065 PRINT_HE_PHY_CAP0(0, 1, "HE40/2.4GHz");
1066 PRINT_HE_PHY_CAP0(0, 2, "HE40/HE80/5GHz");
1067 PRINT_HE_PHY_CAP0(0, 3, "HE160/5GHz");
1068 PRINT_HE_PHY_CAP0(0, 4, "HE160/HE80+80/5GHz");
1069 PRINT_HE_PHY_CAP0(0, 5, "242 tone RUs/2.4GHz");
1070 PRINT_HE_PHY_CAP0(0, 6, "242 tone RUs/5GHz");
1072 PRINT_HE_PHY_CAP_MASK(1, 0, 0xf, "Punctured Preamble RX");
1073 PRINT_HE_PHY_CAP_MASK(1, 4, 0x1, "Device Class");
1074 PRINT_HE_PHY_CAP(1, 5, "LDPC Coding in Payload");
1075 PRINT_HE_PHY_CAP(1, 6, "HE SU PPDU with 1x HE-LTF and 0.8us GI");
1076 PRINT_HE_PHY_CAP_MASK(1, 7, 0x3, "Midamble Rx Max NSTS");
1077 PRINT_HE_PHY_CAP(1, 9, "NDP with 4x HE-LTF and 3.2us GI");
1078 PRINT_HE_PHY_CAP(1, 10, "STBC Tx <= 80MHz");
1079 PRINT_HE_PHY_CAP(1, 11, "STBC Rx <= 80MHz");
1080 PRINT_HE_PHY_CAP(1, 12, "Doppler Tx");
1081 PRINT_HE_PHY_CAP(1, 13, "Doppler Rx");
1082 PRINT_HE_PHY_CAP(1, 14, "Full Bandwidth UL MU-MIMO");
1083 PRINT_HE_PHY_CAP(1, 15, "Partial Bandwidth UL MU-MIMO");
1085 PRINT_HE_PHY_CAP_MASK(2, 0, 0x3, "DCM Max Constellation");
1086 PRINT_HE_PHY_CAP_MASK(2, 2, 0x1, "DCM Max NSS Tx");
1087 PRINT_HE_PHY_CAP_MASK(2, 3, 0x3, "DCM Max Constellation Rx");
1088 PRINT_HE_PHY_CAP_MASK(2, 5, 0x1, "DCM Max NSS Rx");
1089 PRINT_HE_PHY_CAP(2, 6, "Rx HE MU PPDU from Non-AP STA");
1090 PRINT_HE_PHY_CAP(2, 7, "SU Beamformer");
1091 PRINT_HE_PHY_CAP(2, 8, "SU Beamformee");
1092 PRINT_HE_PHY_CAP(2, 9, "MU Beamformer");
1093 PRINT_HE_PHY_CAP_MASK(2, 10, 0x7, "Beamformee STS <= 80Mhz");
1094 PRINT_HE_PHY_CAP_MASK(2, 13, 0x7, "Beamformee STS > 80Mhz");
1096 PRINT_HE_PHY_CAP_MASK(3, 0, 0x7, "Sounding Dimensions <= 80Mhz");
1097 PRINT_HE_PHY_CAP_MASK(3, 3, 0x7, "Sounding Dimensions > 80Mhz");
1098 PRINT_HE_PHY_CAP(3, 6, "Ng = 16 SU Feedback");
1099 PRINT_HE_PHY_CAP(3, 7, "Ng = 16 MU Feedback");
1100 PRINT_HE_PHY_CAP(3, 8, "Codebook Size SU Feedback");
1101 PRINT_HE_PHY_CAP(3, 9, "Codebook Size MU Feedback");
1102 PRINT_HE_PHY_CAP(3, 10, "Triggered SU Beamforming Feedback");
1103 PRINT_HE_PHY_CAP(3, 11, "Triggered MU Beamforming Feedback");
1104 PRINT_HE_PHY_CAP(3, 12, "Triggered CQI Feedback");
1105 PRINT_HE_PHY_CAP(3, 13, "Partial Bandwidth Extended Range");
1106 PRINT_HE_PHY_CAP(3, 14, "Partial Bandwidth DL MU-MIMO");
1107 PRINT_HE_PHY_CAP(3, 15, "PPE Threshold Present");
1109 PRINT_HE_PHY_CAP(4, 0, "SRP-based SR");
1110 PRINT_HE_PHY_CAP(4, 1, "Power Boost Factor ar");
1111 PRINT_HE_PHY_CAP(4, 2, "HE SU PPDU & HE PPDU 4x HE-LTF 0.8us GI");
1112 PRINT_HE_PHY_CAP_MASK(4, 3, 0x7, "Max NC");
1113 PRINT_HE_PHY_CAP(4, 6, "STBC Tx > 80MHz");
1114 PRINT_HE_PHY_CAP(4, 7, "STBC Rx > 80MHz");
1115 PRINT_HE_PHY_CAP(4, 8, "HE ER SU PPDU 4x HE-LTF 0.8us GI");
1116 PRINT_HE_PHY_CAP(4, 9, "20MHz in 40MHz HE PPDU 2.4GHz");
1117 PRINT_HE_PHY_CAP(4, 10, "20MHz in 160/80+80MHz HE PPDU");
1118 PRINT_HE_PHY_CAP(4, 11, "80MHz in 160/80+80MHz HE PPDU");
1119 PRINT_HE_PHY_CAP(4, 12, "HE ER SU PPDU 1x HE-LTF 0.8us GI");
1120 PRINT_HE_PHY_CAP(4, 13, "Midamble Rx 2x & 1x HE-LTF");
1121 PRINT_HE_PHY_CAP_MASK(4, 14, 0x3, "DCM Max BW");
1123 PRINT_HE_PHY_CAP(5, 0, "Longer Than 16HE SIG-B OFDM Symbols");
1124 PRINT_HE_PHY_CAP(5, 1, "Non-Triggered CQI Feedback");
1125 PRINT_HE_PHY_CAP(5, 2, "TX 1024-QAM");
1126 PRINT_HE_PHY_CAP(5, 3, "RX 1024-QAM");
1127 PRINT_HE_PHY_CAP(5, 4, "RX Full BW SU Using HE MU PPDU with Compression SIGB");
1128 PRINT_HE_PHY_CAP(5, 5, "RX Full BW SU Using HE MU PPDU with Non-Compression SIGB");
1131 for (i
= 0; i
< 3; i
++) {
1132 __u8 phy_cap_support
[] = { BIT(1) | BIT(2), BIT(3), BIT(4) };
1133 char *bw
[] = { "<= 80", "160", "80+80" };
1136 if ((phy_cap
[0] & (phy_cap_support
[i
] << 8)) == 0)
1139 /* Supports more, but overflow? Abort. */
1140 if ((i
* 2 + 2) * sizeof(mcs_set
[0]) >= mcs_len
)
1143 for (j
= 0; j
< 2; j
++) {
1145 printf("%s\t\tHE %s MCS and NSS set %s MHz\n", pre
, j
? "TX" : "RX", bw
[i
]);
1146 for (k
= 0; k
< 8; k
++) {
1147 __u16 mcs
= mcs_set
[(i
* 2) + j
];
1150 printf("%s\t\t\t%d streams: ", pre
, k
+ 1);
1152 printf("not supported\n");
1154 printf("MCS 0-%d\n", 7 + (mcs
* 2));
1158 mcs_used
+= 2 * sizeof(mcs_set
[0]);
1161 /* Caller didn't provide ppet; infer it, if there's trailing space. */
1163 ppet
= (const void *)((const __u8
*)mcs_set
+ mcs_used
);
1164 if (mcs_used
< mcs_len
)
1165 ppet_len
= mcs_len
- mcs_used
;
1170 if (ppet_len
&& (phy_cap
[3] & BIT(15))) {
1171 printf("%s\t\tPPE Threshold ", pre
);
1172 for (i
= 0; i
< ppet_len
; i
++)
1174 printf("0x%02x ", ppet
[i
]);
1179 void print_iftype_list(const char *name
, const char *pfx
, struct nlattr
*attr
)
1184 printf("%s:\n", name
);
1185 nla_for_each_nested(ift
, attr
, rem
)
1186 printf("%s * %s\n", pfx
, iftype_name(nla_type(ift
)));
1189 void print_iftype_line(struct nlattr
*attr
)
1195 nla_for_each_nested(ift
, attr
, rem
) {
1200 printf("%s", iftype_name(nla_type(ift
)));
1204 void print_he_info(struct nlattr
*nl_iftype
)
1206 struct nlattr
*tb
[NL80211_BAND_IFTYPE_ATTR_MAX
+ 1];
1207 __u16 mac_cap
[3] = { 0 };
1208 __u16 phy_cap
[6] = { 0 };
1209 __u16 mcs_set
[6] = { 0 };
1210 __u8 ppet
[25] = { 0 };
1212 int mcs_len
= 0, ppet_len
= 0;
1214 nla_parse(tb
, NL80211_BAND_IFTYPE_ATTR_MAX
,
1215 nla_data(nl_iftype
), nla_len(nl_iftype
), NULL
);
1217 if (!tb
[NL80211_BAND_IFTYPE_ATTR_IFTYPES
])
1220 printf("\t\tHE Iftypes: ");
1221 print_iftype_line(tb
[NL80211_BAND_IFTYPE_ATTR_IFTYPES
]);
1224 if (tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC
]) {
1225 len
= nla_len(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC
]);
1226 if (len
> sizeof(mac_cap
))
1227 len
= sizeof(mac_cap
);
1229 nla_data(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MAC
]),
1233 if (tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY
]) {
1234 len
= nla_len(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY
]);
1236 if (len
> sizeof(phy_cap
) - 1)
1237 len
= sizeof(phy_cap
) - 1;
1238 memcpy(&((__u8
*)phy_cap
)[1],
1239 nla_data(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PHY
]),
1243 if (tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET
]) {
1244 len
= nla_len(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET
]);
1245 if (len
> sizeof(mcs_set
))
1246 len
= sizeof(mcs_set
);
1248 nla_data(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET
]),
1253 if (tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE
]) {
1254 len
= nla_len(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE
]);
1255 if (len
> sizeof(ppet
))
1258 nla_data(tb
[NL80211_BAND_IFTYPE_ATTR_HE_CAP_PPE
]),
1263 __print_he_capa(mac_cap
, phy_cap
, mcs_set
, mcs_len
, ppet
, ppet_len
,
1267 void print_he_capability(const uint8_t *ie
, int len
)
1269 const void *mac_cap
, *phy_cap
, *mcs_set
;
1282 __print_he_capa(mac_cap
, phy_cap
- 1, mcs_set
, mcs_len
, NULL
, 0, false);
1285 void iw_hexdump(const char *prefix
, const __u8
*buf
, size_t size
)
1289 printf("%s: ", prefix
);
1290 for (i
= 0; i
< size
; i
++) {
1291 if (i
&& i
% 16 == 0)
1292 printf("\n%s: ", prefix
);
1293 printf("%02x ", buf
[i
]);
1298 int get_cf1(const struct chanmode
*chanmode
, unsigned long freq
)
1300 unsigned int cf1
= freq
, j
;
1301 unsigned int bw80
[] = { 5180, 5260, 5500, 5580, 5660, 5745,
1302 5955, 6035, 6115, 6195, 6275, 6355,
1303 6435, 6515, 6595, 6675, 6755, 6835,
1305 unsigned int vht160
[] = { 5180, 5500 };
1307 switch (chanmode
->width
) {
1308 case NL80211_CHAN_WIDTH_80
:
1309 /* setup center_freq1 */
1310 for (j
= 0; j
< ARRAY_SIZE(bw80
); j
++) {
1311 if (freq
>= bw80
[j
] && freq
< bw80
[j
] + 80)
1315 if (j
== ARRAY_SIZE(bw80
))
1320 case NL80211_CHAN_WIDTH_160
:
1321 /* setup center_freq1 */
1322 for (j
= 0; j
< ARRAY_SIZE(vht160
); j
++) {
1323 if (freq
>= vht160
[j
] && freq
< vht160
[j
] + 160)
1327 if (j
== ARRAY_SIZE(vht160
))
1330 cf1
= vht160
[j
] + 70;
1333 cf1
= freq
+ chanmode
->freq1_diff
;
1340 int parse_random_mac_addr(struct nl_msg
*msg
, char *addrs
)
1342 char *a_addr
, *a_mask
, *sep
;
1343 unsigned char addr
[ETH_ALEN
], mask
[ETH_ALEN
];
1346 /* randomise all but the multicast bit */
1347 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
,
1348 "\x00\x00\x00\x00\x00\x00");
1349 NLA_PUT(msg
, NL80211_ATTR_MAC_MASK
, ETH_ALEN
,
1350 "\x01\x00\x00\x00\x00\x00");
1358 sep
= strchr(addrs
, '/');
1366 if (mac_addr_a2n(addr
, a_addr
) || mac_addr_a2n(mask
, a_mask
))
1369 NLA_PUT(msg
, NL80211_ATTR_MAC
, ETH_ALEN
, addr
);
1370 NLA_PUT(msg
, NL80211_ATTR_MAC_MASK
, ETH_ALEN
, mask
);