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