Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This is the new netlink-based wireless configuration interface. |
| 3 | * |
| 4 | * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net> |
| 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 | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 17 | #include <net/genetlink.h> |
| 18 | #include <net/cfg80211.h> |
| 19 | #include "core.h" |
| 20 | #include "nl80211.h" |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 21 | #include "reg.h" |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 22 | |
| 23 | /* the netlink family */ |
| 24 | static struct genl_family nl80211_fam = { |
| 25 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
| 26 | .name = "nl80211", /* have users key off the name instead */ |
| 27 | .hdrsize = 0, /* no private header */ |
| 28 | .version = 1, /* no particular meaning now */ |
| 29 | .maxattr = NL80211_ATTR_MAX, |
| 30 | }; |
| 31 | |
| 32 | /* internal helper: get drv and dev */ |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 33 | static int get_drv_dev_by_info_ifindex(struct nlattr **attrs, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 34 | struct cfg80211_registered_device **drv, |
| 35 | struct net_device **dev) |
| 36 | { |
| 37 | int ifindex; |
| 38 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 39 | if (!attrs[NL80211_ATTR_IFINDEX]) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 40 | return -EINVAL; |
| 41 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 42 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 43 | *dev = dev_get_by_index(&init_net, ifindex); |
| 44 | if (!*dev) |
| 45 | return -ENODEV; |
| 46 | |
| 47 | *drv = cfg80211_get_dev_from_ifindex(ifindex); |
| 48 | if (IS_ERR(*drv)) { |
| 49 | dev_put(*dev); |
| 50 | return PTR_ERR(*drv); |
| 51 | } |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | /* policy for the attributes */ |
| 57 | static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = { |
| 58 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
| 59 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, |
| 60 | .len = BUS_ID_SIZE-1 }, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 61 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 62 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 63 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 64 | |
| 65 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 66 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 67 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 68 | |
| 69 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
| 70 | |
| 71 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 72 | .len = WLAN_MAX_KEY_LEN }, |
| 73 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 74 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 75 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 76 | |
| 77 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 78 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 79 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 80 | .len = IEEE80211_MAX_DATA_LEN }, |
| 81 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 82 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 83 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 84 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 85 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 86 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 87 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 88 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 89 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 90 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 91 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 92 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 93 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 94 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 95 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 96 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 97 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 98 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 99 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 100 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 101 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 102 | .len = NL80211_MAX_SUPP_RATES }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 103 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 104 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
| 105 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 106 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 107 | .len = NL80211_HT_CAPABILITY_LEN }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 108 | |
| 109 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, |
| 110 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, |
| 111 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 112 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
| 113 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 114 | |
| 115 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, |
| 116 | .len = IEEE80211_MAX_SSID_LEN }, |
| 117 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, |
| 118 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 119 | }; |
| 120 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 121 | /* IE validation */ |
| 122 | static bool is_valid_ie_attr(const struct nlattr *attr) |
| 123 | { |
| 124 | const u8 *pos; |
| 125 | int len; |
| 126 | |
| 127 | if (!attr) |
| 128 | return true; |
| 129 | |
| 130 | pos = nla_data(attr); |
| 131 | len = nla_len(attr); |
| 132 | |
| 133 | while (len) { |
| 134 | u8 elemlen; |
| 135 | |
| 136 | if (len < 2) |
| 137 | return false; |
| 138 | len -= 2; |
| 139 | |
| 140 | elemlen = pos[1]; |
| 141 | if (elemlen > len) |
| 142 | return false; |
| 143 | |
| 144 | len -= elemlen; |
| 145 | pos += 2 + elemlen; |
| 146 | } |
| 147 | |
| 148 | return true; |
| 149 | } |
| 150 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 151 | /* message building helper */ |
| 152 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 153 | int flags, u8 cmd) |
| 154 | { |
| 155 | /* since there is no private header just add the generic one */ |
| 156 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 157 | } |
| 158 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 159 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
| 160 | struct ieee80211_channel *chan) |
| 161 | { |
| 162 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 163 | chan->center_freq); |
| 164 | |
| 165 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 166 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 167 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 168 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 169 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 170 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 171 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 172 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 173 | |
| 174 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
| 175 | DBM_TO_MBM(chan->max_power)); |
| 176 | |
| 177 | return 0; |
| 178 | |
| 179 | nla_put_failure: |
| 180 | return -ENOBUFS; |
| 181 | } |
| 182 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 183 | /* netlink command implementations */ |
| 184 | |
| 185 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 186 | struct cfg80211_registered_device *dev) |
| 187 | { |
| 188 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 189 | struct nlattr *nl_bands, *nl_band; |
| 190 | struct nlattr *nl_freqs, *nl_freq; |
| 191 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 192 | struct nlattr *nl_modes; |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 193 | struct nlattr *nl_cmds; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 194 | enum ieee80211_band band; |
| 195 | struct ieee80211_channel *chan; |
| 196 | struct ieee80211_rate *rate; |
| 197 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 198 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 199 | |
| 200 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 201 | if (!hdr) |
| 202 | return -1; |
| 203 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 204 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 205 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 206 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
| 207 | dev->wiphy.max_scan_ssids); |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 208 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
| 209 | dev->wiphy.max_scan_ie_len); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 210 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 211 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
| 212 | sizeof(u32) * dev->wiphy.n_cipher_suites, |
| 213 | dev->wiphy.cipher_suites); |
| 214 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 215 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 216 | if (!nl_modes) |
| 217 | goto nla_put_failure; |
| 218 | |
| 219 | i = 0; |
| 220 | while (ifmodes) { |
| 221 | if (ifmodes & 1) |
| 222 | NLA_PUT_FLAG(msg, i); |
| 223 | ifmodes >>= 1; |
| 224 | i++; |
| 225 | } |
| 226 | |
| 227 | nla_nest_end(msg, nl_modes); |
| 228 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 229 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 230 | if (!nl_bands) |
| 231 | goto nla_put_failure; |
| 232 | |
| 233 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 234 | if (!dev->wiphy.bands[band]) |
| 235 | continue; |
| 236 | |
| 237 | nl_band = nla_nest_start(msg, band); |
| 238 | if (!nl_band) |
| 239 | goto nla_put_failure; |
| 240 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 241 | /* add HT info */ |
| 242 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 243 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 244 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 245 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 246 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 247 | dev->wiphy.bands[band]->ht_cap.cap); |
| 248 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 249 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 250 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 251 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 252 | } |
| 253 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 254 | /* add frequencies */ |
| 255 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 256 | if (!nl_freqs) |
| 257 | goto nla_put_failure; |
| 258 | |
| 259 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 260 | nl_freq = nla_nest_start(msg, i); |
| 261 | if (!nl_freq) |
| 262 | goto nla_put_failure; |
| 263 | |
| 264 | chan = &dev->wiphy.bands[band]->channels[i]; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 265 | |
Luis R. Rodriguez | 5dab3b8 | 2009-04-02 14:08:08 -0400 | [diff] [blame] | 266 | if (nl80211_msg_put_channel(msg, chan)) |
| 267 | goto nla_put_failure; |
Jouni Malinen | e2f367f26 | 2008-11-21 19:01:30 +0200 | [diff] [blame] | 268 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 269 | nla_nest_end(msg, nl_freq); |
| 270 | } |
| 271 | |
| 272 | nla_nest_end(msg, nl_freqs); |
| 273 | |
| 274 | /* add bitrates */ |
| 275 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 276 | if (!nl_rates) |
| 277 | goto nla_put_failure; |
| 278 | |
| 279 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 280 | nl_rate = nla_nest_start(msg, i); |
| 281 | if (!nl_rate) |
| 282 | goto nla_put_failure; |
| 283 | |
| 284 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 285 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 286 | rate->bitrate); |
| 287 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 288 | NLA_PUT_FLAG(msg, |
| 289 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 290 | |
| 291 | nla_nest_end(msg, nl_rate); |
| 292 | } |
| 293 | |
| 294 | nla_nest_end(msg, nl_rates); |
| 295 | |
| 296 | nla_nest_end(msg, nl_band); |
| 297 | } |
| 298 | nla_nest_end(msg, nl_bands); |
| 299 | |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 300 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
| 301 | if (!nl_cmds) |
| 302 | goto nla_put_failure; |
| 303 | |
| 304 | i = 0; |
| 305 | #define CMD(op, n) \ |
| 306 | do { \ |
| 307 | if (dev->ops->op) { \ |
| 308 | i++; \ |
| 309 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ |
| 310 | } \ |
| 311 | } while (0) |
| 312 | |
| 313 | CMD(add_virtual_intf, NEW_INTERFACE); |
| 314 | CMD(change_virtual_intf, SET_INTERFACE); |
| 315 | CMD(add_key, NEW_KEY); |
| 316 | CMD(add_beacon, NEW_BEACON); |
| 317 | CMD(add_station, NEW_STATION); |
| 318 | CMD(add_mpath, NEW_MPATH); |
| 319 | CMD(set_mesh_params, SET_MESH_PARAMS); |
| 320 | CMD(change_bss, SET_BSS); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 321 | CMD(auth, AUTHENTICATE); |
| 322 | CMD(assoc, ASSOCIATE); |
| 323 | CMD(deauth, DEAUTHENTICATE); |
| 324 | CMD(disassoc, DISASSOCIATE); |
Johannes Berg | 8fdc621 | 2009-03-14 09:34:01 +0100 | [diff] [blame] | 325 | |
| 326 | #undef CMD |
| 327 | nla_nest_end(msg, nl_cmds); |
| 328 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 329 | return genlmsg_end(msg, hdr); |
| 330 | |
| 331 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 332 | genlmsg_cancel(msg, hdr); |
| 333 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 337 | { |
| 338 | int idx = 0; |
| 339 | int start = cb->args[0]; |
| 340 | struct cfg80211_registered_device *dev; |
| 341 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 342 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 343 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 344 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 345 | continue; |
| 346 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 347 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 348 | dev) < 0) { |
| 349 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 350 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 351 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 352 | } |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 353 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 354 | |
| 355 | cb->args[0] = idx; |
| 356 | |
| 357 | return skb->len; |
| 358 | } |
| 359 | |
| 360 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 361 | { |
| 362 | struct sk_buff *msg; |
| 363 | struct cfg80211_registered_device *dev; |
| 364 | |
| 365 | dev = cfg80211_get_dev_from_info(info); |
| 366 | if (IS_ERR(dev)) |
| 367 | return PTR_ERR(dev); |
| 368 | |
| 369 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 370 | if (!msg) |
| 371 | goto out_err; |
| 372 | |
| 373 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) |
| 374 | goto out_free; |
| 375 | |
| 376 | cfg80211_put_dev(dev); |
| 377 | |
| 378 | return genlmsg_unicast(msg, info->snd_pid); |
| 379 | |
| 380 | out_free: |
| 381 | nlmsg_free(msg); |
| 382 | out_err: |
| 383 | cfg80211_put_dev(dev); |
| 384 | return -ENOBUFS; |
| 385 | } |
| 386 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 387 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
| 388 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, |
| 389 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, |
| 390 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, |
| 391 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, |
| 392 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, |
| 393 | }; |
| 394 | |
| 395 | static int parse_txq_params(struct nlattr *tb[], |
| 396 | struct ieee80211_txq_params *txq_params) |
| 397 | { |
| 398 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || |
| 399 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
| 400 | !tb[NL80211_TXQ_ATTR_AIFS]) |
| 401 | return -EINVAL; |
| 402 | |
| 403 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); |
| 404 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
| 405 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); |
| 406 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); |
| 407 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); |
| 408 | |
| 409 | return 0; |
| 410 | } |
| 411 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 412 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 413 | { |
| 414 | struct cfg80211_registered_device *rdev; |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 415 | int result = 0, rem_txq_params = 0; |
| 416 | struct nlattr *nl_txq_params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 417 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 418 | rtnl_lock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 419 | |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 420 | mutex_lock(&cfg80211_mutex); |
| 421 | |
| 422 | rdev = __cfg80211_drv_from_info(info); |
| 423 | if (IS_ERR(rdev)) { |
| 424 | result = PTR_ERR(rdev); |
| 425 | goto unlock; |
| 426 | } |
| 427 | |
| 428 | mutex_lock(&rdev->mtx); |
| 429 | |
| 430 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 431 | result = cfg80211_dev_rename( |
| 432 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 433 | |
| 434 | mutex_unlock(&cfg80211_mutex); |
| 435 | |
| 436 | if (result) |
| 437 | goto bad_res; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 438 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 439 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { |
| 440 | struct ieee80211_txq_params txq_params; |
| 441 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; |
| 442 | |
| 443 | if (!rdev->ops->set_txq_params) { |
| 444 | result = -EOPNOTSUPP; |
| 445 | goto bad_res; |
| 446 | } |
| 447 | |
| 448 | nla_for_each_nested(nl_txq_params, |
| 449 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], |
| 450 | rem_txq_params) { |
| 451 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
| 452 | nla_data(nl_txq_params), |
| 453 | nla_len(nl_txq_params), |
| 454 | txq_params_policy); |
| 455 | result = parse_txq_params(tb, &txq_params); |
| 456 | if (result) |
| 457 | goto bad_res; |
| 458 | |
| 459 | result = rdev->ops->set_txq_params(&rdev->wiphy, |
| 460 | &txq_params); |
| 461 | if (result) |
| 462 | goto bad_res; |
| 463 | } |
| 464 | } |
| 465 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 466 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 467 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 468 | struct ieee80211_channel *chan; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 469 | struct ieee80211_sta_ht_cap *ht_cap; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 470 | u32 freq, sec_freq; |
| 471 | |
| 472 | if (!rdev->ops->set_channel) { |
| 473 | result = -EOPNOTSUPP; |
| 474 | goto bad_res; |
| 475 | } |
| 476 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 477 | result = -EINVAL; |
| 478 | |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 479 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 480 | channel_type = nla_get_u32(info->attrs[ |
| 481 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 482 | if (channel_type != NL80211_CHAN_NO_HT && |
| 483 | channel_type != NL80211_CHAN_HT20 && |
| 484 | channel_type != NL80211_CHAN_HT40PLUS && |
| 485 | channel_type != NL80211_CHAN_HT40MINUS) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 486 | goto bad_res; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 487 | } |
| 488 | |
| 489 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); |
| 490 | chan = ieee80211_get_channel(&rdev->wiphy, freq); |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 491 | |
| 492 | /* Primary channel not allowed */ |
| 493 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 494 | goto bad_res; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 495 | |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 496 | if (channel_type == NL80211_CHAN_HT40MINUS) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 497 | sec_freq = freq - 20; |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 498 | else if (channel_type == NL80211_CHAN_HT40PLUS) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 499 | sec_freq = freq + 20; |
| 500 | else |
| 501 | sec_freq = 0; |
| 502 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 503 | ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap; |
| 504 | |
| 505 | /* no HT capabilities */ |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 506 | if (channel_type != NL80211_CHAN_NO_HT && |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 507 | !ht_cap->ht_supported) |
| 508 | goto bad_res; |
| 509 | |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 510 | if (sec_freq) { |
| 511 | struct ieee80211_channel *schan; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 512 | |
| 513 | /* no 40 MHz capabilities */ |
| 514 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || |
| 515 | (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)) |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 516 | goto bad_res; |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 517 | |
| 518 | schan = ieee80211_get_channel(&rdev->wiphy, sec_freq); |
| 519 | |
| 520 | /* Secondary channel not allowed */ |
| 521 | if (!schan || schan->flags & IEEE80211_CHAN_DISABLED) |
| 522 | goto bad_res; |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | result = rdev->ops->set_channel(&rdev->wiphy, chan, |
Sujith | 094d05d | 2008-12-12 11:57:43 +0530 | [diff] [blame] | 526 | channel_type); |
Jouni Malinen | 72bdcf3 | 2008-11-26 16:15:24 +0200 | [diff] [blame] | 527 | if (result) |
| 528 | goto bad_res; |
| 529 | } |
| 530 | |
| 531 | |
Johannes Berg | 306d611 | 2008-12-08 12:39:04 +0100 | [diff] [blame] | 532 | bad_res: |
Johannes Berg | 4bbf4d5 | 2009-03-24 09:35:46 +0100 | [diff] [blame] | 533 | mutex_unlock(&rdev->mtx); |
| 534 | unlock: |
| 535 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 536 | return result; |
| 537 | } |
| 538 | |
| 539 | |
| 540 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 541 | struct net_device *dev) |
| 542 | { |
| 543 | void *hdr; |
| 544 | |
| 545 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 546 | if (!hdr) |
| 547 | return -1; |
| 548 | |
| 549 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 550 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 551 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 552 | return genlmsg_end(msg, hdr); |
| 553 | |
| 554 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 555 | genlmsg_cancel(msg, hdr); |
| 556 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 560 | { |
| 561 | int wp_idx = 0; |
| 562 | int if_idx = 0; |
| 563 | int wp_start = cb->args[0]; |
| 564 | int if_start = cb->args[1]; |
| 565 | struct cfg80211_registered_device *dev; |
| 566 | struct wireless_dev *wdev; |
| 567 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 568 | mutex_lock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 569 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 570 | if (wp_idx < wp_start) { |
| 571 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 572 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 573 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 574 | if_idx = 0; |
| 575 | |
| 576 | mutex_lock(&dev->devlist_mtx); |
| 577 | list_for_each_entry(wdev, &dev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 578 | if (if_idx < if_start) { |
| 579 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 580 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 581 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 582 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 583 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 584 | wdev->netdev) < 0) { |
| 585 | mutex_unlock(&dev->devlist_mtx); |
| 586 | goto out; |
| 587 | } |
| 588 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 589 | } |
| 590 | mutex_unlock(&dev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 591 | |
| 592 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 593 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 594 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 595 | mutex_unlock(&cfg80211_mutex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 596 | |
| 597 | cb->args[0] = wp_idx; |
| 598 | cb->args[1] = if_idx; |
| 599 | |
| 600 | return skb->len; |
| 601 | } |
| 602 | |
| 603 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 604 | { |
| 605 | struct sk_buff *msg; |
| 606 | struct cfg80211_registered_device *dev; |
| 607 | struct net_device *netdev; |
| 608 | int err; |
| 609 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 610 | err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 611 | if (err) |
| 612 | return err; |
| 613 | |
| 614 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 615 | if (!msg) |
| 616 | goto out_err; |
| 617 | |
| 618 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0) |
| 619 | goto out_free; |
| 620 | |
| 621 | dev_put(netdev); |
| 622 | cfg80211_put_dev(dev); |
| 623 | |
| 624 | return genlmsg_unicast(msg, info->snd_pid); |
| 625 | |
| 626 | out_free: |
| 627 | nlmsg_free(msg); |
| 628 | out_err: |
| 629 | dev_put(netdev); |
| 630 | cfg80211_put_dev(dev); |
| 631 | return -ENOBUFS; |
| 632 | } |
| 633 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 634 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 635 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 636 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 637 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 638 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 639 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 640 | }; |
| 641 | |
| 642 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 643 | { |
| 644 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 645 | int flag; |
| 646 | |
| 647 | *mntrflags = 0; |
| 648 | |
| 649 | if (!nla) |
| 650 | return -EINVAL; |
| 651 | |
| 652 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 653 | nla, mntr_flags_policy)) |
| 654 | return -EINVAL; |
| 655 | |
| 656 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 657 | if (flags[flag]) |
| 658 | *mntrflags |= (1<<flag); |
| 659 | |
| 660 | return 0; |
| 661 | } |
| 662 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 663 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 664 | { |
| 665 | struct cfg80211_registered_device *drv; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 666 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 667 | int err, ifindex; |
| 668 | enum nl80211_iftype type; |
| 669 | struct net_device *dev; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 670 | u32 _flags, *flags = NULL; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 671 | bool change = false; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 672 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 673 | memset(¶ms, 0, sizeof(params)); |
| 674 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 675 | rtnl_lock(); |
| 676 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 677 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 678 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 679 | goto unlock_rtnl; |
| 680 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 681 | ifindex = dev->ifindex; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 682 | type = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 683 | dev_put(dev); |
| 684 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 685 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 686 | enum nl80211_iftype ntype; |
| 687 | |
| 688 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 689 | if (type != ntype) |
| 690 | change = true; |
| 691 | type = ntype; |
| 692 | if (type > NL80211_IFTYPE_MAX) { |
| 693 | err = -EINVAL; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 694 | goto unlock; |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 695 | } |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 696 | } |
| 697 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 698 | if (!drv->ops->change_virtual_intf || |
| 699 | !(drv->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 700 | err = -EOPNOTSUPP; |
| 701 | goto unlock; |
| 702 | } |
| 703 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 704 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
| 705 | if (type != NL80211_IFTYPE_MESH_POINT) { |
| 706 | err = -EINVAL; |
| 707 | goto unlock; |
| 708 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 709 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 710 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 711 | change = true; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 712 | } |
| 713 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 714 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 715 | if (type != NL80211_IFTYPE_MONITOR) { |
| 716 | err = -EINVAL; |
| 717 | goto unlock; |
| 718 | } |
| 719 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 720 | &_flags); |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 721 | if (err) |
| 722 | goto unlock; |
| 723 | |
| 724 | flags = &_flags; |
| 725 | change = true; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 726 | } |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 727 | |
Johannes Berg | ac7f9cf | 2009-03-21 17:07:59 +0100 | [diff] [blame] | 728 | if (change) |
| 729 | err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, |
| 730 | type, flags, ¶ms); |
| 731 | else |
| 732 | err = 0; |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 733 | |
| 734 | dev = __dev_get_by_index(&init_net, ifindex); |
| 735 | WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type)); |
| 736 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 737 | unlock: |
| 738 | cfg80211_put_dev(drv); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 739 | unlock_rtnl: |
| 740 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 741 | return err; |
| 742 | } |
| 743 | |
| 744 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 745 | { |
| 746 | struct cfg80211_registered_device *drv; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 747 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 748 | int err; |
| 749 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 750 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 751 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 752 | memset(¶ms, 0, sizeof(params)); |
| 753 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 754 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 755 | return -EINVAL; |
| 756 | |
| 757 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 758 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 759 | if (type > NL80211_IFTYPE_MAX) |
| 760 | return -EINVAL; |
| 761 | } |
| 762 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 763 | rtnl_lock(); |
| 764 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 765 | drv = cfg80211_get_dev_from_info(info); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 766 | if (IS_ERR(drv)) { |
| 767 | err = PTR_ERR(drv); |
| 768 | goto unlock_rtnl; |
| 769 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 770 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 771 | if (!drv->ops->add_virtual_intf || |
| 772 | !(drv->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 773 | err = -EOPNOTSUPP; |
| 774 | goto unlock; |
| 775 | } |
| 776 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 777 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 778 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 779 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 780 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 781 | } |
| 782 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 783 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 784 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 785 | &flags); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 786 | err = drv->ops->add_virtual_intf(&drv->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 787 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 788 | type, err ? NULL : &flags, ¶ms); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 789 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 790 | unlock: |
| 791 | cfg80211_put_dev(drv); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 792 | unlock_rtnl: |
| 793 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 794 | return err; |
| 795 | } |
| 796 | |
| 797 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 798 | { |
| 799 | struct cfg80211_registered_device *drv; |
| 800 | int ifindex, err; |
| 801 | struct net_device *dev; |
| 802 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 803 | rtnl_lock(); |
| 804 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 805 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 806 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 807 | goto unlock_rtnl; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 808 | ifindex = dev->ifindex; |
| 809 | dev_put(dev); |
| 810 | |
| 811 | if (!drv->ops->del_virtual_intf) { |
| 812 | err = -EOPNOTSUPP; |
| 813 | goto out; |
| 814 | } |
| 815 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 816 | err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 817 | |
| 818 | out: |
| 819 | cfg80211_put_dev(drv); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 820 | unlock_rtnl: |
| 821 | rtnl_unlock(); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 822 | return err; |
| 823 | } |
| 824 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 825 | struct get_key_cookie { |
| 826 | struct sk_buff *msg; |
| 827 | int error; |
| 828 | }; |
| 829 | |
| 830 | static void get_key_callback(void *c, struct key_params *params) |
| 831 | { |
| 832 | struct get_key_cookie *cookie = c; |
| 833 | |
| 834 | if (params->key) |
| 835 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 836 | params->key_len, params->key); |
| 837 | |
| 838 | if (params->seq) |
| 839 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 840 | params->seq_len, params->seq); |
| 841 | |
| 842 | if (params->cipher) |
| 843 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 844 | params->cipher); |
| 845 | |
| 846 | return; |
| 847 | nla_put_failure: |
| 848 | cookie->error = 1; |
| 849 | } |
| 850 | |
| 851 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 852 | { |
| 853 | struct cfg80211_registered_device *drv; |
| 854 | int err; |
| 855 | struct net_device *dev; |
| 856 | u8 key_idx = 0; |
| 857 | u8 *mac_addr = NULL; |
| 858 | struct get_key_cookie cookie = { |
| 859 | .error = 0, |
| 860 | }; |
| 861 | void *hdr; |
| 862 | struct sk_buff *msg; |
| 863 | |
| 864 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 865 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 866 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 867 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 868 | return -EINVAL; |
| 869 | |
| 870 | if (info->attrs[NL80211_ATTR_MAC]) |
| 871 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 872 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 873 | rtnl_lock(); |
| 874 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 875 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 876 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 877 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 878 | |
| 879 | if (!drv->ops->get_key) { |
| 880 | err = -EOPNOTSUPP; |
| 881 | goto out; |
| 882 | } |
| 883 | |
| 884 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 885 | if (!msg) { |
| 886 | err = -ENOMEM; |
| 887 | goto out; |
| 888 | } |
| 889 | |
| 890 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 891 | NL80211_CMD_NEW_KEY); |
| 892 | |
| 893 | if (IS_ERR(hdr)) { |
| 894 | err = PTR_ERR(hdr); |
| 895 | goto out; |
| 896 | } |
| 897 | |
| 898 | cookie.msg = msg; |
| 899 | |
| 900 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 901 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 902 | if (mac_addr) |
| 903 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 904 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 905 | err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr, |
| 906 | &cookie, get_key_callback); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 907 | |
| 908 | if (err) |
| 909 | goto out; |
| 910 | |
| 911 | if (cookie.error) |
| 912 | goto nla_put_failure; |
| 913 | |
| 914 | genlmsg_end(msg, hdr); |
| 915 | err = genlmsg_unicast(msg, info->snd_pid); |
| 916 | goto out; |
| 917 | |
| 918 | nla_put_failure: |
| 919 | err = -ENOBUFS; |
| 920 | nlmsg_free(msg); |
| 921 | out: |
| 922 | cfg80211_put_dev(drv); |
| 923 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 924 | unlock_rtnl: |
| 925 | rtnl_unlock(); |
| 926 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 927 | return err; |
| 928 | } |
| 929 | |
| 930 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 931 | { |
| 932 | struct cfg80211_registered_device *drv; |
| 933 | int err; |
| 934 | struct net_device *dev; |
| 935 | u8 key_idx; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 936 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, |
| 937 | u8 key_index); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 938 | |
| 939 | if (!info->attrs[NL80211_ATTR_KEY_IDX]) |
| 940 | return -EINVAL; |
| 941 | |
| 942 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 943 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 944 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) { |
| 945 | if (key_idx < 4 || key_idx > 5) |
| 946 | return -EINVAL; |
| 947 | } else if (key_idx > 3) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 948 | return -EINVAL; |
| 949 | |
| 950 | /* currently only support setting default key */ |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 951 | if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] && |
| 952 | !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 953 | return -EINVAL; |
| 954 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 955 | rtnl_lock(); |
| 956 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 957 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 958 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 959 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 960 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 961 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT]) |
| 962 | func = drv->ops->set_default_key; |
| 963 | else |
| 964 | func = drv->ops->set_default_mgmt_key; |
| 965 | |
| 966 | if (!func) { |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 967 | err = -EOPNOTSUPP; |
| 968 | goto out; |
| 969 | } |
| 970 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 971 | err = func(&drv->wiphy, dev, key_idx); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 972 | |
| 973 | out: |
| 974 | cfg80211_put_dev(drv); |
| 975 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 976 | |
| 977 | unlock_rtnl: |
| 978 | rtnl_unlock(); |
| 979 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 980 | return err; |
| 981 | } |
| 982 | |
| 983 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 984 | { |
| 985 | struct cfg80211_registered_device *drv; |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 986 | int err, i; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 987 | struct net_device *dev; |
| 988 | struct key_params params; |
| 989 | u8 key_idx = 0; |
| 990 | u8 *mac_addr = NULL; |
| 991 | |
| 992 | memset(¶ms, 0, sizeof(params)); |
| 993 | |
| 994 | if (!info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 995 | return -EINVAL; |
| 996 | |
| 997 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 998 | params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 999 | params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 1000 | } |
| 1001 | |
| 1002 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1003 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1004 | |
| 1005 | params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 1006 | |
| 1007 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1008 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1009 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1010 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1011 | return -EINVAL; |
| 1012 | |
| 1013 | /* |
| 1014 | * Disallow pairwise keys with non-zero index unless it's WEP |
| 1015 | * (because current deployments use pairwise WEP keys with |
| 1016 | * non-zero indizes but 802.11i clearly specifies to use zero) |
| 1017 | */ |
| 1018 | if (mac_addr && key_idx && |
| 1019 | params.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 1020 | params.cipher != WLAN_CIPHER_SUITE_WEP104) |
| 1021 | return -EINVAL; |
| 1022 | |
| 1023 | /* TODO: add definitions for the lengths to linux/ieee80211.h */ |
| 1024 | switch (params.cipher) { |
| 1025 | case WLAN_CIPHER_SUITE_WEP40: |
| 1026 | if (params.key_len != 5) |
| 1027 | return -EINVAL; |
| 1028 | break; |
| 1029 | case WLAN_CIPHER_SUITE_TKIP: |
| 1030 | if (params.key_len != 32) |
| 1031 | return -EINVAL; |
| 1032 | break; |
| 1033 | case WLAN_CIPHER_SUITE_CCMP: |
| 1034 | if (params.key_len != 16) |
| 1035 | return -EINVAL; |
| 1036 | break; |
| 1037 | case WLAN_CIPHER_SUITE_WEP104: |
| 1038 | if (params.key_len != 13) |
| 1039 | return -EINVAL; |
| 1040 | break; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1041 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1042 | if (params.key_len != 16) |
| 1043 | return -EINVAL; |
| 1044 | break; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1045 | default: |
| 1046 | return -EINVAL; |
| 1047 | } |
| 1048 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1049 | rtnl_lock(); |
| 1050 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1051 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1052 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1053 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1054 | |
Johannes Berg | 25e47c1 | 2009-04-02 20:14:06 +0200 | [diff] [blame] | 1055 | for (i = 0; i < drv->wiphy.n_cipher_suites; i++) |
| 1056 | if (params.cipher == drv->wiphy.cipher_suites[i]) |
| 1057 | break; |
| 1058 | if (i == drv->wiphy.n_cipher_suites) { |
| 1059 | err = -EINVAL; |
| 1060 | goto out; |
| 1061 | } |
| 1062 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1063 | if (!drv->ops->add_key) { |
| 1064 | err = -EOPNOTSUPP; |
| 1065 | goto out; |
| 1066 | } |
| 1067 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1068 | err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1069 | |
| 1070 | out: |
| 1071 | cfg80211_put_dev(drv); |
| 1072 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1073 | unlock_rtnl: |
| 1074 | rtnl_unlock(); |
| 1075 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1076 | return err; |
| 1077 | } |
| 1078 | |
| 1079 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 1080 | { |
| 1081 | struct cfg80211_registered_device *drv; |
| 1082 | int err; |
| 1083 | struct net_device *dev; |
| 1084 | u8 key_idx = 0; |
| 1085 | u8 *mac_addr = NULL; |
| 1086 | |
| 1087 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 1088 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 1089 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1090 | if (key_idx > 5) |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1091 | return -EINVAL; |
| 1092 | |
| 1093 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1094 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1095 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1096 | rtnl_lock(); |
| 1097 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1098 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1099 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1100 | goto unlock_rtnl; |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1101 | |
| 1102 | if (!drv->ops->del_key) { |
| 1103 | err = -EOPNOTSUPP; |
| 1104 | goto out; |
| 1105 | } |
| 1106 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1107 | err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1108 | |
| 1109 | out: |
| 1110 | cfg80211_put_dev(drv); |
| 1111 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1112 | |
| 1113 | unlock_rtnl: |
| 1114 | rtnl_unlock(); |
| 1115 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1116 | return err; |
| 1117 | } |
| 1118 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1119 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1120 | { |
| 1121 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 1122 | struct beacon_parameters *info); |
| 1123 | struct cfg80211_registered_device *drv; |
| 1124 | int err; |
| 1125 | struct net_device *dev; |
| 1126 | struct beacon_parameters params; |
| 1127 | int haveinfo = 0; |
| 1128 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 1129 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
| 1130 | return -EINVAL; |
| 1131 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1132 | rtnl_lock(); |
| 1133 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1134 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1135 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1136 | goto unlock_rtnl; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1137 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1138 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 1139 | err = -EOPNOTSUPP; |
| 1140 | goto out; |
| 1141 | } |
| 1142 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1143 | switch (info->genlhdr->cmd) { |
| 1144 | case NL80211_CMD_NEW_BEACON: |
| 1145 | /* these are required for NEW_BEACON */ |
| 1146 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 1147 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 1148 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1149 | err = -EINVAL; |
| 1150 | goto out; |
| 1151 | } |
| 1152 | |
| 1153 | call = drv->ops->add_beacon; |
| 1154 | break; |
| 1155 | case NL80211_CMD_SET_BEACON: |
| 1156 | call = drv->ops->set_beacon; |
| 1157 | break; |
| 1158 | default: |
| 1159 | WARN_ON(1); |
| 1160 | err = -EOPNOTSUPP; |
| 1161 | goto out; |
| 1162 | } |
| 1163 | |
| 1164 | if (!call) { |
| 1165 | err = -EOPNOTSUPP; |
| 1166 | goto out; |
| 1167 | } |
| 1168 | |
| 1169 | memset(¶ms, 0, sizeof(params)); |
| 1170 | |
| 1171 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 1172 | params.interval = |
| 1173 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 1174 | haveinfo = 1; |
| 1175 | } |
| 1176 | |
| 1177 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 1178 | params.dtim_period = |
| 1179 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 1180 | haveinfo = 1; |
| 1181 | } |
| 1182 | |
| 1183 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 1184 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1185 | params.head_len = |
| 1186 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 1187 | haveinfo = 1; |
| 1188 | } |
| 1189 | |
| 1190 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 1191 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1192 | params.tail_len = |
| 1193 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 1194 | haveinfo = 1; |
| 1195 | } |
| 1196 | |
| 1197 | if (!haveinfo) { |
| 1198 | err = -EINVAL; |
| 1199 | goto out; |
| 1200 | } |
| 1201 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1202 | err = call(&drv->wiphy, dev, ¶ms); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1203 | |
| 1204 | out: |
| 1205 | cfg80211_put_dev(drv); |
| 1206 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1207 | unlock_rtnl: |
| 1208 | rtnl_unlock(); |
| 1209 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1210 | return err; |
| 1211 | } |
| 1212 | |
| 1213 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 1214 | { |
| 1215 | struct cfg80211_registered_device *drv; |
| 1216 | int err; |
| 1217 | struct net_device *dev; |
| 1218 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1219 | rtnl_lock(); |
| 1220 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1221 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1222 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1223 | goto unlock_rtnl; |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1224 | |
| 1225 | if (!drv->ops->del_beacon) { |
| 1226 | err = -EOPNOTSUPP; |
| 1227 | goto out; |
| 1228 | } |
| 1229 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1230 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 1231 | err = -EOPNOTSUPP; |
| 1232 | goto out; |
| 1233 | } |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1234 | err = drv->ops->del_beacon(&drv->wiphy, dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1235 | |
| 1236 | out: |
| 1237 | cfg80211_put_dev(drv); |
| 1238 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1239 | unlock_rtnl: |
| 1240 | rtnl_unlock(); |
| 1241 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 1242 | return err; |
| 1243 | } |
| 1244 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1245 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 1246 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 1247 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 1248 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
| 1249 | }; |
| 1250 | |
| 1251 | static int parse_station_flags(struct nlattr *nla, u32 *staflags) |
| 1252 | { |
| 1253 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
| 1254 | int flag; |
| 1255 | |
| 1256 | *staflags = 0; |
| 1257 | |
| 1258 | if (!nla) |
| 1259 | return 0; |
| 1260 | |
| 1261 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 1262 | nla, sta_flags_policy)) |
| 1263 | return -EINVAL; |
| 1264 | |
| 1265 | *staflags = STATION_FLAG_CHANGED; |
| 1266 | |
| 1267 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 1268 | if (flags[flag]) |
| 1269 | *staflags |= (1<<flag); |
| 1270 | |
| 1271 | return 0; |
| 1272 | } |
| 1273 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1274 | static u16 nl80211_calculate_bitrate(struct rate_info *rate) |
| 1275 | { |
| 1276 | int modulation, streams, bitrate; |
| 1277 | |
| 1278 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) |
| 1279 | return rate->legacy; |
| 1280 | |
| 1281 | /* the formula below does only work for MCS values smaller than 32 */ |
| 1282 | if (rate->mcs >= 32) |
| 1283 | return 0; |
| 1284 | |
| 1285 | modulation = rate->mcs & 7; |
| 1286 | streams = (rate->mcs >> 3) + 1; |
| 1287 | |
| 1288 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? |
| 1289 | 13500000 : 6500000; |
| 1290 | |
| 1291 | if (modulation < 4) |
| 1292 | bitrate *= (modulation + 1); |
| 1293 | else if (modulation == 4) |
| 1294 | bitrate *= (modulation + 2); |
| 1295 | else |
| 1296 | bitrate *= (modulation + 3); |
| 1297 | |
| 1298 | bitrate *= streams; |
| 1299 | |
| 1300 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1301 | bitrate = (bitrate / 9) * 10; |
| 1302 | |
| 1303 | /* do NOT round down here */ |
| 1304 | return (bitrate + 50000) / 100000; |
| 1305 | } |
| 1306 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1307 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 1308 | int flags, struct net_device *dev, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1309 | u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1310 | { |
| 1311 | void *hdr; |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1312 | struct nlattr *sinfoattr, *txrate; |
| 1313 | u16 bitrate; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1314 | |
| 1315 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1316 | if (!hdr) |
| 1317 | return -1; |
| 1318 | |
| 1319 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1320 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 1321 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1322 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 1323 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1324 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1325 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 1326 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 1327 | sinfo->inactive_time); |
| 1328 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 1329 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 1330 | sinfo->rx_bytes); |
| 1331 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 1332 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 1333 | sinfo->tx_bytes); |
| 1334 | if (sinfo->filled & STATION_INFO_LLID) |
| 1335 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 1336 | sinfo->llid); |
| 1337 | if (sinfo->filled & STATION_INFO_PLID) |
| 1338 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 1339 | sinfo->plid); |
| 1340 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 1341 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 1342 | sinfo->plink_state); |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1343 | if (sinfo->filled & STATION_INFO_SIGNAL) |
| 1344 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, |
| 1345 | sinfo->signal); |
| 1346 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { |
| 1347 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); |
| 1348 | if (!txrate) |
| 1349 | goto nla_put_failure; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1350 | |
Henning Rogge | 420e7fa | 2008-12-11 22:04:19 +0100 | [diff] [blame] | 1351 | /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */ |
| 1352 | bitrate = nl80211_calculate_bitrate(&sinfo->txrate); |
| 1353 | if (bitrate > 0) |
| 1354 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); |
| 1355 | |
| 1356 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
| 1357 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, |
| 1358 | sinfo->txrate.mcs); |
| 1359 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) |
| 1360 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); |
| 1361 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) |
| 1362 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); |
| 1363 | |
| 1364 | nla_nest_end(msg, txrate); |
| 1365 | } |
Jouni Malinen | 98c8a60a | 2009-02-17 13:24:57 +0200 | [diff] [blame] | 1366 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
| 1367 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, |
| 1368 | sinfo->rx_packets); |
| 1369 | if (sinfo->filled & STATION_INFO_TX_PACKETS) |
| 1370 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, |
| 1371 | sinfo->tx_packets); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1372 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1373 | |
| 1374 | return genlmsg_end(msg, hdr); |
| 1375 | |
| 1376 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1377 | genlmsg_cancel(msg, hdr); |
| 1378 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1379 | } |
| 1380 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1381 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1382 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1383 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1384 | struct station_info sinfo; |
| 1385 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1386 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1387 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1388 | int ifidx = cb->args[0]; |
| 1389 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1390 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1391 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1392 | if (!ifidx) { |
| 1393 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1394 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1395 | nl80211_policy); |
| 1396 | if (err) |
| 1397 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1398 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1399 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1400 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1401 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1402 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1403 | if (!ifidx) |
| 1404 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1405 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1406 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1407 | rtnl_lock(); |
| 1408 | |
| 1409 | netdev = __dev_get_by_index(&init_net, ifidx); |
| 1410 | if (!netdev) { |
| 1411 | err = -ENODEV; |
| 1412 | goto out_rtnl; |
| 1413 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1414 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1415 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1416 | if (IS_ERR(dev)) { |
| 1417 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1418 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | if (!dev->ops->dump_station) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1422 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1423 | goto out_err; |
| 1424 | } |
| 1425 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1426 | while (1) { |
| 1427 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 1428 | mac_addr, &sinfo); |
| 1429 | if (err == -ENOENT) |
| 1430 | break; |
| 1431 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1432 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1433 | |
| 1434 | if (nl80211_send_station(skb, |
| 1435 | NETLINK_CB(cb->skb).pid, |
| 1436 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1437 | netdev, mac_addr, |
| 1438 | &sinfo) < 0) |
| 1439 | goto out; |
| 1440 | |
| 1441 | sta_idx++; |
| 1442 | } |
| 1443 | |
| 1444 | |
| 1445 | out: |
| 1446 | cb->args[1] = sta_idx; |
| 1447 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1448 | out_err: |
| 1449 | cfg80211_put_dev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1450 | out_rtnl: |
| 1451 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1452 | |
| 1453 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1454 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1455 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1456 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 1457 | { |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1458 | struct cfg80211_registered_device *drv; |
| 1459 | int err; |
| 1460 | struct net_device *dev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1461 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1462 | struct sk_buff *msg; |
| 1463 | u8 *mac_addr = NULL; |
| 1464 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1465 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1466 | |
| 1467 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1468 | return -EINVAL; |
| 1469 | |
| 1470 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1471 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1472 | rtnl_lock(); |
| 1473 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1474 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1475 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1476 | goto out_rtnl; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1477 | |
| 1478 | if (!drv->ops->get_station) { |
| 1479 | err = -EOPNOTSUPP; |
| 1480 | goto out; |
| 1481 | } |
| 1482 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1483 | err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1484 | if (err) |
| 1485 | goto out; |
| 1486 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1487 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1488 | if (!msg) |
| 1489 | goto out; |
| 1490 | |
| 1491 | 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] | 1492 | dev, mac_addr, &sinfo) < 0) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1493 | goto out_free; |
| 1494 | |
| 1495 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1496 | goto out; |
| 1497 | |
| 1498 | out_free: |
| 1499 | nlmsg_free(msg); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1500 | out: |
| 1501 | cfg80211_put_dev(drv); |
| 1502 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1503 | out_rtnl: |
| 1504 | rtnl_unlock(); |
| 1505 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1506 | return err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | /* |
| 1510 | * Get vlan interface making sure it is on the right wiphy. |
| 1511 | */ |
| 1512 | static int get_vlan(struct nlattr *vlanattr, |
| 1513 | struct cfg80211_registered_device *rdev, |
| 1514 | struct net_device **vlan) |
| 1515 | { |
| 1516 | *vlan = NULL; |
| 1517 | |
| 1518 | if (vlanattr) { |
| 1519 | *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr)); |
| 1520 | if (!*vlan) |
| 1521 | return -ENODEV; |
| 1522 | if (!(*vlan)->ieee80211_ptr) |
| 1523 | return -EINVAL; |
| 1524 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 1525 | return -EINVAL; |
| 1526 | } |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 1531 | { |
| 1532 | struct cfg80211_registered_device *drv; |
| 1533 | int err; |
| 1534 | struct net_device *dev; |
| 1535 | struct station_parameters params; |
| 1536 | u8 *mac_addr = NULL; |
| 1537 | |
| 1538 | memset(¶ms, 0, sizeof(params)); |
| 1539 | |
| 1540 | params.listen_interval = -1; |
| 1541 | |
| 1542 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 1543 | return -EINVAL; |
| 1544 | |
| 1545 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1546 | return -EINVAL; |
| 1547 | |
| 1548 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1549 | |
| 1550 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 1551 | params.supported_rates = |
| 1552 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1553 | params.supported_rates_len = |
| 1554 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1555 | } |
| 1556 | |
| 1557 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1558 | params.listen_interval = |
| 1559 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 1560 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1561 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1562 | params.ht_capa = |
| 1563 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 1564 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1565 | if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS], |
| 1566 | ¶ms.station_flags)) |
| 1567 | return -EINVAL; |
| 1568 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1569 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 1570 | params.plink_action = |
| 1571 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 1572 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1573 | rtnl_lock(); |
| 1574 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1575 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1576 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1577 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1578 | |
| 1579 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1580 | if (err) |
| 1581 | goto out; |
| 1582 | |
| 1583 | if (!drv->ops->change_station) { |
| 1584 | err = -EOPNOTSUPP; |
| 1585 | goto out; |
| 1586 | } |
| 1587 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1588 | err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1589 | |
| 1590 | out: |
| 1591 | if (params.vlan) |
| 1592 | dev_put(params.vlan); |
| 1593 | cfg80211_put_dev(drv); |
| 1594 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1595 | out_rtnl: |
| 1596 | rtnl_unlock(); |
| 1597 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1598 | return err; |
| 1599 | } |
| 1600 | |
| 1601 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 1602 | { |
| 1603 | struct cfg80211_registered_device *drv; |
| 1604 | int err; |
| 1605 | struct net_device *dev; |
| 1606 | struct station_parameters params; |
| 1607 | u8 *mac_addr = NULL; |
| 1608 | |
| 1609 | memset(¶ms, 0, sizeof(params)); |
| 1610 | |
| 1611 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1612 | return -EINVAL; |
| 1613 | |
| 1614 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 1615 | return -EINVAL; |
| 1616 | |
| 1617 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1618 | return -EINVAL; |
| 1619 | |
| 1620 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 1621 | return -EINVAL; |
| 1622 | |
| 1623 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1624 | params.supported_rates = |
| 1625 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1626 | params.supported_rates_len = |
| 1627 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1628 | params.listen_interval = |
| 1629 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 16f2e85 | 2008-04-07 14:35:46 +0200 | [diff] [blame] | 1630 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1631 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1632 | params.ht_capa = |
| 1633 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1634 | |
| 1635 | if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS], |
| 1636 | ¶ms.station_flags)) |
| 1637 | return -EINVAL; |
| 1638 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1639 | rtnl_lock(); |
| 1640 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1641 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1642 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1643 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1644 | |
| 1645 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1646 | if (err) |
| 1647 | goto out; |
| 1648 | |
| 1649 | if (!drv->ops->add_station) { |
| 1650 | err = -EOPNOTSUPP; |
| 1651 | goto out; |
| 1652 | } |
| 1653 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 1654 | if (!netif_running(dev)) { |
| 1655 | err = -ENETDOWN; |
| 1656 | goto out; |
| 1657 | } |
| 1658 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1659 | err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1660 | |
| 1661 | out: |
| 1662 | if (params.vlan) |
| 1663 | dev_put(params.vlan); |
| 1664 | cfg80211_put_dev(drv); |
| 1665 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1666 | out_rtnl: |
| 1667 | rtnl_unlock(); |
| 1668 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1669 | return err; |
| 1670 | } |
| 1671 | |
| 1672 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 1673 | { |
| 1674 | struct cfg80211_registered_device *drv; |
| 1675 | int err; |
| 1676 | struct net_device *dev; |
| 1677 | u8 *mac_addr = NULL; |
| 1678 | |
| 1679 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1680 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1681 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1682 | rtnl_lock(); |
| 1683 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1684 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1685 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1686 | goto out_rtnl; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1687 | |
| 1688 | if (!drv->ops->del_station) { |
| 1689 | err = -EOPNOTSUPP; |
| 1690 | goto out; |
| 1691 | } |
| 1692 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1693 | err = drv->ops->del_station(&drv->wiphy, dev, mac_addr); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1694 | |
| 1695 | out: |
| 1696 | cfg80211_put_dev(drv); |
| 1697 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1698 | out_rtnl: |
| 1699 | rtnl_unlock(); |
| 1700 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1701 | return err; |
| 1702 | } |
| 1703 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1704 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 1705 | int flags, struct net_device *dev, |
| 1706 | u8 *dst, u8 *next_hop, |
| 1707 | struct mpath_info *pinfo) |
| 1708 | { |
| 1709 | void *hdr; |
| 1710 | struct nlattr *pinfoattr; |
| 1711 | |
| 1712 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1713 | if (!hdr) |
| 1714 | return -1; |
| 1715 | |
| 1716 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1717 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 1718 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 1719 | |
| 1720 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 1721 | if (!pinfoattr) |
| 1722 | goto nla_put_failure; |
| 1723 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 1724 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 1725 | pinfo->frame_qlen); |
| 1726 | if (pinfo->filled & MPATH_INFO_DSN) |
| 1727 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN, |
| 1728 | pinfo->dsn); |
| 1729 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 1730 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 1731 | pinfo->metric); |
| 1732 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 1733 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 1734 | pinfo->exptime); |
| 1735 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 1736 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 1737 | pinfo->flags); |
| 1738 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 1739 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 1740 | pinfo->discovery_timeout); |
| 1741 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 1742 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 1743 | pinfo->discovery_retries); |
| 1744 | |
| 1745 | nla_nest_end(msg, pinfoattr); |
| 1746 | |
| 1747 | return genlmsg_end(msg, hdr); |
| 1748 | |
| 1749 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1750 | genlmsg_cancel(msg, hdr); |
| 1751 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1755 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1756 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1757 | struct mpath_info pinfo; |
| 1758 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1759 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1760 | u8 dst[ETH_ALEN]; |
| 1761 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1762 | int ifidx = cb->args[0]; |
| 1763 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1764 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1765 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1766 | if (!ifidx) { |
| 1767 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1768 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1769 | nl80211_policy); |
| 1770 | if (err) |
| 1771 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1772 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1773 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1774 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1775 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1776 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1777 | if (!ifidx) |
| 1778 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1779 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1780 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1781 | rtnl_lock(); |
| 1782 | |
| 1783 | netdev = __dev_get_by_index(&init_net, ifidx); |
| 1784 | if (!netdev) { |
| 1785 | err = -ENODEV; |
| 1786 | goto out_rtnl; |
| 1787 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1788 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1789 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1790 | if (IS_ERR(dev)) { |
| 1791 | err = PTR_ERR(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1792 | goto out_rtnl; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1793 | } |
| 1794 | |
| 1795 | if (!dev->ops->dump_mpath) { |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1796 | err = -EOPNOTSUPP; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1797 | goto out_err; |
| 1798 | } |
| 1799 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1800 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 1801 | err = -EOPNOTSUPP; |
| 1802 | goto out; |
| 1803 | } |
| 1804 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1805 | while (1) { |
| 1806 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 1807 | dst, next_hop, &pinfo); |
| 1808 | if (err == -ENOENT) |
| 1809 | break; |
| 1810 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1811 | goto out_err; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1812 | |
| 1813 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 1814 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1815 | netdev, dst, next_hop, |
| 1816 | &pinfo) < 0) |
| 1817 | goto out; |
| 1818 | |
| 1819 | path_idx++; |
| 1820 | } |
| 1821 | |
| 1822 | |
| 1823 | out: |
| 1824 | cb->args[1] = path_idx; |
| 1825 | err = skb->len; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1826 | out_err: |
| 1827 | cfg80211_put_dev(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1828 | out_rtnl: |
| 1829 | rtnl_unlock(); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1830 | |
| 1831 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1835 | { |
| 1836 | struct cfg80211_registered_device *drv; |
| 1837 | int err; |
| 1838 | struct net_device *dev; |
| 1839 | struct mpath_info pinfo; |
| 1840 | struct sk_buff *msg; |
| 1841 | u8 *dst = NULL; |
| 1842 | u8 next_hop[ETH_ALEN]; |
| 1843 | |
| 1844 | memset(&pinfo, 0, sizeof(pinfo)); |
| 1845 | |
| 1846 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1847 | return -EINVAL; |
| 1848 | |
| 1849 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1850 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1851 | rtnl_lock(); |
| 1852 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1853 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1854 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1855 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1856 | |
| 1857 | if (!drv->ops->get_mpath) { |
| 1858 | err = -EOPNOTSUPP; |
| 1859 | goto out; |
| 1860 | } |
| 1861 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 1863 | err = -EOPNOTSUPP; |
| 1864 | goto out; |
| 1865 | } |
| 1866 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1867 | err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1868 | if (err) |
| 1869 | goto out; |
| 1870 | |
| 1871 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1872 | if (!msg) |
| 1873 | goto out; |
| 1874 | |
| 1875 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
| 1876 | dev, dst, next_hop, &pinfo) < 0) |
| 1877 | goto out_free; |
| 1878 | |
| 1879 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1880 | goto out; |
| 1881 | |
| 1882 | out_free: |
| 1883 | nlmsg_free(msg); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1884 | out: |
| 1885 | cfg80211_put_dev(drv); |
| 1886 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1887 | out_rtnl: |
| 1888 | rtnl_unlock(); |
| 1889 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1890 | return err; |
| 1891 | } |
| 1892 | |
| 1893 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1894 | { |
| 1895 | struct cfg80211_registered_device *drv; |
| 1896 | int err; |
| 1897 | struct net_device *dev; |
| 1898 | u8 *dst = NULL; |
| 1899 | u8 *next_hop = NULL; |
| 1900 | |
| 1901 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1902 | return -EINVAL; |
| 1903 | |
| 1904 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 1905 | return -EINVAL; |
| 1906 | |
| 1907 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1908 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 1909 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1910 | rtnl_lock(); |
| 1911 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1912 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1913 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1914 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1915 | |
| 1916 | if (!drv->ops->change_mpath) { |
| 1917 | err = -EOPNOTSUPP; |
| 1918 | goto out; |
| 1919 | } |
| 1920 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1921 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 1922 | err = -EOPNOTSUPP; |
| 1923 | goto out; |
| 1924 | } |
| 1925 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 1926 | if (!netif_running(dev)) { |
| 1927 | err = -ENETDOWN; |
| 1928 | goto out; |
| 1929 | } |
| 1930 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1931 | err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1932 | |
| 1933 | out: |
| 1934 | cfg80211_put_dev(drv); |
| 1935 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1936 | out_rtnl: |
| 1937 | rtnl_unlock(); |
| 1938 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1939 | return err; |
| 1940 | } |
| 1941 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1942 | { |
| 1943 | struct cfg80211_registered_device *drv; |
| 1944 | int err; |
| 1945 | struct net_device *dev; |
| 1946 | u8 *dst = NULL; |
| 1947 | u8 *next_hop = NULL; |
| 1948 | |
| 1949 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1950 | return -EINVAL; |
| 1951 | |
| 1952 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 1953 | return -EINVAL; |
| 1954 | |
| 1955 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1956 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 1957 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1958 | rtnl_lock(); |
| 1959 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1960 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1961 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1962 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1963 | |
| 1964 | if (!drv->ops->add_mpath) { |
| 1965 | err = -EOPNOTSUPP; |
| 1966 | goto out; |
| 1967 | } |
| 1968 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 1969 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
| 1970 | err = -EOPNOTSUPP; |
| 1971 | goto out; |
| 1972 | } |
| 1973 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 1974 | if (!netif_running(dev)) { |
| 1975 | err = -ENETDOWN; |
| 1976 | goto out; |
| 1977 | } |
| 1978 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1979 | err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1980 | |
| 1981 | out: |
| 1982 | cfg80211_put_dev(drv); |
| 1983 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 1984 | out_rtnl: |
| 1985 | rtnl_unlock(); |
| 1986 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1987 | return err; |
| 1988 | } |
| 1989 | |
| 1990 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1991 | { |
| 1992 | struct cfg80211_registered_device *drv; |
| 1993 | int err; |
| 1994 | struct net_device *dev; |
| 1995 | u8 *dst = NULL; |
| 1996 | |
| 1997 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1998 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1999 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2000 | rtnl_lock(); |
| 2001 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 2002 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2003 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2004 | goto out_rtnl; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2005 | |
| 2006 | if (!drv->ops->del_mpath) { |
| 2007 | err = -EOPNOTSUPP; |
| 2008 | goto out; |
| 2009 | } |
| 2010 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2011 | err = drv->ops->del_mpath(&drv->wiphy, dev, dst); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2012 | |
| 2013 | out: |
| 2014 | cfg80211_put_dev(drv); |
| 2015 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2016 | out_rtnl: |
| 2017 | rtnl_unlock(); |
| 2018 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2019 | return err; |
| 2020 | } |
| 2021 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2022 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 2023 | { |
| 2024 | struct cfg80211_registered_device *drv; |
| 2025 | int err; |
| 2026 | struct net_device *dev; |
| 2027 | struct bss_parameters params; |
| 2028 | |
| 2029 | memset(¶ms, 0, sizeof(params)); |
| 2030 | /* default to not changing parameters */ |
| 2031 | params.use_cts_prot = -1; |
| 2032 | params.use_short_preamble = -1; |
| 2033 | params.use_short_slot_time = -1; |
| 2034 | |
| 2035 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 2036 | params.use_cts_prot = |
| 2037 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 2038 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 2039 | params.use_short_preamble = |
| 2040 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 2041 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 2042 | params.use_short_slot_time = |
| 2043 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2044 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 2045 | params.basic_rates = |
| 2046 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2047 | params.basic_rates_len = |
| 2048 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 2049 | } |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2050 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2051 | rtnl_lock(); |
| 2052 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2053 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2054 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2055 | goto out_rtnl; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2056 | |
| 2057 | if (!drv->ops->change_bss) { |
| 2058 | err = -EOPNOTSUPP; |
| 2059 | goto out; |
| 2060 | } |
| 2061 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2062 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
| 2063 | err = -EOPNOTSUPP; |
| 2064 | goto out; |
| 2065 | } |
| 2066 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2067 | err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms); |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2068 | |
| 2069 | out: |
| 2070 | cfg80211_put_dev(drv); |
| 2071 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2072 | out_rtnl: |
| 2073 | rtnl_unlock(); |
| 2074 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2075 | return err; |
| 2076 | } |
| 2077 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2078 | static const struct nla_policy |
| 2079 | reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 2080 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 2081 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 2082 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 2083 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 2084 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 2085 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 2086 | }; |
| 2087 | |
| 2088 | static int parse_reg_rule(struct nlattr *tb[], |
| 2089 | struct ieee80211_reg_rule *reg_rule) |
| 2090 | { |
| 2091 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 2092 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 2093 | |
| 2094 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 2095 | return -EINVAL; |
| 2096 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 2097 | return -EINVAL; |
| 2098 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 2099 | return -EINVAL; |
| 2100 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 2101 | return -EINVAL; |
| 2102 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 2103 | return -EINVAL; |
| 2104 | |
| 2105 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 2106 | |
| 2107 | freq_range->start_freq_khz = |
| 2108 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 2109 | freq_range->end_freq_khz = |
| 2110 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 2111 | freq_range->max_bandwidth_khz = |
| 2112 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 2113 | |
| 2114 | power_rule->max_eirp = |
| 2115 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 2116 | |
| 2117 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 2118 | power_rule->max_antenna_gain = |
| 2119 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 2120 | |
| 2121 | return 0; |
| 2122 | } |
| 2123 | |
| 2124 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2125 | { |
| 2126 | int r; |
| 2127 | char *data = NULL; |
| 2128 | |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2129 | /* |
| 2130 | * You should only get this when cfg80211 hasn't yet initialized |
| 2131 | * completely when built-in to the kernel right between the time |
| 2132 | * window between nl80211_init() and regulatory_init(), if that is |
| 2133 | * even possible. |
| 2134 | */ |
| 2135 | mutex_lock(&cfg80211_mutex); |
| 2136 | if (unlikely(!cfg80211_regdomain)) { |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2137 | mutex_unlock(&cfg80211_mutex); |
| 2138 | return -EINPROGRESS; |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2139 | } |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2140 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | 80778f1 | 2009-02-21 00:04:22 -0500 | [diff] [blame] | 2141 | |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2142 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2143 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2144 | |
| 2145 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2146 | |
| 2147 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 2148 | /* We ignore world regdom requests with the old regdom setup */ |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2149 | if (is_world_regdom(data)) |
| 2150 | return -EINVAL; |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2151 | #endif |
Luis R. Rodriguez | fe33eb3 | 2009-02-21 00:04:30 -0500 | [diff] [blame] | 2152 | |
| 2153 | r = regulatory_hint_user(data); |
| 2154 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2155 | return r; |
| 2156 | } |
| 2157 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2158 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
| 2159 | struct genl_info *info) |
| 2160 | { |
| 2161 | struct cfg80211_registered_device *drv; |
| 2162 | struct mesh_config cur_params; |
| 2163 | int err; |
| 2164 | struct net_device *dev; |
| 2165 | void *hdr; |
| 2166 | struct nlattr *pinfoattr; |
| 2167 | struct sk_buff *msg; |
| 2168 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2169 | rtnl_lock(); |
| 2170 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2171 | /* Look up our device */ |
| 2172 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2173 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2174 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2175 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2176 | if (!drv->ops->get_mesh_params) { |
| 2177 | err = -EOPNOTSUPP; |
| 2178 | goto out; |
| 2179 | } |
| 2180 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2181 | /* Get the mesh params */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2182 | err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2183 | if (err) |
| 2184 | goto out; |
| 2185 | |
| 2186 | /* Draw up a netlink message to send back */ |
| 2187 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 2188 | if (!msg) { |
| 2189 | err = -ENOBUFS; |
| 2190 | goto out; |
| 2191 | } |
| 2192 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2193 | NL80211_CMD_GET_MESH_PARAMS); |
| 2194 | if (!hdr) |
| 2195 | goto nla_put_failure; |
| 2196 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); |
| 2197 | if (!pinfoattr) |
| 2198 | goto nla_put_failure; |
| 2199 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2200 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 2201 | cur_params.dot11MeshRetryTimeout); |
| 2202 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 2203 | cur_params.dot11MeshConfirmTimeout); |
| 2204 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 2205 | cur_params.dot11MeshHoldingTimeout); |
| 2206 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 2207 | cur_params.dot11MeshMaxPeerLinks); |
| 2208 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 2209 | cur_params.dot11MeshMaxRetries); |
| 2210 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 2211 | cur_params.dot11MeshTTL); |
| 2212 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 2213 | cur_params.auto_open_plinks); |
| 2214 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2215 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 2216 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 2217 | cur_params.path_refresh_time); |
| 2218 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2219 | cur_params.min_discovery_timeout); |
| 2220 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2221 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 2222 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2223 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 2224 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2225 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
| 2226 | nla_nest_end(msg, pinfoattr); |
| 2227 | genlmsg_end(msg, hdr); |
| 2228 | err = genlmsg_unicast(msg, info->snd_pid); |
| 2229 | goto out; |
| 2230 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2231 | nla_put_failure: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2232 | genlmsg_cancel(msg, hdr); |
| 2233 | err = -EMSGSIZE; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2234 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2235 | /* Cleanup */ |
| 2236 | cfg80211_put_dev(drv); |
| 2237 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2238 | out_rtnl: |
| 2239 | rtnl_unlock(); |
| 2240 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2241 | return err; |
| 2242 | } |
| 2243 | |
| 2244 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 2245 | do {\ |
| 2246 | if (table[attr_num]) {\ |
| 2247 | cfg.param = nla_fn(table[attr_num]); \ |
| 2248 | mask |= (1 << (attr_num - 1)); \ |
| 2249 | } \ |
| 2250 | } while (0);\ |
| 2251 | |
| 2252 | static struct nla_policy |
| 2253 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = { |
| 2254 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 2255 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 2256 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 2257 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 2258 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 2259 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
| 2260 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 2261 | |
| 2262 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 2263 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 2264 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 2265 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 2266 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 2267 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 2268 | }; |
| 2269 | |
| 2270 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) |
| 2271 | { |
| 2272 | int err; |
| 2273 | u32 mask; |
| 2274 | struct cfg80211_registered_device *drv; |
| 2275 | struct net_device *dev; |
| 2276 | struct mesh_config cfg; |
| 2277 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
| 2278 | struct nlattr *parent_attr; |
| 2279 | |
| 2280 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; |
| 2281 | if (!parent_attr) |
| 2282 | return -EINVAL; |
| 2283 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
| 2284 | parent_attr, nl80211_meshconf_params_policy)) |
| 2285 | return -EINVAL; |
| 2286 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2287 | rtnl_lock(); |
| 2288 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2289 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2290 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2291 | goto out_rtnl; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2292 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2293 | if (!drv->ops->set_mesh_params) { |
| 2294 | err = -EOPNOTSUPP; |
| 2295 | goto out; |
| 2296 | } |
| 2297 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2298 | /* This makes sure that there aren't more than 32 mesh config |
| 2299 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 2300 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 2301 | |
| 2302 | /* Fill in the params struct */ |
| 2303 | mask = 0; |
| 2304 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 2305 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 2306 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 2307 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 2308 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 2309 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 2310 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 2311 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 2312 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 2313 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 2314 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 2315 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
| 2316 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 2317 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 2318 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 2319 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 2320 | nla_get_u8); |
| 2321 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 2322 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 2323 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 2324 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 2325 | nla_get_u16); |
| 2326 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 2327 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 2328 | nla_get_u32); |
| 2329 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 2330 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 2331 | nla_get_u16); |
| 2332 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 2333 | dot11MeshHWMPnetDiameterTraversalTime, |
| 2334 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 2335 | nla_get_u16); |
| 2336 | |
| 2337 | /* Apply changes */ |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2338 | err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2339 | |
Jouni Malinen | f3f9258 | 2009-03-20 17:57:36 +0200 | [diff] [blame] | 2340 | out: |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2341 | /* cleanup */ |
| 2342 | cfg80211_put_dev(drv); |
| 2343 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2344 | out_rtnl: |
| 2345 | rtnl_unlock(); |
| 2346 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2347 | return err; |
| 2348 | } |
| 2349 | |
| 2350 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 2351 | |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2352 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
| 2353 | { |
| 2354 | struct sk_buff *msg; |
| 2355 | void *hdr = NULL; |
| 2356 | struct nlattr *nl_reg_rules; |
| 2357 | unsigned int i; |
| 2358 | int err = -EINVAL; |
| 2359 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2360 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2361 | |
| 2362 | if (!cfg80211_regdomain) |
| 2363 | goto out; |
| 2364 | |
| 2365 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 2366 | if (!msg) { |
| 2367 | err = -ENOBUFS; |
| 2368 | goto out; |
| 2369 | } |
| 2370 | |
| 2371 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 2372 | NL80211_CMD_GET_REG); |
| 2373 | if (!hdr) |
| 2374 | goto nla_put_failure; |
| 2375 | |
| 2376 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, |
| 2377 | cfg80211_regdomain->alpha2); |
| 2378 | |
| 2379 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
| 2380 | if (!nl_reg_rules) |
| 2381 | goto nla_put_failure; |
| 2382 | |
| 2383 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { |
| 2384 | struct nlattr *nl_reg_rule; |
| 2385 | const struct ieee80211_reg_rule *reg_rule; |
| 2386 | const struct ieee80211_freq_range *freq_range; |
| 2387 | const struct ieee80211_power_rule *power_rule; |
| 2388 | |
| 2389 | reg_rule = &cfg80211_regdomain->reg_rules[i]; |
| 2390 | freq_range = ®_rule->freq_range; |
| 2391 | power_rule = ®_rule->power_rule; |
| 2392 | |
| 2393 | nl_reg_rule = nla_nest_start(msg, i); |
| 2394 | if (!nl_reg_rule) |
| 2395 | goto nla_put_failure; |
| 2396 | |
| 2397 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
| 2398 | reg_rule->flags); |
| 2399 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, |
| 2400 | freq_range->start_freq_khz); |
| 2401 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, |
| 2402 | freq_range->end_freq_khz); |
| 2403 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, |
| 2404 | freq_range->max_bandwidth_khz); |
| 2405 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
| 2406 | power_rule->max_antenna_gain); |
| 2407 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, |
| 2408 | power_rule->max_eirp); |
| 2409 | |
| 2410 | nla_nest_end(msg, nl_reg_rule); |
| 2411 | } |
| 2412 | |
| 2413 | nla_nest_end(msg, nl_reg_rules); |
| 2414 | |
| 2415 | genlmsg_end(msg, hdr); |
| 2416 | err = genlmsg_unicast(msg, info->snd_pid); |
| 2417 | goto out; |
| 2418 | |
| 2419 | nla_put_failure: |
| 2420 | genlmsg_cancel(msg, hdr); |
| 2421 | err = -EMSGSIZE; |
| 2422 | out: |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2423 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 2424 | return err; |
| 2425 | } |
| 2426 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2427 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 2428 | { |
| 2429 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 2430 | struct nlattr *nl_reg_rule; |
| 2431 | char *alpha2 = NULL; |
| 2432 | int rem_reg_rules = 0, r = 0; |
| 2433 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 2434 | struct ieee80211_regdomain *rd = NULL; |
| 2435 | |
| 2436 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 2437 | return -EINVAL; |
| 2438 | |
| 2439 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 2440 | return -EINVAL; |
| 2441 | |
| 2442 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 2443 | |
| 2444 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2445 | rem_reg_rules) { |
| 2446 | num_rules++; |
| 2447 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
| 2448 | goto bad_reg; |
| 2449 | } |
| 2450 | |
| 2451 | if (!reg_is_valid_request(alpha2)) |
| 2452 | return -EINVAL; |
| 2453 | |
| 2454 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 2455 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 2456 | |
| 2457 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 2458 | if (!rd) |
| 2459 | return -ENOMEM; |
| 2460 | |
| 2461 | rd->n_reg_rules = num_rules; |
| 2462 | rd->alpha2[0] = alpha2[0]; |
| 2463 | rd->alpha2[1] = alpha2[1]; |
| 2464 | |
| 2465 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 2466 | rem_reg_rules) { |
| 2467 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 2468 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 2469 | reg_rule_policy); |
| 2470 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 2471 | if (r) |
| 2472 | goto bad_reg; |
| 2473 | |
| 2474 | rule_idx++; |
| 2475 | |
| 2476 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) |
| 2477 | goto bad_reg; |
| 2478 | } |
| 2479 | |
| 2480 | BUG_ON(rule_idx != num_rules); |
| 2481 | |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2482 | mutex_lock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2483 | r = set_regdom(rd); |
Luis R. Rodriguez | a179439 | 2009-02-21 00:04:21 -0500 | [diff] [blame] | 2484 | mutex_unlock(&cfg80211_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2485 | return r; |
| 2486 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 2487 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2488 | kfree(rd); |
| 2489 | return -EINVAL; |
| 2490 | } |
| 2491 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2492 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
| 2493 | { |
| 2494 | struct cfg80211_registered_device *drv; |
| 2495 | struct net_device *dev; |
| 2496 | struct cfg80211_scan_request *request; |
| 2497 | struct cfg80211_ssid *ssid; |
| 2498 | struct ieee80211_channel *channel; |
| 2499 | struct nlattr *attr; |
| 2500 | struct wiphy *wiphy; |
| 2501 | int err, tmp, n_ssids = 0, n_channels = 0, i; |
| 2502 | enum ieee80211_band band; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2503 | size_t ie_len; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2504 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2505 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2506 | return -EINVAL; |
| 2507 | |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2508 | rtnl_lock(); |
| 2509 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2510 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2511 | if (err) |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2512 | goto out_rtnl; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2513 | |
| 2514 | wiphy = &drv->wiphy; |
| 2515 | |
| 2516 | if (!drv->ops->scan) { |
| 2517 | err = -EOPNOTSUPP; |
| 2518 | goto out; |
| 2519 | } |
| 2520 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2521 | if (!netif_running(dev)) { |
| 2522 | err = -ENETDOWN; |
| 2523 | goto out; |
| 2524 | } |
| 2525 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2526 | if (drv->scan_req) { |
| 2527 | err = -EBUSY; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2528 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 2532 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) |
| 2533 | n_channels++; |
| 2534 | if (!n_channels) { |
| 2535 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2536 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2537 | } |
| 2538 | } else { |
| 2539 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
| 2540 | if (wiphy->bands[band]) |
| 2541 | n_channels += wiphy->bands[band]->n_channels; |
| 2542 | } |
| 2543 | |
| 2544 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) |
| 2545 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) |
| 2546 | n_ssids++; |
| 2547 | |
| 2548 | if (n_ssids > wiphy->max_scan_ssids) { |
| 2549 | err = -EINVAL; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2550 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2551 | } |
| 2552 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2553 | if (info->attrs[NL80211_ATTR_IE]) |
| 2554 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2555 | else |
| 2556 | ie_len = 0; |
| 2557 | |
Johannes Berg | 18a8365 | 2009-03-31 12:12:05 +0200 | [diff] [blame] | 2558 | if (ie_len > wiphy->max_scan_ie_len) { |
| 2559 | err = -EINVAL; |
| 2560 | goto out; |
| 2561 | } |
| 2562 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2563 | request = kzalloc(sizeof(*request) |
| 2564 | + sizeof(*ssid) * n_ssids |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2565 | + sizeof(channel) * n_channels |
| 2566 | + ie_len, GFP_KERNEL); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2567 | if (!request) { |
| 2568 | err = -ENOMEM; |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2569 | goto out; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | request->channels = (void *)((char *)request + sizeof(*request)); |
| 2573 | request->n_channels = n_channels; |
| 2574 | if (n_ssids) |
| 2575 | request->ssids = (void *)(request->channels + n_channels); |
| 2576 | request->n_ssids = n_ssids; |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2577 | if (ie_len) { |
| 2578 | if (request->ssids) |
| 2579 | request->ie = (void *)(request->ssids + n_ssids); |
| 2580 | else |
| 2581 | request->ie = (void *)(request->channels + n_channels); |
| 2582 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2583 | |
| 2584 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
| 2585 | /* user specified, bail out if channel not found */ |
| 2586 | request->n_channels = n_channels; |
| 2587 | i = 0; |
| 2588 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
| 2589 | request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr)); |
| 2590 | if (!request->channels[i]) { |
| 2591 | err = -EINVAL; |
| 2592 | goto out_free; |
| 2593 | } |
| 2594 | i++; |
| 2595 | } |
| 2596 | } else { |
| 2597 | /* all channels */ |
| 2598 | i = 0; |
| 2599 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 2600 | int j; |
| 2601 | if (!wiphy->bands[band]) |
| 2602 | continue; |
| 2603 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { |
| 2604 | request->channels[i] = &wiphy->bands[band]->channels[j]; |
| 2605 | i++; |
| 2606 | } |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | i = 0; |
| 2611 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { |
| 2612 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
| 2613 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { |
| 2614 | err = -EINVAL; |
| 2615 | goto out_free; |
| 2616 | } |
| 2617 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
| 2618 | request->ssids[i].ssid_len = nla_len(attr); |
| 2619 | i++; |
| 2620 | } |
| 2621 | } |
| 2622 | |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2623 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2624 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
Johannes Berg | de95a54 | 2009-04-01 11:58:36 +0200 | [diff] [blame] | 2625 | memcpy((void *)request->ie, |
| 2626 | nla_data(info->attrs[NL80211_ATTR_IE]), |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame] | 2627 | request->ie_len); |
| 2628 | } |
| 2629 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2630 | request->ifidx = dev->ifindex; |
| 2631 | request->wiphy = &drv->wiphy; |
| 2632 | |
| 2633 | drv->scan_req = request; |
| 2634 | err = drv->ops->scan(&drv->wiphy, dev, request); |
| 2635 | |
| 2636 | out_free: |
| 2637 | if (err) { |
| 2638 | drv->scan_req = NULL; |
| 2639 | kfree(request); |
| 2640 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2641 | out: |
| 2642 | cfg80211_put_dev(drv); |
| 2643 | dev_put(dev); |
Johannes Berg | 3b85875 | 2009-03-12 09:55:09 +0100 | [diff] [blame] | 2644 | out_rtnl: |
| 2645 | rtnl_unlock(); |
| 2646 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2647 | return err; |
| 2648 | } |
| 2649 | |
| 2650 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 2651 | struct cfg80211_registered_device *rdev, |
| 2652 | struct net_device *dev, |
| 2653 | struct cfg80211_bss *res) |
| 2654 | { |
| 2655 | void *hdr; |
| 2656 | struct nlattr *bss; |
| 2657 | |
| 2658 | hdr = nl80211hdr_put(msg, pid, seq, flags, |
| 2659 | NL80211_CMD_NEW_SCAN_RESULTS); |
| 2660 | if (!hdr) |
| 2661 | return -1; |
| 2662 | |
| 2663 | NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION, |
| 2664 | rdev->bss_generation); |
| 2665 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 2666 | |
| 2667 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); |
| 2668 | if (!bss) |
| 2669 | goto nla_put_failure; |
| 2670 | if (!is_zero_ether_addr(res->bssid)) |
| 2671 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); |
| 2672 | if (res->information_elements && res->len_information_elements) |
| 2673 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
| 2674 | res->len_information_elements, |
| 2675 | res->information_elements); |
| 2676 | if (res->tsf) |
| 2677 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); |
| 2678 | if (res->beacon_interval) |
| 2679 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); |
| 2680 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); |
| 2681 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); |
| 2682 | |
Johannes Berg | 77965c9 | 2009-02-18 18:45:06 +0100 | [diff] [blame] | 2683 | switch (rdev->wiphy.signal_type) { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2684 | case CFG80211_SIGNAL_TYPE_MBM: |
| 2685 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); |
| 2686 | break; |
| 2687 | case CFG80211_SIGNAL_TYPE_UNSPEC: |
| 2688 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); |
| 2689 | break; |
| 2690 | default: |
| 2691 | break; |
| 2692 | } |
| 2693 | |
| 2694 | nla_nest_end(msg, bss); |
| 2695 | |
| 2696 | return genlmsg_end(msg, hdr); |
| 2697 | |
| 2698 | nla_put_failure: |
| 2699 | genlmsg_cancel(msg, hdr); |
| 2700 | return -EMSGSIZE; |
| 2701 | } |
| 2702 | |
| 2703 | static int nl80211_dump_scan(struct sk_buff *skb, |
| 2704 | struct netlink_callback *cb) |
| 2705 | { |
| 2706 | struct cfg80211_registered_device *dev; |
| 2707 | struct net_device *netdev; |
| 2708 | struct cfg80211_internal_bss *scan; |
| 2709 | int ifidx = cb->args[0]; |
| 2710 | int start = cb->args[1], idx = 0; |
| 2711 | int err; |
| 2712 | |
| 2713 | if (!ifidx) { |
| 2714 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 2715 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 2716 | nl80211_policy); |
| 2717 | if (err) |
| 2718 | return err; |
| 2719 | |
| 2720 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 2721 | return -EINVAL; |
| 2722 | |
| 2723 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 2724 | if (!ifidx) |
| 2725 | return -EINVAL; |
| 2726 | cb->args[0] = ifidx; |
| 2727 | } |
| 2728 | |
| 2729 | netdev = dev_get_by_index(&init_net, ifidx); |
| 2730 | if (!netdev) |
| 2731 | return -ENODEV; |
| 2732 | |
| 2733 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 2734 | if (IS_ERR(dev)) { |
| 2735 | err = PTR_ERR(dev); |
| 2736 | goto out_put_netdev; |
| 2737 | } |
| 2738 | |
| 2739 | spin_lock_bh(&dev->bss_lock); |
| 2740 | cfg80211_bss_expire(dev); |
| 2741 | |
| 2742 | list_for_each_entry(scan, &dev->bss_list, list) { |
| 2743 | if (++idx <= start) |
| 2744 | continue; |
| 2745 | if (nl80211_send_bss(skb, |
| 2746 | NETLINK_CB(cb->skb).pid, |
| 2747 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 2748 | dev, netdev, &scan->pub) < 0) { |
| 2749 | idx--; |
| 2750 | goto out; |
| 2751 | } |
| 2752 | } |
| 2753 | |
| 2754 | out: |
| 2755 | spin_unlock_bh(&dev->bss_lock); |
| 2756 | |
| 2757 | cb->args[1] = idx; |
| 2758 | err = skb->len; |
| 2759 | cfg80211_put_dev(dev); |
| 2760 | out_put_netdev: |
| 2761 | dev_put(netdev); |
| 2762 | |
| 2763 | return err; |
| 2764 | } |
| 2765 | |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 2766 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
| 2767 | { |
| 2768 | return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM || |
| 2769 | auth_type == NL80211_AUTHTYPE_SHARED_KEY || |
| 2770 | auth_type == NL80211_AUTHTYPE_FT || |
| 2771 | auth_type == NL80211_AUTHTYPE_NETWORK_EAP; |
| 2772 | } |
| 2773 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2774 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
| 2775 | { |
| 2776 | struct cfg80211_registered_device *drv; |
| 2777 | struct net_device *dev; |
| 2778 | struct cfg80211_auth_request req; |
| 2779 | struct wiphy *wiphy; |
| 2780 | int err; |
| 2781 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2782 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2783 | return -EINVAL; |
| 2784 | |
| 2785 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2786 | return -EINVAL; |
| 2787 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 2788 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
| 2789 | return -EINVAL; |
| 2790 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2791 | rtnl_lock(); |
| 2792 | |
| 2793 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2794 | if (err) |
| 2795 | goto unlock_rtnl; |
| 2796 | |
| 2797 | if (!drv->ops->auth) { |
| 2798 | err = -EOPNOTSUPP; |
| 2799 | goto out; |
| 2800 | } |
| 2801 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2802 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 2803 | err = -EOPNOTSUPP; |
| 2804 | goto out; |
| 2805 | } |
| 2806 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2807 | if (!netif_running(dev)) { |
| 2808 | err = -ENETDOWN; |
| 2809 | goto out; |
| 2810 | } |
| 2811 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2812 | wiphy = &drv->wiphy; |
| 2813 | memset(&req, 0, sizeof(req)); |
| 2814 | |
| 2815 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2816 | |
| 2817 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2818 | req.chan = ieee80211_get_channel( |
| 2819 | wiphy, |
| 2820 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 2821 | if (!req.chan) { |
| 2822 | err = -EINVAL; |
| 2823 | goto out; |
| 2824 | } |
| 2825 | } |
| 2826 | |
| 2827 | if (info->attrs[NL80211_ATTR_SSID]) { |
| 2828 | req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2829 | req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2830 | } |
| 2831 | |
| 2832 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2833 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2834 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2835 | } |
| 2836 | |
Jouni Malinen | 1778092 | 2009-03-27 20:52:47 +0200 | [diff] [blame] | 2837 | req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
| 2838 | if (!nl80211_valid_auth_type(req.auth_type)) { |
| 2839 | err = -EINVAL; |
| 2840 | goto out; |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2841 | } |
| 2842 | |
| 2843 | err = drv->ops->auth(&drv->wiphy, dev, &req); |
| 2844 | |
| 2845 | out: |
| 2846 | cfg80211_put_dev(drv); |
| 2847 | dev_put(dev); |
| 2848 | unlock_rtnl: |
| 2849 | rtnl_unlock(); |
| 2850 | return err; |
| 2851 | } |
| 2852 | |
| 2853 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
| 2854 | { |
| 2855 | struct cfg80211_registered_device *drv; |
| 2856 | struct net_device *dev; |
| 2857 | struct cfg80211_assoc_request req; |
| 2858 | struct wiphy *wiphy; |
| 2859 | int err; |
| 2860 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2861 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2862 | return -EINVAL; |
| 2863 | |
| 2864 | if (!info->attrs[NL80211_ATTR_MAC] || |
| 2865 | !info->attrs[NL80211_ATTR_SSID]) |
| 2866 | return -EINVAL; |
| 2867 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2868 | rtnl_lock(); |
| 2869 | |
| 2870 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2871 | if (err) |
| 2872 | goto unlock_rtnl; |
| 2873 | |
| 2874 | if (!drv->ops->assoc) { |
| 2875 | err = -EOPNOTSUPP; |
| 2876 | goto out; |
| 2877 | } |
| 2878 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2879 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 2880 | err = -EOPNOTSUPP; |
| 2881 | goto out; |
| 2882 | } |
| 2883 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2884 | if (!netif_running(dev)) { |
| 2885 | err = -ENETDOWN; |
| 2886 | goto out; |
| 2887 | } |
| 2888 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2889 | wiphy = &drv->wiphy; |
| 2890 | memset(&req, 0, sizeof(req)); |
| 2891 | |
| 2892 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2893 | |
| 2894 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
| 2895 | req.chan = ieee80211_get_channel( |
| 2896 | wiphy, |
| 2897 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
| 2898 | if (!req.chan) { |
| 2899 | err = -EINVAL; |
| 2900 | goto out; |
| 2901 | } |
| 2902 | } |
| 2903 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2904 | req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
| 2905 | req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); |
| 2906 | |
| 2907 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2908 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2909 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2910 | } |
| 2911 | |
| 2912 | err = drv->ops->assoc(&drv->wiphy, dev, &req); |
| 2913 | |
| 2914 | out: |
| 2915 | cfg80211_put_dev(drv); |
| 2916 | dev_put(dev); |
| 2917 | unlock_rtnl: |
| 2918 | rtnl_unlock(); |
| 2919 | return err; |
| 2920 | } |
| 2921 | |
| 2922 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) |
| 2923 | { |
| 2924 | struct cfg80211_registered_device *drv; |
| 2925 | struct net_device *dev; |
| 2926 | struct cfg80211_deauth_request req; |
| 2927 | struct wiphy *wiphy; |
| 2928 | int err; |
| 2929 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2930 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2931 | return -EINVAL; |
| 2932 | |
| 2933 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2934 | return -EINVAL; |
| 2935 | |
| 2936 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 2937 | return -EINVAL; |
| 2938 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2939 | rtnl_lock(); |
| 2940 | |
| 2941 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 2942 | if (err) |
| 2943 | goto unlock_rtnl; |
| 2944 | |
| 2945 | if (!drv->ops->deauth) { |
| 2946 | err = -EOPNOTSUPP; |
| 2947 | goto out; |
| 2948 | } |
| 2949 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 2950 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 2951 | err = -EOPNOTSUPP; |
| 2952 | goto out; |
| 2953 | } |
| 2954 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 2955 | if (!netif_running(dev)) { |
| 2956 | err = -ENETDOWN; |
| 2957 | goto out; |
| 2958 | } |
| 2959 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2960 | wiphy = &drv->wiphy; |
| 2961 | memset(&req, 0, sizeof(req)); |
| 2962 | |
| 2963 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 2964 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2965 | req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 2966 | if (req.reason_code == 0) { |
| 2967 | /* Reason Code 0 is reserved */ |
| 2968 | err = -EINVAL; |
| 2969 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 2970 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2971 | |
| 2972 | if (info->attrs[NL80211_ATTR_IE]) { |
| 2973 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 2974 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 2975 | } |
| 2976 | |
| 2977 | err = drv->ops->deauth(&drv->wiphy, dev, &req); |
| 2978 | |
| 2979 | out: |
| 2980 | cfg80211_put_dev(drv); |
| 2981 | dev_put(dev); |
| 2982 | unlock_rtnl: |
| 2983 | rtnl_unlock(); |
| 2984 | return err; |
| 2985 | } |
| 2986 | |
| 2987 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) |
| 2988 | { |
| 2989 | struct cfg80211_registered_device *drv; |
| 2990 | struct net_device *dev; |
| 2991 | struct cfg80211_disassoc_request req; |
| 2992 | struct wiphy *wiphy; |
| 2993 | int err; |
| 2994 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 2995 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
| 2996 | return -EINVAL; |
| 2997 | |
| 2998 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 2999 | return -EINVAL; |
| 3000 | |
| 3001 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) |
| 3002 | return -EINVAL; |
| 3003 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3004 | rtnl_lock(); |
| 3005 | |
| 3006 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 3007 | if (err) |
| 3008 | goto unlock_rtnl; |
| 3009 | |
| 3010 | if (!drv->ops->disassoc) { |
| 3011 | err = -EOPNOTSUPP; |
| 3012 | goto out; |
| 3013 | } |
| 3014 | |
Jouni Malinen | eec60b0 | 2009-03-20 21:21:19 +0200 | [diff] [blame] | 3015 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
| 3016 | err = -EOPNOTSUPP; |
| 3017 | goto out; |
| 3018 | } |
| 3019 | |
Jouni Malinen | 35a8efe | 2009-03-20 21:21:18 +0200 | [diff] [blame] | 3020 | if (!netif_running(dev)) { |
| 3021 | err = -ENETDOWN; |
| 3022 | goto out; |
| 3023 | } |
| 3024 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3025 | wiphy = &drv->wiphy; |
| 3026 | memset(&req, 0, sizeof(req)); |
| 3027 | |
| 3028 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 3029 | |
Johannes Berg | f4a11bb | 2009-03-27 12:40:28 +0100 | [diff] [blame] | 3030 | req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
| 3031 | if (req.reason_code == 0) { |
| 3032 | /* Reason Code 0 is reserved */ |
| 3033 | err = -EINVAL; |
| 3034 | goto out; |
Jouni Malinen | 255e737 | 2009-03-20 21:21:17 +0200 | [diff] [blame] | 3035 | } |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3036 | |
| 3037 | if (info->attrs[NL80211_ATTR_IE]) { |
| 3038 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
| 3039 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); |
| 3040 | } |
| 3041 | |
| 3042 | err = drv->ops->disassoc(&drv->wiphy, dev, &req); |
| 3043 | |
| 3044 | out: |
| 3045 | cfg80211_put_dev(drv); |
| 3046 | dev_put(dev); |
| 3047 | unlock_rtnl: |
| 3048 | rtnl_unlock(); |
| 3049 | return err; |
| 3050 | } |
| 3051 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3052 | static struct genl_ops nl80211_ops[] = { |
| 3053 | { |
| 3054 | .cmd = NL80211_CMD_GET_WIPHY, |
| 3055 | .doit = nl80211_get_wiphy, |
| 3056 | .dumpit = nl80211_dump_wiphy, |
| 3057 | .policy = nl80211_policy, |
| 3058 | /* can be retrieved by unprivileged users */ |
| 3059 | }, |
| 3060 | { |
| 3061 | .cmd = NL80211_CMD_SET_WIPHY, |
| 3062 | .doit = nl80211_set_wiphy, |
| 3063 | .policy = nl80211_policy, |
| 3064 | .flags = GENL_ADMIN_PERM, |
| 3065 | }, |
| 3066 | { |
| 3067 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 3068 | .doit = nl80211_get_interface, |
| 3069 | .dumpit = nl80211_dump_interface, |
| 3070 | .policy = nl80211_policy, |
| 3071 | /* can be retrieved by unprivileged users */ |
| 3072 | }, |
| 3073 | { |
| 3074 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 3075 | .doit = nl80211_set_interface, |
| 3076 | .policy = nl80211_policy, |
| 3077 | .flags = GENL_ADMIN_PERM, |
| 3078 | }, |
| 3079 | { |
| 3080 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 3081 | .doit = nl80211_new_interface, |
| 3082 | .policy = nl80211_policy, |
| 3083 | .flags = GENL_ADMIN_PERM, |
| 3084 | }, |
| 3085 | { |
| 3086 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 3087 | .doit = nl80211_del_interface, |
| 3088 | .policy = nl80211_policy, |
| 3089 | .flags = GENL_ADMIN_PERM, |
| 3090 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 3091 | { |
| 3092 | .cmd = NL80211_CMD_GET_KEY, |
| 3093 | .doit = nl80211_get_key, |
| 3094 | .policy = nl80211_policy, |
| 3095 | .flags = GENL_ADMIN_PERM, |
| 3096 | }, |
| 3097 | { |
| 3098 | .cmd = NL80211_CMD_SET_KEY, |
| 3099 | .doit = nl80211_set_key, |
| 3100 | .policy = nl80211_policy, |
| 3101 | .flags = GENL_ADMIN_PERM, |
| 3102 | }, |
| 3103 | { |
| 3104 | .cmd = NL80211_CMD_NEW_KEY, |
| 3105 | .doit = nl80211_new_key, |
| 3106 | .policy = nl80211_policy, |
| 3107 | .flags = GENL_ADMIN_PERM, |
| 3108 | }, |
| 3109 | { |
| 3110 | .cmd = NL80211_CMD_DEL_KEY, |
| 3111 | .doit = nl80211_del_key, |
| 3112 | .policy = nl80211_policy, |
| 3113 | .flags = GENL_ADMIN_PERM, |
| 3114 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 3115 | { |
| 3116 | .cmd = NL80211_CMD_SET_BEACON, |
| 3117 | .policy = nl80211_policy, |
| 3118 | .flags = GENL_ADMIN_PERM, |
| 3119 | .doit = nl80211_addset_beacon, |
| 3120 | }, |
| 3121 | { |
| 3122 | .cmd = NL80211_CMD_NEW_BEACON, |
| 3123 | .policy = nl80211_policy, |
| 3124 | .flags = GENL_ADMIN_PERM, |
| 3125 | .doit = nl80211_addset_beacon, |
| 3126 | }, |
| 3127 | { |
| 3128 | .cmd = NL80211_CMD_DEL_BEACON, |
| 3129 | .policy = nl80211_policy, |
| 3130 | .flags = GENL_ADMIN_PERM, |
| 3131 | .doit = nl80211_del_beacon, |
| 3132 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3133 | { |
| 3134 | .cmd = NL80211_CMD_GET_STATION, |
| 3135 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3136 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3137 | .policy = nl80211_policy, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 3138 | }, |
| 3139 | { |
| 3140 | .cmd = NL80211_CMD_SET_STATION, |
| 3141 | .doit = nl80211_set_station, |
| 3142 | .policy = nl80211_policy, |
| 3143 | .flags = GENL_ADMIN_PERM, |
| 3144 | }, |
| 3145 | { |
| 3146 | .cmd = NL80211_CMD_NEW_STATION, |
| 3147 | .doit = nl80211_new_station, |
| 3148 | .policy = nl80211_policy, |
| 3149 | .flags = GENL_ADMIN_PERM, |
| 3150 | }, |
| 3151 | { |
| 3152 | .cmd = NL80211_CMD_DEL_STATION, |
| 3153 | .doit = nl80211_del_station, |
| 3154 | .policy = nl80211_policy, |
| 3155 | .flags = GENL_ADMIN_PERM, |
| 3156 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 3157 | { |
| 3158 | .cmd = NL80211_CMD_GET_MPATH, |
| 3159 | .doit = nl80211_get_mpath, |
| 3160 | .dumpit = nl80211_dump_mpath, |
| 3161 | .policy = nl80211_policy, |
| 3162 | .flags = GENL_ADMIN_PERM, |
| 3163 | }, |
| 3164 | { |
| 3165 | .cmd = NL80211_CMD_SET_MPATH, |
| 3166 | .doit = nl80211_set_mpath, |
| 3167 | .policy = nl80211_policy, |
| 3168 | .flags = GENL_ADMIN_PERM, |
| 3169 | }, |
| 3170 | { |
| 3171 | .cmd = NL80211_CMD_NEW_MPATH, |
| 3172 | .doit = nl80211_new_mpath, |
| 3173 | .policy = nl80211_policy, |
| 3174 | .flags = GENL_ADMIN_PERM, |
| 3175 | }, |
| 3176 | { |
| 3177 | .cmd = NL80211_CMD_DEL_MPATH, |
| 3178 | .doit = nl80211_del_mpath, |
| 3179 | .policy = nl80211_policy, |
| 3180 | .flags = GENL_ADMIN_PERM, |
| 3181 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3182 | { |
| 3183 | .cmd = NL80211_CMD_SET_BSS, |
| 3184 | .doit = nl80211_set_bss, |
| 3185 | .policy = nl80211_policy, |
| 3186 | .flags = GENL_ADMIN_PERM, |
| 3187 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3188 | { |
Luis R. Rodriguez | f130347 | 2009-01-30 09:26:42 -0800 | [diff] [blame] | 3189 | .cmd = NL80211_CMD_GET_REG, |
| 3190 | .doit = nl80211_get_reg, |
| 3191 | .policy = nl80211_policy, |
| 3192 | /* can be retrieved by unprivileged users */ |
| 3193 | }, |
| 3194 | { |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 3195 | .cmd = NL80211_CMD_SET_REG, |
| 3196 | .doit = nl80211_set_reg, |
| 3197 | .policy = nl80211_policy, |
| 3198 | .flags = GENL_ADMIN_PERM, |
| 3199 | }, |
| 3200 | { |
| 3201 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 3202 | .doit = nl80211_req_set_reg, |
| 3203 | .policy = nl80211_policy, |
| 3204 | .flags = GENL_ADMIN_PERM, |
| 3205 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 3206 | { |
| 3207 | .cmd = NL80211_CMD_GET_MESH_PARAMS, |
| 3208 | .doit = nl80211_get_mesh_params, |
| 3209 | .policy = nl80211_policy, |
| 3210 | /* can be retrieved by unprivileged users */ |
| 3211 | }, |
| 3212 | { |
| 3213 | .cmd = NL80211_CMD_SET_MESH_PARAMS, |
| 3214 | .doit = nl80211_set_mesh_params, |
| 3215 | .policy = nl80211_policy, |
| 3216 | .flags = GENL_ADMIN_PERM, |
| 3217 | }, |
Jouni Malinen | 9aed3cc | 2009-01-13 16:03:29 +0200 | [diff] [blame] | 3218 | { |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3219 | .cmd = NL80211_CMD_TRIGGER_SCAN, |
| 3220 | .doit = nl80211_trigger_scan, |
| 3221 | .policy = nl80211_policy, |
| 3222 | .flags = GENL_ADMIN_PERM, |
| 3223 | }, |
| 3224 | { |
| 3225 | .cmd = NL80211_CMD_GET_SCAN, |
| 3226 | .policy = nl80211_policy, |
| 3227 | .dumpit = nl80211_dump_scan, |
| 3228 | }, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3229 | { |
| 3230 | .cmd = NL80211_CMD_AUTHENTICATE, |
| 3231 | .doit = nl80211_authenticate, |
| 3232 | .policy = nl80211_policy, |
| 3233 | .flags = GENL_ADMIN_PERM, |
| 3234 | }, |
| 3235 | { |
| 3236 | .cmd = NL80211_CMD_ASSOCIATE, |
| 3237 | .doit = nl80211_associate, |
| 3238 | .policy = nl80211_policy, |
| 3239 | .flags = GENL_ADMIN_PERM, |
| 3240 | }, |
| 3241 | { |
| 3242 | .cmd = NL80211_CMD_DEAUTHENTICATE, |
| 3243 | .doit = nl80211_deauthenticate, |
| 3244 | .policy = nl80211_policy, |
| 3245 | .flags = GENL_ADMIN_PERM, |
| 3246 | }, |
| 3247 | { |
| 3248 | .cmd = NL80211_CMD_DISASSOCIATE, |
| 3249 | .doit = nl80211_disassociate, |
| 3250 | .policy = nl80211_policy, |
| 3251 | .flags = GENL_ADMIN_PERM, |
| 3252 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3253 | }; |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3254 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
| 3255 | .name = "mlme", |
| 3256 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3257 | |
| 3258 | /* multicast groups */ |
| 3259 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 3260 | .name = "config", |
| 3261 | }; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3262 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
| 3263 | .name = "scan", |
| 3264 | }; |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3265 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
| 3266 | .name = "regulatory", |
| 3267 | }; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3268 | |
| 3269 | /* notification functions */ |
| 3270 | |
| 3271 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 3272 | { |
| 3273 | struct sk_buff *msg; |
| 3274 | |
| 3275 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3276 | if (!msg) |
| 3277 | return; |
| 3278 | |
| 3279 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 3280 | nlmsg_free(msg); |
| 3281 | return; |
| 3282 | } |
| 3283 | |
| 3284 | genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); |
| 3285 | } |
| 3286 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3287 | static int nl80211_send_scan_donemsg(struct sk_buff *msg, |
| 3288 | struct cfg80211_registered_device *rdev, |
| 3289 | struct net_device *netdev, |
| 3290 | u32 pid, u32 seq, int flags, |
| 3291 | u32 cmd) |
| 3292 | { |
| 3293 | void *hdr; |
| 3294 | |
| 3295 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); |
| 3296 | if (!hdr) |
| 3297 | return -1; |
| 3298 | |
Luis R. Rodriguez | b5850a7 | 2009-02-21 00:04:19 -0500 | [diff] [blame] | 3299 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3300 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3301 | |
| 3302 | /* XXX: we should probably bounce back the request? */ |
| 3303 | |
| 3304 | return genlmsg_end(msg, hdr); |
| 3305 | |
| 3306 | nla_put_failure: |
| 3307 | genlmsg_cancel(msg, hdr); |
| 3308 | return -EMSGSIZE; |
| 3309 | } |
| 3310 | |
| 3311 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
| 3312 | struct net_device *netdev) |
| 3313 | { |
| 3314 | struct sk_buff *msg; |
| 3315 | |
| 3316 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3317 | if (!msg) |
| 3318 | return; |
| 3319 | |
| 3320 | if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, |
| 3321 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { |
| 3322 | nlmsg_free(msg); |
| 3323 | return; |
| 3324 | } |
| 3325 | |
| 3326 | genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 3327 | } |
| 3328 | |
| 3329 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, |
| 3330 | struct net_device *netdev) |
| 3331 | { |
| 3332 | struct sk_buff *msg; |
| 3333 | |
| 3334 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3335 | if (!msg) |
| 3336 | return; |
| 3337 | |
| 3338 | if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, |
| 3339 | NL80211_CMD_SCAN_ABORTED) < 0) { |
| 3340 | nlmsg_free(msg); |
| 3341 | return; |
| 3342 | } |
| 3343 | |
| 3344 | genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL); |
| 3345 | } |
| 3346 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3347 | /* |
| 3348 | * This can happen on global regulatory changes or device specific settings |
| 3349 | * based on custom world regulatory domains. |
| 3350 | */ |
| 3351 | void nl80211_send_reg_change_event(struct regulatory_request *request) |
| 3352 | { |
| 3353 | struct sk_buff *msg; |
| 3354 | void *hdr; |
| 3355 | |
| 3356 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3357 | if (!msg) |
| 3358 | return; |
| 3359 | |
| 3360 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); |
| 3361 | if (!hdr) { |
| 3362 | nlmsg_free(msg); |
| 3363 | return; |
| 3364 | } |
| 3365 | |
| 3366 | /* Userspace can always count this one always being set */ |
| 3367 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); |
| 3368 | |
| 3369 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') |
| 3370 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3371 | NL80211_REGDOM_TYPE_WORLD); |
| 3372 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') |
| 3373 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3374 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); |
| 3375 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || |
| 3376 | request->intersect) |
| 3377 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3378 | NL80211_REGDOM_TYPE_INTERSECTION); |
| 3379 | else { |
| 3380 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, |
| 3381 | NL80211_REGDOM_TYPE_COUNTRY); |
| 3382 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); |
| 3383 | } |
| 3384 | |
| 3385 | if (wiphy_idx_valid(request->wiphy_idx)) |
| 3386 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); |
| 3387 | |
| 3388 | if (genlmsg_end(msg, hdr) < 0) { |
| 3389 | nlmsg_free(msg); |
| 3390 | return; |
| 3391 | } |
| 3392 | |
| 3393 | genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL); |
| 3394 | |
| 3395 | return; |
| 3396 | |
| 3397 | nla_put_failure: |
| 3398 | genlmsg_cancel(msg, hdr); |
| 3399 | nlmsg_free(msg); |
| 3400 | } |
| 3401 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3402 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
| 3403 | struct net_device *netdev, |
| 3404 | const u8 *buf, size_t len, |
| 3405 | enum nl80211_commands cmd) |
| 3406 | { |
| 3407 | struct sk_buff *msg; |
| 3408 | void *hdr; |
| 3409 | |
Jouni Malinen | d91c01c | 2009-04-18 21:53:15 +0300 | [diff] [blame] | 3410 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3411 | if (!msg) |
| 3412 | return; |
| 3413 | |
| 3414 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
| 3415 | if (!hdr) { |
| 3416 | nlmsg_free(msg); |
| 3417 | return; |
| 3418 | } |
| 3419 | |
| 3420 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3421 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3422 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); |
| 3423 | |
| 3424 | if (genlmsg_end(msg, hdr) < 0) { |
| 3425 | nlmsg_free(msg); |
| 3426 | return; |
| 3427 | } |
| 3428 | |
Jouni Malinen | d91c01c | 2009-04-18 21:53:15 +0300 | [diff] [blame] | 3429 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3430 | return; |
| 3431 | |
| 3432 | nla_put_failure: |
| 3433 | genlmsg_cancel(msg, hdr); |
| 3434 | nlmsg_free(msg); |
| 3435 | } |
| 3436 | |
| 3437 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, |
| 3438 | struct net_device *netdev, const u8 *buf, size_t len) |
| 3439 | { |
| 3440 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3441 | NL80211_CMD_AUTHENTICATE); |
| 3442 | } |
| 3443 | |
| 3444 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, |
| 3445 | struct net_device *netdev, const u8 *buf, |
| 3446 | size_t len) |
| 3447 | { |
| 3448 | nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE); |
| 3449 | } |
| 3450 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 3451 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
| 3452 | struct net_device *netdev, const u8 *buf, size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3453 | { |
| 3454 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3455 | NL80211_CMD_DEAUTHENTICATE); |
| 3456 | } |
| 3457 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 3458 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
| 3459 | struct net_device *netdev, const u8 *buf, |
| 3460 | size_t len) |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3461 | { |
| 3462 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
| 3463 | NL80211_CMD_DISASSOCIATE); |
| 3464 | } |
| 3465 | |
Jouni Malinen | a3b8b05 | 2009-03-27 21:59:49 +0200 | [diff] [blame] | 3466 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
| 3467 | struct net_device *netdev, const u8 *addr, |
| 3468 | enum nl80211_key_type key_type, int key_id, |
| 3469 | const u8 *tsc) |
| 3470 | { |
| 3471 | struct sk_buff *msg; |
| 3472 | void *hdr; |
| 3473 | |
| 3474 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 3475 | if (!msg) |
| 3476 | return; |
| 3477 | |
| 3478 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); |
| 3479 | if (!hdr) { |
| 3480 | nlmsg_free(msg); |
| 3481 | return; |
| 3482 | } |
| 3483 | |
| 3484 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
| 3485 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
| 3486 | if (addr) |
| 3487 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); |
| 3488 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); |
| 3489 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); |
| 3490 | if (tsc) |
| 3491 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); |
| 3492 | |
| 3493 | if (genlmsg_end(msg, hdr) < 0) { |
| 3494 | nlmsg_free(msg); |
| 3495 | return; |
| 3496 | } |
| 3497 | |
| 3498 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL); |
| 3499 | return; |
| 3500 | |
| 3501 | nla_put_failure: |
| 3502 | genlmsg_cancel(msg, hdr); |
| 3503 | nlmsg_free(msg); |
| 3504 | } |
| 3505 | |
Luis R. Rodriguez | 6bad876 | 2009-04-02 14:08:09 -0400 | [diff] [blame] | 3506 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
| 3507 | struct ieee80211_channel *channel_before, |
| 3508 | struct ieee80211_channel *channel_after) |
| 3509 | { |
| 3510 | struct sk_buff *msg; |
| 3511 | void *hdr; |
| 3512 | struct nlattr *nl_freq; |
| 3513 | |
| 3514 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); |
| 3515 | if (!msg) |
| 3516 | return; |
| 3517 | |
| 3518 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); |
| 3519 | if (!hdr) { |
| 3520 | nlmsg_free(msg); |
| 3521 | return; |
| 3522 | } |
| 3523 | |
| 3524 | /* |
| 3525 | * Since we are applying the beacon hint to a wiphy we know its |
| 3526 | * wiphy_idx is valid |
| 3527 | */ |
| 3528 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); |
| 3529 | |
| 3530 | /* Before */ |
| 3531 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); |
| 3532 | if (!nl_freq) |
| 3533 | goto nla_put_failure; |
| 3534 | if (nl80211_msg_put_channel(msg, channel_before)) |
| 3535 | goto nla_put_failure; |
| 3536 | nla_nest_end(msg, nl_freq); |
| 3537 | |
| 3538 | /* After */ |
| 3539 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); |
| 3540 | if (!nl_freq) |
| 3541 | goto nla_put_failure; |
| 3542 | if (nl80211_msg_put_channel(msg, channel_after)) |
| 3543 | goto nla_put_failure; |
| 3544 | nla_nest_end(msg, nl_freq); |
| 3545 | |
| 3546 | if (genlmsg_end(msg, hdr) < 0) { |
| 3547 | nlmsg_free(msg); |
| 3548 | return; |
| 3549 | } |
| 3550 | |
| 3551 | genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_ATOMIC); |
| 3552 | |
| 3553 | return; |
| 3554 | |
| 3555 | nla_put_failure: |
| 3556 | genlmsg_cancel(msg, hdr); |
| 3557 | nlmsg_free(msg); |
| 3558 | } |
| 3559 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3560 | /* initialisation/exit functions */ |
| 3561 | |
| 3562 | int nl80211_init(void) |
| 3563 | { |
| 3564 | int err, i; |
| 3565 | |
| 3566 | err = genl_register_family(&nl80211_fam); |
| 3567 | if (err) |
| 3568 | return err; |
| 3569 | |
| 3570 | for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) { |
| 3571 | err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]); |
| 3572 | if (err) |
| 3573 | goto err_out; |
| 3574 | } |
| 3575 | |
| 3576 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 3577 | if (err) |
| 3578 | goto err_out; |
| 3579 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3580 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
| 3581 | if (err) |
| 3582 | goto err_out; |
| 3583 | |
Luis R. Rodriguez | 73d54c9 | 2009-03-09 22:07:42 -0400 | [diff] [blame] | 3584 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
| 3585 | if (err) |
| 3586 | goto err_out; |
| 3587 | |
Jouni Malinen | 6039f6d | 2009-03-19 13:39:21 +0200 | [diff] [blame] | 3588 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
| 3589 | if (err) |
| 3590 | goto err_out; |
| 3591 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 3592 | return 0; |
| 3593 | err_out: |
| 3594 | genl_unregister_family(&nl80211_fam); |
| 3595 | return err; |
| 3596 | } |
| 3597 | |
| 3598 | void nl80211_exit(void) |
| 3599 | { |
| 3600 | genl_unregister_family(&nl80211_fam); |
| 3601 | } |