]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
4 | * Copyright 2006, 2007 Johannes Berg <johannes@sipsolutions.net> | |
5 | */ | |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
55682965 JB |
10 | #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> | |
2a519311 | 16 | #include <linux/etherdevice.h> |
55682965 JB |
17 | #include <net/genetlink.h> |
18 | #include <net/cfg80211.h> | |
19 | #include "core.h" | |
20 | #include "nl80211.h" | |
b2e1b302 | 21 | #include "reg.h" |
55682965 JB |
22 | |
23 | /* the netlink family */ | |
24 | static struct genl_family nl80211_fam = { | |
25 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ | |
26 | .name = "nl80211", /* have users key off the name instead */ | |
27 | .hdrsize = 0, /* no private header */ | |
28 | .version = 1, /* no particular meaning now */ | |
29 | .maxattr = NL80211_ATTR_MAX, | |
30 | }; | |
31 | ||
32 | /* internal helper: get drv and dev */ | |
bba95fef | 33 | static int get_drv_dev_by_info_ifindex(struct nlattr **attrs, |
55682965 JB |
34 | struct cfg80211_registered_device **drv, |
35 | struct net_device **dev) | |
36 | { | |
37 | int ifindex; | |
38 | ||
bba95fef | 39 | if (!attrs[NL80211_ATTR_IFINDEX]) |
55682965 JB |
40 | return -EINVAL; |
41 | ||
bba95fef | 42 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
55682965 JB |
43 | *dev = dev_get_by_index(&init_net, ifindex); |
44 | if (!*dev) | |
45 | return -ENODEV; | |
46 | ||
47 | *drv = cfg80211_get_dev_from_ifindex(ifindex); | |
48 | if (IS_ERR(*drv)) { | |
49 | dev_put(*dev); | |
50 | return PTR_ERR(*drv); | |
51 | } | |
52 | ||
53 | return 0; | |
54 | } | |
55 | ||
56 | /* policy for the attributes */ | |
57 | static struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] __read_mostly = { | |
58 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, | |
59 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
60 | .len = BUS_ID_SIZE-1 }, | |
31888487 | 61 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
72bdcf34 | 62 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 63 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
55682965 JB |
64 | |
65 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
66 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
67 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f JB |
68 | |
69 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, | |
70 | ||
71 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, | |
72 | .len = WLAN_MAX_KEY_LEN }, | |
73 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
74 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
75 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
ed1b6cc7 JB |
76 | |
77 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
78 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
79 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
80 | .len = IEEE80211_MAX_DATA_LEN }, | |
81 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
82 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
83 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
84 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
85 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
86 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
87 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 88 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 89 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 90 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 LCC |
91 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
92 | .len = IEEE80211_MAX_MESH_ID_LEN }, | |
93 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, | |
9f1ba906 | 94 | |
b2e1b302 LR |
95 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
96 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
97 | ||
9f1ba906 JM |
98 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
99 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
100 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
101 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
102 | .len = NL80211_MAX_SUPP_RATES }, | |
36aedc90 | 103 | |
93da9cc1 | 104 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
105 | ||
36aedc90 JM |
106 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
107 | .len = NL80211_HT_CAPABILITY_LEN }, | |
9aed3cc1 JM |
108 | |
109 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
110 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
111 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
112 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
113 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
114 | |
115 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
116 | .len = IEEE80211_MAX_SSID_LEN }, | |
117 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
118 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
55682965 JB |
119 | }; |
120 | ||
f4a11bb0 JB |
121 | /* IE validation */ |
122 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
123 | { | |
124 | const u8 *pos; | |
125 | int len; | |
126 | ||
127 | if (!attr) | |
128 | return true; | |
129 | ||
130 | pos = nla_data(attr); | |
131 | len = nla_len(attr); | |
132 | ||
133 | while (len) { | |
134 | u8 elemlen; | |
135 | ||
136 | if (len < 2) | |
137 | return false; | |
138 | len -= 2; | |
139 | ||
140 | elemlen = pos[1]; | |
141 | if (elemlen > len) | |
142 | return false; | |
143 | ||
144 | len -= elemlen; | |
145 | pos += 2 + elemlen; | |
146 | } | |
147 | ||
148 | return true; | |
149 | } | |
150 | ||
55682965 JB |
151 | /* message building helper */ |
152 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, | |
153 | int flags, u8 cmd) | |
154 | { | |
155 | /* since there is no private header just add the generic one */ | |
156 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); | |
157 | } | |
158 | ||
5dab3b8a LR |
159 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
160 | struct ieee80211_channel *chan) | |
161 | { | |
162 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, | |
163 | chan->center_freq); | |
164 | ||
165 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
166 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); | |
167 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) | |
168 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); | |
169 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) | |
170 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); | |
171 | if (chan->flags & IEEE80211_CHAN_RADAR) | |
172 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); | |
173 | ||
174 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, | |
175 | DBM_TO_MBM(chan->max_power)); | |
176 | ||
177 | return 0; | |
178 | ||
179 | nla_put_failure: | |
180 | return -ENOBUFS; | |
181 | } | |
182 | ||
55682965 JB |
183 | /* netlink command implementations */ |
184 | ||
185 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
186 | struct cfg80211_registered_device *dev) | |
187 | { | |
188 | void *hdr; | |
ee688b00 JB |
189 | struct nlattr *nl_bands, *nl_band; |
190 | struct nlattr *nl_freqs, *nl_freq; | |
191 | struct nlattr *nl_rates, *nl_rate; | |
f59ac048 | 192 | struct nlattr *nl_modes; |
8fdc621d | 193 | struct nlattr *nl_cmds; |
ee688b00 JB |
194 | enum ieee80211_band band; |
195 | struct ieee80211_channel *chan; | |
196 | struct ieee80211_rate *rate; | |
197 | int i; | |
f59ac048 | 198 | u16 ifmodes = dev->wiphy.interface_modes; |
55682965 JB |
199 | |
200 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); | |
201 | if (!hdr) | |
202 | return -1; | |
203 | ||
b5850a7a | 204 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
55682965 | 205 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
2a519311 JB |
206 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
207 | dev->wiphy.max_scan_ssids); | |
18a83659 JB |
208 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
209 | dev->wiphy.max_scan_ie_len); | |
ee688b00 | 210 | |
25e47c18 JB |
211 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
212 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
213 | dev->wiphy.cipher_suites); | |
214 | ||
f59ac048 LR |
215 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
216 | if (!nl_modes) | |
217 | goto nla_put_failure; | |
218 | ||
219 | i = 0; | |
220 | while (ifmodes) { | |
221 | if (ifmodes & 1) | |
222 | NLA_PUT_FLAG(msg, i); | |
223 | ifmodes >>= 1; | |
224 | i++; | |
225 | } | |
226 | ||
227 | nla_nest_end(msg, nl_modes); | |
228 | ||
ee688b00 JB |
229 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
230 | if (!nl_bands) | |
231 | goto nla_put_failure; | |
232 | ||
233 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
234 | if (!dev->wiphy.bands[band]) | |
235 | continue; | |
236 | ||
237 | nl_band = nla_nest_start(msg, band); | |
238 | if (!nl_band) | |
239 | goto nla_put_failure; | |
240 | ||
d51626df JB |
241 | /* add HT info */ |
242 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { | |
243 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
244 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), | |
245 | &dev->wiphy.bands[band]->ht_cap.mcs); | |
246 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
247 | dev->wiphy.bands[band]->ht_cap.cap); | |
248 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
249 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); | |
250 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
251 | dev->wiphy.bands[band]->ht_cap.ampdu_density); | |
252 | } | |
253 | ||
ee688b00 JB |
254 | /* add frequencies */ |
255 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); | |
256 | if (!nl_freqs) | |
257 | goto nla_put_failure; | |
258 | ||
259 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { | |
260 | nl_freq = nla_nest_start(msg, i); | |
261 | if (!nl_freq) | |
262 | goto nla_put_failure; | |
263 | ||
264 | chan = &dev->wiphy.bands[band]->channels[i]; | |
5dab3b8a LR |
265 | |
266 | if (nl80211_msg_put_channel(msg, chan)) | |
267 | goto nla_put_failure; | |
e2f367f2 | 268 | |
ee688b00 JB |
269 | nla_nest_end(msg, nl_freq); |
270 | } | |
271 | ||
272 | nla_nest_end(msg, nl_freqs); | |
273 | ||
274 | /* add bitrates */ | |
275 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
276 | if (!nl_rates) | |
277 | goto nla_put_failure; | |
278 | ||
279 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { | |
280 | nl_rate = nla_nest_start(msg, i); | |
281 | if (!nl_rate) | |
282 | goto nla_put_failure; | |
283 | ||
284 | rate = &dev->wiphy.bands[band]->bitrates[i]; | |
285 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, | |
286 | rate->bitrate); | |
287 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) | |
288 | NLA_PUT_FLAG(msg, | |
289 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); | |
290 | ||
291 | nla_nest_end(msg, nl_rate); | |
292 | } | |
293 | ||
294 | nla_nest_end(msg, nl_rates); | |
295 | ||
296 | nla_nest_end(msg, nl_band); | |
297 | } | |
298 | nla_nest_end(msg, nl_bands); | |
299 | ||
8fdc621d JB |
300 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
301 | if (!nl_cmds) | |
302 | goto nla_put_failure; | |
303 | ||
304 | i = 0; | |
305 | #define CMD(op, n) \ | |
306 | do { \ | |
307 | if (dev->ops->op) { \ | |
308 | i++; \ | |
309 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ | |
310 | } \ | |
311 | } while (0) | |
312 | ||
313 | CMD(add_virtual_intf, NEW_INTERFACE); | |
314 | CMD(change_virtual_intf, SET_INTERFACE); | |
315 | CMD(add_key, NEW_KEY); | |
316 | CMD(add_beacon, NEW_BEACON); | |
317 | CMD(add_station, NEW_STATION); | |
318 | CMD(add_mpath, NEW_MPATH); | |
319 | CMD(set_mesh_params, SET_MESH_PARAMS); | |
320 | CMD(change_bss, SET_BSS); | |
636a5d36 JM |
321 | CMD(auth, AUTHENTICATE); |
322 | CMD(assoc, ASSOCIATE); | |
323 | CMD(deauth, DEAUTHENTICATE); | |
324 | CMD(disassoc, DISASSOCIATE); | |
8fdc621d JB |
325 | |
326 | #undef CMD | |
327 | nla_nest_end(msg, nl_cmds); | |
328 | ||
55682965 JB |
329 | return genlmsg_end(msg, hdr); |
330 | ||
331 | nla_put_failure: | |
bc3ed28c TG |
332 | genlmsg_cancel(msg, hdr); |
333 | return -EMSGSIZE; | |
55682965 JB |
334 | } |
335 | ||
336 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
337 | { | |
338 | int idx = 0; | |
339 | int start = cb->args[0]; | |
340 | struct cfg80211_registered_device *dev; | |
341 | ||
a1794390 | 342 | mutex_lock(&cfg80211_mutex); |
55682965 | 343 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
b4637271 | 344 | if (++idx <= start) |
55682965 JB |
345 | continue; |
346 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, | |
347 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
b4637271 JV |
348 | dev) < 0) { |
349 | idx--; | |
55682965 | 350 | break; |
b4637271 | 351 | } |
55682965 | 352 | } |
a1794390 | 353 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
354 | |
355 | cb->args[0] = idx; | |
356 | ||
357 | return skb->len; | |
358 | } | |
359 | ||
360 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
361 | { | |
362 | struct sk_buff *msg; | |
363 | struct cfg80211_registered_device *dev; | |
364 | ||
365 | dev = cfg80211_get_dev_from_info(info); | |
366 | if (IS_ERR(dev)) | |
367 | return PTR_ERR(dev); | |
368 | ||
369 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
370 | if (!msg) | |
371 | goto out_err; | |
372 | ||
373 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) | |
374 | goto out_free; | |
375 | ||
376 | cfg80211_put_dev(dev); | |
377 | ||
378 | return genlmsg_unicast(msg, info->snd_pid); | |
379 | ||
380 | out_free: | |
381 | nlmsg_free(msg); | |
382 | out_err: | |
383 | cfg80211_put_dev(dev); | |
384 | return -ENOBUFS; | |
385 | } | |
386 | ||
31888487 JM |
387 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
388 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
389 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
390 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
391 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
392 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
393 | }; | |
394 | ||
395 | static int parse_txq_params(struct nlattr *tb[], | |
396 | struct ieee80211_txq_params *txq_params) | |
397 | { | |
398 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || | |
399 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || | |
400 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
401 | return -EINVAL; | |
402 | ||
403 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); | |
404 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); | |
405 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
406 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
407 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
408 | ||
409 | return 0; | |
410 | } | |
411 | ||
55682965 JB |
412 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
413 | { | |
414 | struct cfg80211_registered_device *rdev; | |
31888487 JM |
415 | int result = 0, rem_txq_params = 0; |
416 | struct nlattr *nl_txq_params; | |
55682965 | 417 | |
4bbf4d56 | 418 | rtnl_lock(); |
55682965 | 419 | |
4bbf4d56 JB |
420 | mutex_lock(&cfg80211_mutex); |
421 | ||
422 | rdev = __cfg80211_drv_from_info(info); | |
423 | if (IS_ERR(rdev)) { | |
424 | result = PTR_ERR(rdev); | |
425 | goto unlock; | |
426 | } | |
427 | ||
428 | mutex_lock(&rdev->mtx); | |
429 | ||
430 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
431 | result = cfg80211_dev_rename( |
432 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
433 | |
434 | mutex_unlock(&cfg80211_mutex); | |
435 | ||
436 | if (result) | |
437 | goto bad_res; | |
31888487 JM |
438 | |
439 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
440 | struct ieee80211_txq_params txq_params; | |
441 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
442 | ||
443 | if (!rdev->ops->set_txq_params) { | |
444 | result = -EOPNOTSUPP; | |
445 | goto bad_res; | |
446 | } | |
447 | ||
448 | nla_for_each_nested(nl_txq_params, | |
449 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
450 | rem_txq_params) { | |
451 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
452 | nla_data(nl_txq_params), | |
453 | nla_len(nl_txq_params), | |
454 | txq_params_policy); | |
455 | result = parse_txq_params(tb, &txq_params); | |
456 | if (result) | |
457 | goto bad_res; | |
458 | ||
459 | result = rdev->ops->set_txq_params(&rdev->wiphy, | |
460 | &txq_params); | |
461 | if (result) | |
462 | goto bad_res; | |
463 | } | |
464 | } | |
55682965 | 465 | |
72bdcf34 | 466 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
094d05dc | 467 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
72bdcf34 | 468 | struct ieee80211_channel *chan; |
306d6112 | 469 | struct ieee80211_sta_ht_cap *ht_cap; |
72bdcf34 JM |
470 | u32 freq, sec_freq; |
471 | ||
472 | if (!rdev->ops->set_channel) { | |
473 | result = -EOPNOTSUPP; | |
474 | goto bad_res; | |
475 | } | |
476 | ||
306d6112 JB |
477 | result = -EINVAL; |
478 | ||
094d05dc S |
479 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
480 | channel_type = nla_get_u32(info->attrs[ | |
481 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
482 | if (channel_type != NL80211_CHAN_NO_HT && | |
483 | channel_type != NL80211_CHAN_HT20 && | |
484 | channel_type != NL80211_CHAN_HT40PLUS && | |
485 | channel_type != NL80211_CHAN_HT40MINUS) | |
72bdcf34 | 486 | goto bad_res; |
72bdcf34 JM |
487 | } |
488 | ||
489 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
490 | chan = ieee80211_get_channel(&rdev->wiphy, freq); | |
306d6112 JB |
491 | |
492 | /* Primary channel not allowed */ | |
493 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
72bdcf34 | 494 | goto bad_res; |
306d6112 | 495 | |
094d05dc | 496 | if (channel_type == NL80211_CHAN_HT40MINUS) |
72bdcf34 | 497 | sec_freq = freq - 20; |
094d05dc | 498 | else if (channel_type == NL80211_CHAN_HT40PLUS) |
72bdcf34 JM |
499 | sec_freq = freq + 20; |
500 | else | |
501 | sec_freq = 0; | |
502 | ||
306d6112 JB |
503 | ht_cap = &rdev->wiphy.bands[chan->band]->ht_cap; |
504 | ||
505 | /* no HT capabilities */ | |
094d05dc | 506 | if (channel_type != NL80211_CHAN_NO_HT && |
306d6112 JB |
507 | !ht_cap->ht_supported) |
508 | goto bad_res; | |
509 | ||
72bdcf34 JM |
510 | if (sec_freq) { |
511 | struct ieee80211_channel *schan; | |
306d6112 JB |
512 | |
513 | /* no 40 MHz capabilities */ | |
514 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || | |
515 | (ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT)) | |
516 | goto bad_res; | |
517 | ||
72bdcf34 | 518 | schan = ieee80211_get_channel(&rdev->wiphy, sec_freq); |
306d6112 JB |
519 | |
520 | /* Secondary channel not allowed */ | |
521 | if (!schan || schan->flags & IEEE80211_CHAN_DISABLED) | |
72bdcf34 | 522 | goto bad_res; |
72bdcf34 JM |
523 | } |
524 | ||
525 | result = rdev->ops->set_channel(&rdev->wiphy, chan, | |
094d05dc | 526 | channel_type); |
72bdcf34 JM |
527 | if (result) |
528 | goto bad_res; | |
529 | } | |
530 | ||
531 | ||
306d6112 | 532 | bad_res: |
4bbf4d56 JB |
533 | mutex_unlock(&rdev->mtx); |
534 | unlock: | |
535 | rtnl_unlock(); | |
55682965 JB |
536 | return result; |
537 | } | |
538 | ||
539 | ||
540 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
541 | struct net_device *dev) | |
542 | { | |
543 | void *hdr; | |
544 | ||
545 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); | |
546 | if (!hdr) | |
547 | return -1; | |
548 | ||
549 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
550 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); | |
60719ffd | 551 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
55682965 JB |
552 | return genlmsg_end(msg, hdr); |
553 | ||
554 | nla_put_failure: | |
bc3ed28c TG |
555 | genlmsg_cancel(msg, hdr); |
556 | return -EMSGSIZE; | |
55682965 JB |
557 | } |
558 | ||
559 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
560 | { | |
561 | int wp_idx = 0; | |
562 | int if_idx = 0; | |
563 | int wp_start = cb->args[0]; | |
564 | int if_start = cb->args[1]; | |
565 | struct cfg80211_registered_device *dev; | |
566 | struct wireless_dev *wdev; | |
567 | ||
a1794390 | 568 | mutex_lock(&cfg80211_mutex); |
55682965 | 569 | list_for_each_entry(dev, &cfg80211_drv_list, list) { |
bba95fef JB |
570 | if (wp_idx < wp_start) { |
571 | wp_idx++; | |
55682965 | 572 | continue; |
bba95fef | 573 | } |
55682965 JB |
574 | if_idx = 0; |
575 | ||
576 | mutex_lock(&dev->devlist_mtx); | |
577 | list_for_each_entry(wdev, &dev->netdev_list, list) { | |
bba95fef JB |
578 | if (if_idx < if_start) { |
579 | if_idx++; | |
55682965 | 580 | continue; |
bba95fef | 581 | } |
55682965 JB |
582 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
583 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
bba95fef JB |
584 | wdev->netdev) < 0) { |
585 | mutex_unlock(&dev->devlist_mtx); | |
586 | goto out; | |
587 | } | |
588 | if_idx++; | |
55682965 JB |
589 | } |
590 | mutex_unlock(&dev->devlist_mtx); | |
bba95fef JB |
591 | |
592 | wp_idx++; | |
55682965 | 593 | } |
bba95fef | 594 | out: |
a1794390 | 595 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
596 | |
597 | cb->args[0] = wp_idx; | |
598 | cb->args[1] = if_idx; | |
599 | ||
600 | return skb->len; | |
601 | } | |
602 | ||
603 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
604 | { | |
605 | struct sk_buff *msg; | |
606 | struct cfg80211_registered_device *dev; | |
607 | struct net_device *netdev; | |
608 | int err; | |
609 | ||
bba95fef | 610 | err = get_drv_dev_by_info_ifindex(info->attrs, &dev, &netdev); |
55682965 JB |
611 | if (err) |
612 | return err; | |
613 | ||
614 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
615 | if (!msg) | |
616 | goto out_err; | |
617 | ||
618 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, netdev) < 0) | |
619 | goto out_free; | |
620 | ||
621 | dev_put(netdev); | |
622 | cfg80211_put_dev(dev); | |
623 | ||
624 | return genlmsg_unicast(msg, info->snd_pid); | |
625 | ||
626 | out_free: | |
627 | nlmsg_free(msg); | |
628 | out_err: | |
629 | dev_put(netdev); | |
630 | cfg80211_put_dev(dev); | |
631 | return -ENOBUFS; | |
632 | } | |
633 | ||
66f7ac50 MW |
634 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
635 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
636 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
637 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
638 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
639 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
640 | }; | |
641 | ||
642 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
643 | { | |
644 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
645 | int flag; | |
646 | ||
647 | *mntrflags = 0; | |
648 | ||
649 | if (!nla) | |
650 | return -EINVAL; | |
651 | ||
652 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
653 | nla, mntr_flags_policy)) | |
654 | return -EINVAL; | |
655 | ||
656 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
657 | if (flags[flag]) | |
658 | *mntrflags |= (1<<flag); | |
659 | ||
660 | return 0; | |
661 | } | |
662 | ||
55682965 JB |
663 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
664 | { | |
665 | struct cfg80211_registered_device *drv; | |
2ec600d6 | 666 | struct vif_params params; |
55682965 JB |
667 | int err, ifindex; |
668 | enum nl80211_iftype type; | |
669 | struct net_device *dev; | |
92ffe055 | 670 | u32 _flags, *flags = NULL; |
ac7f9cfa | 671 | bool change = false; |
55682965 | 672 | |
2ec600d6 LCC |
673 | memset(¶ms, 0, sizeof(params)); |
674 | ||
3b85875a JB |
675 | rtnl_lock(); |
676 | ||
bba95fef | 677 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
55682965 | 678 | if (err) |
3b85875a JB |
679 | goto unlock_rtnl; |
680 | ||
55682965 | 681 | ifindex = dev->ifindex; |
723b038d | 682 | type = dev->ieee80211_ptr->iftype; |
55682965 JB |
683 | dev_put(dev); |
684 | ||
723b038d | 685 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa JB |
686 | enum nl80211_iftype ntype; |
687 | ||
688 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
689 | if (type != ntype) | |
690 | change = true; | |
691 | type = ntype; | |
692 | if (type > NL80211_IFTYPE_MAX) { | |
693 | err = -EINVAL; | |
723b038d | 694 | goto unlock; |
ac7f9cfa | 695 | } |
723b038d JB |
696 | } |
697 | ||
f59ac048 LR |
698 | if (!drv->ops->change_virtual_intf || |
699 | !(drv->wiphy.interface_modes & (1 << type))) { | |
55682965 JB |
700 | err = -EOPNOTSUPP; |
701 | goto unlock; | |
702 | } | |
703 | ||
92ffe055 JB |
704 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
705 | if (type != NL80211_IFTYPE_MESH_POINT) { | |
706 | err = -EINVAL; | |
707 | goto unlock; | |
708 | } | |
2ec600d6 LCC |
709 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
710 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
ac7f9cfa | 711 | change = true; |
2ec600d6 LCC |
712 | } |
713 | ||
92ffe055 JB |
714 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
715 | if (type != NL80211_IFTYPE_MONITOR) { | |
716 | err = -EINVAL; | |
717 | goto unlock; | |
718 | } | |
719 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | |
720 | &_flags); | |
ac7f9cfa JB |
721 | if (err) |
722 | goto unlock; | |
723 | ||
724 | flags = &_flags; | |
725 | change = true; | |
92ffe055 | 726 | } |
3b85875a | 727 | |
ac7f9cfa JB |
728 | if (change) |
729 | err = drv->ops->change_virtual_intf(&drv->wiphy, ifindex, | |
730 | type, flags, ¶ms); | |
731 | else | |
732 | err = 0; | |
60719ffd JB |
733 | |
734 | dev = __dev_get_by_index(&init_net, ifindex); | |
735 | WARN_ON(!dev || (!err && dev->ieee80211_ptr->iftype != type)); | |
736 | ||
55682965 JB |
737 | unlock: |
738 | cfg80211_put_dev(drv); | |
3b85875a JB |
739 | unlock_rtnl: |
740 | rtnl_unlock(); | |
55682965 JB |
741 | return err; |
742 | } | |
743 | ||
744 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
745 | { | |
746 | struct cfg80211_registered_device *drv; | |
2ec600d6 | 747 | struct vif_params params; |
55682965 JB |
748 | int err; |
749 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 750 | u32 flags; |
55682965 | 751 | |
2ec600d6 LCC |
752 | memset(¶ms, 0, sizeof(params)); |
753 | ||
55682965 JB |
754 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
755 | return -EINVAL; | |
756 | ||
757 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
758 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
759 | if (type > NL80211_IFTYPE_MAX) | |
760 | return -EINVAL; | |
761 | } | |
762 | ||
3b85875a JB |
763 | rtnl_lock(); |
764 | ||
55682965 | 765 | drv = cfg80211_get_dev_from_info(info); |
3b85875a JB |
766 | if (IS_ERR(drv)) { |
767 | err = PTR_ERR(drv); | |
768 | goto unlock_rtnl; | |
769 | } | |
55682965 | 770 | |
f59ac048 LR |
771 | if (!drv->ops->add_virtual_intf || |
772 | !(drv->wiphy.interface_modes & (1 << type))) { | |
55682965 JB |
773 | err = -EOPNOTSUPP; |
774 | goto unlock; | |
775 | } | |
776 | ||
2ec600d6 LCC |
777 | if (type == NL80211_IFTYPE_MESH_POINT && |
778 | info->attrs[NL80211_ATTR_MESH_ID]) { | |
779 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); | |
780 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
781 | } | |
782 | ||
66f7ac50 MW |
783 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
784 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
785 | &flags); | |
55682965 | 786 | err = drv->ops->add_virtual_intf(&drv->wiphy, |
66f7ac50 | 787 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
2ec600d6 | 788 | type, err ? NULL : &flags, ¶ms); |
2ec600d6 | 789 | |
55682965 JB |
790 | unlock: |
791 | cfg80211_put_dev(drv); | |
3b85875a JB |
792 | unlock_rtnl: |
793 | rtnl_unlock(); | |
55682965 JB |
794 | return err; |
795 | } | |
796 | ||
797 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
798 | { | |
799 | struct cfg80211_registered_device *drv; | |
800 | int ifindex, err; | |
801 | struct net_device *dev; | |
802 | ||
3b85875a JB |
803 | rtnl_lock(); |
804 | ||
bba95fef | 805 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
55682965 | 806 | if (err) |
3b85875a | 807 | goto unlock_rtnl; |
55682965 JB |
808 | ifindex = dev->ifindex; |
809 | dev_put(dev); | |
810 | ||
811 | if (!drv->ops->del_virtual_intf) { | |
812 | err = -EOPNOTSUPP; | |
813 | goto out; | |
814 | } | |
815 | ||
55682965 | 816 | err = drv->ops->del_virtual_intf(&drv->wiphy, ifindex); |
55682965 JB |
817 | |
818 | out: | |
819 | cfg80211_put_dev(drv); | |
3b85875a JB |
820 | unlock_rtnl: |
821 | rtnl_unlock(); | |
55682965 JB |
822 | return err; |
823 | } | |
824 | ||
41ade00f JB |
825 | struct get_key_cookie { |
826 | struct sk_buff *msg; | |
827 | int error; | |
828 | }; | |
829 | ||
830 | static void get_key_callback(void *c, struct key_params *params) | |
831 | { | |
832 | struct get_key_cookie *cookie = c; | |
833 | ||
834 | if (params->key) | |
835 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, | |
836 | params->key_len, params->key); | |
837 | ||
838 | if (params->seq) | |
839 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
840 | params->seq_len, params->seq); | |
841 | ||
842 | if (params->cipher) | |
843 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
844 | params->cipher); | |
845 | ||
846 | return; | |
847 | nla_put_failure: | |
848 | cookie->error = 1; | |
849 | } | |
850 | ||
851 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
852 | { | |
853 | struct cfg80211_registered_device *drv; | |
854 | int err; | |
855 | struct net_device *dev; | |
856 | u8 key_idx = 0; | |
857 | u8 *mac_addr = NULL; | |
858 | struct get_key_cookie cookie = { | |
859 | .error = 0, | |
860 | }; | |
861 | void *hdr; | |
862 | struct sk_buff *msg; | |
863 | ||
864 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
865 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
866 | ||
3cfcf6ac | 867 | if (key_idx > 5) |
41ade00f JB |
868 | return -EINVAL; |
869 | ||
870 | if (info->attrs[NL80211_ATTR_MAC]) | |
871 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
872 | ||
3b85875a JB |
873 | rtnl_lock(); |
874 | ||
bba95fef | 875 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
41ade00f | 876 | if (err) |
3b85875a | 877 | goto unlock_rtnl; |
41ade00f JB |
878 | |
879 | if (!drv->ops->get_key) { | |
880 | err = -EOPNOTSUPP; | |
881 | goto out; | |
882 | } | |
883 | ||
884 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
885 | if (!msg) { | |
886 | err = -ENOMEM; | |
887 | goto out; | |
888 | } | |
889 | ||
890 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
891 | NL80211_CMD_NEW_KEY); | |
892 | ||
893 | if (IS_ERR(hdr)) { | |
894 | err = PTR_ERR(hdr); | |
895 | goto out; | |
896 | } | |
897 | ||
898 | cookie.msg = msg; | |
899 | ||
900 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
901 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
902 | if (mac_addr) | |
903 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
904 | ||
41ade00f JB |
905 | err = drv->ops->get_key(&drv->wiphy, dev, key_idx, mac_addr, |
906 | &cookie, get_key_callback); | |
41ade00f JB |
907 | |
908 | if (err) | |
909 | goto out; | |
910 | ||
911 | if (cookie.error) | |
912 | goto nla_put_failure; | |
913 | ||
914 | genlmsg_end(msg, hdr); | |
915 | err = genlmsg_unicast(msg, info->snd_pid); | |
916 | goto out; | |
917 | ||
918 | nla_put_failure: | |
919 | err = -ENOBUFS; | |
920 | nlmsg_free(msg); | |
921 | out: | |
922 | cfg80211_put_dev(drv); | |
923 | dev_put(dev); | |
3b85875a JB |
924 | unlock_rtnl: |
925 | rtnl_unlock(); | |
926 | ||
41ade00f JB |
927 | return err; |
928 | } | |
929 | ||
930 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
931 | { | |
932 | struct cfg80211_registered_device *drv; | |
933 | int err; | |
934 | struct net_device *dev; | |
935 | u8 key_idx; | |
3cfcf6ac JM |
936 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, |
937 | u8 key_index); | |
41ade00f JB |
938 | |
939 | if (!info->attrs[NL80211_ATTR_KEY_IDX]) | |
940 | return -EINVAL; | |
941 | ||
942 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
943 | ||
3cfcf6ac JM |
944 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) { |
945 | if (key_idx < 4 || key_idx > 5) | |
946 | return -EINVAL; | |
947 | } else if (key_idx > 3) | |
41ade00f JB |
948 | return -EINVAL; |
949 | ||
950 | /* currently only support setting default key */ | |
3cfcf6ac JM |
951 | if (!info->attrs[NL80211_ATTR_KEY_DEFAULT] && |
952 | !info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]) | |
41ade00f JB |
953 | return -EINVAL; |
954 | ||
3b85875a JB |
955 | rtnl_lock(); |
956 | ||
bba95fef | 957 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
41ade00f | 958 | if (err) |
3b85875a | 959 | goto unlock_rtnl; |
41ade00f | 960 | |
3cfcf6ac JM |
961 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT]) |
962 | func = drv->ops->set_default_key; | |
963 | else | |
964 | func = drv->ops->set_default_mgmt_key; | |
965 | ||
966 | if (!func) { | |
41ade00f JB |
967 | err = -EOPNOTSUPP; |
968 | goto out; | |
969 | } | |
970 | ||
3cfcf6ac | 971 | err = func(&drv->wiphy, dev, key_idx); |
41ade00f JB |
972 | |
973 | out: | |
974 | cfg80211_put_dev(drv); | |
975 | dev_put(dev); | |
3b85875a JB |
976 | |
977 | unlock_rtnl: | |
978 | rtnl_unlock(); | |
979 | ||
41ade00f JB |
980 | return err; |
981 | } | |
982 | ||
983 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
984 | { | |
985 | struct cfg80211_registered_device *drv; | |
25e47c18 | 986 | int err, i; |
41ade00f JB |
987 | struct net_device *dev; |
988 | struct key_params params; | |
989 | u8 key_idx = 0; | |
990 | u8 *mac_addr = NULL; | |
991 | ||
992 | memset(¶ms, 0, sizeof(params)); | |
993 | ||
994 | if (!info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
995 | return -EINVAL; | |
996 | ||
997 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
998 | params.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
999 | params.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
1000 | } | |
1001 | ||
1002 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
1003 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
1004 | ||
1005 | params.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
1006 | ||
1007 | if (info->attrs[NL80211_ATTR_MAC]) | |
1008 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1009 | ||
3cfcf6ac | 1010 | if (key_idx > 5) |
41ade00f JB |
1011 | return -EINVAL; |
1012 | ||
1013 | /* | |
1014 | * Disallow pairwise keys with non-zero index unless it's WEP | |
1015 | * (because current deployments use pairwise WEP keys with | |
1016 | * non-zero indizes but 802.11i clearly specifies to use zero) | |
1017 | */ | |
1018 | if (mac_addr && key_idx && | |
1019 | params.cipher != WLAN_CIPHER_SUITE_WEP40 && | |
1020 | params.cipher != WLAN_CIPHER_SUITE_WEP104) | |
1021 | return -EINVAL; | |
1022 | ||
1023 | /* TODO: add definitions for the lengths to linux/ieee80211.h */ | |
1024 | switch (params.cipher) { | |
1025 | case WLAN_CIPHER_SUITE_WEP40: | |
1026 | if (params.key_len != 5) | |
1027 | return -EINVAL; | |
1028 | break; | |
1029 | case WLAN_CIPHER_SUITE_TKIP: | |
1030 | if (params.key_len != 32) | |
1031 | return -EINVAL; | |
1032 | break; | |
1033 | case WLAN_CIPHER_SUITE_CCMP: | |
1034 | if (params.key_len != 16) | |
1035 | return -EINVAL; | |
1036 | break; | |
1037 | case WLAN_CIPHER_SUITE_WEP104: | |
1038 | if (params.key_len != 13) | |
1039 | return -EINVAL; | |
1040 | break; | |
3cfcf6ac JM |
1041 | case WLAN_CIPHER_SUITE_AES_CMAC: |
1042 | if (params.key_len != 16) | |
1043 | return -EINVAL; | |
1044 | break; | |
41ade00f JB |
1045 | default: |
1046 | return -EINVAL; | |
1047 | } | |
1048 | ||
3b85875a JB |
1049 | rtnl_lock(); |
1050 | ||
bba95fef | 1051 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
41ade00f | 1052 | if (err) |
3b85875a | 1053 | goto unlock_rtnl; |
41ade00f | 1054 | |
25e47c18 JB |
1055 | for (i = 0; i < drv->wiphy.n_cipher_suites; i++) |
1056 | if (params.cipher == drv->wiphy.cipher_suites[i]) | |
1057 | break; | |
1058 | if (i == drv->wiphy.n_cipher_suites) { | |
1059 | err = -EINVAL; | |
1060 | goto out; | |
1061 | } | |
1062 | ||
41ade00f JB |
1063 | if (!drv->ops->add_key) { |
1064 | err = -EOPNOTSUPP; | |
1065 | goto out; | |
1066 | } | |
1067 | ||
41ade00f | 1068 | err = drv->ops->add_key(&drv->wiphy, dev, key_idx, mac_addr, ¶ms); |
41ade00f JB |
1069 | |
1070 | out: | |
1071 | cfg80211_put_dev(drv); | |
1072 | dev_put(dev); | |
3b85875a JB |
1073 | unlock_rtnl: |
1074 | rtnl_unlock(); | |
1075 | ||
41ade00f JB |
1076 | return err; |
1077 | } | |
1078 | ||
1079 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
1080 | { | |
1081 | struct cfg80211_registered_device *drv; | |
1082 | int err; | |
1083 | struct net_device *dev; | |
1084 | u8 key_idx = 0; | |
1085 | u8 *mac_addr = NULL; | |
1086 | ||
1087 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
1088 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
1089 | ||
3cfcf6ac | 1090 | if (key_idx > 5) |
41ade00f JB |
1091 | return -EINVAL; |
1092 | ||
1093 | if (info->attrs[NL80211_ATTR_MAC]) | |
1094 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1095 | ||
3b85875a JB |
1096 | rtnl_lock(); |
1097 | ||
bba95fef | 1098 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
41ade00f | 1099 | if (err) |
3b85875a | 1100 | goto unlock_rtnl; |
41ade00f JB |
1101 | |
1102 | if (!drv->ops->del_key) { | |
1103 | err = -EOPNOTSUPP; | |
1104 | goto out; | |
1105 | } | |
1106 | ||
41ade00f | 1107 | err = drv->ops->del_key(&drv->wiphy, dev, key_idx, mac_addr); |
41ade00f JB |
1108 | |
1109 | out: | |
1110 | cfg80211_put_dev(drv); | |
1111 | dev_put(dev); | |
3b85875a JB |
1112 | |
1113 | unlock_rtnl: | |
1114 | rtnl_unlock(); | |
1115 | ||
41ade00f JB |
1116 | return err; |
1117 | } | |
1118 | ||
ed1b6cc7 JB |
1119 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
1120 | { | |
1121 | int (*call)(struct wiphy *wiphy, struct net_device *dev, | |
1122 | struct beacon_parameters *info); | |
1123 | struct cfg80211_registered_device *drv; | |
1124 | int err; | |
1125 | struct net_device *dev; | |
1126 | struct beacon_parameters params; | |
1127 | int haveinfo = 0; | |
1128 | ||
f4a11bb0 JB |
1129 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
1130 | return -EINVAL; | |
1131 | ||
3b85875a JB |
1132 | rtnl_lock(); |
1133 | ||
bba95fef | 1134 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
ed1b6cc7 | 1135 | if (err) |
3b85875a | 1136 | goto unlock_rtnl; |
ed1b6cc7 | 1137 | |
eec60b03 JM |
1138 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
1139 | err = -EOPNOTSUPP; | |
1140 | goto out; | |
1141 | } | |
1142 | ||
ed1b6cc7 JB |
1143 | switch (info->genlhdr->cmd) { |
1144 | case NL80211_CMD_NEW_BEACON: | |
1145 | /* these are required for NEW_BEACON */ | |
1146 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
1147 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
1148 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { | |
1149 | err = -EINVAL; | |
1150 | goto out; | |
1151 | } | |
1152 | ||
1153 | call = drv->ops->add_beacon; | |
1154 | break; | |
1155 | case NL80211_CMD_SET_BEACON: | |
1156 | call = drv->ops->set_beacon; | |
1157 | break; | |
1158 | default: | |
1159 | WARN_ON(1); | |
1160 | err = -EOPNOTSUPP; | |
1161 | goto out; | |
1162 | } | |
1163 | ||
1164 | if (!call) { | |
1165 | err = -EOPNOTSUPP; | |
1166 | goto out; | |
1167 | } | |
1168 | ||
1169 | memset(¶ms, 0, sizeof(params)); | |
1170 | ||
1171 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
1172 | params.interval = | |
1173 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
1174 | haveinfo = 1; | |
1175 | } | |
1176 | ||
1177 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
1178 | params.dtim_period = | |
1179 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
1180 | haveinfo = 1; | |
1181 | } | |
1182 | ||
1183 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { | |
1184 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
1185 | params.head_len = | |
1186 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
1187 | haveinfo = 1; | |
1188 | } | |
1189 | ||
1190 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
1191 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); | |
1192 | params.tail_len = | |
1193 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); | |
1194 | haveinfo = 1; | |
1195 | } | |
1196 | ||
1197 | if (!haveinfo) { | |
1198 | err = -EINVAL; | |
1199 | goto out; | |
1200 | } | |
1201 | ||
ed1b6cc7 | 1202 | err = call(&drv->wiphy, dev, ¶ms); |
ed1b6cc7 JB |
1203 | |
1204 | out: | |
1205 | cfg80211_put_dev(drv); | |
1206 | dev_put(dev); | |
3b85875a JB |
1207 | unlock_rtnl: |
1208 | rtnl_unlock(); | |
1209 | ||
ed1b6cc7 JB |
1210 | return err; |
1211 | } | |
1212 | ||
1213 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) | |
1214 | { | |
1215 | struct cfg80211_registered_device *drv; | |
1216 | int err; | |
1217 | struct net_device *dev; | |
1218 | ||
3b85875a JB |
1219 | rtnl_lock(); |
1220 | ||
bba95fef | 1221 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
ed1b6cc7 | 1222 | if (err) |
3b85875a | 1223 | goto unlock_rtnl; |
ed1b6cc7 JB |
1224 | |
1225 | if (!drv->ops->del_beacon) { | |
1226 | err = -EOPNOTSUPP; | |
1227 | goto out; | |
1228 | } | |
1229 | ||
eec60b03 JM |
1230 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
1231 | err = -EOPNOTSUPP; | |
1232 | goto out; | |
1233 | } | |
ed1b6cc7 | 1234 | err = drv->ops->del_beacon(&drv->wiphy, dev); |
ed1b6cc7 JB |
1235 | |
1236 | out: | |
1237 | cfg80211_put_dev(drv); | |
1238 | dev_put(dev); | |
3b85875a JB |
1239 | unlock_rtnl: |
1240 | rtnl_unlock(); | |
1241 | ||
ed1b6cc7 JB |
1242 | return err; |
1243 | } | |
1244 | ||
5727ef1b JB |
1245 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
1246 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
1247 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
1248 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
1249 | }; | |
1250 | ||
1251 | static int parse_station_flags(struct nlattr *nla, u32 *staflags) | |
1252 | { | |
1253 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
1254 | int flag; | |
1255 | ||
1256 | *staflags = 0; | |
1257 | ||
1258 | if (!nla) | |
1259 | return 0; | |
1260 | ||
1261 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
1262 | nla, sta_flags_policy)) | |
1263 | return -EINVAL; | |
1264 | ||
1265 | *staflags = STATION_FLAG_CHANGED; | |
1266 | ||
1267 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) | |
1268 | if (flags[flag]) | |
1269 | *staflags |= (1<<flag); | |
1270 | ||
1271 | return 0; | |
1272 | } | |
1273 | ||
420e7fab HR |
1274 | static u16 nl80211_calculate_bitrate(struct rate_info *rate) |
1275 | { | |
1276 | int modulation, streams, bitrate; | |
1277 | ||
1278 | if (!(rate->flags & RATE_INFO_FLAGS_MCS)) | |
1279 | return rate->legacy; | |
1280 | ||
1281 | /* the formula below does only work for MCS values smaller than 32 */ | |
1282 | if (rate->mcs >= 32) | |
1283 | return 0; | |
1284 | ||
1285 | modulation = rate->mcs & 7; | |
1286 | streams = (rate->mcs >> 3) + 1; | |
1287 | ||
1288 | bitrate = (rate->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) ? | |
1289 | 13500000 : 6500000; | |
1290 | ||
1291 | if (modulation < 4) | |
1292 | bitrate *= (modulation + 1); | |
1293 | else if (modulation == 4) | |
1294 | bitrate *= (modulation + 2); | |
1295 | else | |
1296 | bitrate *= (modulation + 3); | |
1297 | ||
1298 | bitrate *= streams; | |
1299 | ||
1300 | if (rate->flags & RATE_INFO_FLAGS_SHORT_GI) | |
1301 | bitrate = (bitrate / 9) * 10; | |
1302 | ||
1303 | /* do NOT round down here */ | |
1304 | return (bitrate + 50000) / 100000; | |
1305 | } | |
1306 | ||
fd5b74dc JB |
1307 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
1308 | int flags, struct net_device *dev, | |
2ec600d6 | 1309 | u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
1310 | { |
1311 | void *hdr; | |
420e7fab HR |
1312 | struct nlattr *sinfoattr, *txrate; |
1313 | u16 bitrate; | |
fd5b74dc JB |
1314 | |
1315 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
1316 | if (!hdr) | |
1317 | return -1; | |
1318 | ||
1319 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
1320 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
1321 | ||
2ec600d6 LCC |
1322 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
1323 | if (!sinfoattr) | |
fd5b74dc | 1324 | goto nla_put_failure; |
2ec600d6 LCC |
1325 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
1326 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
1327 | sinfo->inactive_time); | |
1328 | if (sinfo->filled & STATION_INFO_RX_BYTES) | |
1329 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, | |
1330 | sinfo->rx_bytes); | |
1331 | if (sinfo->filled & STATION_INFO_TX_BYTES) | |
1332 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, | |
1333 | sinfo->tx_bytes); | |
1334 | if (sinfo->filled & STATION_INFO_LLID) | |
1335 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, | |
1336 | sinfo->llid); | |
1337 | if (sinfo->filled & STATION_INFO_PLID) | |
1338 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, | |
1339 | sinfo->plid); | |
1340 | if (sinfo->filled & STATION_INFO_PLINK_STATE) | |
1341 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, | |
1342 | sinfo->plink_state); | |
420e7fab HR |
1343 | if (sinfo->filled & STATION_INFO_SIGNAL) |
1344 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, | |
1345 | sinfo->signal); | |
1346 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { | |
1347 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); | |
1348 | if (!txrate) | |
1349 | goto nla_put_failure; | |
1350 | ||
1351 | /* nl80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
1352 | bitrate = nl80211_calculate_bitrate(&sinfo->txrate); | |
1353 | if (bitrate > 0) | |
1354 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); | |
2ec600d6 | 1355 | |
420e7fab HR |
1356 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
1357 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, | |
1358 | sinfo->txrate.mcs); | |
1359 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) | |
1360 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); | |
1361 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) | |
1362 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); | |
1363 | ||
1364 | nla_nest_end(msg, txrate); | |
1365 | } | |
98c8a60a JM |
1366 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
1367 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, | |
1368 | sinfo->rx_packets); | |
1369 | if (sinfo->filled & STATION_INFO_TX_PACKETS) | |
1370 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, | |
1371 | sinfo->tx_packets); | |
2ec600d6 | 1372 | nla_nest_end(msg, sinfoattr); |
fd5b74dc JB |
1373 | |
1374 | return genlmsg_end(msg, hdr); | |
1375 | ||
1376 | nla_put_failure: | |
bc3ed28c TG |
1377 | genlmsg_cancel(msg, hdr); |
1378 | return -EMSGSIZE; | |
fd5b74dc JB |
1379 | } |
1380 | ||
2ec600d6 | 1381 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 1382 | struct netlink_callback *cb) |
2ec600d6 | 1383 | { |
2ec600d6 LCC |
1384 | struct station_info sinfo; |
1385 | struct cfg80211_registered_device *dev; | |
bba95fef | 1386 | struct net_device *netdev; |
2ec600d6 | 1387 | u8 mac_addr[ETH_ALEN]; |
bba95fef JB |
1388 | int ifidx = cb->args[0]; |
1389 | int sta_idx = cb->args[1]; | |
2ec600d6 | 1390 | int err; |
2ec600d6 | 1391 | |
bba95fef JB |
1392 | if (!ifidx) { |
1393 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1394 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
1395 | nl80211_policy); | |
1396 | if (err) | |
1397 | return err; | |
2ec600d6 | 1398 | |
bba95fef JB |
1399 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) |
1400 | return -EINVAL; | |
2ec600d6 | 1401 | |
bba95fef JB |
1402 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); |
1403 | if (!ifidx) | |
1404 | return -EINVAL; | |
2ec600d6 | 1405 | } |
2ec600d6 | 1406 | |
3b85875a JB |
1407 | rtnl_lock(); |
1408 | ||
1409 | netdev = __dev_get_by_index(&init_net, ifidx); | |
1410 | if (!netdev) { | |
1411 | err = -ENODEV; | |
1412 | goto out_rtnl; | |
1413 | } | |
2ec600d6 | 1414 | |
bba95fef JB |
1415 | dev = cfg80211_get_dev_from_ifindex(ifidx); |
1416 | if (IS_ERR(dev)) { | |
1417 | err = PTR_ERR(dev); | |
3b85875a | 1418 | goto out_rtnl; |
bba95fef JB |
1419 | } |
1420 | ||
1421 | if (!dev->ops->dump_station) { | |
eec60b03 | 1422 | err = -EOPNOTSUPP; |
bba95fef JB |
1423 | goto out_err; |
1424 | } | |
1425 | ||
bba95fef JB |
1426 | while (1) { |
1427 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, | |
1428 | mac_addr, &sinfo); | |
1429 | if (err == -ENOENT) | |
1430 | break; | |
1431 | if (err) | |
3b85875a | 1432 | goto out_err; |
bba95fef JB |
1433 | |
1434 | if (nl80211_send_station(skb, | |
1435 | NETLINK_CB(cb->skb).pid, | |
1436 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
1437 | netdev, mac_addr, | |
1438 | &sinfo) < 0) | |
1439 | goto out; | |
1440 | ||
1441 | sta_idx++; | |
1442 | } | |
1443 | ||
1444 | ||
1445 | out: | |
1446 | cb->args[1] = sta_idx; | |
1447 | err = skb->len; | |
bba95fef JB |
1448 | out_err: |
1449 | cfg80211_put_dev(dev); | |
3b85875a JB |
1450 | out_rtnl: |
1451 | rtnl_unlock(); | |
bba95fef JB |
1452 | |
1453 | return err; | |
2ec600d6 | 1454 | } |
fd5b74dc | 1455 | |
5727ef1b JB |
1456 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
1457 | { | |
fd5b74dc JB |
1458 | struct cfg80211_registered_device *drv; |
1459 | int err; | |
1460 | struct net_device *dev; | |
2ec600d6 | 1461 | struct station_info sinfo; |
fd5b74dc JB |
1462 | struct sk_buff *msg; |
1463 | u8 *mac_addr = NULL; | |
1464 | ||
2ec600d6 | 1465 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
1466 | |
1467 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1468 | return -EINVAL; | |
1469 | ||
1470 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1471 | ||
3b85875a JB |
1472 | rtnl_lock(); |
1473 | ||
bba95fef | 1474 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
fd5b74dc | 1475 | if (err) |
3b85875a | 1476 | goto out_rtnl; |
fd5b74dc JB |
1477 | |
1478 | if (!drv->ops->get_station) { | |
1479 | err = -EOPNOTSUPP; | |
1480 | goto out; | |
1481 | } | |
1482 | ||
2ec600d6 | 1483 | err = drv->ops->get_station(&drv->wiphy, dev, mac_addr, &sinfo); |
2ec600d6 LCC |
1484 | if (err) |
1485 | goto out; | |
1486 | ||
fd5b74dc JB |
1487 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
1488 | if (!msg) | |
1489 | goto out; | |
1490 | ||
1491 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, | |
2ec600d6 | 1492 | dev, mac_addr, &sinfo) < 0) |
fd5b74dc JB |
1493 | goto out_free; |
1494 | ||
1495 | err = genlmsg_unicast(msg, info->snd_pid); | |
1496 | goto out; | |
1497 | ||
1498 | out_free: | |
1499 | nlmsg_free(msg); | |
fd5b74dc JB |
1500 | out: |
1501 | cfg80211_put_dev(drv); | |
1502 | dev_put(dev); | |
3b85875a JB |
1503 | out_rtnl: |
1504 | rtnl_unlock(); | |
1505 | ||
fd5b74dc | 1506 | return err; |
5727ef1b JB |
1507 | } |
1508 | ||
1509 | /* | |
1510 | * Get vlan interface making sure it is on the right wiphy. | |
1511 | */ | |
1512 | static int get_vlan(struct nlattr *vlanattr, | |
1513 | struct cfg80211_registered_device *rdev, | |
1514 | struct net_device **vlan) | |
1515 | { | |
1516 | *vlan = NULL; | |
1517 | ||
1518 | if (vlanattr) { | |
1519 | *vlan = dev_get_by_index(&init_net, nla_get_u32(vlanattr)); | |
1520 | if (!*vlan) | |
1521 | return -ENODEV; | |
1522 | if (!(*vlan)->ieee80211_ptr) | |
1523 | return -EINVAL; | |
1524 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) | |
1525 | return -EINVAL; | |
1526 | } | |
1527 | return 0; | |
1528 | } | |
1529 | ||
1530 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |
1531 | { | |
1532 | struct cfg80211_registered_device *drv; | |
1533 | int err; | |
1534 | struct net_device *dev; | |
1535 | struct station_parameters params; | |
1536 | u8 *mac_addr = NULL; | |
1537 | ||
1538 | memset(¶ms, 0, sizeof(params)); | |
1539 | ||
1540 | params.listen_interval = -1; | |
1541 | ||
1542 | if (info->attrs[NL80211_ATTR_STA_AID]) | |
1543 | return -EINVAL; | |
1544 | ||
1545 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1546 | return -EINVAL; | |
1547 | ||
1548 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1549 | ||
1550 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
1551 | params.supported_rates = | |
1552 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
1553 | params.supported_rates_len = | |
1554 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
1555 | } | |
1556 | ||
1557 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
1558 | params.listen_interval = | |
1559 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
1560 | ||
36aedc90 JM |
1561 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
1562 | params.ht_capa = | |
1563 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
1564 | ||
5727ef1b JB |
1565 | if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS], |
1566 | ¶ms.station_flags)) | |
1567 | return -EINVAL; | |
1568 | ||
2ec600d6 LCC |
1569 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
1570 | params.plink_action = | |
1571 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
1572 | ||
3b85875a JB |
1573 | rtnl_lock(); |
1574 | ||
bba95fef | 1575 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
5727ef1b | 1576 | if (err) |
3b85875a | 1577 | goto out_rtnl; |
5727ef1b JB |
1578 | |
1579 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); | |
1580 | if (err) | |
1581 | goto out; | |
1582 | ||
1583 | if (!drv->ops->change_station) { | |
1584 | err = -EOPNOTSUPP; | |
1585 | goto out; | |
1586 | } | |
1587 | ||
5727ef1b | 1588 | err = drv->ops->change_station(&drv->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
1589 | |
1590 | out: | |
1591 | if (params.vlan) | |
1592 | dev_put(params.vlan); | |
1593 | cfg80211_put_dev(drv); | |
1594 | dev_put(dev); | |
3b85875a JB |
1595 | out_rtnl: |
1596 | rtnl_unlock(); | |
1597 | ||
5727ef1b JB |
1598 | return err; |
1599 | } | |
1600 | ||
1601 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
1602 | { | |
1603 | struct cfg80211_registered_device *drv; | |
1604 | int err; | |
1605 | struct net_device *dev; | |
1606 | struct station_parameters params; | |
1607 | u8 *mac_addr = NULL; | |
1608 | ||
1609 | memset(¶ms, 0, sizeof(params)); | |
1610 | ||
1611 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1612 | return -EINVAL; | |
1613 | ||
1614 | if (!info->attrs[NL80211_ATTR_STA_AID]) | |
1615 | return -EINVAL; | |
1616 | ||
1617 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
1618 | return -EINVAL; | |
1619 | ||
1620 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
1621 | return -EINVAL; | |
1622 | ||
1623 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1624 | params.supported_rates = | |
1625 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
1626 | params.supported_rates_len = | |
1627 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
1628 | params.listen_interval = | |
1629 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
16f2e85d | 1630 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
36aedc90 JM |
1631 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
1632 | params.ht_capa = | |
1633 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b JB |
1634 | |
1635 | if (parse_station_flags(info->attrs[NL80211_ATTR_STA_FLAGS], | |
1636 | ¶ms.station_flags)) | |
1637 | return -EINVAL; | |
1638 | ||
3b85875a JB |
1639 | rtnl_lock(); |
1640 | ||
bba95fef | 1641 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
5727ef1b | 1642 | if (err) |
3b85875a | 1643 | goto out_rtnl; |
5727ef1b JB |
1644 | |
1645 | err = get_vlan(info->attrs[NL80211_ATTR_STA_VLAN], drv, ¶ms.vlan); | |
1646 | if (err) | |
1647 | goto out; | |
1648 | ||
1649 | if (!drv->ops->add_station) { | |
1650 | err = -EOPNOTSUPP; | |
1651 | goto out; | |
1652 | } | |
1653 | ||
35a8efe1 JM |
1654 | if (!netif_running(dev)) { |
1655 | err = -ENETDOWN; | |
1656 | goto out; | |
1657 | } | |
1658 | ||
5727ef1b | 1659 | err = drv->ops->add_station(&drv->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
1660 | |
1661 | out: | |
1662 | if (params.vlan) | |
1663 | dev_put(params.vlan); | |
1664 | cfg80211_put_dev(drv); | |
1665 | dev_put(dev); | |
3b85875a JB |
1666 | out_rtnl: |
1667 | rtnl_unlock(); | |
1668 | ||
5727ef1b JB |
1669 | return err; |
1670 | } | |
1671 | ||
1672 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
1673 | { | |
1674 | struct cfg80211_registered_device *drv; | |
1675 | int err; | |
1676 | struct net_device *dev; | |
1677 | u8 *mac_addr = NULL; | |
1678 | ||
1679 | if (info->attrs[NL80211_ATTR_MAC]) | |
1680 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1681 | ||
3b85875a JB |
1682 | rtnl_lock(); |
1683 | ||
bba95fef | 1684 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
5727ef1b | 1685 | if (err) |
3b85875a | 1686 | goto out_rtnl; |
5727ef1b JB |
1687 | |
1688 | if (!drv->ops->del_station) { | |
1689 | err = -EOPNOTSUPP; | |
1690 | goto out; | |
1691 | } | |
1692 | ||
5727ef1b | 1693 | err = drv->ops->del_station(&drv->wiphy, dev, mac_addr); |
5727ef1b JB |
1694 | |
1695 | out: | |
1696 | cfg80211_put_dev(drv); | |
1697 | dev_put(dev); | |
3b85875a JB |
1698 | out_rtnl: |
1699 | rtnl_unlock(); | |
1700 | ||
5727ef1b JB |
1701 | return err; |
1702 | } | |
1703 | ||
2ec600d6 LCC |
1704 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
1705 | int flags, struct net_device *dev, | |
1706 | u8 *dst, u8 *next_hop, | |
1707 | struct mpath_info *pinfo) | |
1708 | { | |
1709 | void *hdr; | |
1710 | struct nlattr *pinfoattr; | |
1711 | ||
1712 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
1713 | if (!hdr) | |
1714 | return -1; | |
1715 | ||
1716 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
1717 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
1718 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); | |
1719 | ||
1720 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); | |
1721 | if (!pinfoattr) | |
1722 | goto nla_put_failure; | |
1723 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) | |
1724 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
1725 | pinfo->frame_qlen); | |
1726 | if (pinfo->filled & MPATH_INFO_DSN) | |
1727 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DSN, | |
1728 | pinfo->dsn); | |
1729 | if (pinfo->filled & MPATH_INFO_METRIC) | |
1730 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, | |
1731 | pinfo->metric); | |
1732 | if (pinfo->filled & MPATH_INFO_EXPTIME) | |
1733 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, | |
1734 | pinfo->exptime); | |
1735 | if (pinfo->filled & MPATH_INFO_FLAGS) | |
1736 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, | |
1737 | pinfo->flags); | |
1738 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) | |
1739 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
1740 | pinfo->discovery_timeout); | |
1741 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) | |
1742 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
1743 | pinfo->discovery_retries); | |
1744 | ||
1745 | nla_nest_end(msg, pinfoattr); | |
1746 | ||
1747 | return genlmsg_end(msg, hdr); | |
1748 | ||
1749 | nla_put_failure: | |
bc3ed28c TG |
1750 | genlmsg_cancel(msg, hdr); |
1751 | return -EMSGSIZE; | |
2ec600d6 LCC |
1752 | } |
1753 | ||
1754 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 1755 | struct netlink_callback *cb) |
2ec600d6 | 1756 | { |
2ec600d6 LCC |
1757 | struct mpath_info pinfo; |
1758 | struct cfg80211_registered_device *dev; | |
bba95fef | 1759 | struct net_device *netdev; |
2ec600d6 LCC |
1760 | u8 dst[ETH_ALEN]; |
1761 | u8 next_hop[ETH_ALEN]; | |
bba95fef JB |
1762 | int ifidx = cb->args[0]; |
1763 | int path_idx = cb->args[1]; | |
2ec600d6 | 1764 | int err; |
2ec600d6 | 1765 | |
bba95fef JB |
1766 | if (!ifidx) { |
1767 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1768 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
1769 | nl80211_policy); | |
1770 | if (err) | |
1771 | return err; | |
1772 | ||
1773 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
1774 | return -EINVAL; | |
1775 | ||
1776 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
1777 | if (!ifidx) | |
1778 | return -EINVAL; | |
1779 | } | |
1780 | ||
3b85875a JB |
1781 | rtnl_lock(); |
1782 | ||
1783 | netdev = __dev_get_by_index(&init_net, ifidx); | |
1784 | if (!netdev) { | |
1785 | err = -ENODEV; | |
1786 | goto out_rtnl; | |
1787 | } | |
bba95fef JB |
1788 | |
1789 | dev = cfg80211_get_dev_from_ifindex(ifidx); | |
1790 | if (IS_ERR(dev)) { | |
1791 | err = PTR_ERR(dev); | |
3b85875a | 1792 | goto out_rtnl; |
bba95fef JB |
1793 | } |
1794 | ||
1795 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 1796 | err = -EOPNOTSUPP; |
bba95fef JB |
1797 | goto out_err; |
1798 | } | |
1799 | ||
eec60b03 JM |
1800 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
1801 | err = -EOPNOTSUPP; | |
1802 | goto out; | |
1803 | } | |
1804 | ||
bba95fef JB |
1805 | while (1) { |
1806 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, | |
1807 | dst, next_hop, &pinfo); | |
1808 | if (err == -ENOENT) | |
2ec600d6 | 1809 | break; |
bba95fef | 1810 | if (err) |
3b85875a | 1811 | goto out_err; |
2ec600d6 | 1812 | |
bba95fef JB |
1813 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
1814 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
1815 | netdev, dst, next_hop, | |
1816 | &pinfo) < 0) | |
1817 | goto out; | |
2ec600d6 | 1818 | |
bba95fef | 1819 | path_idx++; |
2ec600d6 | 1820 | } |
2ec600d6 | 1821 | |
2ec600d6 | 1822 | |
bba95fef JB |
1823 | out: |
1824 | cb->args[1] = path_idx; | |
1825 | err = skb->len; | |
bba95fef JB |
1826 | out_err: |
1827 | cfg80211_put_dev(dev); | |
3b85875a JB |
1828 | out_rtnl: |
1829 | rtnl_unlock(); | |
bba95fef JB |
1830 | |
1831 | return err; | |
2ec600d6 LCC |
1832 | } |
1833 | ||
1834 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
1835 | { | |
1836 | struct cfg80211_registered_device *drv; | |
1837 | int err; | |
1838 | struct net_device *dev; | |
1839 | struct mpath_info pinfo; | |
1840 | struct sk_buff *msg; | |
1841 | u8 *dst = NULL; | |
1842 | u8 next_hop[ETH_ALEN]; | |
1843 | ||
1844 | memset(&pinfo, 0, sizeof(pinfo)); | |
1845 | ||
1846 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1847 | return -EINVAL; | |
1848 | ||
1849 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1850 | ||
3b85875a JB |
1851 | rtnl_lock(); |
1852 | ||
bba95fef | 1853 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
2ec600d6 | 1854 | if (err) |
3b85875a | 1855 | goto out_rtnl; |
2ec600d6 LCC |
1856 | |
1857 | if (!drv->ops->get_mpath) { | |
1858 | err = -EOPNOTSUPP; | |
1859 | goto out; | |
1860 | } | |
1861 | ||
eec60b03 JM |
1862 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
1863 | err = -EOPNOTSUPP; | |
1864 | goto out; | |
1865 | } | |
1866 | ||
2ec600d6 | 1867 | err = drv->ops->get_mpath(&drv->wiphy, dev, dst, next_hop, &pinfo); |
2ec600d6 LCC |
1868 | if (err) |
1869 | goto out; | |
1870 | ||
1871 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
1872 | if (!msg) | |
1873 | goto out; | |
1874 | ||
1875 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, | |
1876 | dev, dst, next_hop, &pinfo) < 0) | |
1877 | goto out_free; | |
1878 | ||
1879 | err = genlmsg_unicast(msg, info->snd_pid); | |
1880 | goto out; | |
1881 | ||
1882 | out_free: | |
1883 | nlmsg_free(msg); | |
2ec600d6 LCC |
1884 | out: |
1885 | cfg80211_put_dev(drv); | |
1886 | dev_put(dev); | |
3b85875a JB |
1887 | out_rtnl: |
1888 | rtnl_unlock(); | |
1889 | ||
2ec600d6 LCC |
1890 | return err; |
1891 | } | |
1892 | ||
1893 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
1894 | { | |
1895 | struct cfg80211_registered_device *drv; | |
1896 | int err; | |
1897 | struct net_device *dev; | |
1898 | u8 *dst = NULL; | |
1899 | u8 *next_hop = NULL; | |
1900 | ||
1901 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1902 | return -EINVAL; | |
1903 | ||
1904 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
1905 | return -EINVAL; | |
1906 | ||
1907 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1908 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
1909 | ||
3b85875a JB |
1910 | rtnl_lock(); |
1911 | ||
bba95fef | 1912 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
2ec600d6 | 1913 | if (err) |
3b85875a | 1914 | goto out_rtnl; |
2ec600d6 LCC |
1915 | |
1916 | if (!drv->ops->change_mpath) { | |
1917 | err = -EOPNOTSUPP; | |
1918 | goto out; | |
1919 | } | |
1920 | ||
eec60b03 JM |
1921 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
1922 | err = -EOPNOTSUPP; | |
1923 | goto out; | |
1924 | } | |
1925 | ||
35a8efe1 JM |
1926 | if (!netif_running(dev)) { |
1927 | err = -ENETDOWN; | |
1928 | goto out; | |
1929 | } | |
1930 | ||
2ec600d6 | 1931 | err = drv->ops->change_mpath(&drv->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
1932 | |
1933 | out: | |
1934 | cfg80211_put_dev(drv); | |
1935 | dev_put(dev); | |
3b85875a JB |
1936 | out_rtnl: |
1937 | rtnl_unlock(); | |
1938 | ||
2ec600d6 LCC |
1939 | return err; |
1940 | } | |
1941 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) | |
1942 | { | |
1943 | struct cfg80211_registered_device *drv; | |
1944 | int err; | |
1945 | struct net_device *dev; | |
1946 | u8 *dst = NULL; | |
1947 | u8 *next_hop = NULL; | |
1948 | ||
1949 | if (!info->attrs[NL80211_ATTR_MAC]) | |
1950 | return -EINVAL; | |
1951 | ||
1952 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
1953 | return -EINVAL; | |
1954 | ||
1955 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1956 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
1957 | ||
3b85875a JB |
1958 | rtnl_lock(); |
1959 | ||
bba95fef | 1960 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
2ec600d6 | 1961 | if (err) |
3b85875a | 1962 | goto out_rtnl; |
2ec600d6 LCC |
1963 | |
1964 | if (!drv->ops->add_mpath) { | |
1965 | err = -EOPNOTSUPP; | |
1966 | goto out; | |
1967 | } | |
1968 | ||
eec60b03 JM |
1969 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
1970 | err = -EOPNOTSUPP; | |
1971 | goto out; | |
1972 | } | |
1973 | ||
35a8efe1 JM |
1974 | if (!netif_running(dev)) { |
1975 | err = -ENETDOWN; | |
1976 | goto out; | |
1977 | } | |
1978 | ||
2ec600d6 | 1979 | err = drv->ops->add_mpath(&drv->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
1980 | |
1981 | out: | |
1982 | cfg80211_put_dev(drv); | |
1983 | dev_put(dev); | |
3b85875a JB |
1984 | out_rtnl: |
1985 | rtnl_unlock(); | |
1986 | ||
2ec600d6 LCC |
1987 | return err; |
1988 | } | |
1989 | ||
1990 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
1991 | { | |
1992 | struct cfg80211_registered_device *drv; | |
1993 | int err; | |
1994 | struct net_device *dev; | |
1995 | u8 *dst = NULL; | |
1996 | ||
1997 | if (info->attrs[NL80211_ATTR_MAC]) | |
1998 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1999 | ||
3b85875a JB |
2000 | rtnl_lock(); |
2001 | ||
bba95fef | 2002 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
2ec600d6 | 2003 | if (err) |
3b85875a | 2004 | goto out_rtnl; |
2ec600d6 LCC |
2005 | |
2006 | if (!drv->ops->del_mpath) { | |
2007 | err = -EOPNOTSUPP; | |
2008 | goto out; | |
2009 | } | |
2010 | ||
2ec600d6 | 2011 | err = drv->ops->del_mpath(&drv->wiphy, dev, dst); |
2ec600d6 LCC |
2012 | |
2013 | out: | |
2014 | cfg80211_put_dev(drv); | |
2015 | dev_put(dev); | |
3b85875a JB |
2016 | out_rtnl: |
2017 | rtnl_unlock(); | |
2018 | ||
2ec600d6 LCC |
2019 | return err; |
2020 | } | |
2021 | ||
9f1ba906 JM |
2022 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
2023 | { | |
2024 | struct cfg80211_registered_device *drv; | |
2025 | int err; | |
2026 | struct net_device *dev; | |
2027 | struct bss_parameters params; | |
2028 | ||
2029 | memset(¶ms, 0, sizeof(params)); | |
2030 | /* default to not changing parameters */ | |
2031 | params.use_cts_prot = -1; | |
2032 | params.use_short_preamble = -1; | |
2033 | params.use_short_slot_time = -1; | |
2034 | ||
2035 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
2036 | params.use_cts_prot = | |
2037 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
2038 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
2039 | params.use_short_preamble = | |
2040 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
2041 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
2042 | params.use_short_slot_time = | |
2043 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
2044 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
2045 | params.basic_rates = | |
2046 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
2047 | params.basic_rates_len = | |
2048 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
2049 | } | |
9f1ba906 | 2050 | |
3b85875a JB |
2051 | rtnl_lock(); |
2052 | ||
9f1ba906 JM |
2053 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
2054 | if (err) | |
3b85875a | 2055 | goto out_rtnl; |
9f1ba906 JM |
2056 | |
2057 | if (!drv->ops->change_bss) { | |
2058 | err = -EOPNOTSUPP; | |
2059 | goto out; | |
2060 | } | |
2061 | ||
eec60b03 JM |
2062 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP) { |
2063 | err = -EOPNOTSUPP; | |
2064 | goto out; | |
2065 | } | |
2066 | ||
9f1ba906 | 2067 | err = drv->ops->change_bss(&drv->wiphy, dev, ¶ms); |
9f1ba906 JM |
2068 | |
2069 | out: | |
2070 | cfg80211_put_dev(drv); | |
2071 | dev_put(dev); | |
3b85875a JB |
2072 | out_rtnl: |
2073 | rtnl_unlock(); | |
2074 | ||
9f1ba906 JM |
2075 | return err; |
2076 | } | |
2077 | ||
b2e1b302 LR |
2078 | static const struct nla_policy |
2079 | reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | |
2080 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
2081 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
2082 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
2083 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
2084 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
2085 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
2086 | }; | |
2087 | ||
2088 | static int parse_reg_rule(struct nlattr *tb[], | |
2089 | struct ieee80211_reg_rule *reg_rule) | |
2090 | { | |
2091 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
2092 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
2093 | ||
2094 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
2095 | return -EINVAL; | |
2096 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
2097 | return -EINVAL; | |
2098 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
2099 | return -EINVAL; | |
2100 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
2101 | return -EINVAL; | |
2102 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
2103 | return -EINVAL; | |
2104 | ||
2105 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
2106 | ||
2107 | freq_range->start_freq_khz = | |
2108 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
2109 | freq_range->end_freq_khz = | |
2110 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
2111 | freq_range->max_bandwidth_khz = | |
2112 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
2113 | ||
2114 | power_rule->max_eirp = | |
2115 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
2116 | ||
2117 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
2118 | power_rule->max_antenna_gain = | |
2119 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
2120 | ||
2121 | return 0; | |
2122 | } | |
2123 | ||
2124 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
2125 | { | |
2126 | int r; | |
2127 | char *data = NULL; | |
2128 | ||
80778f18 LR |
2129 | /* |
2130 | * You should only get this when cfg80211 hasn't yet initialized | |
2131 | * completely when built-in to the kernel right between the time | |
2132 | * window between nl80211_init() and regulatory_init(), if that is | |
2133 | * even possible. | |
2134 | */ | |
2135 | mutex_lock(&cfg80211_mutex); | |
2136 | if (unlikely(!cfg80211_regdomain)) { | |
fe33eb39 LR |
2137 | mutex_unlock(&cfg80211_mutex); |
2138 | return -EINPROGRESS; | |
80778f18 | 2139 | } |
fe33eb39 | 2140 | mutex_unlock(&cfg80211_mutex); |
80778f18 | 2141 | |
fe33eb39 LR |
2142 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
2143 | return -EINVAL; | |
b2e1b302 LR |
2144 | |
2145 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
2146 | ||
2147 | #ifdef CONFIG_WIRELESS_OLD_REGULATORY | |
2148 | /* We ignore world regdom requests with the old regdom setup */ | |
fe33eb39 LR |
2149 | if (is_world_regdom(data)) |
2150 | return -EINVAL; | |
b2e1b302 | 2151 | #endif |
fe33eb39 LR |
2152 | |
2153 | r = regulatory_hint_user(data); | |
2154 | ||
b2e1b302 LR |
2155 | return r; |
2156 | } | |
2157 | ||
93da9cc1 | 2158 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
2159 | struct genl_info *info) | |
2160 | { | |
2161 | struct cfg80211_registered_device *drv; | |
2162 | struct mesh_config cur_params; | |
2163 | int err; | |
2164 | struct net_device *dev; | |
2165 | void *hdr; | |
2166 | struct nlattr *pinfoattr; | |
2167 | struct sk_buff *msg; | |
2168 | ||
3b85875a JB |
2169 | rtnl_lock(); |
2170 | ||
93da9cc1 | 2171 | /* Look up our device */ |
2172 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); | |
2173 | if (err) | |
3b85875a | 2174 | goto out_rtnl; |
93da9cc1 | 2175 | |
f3f92586 JM |
2176 | if (!drv->ops->get_mesh_params) { |
2177 | err = -EOPNOTSUPP; | |
2178 | goto out; | |
2179 | } | |
2180 | ||
93da9cc1 | 2181 | /* Get the mesh params */ |
93da9cc1 | 2182 | err = drv->ops->get_mesh_params(&drv->wiphy, dev, &cur_params); |
93da9cc1 | 2183 | if (err) |
2184 | goto out; | |
2185 | ||
2186 | /* Draw up a netlink message to send back */ | |
2187 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
2188 | if (!msg) { | |
2189 | err = -ENOBUFS; | |
2190 | goto out; | |
2191 | } | |
2192 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2193 | NL80211_CMD_GET_MESH_PARAMS); | |
2194 | if (!hdr) | |
2195 | goto nla_put_failure; | |
2196 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); | |
2197 | if (!pinfoattr) | |
2198 | goto nla_put_failure; | |
2199 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2200 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
2201 | cur_params.dot11MeshRetryTimeout); | |
2202 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
2203 | cur_params.dot11MeshConfirmTimeout); | |
2204 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
2205 | cur_params.dot11MeshHoldingTimeout); | |
2206 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
2207 | cur_params.dot11MeshMaxPeerLinks); | |
2208 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
2209 | cur_params.dot11MeshMaxRetries); | |
2210 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, | |
2211 | cur_params.dot11MeshTTL); | |
2212 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
2213 | cur_params.auto_open_plinks); | |
2214 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
2215 | cur_params.dot11MeshHWMPmaxPREQretries); | |
2216 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
2217 | cur_params.path_refresh_time); | |
2218 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
2219 | cur_params.min_discovery_timeout); | |
2220 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
2221 | cur_params.dot11MeshHWMPactivePathTimeout); | |
2222 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
2223 | cur_params.dot11MeshHWMPpreqMinInterval); | |
2224 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
2225 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); | |
2226 | nla_nest_end(msg, pinfoattr); | |
2227 | genlmsg_end(msg, hdr); | |
2228 | err = genlmsg_unicast(msg, info->snd_pid); | |
2229 | goto out; | |
2230 | ||
3b85875a | 2231 | nla_put_failure: |
93da9cc1 | 2232 | genlmsg_cancel(msg, hdr); |
2233 | err = -EMSGSIZE; | |
3b85875a | 2234 | out: |
93da9cc1 | 2235 | /* Cleanup */ |
2236 | cfg80211_put_dev(drv); | |
2237 | dev_put(dev); | |
3b85875a JB |
2238 | out_rtnl: |
2239 | rtnl_unlock(); | |
2240 | ||
93da9cc1 | 2241 | return err; |
2242 | } | |
2243 | ||
2244 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ | |
2245 | do {\ | |
2246 | if (table[attr_num]) {\ | |
2247 | cfg.param = nla_fn(table[attr_num]); \ | |
2248 | mask |= (1 << (attr_num - 1)); \ | |
2249 | } \ | |
2250 | } while (0);\ | |
2251 | ||
2252 | static struct nla_policy | |
2253 | nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] __read_mostly = { | |
2254 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, | |
2255 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
2256 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
2257 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
2258 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
2259 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
2260 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, | |
2261 | ||
2262 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | |
2263 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
2264 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
2265 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
2266 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
2267 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | |
2268 | }; | |
2269 | ||
2270 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) | |
2271 | { | |
2272 | int err; | |
2273 | u32 mask; | |
2274 | struct cfg80211_registered_device *drv; | |
2275 | struct net_device *dev; | |
2276 | struct mesh_config cfg; | |
2277 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; | |
2278 | struct nlattr *parent_attr; | |
2279 | ||
2280 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; | |
2281 | if (!parent_attr) | |
2282 | return -EINVAL; | |
2283 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
2284 | parent_attr, nl80211_meshconf_params_policy)) | |
2285 | return -EINVAL; | |
2286 | ||
3b85875a JB |
2287 | rtnl_lock(); |
2288 | ||
93da9cc1 | 2289 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
2290 | if (err) | |
3b85875a | 2291 | goto out_rtnl; |
93da9cc1 | 2292 | |
f3f92586 JM |
2293 | if (!drv->ops->set_mesh_params) { |
2294 | err = -EOPNOTSUPP; | |
2295 | goto out; | |
2296 | } | |
2297 | ||
93da9cc1 | 2298 | /* This makes sure that there aren't more than 32 mesh config |
2299 | * parameters (otherwise our bitfield scheme would not work.) */ | |
2300 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
2301 | ||
2302 | /* Fill in the params struct */ | |
2303 | mask = 0; | |
2304 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, | |
2305 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | |
2306 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, | |
2307 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); | |
2308 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, | |
2309 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); | |
2310 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, | |
2311 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); | |
2312 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, | |
2313 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | |
2314 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, | |
2315 | mask, NL80211_MESHCONF_TTL, nla_get_u8); | |
2316 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, | |
2317 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); | |
2318 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, | |
2319 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
2320 | nla_get_u8); | |
2321 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, | |
2322 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); | |
2323 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, | |
2324 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
2325 | nla_get_u16); | |
2326 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | |
2327 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
2328 | nla_get_u32); | |
2329 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | |
2330 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
2331 | nla_get_u16); | |
2332 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
2333 | dot11MeshHWMPnetDiameterTraversalTime, | |
2334 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
2335 | nla_get_u16); | |
2336 | ||
2337 | /* Apply changes */ | |
93da9cc1 | 2338 | err = drv->ops->set_mesh_params(&drv->wiphy, dev, &cfg, mask); |
93da9cc1 | 2339 | |
f3f92586 | 2340 | out: |
93da9cc1 | 2341 | /* cleanup */ |
2342 | cfg80211_put_dev(drv); | |
2343 | dev_put(dev); | |
3b85875a JB |
2344 | out_rtnl: |
2345 | rtnl_unlock(); | |
2346 | ||
93da9cc1 | 2347 | return err; |
2348 | } | |
2349 | ||
2350 | #undef FILL_IN_MESH_PARAM_IF_SET | |
2351 | ||
f130347c LR |
2352 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
2353 | { | |
2354 | struct sk_buff *msg; | |
2355 | void *hdr = NULL; | |
2356 | struct nlattr *nl_reg_rules; | |
2357 | unsigned int i; | |
2358 | int err = -EINVAL; | |
2359 | ||
a1794390 | 2360 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
2361 | |
2362 | if (!cfg80211_regdomain) | |
2363 | goto out; | |
2364 | ||
2365 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
2366 | if (!msg) { | |
2367 | err = -ENOBUFS; | |
2368 | goto out; | |
2369 | } | |
2370 | ||
2371 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2372 | NL80211_CMD_GET_REG); | |
2373 | if (!hdr) | |
2374 | goto nla_put_failure; | |
2375 | ||
2376 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, | |
2377 | cfg80211_regdomain->alpha2); | |
2378 | ||
2379 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | |
2380 | if (!nl_reg_rules) | |
2381 | goto nla_put_failure; | |
2382 | ||
2383 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { | |
2384 | struct nlattr *nl_reg_rule; | |
2385 | const struct ieee80211_reg_rule *reg_rule; | |
2386 | const struct ieee80211_freq_range *freq_range; | |
2387 | const struct ieee80211_power_rule *power_rule; | |
2388 | ||
2389 | reg_rule = &cfg80211_regdomain->reg_rules[i]; | |
2390 | freq_range = ®_rule->freq_range; | |
2391 | power_rule = ®_rule->power_rule; | |
2392 | ||
2393 | nl_reg_rule = nla_nest_start(msg, i); | |
2394 | if (!nl_reg_rule) | |
2395 | goto nla_put_failure; | |
2396 | ||
2397 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, | |
2398 | reg_rule->flags); | |
2399 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
2400 | freq_range->start_freq_khz); | |
2401 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
2402 | freq_range->end_freq_khz); | |
2403 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
2404 | freq_range->max_bandwidth_khz); | |
2405 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
2406 | power_rule->max_antenna_gain); | |
2407 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
2408 | power_rule->max_eirp); | |
2409 | ||
2410 | nla_nest_end(msg, nl_reg_rule); | |
2411 | } | |
2412 | ||
2413 | nla_nest_end(msg, nl_reg_rules); | |
2414 | ||
2415 | genlmsg_end(msg, hdr); | |
2416 | err = genlmsg_unicast(msg, info->snd_pid); | |
2417 | goto out; | |
2418 | ||
2419 | nla_put_failure: | |
2420 | genlmsg_cancel(msg, hdr); | |
2421 | err = -EMSGSIZE; | |
2422 | out: | |
a1794390 | 2423 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
2424 | return err; |
2425 | } | |
2426 | ||
b2e1b302 LR |
2427 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
2428 | { | |
2429 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
2430 | struct nlattr *nl_reg_rule; | |
2431 | char *alpha2 = NULL; | |
2432 | int rem_reg_rules = 0, r = 0; | |
2433 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
2434 | struct ieee80211_regdomain *rd = NULL; | |
2435 | ||
2436 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
2437 | return -EINVAL; | |
2438 | ||
2439 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
2440 | return -EINVAL; | |
2441 | ||
2442 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
2443 | ||
2444 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | |
2445 | rem_reg_rules) { | |
2446 | num_rules++; | |
2447 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
2448 | goto bad_reg; | |
2449 | } | |
2450 | ||
2451 | if (!reg_is_valid_request(alpha2)) | |
2452 | return -EINVAL; | |
2453 | ||
2454 | size_of_regd = sizeof(struct ieee80211_regdomain) + | |
2455 | (num_rules * sizeof(struct ieee80211_reg_rule)); | |
2456 | ||
2457 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
2458 | if (!rd) | |
2459 | return -ENOMEM; | |
2460 | ||
2461 | rd->n_reg_rules = num_rules; | |
2462 | rd->alpha2[0] = alpha2[0]; | |
2463 | rd->alpha2[1] = alpha2[1]; | |
2464 | ||
2465 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | |
2466 | rem_reg_rules) { | |
2467 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, | |
2468 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
2469 | reg_rule_policy); | |
2470 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | |
2471 | if (r) | |
2472 | goto bad_reg; | |
2473 | ||
2474 | rule_idx++; | |
2475 | ||
2476 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) | |
2477 | goto bad_reg; | |
2478 | } | |
2479 | ||
2480 | BUG_ON(rule_idx != num_rules); | |
2481 | ||
a1794390 | 2482 | mutex_lock(&cfg80211_mutex); |
b2e1b302 | 2483 | r = set_regdom(rd); |
a1794390 | 2484 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 LR |
2485 | return r; |
2486 | ||
d2372b31 | 2487 | bad_reg: |
b2e1b302 LR |
2488 | kfree(rd); |
2489 | return -EINVAL; | |
2490 | } | |
2491 | ||
2a519311 JB |
2492 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
2493 | { | |
2494 | struct cfg80211_registered_device *drv; | |
2495 | struct net_device *dev; | |
2496 | struct cfg80211_scan_request *request; | |
2497 | struct cfg80211_ssid *ssid; | |
2498 | struct ieee80211_channel *channel; | |
2499 | struct nlattr *attr; | |
2500 | struct wiphy *wiphy; | |
2501 | int err, tmp, n_ssids = 0, n_channels = 0, i; | |
2502 | enum ieee80211_band band; | |
70692ad2 | 2503 | size_t ie_len; |
2a519311 | 2504 | |
f4a11bb0 JB |
2505 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
2506 | return -EINVAL; | |
2507 | ||
3b85875a JB |
2508 | rtnl_lock(); |
2509 | ||
2a519311 JB |
2510 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); |
2511 | if (err) | |
3b85875a | 2512 | goto out_rtnl; |
2a519311 JB |
2513 | |
2514 | wiphy = &drv->wiphy; | |
2515 | ||
2516 | if (!drv->ops->scan) { | |
2517 | err = -EOPNOTSUPP; | |
2518 | goto out; | |
2519 | } | |
2520 | ||
35a8efe1 JM |
2521 | if (!netif_running(dev)) { |
2522 | err = -ENETDOWN; | |
2523 | goto out; | |
2524 | } | |
2525 | ||
2a519311 JB |
2526 | if (drv->scan_req) { |
2527 | err = -EBUSY; | |
3b85875a | 2528 | goto out; |
2a519311 JB |
2529 | } |
2530 | ||
2531 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
2532 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) | |
2533 | n_channels++; | |
2534 | if (!n_channels) { | |
2535 | err = -EINVAL; | |
3b85875a | 2536 | goto out; |
2a519311 JB |
2537 | } |
2538 | } else { | |
2539 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) | |
2540 | if (wiphy->bands[band]) | |
2541 | n_channels += wiphy->bands[band]->n_channels; | |
2542 | } | |
2543 | ||
2544 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
2545 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
2546 | n_ssids++; | |
2547 | ||
2548 | if (n_ssids > wiphy->max_scan_ssids) { | |
2549 | err = -EINVAL; | |
3b85875a | 2550 | goto out; |
2a519311 JB |
2551 | } |
2552 | ||
70692ad2 JM |
2553 | if (info->attrs[NL80211_ATTR_IE]) |
2554 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
2555 | else | |
2556 | ie_len = 0; | |
2557 | ||
18a83659 JB |
2558 | if (ie_len > wiphy->max_scan_ie_len) { |
2559 | err = -EINVAL; | |
2560 | goto out; | |
2561 | } | |
2562 | ||
2a519311 JB |
2563 | request = kzalloc(sizeof(*request) |
2564 | + sizeof(*ssid) * n_ssids | |
70692ad2 JM |
2565 | + sizeof(channel) * n_channels |
2566 | + ie_len, GFP_KERNEL); | |
2a519311 JB |
2567 | if (!request) { |
2568 | err = -ENOMEM; | |
3b85875a | 2569 | goto out; |
2a519311 JB |
2570 | } |
2571 | ||
2572 | request->channels = (void *)((char *)request + sizeof(*request)); | |
2573 | request->n_channels = n_channels; | |
2574 | if (n_ssids) | |
2575 | request->ssids = (void *)(request->channels + n_channels); | |
2576 | request->n_ssids = n_ssids; | |
70692ad2 JM |
2577 | if (ie_len) { |
2578 | if (request->ssids) | |
2579 | request->ie = (void *)(request->ssids + n_ssids); | |
2580 | else | |
2581 | request->ie = (void *)(request->channels + n_channels); | |
2582 | } | |
2a519311 JB |
2583 | |
2584 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
2585 | /* user specified, bail out if channel not found */ | |
2586 | request->n_channels = n_channels; | |
2587 | i = 0; | |
2588 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { | |
2589 | request->channels[i] = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
2590 | if (!request->channels[i]) { | |
2591 | err = -EINVAL; | |
2592 | goto out_free; | |
2593 | } | |
2594 | i++; | |
2595 | } | |
2596 | } else { | |
2597 | /* all channels */ | |
2598 | i = 0; | |
2599 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
2600 | int j; | |
2601 | if (!wiphy->bands[band]) | |
2602 | continue; | |
2603 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
2604 | request->channels[i] = &wiphy->bands[band]->channels[j]; | |
2605 | i++; | |
2606 | } | |
2607 | } | |
2608 | } | |
2609 | ||
2610 | i = 0; | |
2611 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
2612 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
2613 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { | |
2614 | err = -EINVAL; | |
2615 | goto out_free; | |
2616 | } | |
2617 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); | |
2618 | request->ssids[i].ssid_len = nla_len(attr); | |
2619 | i++; | |
2620 | } | |
2621 | } | |
2622 | ||
70692ad2 JM |
2623 | if (info->attrs[NL80211_ATTR_IE]) { |
2624 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
2625 | memcpy((void *)request->ie, |
2626 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
2627 | request->ie_len); |
2628 | } | |
2629 | ||
2a519311 JB |
2630 | request->ifidx = dev->ifindex; |
2631 | request->wiphy = &drv->wiphy; | |
2632 | ||
2633 | drv->scan_req = request; | |
2634 | err = drv->ops->scan(&drv->wiphy, dev, request); | |
2635 | ||
2636 | out_free: | |
2637 | if (err) { | |
2638 | drv->scan_req = NULL; | |
2639 | kfree(request); | |
2640 | } | |
2a519311 JB |
2641 | out: |
2642 | cfg80211_put_dev(drv); | |
2643 | dev_put(dev); | |
3b85875a JB |
2644 | out_rtnl: |
2645 | rtnl_unlock(); | |
2646 | ||
2a519311 JB |
2647 | return err; |
2648 | } | |
2649 | ||
2650 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
2651 | struct cfg80211_registered_device *rdev, | |
2652 | struct net_device *dev, | |
2653 | struct cfg80211_bss *res) | |
2654 | { | |
2655 | void *hdr; | |
2656 | struct nlattr *bss; | |
2657 | ||
2658 | hdr = nl80211hdr_put(msg, pid, seq, flags, | |
2659 | NL80211_CMD_NEW_SCAN_RESULTS); | |
2660 | if (!hdr) | |
2661 | return -1; | |
2662 | ||
2663 | NLA_PUT_U32(msg, NL80211_ATTR_SCAN_GENERATION, | |
2664 | rdev->bss_generation); | |
2665 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2666 | ||
2667 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
2668 | if (!bss) | |
2669 | goto nla_put_failure; | |
2670 | if (!is_zero_ether_addr(res->bssid)) | |
2671 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); | |
2672 | if (res->information_elements && res->len_information_elements) | |
2673 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
2674 | res->len_information_elements, | |
2675 | res->information_elements); | |
2676 | if (res->tsf) | |
2677 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); | |
2678 | if (res->beacon_interval) | |
2679 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); | |
2680 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); | |
2681 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); | |
2682 | ||
77965c97 | 2683 | switch (rdev->wiphy.signal_type) { |
2a519311 JB |
2684 | case CFG80211_SIGNAL_TYPE_MBM: |
2685 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); | |
2686 | break; | |
2687 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
2688 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); | |
2689 | break; | |
2690 | default: | |
2691 | break; | |
2692 | } | |
2693 | ||
2694 | nla_nest_end(msg, bss); | |
2695 | ||
2696 | return genlmsg_end(msg, hdr); | |
2697 | ||
2698 | nla_put_failure: | |
2699 | genlmsg_cancel(msg, hdr); | |
2700 | return -EMSGSIZE; | |
2701 | } | |
2702 | ||
2703 | static int nl80211_dump_scan(struct sk_buff *skb, | |
2704 | struct netlink_callback *cb) | |
2705 | { | |
2706 | struct cfg80211_registered_device *dev; | |
2707 | struct net_device *netdev; | |
2708 | struct cfg80211_internal_bss *scan; | |
2709 | int ifidx = cb->args[0]; | |
2710 | int start = cb->args[1], idx = 0; | |
2711 | int err; | |
2712 | ||
2713 | if (!ifidx) { | |
2714 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
2715 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
2716 | nl80211_policy); | |
2717 | if (err) | |
2718 | return err; | |
2719 | ||
2720 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
2721 | return -EINVAL; | |
2722 | ||
2723 | ifidx = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
2724 | if (!ifidx) | |
2725 | return -EINVAL; | |
2726 | cb->args[0] = ifidx; | |
2727 | } | |
2728 | ||
2729 | netdev = dev_get_by_index(&init_net, ifidx); | |
2730 | if (!netdev) | |
2731 | return -ENODEV; | |
2732 | ||
2733 | dev = cfg80211_get_dev_from_ifindex(ifidx); | |
2734 | if (IS_ERR(dev)) { | |
2735 | err = PTR_ERR(dev); | |
2736 | goto out_put_netdev; | |
2737 | } | |
2738 | ||
2739 | spin_lock_bh(&dev->bss_lock); | |
2740 | cfg80211_bss_expire(dev); | |
2741 | ||
2742 | list_for_each_entry(scan, &dev->bss_list, list) { | |
2743 | if (++idx <= start) | |
2744 | continue; | |
2745 | if (nl80211_send_bss(skb, | |
2746 | NETLINK_CB(cb->skb).pid, | |
2747 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
2748 | dev, netdev, &scan->pub) < 0) { | |
2749 | idx--; | |
2750 | goto out; | |
2751 | } | |
2752 | } | |
2753 | ||
2754 | out: | |
2755 | spin_unlock_bh(&dev->bss_lock); | |
2756 | ||
2757 | cb->args[1] = idx; | |
2758 | err = skb->len; | |
2759 | cfg80211_put_dev(dev); | |
2760 | out_put_netdev: | |
2761 | dev_put(netdev); | |
2762 | ||
2763 | return err; | |
2764 | } | |
2765 | ||
255e737e JM |
2766 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
2767 | { | |
2768 | return auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM || | |
2769 | auth_type == NL80211_AUTHTYPE_SHARED_KEY || | |
2770 | auth_type == NL80211_AUTHTYPE_FT || | |
2771 | auth_type == NL80211_AUTHTYPE_NETWORK_EAP; | |
2772 | } | |
2773 | ||
636a5d36 JM |
2774 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
2775 | { | |
2776 | struct cfg80211_registered_device *drv; | |
2777 | struct net_device *dev; | |
2778 | struct cfg80211_auth_request req; | |
2779 | struct wiphy *wiphy; | |
2780 | int err; | |
2781 | ||
f4a11bb0 JB |
2782 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
2783 | return -EINVAL; | |
2784 | ||
2785 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2786 | return -EINVAL; | |
2787 | ||
1778092e JM |
2788 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
2789 | return -EINVAL; | |
2790 | ||
636a5d36 JM |
2791 | rtnl_lock(); |
2792 | ||
2793 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); | |
2794 | if (err) | |
2795 | goto unlock_rtnl; | |
2796 | ||
2797 | if (!drv->ops->auth) { | |
2798 | err = -EOPNOTSUPP; | |
2799 | goto out; | |
2800 | } | |
2801 | ||
eec60b03 JM |
2802 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
2803 | err = -EOPNOTSUPP; | |
2804 | goto out; | |
2805 | } | |
2806 | ||
35a8efe1 JM |
2807 | if (!netif_running(dev)) { |
2808 | err = -ENETDOWN; | |
2809 | goto out; | |
2810 | } | |
2811 | ||
636a5d36 JM |
2812 | wiphy = &drv->wiphy; |
2813 | memset(&req, 0, sizeof(req)); | |
2814 | ||
2815 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2816 | ||
2817 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
2818 | req.chan = ieee80211_get_channel( | |
2819 | wiphy, | |
2820 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
2821 | if (!req.chan) { | |
2822 | err = -EINVAL; | |
2823 | goto out; | |
2824 | } | |
2825 | } | |
2826 | ||
2827 | if (info->attrs[NL80211_ATTR_SSID]) { | |
2828 | req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
2829 | req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
2830 | } | |
2831 | ||
2832 | if (info->attrs[NL80211_ATTR_IE]) { | |
2833 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
2834 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
2835 | } | |
2836 | ||
1778092e JM |
2837 | req.auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
2838 | if (!nl80211_valid_auth_type(req.auth_type)) { | |
2839 | err = -EINVAL; | |
2840 | goto out; | |
636a5d36 JM |
2841 | } |
2842 | ||
2843 | err = drv->ops->auth(&drv->wiphy, dev, &req); | |
2844 | ||
2845 | out: | |
2846 | cfg80211_put_dev(drv); | |
2847 | dev_put(dev); | |
2848 | unlock_rtnl: | |
2849 | rtnl_unlock(); | |
2850 | return err; | |
2851 | } | |
2852 | ||
2853 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) | |
2854 | { | |
2855 | struct cfg80211_registered_device *drv; | |
2856 | struct net_device *dev; | |
2857 | struct cfg80211_assoc_request req; | |
2858 | struct wiphy *wiphy; | |
2859 | int err; | |
2860 | ||
f4a11bb0 JB |
2861 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
2862 | return -EINVAL; | |
2863 | ||
2864 | if (!info->attrs[NL80211_ATTR_MAC] || | |
2865 | !info->attrs[NL80211_ATTR_SSID]) | |
2866 | return -EINVAL; | |
2867 | ||
636a5d36 JM |
2868 | rtnl_lock(); |
2869 | ||
2870 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); | |
2871 | if (err) | |
2872 | goto unlock_rtnl; | |
2873 | ||
2874 | if (!drv->ops->assoc) { | |
2875 | err = -EOPNOTSUPP; | |
2876 | goto out; | |
2877 | } | |
2878 | ||
eec60b03 JM |
2879 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
2880 | err = -EOPNOTSUPP; | |
2881 | goto out; | |
2882 | } | |
2883 | ||
35a8efe1 JM |
2884 | if (!netif_running(dev)) { |
2885 | err = -ENETDOWN; | |
2886 | goto out; | |
2887 | } | |
2888 | ||
636a5d36 JM |
2889 | wiphy = &drv->wiphy; |
2890 | memset(&req, 0, sizeof(req)); | |
2891 | ||
2892 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2893 | ||
2894 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
2895 | req.chan = ieee80211_get_channel( | |
2896 | wiphy, | |
2897 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
2898 | if (!req.chan) { | |
2899 | err = -EINVAL; | |
2900 | goto out; | |
2901 | } | |
2902 | } | |
2903 | ||
636a5d36 JM |
2904 | req.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
2905 | req.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
2906 | ||
2907 | if (info->attrs[NL80211_ATTR_IE]) { | |
2908 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
2909 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
2910 | } | |
2911 | ||
2912 | err = drv->ops->assoc(&drv->wiphy, dev, &req); | |
2913 | ||
2914 | out: | |
2915 | cfg80211_put_dev(drv); | |
2916 | dev_put(dev); | |
2917 | unlock_rtnl: | |
2918 | rtnl_unlock(); | |
2919 | return err; | |
2920 | } | |
2921 | ||
2922 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
2923 | { | |
2924 | struct cfg80211_registered_device *drv; | |
2925 | struct net_device *dev; | |
2926 | struct cfg80211_deauth_request req; | |
2927 | struct wiphy *wiphy; | |
2928 | int err; | |
2929 | ||
f4a11bb0 JB |
2930 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
2931 | return -EINVAL; | |
2932 | ||
2933 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2934 | return -EINVAL; | |
2935 | ||
2936 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
2937 | return -EINVAL; | |
2938 | ||
636a5d36 JM |
2939 | rtnl_lock(); |
2940 | ||
2941 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); | |
2942 | if (err) | |
2943 | goto unlock_rtnl; | |
2944 | ||
2945 | if (!drv->ops->deauth) { | |
2946 | err = -EOPNOTSUPP; | |
2947 | goto out; | |
2948 | } | |
2949 | ||
eec60b03 JM |
2950 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
2951 | err = -EOPNOTSUPP; | |
2952 | goto out; | |
2953 | } | |
2954 | ||
35a8efe1 JM |
2955 | if (!netif_running(dev)) { |
2956 | err = -ENETDOWN; | |
2957 | goto out; | |
2958 | } | |
2959 | ||
636a5d36 JM |
2960 | wiphy = &drv->wiphy; |
2961 | memset(&req, 0, sizeof(req)); | |
2962 | ||
2963 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2964 | ||
f4a11bb0 JB |
2965 | req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
2966 | if (req.reason_code == 0) { | |
2967 | /* Reason Code 0 is reserved */ | |
2968 | err = -EINVAL; | |
2969 | goto out; | |
255e737e | 2970 | } |
636a5d36 JM |
2971 | |
2972 | if (info->attrs[NL80211_ATTR_IE]) { | |
2973 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
2974 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
2975 | } | |
2976 | ||
2977 | err = drv->ops->deauth(&drv->wiphy, dev, &req); | |
2978 | ||
2979 | out: | |
2980 | cfg80211_put_dev(drv); | |
2981 | dev_put(dev); | |
2982 | unlock_rtnl: | |
2983 | rtnl_unlock(); | |
2984 | return err; | |
2985 | } | |
2986 | ||
2987 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
2988 | { | |
2989 | struct cfg80211_registered_device *drv; | |
2990 | struct net_device *dev; | |
2991 | struct cfg80211_disassoc_request req; | |
2992 | struct wiphy *wiphy; | |
2993 | int err; | |
2994 | ||
f4a11bb0 JB |
2995 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
2996 | return -EINVAL; | |
2997 | ||
2998 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2999 | return -EINVAL; | |
3000 | ||
3001 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
3002 | return -EINVAL; | |
3003 | ||
636a5d36 JM |
3004 | rtnl_lock(); |
3005 | ||
3006 | err = get_drv_dev_by_info_ifindex(info->attrs, &drv, &dev); | |
3007 | if (err) | |
3008 | goto unlock_rtnl; | |
3009 | ||
3010 | if (!drv->ops->disassoc) { | |
3011 | err = -EOPNOTSUPP; | |
3012 | goto out; | |
3013 | } | |
3014 | ||
eec60b03 JM |
3015 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION) { |
3016 | err = -EOPNOTSUPP; | |
3017 | goto out; | |
3018 | } | |
3019 | ||
35a8efe1 JM |
3020 | if (!netif_running(dev)) { |
3021 | err = -ENETDOWN; | |
3022 | goto out; | |
3023 | } | |
3024 | ||
636a5d36 JM |
3025 | wiphy = &drv->wiphy; |
3026 | memset(&req, 0, sizeof(req)); | |
3027 | ||
3028 | req.peer_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3029 | ||
f4a11bb0 JB |
3030 | req.reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
3031 | if (req.reason_code == 0) { | |
3032 | /* Reason Code 0 is reserved */ | |
3033 | err = -EINVAL; | |
3034 | goto out; | |
255e737e | 3035 | } |
636a5d36 JM |
3036 | |
3037 | if (info->attrs[NL80211_ATTR_IE]) { | |
3038 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
3039 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3040 | } | |
3041 | ||
3042 | err = drv->ops->disassoc(&drv->wiphy, dev, &req); | |
3043 | ||
3044 | out: | |
3045 | cfg80211_put_dev(drv); | |
3046 | dev_put(dev); | |
3047 | unlock_rtnl: | |
3048 | rtnl_unlock(); | |
3049 | return err; | |
3050 | } | |
3051 | ||
55682965 JB |
3052 | static struct genl_ops nl80211_ops[] = { |
3053 | { | |
3054 | .cmd = NL80211_CMD_GET_WIPHY, | |
3055 | .doit = nl80211_get_wiphy, | |
3056 | .dumpit = nl80211_dump_wiphy, | |
3057 | .policy = nl80211_policy, | |
3058 | /* can be retrieved by unprivileged users */ | |
3059 | }, | |
3060 | { | |
3061 | .cmd = NL80211_CMD_SET_WIPHY, | |
3062 | .doit = nl80211_set_wiphy, | |
3063 | .policy = nl80211_policy, | |
3064 | .flags = GENL_ADMIN_PERM, | |
3065 | }, | |
3066 | { | |
3067 | .cmd = NL80211_CMD_GET_INTERFACE, | |
3068 | .doit = nl80211_get_interface, | |
3069 | .dumpit = nl80211_dump_interface, | |
3070 | .policy = nl80211_policy, | |
3071 | /* can be retrieved by unprivileged users */ | |
3072 | }, | |
3073 | { | |
3074 | .cmd = NL80211_CMD_SET_INTERFACE, | |
3075 | .doit = nl80211_set_interface, | |
3076 | .policy = nl80211_policy, | |
3077 | .flags = GENL_ADMIN_PERM, | |
3078 | }, | |
3079 | { | |
3080 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
3081 | .doit = nl80211_new_interface, | |
3082 | .policy = nl80211_policy, | |
3083 | .flags = GENL_ADMIN_PERM, | |
3084 | }, | |
3085 | { | |
3086 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
3087 | .doit = nl80211_del_interface, | |
3088 | .policy = nl80211_policy, | |
41ade00f JB |
3089 | .flags = GENL_ADMIN_PERM, |
3090 | }, | |
3091 | { | |
3092 | .cmd = NL80211_CMD_GET_KEY, | |
3093 | .doit = nl80211_get_key, | |
3094 | .policy = nl80211_policy, | |
3095 | .flags = GENL_ADMIN_PERM, | |
3096 | }, | |
3097 | { | |
3098 | .cmd = NL80211_CMD_SET_KEY, | |
3099 | .doit = nl80211_set_key, | |
3100 | .policy = nl80211_policy, | |
3101 | .flags = GENL_ADMIN_PERM, | |
3102 | }, | |
3103 | { | |
3104 | .cmd = NL80211_CMD_NEW_KEY, | |
3105 | .doit = nl80211_new_key, | |
3106 | .policy = nl80211_policy, | |
3107 | .flags = GENL_ADMIN_PERM, | |
3108 | }, | |
3109 | { | |
3110 | .cmd = NL80211_CMD_DEL_KEY, | |
3111 | .doit = nl80211_del_key, | |
3112 | .policy = nl80211_policy, | |
55682965 JB |
3113 | .flags = GENL_ADMIN_PERM, |
3114 | }, | |
ed1b6cc7 JB |
3115 | { |
3116 | .cmd = NL80211_CMD_SET_BEACON, | |
3117 | .policy = nl80211_policy, | |
3118 | .flags = GENL_ADMIN_PERM, | |
3119 | .doit = nl80211_addset_beacon, | |
3120 | }, | |
3121 | { | |
3122 | .cmd = NL80211_CMD_NEW_BEACON, | |
3123 | .policy = nl80211_policy, | |
3124 | .flags = GENL_ADMIN_PERM, | |
3125 | .doit = nl80211_addset_beacon, | |
3126 | }, | |
3127 | { | |
3128 | .cmd = NL80211_CMD_DEL_BEACON, | |
3129 | .policy = nl80211_policy, | |
3130 | .flags = GENL_ADMIN_PERM, | |
3131 | .doit = nl80211_del_beacon, | |
3132 | }, | |
5727ef1b JB |
3133 | { |
3134 | .cmd = NL80211_CMD_GET_STATION, | |
3135 | .doit = nl80211_get_station, | |
2ec600d6 | 3136 | .dumpit = nl80211_dump_station, |
5727ef1b | 3137 | .policy = nl80211_policy, |
5727ef1b JB |
3138 | }, |
3139 | { | |
3140 | .cmd = NL80211_CMD_SET_STATION, | |
3141 | .doit = nl80211_set_station, | |
3142 | .policy = nl80211_policy, | |
3143 | .flags = GENL_ADMIN_PERM, | |
3144 | }, | |
3145 | { | |
3146 | .cmd = NL80211_CMD_NEW_STATION, | |
3147 | .doit = nl80211_new_station, | |
3148 | .policy = nl80211_policy, | |
3149 | .flags = GENL_ADMIN_PERM, | |
3150 | }, | |
3151 | { | |
3152 | .cmd = NL80211_CMD_DEL_STATION, | |
3153 | .doit = nl80211_del_station, | |
3154 | .policy = nl80211_policy, | |
2ec600d6 LCC |
3155 | .flags = GENL_ADMIN_PERM, |
3156 | }, | |
3157 | { | |
3158 | .cmd = NL80211_CMD_GET_MPATH, | |
3159 | .doit = nl80211_get_mpath, | |
3160 | .dumpit = nl80211_dump_mpath, | |
3161 | .policy = nl80211_policy, | |
3162 | .flags = GENL_ADMIN_PERM, | |
3163 | }, | |
3164 | { | |
3165 | .cmd = NL80211_CMD_SET_MPATH, | |
3166 | .doit = nl80211_set_mpath, | |
3167 | .policy = nl80211_policy, | |
3168 | .flags = GENL_ADMIN_PERM, | |
3169 | }, | |
3170 | { | |
3171 | .cmd = NL80211_CMD_NEW_MPATH, | |
3172 | .doit = nl80211_new_mpath, | |
3173 | .policy = nl80211_policy, | |
3174 | .flags = GENL_ADMIN_PERM, | |
3175 | }, | |
3176 | { | |
3177 | .cmd = NL80211_CMD_DEL_MPATH, | |
3178 | .doit = nl80211_del_mpath, | |
3179 | .policy = nl80211_policy, | |
9f1ba906 JM |
3180 | .flags = GENL_ADMIN_PERM, |
3181 | }, | |
3182 | { | |
3183 | .cmd = NL80211_CMD_SET_BSS, | |
3184 | .doit = nl80211_set_bss, | |
3185 | .policy = nl80211_policy, | |
b2e1b302 LR |
3186 | .flags = GENL_ADMIN_PERM, |
3187 | }, | |
f130347c LR |
3188 | { |
3189 | .cmd = NL80211_CMD_GET_REG, | |
3190 | .doit = nl80211_get_reg, | |
3191 | .policy = nl80211_policy, | |
3192 | /* can be retrieved by unprivileged users */ | |
3193 | }, | |
b2e1b302 LR |
3194 | { |
3195 | .cmd = NL80211_CMD_SET_REG, | |
3196 | .doit = nl80211_set_reg, | |
3197 | .policy = nl80211_policy, | |
3198 | .flags = GENL_ADMIN_PERM, | |
3199 | }, | |
3200 | { | |
3201 | .cmd = NL80211_CMD_REQ_SET_REG, | |
3202 | .doit = nl80211_req_set_reg, | |
3203 | .policy = nl80211_policy, | |
93da9cc1 | 3204 | .flags = GENL_ADMIN_PERM, |
3205 | }, | |
3206 | { | |
3207 | .cmd = NL80211_CMD_GET_MESH_PARAMS, | |
3208 | .doit = nl80211_get_mesh_params, | |
3209 | .policy = nl80211_policy, | |
3210 | /* can be retrieved by unprivileged users */ | |
3211 | }, | |
3212 | { | |
3213 | .cmd = NL80211_CMD_SET_MESH_PARAMS, | |
3214 | .doit = nl80211_set_mesh_params, | |
3215 | .policy = nl80211_policy, | |
9aed3cc1 JM |
3216 | .flags = GENL_ADMIN_PERM, |
3217 | }, | |
2a519311 JB |
3218 | { |
3219 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
3220 | .doit = nl80211_trigger_scan, | |
3221 | .policy = nl80211_policy, | |
3222 | .flags = GENL_ADMIN_PERM, | |
3223 | }, | |
3224 | { | |
3225 | .cmd = NL80211_CMD_GET_SCAN, | |
3226 | .policy = nl80211_policy, | |
3227 | .dumpit = nl80211_dump_scan, | |
3228 | }, | |
636a5d36 JM |
3229 | { |
3230 | .cmd = NL80211_CMD_AUTHENTICATE, | |
3231 | .doit = nl80211_authenticate, | |
3232 | .policy = nl80211_policy, | |
3233 | .flags = GENL_ADMIN_PERM, | |
3234 | }, | |
3235 | { | |
3236 | .cmd = NL80211_CMD_ASSOCIATE, | |
3237 | .doit = nl80211_associate, | |
3238 | .policy = nl80211_policy, | |
3239 | .flags = GENL_ADMIN_PERM, | |
3240 | }, | |
3241 | { | |
3242 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
3243 | .doit = nl80211_deauthenticate, | |
3244 | .policy = nl80211_policy, | |
3245 | .flags = GENL_ADMIN_PERM, | |
3246 | }, | |
3247 | { | |
3248 | .cmd = NL80211_CMD_DISASSOCIATE, | |
3249 | .doit = nl80211_disassociate, | |
3250 | .policy = nl80211_policy, | |
3251 | .flags = GENL_ADMIN_PERM, | |
3252 | }, | |
55682965 | 3253 | }; |
6039f6d2 JM |
3254 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
3255 | .name = "mlme", | |
3256 | }; | |
55682965 JB |
3257 | |
3258 | /* multicast groups */ | |
3259 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
3260 | .name = "config", | |
3261 | }; | |
2a519311 JB |
3262 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
3263 | .name = "scan", | |
3264 | }; | |
73d54c9e LR |
3265 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
3266 | .name = "regulatory", | |
3267 | }; | |
55682965 JB |
3268 | |
3269 | /* notification functions */ | |
3270 | ||
3271 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
3272 | { | |
3273 | struct sk_buff *msg; | |
3274 | ||
3275 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
3276 | if (!msg) | |
3277 | return; | |
3278 | ||
3279 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { | |
3280 | nlmsg_free(msg); | |
3281 | return; | |
3282 | } | |
3283 | ||
3284 | genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL); | |
3285 | } | |
3286 | ||
2a519311 JB |
3287 | static int nl80211_send_scan_donemsg(struct sk_buff *msg, |
3288 | struct cfg80211_registered_device *rdev, | |
3289 | struct net_device *netdev, | |
3290 | u32 pid, u32 seq, int flags, | |
3291 | u32 cmd) | |
3292 | { | |
3293 | void *hdr; | |
3294 | ||
3295 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
3296 | if (!hdr) | |
3297 | return -1; | |
3298 | ||
b5850a7a | 3299 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
2a519311 JB |
3300 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
3301 | ||
3302 | /* XXX: we should probably bounce back the request? */ | |
3303 | ||
3304 | return genlmsg_end(msg, hdr); | |
3305 | ||
3306 | nla_put_failure: | |
3307 | genlmsg_cancel(msg, hdr); | |
3308 | return -EMSGSIZE; | |
3309 | } | |
3310 | ||
3311 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, | |
3312 | struct net_device *netdev) | |
3313 | { | |
3314 | struct sk_buff *msg; | |
3315 | ||
3316 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
3317 | if (!msg) | |
3318 | return; | |
3319 | ||
3320 | if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, | |
3321 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
3322 | nlmsg_free(msg); | |
3323 | return; | |
3324 | } | |
3325 | ||
3326 | genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL); | |
3327 | } | |
3328 | ||
3329 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
3330 | struct net_device *netdev) | |
3331 | { | |
3332 | struct sk_buff *msg; | |
3333 | ||
3334 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
3335 | if (!msg) | |
3336 | return; | |
3337 | ||
3338 | if (nl80211_send_scan_donemsg(msg, rdev, netdev, 0, 0, 0, | |
3339 | NL80211_CMD_SCAN_ABORTED) < 0) { | |
3340 | nlmsg_free(msg); | |
3341 | return; | |
3342 | } | |
3343 | ||
3344 | genlmsg_multicast(msg, 0, nl80211_scan_mcgrp.id, GFP_KERNEL); | |
3345 | } | |
3346 | ||
73d54c9e LR |
3347 | /* |
3348 | * This can happen on global regulatory changes or device specific settings | |
3349 | * based on custom world regulatory domains. | |
3350 | */ | |
3351 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
3352 | { | |
3353 | struct sk_buff *msg; | |
3354 | void *hdr; | |
3355 | ||
3356 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
3357 | if (!msg) | |
3358 | return; | |
3359 | ||
3360 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
3361 | if (!hdr) { | |
3362 | nlmsg_free(msg); | |
3363 | return; | |
3364 | } | |
3365 | ||
3366 | /* Userspace can always count this one always being set */ | |
3367 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); | |
3368 | ||
3369 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') | |
3370 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
3371 | NL80211_REGDOM_TYPE_WORLD); | |
3372 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') | |
3373 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
3374 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); | |
3375 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
3376 | request->intersect) | |
3377 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
3378 | NL80211_REGDOM_TYPE_INTERSECTION); | |
3379 | else { | |
3380 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
3381 | NL80211_REGDOM_TYPE_COUNTRY); | |
3382 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); | |
3383 | } | |
3384 | ||
3385 | if (wiphy_idx_valid(request->wiphy_idx)) | |
3386 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); | |
3387 | ||
3388 | if (genlmsg_end(msg, hdr) < 0) { | |
3389 | nlmsg_free(msg); | |
3390 | return; | |
3391 | } | |
3392 | ||
3393 | genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_KERNEL); | |
3394 | ||
3395 | return; | |
3396 | ||
3397 | nla_put_failure: | |
3398 | genlmsg_cancel(msg, hdr); | |
3399 | nlmsg_free(msg); | |
3400 | } | |
3401 | ||
6039f6d2 JM |
3402 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
3403 | struct net_device *netdev, | |
3404 | const u8 *buf, size_t len, | |
3405 | enum nl80211_commands cmd) | |
3406 | { | |
3407 | struct sk_buff *msg; | |
3408 | void *hdr; | |
3409 | ||
d91c01c7 | 3410 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); |
6039f6d2 JM |
3411 | if (!msg) |
3412 | return; | |
3413 | ||
3414 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
3415 | if (!hdr) { | |
3416 | nlmsg_free(msg); | |
3417 | return; | |
3418 | } | |
3419 | ||
3420 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
3421 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
3422 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
3423 | ||
3424 | if (genlmsg_end(msg, hdr) < 0) { | |
3425 | nlmsg_free(msg); | |
3426 | return; | |
3427 | } | |
3428 | ||
d91c01c7 | 3429 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_ATOMIC); |
6039f6d2 JM |
3430 | return; |
3431 | ||
3432 | nla_put_failure: | |
3433 | genlmsg_cancel(msg, hdr); | |
3434 | nlmsg_free(msg); | |
3435 | } | |
3436 | ||
3437 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
3438 | struct net_device *netdev, const u8 *buf, size_t len) | |
3439 | { | |
3440 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
3441 | NL80211_CMD_AUTHENTICATE); | |
3442 | } | |
3443 | ||
3444 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
3445 | struct net_device *netdev, const u8 *buf, | |
3446 | size_t len) | |
3447 | { | |
3448 | nl80211_send_mlme_event(rdev, netdev, buf, len, NL80211_CMD_ASSOCIATE); | |
3449 | } | |
3450 | ||
53b46b84 JM |
3451 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
3452 | struct net_device *netdev, const u8 *buf, size_t len) | |
6039f6d2 JM |
3453 | { |
3454 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
3455 | NL80211_CMD_DEAUTHENTICATE); | |
3456 | } | |
3457 | ||
53b46b84 JM |
3458 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
3459 | struct net_device *netdev, const u8 *buf, | |
3460 | size_t len) | |
6039f6d2 JM |
3461 | { |
3462 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
3463 | NL80211_CMD_DISASSOCIATE); | |
3464 | } | |
3465 | ||
a3b8b056 JM |
3466 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
3467 | struct net_device *netdev, const u8 *addr, | |
3468 | enum nl80211_key_type key_type, int key_id, | |
3469 | const u8 *tsc) | |
3470 | { | |
3471 | struct sk_buff *msg; | |
3472 | void *hdr; | |
3473 | ||
3474 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
3475 | if (!msg) | |
3476 | return; | |
3477 | ||
3478 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
3479 | if (!hdr) { | |
3480 | nlmsg_free(msg); | |
3481 | return; | |
3482 | } | |
3483 | ||
3484 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
3485 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
3486 | if (addr) | |
3487 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
3488 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); | |
3489 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); | |
3490 | if (tsc) | |
3491 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); | |
3492 | ||
3493 | if (genlmsg_end(msg, hdr) < 0) { | |
3494 | nlmsg_free(msg); | |
3495 | return; | |
3496 | } | |
3497 | ||
3498 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
3499 | return; | |
3500 | ||
3501 | nla_put_failure: | |
3502 | genlmsg_cancel(msg, hdr); | |
3503 | nlmsg_free(msg); | |
3504 | } | |
3505 | ||
6bad8766 LR |
3506 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
3507 | struct ieee80211_channel *channel_before, | |
3508 | struct ieee80211_channel *channel_after) | |
3509 | { | |
3510 | struct sk_buff *msg; | |
3511 | void *hdr; | |
3512 | struct nlattr *nl_freq; | |
3513 | ||
3514 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_ATOMIC); | |
3515 | if (!msg) | |
3516 | return; | |
3517 | ||
3518 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
3519 | if (!hdr) { | |
3520 | nlmsg_free(msg); | |
3521 | return; | |
3522 | } | |
3523 | ||
3524 | /* | |
3525 | * Since we are applying the beacon hint to a wiphy we know its | |
3526 | * wiphy_idx is valid | |
3527 | */ | |
3528 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); | |
3529 | ||
3530 | /* Before */ | |
3531 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
3532 | if (!nl_freq) | |
3533 | goto nla_put_failure; | |
3534 | if (nl80211_msg_put_channel(msg, channel_before)) | |
3535 | goto nla_put_failure; | |
3536 | nla_nest_end(msg, nl_freq); | |
3537 | ||
3538 | /* After */ | |
3539 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
3540 | if (!nl_freq) | |
3541 | goto nla_put_failure; | |
3542 | if (nl80211_msg_put_channel(msg, channel_after)) | |
3543 | goto nla_put_failure; | |
3544 | nla_nest_end(msg, nl_freq); | |
3545 | ||
3546 | if (genlmsg_end(msg, hdr) < 0) { | |
3547 | nlmsg_free(msg); | |
3548 | return; | |
3549 | } | |
3550 | ||
3551 | genlmsg_multicast(msg, 0, nl80211_regulatory_mcgrp.id, GFP_ATOMIC); | |
3552 | ||
3553 | return; | |
3554 | ||
3555 | nla_put_failure: | |
3556 | genlmsg_cancel(msg, hdr); | |
3557 | nlmsg_free(msg); | |
3558 | } | |
3559 | ||
55682965 JB |
3560 | /* initialisation/exit functions */ |
3561 | ||
3562 | int nl80211_init(void) | |
3563 | { | |
3564 | int err, i; | |
3565 | ||
3566 | err = genl_register_family(&nl80211_fam); | |
3567 | if (err) | |
3568 | return err; | |
3569 | ||
3570 | for (i = 0; i < ARRAY_SIZE(nl80211_ops); i++) { | |
3571 | err = genl_register_ops(&nl80211_fam, &nl80211_ops[i]); | |
3572 | if (err) | |
3573 | goto err_out; | |
3574 | } | |
3575 | ||
3576 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); | |
3577 | if (err) | |
3578 | goto err_out; | |
3579 | ||
2a519311 JB |
3580 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
3581 | if (err) | |
3582 | goto err_out; | |
3583 | ||
73d54c9e LR |
3584 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
3585 | if (err) | |
3586 | goto err_out; | |
3587 | ||
6039f6d2 JM |
3588 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
3589 | if (err) | |
3590 | goto err_out; | |
3591 | ||
55682965 JB |
3592 | return 0; |
3593 | err_out: | |
3594 | genl_unregister_family(&nl80211_fam); | |
3595 | return err; | |
3596 | } | |
3597 | ||
3598 | void nl80211_exit(void) | |
3599 | { | |
3600 | genl_unregister_family(&nl80211_fam); | |
3601 | } |