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 }, |
| 37 | }; |
| 38 | |
| 39 | struct nlattr *tb_rate[NL80211_BITRATE_ATTR_MAX + 1]; |
| 40 | static struct nla_policy rate_policy[NL80211_BITRATE_ATTR_MAX + 1] = { |
| 41 | [NL80211_BITRATE_ATTR_RATE] = { .type = NLA_U32 }, |
| 42 | [NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE] = { .type = NLA_FLAG }, |
| 43 | }; |
| 44 | |
| 45 | struct nlattr *nl_band; |
| 46 | struct nlattr *nl_freq; |
| 47 | struct nlattr *nl_rate; |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 48 | struct nlattr *nl_mode; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 49 | int bandidx = 1; |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 50 | int rem_band, rem_freq, rem_rate, rem_mode; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 51 | int open; |
| 52 | |
| 53 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 54 | genlmsg_attrlen(gnlh, 0), NULL); |
| 55 | |
| 56 | if (!tb_msg[NL80211_ATTR_WIPHY_BANDS]) |
| 57 | return NL_SKIP; |
| 58 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 59 | if (tb_msg[NL80211_ATTR_WIPHY_NAME]) |
| 60 | printf("Wiphy %s\n", nla_get_string(tb_msg[NL80211_ATTR_WIPHY_NAME])); |
| 61 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 62 | 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] | 63 | printf("\tBand %d:\n", bandidx); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 64 | bandidx++; |
| 65 | |
| 66 | nla_parse(tb_band, NL80211_BAND_ATTR_MAX, nla_data(nl_band), |
| 67 | nla_len(nl_band), NULL); |
| 68 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 69 | printf("\t\tFrequencies:\n"); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 70 | |
| 71 | nla_for_each_nested(nl_freq, tb_band[NL80211_BAND_ATTR_FREQS], rem_freq) { |
| 72 | nla_parse(tb_freq, NL80211_FREQUENCY_ATTR_MAX, nla_data(nl_freq), |
| 73 | nla_len(nl_freq), freq_policy); |
| 74 | if (!tb_freq[NL80211_FREQUENCY_ATTR_FREQ]) |
| 75 | continue; |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 76 | printf("\t\t\t* %d MHz", nla_get_u32(tb_freq[NL80211_FREQUENCY_ATTR_FREQ])); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 77 | open = 0; |
| 78 | if (tb_freq[NL80211_FREQUENCY_ATTR_DISABLED]) |
| 79 | print_flag("disabled", &open); |
| 80 | if (tb_freq[NL80211_FREQUENCY_ATTR_PASSIVE_SCAN]) |
| 81 | print_flag("passive scanning", &open); |
| 82 | if (tb_freq[NL80211_FREQUENCY_ATTR_NO_IBSS]) |
| 83 | print_flag("no IBSS", &open); |
| 84 | if (tb_freq[NL80211_FREQUENCY_ATTR_RADAR]) |
| 85 | print_flag("radar detection", &open); |
| 86 | if (open) |
| 87 | printf(")"); |
| 88 | printf("\n"); |
| 89 | } |
| 90 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 91 | printf("\t\tBitrates:\n"); |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 92 | |
| 93 | nla_for_each_nested(nl_rate, tb_band[NL80211_BAND_ATTR_RATES], rem_rate) { |
| 94 | nla_parse(tb_rate, NL80211_BITRATE_ATTR_MAX, nla_data(nl_rate), |
| 95 | nla_len(nl_rate), rate_policy); |
| 96 | if (!tb_rate[NL80211_BITRATE_ATTR_RATE]) |
| 97 | continue; |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 98 | 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] | 99 | open = 0; |
| 100 | if (tb_rate[NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE]) |
| 101 | print_flag("short preamble supported", &open); |
| 102 | if (open) |
| 103 | printf(")"); |
| 104 | printf("\n"); |
| 105 | } |
| 106 | } |
| 107 | |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 108 | if (!tb_msg[NL80211_ATTR_SUPPORTED_IFTYPES]) |
| 109 | return NL_SKIP; |
| 110 | |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 111 | printf("\tSupported interface modes:\n"); |
Johannes Berg | 541ef42 | 2008-09-16 14:50:11 +0200 | [diff] [blame] | 112 | 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] | 113 | printf("\t\t * %s\n", iftype_name(nl_mode->nla_type)); |
Johannes Berg | 6367e71 | 2008-09-05 23:01:11 +0200 | [diff] [blame] | 114 | |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 115 | return NL_SKIP; |
| 116 | } |
| 117 | |
Johannes Berg | 70391cc | 2008-09-16 18:35:06 +0200 | [diff] [blame] | 118 | static int handle_info(struct nl_cb *cb, |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 119 | struct nl_msg *msg, |
| 120 | int argc, char **argv) |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 121 | { |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 122 | 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] | 123 | |
Johannes Berg | 70391cc | 2008-09-16 18:35:06 +0200 | [diff] [blame] | 124 | return 0; |
Johannes Berg | 79f99b9 | 2008-01-16 00:21:59 +0100 | [diff] [blame] | 125 | } |
Johannes Berg | d631650 | 2008-09-16 17:05:33 +0200 | [diff] [blame] | 126 | TOPLEVEL(info, NULL, NL80211_CMD_GET_WIPHY, 0, CIB_PHY, handle_info); |
| 127 | TOPLEVEL(list, NULL, NL80211_CMD_GET_WIPHY, NLM_F_DUMP, CIB_NONE, handle_info); |