2 #include <netlink/attr.h>
8 void mac_addr_n2a(char *mac_addr
, 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 static const char *ifmodes
[NL80211_IFTYPE_MAX
+ 1] = {
62 static char modebuf
[100];
64 const char *iftype_name(enum nl80211_iftype iftype
)
66 if (iftype
<= NL80211_IFTYPE_MAX
)
67 return ifmodes
[iftype
];
68 sprintf(modebuf
, "Unknown mode (%d)", iftype
);
72 static const char *commands
[NL80211_CMD_MAX
+ 1] = {
114 "michael_mic_failure",
125 static char cmdbuf
[100];
127 const char *command_name(enum nl80211_commands cmd
)
129 if (cmd
<= NL80211_CMD_MAX
)
130 return commands
[cmd
];
131 sprintf(cmdbuf
, "Unknown command (%d)", cmd
);
135 int ieee80211_channel_to_frequency(int chan
)
138 return 2407 + chan
* 5;
143 /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */
144 return (chan
+ 1000) * 5;
147 int ieee80211_frequency_to_channel(int freq
)
153 return (freq
- 2407) / 5;
155 /* FIXME: dot11ChannelStartingFactor (802.11-2007 17.3.8.3.2) */
156 return freq
/5 - 1000;
159 void print_ssid_escaped(const uint8_t len
, const uint8_t *data
)
163 for (i
= 0; i
< len
; i
++) {
164 if (isprint(data
[i
]))
165 printf("%c", data
[i
]);
167 printf("\\x%.2x", data
[i
]);
171 static int hex2num(char digit
)
173 if (!isxdigit(digit
))
177 return tolower(digit
) - 'a' + 10;
180 static int hex2byte(char *hex
)
184 d1
= hex2num(hex
[0]);
187 d2
= hex2num(hex
[1]);
190 return (d1
<< 4) | d2
;
193 static char *hex2bin(char *hex
, char *buf
)
210 int parse_keys(struct nl_msg
*msg
, char **argv
, int argc
)
214 bool have_default
= false;
220 NLA_PUT_FLAG(msg
, NL80211_ATTR_PRIVACY
);
222 keys
= nla_nest_start(msg
, NL80211_ATTR_KEYS
);
229 struct nlattr
*key
= nla_nest_start(msg
, ++i
);
235 if (arg
[pos
] == 'd') {
236 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
243 if (!isdigit(arg
[pos
]))
245 NLA_PUT_U8(msg
, NL80211_KEY_IDX
, arg
[pos
++] - '0');
246 if (arg
[pos
++] != ':')
249 switch (strlen(keydata
)) {
251 keydata
= hex2bin(keydata
, keybuf
);
253 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, 0x000FAC01);
257 keydata
= hex2bin(keydata
, keybuf
);
259 NLA_PUT_U32(msg
, NL80211_KEY_CIPHER
, 0x000FAC05);
269 NLA_PUT(msg
, NL80211_KEY_DATA
, keylen
, keydata
);
274 /* one key should be TX key */
275 if (!have_default
&& !argc
)
276 NLA_PUT_FLAG(msg
, NL80211_KEY_DEFAULT
);
278 nla_nest_end(msg
, key
);
281 nla_nest_end(msg
, keys
);
287 fprintf(stderr
, "key must be [d:]index:data where\n"
288 " 'd:' means default (transmit) key\n"
289 " 'index:' is a single digit (0-3)\n"
290 " 'data' must be 5 or 13 ascii chars\n"
291 " or 10 or 26 hex digits\n"
292 "for example: d:2:6162636465 is the same as d:2:abcde\n");
296 static void print_mcs_index(const __u8
*mcs
)
298 unsigned int mcs_bit
, prev_bit
= -2, prev_cont
= 0;
300 for (mcs_bit
= 0; mcs_bit
<= 76; mcs_bit
++) {
301 unsigned int mcs_octet
= mcs_bit
/8;
302 unsigned int MCS_RATE_BIT
= 1 << mcs_bit
% 8;
303 bool mcs_rate_idx_set
;
305 mcs_rate_idx_set
= !!(mcs
[mcs_octet
] & MCS_RATE_BIT
);
307 if (!mcs_rate_idx_set
)
310 if (prev_bit
!= mcs_bit
- 1) {
312 printf("%d, ", prev_bit
);
315 printf("%d", mcs_bit
);
317 } else if (!prev_cont
) {
326 printf("%d", prev_bit
);
331 * There are only 4 possible values, we just use a case instead of computing it,
332 * but technically this can also be computed through the formula:
334 * Max AMPDU length = (2 ^ (13 + exponent)) - 1 bytes
336 static __u32
compute_ampdu_length(__u8 exponent
)
339 case 0: return 8191; /* (2 ^(13 + 0)) -1 */
340 case 1: return 16383; /* (2 ^(13 + 1)) -1 */
341 case 2: return 32767; /* (2 ^(13 + 2)) -1 */
342 case 3: return 65535; /* (2 ^(13 + 3)) -1 */
347 static const char *print_ampdu_space(__u8 space
)
350 case 0: return "No restriction";
351 case 1: return "1/4 usec";
352 case 2: return "1/2 usec";
353 case 3: return "1 usec";
354 case 4: return "2 usec";
355 case 5: return "4 usec";
356 case 6: return "8 usec";
357 case 7: return "16 usec";
359 return "BUG (spacing more than 3 bits!)";
363 void print_ampdu_length(__u8 exponent
)
365 __u32 max_ampdu_length
;
367 max_ampdu_length
= compute_ampdu_length(exponent
);
369 if (max_ampdu_length
) {
370 printf("\t\tMaximum RX AMPDU length %d bytes (exponent: 0x0%02x)\n",
371 max_ampdu_length
, exponent
);
373 printf("\t\tMaximum RX AMPDU length: unrecognized bytes "
374 "(exponent: %d)\n", exponent
);
378 void print_ampdu_spacing(__u8 spacing
)
380 printf("\t\tMinimum RX AMPDU time spacing: %s (0x%02x)\n",
381 print_ampdu_space(spacing
), spacing
);
384 void print_ht_capability(__u16 cap
)
386 #define PRINT_HT_CAP(_cond, _str) \
389 printf("\t\t\t" _str "\n"); \
392 printf("\t\tCapabilities: 0x%02x\n", cap
);
394 PRINT_HT_CAP((cap
& BIT(0)), "RX LDCP");
395 PRINT_HT_CAP((cap
& BIT(1)), "HT20/HT40");
396 PRINT_HT_CAP(!(cap
& BIT(1)), "HT20");
398 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 0, "Static SM Power Save");
399 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 1, "Dynamic SM Power Save");
400 PRINT_HT_CAP(((cap
>> 2) & 0x3) == 3, "SM Power Save disabled");
402 PRINT_HT_CAP((cap
& BIT(4)), "RX Greenfield");
403 PRINT_HT_CAP((cap
& BIT(5)), "RX HT20 SGI");
404 PRINT_HT_CAP((cap
& BIT(6)), "RX HT40 SGI");
405 PRINT_HT_CAP((cap
& BIT(7)), "TX STBC");
407 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 0, "No RX STBC");
408 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 1, "RX STBC 1-stream");
409 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 2, "RX STBC 2-streams");
410 PRINT_HT_CAP(((cap
>> 8) & 0x3) == 3, "RX STBC 3-streams");
412 PRINT_HT_CAP((cap
& BIT(10)), "HT Delayed Block Ack");
414 PRINT_HT_CAP((cap
& BIT(11)), "Max AMSDU length: 3839 bytes");
415 PRINT_HT_CAP(!(cap
& BIT(11)), "Max AMSDU length: 7935 bytes");
418 * For beacons and probe response this would mean the BSS
419 * does or does not allow the usage of DSSS/CCK HT40.
420 * Otherwise it means the STA does or does not use
423 PRINT_HT_CAP((cap
& BIT(12)), "DSSS/CCK HT40");
424 PRINT_HT_CAP(!(cap
& BIT(12)), "No DSSS/CCK HT40");
426 /* BIT(13) is reserved */
428 PRINT_HT_CAP((cap
& BIT(14)), "40 MHz Intolerant");
430 PRINT_HT_CAP((cap
& BIT(15)), "L-SIG TXOP protection");
434 void print_ht_mcs(const __u8
*mcs
)
436 /* As defined in 7.3.2.57.4 Supported MCS Set field */
437 unsigned int tx_max_num_spatial_streams
, max_rx_supp_data_rate
;
438 bool tx_mcs_set_defined
, tx_mcs_set_equal
, tx_unequal_modulation
;
440 max_rx_supp_data_rate
= ((mcs
[10] >> 8) & ((mcs
[11] & 0x3) << 8));
441 tx_mcs_set_defined
= !!(mcs
[12] & (1 << 0));
442 tx_mcs_set_equal
= !(mcs
[12] & (1 << 1));
443 tx_max_num_spatial_streams
= ((mcs
[12] >> 2) & 3) + 1;
444 tx_unequal_modulation
= !!(mcs
[12] & (1 << 4));
446 if (max_rx_supp_data_rate
)
447 printf("\t\tHT Max RX data rate: %d Mbps\n", max_rx_supp_data_rate
);
448 /* XXX: else see 9.6.0e.5.3 how to get this I think */
450 if (tx_mcs_set_defined
) {
451 if (tx_mcs_set_equal
) {
452 printf("\t\tHT TX/RX MCS rate indexes supported:");
453 print_mcs_index(mcs
);
455 printf("\t\tHT RX MCS rate indexes supported:");
456 print_mcs_index(mcs
);
458 if (tx_unequal_modulation
)
459 printf("\t\tTX unequal modulation supported\n");
461 printf("\t\tTX unequal modulation not supported\n");
463 printf("\t\tHT TX Max spatial streams: %d\n",
464 tx_max_num_spatial_streams
);
466 printf("\t\tHT TX MCS rate indexes supported may differ\n");
469 printf("\t\tHT RX MCS rate indexes supported:");
470 print_mcs_index(mcs
);
471 printf("\t\tHT TX MCS rates indexes are undefined\n");