blob: a39e4644778b3dd97f4ec96f4931df84f3e1bb81 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
4 * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net>
5 */
6
7#include <linux/if.h>
8#include <linux/module.h>
9#include <linux/err.h>
Johannes Berg55682962007-09-20 13:09:35 -040010#include <linux/list.h>
11#include <linux/if_ether.h>
12#include <linux/ieee80211.h>
13#include <linux/nl80211.h>
14#include <linux/rtnetlink.h>
15#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010016#include <linux/etherdevice.h>
Johannes Berg55682962007-09-20 13:09:35 -040017#include <net/genetlink.h>
18#include <net/cfg80211.h>
19#include "core.h"
20#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070021#include "reg.h"
Johannes Berg55682962007-09-20 13:09:35 -040022
23/* the netlink family */
24static 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 Bergbba95fe2008-07-29 13:22:51 +020033static int get_drv_dev_by_info_ifindex(struct nlattr **attrs,
Johannes Berg55682962007-09-20 13:09:35 -040034 struct cfg80211_registered_device **drv,
35 struct net_device **dev)
36{
37 int ifindex;
38
Johannes Bergbba95fe2008-07-29 13:22:51 +020039 if (!attrs[NL80211_ATTR_IFINDEX])
Johannes Berg55682962007-09-20 13:09:35 -040040 return -EINVAL;
41
Johannes Bergbba95fe2008-07-29 13:22:51 +020042 ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Johannes Berg55682962007-09-20 13:09:35 -040043 *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 */
57static 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 Malinen31888482008-10-30 16:59:24 +020061 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Jouni Malinen72bdcf32008-11-26 16:15:24 +020062 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +053063 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +020064 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
65 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
66 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
67 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Johannes Berg55682962007-09-20 13:09:35 -040068
69 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
70 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
71 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +010072
73 [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN },
74
75 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
76 .len = WLAN_MAX_KEY_LEN },
77 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
78 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
79 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Johannes Berged1b6cc2007-12-19 02:03:32 +010080
81 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
82 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
83 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
84 .len = IEEE80211_MAX_DATA_LEN },
85 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
86 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +010087 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
88 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
89 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
90 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
91 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010092 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +010093 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +020094 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010095 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
96 .len = IEEE80211_MAX_MESH_ID_LEN },
97 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030098
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070099 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
100 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
101
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300102 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
103 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
104 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200105 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
106 .len = NL80211_MAX_SUPP_RATES },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300107
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700108 [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED },
109
Jouni Malinen36aedc92008-08-25 11:58:58 +0300110 [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY,
111 .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200112
113 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
114 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
115 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100116 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
117 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200118
119 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
120 .len = IEEE80211_MAX_SSID_LEN },
121 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
122 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200123 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300124 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300125 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Berg55682962007-09-20 13:09:35 -0400126};
127
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100128/* IE validation */
129static bool is_valid_ie_attr(const struct nlattr *attr)
130{
131 const u8 *pos;
132 int len;
133
134 if (!attr)
135 return true;
136
137 pos = nla_data(attr);
138 len = nla_len(attr);
139
140 while (len) {
141 u8 elemlen;
142
143 if (len < 2)
144 return false;
145 len -= 2;
146
147 elemlen = pos[1];
148 if (elemlen > len)
149 return false;
150
151 len -= elemlen;
152 pos += 2 + elemlen;
153 }
154
155 return true;
156}
157
Johannes Berg55682962007-09-20 13:09:35 -0400158/* message building helper */
159static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq,
160 int flags, u8 cmd)
161{
162 /* since there is no private header just add the generic one */
163 return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd);
164}
165
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400166static int nl80211_msg_put_channel(struct sk_buff *msg,
167 struct ieee80211_channel *chan)
168{
169 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ,
170 chan->center_freq);
171
172 if (chan->flags & IEEE80211_CHAN_DISABLED)
173 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED);
174 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)
175 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN);
176 if (chan->flags & IEEE80211_CHAN_NO_IBSS)
177 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS);
178 if (chan->flags & IEEE80211_CHAN_RADAR)
179 NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR);
180
181 NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
182 DBM_TO_MBM(chan->max_power));
183
184 return 0;
185
186 nla_put_failure:
187 return -ENOBUFS;
188}
189
Johannes Berg55682962007-09-20 13:09:35 -0400190/* netlink command implementations */
191
192static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags,
193 struct cfg80211_registered_device *dev)
194{
195 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +0100196 struct nlattr *nl_bands, *nl_band;
197 struct nlattr *nl_freqs, *nl_freq;
198 struct nlattr *nl_rates, *nl_rate;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700199 struct nlattr *nl_modes;
Johannes Berg8fdc6212009-03-14 09:34:01 +0100200 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +0100201 enum ieee80211_band band;
202 struct ieee80211_channel *chan;
203 struct ieee80211_rate *rate;
204 int i;
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700205 u16 ifmodes = dev->wiphy.interface_modes;
Johannes Berg55682962007-09-20 13:09:35 -0400206
207 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY);
208 if (!hdr)
209 return -1;
210
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -0500211 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400212 NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy));
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200213
214 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
215 dev->wiphy.retry_short);
216 NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
217 dev->wiphy.retry_long);
218 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
219 dev->wiphy.frag_threshold);
220 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
221 dev->wiphy.rts_threshold);
222
Johannes Berg2a519312009-02-10 21:25:55 +0100223 NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
224 dev->wiphy.max_scan_ssids);
Johannes Berg18a83652009-03-31 12:12:05 +0200225 NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
226 dev->wiphy.max_scan_ie_len);
Johannes Bergee688b002008-01-24 19:38:39 +0100227
Johannes Berg25e47c182009-04-02 20:14:06 +0200228 NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES,
229 sizeof(u32) * dev->wiphy.n_cipher_suites,
230 dev->wiphy.cipher_suites);
231
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700232 nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES);
233 if (!nl_modes)
234 goto nla_put_failure;
235
236 i = 0;
237 while (ifmodes) {
238 if (ifmodes & 1)
239 NLA_PUT_FLAG(msg, i);
240 ifmodes >>= 1;
241 i++;
242 }
243
244 nla_nest_end(msg, nl_modes);
245
Johannes Bergee688b002008-01-24 19:38:39 +0100246 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
247 if (!nl_bands)
248 goto nla_put_failure;
249
250 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
251 if (!dev->wiphy.bands[band])
252 continue;
253
254 nl_band = nla_nest_start(msg, band);
255 if (!nl_band)
256 goto nla_put_failure;
257
Johannes Bergd51626d2008-10-09 12:20:13 +0200258 /* add HT info */
259 if (dev->wiphy.bands[band]->ht_cap.ht_supported) {
260 NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET,
261 sizeof(dev->wiphy.bands[band]->ht_cap.mcs),
262 &dev->wiphy.bands[band]->ht_cap.mcs);
263 NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA,
264 dev->wiphy.bands[band]->ht_cap.cap);
265 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
266 dev->wiphy.bands[band]->ht_cap.ampdu_factor);
267 NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
268 dev->wiphy.bands[band]->ht_cap.ampdu_density);
269 }
270
Johannes Bergee688b002008-01-24 19:38:39 +0100271 /* add frequencies */
272 nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS);
273 if (!nl_freqs)
274 goto nla_put_failure;
275
276 for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) {
277 nl_freq = nla_nest_start(msg, i);
278 if (!nl_freq)
279 goto nla_put_failure;
280
281 chan = &dev->wiphy.bands[band]->channels[i];
Johannes Bergee688b002008-01-24 19:38:39 +0100282
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400283 if (nl80211_msg_put_channel(msg, chan))
284 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +0200285
Johannes Bergee688b002008-01-24 19:38:39 +0100286 nla_nest_end(msg, nl_freq);
287 }
288
289 nla_nest_end(msg, nl_freqs);
290
291 /* add bitrates */
292 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
293 if (!nl_rates)
294 goto nla_put_failure;
295
296 for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) {
297 nl_rate = nla_nest_start(msg, i);
298 if (!nl_rate)
299 goto nla_put_failure;
300
301 rate = &dev->wiphy.bands[band]->bitrates[i];
302 NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE,
303 rate->bitrate);
304 if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
305 NLA_PUT_FLAG(msg,
306 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE);
307
308 nla_nest_end(msg, nl_rate);
309 }
310
311 nla_nest_end(msg, nl_rates);
312
313 nla_nest_end(msg, nl_band);
314 }
315 nla_nest_end(msg, nl_bands);
316
Johannes Berg8fdc6212009-03-14 09:34:01 +0100317 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
318 if (!nl_cmds)
319 goto nla_put_failure;
320
321 i = 0;
322#define CMD(op, n) \
323 do { \
324 if (dev->ops->op) { \
325 i++; \
326 NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \
327 } \
328 } while (0)
329
330 CMD(add_virtual_intf, NEW_INTERFACE);
331 CMD(change_virtual_intf, SET_INTERFACE);
332 CMD(add_key, NEW_KEY);
333 CMD(add_beacon, NEW_BEACON);
334 CMD(add_station, NEW_STATION);
335 CMD(add_mpath, NEW_MPATH);
336 CMD(set_mesh_params, SET_MESH_PARAMS);
337 CMD(change_bss, SET_BSS);
Jouni Malinen636a5d32009-03-19 13:39:22 +0200338 CMD(auth, AUTHENTICATE);
339 CMD(assoc, ASSOCIATE);
340 CMD(deauth, DEAUTHENTICATE);
341 CMD(disassoc, DISASSOCIATE);
Johannes Berg04a773a2009-04-19 21:24:32 +0200342 CMD(join_ibss, JOIN_IBSS);
Johannes Berg8fdc6212009-03-14 09:34:01 +0100343
344#undef CMD
345 nla_nest_end(msg, nl_cmds);
346
Johannes Berg55682962007-09-20 13:09:35 -0400347 return genlmsg_end(msg, hdr);
348
349 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -0700350 genlmsg_cancel(msg, hdr);
351 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -0400352}
353
354static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
355{
356 int idx = 0;
357 int start = cb->args[0];
358 struct cfg80211_registered_device *dev;
359
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500360 mutex_lock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400361 list_for_each_entry(dev, &cfg80211_drv_list, list) {
Julius Volzb4637272008-07-08 14:02:19 +0200362 if (++idx <= start)
Johannes Berg55682962007-09-20 13:09:35 -0400363 continue;
364 if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid,
365 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Julius Volzb4637272008-07-08 14:02:19 +0200366 dev) < 0) {
367 idx--;
Johannes Berg55682962007-09-20 13:09:35 -0400368 break;
Julius Volzb4637272008-07-08 14:02:19 +0200369 }
Johannes Berg55682962007-09-20 13:09:35 -0400370 }
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500371 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400372
373 cb->args[0] = idx;
374
375 return skb->len;
376}
377
378static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
379{
380 struct sk_buff *msg;
381 struct cfg80211_registered_device *dev;
382
383 dev = cfg80211_get_dev_from_info(info);
384 if (IS_ERR(dev))
385 return PTR_ERR(dev);
386
387 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
388 if (!msg)
389 goto out_err;
390
391 if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0)
392 goto out_free;
393
394 cfg80211_put_dev(dev);
395
396 return genlmsg_unicast(msg, info->snd_pid);
397
398 out_free:
399 nlmsg_free(msg);
400 out_err:
401 cfg80211_put_dev(dev);
402 return -ENOBUFS;
403}
404
Jouni Malinen31888482008-10-30 16:59:24 +0200405static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
406 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
407 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
408 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
409 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
410 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
411};
412
413static int parse_txq_params(struct nlattr *tb[],
414 struct ieee80211_txq_params *txq_params)
415{
416 if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] ||
417 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
418 !tb[NL80211_TXQ_ATTR_AIFS])
419 return -EINVAL;
420
421 txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]);
422 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
423 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
424 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
425 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
426
427 return 0;
428}
429
Johannes Berg55682962007-09-20 13:09:35 -0400430static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
431{
432 struct cfg80211_registered_device *rdev;
Jouni Malinen31888482008-10-30 16:59:24 +0200433 int result = 0, rem_txq_params = 0;
434 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200435 u32 changed;
436 u8 retry_short = 0, retry_long = 0;
437 u32 frag_threshold = 0, rts_threshold = 0;
Johannes Berg55682962007-09-20 13:09:35 -0400438
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100439 rtnl_lock();
Johannes Berg55682962007-09-20 13:09:35 -0400440
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100441 mutex_lock(&cfg80211_mutex);
442
443 rdev = __cfg80211_drv_from_info(info);
444 if (IS_ERR(rdev)) {
445 result = PTR_ERR(rdev);
446 goto unlock;
447 }
448
449 mutex_lock(&rdev->mtx);
450
451 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +0200452 result = cfg80211_dev_rename(
453 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100454
455 mutex_unlock(&cfg80211_mutex);
456
457 if (result)
458 goto bad_res;
Johannes Berg55682962007-09-20 13:09:35 -0400459
Jouni Malinen31888482008-10-30 16:59:24 +0200460 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
461 struct ieee80211_txq_params txq_params;
462 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
463
464 if (!rdev->ops->set_txq_params) {
465 result = -EOPNOTSUPP;
466 goto bad_res;
467 }
468
469 nla_for_each_nested(nl_txq_params,
470 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
471 rem_txq_params) {
472 nla_parse(tb, NL80211_TXQ_ATTR_MAX,
473 nla_data(nl_txq_params),
474 nla_len(nl_txq_params),
475 txq_params_policy);
476 result = parse_txq_params(tb, &txq_params);
477 if (result)
478 goto bad_res;
479
480 result = rdev->ops->set_txq_params(&rdev->wiphy,
481 &txq_params);
482 if (result)
483 goto bad_res;
484 }
485 }
486
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200487 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Sujith094d05d2008-12-12 11:57:43 +0530488 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200489 struct ieee80211_channel *chan;
Johannes Berg306d6112008-12-08 12:39:04 +0100490 struct ieee80211_sta_ht_cap *ht_cap;
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200491 u32 freq, sec_freq;
492
493 if (!rdev->ops->set_channel) {
494 result = -EOPNOTSUPP;
495 goto bad_res;
496 }
497
Johannes Berg306d6112008-12-08 12:39:04 +0100498 result = -EINVAL;
499
Sujith094d05d2008-12-12 11:57:43 +0530500 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
501 channel_type = nla_get_u32(info->attrs[
502 NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
503 if (channel_type != NL80211_CHAN_NO_HT &&
504 channel_type != NL80211_CHAN_HT20 &&
505 channel_type != NL80211_CHAN_HT40PLUS &&
506 channel_type != NL80211_CHAN_HT40MINUS)
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200507 goto bad_res;
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200508 }
509
510 freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
511 chan = ieee80211_get_channel(&rdev->wiphy, freq);
Johannes Berg306d6112008-12-08 12:39:04 +0100512
513 /* Primary channel not allowed */
514 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200515 goto bad_res;
Johannes Berg306d6112008-12-08 12:39:04 +0100516
Sujith094d05d2008-12-12 11:57:43 +0530517 if (channel_type == NL80211_CHAN_HT40MINUS)
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200518 sec_freq = freq - 20;
Sujith094d05d2008-12-12 11:57:43 +0530519 else if (channel_type == NL80211_CHAN_HT40PLUS)
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200520 sec_freq = freq + 20;
521 else
522 sec_freq = 0;
523
Johannes Berg306d6112008-12-08 12:39:04 +0100524 ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap;
525
526 /* no HT capabilities */
Sujith094d05d2008-12-12 11:57:43 +0530527 if (channel_type != NL80211_CHAN_NO_HT &&
Johannes Berg306d6112008-12-08 12:39:04 +0100528 !ht_cap->ht_supported)
529 goto bad_res;
530
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200531 if (sec_freq) {
532 struct ieee80211_channel *schan;
Johannes Berg306d6112008-12-08 12:39:04 +0100533
534 /* no 40 MHz capabilities */
535 if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) ||
536 (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT))
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200537 goto bad_res;
Johannes Berg306d6112008-12-08 12:39:04 +0100538
539 schan = ieee80211_get_channel(&rdev->wiphy, sec_freq);
540
541 /* Secondary channel not allowed */
542 if (!schan || schan->flags & IEEE80211_CHAN_DISABLED)
543 goto bad_res;
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200544 }
545
546 result = rdev->ops->set_channel(&rdev->wiphy, chan,
Sujith094d05d2008-12-12 11:57:43 +0530547 channel_type);
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200548 if (result)
549 goto bad_res;
550 }
551
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200552 changed = 0;
553
554 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
555 retry_short = nla_get_u8(
556 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
557 if (retry_short == 0) {
558 result = -EINVAL;
559 goto bad_res;
560 }
561 changed |= WIPHY_PARAM_RETRY_SHORT;
562 }
563
564 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
565 retry_long = nla_get_u8(
566 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
567 if (retry_long == 0) {
568 result = -EINVAL;
569 goto bad_res;
570 }
571 changed |= WIPHY_PARAM_RETRY_LONG;
572 }
573
574 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
575 frag_threshold = nla_get_u32(
576 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
577 if (frag_threshold < 256) {
578 result = -EINVAL;
579 goto bad_res;
580 }
581 if (frag_threshold != (u32) -1) {
582 /*
583 * Fragments (apart from the last one) are required to
584 * have even length. Make the fragmentation code
585 * simpler by stripping LSB should someone try to use
586 * odd threshold value.
587 */
588 frag_threshold &= ~0x1;
589 }
590 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
591 }
592
593 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
594 rts_threshold = nla_get_u32(
595 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
596 changed |= WIPHY_PARAM_RTS_THRESHOLD;
597 }
598
599 if (changed) {
600 u8 old_retry_short, old_retry_long;
601 u32 old_frag_threshold, old_rts_threshold;
602
603 if (!rdev->ops->set_wiphy_params) {
604 result = -EOPNOTSUPP;
605 goto bad_res;
606 }
607
608 old_retry_short = rdev->wiphy.retry_short;
609 old_retry_long = rdev->wiphy.retry_long;
610 old_frag_threshold = rdev->wiphy.frag_threshold;
611 old_rts_threshold = rdev->wiphy.rts_threshold;
612
613 if (changed & WIPHY_PARAM_RETRY_SHORT)
614 rdev->wiphy.retry_short = retry_short;
615 if (changed & WIPHY_PARAM_RETRY_LONG)
616 rdev->wiphy.retry_long = retry_long;
617 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
618 rdev->wiphy.frag_threshold = frag_threshold;
619 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
620 rdev->wiphy.rts_threshold = rts_threshold;
621
622 result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed);
623 if (result) {
624 rdev->wiphy.retry_short = old_retry_short;
625 rdev->wiphy.retry_long = old_retry_long;
626 rdev->wiphy.frag_threshold = old_frag_threshold;
627 rdev->wiphy.rts_threshold = old_rts_threshold;
628 }
629 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200630
Johannes Berg306d6112008-12-08 12:39:04 +0100631 bad_res:
Johannes Berg4bbf4d52009-03-24 09:35:46 +0100632 mutex_unlock(&rdev->mtx);
633 unlock:
634 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -0400635 return result;
636}
637
638
639static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +0200640 struct cfg80211_registered_device *rdev,
Johannes Berg55682962007-09-20 13:09:35 -0400641 struct net_device *dev)
642{
643 void *hdr;
644
645 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE);
646 if (!hdr)
647 return -1;
648
649 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
Johannes Bergd7264052009-04-19 16:23:20 +0200650 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg55682962007-09-20 13:09:35 -0400651 NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name);
Johannes Berg60719ff2008-09-16 14:55:09 +0200652 NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype);
Johannes Berg55682962007-09-20 13:09:35 -0400653 return genlmsg_end(msg, hdr);
654
655 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -0700656 genlmsg_cancel(msg, hdr);
657 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -0400658}
659
660static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
661{
662 int wp_idx = 0;
663 int if_idx = 0;
664 int wp_start = cb->args[0];
665 int if_start = cb->args[1];
666 struct cfg80211_registered_device *dev;
667 struct wireless_dev *wdev;
668
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500669 mutex_lock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400670 list_for_each_entry(dev, &cfg80211_drv_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +0200671 if (wp_idx < wp_start) {
672 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -0400673 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +0200674 }
Johannes Berg55682962007-09-20 13:09:35 -0400675 if_idx = 0;
676
677 mutex_lock(&dev->devlist_mtx);
678 list_for_each_entry(wdev, &dev->netdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +0200679 if (if_idx < if_start) {
680 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -0400681 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +0200682 }
Johannes Berg55682962007-09-20 13:09:35 -0400683 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid,
684 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Bergd7264052009-04-19 16:23:20 +0200685 dev, wdev->netdev) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +0200686 mutex_unlock(&dev->devlist_mtx);
687 goto out;
688 }
689 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -0400690 }
691 mutex_unlock(&dev->devlist_mtx);
Johannes Bergbba95fe2008-07-29 13:22:51 +0200692
693 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -0400694 }
Johannes Bergbba95fe2008-07-29 13:22:51 +0200695 out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -0500696 mutex_unlock(&cfg80211_mutex);
Johannes Berg55682962007-09-20 13:09:35 -0400697
698 cb->args[0] = wp_idx;
699 cb->args[1] = if_idx;
700
701 return skb->len;
702}
703
704static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
705{
706 struct sk_buff *msg;
707 struct cfg80211_registered_device *dev;
708 struct net_device *netdev;
709 int err;
710
Johannes Bergbba95fe2008-07-29 13:22:51 +0200711 err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev);
Johannes Berg55682962007-09-20 13:09:35 -0400712 if (err)
713 return err;
714
715 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
716 if (!msg)
717 goto out_err;
718
Johannes Bergd7264052009-04-19 16:23:20 +0200719 if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0,
720 dev, netdev) < 0)
Johannes Berg55682962007-09-20 13:09:35 -0400721 goto out_free;
722
723 dev_put(netdev);
724 cfg80211_put_dev(dev);
725
726 return genlmsg_unicast(msg, info->snd_pid);
727
728 out_free:
729 nlmsg_free(msg);
730 out_err:
731 dev_put(netdev);
732 cfg80211_put_dev(dev);
733 return -ENOBUFS;
734}
735
Michael Wu66f7ac52008-01-31 19:48:22 +0100736static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
737 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
738 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
739 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
740 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
741 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
742};
743
744static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
745{
746 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
747 int flag;
748
749 *mntrflags = 0;
750
751 if (!nla)
752 return -EINVAL;
753
754 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
755 nla, mntr_flags_policy))
756 return -EINVAL;
757
758 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
759 if (flags[flag])
760 *mntrflags |= (1<<flag);
761
762 return 0;
763}
764
Johannes Berg55682962007-09-20 13:09:35 -0400765static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
766{
767 struct cfg80211_registered_device *drv;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100768 struct vif_params params;
Johannes Berg55682962007-09-20 13:09:35 -0400769 int err, ifindex;
Johannes Berg04a773a2009-04-19 21:24:32 +0200770 enum nl80211_iftype otype, ntype;
Johannes Berg55682962007-09-20 13:09:35 -0400771 struct net_device *dev;
Johannes Berg92ffe052008-09-16 20:39:36 +0200772 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100773 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -0400774
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100775 memset(&params, 0, sizeof(params));
776
Johannes Berg3b858752009-03-12 09:55:09 +0100777 rtnl_lock();
778
Johannes Bergbba95fe2008-07-29 13:22:51 +0200779 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg55682962007-09-20 13:09:35 -0400780 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +0100781 goto unlock_rtnl;
782
Johannes Berg55682962007-09-20 13:09:35 -0400783 ifindex = dev->ifindex;
Johannes Berg04a773a2009-04-19 21:24:32 +0200784 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -0400785 dev_put(dev);
786
Johannes Berg723b0382008-09-16 20:22:09 +0200787 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100788 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +0200789 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100790 change = true;
Johannes Berg04a773a2009-04-19 21:24:32 +0200791 if (ntype > NL80211_IFTYPE_MAX) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100792 err = -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +0200793 goto unlock;
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100794 }
Johannes Berg723b0382008-09-16 20:22:09 +0200795 }
796
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700797 if (!drv->ops->change_virtual_intf ||
Johannes Berg04a773a2009-04-19 21:24:32 +0200798 !(drv->wiphy.interface_modes & (1 << ntype))) {
Johannes Berg55682962007-09-20 13:09:35 -0400799 err = -EOPNOTSUPP;
800 goto unlock;
801 }
802
Johannes Berg92ffe052008-09-16 20:39:36 +0200803 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg04a773a2009-04-19 21:24:32 +0200804 if (ntype != NL80211_IFTYPE_MESH_POINT) {
Johannes Berg92ffe052008-09-16 20:39:36 +0200805 err = -EINVAL;
806 goto unlock;
807 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100808 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
809 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100810 change = true;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100811 }
812
Johannes Berg92ffe052008-09-16 20:39:36 +0200813 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg04a773a2009-04-19 21:24:32 +0200814 if (ntype != NL80211_IFTYPE_MONITOR) {
Johannes Berg92ffe052008-09-16 20:39:36 +0200815 err = -EINVAL;
816 goto unlock;
817 }
818 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
819 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100820 if (err)
821 goto unlock;
822
823 flags = &_flags;
824 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +0200825 }
Johannes Berg3b858752009-03-12 09:55:09 +0100826
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100827 if (change)
828 err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex,
Johannes Berg04a773a2009-04-19 21:24:32 +0200829 ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +0100830 else
831 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +0200832
833 dev = __dev_get_by_index(&init_net, ifindex);
Johannes Berg04a773a2009-04-19 21:24:32 +0200834 WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != ntype));
835
836 if (dev && !err && (ntype != otype)) {
837 if (otype == NL80211_IFTYPE_ADHOC)
Johannes Berg9d308422009-04-20 18:43:46 +0200838 cfg80211_clear_ibss(dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +0200839 }
Johannes Berg60719ff2008-09-16 14:55:09 +0200840
Johannes Berg55682962007-09-20 13:09:35 -0400841 unlock:
842 cfg80211_put_dev(drv);
Johannes Berg3b858752009-03-12 09:55:09 +0100843 unlock_rtnl:
844 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -0400845 return err;
846}
847
848static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
849{
850 struct cfg80211_registered_device *drv;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100851 struct vif_params params;
Johannes Berg55682962007-09-20 13:09:35 -0400852 int err;
853 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +0100854 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -0400855
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100856 memset(&params, 0, sizeof(params));
857
Johannes Berg55682962007-09-20 13:09:35 -0400858 if (!info->attrs[NL80211_ATTR_IFNAME])
859 return -EINVAL;
860
861 if (info->attrs[NL80211_ATTR_IFTYPE]) {
862 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
863 if (type > NL80211_IFTYPE_MAX)
864 return -EINVAL;
865 }
866
Johannes Berg3b858752009-03-12 09:55:09 +0100867 rtnl_lock();
868
Johannes Berg55682962007-09-20 13:09:35 -0400869 drv = cfg80211_get_dev_from_info(info);
Johannes Berg3b858752009-03-12 09:55:09 +0100870 if (IS_ERR(drv)) {
871 err = PTR_ERR(drv);
872 goto unlock_rtnl;
873 }
Johannes Berg55682962007-09-20 13:09:35 -0400874
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -0700875 if (!drv->ops->add_virtual_intf ||
876 !(drv->wiphy.interface_modes & (1 << type))) {
Johannes Berg55682962007-09-20 13:09:35 -0400877 err = -EOPNOTSUPP;
878 goto unlock;
879 }
880
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100881 if (type == NL80211_IFTYPE_MESH_POINT &&
882 info->attrs[NL80211_ATTR_MESH_ID]) {
883 params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
884 params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
885 }
886
Michael Wu66f7ac52008-01-31 19:48:22 +0100887 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
888 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
889 &flags);
Johannes Berg55682962007-09-20 13:09:35 -0400890 err = drv->ops->add_virtual_intf(&drv->wiphy,
Michael Wu66f7ac52008-01-31 19:48:22 +0100891 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100892 type, err ? NULL : &flags, &params);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100893
Johannes Berg55682962007-09-20 13:09:35 -0400894 unlock:
895 cfg80211_put_dev(drv);
Johannes Berg3b858752009-03-12 09:55:09 +0100896 unlock_rtnl:
897 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -0400898 return err;
899}
900
901static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
902{
903 struct cfg80211_registered_device *drv;
904 int ifindex, err;
905 struct net_device *dev;
906
Johannes Berg3b858752009-03-12 09:55:09 +0100907 rtnl_lock();
908
Johannes Bergbba95fe2008-07-29 13:22:51 +0200909 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg55682962007-09-20 13:09:35 -0400910 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +0100911 goto unlock_rtnl;
Johannes Berg55682962007-09-20 13:09:35 -0400912 ifindex = dev->ifindex;
913 dev_put(dev);
914
915 if (!drv->ops->del_virtual_intf) {
916 err = -EOPNOTSUPP;
917 goto out;
918 }
919
Johannes Berg55682962007-09-20 13:09:35 -0400920 err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex);
Johannes Berg55682962007-09-20 13:09:35 -0400921
922 out:
923 cfg80211_put_dev(drv);
Johannes Berg3b858752009-03-12 09:55:09 +0100924 unlock_rtnl:
925 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -0400926 return err;
927}
928
Johannes Berg41ade002007-12-19 02:03:29 +0100929struct get_key_cookie {
930 struct sk_buff *msg;
931 int error;
932};
933
934static void get_key_callback(void *c, struct key_params *params)
935{
936 struct get_key_cookie *cookie = c;
937
938 if (params->key)
939 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA,
940 params->key_len, params->key);
941
942 if (params->seq)
943 NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ,
944 params->seq_len, params->seq);
945
946 if (params->cipher)
947 NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
948 params->cipher);
949
950 return;
951 nla_put_failure:
952 cookie->error = 1;
953}
954
955static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
956{
957 struct cfg80211_registered_device *drv;
958 int err;
959 struct net_device *dev;
960 u8 key_idx = 0;
961 u8 *mac_addr = NULL;
962 struct get_key_cookie cookie = {
963 .error = 0,
964 };
965 void *hdr;
966 struct sk_buff *msg;
967
968 if (info->attrs[NL80211_ATTR_KEY_IDX])
969 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
970
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200971 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +0100972 return -EINVAL;
973
974 if (info->attrs[NL80211_ATTR_MAC])
975 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
976
Johannes Berg3b858752009-03-12 09:55:09 +0100977 rtnl_lock();
978
Johannes Bergbba95fe2008-07-29 13:22:51 +0200979 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg41ade002007-12-19 02:03:29 +0100980 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +0100981 goto unlock_rtnl;
Johannes Berg41ade002007-12-19 02:03:29 +0100982
983 if (!drv->ops->get_key) {
984 err = -EOPNOTSUPP;
985 goto out;
986 }
987
988 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
989 if (!msg) {
990 err = -ENOMEM;
991 goto out;
992 }
993
994 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
995 NL80211_CMD_NEW_KEY);
996
997 if (IS_ERR(hdr)) {
998 err = PTR_ERR(hdr);
999 goto out;
1000 }
1001
1002 cookie.msg = msg;
1003
1004 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1005 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx);
1006 if (mac_addr)
1007 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1008
Johannes Berg41ade002007-12-19 02:03:29 +01001009 err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr,
1010 &cookie, get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01001011
1012 if (err)
1013 goto out;
1014
1015 if (cookie.error)
1016 goto nla_put_failure;
1017
1018 genlmsg_end(msg, hdr);
1019 err = genlmsg_unicast(msg, info->snd_pid);
1020 goto out;
1021
1022 nla_put_failure:
1023 err = -ENOBUFS;
1024 nlmsg_free(msg);
1025 out:
1026 cfg80211_put_dev(drv);
1027 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001028 unlock_rtnl:
1029 rtnl_unlock();
1030
Johannes Berg41ade002007-12-19 02:03:29 +01001031 return err;
1032}
1033
1034static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
1035{
1036 struct cfg80211_registered_device *drv;
1037 int err;
1038 struct net_device *dev;
1039 u8 key_idx;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001040 int (*func)(struct wiphy *wiphy, struct net_device *netdev,
1041 u8 key_index);
Johannes Berg41ade002007-12-19 02:03:29 +01001042
1043 if (!info->attrs[NL80211_ATTR_KEY_IDX])
1044 return -EINVAL;
1045
1046 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1047
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001048 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) {
1049 if (key_idx < 4 || key_idx > 5)
1050 return -EINVAL;
1051 } else if (key_idx > 3)
Johannes Berg41ade002007-12-19 02:03:29 +01001052 return -EINVAL;
1053
1054 /* currently only support setting default key */
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001055 if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] &&
1056 !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT])
Johannes Berg41ade002007-12-19 02:03:29 +01001057 return -EINVAL;
1058
Johannes Berg3b858752009-03-12 09:55:09 +01001059 rtnl_lock();
1060
Johannes Bergbba95fe2008-07-29 13:22:51 +02001061 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg41ade002007-12-19 02:03:29 +01001062 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001063 goto unlock_rtnl;
Johannes Berg41ade002007-12-19 02:03:29 +01001064
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001065 if (info->attrs[NL80211_ATTR_KEY_DEFAULT])
1066 func = drv->ops->set_default_key;
1067 else
1068 func = drv->ops->set_default_mgmt_key;
1069
1070 if (!func) {
Johannes Berg41ade002007-12-19 02:03:29 +01001071 err = -EOPNOTSUPP;
1072 goto out;
1073 }
1074
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001075 err = func(&drv->wiphy, dev, key_idx);
Johannes Berg41ade002007-12-19 02:03:29 +01001076
1077 out:
1078 cfg80211_put_dev(drv);
1079 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001080
1081 unlock_rtnl:
1082 rtnl_unlock();
1083
Johannes Berg41ade002007-12-19 02:03:29 +01001084 return err;
1085}
1086
1087static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
1088{
1089 struct cfg80211_registered_device *drv;
Johannes Berg25e47c182009-04-02 20:14:06 +02001090 int err, i;
Johannes Berg41ade002007-12-19 02:03:29 +01001091 struct net_device *dev;
1092 struct key_params params;
1093 u8 key_idx = 0;
1094 u8 *mac_addr = NULL;
1095
1096 memset(&params, 0, sizeof(params));
1097
1098 if (!info->attrs[NL80211_ATTR_KEY_CIPHER])
1099 return -EINVAL;
1100
1101 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
1102 params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
1103 params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
1104 }
1105
1106 if (info->attrs[NL80211_ATTR_KEY_IDX])
1107 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1108
1109 params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
1110
1111 if (info->attrs[NL80211_ATTR_MAC])
1112 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1113
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001114 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001115 return -EINVAL;
1116
1117 /*
1118 * Disallow pairwise keys with non-zero index unless it's WEP
1119 * (because current deployments use pairwise WEP keys with
1120 * non-zero indizes but 802.11i clearly specifies to use zero)
1121 */
1122 if (mac_addr && key_idx &&
1123 params.cipher != WLAN_CIPHER_SUITE_WEP40 &&
1124 params.cipher != WLAN_CIPHER_SUITE_WEP104)
1125 return -EINVAL;
1126
1127 /* TODO: add definitions for the lengths to linux/ieee80211.h */
1128 switch (params.cipher) {
1129 case WLAN_CIPHER_SUITE_WEP40:
1130 if (params.key_len != 5)
1131 return -EINVAL;
1132 break;
1133 case WLAN_CIPHER_SUITE_TKIP:
1134 if (params.key_len != 32)
1135 return -EINVAL;
1136 break;
1137 case WLAN_CIPHER_SUITE_CCMP:
1138 if (params.key_len != 16)
1139 return -EINVAL;
1140 break;
1141 case WLAN_CIPHER_SUITE_WEP104:
1142 if (params.key_len != 13)
1143 return -EINVAL;
1144 break;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001145 case WLAN_CIPHER_SUITE_AES_CMAC:
1146 if (params.key_len != 16)
1147 return -EINVAL;
1148 break;
Johannes Berg41ade002007-12-19 02:03:29 +01001149 default:
1150 return -EINVAL;
1151 }
1152
Johannes Berg3b858752009-03-12 09:55:09 +01001153 rtnl_lock();
1154
Johannes Bergbba95fe2008-07-29 13:22:51 +02001155 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg41ade002007-12-19 02:03:29 +01001156 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001157 goto unlock_rtnl;
Johannes Berg41ade002007-12-19 02:03:29 +01001158
Johannes Berg25e47c182009-04-02 20:14:06 +02001159 for (i = 0; i < drv->wiphy.n_cipher_suites; i++)
1160 if (params.cipher == drv->wiphy.cipher_suites[i])
1161 break;
1162 if (i == drv->wiphy.n_cipher_suites) {
1163 err = -EINVAL;
1164 goto out;
1165 }
1166
Johannes Berg41ade002007-12-19 02:03:29 +01001167 if (!drv->ops->add_key) {
1168 err = -EOPNOTSUPP;
1169 goto out;
1170 }
1171
Johannes Berg41ade002007-12-19 02:03:29 +01001172 err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, &params);
Johannes Berg41ade002007-12-19 02:03:29 +01001173
1174 out:
1175 cfg80211_put_dev(drv);
1176 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001177 unlock_rtnl:
1178 rtnl_unlock();
1179
Johannes Berg41ade002007-12-19 02:03:29 +01001180 return err;
1181}
1182
1183static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
1184{
1185 struct cfg80211_registered_device *drv;
1186 int err;
1187 struct net_device *dev;
1188 u8 key_idx = 0;
1189 u8 *mac_addr = NULL;
1190
1191 if (info->attrs[NL80211_ATTR_KEY_IDX])
1192 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
1193
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001194 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01001195 return -EINVAL;
1196
1197 if (info->attrs[NL80211_ATTR_MAC])
1198 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1199
Johannes Berg3b858752009-03-12 09:55:09 +01001200 rtnl_lock();
1201
Johannes Bergbba95fe2008-07-29 13:22:51 +02001202 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg41ade002007-12-19 02:03:29 +01001203 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001204 goto unlock_rtnl;
Johannes Berg41ade002007-12-19 02:03:29 +01001205
1206 if (!drv->ops->del_key) {
1207 err = -EOPNOTSUPP;
1208 goto out;
1209 }
1210
Johannes Berg41ade002007-12-19 02:03:29 +01001211 err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01001212
1213 out:
1214 cfg80211_put_dev(drv);
1215 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001216
1217 unlock_rtnl:
1218 rtnl_unlock();
1219
Johannes Berg41ade002007-12-19 02:03:29 +01001220 return err;
1221}
1222
Johannes Berged1b6cc2007-12-19 02:03:32 +01001223static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info)
1224{
1225 int (*call)(struct wiphy *wiphy, struct net_device *dev,
1226 struct beacon_parameters *info);
1227 struct cfg80211_registered_device *drv;
1228 int err;
1229 struct net_device *dev;
1230 struct beacon_parameters params;
1231 int haveinfo = 0;
1232
Johannes Bergf4a11bb2009-03-27 12:40:28 +01001233 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL]))
1234 return -EINVAL;
1235
Johannes Berg3b858752009-03-12 09:55:09 +01001236 rtnl_lock();
1237
Johannes Bergbba95fe2008-07-29 13:22:51 +02001238 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01001239 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001240 goto unlock_rtnl;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001241
Jouni Malineneec60b02009-03-20 21:21:19 +02001242 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1243 err = -EOPNOTSUPP;
1244 goto out;
1245 }
1246
Johannes Berged1b6cc2007-12-19 02:03:32 +01001247 switch (info->genlhdr->cmd) {
1248 case NL80211_CMD_NEW_BEACON:
1249 /* these are required for NEW_BEACON */
1250 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
1251 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
1252 !info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1253 err = -EINVAL;
1254 goto out;
1255 }
1256
1257 call = drv->ops->add_beacon;
1258 break;
1259 case NL80211_CMD_SET_BEACON:
1260 call = drv->ops->set_beacon;
1261 break;
1262 default:
1263 WARN_ON(1);
1264 err = -EOPNOTSUPP;
1265 goto out;
1266 }
1267
1268 if (!call) {
1269 err = -EOPNOTSUPP;
1270 goto out;
1271 }
1272
1273 memset(&params, 0, sizeof(params));
1274
1275 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
1276 params.interval =
1277 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
1278 haveinfo = 1;
1279 }
1280
1281 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
1282 params.dtim_period =
1283 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
1284 haveinfo = 1;
1285 }
1286
1287 if (info->attrs[NL80211_ATTR_BEACON_HEAD]) {
1288 params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1289 params.head_len =
1290 nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]);
1291 haveinfo = 1;
1292 }
1293
1294 if (info->attrs[NL80211_ATTR_BEACON_TAIL]) {
1295 params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1296 params.tail_len =
1297 nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]);
1298 haveinfo = 1;
1299 }
1300
1301 if (!haveinfo) {
1302 err = -EINVAL;
1303 goto out;
1304 }
1305
Johannes Berged1b6cc2007-12-19 02:03:32 +01001306 err = call(&drv->wiphy, dev, &params);
Johannes Berged1b6cc2007-12-19 02:03:32 +01001307
1308 out:
1309 cfg80211_put_dev(drv);
1310 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001311 unlock_rtnl:
1312 rtnl_unlock();
1313
Johannes Berged1b6cc2007-12-19 02:03:32 +01001314 return err;
1315}
1316
1317static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info)
1318{
1319 struct cfg80211_registered_device *drv;
1320 int err;
1321 struct net_device *dev;
1322
Johannes Berg3b858752009-03-12 09:55:09 +01001323 rtnl_lock();
1324
Johannes Bergbba95fe2008-07-29 13:22:51 +02001325 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01001326 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001327 goto unlock_rtnl;
Johannes Berged1b6cc2007-12-19 02:03:32 +01001328
1329 if (!drv->ops->del_beacon) {
1330 err = -EOPNOTSUPP;
1331 goto out;
1332 }
1333
Jouni Malineneec60b02009-03-20 21:21:19 +02001334 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
1335 err = -EOPNOTSUPP;
1336 goto out;
1337 }
Johannes Berged1b6cc2007-12-19 02:03:32 +01001338 err = drv->ops->del_beacon(&drv->wiphy, dev);
Johannes Berged1b6cc2007-12-19 02:03:32 +01001339
1340 out:
1341 cfg80211_put_dev(drv);
1342 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001343 unlock_rtnl:
1344 rtnl_unlock();
1345
Johannes Berged1b6cc2007-12-19 02:03:32 +01001346 return err;
1347}
1348
Johannes Berg5727ef12007-12-19 02:03:34 +01001349static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
1350 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
1351 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
1352 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
1353};
1354
1355static int parse_station_flags(struct nlattr *nla, u32 *staflags)
1356{
1357 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
1358 int flag;
1359
1360 *staflags = 0;
1361
1362 if (!nla)
1363 return 0;
1364
1365 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
1366 nla, sta_flags_policy))
1367 return -EINVAL;
1368
1369 *staflags = STATION_FLAG_CHANGED;
1370
1371 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++)
1372 if (flags[flag])
1373 *staflags |= (1<<flag);
1374
1375 return 0;
1376}
1377
Henning Rogge420e7fa2008-12-11 22:04:19 +01001378static u16 nl80211_calculate_bitrate(struct rate_info *rate)
1379{
1380 int modulation, streams, bitrate;
1381
1382 if (!(rate->flags & RATE_INFO_FLAGS_MCS))
1383 return rate->legacy;
1384
1385 /* the formula below does only work for MCS values smaller than 32 */
1386 if (rate->mcs >= 32)
1387 return 0;
1388
1389 modulation = rate->mcs & 7;
1390 streams = (rate->mcs >> 3) + 1;
1391
1392 bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ?
1393 13500000 : 6500000;
1394
1395 if (modulation < 4)
1396 bitrate *= (modulation + 1);
1397 else if (modulation == 4)
1398 bitrate *= (modulation + 2);
1399 else
1400 bitrate *= (modulation + 3);
1401
1402 bitrate *= streams;
1403
1404 if (rate->flags & RATE_INFO_FLAGS_SHORT_GI)
1405 bitrate = (bitrate / 9) * 10;
1406
1407 /* do NOT round down here */
1408 return (bitrate + 50000) / 100000;
1409}
1410
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001411static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq,
1412 int flags, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001413 u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001414{
1415 void *hdr;
Henning Rogge420e7fa2008-12-11 22:04:19 +01001416 struct nlattr *sinfoattr, *txrate;
1417 u16 bitrate;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001418
1419 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1420 if (!hdr)
1421 return -1;
1422
1423 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1424 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr);
1425
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001426 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
1427 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001428 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001429 if (sinfo->filled & STATION_INFO_INACTIVE_TIME)
1430 NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME,
1431 sinfo->inactive_time);
1432 if (sinfo->filled & STATION_INFO_RX_BYTES)
1433 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES,
1434 sinfo->rx_bytes);
1435 if (sinfo->filled & STATION_INFO_TX_BYTES)
1436 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES,
1437 sinfo->tx_bytes);
1438 if (sinfo->filled & STATION_INFO_LLID)
1439 NLA_PUT_U16(msg, NL80211_STA_INFO_LLID,
1440 sinfo->llid);
1441 if (sinfo->filled & STATION_INFO_PLID)
1442 NLA_PUT_U16(msg, NL80211_STA_INFO_PLID,
1443 sinfo->plid);
1444 if (sinfo->filled & STATION_INFO_PLINK_STATE)
1445 NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE,
1446 sinfo->plink_state);
Henning Rogge420e7fa2008-12-11 22:04:19 +01001447 if (sinfo->filled & STATION_INFO_SIGNAL)
1448 NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL,
1449 sinfo->signal);
1450 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
1451 txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE);
1452 if (!txrate)
1453 goto nla_put_failure;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001454
Henning Rogge420e7fa2008-12-11 22:04:19 +01001455 /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */
1456 bitrate = nl80211_calculate_bitrate(&sinfo->txrate);
1457 if (bitrate > 0)
1458 NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate);
1459
1460 if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS)
1461 NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS,
1462 sinfo->txrate.mcs);
1463 if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH)
1464 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH);
1465 if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI)
1466 NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI);
1467
1468 nla_nest_end(msg, txrate);
1469 }
Jouni Malinen98c8a60a2009-02-17 13:24:57 +02001470 if (sinfo->filled & STATION_INFO_RX_PACKETS)
1471 NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS,
1472 sinfo->rx_packets);
1473 if (sinfo->filled & STATION_INFO_TX_PACKETS)
1474 NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS,
1475 sinfo->tx_packets);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001476 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001477
1478 return genlmsg_end(msg, hdr);
1479
1480 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001481 genlmsg_cancel(msg, hdr);
1482 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001483}
1484
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001485static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02001486 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001487{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001488 struct station_info sinfo;
1489 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001490 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001491 u8 mac_addr[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02001492 int ifidx = cb->args[0];
1493 int sta_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001494 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001495
Johannes Bergbba95fe2008-07-29 13:22:51 +02001496 if (!ifidx) {
1497 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1498 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1499 nl80211_policy);
1500 if (err)
1501 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001502
Johannes Bergbba95fe2008-07-29 13:22:51 +02001503 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1504 return -EINVAL;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001505
Johannes Bergbba95fe2008-07-29 13:22:51 +02001506 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1507 if (!ifidx)
1508 return -EINVAL;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001509 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001510
Johannes Berg3b858752009-03-12 09:55:09 +01001511 rtnl_lock();
1512
1513 netdev = __dev_get_by_index(&init_net, ifidx);
1514 if (!netdev) {
1515 err = -ENODEV;
1516 goto out_rtnl;
1517 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001518
Johannes Bergbba95fe2008-07-29 13:22:51 +02001519 dev = cfg80211_get_dev_from_ifindex(ifidx);
1520 if (IS_ERR(dev)) {
1521 err = PTR_ERR(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001522 goto out_rtnl;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001523 }
1524
1525 if (!dev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02001526 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001527 goto out_err;
1528 }
1529
Johannes Bergbba95fe2008-07-29 13:22:51 +02001530 while (1) {
1531 err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx,
1532 mac_addr, &sinfo);
1533 if (err == -ENOENT)
1534 break;
1535 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001536 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001537
1538 if (nl80211_send_station(skb,
1539 NETLINK_CB(cb->skb).pid,
1540 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1541 netdev, mac_addr,
1542 &sinfo) < 0)
1543 goto out;
1544
1545 sta_idx++;
1546 }
1547
1548
1549 out:
1550 cb->args[1] = sta_idx;
1551 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001552 out_err:
1553 cfg80211_put_dev(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001554 out_rtnl:
1555 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02001556
1557 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001558}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001559
Johannes Berg5727ef12007-12-19 02:03:34 +01001560static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
1561{
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001562 struct cfg80211_registered_device *drv;
1563 int err;
1564 struct net_device *dev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001565 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001566 struct sk_buff *msg;
1567 u8 *mac_addr = NULL;
1568
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001569 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001570
1571 if (!info->attrs[NL80211_ATTR_MAC])
1572 return -EINVAL;
1573
1574 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1575
Johannes Berg3b858752009-03-12 09:55:09 +01001576 rtnl_lock();
1577
Johannes Bergbba95fe2008-07-29 13:22:51 +02001578 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001579 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001580 goto out_rtnl;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001581
1582 if (!drv->ops->get_station) {
1583 err = -EOPNOTSUPP;
1584 goto out;
1585 }
1586
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001587 err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001588 if (err)
1589 goto out;
1590
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001591 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1592 if (!msg)
1593 goto out;
1594
1595 if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001596 dev, mac_addr, &sinfo) < 0)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001597 goto out_free;
1598
1599 err = genlmsg_unicast(msg, info->snd_pid);
1600 goto out;
1601
1602 out_free:
1603 nlmsg_free(msg);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001604 out:
1605 cfg80211_put_dev(drv);
1606 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001607 out_rtnl:
1608 rtnl_unlock();
1609
Johannes Bergfd5b74d2007-12-19 02:03:36 +01001610 return err;
Johannes Berg5727ef12007-12-19 02:03:34 +01001611}
1612
1613/*
1614 * Get vlan interface making sure it is on the right wiphy.
1615 */
1616static int get_vlan(struct nlattr *vlanattr,
1617 struct cfg80211_registered_device *rdev,
1618 struct net_device **vlan)
1619{
1620 *vlan = NULL;
1621
1622 if (vlanattr) {
1623 *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr));
1624 if (!*vlan)
1625 return -ENODEV;
1626 if (!(*vlan)->ieee80211_ptr)
1627 return -EINVAL;
1628 if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy)
1629 return -EINVAL;
1630 }
1631 return 0;
1632}
1633
1634static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
1635{
1636 struct cfg80211_registered_device *drv;
1637 int err;
1638 struct net_device *dev;
1639 struct station_parameters params;
1640 u8 *mac_addr = NULL;
1641
1642 memset(&params, 0, sizeof(params));
1643
1644 params.listen_interval = -1;
1645
1646 if (info->attrs[NL80211_ATTR_STA_AID])
1647 return -EINVAL;
1648
1649 if (!info->attrs[NL80211_ATTR_MAC])
1650 return -EINVAL;
1651
1652 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1653
1654 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
1655 params.supported_rates =
1656 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1657 params.supported_rates_len =
1658 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1659 }
1660
1661 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1662 params.listen_interval =
1663 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
1664
Jouni Malinen36aedc92008-08-25 11:58:58 +03001665 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1666 params.ht_capa =
1667 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
1668
Johannes Berg5727ef12007-12-19 02:03:34 +01001669 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1670 &params.station_flags))
1671 return -EINVAL;
1672
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001673 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION])
1674 params.plink_action =
1675 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
1676
Johannes Berg3b858752009-03-12 09:55:09 +01001677 rtnl_lock();
1678
Johannes Bergbba95fe2008-07-29 13:22:51 +02001679 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg5727ef12007-12-19 02:03:34 +01001680 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001681 goto out_rtnl;
Johannes Berg5727ef12007-12-19 02:03:34 +01001682
1683 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan);
1684 if (err)
1685 goto out;
1686
1687 if (!drv->ops->change_station) {
1688 err = -EOPNOTSUPP;
1689 goto out;
1690 }
1691
Johannes Berg5727ef12007-12-19 02:03:34 +01001692 err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01001693
1694 out:
1695 if (params.vlan)
1696 dev_put(params.vlan);
1697 cfg80211_put_dev(drv);
1698 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001699 out_rtnl:
1700 rtnl_unlock();
1701
Johannes Berg5727ef12007-12-19 02:03:34 +01001702 return err;
1703}
1704
1705static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
1706{
1707 struct cfg80211_registered_device *drv;
1708 int err;
1709 struct net_device *dev;
1710 struct station_parameters params;
1711 u8 *mac_addr = NULL;
1712
1713 memset(&params, 0, sizeof(params));
1714
1715 if (!info->attrs[NL80211_ATTR_MAC])
1716 return -EINVAL;
1717
1718 if (!info->attrs[NL80211_ATTR_STA_AID])
1719 return -EINVAL;
1720
1721 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
1722 return -EINVAL;
1723
1724 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
1725 return -EINVAL;
1726
1727 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1728 params.supported_rates =
1729 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1730 params.supported_rates_len =
1731 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
1732 params.listen_interval =
1733 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg16f2e852008-04-07 14:35:46 +02001734 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001735 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
1736 params.ht_capa =
1737 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01001738
1739 if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS],
1740 &params.station_flags))
1741 return -EINVAL;
1742
Johannes Berg3b858752009-03-12 09:55:09 +01001743 rtnl_lock();
1744
Johannes Bergbba95fe2008-07-29 13:22:51 +02001745 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg5727ef12007-12-19 02:03:34 +01001746 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001747 goto out_rtnl;
Johannes Berg5727ef12007-12-19 02:03:34 +01001748
Johannes Berge80cf852009-05-11 14:43:13 +02001749 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1750 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) {
1751 err = -EINVAL;
1752 goto out;
1753 }
1754
Johannes Berg5727ef12007-12-19 02:03:34 +01001755 err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, &params.vlan);
1756 if (err)
1757 goto out;
1758
1759 if (!drv->ops->add_station) {
1760 err = -EOPNOTSUPP;
1761 goto out;
1762 }
1763
Jouni Malinen35a8efe2009-03-20 21:21:18 +02001764 if (!netif_running(dev)) {
1765 err = -ENETDOWN;
1766 goto out;
1767 }
1768
Johannes Berg5727ef12007-12-19 02:03:34 +01001769 err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01001770
1771 out:
1772 if (params.vlan)
1773 dev_put(params.vlan);
1774 cfg80211_put_dev(drv);
1775 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001776 out_rtnl:
1777 rtnl_unlock();
1778
Johannes Berg5727ef12007-12-19 02:03:34 +01001779 return err;
1780}
1781
1782static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
1783{
1784 struct cfg80211_registered_device *drv;
1785 int err;
1786 struct net_device *dev;
1787 u8 *mac_addr = NULL;
1788
1789 if (info->attrs[NL80211_ATTR_MAC])
1790 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
1791
Johannes Berg3b858752009-03-12 09:55:09 +01001792 rtnl_lock();
1793
Johannes Bergbba95fe2008-07-29 13:22:51 +02001794 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Johannes Berg5727ef12007-12-19 02:03:34 +01001795 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001796 goto out_rtnl;
Johannes Berg5727ef12007-12-19 02:03:34 +01001797
Johannes Berge80cf852009-05-11 14:43:13 +02001798 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
1799 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN) {
1800 err = -EINVAL;
1801 goto out;
1802 }
1803
Johannes Berg5727ef12007-12-19 02:03:34 +01001804 if (!drv->ops->del_station) {
1805 err = -EOPNOTSUPP;
1806 goto out;
1807 }
1808
Johannes Berg5727ef12007-12-19 02:03:34 +01001809 err = drv->ops->del_station(&drv->wiphy, dev, mac_addr);
Johannes Berg5727ef12007-12-19 02:03:34 +01001810
1811 out:
1812 cfg80211_put_dev(drv);
1813 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001814 out_rtnl:
1815 rtnl_unlock();
1816
Johannes Berg5727ef12007-12-19 02:03:34 +01001817 return err;
1818}
1819
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001820static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq,
1821 int flags, struct net_device *dev,
1822 u8 *dst, u8 *next_hop,
1823 struct mpath_info *pinfo)
1824{
1825 void *hdr;
1826 struct nlattr *pinfoattr;
1827
1828 hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION);
1829 if (!hdr)
1830 return -1;
1831
1832 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
1833 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst);
1834 NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop);
1835
1836 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
1837 if (!pinfoattr)
1838 goto nla_put_failure;
1839 if (pinfo->filled & MPATH_INFO_FRAME_QLEN)
1840 NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
1841 pinfo->frame_qlen);
1842 if (pinfo->filled & MPATH_INFO_DSN)
1843 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN,
1844 pinfo->dsn);
1845 if (pinfo->filled & MPATH_INFO_METRIC)
1846 NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC,
1847 pinfo->metric);
1848 if (pinfo->filled & MPATH_INFO_EXPTIME)
1849 NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME,
1850 pinfo->exptime);
1851 if (pinfo->filled & MPATH_INFO_FLAGS)
1852 NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS,
1853 pinfo->flags);
1854 if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT)
1855 NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
1856 pinfo->discovery_timeout);
1857 if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES)
1858 NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
1859 pinfo->discovery_retries);
1860
1861 nla_nest_end(msg, pinfoattr);
1862
1863 return genlmsg_end(msg, hdr);
1864
1865 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001866 genlmsg_cancel(msg, hdr);
1867 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001868}
1869
1870static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02001871 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001872{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001873 struct mpath_info pinfo;
1874 struct cfg80211_registered_device *dev;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001875 struct net_device *netdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001876 u8 dst[ETH_ALEN];
1877 u8 next_hop[ETH_ALEN];
Johannes Bergbba95fe2008-07-29 13:22:51 +02001878 int ifidx = cb->args[0];
1879 int path_idx = cb->args[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001880 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001881
Johannes Bergbba95fe2008-07-29 13:22:51 +02001882 if (!ifidx) {
1883 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1884 nl80211_fam.attrbuf, nl80211_fam.maxattr,
1885 nl80211_policy);
1886 if (err)
1887 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001888
Johannes Bergbba95fe2008-07-29 13:22:51 +02001889 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
1890 return -EINVAL;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001891
Johannes Bergbba95fe2008-07-29 13:22:51 +02001892 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
1893 if (!ifidx)
1894 return -EINVAL;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001895 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001896
Johannes Berg3b858752009-03-12 09:55:09 +01001897 rtnl_lock();
1898
1899 netdev = __dev_get_by_index(&init_net, ifidx);
1900 if (!netdev) {
1901 err = -ENODEV;
1902 goto out_rtnl;
1903 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001904
Johannes Bergbba95fe2008-07-29 13:22:51 +02001905 dev = cfg80211_get_dev_from_ifindex(ifidx);
1906 if (IS_ERR(dev)) {
1907 err = PTR_ERR(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001908 goto out_rtnl;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001909 }
1910
1911 if (!dev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02001912 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001913 goto out_err;
1914 }
1915
Jouni Malineneec60b02009-03-20 21:21:19 +02001916 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1917 err = -EOPNOTSUPP;
1918 goto out;
1919 }
1920
Johannes Bergbba95fe2008-07-29 13:22:51 +02001921 while (1) {
1922 err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx,
1923 dst, next_hop, &pinfo);
1924 if (err == -ENOENT)
1925 break;
1926 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001927 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001928
1929 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid,
1930 cb->nlh->nlmsg_seq, NLM_F_MULTI,
1931 netdev, dst, next_hop,
1932 &pinfo) < 0)
1933 goto out;
1934
1935 path_idx++;
1936 }
1937
1938
1939 out:
1940 cb->args[1] = path_idx;
1941 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02001942 out_err:
1943 cfg80211_put_dev(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01001944 out_rtnl:
1945 rtnl_unlock();
Johannes Bergbba95fe2008-07-29 13:22:51 +02001946
1947 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001948}
1949
1950static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
1951{
1952 struct cfg80211_registered_device *drv;
1953 int err;
1954 struct net_device *dev;
1955 struct mpath_info pinfo;
1956 struct sk_buff *msg;
1957 u8 *dst = NULL;
1958 u8 next_hop[ETH_ALEN];
1959
1960 memset(&pinfo, 0, sizeof(pinfo));
1961
1962 if (!info->attrs[NL80211_ATTR_MAC])
1963 return -EINVAL;
1964
1965 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
1966
Johannes Berg3b858752009-03-12 09:55:09 +01001967 rtnl_lock();
1968
Johannes Bergbba95fe2008-07-29 13:22:51 +02001969 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001970 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01001971 goto out_rtnl;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001972
1973 if (!drv->ops->get_mpath) {
1974 err = -EOPNOTSUPP;
1975 goto out;
1976 }
1977
Jouni Malineneec60b02009-03-20 21:21:19 +02001978 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
1979 err = -EOPNOTSUPP;
1980 goto out;
1981 }
1982
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001983 err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01001984 if (err)
1985 goto out;
1986
1987 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
1988 if (!msg)
1989 goto out;
1990
1991 if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0,
1992 dev, dst, next_hop, &pinfo) < 0)
1993 goto out_free;
1994
1995 err = genlmsg_unicast(msg, info->snd_pid);
1996 goto out;
1997
1998 out_free:
1999 nlmsg_free(msg);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002000 out:
2001 cfg80211_put_dev(drv);
2002 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01002003 out_rtnl:
2004 rtnl_unlock();
2005
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002006 return err;
2007}
2008
2009static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
2010{
2011 struct cfg80211_registered_device *drv;
2012 int err;
2013 struct net_device *dev;
2014 u8 *dst = NULL;
2015 u8 *next_hop = NULL;
2016
2017 if (!info->attrs[NL80211_ATTR_MAC])
2018 return -EINVAL;
2019
2020 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2021 return -EINVAL;
2022
2023 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2024 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2025
Johannes Berg3b858752009-03-12 09:55:09 +01002026 rtnl_lock();
2027
Johannes Bergbba95fe2008-07-29 13:22:51 +02002028 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002029 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002030 goto out_rtnl;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002031
2032 if (!drv->ops->change_mpath) {
2033 err = -EOPNOTSUPP;
2034 goto out;
2035 }
2036
Jouni Malineneec60b02009-03-20 21:21:19 +02002037 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2038 err = -EOPNOTSUPP;
2039 goto out;
2040 }
2041
Jouni Malinen35a8efe2009-03-20 21:21:18 +02002042 if (!netif_running(dev)) {
2043 err = -ENETDOWN;
2044 goto out;
2045 }
2046
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002047 err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002048
2049 out:
2050 cfg80211_put_dev(drv);
2051 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01002052 out_rtnl:
2053 rtnl_unlock();
2054
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002055 return err;
2056}
2057static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
2058{
2059 struct cfg80211_registered_device *drv;
2060 int err;
2061 struct net_device *dev;
2062 u8 *dst = NULL;
2063 u8 *next_hop = NULL;
2064
2065 if (!info->attrs[NL80211_ATTR_MAC])
2066 return -EINVAL;
2067
2068 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
2069 return -EINVAL;
2070
2071 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2072 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
2073
Johannes Berg3b858752009-03-12 09:55:09 +01002074 rtnl_lock();
2075
Johannes Bergbba95fe2008-07-29 13:22:51 +02002076 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002077 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002078 goto out_rtnl;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002079
2080 if (!drv->ops->add_mpath) {
2081 err = -EOPNOTSUPP;
2082 goto out;
2083 }
2084
Jouni Malineneec60b02009-03-20 21:21:19 +02002085 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) {
2086 err = -EOPNOTSUPP;
2087 goto out;
2088 }
2089
Jouni Malinen35a8efe2009-03-20 21:21:18 +02002090 if (!netif_running(dev)) {
2091 err = -ENETDOWN;
2092 goto out;
2093 }
2094
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002095 err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002096
2097 out:
2098 cfg80211_put_dev(drv);
2099 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01002100 out_rtnl:
2101 rtnl_unlock();
2102
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002103 return err;
2104}
2105
2106static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
2107{
2108 struct cfg80211_registered_device *drv;
2109 int err;
2110 struct net_device *dev;
2111 u8 *dst = NULL;
2112
2113 if (info->attrs[NL80211_ATTR_MAC])
2114 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
2115
Johannes Berg3b858752009-03-12 09:55:09 +01002116 rtnl_lock();
2117
Johannes Bergbba95fe2008-07-29 13:22:51 +02002118 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002119 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002120 goto out_rtnl;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002121
2122 if (!drv->ops->del_mpath) {
2123 err = -EOPNOTSUPP;
2124 goto out;
2125 }
2126
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002127 err = drv->ops->del_mpath(&drv->wiphy, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002128
2129 out:
2130 cfg80211_put_dev(drv);
2131 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01002132 out_rtnl:
2133 rtnl_unlock();
2134
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002135 return err;
2136}
2137
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002138static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
2139{
2140 struct cfg80211_registered_device *drv;
2141 int err;
2142 struct net_device *dev;
2143 struct bss_parameters params;
2144
2145 memset(&params, 0, sizeof(params));
2146 /* default to not changing parameters */
2147 params.use_cts_prot = -1;
2148 params.use_short_preamble = -1;
2149 params.use_short_slot_time = -1;
2150
2151 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
2152 params.use_cts_prot =
2153 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
2154 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
2155 params.use_short_preamble =
2156 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
2157 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
2158 params.use_short_slot_time =
2159 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002160 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
2161 params.basic_rates =
2162 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2163 params.basic_rates_len =
2164 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
2165 }
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002166
Johannes Berg3b858752009-03-12 09:55:09 +01002167 rtnl_lock();
2168
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002169 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2170 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002171 goto out_rtnl;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002172
2173 if (!drv->ops->change_bss) {
2174 err = -EOPNOTSUPP;
2175 goto out;
2176 }
2177
Jouni Malineneec60b02009-03-20 21:21:19 +02002178 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) {
2179 err = -EOPNOTSUPP;
2180 goto out;
2181 }
2182
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002183 err = drv->ops->change_bss(&drv->wiphy, dev, &params);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002184
2185 out:
2186 cfg80211_put_dev(drv);
2187 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01002188 out_rtnl:
2189 rtnl_unlock();
2190
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002191 return err;
2192}
2193
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002194static const struct nla_policy
2195 reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
2196 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
2197 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
2198 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
2199 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
2200 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
2201 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
2202};
2203
2204static int parse_reg_rule(struct nlattr *tb[],
2205 struct ieee80211_reg_rule *reg_rule)
2206{
2207 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
2208 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
2209
2210 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
2211 return -EINVAL;
2212 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
2213 return -EINVAL;
2214 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
2215 return -EINVAL;
2216 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
2217 return -EINVAL;
2218 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
2219 return -EINVAL;
2220
2221 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
2222
2223 freq_range->start_freq_khz =
2224 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
2225 freq_range->end_freq_khz =
2226 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
2227 freq_range->max_bandwidth_khz =
2228 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
2229
2230 power_rule->max_eirp =
2231 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
2232
2233 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
2234 power_rule->max_antenna_gain =
2235 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
2236
2237 return 0;
2238}
2239
2240static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
2241{
2242 int r;
2243 char *data = NULL;
2244
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002245 /*
2246 * You should only get this when cfg80211 hasn't yet initialized
2247 * completely when built-in to the kernel right between the time
2248 * window between nl80211_init() and regulatory_init(), if that is
2249 * even possible.
2250 */
2251 mutex_lock(&cfg80211_mutex);
2252 if (unlikely(!cfg80211_regdomain)) {
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002253 mutex_unlock(&cfg80211_mutex);
2254 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002255 }
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002256 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05002257
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002258 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2259 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002260
2261 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2262
2263#ifdef CONFIG_WIRELESS_OLD_REGULATORY
2264 /* We ignore world regdom requests with the old regdom setup */
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002265 if (is_world_regdom(data))
2266 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002267#endif
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05002268
2269 r = regulatory_hint_user(data);
2270
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002271 return r;
2272}
2273
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002274static int nl80211_get_mesh_params(struct sk_buff *skb,
2275 struct genl_info *info)
2276{
2277 struct cfg80211_registered_device *drv;
2278 struct mesh_config cur_params;
2279 int err;
2280 struct net_device *dev;
2281 void *hdr;
2282 struct nlattr *pinfoattr;
2283 struct sk_buff *msg;
2284
Johannes Berg3b858752009-03-12 09:55:09 +01002285 rtnl_lock();
2286
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002287 /* Look up our device */
2288 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2289 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002290 goto out_rtnl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002291
Jouni Malinenf3f92582009-03-20 17:57:36 +02002292 if (!drv->ops->get_mesh_params) {
2293 err = -EOPNOTSUPP;
2294 goto out;
2295 }
2296
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002297 /* Get the mesh params */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002298 err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002299 if (err)
2300 goto out;
2301
2302 /* Draw up a netlink message to send back */
2303 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2304 if (!msg) {
2305 err = -ENOBUFS;
2306 goto out;
2307 }
2308 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2309 NL80211_CMD_GET_MESH_PARAMS);
2310 if (!hdr)
2311 goto nla_put_failure;
2312 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS);
2313 if (!pinfoattr)
2314 goto nla_put_failure;
2315 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2316 NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
2317 cur_params.dot11MeshRetryTimeout);
2318 NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
2319 cur_params.dot11MeshConfirmTimeout);
2320 NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
2321 cur_params.dot11MeshHoldingTimeout);
2322 NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
2323 cur_params.dot11MeshMaxPeerLinks);
2324 NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES,
2325 cur_params.dot11MeshMaxRetries);
2326 NLA_PUT_U8(msg, NL80211_MESHCONF_TTL,
2327 cur_params.dot11MeshTTL);
2328 NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
2329 cur_params.auto_open_plinks);
2330 NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2331 cur_params.dot11MeshHWMPmaxPREQretries);
2332 NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
2333 cur_params.path_refresh_time);
2334 NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2335 cur_params.min_discovery_timeout);
2336 NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2337 cur_params.dot11MeshHWMPactivePathTimeout);
2338 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2339 cur_params.dot11MeshHWMPpreqMinInterval);
2340 NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2341 cur_params.dot11MeshHWMPnetDiameterTraversalTime);
2342 nla_nest_end(msg, pinfoattr);
2343 genlmsg_end(msg, hdr);
2344 err = genlmsg_unicast(msg, info->snd_pid);
2345 goto out;
2346
Johannes Berg3b858752009-03-12 09:55:09 +01002347 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002348 genlmsg_cancel(msg, hdr);
2349 err = -EMSGSIZE;
Johannes Berg3b858752009-03-12 09:55:09 +01002350 out:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002351 /* Cleanup */
2352 cfg80211_put_dev(drv);
2353 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01002354 out_rtnl:
2355 rtnl_unlock();
2356
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002357 return err;
2358}
2359
2360#define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \
2361do {\
2362 if (table[attr_num]) {\
2363 cfg.param = nla_fn(table[attr_num]); \
2364 mask |= (1 << (attr_num - 1)); \
2365 } \
2366} while (0);\
2367
2368static struct nla_policy
2369nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = {
2370 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
2371 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
2372 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
2373 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
2374 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
2375 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
2376 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
2377
2378 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
2379 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
2380 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
2381 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
2382 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
2383 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
2384};
2385
2386static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info)
2387{
2388 int err;
2389 u32 mask;
2390 struct cfg80211_registered_device *drv;
2391 struct net_device *dev;
2392 struct mesh_config cfg;
2393 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
2394 struct nlattr *parent_attr;
2395
2396 parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS];
2397 if (!parent_attr)
2398 return -EINVAL;
2399 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
2400 parent_attr, nl80211_meshconf_params_policy))
2401 return -EINVAL;
2402
Johannes Berg3b858752009-03-12 09:55:09 +01002403 rtnl_lock();
2404
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002405 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2406 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002407 goto out_rtnl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002408
Jouni Malinenf3f92582009-03-20 17:57:36 +02002409 if (!drv->ops->set_mesh_params) {
2410 err = -EOPNOTSUPP;
2411 goto out;
2412 }
2413
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002414 /* This makes sure that there aren't more than 32 mesh config
2415 * parameters (otherwise our bitfield scheme would not work.) */
2416 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
2417
2418 /* Fill in the params struct */
2419 mask = 0;
2420 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout,
2421 mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16);
2422 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout,
2423 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16);
2424 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout,
2425 mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16);
2426 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks,
2427 mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16);
2428 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries,
2429 mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8);
2430 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL,
2431 mask, NL80211_MESHCONF_TTL, nla_get_u8);
2432 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks,
2433 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8);
2434 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries,
2435 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
2436 nla_get_u8);
2437 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time,
2438 mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32);
2439 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout,
2440 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
2441 nla_get_u16);
2442 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
2443 mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
2444 nla_get_u32);
2445 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
2446 mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
2447 nla_get_u16);
2448 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
2449 dot11MeshHWMPnetDiameterTraversalTime,
2450 mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
2451 nla_get_u16);
2452
2453 /* Apply changes */
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002454 err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002455
Jouni Malinenf3f92582009-03-20 17:57:36 +02002456 out:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002457 /* cleanup */
2458 cfg80211_put_dev(drv);
2459 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01002460 out_rtnl:
2461 rtnl_unlock();
2462
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07002463 return err;
2464}
2465
2466#undef FILL_IN_MESH_PARAM_IF_SET
2467
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002468static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
2469{
2470 struct sk_buff *msg;
2471 void *hdr = NULL;
2472 struct nlattr *nl_reg_rules;
2473 unsigned int i;
2474 int err = -EINVAL;
2475
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002476 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002477
2478 if (!cfg80211_regdomain)
2479 goto out;
2480
2481 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
2482 if (!msg) {
2483 err = -ENOBUFS;
2484 goto out;
2485 }
2486
2487 hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0,
2488 NL80211_CMD_GET_REG);
2489 if (!hdr)
2490 goto nla_put_failure;
2491
2492 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2,
2493 cfg80211_regdomain->alpha2);
2494
2495 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
2496 if (!nl_reg_rules)
2497 goto nla_put_failure;
2498
2499 for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) {
2500 struct nlattr *nl_reg_rule;
2501 const struct ieee80211_reg_rule *reg_rule;
2502 const struct ieee80211_freq_range *freq_range;
2503 const struct ieee80211_power_rule *power_rule;
2504
2505 reg_rule = &cfg80211_regdomain->reg_rules[i];
2506 freq_range = &reg_rule->freq_range;
2507 power_rule = &reg_rule->power_rule;
2508
2509 nl_reg_rule = nla_nest_start(msg, i);
2510 if (!nl_reg_rule)
2511 goto nla_put_failure;
2512
2513 NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS,
2514 reg_rule->flags);
2515 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START,
2516 freq_range->start_freq_khz);
2517 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END,
2518 freq_range->end_freq_khz);
2519 NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
2520 freq_range->max_bandwidth_khz);
2521 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
2522 power_rule->max_antenna_gain);
2523 NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
2524 power_rule->max_eirp);
2525
2526 nla_nest_end(msg, nl_reg_rule);
2527 }
2528
2529 nla_nest_end(msg, nl_reg_rules);
2530
2531 genlmsg_end(msg, hdr);
2532 err = genlmsg_unicast(msg, info->snd_pid);
2533 goto out;
2534
2535nla_put_failure:
2536 genlmsg_cancel(msg, hdr);
2537 err = -EMSGSIZE;
2538out:
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002539 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08002540 return err;
2541}
2542
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002543static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
2544{
2545 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
2546 struct nlattr *nl_reg_rule;
2547 char *alpha2 = NULL;
2548 int rem_reg_rules = 0, r = 0;
2549 u32 num_rules = 0, rule_idx = 0, size_of_regd;
2550 struct ieee80211_regdomain *rd = NULL;
2551
2552 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
2553 return -EINVAL;
2554
2555 if (!info->attrs[NL80211_ATTR_REG_RULES])
2556 return -EINVAL;
2557
2558 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
2559
2560 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2561 rem_reg_rules) {
2562 num_rules++;
2563 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
2564 goto bad_reg;
2565 }
2566
2567 if (!reg_is_valid_request(alpha2))
2568 return -EINVAL;
2569
2570 size_of_regd = sizeof(struct ieee80211_regdomain) +
2571 (num_rules * sizeof(struct ieee80211_reg_rule));
2572
2573 rd = kzalloc(size_of_regd, GFP_KERNEL);
2574 if (!rd)
2575 return -ENOMEM;
2576
2577 rd->n_reg_rules = num_rules;
2578 rd->alpha2[0] = alpha2[0];
2579 rd->alpha2[1] = alpha2[1];
2580
2581 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
2582 rem_reg_rules) {
2583 nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
2584 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
2585 reg_rule_policy);
2586 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
2587 if (r)
2588 goto bad_reg;
2589
2590 rule_idx++;
2591
2592 if (rule_idx > NL80211_MAX_SUPP_REG_RULES)
2593 goto bad_reg;
2594 }
2595
2596 BUG_ON(rule_idx != num_rules);
2597
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002598 mutex_lock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002599 r = set_regdom(rd);
Luis R. Rodrigueza1794392009-02-21 00:04:21 -05002600 mutex_unlock(&cfg80211_mutex);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002601 return r;
2602
Johannes Bergd2372b32008-10-24 20:32:20 +02002603 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07002604 kfree(rd);
2605 return -EINVAL;
2606}
2607
Johannes Berg2a519312009-02-10 21:25:55 +01002608static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
2609{
2610 struct cfg80211_registered_device *drv;
2611 struct net_device *dev;
2612 struct cfg80211_scan_request *request;
2613 struct cfg80211_ssid *ssid;
2614 struct ieee80211_channel *channel;
2615 struct nlattr *attr;
2616 struct wiphy *wiphy;
2617 int err, tmp, n_ssids = 0, n_channels = 0, i;
2618 enum ieee80211_band band;
Jouni Malinen70692ad2009-02-16 19:39:13 +02002619 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01002620
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002621 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2622 return -EINVAL;
2623
Johannes Berg3b858752009-03-12 09:55:09 +01002624 rtnl_lock();
2625
Johannes Berg2a519312009-02-10 21:25:55 +01002626 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2627 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01002628 goto out_rtnl;
Johannes Berg2a519312009-02-10 21:25:55 +01002629
2630 wiphy = &drv->wiphy;
2631
2632 if (!drv->ops->scan) {
2633 err = -EOPNOTSUPP;
2634 goto out;
2635 }
2636
Jouni Malinen35a8efe2009-03-20 21:21:18 +02002637 if (!netif_running(dev)) {
2638 err = -ENETDOWN;
2639 goto out;
2640 }
2641
Johannes Berg2a519312009-02-10 21:25:55 +01002642 if (drv->scan_req) {
2643 err = -EBUSY;
Johannes Berg3b858752009-03-12 09:55:09 +01002644 goto out;
Johannes Berg2a519312009-02-10 21:25:55 +01002645 }
2646
2647 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2648 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp)
2649 n_channels++;
2650 if (!n_channels) {
2651 err = -EINVAL;
Johannes Berg3b858752009-03-12 09:55:09 +01002652 goto out;
Johannes Berg2a519312009-02-10 21:25:55 +01002653 }
2654 } else {
2655 for (band = 0; band < IEEE80211_NUM_BANDS; band++)
2656 if (wiphy->bands[band])
2657 n_channels += wiphy->bands[band]->n_channels;
2658 }
2659
2660 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
2661 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
2662 n_ssids++;
2663
2664 if (n_ssids > wiphy->max_scan_ssids) {
2665 err = -EINVAL;
Johannes Berg3b858752009-03-12 09:55:09 +01002666 goto out;
Johannes Berg2a519312009-02-10 21:25:55 +01002667 }
2668
Jouni Malinen70692ad2009-02-16 19:39:13 +02002669 if (info->attrs[NL80211_ATTR_IE])
2670 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2671 else
2672 ie_len = 0;
2673
Johannes Berg18a83652009-03-31 12:12:05 +02002674 if (ie_len > wiphy->max_scan_ie_len) {
2675 err = -EINVAL;
2676 goto out;
2677 }
2678
Johannes Berg2a519312009-02-10 21:25:55 +01002679 request = kzalloc(sizeof(*request)
2680 + sizeof(*ssid) * n_ssids
Jouni Malinen70692ad2009-02-16 19:39:13 +02002681 + sizeof(channel) * n_channels
2682 + ie_len, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +01002683 if (!request) {
2684 err = -ENOMEM;
Johannes Berg3b858752009-03-12 09:55:09 +01002685 goto out;
Johannes Berg2a519312009-02-10 21:25:55 +01002686 }
2687
2688 request->channels = (void *)((char *)request + sizeof(*request));
2689 request->n_channels = n_channels;
2690 if (n_ssids)
2691 request->ssids = (void *)(request->channels + n_channels);
2692 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02002693 if (ie_len) {
2694 if (request->ssids)
2695 request->ie = (void *)(request->ssids + n_ssids);
2696 else
2697 request->ie = (void *)(request->channels + n_channels);
2698 }
Johannes Berg2a519312009-02-10 21:25:55 +01002699
2700 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
2701 /* user specified, bail out if channel not found */
2702 request->n_channels = n_channels;
2703 i = 0;
2704 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
2705 request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr));
2706 if (!request->channels[i]) {
2707 err = -EINVAL;
2708 goto out_free;
2709 }
2710 i++;
2711 }
2712 } else {
2713 /* all channels */
2714 i = 0;
2715 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
2716 int j;
2717 if (!wiphy->bands[band])
2718 continue;
2719 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
2720 request->channels[i] = &wiphy->bands[band]->channels[j];
2721 i++;
2722 }
2723 }
2724 }
2725
2726 i = 0;
2727 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
2728 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
2729 if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) {
2730 err = -EINVAL;
2731 goto out_free;
2732 }
2733 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
2734 request->ssids[i].ssid_len = nla_len(attr);
2735 i++;
2736 }
2737 }
2738
Jouni Malinen70692ad2009-02-16 19:39:13 +02002739 if (info->attrs[NL80211_ATTR_IE]) {
2740 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02002741 memcpy((void *)request->ie,
2742 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02002743 request->ie_len);
2744 }
2745
Johannes Berg2a519312009-02-10 21:25:55 +01002746 request->ifidx = dev->ifindex;
2747 request->wiphy = &drv->wiphy;
2748
2749 drv->scan_req = request;
2750 err = drv->ops->scan(&drv->wiphy, dev, request);
2751
2752 out_free:
2753 if (err) {
2754 drv->scan_req = NULL;
2755 kfree(request);
2756 }
Johannes Berg2a519312009-02-10 21:25:55 +01002757 out:
2758 cfg80211_put_dev(drv);
2759 dev_put(dev);
Johannes Berg3b858752009-03-12 09:55:09 +01002760 out_rtnl:
2761 rtnl_unlock();
2762
Johannes Berg2a519312009-02-10 21:25:55 +01002763 return err;
2764}
2765
2766static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags,
2767 struct cfg80211_registered_device *rdev,
2768 struct net_device *dev,
2769 struct cfg80211_bss *res)
2770{
2771 void *hdr;
2772 struct nlattr *bss;
2773
2774 hdr = nl80211hdr_put(msg, pid, seq, flags,
2775 NL80211_CMD_NEW_SCAN_RESULTS);
2776 if (!hdr)
2777 return -1;
2778
2779 NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION,
2780 rdev->bss_generation);
2781 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex);
2782
2783 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
2784 if (!bss)
2785 goto nla_put_failure;
2786 if (!is_zero_ether_addr(res->bssid))
2787 NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid);
2788 if (res->information_elements && res->len_information_elements)
2789 NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS,
2790 res->len_information_elements,
2791 res->information_elements);
2792 if (res->tsf)
2793 NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf);
2794 if (res->beacon_interval)
2795 NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval);
2796 NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability);
2797 NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq);
2798
Johannes Berg77965c92009-02-18 18:45:06 +01002799 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01002800 case CFG80211_SIGNAL_TYPE_MBM:
2801 NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal);
2802 break;
2803 case CFG80211_SIGNAL_TYPE_UNSPEC:
2804 NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal);
2805 break;
2806 default:
2807 break;
2808 }
2809
2810 nla_nest_end(msg, bss);
2811
2812 return genlmsg_end(msg, hdr);
2813
2814 nla_put_failure:
2815 genlmsg_cancel(msg, hdr);
2816 return -EMSGSIZE;
2817}
2818
2819static int nl80211_dump_scan(struct sk_buff *skb,
2820 struct netlink_callback *cb)
2821{
2822 struct cfg80211_registered_device *dev;
2823 struct net_device *netdev;
2824 struct cfg80211_internal_bss *scan;
2825 int ifidx = cb->args[0];
2826 int start = cb->args[1], idx = 0;
2827 int err;
2828
2829 if (!ifidx) {
2830 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
2831 nl80211_fam.attrbuf, nl80211_fam.maxattr,
2832 nl80211_policy);
2833 if (err)
2834 return err;
2835
2836 if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX])
2837 return -EINVAL;
2838
2839 ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]);
2840 if (!ifidx)
2841 return -EINVAL;
2842 cb->args[0] = ifidx;
2843 }
2844
2845 netdev = dev_get_by_index(&init_net, ifidx);
2846 if (!netdev)
2847 return -ENODEV;
2848
2849 dev = cfg80211_get_dev_from_ifindex(ifidx);
2850 if (IS_ERR(dev)) {
2851 err = PTR_ERR(dev);
2852 goto out_put_netdev;
2853 }
2854
2855 spin_lock_bh(&dev->bss_lock);
2856 cfg80211_bss_expire(dev);
2857
2858 list_for_each_entry(scan, &dev->bss_list, list) {
2859 if (++idx <= start)
2860 continue;
2861 if (nl80211_send_bss(skb,
2862 NETLINK_CB(cb->skb).pid,
2863 cb->nlh->nlmsg_seq, NLM_F_MULTI,
2864 dev, netdev, &scan->pub) < 0) {
2865 idx--;
2866 goto out;
2867 }
2868 }
2869
2870 out:
2871 spin_unlock_bh(&dev->bss_lock);
2872
2873 cb->args[1] = idx;
2874 err = skb->len;
2875 cfg80211_put_dev(dev);
2876 out_put_netdev:
2877 dev_put(netdev);
2878
2879 return err;
2880}
2881
Jouni Malinen255e7372009-03-20 21:21:17 +02002882static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type)
2883{
2884 return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM ||
2885 auth_type == NL80211_AUTHTYPE_SHARED_KEY ||
2886 auth_type == NL80211_AUTHTYPE_FT ||
2887 auth_type == NL80211_AUTHTYPE_NETWORK_EAP;
2888}
2889
Jouni Malinen636a5d32009-03-19 13:39:22 +02002890static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
2891{
2892 struct cfg80211_registered_device *drv;
2893 struct net_device *dev;
2894 struct cfg80211_auth_request req;
2895 struct wiphy *wiphy;
2896 int err;
2897
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002898 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2899 return -EINVAL;
2900
2901 if (!info->attrs[NL80211_ATTR_MAC])
2902 return -EINVAL;
2903
Jouni Malinen17780922009-03-27 20:52:47 +02002904 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
2905 return -EINVAL;
2906
Jouni Malinen636a5d32009-03-19 13:39:22 +02002907 rtnl_lock();
2908
2909 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2910 if (err)
2911 goto unlock_rtnl;
2912
2913 if (!drv->ops->auth) {
2914 err = -EOPNOTSUPP;
2915 goto out;
2916 }
2917
Jouni Malineneec60b02009-03-20 21:21:19 +02002918 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2919 err = -EOPNOTSUPP;
2920 goto out;
2921 }
2922
Jouni Malinen35a8efe2009-03-20 21:21:18 +02002923 if (!netif_running(dev)) {
2924 err = -ENETDOWN;
2925 goto out;
2926 }
2927
Jouni Malinen636a5d32009-03-19 13:39:22 +02002928 wiphy = &drv->wiphy;
2929 memset(&req, 0, sizeof(req));
2930
2931 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2932
2933 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
2934 req.chan = ieee80211_get_channel(
2935 wiphy,
2936 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
2937 if (!req.chan) {
2938 err = -EINVAL;
2939 goto out;
2940 }
2941 }
2942
2943 if (info->attrs[NL80211_ATTR_SSID]) {
2944 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
2945 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
2946 }
2947
2948 if (info->attrs[NL80211_ATTR_IE]) {
2949 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
2950 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
2951 }
2952
Jouni Malinen17780922009-03-27 20:52:47 +02002953 req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
2954 if (!nl80211_valid_auth_type(req.auth_type)) {
2955 err = -EINVAL;
2956 goto out;
Jouni Malinen636a5d32009-03-19 13:39:22 +02002957 }
2958
2959 err = drv->ops->auth(&drv->wiphy, dev, &req);
2960
2961out:
2962 cfg80211_put_dev(drv);
2963 dev_put(dev);
2964unlock_rtnl:
2965 rtnl_unlock();
2966 return err;
2967}
2968
2969static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
2970{
2971 struct cfg80211_registered_device *drv;
2972 struct net_device *dev;
2973 struct cfg80211_assoc_request req;
2974 struct wiphy *wiphy;
2975 int err;
2976
Johannes Bergf4a11bb2009-03-27 12:40:28 +01002977 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
2978 return -EINVAL;
2979
2980 if (!info->attrs[NL80211_ATTR_MAC] ||
2981 !info->attrs[NL80211_ATTR_SSID])
2982 return -EINVAL;
2983
Jouni Malinen636a5d32009-03-19 13:39:22 +02002984 rtnl_lock();
2985
2986 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
2987 if (err)
2988 goto unlock_rtnl;
2989
2990 if (!drv->ops->assoc) {
2991 err = -EOPNOTSUPP;
2992 goto out;
2993 }
2994
Jouni Malineneec60b02009-03-20 21:21:19 +02002995 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
2996 err = -EOPNOTSUPP;
2997 goto out;
2998 }
2999
Jouni Malinen35a8efe2009-03-20 21:21:18 +02003000 if (!netif_running(dev)) {
3001 err = -ENETDOWN;
3002 goto out;
3003 }
3004
Jouni Malinen636a5d32009-03-19 13:39:22 +02003005 wiphy = &drv->wiphy;
3006 memset(&req, 0, sizeof(req));
3007
3008 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3009
3010 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
3011 req.chan = ieee80211_get_channel(
3012 wiphy,
3013 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3014 if (!req.chan) {
3015 err = -EINVAL;
3016 goto out;
3017 }
3018 }
3019
Jouni Malinen636a5d32009-03-19 13:39:22 +02003020 req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3021 req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3022
3023 if (info->attrs[NL80211_ATTR_IE]) {
3024 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3025 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3026 }
3027
Jouni Malinendc6382ce2009-05-06 22:09:37 +03003028 if (info->attrs[NL80211_ATTR_USE_MFP]) {
3029 enum nl80211_mfp use_mfp =
3030 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
3031 if (use_mfp == NL80211_MFP_REQUIRED)
3032 req.use_mfp = true;
3033 else if (use_mfp != NL80211_MFP_NO) {
3034 err = -EINVAL;
3035 goto out;
3036 }
3037 }
3038
Jouni Malinen636a5d32009-03-19 13:39:22 +02003039 err = drv->ops->assoc(&drv->wiphy, dev, &req);
3040
3041out:
3042 cfg80211_put_dev(drv);
3043 dev_put(dev);
3044unlock_rtnl:
3045 rtnl_unlock();
3046 return err;
3047}
3048
3049static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
3050{
3051 struct cfg80211_registered_device *drv;
3052 struct net_device *dev;
3053 struct cfg80211_deauth_request req;
3054 struct wiphy *wiphy;
3055 int err;
3056
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003057 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3058 return -EINVAL;
3059
3060 if (!info->attrs[NL80211_ATTR_MAC])
3061 return -EINVAL;
3062
3063 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3064 return -EINVAL;
3065
Jouni Malinen636a5d32009-03-19 13:39:22 +02003066 rtnl_lock();
3067
3068 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3069 if (err)
3070 goto unlock_rtnl;
3071
3072 if (!drv->ops->deauth) {
3073 err = -EOPNOTSUPP;
3074 goto out;
3075 }
3076
Jouni Malineneec60b02009-03-20 21:21:19 +02003077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3078 err = -EOPNOTSUPP;
3079 goto out;
3080 }
3081
Jouni Malinen35a8efe2009-03-20 21:21:18 +02003082 if (!netif_running(dev)) {
3083 err = -ENETDOWN;
3084 goto out;
3085 }
3086
Jouni Malinen636a5d32009-03-19 13:39:22 +02003087 wiphy = &drv->wiphy;
3088 memset(&req, 0, sizeof(req));
3089
3090 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3091
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003092 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3093 if (req.reason_code == 0) {
3094 /* Reason Code 0 is reserved */
3095 err = -EINVAL;
3096 goto out;
Jouni Malinen255e7372009-03-20 21:21:17 +02003097 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02003098
3099 if (info->attrs[NL80211_ATTR_IE]) {
3100 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3101 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3102 }
3103
3104 err = drv->ops->deauth(&drv->wiphy, dev, &req);
3105
3106out:
3107 cfg80211_put_dev(drv);
3108 dev_put(dev);
3109unlock_rtnl:
3110 rtnl_unlock();
3111 return err;
3112}
3113
3114static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
3115{
3116 struct cfg80211_registered_device *drv;
3117 struct net_device *dev;
3118 struct cfg80211_disassoc_request req;
3119 struct wiphy *wiphy;
3120 int err;
3121
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003122 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3123 return -EINVAL;
3124
3125 if (!info->attrs[NL80211_ATTR_MAC])
3126 return -EINVAL;
3127
3128 if (!info->attrs[NL80211_ATTR_REASON_CODE])
3129 return -EINVAL;
3130
Jouni Malinen636a5d32009-03-19 13:39:22 +02003131 rtnl_lock();
3132
3133 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3134 if (err)
3135 goto unlock_rtnl;
3136
3137 if (!drv->ops->disassoc) {
3138 err = -EOPNOTSUPP;
3139 goto out;
3140 }
3141
Jouni Malineneec60b02009-03-20 21:21:19 +02003142 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) {
3143 err = -EOPNOTSUPP;
3144 goto out;
3145 }
3146
Jouni Malinen35a8efe2009-03-20 21:21:18 +02003147 if (!netif_running(dev)) {
3148 err = -ENETDOWN;
3149 goto out;
3150 }
3151
Jouni Malinen636a5d32009-03-19 13:39:22 +02003152 wiphy = &drv->wiphy;
3153 memset(&req, 0, sizeof(req));
3154
3155 req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3156
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003157 req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
3158 if (req.reason_code == 0) {
3159 /* Reason Code 0 is reserved */
3160 err = -EINVAL;
3161 goto out;
Jouni Malinen255e7372009-03-20 21:21:17 +02003162 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02003163
3164 if (info->attrs[NL80211_ATTR_IE]) {
3165 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3166 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3167 }
3168
3169 err = drv->ops->disassoc(&drv->wiphy, dev, &req);
3170
3171out:
3172 cfg80211_put_dev(drv);
3173 dev_put(dev);
3174unlock_rtnl:
3175 rtnl_unlock();
3176 return err;
3177}
3178
Johannes Berg04a773a2009-04-19 21:24:32 +02003179static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
3180{
3181 struct cfg80211_registered_device *drv;
3182 struct net_device *dev;
3183 struct cfg80211_ibss_params ibss;
3184 struct wiphy *wiphy;
3185 int err;
3186
Johannes Berg8e30bc52009-04-22 17:45:38 +02003187 memset(&ibss, 0, sizeof(ibss));
3188
Johannes Berg04a773a2009-04-19 21:24:32 +02003189 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
3190 return -EINVAL;
3191
3192 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
3193 !info->attrs[NL80211_ATTR_SSID] ||
3194 !nla_len(info->attrs[NL80211_ATTR_SSID]))
3195 return -EINVAL;
3196
Johannes Berg8e30bc52009-04-22 17:45:38 +02003197 ibss.beacon_interval = 100;
3198
3199 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
3200 ibss.beacon_interval =
3201 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3202 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
3203 return -EINVAL;
3204 }
3205
Johannes Berg04a773a2009-04-19 21:24:32 +02003206 rtnl_lock();
3207
3208 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3209 if (err)
3210 goto unlock_rtnl;
3211
3212 if (!drv->ops->join_ibss) {
3213 err = -EOPNOTSUPP;
3214 goto out;
3215 }
3216
3217 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) {
3218 err = -EOPNOTSUPP;
3219 goto out;
3220 }
3221
3222 if (!netif_running(dev)) {
3223 err = -ENETDOWN;
3224 goto out;
3225 }
3226
3227 wiphy = &drv->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02003228
3229 if (info->attrs[NL80211_ATTR_MAC])
3230 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
3231 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3232 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
3233
3234 if (info->attrs[NL80211_ATTR_IE]) {
3235 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
3236 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
3237 }
3238
3239 ibss.channel = ieee80211_get_channel(wiphy,
3240 nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]));
3241 if (!ibss.channel ||
3242 ibss.channel->flags & IEEE80211_CHAN_NO_IBSS ||
3243 ibss.channel->flags & IEEE80211_CHAN_DISABLED) {
3244 err = -EINVAL;
3245 goto out;
3246 }
3247
3248 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
3249
3250 err = cfg80211_join_ibss(drv, dev, &ibss);
3251
3252out:
3253 cfg80211_put_dev(drv);
3254 dev_put(dev);
3255unlock_rtnl:
3256 rtnl_unlock();
3257 return err;
3258}
3259
3260static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
3261{
3262 struct cfg80211_registered_device *drv;
3263 struct net_device *dev;
3264 int err;
3265
3266 rtnl_lock();
3267
3268 err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev);
3269 if (err)
3270 goto unlock_rtnl;
3271
3272 if (!drv->ops->leave_ibss) {
3273 err = -EOPNOTSUPP;
3274 goto out;
3275 }
3276
3277 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) {
3278 err = -EOPNOTSUPP;
3279 goto out;
3280 }
3281
3282 if (!netif_running(dev)) {
3283 err = -ENETDOWN;
3284 goto out;
3285 }
3286
Johannes Berg9d308422009-04-20 18:43:46 +02003287 err = cfg80211_leave_ibss(drv, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02003288
3289out:
3290 cfg80211_put_dev(drv);
3291 dev_put(dev);
3292unlock_rtnl:
3293 rtnl_unlock();
3294 return err;
3295}
3296
Johannes Berg55682962007-09-20 13:09:35 -04003297static struct genl_ops nl80211_ops[] = {
3298 {
3299 .cmd = NL80211_CMD_GET_WIPHY,
3300 .doit = nl80211_get_wiphy,
3301 .dumpit = nl80211_dump_wiphy,
3302 .policy = nl80211_policy,
3303 /* can be retrieved by unprivileged users */
3304 },
3305 {
3306 .cmd = NL80211_CMD_SET_WIPHY,
3307 .doit = nl80211_set_wiphy,
3308 .policy = nl80211_policy,
3309 .flags = GENL_ADMIN_PERM,
3310 },
3311 {
3312 .cmd = NL80211_CMD_GET_INTERFACE,
3313 .doit = nl80211_get_interface,
3314 .dumpit = nl80211_dump_interface,
3315 .policy = nl80211_policy,
3316 /* can be retrieved by unprivileged users */
3317 },
3318 {
3319 .cmd = NL80211_CMD_SET_INTERFACE,
3320 .doit = nl80211_set_interface,
3321 .policy = nl80211_policy,
3322 .flags = GENL_ADMIN_PERM,
3323 },
3324 {
3325 .cmd = NL80211_CMD_NEW_INTERFACE,
3326 .doit = nl80211_new_interface,
3327 .policy = nl80211_policy,
3328 .flags = GENL_ADMIN_PERM,
3329 },
3330 {
3331 .cmd = NL80211_CMD_DEL_INTERFACE,
3332 .doit = nl80211_del_interface,
3333 .policy = nl80211_policy,
3334 .flags = GENL_ADMIN_PERM,
3335 },
Johannes Berg41ade002007-12-19 02:03:29 +01003336 {
3337 .cmd = NL80211_CMD_GET_KEY,
3338 .doit = nl80211_get_key,
3339 .policy = nl80211_policy,
3340 .flags = GENL_ADMIN_PERM,
3341 },
3342 {
3343 .cmd = NL80211_CMD_SET_KEY,
3344 .doit = nl80211_set_key,
3345 .policy = nl80211_policy,
3346 .flags = GENL_ADMIN_PERM,
3347 },
3348 {
3349 .cmd = NL80211_CMD_NEW_KEY,
3350 .doit = nl80211_new_key,
3351 .policy = nl80211_policy,
3352 .flags = GENL_ADMIN_PERM,
3353 },
3354 {
3355 .cmd = NL80211_CMD_DEL_KEY,
3356 .doit = nl80211_del_key,
3357 .policy = nl80211_policy,
3358 .flags = GENL_ADMIN_PERM,
3359 },
Johannes Berged1b6cc2007-12-19 02:03:32 +01003360 {
3361 .cmd = NL80211_CMD_SET_BEACON,
3362 .policy = nl80211_policy,
3363 .flags = GENL_ADMIN_PERM,
3364 .doit = nl80211_addset_beacon,
3365 },
3366 {
3367 .cmd = NL80211_CMD_NEW_BEACON,
3368 .policy = nl80211_policy,
3369 .flags = GENL_ADMIN_PERM,
3370 .doit = nl80211_addset_beacon,
3371 },
3372 {
3373 .cmd = NL80211_CMD_DEL_BEACON,
3374 .policy = nl80211_policy,
3375 .flags = GENL_ADMIN_PERM,
3376 .doit = nl80211_del_beacon,
3377 },
Johannes Berg5727ef12007-12-19 02:03:34 +01003378 {
3379 .cmd = NL80211_CMD_GET_STATION,
3380 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003381 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +01003382 .policy = nl80211_policy,
Johannes Berg5727ef12007-12-19 02:03:34 +01003383 },
3384 {
3385 .cmd = NL80211_CMD_SET_STATION,
3386 .doit = nl80211_set_station,
3387 .policy = nl80211_policy,
3388 .flags = GENL_ADMIN_PERM,
3389 },
3390 {
3391 .cmd = NL80211_CMD_NEW_STATION,
3392 .doit = nl80211_new_station,
3393 .policy = nl80211_policy,
3394 .flags = GENL_ADMIN_PERM,
3395 },
3396 {
3397 .cmd = NL80211_CMD_DEL_STATION,
3398 .doit = nl80211_del_station,
3399 .policy = nl80211_policy,
3400 .flags = GENL_ADMIN_PERM,
3401 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003402 {
3403 .cmd = NL80211_CMD_GET_MPATH,
3404 .doit = nl80211_get_mpath,
3405 .dumpit = nl80211_dump_mpath,
3406 .policy = nl80211_policy,
3407 .flags = GENL_ADMIN_PERM,
3408 },
3409 {
3410 .cmd = NL80211_CMD_SET_MPATH,
3411 .doit = nl80211_set_mpath,
3412 .policy = nl80211_policy,
3413 .flags = GENL_ADMIN_PERM,
3414 },
3415 {
3416 .cmd = NL80211_CMD_NEW_MPATH,
3417 .doit = nl80211_new_mpath,
3418 .policy = nl80211_policy,
3419 .flags = GENL_ADMIN_PERM,
3420 },
3421 {
3422 .cmd = NL80211_CMD_DEL_MPATH,
3423 .doit = nl80211_del_mpath,
3424 .policy = nl80211_policy,
3425 .flags = GENL_ADMIN_PERM,
3426 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003427 {
3428 .cmd = NL80211_CMD_SET_BSS,
3429 .doit = nl80211_set_bss,
3430 .policy = nl80211_policy,
3431 .flags = GENL_ADMIN_PERM,
3432 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003433 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08003434 .cmd = NL80211_CMD_GET_REG,
3435 .doit = nl80211_get_reg,
3436 .policy = nl80211_policy,
3437 /* can be retrieved by unprivileged users */
3438 },
3439 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07003440 .cmd = NL80211_CMD_SET_REG,
3441 .doit = nl80211_set_reg,
3442 .policy = nl80211_policy,
3443 .flags = GENL_ADMIN_PERM,
3444 },
3445 {
3446 .cmd = NL80211_CMD_REQ_SET_REG,
3447 .doit = nl80211_req_set_reg,
3448 .policy = nl80211_policy,
3449 .flags = GENL_ADMIN_PERM,
3450 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07003451 {
3452 .cmd = NL80211_CMD_GET_MESH_PARAMS,
3453 .doit = nl80211_get_mesh_params,
3454 .policy = nl80211_policy,
3455 /* can be retrieved by unprivileged users */
3456 },
3457 {
3458 .cmd = NL80211_CMD_SET_MESH_PARAMS,
3459 .doit = nl80211_set_mesh_params,
3460 .policy = nl80211_policy,
3461 .flags = GENL_ADMIN_PERM,
3462 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +02003463 {
Johannes Berg2a519312009-02-10 21:25:55 +01003464 .cmd = NL80211_CMD_TRIGGER_SCAN,
3465 .doit = nl80211_trigger_scan,
3466 .policy = nl80211_policy,
3467 .flags = GENL_ADMIN_PERM,
3468 },
3469 {
3470 .cmd = NL80211_CMD_GET_SCAN,
3471 .policy = nl80211_policy,
3472 .dumpit = nl80211_dump_scan,
3473 },
Jouni Malinen636a5d32009-03-19 13:39:22 +02003474 {
3475 .cmd = NL80211_CMD_AUTHENTICATE,
3476 .doit = nl80211_authenticate,
3477 .policy = nl80211_policy,
3478 .flags = GENL_ADMIN_PERM,
3479 },
3480 {
3481 .cmd = NL80211_CMD_ASSOCIATE,
3482 .doit = nl80211_associate,
3483 .policy = nl80211_policy,
3484 .flags = GENL_ADMIN_PERM,
3485 },
3486 {
3487 .cmd = NL80211_CMD_DEAUTHENTICATE,
3488 .doit = nl80211_deauthenticate,
3489 .policy = nl80211_policy,
3490 .flags = GENL_ADMIN_PERM,
3491 },
3492 {
3493 .cmd = NL80211_CMD_DISASSOCIATE,
3494 .doit = nl80211_disassociate,
3495 .policy = nl80211_policy,
3496 .flags = GENL_ADMIN_PERM,
3497 },
Johannes Berg04a773a2009-04-19 21:24:32 +02003498 {
3499 .cmd = NL80211_CMD_JOIN_IBSS,
3500 .doit = nl80211_join_ibss,
3501 .policy = nl80211_policy,
3502 .flags = GENL_ADMIN_PERM,
3503 },
3504 {
3505 .cmd = NL80211_CMD_LEAVE_IBSS,
3506 .doit = nl80211_leave_ibss,
3507 .policy = nl80211_policy,
3508 .flags = GENL_ADMIN_PERM,
3509 },
Johannes Berg55682962007-09-20 13:09:35 -04003510};
Jouni Malinen6039f6d2009-03-19 13:39:21 +02003511static struct genl_multicast_group nl80211_mlme_mcgrp = {
3512 .name = "mlme",
3513};
Johannes Berg55682962007-09-20 13:09:35 -04003514
3515/* multicast groups */
3516static struct genl_multicast_group nl80211_config_mcgrp = {
3517 .name = "config",
3518};
Johannes Berg2a519312009-02-10 21:25:55 +01003519static struct genl_multicast_group nl80211_scan_mcgrp = {
3520 .name = "scan",
3521};
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04003522static struct genl_multicast_group nl80211_regulatory_mcgrp = {
3523 .name = "regulatory",
3524};
Johannes Berg55682962007-09-20 13:09:35 -04003525
3526/* notification functions */
3527
3528void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev)
3529{
3530 struct sk_buff *msg;
3531
3532 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3533 if (!msg)
3534 return;
3535
3536 if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) {
3537 nlmsg_free(msg);
3538 return;
3539 }
3540
3541 genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
3542}
3543
Johannes Berg2a519312009-02-10 21:25:55 +01003544static int nl80211_send_scan_donemsg(struct sk_buff *msg,
3545 struct cfg80211_registered_device *rdev,
3546 struct net_device *netdev,
3547 u32 pid, u32 seq, int flags,
3548 u32 cmd)
3549{
3550 void *hdr;
3551
3552 hdr = nl80211hdr_put(msg, pid, seq, flags, cmd);
3553 if (!hdr)
3554 return -1;
3555
Luis R. Rodriguezb5850a72009-02-21 00:04:19 -05003556 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
Johannes Berg2a519312009-02-10 21:25:55 +01003557 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3558
3559 /* XXX: we should probably bounce back the request? */
3560
3561 return genlmsg_end(msg, hdr);
3562
3563 nla_put_failure:
3564 genlmsg_cancel(msg, hdr);
3565 return -EMSGSIZE;
3566}
3567
3568void nl80211_send_scan_done(struct cfg80211_registered_device *rdev,
3569 struct net_device *netdev)
3570{
3571 struct sk_buff *msg;
3572
3573 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3574 if (!msg)
3575 return;
3576
3577 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3578 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
3579 nlmsg_free(msg);
3580 return;
3581 }
3582
3583 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3584}
3585
3586void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev,
3587 struct net_device *netdev)
3588{
3589 struct sk_buff *msg;
3590
3591 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3592 if (!msg)
3593 return;
3594
3595 if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0,
3596 NL80211_CMD_SCAN_ABORTED) < 0) {
3597 nlmsg_free(msg);
3598 return;
3599 }
3600
3601 genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL);
3602}
3603
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04003604/*
3605 * This can happen on global regulatory changes or device specific settings
3606 * based on custom world regulatory domains.
3607 */
3608void nl80211_send_reg_change_event(struct regulatory_request *request)
3609{
3610 struct sk_buff *msg;
3611 void *hdr;
3612
3613 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3614 if (!msg)
3615 return;
3616
3617 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
3618 if (!hdr) {
3619 nlmsg_free(msg);
3620 return;
3621 }
3622
3623 /* Userspace can always count this one always being set */
3624 NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator);
3625
3626 if (request->alpha2[0] == '0' && request->alpha2[1] == '0')
3627 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3628 NL80211_REGDOM_TYPE_WORLD);
3629 else if (request->alpha2[0] == '9' && request->alpha2[1] == '9')
3630 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3631 NL80211_REGDOM_TYPE_CUSTOM_WORLD);
3632 else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
3633 request->intersect)
3634 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3635 NL80211_REGDOM_TYPE_INTERSECTION);
3636 else {
3637 NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE,
3638 NL80211_REGDOM_TYPE_COUNTRY);
3639 NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2);
3640 }
3641
3642 if (wiphy_idx_valid(request->wiphy_idx))
3643 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx);
3644
3645 if (genlmsg_end(msg, hdr) < 0) {
3646 nlmsg_free(msg);
3647 return;
3648 }
3649
3650 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL);
3651
3652 return;
3653
3654nla_put_failure:
3655 genlmsg_cancel(msg, hdr);
3656 nlmsg_free(msg);
3657}
3658
Jouni Malinen6039f6d2009-03-19 13:39:21 +02003659static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
3660 struct net_device *netdev,
3661 const u8 *buf, size_t len,
3662 enum nl80211_commands cmd)
3663{
3664 struct sk_buff *msg;
3665 void *hdr;
3666
Jouni Malinend91c01c2009-04-18 21:53:15 +03003667 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02003668 if (!msg)
3669 return;
3670
3671 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3672 if (!hdr) {
3673 nlmsg_free(msg);
3674 return;
3675 }
3676
3677 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3678 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3679 NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf);
3680
3681 if (genlmsg_end(msg, hdr) < 0) {
3682 nlmsg_free(msg);
3683 return;
3684 }
3685
Jouni Malinend91c01c2009-04-18 21:53:15 +03003686 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC);
Jouni Malinen6039f6d2009-03-19 13:39:21 +02003687 return;
3688
3689 nla_put_failure:
3690 genlmsg_cancel(msg, hdr);
3691 nlmsg_free(msg);
3692}
3693
3694void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
3695 struct net_device *netdev, const u8 *buf, size_t len)
3696{
3697 nl80211_send_mlme_event(rdev, netdev, buf, len,
3698 NL80211_CMD_AUTHENTICATE);
3699}
3700
3701void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
3702 struct net_device *netdev, const u8 *buf,
3703 size_t len)
3704{
3705 nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE);
3706}
3707
Jouni Malinen53b46b82009-03-27 20:53:56 +02003708void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
3709 struct net_device *netdev, const u8 *buf, size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02003710{
3711 nl80211_send_mlme_event(rdev, netdev, buf, len,
3712 NL80211_CMD_DEAUTHENTICATE);
3713}
3714
Jouni Malinen53b46b82009-03-27 20:53:56 +02003715void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
3716 struct net_device *netdev, const u8 *buf,
3717 size_t len)
Jouni Malinen6039f6d2009-03-19 13:39:21 +02003718{
3719 nl80211_send_mlme_event(rdev, netdev, buf, len,
3720 NL80211_CMD_DISASSOCIATE);
3721}
3722
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -04003723static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
3724 struct net_device *netdev, int cmd,
3725 const u8 *addr)
Jouni Malinen1965c852009-04-22 21:38:25 +03003726{
3727 struct sk_buff *msg;
3728 void *hdr;
3729
3730 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
3731 if (!msg)
3732 return;
3733
3734 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
3735 if (!hdr) {
3736 nlmsg_free(msg);
3737 return;
3738 }
3739
3740 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3741 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3742 NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT);
3743 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
3744
3745 if (genlmsg_end(msg, hdr) < 0) {
3746 nlmsg_free(msg);
3747 return;
3748 }
3749
3750 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC);
3751 return;
3752
3753 nla_put_failure:
3754 genlmsg_cancel(msg, hdr);
3755 nlmsg_free(msg);
3756}
3757
3758void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
3759 struct net_device *netdev, const u8 *addr)
3760{
3761 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
3762 addr);
3763}
3764
3765void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
3766 struct net_device *netdev, const u8 *addr)
3767{
3768 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, addr);
3769}
3770
Johannes Berg04a773a2009-04-19 21:24:32 +02003771void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
3772 struct net_device *netdev, const u8 *bssid,
3773 gfp_t gfp)
3774{
3775 struct sk_buff *msg;
3776 void *hdr;
3777
3778 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
3779 if (!msg)
3780 return;
3781
3782 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
3783 if (!hdr) {
3784 nlmsg_free(msg);
3785 return;
3786 }
3787
3788 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3789 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3790 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid);
3791
3792 if (genlmsg_end(msg, hdr) < 0) {
3793 nlmsg_free(msg);
3794 return;
3795 }
3796
3797 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp);
3798 return;
3799
3800 nla_put_failure:
3801 genlmsg_cancel(msg, hdr);
3802 nlmsg_free(msg);
3803}
3804
Jouni Malinena3b8b052009-03-27 21:59:49 +02003805void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
3806 struct net_device *netdev, const u8 *addr,
3807 enum nl80211_key_type key_type, int key_id,
3808 const u8 *tsc)
3809{
3810 struct sk_buff *msg;
3811 void *hdr;
3812
3813 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL);
3814 if (!msg)
3815 return;
3816
3817 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
3818 if (!hdr) {
3819 nlmsg_free(msg);
3820 return;
3821 }
3822
3823 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx);
3824 NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex);
3825 if (addr)
3826 NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
3827 NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type);
3828 NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id);
3829 if (tsc)
3830 NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc);
3831
3832 if (genlmsg_end(msg, hdr) < 0) {
3833 nlmsg_free(msg);
3834 return;
3835 }
3836
3837 genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL);
3838 return;
3839
3840 nla_put_failure:
3841 genlmsg_cancel(msg, hdr);
3842 nlmsg_free(msg);
3843}
3844
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -04003845void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
3846 struct ieee80211_channel *channel_before,
3847 struct ieee80211_channel *channel_after)
3848{
3849 struct sk_buff *msg;
3850 void *hdr;
3851 struct nlattr *nl_freq;
3852
3853 msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC);
3854 if (!msg)
3855 return;
3856
3857 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
3858 if (!hdr) {
3859 nlmsg_free(msg);
3860 return;
3861 }
3862
3863 /*
3864 * Since we are applying the beacon hint to a wiphy we know its
3865 * wiphy_idx is valid
3866 */
3867 NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy));
3868
3869 /* Before */
3870 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
3871 if (!nl_freq)
3872 goto nla_put_failure;
3873 if (nl80211_msg_put_channel(msg, channel_before))
3874 goto nla_put_failure;
3875 nla_nest_end(msg, nl_freq);
3876
3877 /* After */
3878 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
3879 if (!nl_freq)
3880 goto nla_put_failure;
3881 if (nl80211_msg_put_channel(msg, channel_after))
3882 goto nla_put_failure;
3883 nla_nest_end(msg, nl_freq);
3884
3885 if (genlmsg_end(msg, hdr) < 0) {
3886 nlmsg_free(msg);
3887 return;
3888 }
3889
3890 genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_ATOMIC);
3891
3892 return;
3893
3894nla_put_failure:
3895 genlmsg_cancel(msg, hdr);
3896 nlmsg_free(msg);
3897}
3898
Johannes Berg55682962007-09-20 13:09:35 -04003899/* initialisation/exit functions */
3900
3901int nl80211_init(void)
3902{
3903 int err, i;
3904
3905 err = genl_register_family(&nl80211_fam);
3906 if (err)
3907 return err;
3908
3909 for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) {
3910 err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]);
3911 if (err)
3912 goto err_out;
3913 }
3914
3915 err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp);
3916 if (err)
3917 goto err_out;
3918
Johannes Berg2a519312009-02-10 21:25:55 +01003919 err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp);
3920 if (err)
3921 goto err_out;
3922
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -04003923 err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp);
3924 if (err)
3925 goto err_out;
3926
Jouni Malinen6039f6d2009-03-19 13:39:21 +02003927 err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp);
3928 if (err)
3929 goto err_out;
3930
Johannes Berg55682962007-09-20 13:09:35 -04003931 return 0;
3932 err_out:
3933 genl_unregister_family(&nl80211_fam);
3934 return err;
3935}
3936
3937void nl80211_exit(void)
3938{
3939 genl_unregister_family(&nl80211_fam);
3940}