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