nlmsg_free(freqs);
return err;
}
-COMMAND(scan, trigger, "[freq <freq>*] [ssid <ssid>*|passive]",
- NL80211_CMD_TRIGGER_SCAN, 0, CIB_NETDEV, handle_scan,
- "Trigger a scan on the given frequencies with probing for the given\n"
- "SSIDs (or wildcard if not given) unless passive scanning is requested.");
static void tab_on_first(bool *first)
{
print_rsn_ie("CCMP", "IEEE 802.1X", len, data);
}
+/*
+ * There are only 4 possible values, we just use a case instead of computing it,
+ * but technically this can also be computed through the formula:
+ *
+ * Max AMPDU length = (2 ^ (13 + exponent)) - 1 bytes
+ */
+__u32 compute_ampdu_length(__u8 exponent)
+{
+ switch (exponent) {
+ case 0: return 8191; /* (2 ^(13 + 0)) -1 */
+ case 1: return 16383; /* (2 ^(13 + 1)) -1 */
+ case 2: return 32767; /* (2 ^(13 + 2)) -1 */
+ case 3: return 65535; /* (2 ^(13 + 3)) -1 */
+ default: return 0;
+ }
+}
+
+const char *print_ampdu_space(__u8 space)
+{
+ switch (space) {
+ case 0: return "No restriction";
+ case 1: return "1/4 usec";
+ case 2: return "1/2 usec";
+ case 3: return "1 usec";
+ case 4: return "2 usec";
+ case 5: return "4 usec";
+ case 6: return "8 usec";
+ case 7: return "16 usec";
+ default:
+ return "Uknown";
+ }
+}
+
+static void print_ht_capa(const uint8_t type, uint8_t len, const uint8_t *data)
+{
+#define PRINT_HT_CAP(_cond, _str) \
+ do { \
+ if (_cond) \
+ printf("\t\t\t" _str "\n"); \
+ } while (0)
+ struct ht_cap_data {
+ __u16 cap;
+ __u8 ampdu_params;
+ struct {
+ __u8 rx_mcs_bitmask[10]; /* last 3 bits reserved */
+ __u16 max_rx_rate_1mbps: 10,
+ reserved_0: 6;
+ __u8 tx_rx_mcs_defined:1,
+ tx_rx_mcs_not_equal:1,
+ tx_max_streams:2,
+ tx_unequal_modulation:1,
+ reserved_1:3; /* 3 reserved bits here */
+ __u8 reserved_2[3]; /* 24 reserved bits here = 27 */
+ } mcs_set;
+ __u16 ht_extend_cap;
+ __u32 tx_beamform_cap;
+ __u8 asel_cap;
+ } __attribute__((packed)) ht_cap;
+ struct ht_cap_data *htc = &ht_cap;
+ __u8 ampdu_exponent, ampdu_spacing, bit;
+ __u32 max_ampdu_length, i;
+ bool tx_rx_mcs_equal = false;
+
+ if (len != 26) {
+ printf("\n\t\tHT Capability IE len != expected 26 bytes, skipping parse\n");
+ return;
+ }
+
+ memcpy(&ht_cap, data, 26);
+
+ printf("\n\t\tCapabilities: %#.4x\n", htc->cap);
+
+ PRINT_HT_CAP((htc->cap & BIT(0)), "RX LDCP");
+ PRINT_HT_CAP((htc->cap & BIT(1)), "HT20/HT40");
+ PRINT_HT_CAP(!(htc->cap & BIT(1)), "HT20");
+
+ PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 0, "Static SM Power Save");
+ PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 1, "Dynamic SM Power Save");
+ PRINT_HT_CAP(((htc->cap >> 2) & 0x3) == 3, "SM Power Save disabled");
+
+ PRINT_HT_CAP((htc->cap & BIT(4)), "RX Greenfield");
+ PRINT_HT_CAP((htc->cap & BIT(5)), "RX HT20 SGI");
+ PRINT_HT_CAP((htc->cap & BIT(6)), "RX HT40 SGI");
+ PRINT_HT_CAP((htc->cap & BIT(7)), "TX STBC");
+
+ PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 0, "No RX STBC");
+ PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 1, "RX STBC 1-stream");
+ PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 2, "RX STBC 2-streams");
+ PRINT_HT_CAP(((htc->cap >> 8) & 0x3) == 3, "RX STBC 3-streams");
+
+ PRINT_HT_CAP((htc->cap & BIT(10)), "HT Delayed Block Ack");
+
+ PRINT_HT_CAP((htc->cap & BIT(11)), "Max AMSDU length: 3839 bytes");
+ PRINT_HT_CAP(!(htc->cap & BIT(11)), "Max AMSDU length: 7935 bytes");
+
+ /*
+ * For beacons and probe response this would mean the BSS
+ * does or does not allow the usage of DSSS/CCK HT40.
+ * Otherwise it means the STA does or does not use
+ * DSSS/CCK HT40.
+ */
+ PRINT_HT_CAP((htc->cap & BIT(12)), "DSSS/CCK HT40");
+ PRINT_HT_CAP(!(htc->cap & BIT(12)), "No DSSS/CCK HT40");
+
+ /* BIT(13) is reserved */
+
+ PRINT_HT_CAP((htc->cap & BIT(14)), "40 MHz Intolerant");
+
+ PRINT_HT_CAP((htc->cap & BIT(15)), "L-SIG TXOP protection");
+
+ ampdu_exponent = htc->ampdu_params & 0x3;
+ max_ampdu_length = compute_ampdu_length(ampdu_exponent);
+ if (max_ampdu_length) {
+ printf("\t\tMaximum RX AMPDU length %d bytes (exponent: 0x0%02x)\n",
+ compute_ampdu_length(ampdu_exponent), ampdu_exponent);
+ }
+ else
+ printf("\t\tMaximum RX AMPDU length: unrecognized bytes "
+ "(exponent: %d)\n", ampdu_exponent);
+
+
+ ampdu_spacing = (htc->ampdu_params >> 2) & 0x3 ;
+ printf("\t\tMinimum RX AMPDU time spacing: %s (0x%02x)\n",
+ print_ampdu_space(ampdu_spacing), ampdu_spacing);
+
+ /* This is the whole MCS set, which is 16 bytes */
+ printf("\t\tMCS set:");
+ data+=2;
+ print_mcs_set(data);
+ printf("\n");
+
+ if (htc->mcs_set.tx_rx_mcs_defined && htc->mcs_set.tx_rx_mcs_not_equal)
+ tx_rx_mcs_equal = true;
+ if (tx_rx_mcs_equal)
+ printf("\t\tSupported TX/RX MCS Indexes:\n");
+ else
+ printf("\t\tSupported RX MCS Indexes:\n");
+ /*
+ * Parses the RX MCS rates. Only 10 bits correspond to actual MCS rates
+ * MCS [0-76]
+ */
+ for (i = 0; i < 10; i++) {
+ for (bit = 0; bit < 8; bit++) {
+ /* Only bits 0-76 are valid, bits 76-79 are reserved */
+ if (((i * 8) + bit) > 76)
+ break;
+ if (htc->mcs_set.rx_mcs_bitmask[i] & BIT(bit))
+ printf("\t\t\tMCS Index %d\n",
+ (i * 8) + bit);
+ }
+ }
+
+ if (!htc->mcs_set.tx_rx_mcs_defined) {
+ /* This is actually quite common */
+ printf("\t\tNo TX MCS set defined\n");
+ goto out;
+ }
+
+ if (htc->mcs_set.tx_rx_mcs_not_equal) {
+ printf("\t\tMaximum supported TX spatial streams: %d\n",
+ htc->mcs_set.tx_max_streams);
+ printf("\t\tTX unequal modulation ");
+ if (htc->mcs_set.tx_unequal_modulation)
+ printf("supported\n");
+ else
+ printf("unsupported\n");
+ }
+
+out:
+ return;
+}
+
static void print_capabilities(const uint8_t type, uint8_t len, const uint8_t *data)
{
int i, base, bit;
static const struct ie_print ieprinters[] = {
[0] = { "SSID", print_ssid, 0, 32, BIT(PRINT_SCAN) | BIT(PRINT_LINK), },
[1] = { "Supported rates", print_supprates, 0, 255, BIT(PRINT_SCAN), },
- [3] = { "DS Paramater set", print_ds, 1, 1, BIT(PRINT_SCAN), },
+ [3] = { "DS Parameter set", print_ds, 1, 1, BIT(PRINT_SCAN), },
[5] = PRINT_IGN,
[7] = { "Country", print_country, 3, 255, BIT(PRINT_SCAN), },
[32] = { "Power constraint", print_powerconstraint, 1, 1, BIT(PRINT_SCAN), },
[42] = { "ERP", print_erp, 1, 255, BIT(PRINT_SCAN), },
+ [45] = { "HT capabilities", print_ht_capa, 1, 255, BIT(PRINT_SCAN), },
[48] = { "RSN", print_rsn, 2, 255, BIT(PRINT_SCAN), },
[50] = { "Extended supported rates", print_supprates, 0, 255, BIT(PRINT_SCAN), },
[127] = { "Extended capabilities", print_capabilities, 0, 255, BIT(PRINT_SCAN), },
print_rsn_ie("TKIP", "IEEE 802.1X", len, data);
}
+static bool print_wifi_wmm_param(const uint8_t *data, uint8_t len)
+{
+ int i;
+ static const char *aci_tbl[] = { "BE", "BK", "VI", "VO" };
+
+ if (len < 19)
+ goto invalid;
+
+ if (data[0] != 1) {
+ printf("Parameter: not version 1: ");
+ return false;
+ }
+
+ printf("\t* Parameter version 1");
+
+ data++;
+
+ if (data[0] & 0x80)
+ printf("\n\t\t* u-APSD");
+
+ data += 2;
+
+ for (i = 0; i < 4; i++) {
+ printf("\n\t\t* %s:", aci_tbl[(data[0] >> 5) & 3]);
+ if (data[4] & 0x10)
+ printf(" acm");
+ printf(" CW %d-%d", (1 << (data[1] & 0xf)) - 1,
+ (1 << (data[1] >> 4)) - 1);
+ printf(", AIFSN %d", data[0] & 0xf);
+ if (data[2] | data[3])
+ printf(", TXOP %d usec", (data[2] + (data[3] << 8)) * 32);
+ data += 4;
+ }
+
+ printf("\n");
+ return true;
+
+ invalid:
+ printf("invalid: ");
+ return false;
+}
+
static void print_wifi_wmm(const uint8_t type, uint8_t len, const uint8_t *data)
{
int i;
printf(" information:");
break;
case 0x01:
- printf(" parameter:");
+ if (print_wifi_wmm_param(data + 1, len - 1))
+ return;
break;
default:
printf(" type %d:", data[0]);
break;
}
- for(i = 0; i < len - 1; i++)
- printf(" %.02x", data[i + 1]);
+ for(i = 1; i < len; i++)
+ printf(" %.02x", data[i]);
printf("\n");
}
[NL80211_BSS_SIGNAL_MBM] = { .type = NLA_U32 },
[NL80211_BSS_SIGNAL_UNSPEC] = { .type = NLA_U8 },
[NL80211_BSS_STATUS] = { .type = NLA_U32 },
+ [NL80211_BSS_SEEN_MS_AGO] = { .type = NLA_U32 },
};
struct scan_params *params = arg;
genlmsg_attrlen(gnlh, 0), NULL);
if (!tb[NL80211_ATTR_BSS]) {
- fprintf(stderr, "bss info missing!");
+ fprintf(stderr, "bss info missing!\n");
return NL_SKIP;
}
if (nla_parse_nested(bss, NL80211_BSS_MAX,
tb[NL80211_ATTR_BSS],
bss_policy)) {
- fprintf(stderr, "failed to parse nested attributes!");
+ fprintf(stderr, "failed to parse nested attributes!\n");
return NL_SKIP;
}
unsigned char s = nla_get_u8(bss[NL80211_BSS_SIGNAL_UNSPEC]);
printf("\tsignal: %d/100\n", s);
}
+ if (bss[NL80211_BSS_SEEN_MS_AGO]) {
+ int age = nla_get_u32(bss[NL80211_BSS_SEEN_MS_AGO]);
+ printf("\tlast seen: %d ms ago\n", age);
+ }
if (bss[NL80211_BSS_INFORMATION_ELEMENTS])
print_ies(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]),
nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]),
&scan_params);
return 0;
}
-COMMAND(scan, dump, "[-u]",
- NL80211_CMD_GET_SCAN, NLM_F_DUMP, CIB_NETDEV, handle_scan_dump,
- "Dump the current scan results. If -u is specified, print unknown\n"
- "data in scan results.");
static int handle_scan_combined(struct nl80211_state *state,
struct nl_cb *cb,
"Scan on the given frequencies and probe for the given SSIDs\n"
"(or wildcard if not given) unless passive scanning is requested.\n"
"If -u is specified print unknown data in the scan results.");
+COMMAND(scan, dump, "[-u]",
+ NL80211_CMD_GET_SCAN, NLM_F_DUMP, CIB_NETDEV, handle_scan_dump,
+ "Dump the current scan results. If -u is specified, print unknown\n"
+ "data in scan results.");
+COMMAND(scan, trigger, "[freq <freq>*] [ssid <ssid>*|passive]",
+ NL80211_CMD_TRIGGER_SCAN, 0, CIB_NETDEV, handle_scan,
+ "Trigger a scan on the given frequencies with probing for the given\n"
+ "SSIDs (or wildcard if not given) unless passive scanning is requested.");