Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 1 | #include <errno.h> |
Johannes Berg | 2ef1be6 | 2008-04-02 17:40:11 +0200 | [diff] [blame] | 2 | #include <net/if.h> |
| 3 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 4 | #include <netlink/genl/genl.h> |
| 5 | #include <netlink/genl/family.h> |
| 6 | #include <netlink/genl/ctrl.h> |
| 7 | #include <netlink/msg.h> |
| 8 | #include <netlink/attr.h> |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 9 | |
Johannes Berg | f408e01 | 2008-09-18 19:32:11 +0200 | [diff] [blame] | 10 | #include "nl80211.h" |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 11 | #include "iw.h" |
| 12 | |
| 13 | static void print_flag(const char *name, int *open) |
| 14 | { |
| 15 | if (!*open) |
| 16 | printf(" ("); |
| 17 | else |
| 18 | printf(", "); |
| 19 | printf(name); |
| 20 | *open = 1; |
| 21 | } |
| 22 | |
| 23 | static int print_phy_handler(struct nl_msg *msg, void *arg) |
| 24 | { |
| 25 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 26 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 27 | |
| 28 | struct nlattr *tb_band[NL80211_BAND_ATTR_MAX + 1]; |
| 29 | |
| 30 | struct nlattr *tb_freq[NL80211_FREQUENCY_ATTR_MAX + 1]; |
| 31 | static struct nla_policy freq_policy[NL80211_FREQUENCY_ATTR_MAX + 1] = { |
| 32 | [NL80211_FREQUENCY_ATTR_FREQ] = { .type = NLA_U32 }, |
| 33 | [NL80211_FREQUENCY_ATTR_DISABLED] = { .type = NLA_FLAG }, |
| 34 | [NL80211_FREQUENCY_ATTR_PASSIVE_SCAN] = { .type = NLA_FLAG }, |
| 35 | [NL80211_FREQUENCY_ATTR_NO_IBSS] = { .type = NLA_FLAG }, |
| 36 | [NL80211_FREQUENCY_ATTR_RADAR] = { .type = NLA_FLAG }, |
Johannes Berg | c1081c2 | 2008-11-23 12:11:26 +0100 | [diff] [blame^] | 37 | [NL80211_FREQUENCY_ATTR_MAX_TX_POWER] = { .type = NLA_U32 }, |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; |
| 41 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { |
| 42 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, |
| 43 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG }, |
| 44 | }; |
| 45 | |
| 46 | struct nlattr *nl_band; |
| 47 | struct nlattr *nl_freq; |
| 48 | struct nlattr *nl_rate; |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 49 | struct nlattr *nl_mode; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 50 | int bandidx = 1; |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 51 | int rem_band, rem_freq, rem_rate, rem_mode; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 52 | int open; |
| 53 | |
| 54 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 55 | genlmsg_attrlen(gnlh, 0), NULL); |
| 56 | |
| 57 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) |
| 58 | return NL_SKIP; |
| 59 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 60 | if (tb_msg[NL80211_ATTR_WIPHY_NAME]) |
| 61 | printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME])); |
| 62 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 63 | nla_for_each_nested(nl_band, tb_msg[NL80211_ATTR_WIPHY_BANDS], rem_band) { |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 64 | printf("\tBand %d:\n", bandidx); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 65 | bandidx++; |
| 66 | |
| 67 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), |
| 68 | nla_len(nl_band), NULL); |
| 69 | |
Johannes Berg | 3dd781c | 2008-10-14 18:46:23 +0200 | [diff] [blame] | 70 | #ifdef NL80211_BAND_ATTR_HT_CAPA |
| 71 | if (tb_band[NL80211_BAND_ATTR_HT_CAPA]) { |
| 72 | unsigned short cap = nla_get_u16(tb_band[NL80211_BAND_ATTR_HT_CAPA]); |
| 73 | #define PCOM(fmt, args...) do { printf("\t\t\t * " fmt "\n", ##args); } while (0) |
| 74 | #define PBCOM(bit, args...) if (cap & (bit)) PCOM(args) |
| 75 | printf("\t\tHT capabilities: 0x%.4x\n", cap); |
| 76 | PBCOM(0x0001, "LPDC coding"); |
| 77 | if (cap & 0x0002) |
| 78 | PCOM("20/40 MHz operation"); |
| 79 | else |
| 80 | PCOM("20 MHz operation"); |
| 81 | switch ((cap & 0x000c) >> 2) { |
| 82 | case 0: |
| 83 | PCOM("static SM PS"); |
| 84 | break; |
| 85 | case 1: |
| 86 | PCOM("dynamic SM PS"); |
| 87 | break; |
| 88 | case 2: |
| 89 | PCOM("reserved SM PS"); |
| 90 | break; |
| 91 | case 3: |
| 92 | PCOM("SM PS disabled"); |
| 93 | break; |
| 94 | } |
| 95 | PBCOM(0x0010, "HT-greenfield"); |
| 96 | PBCOM(0x0020, "20 MHz short GI"); |
| 97 | PBCOM(0x0040, "40 MHz short GI"); |
| 98 | PBCOM(0x0080, "TX STBC"); |
| 99 | if (cap & 0x300) |
| 100 | PCOM("RX STBC %d streams", (cap & 0x0300) >> 8); |
| 101 | PBCOM(0x0400, "HT-delayed block-ack"); |
| 102 | PCOM("max A-MSDU len %d", 0xeff + ((cap & 0x0800) << 1)); |
| 103 | PBCOM(0x1000, "DSSS/CCK 40 MHz"); |
| 104 | PBCOM(0x2000, "PSMP support"); |
| 105 | PBCOM(0x4000, "40 MHz intolerant"); |
| 106 | PBCOM(0x8000, "L-SIG TXOP protection support"); |
| 107 | } |
| 108 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]) { |
| 109 | unsigned char factor = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_FACTOR]); |
| 110 | printf("\t\tHT A-MPDU factor: 0x%.4x (%d bytes)\n", factor, (1<<(13+factor))-1); |
| 111 | } |
| 112 | if (tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]) { |
| 113 | unsigned char dens = nla_get_u8(tb_band[NL80211_BAND_ATTR_HT_AMPDU_DENSITY]); |
| 114 | printf("\t\tHT A-MPDU density: 0x%.4x (", dens); |
| 115 | switch (dens) { |
| 116 | case 0: |
| 117 | printf("no restriction)\n"); |
| 118 | break; |
| 119 | case 1: |
| 120 | printf("1/4 usec)\n"); |
| 121 | break; |
| 122 | case 2: |
| 123 | printf("1/2 usec)\n"); |
| 124 | break; |
| 125 | default: |
| 126 | printf("%d usec)\n", 1<<(dens - 3)); |
| 127 | } |
| 128 | } |
| 129 | if (tb_band[NL80211_BAND_ATTR_HT_MCS_SET] && |
| 130 | nla_len(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]) == 16) { |
| 131 | unsigned char *mcs = nla_data(tb_band[NL80211_BAND_ATTR_HT_MCS_SET]); |
| 132 | printf("\t\tHT MCS set: %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", |
| 133 | mcs[0], mcs[1], mcs[2], mcs[3], mcs[4], mcs[5], mcs[6], mcs[7], |
| 134 | mcs[8], mcs[9], mcs[10], mcs[11], mcs[12], mcs[13], mcs[14], mcs[15]); |
| 135 | } |
| 136 | #endif |
| 137 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 138 | printf("\t\tFrequencies:\n"); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 139 | |
| 140 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { |
| 141 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), |
| 142 | nla_len(nl_freq), freq_policy); |
| 143 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 144 | continue; |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 145 | printf("\t\t\t* %d MHz", nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ])); |
Johannes Berg | c1081c2 | 2008-11-23 12:11:26 +0100 | [diff] [blame^] | 146 | |
| 147 | if (tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER] && |
| 148 | !tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) |
| 149 | printf(" (%.1f dBm)", 0.01 * nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_MAX_TX_POWER])); |
| 150 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 151 | open = 0; |
| 152 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) |
| 153 | print_flag("disabled", &open); |
| 154 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) |
| 155 | print_flag("passive scanning", &open); |
| 156 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) |
| 157 | print_flag("no IBSS", &open); |
| 158 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) |
| 159 | print_flag("radar detection", &open); |
| 160 | if (open) |
| 161 | printf(")"); |
| 162 | printf("\n"); |
| 163 | } |
| 164 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 165 | printf("\t\tBitrates:\n"); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 166 | |
| 167 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { |
| 168 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), |
| 169 | nla_len(nl_rate), rate_policy); |
| 170 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 171 | continue; |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 172 | printf("\t\t\t* %2.1f Mbps", 0.1 * nla_get_u32(tb_rate[NL80211_BITRATE_ATTR_RATE])); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 173 | open = 0; |
| 174 | if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE]) |
| 175 | print_flag("short preamble supported", &open); |
| 176 | if (open) |
| 177 | printf(")"); |
| 178 | printf("\n"); |
| 179 | } |
| 180 | } |
| 181 | |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 182 | if (!tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) |
| 183 | return NL_SKIP; |
| 184 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 185 | printf("\tSupported interface modes:\n"); |
Johannes Berg | 541ef42 | 2008-09-16 14:50:11 +0200 | [diff] [blame] | 186 | nla_for_each_nested(nl_mode, tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES], rem_mode) |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 187 | printf("\t\t * %s\n", iftype_name(nl_mode->nla_type)); |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 188 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 189 | return NL_SKIP; |
| 190 | } |
| 191 | |
Johannes Berg | 70391cc | 2008-09-16 18:35:06 +0200 | [diff] [blame] | 192 | static int handle_info(struct nl_cb *cb, |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 193 | struct nl_msg *msg, |
| 194 | int argc, char **argv) |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 195 | { |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 196 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, print_phy_handler, NULL); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 197 | |
Johannes Berg | 70391cc | 2008-09-16 18:35:06 +0200 | [diff] [blame] | 198 | return 0; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 199 | } |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 200 | TOPLEVEL(info, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_PHY, handle_info); |
| 201 | TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info); |