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