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] = {
152 * sed 's%^\tNL80211_CMD_%%;t n;d;:n s%^\([^=]*\),.*%\t[NL80211_CMD_\1] = \"\L\1\",%;t;d' nl80211.h | grep -v "reserved"
154 [NL80211_CMD_UNSPEC
] = "unspec",
155 [NL80211_CMD_GET_WIPHY
] = "get_wiphy",
156 [NL80211_CMD_SET_WIPHY
] = "set_wiphy",
157 [NL80211_CMD_NEW_WIPHY
] = "new_wiphy",
158 [NL80211_CMD_DEL_WIPHY
] = "del_wiphy",
159 [NL80211_CMD_GET_INTERFACE
] = "get_interface",
160 [NL80211_CMD_SET_INTERFACE
] = "set_interface",
161 [NL80211_CMD_NEW_INTERFACE
] = "new_interface",
162 [NL80211_CMD_DEL_INTERFACE
] = "del_interface",
163 [NL80211_CMD_GET_KEY
] = "get_key",
164 [NL80211_CMD_SET_KEY
] = "set_key",
165 [NL80211_CMD_NEW_KEY
] = "new_key",
166 [NL80211_CMD_DEL_KEY
] = "del_key",
167 [NL80211_CMD_GET_BEACON
] = "get_beacon",
168 [NL80211_CMD_SET_BEACON
] = "set_beacon",
169 [NL80211_CMD_START_AP
] = "start_ap",
170 [NL80211_CMD_STOP_AP
] = "stop_ap",
171 [NL80211_CMD_GET_STATION
] = "get_station",
172 [NL80211_CMD_SET_STATION
] = "set_station",
173 [NL80211_CMD_NEW_STATION
] = "new_station",
174 [NL80211_CMD_DEL_STATION
] = "del_station",
175 [NL80211_CMD_GET_MPATH
] = "get_mpath",
176 [NL80211_CMD_SET_MPATH
] = "set_mpath",
177 [NL80211_CMD_NEW_MPATH
] = "new_mpath",
178 [NL80211_CMD_DEL_MPATH
] = "del_mpath",
179 [NL80211_CMD_SET_BSS
] = "set_bss",
180 [NL80211_CMD_SET_REG
] = "set_reg",
181 [NL80211_CMD_REQ_SET_REG
] = "req_set_reg",
182 [NL80211_CMD_GET_MESH_CONFIG
] = "get_mesh_config",
183 [NL80211_CMD_SET_MESH_CONFIG
] = "set_mesh_config",
184 [NL80211_CMD_GET_REG
] = "get_reg",
185 [NL80211_CMD_GET_SCAN
] = "get_scan",
186 [NL80211_CMD_TRIGGER_SCAN
] = "trigger_scan",
187 [NL80211_CMD_NEW_SCAN_RESULTS
] = "new_scan_results",
188 [NL80211_CMD_SCAN_ABORTED
] = "scan_aborted",
189 [NL80211_CMD_REG_CHANGE
] = "reg_change",
190 [NL80211_CMD_AUTHENTICATE
] = "authenticate",
191 [NL80211_CMD_ASSOCIATE
] = "associate",
192 [NL80211_CMD_DEAUTHENTICATE
] = "deauthenticate",
193 [NL80211_CMD_DISASSOCIATE
] = "disassociate",
194 [NL80211_CMD_MICHAEL_MIC_FAILURE
] = "michael_mic_failure",
195 [NL80211_CMD_REG_BEACON_HINT
] = "reg_beacon_hint",
196 [NL80211_CMD_JOIN_IBSS
] = "join_ibss",
197 [NL80211_CMD_LEAVE_IBSS
] = "leave_ibss",
198 [NL80211_CMD_TESTMODE
] = "testmode",
199 [NL80211_CMD_CONNECT
] = "connect",
200 [NL80211_CMD_ROAM
] = "roam",
201 [NL80211_CMD_DISCONNECT
] = "disconnect",
202 [NL80211_CMD_SET_WIPHY_NETNS
] = "set_wiphy_netns",
203 [NL80211_CMD_GET_SURVEY
] = "get_survey",
204 [NL80211_CMD_NEW_SURVEY_RESULTS
] = "new_survey_results",
205 [NL80211_CMD_SET_PMKSA
] = "set_pmksa",
206 [NL80211_CMD_DEL_PMKSA
] = "del_pmksa",
207 [NL80211_CMD_FLUSH_PMKSA
] = "flush_pmksa",
208 [NL80211_CMD_REMAIN_ON_CHANNEL
] = "remain_on_channel",
209 [NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL
] = "cancel_remain_on_channel",
210 [NL80211_CMD_SET_TX_BITRATE_MASK
] = "set_tx_bitrate_mask",
211 [NL80211_CMD_REGISTER_FRAME
] = "register_frame",
212 [NL80211_CMD_FRAME
] = "frame",
213 [NL80211_CMD_FRAME_TX_STATUS
] = "frame_tx_status",
214 [NL80211_CMD_SET_POWER_SAVE
] = "set_power_save",
215 [NL80211_CMD_GET_POWER_SAVE
] = "get_power_save",
216 [NL80211_CMD_SET_CQM
] = "set_cqm",
217 [NL80211_CMD_NOTIFY_CQM
] = "notify_cqm",
218 [NL80211_CMD_SET_CHANNEL
] = "set_channel",
219 [NL80211_CMD_SET_WDS_PEER
] = "set_wds_peer",
220 [NL80211_CMD_FRAME_WAIT_CANCEL
] = "frame_wait_cancel",
221 [NL80211_CMD_JOIN_MESH
] = "join_mesh",
222 [NL80211_CMD_LEAVE_MESH
] = "leave_mesh",
223 [NL80211_CMD_UNPROT_DEAUTHENTICATE
] = "unprot_deauthenticate",
224 [NL80211_CMD_UNPROT_DISASSOCIATE
] = "unprot_disassociate",
225 [NL80211_CMD_NEW_PEER_CANDIDATE
] = "new_peer_candidate",
226 [NL80211_CMD_GET_WOWLAN
] = "get_wowlan",
227 [NL80211_CMD_SET_WOWLAN
] = "set_wowlan",
228 [NL80211_CMD_START_SCHED_SCAN
] = "start_sched_scan",
229 [NL80211_CMD_STOP_SCHED_SCAN
] = "stop_sched_scan",
230 [NL80211_CMD_SCHED_SCAN_RESULTS
] = "sched_scan_results",
231 [NL80211_CMD_SCHED_SCAN_STOPPED
] = "sched_scan_stopped",
232 [NL80211_CMD_SET_REKEY_OFFLOAD
] = "set_rekey_offload",
233 [NL80211_CMD_PMKSA_CANDIDATE
] = "pmksa_candidate",
234 [NL80211_CMD_TDLS_OPER
] = "tdls_oper",
235 [NL80211_CMD_TDLS_MGMT
] = "tdls_mgmt",
236 [NL80211_CMD_UNEXPECTED_FRAME
] = "unexpected_frame",
237 [NL80211_CMD_PROBE_CLIENT
] = "probe_client",
238 [NL80211_CMD_REGISTER_BEACONS
] = "register_beacons",
239 [NL80211_CMD_UNEXPECTED_4ADDR_FRAME
] = "unexpected_4addr_frame",
240 [NL80211_CMD_SET_NOACK_MAP
] = "set_noack_map",
241 [NL80211_CMD_CH_SWITCH_NOTIFY
] = "ch_switch_notify",
242 [NL80211_CMD_START_P2P_DEVICE
] = "start_p2p_device",
243 [NL80211_CMD_STOP_P2P_DEVICE
] = "stop_p2p_device",
244 [NL80211_CMD_CONN_FAILED
] = "conn_failed",
245 [NL80211_CMD_SET_MCAST_RATE
] = "set_mcast_rate",
246 [NL80211_CMD_SET_MAC_ACL
] = "set_mac_acl",
247 [NL80211_CMD_RADAR_DETECT
] = "radar_detect",
248 [NL80211_CMD_GET_PROTOCOL_FEATURES
] = "get_protocol_features",
249 [NL80211_CMD_UPDATE_FT_IES
] = "update_ft_ies",
250 [NL80211_CMD_FT_EVENT
] = "ft_event",
251 [NL80211_CMD_CRIT_PROTOCOL_START
] = "crit_protocol_start",
252 [NL80211_CMD_CRIT_PROTOCOL_STOP
] = "crit_protocol_stop",
253 [NL80211_CMD_GET_COALESCE
] = "get_coalesce",
254 [NL80211_CMD_SET_COALESCE
] = "set_coalesce",
255 [NL80211_CMD_CHANNEL_SWITCH
] = "channel_switch",
256 [NL80211_CMD_VENDOR
] = "vendor",
257 [NL80211_CMD_SET_QOS_MAP
] = "set_qos_map",
258 [NL80211_CMD_ADD_TX_TS
] = "add_tx_ts",
259 [NL80211_CMD_DEL_TX_TS
] = "del_tx_ts",
260 [NL80211_CMD_GET_MPP
] = "get_mpp",
261 [NL80211_CMD_JOIN_OCB
] = "join_ocb",
262 [NL80211_CMD_LEAVE_OCB
] = "leave_ocb",
263 [NL80211_CMD_CH_SWITCH_STARTED_NOTIFY
] = "ch_switch_started_notify",
264 [NL80211_CMD_TDLS_CHANNEL_SWITCH
] = "tdls_channel_switch",
265 [NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH
] = "tdls_cancel_channel_switch",
266 [NL80211_CMD_WIPHY_REG_CHANGE
] = "wiphy_reg_change",
267 [NL80211_CMD_ABORT_SCAN
] = "abort_scan",
268 [NL80211_CMD_START_NAN
] = "start_nan",
269 [NL80211_CMD_STOP_NAN
] = "stop_nan",
270 [NL80211_CMD_ADD_NAN_FUNCTION
] = "add_nan_function",
271 [NL80211_CMD_DEL_NAN_FUNCTION
] = "del_nan_function",
272 [NL80211_CMD_CHANGE_NAN_CONFIG
] = "change_nan_config",
273 [NL80211_CMD_NAN_MATCH
] = "nan_match",
274 [NL80211_CMD_SET_MULTICAST_TO_UNICAST
] = "set_multicast_to_unicast",
275 [NL80211_CMD_UPDATE_CONNECT_PARAMS
] = "update_connect_params",
276 [NL80211_CMD_SET_PMK
] = "set_pmk",
277 [NL80211_CMD_DEL_PMK
] = "del_pmk",
278 [NL80211_CMD_PORT_AUTHORIZED
] = "port_authorized",
279 [NL80211_CMD_RELOAD_REGDB
] = "reload_regdb",
282 static char cmdbuf
[100];
284 const char *command_name(enum nl80211_commands cmd
)
286 if (cmd
<= NL80211_CMD_MAX
&& commands
[cmd
])
287 return commands
[cmd
];
288 sprintf(cmdbuf
, "Unknown command (%d)", cmd
);
292 int ieee80211_channel_to_frequency(int chan
, enum nl80211_band band
)
294 /* see 802.11 17.3.8.3.2 and Annex J
295 * there are overlapping channel numbers in 5GHz and 2GHz bands */
297 return 0; /* not supported */
299 case NL80211_BAND_2GHZ
:
303 return 2407 + chan
* 5;
305 case NL80211_BAND_5GHZ
:
306 if (chan
>= 182 && chan
<= 196)
307 return 4000 + chan
* 5;
309 return 5000 + chan
* 5;
311 case NL80211_BAND_60GHZ
:
313 return 56160 + chan
* 2160;
318 return 0; /* not supported */
321 int ieee80211_frequency_to_channel(int freq
)
323 /* see 802.11-2007 17.3.8.3.2 and Annex J */
326 else if (freq
< 2484)
327 return (freq
- 2407) / 5;
328 else if (freq
>= 4910 && freq
<= 4980)
329 return (freq
- 4000) / 5;
330 else if (freq
<= 45000) /* DMG band lower limit */
331 return (freq
- 5000) / 5;
332 else if (freq
>= 58320 && freq
<= 64800)
333 return (freq
- 56160) / 2160;
338 void print_ssid_escaped(const uint8_t len
, const uint8_t *data
)
342 for (i
= 0; i
< len
; i
++) {
343 if (isprint(data
[i
]) && data
[i
] != ' ' && data
[i
] != '\\')
344 printf("%c", data
[i
]);
345 else if (data
[i
] == ' ' &&
346 (i
!= 0 && i
!= len
-1))
349 printf("\\x%.2x", data
[i
]);
353 static int hex2num(char digit
)
355 if (!isxdigit(digit
))
359 return tolower(digit
) - 'a' + 10;
362 static int hex2byte(const char *hex
)
366 d1
= hex2num(hex
[0]);
369 d2
= hex2num(hex
[1]);
372 return (d1
<< 4) | d2
;
375 char *hex2bin(const char *hex
, char *buf
)
392 static int parse_akm_suite(const char *cipher_str
)
395 if (!strcmp(cipher_str
, "PSK"))
397 if (!strcmp(cipher_str
, "FT/PSK"))
399 if (!strcmp(cipher_str
, "PSK/SHA-256"))
404 static int parse_cipher_suite(const char *cipher_str
)
407 if (!strcmp(cipher_str
, "TKIP"))
409 if (!strcmp(cipher_str
, "CCMP") || !strcmp(cipher_str
, "CCMP-128"))
411 if (!strcmp(cipher_str
, "GCMP") || !strcmp(cipher_str
, "GCMP-128"))
413 if (!strcmp(cipher_str
, "GCMP-256"))
415 if (!strcmp(cipher_str
, "CCMP-256"))
420 int parse_keys(struct nl_msg
*msg
, char **argv
[], int *argc
)
424 bool have_default
= false;
432 if (!memcmp(&arg
[pos
], "psk", 3)) {
434 int cipher_suite
, akm_suite
;
444 NLA_PUT_U32(msg
, NL80211_ATTR_WPA_VERSIONS
, NL80211_WPA_VERSION_2
);
446 if (strlen(&arg
[pos
]) != (sizeof(psk_keybuf
) * 2) || !hex2bin(&arg
[pos
], psk_keybuf
)) {
451 NLA_PUT(msg
, NL80211_ATTR_PMK
, 32, psk_keybuf
);
452 NLA_PUT_U32(msg
, NL80211_ATTR_AUTH_TYPE
, NL80211_AUTHTYPE_OPEN_SYSTEM
);
458 akm_suite
= parse_akm_suite(arg
);
462 NLA_PUT_U32(msg
, NL80211_ATTR_AKM_SUITES
, akm_suite
);
468 cipher_suite
= parse_cipher_suite(arg
);
469 if (cipher_suite
< 0)
472 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITES_PAIRWISE
, cipher_suite
);
478 cipher_suite
= parse_cipher_suite(arg
);
479 if (cipher_suite
< 0)
482 NLA_PUT_U32(msg
, NL80211_ATTR_CIPHER_SUITE_GROUP
, cipher_suite
);
489 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
491 keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
497 struct nlattr
*key
= nla_nest_start(msg
, ++i
);
506 if (arg
[pos
] == 'd') {
507 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
514 if (!isdigit(arg
[pos
]))
516 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, arg
[pos
++] - '0');
517 if (arg
[pos
++] != ':')
520 switch (strlen(keydata
)) {
522 keydata
= hex2bin(keydata
, keybuf
);
525 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, 0x000FAC01);
529 keydata
= hex2bin(keydata
, keybuf
);
532 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, 0x000FAC05);
542 NLA_PUT(msg
, NL80211_KEY_DATA
, keylen
, keydata
);
547 /* one key should be TX key */
548 if (!have_default
&& !*argc
)
549 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
551 nla_nest_end(msg
, key
);
554 nla_nest_end(msg
, keys
);
560 fprintf(stderr
, "key must be [d:]index:data where\n"
561 " 'd:' means default (transmit) key\n"
562 " 'index:' is a single digit (0-3)\n"
563 " 'data' must be 5 or 13 ascii chars\n"
564 " or 10 or 26 hex digits\n"
565 "for example: d:2:6162636465 is the same as d:2:abcde\n"
566 "or psk:data <AKM Suite> <pairwise CIPHER> <groupwise CIPHER> where\n"
567 " 'data' is the PSK (output of wpa_passphrase and the CIPHER can be CCMP or GCMP\n"
568 "for example: psk:0123456789abcdef PSK CCMP CCMP\n"
569 "The allowed AKM suites are PSK, FT/PSK, PSK/SHA-256\n"
570 "The allowed Cipher suites are TKIP, CCMP, GCMP, GCMP-256, CCMP-256\n");
574 enum nl80211_chan_width
str_to_bw(const char *str
)
576 static const struct {
580 { .name
= "5", .val
= NL80211_CHAN_WIDTH_5
, },
581 { .name
= "10", .val
= NL80211_CHAN_WIDTH_10
, },
582 { .name
= "20", .val
= NL80211_CHAN_WIDTH_20
, },
583 { .name
= "40", .val
= NL80211_CHAN_WIDTH_40
, },
584 { .name
= "80", .val
= NL80211_CHAN_WIDTH_80
, },
585 { .name
= "80+80", .val
= NL80211_CHAN_WIDTH_80P80
, },
586 { .name
= "160", .val
= NL80211_CHAN_WIDTH_160
, },
590 for (i
= 0; i
< ARRAY_SIZE(bwmap
); i
++) {
591 if (strcasecmp(bwmap
[i
].name
, str
) == 0)
595 return NL80211_CHAN_WIDTH_20_NOHT
;
598 static int parse_freqs(struct chandef
*chandef
, int argc
, char **argv
,
603 bool need_cf1
= false, need_cf2
= false;
608 chandef
->width
= str_to_bw(argv
[0]);
610 switch (chandef
->width
) {
611 case NL80211_CHAN_WIDTH_20_NOHT
:
612 /* First argument was not understood, give up gracefully. */
614 case NL80211_CHAN_WIDTH_20
:
615 case NL80211_CHAN_WIDTH_5
:
616 case NL80211_CHAN_WIDTH_10
:
618 case NL80211_CHAN_WIDTH_80P80
:
621 case NL80211_CHAN_WIDTH_40
:
622 case NL80211_CHAN_WIDTH_80
:
623 case NL80211_CHAN_WIDTH_160
:
639 freq
= strtoul(argv
[1], &end
, 10);
644 chandef
->center_freq1
= freq
;
655 freq
= strtoul(argv
[2], &end
, 10);
658 chandef
->center_freq2
= freq
;
667 * parse_freqchan - Parse frequency or channel definition
669 * @chandef: chandef structure to be filled in
670 * @chan: Boolean whether to parse a channel or frequency based specifier
671 * @argc: Number of arguments
672 * @argv: Array of string arguments
673 * @parsed: Pointer to return the number of used arguments, or NULL to error
674 * out if any argument is left unused.
676 * The given chandef structure will be filled in from the command line
677 * arguments. argc/argv will be updated so that further arguments from the
678 * command line can be parsed.
680 * Note that despite the fact that the function knows how many center freqs
681 * are needed, there's an ambiguity if the next argument after this is an
682 * integer argument, since the valid channel width values are interpreted
683 * as such, rather than a following argument. This can be avoided by the
684 * user by giving "NOHT" instead.
686 * The working specifier if chan is set are:
687 * <channel> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]
689 * And if frequency is set:
690 * <freq> [NOHT|HT20|HT40+|HT40-|5MHz|10MHz|80MHz]
691 * <control freq> [5|10|20|40|80|80+80|160] [<center1_freq> [<center2_freq>]]
693 * If the mode/channel width is not given the NOHT is assumed.
695 * Return: Number of used arguments, zero or negative error number otherwise
697 int parse_freqchan(struct chandef
*chandef
, bool chan
, int argc
, char **argv
,
701 static const struct chanmode chanmode
[] = {
703 .width
= NL80211_CHAN_WIDTH_20
,
705 .chantype
= NL80211_CHAN_HT20
},
707 .width
= NL80211_CHAN_WIDTH_40
,
709 .chantype
= NL80211_CHAN_HT40PLUS
},
711 .width
= NL80211_CHAN_WIDTH_40
,
713 .chantype
= NL80211_CHAN_HT40MINUS
},
715 .width
= NL80211_CHAN_WIDTH_20_NOHT
,
717 .chantype
= NL80211_CHAN_NO_HT
},
719 .width
= NL80211_CHAN_WIDTH_5
,
723 .width
= NL80211_CHAN_WIDTH_10
,
727 .width
= NL80211_CHAN_WIDTH_80
,
731 const struct chanmode
*chanmode_selected
= NULL
;
742 freq
= strtoul(argv
[0], &end
, 10);
750 memset(chandef
, 0, sizeof(struct chandef
));
753 enum nl80211_band band
;
755 band
= freq
<= 14 ? NL80211_BAND_2GHZ
: NL80211_BAND_5GHZ
;
756 freq
= ieee80211_channel_to_frequency(freq
, band
);
758 chandef
->control_freq
= freq
;
759 /* Assume 20MHz NOHT channel for now. */
760 chandef
->center_freq1
= freq
;
762 /* Try to parse HT mode definitions */
764 for (i
= 0; i
< ARRAY_SIZE(chanmode
); i
++) {
765 if (strcasecmp(chanmode
[i
].name
, argv
[1]) == 0) {
766 chanmode_selected
= &chanmode
[i
];
773 /* channel mode given, use it and return. */
774 if (chanmode_selected
) {
775 chandef
->center_freq1
= get_cf1(chanmode_selected
, freq
);
776 chandef
->width
= chanmode_selected
->width
;
780 /* This was a only a channel definition, nothing further may follow. */
784 res
= parse_freqs(chandef
, argc
- 1, argv
+ 1, &_parsed
);
787 /* Error out if parsed is NULL. */
788 if (!parsed
&& _parsed
!= argc
)
797 int put_chandef(struct nl_msg
*msg
, struct chandef
*chandef
)
799 NLA_PUT_U32(msg
, NL80211_ATTR_WIPHY_FREQ
, chandef
->control_freq
);
800 NLA_PUT_U32(msg
, NL80211_ATTR_CHANNEL_WIDTH
, chandef
->width
);
802 switch (chandef
->width
) {
803 case NL80211_CHAN_WIDTH_20_NOHT
:
805 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
808 case NL80211_CHAN_WIDTH_20
:
810 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
813 case NL80211_CHAN_WIDTH_40
:
814 if (chandef
->control_freq
> chandef
->center_freq1
)
816 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
817 NL80211_CHAN_HT40MINUS
);
820 NL80211_ATTR_WIPHY_CHANNEL_TYPE
,
821 NL80211_CHAN_HT40PLUS
);
827 if (chandef
->center_freq1
)
829 NL80211_ATTR_CENTER_FREQ1
,
830 chandef
->center_freq1
);
832 if (chandef
->center_freq2
)
834 NL80211_ATTR_CENTER_FREQ2
,
835 chandef
->center_freq2
);
843 static void print_mcs_index(const __u8
*mcs
)
845 int mcs_bit
, prev_bit
= -2, prev_cont
= 0;
847 for (mcs_bit
= 0; mcs_bit
<= 76; mcs_bit
++) {
848 unsigned int mcs_octet
= mcs_bit
/8;
849 unsigned int MCS_RATE_BIT
= 1 << mcs_bit
% 8;
850 bool mcs_rate_idx_set
;
852 mcs_rate_idx_set
= !!(mcs
[mcs_octet
] & MCS_RATE_BIT
);
854 if (!mcs_rate_idx_set
)
857 if (prev_bit
!= mcs_bit
- 1) {
859 printf("%d, ", prev_bit
);
862 printf("%d", mcs_bit
);
864 } else if (!prev_cont
) {
873 printf("%d", prev_bit
);
878 * There are only 4 possible values, we just use a case instead of computing it,
879 * but technically this can also be computed through the formula:
881 * Max AMPDU length = (2 ^ (13 + exponent)) - 1 bytes
883 static __u32
compute_ampdu_length(__u8 exponent
)
886 case 0: return 8191; /* (2 ^(13 + 0)) -1 */
887 case 1: return 16383; /* (2 ^(13 + 1)) -1 */
888 case 2: return 32767; /* (2 ^(13 + 2)) -1 */
889 case 3: return 65535; /* (2 ^(13 + 3)) -1 */
894 static const char *print_ampdu_space(__u8 space
)
897 case 0: return "No restriction";
898 case 1: return "1/4 usec";
899 case 2: return "1/2 usec";
900 case 3: return "1 usec";
901 case 4: return "2 usec";
902 case 5: return "4 usec";
903 case 6: return "8 usec";
904 case 7: return "16 usec";
906 return "BUG (spacing more than 3 bits!)";
910 void print_ampdu_length(__u8 exponent
)
912 __u32 max_ampdu_length
;
914 max_ampdu_length
= compute_ampdu_length(exponent
);
916 if (max_ampdu_length
) {
917 printf("\t\tMaximum RX AMPDU length %d bytes (exponent: 0x0%02x)\n",
918 max_ampdu_length
, exponent
);
920 printf("\t\tMaximum RX AMPDU length: unrecognized bytes "
921 "(exponent: %d)\n", exponent
);
925 void print_ampdu_spacing(__u8 spacing
)
927 printf("\t\tMinimum RX AMPDU time spacing: %s (0x%02x)\n",
928 print_ampdu_space(spacing
), spacing
);
931 void print_ht_capability(__u16 cap
)
933 #define PRINT_HT_CAP(_cond, _str) \
936 printf("\t\t\t" _str "\n"); \
939 printf("\t\tCapabilities: 0x%02x\n", cap
);
941 PRINT_HT_CAP((cap
& BIT(0)), "RX LDPC");
942 PRINT_HT_CAP((cap
& BIT(1)), "HT20/HT40");
943 PRINT_HT_CAP(!(cap
& BIT(1)), "HT20");
945 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 0, "Static SM Power Save");
946 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 1, "Dynamic SM Power Save");
947 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 3, "SM Power Save disabled");
949 PRINT_HT_CAP((cap
& BIT(4)), "RX Greenfield");
950 PRINT_HT_CAP((cap
& BIT(5)), "RX HT20 SGI");
951 PRINT_HT_CAP((cap
& BIT(6)), "RX HT40 SGI");
952 PRINT_HT_CAP((cap
& BIT(7)), "TX STBC");
954 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 0, "No RX STBC");
955 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 1, "RX STBC 1-stream");
956 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 2, "RX STBC 2-streams");
957 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 3, "RX STBC 3-streams");
959 PRINT_HT_CAP((cap
& BIT(10)), "HT Delayed Block Ack");
961 PRINT_HT_CAP(!(cap
& BIT(11)), "Max AMSDU length: 3839 bytes");
962 PRINT_HT_CAP((cap
& BIT(11)), "Max AMSDU length: 7935 bytes");
965 * For beacons and probe response this would mean the BSS
966 * does or does not allow the usage of DSSS/CCK HT40.
967 * Otherwise it means the STA does or does not use
970 PRINT_HT_CAP((cap
& BIT(12)), "DSSS/CCK HT40");
971 PRINT_HT_CAP(!(cap
& BIT(12)), "No DSSS/CCK HT40");
973 /* BIT(13) is reserved */
975 PRINT_HT_CAP((cap
& BIT(14)), "40 MHz Intolerant");
977 PRINT_HT_CAP((cap
& BIT(15)), "L-SIG TXOP protection");
981 void print_ht_mcs(const __u8
*mcs
)
983 /* As defined in 7.3.2.57.4 Supported MCS Set field */
984 unsigned int tx_max_num_spatial_streams
, max_rx_supp_data_rate
;
985 bool tx_mcs_set_defined
, tx_mcs_set_equal
, tx_unequal_modulation
;
987 max_rx_supp_data_rate
= (mcs
[10] | ((mcs
[11] & 0x3) << 8));
988 tx_mcs_set_defined
= !!(mcs
[12] & (1 << 0));
989 tx_mcs_set_equal
= !(mcs
[12] & (1 << 1));
990 tx_max_num_spatial_streams
= ((mcs
[12] >> 2) & 3) + 1;
991 tx_unequal_modulation
= !!(mcs
[12] & (1 << 4));
993 if (max_rx_supp_data_rate
)
994 printf("\t\tHT Max RX data rate: %d Mbps\n", max_rx_supp_data_rate
);
995 /* XXX: else see 9.6.0e.5.3 how to get this I think */
997 if (tx_mcs_set_defined
) {
998 if (tx_mcs_set_equal
) {
999 printf("\t\tHT TX/RX MCS rate indexes supported:");
1000 print_mcs_index(mcs
);
1002 printf("\t\tHT RX MCS rate indexes supported:");
1003 print_mcs_index(mcs
);
1005 if (tx_unequal_modulation
)
1006 printf("\t\tTX unequal modulation supported\n");
1008 printf("\t\tTX unequal modulation not supported\n");
1010 printf("\t\tHT TX Max spatial streams: %d\n",
1011 tx_max_num_spatial_streams
);
1013 printf("\t\tHT TX MCS rate indexes supported may differ\n");
1016 printf("\t\tHT RX MCS rate indexes supported:");
1017 print_mcs_index(mcs
);
1018 printf("\t\tHT TX MCS rate indexes are undefined\n");
1022 void print_vht_info(__u32 capa
, const __u8
*mcs
)
1027 printf("\t\tVHT Capabilities (0x%.8x):\n", capa
);
1029 #define PRINT_VHT_CAPA(_bit, _str) \
1031 if (capa & BIT(_bit)) \
1032 printf("\t\t\t" _str "\n"); \
1035 printf("\t\t\tMax MPDU length: ");
1037 case 0: printf("3895\n"); break;
1038 case 1: printf("7991\n"); break;
1039 case 2: printf("11454\n"); break;
1040 case 3: printf("(reserved)\n");
1042 printf("\t\t\tSupported Channel Width: ");
1043 switch ((capa
>> 2) & 3) {
1044 case 0: printf("neither 160 nor 80+80\n"); break;
1045 case 1: printf("160 MHz\n"); break;
1046 case 2: printf("160 MHz, 80+80 MHz\n"); break;
1047 case 3: printf("(reserved)\n");
1049 PRINT_VHT_CAPA(4, "RX LDPC");
1050 PRINT_VHT_CAPA(5, "short GI (80 MHz)");
1051 PRINT_VHT_CAPA(6, "short GI (160/80+80 MHz)");
1052 PRINT_VHT_CAPA(7, "TX STBC");
1054 PRINT_VHT_CAPA(11, "SU Beamformer");
1055 PRINT_VHT_CAPA(12, "SU Beamformee");
1056 /* compressed steering */
1057 /* # of sounding dimensions */
1058 PRINT_VHT_CAPA(19, "MU Beamformer");
1059 PRINT_VHT_CAPA(20, "MU Beamformee");
1060 PRINT_VHT_CAPA(21, "VHT TXOP PS");
1061 PRINT_VHT_CAPA(22, "+HTC-VHT");
1063 /* VHT link adaptation */
1064 PRINT_VHT_CAPA(28, "RX antenna pattern consistency");
1065 PRINT_VHT_CAPA(29, "TX antenna pattern consistency");
1067 printf("\t\tVHT RX MCS set:\n");
1068 tmp
= mcs
[0] | (mcs
[1] << 8);
1069 for (i
= 1; i
<= 8; i
++) {
1070 printf("\t\t\t%d streams: ", i
);
1071 switch ((tmp
>> ((i
-1)*2) ) & 3) {
1072 case 0: printf("MCS 0-7\n"); break;
1073 case 1: printf("MCS 0-8\n"); break;
1074 case 2: printf("MCS 0-9\n"); break;
1075 case 3: printf("not supported\n"); break;
1078 tmp
= mcs
[2] | (mcs
[3] << 8);
1079 printf("\t\tVHT RX highest supported: %d Mbps\n", tmp
& 0x1fff);
1081 printf("\t\tVHT TX MCS set:\n");
1082 tmp
= mcs
[4] | (mcs
[5] << 8);
1083 for (i
= 1; i
<= 8; i
++) {
1084 printf("\t\t\t%d streams: ", i
);
1085 switch ((tmp
>> ((i
-1)*2) ) & 3) {
1086 case 0: printf("MCS 0-7\n"); break;
1087 case 1: printf("MCS 0-8\n"); break;
1088 case 2: printf("MCS 0-9\n"); break;
1089 case 3: printf("not supported\n"); break;
1092 tmp
= mcs
[6] | (mcs
[7] << 8);
1093 printf("\t\tVHT TX highest supported: %d Mbps\n", tmp
& 0x1fff);
1096 void iw_hexdump(const char *prefix
, const __u8
*buf
, size_t size
)
1100 printf("%s: ", prefix
);
1101 for (i
= 0; i
< size
; i
++) {
1102 if (i
&& i
% 16 == 0)
1103 printf("\n%s: ", prefix
);
1104 printf("%02x ", buf
[i
]);
1109 int get_cf1(const struct chanmode
*chanmode
, unsigned long freq
)
1111 unsigned int cf1
= freq
, j
;
1112 unsigned int vht80
[] = { 5180, 5260, 5500, 5580, 5660, 5745 };
1114 switch (chanmode
->width
) {
1115 case NL80211_CHAN_WIDTH_80
:
1116 /* setup center_freq1 */
1117 for (j
= 0; j
< ARRAY_SIZE(vht80
); j
++) {
1118 if (freq
>= vht80
[j
] && freq
< vht80
[j
] + 80)
1122 if (j
== ARRAY_SIZE(vht80
))
1125 cf1
= vht80
[j
] + 30;
1128 cf1
= freq
+ chanmode
->freq1_diff
;