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