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