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> |
| 10 | #include <linux/mutex.h> |
| 11 | #include <linux/list.h> |
| 12 | #include <linux/if_ether.h> |
| 13 | #include <linux/ieee80211.h> |
| 14 | #include <linux/nl80211.h> |
| 15 | #include <linux/rtnetlink.h> |
| 16 | #include <linux/netlink.h> |
| 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 }, |
| 61 | |
| 62 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, |
| 63 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, |
| 64 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 65 | |
| 66 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
| 67 | |
| 68 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
| 69 | .len = WLAN_MAX_KEY_LEN }, |
| 70 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, |
| 71 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, |
| 72 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 73 | |
| 74 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, |
| 75 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, |
| 76 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, |
| 77 | .len = IEEE80211_MAX_DATA_LEN }, |
| 78 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, |
| 79 | .len = IEEE80211_MAX_DATA_LEN }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 80 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
| 81 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, |
| 82 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, |
| 83 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, |
| 84 | .len = NL80211_MAX_SUPP_RATES }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 85 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 86 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
Johannes Berg | 0a9542e | 2008-10-15 11:54:04 +0200 | [diff] [blame] | 87 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 88 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
| 89 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
| 90 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 91 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 92 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
| 93 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, |
| 94 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 95 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
| 96 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, |
| 97 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame^] | 98 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
| 99 | .len = NL80211_MAX_SUPP_RATES }, |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 100 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 101 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
| 102 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 103 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
| 104 | .len = NL80211_HT_CAPABILITY_LEN }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /* message building helper */ |
| 108 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, |
| 109 | int flags, u8 cmd) |
| 110 | { |
| 111 | /* since there is no private header just add the generic one */ |
| 112 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); |
| 113 | } |
| 114 | |
| 115 | /* netlink command implementations */ |
| 116 | |
| 117 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 118 | struct cfg80211_registered_device *dev) |
| 119 | { |
| 120 | void *hdr; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 121 | struct nlattr *nl_bands, *nl_band; |
| 122 | struct nlattr *nl_freqs, *nl_freq; |
| 123 | struct nlattr *nl_rates, *nl_rate; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 124 | struct nlattr *nl_modes; |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 125 | enum ieee80211_band band; |
| 126 | struct ieee80211_channel *chan; |
| 127 | struct ieee80211_rate *rate; |
| 128 | int i; |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 129 | u16 ifmodes = dev->wiphy.interface_modes; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 130 | |
| 131 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); |
| 132 | if (!hdr) |
| 133 | return -1; |
| 134 | |
| 135 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->idx); |
| 136 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 137 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 138 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
| 139 | if (!nl_modes) |
| 140 | goto nla_put_failure; |
| 141 | |
| 142 | i = 0; |
| 143 | while (ifmodes) { |
| 144 | if (ifmodes & 1) |
| 145 | NLA_PUT_FLAG(msg, i); |
| 146 | ifmodes >>= 1; |
| 147 | i++; |
| 148 | } |
| 149 | |
| 150 | nla_nest_end(msg, nl_modes); |
| 151 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 152 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
| 153 | if (!nl_bands) |
| 154 | goto nla_put_failure; |
| 155 | |
| 156 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
| 157 | if (!dev->wiphy.bands[band]) |
| 158 | continue; |
| 159 | |
| 160 | nl_band = nla_nest_start(msg, band); |
| 161 | if (!nl_band) |
| 162 | goto nla_put_failure; |
| 163 | |
Johannes Berg | d51626d | 2008-10-09 12:20:13 +0200 | [diff] [blame] | 164 | /* add HT info */ |
| 165 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { |
| 166 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, |
| 167 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), |
| 168 | &dev->wiphy.bands[band]->ht_cap.mcs); |
| 169 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, |
| 170 | dev->wiphy.bands[band]->ht_cap.cap); |
| 171 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, |
| 172 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); |
| 173 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, |
| 174 | dev->wiphy.bands[band]->ht_cap.ampdu_density); |
| 175 | } |
| 176 | |
Johannes Berg | ee688b00 | 2008-01-24 19:38:39 +0100 | [diff] [blame] | 177 | /* add frequencies */ |
| 178 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); |
| 179 | if (!nl_freqs) |
| 180 | goto nla_put_failure; |
| 181 | |
| 182 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { |
| 183 | nl_freq = nla_nest_start(msg, i); |
| 184 | if (!nl_freq) |
| 185 | goto nla_put_failure; |
| 186 | |
| 187 | chan = &dev->wiphy.bands[band]->channels[i]; |
| 188 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
| 189 | chan->center_freq); |
| 190 | |
| 191 | if (chan->flags & IEEE80211_CHAN_DISABLED) |
| 192 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); |
| 193 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
| 194 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); |
| 195 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) |
| 196 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); |
| 197 | if (chan->flags & IEEE80211_CHAN_RADAR) |
| 198 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); |
| 199 | |
| 200 | nla_nest_end(msg, nl_freq); |
| 201 | } |
| 202 | |
| 203 | nla_nest_end(msg, nl_freqs); |
| 204 | |
| 205 | /* add bitrates */ |
| 206 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); |
| 207 | if (!nl_rates) |
| 208 | goto nla_put_failure; |
| 209 | |
| 210 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { |
| 211 | nl_rate = nla_nest_start(msg, i); |
| 212 | if (!nl_rate) |
| 213 | goto nla_put_failure; |
| 214 | |
| 215 | rate = &dev->wiphy.bands[band]->bitrates[i]; |
| 216 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, |
| 217 | rate->bitrate); |
| 218 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) |
| 219 | NLA_PUT_FLAG(msg, |
| 220 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); |
| 221 | |
| 222 | nla_nest_end(msg, nl_rate); |
| 223 | } |
| 224 | |
| 225 | nla_nest_end(msg, nl_rates); |
| 226 | |
| 227 | nla_nest_end(msg, nl_band); |
| 228 | } |
| 229 | nla_nest_end(msg, nl_bands); |
| 230 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 231 | return genlmsg_end(msg, hdr); |
| 232 | |
| 233 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 234 | genlmsg_cancel(msg, hdr); |
| 235 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
| 239 | { |
| 240 | int idx = 0; |
| 241 | int start = cb->args[0]; |
| 242 | struct cfg80211_registered_device *dev; |
| 243 | |
| 244 | mutex_lock(&cfg80211_drv_mutex); |
| 245 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 246 | if (++idx <= start) |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 247 | continue; |
| 248 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, |
| 249 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 250 | dev) < 0) { |
| 251 | idx--; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 252 | break; |
Julius Volz | b463727 | 2008-07-08 14:02:19 +0200 | [diff] [blame] | 253 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 254 | } |
| 255 | mutex_unlock(&cfg80211_drv_mutex); |
| 256 | |
| 257 | cb->args[0] = idx; |
| 258 | |
| 259 | return skb->len; |
| 260 | } |
| 261 | |
| 262 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 263 | { |
| 264 | struct sk_buff *msg; |
| 265 | struct cfg80211_registered_device *dev; |
| 266 | |
| 267 | dev = cfg80211_get_dev_from_info(info); |
| 268 | if (IS_ERR(dev)) |
| 269 | return PTR_ERR(dev); |
| 270 | |
| 271 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 272 | if (!msg) |
| 273 | goto out_err; |
| 274 | |
| 275 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) |
| 276 | goto out_free; |
| 277 | |
| 278 | cfg80211_put_dev(dev); |
| 279 | |
| 280 | return genlmsg_unicast(msg, info->snd_pid); |
| 281 | |
| 282 | out_free: |
| 283 | nlmsg_free(msg); |
| 284 | out_err: |
| 285 | cfg80211_put_dev(dev); |
| 286 | return -ENOBUFS; |
| 287 | } |
| 288 | |
| 289 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
| 290 | { |
| 291 | struct cfg80211_registered_device *rdev; |
| 292 | int result; |
| 293 | |
| 294 | if (!info->attrs[NL80211_ATTR_WIPHY_NAME]) |
| 295 | return -EINVAL; |
| 296 | |
| 297 | rdev = cfg80211_get_dev_from_info(info); |
| 298 | if (IS_ERR(rdev)) |
| 299 | return PTR_ERR(rdev); |
| 300 | |
| 301 | result = cfg80211_dev_rename(rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); |
| 302 | |
| 303 | cfg80211_put_dev(rdev); |
| 304 | return result; |
| 305 | } |
| 306 | |
| 307 | |
| 308 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
| 309 | struct net_device *dev) |
| 310 | { |
| 311 | void *hdr; |
| 312 | |
| 313 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); |
| 314 | if (!hdr) |
| 315 | return -1; |
| 316 | |
| 317 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 318 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 319 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 320 | return genlmsg_end(msg, hdr); |
| 321 | |
| 322 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 323 | genlmsg_cancel(msg, hdr); |
| 324 | return -EMSGSIZE; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) |
| 328 | { |
| 329 | int wp_idx = 0; |
| 330 | int if_idx = 0; |
| 331 | int wp_start = cb->args[0]; |
| 332 | int if_start = cb->args[1]; |
| 333 | struct cfg80211_registered_device *dev; |
| 334 | struct wireless_dev *wdev; |
| 335 | |
| 336 | mutex_lock(&cfg80211_drv_mutex); |
| 337 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 338 | if (wp_idx < wp_start) { |
| 339 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 340 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 341 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 342 | if_idx = 0; |
| 343 | |
| 344 | mutex_lock(&dev->devlist_mtx); |
| 345 | list_for_each_entry(wdev, &dev->netdev_list, list) { |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 346 | if (if_idx < if_start) { |
| 347 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 348 | continue; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 349 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 350 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
| 351 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 352 | wdev->netdev) < 0) { |
| 353 | mutex_unlock(&dev->devlist_mtx); |
| 354 | goto out; |
| 355 | } |
| 356 | if_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 357 | } |
| 358 | mutex_unlock(&dev->devlist_mtx); |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 359 | |
| 360 | wp_idx++; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 361 | } |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 362 | out: |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 363 | mutex_unlock(&cfg80211_drv_mutex); |
| 364 | |
| 365 | cb->args[0] = wp_idx; |
| 366 | cb->args[1] = if_idx; |
| 367 | |
| 368 | return skb->len; |
| 369 | } |
| 370 | |
| 371 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) |
| 372 | { |
| 373 | struct sk_buff *msg; |
| 374 | struct cfg80211_registered_device *dev; |
| 375 | struct net_device *netdev; |
| 376 | int err; |
| 377 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 378 | err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 379 | if (err) |
| 380 | return err; |
| 381 | |
| 382 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 383 | if (!msg) |
| 384 | goto out_err; |
| 385 | |
| 386 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0) |
| 387 | goto out_free; |
| 388 | |
| 389 | dev_put(netdev); |
| 390 | cfg80211_put_dev(dev); |
| 391 | |
| 392 | return genlmsg_unicast(msg, info->snd_pid); |
| 393 | |
| 394 | out_free: |
| 395 | nlmsg_free(msg); |
| 396 | out_err: |
| 397 | dev_put(netdev); |
| 398 | cfg80211_put_dev(dev); |
| 399 | return -ENOBUFS; |
| 400 | } |
| 401 | |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 402 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
| 403 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, |
| 404 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, |
| 405 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, |
| 406 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, |
| 407 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, |
| 408 | }; |
| 409 | |
| 410 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) |
| 411 | { |
| 412 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; |
| 413 | int flag; |
| 414 | |
| 415 | *mntrflags = 0; |
| 416 | |
| 417 | if (!nla) |
| 418 | return -EINVAL; |
| 419 | |
| 420 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, |
| 421 | nla, mntr_flags_policy)) |
| 422 | return -EINVAL; |
| 423 | |
| 424 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) |
| 425 | if (flags[flag]) |
| 426 | *mntrflags |= (1<<flag); |
| 427 | |
| 428 | return 0; |
| 429 | } |
| 430 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 431 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
| 432 | { |
| 433 | struct cfg80211_registered_device *drv; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 434 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 435 | int err, ifindex; |
| 436 | enum nl80211_iftype type; |
| 437 | struct net_device *dev; |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 438 | u32 _flags, *flags = NULL; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 439 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 440 | memset(¶ms, 0, sizeof(params)); |
| 441 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 442 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 443 | if (err) |
| 444 | return err; |
| 445 | ifindex = dev->ifindex; |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 446 | type = dev->ieee80211_ptr->iftype; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 447 | dev_put(dev); |
| 448 | |
Johannes Berg | 723b038 | 2008-09-16 20:22:09 +0200 | [diff] [blame] | 449 | err = -EINVAL; |
| 450 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 451 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 452 | if (type > NL80211_IFTYPE_MAX) |
| 453 | goto unlock; |
| 454 | } |
| 455 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 456 | if (!drv->ops->change_virtual_intf || |
| 457 | !(drv->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 458 | err = -EOPNOTSUPP; |
| 459 | goto unlock; |
| 460 | } |
| 461 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 462 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
| 463 | if (type != NL80211_IFTYPE_MESH_POINT) { |
| 464 | err = -EINVAL; |
| 465 | goto unlock; |
| 466 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 467 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 468 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 469 | } |
| 470 | |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 471 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
| 472 | if (type != NL80211_IFTYPE_MONITOR) { |
| 473 | err = -EINVAL; |
| 474 | goto unlock; |
| 475 | } |
| 476 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
| 477 | &_flags); |
| 478 | if (!err) |
| 479 | flags = &_flags; |
| 480 | } |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 481 | rtnl_lock(); |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 482 | err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, |
Johannes Berg | 92ffe05 | 2008-09-16 20:39:36 +0200 | [diff] [blame] | 483 | type, flags, ¶ms); |
Johannes Berg | 60719ff | 2008-09-16 14:55:09 +0200 | [diff] [blame] | 484 | |
| 485 | dev = __dev_get_by_index(&init_net, ifindex); |
| 486 | WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type)); |
| 487 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 488 | rtnl_unlock(); |
| 489 | |
| 490 | unlock: |
| 491 | cfg80211_put_dev(drv); |
| 492 | return err; |
| 493 | } |
| 494 | |
| 495 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) |
| 496 | { |
| 497 | struct cfg80211_registered_device *drv; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 498 | struct vif_params params; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 499 | int err; |
| 500 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 501 | u32 flags; |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 502 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 503 | memset(¶ms, 0, sizeof(params)); |
| 504 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 505 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
| 506 | return -EINVAL; |
| 507 | |
| 508 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
| 509 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
| 510 | if (type > NL80211_IFTYPE_MAX) |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | |
| 514 | drv = cfg80211_get_dev_from_info(info); |
| 515 | if (IS_ERR(drv)) |
| 516 | return PTR_ERR(drv); |
| 517 | |
Luis R. Rodriguez | f59ac04 | 2008-08-29 16:26:43 -0700 | [diff] [blame] | 518 | if (!drv->ops->add_virtual_intf || |
| 519 | !(drv->wiphy.interface_modes & (1 << type))) { |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 520 | err = -EOPNOTSUPP; |
| 521 | goto unlock; |
| 522 | } |
| 523 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 524 | if (type == NL80211_IFTYPE_MESH_POINT && |
| 525 | info->attrs[NL80211_ATTR_MESH_ID]) { |
| 526 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
| 527 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); |
| 528 | } |
| 529 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 530 | rtnl_lock(); |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 531 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
| 532 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, |
| 533 | &flags); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 534 | err = drv->ops->add_virtual_intf(&drv->wiphy, |
Michael Wu | 66f7ac5 | 2008-01-31 19:48:22 +0100 | [diff] [blame] | 535 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 536 | type, err ? NULL : &flags, ¶ms); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 537 | rtnl_unlock(); |
| 538 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 539 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 540 | unlock: |
| 541 | cfg80211_put_dev(drv); |
| 542 | return err; |
| 543 | } |
| 544 | |
| 545 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) |
| 546 | { |
| 547 | struct cfg80211_registered_device *drv; |
| 548 | int ifindex, err; |
| 549 | struct net_device *dev; |
| 550 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 551 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 552 | if (err) |
| 553 | return err; |
| 554 | ifindex = dev->ifindex; |
| 555 | dev_put(dev); |
| 556 | |
| 557 | if (!drv->ops->del_virtual_intf) { |
| 558 | err = -EOPNOTSUPP; |
| 559 | goto out; |
| 560 | } |
| 561 | |
| 562 | rtnl_lock(); |
| 563 | err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex); |
| 564 | rtnl_unlock(); |
| 565 | |
| 566 | out: |
| 567 | cfg80211_put_dev(drv); |
| 568 | return err; |
| 569 | } |
| 570 | |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 571 | struct get_key_cookie { |
| 572 | struct sk_buff *msg; |
| 573 | int error; |
| 574 | }; |
| 575 | |
| 576 | static void get_key_callback(void *c, struct key_params *params) |
| 577 | { |
| 578 | struct get_key_cookie *cookie = c; |
| 579 | |
| 580 | if (params->key) |
| 581 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, |
| 582 | params->key_len, params->key); |
| 583 | |
| 584 | if (params->seq) |
| 585 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, |
| 586 | params->seq_len, params->seq); |
| 587 | |
| 588 | if (params->cipher) |
| 589 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, |
| 590 | params->cipher); |
| 591 | |
| 592 | return; |
| 593 | nla_put_failure: |
| 594 | cookie->error = 1; |
| 595 | } |
| 596 | |
| 597 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) |
| 598 | { |
| 599 | struct cfg80211_registered_device *drv; |
| 600 | int err; |
| 601 | struct net_device *dev; |
| 602 | u8 key_idx = 0; |
| 603 | u8 *mac_addr = NULL; |
| 604 | struct get_key_cookie cookie = { |
| 605 | .error = 0, |
| 606 | }; |
| 607 | void *hdr; |
| 608 | struct sk_buff *msg; |
| 609 | |
| 610 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 611 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 612 | |
| 613 | if (key_idx > 3) |
| 614 | return -EINVAL; |
| 615 | |
| 616 | if (info->attrs[NL80211_ATTR_MAC]) |
| 617 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 618 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 619 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 620 | if (err) |
| 621 | return err; |
| 622 | |
| 623 | if (!drv->ops->get_key) { |
| 624 | err = -EOPNOTSUPP; |
| 625 | goto out; |
| 626 | } |
| 627 | |
| 628 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 629 | if (!msg) { |
| 630 | err = -ENOMEM; |
| 631 | goto out; |
| 632 | } |
| 633 | |
| 634 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 635 | NL80211_CMD_NEW_KEY); |
| 636 | |
| 637 | if (IS_ERR(hdr)) { |
| 638 | err = PTR_ERR(hdr); |
| 639 | goto out; |
| 640 | } |
| 641 | |
| 642 | cookie.msg = msg; |
| 643 | |
| 644 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 645 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); |
| 646 | if (mac_addr) |
| 647 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 648 | |
| 649 | rtnl_lock(); |
| 650 | err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr, |
| 651 | &cookie, get_key_callback); |
| 652 | rtnl_unlock(); |
| 653 | |
| 654 | if (err) |
| 655 | goto out; |
| 656 | |
| 657 | if (cookie.error) |
| 658 | goto nla_put_failure; |
| 659 | |
| 660 | genlmsg_end(msg, hdr); |
| 661 | err = genlmsg_unicast(msg, info->snd_pid); |
| 662 | goto out; |
| 663 | |
| 664 | nla_put_failure: |
| 665 | err = -ENOBUFS; |
| 666 | nlmsg_free(msg); |
| 667 | out: |
| 668 | cfg80211_put_dev(drv); |
| 669 | dev_put(dev); |
| 670 | return err; |
| 671 | } |
| 672 | |
| 673 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) |
| 674 | { |
| 675 | struct cfg80211_registered_device *drv; |
| 676 | int err; |
| 677 | struct net_device *dev; |
| 678 | u8 key_idx; |
| 679 | |
| 680 | if (!info->attrs[NL80211_ATTR_KEY_IDX]) |
| 681 | return -EINVAL; |
| 682 | |
| 683 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 684 | |
| 685 | if (key_idx > 3) |
| 686 | return -EINVAL; |
| 687 | |
| 688 | /* currently only support setting default key */ |
| 689 | if (!info->attrs[NL80211_ATTR_KEY_DEFAULT]) |
| 690 | return -EINVAL; |
| 691 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 692 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 693 | if (err) |
| 694 | return err; |
| 695 | |
| 696 | if (!drv->ops->set_default_key) { |
| 697 | err = -EOPNOTSUPP; |
| 698 | goto out; |
| 699 | } |
| 700 | |
| 701 | rtnl_lock(); |
| 702 | err = drv->ops->set_default_key(&drv->wiphy, dev, key_idx); |
| 703 | rtnl_unlock(); |
| 704 | |
| 705 | out: |
| 706 | cfg80211_put_dev(drv); |
| 707 | dev_put(dev); |
| 708 | return err; |
| 709 | } |
| 710 | |
| 711 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) |
| 712 | { |
| 713 | struct cfg80211_registered_device *drv; |
| 714 | int err; |
| 715 | struct net_device *dev; |
| 716 | struct key_params params; |
| 717 | u8 key_idx = 0; |
| 718 | u8 *mac_addr = NULL; |
| 719 | |
| 720 | memset(¶ms, 0, sizeof(params)); |
| 721 | |
| 722 | if (!info->attrs[NL80211_ATTR_KEY_CIPHER]) |
| 723 | return -EINVAL; |
| 724 | |
| 725 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { |
| 726 | params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 727 | params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); |
| 728 | } |
| 729 | |
| 730 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 731 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 732 | |
| 733 | params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); |
| 734 | |
| 735 | if (info->attrs[NL80211_ATTR_MAC]) |
| 736 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 737 | |
| 738 | if (key_idx > 3) |
| 739 | return -EINVAL; |
| 740 | |
| 741 | /* |
| 742 | * Disallow pairwise keys with non-zero index unless it's WEP |
| 743 | * (because current deployments use pairwise WEP keys with |
| 744 | * non-zero indizes but 802.11i clearly specifies to use zero) |
| 745 | */ |
| 746 | if (mac_addr && key_idx && |
| 747 | params.cipher != WLAN_CIPHER_SUITE_WEP40 && |
| 748 | params.cipher != WLAN_CIPHER_SUITE_WEP104) |
| 749 | return -EINVAL; |
| 750 | |
| 751 | /* TODO: add definitions for the lengths to linux/ieee80211.h */ |
| 752 | switch (params.cipher) { |
| 753 | case WLAN_CIPHER_SUITE_WEP40: |
| 754 | if (params.key_len != 5) |
| 755 | return -EINVAL; |
| 756 | break; |
| 757 | case WLAN_CIPHER_SUITE_TKIP: |
| 758 | if (params.key_len != 32) |
| 759 | return -EINVAL; |
| 760 | break; |
| 761 | case WLAN_CIPHER_SUITE_CCMP: |
| 762 | if (params.key_len != 16) |
| 763 | return -EINVAL; |
| 764 | break; |
| 765 | case WLAN_CIPHER_SUITE_WEP104: |
| 766 | if (params.key_len != 13) |
| 767 | return -EINVAL; |
| 768 | break; |
| 769 | default: |
| 770 | return -EINVAL; |
| 771 | } |
| 772 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 773 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 774 | if (err) |
| 775 | return err; |
| 776 | |
| 777 | if (!drv->ops->add_key) { |
| 778 | err = -EOPNOTSUPP; |
| 779 | goto out; |
| 780 | } |
| 781 | |
| 782 | rtnl_lock(); |
| 783 | err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms); |
| 784 | rtnl_unlock(); |
| 785 | |
| 786 | out: |
| 787 | cfg80211_put_dev(drv); |
| 788 | dev_put(dev); |
| 789 | return err; |
| 790 | } |
| 791 | |
| 792 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) |
| 793 | { |
| 794 | struct cfg80211_registered_device *drv; |
| 795 | int err; |
| 796 | struct net_device *dev; |
| 797 | u8 key_idx = 0; |
| 798 | u8 *mac_addr = NULL; |
| 799 | |
| 800 | if (info->attrs[NL80211_ATTR_KEY_IDX]) |
| 801 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); |
| 802 | |
| 803 | if (key_idx > 3) |
| 804 | return -EINVAL; |
| 805 | |
| 806 | if (info->attrs[NL80211_ATTR_MAC]) |
| 807 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 808 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 809 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 810 | if (err) |
| 811 | return err; |
| 812 | |
| 813 | if (!drv->ops->del_key) { |
| 814 | err = -EOPNOTSUPP; |
| 815 | goto out; |
| 816 | } |
| 817 | |
| 818 | rtnl_lock(); |
| 819 | err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr); |
| 820 | rtnl_unlock(); |
| 821 | |
| 822 | out: |
| 823 | cfg80211_put_dev(drv); |
| 824 | dev_put(dev); |
| 825 | return err; |
| 826 | } |
| 827 | |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 828 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
| 829 | { |
| 830 | int (*call)(struct wiphy *wiphy, struct net_device *dev, |
| 831 | struct beacon_parameters *info); |
| 832 | struct cfg80211_registered_device *drv; |
| 833 | int err; |
| 834 | struct net_device *dev; |
| 835 | struct beacon_parameters params; |
| 836 | int haveinfo = 0; |
| 837 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 838 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 839 | if (err) |
| 840 | return err; |
| 841 | |
| 842 | switch (info->genlhdr->cmd) { |
| 843 | case NL80211_CMD_NEW_BEACON: |
| 844 | /* these are required for NEW_BEACON */ |
| 845 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || |
| 846 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || |
| 847 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 848 | err = -EINVAL; |
| 849 | goto out; |
| 850 | } |
| 851 | |
| 852 | call = drv->ops->add_beacon; |
| 853 | break; |
| 854 | case NL80211_CMD_SET_BEACON: |
| 855 | call = drv->ops->set_beacon; |
| 856 | break; |
| 857 | default: |
| 858 | WARN_ON(1); |
| 859 | err = -EOPNOTSUPP; |
| 860 | goto out; |
| 861 | } |
| 862 | |
| 863 | if (!call) { |
| 864 | err = -EOPNOTSUPP; |
| 865 | goto out; |
| 866 | } |
| 867 | |
| 868 | memset(¶ms, 0, sizeof(params)); |
| 869 | |
| 870 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
| 871 | params.interval = |
| 872 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); |
| 873 | haveinfo = 1; |
| 874 | } |
| 875 | |
| 876 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { |
| 877 | params.dtim_period = |
| 878 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); |
| 879 | haveinfo = 1; |
| 880 | } |
| 881 | |
| 882 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { |
| 883 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 884 | params.head_len = |
| 885 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); |
| 886 | haveinfo = 1; |
| 887 | } |
| 888 | |
| 889 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { |
| 890 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 891 | params.tail_len = |
| 892 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); |
| 893 | haveinfo = 1; |
| 894 | } |
| 895 | |
| 896 | if (!haveinfo) { |
| 897 | err = -EINVAL; |
| 898 | goto out; |
| 899 | } |
| 900 | |
| 901 | rtnl_lock(); |
| 902 | err = call(&drv->wiphy, dev, ¶ms); |
| 903 | rtnl_unlock(); |
| 904 | |
| 905 | out: |
| 906 | cfg80211_put_dev(drv); |
| 907 | dev_put(dev); |
| 908 | return err; |
| 909 | } |
| 910 | |
| 911 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) |
| 912 | { |
| 913 | struct cfg80211_registered_device *drv; |
| 914 | int err; |
| 915 | struct net_device *dev; |
| 916 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 917 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 918 | if (err) |
| 919 | return err; |
| 920 | |
| 921 | if (!drv->ops->del_beacon) { |
| 922 | err = -EOPNOTSUPP; |
| 923 | goto out; |
| 924 | } |
| 925 | |
| 926 | rtnl_lock(); |
| 927 | err = drv->ops->del_beacon(&drv->wiphy, dev); |
| 928 | rtnl_unlock(); |
| 929 | |
| 930 | out: |
| 931 | cfg80211_put_dev(drv); |
| 932 | dev_put(dev); |
| 933 | return err; |
| 934 | } |
| 935 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 936 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
| 937 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, |
| 938 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, |
| 939 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, |
| 940 | }; |
| 941 | |
| 942 | static int parse_station_flags(struct nlattr *nla, u32 *staflags) |
| 943 | { |
| 944 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; |
| 945 | int flag; |
| 946 | |
| 947 | *staflags = 0; |
| 948 | |
| 949 | if (!nla) |
| 950 | return 0; |
| 951 | |
| 952 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, |
| 953 | nla, sta_flags_policy)) |
| 954 | return -EINVAL; |
| 955 | |
| 956 | *staflags = STATION_FLAG_CHANGED; |
| 957 | |
| 958 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) |
| 959 | if (flags[flag]) |
| 960 | *staflags |= (1<<flag); |
| 961 | |
| 962 | return 0; |
| 963 | } |
| 964 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 965 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
| 966 | int flags, struct net_device *dev, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 967 | u8 *mac_addr, struct station_info *sinfo) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 968 | { |
| 969 | void *hdr; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 970 | struct nlattr *sinfoattr; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 971 | |
| 972 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 973 | if (!hdr) |
| 974 | return -1; |
| 975 | |
| 976 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 977 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); |
| 978 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 979 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
| 980 | if (!sinfoattr) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 981 | goto nla_put_failure; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 982 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
| 983 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, |
| 984 | sinfo->inactive_time); |
| 985 | if (sinfo->filled & STATION_INFO_RX_BYTES) |
| 986 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, |
| 987 | sinfo->rx_bytes); |
| 988 | if (sinfo->filled & STATION_INFO_TX_BYTES) |
| 989 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, |
| 990 | sinfo->tx_bytes); |
| 991 | if (sinfo->filled & STATION_INFO_LLID) |
| 992 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, |
| 993 | sinfo->llid); |
| 994 | if (sinfo->filled & STATION_INFO_PLID) |
| 995 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, |
| 996 | sinfo->plid); |
| 997 | if (sinfo->filled & STATION_INFO_PLINK_STATE) |
| 998 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, |
| 999 | sinfo->plink_state); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1000 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1001 | nla_nest_end(msg, sinfoattr); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1002 | |
| 1003 | return genlmsg_end(msg, hdr); |
| 1004 | |
| 1005 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1006 | genlmsg_cancel(msg, hdr); |
| 1007 | return -EMSGSIZE; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1008 | } |
| 1009 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1010 | static int nl80211_dump_station(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1011 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1012 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1013 | struct station_info sinfo; |
| 1014 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1015 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1016 | u8 mac_addr[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1017 | int ifidx = cb->args[0]; |
| 1018 | int sta_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1019 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1020 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1021 | if (!ifidx) { |
| 1022 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1023 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1024 | nl80211_policy); |
| 1025 | if (err) |
| 1026 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1027 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1028 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1029 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1030 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1031 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1032 | if (!ifidx) |
| 1033 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1034 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1035 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1036 | netdev = dev_get_by_index(&init_net, ifidx); |
| 1037 | if (!netdev) |
| 1038 | return -ENODEV; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1039 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1040 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1041 | if (IS_ERR(dev)) { |
| 1042 | err = PTR_ERR(dev); |
| 1043 | goto out_put_netdev; |
| 1044 | } |
| 1045 | |
| 1046 | if (!dev->ops->dump_station) { |
| 1047 | err = -ENOSYS; |
| 1048 | goto out_err; |
| 1049 | } |
| 1050 | |
| 1051 | rtnl_lock(); |
| 1052 | |
| 1053 | while (1) { |
| 1054 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, |
| 1055 | mac_addr, &sinfo); |
| 1056 | if (err == -ENOENT) |
| 1057 | break; |
| 1058 | if (err) |
| 1059 | goto out_err_rtnl; |
| 1060 | |
| 1061 | if (nl80211_send_station(skb, |
| 1062 | NETLINK_CB(cb->skb).pid, |
| 1063 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1064 | netdev, mac_addr, |
| 1065 | &sinfo) < 0) |
| 1066 | goto out; |
| 1067 | |
| 1068 | sta_idx++; |
| 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | out: |
| 1073 | cb->args[1] = sta_idx; |
| 1074 | err = skb->len; |
| 1075 | out_err_rtnl: |
| 1076 | rtnl_unlock(); |
| 1077 | out_err: |
| 1078 | cfg80211_put_dev(dev); |
| 1079 | out_put_netdev: |
| 1080 | dev_put(netdev); |
| 1081 | |
| 1082 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1083 | } |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1084 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1085 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
| 1086 | { |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1087 | struct cfg80211_registered_device *drv; |
| 1088 | int err; |
| 1089 | struct net_device *dev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1090 | struct station_info sinfo; |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1091 | struct sk_buff *msg; |
| 1092 | u8 *mac_addr = NULL; |
| 1093 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1094 | memset(&sinfo, 0, sizeof(sinfo)); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1095 | |
| 1096 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1097 | return -EINVAL; |
| 1098 | |
| 1099 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1100 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1101 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1102 | if (err) |
| 1103 | return err; |
| 1104 | |
| 1105 | if (!drv->ops->get_station) { |
| 1106 | err = -EOPNOTSUPP; |
| 1107 | goto out; |
| 1108 | } |
| 1109 | |
| 1110 | rtnl_lock(); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1111 | err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo); |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1112 | rtnl_unlock(); |
| 1113 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1114 | if (err) |
| 1115 | goto out; |
| 1116 | |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1117 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1118 | if (!msg) |
| 1119 | goto out; |
| 1120 | |
| 1121 | 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] | 1122 | dev, mac_addr, &sinfo) < 0) |
Johannes Berg | fd5b74d | 2007-12-19 02:03:36 +0100 | [diff] [blame] | 1123 | goto out_free; |
| 1124 | |
| 1125 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1126 | goto out; |
| 1127 | |
| 1128 | out_free: |
| 1129 | nlmsg_free(msg); |
| 1130 | |
| 1131 | out: |
| 1132 | cfg80211_put_dev(drv); |
| 1133 | dev_put(dev); |
| 1134 | return err; |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | /* |
| 1138 | * Get vlan interface making sure it is on the right wiphy. |
| 1139 | */ |
| 1140 | static int get_vlan(struct nlattr *vlanattr, |
| 1141 | struct cfg80211_registered_device *rdev, |
| 1142 | struct net_device **vlan) |
| 1143 | { |
| 1144 | *vlan = NULL; |
| 1145 | |
| 1146 | if (vlanattr) { |
| 1147 | *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr)); |
| 1148 | if (!*vlan) |
| 1149 | return -ENODEV; |
| 1150 | if (!(*vlan)->ieee80211_ptr) |
| 1151 | return -EINVAL; |
| 1152 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) |
| 1153 | return -EINVAL; |
| 1154 | } |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
| 1159 | { |
| 1160 | struct cfg80211_registered_device *drv; |
| 1161 | int err; |
| 1162 | struct net_device *dev; |
| 1163 | struct station_parameters params; |
| 1164 | u8 *mac_addr = NULL; |
| 1165 | |
| 1166 | memset(¶ms, 0, sizeof(params)); |
| 1167 | |
| 1168 | params.listen_interval = -1; |
| 1169 | |
| 1170 | if (info->attrs[NL80211_ATTR_STA_AID]) |
| 1171 | return -EINVAL; |
| 1172 | |
| 1173 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1174 | return -EINVAL; |
| 1175 | |
| 1176 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1177 | |
| 1178 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { |
| 1179 | params.supported_rates = |
| 1180 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1181 | params.supported_rates_len = |
| 1182 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1183 | } |
| 1184 | |
| 1185 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1186 | params.listen_interval = |
| 1187 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
| 1188 | |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1189 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1190 | params.ht_capa = |
| 1191 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
| 1192 | |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1193 | if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS], |
| 1194 | ¶ms.station_flags)) |
| 1195 | return -EINVAL; |
| 1196 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1197 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
| 1198 | params.plink_action = |
| 1199 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
| 1200 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1201 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1202 | if (err) |
| 1203 | return err; |
| 1204 | |
| 1205 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1206 | if (err) |
| 1207 | goto out; |
| 1208 | |
| 1209 | if (!drv->ops->change_station) { |
| 1210 | err = -EOPNOTSUPP; |
| 1211 | goto out; |
| 1212 | } |
| 1213 | |
| 1214 | rtnl_lock(); |
| 1215 | err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms); |
| 1216 | rtnl_unlock(); |
| 1217 | |
| 1218 | out: |
| 1219 | if (params.vlan) |
| 1220 | dev_put(params.vlan); |
| 1221 | cfg80211_put_dev(drv); |
| 1222 | dev_put(dev); |
| 1223 | return err; |
| 1224 | } |
| 1225 | |
| 1226 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) |
| 1227 | { |
| 1228 | struct cfg80211_registered_device *drv; |
| 1229 | int err; |
| 1230 | struct net_device *dev; |
| 1231 | struct station_parameters params; |
| 1232 | u8 *mac_addr = NULL; |
| 1233 | |
| 1234 | memset(¶ms, 0, sizeof(params)); |
| 1235 | |
| 1236 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1237 | return -EINVAL; |
| 1238 | |
| 1239 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
| 1240 | return -EINVAL; |
| 1241 | |
| 1242 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
| 1243 | return -EINVAL; |
| 1244 | |
| 1245 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) |
| 1246 | return -EINVAL; |
| 1247 | |
| 1248 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1249 | params.supported_rates = |
| 1250 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1251 | params.supported_rates_len = |
| 1252 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); |
| 1253 | params.listen_interval = |
| 1254 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); |
Johannes Berg | 16f2e85 | 2008-04-07 14:35:46 +0200 | [diff] [blame] | 1255 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1256 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
| 1257 | params.ht_capa = |
| 1258 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1259 | |
| 1260 | if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS], |
| 1261 | ¶ms.station_flags)) |
| 1262 | return -EINVAL; |
| 1263 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1264 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1265 | if (err) |
| 1266 | return err; |
| 1267 | |
| 1268 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); |
| 1269 | if (err) |
| 1270 | goto out; |
| 1271 | |
| 1272 | if (!drv->ops->add_station) { |
| 1273 | err = -EOPNOTSUPP; |
| 1274 | goto out; |
| 1275 | } |
| 1276 | |
| 1277 | rtnl_lock(); |
| 1278 | err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms); |
| 1279 | rtnl_unlock(); |
| 1280 | |
| 1281 | out: |
| 1282 | if (params.vlan) |
| 1283 | dev_put(params.vlan); |
| 1284 | cfg80211_put_dev(drv); |
| 1285 | dev_put(dev); |
| 1286 | return err; |
| 1287 | } |
| 1288 | |
| 1289 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) |
| 1290 | { |
| 1291 | struct cfg80211_registered_device *drv; |
| 1292 | int err; |
| 1293 | struct net_device *dev; |
| 1294 | u8 *mac_addr = NULL; |
| 1295 | |
| 1296 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1297 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1298 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1299 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 1300 | if (err) |
| 1301 | return err; |
| 1302 | |
| 1303 | if (!drv->ops->del_station) { |
| 1304 | err = -EOPNOTSUPP; |
| 1305 | goto out; |
| 1306 | } |
| 1307 | |
| 1308 | rtnl_lock(); |
| 1309 | err = drv->ops->del_station(&drv->wiphy, dev, mac_addr); |
| 1310 | rtnl_unlock(); |
| 1311 | |
| 1312 | out: |
| 1313 | cfg80211_put_dev(drv); |
| 1314 | dev_put(dev); |
| 1315 | return err; |
| 1316 | } |
| 1317 | |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1318 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
| 1319 | int flags, struct net_device *dev, |
| 1320 | u8 *dst, u8 *next_hop, |
| 1321 | struct mpath_info *pinfo) |
| 1322 | { |
| 1323 | void *hdr; |
| 1324 | struct nlattr *pinfoattr; |
| 1325 | |
| 1326 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); |
| 1327 | if (!hdr) |
| 1328 | return -1; |
| 1329 | |
| 1330 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1331 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); |
| 1332 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); |
| 1333 | |
| 1334 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
| 1335 | if (!pinfoattr) |
| 1336 | goto nla_put_failure; |
| 1337 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) |
| 1338 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, |
| 1339 | pinfo->frame_qlen); |
| 1340 | if (pinfo->filled & MPATH_INFO_DSN) |
| 1341 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN, |
| 1342 | pinfo->dsn); |
| 1343 | if (pinfo->filled & MPATH_INFO_METRIC) |
| 1344 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, |
| 1345 | pinfo->metric); |
| 1346 | if (pinfo->filled & MPATH_INFO_EXPTIME) |
| 1347 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, |
| 1348 | pinfo->exptime); |
| 1349 | if (pinfo->filled & MPATH_INFO_FLAGS) |
| 1350 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, |
| 1351 | pinfo->flags); |
| 1352 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) |
| 1353 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, |
| 1354 | pinfo->discovery_timeout); |
| 1355 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) |
| 1356 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, |
| 1357 | pinfo->discovery_retries); |
| 1358 | |
| 1359 | nla_nest_end(msg, pinfoattr); |
| 1360 | |
| 1361 | return genlmsg_end(msg, hdr); |
| 1362 | |
| 1363 | nla_put_failure: |
Thomas Graf | bc3ed28 | 2008-06-03 16:36:54 -0700 | [diff] [blame] | 1364 | genlmsg_cancel(msg, hdr); |
| 1365 | return -EMSGSIZE; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | static int nl80211_dump_mpath(struct sk_buff *skb, |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1369 | struct netlink_callback *cb) |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1370 | { |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1371 | struct mpath_info pinfo; |
| 1372 | struct cfg80211_registered_device *dev; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1373 | struct net_device *netdev; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1374 | u8 dst[ETH_ALEN]; |
| 1375 | u8 next_hop[ETH_ALEN]; |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1376 | int ifidx = cb->args[0]; |
| 1377 | int path_idx = cb->args[1]; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1378 | int err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1379 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1380 | if (!ifidx) { |
| 1381 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
| 1382 | nl80211_fam.attrbuf, nl80211_fam.maxattr, |
| 1383 | nl80211_policy); |
| 1384 | if (err) |
| 1385 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1386 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1387 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
| 1388 | return -EINVAL; |
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 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
| 1391 | if (!ifidx) |
| 1392 | return -EINVAL; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1393 | } |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1394 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1395 | netdev = dev_get_by_index(&init_net, ifidx); |
| 1396 | if (!netdev) |
| 1397 | return -ENODEV; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1398 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1399 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
| 1400 | if (IS_ERR(dev)) { |
| 1401 | err = PTR_ERR(dev); |
| 1402 | goto out_put_netdev; |
| 1403 | } |
| 1404 | |
| 1405 | if (!dev->ops->dump_mpath) { |
| 1406 | err = -ENOSYS; |
| 1407 | goto out_err; |
| 1408 | } |
| 1409 | |
| 1410 | rtnl_lock(); |
| 1411 | |
| 1412 | while (1) { |
| 1413 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, |
| 1414 | dst, next_hop, &pinfo); |
| 1415 | if (err == -ENOENT) |
| 1416 | break; |
| 1417 | if (err) |
| 1418 | goto out_err_rtnl; |
| 1419 | |
| 1420 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
| 1421 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
| 1422 | netdev, dst, next_hop, |
| 1423 | &pinfo) < 0) |
| 1424 | goto out; |
| 1425 | |
| 1426 | path_idx++; |
| 1427 | } |
| 1428 | |
| 1429 | |
| 1430 | out: |
| 1431 | cb->args[1] = path_idx; |
| 1432 | err = skb->len; |
| 1433 | out_err_rtnl: |
| 1434 | rtnl_unlock(); |
| 1435 | out_err: |
| 1436 | cfg80211_put_dev(dev); |
| 1437 | out_put_netdev: |
| 1438 | dev_put(netdev); |
| 1439 | |
| 1440 | return err; |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1444 | { |
| 1445 | struct cfg80211_registered_device *drv; |
| 1446 | int err; |
| 1447 | struct net_device *dev; |
| 1448 | struct mpath_info pinfo; |
| 1449 | struct sk_buff *msg; |
| 1450 | u8 *dst = NULL; |
| 1451 | u8 next_hop[ETH_ALEN]; |
| 1452 | |
| 1453 | memset(&pinfo, 0, sizeof(pinfo)); |
| 1454 | |
| 1455 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1456 | return -EINVAL; |
| 1457 | |
| 1458 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1459 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1460 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1461 | if (err) |
| 1462 | return err; |
| 1463 | |
| 1464 | if (!drv->ops->get_mpath) { |
| 1465 | err = -EOPNOTSUPP; |
| 1466 | goto out; |
| 1467 | } |
| 1468 | |
| 1469 | rtnl_lock(); |
| 1470 | err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo); |
| 1471 | rtnl_unlock(); |
| 1472 | |
| 1473 | if (err) |
| 1474 | goto out; |
| 1475 | |
| 1476 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1477 | if (!msg) |
| 1478 | goto out; |
| 1479 | |
| 1480 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, |
| 1481 | dev, dst, next_hop, &pinfo) < 0) |
| 1482 | goto out_free; |
| 1483 | |
| 1484 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1485 | goto out; |
| 1486 | |
| 1487 | out_free: |
| 1488 | nlmsg_free(msg); |
| 1489 | |
| 1490 | out: |
| 1491 | cfg80211_put_dev(drv); |
| 1492 | dev_put(dev); |
| 1493 | return err; |
| 1494 | } |
| 1495 | |
| 1496 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1497 | { |
| 1498 | struct cfg80211_registered_device *drv; |
| 1499 | int err; |
| 1500 | struct net_device *dev; |
| 1501 | u8 *dst = NULL; |
| 1502 | u8 *next_hop = NULL; |
| 1503 | |
| 1504 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1505 | return -EINVAL; |
| 1506 | |
| 1507 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 1508 | return -EINVAL; |
| 1509 | |
| 1510 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1511 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 1512 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1513 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1514 | if (err) |
| 1515 | return err; |
| 1516 | |
| 1517 | if (!drv->ops->change_mpath) { |
| 1518 | err = -EOPNOTSUPP; |
| 1519 | goto out; |
| 1520 | } |
| 1521 | |
| 1522 | rtnl_lock(); |
| 1523 | err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop); |
| 1524 | rtnl_unlock(); |
| 1525 | |
| 1526 | out: |
| 1527 | cfg80211_put_dev(drv); |
| 1528 | dev_put(dev); |
| 1529 | return err; |
| 1530 | } |
| 1531 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1532 | { |
| 1533 | struct cfg80211_registered_device *drv; |
| 1534 | int err; |
| 1535 | struct net_device *dev; |
| 1536 | u8 *dst = NULL; |
| 1537 | u8 *next_hop = NULL; |
| 1538 | |
| 1539 | if (!info->attrs[NL80211_ATTR_MAC]) |
| 1540 | return -EINVAL; |
| 1541 | |
| 1542 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) |
| 1543 | return -EINVAL; |
| 1544 | |
| 1545 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1546 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); |
| 1547 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1548 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1549 | if (err) |
| 1550 | return err; |
| 1551 | |
| 1552 | if (!drv->ops->add_mpath) { |
| 1553 | err = -EOPNOTSUPP; |
| 1554 | goto out; |
| 1555 | } |
| 1556 | |
| 1557 | rtnl_lock(); |
| 1558 | err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop); |
| 1559 | rtnl_unlock(); |
| 1560 | |
| 1561 | out: |
| 1562 | cfg80211_put_dev(drv); |
| 1563 | dev_put(dev); |
| 1564 | return err; |
| 1565 | } |
| 1566 | |
| 1567 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) |
| 1568 | { |
| 1569 | struct cfg80211_registered_device *drv; |
| 1570 | int err; |
| 1571 | struct net_device *dev; |
| 1572 | u8 *dst = NULL; |
| 1573 | |
| 1574 | if (info->attrs[NL80211_ATTR_MAC]) |
| 1575 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); |
| 1576 | |
Johannes Berg | bba95fe | 2008-07-29 13:22:51 +0200 | [diff] [blame] | 1577 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 1578 | if (err) |
| 1579 | return err; |
| 1580 | |
| 1581 | if (!drv->ops->del_mpath) { |
| 1582 | err = -EOPNOTSUPP; |
| 1583 | goto out; |
| 1584 | } |
| 1585 | |
| 1586 | rtnl_lock(); |
| 1587 | err = drv->ops->del_mpath(&drv->wiphy, dev, dst); |
| 1588 | rtnl_unlock(); |
| 1589 | |
| 1590 | out: |
| 1591 | cfg80211_put_dev(drv); |
| 1592 | dev_put(dev); |
| 1593 | return err; |
| 1594 | } |
| 1595 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1596 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
| 1597 | { |
| 1598 | struct cfg80211_registered_device *drv; |
| 1599 | int err; |
| 1600 | struct net_device *dev; |
| 1601 | struct bss_parameters params; |
| 1602 | |
| 1603 | memset(¶ms, 0, sizeof(params)); |
| 1604 | /* default to not changing parameters */ |
| 1605 | params.use_cts_prot = -1; |
| 1606 | params.use_short_preamble = -1; |
| 1607 | params.use_short_slot_time = -1; |
| 1608 | |
| 1609 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) |
| 1610 | params.use_cts_prot = |
| 1611 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); |
| 1612 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) |
| 1613 | params.use_short_preamble = |
| 1614 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); |
| 1615 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) |
| 1616 | params.use_short_slot_time = |
| 1617 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame^] | 1618 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
| 1619 | params.basic_rates = |
| 1620 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 1621 | params.basic_rates_len = |
| 1622 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); |
| 1623 | } |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 1624 | |
| 1625 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 1626 | if (err) |
| 1627 | return err; |
| 1628 | |
| 1629 | if (!drv->ops->change_bss) { |
| 1630 | err = -EOPNOTSUPP; |
| 1631 | goto out; |
| 1632 | } |
| 1633 | |
| 1634 | rtnl_lock(); |
| 1635 | err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms); |
| 1636 | rtnl_unlock(); |
| 1637 | |
| 1638 | out: |
| 1639 | cfg80211_put_dev(drv); |
| 1640 | dev_put(dev); |
| 1641 | return err; |
| 1642 | } |
| 1643 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1644 | static const struct nla_policy |
| 1645 | reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
| 1646 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
| 1647 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, |
| 1648 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, |
| 1649 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, |
| 1650 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, |
| 1651 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, |
| 1652 | }; |
| 1653 | |
| 1654 | static int parse_reg_rule(struct nlattr *tb[], |
| 1655 | struct ieee80211_reg_rule *reg_rule) |
| 1656 | { |
| 1657 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; |
| 1658 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; |
| 1659 | |
| 1660 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) |
| 1661 | return -EINVAL; |
| 1662 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) |
| 1663 | return -EINVAL; |
| 1664 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) |
| 1665 | return -EINVAL; |
| 1666 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
| 1667 | return -EINVAL; |
| 1668 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
| 1669 | return -EINVAL; |
| 1670 | |
| 1671 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); |
| 1672 | |
| 1673 | freq_range->start_freq_khz = |
| 1674 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); |
| 1675 | freq_range->end_freq_khz = |
| 1676 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); |
| 1677 | freq_range->max_bandwidth_khz = |
| 1678 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); |
| 1679 | |
| 1680 | power_rule->max_eirp = |
| 1681 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); |
| 1682 | |
| 1683 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) |
| 1684 | power_rule->max_antenna_gain = |
| 1685 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); |
| 1686 | |
| 1687 | return 0; |
| 1688 | } |
| 1689 | |
| 1690 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 1691 | { |
| 1692 | int r; |
| 1693 | char *data = NULL; |
| 1694 | |
| 1695 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 1696 | return -EINVAL; |
| 1697 | |
| 1698 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 1699 | |
| 1700 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY |
| 1701 | /* We ignore world regdom requests with the old regdom setup */ |
| 1702 | if (is_world_regdom(data)) |
| 1703 | return -EINVAL; |
| 1704 | #endif |
| 1705 | mutex_lock(&cfg80211_drv_mutex); |
Johannes Berg | be3d481 | 2008-10-24 20:32:21 +0200 | [diff] [blame] | 1706 | r = __regulatory_hint(NULL, REGDOM_SET_BY_USER, data); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1707 | mutex_unlock(&cfg80211_drv_mutex); |
| 1708 | return r; |
| 1709 | } |
| 1710 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1711 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
| 1712 | struct genl_info *info) |
| 1713 | { |
| 1714 | struct cfg80211_registered_device *drv; |
| 1715 | struct mesh_config cur_params; |
| 1716 | int err; |
| 1717 | struct net_device *dev; |
| 1718 | void *hdr; |
| 1719 | struct nlattr *pinfoattr; |
| 1720 | struct sk_buff *msg; |
| 1721 | |
| 1722 | /* Look up our device */ |
| 1723 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 1724 | if (err) |
| 1725 | return err; |
| 1726 | |
| 1727 | /* Get the mesh params */ |
| 1728 | rtnl_lock(); |
| 1729 | err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); |
| 1730 | rtnl_unlock(); |
| 1731 | if (err) |
| 1732 | goto out; |
| 1733 | |
| 1734 | /* Draw up a netlink message to send back */ |
| 1735 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 1736 | if (!msg) { |
| 1737 | err = -ENOBUFS; |
| 1738 | goto out; |
| 1739 | } |
| 1740 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, |
| 1741 | NL80211_CMD_GET_MESH_PARAMS); |
| 1742 | if (!hdr) |
| 1743 | goto nla_put_failure; |
| 1744 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); |
| 1745 | if (!pinfoattr) |
| 1746 | goto nla_put_failure; |
| 1747 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); |
| 1748 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, |
| 1749 | cur_params.dot11MeshRetryTimeout); |
| 1750 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
| 1751 | cur_params.dot11MeshConfirmTimeout); |
| 1752 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, |
| 1753 | cur_params.dot11MeshHoldingTimeout); |
| 1754 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 1755 | cur_params.dot11MeshMaxPeerLinks); |
| 1756 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, |
| 1757 | cur_params.dot11MeshMaxRetries); |
| 1758 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, |
| 1759 | cur_params.dot11MeshTTL); |
| 1760 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 1761 | cur_params.auto_open_plinks); |
| 1762 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 1763 | cur_params.dot11MeshHWMPmaxPREQretries); |
| 1764 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, |
| 1765 | cur_params.path_refresh_time); |
| 1766 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 1767 | cur_params.min_discovery_timeout); |
| 1768 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 1769 | cur_params.dot11MeshHWMPactivePathTimeout); |
| 1770 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 1771 | cur_params.dot11MeshHWMPpreqMinInterval); |
| 1772 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 1773 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); |
| 1774 | nla_nest_end(msg, pinfoattr); |
| 1775 | genlmsg_end(msg, hdr); |
| 1776 | err = genlmsg_unicast(msg, info->snd_pid); |
| 1777 | goto out; |
| 1778 | |
| 1779 | nla_put_failure: |
| 1780 | genlmsg_cancel(msg, hdr); |
| 1781 | err = -EMSGSIZE; |
| 1782 | out: |
| 1783 | /* Cleanup */ |
| 1784 | cfg80211_put_dev(drv); |
| 1785 | dev_put(dev); |
| 1786 | return err; |
| 1787 | } |
| 1788 | |
| 1789 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ |
| 1790 | do {\ |
| 1791 | if (table[attr_num]) {\ |
| 1792 | cfg.param = nla_fn(table[attr_num]); \ |
| 1793 | mask |= (1 << (attr_num - 1)); \ |
| 1794 | } \ |
| 1795 | } while (0);\ |
| 1796 | |
| 1797 | static struct nla_policy |
| 1798 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = { |
| 1799 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
| 1800 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, |
| 1801 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, |
| 1802 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, |
| 1803 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, |
| 1804 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, |
| 1805 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
| 1806 | |
| 1807 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
| 1808 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, |
| 1809 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, |
| 1810 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, |
| 1811 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, |
| 1812 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
| 1813 | }; |
| 1814 | |
| 1815 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) |
| 1816 | { |
| 1817 | int err; |
| 1818 | u32 mask; |
| 1819 | struct cfg80211_registered_device *drv; |
| 1820 | struct net_device *dev; |
| 1821 | struct mesh_config cfg; |
| 1822 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
| 1823 | struct nlattr *parent_attr; |
| 1824 | |
| 1825 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; |
| 1826 | if (!parent_attr) |
| 1827 | return -EINVAL; |
| 1828 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, |
| 1829 | parent_attr, nl80211_meshconf_params_policy)) |
| 1830 | return -EINVAL; |
| 1831 | |
| 1832 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
| 1833 | if (err) |
| 1834 | return err; |
| 1835 | |
| 1836 | /* This makes sure that there aren't more than 32 mesh config |
| 1837 | * parameters (otherwise our bitfield scheme would not work.) */ |
| 1838 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); |
| 1839 | |
| 1840 | /* Fill in the params struct */ |
| 1841 | mask = 0; |
| 1842 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, |
| 1843 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); |
| 1844 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, |
| 1845 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); |
| 1846 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, |
| 1847 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); |
| 1848 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, |
| 1849 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); |
| 1850 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, |
| 1851 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); |
| 1852 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, |
| 1853 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
| 1854 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, |
| 1855 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); |
| 1856 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, |
| 1857 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
| 1858 | nla_get_u8); |
| 1859 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, |
| 1860 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); |
| 1861 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, |
| 1862 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
| 1863 | nla_get_u16); |
| 1864 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
| 1865 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
| 1866 | nla_get_u32); |
| 1867 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
| 1868 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, |
| 1869 | nla_get_u16); |
| 1870 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
| 1871 | dot11MeshHWMPnetDiameterTraversalTime, |
| 1872 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 1873 | nla_get_u16); |
| 1874 | |
| 1875 | /* Apply changes */ |
| 1876 | rtnl_lock(); |
| 1877 | err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); |
| 1878 | rtnl_unlock(); |
| 1879 | |
| 1880 | /* cleanup */ |
| 1881 | cfg80211_put_dev(drv); |
| 1882 | dev_put(dev); |
| 1883 | return err; |
| 1884 | } |
| 1885 | |
| 1886 | #undef FILL_IN_MESH_PARAM_IF_SET |
| 1887 | |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1888 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
| 1889 | { |
| 1890 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; |
| 1891 | struct nlattr *nl_reg_rule; |
| 1892 | char *alpha2 = NULL; |
| 1893 | int rem_reg_rules = 0, r = 0; |
| 1894 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
| 1895 | struct ieee80211_regdomain *rd = NULL; |
| 1896 | |
| 1897 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
| 1898 | return -EINVAL; |
| 1899 | |
| 1900 | if (!info->attrs[NL80211_ATTR_REG_RULES]) |
| 1901 | return -EINVAL; |
| 1902 | |
| 1903 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); |
| 1904 | |
| 1905 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 1906 | rem_reg_rules) { |
| 1907 | num_rules++; |
| 1908 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) |
| 1909 | goto bad_reg; |
| 1910 | } |
| 1911 | |
| 1912 | if (!reg_is_valid_request(alpha2)) |
| 1913 | return -EINVAL; |
| 1914 | |
| 1915 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
| 1916 | (num_rules * sizeof(struct ieee80211_reg_rule)); |
| 1917 | |
| 1918 | rd = kzalloc(size_of_regd, GFP_KERNEL); |
| 1919 | if (!rd) |
| 1920 | return -ENOMEM; |
| 1921 | |
| 1922 | rd->n_reg_rules = num_rules; |
| 1923 | rd->alpha2[0] = alpha2[0]; |
| 1924 | rd->alpha2[1] = alpha2[1]; |
| 1925 | |
| 1926 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
| 1927 | rem_reg_rules) { |
| 1928 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
| 1929 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), |
| 1930 | reg_rule_policy); |
| 1931 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
| 1932 | if (r) |
| 1933 | goto bad_reg; |
| 1934 | |
| 1935 | rule_idx++; |
| 1936 | |
| 1937 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) |
| 1938 | goto bad_reg; |
| 1939 | } |
| 1940 | |
| 1941 | BUG_ON(rule_idx != num_rules); |
| 1942 | |
| 1943 | mutex_lock(&cfg80211_drv_mutex); |
| 1944 | r = set_regdom(rd); |
| 1945 | mutex_unlock(&cfg80211_drv_mutex); |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1946 | return r; |
| 1947 | |
Johannes Berg | d2372b3 | 2008-10-24 20:32:20 +0200 | [diff] [blame] | 1948 | bad_reg: |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 1949 | kfree(rd); |
| 1950 | return -EINVAL; |
| 1951 | } |
| 1952 | |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 1953 | static struct genl_ops nl80211_ops[] = { |
| 1954 | { |
| 1955 | .cmd = NL80211_CMD_GET_WIPHY, |
| 1956 | .doit = nl80211_get_wiphy, |
| 1957 | .dumpit = nl80211_dump_wiphy, |
| 1958 | .policy = nl80211_policy, |
| 1959 | /* can be retrieved by unprivileged users */ |
| 1960 | }, |
| 1961 | { |
| 1962 | .cmd = NL80211_CMD_SET_WIPHY, |
| 1963 | .doit = nl80211_set_wiphy, |
| 1964 | .policy = nl80211_policy, |
| 1965 | .flags = GENL_ADMIN_PERM, |
| 1966 | }, |
| 1967 | { |
| 1968 | .cmd = NL80211_CMD_GET_INTERFACE, |
| 1969 | .doit = nl80211_get_interface, |
| 1970 | .dumpit = nl80211_dump_interface, |
| 1971 | .policy = nl80211_policy, |
| 1972 | /* can be retrieved by unprivileged users */ |
| 1973 | }, |
| 1974 | { |
| 1975 | .cmd = NL80211_CMD_SET_INTERFACE, |
| 1976 | .doit = nl80211_set_interface, |
| 1977 | .policy = nl80211_policy, |
| 1978 | .flags = GENL_ADMIN_PERM, |
| 1979 | }, |
| 1980 | { |
| 1981 | .cmd = NL80211_CMD_NEW_INTERFACE, |
| 1982 | .doit = nl80211_new_interface, |
| 1983 | .policy = nl80211_policy, |
| 1984 | .flags = GENL_ADMIN_PERM, |
| 1985 | }, |
| 1986 | { |
| 1987 | .cmd = NL80211_CMD_DEL_INTERFACE, |
| 1988 | .doit = nl80211_del_interface, |
| 1989 | .policy = nl80211_policy, |
| 1990 | .flags = GENL_ADMIN_PERM, |
| 1991 | }, |
Johannes Berg | 41ade00 | 2007-12-19 02:03:29 +0100 | [diff] [blame] | 1992 | { |
| 1993 | .cmd = NL80211_CMD_GET_KEY, |
| 1994 | .doit = nl80211_get_key, |
| 1995 | .policy = nl80211_policy, |
| 1996 | .flags = GENL_ADMIN_PERM, |
| 1997 | }, |
| 1998 | { |
| 1999 | .cmd = NL80211_CMD_SET_KEY, |
| 2000 | .doit = nl80211_set_key, |
| 2001 | .policy = nl80211_policy, |
| 2002 | .flags = GENL_ADMIN_PERM, |
| 2003 | }, |
| 2004 | { |
| 2005 | .cmd = NL80211_CMD_NEW_KEY, |
| 2006 | .doit = nl80211_new_key, |
| 2007 | .policy = nl80211_policy, |
| 2008 | .flags = GENL_ADMIN_PERM, |
| 2009 | }, |
| 2010 | { |
| 2011 | .cmd = NL80211_CMD_DEL_KEY, |
| 2012 | .doit = nl80211_del_key, |
| 2013 | .policy = nl80211_policy, |
| 2014 | .flags = GENL_ADMIN_PERM, |
| 2015 | }, |
Johannes Berg | ed1b6cc | 2007-12-19 02:03:32 +0100 | [diff] [blame] | 2016 | { |
| 2017 | .cmd = NL80211_CMD_SET_BEACON, |
| 2018 | .policy = nl80211_policy, |
| 2019 | .flags = GENL_ADMIN_PERM, |
| 2020 | .doit = nl80211_addset_beacon, |
| 2021 | }, |
| 2022 | { |
| 2023 | .cmd = NL80211_CMD_NEW_BEACON, |
| 2024 | .policy = nl80211_policy, |
| 2025 | .flags = GENL_ADMIN_PERM, |
| 2026 | .doit = nl80211_addset_beacon, |
| 2027 | }, |
| 2028 | { |
| 2029 | .cmd = NL80211_CMD_DEL_BEACON, |
| 2030 | .policy = nl80211_policy, |
| 2031 | .flags = GENL_ADMIN_PERM, |
| 2032 | .doit = nl80211_del_beacon, |
| 2033 | }, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2034 | { |
| 2035 | .cmd = NL80211_CMD_GET_STATION, |
| 2036 | .doit = nl80211_get_station, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2037 | .dumpit = nl80211_dump_station, |
Johannes Berg | 5727ef1 | 2007-12-19 02:03:34 +0100 | [diff] [blame] | 2038 | .policy = nl80211_policy, |
| 2039 | .flags = GENL_ADMIN_PERM, |
| 2040 | }, |
| 2041 | { |
| 2042 | .cmd = NL80211_CMD_SET_STATION, |
| 2043 | .doit = nl80211_set_station, |
| 2044 | .policy = nl80211_policy, |
| 2045 | .flags = GENL_ADMIN_PERM, |
| 2046 | }, |
| 2047 | { |
| 2048 | .cmd = NL80211_CMD_NEW_STATION, |
| 2049 | .doit = nl80211_new_station, |
| 2050 | .policy = nl80211_policy, |
| 2051 | .flags = GENL_ADMIN_PERM, |
| 2052 | }, |
| 2053 | { |
| 2054 | .cmd = NL80211_CMD_DEL_STATION, |
| 2055 | .doit = nl80211_del_station, |
| 2056 | .policy = nl80211_policy, |
| 2057 | .flags = GENL_ADMIN_PERM, |
| 2058 | }, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 2059 | { |
| 2060 | .cmd = NL80211_CMD_GET_MPATH, |
| 2061 | .doit = nl80211_get_mpath, |
| 2062 | .dumpit = nl80211_dump_mpath, |
| 2063 | .policy = nl80211_policy, |
| 2064 | .flags = GENL_ADMIN_PERM, |
| 2065 | }, |
| 2066 | { |
| 2067 | .cmd = NL80211_CMD_SET_MPATH, |
| 2068 | .doit = nl80211_set_mpath, |
| 2069 | .policy = nl80211_policy, |
| 2070 | .flags = GENL_ADMIN_PERM, |
| 2071 | }, |
| 2072 | { |
| 2073 | .cmd = NL80211_CMD_NEW_MPATH, |
| 2074 | .doit = nl80211_new_mpath, |
| 2075 | .policy = nl80211_policy, |
| 2076 | .flags = GENL_ADMIN_PERM, |
| 2077 | }, |
| 2078 | { |
| 2079 | .cmd = NL80211_CMD_DEL_MPATH, |
| 2080 | .doit = nl80211_del_mpath, |
| 2081 | .policy = nl80211_policy, |
| 2082 | .flags = GENL_ADMIN_PERM, |
| 2083 | }, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2084 | { |
| 2085 | .cmd = NL80211_CMD_SET_BSS, |
| 2086 | .doit = nl80211_set_bss, |
| 2087 | .policy = nl80211_policy, |
| 2088 | .flags = GENL_ADMIN_PERM, |
| 2089 | }, |
Luis R. Rodriguez | b2e1b30 | 2008-09-09 23:19:48 -0700 | [diff] [blame] | 2090 | { |
| 2091 | .cmd = NL80211_CMD_SET_REG, |
| 2092 | .doit = nl80211_set_reg, |
| 2093 | .policy = nl80211_policy, |
| 2094 | .flags = GENL_ADMIN_PERM, |
| 2095 | }, |
| 2096 | { |
| 2097 | .cmd = NL80211_CMD_REQ_SET_REG, |
| 2098 | .doit = nl80211_req_set_reg, |
| 2099 | .policy = nl80211_policy, |
| 2100 | .flags = GENL_ADMIN_PERM, |
| 2101 | }, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2102 | { |
| 2103 | .cmd = NL80211_CMD_GET_MESH_PARAMS, |
| 2104 | .doit = nl80211_get_mesh_params, |
| 2105 | .policy = nl80211_policy, |
| 2106 | /* can be retrieved by unprivileged users */ |
| 2107 | }, |
| 2108 | { |
| 2109 | .cmd = NL80211_CMD_SET_MESH_PARAMS, |
| 2110 | .doit = nl80211_set_mesh_params, |
| 2111 | .policy = nl80211_policy, |
| 2112 | .flags = GENL_ADMIN_PERM, |
| 2113 | }, |
Johannes Berg | 5568296 | 2007-09-20 13:09:35 -0400 | [diff] [blame] | 2114 | }; |
| 2115 | |
| 2116 | /* multicast groups */ |
| 2117 | static struct genl_multicast_group nl80211_config_mcgrp = { |
| 2118 | .name = "config", |
| 2119 | }; |
| 2120 | |
| 2121 | /* notification functions */ |
| 2122 | |
| 2123 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) |
| 2124 | { |
| 2125 | struct sk_buff *msg; |
| 2126 | |
| 2127 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
| 2128 | if (!msg) |
| 2129 | return; |
| 2130 | |
| 2131 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { |
| 2132 | nlmsg_free(msg); |
| 2133 | return; |
| 2134 | } |
| 2135 | |
| 2136 | genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); |
| 2137 | } |
| 2138 | |
| 2139 | /* initialisation/exit functions */ |
| 2140 | |
| 2141 | int nl80211_init(void) |
| 2142 | { |
| 2143 | int err, i; |
| 2144 | |
| 2145 | err = genl_register_family(&nl80211_fam); |
| 2146 | if (err) |
| 2147 | return err; |
| 2148 | |
| 2149 | for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) { |
| 2150 | err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]); |
| 2151 | if (err) |
| 2152 | goto err_out; |
| 2153 | } |
| 2154 | |
| 2155 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
| 2156 | if (err) |
| 2157 | goto err_out; |
| 2158 | |
| 2159 | return 0; |
| 2160 | err_out: |
| 2161 | genl_unregister_family(&nl80211_fam); |
| 2162 | return err; |
| 2163 | } |
| 2164 | |
| 2165 | void nl80211_exit(void) |
| 2166 | { |
| 2167 | genl_unregister_family(&nl80211_fam); |
| 2168 | } |