Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 4 | * Copyright 2006-2009 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/if.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/err.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 10 | #include <linux/list.h> |
| 11 | #include <linux/if_ether.h> |
| 12 | #include <linux/ieee80211.h> |
| 13 | #include <linux/nl80211.h> |
| 14 | #include <linux/rtnetlink.h> |
| 15 | #include <linux/netlink.h> |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 16 | #include <linux/etherdevice.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 17 | #include <net/net_namespace.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 18 | #include <net/genetlink.h> |
| 19 | #include <net/cfg80211.h> |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 20 | #include <net/sock.h> |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 21 | #include "core.h" |
| 22 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 23 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 24 | |
| 25 | /* the netlink family */ |
| 26 | static struct genl_family nl80211_fam = { |
| 27 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 28 | .name = "nl80211", /* have users key off the name instead */ |
| 29 | .hdrsize = 0, /* no private header */ |
| 30 | .version = 1, /* no particular meaning now */ |
| 31 | .maxattr = NL80211_ATTR_MAX, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 32 | .netnsok = true, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 33 | }; |
| 34 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 35 | /* internal helper: get rdev and dev */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 36 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 37 | struct cfg80211_registered_device **rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 38 | struct net_device **dev) |
| 39 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 40 | struct nlattr **attrs = info->attrs; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 41 | int ifindex; |
| 42 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 43 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 44 | return -EINVAL; |
| 45 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 46 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 47 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 48 | if (!*dev) |
| 49 | return -ENODEV; |
| 50 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 51 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 52 | if (IS_ERR(*rdev)) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 53 | dev_put(*dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 54 | return PTR_ERR(*rdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
| 60 | /* policy for the attributes */ |
| 61 | static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = { |
| 62 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 63 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
David S. Miller | 079e24e | 2009-05-26 21:15:00 -0700 | [diff] [blame] | 64 | .len = 20-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 65 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 66 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 67 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 68 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
| 69 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, |
| 70 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, |
| 71 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 72 | |
| 73 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 74 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 75 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 76 | |
| 77 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 78 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 79 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 80 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 81 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 82 | .len = WLAN_MAX_KEY_LEN }, |
| 83 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 84 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 85 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Jouni Malinen | 9f26a95 | 2009-05-15 12:38:32 +0300 | [diff] [blame] | 86 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 87 | |
| 88 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 89 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 90 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 91 | .len = IEEE80211_MAX_DATA_LEN }, |
| 92 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 93 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 94 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 95 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 96 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 97 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 98 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 99 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 100 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 101 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 102 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 103 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 104 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 105 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 106 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 107 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 108 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 109 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 110 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 111 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 112 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 113 | .len = NL80211_MAX_SUPP_RATES }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 114 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 115 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
| 116 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 117 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 118 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 119 | |
| 120 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 121 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 122 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 123 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 124 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 125 | |
| 126 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 127 | .len = IEEE80211_MAX_SSID_LEN }, |
| 128 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 129 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 130 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 131 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 132 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 133 | [NL80211_ATTR_STA_FLAGS2] = { |
| 134 | .len = sizeof(struct nl80211_sta_flag_update), |
| 135 | }, |
Jouni Malinen | 3f77316c | 2009-05-11 21:57:57 +0300 | [diff] [blame] | 136 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 137 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
| 138 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, |
| 139 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 140 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 141 | }; |
| 142 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 143 | /* policy for the attributes */ |
| 144 | static struct nla_policy |
| 145 | nl80211_key_policy[NL80211_KEY_MAX + 1] __read_mostly = { |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 146 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 147 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
| 148 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, |
| 149 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
| 150 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
| 151 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, |
| 152 | }; |
| 153 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 154 | /* IE validation */ |
| 155 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 156 | { |
| 157 | const u8 *pos; |
| 158 | int len; |
| 159 | |
| 160 | if (!attr) |
| 161 | return true; |
| 162 | |
| 163 | pos = nla_data(attr); |
| 164 | len = nla_len(attr); |
| 165 | |
| 166 | while (len) { |
| 167 | u8 elemlen; |
| 168 | |
| 169 | if (len < 2) |
| 170 | return false; |
| 171 | len -= 2; |
| 172 | |
| 173 | elemlen = pos[1]; |
| 174 | if (elemlen > len) |
| 175 | return false; |
| 176 | |
| 177 | len -= elemlen; |
| 178 | pos += 2 + elemlen; |
| 179 | } |
| 180 | |
| 181 | return true; |
| 182 | } |
| 183 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 184 | /* message building helper */ |
| 185 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 186 | int flags, u8 cmd) |
| 187 | { |
| 188 | /* since there is no private header just add the generic one */ |
| 189 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 190 | } |
| 191 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 192 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 193 | struct ieee80211_channel *chan) |
| 194 | { |
| 195 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 196 | chan->center_freq); |
| 197 | |
| 198 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 199 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 200 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 201 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 202 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 203 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 204 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 205 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 206 | |
| 207 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 208 | DBM_TO_MBM(chan->max_power)); |
| 209 | |
| 210 | return 0; |
| 211 | |
| 212 | nla_put_failure: |
| 213 | return -ENOBUFS; |
| 214 | } |
| 215 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 216 | /* netlink command implementations */ |
| 217 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 218 | struct key_parse { |
| 219 | struct key_params p; |
| 220 | int idx; |
| 221 | bool def, defmgmt; |
| 222 | }; |
| 223 | |
| 224 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) |
| 225 | { |
| 226 | struct nlattr *tb[NL80211_KEY_MAX + 1]; |
| 227 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, |
| 228 | nl80211_key_policy); |
| 229 | if (err) |
| 230 | return err; |
| 231 | |
| 232 | k->def = !!tb[NL80211_KEY_DEFAULT]; |
| 233 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; |
| 234 | |
| 235 | if (tb[NL80211_KEY_IDX]) |
| 236 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); |
| 237 | |
| 238 | if (tb[NL80211_KEY_DATA]) { |
| 239 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); |
| 240 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); |
| 241 | } |
| 242 | |
| 243 | if (tb[NL80211_KEY_SEQ]) { |
| 244 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); |
| 245 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); |
| 246 | } |
| 247 | |
| 248 | if (tb[NL80211_KEY_CIPHER]) |
| 249 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); |
| 250 | |
| 251 | return 0; |
| 252 | } |
| 253 | |
| 254 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) |
| 255 | { |
| 256 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 257 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 258 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 259 | } |
| 260 | |
| 261 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { |
| 262 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 263 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); |
| 264 | } |
| 265 | |
| 266 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 267 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 268 | |
| 269 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 270 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 271 | |
| 272 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; |
| 273 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) |
| 279 | { |
| 280 | int err; |
| 281 | |
| 282 | memset(k, 0, sizeof(*k)); |
| 283 | k->idx = -1; |
| 284 | |
| 285 | if (info->attrs[NL80211_ATTR_KEY]) |
| 286 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); |
| 287 | else |
| 288 | err = nl80211_parse_key_old(info, k); |
| 289 | |
| 290 | if (err) |
| 291 | return err; |
| 292 | |
| 293 | if (k->def && k->defmgmt) |
| 294 | return -EINVAL; |
| 295 | |
| 296 | if (k->idx != -1) { |
| 297 | if (k->defmgmt) { |
| 298 | if (k->idx < 4 || k->idx > 5) |
| 299 | return -EINVAL; |
| 300 | } else if (k->def) { |
| 301 | if (k->idx < 0 || k->idx > 3) |
| 302 | return -EINVAL; |
| 303 | } else { |
| 304 | if (k->idx < 0 || k->idx > 5) |
| 305 | return -EINVAL; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 312 | static struct cfg80211_cached_keys * |
| 313 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, |
| 314 | struct nlattr *keys) |
| 315 | { |
| 316 | struct key_parse parse; |
| 317 | struct nlattr *key; |
| 318 | struct cfg80211_cached_keys *result; |
| 319 | int rem, err, def = 0; |
| 320 | |
| 321 | result = kzalloc(sizeof(*result), GFP_KERNEL); |
| 322 | if (!result) |
| 323 | return ERR_PTR(-ENOMEM); |
| 324 | |
| 325 | result->def = -1; |
| 326 | result->defmgmt = -1; |
| 327 | |
| 328 | nla_for_each_nested(key, keys, rem) { |
| 329 | memset(&parse, 0, sizeof(parse)); |
| 330 | parse.idx = -1; |
| 331 | |
| 332 | err = nl80211_parse_key_new(key, &parse); |
| 333 | if (err) |
| 334 | goto error; |
| 335 | err = -EINVAL; |
| 336 | if (!parse.p.key) |
| 337 | goto error; |
| 338 | if (parse.idx < 0 || parse.idx > 4) |
| 339 | goto error; |
| 340 | if (parse.def) { |
| 341 | if (def) |
| 342 | goto error; |
| 343 | def = 1; |
| 344 | result->def = parse.idx; |
| 345 | } else if (parse.defmgmt) |
| 346 | goto error; |
| 347 | err = cfg80211_validate_key_settings(rdev, &parse.p, |
| 348 | parse.idx, NULL); |
| 349 | if (err) |
| 350 | goto error; |
| 351 | result->params[parse.idx].cipher = parse.p.cipher; |
| 352 | result->params[parse.idx].key_len = parse.p.key_len; |
| 353 | result->params[parse.idx].key = result->data[parse.idx]; |
| 354 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); |
| 355 | } |
| 356 | |
| 357 | return result; |
| 358 | error: |
| 359 | kfree(result); |
| 360 | return ERR_PTR(err); |
| 361 | } |
| 362 | |
| 363 | static int nl80211_key_allowed(struct wireless_dev *wdev) |
| 364 | { |
| 365 | ASSERT_WDEV_LOCK(wdev); |
| 366 | |
| 367 | if (!netif_running(wdev->netdev)) |
| 368 | return -ENETDOWN; |
| 369 | |
| 370 | switch (wdev->iftype) { |
| 371 | case NL80211_IFTYPE_AP: |
| 372 | case NL80211_IFTYPE_AP_VLAN: |
| 373 | break; |
| 374 | case NL80211_IFTYPE_ADHOC: |
| 375 | if (!wdev->current_bss) |
| 376 | return -ENOLINK; |
| 377 | break; |
| 378 | case NL80211_IFTYPE_STATION: |
| 379 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
| 380 | return -ENOLINK; |
| 381 | break; |
| 382 | default: |
| 383 | return -EINVAL; |
| 384 | } |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 389 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 390 | struct cfg80211_registered_device *dev) |
| 391 | { |
| 392 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 393 | struct nlattr *nl_bands, *nl_band; |
| 394 | struct nlattr *nl_freqs, *nl_freq; |
| 395 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 396 | struct nlattr *nl_modes; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 397 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 398 | enum ieee80211_band band; |
| 399 | struct ieee80211_channel *chan; |
| 400 | struct ieee80211_rate *rate; |
| 401 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 402 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 403 | |
| 404 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 405 | if (!hdr) |
| 406 | return -1; |
| 407 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 408 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 409 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 410 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 411 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 412 | cfg80211_rdev_list_generation); |
| 413 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 414 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
| 415 | dev->wiphy.retry_short); |
| 416 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
| 417 | dev->wiphy.retry_long); |
| 418 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
| 419 | dev->wiphy.frag_threshold); |
| 420 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
| 421 | dev->wiphy.rts_threshold); |
| 422 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 423 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 424 | dev->wiphy.max_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 425 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 426 | dev->wiphy.max_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 427 | |
Johannes Berg | 25e47c18 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 428 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 429 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 430 | dev->wiphy.cipher_suites); |
| 431 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 432 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 433 | if (!nl_modes) |
| 434 | goto nla_put_failure; |
| 435 | |
| 436 | i = 0; |
| 437 | while (ifmodes) { |
| 438 | if (ifmodes & 1) |
| 439 | NLA_PUT_FLAG(msg, i); |
| 440 | ifmodes >>= 1; |
| 441 | i++; |
| 442 | } |
| 443 | |
| 444 | nla_nest_end(msg, nl_modes); |
| 445 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 446 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 447 | if (!nl_bands) |
| 448 | goto nla_put_failure; |
| 449 | |
| 450 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 451 | if (!dev->wiphy.bands[band]) |
| 452 | continue; |
| 453 | |
| 454 | nl_band = nla_nest_start(msg, band); |
| 455 | if (!nl_band) |
| 456 | goto nla_put_failure; |
| 457 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 458 | /* add HT info */ |
| 459 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 460 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 461 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 462 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 463 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 464 | dev->wiphy.bands[band]->ht_cap.cap); |
| 465 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 466 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 467 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 468 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 469 | } |
| 470 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 471 | /* add frequencies */ |
| 472 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 473 | if (!nl_freqs) |
| 474 | goto nla_put_failure; |
| 475 | |
| 476 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 477 | nl_freq = nla_nest_start(msg, i); |
| 478 | if (!nl_freq) |
| 479 | goto nla_put_failure; |
| 480 | |
| 481 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 482 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 483 | if (nl80211_msg_put_channel(msg, chan)) |
| 484 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 485 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 486 | nla_nest_end(msg, nl_freq); |
| 487 | } |
| 488 | |
| 489 | nla_nest_end(msg, nl_freqs); |
| 490 | |
| 491 | /* add bitrates */ |
| 492 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 493 | if (!nl_rates) |
| 494 | goto nla_put_failure; |
| 495 | |
| 496 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 497 | nl_rate = nla_nest_start(msg, i); |
| 498 | if (!nl_rate) |
| 499 | goto nla_put_failure; |
| 500 | |
| 501 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 502 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 503 | rate->bitrate); |
| 504 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 505 | NLA_PUT_FLAG(msg, |
| 506 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 507 | |
| 508 | nla_nest_end(msg, nl_rate); |
| 509 | } |
| 510 | |
| 511 | nla_nest_end(msg, nl_rates); |
| 512 | |
| 513 | nla_nest_end(msg, nl_band); |
| 514 | } |
| 515 | nla_nest_end(msg, nl_bands); |
| 516 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 517 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 518 | if (!nl_cmds) |
| 519 | goto nla_put_failure; |
| 520 | |
| 521 | i = 0; |
| 522 | #define CMD(op, n) \ |
| 523 | do { \ |
| 524 | if (dev->ops->op) { \ |
| 525 | i++; \ |
| 526 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 527 | } \ |
| 528 | } while (0) |
| 529 | |
| 530 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 531 | CMD(change_virtual_intf, SET_INTERFACE); |
| 532 | CMD(add_key, NEW_KEY); |
| 533 | CMD(add_beacon, NEW_BEACON); |
| 534 | CMD(add_station, NEW_STATION); |
| 535 | CMD(add_mpath, NEW_MPATH); |
| 536 | CMD(set_mesh_params, SET_MESH_PARAMS); |
| 537 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 538 | CMD(auth, AUTHENTICATE); |
| 539 | CMD(assoc, ASSOCIATE); |
| 540 | CMD(deauth, DEAUTHENTICATE); |
| 541 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 542 | CMD(join_ibss, JOIN_IBSS); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 543 | if (dev->wiphy.netnsok) { |
| 544 | i++; |
| 545 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); |
| 546 | } |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 547 | |
| 548 | #undef CMD |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 549 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 550 | if (dev->ops->connect || dev->ops->auth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 551 | i++; |
| 552 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); |
| 553 | } |
| 554 | |
Johannes Berg | 6829c878 | 2009-07-02 09:13:27 +0200 | [diff] [blame] | 555 | if (dev->ops->disconnect || dev->ops->deauth) { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 556 | i++; |
| 557 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); |
| 558 | } |
| 559 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 560 | nla_nest_end(msg, nl_cmds); |
| 561 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 562 | return genlmsg_end(msg, hdr); |
| 563 | |
| 564 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 565 | genlmsg_cancel(msg, hdr); |
| 566 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 570 | { |
| 571 | int idx = 0; |
| 572 | int start = cb->args[0]; |
| 573 | struct cfg80211_registered_device *dev; |
| 574 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 575 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 576 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 577 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
| 578 | continue; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 579 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 580 | continue; |
| 581 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 582 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 583 | dev) < 0) { |
| 584 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 585 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 586 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 587 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 588 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 589 | |
| 590 | cb->args[0] = idx; |
| 591 | |
| 592 | return skb->len; |
| 593 | } |
| 594 | |
| 595 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 596 | { |
| 597 | struct sk_buff *msg; |
| 598 | struct cfg80211_registered_device *dev; |
| 599 | |
| 600 | dev = cfg80211_get_dev_from_info(info); |
| 601 | if (IS_ERR(dev)) |
| 602 | return PTR_ERR(dev); |
| 603 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 604 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 605 | if (!msg) |
| 606 | goto out_err; |
| 607 | |
| 608 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) |
| 609 | goto out_free; |
| 610 | |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 611 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 612 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 613 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 614 | |
| 615 | out_free: |
| 616 | nlmsg_free(msg); |
| 617 | out_err: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 618 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 619 | return -ENOBUFS; |
| 620 | } |
| 621 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 622 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 623 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 624 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 625 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 626 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 627 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 628 | }; |
| 629 | |
| 630 | static int parse_txq_params(struct nlattr *tb[], |
| 631 | struct ieee80211_txq_params *txq_params) |
| 632 | { |
| 633 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 634 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 635 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 636 | return -EINVAL; |
| 637 | |
| 638 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 639 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 640 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 641 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 642 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 643 | |
| 644 | return 0; |
| 645 | } |
| 646 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 647 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 648 | { |
| 649 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 650 | int result = 0, rem_txq_params = 0; |
| 651 | struct nlattr *nl_txq_params; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 652 | u32 changed; |
| 653 | u8 retry_short = 0, retry_long = 0; |
| 654 | u32 frag_threshold = 0, rts_threshold = 0; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 655 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 656 | rtnl_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 657 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 658 | mutex_lock(&cfg80211_mutex); |
| 659 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 660 | rdev = __cfg80211_rdev_from_info(info); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 661 | if (IS_ERR(rdev)) { |
Jiri Slaby | 1f5fc70 | 2009-06-20 12:31:11 +0200 | [diff] [blame] | 662 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 663 | result = PTR_ERR(rdev); |
| 664 | goto unlock; |
| 665 | } |
| 666 | |
| 667 | mutex_lock(&rdev->mtx); |
| 668 | |
| 669 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 670 | result = cfg80211_dev_rename( |
| 671 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 672 | |
| 673 | mutex_unlock(&cfg80211_mutex); |
| 674 | |
| 675 | if (result) |
| 676 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 677 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 678 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 679 | struct ieee80211_txq_params txq_params; |
| 680 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 681 | |
| 682 | if (!rdev->ops->set_txq_params) { |
| 683 | result = -EOPNOTSUPP; |
| 684 | goto bad_res; |
| 685 | } |
| 686 | |
| 687 | nla_for_each_nested(nl_txq_params, |
| 688 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 689 | rem_txq_params) { |
| 690 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 691 | nla_data(nl_txq_params), |
| 692 | nla_len(nl_txq_params), |
| 693 | txq_params_policy); |
| 694 | result = parse_txq_params(tb, &txq_params); |
| 695 | if (result) |
| 696 | goto bad_res; |
| 697 | |
| 698 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 699 | &txq_params); |
| 700 | if (result) |
| 701 | goto bad_res; |
| 702 | } |
| 703 | } |
| 704 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 705 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 706 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Luis R. Rodriguez | 294196a | 2009-05-02 00:37:20 -0400 | [diff] [blame] | 707 | u32 freq; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 708 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 709 | result = -EINVAL; |
| 710 | |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 711 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 712 | channel_type = nla_get_u32(info->attrs[ |
| 713 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 714 | if (channel_type != NL80211_CHAN_NO_HT && |
| 715 | channel_type != NL80211_CHAN_HT20 && |
| 716 | channel_type != NL80211_CHAN_HT40PLUS && |
| 717 | channel_type != NL80211_CHAN_HT40MINUS) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 718 | goto bad_res; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 722 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 723 | mutex_lock(&rdev->devlist_mtx); |
Johannes Berg | 4b18114 | 2009-08-08 11:03:58 +0200 | [diff] [blame] | 724 | result = rdev_set_freq(rdev, NULL, freq, channel_type); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 725 | mutex_unlock(&rdev->devlist_mtx); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 726 | if (result) |
| 727 | goto bad_res; |
| 728 | } |
| 729 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 730 | changed = 0; |
| 731 | |
| 732 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { |
| 733 | retry_short = nla_get_u8( |
| 734 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); |
| 735 | if (retry_short == 0) { |
| 736 | result = -EINVAL; |
| 737 | goto bad_res; |
| 738 | } |
| 739 | changed |= WIPHY_PARAM_RETRY_SHORT; |
| 740 | } |
| 741 | |
| 742 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { |
| 743 | retry_long = nla_get_u8( |
| 744 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); |
| 745 | if (retry_long == 0) { |
| 746 | result = -EINVAL; |
| 747 | goto bad_res; |
| 748 | } |
| 749 | changed |= WIPHY_PARAM_RETRY_LONG; |
| 750 | } |
| 751 | |
| 752 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { |
| 753 | frag_threshold = nla_get_u32( |
| 754 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); |
| 755 | if (frag_threshold < 256) { |
| 756 | result = -EINVAL; |
| 757 | goto bad_res; |
| 758 | } |
| 759 | if (frag_threshold != (u32) -1) { |
| 760 | /* |
| 761 | * Fragments (apart from the last one) are required to |
| 762 | * have even length. Make the fragmentation code |
| 763 | * simpler by stripping LSB should someone try to use |
| 764 | * odd threshold value. |
| 765 | */ |
| 766 | frag_threshold &= ~0x1; |
| 767 | } |
| 768 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; |
| 769 | } |
| 770 | |
| 771 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { |
| 772 | rts_threshold = nla_get_u32( |
| 773 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); |
| 774 | changed |= WIPHY_PARAM_RTS_THRESHOLD; |
| 775 | } |
| 776 | |
| 777 | if (changed) { |
| 778 | u8 old_retry_short, old_retry_long; |
| 779 | u32 old_frag_threshold, old_rts_threshold; |
| 780 | |
| 781 | if (!rdev->ops->set_wiphy_params) { |
| 782 | result = -EOPNOTSUPP; |
| 783 | goto bad_res; |
| 784 | } |
| 785 | |
| 786 | old_retry_short = rdev->wiphy.retry_short; |
| 787 | old_retry_long = rdev->wiphy.retry_long; |
| 788 | old_frag_threshold = rdev->wiphy.frag_threshold; |
| 789 | old_rts_threshold = rdev->wiphy.rts_threshold; |
| 790 | |
| 791 | if (changed & WIPHY_PARAM_RETRY_SHORT) |
| 792 | rdev->wiphy.retry_short = retry_short; |
| 793 | if (changed & WIPHY_PARAM_RETRY_LONG) |
| 794 | rdev->wiphy.retry_long = retry_long; |
| 795 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) |
| 796 | rdev->wiphy.frag_threshold = frag_threshold; |
| 797 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) |
| 798 | rdev->wiphy.rts_threshold = rts_threshold; |
| 799 | |
| 800 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); |
| 801 | if (result) { |
| 802 | rdev->wiphy.retry_short = old_retry_short; |
| 803 | rdev->wiphy.retry_long = old_retry_long; |
| 804 | rdev->wiphy.frag_threshold = old_frag_threshold; |
| 805 | rdev->wiphy.rts_threshold = old_rts_threshold; |
| 806 | } |
| 807 | } |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 808 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 809 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 810 | mutex_unlock(&rdev->mtx); |
| 811 | unlock: |
| 812 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 813 | return result; |
| 814 | } |
| 815 | |
| 816 | |
| 817 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 818 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 819 | struct net_device *dev) |
| 820 | { |
| 821 | void *hdr; |
| 822 | |
| 823 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 824 | if (!hdr) |
| 825 | return -1; |
| 826 | |
| 827 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 828 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 829 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 830 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 831 | |
| 832 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
| 833 | rdev->devlist_generation ^ |
| 834 | (cfg80211_rdev_list_generation << 2)); |
| 835 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 836 | return genlmsg_end(msg, hdr); |
| 837 | |
| 838 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 839 | genlmsg_cancel(msg, hdr); |
| 840 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 844 | { |
| 845 | int wp_idx = 0; |
| 846 | int if_idx = 0; |
| 847 | int wp_start = cb->args[0]; |
| 848 | int if_start = cb->args[1]; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 849 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 850 | struct wireless_dev *wdev; |
| 851 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 852 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 853 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
| 854 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 855 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 856 | if (wp_idx < wp_start) { |
| 857 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 858 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 859 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 860 | if_idx = 0; |
| 861 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 862 | mutex_lock(&rdev->devlist_mtx); |
| 863 | list_for_each_entry(wdev, &rdev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 864 | if (if_idx < if_start) { |
| 865 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 866 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 867 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 868 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 869 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 870 | rdev, wdev->netdev) < 0) { |
| 871 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 872 | goto out; |
| 873 | } |
| 874 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 875 | } |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 876 | mutex_unlock(&rdev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 877 | |
| 878 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 879 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 880 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 881 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 882 | |
| 883 | cb->args[0] = wp_idx; |
| 884 | cb->args[1] = if_idx; |
| 885 | |
| 886 | return skb->len; |
| 887 | } |
| 888 | |
| 889 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 890 | { |
| 891 | struct sk_buff *msg; |
| 892 | struct cfg80211_registered_device *dev; |
| 893 | struct net_device *netdev; |
| 894 | int err; |
| 895 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 896 | err = get_rdev_dev_by_info_ifindex(info, &dev, &netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 897 | if (err) |
| 898 | return err; |
| 899 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 900 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 901 | if (!msg) |
| 902 | goto out_err; |
| 903 | |
Johannes Berg | d726405 | 2009-04-19 16:23:20 +0200 | [diff] [blame] | 904 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
| 905 | dev, netdev) < 0) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 906 | goto out_free; |
| 907 | |
| 908 | dev_put(netdev); |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 909 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 910 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 911 | return genlmsg_reply(msg, info); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 912 | |
| 913 | out_free: |
| 914 | nlmsg_free(msg); |
| 915 | out_err: |
| 916 | dev_put(netdev); |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 917 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 918 | return -ENOBUFS; |
| 919 | } |
| 920 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 921 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 922 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 923 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 924 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 925 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 926 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 927 | }; |
| 928 | |
| 929 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 930 | { |
| 931 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 932 | int flag; |
| 933 | |
| 934 | *mntrflags = 0; |
| 935 | |
| 936 | if (!nla) |
| 937 | return -EINVAL; |
| 938 | |
| 939 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 940 | nla, mntr_flags_policy)) |
| 941 | return -EINVAL; |
| 942 | |
| 943 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 944 | if (flags[flag]) |
| 945 | *mntrflags |= (1<<flag); |
| 946 | |
| 947 | return 0; |
| 948 | } |
| 949 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 950 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 951 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 952 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 953 | struct vif_params params; |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 954 | int err; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 955 | enum nl80211_iftype otype, ntype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 956 | struct net_device *dev; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 957 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 958 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 959 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 960 | memset(¶ms, 0, sizeof(params)); |
| 961 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 962 | rtnl_lock(); |
| 963 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 964 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 965 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 966 | goto unlock_rtnl; |
| 967 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 968 | otype = ntype = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 969 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 970 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 971 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 972 | if (otype != ntype) |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 973 | change = true; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 974 | if (ntype > NL80211_IFTYPE_MAX) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 975 | err = -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 976 | goto unlock; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 977 | } |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 978 | } |
| 979 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 980 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 981 | if (ntype != NL80211_IFTYPE_MESH_POINT) { |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 982 | err = -EINVAL; |
| 983 | goto unlock; |
| 984 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 985 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 986 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 987 | change = true; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 988 | } |
| 989 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 990 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 991 | if (ntype != NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 992 | err = -EINVAL; |
| 993 | goto unlock; |
| 994 | } |
| 995 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 996 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 997 | if (err) |
| 998 | goto unlock; |
| 999 | |
| 1000 | flags = &_flags; |
| 1001 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 1002 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1003 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1004 | if (change) |
Johannes Berg | 3d54d25 | 2009-08-21 14:51:05 +0200 | [diff] [blame] | 1005 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 1006 | else |
| 1007 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 1008 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1009 | unlock: |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 1010 | dev_put(dev); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1011 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1012 | unlock_rtnl: |
| 1013 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1014 | return err; |
| 1015 | } |
| 1016 | |
| 1017 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 1018 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1019 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1020 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1021 | int err; |
| 1022 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1023 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1024 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1025 | memset(¶ms, 0, sizeof(params)); |
| 1026 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1027 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 1028 | return -EINVAL; |
| 1029 | |
| 1030 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 1031 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 1032 | if (type > NL80211_IFTYPE_MAX) |
| 1033 | return -EINVAL; |
| 1034 | } |
| 1035 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1036 | rtnl_lock(); |
| 1037 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1038 | rdev = cfg80211_get_dev_from_info(info); |
| 1039 | if (IS_ERR(rdev)) { |
| 1040 | err = PTR_ERR(rdev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1041 | goto unlock_rtnl; |
| 1042 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1043 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1044 | if (!rdev->ops->add_virtual_intf || |
| 1045 | !(rdev->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1046 | err = -EOPNOTSUPP; |
| 1047 | goto unlock; |
| 1048 | } |
| 1049 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1050 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 1051 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 1052 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1053 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 1054 | } |
| 1055 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1056 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 1057 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 1058 | &flags); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1059 | err = rdev->ops->add_virtual_intf(&rdev->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 1060 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1061 | type, err ? NULL : &flags, ¶ms); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1062 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1063 | unlock: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1064 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1065 | unlock_rtnl: |
| 1066 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1067 | return err; |
| 1068 | } |
| 1069 | |
| 1070 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 1071 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1072 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1073 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1074 | struct net_device *dev; |
| 1075 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1076 | rtnl_lock(); |
| 1077 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1078 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1079 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1080 | goto unlock_rtnl; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1081 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1082 | if (!rdev->ops->del_virtual_intf) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1083 | err = -EOPNOTSUPP; |
| 1084 | goto out; |
| 1085 | } |
| 1086 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1087 | err = rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1088 | |
| 1089 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1090 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1091 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1092 | unlock_rtnl: |
| 1093 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1094 | return err; |
| 1095 | } |
| 1096 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1097 | struct get_key_cookie { |
| 1098 | struct sk_buff *msg; |
| 1099 | int error; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1100 | int idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1101 | }; |
| 1102 | |
| 1103 | static void get_key_callback(void *c, struct key_params *params) |
| 1104 | { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1105 | struct nlattr *key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1106 | struct get_key_cookie *cookie = c; |
| 1107 | |
| 1108 | if (params->key) |
| 1109 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 1110 | params->key_len, params->key); |
| 1111 | |
| 1112 | if (params->seq) |
| 1113 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 1114 | params->seq_len, params->seq); |
| 1115 | |
| 1116 | if (params->cipher) |
| 1117 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 1118 | params->cipher); |
| 1119 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1120 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
| 1121 | if (!key) |
| 1122 | goto nla_put_failure; |
| 1123 | |
| 1124 | if (params->key) |
| 1125 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, |
| 1126 | params->key_len, params->key); |
| 1127 | |
| 1128 | if (params->seq) |
| 1129 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, |
| 1130 | params->seq_len, params->seq); |
| 1131 | |
| 1132 | if (params->cipher) |
| 1133 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, |
| 1134 | params->cipher); |
| 1135 | |
| 1136 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); |
| 1137 | |
| 1138 | nla_nest_end(cookie->msg, key); |
| 1139 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1140 | return; |
| 1141 | nla_put_failure: |
| 1142 | cookie->error = 1; |
| 1143 | } |
| 1144 | |
| 1145 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 1146 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1147 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1148 | int err; |
| 1149 | struct net_device *dev; |
| 1150 | u8 key_idx = 0; |
| 1151 | u8 *mac_addr = NULL; |
| 1152 | struct get_key_cookie cookie = { |
| 1153 | .error = 0, |
| 1154 | }; |
| 1155 | void *hdr; |
| 1156 | struct sk_buff *msg; |
| 1157 | |
| 1158 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1159 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1160 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1161 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1162 | return -EINVAL; |
| 1163 | |
| 1164 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1165 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1166 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1167 | rtnl_lock(); |
| 1168 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1169 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1170 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1171 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1172 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1173 | if (!rdev->ops->get_key) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1174 | err = -EOPNOTSUPP; |
| 1175 | goto out; |
| 1176 | } |
| 1177 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1178 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1179 | if (!msg) { |
| 1180 | err = -ENOMEM; |
| 1181 | goto out; |
| 1182 | } |
| 1183 | |
| 1184 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1185 | NL80211_CMD_NEW_KEY); |
| 1186 | |
| 1187 | if (IS_ERR(hdr)) { |
| 1188 | err = PTR_ERR(hdr); |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1189 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | cookie.msg = msg; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1193 | cookie.idx = key_idx; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1194 | |
| 1195 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1196 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 1197 | if (mac_addr) |
| 1198 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1199 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1200 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, mac_addr, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1201 | &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1202 | |
| 1203 | if (err) |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1204 | goto free_msg; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1205 | |
| 1206 | if (cookie.error) |
| 1207 | goto nla_put_failure; |
| 1208 | |
| 1209 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1210 | err = genlmsg_reply(msg, info); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1211 | goto out; |
| 1212 | |
| 1213 | nla_put_failure: |
| 1214 | err = -ENOBUFS; |
Niko Jokinen | 6c95e2a | 2009-07-15 11:00:53 +0300 | [diff] [blame] | 1215 | free_msg: |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1216 | nlmsg_free(msg); |
| 1217 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1218 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1219 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1220 | unlock_rtnl: |
| 1221 | rtnl_unlock(); |
| 1222 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1223 | return err; |
| 1224 | } |
| 1225 | |
| 1226 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 1227 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1228 | struct cfg80211_registered_device *rdev; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1229 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1230 | int err; |
| 1231 | struct net_device *dev; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1232 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, |
| 1233 | u8 key_index); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1234 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1235 | err = nl80211_parse_key(info, &key); |
| 1236 | if (err) |
| 1237 | return err; |
| 1238 | |
| 1239 | if (key.idx < 0) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1240 | return -EINVAL; |
| 1241 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1242 | /* only support setting default key */ |
| 1243 | if (!key.def && !key.defmgmt) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1244 | return -EINVAL; |
| 1245 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1246 | rtnl_lock(); |
| 1247 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1248 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1249 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1250 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1251 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1252 | if (key.def) |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1253 | func = rdev->ops->set_default_key; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1254 | else |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1255 | func = rdev->ops->set_default_mgmt_key; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1256 | |
| 1257 | if (!func) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1258 | err = -EOPNOTSUPP; |
| 1259 | goto out; |
| 1260 | } |
| 1261 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1262 | wdev_lock(dev->ieee80211_ptr); |
| 1263 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1264 | if (!err) |
| 1265 | err = func(&rdev->wiphy, dev, key.idx); |
| 1266 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1267 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1268 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1269 | if (func == rdev->ops->set_default_key) |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1270 | dev->ieee80211_ptr->wext.default_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1271 | else |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1272 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1273 | } |
| 1274 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1275 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1276 | |
| 1277 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1278 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1279 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1280 | |
| 1281 | unlock_rtnl: |
| 1282 | rtnl_unlock(); |
| 1283 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1284 | return err; |
| 1285 | } |
| 1286 | |
| 1287 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 1288 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1289 | struct cfg80211_registered_device *rdev; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1290 | int err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1291 | struct net_device *dev; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1292 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1293 | u8 *mac_addr = NULL; |
| 1294 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1295 | err = nl80211_parse_key(info, &key); |
| 1296 | if (err) |
| 1297 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1298 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1299 | if (!key.p.key) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1300 | return -EINVAL; |
| 1301 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1302 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1303 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1304 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1305 | rtnl_lock(); |
| 1306 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1307 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1308 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1309 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1310 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1311 | if (!rdev->ops->add_key) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1312 | err = -EOPNOTSUPP; |
| 1313 | goto out; |
| 1314 | } |
| 1315 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1316 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, mac_addr)) { |
| 1317 | err = -EINVAL; |
| 1318 | goto out; |
| 1319 | } |
| 1320 | |
| 1321 | wdev_lock(dev->ieee80211_ptr); |
| 1322 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1323 | if (!err) |
| 1324 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, |
| 1325 | mac_addr, &key.p); |
| 1326 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1327 | |
| 1328 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1329 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1330 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1331 | unlock_rtnl: |
| 1332 | rtnl_unlock(); |
| 1333 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1334 | return err; |
| 1335 | } |
| 1336 | |
| 1337 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1338 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1339 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1340 | int err; |
| 1341 | struct net_device *dev; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1342 | u8 *mac_addr = NULL; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1343 | struct key_parse key; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1344 | |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1345 | err = nl80211_parse_key(info, &key); |
| 1346 | if (err) |
| 1347 | return err; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1348 | |
| 1349 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1350 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1351 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1352 | rtnl_lock(); |
| 1353 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1354 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1355 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1356 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1357 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1358 | if (!rdev->ops->del_key) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1359 | err = -EOPNOTSUPP; |
| 1360 | goto out; |
| 1361 | } |
| 1362 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1363 | wdev_lock(dev->ieee80211_ptr); |
| 1364 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
| 1365 | if (!err) |
| 1366 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1367 | |
Johannes Berg | 3d23e34 | 2009-09-29 23:27:28 +0200 | [diff] [blame] | 1368 | #ifdef CONFIG_CFG80211_WEXT |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1369 | if (!err) { |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1370 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1371 | dev->ieee80211_ptr->wext.default_key = -1; |
Johannes Berg | b9454e8 | 2009-07-08 13:29:08 +0200 | [diff] [blame] | 1372 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1373 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
| 1374 | } |
| 1375 | #endif |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 1376 | wdev_unlock(dev->ieee80211_ptr); |
Johannes Berg | 0864512 | 2009-05-11 13:54:58 +0200 | [diff] [blame] | 1377 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1378 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1379 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1380 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1381 | |
| 1382 | unlock_rtnl: |
| 1383 | rtnl_unlock(); |
| 1384 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1385 | return err; |
| 1386 | } |
| 1387 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1388 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1389 | { |
| 1390 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1391 | struct beacon_parameters *info); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1392 | struct cfg80211_registered_device *rdev; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1393 | int err; |
| 1394 | struct net_device *dev; |
| 1395 | struct beacon_parameters params; |
| 1396 | int haveinfo = 0; |
| 1397 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1398 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1399 | return -EINVAL; |
| 1400 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1401 | rtnl_lock(); |
| 1402 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1403 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1404 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1405 | goto unlock_rtnl; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1406 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1407 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 1408 | err = -EOPNOTSUPP; |
| 1409 | goto out; |
| 1410 | } |
| 1411 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1412 | switch (info->genlhdr->cmd) { |
| 1413 | case NL80211_CMD_NEW_BEACON: |
| 1414 | /* these are required for NEW_BEACON */ |
| 1415 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 1416 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 1417 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1418 | err = -EINVAL; |
| 1419 | goto out; |
| 1420 | } |
| 1421 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1422 | call = rdev->ops->add_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1423 | break; |
| 1424 | case NL80211_CMD_SET_BEACON: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1425 | call = rdev->ops->set_beacon; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1426 | break; |
| 1427 | default: |
| 1428 | WARN_ON(1); |
| 1429 | err = -EOPNOTSUPP; |
| 1430 | goto out; |
| 1431 | } |
| 1432 | |
| 1433 | if (!call) { |
| 1434 | err = -EOPNOTSUPP; |
| 1435 | goto out; |
| 1436 | } |
| 1437 | |
| 1438 | memset(¶ms, 0, sizeof(params)); |
| 1439 | |
| 1440 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 1441 | params.interval = |
| 1442 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1443 | haveinfo = 1; |
| 1444 | } |
| 1445 | |
| 1446 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 1447 | params.dtim_period = |
| 1448 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1449 | haveinfo = 1; |
| 1450 | } |
| 1451 | |
| 1452 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1453 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1454 | params.head_len = |
| 1455 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1456 | haveinfo = 1; |
| 1457 | } |
| 1458 | |
| 1459 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 1460 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1461 | params.tail_len = |
| 1462 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1463 | haveinfo = 1; |
| 1464 | } |
| 1465 | |
| 1466 | if (!haveinfo) { |
| 1467 | err = -EINVAL; |
| 1468 | goto out; |
| 1469 | } |
| 1470 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1471 | err = call(&rdev->wiphy, dev, ¶ms); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1472 | |
| 1473 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1474 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1475 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1476 | unlock_rtnl: |
| 1477 | rtnl_unlock(); |
| 1478 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1479 | return err; |
| 1480 | } |
| 1481 | |
| 1482 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1483 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1484 | struct cfg80211_registered_device *rdev; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1485 | int err; |
| 1486 | struct net_device *dev; |
| 1487 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1488 | rtnl_lock(); |
| 1489 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1490 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1491 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1492 | goto unlock_rtnl; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1493 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1494 | if (!rdev->ops->del_beacon) { |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1495 | err = -EOPNOTSUPP; |
| 1496 | goto out; |
| 1497 | } |
| 1498 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1499 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 1500 | err = -EOPNOTSUPP; |
| 1501 | goto out; |
| 1502 | } |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1503 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1504 | |
| 1505 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1506 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1507 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1508 | unlock_rtnl: |
| 1509 | rtnl_unlock(); |
| 1510 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1511 | return err; |
| 1512 | } |
| 1513 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1514 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 1515 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 1516 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 1517 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
Jouni Malinen | 0e46724 | 2009-05-11 21:57:55 +0300 | [diff] [blame] | 1518 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1519 | }; |
| 1520 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1521 | static int parse_station_flags(struct genl_info *info, |
| 1522 | struct station_parameters *params) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1523 | { |
| 1524 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1525 | struct nlattr *nla; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1526 | int flag; |
| 1527 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1528 | /* |
| 1529 | * Try parsing the new attribute first so userspace |
| 1530 | * can specify both for older kernels. |
| 1531 | */ |
| 1532 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; |
| 1533 | if (nla) { |
| 1534 | struct nl80211_sta_flag_update *sta_flags; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1535 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1536 | sta_flags = nla_data(nla); |
| 1537 | params->sta_flags_mask = sta_flags->mask; |
| 1538 | params->sta_flags_set = sta_flags->set; |
| 1539 | if ((params->sta_flags_mask | |
| 1540 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) |
| 1541 | return -EINVAL; |
| 1542 | return 0; |
| 1543 | } |
| 1544 | |
| 1545 | /* if present, parse the old attribute */ |
| 1546 | |
| 1547 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1548 | if (!nla) |
| 1549 | return 0; |
| 1550 | |
| 1551 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 1552 | nla, sta_flags_policy)) |
| 1553 | return -EINVAL; |
| 1554 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1555 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
| 1556 | params->sta_flags_mask &= ~1; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1557 | |
| 1558 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 1559 | if (flags[flag]) |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1560 | params->sta_flags_set |= (1<<flag); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1561 | |
| 1562 | return 0; |
| 1563 | } |
| 1564 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1565 | static u16 nl80211_calculate_bitrate(struct rate_info *rate) |
| 1566 | { |
| 1567 | int modulation, streams, bitrate; |
| 1568 | |
| 1569 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) |
| 1570 | return rate->legacy; |
| 1571 | |
| 1572 | /* the formula below does only work for MCS values smaller than 32 */ |
| 1573 | if (rate->mcs >= 32) |
| 1574 | return 0; |
| 1575 | |
| 1576 | modulation = rate->mcs & 7; |
| 1577 | streams = (rate->mcs >> 3) + 1; |
| 1578 | |
| 1579 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? |
| 1580 | 13500000 : 6500000; |
| 1581 | |
| 1582 | if (modulation < 4) |
| 1583 | bitrate *= (modulation + 1); |
| 1584 | else if (modulation == 4) |
| 1585 | bitrate *= (modulation + 2); |
| 1586 | else |
| 1587 | bitrate *= (modulation + 3); |
| 1588 | |
| 1589 | bitrate *= streams; |
| 1590 | |
| 1591 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1592 | bitrate = (bitrate / 9) * 10; |
| 1593 | |
| 1594 | /* do NOT round down here */ |
| 1595 | return (bitrate + 50000) / 100000; |
| 1596 | } |
| 1597 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1598 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 1599 | int flags, struct net_device *dev, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1600 | u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1601 | { |
| 1602 | void *hdr; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1603 | struct nlattr *sinfoattr, *txrate; |
| 1604 | u16 bitrate; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1605 | |
| 1606 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1607 | if (!hdr) |
| 1608 | return -1; |
| 1609 | |
| 1610 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1611 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1612 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1613 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
| 1614 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1615 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 1616 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1617 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1618 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 1619 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 1620 | sinfo->inactive_time); |
| 1621 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 1622 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 1623 | sinfo->rx_bytes); |
| 1624 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 1625 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 1626 | sinfo->tx_bytes); |
| 1627 | if (sinfo->filled & STATION_INFO_LLID) |
| 1628 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 1629 | sinfo->llid); |
| 1630 | if (sinfo->filled & STATION_INFO_PLID) |
| 1631 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 1632 | sinfo->plid); |
| 1633 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 1634 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 1635 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1636 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 1637 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 1638 | sinfo->signal); |
| 1639 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
| 1640 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); |
| 1641 | if (!txrate) |
| 1642 | goto nla_put_failure; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1643 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1644 | /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 1645 | bitrate = nl80211_calculate_bitrate(&sinfo->txrate); |
| 1646 | if (bitrate > 0) |
| 1647 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 1648 | |
| 1649 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
| 1650 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, |
| 1651 | sinfo->txrate.mcs); |
| 1652 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 1653 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 1654 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1655 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 1656 | |
| 1657 | nla_nest_end(msg, txrate); |
| 1658 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 1659 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 1660 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 1661 | sinfo->rx_packets); |
| 1662 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 1663 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 1664 | sinfo->tx_packets); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1665 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1666 | |
| 1667 | return genlmsg_end(msg, hdr); |
| 1668 | |
| 1669 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1670 | genlmsg_cancel(msg, hdr); |
| 1671 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1672 | } |
| 1673 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1674 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1675 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1676 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1677 | struct station_info sinfo; |
| 1678 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1679 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1680 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1681 | int ifidx = cb->args[0]; |
| 1682 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1683 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1684 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1685 | if (!ifidx) { |
| 1686 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1687 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1688 | nl80211_policy); |
| 1689 | if (err) |
| 1690 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1691 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1692 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1693 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1694 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1695 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1696 | if (!ifidx) |
| 1697 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1698 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1699 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1700 | rtnl_lock(); |
| 1701 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1702 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1703 | if (!netdev) { |
| 1704 | err = -ENODEV; |
| 1705 | goto out_rtnl; |
| 1706 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1707 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1708 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1709 | if (IS_ERR(dev)) { |
| 1710 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1711 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1715 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1716 | goto out_err; |
| 1717 | } |
| 1718 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1719 | while (1) { |
| 1720 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 1721 | mac_addr, &sinfo); |
| 1722 | if (err == -ENOENT) |
| 1723 | break; |
| 1724 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1725 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1726 | |
| 1727 | if (nl80211_send_station(skb, |
| 1728 | NETLINK_CB(cb->skb).pid, |
| 1729 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1730 | netdev, mac_addr, |
| 1731 | &sinfo) < 0) |
| 1732 | goto out; |
| 1733 | |
| 1734 | sta_idx++; |
| 1735 | } |
| 1736 | |
| 1737 | |
| 1738 | out: |
| 1739 | cb->args[1] = sta_idx; |
| 1740 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1741 | out_err: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 1742 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1743 | out_rtnl: |
| 1744 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1745 | |
| 1746 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1747 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1748 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1749 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 1750 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1751 | struct cfg80211_registered_device *rdev; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1752 | int err; |
| 1753 | struct net_device *dev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1754 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1755 | struct sk_buff *msg; |
| 1756 | u8 *mac_addr = NULL; |
| 1757 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1758 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1759 | |
| 1760 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1761 | return -EINVAL; |
| 1762 | |
| 1763 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1764 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1765 | rtnl_lock(); |
| 1766 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1767 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1768 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1769 | goto out_rtnl; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1770 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1771 | if (!rdev->ops->get_station) { |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1772 | err = -EOPNOTSUPP; |
| 1773 | goto out; |
| 1774 | } |
| 1775 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1776 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1777 | if (err) |
| 1778 | goto out; |
| 1779 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 1780 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1781 | if (!msg) |
| 1782 | goto out; |
| 1783 | |
| 1784 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1785 | dev, mac_addr, &sinfo) < 0) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1786 | goto out_free; |
| 1787 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 1788 | err = genlmsg_reply(msg, info); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1789 | goto out; |
| 1790 | |
| 1791 | out_free: |
| 1792 | nlmsg_free(msg); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1793 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1794 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1795 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1796 | out_rtnl: |
| 1797 | rtnl_unlock(); |
| 1798 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1799 | return err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1800 | } |
| 1801 | |
| 1802 | /* |
| 1803 | * Get vlan interface making sure it is on the right wiphy. |
| 1804 | */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1805 | static int get_vlan(struct genl_info *info, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1806 | struct cfg80211_registered_device *rdev, |
| 1807 | struct net_device **vlan) |
| 1808 | { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1809 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1810 | *vlan = NULL; |
| 1811 | |
| 1812 | if (vlanattr) { |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1813 | *vlan = dev_get_by_index(genl_info_net(info), |
| 1814 | nla_get_u32(vlanattr)); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1815 | if (!*vlan) |
| 1816 | return -ENODEV; |
| 1817 | if (!(*vlan)->ieee80211_ptr) |
| 1818 | return -EINVAL; |
| 1819 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 1820 | return -EINVAL; |
| 1821 | } |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
| 1825 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 1826 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1827 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1828 | int err; |
| 1829 | struct net_device *dev; |
| 1830 | struct station_parameters params; |
| 1831 | u8 *mac_addr = NULL; |
| 1832 | |
| 1833 | memset(¶ms, 0, sizeof(params)); |
| 1834 | |
| 1835 | params.listen_interval = -1; |
| 1836 | |
| 1837 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 1838 | return -EINVAL; |
| 1839 | |
| 1840 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1841 | return -EINVAL; |
| 1842 | |
| 1843 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1844 | |
| 1845 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 1846 | params.supported_rates = |
| 1847 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1848 | params.supported_rates_len = |
| 1849 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1850 | } |
| 1851 | |
| 1852 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1853 | params.listen_interval = |
| 1854 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 1855 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1856 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1857 | params.ht_capa = |
| 1858 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 1859 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1860 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1861 | return -EINVAL; |
| 1862 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1863 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 1864 | params.plink_action = |
| 1865 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 1866 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1867 | rtnl_lock(); |
| 1868 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1869 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1870 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1871 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1872 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1873 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 1874 | if (err) |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 1875 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 1876 | |
| 1877 | /* validate settings */ |
| 1878 | err = 0; |
| 1879 | |
| 1880 | switch (dev->ieee80211_ptr->iftype) { |
| 1881 | case NL80211_IFTYPE_AP: |
| 1882 | case NL80211_IFTYPE_AP_VLAN: |
| 1883 | /* disallow mesh-specific things */ |
| 1884 | if (params.plink_action) |
| 1885 | err = -EINVAL; |
| 1886 | break; |
| 1887 | case NL80211_IFTYPE_STATION: |
| 1888 | /* disallow everything but AUTHORIZED flag */ |
| 1889 | if (params.plink_action) |
| 1890 | err = -EINVAL; |
| 1891 | if (params.vlan) |
| 1892 | err = -EINVAL; |
| 1893 | if (params.supported_rates) |
| 1894 | err = -EINVAL; |
| 1895 | if (params.ht_capa) |
| 1896 | err = -EINVAL; |
| 1897 | if (params.listen_interval >= 0) |
| 1898 | err = -EINVAL; |
| 1899 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 1900 | err = -EINVAL; |
| 1901 | break; |
| 1902 | case NL80211_IFTYPE_MESH_POINT: |
| 1903 | /* disallow things mesh doesn't support */ |
| 1904 | if (params.vlan) |
| 1905 | err = -EINVAL; |
| 1906 | if (params.ht_capa) |
| 1907 | err = -EINVAL; |
| 1908 | if (params.listen_interval >= 0) |
| 1909 | err = -EINVAL; |
| 1910 | if (params.supported_rates) |
| 1911 | err = -EINVAL; |
| 1912 | if (params.sta_flags_mask) |
| 1913 | err = -EINVAL; |
| 1914 | break; |
| 1915 | default: |
| 1916 | err = -EINVAL; |
Johannes Berg | 034d655 | 2009-05-27 10:35:29 +0200 | [diff] [blame] | 1917 | } |
| 1918 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1919 | if (err) |
| 1920 | goto out; |
| 1921 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1922 | if (!rdev->ops->change_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1923 | err = -EOPNOTSUPP; |
| 1924 | goto out; |
| 1925 | } |
| 1926 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1927 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1928 | |
| 1929 | out: |
| 1930 | if (params.vlan) |
| 1931 | dev_put(params.vlan); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1932 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1933 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1934 | out_rtnl: |
| 1935 | rtnl_unlock(); |
| 1936 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1937 | return err; |
| 1938 | } |
| 1939 | |
| 1940 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 1941 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 1942 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1943 | int err; |
| 1944 | struct net_device *dev; |
| 1945 | struct station_parameters params; |
| 1946 | u8 *mac_addr = NULL; |
| 1947 | |
| 1948 | memset(¶ms, 0, sizeof(params)); |
| 1949 | |
| 1950 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1951 | return -EINVAL; |
| 1952 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1953 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1954 | return -EINVAL; |
| 1955 | |
| 1956 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 1957 | return -EINVAL; |
| 1958 | |
| 1959 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1960 | params.supported_rates = |
| 1961 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1962 | params.supported_rates_len = |
| 1963 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1964 | params.listen_interval = |
| 1965 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 1966 | |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 1967 | if (info->attrs[NL80211_ATTR_STA_AID]) { |
| 1968 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
| 1969 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
| 1970 | return -EINVAL; |
| 1971 | } |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 1972 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1973 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1974 | params.ht_capa = |
| 1975 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1976 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1977 | if (parse_station_flags(info, ¶ms)) |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1978 | return -EINVAL; |
| 1979 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1980 | rtnl_lock(); |
| 1981 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1982 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1983 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1984 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1985 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 1986 | err = get_vlan(info, rdev, ¶ms.vlan); |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 1987 | if (err) |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 1988 | goto out; |
Johannes Berg | a97f442 | 2009-06-18 17:23:43 +0200 | [diff] [blame] | 1989 | |
| 1990 | /* validate settings */ |
| 1991 | err = 0; |
| 1992 | |
| 1993 | switch (dev->ieee80211_ptr->iftype) { |
| 1994 | case NL80211_IFTYPE_AP: |
| 1995 | case NL80211_IFTYPE_AP_VLAN: |
| 1996 | /* all ok but must have AID */ |
| 1997 | if (!params.aid) |
| 1998 | err = -EINVAL; |
| 1999 | break; |
| 2000 | case NL80211_IFTYPE_MESH_POINT: |
| 2001 | /* disallow things mesh doesn't support */ |
| 2002 | if (params.vlan) |
| 2003 | err = -EINVAL; |
| 2004 | if (params.aid) |
| 2005 | err = -EINVAL; |
| 2006 | if (params.ht_capa) |
| 2007 | err = -EINVAL; |
| 2008 | if (params.listen_interval >= 0) |
| 2009 | err = -EINVAL; |
| 2010 | if (params.supported_rates) |
| 2011 | err = -EINVAL; |
| 2012 | if (params.sta_flags_mask) |
| 2013 | err = -EINVAL; |
| 2014 | break; |
| 2015 | default: |
| 2016 | err = -EINVAL; |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2017 | } |
| 2018 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2019 | if (err) |
| 2020 | goto out; |
| 2021 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2022 | if (!rdev->ops->add_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2023 | err = -EOPNOTSUPP; |
| 2024 | goto out; |
| 2025 | } |
| 2026 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2027 | if (!netif_running(dev)) { |
| 2028 | err = -ENETDOWN; |
| 2029 | goto out; |
| 2030 | } |
| 2031 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2032 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2033 | |
| 2034 | out: |
| 2035 | if (params.vlan) |
| 2036 | dev_put(params.vlan); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2037 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2038 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2039 | out_rtnl: |
| 2040 | rtnl_unlock(); |
| 2041 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2042 | return err; |
| 2043 | } |
| 2044 | |
| 2045 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 2046 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2047 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2048 | int err; |
| 2049 | struct net_device *dev; |
| 2050 | u8 *mac_addr = NULL; |
| 2051 | |
| 2052 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2053 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2054 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2055 | rtnl_lock(); |
| 2056 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2057 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2058 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2059 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2060 | |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2061 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
Andrey Yurovsky | 155cc9e | 2009-06-16 11:31:04 -0700 | [diff] [blame] | 2062 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
| 2063 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
Johannes Berg | e80cf85 | 2009-05-11 14:43:13 +0200 | [diff] [blame] | 2064 | err = -EINVAL; |
| 2065 | goto out; |
| 2066 | } |
| 2067 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2068 | if (!rdev->ops->del_station) { |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2069 | err = -EOPNOTSUPP; |
| 2070 | goto out; |
| 2071 | } |
| 2072 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2073 | err = rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2074 | |
| 2075 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2076 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2077 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2078 | out_rtnl: |
| 2079 | rtnl_unlock(); |
| 2080 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2081 | return err; |
| 2082 | } |
| 2083 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2084 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 2085 | int flags, struct net_device *dev, |
| 2086 | u8 *dst, u8 *next_hop, |
| 2087 | struct mpath_info *pinfo) |
| 2088 | { |
| 2089 | void *hdr; |
| 2090 | struct nlattr *pinfoattr; |
| 2091 | |
| 2092 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 2093 | if (!hdr) |
| 2094 | return -1; |
| 2095 | |
| 2096 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2097 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 2098 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 2099 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 2100 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
| 2101 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2102 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 2103 | if (!pinfoattr) |
| 2104 | goto nla_put_failure; |
| 2105 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 2106 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 2107 | pinfo->frame_qlen); |
| 2108 | if (pinfo->filled & MPATH_INFO_DSN) |
| 2109 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN, |
| 2110 | pinfo->dsn); |
| 2111 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 2112 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 2113 | pinfo->metric); |
| 2114 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 2115 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 2116 | pinfo->exptime); |
| 2117 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 2118 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 2119 | pinfo->flags); |
| 2120 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 2121 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 2122 | pinfo->discovery_timeout); |
| 2123 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 2124 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 2125 | pinfo->discovery_retries); |
| 2126 | |
| 2127 | nla_nest_end(msg, pinfoattr); |
| 2128 | |
| 2129 | return genlmsg_end(msg, hdr); |
| 2130 | |
| 2131 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 2132 | genlmsg_cancel(msg, hdr); |
| 2133 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2137 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2138 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2139 | struct mpath_info pinfo; |
| 2140 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2141 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2142 | u8 dst[ETH_ALEN]; |
| 2143 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2144 | int ifidx = cb->args[0]; |
| 2145 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2146 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2147 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2148 | if (!ifidx) { |
| 2149 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2150 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 2151 | nl80211_policy); |
| 2152 | if (err) |
| 2153 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2154 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2155 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 2156 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2157 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2158 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 2159 | if (!ifidx) |
| 2160 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2161 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2162 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2163 | rtnl_lock(); |
| 2164 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2165 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2166 | if (!netdev) { |
| 2167 | err = -ENODEV; |
| 2168 | goto out_rtnl; |
| 2169 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2170 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2171 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2172 | if (IS_ERR(dev)) { |
| 2173 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2174 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2178 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2179 | goto out_err; |
| 2180 | } |
| 2181 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2182 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2183 | err = -EOPNOTSUPP; |
Roel Kluin | 0448b5f | 2009-08-22 21:15:49 +0200 | [diff] [blame] | 2184 | goto out_err; |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2185 | } |
| 2186 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2187 | while (1) { |
| 2188 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 2189 | dst, next_hop, &pinfo); |
| 2190 | if (err == -ENOENT) |
| 2191 | break; |
| 2192 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2193 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2194 | |
| 2195 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 2196 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2197 | netdev, dst, next_hop, |
| 2198 | &pinfo) < 0) |
| 2199 | goto out; |
| 2200 | |
| 2201 | path_idx++; |
| 2202 | } |
| 2203 | |
| 2204 | |
| 2205 | out: |
| 2206 | cb->args[1] = path_idx; |
| 2207 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2208 | out_err: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 2209 | cfg80211_unlock_rdev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2210 | out_rtnl: |
| 2211 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2212 | |
| 2213 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2214 | } |
| 2215 | |
| 2216 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2217 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2218 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2219 | int err; |
| 2220 | struct net_device *dev; |
| 2221 | struct mpath_info pinfo; |
| 2222 | struct sk_buff *msg; |
| 2223 | u8 *dst = NULL; |
| 2224 | u8 next_hop[ETH_ALEN]; |
| 2225 | |
| 2226 | memset(&pinfo, 0, sizeof(pinfo)); |
| 2227 | |
| 2228 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2229 | return -EINVAL; |
| 2230 | |
| 2231 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2232 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2233 | rtnl_lock(); |
| 2234 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2235 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2236 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2237 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2238 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2239 | if (!rdev->ops->get_mpath) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2240 | err = -EOPNOTSUPP; |
| 2241 | goto out; |
| 2242 | } |
| 2243 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2244 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2245 | err = -EOPNOTSUPP; |
| 2246 | goto out; |
| 2247 | } |
| 2248 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2249 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2250 | if (err) |
| 2251 | goto out; |
| 2252 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2253 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2254 | if (!msg) |
| 2255 | goto out; |
| 2256 | |
| 2257 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
| 2258 | dev, dst, next_hop, &pinfo) < 0) |
| 2259 | goto out_free; |
| 2260 | |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2261 | err = genlmsg_reply(msg, info); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2262 | goto out; |
| 2263 | |
| 2264 | out_free: |
| 2265 | nlmsg_free(msg); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2266 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2267 | cfg80211_unlock_rdev(rdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2268 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2269 | out_rtnl: |
| 2270 | rtnl_unlock(); |
| 2271 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2272 | return err; |
| 2273 | } |
| 2274 | |
| 2275 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2276 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2277 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2278 | int err; |
| 2279 | struct net_device *dev; |
| 2280 | u8 *dst = NULL; |
| 2281 | u8 *next_hop = NULL; |
| 2282 | |
| 2283 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2284 | return -EINVAL; |
| 2285 | |
| 2286 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2287 | return -EINVAL; |
| 2288 | |
| 2289 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2290 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2291 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2292 | rtnl_lock(); |
| 2293 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2294 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2295 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2296 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2297 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2298 | if (!rdev->ops->change_mpath) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2299 | err = -EOPNOTSUPP; |
| 2300 | goto out; |
| 2301 | } |
| 2302 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2303 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2304 | err = -EOPNOTSUPP; |
| 2305 | goto out; |
| 2306 | } |
| 2307 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2308 | if (!netif_running(dev)) { |
| 2309 | err = -ENETDOWN; |
| 2310 | goto out; |
| 2311 | } |
| 2312 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2313 | err = rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2314 | |
| 2315 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2316 | cfg80211_unlock_rdev(rdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2317 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2318 | out_rtnl: |
| 2319 | rtnl_unlock(); |
| 2320 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2321 | return err; |
| 2322 | } |
| 2323 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2324 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2325 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2326 | int err; |
| 2327 | struct net_device *dev; |
| 2328 | u8 *dst = NULL; |
| 2329 | u8 *next_hop = NULL; |
| 2330 | |
| 2331 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2332 | return -EINVAL; |
| 2333 | |
| 2334 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 2335 | return -EINVAL; |
| 2336 | |
| 2337 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2338 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 2339 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2340 | rtnl_lock(); |
| 2341 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2342 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2343 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2344 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2345 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2346 | if (!rdev->ops->add_mpath) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2347 | err = -EOPNOTSUPP; |
| 2348 | goto out; |
| 2349 | } |
| 2350 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2351 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 2352 | err = -EOPNOTSUPP; |
| 2353 | goto out; |
| 2354 | } |
| 2355 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2356 | if (!netif_running(dev)) { |
| 2357 | err = -ENETDOWN; |
| 2358 | goto out; |
| 2359 | } |
| 2360 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2361 | err = rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2362 | |
| 2363 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2364 | cfg80211_unlock_rdev(rdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2365 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2366 | out_rtnl: |
| 2367 | rtnl_unlock(); |
| 2368 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2369 | return err; |
| 2370 | } |
| 2371 | |
| 2372 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 2373 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2374 | struct cfg80211_registered_device *rdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2375 | int err; |
| 2376 | struct net_device *dev; |
| 2377 | u8 *dst = NULL; |
| 2378 | |
| 2379 | if (info->attrs[NL80211_ATTR_MAC]) |
| 2380 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2381 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2382 | rtnl_lock(); |
| 2383 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2384 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2385 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2386 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2387 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2388 | if (!rdev->ops->del_mpath) { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2389 | err = -EOPNOTSUPP; |
| 2390 | goto out; |
| 2391 | } |
| 2392 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2393 | err = rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2394 | |
| 2395 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2396 | cfg80211_unlock_rdev(rdev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2397 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2398 | out_rtnl: |
| 2399 | rtnl_unlock(); |
| 2400 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2401 | return err; |
| 2402 | } |
| 2403 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2404 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2405 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2406 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2407 | int err; |
| 2408 | struct net_device *dev; |
| 2409 | struct bss_parameters params; |
| 2410 | |
| 2411 | memset(¶ms, 0, sizeof(params)); |
| 2412 | /* default to not changing parameters */ |
| 2413 | params.use_cts_prot = -1; |
| 2414 | params.use_short_preamble = -1; |
| 2415 | params.use_short_slot_time = -1; |
| 2416 | |
| 2417 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2418 | params.use_cts_prot = |
| 2419 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2420 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2421 | params.use_short_preamble = |
| 2422 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2423 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2424 | params.use_short_slot_time = |
| 2425 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2426 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2427 | params.basic_rates = |
| 2428 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2429 | params.basic_rates_len = |
| 2430 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2431 | } |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2432 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2433 | rtnl_lock(); |
| 2434 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2435 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2436 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2437 | goto out_rtnl; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2438 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2439 | if (!rdev->ops->change_bss) { |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2440 | err = -EOPNOTSUPP; |
| 2441 | goto out; |
| 2442 | } |
| 2443 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2444 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 2445 | err = -EOPNOTSUPP; |
| 2446 | goto out; |
| 2447 | } |
| 2448 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2449 | err = rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2450 | |
| 2451 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2452 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2453 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2454 | out_rtnl: |
| 2455 | rtnl_unlock(); |
| 2456 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2457 | return err; |
| 2458 | } |
| 2459 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2460 | static const struct nla_policy |
| 2461 | reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 2462 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2463 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2464 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2465 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2466 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2467 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2468 | }; |
| 2469 | |
| 2470 | static int parse_reg_rule(struct nlattr *tb[], |
| 2471 | struct ieee80211_reg_rule *reg_rule) |
| 2472 | { |
| 2473 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2474 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2475 | |
| 2476 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2477 | return -EINVAL; |
| 2478 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2479 | return -EINVAL; |
| 2480 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2481 | return -EINVAL; |
| 2482 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2483 | return -EINVAL; |
| 2484 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2485 | return -EINVAL; |
| 2486 | |
| 2487 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2488 | |
| 2489 | freq_range->start_freq_khz = |
| 2490 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2491 | freq_range->end_freq_khz = |
| 2492 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2493 | freq_range->max_bandwidth_khz = |
| 2494 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2495 | |
| 2496 | power_rule->max_eirp = |
| 2497 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2498 | |
| 2499 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2500 | power_rule->max_antenna_gain = |
| 2501 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2502 | |
| 2503 | return 0; |
| 2504 | } |
| 2505 | |
| 2506 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2507 | { |
| 2508 | int r; |
| 2509 | char *data = NULL; |
| 2510 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2511 | /* |
| 2512 | * You should only get this when cfg80211 hasn't yet initialized |
| 2513 | * completely when built-in to the kernel right between the time |
| 2514 | * window between nl80211_init() and regulatory_init(), if that is |
| 2515 | * even possible. |
| 2516 | */ |
| 2517 | mutex_lock(&cfg80211_mutex); |
| 2518 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2519 | mutex_unlock(&cfg80211_mutex); |
| 2520 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2521 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2522 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2523 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2524 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2525 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2526 | |
| 2527 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2528 | |
| 2529 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 2530 | /* We ignore world regdom requests with the old regdom setup */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2531 | if (is_world_regdom(data)) |
| 2532 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2533 | #endif |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2534 | |
| 2535 | r = regulatory_hint_user(data); |
| 2536 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2537 | return r; |
| 2538 | } |
| 2539 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2540 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
| 2541 | struct genl_info *info) |
| 2542 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2543 | struct cfg80211_registered_device *rdev; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2544 | struct mesh_config cur_params; |
| 2545 | int err; |
| 2546 | struct net_device *dev; |
| 2547 | void *hdr; |
| 2548 | struct nlattr *pinfoattr; |
| 2549 | struct sk_buff *msg; |
| 2550 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2551 | rtnl_lock(); |
| 2552 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2553 | /* Look up our device */ |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2554 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2555 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2556 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2557 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2558 | if (!rdev->ops->get_mesh_params) { |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2559 | err = -EOPNOTSUPP; |
| 2560 | goto out; |
| 2561 | } |
| 2562 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2563 | /* Get the mesh params */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2564 | err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2565 | if (err) |
| 2566 | goto out; |
| 2567 | |
| 2568 | /* Draw up a netlink message to send back */ |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2569 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2570 | if (!msg) { |
| 2571 | err = -ENOBUFS; |
| 2572 | goto out; |
| 2573 | } |
| 2574 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2575 | NL80211_CMD_GET_MESH_PARAMS); |
| 2576 | if (!hdr) |
| 2577 | goto nla_put_failure; |
| 2578 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); |
| 2579 | if (!pinfoattr) |
| 2580 | goto nla_put_failure; |
| 2581 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2582 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2583 | cur_params.dot11MeshRetryTimeout); |
| 2584 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2585 | cur_params.dot11MeshConfirmTimeout); |
| 2586 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2587 | cur_params.dot11MeshHoldingTimeout); |
| 2588 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2589 | cur_params.dot11MeshMaxPeerLinks); |
| 2590 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2591 | cur_params.dot11MeshMaxRetries); |
| 2592 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2593 | cur_params.dot11MeshTTL); |
| 2594 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2595 | cur_params.auto_open_plinks); |
| 2596 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2597 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2598 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2599 | cur_params.path_refresh_time); |
| 2600 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2601 | cur_params.min_discovery_timeout); |
| 2602 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2603 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2604 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2605 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2606 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2607 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
| 2608 | nla_nest_end(msg, pinfoattr); |
| 2609 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2610 | err = genlmsg_reply(msg, info); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2611 | goto out; |
| 2612 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2613 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2614 | genlmsg_cancel(msg, hdr); |
| 2615 | err = -EMSGSIZE; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2616 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2617 | /* Cleanup */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2618 | cfg80211_unlock_rdev(rdev); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2619 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2620 | out_rtnl: |
| 2621 | rtnl_unlock(); |
| 2622 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2623 | return err; |
| 2624 | } |
| 2625 | |
| 2626 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2627 | do {\ |
| 2628 | if (table[attr_num]) {\ |
| 2629 | cfg.param = nla_fn(table[attr_num]); \ |
| 2630 | mask |= (1 << (attr_num - 1)); \ |
| 2631 | } \ |
| 2632 | } while (0);\ |
| 2633 | |
| 2634 | static struct nla_policy |
| 2635 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = { |
| 2636 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2637 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2638 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2639 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2640 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2641 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
| 2642 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2643 | |
| 2644 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2645 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2646 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2647 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2648 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2649 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2650 | }; |
| 2651 | |
| 2652 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) |
| 2653 | { |
| 2654 | int err; |
| 2655 | u32 mask; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2656 | struct cfg80211_registered_device *rdev; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2657 | struct net_device *dev; |
| 2658 | struct mesh_config cfg; |
| 2659 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
| 2660 | struct nlattr *parent_attr; |
| 2661 | |
| 2662 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; |
| 2663 | if (!parent_attr) |
| 2664 | return -EINVAL; |
| 2665 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
| 2666 | parent_attr, nl80211_meshconf_params_policy)) |
| 2667 | return -EINVAL; |
| 2668 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2669 | rtnl_lock(); |
| 2670 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2671 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2672 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2673 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2674 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2675 | if (!rdev->ops->set_mesh_params) { |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2676 | err = -EOPNOTSUPP; |
| 2677 | goto out; |
| 2678 | } |
| 2679 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2680 | /* This makes sure that there aren't more than 32 mesh config |
| 2681 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2682 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2683 | |
| 2684 | /* Fill in the params struct */ |
| 2685 | mask = 0; |
| 2686 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2687 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2688 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2689 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2690 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2691 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2692 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2693 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2694 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2695 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2696 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2697 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
| 2698 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2699 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2700 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2701 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2702 | nla_get_u8); |
| 2703 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2704 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2705 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2706 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2707 | nla_get_u16); |
| 2708 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2709 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2710 | nla_get_u32); |
| 2711 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2712 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2713 | nla_get_u16); |
| 2714 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2715 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2716 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2717 | nla_get_u16); |
| 2718 | |
| 2719 | /* Apply changes */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2720 | err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2721 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2722 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2723 | /* cleanup */ |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2724 | cfg80211_unlock_rdev(rdev); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2725 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2726 | out_rtnl: |
| 2727 | rtnl_unlock(); |
| 2728 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2729 | return err; |
| 2730 | } |
| 2731 | |
| 2732 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2733 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2734 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 2735 | { |
| 2736 | struct sk_buff *msg; |
| 2737 | void *hdr = NULL; |
| 2738 | struct nlattr *nl_reg_rules; |
| 2739 | unsigned int i; |
| 2740 | int err = -EINVAL; |
| 2741 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2742 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2743 | |
| 2744 | if (!cfg80211_regdomain) |
| 2745 | goto out; |
| 2746 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 2747 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2748 | if (!msg) { |
| 2749 | err = -ENOBUFS; |
| 2750 | goto out; |
| 2751 | } |
| 2752 | |
| 2753 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2754 | NL80211_CMD_GET_REG); |
| 2755 | if (!hdr) |
| 2756 | goto nla_put_failure; |
| 2757 | |
| 2758 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 2759 | cfg80211_regdomain->alpha2); |
| 2760 | |
| 2761 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 2762 | if (!nl_reg_rules) |
| 2763 | goto nla_put_failure; |
| 2764 | |
| 2765 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 2766 | struct nlattr *nl_reg_rule; |
| 2767 | const struct ieee80211_reg_rule *reg_rule; |
| 2768 | const struct ieee80211_freq_range *freq_range; |
| 2769 | const struct ieee80211_power_rule *power_rule; |
| 2770 | |
| 2771 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 2772 | freq_range = ®_rule->freq_range; |
| 2773 | power_rule = ®_rule->power_rule; |
| 2774 | |
| 2775 | nl_reg_rule = nla_nest_start(msg, i); |
| 2776 | if (!nl_reg_rule) |
| 2777 | goto nla_put_failure; |
| 2778 | |
| 2779 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 2780 | reg_rule->flags); |
| 2781 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 2782 | freq_range->start_freq_khz); |
| 2783 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 2784 | freq_range->end_freq_khz); |
| 2785 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 2786 | freq_range->max_bandwidth_khz); |
| 2787 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 2788 | power_rule->max_antenna_gain); |
| 2789 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 2790 | power_rule->max_eirp); |
| 2791 | |
| 2792 | nla_nest_end(msg, nl_reg_rule); |
| 2793 | } |
| 2794 | |
| 2795 | nla_nest_end(msg, nl_reg_rules); |
| 2796 | |
| 2797 | genlmsg_end(msg, hdr); |
Johannes Berg | 134e637 | 2009-07-10 09:51:34 +0000 | [diff] [blame] | 2798 | err = genlmsg_reply(msg, info); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2799 | goto out; |
| 2800 | |
| 2801 | nla_put_failure: |
| 2802 | genlmsg_cancel(msg, hdr); |
| 2803 | err = -EMSGSIZE; |
| 2804 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2805 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2806 | return err; |
| 2807 | } |
| 2808 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2809 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2810 | { |
| 2811 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 2812 | struct nlattr *nl_reg_rule; |
| 2813 | char *alpha2 = NULL; |
| 2814 | int rem_reg_rules = 0, r = 0; |
| 2815 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 2816 | struct ieee80211_regdomain *rd = NULL; |
| 2817 | |
| 2818 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2819 | return -EINVAL; |
| 2820 | |
| 2821 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 2822 | return -EINVAL; |
| 2823 | |
| 2824 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2825 | |
| 2826 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2827 | rem_reg_rules) { |
| 2828 | num_rules++; |
| 2829 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
Luis R. Rodriguez | 4776c6e | 2009-05-13 17:04:39 -0400 | [diff] [blame] | 2830 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2831 | } |
| 2832 | |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2833 | mutex_lock(&cfg80211_mutex); |
| 2834 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2835 | if (!reg_is_valid_request(alpha2)) { |
| 2836 | r = -EINVAL; |
| 2837 | goto bad_reg; |
| 2838 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2839 | |
| 2840 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 2841 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 2842 | |
| 2843 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2844 | if (!rd) { |
| 2845 | r = -ENOMEM; |
| 2846 | goto bad_reg; |
| 2847 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2848 | |
| 2849 | rd->n_reg_rules = num_rules; |
| 2850 | rd->alpha2[0] = alpha2[0]; |
| 2851 | rd->alpha2[1] = alpha2[1]; |
| 2852 | |
| 2853 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2854 | rem_reg_rules) { |
| 2855 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 2856 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 2857 | reg_rule_policy); |
| 2858 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 2859 | if (r) |
| 2860 | goto bad_reg; |
| 2861 | |
| 2862 | rule_idx++; |
| 2863 | |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2864 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
| 2865 | r = -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2866 | goto bad_reg; |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2867 | } |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2868 | } |
| 2869 | |
| 2870 | BUG_ON(rule_idx != num_rules); |
| 2871 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2872 | r = set_regdom(rd); |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2873 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2874 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2875 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2876 | return r; |
| 2877 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2878 | bad_reg: |
Luis R. Rodriguez | 61405e9 | 2009-05-13 17:04:41 -0400 | [diff] [blame] | 2879 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2880 | kfree(rd); |
Luis R. Rodriguez | d0e18f8 | 2009-05-13 17:04:40 -0400 | [diff] [blame] | 2881 | return r; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2882 | } |
| 2883 | |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 2884 | static int validate_scan_freqs(struct nlattr *freqs) |
| 2885 | { |
| 2886 | struct nlattr *attr1, *attr2; |
| 2887 | int n_channels = 0, tmp1, tmp2; |
| 2888 | |
| 2889 | nla_for_each_nested(attr1, freqs, tmp1) { |
| 2890 | n_channels++; |
| 2891 | /* |
| 2892 | * Some hardware has a limited channel list for |
| 2893 | * scanning, and it is pretty much nonsensical |
| 2894 | * to scan for a channel twice, so disallow that |
| 2895 | * and don't require drivers to check that the |
| 2896 | * channel list they get isn't longer than what |
| 2897 | * they can scan, as long as they can scan all |
| 2898 | * the channels they registered at once. |
| 2899 | */ |
| 2900 | nla_for_each_nested(attr2, freqs, tmp2) |
| 2901 | if (attr1 != attr2 && |
| 2902 | nla_get_u32(attr1) == nla_get_u32(attr2)) |
| 2903 | return 0; |
| 2904 | } |
| 2905 | |
| 2906 | return n_channels; |
| 2907 | } |
| 2908 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2909 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 2910 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2911 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2912 | struct net_device *dev; |
| 2913 | struct cfg80211_scan_request *request; |
| 2914 | struct cfg80211_ssid *ssid; |
| 2915 | struct ieee80211_channel *channel; |
| 2916 | struct nlattr *attr; |
| 2917 | struct wiphy *wiphy; |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 2918 | int err, tmp, n_ssids = 0, n_channels, i; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2919 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2920 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2921 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2922 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2923 | return -EINVAL; |
| 2924 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2925 | rtnl_lock(); |
| 2926 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 2927 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2928 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2929 | goto out_rtnl; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2930 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2931 | wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2932 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2933 | if (!rdev->ops->scan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2934 | err = -EOPNOTSUPP; |
| 2935 | goto out; |
| 2936 | } |
| 2937 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2938 | if (!netif_running(dev)) { |
| 2939 | err = -ENETDOWN; |
| 2940 | goto out; |
| 2941 | } |
| 2942 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 2943 | if (rdev->scan_req) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2944 | err = -EBUSY; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2945 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 2949 | n_channels = validate_scan_freqs( |
| 2950 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2951 | if (!n_channels) { |
| 2952 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2953 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2954 | } |
| 2955 | } else { |
Johannes Berg | 83f5e2c | 2009-06-17 17:41:49 +0200 | [diff] [blame] | 2956 | n_channels = 0; |
| 2957 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2958 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 2959 | if (wiphy->bands[band]) |
| 2960 | n_channels += wiphy->bands[band]->n_channels; |
| 2961 | } |
| 2962 | |
| 2963 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 2964 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 2965 | n_ssids++; |
| 2966 | |
| 2967 | if (n_ssids > wiphy->max_scan_ssids) { |
| 2968 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2969 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2970 | } |
| 2971 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2972 | if (info->attrs[NL80211_ATTR_IE]) |
| 2973 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2974 | else |
| 2975 | ie_len = 0; |
| 2976 | |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 2977 | if (ie_len > wiphy->max_scan_ie_len) { |
| 2978 | err = -EINVAL; |
| 2979 | goto out; |
| 2980 | } |
| 2981 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2982 | request = kzalloc(sizeof(*request) |
| 2983 | + sizeof(*ssid) * n_ssids |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2984 | + sizeof(channel) * n_channels |
| 2985 | + ie_len, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2986 | if (!request) { |
| 2987 | err = -ENOMEM; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2988 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2989 | } |
| 2990 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2991 | if (n_ssids) |
Johannes Berg | 5ba6353 | 2009-08-07 17:54:07 +0200 | [diff] [blame] | 2992 | request->ssids = (void *)&request->channels[n_channels]; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2993 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2994 | if (ie_len) { |
| 2995 | if (request->ssids) |
| 2996 | request->ie = (void *)(request->ssids + n_ssids); |
| 2997 | else |
| 2998 | request->ie = (void *)(request->channels + n_channels); |
| 2999 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3000 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame^] | 3001 | i = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3002 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 3003 | /* user specified, bail out if channel not found */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3004 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame^] | 3005 | struct ieee80211_channel *chan; |
| 3006 | |
| 3007 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 3008 | |
| 3009 | if (!chan) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3010 | err = -EINVAL; |
| 3011 | goto out_free; |
| 3012 | } |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame^] | 3013 | |
| 3014 | /* ignore disabled channels */ |
| 3015 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3016 | continue; |
| 3017 | |
| 3018 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3019 | i++; |
| 3020 | } |
| 3021 | } else { |
| 3022 | /* all channels */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3023 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 3024 | int j; |
| 3025 | if (!wiphy->bands[band]) |
| 3026 | continue; |
| 3027 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame^] | 3028 | struct ieee80211_channel *chan; |
| 3029 | |
| 3030 | chan = &wiphy->bands[band]->channels[j]; |
| 3031 | |
| 3032 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 3033 | continue; |
| 3034 | |
| 3035 | request->channels[i] = chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3036 | i++; |
| 3037 | } |
| 3038 | } |
| 3039 | } |
| 3040 | |
Johannes Berg | 584991d | 2009-11-02 13:32:03 +0100 | [diff] [blame^] | 3041 | if (!i) { |
| 3042 | err = -EINVAL; |
| 3043 | goto out_free; |
| 3044 | } |
| 3045 | |
| 3046 | request->n_channels = i; |
| 3047 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3048 | i = 0; |
| 3049 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 3050 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 3051 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 3052 | err = -EINVAL; |
| 3053 | goto out_free; |
| 3054 | } |
| 3055 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 3056 | request->ssids[i].ssid_len = nla_len(attr); |
| 3057 | i++; |
| 3058 | } |
| 3059 | } |
| 3060 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3061 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3062 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 3063 | memcpy((void *)request->ie, |
| 3064 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 3065 | request->ie_len); |
| 3066 | } |
| 3067 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3068 | request->dev = dev; |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3069 | request->wiphy = &rdev->wiphy; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3070 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3071 | rdev->scan_req = request; |
| 3072 | err = rdev->ops->scan(&rdev->wiphy, dev, request); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3073 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3074 | if (!err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3075 | nl80211_send_scan_start(rdev, dev); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3076 | dev_hold(dev); |
| 3077 | } |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 3078 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3079 | out_free: |
| 3080 | if (err) { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3081 | rdev->scan_req = NULL; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3082 | kfree(request); |
| 3083 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3084 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3085 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3086 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 3087 | out_rtnl: |
| 3088 | rtnl_unlock(); |
| 3089 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3090 | return err; |
| 3091 | } |
| 3092 | |
| 3093 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 3094 | struct cfg80211_registered_device *rdev, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3095 | struct wireless_dev *wdev, |
| 3096 | struct cfg80211_internal_bss *intbss) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3097 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3098 | struct cfg80211_bss *res = &intbss->pub; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3099 | void *hdr; |
| 3100 | struct nlattr *bss; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3101 | int i; |
| 3102 | |
| 3103 | ASSERT_WDEV_LOCK(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3104 | |
| 3105 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 3106 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 3107 | if (!hdr) |
| 3108 | return -1; |
| 3109 | |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 3110 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3111 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3112 | |
| 3113 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 3114 | if (!bss) |
| 3115 | goto nla_put_failure; |
| 3116 | if (!is_zero_ether_addr(res->bssid)) |
| 3117 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 3118 | if (res->information_elements && res->len_information_elements) |
| 3119 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 3120 | res->len_information_elements, |
| 3121 | res->information_elements); |
| 3122 | if (res->tsf) |
| 3123 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 3124 | if (res->beacon_interval) |
| 3125 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 3126 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 3127 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
Holger Schurig | 7c89606 | 2009-09-24 12:21:01 +0200 | [diff] [blame] | 3128 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
| 3129 | jiffies_to_msecs(jiffies - intbss->ts)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3130 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 3131 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3132 | case CFG80211_SIGNAL_TYPE_MBM: |
| 3133 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 3134 | break; |
| 3135 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 3136 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 3137 | break; |
| 3138 | default: |
| 3139 | break; |
| 3140 | } |
| 3141 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3142 | switch (wdev->iftype) { |
| 3143 | case NL80211_IFTYPE_STATION: |
| 3144 | if (intbss == wdev->current_bss) |
| 3145 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3146 | NL80211_BSS_STATUS_ASSOCIATED); |
| 3147 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { |
| 3148 | if (intbss != wdev->auth_bsses[i]) |
| 3149 | continue; |
| 3150 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3151 | NL80211_BSS_STATUS_AUTHENTICATED); |
| 3152 | break; |
| 3153 | } |
| 3154 | break; |
| 3155 | case NL80211_IFTYPE_ADHOC: |
| 3156 | if (intbss == wdev->current_bss) |
| 3157 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, |
| 3158 | NL80211_BSS_STATUS_IBSS_JOINED); |
| 3159 | break; |
| 3160 | default: |
| 3161 | break; |
| 3162 | } |
| 3163 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3164 | nla_nest_end(msg, bss); |
| 3165 | |
| 3166 | return genlmsg_end(msg, hdr); |
| 3167 | |
| 3168 | nla_put_failure: |
| 3169 | genlmsg_cancel(msg, hdr); |
| 3170 | return -EMSGSIZE; |
| 3171 | } |
| 3172 | |
| 3173 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 3174 | struct netlink_callback *cb) |
| 3175 | { |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3176 | struct cfg80211_registered_device *rdev; |
| 3177 | struct net_device *dev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3178 | struct cfg80211_internal_bss *scan; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3179 | struct wireless_dev *wdev; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3180 | int ifidx = cb->args[0]; |
| 3181 | int start = cb->args[1], idx = 0; |
| 3182 | int err; |
| 3183 | |
| 3184 | if (!ifidx) { |
| 3185 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 3186 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 3187 | nl80211_policy); |
| 3188 | if (err) |
| 3189 | return err; |
| 3190 | |
| 3191 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 3192 | return -EINVAL; |
| 3193 | |
| 3194 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 3195 | if (!ifidx) |
| 3196 | return -EINVAL; |
| 3197 | cb->args[0] = ifidx; |
| 3198 | } |
| 3199 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3200 | dev = dev_get_by_index(sock_net(skb->sk), ifidx); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3201 | if (!dev) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3202 | return -ENODEV; |
| 3203 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3204 | rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3205 | if (IS_ERR(rdev)) { |
| 3206 | err = PTR_ERR(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3207 | goto out_put_netdev; |
| 3208 | } |
| 3209 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3210 | wdev = dev->ieee80211_ptr; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3211 | |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3212 | wdev_lock(wdev); |
| 3213 | spin_lock_bh(&rdev->bss_lock); |
| 3214 | cfg80211_bss_expire(rdev); |
| 3215 | |
| 3216 | list_for_each_entry(scan, &rdev->bss_list, list) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3217 | if (++idx <= start) |
| 3218 | continue; |
| 3219 | if (nl80211_send_bss(skb, |
| 3220 | NETLINK_CB(cb->skb).pid, |
| 3221 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3222 | rdev, wdev, scan) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3223 | idx--; |
| 3224 | goto out; |
| 3225 | } |
| 3226 | } |
| 3227 | |
| 3228 | out: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3229 | spin_unlock_bh(&rdev->bss_lock); |
| 3230 | wdev_unlock(wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3231 | |
| 3232 | cb->args[1] = idx; |
| 3233 | err = skb->len; |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3234 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3235 | out_put_netdev: |
Johannes Berg | 48ab905 | 2009-07-10 18:42:31 +0200 | [diff] [blame] | 3236 | dev_put(dev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3237 | |
| 3238 | return err; |
| 3239 | } |
| 3240 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3241 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 3242 | { |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3243 | return auth_type <= NL80211_AUTHTYPE_MAX; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3244 | } |
| 3245 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3246 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
| 3247 | { |
| 3248 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | |
| 3249 | NL80211_WPA_VERSION_2)); |
| 3250 | } |
| 3251 | |
| 3252 | static bool nl80211_valid_akm_suite(u32 akm) |
| 3253 | { |
| 3254 | return akm == WLAN_AKM_SUITE_8021X || |
| 3255 | akm == WLAN_AKM_SUITE_PSK; |
| 3256 | } |
| 3257 | |
| 3258 | static bool nl80211_valid_cipher_suite(u32 cipher) |
| 3259 | { |
| 3260 | return cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3261 | cipher == WLAN_CIPHER_SUITE_WEP104 || |
| 3262 | cipher == WLAN_CIPHER_SUITE_TKIP || |
| 3263 | cipher == WLAN_CIPHER_SUITE_CCMP || |
| 3264 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; |
| 3265 | } |
| 3266 | |
| 3267 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3268 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 3269 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3270 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3271 | struct net_device *dev; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3272 | struct ieee80211_channel *chan; |
| 3273 | const u8 *bssid, *ssid, *ie = NULL; |
| 3274 | int err, ssid_len, ie_len = 0; |
| 3275 | enum nl80211_auth_type auth_type; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3276 | struct key_parse key; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3277 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3278 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3279 | return -EINVAL; |
| 3280 | |
| 3281 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3282 | return -EINVAL; |
| 3283 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3284 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 3285 | return -EINVAL; |
| 3286 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3287 | if (!info->attrs[NL80211_ATTR_SSID]) |
| 3288 | return -EINVAL; |
| 3289 | |
| 3290 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
| 3291 | return -EINVAL; |
| 3292 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3293 | err = nl80211_parse_key(info, &key); |
| 3294 | if (err) |
| 3295 | return err; |
| 3296 | |
| 3297 | if (key.idx >= 0) { |
| 3298 | if (!key.p.key || !key.p.key_len) |
| 3299 | return -EINVAL; |
| 3300 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || |
| 3301 | key.p.key_len != WLAN_KEY_LEN_WEP40) && |
| 3302 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || |
| 3303 | key.p.key_len != WLAN_KEY_LEN_WEP104)) |
| 3304 | return -EINVAL; |
| 3305 | if (key.idx > 4) |
| 3306 | return -EINVAL; |
| 3307 | } else { |
| 3308 | key.p.key_len = 0; |
| 3309 | key.p.key = NULL; |
| 3310 | } |
| 3311 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3312 | rtnl_lock(); |
| 3313 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3314 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3315 | if (err) |
| 3316 | goto unlock_rtnl; |
| 3317 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3318 | if (!rdev->ops->auth) { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3319 | err = -EOPNOTSUPP; |
| 3320 | goto out; |
| 3321 | } |
| 3322 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3323 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3324 | err = -EOPNOTSUPP; |
| 3325 | goto out; |
| 3326 | } |
| 3327 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3328 | if (!netif_running(dev)) { |
| 3329 | err = -ENETDOWN; |
| 3330 | goto out; |
| 3331 | } |
| 3332 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3333 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3334 | chan = ieee80211_get_channel(&rdev->wiphy, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3335 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3336 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 3337 | err = -EINVAL; |
| 3338 | goto out; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3339 | } |
| 3340 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3341 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3342 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3343 | |
| 3344 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3345 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3346 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3347 | } |
| 3348 | |
| 3349 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 3350 | if (!nl80211_valid_auth_type(auth_type)) { |
| 3351 | err = -EINVAL; |
| 3352 | goto out; |
| 3353 | } |
| 3354 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3355 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3356 | ssid, ssid_len, ie, ie_len, |
| 3357 | key.p.key, key.p.key_len, key.idx); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3358 | |
| 3359 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3360 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3361 | dev_put(dev); |
| 3362 | unlock_rtnl: |
| 3363 | rtnl_unlock(); |
| 3364 | return err; |
| 3365 | } |
| 3366 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3367 | static int nl80211_crypto_settings(struct genl_info *info, |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3368 | struct cfg80211_crypto_settings *settings, |
| 3369 | int cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3370 | { |
Johannes Berg | c0b2bbd | 2009-07-25 16:54:36 +0200 | [diff] [blame] | 3371 | memset(settings, 0, sizeof(*settings)); |
| 3372 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3373 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
| 3374 | |
| 3375 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
| 3376 | void *data; |
| 3377 | int len, i; |
| 3378 | |
| 3379 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3380 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); |
| 3381 | settings->n_ciphers_pairwise = len / sizeof(u32); |
| 3382 | |
| 3383 | if (len % sizeof(u32)) |
| 3384 | return -EINVAL; |
| 3385 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3386 | if (settings->n_ciphers_pairwise > cipher_limit) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3387 | return -EINVAL; |
| 3388 | |
| 3389 | memcpy(settings->ciphers_pairwise, data, len); |
| 3390 | |
| 3391 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3392 | if (!nl80211_valid_cipher_suite( |
| 3393 | settings->ciphers_pairwise[i])) |
| 3394 | return -EINVAL; |
| 3395 | } |
| 3396 | |
| 3397 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { |
| 3398 | settings->cipher_group = |
| 3399 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); |
| 3400 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) |
| 3401 | return -EINVAL; |
| 3402 | } |
| 3403 | |
| 3404 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { |
| 3405 | settings->wpa_versions = |
| 3406 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); |
| 3407 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) |
| 3408 | return -EINVAL; |
| 3409 | } |
| 3410 | |
| 3411 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { |
| 3412 | void *data; |
| 3413 | int len, i; |
| 3414 | |
| 3415 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3416 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); |
| 3417 | settings->n_akm_suites = len / sizeof(u32); |
| 3418 | |
| 3419 | if (len % sizeof(u32)) |
| 3420 | return -EINVAL; |
| 3421 | |
| 3422 | memcpy(settings->akm_suites, data, len); |
| 3423 | |
| 3424 | for (i = 0; i < settings->n_ciphers_pairwise; i++) |
| 3425 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) |
| 3426 | return -EINVAL; |
| 3427 | } |
| 3428 | |
| 3429 | return 0; |
| 3430 | } |
| 3431 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3432 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 3433 | { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3434 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3435 | struct net_device *dev; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3436 | struct cfg80211_crypto_settings crypto; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 3437 | struct ieee80211_channel *chan, *fixedchan; |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3438 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3439 | int err, ssid_len, ie_len = 0; |
| 3440 | bool use_mfp = false; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3441 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3442 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3443 | return -EINVAL; |
| 3444 | |
| 3445 | if (!info->attrs[NL80211_ATTR_MAC] || |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3446 | !info->attrs[NL80211_ATTR_SSID] || |
| 3447 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3448 | return -EINVAL; |
| 3449 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3450 | rtnl_lock(); |
| 3451 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3452 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3453 | if (err) |
| 3454 | goto unlock_rtnl; |
| 3455 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3456 | if (!rdev->ops->assoc) { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3457 | err = -EOPNOTSUPP; |
| 3458 | goto out; |
| 3459 | } |
| 3460 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3461 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3462 | err = -EOPNOTSUPP; |
| 3463 | goto out; |
| 3464 | } |
| 3465 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3466 | if (!netif_running(dev)) { |
| 3467 | err = -ENETDOWN; |
| 3468 | goto out; |
| 3469 | } |
| 3470 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3471 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3472 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3473 | chan = ieee80211_get_channel(&rdev->wiphy, |
| 3474 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3475 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { |
| 3476 | err = -EINVAL; |
| 3477 | goto out; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3478 | } |
| 3479 | |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 3480 | mutex_lock(&rdev->devlist_mtx); |
| 3481 | fixedchan = rdev_fixed_channel(rdev, NULL); |
| 3482 | if (fixedchan && chan != fixedchan) { |
| 3483 | err = -EBUSY; |
| 3484 | mutex_unlock(&rdev->devlist_mtx); |
| 3485 | goto out; |
| 3486 | } |
| 3487 | mutex_unlock(&rdev->devlist_mtx); |
| 3488 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3489 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3490 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3491 | |
| 3492 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3493 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3494 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3495 | } |
| 3496 | |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3497 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3498 | enum nl80211_mfp mfp = |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3499 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3500 | if (mfp == NL80211_MFP_REQUIRED) |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3501 | use_mfp = true; |
Johannes Berg | 4f5dadc | 2009-07-07 03:56:10 +0200 | [diff] [blame] | 3502 | else if (mfp != NL80211_MFP_NO) { |
Jouni Malinen | dc6382ce | 2009-05-06 22:09:37 +0300 | [diff] [blame] | 3503 | err = -EINVAL; |
| 3504 | goto out; |
| 3505 | } |
| 3506 | } |
| 3507 | |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3508 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
| 3509 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
| 3510 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3511 | err = nl80211_crypto_settings(info, &crypto, 1); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3512 | if (!err) |
Johannes Berg | 3e5d764 | 2009-07-07 14:37:26 +0200 | [diff] [blame] | 3513 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
| 3514 | ssid, ssid_len, ie, ie_len, use_mfp, |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3515 | &crypto); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3516 | |
| 3517 | out: |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 3518 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3519 | dev_put(dev); |
| 3520 | unlock_rtnl: |
| 3521 | rtnl_unlock(); |
| 3522 | return err; |
| 3523 | } |
| 3524 | |
| 3525 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 3526 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3527 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3528 | struct net_device *dev; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3529 | const u8 *ie = NULL, *bssid; |
| 3530 | int err, ie_len = 0; |
| 3531 | u16 reason_code; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3532 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3533 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3534 | return -EINVAL; |
| 3535 | |
| 3536 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3537 | return -EINVAL; |
| 3538 | |
| 3539 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3540 | return -EINVAL; |
| 3541 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3542 | rtnl_lock(); |
| 3543 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3544 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3545 | if (err) |
| 3546 | goto unlock_rtnl; |
| 3547 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3548 | if (!rdev->ops->deauth) { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3549 | err = -EOPNOTSUPP; |
| 3550 | goto out; |
| 3551 | } |
| 3552 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3553 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3554 | err = -EOPNOTSUPP; |
| 3555 | goto out; |
| 3556 | } |
| 3557 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3558 | if (!netif_running(dev)) { |
| 3559 | err = -ENETDOWN; |
| 3560 | goto out; |
| 3561 | } |
| 3562 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3563 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3564 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3565 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3566 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3567 | /* Reason Code 0 is reserved */ |
| 3568 | err = -EINVAL; |
| 3569 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3570 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3571 | |
| 3572 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3573 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3574 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3575 | } |
| 3576 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3577 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3578 | |
| 3579 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3580 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3581 | dev_put(dev); |
| 3582 | unlock_rtnl: |
| 3583 | rtnl_unlock(); |
| 3584 | return err; |
| 3585 | } |
| 3586 | |
| 3587 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 3588 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3589 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3590 | struct net_device *dev; |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3591 | const u8 *ie = NULL, *bssid; |
| 3592 | int err, ie_len = 0; |
| 3593 | u16 reason_code; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3594 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3595 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3596 | return -EINVAL; |
| 3597 | |
| 3598 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 3599 | return -EINVAL; |
| 3600 | |
| 3601 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3602 | return -EINVAL; |
| 3603 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3604 | rtnl_lock(); |
| 3605 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3606 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3607 | if (err) |
| 3608 | goto unlock_rtnl; |
| 3609 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3610 | if (!rdev->ops->disassoc) { |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3611 | err = -EOPNOTSUPP; |
| 3612 | goto out; |
| 3613 | } |
| 3614 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3615 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3616 | err = -EOPNOTSUPP; |
| 3617 | goto out; |
| 3618 | } |
| 3619 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3620 | if (!netif_running(dev)) { |
| 3621 | err = -ENETDOWN; |
| 3622 | goto out; |
| 3623 | } |
| 3624 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3625 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3626 | |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3627 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3628 | if (reason_code == 0) { |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3629 | /* Reason Code 0 is reserved */ |
| 3630 | err = -EINVAL; |
| 3631 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3632 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3633 | |
| 3634 | if (info->attrs[NL80211_ATTR_IE]) { |
Johannes Berg | 19957bb | 2009-07-02 17:20:43 +0200 | [diff] [blame] | 3635 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3636 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3637 | } |
| 3638 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3639 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3640 | |
| 3641 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3642 | cfg80211_unlock_rdev(rdev); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3643 | dev_put(dev); |
| 3644 | unlock_rtnl: |
| 3645 | rtnl_unlock(); |
| 3646 | return err; |
| 3647 | } |
| 3648 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3649 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3650 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3651 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3652 | struct net_device *dev; |
| 3653 | struct cfg80211_ibss_params ibss; |
| 3654 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3655 | struct cfg80211_cached_keys *connkeys = NULL; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3656 | int err; |
| 3657 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3658 | memset(&ibss, 0, sizeof(ibss)); |
| 3659 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3660 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3661 | return -EINVAL; |
| 3662 | |
| 3663 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || |
| 3664 | !info->attrs[NL80211_ATTR_SSID] || |
| 3665 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 3666 | return -EINVAL; |
| 3667 | |
Johannes Berg | 8e30bc5 | 2009-04-22 17:45:38 +0200 | [diff] [blame] | 3668 | ibss.beacon_interval = 100; |
| 3669 | |
| 3670 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 3671 | ibss.beacon_interval = |
| 3672 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 3673 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) |
| 3674 | return -EINVAL; |
| 3675 | } |
| 3676 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3677 | rtnl_lock(); |
| 3678 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3679 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3680 | if (err) |
| 3681 | goto unlock_rtnl; |
| 3682 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3683 | if (!rdev->ops->join_ibss) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3684 | err = -EOPNOTSUPP; |
| 3685 | goto out; |
| 3686 | } |
| 3687 | |
| 3688 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { |
| 3689 | err = -EOPNOTSUPP; |
| 3690 | goto out; |
| 3691 | } |
| 3692 | |
| 3693 | if (!netif_running(dev)) { |
| 3694 | err = -ENETDOWN; |
| 3695 | goto out; |
| 3696 | } |
| 3697 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3698 | wiphy = &rdev->wiphy; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3699 | |
| 3700 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3701 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3702 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3703 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3704 | |
| 3705 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3706 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3707 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3708 | } |
| 3709 | |
| 3710 | ibss.channel = ieee80211_get_channel(wiphy, |
| 3711 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3712 | if (!ibss.channel || |
| 3713 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || |
| 3714 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) { |
| 3715 | err = -EINVAL; |
| 3716 | goto out; |
| 3717 | } |
| 3718 | |
| 3719 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3720 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3721 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3722 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 3723 | connkeys = nl80211_parse_connkeys(rdev, |
| 3724 | info->attrs[NL80211_ATTR_KEYS]); |
| 3725 | if (IS_ERR(connkeys)) { |
| 3726 | err = PTR_ERR(connkeys); |
| 3727 | connkeys = NULL; |
| 3728 | goto out; |
| 3729 | } |
| 3730 | } |
| 3731 | |
| 3732 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3733 | |
| 3734 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3735 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3736 | dev_put(dev); |
| 3737 | unlock_rtnl: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3738 | if (err) |
| 3739 | kfree(connkeys); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3740 | rtnl_unlock(); |
| 3741 | return err; |
| 3742 | } |
| 3743 | |
| 3744 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) |
| 3745 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3746 | struct cfg80211_registered_device *rdev; |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3747 | struct net_device *dev; |
| 3748 | int err; |
| 3749 | |
| 3750 | rtnl_lock(); |
| 3751 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3752 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3753 | if (err) |
| 3754 | goto unlock_rtnl; |
| 3755 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3756 | if (!rdev->ops->leave_ibss) { |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3757 | err = -EOPNOTSUPP; |
| 3758 | goto out; |
| 3759 | } |
| 3760 | |
| 3761 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { |
| 3762 | err = -EOPNOTSUPP; |
| 3763 | goto out; |
| 3764 | } |
| 3765 | |
| 3766 | if (!netif_running(dev)) { |
| 3767 | err = -ENETDOWN; |
| 3768 | goto out; |
| 3769 | } |
| 3770 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3771 | err = cfg80211_leave_ibss(rdev, dev, false); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3772 | |
| 3773 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3774 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 3775 | dev_put(dev); |
| 3776 | unlock_rtnl: |
| 3777 | rtnl_unlock(); |
| 3778 | return err; |
| 3779 | } |
| 3780 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 3781 | #ifdef CONFIG_NL80211_TESTMODE |
| 3782 | static struct genl_multicast_group nl80211_testmode_mcgrp = { |
| 3783 | .name = "testmode", |
| 3784 | }; |
| 3785 | |
| 3786 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
| 3787 | { |
| 3788 | struct cfg80211_registered_device *rdev; |
| 3789 | int err; |
| 3790 | |
| 3791 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
| 3792 | return -EINVAL; |
| 3793 | |
| 3794 | rtnl_lock(); |
| 3795 | |
| 3796 | rdev = cfg80211_get_dev_from_info(info); |
| 3797 | if (IS_ERR(rdev)) { |
| 3798 | err = PTR_ERR(rdev); |
| 3799 | goto unlock_rtnl; |
| 3800 | } |
| 3801 | |
| 3802 | err = -EOPNOTSUPP; |
| 3803 | if (rdev->ops->testmode_cmd) { |
| 3804 | rdev->testmode_info = info; |
| 3805 | err = rdev->ops->testmode_cmd(&rdev->wiphy, |
| 3806 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
| 3807 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); |
| 3808 | rdev->testmode_info = NULL; |
| 3809 | } |
| 3810 | |
Johannes Berg | 4d0c8ae | 2009-07-07 03:56:09 +0200 | [diff] [blame] | 3811 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 3812 | |
| 3813 | unlock_rtnl: |
| 3814 | rtnl_unlock(); |
| 3815 | return err; |
| 3816 | } |
| 3817 | |
| 3818 | static struct sk_buff * |
| 3819 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, |
| 3820 | int approxlen, u32 pid, u32 seq, gfp_t gfp) |
| 3821 | { |
| 3822 | struct sk_buff *skb; |
| 3823 | void *hdr; |
| 3824 | struct nlattr *data; |
| 3825 | |
| 3826 | skb = nlmsg_new(approxlen + 100, gfp); |
| 3827 | if (!skb) |
| 3828 | return NULL; |
| 3829 | |
| 3830 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); |
| 3831 | if (!hdr) { |
| 3832 | kfree_skb(skb); |
| 3833 | return NULL; |
| 3834 | } |
| 3835 | |
| 3836 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3837 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); |
| 3838 | |
| 3839 | ((void **)skb->cb)[0] = rdev; |
| 3840 | ((void **)skb->cb)[1] = hdr; |
| 3841 | ((void **)skb->cb)[2] = data; |
| 3842 | |
| 3843 | return skb; |
| 3844 | |
| 3845 | nla_put_failure: |
| 3846 | kfree_skb(skb); |
| 3847 | return NULL; |
| 3848 | } |
| 3849 | |
| 3850 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, |
| 3851 | int approxlen) |
| 3852 | { |
| 3853 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 3854 | |
| 3855 | if (WARN_ON(!rdev->testmode_info)) |
| 3856 | return NULL; |
| 3857 | |
| 3858 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, |
| 3859 | rdev->testmode_info->snd_pid, |
| 3860 | rdev->testmode_info->snd_seq, |
| 3861 | GFP_KERNEL); |
| 3862 | } |
| 3863 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); |
| 3864 | |
| 3865 | int cfg80211_testmode_reply(struct sk_buff *skb) |
| 3866 | { |
| 3867 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; |
| 3868 | void *hdr = ((void **)skb->cb)[1]; |
| 3869 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 3870 | |
| 3871 | if (WARN_ON(!rdev->testmode_info)) { |
| 3872 | kfree_skb(skb); |
| 3873 | return -EINVAL; |
| 3874 | } |
| 3875 | |
| 3876 | nla_nest_end(skb, data); |
| 3877 | genlmsg_end(skb, hdr); |
| 3878 | return genlmsg_reply(skb, rdev->testmode_info); |
| 3879 | } |
| 3880 | EXPORT_SYMBOL(cfg80211_testmode_reply); |
| 3881 | |
| 3882 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, |
| 3883 | int approxlen, gfp_t gfp) |
| 3884 | { |
| 3885 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); |
| 3886 | |
| 3887 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); |
| 3888 | } |
| 3889 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); |
| 3890 | |
| 3891 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) |
| 3892 | { |
| 3893 | void *hdr = ((void **)skb->cb)[1]; |
| 3894 | struct nlattr *data = ((void **)skb->cb)[2]; |
| 3895 | |
| 3896 | nla_nest_end(skb, data); |
| 3897 | genlmsg_end(skb, hdr); |
| 3898 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); |
| 3899 | } |
| 3900 | EXPORT_SYMBOL(cfg80211_testmode_event); |
| 3901 | #endif |
| 3902 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3903 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
| 3904 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3905 | struct cfg80211_registered_device *rdev; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3906 | struct net_device *dev; |
| 3907 | struct cfg80211_connect_params connect; |
| 3908 | struct wiphy *wiphy; |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3909 | struct cfg80211_cached_keys *connkeys = NULL; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3910 | int err; |
| 3911 | |
| 3912 | memset(&connect, 0, sizeof(connect)); |
| 3913 | |
| 3914 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 3915 | return -EINVAL; |
| 3916 | |
| 3917 | if (!info->attrs[NL80211_ATTR_SSID] || |
| 3918 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
| 3919 | return -EINVAL; |
| 3920 | |
| 3921 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { |
| 3922 | connect.auth_type = |
| 3923 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 3924 | if (!nl80211_valid_auth_type(connect.auth_type)) |
| 3925 | return -EINVAL; |
| 3926 | } else |
| 3927 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; |
| 3928 | |
| 3929 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; |
| 3930 | |
Johannes Berg | 3dc27d2 | 2009-07-02 21:36:37 +0200 | [diff] [blame] | 3931 | err = nl80211_crypto_settings(info, &connect.crypto, |
| 3932 | NL80211_MAX_NR_CIPHER_SUITES); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3933 | if (err) |
| 3934 | return err; |
| 3935 | rtnl_lock(); |
| 3936 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 3937 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3938 | if (err) |
| 3939 | goto unlock_rtnl; |
| 3940 | |
| 3941 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3942 | err = -EOPNOTSUPP; |
| 3943 | goto out; |
| 3944 | } |
| 3945 | |
| 3946 | if (!netif_running(dev)) { |
| 3947 | err = -ENETDOWN; |
| 3948 | goto out; |
| 3949 | } |
| 3950 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3951 | wiphy = &rdev->wiphy; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3952 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3953 | if (info->attrs[NL80211_ATTR_MAC]) |
| 3954 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3955 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 3956 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 3957 | |
| 3958 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3959 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3960 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3961 | } |
| 3962 | |
| 3963 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 3964 | connect.channel = |
| 3965 | ieee80211_get_channel(wiphy, |
| 3966 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 3967 | if (!connect.channel || |
| 3968 | connect.channel->flags & IEEE80211_CHAN_DISABLED) { |
| 3969 | err = -EINVAL; |
| 3970 | goto out; |
| 3971 | } |
| 3972 | } |
| 3973 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3974 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
| 3975 | connkeys = nl80211_parse_connkeys(rdev, |
| 3976 | info->attrs[NL80211_ATTR_KEYS]); |
| 3977 | if (IS_ERR(connkeys)) { |
| 3978 | err = PTR_ERR(connkeys); |
| 3979 | connkeys = NULL; |
| 3980 | goto out; |
| 3981 | } |
| 3982 | } |
| 3983 | |
| 3984 | err = cfg80211_connect(rdev, dev, &connect, connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3985 | |
| 3986 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3987 | cfg80211_unlock_rdev(rdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3988 | dev_put(dev); |
| 3989 | unlock_rtnl: |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3990 | if (err) |
| 3991 | kfree(connkeys); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3992 | rtnl_unlock(); |
| 3993 | return err; |
| 3994 | } |
| 3995 | |
| 3996 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
| 3997 | { |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 3998 | struct cfg80211_registered_device *rdev; |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 3999 | struct net_device *dev; |
| 4000 | int err; |
| 4001 | u16 reason; |
| 4002 | |
| 4003 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 4004 | reason = WLAN_REASON_DEAUTH_LEAVING; |
| 4005 | else |
| 4006 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 4007 | |
| 4008 | if (reason == 0) |
| 4009 | return -EINVAL; |
| 4010 | |
| 4011 | rtnl_lock(); |
| 4012 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4013 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4014 | if (err) |
| 4015 | goto unlock_rtnl; |
| 4016 | |
| 4017 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 4018 | err = -EOPNOTSUPP; |
| 4019 | goto out; |
| 4020 | } |
| 4021 | |
| 4022 | if (!netif_running(dev)) { |
| 4023 | err = -ENETDOWN; |
| 4024 | goto out; |
| 4025 | } |
| 4026 | |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4027 | err = cfg80211_disconnect(rdev, dev, reason, true); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4028 | |
| 4029 | out: |
Johannes Berg | 79c97e9 | 2009-07-07 03:56:12 +0200 | [diff] [blame] | 4030 | cfg80211_unlock_rdev(rdev); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4031 | dev_put(dev); |
| 4032 | unlock_rtnl: |
| 4033 | rtnl_unlock(); |
| 4034 | return err; |
| 4035 | } |
| 4036 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4037 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
| 4038 | { |
| 4039 | struct cfg80211_registered_device *rdev; |
| 4040 | struct net *net; |
| 4041 | int err; |
| 4042 | u32 pid; |
| 4043 | |
| 4044 | if (!info->attrs[NL80211_ATTR_PID]) |
| 4045 | return -EINVAL; |
| 4046 | |
| 4047 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 4048 | |
| 4049 | rtnl_lock(); |
| 4050 | |
| 4051 | rdev = cfg80211_get_dev_from_info(info); |
| 4052 | if (IS_ERR(rdev)) { |
| 4053 | err = PTR_ERR(rdev); |
Johannes Berg | 8a8e05e | 2009-10-08 21:02:02 +0200 | [diff] [blame] | 4054 | goto out_rtnl; |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4055 | } |
| 4056 | |
| 4057 | net = get_net_ns_by_pid(pid); |
| 4058 | if (IS_ERR(net)) { |
| 4059 | err = PTR_ERR(net); |
| 4060 | goto out; |
| 4061 | } |
| 4062 | |
| 4063 | err = 0; |
| 4064 | |
| 4065 | /* check if anything to do */ |
| 4066 | if (net_eq(wiphy_net(&rdev->wiphy), net)) |
| 4067 | goto out_put_net; |
| 4068 | |
| 4069 | err = cfg80211_switch_netns(rdev, net); |
| 4070 | out_put_net: |
| 4071 | put_net(net); |
| 4072 | out: |
| 4073 | cfg80211_unlock_rdev(rdev); |
Johannes Berg | 8a8e05e | 2009-10-08 21:02:02 +0200 | [diff] [blame] | 4074 | out_rtnl: |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4075 | rtnl_unlock(); |
| 4076 | return err; |
| 4077 | } |
| 4078 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4079 | static struct genl_ops nl80211_ops[] = { |
| 4080 | { |
| 4081 | .cmd = NL80211_CMD_GET_WIPHY, |
| 4082 | .doit = nl80211_get_wiphy, |
| 4083 | .dumpit = nl80211_dump_wiphy, |
| 4084 | .policy = nl80211_policy, |
| 4085 | /* can be retrieved by unprivileged users */ |
| 4086 | }, |
| 4087 | { |
| 4088 | .cmd = NL80211_CMD_SET_WIPHY, |
| 4089 | .doit = nl80211_set_wiphy, |
| 4090 | .policy = nl80211_policy, |
| 4091 | .flags = GENL_ADMIN_PERM, |
| 4092 | }, |
| 4093 | { |
| 4094 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 4095 | .doit = nl80211_get_interface, |
| 4096 | .dumpit = nl80211_dump_interface, |
| 4097 | .policy = nl80211_policy, |
| 4098 | /* can be retrieved by unprivileged users */ |
| 4099 | }, |
| 4100 | { |
| 4101 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 4102 | .doit = nl80211_set_interface, |
| 4103 | .policy = nl80211_policy, |
| 4104 | .flags = GENL_ADMIN_PERM, |
| 4105 | }, |
| 4106 | { |
| 4107 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 4108 | .doit = nl80211_new_interface, |
| 4109 | .policy = nl80211_policy, |
| 4110 | .flags = GENL_ADMIN_PERM, |
| 4111 | }, |
| 4112 | { |
| 4113 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 4114 | .doit = nl80211_del_interface, |
| 4115 | .policy = nl80211_policy, |
| 4116 | .flags = GENL_ADMIN_PERM, |
| 4117 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 4118 | { |
| 4119 | .cmd = NL80211_CMD_GET_KEY, |
| 4120 | .doit = nl80211_get_key, |
| 4121 | .policy = nl80211_policy, |
| 4122 | .flags = GENL_ADMIN_PERM, |
| 4123 | }, |
| 4124 | { |
| 4125 | .cmd = NL80211_CMD_SET_KEY, |
| 4126 | .doit = nl80211_set_key, |
| 4127 | .policy = nl80211_policy, |
| 4128 | .flags = GENL_ADMIN_PERM, |
| 4129 | }, |
| 4130 | { |
| 4131 | .cmd = NL80211_CMD_NEW_KEY, |
| 4132 | .doit = nl80211_new_key, |
| 4133 | .policy = nl80211_policy, |
| 4134 | .flags = GENL_ADMIN_PERM, |
| 4135 | }, |
| 4136 | { |
| 4137 | .cmd = NL80211_CMD_DEL_KEY, |
| 4138 | .doit = nl80211_del_key, |
| 4139 | .policy = nl80211_policy, |
| 4140 | .flags = GENL_ADMIN_PERM, |
| 4141 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 4142 | { |
| 4143 | .cmd = NL80211_CMD_SET_BEACON, |
| 4144 | .policy = nl80211_policy, |
| 4145 | .flags = GENL_ADMIN_PERM, |
| 4146 | .doit = nl80211_addset_beacon, |
| 4147 | }, |
| 4148 | { |
| 4149 | .cmd = NL80211_CMD_NEW_BEACON, |
| 4150 | .policy = nl80211_policy, |
| 4151 | .flags = GENL_ADMIN_PERM, |
| 4152 | .doit = nl80211_addset_beacon, |
| 4153 | }, |
| 4154 | { |
| 4155 | .cmd = NL80211_CMD_DEL_BEACON, |
| 4156 | .policy = nl80211_policy, |
| 4157 | .flags = GENL_ADMIN_PERM, |
| 4158 | .doit = nl80211_del_beacon, |
| 4159 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4160 | { |
| 4161 | .cmd = NL80211_CMD_GET_STATION, |
| 4162 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4163 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4164 | .policy = nl80211_policy, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 4165 | }, |
| 4166 | { |
| 4167 | .cmd = NL80211_CMD_SET_STATION, |
| 4168 | .doit = nl80211_set_station, |
| 4169 | .policy = nl80211_policy, |
| 4170 | .flags = GENL_ADMIN_PERM, |
| 4171 | }, |
| 4172 | { |
| 4173 | .cmd = NL80211_CMD_NEW_STATION, |
| 4174 | .doit = nl80211_new_station, |
| 4175 | .policy = nl80211_policy, |
| 4176 | .flags = GENL_ADMIN_PERM, |
| 4177 | }, |
| 4178 | { |
| 4179 | .cmd = NL80211_CMD_DEL_STATION, |
| 4180 | .doit = nl80211_del_station, |
| 4181 | .policy = nl80211_policy, |
| 4182 | .flags = GENL_ADMIN_PERM, |
| 4183 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 4184 | { |
| 4185 | .cmd = NL80211_CMD_GET_MPATH, |
| 4186 | .doit = nl80211_get_mpath, |
| 4187 | .dumpit = nl80211_dump_mpath, |
| 4188 | .policy = nl80211_policy, |
| 4189 | .flags = GENL_ADMIN_PERM, |
| 4190 | }, |
| 4191 | { |
| 4192 | .cmd = NL80211_CMD_SET_MPATH, |
| 4193 | .doit = nl80211_set_mpath, |
| 4194 | .policy = nl80211_policy, |
| 4195 | .flags = GENL_ADMIN_PERM, |
| 4196 | }, |
| 4197 | { |
| 4198 | .cmd = NL80211_CMD_NEW_MPATH, |
| 4199 | .doit = nl80211_new_mpath, |
| 4200 | .policy = nl80211_policy, |
| 4201 | .flags = GENL_ADMIN_PERM, |
| 4202 | }, |
| 4203 | { |
| 4204 | .cmd = NL80211_CMD_DEL_MPATH, |
| 4205 | .doit = nl80211_del_mpath, |
| 4206 | .policy = nl80211_policy, |
| 4207 | .flags = GENL_ADMIN_PERM, |
| 4208 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 4209 | { |
| 4210 | .cmd = NL80211_CMD_SET_BSS, |
| 4211 | .doit = nl80211_set_bss, |
| 4212 | .policy = nl80211_policy, |
| 4213 | .flags = GENL_ADMIN_PERM, |
| 4214 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4215 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 4216 | .cmd = NL80211_CMD_GET_REG, |
| 4217 | .doit = nl80211_get_reg, |
| 4218 | .policy = nl80211_policy, |
| 4219 | /* can be retrieved by unprivileged users */ |
| 4220 | }, |
| 4221 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 4222 | .cmd = NL80211_CMD_SET_REG, |
| 4223 | .doit = nl80211_set_reg, |
| 4224 | .policy = nl80211_policy, |
| 4225 | .flags = GENL_ADMIN_PERM, |
| 4226 | }, |
| 4227 | { |
| 4228 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 4229 | .doit = nl80211_req_set_reg, |
| 4230 | .policy = nl80211_policy, |
| 4231 | .flags = GENL_ADMIN_PERM, |
| 4232 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 4233 | { |
| 4234 | .cmd = NL80211_CMD_GET_MESH_PARAMS, |
| 4235 | .doit = nl80211_get_mesh_params, |
| 4236 | .policy = nl80211_policy, |
| 4237 | /* can be retrieved by unprivileged users */ |
| 4238 | }, |
| 4239 | { |
| 4240 | .cmd = NL80211_CMD_SET_MESH_PARAMS, |
| 4241 | .doit = nl80211_set_mesh_params, |
| 4242 | .policy = nl80211_policy, |
| 4243 | .flags = GENL_ADMIN_PERM, |
| 4244 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 4245 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4246 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 4247 | .doit = nl80211_trigger_scan, |
| 4248 | .policy = nl80211_policy, |
| 4249 | .flags = GENL_ADMIN_PERM, |
| 4250 | }, |
| 4251 | { |
| 4252 | .cmd = NL80211_CMD_GET_SCAN, |
| 4253 | .policy = nl80211_policy, |
| 4254 | .dumpit = nl80211_dump_scan, |
| 4255 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 4256 | { |
| 4257 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 4258 | .doit = nl80211_authenticate, |
| 4259 | .policy = nl80211_policy, |
| 4260 | .flags = GENL_ADMIN_PERM, |
| 4261 | }, |
| 4262 | { |
| 4263 | .cmd = NL80211_CMD_ASSOCIATE, |
| 4264 | .doit = nl80211_associate, |
| 4265 | .policy = nl80211_policy, |
| 4266 | .flags = GENL_ADMIN_PERM, |
| 4267 | }, |
| 4268 | { |
| 4269 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 4270 | .doit = nl80211_deauthenticate, |
| 4271 | .policy = nl80211_policy, |
| 4272 | .flags = GENL_ADMIN_PERM, |
| 4273 | }, |
| 4274 | { |
| 4275 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 4276 | .doit = nl80211_disassociate, |
| 4277 | .policy = nl80211_policy, |
| 4278 | .flags = GENL_ADMIN_PERM, |
| 4279 | }, |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4280 | { |
| 4281 | .cmd = NL80211_CMD_JOIN_IBSS, |
| 4282 | .doit = nl80211_join_ibss, |
| 4283 | .policy = nl80211_policy, |
| 4284 | .flags = GENL_ADMIN_PERM, |
| 4285 | }, |
| 4286 | { |
| 4287 | .cmd = NL80211_CMD_LEAVE_IBSS, |
| 4288 | .doit = nl80211_leave_ibss, |
| 4289 | .policy = nl80211_policy, |
| 4290 | .flags = GENL_ADMIN_PERM, |
| 4291 | }, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4292 | #ifdef CONFIG_NL80211_TESTMODE |
| 4293 | { |
| 4294 | .cmd = NL80211_CMD_TESTMODE, |
| 4295 | .doit = nl80211_testmode_do, |
| 4296 | .policy = nl80211_policy, |
| 4297 | .flags = GENL_ADMIN_PERM, |
| 4298 | }, |
| 4299 | #endif |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4300 | { |
| 4301 | .cmd = NL80211_CMD_CONNECT, |
| 4302 | .doit = nl80211_connect, |
| 4303 | .policy = nl80211_policy, |
| 4304 | .flags = GENL_ADMIN_PERM, |
| 4305 | }, |
| 4306 | { |
| 4307 | .cmd = NL80211_CMD_DISCONNECT, |
| 4308 | .doit = nl80211_disconnect, |
| 4309 | .policy = nl80211_policy, |
| 4310 | .flags = GENL_ADMIN_PERM, |
| 4311 | }, |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4312 | { |
| 4313 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, |
| 4314 | .doit = nl80211_wiphy_netns, |
| 4315 | .policy = nl80211_policy, |
| 4316 | .flags = GENL_ADMIN_PERM, |
| 4317 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4318 | }; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4319 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 4320 | .name = "mlme", |
| 4321 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4322 | |
| 4323 | /* multicast groups */ |
| 4324 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 4325 | .name = "config", |
| 4326 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4327 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 4328 | .name = "scan", |
| 4329 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 4330 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 4331 | .name = "regulatory", |
| 4332 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4333 | |
| 4334 | /* notification functions */ |
| 4335 | |
| 4336 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 4337 | { |
| 4338 | struct sk_buff *msg; |
| 4339 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4340 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4341 | if (!msg) |
| 4342 | return; |
| 4343 | |
| 4344 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 4345 | nlmsg_free(msg); |
| 4346 | return; |
| 4347 | } |
| 4348 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4349 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4350 | nl80211_config_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4351 | } |
| 4352 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 4353 | static int nl80211_add_scan_req(struct sk_buff *msg, |
| 4354 | struct cfg80211_registered_device *rdev) |
| 4355 | { |
| 4356 | struct cfg80211_scan_request *req = rdev->scan_req; |
| 4357 | struct nlattr *nest; |
| 4358 | int i; |
| 4359 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 4360 | ASSERT_RDEV_LOCK(rdev); |
| 4361 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 4362 | if (WARN_ON(!req)) |
| 4363 | return 0; |
| 4364 | |
| 4365 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); |
| 4366 | if (!nest) |
| 4367 | goto nla_put_failure; |
| 4368 | for (i = 0; i < req->n_ssids; i++) |
| 4369 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); |
| 4370 | nla_nest_end(msg, nest); |
| 4371 | |
| 4372 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
| 4373 | if (!nest) |
| 4374 | goto nla_put_failure; |
| 4375 | for (i = 0; i < req->n_channels; i++) |
| 4376 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); |
| 4377 | nla_nest_end(msg, nest); |
| 4378 | |
| 4379 | if (req->ie) |
| 4380 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); |
| 4381 | |
| 4382 | return 0; |
| 4383 | nla_put_failure: |
| 4384 | return -ENOBUFS; |
| 4385 | } |
| 4386 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 4387 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
| 4388 | struct cfg80211_registered_device *rdev, |
| 4389 | struct net_device *netdev, |
| 4390 | u32 pid, u32 seq, int flags, |
| 4391 | u32 cmd) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4392 | { |
| 4393 | void *hdr; |
| 4394 | |
| 4395 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 4396 | if (!hdr) |
| 4397 | return -1; |
| 4398 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 4399 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4400 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 4401 | |
Johannes Berg | 362a415 | 2009-05-24 16:43:15 +0200 | [diff] [blame] | 4402 | /* ignore errors and send incomplete event anyway */ |
| 4403 | nl80211_add_scan_req(msg, rdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4404 | |
| 4405 | return genlmsg_end(msg, hdr); |
| 4406 | |
| 4407 | nla_put_failure: |
| 4408 | genlmsg_cancel(msg, hdr); |
| 4409 | return -EMSGSIZE; |
| 4410 | } |
| 4411 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 4412 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
| 4413 | struct net_device *netdev) |
| 4414 | { |
| 4415 | struct sk_buff *msg; |
| 4416 | |
| 4417 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 4418 | if (!msg) |
| 4419 | return; |
| 4420 | |
| 4421 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 4422 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
| 4423 | nlmsg_free(msg); |
| 4424 | return; |
| 4425 | } |
| 4426 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4427 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4428 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 4429 | } |
| 4430 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4431 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 4432 | struct net_device *netdev) |
| 4433 | { |
| 4434 | struct sk_buff *msg; |
| 4435 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4436 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4437 | if (!msg) |
| 4438 | return; |
| 4439 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 4440 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 4441 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4442 | nlmsg_free(msg); |
| 4443 | return; |
| 4444 | } |
| 4445 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4446 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4447 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 4451 | struct net_device *netdev) |
| 4452 | { |
| 4453 | struct sk_buff *msg; |
| 4454 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4455 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4456 | if (!msg) |
| 4457 | return; |
| 4458 | |
Johannes Berg | a538e2d | 2009-06-16 19:56:42 +0200 | [diff] [blame] | 4459 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
| 4460 | NL80211_CMD_SCAN_ABORTED) < 0) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4461 | nlmsg_free(msg); |
| 4462 | return; |
| 4463 | } |
| 4464 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4465 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4466 | nl80211_scan_mcgrp.id, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4467 | } |
| 4468 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 4469 | /* |
| 4470 | * This can happen on global regulatory changes or device specific settings |
| 4471 | * based on custom world regulatory domains. |
| 4472 | */ |
| 4473 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 4474 | { |
| 4475 | struct sk_buff *msg; |
| 4476 | void *hdr; |
| 4477 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4478 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 4479 | if (!msg) |
| 4480 | return; |
| 4481 | |
| 4482 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 4483 | if (!hdr) { |
| 4484 | nlmsg_free(msg); |
| 4485 | return; |
| 4486 | } |
| 4487 | |
| 4488 | /* Userspace can always count this one always being set */ |
| 4489 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 4490 | |
| 4491 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 4492 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 4493 | NL80211_REGDOM_TYPE_WORLD); |
| 4494 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 4495 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 4496 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 4497 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 4498 | request->intersect) |
| 4499 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 4500 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 4501 | else { |
| 4502 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 4503 | NL80211_REGDOM_TYPE_COUNTRY); |
| 4504 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 4505 | } |
| 4506 | |
| 4507 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 4508 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 4509 | |
| 4510 | if (genlmsg_end(msg, hdr) < 0) { |
| 4511 | nlmsg_free(msg); |
| 4512 | return; |
| 4513 | } |
| 4514 | |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 4515 | rcu_read_lock(); |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4516 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
Johannes Berg | bc43b28 | 2009-07-25 10:54:13 +0200 | [diff] [blame] | 4517 | GFP_ATOMIC); |
| 4518 | rcu_read_unlock(); |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 4519 | |
| 4520 | return; |
| 4521 | |
| 4522 | nla_put_failure: |
| 4523 | genlmsg_cancel(msg, hdr); |
| 4524 | nlmsg_free(msg); |
| 4525 | } |
| 4526 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4527 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 4528 | struct net_device *netdev, |
| 4529 | const u8 *buf, size_t len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4530 | enum nl80211_commands cmd, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4531 | { |
| 4532 | struct sk_buff *msg; |
| 4533 | void *hdr; |
| 4534 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4535 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4536 | if (!msg) |
| 4537 | return; |
| 4538 | |
| 4539 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 4540 | if (!hdr) { |
| 4541 | nlmsg_free(msg); |
| 4542 | return; |
| 4543 | } |
| 4544 | |
| 4545 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4546 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 4547 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 4548 | |
| 4549 | if (genlmsg_end(msg, hdr) < 0) { |
| 4550 | nlmsg_free(msg); |
| 4551 | return; |
| 4552 | } |
| 4553 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4554 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4555 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4556 | return; |
| 4557 | |
| 4558 | nla_put_failure: |
| 4559 | genlmsg_cancel(msg, hdr); |
| 4560 | nlmsg_free(msg); |
| 4561 | } |
| 4562 | |
| 4563 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4564 | struct net_device *netdev, const u8 *buf, |
| 4565 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4566 | { |
| 4567 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4568 | NL80211_CMD_AUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4569 | } |
| 4570 | |
| 4571 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 4572 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4573 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4574 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4575 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 4576 | NL80211_CMD_ASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4577 | } |
| 4578 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 4579 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4580 | struct net_device *netdev, const u8 *buf, |
| 4581 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4582 | { |
| 4583 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4584 | NL80211_CMD_DEAUTHENTICATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4585 | } |
| 4586 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 4587 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 4588 | struct net_device *netdev, const u8 *buf, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4589 | size_t len, gfp_t gfp) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4590 | { |
| 4591 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4592 | NL80211_CMD_DISASSOCIATE, gfp); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4593 | } |
| 4594 | |
Luis R. Rodriguez | 1b06bb4 | 2009-05-02 00:34:48 -0400 | [diff] [blame] | 4595 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
| 4596 | struct net_device *netdev, int cmd, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4597 | const u8 *addr, gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 4598 | { |
| 4599 | struct sk_buff *msg; |
| 4600 | void *hdr; |
| 4601 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 4603 | if (!msg) |
| 4604 | return; |
| 4605 | |
| 4606 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 4607 | if (!hdr) { |
| 4608 | nlmsg_free(msg); |
| 4609 | return; |
| 4610 | } |
| 4611 | |
| 4612 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4613 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 4614 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); |
| 4615 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 4616 | |
| 4617 | if (genlmsg_end(msg, hdr) < 0) { |
| 4618 | nlmsg_free(msg); |
| 4619 | return; |
| 4620 | } |
| 4621 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4622 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4623 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 4624 | return; |
| 4625 | |
| 4626 | nla_put_failure: |
| 4627 | genlmsg_cancel(msg, hdr); |
| 4628 | nlmsg_free(msg); |
| 4629 | } |
| 4630 | |
| 4631 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4632 | struct net_device *netdev, const u8 *addr, |
| 4633 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 4634 | { |
| 4635 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4636 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4640 | struct net_device *netdev, const u8 *addr, |
| 4641 | gfp_t gfp) |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 4642 | { |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4643 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
| 4644 | addr, gfp); |
Jouni Malinen | 1965c85 | 2009-04-22 21:38:25 +0300 | [diff] [blame] | 4645 | } |
| 4646 | |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4647 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
| 4648 | struct net_device *netdev, const u8 *bssid, |
| 4649 | const u8 *req_ie, size_t req_ie_len, |
| 4650 | const u8 *resp_ie, size_t resp_ie_len, |
| 4651 | u16 status, gfp_t gfp) |
| 4652 | { |
| 4653 | struct sk_buff *msg; |
| 4654 | void *hdr; |
| 4655 | |
| 4656 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 4657 | if (!msg) |
| 4658 | return; |
| 4659 | |
| 4660 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); |
| 4661 | if (!hdr) { |
| 4662 | nlmsg_free(msg); |
| 4663 | return; |
| 4664 | } |
| 4665 | |
| 4666 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4667 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 4668 | if (bssid) |
| 4669 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 4670 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); |
| 4671 | if (req_ie) |
| 4672 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 4673 | if (resp_ie) |
| 4674 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 4675 | |
| 4676 | if (genlmsg_end(msg, hdr) < 0) { |
| 4677 | nlmsg_free(msg); |
| 4678 | return; |
| 4679 | } |
| 4680 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4681 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4682 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4683 | return; |
| 4684 | |
| 4685 | nla_put_failure: |
| 4686 | genlmsg_cancel(msg, hdr); |
| 4687 | nlmsg_free(msg); |
| 4688 | |
| 4689 | } |
| 4690 | |
| 4691 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, |
| 4692 | struct net_device *netdev, const u8 *bssid, |
| 4693 | const u8 *req_ie, size_t req_ie_len, |
| 4694 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) |
| 4695 | { |
| 4696 | struct sk_buff *msg; |
| 4697 | void *hdr; |
| 4698 | |
| 4699 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); |
| 4700 | if (!msg) |
| 4701 | return; |
| 4702 | |
| 4703 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); |
| 4704 | if (!hdr) { |
| 4705 | nlmsg_free(msg); |
| 4706 | return; |
| 4707 | } |
| 4708 | |
| 4709 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4710 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 4711 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 4712 | if (req_ie) |
| 4713 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); |
| 4714 | if (resp_ie) |
| 4715 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); |
| 4716 | |
| 4717 | if (genlmsg_end(msg, hdr) < 0) { |
| 4718 | nlmsg_free(msg); |
| 4719 | return; |
| 4720 | } |
| 4721 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4722 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4723 | nl80211_mlme_mcgrp.id, gfp); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4724 | return; |
| 4725 | |
| 4726 | nla_put_failure: |
| 4727 | genlmsg_cancel(msg, hdr); |
| 4728 | nlmsg_free(msg); |
| 4729 | |
| 4730 | } |
| 4731 | |
| 4732 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, |
| 4733 | struct net_device *netdev, u16 reason, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 4734 | const u8 *ie, size_t ie_len, bool from_ap) |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4735 | { |
| 4736 | struct sk_buff *msg; |
| 4737 | void *hdr; |
| 4738 | |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 4739 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4740 | if (!msg) |
| 4741 | return; |
| 4742 | |
| 4743 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); |
| 4744 | if (!hdr) { |
| 4745 | nlmsg_free(msg); |
| 4746 | return; |
| 4747 | } |
| 4748 | |
| 4749 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4750 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 4751 | if (from_ap && reason) |
| 4752 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); |
| 4753 | if (from_ap) |
| 4754 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); |
| 4755 | if (ie) |
| 4756 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); |
| 4757 | |
| 4758 | if (genlmsg_end(msg, hdr) < 0) { |
| 4759 | nlmsg_free(msg); |
| 4760 | return; |
| 4761 | } |
| 4762 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4763 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4764 | nl80211_mlme_mcgrp.id, GFP_KERNEL); |
Samuel Ortiz | b23aa67 | 2009-07-01 21:26:54 +0200 | [diff] [blame] | 4765 | return; |
| 4766 | |
| 4767 | nla_put_failure: |
| 4768 | genlmsg_cancel(msg, hdr); |
| 4769 | nlmsg_free(msg); |
| 4770 | |
| 4771 | } |
| 4772 | |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4773 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
| 4774 | struct net_device *netdev, const u8 *bssid, |
| 4775 | gfp_t gfp) |
| 4776 | { |
| 4777 | struct sk_buff *msg; |
| 4778 | void *hdr; |
| 4779 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4780 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4781 | if (!msg) |
| 4782 | return; |
| 4783 | |
| 4784 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); |
| 4785 | if (!hdr) { |
| 4786 | nlmsg_free(msg); |
| 4787 | return; |
| 4788 | } |
| 4789 | |
| 4790 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4791 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 4792 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); |
| 4793 | |
| 4794 | if (genlmsg_end(msg, hdr) < 0) { |
| 4795 | nlmsg_free(msg); |
| 4796 | return; |
| 4797 | } |
| 4798 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4799 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4800 | nl80211_mlme_mcgrp.id, gfp); |
Johannes Berg | 04a773a | 2009-04-19 21:24:32 +0200 | [diff] [blame] | 4801 | return; |
| 4802 | |
| 4803 | nla_put_failure: |
| 4804 | genlmsg_cancel(msg, hdr); |
| 4805 | nlmsg_free(msg); |
| 4806 | } |
| 4807 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 4808 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 4809 | struct net_device *netdev, const u8 *addr, |
| 4810 | enum nl80211_key_type key_type, int key_id, |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4811 | const u8 *tsc, gfp_t gfp) |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 4812 | { |
| 4813 | struct sk_buff *msg; |
| 4814 | void *hdr; |
| 4815 | |
Johannes Berg | e6d6e34 | 2009-07-01 21:26:47 +0200 | [diff] [blame] | 4816 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 4817 | if (!msg) |
| 4818 | return; |
| 4819 | |
| 4820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 4821 | if (!hdr) { |
| 4822 | nlmsg_free(msg); |
| 4823 | return; |
| 4824 | } |
| 4825 | |
| 4826 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 4827 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 4828 | if (addr) |
| 4829 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 4830 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
| 4831 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
| 4832 | if (tsc) |
| 4833 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 4834 | |
| 4835 | if (genlmsg_end(msg, hdr) < 0) { |
| 4836 | nlmsg_free(msg); |
| 4837 | return; |
| 4838 | } |
| 4839 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4840 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
| 4841 | nl80211_mlme_mcgrp.id, gfp); |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 4842 | return; |
| 4843 | |
| 4844 | nla_put_failure: |
| 4845 | genlmsg_cancel(msg, hdr); |
| 4846 | nlmsg_free(msg); |
| 4847 | } |
| 4848 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 4849 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 4850 | struct ieee80211_channel *channel_before, |
| 4851 | struct ieee80211_channel *channel_after) |
| 4852 | { |
| 4853 | struct sk_buff *msg; |
| 4854 | void *hdr; |
| 4855 | struct nlattr *nl_freq; |
| 4856 | |
Pablo Neira Ayuso | fd2120c | 2009-05-19 15:27:55 -0700 | [diff] [blame] | 4857 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 4858 | if (!msg) |
| 4859 | return; |
| 4860 | |
| 4861 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 4862 | if (!hdr) { |
| 4863 | nlmsg_free(msg); |
| 4864 | return; |
| 4865 | } |
| 4866 | |
| 4867 | /* |
| 4868 | * Since we are applying the beacon hint to a wiphy we know its |
| 4869 | * wiphy_idx is valid |
| 4870 | */ |
| 4871 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 4872 | |
| 4873 | /* Before */ |
| 4874 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 4875 | if (!nl_freq) |
| 4876 | goto nla_put_failure; |
| 4877 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 4878 | goto nla_put_failure; |
| 4879 | nla_nest_end(msg, nl_freq); |
| 4880 | |
| 4881 | /* After */ |
| 4882 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 4883 | if (!nl_freq) |
| 4884 | goto nla_put_failure; |
| 4885 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 4886 | goto nla_put_failure; |
| 4887 | nla_nest_end(msg, nl_freq); |
| 4888 | |
| 4889 | if (genlmsg_end(msg, hdr) < 0) { |
| 4890 | nlmsg_free(msg); |
| 4891 | return; |
| 4892 | } |
| 4893 | |
Johannes Berg | 463d018 | 2009-07-14 00:33:35 +0200 | [diff] [blame] | 4894 | rcu_read_lock(); |
| 4895 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
| 4896 | GFP_ATOMIC); |
| 4897 | rcu_read_unlock(); |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 4898 | |
| 4899 | return; |
| 4900 | |
| 4901 | nla_put_failure: |
| 4902 | genlmsg_cancel(msg, hdr); |
| 4903 | nlmsg_free(msg); |
| 4904 | } |
| 4905 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4906 | /* initialisation/exit functions */ |
| 4907 | |
| 4908 | int nl80211_init(void) |
| 4909 | { |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 4910 | int err; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4911 | |
Michał Mirosław | 0d63cbb | 2009-05-21 10:34:06 +0000 | [diff] [blame] | 4912 | err = genl_register_family_with_ops(&nl80211_fam, |
| 4913 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4914 | if (err) |
| 4915 | return err; |
| 4916 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4917 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 4918 | if (err) |
| 4919 | goto err_out; |
| 4920 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 4921 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 4922 | if (err) |
| 4923 | goto err_out; |
| 4924 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 4925 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 4926 | if (err) |
| 4927 | goto err_out; |
| 4928 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 4929 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 4930 | if (err) |
| 4931 | goto err_out; |
| 4932 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 4933 | #ifdef CONFIG_NL80211_TESTMODE |
| 4934 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); |
| 4935 | if (err) |
| 4936 | goto err_out; |
| 4937 | #endif |
| 4938 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 4939 | return 0; |
| 4940 | err_out: |
| 4941 | genl_unregister_family(&nl80211_fam); |
| 4942 | return err; |
| 4943 | } |
| 4944 | |
| 4945 | void nl80211_exit(void) |
| 4946 | { |
| 4947 | genl_unregister_family(&nl80211_fam); |
| 4948 | } |