]>
Commit | Line | Data |
---|---|---|
55682965 JB |
1 | /* |
2 | * This is the new netlink-based wireless configuration interface. | |
3 | * | |
026331c4 | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
55682965 JB |
5 | */ |
6 | ||
7 | #include <linux/if.h> | |
8 | #include <linux/module.h> | |
9 | #include <linux/err.h> | |
5a0e3ad6 | 10 | #include <linux/slab.h> |
55682965 JB |
11 | #include <linux/list.h> |
12 | #include <linux/if_ether.h> | |
13 | #include <linux/ieee80211.h> | |
14 | #include <linux/nl80211.h> | |
15 | #include <linux/rtnetlink.h> | |
16 | #include <linux/netlink.h> | |
2a519311 | 17 | #include <linux/etherdevice.h> |
463d0183 | 18 | #include <net/net_namespace.h> |
55682965 JB |
19 | #include <net/genetlink.h> |
20 | #include <net/cfg80211.h> | |
463d0183 | 21 | #include <net/sock.h> |
55682965 JB |
22 | #include "core.h" |
23 | #include "nl80211.h" | |
b2e1b302 | 24 | #include "reg.h" |
55682965 JB |
25 | |
26 | /* the netlink family */ | |
27 | static struct genl_family nl80211_fam = { | |
28 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ | |
29 | .name = "nl80211", /* have users key off the name instead */ | |
30 | .hdrsize = 0, /* no private header */ | |
31 | .version = 1, /* no particular meaning now */ | |
32 | .maxattr = NL80211_ATTR_MAX, | |
463d0183 | 33 | .netnsok = true, |
55682965 JB |
34 | }; |
35 | ||
79c97e97 | 36 | /* internal helper: get rdev and dev */ |
463d0183 | 37 | static int get_rdev_dev_by_info_ifindex(struct genl_info *info, |
79c97e97 | 38 | struct cfg80211_registered_device **rdev, |
55682965 JB |
39 | struct net_device **dev) |
40 | { | |
463d0183 | 41 | struct nlattr **attrs = info->attrs; |
55682965 JB |
42 | int ifindex; |
43 | ||
bba95fef | 44 | if (!attrs[NL80211_ATTR_IFINDEX]) |
55682965 JB |
45 | return -EINVAL; |
46 | ||
bba95fef | 47 | ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); |
463d0183 | 48 | *dev = dev_get_by_index(genl_info_net(info), ifindex); |
55682965 JB |
49 | if (!*dev) |
50 | return -ENODEV; | |
51 | ||
463d0183 | 52 | *rdev = cfg80211_get_dev_from_ifindex(genl_info_net(info), ifindex); |
79c97e97 | 53 | if (IS_ERR(*rdev)) { |
55682965 | 54 | dev_put(*dev); |
79c97e97 | 55 | return PTR_ERR(*rdev); |
55682965 JB |
56 | } |
57 | ||
58 | return 0; | |
59 | } | |
60 | ||
61 | /* policy for the attributes */ | |
b54452b0 | 62 | static const struct nla_policy nl80211_policy[NL80211_ATTR_MAX+1] = { |
55682965 JB |
63 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
64 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 65 | .len = 20-1 }, |
31888487 | 66 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
72bdcf34 | 67 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 68 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
b9a5f8ca JM |
69 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
70 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
71 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
72 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 73 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
55682965 JB |
74 | |
75 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
76 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
77 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f JB |
78 | |
79 | [NL80211_ATTR_MAC] = { .type = NLA_BINARY, .len = ETH_ALEN }, | |
3e5d7649 | 80 | [NL80211_ATTR_PREV_BSSID] = { .type = NLA_BINARY, .len = ETH_ALEN }, |
41ade00f | 81 | |
b9454e83 | 82 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
83 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
84 | .len = WLAN_MAX_KEY_LEN }, | |
85 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
86 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
87 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
9f26a952 | 88 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, |
ed1b6cc7 JB |
89 | |
90 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
91 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
92 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
93 | .len = IEEE80211_MAX_DATA_LEN }, | |
94 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
95 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
96 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
97 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
98 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
99 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
100 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 101 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 102 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 103 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 LCC |
104 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
105 | .len = IEEE80211_MAX_MESH_ID_LEN }, | |
106 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, | |
9f1ba906 | 107 | |
b2e1b302 LR |
108 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
109 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
110 | ||
9f1ba906 JM |
111 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
112 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
113 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
114 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
115 | .len = NL80211_MAX_SUPP_RATES }, | |
36aedc90 | 116 | |
93da9cc1 | 117 | [NL80211_ATTR_MESH_PARAMS] = { .type = NLA_NESTED }, |
118 | ||
36aedc90 JM |
119 | [NL80211_ATTR_HT_CAPABILITY] = { .type = NLA_BINARY, |
120 | .len = NL80211_HT_CAPABILITY_LEN }, | |
9aed3cc1 JM |
121 | |
122 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
123 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
124 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
125 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
126 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
127 | |
128 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
129 | .len = IEEE80211_MAX_SSID_LEN }, | |
130 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
131 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 132 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 133 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 134 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
135 | [NL80211_ATTR_STA_FLAGS2] = { |
136 | .len = sizeof(struct nl80211_sta_flag_update), | |
137 | }, | |
3f77316c | 138 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
139 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
140 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
141 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
142 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
143 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 144 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 145 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
146 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
147 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
148 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
149 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 150 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
151 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
152 | .len = IEEE80211_MAX_DATA_LEN }, | |
153 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 154 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 155 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 156 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 157 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
158 | |
159 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, | |
160 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 161 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
55682965 JB |
162 | }; |
163 | ||
b9454e83 | 164 | /* policy for the attributes */ |
b54452b0 | 165 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 166 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
167 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
168 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
169 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 8 }, | |
170 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
171 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
172 | }; | |
173 | ||
a043897a HS |
174 | /* ifidx get helper */ |
175 | static int nl80211_get_ifidx(struct netlink_callback *cb) | |
176 | { | |
177 | int res; | |
178 | ||
179 | res = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
180 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
181 | nl80211_policy); | |
182 | if (res) | |
183 | return res; | |
184 | ||
185 | if (!nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]) | |
186 | return -EINVAL; | |
187 | ||
188 | res = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_IFINDEX]); | |
189 | if (!res) | |
190 | return -EINVAL; | |
191 | return res; | |
192 | } | |
193 | ||
f4a11bb0 JB |
194 | /* IE validation */ |
195 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
196 | { | |
197 | const u8 *pos; | |
198 | int len; | |
199 | ||
200 | if (!attr) | |
201 | return true; | |
202 | ||
203 | pos = nla_data(attr); | |
204 | len = nla_len(attr); | |
205 | ||
206 | while (len) { | |
207 | u8 elemlen; | |
208 | ||
209 | if (len < 2) | |
210 | return false; | |
211 | len -= 2; | |
212 | ||
213 | elemlen = pos[1]; | |
214 | if (elemlen > len) | |
215 | return false; | |
216 | ||
217 | len -= elemlen; | |
218 | pos += 2 + elemlen; | |
219 | } | |
220 | ||
221 | return true; | |
222 | } | |
223 | ||
55682965 JB |
224 | /* message building helper */ |
225 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 pid, u32 seq, | |
226 | int flags, u8 cmd) | |
227 | { | |
228 | /* since there is no private header just add the generic one */ | |
229 | return genlmsg_put(skb, pid, seq, &nl80211_fam, flags, cmd); | |
230 | } | |
231 | ||
5dab3b8a LR |
232 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
233 | struct ieee80211_channel *chan) | |
234 | { | |
235 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_FREQ, | |
236 | chan->center_freq); | |
237 | ||
238 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
239 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_DISABLED); | |
240 | if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN) | |
241 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_PASSIVE_SCAN); | |
242 | if (chan->flags & IEEE80211_CHAN_NO_IBSS) | |
243 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_NO_IBSS); | |
244 | if (chan->flags & IEEE80211_CHAN_RADAR) | |
245 | NLA_PUT_FLAG(msg, NL80211_FREQUENCY_ATTR_RADAR); | |
246 | ||
247 | NLA_PUT_U32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, | |
248 | DBM_TO_MBM(chan->max_power)); | |
249 | ||
250 | return 0; | |
251 | ||
252 | nla_put_failure: | |
253 | return -ENOBUFS; | |
254 | } | |
255 | ||
55682965 JB |
256 | /* netlink command implementations */ |
257 | ||
b9454e83 JB |
258 | struct key_parse { |
259 | struct key_params p; | |
260 | int idx; | |
261 | bool def, defmgmt; | |
262 | }; | |
263 | ||
264 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
265 | { | |
266 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
267 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
268 | nl80211_key_policy); | |
269 | if (err) | |
270 | return err; | |
271 | ||
272 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
273 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
274 | ||
275 | if (tb[NL80211_KEY_IDX]) | |
276 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
277 | ||
278 | if (tb[NL80211_KEY_DATA]) { | |
279 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
280 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
281 | } | |
282 | ||
283 | if (tb[NL80211_KEY_SEQ]) { | |
284 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
285 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
286 | } | |
287 | ||
288 | if (tb[NL80211_KEY_CIPHER]) | |
289 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
290 | ||
291 | return 0; | |
292 | } | |
293 | ||
294 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
295 | { | |
296 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
297 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
298 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
299 | } | |
300 | ||
301 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
302 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
303 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
304 | } | |
305 | ||
306 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
307 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
308 | ||
309 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
310 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
311 | ||
312 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
313 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
314 | ||
315 | return 0; | |
316 | } | |
317 | ||
318 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
319 | { | |
320 | int err; | |
321 | ||
322 | memset(k, 0, sizeof(*k)); | |
323 | k->idx = -1; | |
324 | ||
325 | if (info->attrs[NL80211_ATTR_KEY]) | |
326 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
327 | else | |
328 | err = nl80211_parse_key_old(info, k); | |
329 | ||
330 | if (err) | |
331 | return err; | |
332 | ||
333 | if (k->def && k->defmgmt) | |
334 | return -EINVAL; | |
335 | ||
336 | if (k->idx != -1) { | |
337 | if (k->defmgmt) { | |
338 | if (k->idx < 4 || k->idx > 5) | |
339 | return -EINVAL; | |
340 | } else if (k->def) { | |
341 | if (k->idx < 0 || k->idx > 3) | |
342 | return -EINVAL; | |
343 | } else { | |
344 | if (k->idx < 0 || k->idx > 5) | |
345 | return -EINVAL; | |
346 | } | |
347 | } | |
348 | ||
349 | return 0; | |
350 | } | |
351 | ||
fffd0934 JB |
352 | static struct cfg80211_cached_keys * |
353 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
354 | struct nlattr *keys) | |
355 | { | |
356 | struct key_parse parse; | |
357 | struct nlattr *key; | |
358 | struct cfg80211_cached_keys *result; | |
359 | int rem, err, def = 0; | |
360 | ||
361 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
362 | if (!result) | |
363 | return ERR_PTR(-ENOMEM); | |
364 | ||
365 | result->def = -1; | |
366 | result->defmgmt = -1; | |
367 | ||
368 | nla_for_each_nested(key, keys, rem) { | |
369 | memset(&parse, 0, sizeof(parse)); | |
370 | parse.idx = -1; | |
371 | ||
372 | err = nl80211_parse_key_new(key, &parse); | |
373 | if (err) | |
374 | goto error; | |
375 | err = -EINVAL; | |
376 | if (!parse.p.key) | |
377 | goto error; | |
378 | if (parse.idx < 0 || parse.idx > 4) | |
379 | goto error; | |
380 | if (parse.def) { | |
381 | if (def) | |
382 | goto error; | |
383 | def = 1; | |
384 | result->def = parse.idx; | |
385 | } else if (parse.defmgmt) | |
386 | goto error; | |
387 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
388 | parse.idx, NULL); | |
389 | if (err) | |
390 | goto error; | |
391 | result->params[parse.idx].cipher = parse.p.cipher; | |
392 | result->params[parse.idx].key_len = parse.p.key_len; | |
393 | result->params[parse.idx].key = result->data[parse.idx]; | |
394 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
395 | } | |
396 | ||
397 | return result; | |
398 | error: | |
399 | kfree(result); | |
400 | return ERR_PTR(err); | |
401 | } | |
402 | ||
403 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
404 | { | |
405 | ASSERT_WDEV_LOCK(wdev); | |
406 | ||
407 | if (!netif_running(wdev->netdev)) | |
408 | return -ENETDOWN; | |
409 | ||
410 | switch (wdev->iftype) { | |
411 | case NL80211_IFTYPE_AP: | |
412 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 413 | case NL80211_IFTYPE_P2P_GO: |
fffd0934 JB |
414 | break; |
415 | case NL80211_IFTYPE_ADHOC: | |
416 | if (!wdev->current_bss) | |
417 | return -ENOLINK; | |
418 | break; | |
419 | case NL80211_IFTYPE_STATION: | |
074ac8df | 420 | case NL80211_IFTYPE_P2P_CLIENT: |
fffd0934 JB |
421 | if (wdev->sme_state != CFG80211_SME_CONNECTED) |
422 | return -ENOLINK; | |
423 | break; | |
424 | default: | |
425 | return -EINVAL; | |
426 | } | |
427 | ||
428 | return 0; | |
429 | } | |
430 | ||
55682965 JB |
431 | static int nl80211_send_wiphy(struct sk_buff *msg, u32 pid, u32 seq, int flags, |
432 | struct cfg80211_registered_device *dev) | |
433 | { | |
434 | void *hdr; | |
ee688b00 JB |
435 | struct nlattr *nl_bands, *nl_band; |
436 | struct nlattr *nl_freqs, *nl_freq; | |
437 | struct nlattr *nl_rates, *nl_rate; | |
f59ac048 | 438 | struct nlattr *nl_modes; |
8fdc621d | 439 | struct nlattr *nl_cmds; |
ee688b00 JB |
440 | enum ieee80211_band band; |
441 | struct ieee80211_channel *chan; | |
442 | struct ieee80211_rate *rate; | |
443 | int i; | |
f59ac048 | 444 | u16 ifmodes = dev->wiphy.interface_modes; |
2e161f78 JB |
445 | const struct ieee80211_txrx_stypes *mgmt_stypes = |
446 | dev->wiphy.mgmt_stypes; | |
55682965 JB |
447 | |
448 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_WIPHY); | |
449 | if (!hdr) | |
450 | return -1; | |
451 | ||
b5850a7a | 452 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, dev->wiphy_idx); |
55682965 | 453 | NLA_PUT_STRING(msg, NL80211_ATTR_WIPHY_NAME, wiphy_name(&dev->wiphy)); |
b9a5f8ca | 454 | |
f5ea9120 JB |
455 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, |
456 | cfg80211_rdev_list_generation); | |
457 | ||
b9a5f8ca JM |
458 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, |
459 | dev->wiphy.retry_short); | |
460 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, | |
461 | dev->wiphy.retry_long); | |
462 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, | |
463 | dev->wiphy.frag_threshold); | |
464 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, | |
465 | dev->wiphy.rts_threshold); | |
81077e82 LT |
466 | NLA_PUT_U8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
467 | dev->wiphy.coverage_class); | |
b9a5f8ca | 468 | |
2a519311 JB |
469 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
470 | dev->wiphy.max_scan_ssids); | |
18a83659 JB |
471 | NLA_PUT_U16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
472 | dev->wiphy.max_scan_ie_len); | |
ee688b00 | 473 | |
25e47c18 JB |
474 | NLA_PUT(msg, NL80211_ATTR_CIPHER_SUITES, |
475 | sizeof(u32) * dev->wiphy.n_cipher_suites, | |
476 | dev->wiphy.cipher_suites); | |
477 | ||
67fbb16b SO |
478 | NLA_PUT_U8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
479 | dev->wiphy.max_num_pmkids); | |
480 | ||
c0692b8f JB |
481 | if (dev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) |
482 | NLA_PUT_FLAG(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE); | |
483 | ||
f59ac048 LR |
484 | nl_modes = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_IFTYPES); |
485 | if (!nl_modes) | |
486 | goto nla_put_failure; | |
487 | ||
488 | i = 0; | |
489 | while (ifmodes) { | |
490 | if (ifmodes & 1) | |
491 | NLA_PUT_FLAG(msg, i); | |
492 | ifmodes >>= 1; | |
493 | i++; | |
494 | } | |
495 | ||
496 | nla_nest_end(msg, nl_modes); | |
497 | ||
ee688b00 JB |
498 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); |
499 | if (!nl_bands) | |
500 | goto nla_put_failure; | |
501 | ||
502 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
503 | if (!dev->wiphy.bands[band]) | |
504 | continue; | |
505 | ||
506 | nl_band = nla_nest_start(msg, band); | |
507 | if (!nl_band) | |
508 | goto nla_put_failure; | |
509 | ||
d51626df JB |
510 | /* add HT info */ |
511 | if (dev->wiphy.bands[band]->ht_cap.ht_supported) { | |
512 | NLA_PUT(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
513 | sizeof(dev->wiphy.bands[band]->ht_cap.mcs), | |
514 | &dev->wiphy.bands[band]->ht_cap.mcs); | |
515 | NLA_PUT_U16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
516 | dev->wiphy.bands[band]->ht_cap.cap); | |
517 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
518 | dev->wiphy.bands[band]->ht_cap.ampdu_factor); | |
519 | NLA_PUT_U8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
520 | dev->wiphy.bands[band]->ht_cap.ampdu_density); | |
521 | } | |
522 | ||
ee688b00 JB |
523 | /* add frequencies */ |
524 | nl_freqs = nla_nest_start(msg, NL80211_BAND_ATTR_FREQS); | |
525 | if (!nl_freqs) | |
526 | goto nla_put_failure; | |
527 | ||
528 | for (i = 0; i < dev->wiphy.bands[band]->n_channels; i++) { | |
529 | nl_freq = nla_nest_start(msg, i); | |
530 | if (!nl_freq) | |
531 | goto nla_put_failure; | |
532 | ||
533 | chan = &dev->wiphy.bands[band]->channels[i]; | |
5dab3b8a LR |
534 | |
535 | if (nl80211_msg_put_channel(msg, chan)) | |
536 | goto nla_put_failure; | |
e2f367f2 | 537 | |
ee688b00 JB |
538 | nla_nest_end(msg, nl_freq); |
539 | } | |
540 | ||
541 | nla_nest_end(msg, nl_freqs); | |
542 | ||
543 | /* add bitrates */ | |
544 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
545 | if (!nl_rates) | |
546 | goto nla_put_failure; | |
547 | ||
548 | for (i = 0; i < dev->wiphy.bands[band]->n_bitrates; i++) { | |
549 | nl_rate = nla_nest_start(msg, i); | |
550 | if (!nl_rate) | |
551 | goto nla_put_failure; | |
552 | ||
553 | rate = &dev->wiphy.bands[band]->bitrates[i]; | |
554 | NLA_PUT_U32(msg, NL80211_BITRATE_ATTR_RATE, | |
555 | rate->bitrate); | |
556 | if (rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) | |
557 | NLA_PUT_FLAG(msg, | |
558 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE); | |
559 | ||
560 | nla_nest_end(msg, nl_rate); | |
561 | } | |
562 | ||
563 | nla_nest_end(msg, nl_rates); | |
564 | ||
565 | nla_nest_end(msg, nl_band); | |
566 | } | |
567 | nla_nest_end(msg, nl_bands); | |
568 | ||
8fdc621d JB |
569 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); |
570 | if (!nl_cmds) | |
571 | goto nla_put_failure; | |
572 | ||
573 | i = 0; | |
574 | #define CMD(op, n) \ | |
575 | do { \ | |
576 | if (dev->ops->op) { \ | |
577 | i++; \ | |
578 | NLA_PUT_U32(msg, i, NL80211_CMD_ ## n); \ | |
579 | } \ | |
580 | } while (0) | |
581 | ||
582 | CMD(add_virtual_intf, NEW_INTERFACE); | |
583 | CMD(change_virtual_intf, SET_INTERFACE); | |
584 | CMD(add_key, NEW_KEY); | |
585 | CMD(add_beacon, NEW_BEACON); | |
586 | CMD(add_station, NEW_STATION); | |
587 | CMD(add_mpath, NEW_MPATH); | |
588 | CMD(set_mesh_params, SET_MESH_PARAMS); | |
589 | CMD(change_bss, SET_BSS); | |
636a5d36 JM |
590 | CMD(auth, AUTHENTICATE); |
591 | CMD(assoc, ASSOCIATE); | |
592 | CMD(deauth, DEAUTHENTICATE); | |
593 | CMD(disassoc, DISASSOCIATE); | |
04a773ad | 594 | CMD(join_ibss, JOIN_IBSS); |
67fbb16b SO |
595 | CMD(set_pmksa, SET_PMKSA); |
596 | CMD(del_pmksa, DEL_PMKSA); | |
597 | CMD(flush_pmksa, FLUSH_PMKSA); | |
9588bbd5 | 598 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
13ae75b1 | 599 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); |
2e161f78 | 600 | CMD(mgmt_tx, FRAME); |
5be83de5 | 601 | if (dev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
463d0183 JB |
602 | i++; |
603 | NLA_PUT_U32(msg, i, NL80211_CMD_SET_WIPHY_NETNS); | |
604 | } | |
f444de05 | 605 | CMD(set_channel, SET_CHANNEL); |
8fdc621d JB |
606 | |
607 | #undef CMD | |
b23aa676 | 608 | |
6829c878 | 609 | if (dev->ops->connect || dev->ops->auth) { |
b23aa676 SO |
610 | i++; |
611 | NLA_PUT_U32(msg, i, NL80211_CMD_CONNECT); | |
612 | } | |
613 | ||
6829c878 | 614 | if (dev->ops->disconnect || dev->ops->deauth) { |
b23aa676 SO |
615 | i++; |
616 | NLA_PUT_U32(msg, i, NL80211_CMD_DISCONNECT); | |
617 | } | |
618 | ||
8fdc621d JB |
619 | nla_nest_end(msg, nl_cmds); |
620 | ||
2e161f78 JB |
621 | if (mgmt_stypes) { |
622 | u16 stypes; | |
623 | struct nlattr *nl_ftypes, *nl_ifs; | |
624 | enum nl80211_iftype ift; | |
625 | ||
626 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); | |
627 | if (!nl_ifs) | |
628 | goto nla_put_failure; | |
629 | ||
630 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
631 | nl_ftypes = nla_nest_start(msg, ift); | |
632 | if (!nl_ftypes) | |
633 | goto nla_put_failure; | |
634 | i = 0; | |
635 | stypes = mgmt_stypes[ift].tx; | |
636 | while (stypes) { | |
637 | if (stypes & 1) | |
638 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, | |
639 | (i << 4) | IEEE80211_FTYPE_MGMT); | |
640 | stypes >>= 1; | |
641 | i++; | |
642 | } | |
643 | nla_nest_end(msg, nl_ftypes); | |
644 | } | |
645 | ||
74b70a4e JB |
646 | nla_nest_end(msg, nl_ifs); |
647 | ||
2e161f78 JB |
648 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
649 | if (!nl_ifs) | |
650 | goto nla_put_failure; | |
651 | ||
652 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { | |
653 | nl_ftypes = nla_nest_start(msg, ift); | |
654 | if (!nl_ftypes) | |
655 | goto nla_put_failure; | |
656 | i = 0; | |
657 | stypes = mgmt_stypes[ift].rx; | |
658 | while (stypes) { | |
659 | if (stypes & 1) | |
660 | NLA_PUT_U16(msg, NL80211_ATTR_FRAME_TYPE, | |
661 | (i << 4) | IEEE80211_FTYPE_MGMT); | |
662 | stypes >>= 1; | |
663 | i++; | |
664 | } | |
665 | nla_nest_end(msg, nl_ftypes); | |
666 | } | |
667 | nla_nest_end(msg, nl_ifs); | |
668 | } | |
669 | ||
55682965 JB |
670 | return genlmsg_end(msg, hdr); |
671 | ||
672 | nla_put_failure: | |
bc3ed28c TG |
673 | genlmsg_cancel(msg, hdr); |
674 | return -EMSGSIZE; | |
55682965 JB |
675 | } |
676 | ||
677 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) | |
678 | { | |
679 | int idx = 0; | |
680 | int start = cb->args[0]; | |
681 | struct cfg80211_registered_device *dev; | |
682 | ||
a1794390 | 683 | mutex_lock(&cfg80211_mutex); |
79c97e97 | 684 | list_for_each_entry(dev, &cfg80211_rdev_list, list) { |
463d0183 JB |
685 | if (!net_eq(wiphy_net(&dev->wiphy), sock_net(skb->sk))) |
686 | continue; | |
b4637271 | 687 | if (++idx <= start) |
55682965 JB |
688 | continue; |
689 | if (nl80211_send_wiphy(skb, NETLINK_CB(cb->skb).pid, | |
690 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
b4637271 JV |
691 | dev) < 0) { |
692 | idx--; | |
55682965 | 693 | break; |
b4637271 | 694 | } |
55682965 | 695 | } |
a1794390 | 696 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
697 | |
698 | cb->args[0] = idx; | |
699 | ||
700 | return skb->len; | |
701 | } | |
702 | ||
703 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) | |
704 | { | |
705 | struct sk_buff *msg; | |
706 | struct cfg80211_registered_device *dev; | |
707 | ||
708 | dev = cfg80211_get_dev_from_info(info); | |
709 | if (IS_ERR(dev)) | |
710 | return PTR_ERR(dev); | |
711 | ||
fd2120ca | 712 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
713 | if (!msg) |
714 | goto out_err; | |
715 | ||
716 | if (nl80211_send_wiphy(msg, info->snd_pid, info->snd_seq, 0, dev) < 0) | |
717 | goto out_free; | |
718 | ||
4d0c8aea | 719 | cfg80211_unlock_rdev(dev); |
55682965 | 720 | |
134e6375 | 721 | return genlmsg_reply(msg, info); |
55682965 JB |
722 | |
723 | out_free: | |
724 | nlmsg_free(msg); | |
725 | out_err: | |
4d0c8aea | 726 | cfg80211_unlock_rdev(dev); |
55682965 JB |
727 | return -ENOBUFS; |
728 | } | |
729 | ||
31888487 JM |
730 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
731 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
732 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
733 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
734 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
735 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
736 | }; | |
737 | ||
738 | static int parse_txq_params(struct nlattr *tb[], | |
739 | struct ieee80211_txq_params *txq_params) | |
740 | { | |
741 | if (!tb[NL80211_TXQ_ATTR_QUEUE] || !tb[NL80211_TXQ_ATTR_TXOP] || | |
742 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || | |
743 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
744 | return -EINVAL; | |
745 | ||
746 | txq_params->queue = nla_get_u8(tb[NL80211_TXQ_ATTR_QUEUE]); | |
747 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); | |
748 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
749 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
750 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
751 | ||
752 | return 0; | |
753 | } | |
754 | ||
f444de05 JB |
755 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
756 | { | |
757 | /* | |
758 | * You can only set the channel explicitly for AP, mesh | |
759 | * and WDS type interfaces; all others have their channel | |
760 | * managed via their respective "establish a connection" | |
761 | * command (connect, join, ...) | |
762 | * | |
763 | * Monitors are special as they are normally slaved to | |
764 | * whatever else is going on, so they behave as though | |
765 | * you tried setting the wiphy channel itself. | |
766 | */ | |
767 | return !wdev || | |
768 | wdev->iftype == NL80211_IFTYPE_AP || | |
769 | wdev->iftype == NL80211_IFTYPE_WDS || | |
770 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || | |
074ac8df JB |
771 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
772 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
773 | } |
774 | ||
775 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, | |
776 | struct wireless_dev *wdev, | |
777 | struct genl_info *info) | |
778 | { | |
779 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
780 | u32 freq; | |
781 | int result; | |
782 | ||
783 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
784 | return -EINVAL; | |
785 | ||
786 | if (!nl80211_can_set_dev_channel(wdev)) | |
787 | return -EOPNOTSUPP; | |
788 | ||
789 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
790 | channel_type = nla_get_u32(info->attrs[ | |
791 | NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
792 | if (channel_type != NL80211_CHAN_NO_HT && | |
793 | channel_type != NL80211_CHAN_HT20 && | |
794 | channel_type != NL80211_CHAN_HT40PLUS && | |
795 | channel_type != NL80211_CHAN_HT40MINUS) | |
796 | return -EINVAL; | |
797 | } | |
798 | ||
799 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
800 | ||
801 | mutex_lock(&rdev->devlist_mtx); | |
802 | if (wdev) { | |
803 | wdev_lock(wdev); | |
804 | result = cfg80211_set_freq(rdev, wdev, freq, channel_type); | |
805 | wdev_unlock(wdev); | |
806 | } else { | |
807 | result = cfg80211_set_freq(rdev, NULL, freq, channel_type); | |
808 | } | |
809 | mutex_unlock(&rdev->devlist_mtx); | |
810 | ||
811 | return result; | |
812 | } | |
813 | ||
814 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
815 | { | |
816 | struct cfg80211_registered_device *rdev; | |
817 | struct net_device *netdev; | |
818 | int result; | |
819 | ||
820 | rtnl_lock(); | |
821 | ||
822 | result = get_rdev_dev_by_info_ifindex(info, &rdev, &netdev); | |
823 | if (result) | |
2234362c | 824 | goto unlock_rtnl; |
f444de05 JB |
825 | |
826 | result = __nl80211_set_channel(rdev, netdev->ieee80211_ptr, info); | |
827 | ||
2234362c JB |
828 | dev_put(netdev); |
829 | cfg80211_unlock_rdev(rdev); | |
830 | unlock_rtnl: | |
f444de05 JB |
831 | rtnl_unlock(); |
832 | ||
833 | return result; | |
834 | } | |
835 | ||
55682965 JB |
836 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
837 | { | |
838 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
839 | struct net_device *netdev = NULL; |
840 | struct wireless_dev *wdev; | |
a1e567c8 | 841 | int result = 0, rem_txq_params = 0; |
31888487 | 842 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
843 | u32 changed; |
844 | u8 retry_short = 0, retry_long = 0; | |
845 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 846 | u8 coverage_class = 0; |
55682965 | 847 | |
4bbf4d56 | 848 | rtnl_lock(); |
55682965 | 849 | |
f444de05 JB |
850 | /* |
851 | * Try to find the wiphy and netdev. Normally this | |
852 | * function shouldn't need the netdev, but this is | |
853 | * done for backward compatibility -- previously | |
854 | * setting the channel was done per wiphy, but now | |
855 | * it is per netdev. Previous userland like hostapd | |
856 | * also passed a netdev to set_wiphy, so that it is | |
857 | * possible to let that go to the right netdev! | |
858 | */ | |
4bbf4d56 JB |
859 | mutex_lock(&cfg80211_mutex); |
860 | ||
f444de05 JB |
861 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
862 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
863 | ||
864 | netdev = dev_get_by_index(genl_info_net(info), ifindex); | |
865 | if (netdev && netdev->ieee80211_ptr) { | |
866 | rdev = wiphy_to_dev(netdev->ieee80211_ptr->wiphy); | |
867 | mutex_lock(&rdev->mtx); | |
868 | } else | |
869 | netdev = NULL; | |
4bbf4d56 JB |
870 | } |
871 | ||
f444de05 JB |
872 | if (!netdev) { |
873 | rdev = __cfg80211_rdev_from_info(info); | |
874 | if (IS_ERR(rdev)) { | |
875 | mutex_unlock(&cfg80211_mutex); | |
876 | result = PTR_ERR(rdev); | |
877 | goto unlock; | |
878 | } | |
879 | wdev = NULL; | |
880 | netdev = NULL; | |
881 | result = 0; | |
882 | ||
883 | mutex_lock(&rdev->mtx); | |
884 | } else if (netif_running(netdev) && | |
885 | nl80211_can_set_dev_channel(netdev->ieee80211_ptr)) | |
886 | wdev = netdev->ieee80211_ptr; | |
887 | else | |
888 | wdev = NULL; | |
889 | ||
890 | /* | |
891 | * end workaround code, by now the rdev is available | |
892 | * and locked, and wdev may or may not be NULL. | |
893 | */ | |
4bbf4d56 JB |
894 | |
895 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
896 | result = cfg80211_dev_rename( |
897 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 JB |
898 | |
899 | mutex_unlock(&cfg80211_mutex); | |
900 | ||
901 | if (result) | |
902 | goto bad_res; | |
31888487 JM |
903 | |
904 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
905 | struct ieee80211_txq_params txq_params; | |
906 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
907 | ||
908 | if (!rdev->ops->set_txq_params) { | |
909 | result = -EOPNOTSUPP; | |
910 | goto bad_res; | |
911 | } | |
912 | ||
913 | nla_for_each_nested(nl_txq_params, | |
914 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
915 | rem_txq_params) { | |
916 | nla_parse(tb, NL80211_TXQ_ATTR_MAX, | |
917 | nla_data(nl_txq_params), | |
918 | nla_len(nl_txq_params), | |
919 | txq_params_policy); | |
920 | result = parse_txq_params(tb, &txq_params); | |
921 | if (result) | |
922 | goto bad_res; | |
923 | ||
924 | result = rdev->ops->set_txq_params(&rdev->wiphy, | |
925 | &txq_params); | |
926 | if (result) | |
927 | goto bad_res; | |
928 | } | |
929 | } | |
55682965 | 930 | |
72bdcf34 | 931 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
f444de05 | 932 | result = __nl80211_set_channel(rdev, wdev, info); |
72bdcf34 JM |
933 | if (result) |
934 | goto bad_res; | |
935 | } | |
936 | ||
98d2ff8b JO |
937 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
938 | enum nl80211_tx_power_setting type; | |
939 | int idx, mbm = 0; | |
940 | ||
941 | if (!rdev->ops->set_tx_power) { | |
60ea385f | 942 | result = -EOPNOTSUPP; |
98d2ff8b JO |
943 | goto bad_res; |
944 | } | |
945 | ||
946 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
947 | type = nla_get_u32(info->attrs[idx]); | |
948 | ||
949 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
950 | (type != NL80211_TX_POWER_AUTOMATIC)) { | |
951 | result = -EINVAL; | |
952 | goto bad_res; | |
953 | } | |
954 | ||
955 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
956 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
957 | mbm = nla_get_u32(info->attrs[idx]); | |
958 | } | |
959 | ||
960 | result = rdev->ops->set_tx_power(&rdev->wiphy, type, mbm); | |
961 | if (result) | |
962 | goto bad_res; | |
963 | } | |
964 | ||
b9a5f8ca JM |
965 | changed = 0; |
966 | ||
967 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
968 | retry_short = nla_get_u8( | |
969 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
970 | if (retry_short == 0) { | |
971 | result = -EINVAL; | |
972 | goto bad_res; | |
973 | } | |
974 | changed |= WIPHY_PARAM_RETRY_SHORT; | |
975 | } | |
976 | ||
977 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
978 | retry_long = nla_get_u8( | |
979 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
980 | if (retry_long == 0) { | |
981 | result = -EINVAL; | |
982 | goto bad_res; | |
983 | } | |
984 | changed |= WIPHY_PARAM_RETRY_LONG; | |
985 | } | |
986 | ||
987 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
988 | frag_threshold = nla_get_u32( | |
989 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
990 | if (frag_threshold < 256) { | |
991 | result = -EINVAL; | |
992 | goto bad_res; | |
993 | } | |
994 | if (frag_threshold != (u32) -1) { | |
995 | /* | |
996 | * Fragments (apart from the last one) are required to | |
997 | * have even length. Make the fragmentation code | |
998 | * simpler by stripping LSB should someone try to use | |
999 | * odd threshold value. | |
1000 | */ | |
1001 | frag_threshold &= ~0x1; | |
1002 | } | |
1003 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
1004 | } | |
1005 | ||
1006 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
1007 | rts_threshold = nla_get_u32( | |
1008 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
1009 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
1010 | } | |
1011 | ||
81077e82 LT |
1012 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
1013 | coverage_class = nla_get_u8( | |
1014 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
1015 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
1016 | } | |
1017 | ||
b9a5f8ca JM |
1018 | if (changed) { |
1019 | u8 old_retry_short, old_retry_long; | |
1020 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 1021 | u8 old_coverage_class; |
b9a5f8ca JM |
1022 | |
1023 | if (!rdev->ops->set_wiphy_params) { | |
1024 | result = -EOPNOTSUPP; | |
1025 | goto bad_res; | |
1026 | } | |
1027 | ||
1028 | old_retry_short = rdev->wiphy.retry_short; | |
1029 | old_retry_long = rdev->wiphy.retry_long; | |
1030 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
1031 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 1032 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
1033 | |
1034 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
1035 | rdev->wiphy.retry_short = retry_short; | |
1036 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
1037 | rdev->wiphy.retry_long = retry_long; | |
1038 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
1039 | rdev->wiphy.frag_threshold = frag_threshold; | |
1040 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
1041 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
1042 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
1043 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca JM |
1044 | |
1045 | result = rdev->ops->set_wiphy_params(&rdev->wiphy, changed); | |
1046 | if (result) { | |
1047 | rdev->wiphy.retry_short = old_retry_short; | |
1048 | rdev->wiphy.retry_long = old_retry_long; | |
1049 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
1050 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 1051 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
1052 | } |
1053 | } | |
72bdcf34 | 1054 | |
306d6112 | 1055 | bad_res: |
4bbf4d56 | 1056 | mutex_unlock(&rdev->mtx); |
f444de05 JB |
1057 | if (netdev) |
1058 | dev_put(netdev); | |
4bbf4d56 JB |
1059 | unlock: |
1060 | rtnl_unlock(); | |
55682965 JB |
1061 | return result; |
1062 | } | |
1063 | ||
1064 | ||
1065 | static int nl80211_send_iface(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
d726405a | 1066 | struct cfg80211_registered_device *rdev, |
55682965 JB |
1067 | struct net_device *dev) |
1068 | { | |
1069 | void *hdr; | |
1070 | ||
1071 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_INTERFACE); | |
1072 | if (!hdr) | |
1073 | return -1; | |
1074 | ||
1075 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
d726405a | 1076 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
55682965 | 1077 | NLA_PUT_STRING(msg, NL80211_ATTR_IFNAME, dev->name); |
60719ffd | 1078 | NLA_PUT_U32(msg, NL80211_ATTR_IFTYPE, dev->ieee80211_ptr->iftype); |
f5ea9120 JB |
1079 | |
1080 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, | |
1081 | rdev->devlist_generation ^ | |
1082 | (cfg80211_rdev_list_generation << 2)); | |
1083 | ||
55682965 JB |
1084 | return genlmsg_end(msg, hdr); |
1085 | ||
1086 | nla_put_failure: | |
bc3ed28c TG |
1087 | genlmsg_cancel(msg, hdr); |
1088 | return -EMSGSIZE; | |
55682965 JB |
1089 | } |
1090 | ||
1091 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
1092 | { | |
1093 | int wp_idx = 0; | |
1094 | int if_idx = 0; | |
1095 | int wp_start = cb->args[0]; | |
1096 | int if_start = cb->args[1]; | |
f5ea9120 | 1097 | struct cfg80211_registered_device *rdev; |
55682965 JB |
1098 | struct wireless_dev *wdev; |
1099 | ||
a1794390 | 1100 | mutex_lock(&cfg80211_mutex); |
f5ea9120 JB |
1101 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1102 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1103 | continue; |
bba95fef JB |
1104 | if (wp_idx < wp_start) { |
1105 | wp_idx++; | |
55682965 | 1106 | continue; |
bba95fef | 1107 | } |
55682965 JB |
1108 | if_idx = 0; |
1109 | ||
f5ea9120 JB |
1110 | mutex_lock(&rdev->devlist_mtx); |
1111 | list_for_each_entry(wdev, &rdev->netdev_list, list) { | |
bba95fef JB |
1112 | if (if_idx < if_start) { |
1113 | if_idx++; | |
55682965 | 1114 | continue; |
bba95fef | 1115 | } |
55682965 JB |
1116 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).pid, |
1117 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
f5ea9120 JB |
1118 | rdev, wdev->netdev) < 0) { |
1119 | mutex_unlock(&rdev->devlist_mtx); | |
bba95fef JB |
1120 | goto out; |
1121 | } | |
1122 | if_idx++; | |
55682965 | 1123 | } |
f5ea9120 | 1124 | mutex_unlock(&rdev->devlist_mtx); |
bba95fef JB |
1125 | |
1126 | wp_idx++; | |
55682965 | 1127 | } |
bba95fef | 1128 | out: |
a1794390 | 1129 | mutex_unlock(&cfg80211_mutex); |
55682965 JB |
1130 | |
1131 | cb->args[0] = wp_idx; | |
1132 | cb->args[1] = if_idx; | |
1133 | ||
1134 | return skb->len; | |
1135 | } | |
1136 | ||
1137 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
1138 | { | |
1139 | struct sk_buff *msg; | |
1140 | struct cfg80211_registered_device *dev; | |
1141 | struct net_device *netdev; | |
1142 | int err; | |
1143 | ||
463d0183 | 1144 | err = get_rdev_dev_by_info_ifindex(info, &dev, &netdev); |
55682965 JB |
1145 | if (err) |
1146 | return err; | |
1147 | ||
fd2120ca | 1148 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
1149 | if (!msg) |
1150 | goto out_err; | |
1151 | ||
d726405a JB |
1152 | if (nl80211_send_iface(msg, info->snd_pid, info->snd_seq, 0, |
1153 | dev, netdev) < 0) | |
55682965 JB |
1154 | goto out_free; |
1155 | ||
1156 | dev_put(netdev); | |
4d0c8aea | 1157 | cfg80211_unlock_rdev(dev); |
55682965 | 1158 | |
134e6375 | 1159 | return genlmsg_reply(msg, info); |
55682965 JB |
1160 | |
1161 | out_free: | |
1162 | nlmsg_free(msg); | |
1163 | out_err: | |
1164 | dev_put(netdev); | |
4d0c8aea | 1165 | cfg80211_unlock_rdev(dev); |
55682965 JB |
1166 | return -ENOBUFS; |
1167 | } | |
1168 | ||
66f7ac50 MW |
1169 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
1170 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
1171 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
1172 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
1173 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
1174 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
1175 | }; | |
1176 | ||
1177 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
1178 | { | |
1179 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
1180 | int flag; | |
1181 | ||
1182 | *mntrflags = 0; | |
1183 | ||
1184 | if (!nla) | |
1185 | return -EINVAL; | |
1186 | ||
1187 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
1188 | nla, mntr_flags_policy)) | |
1189 | return -EINVAL; | |
1190 | ||
1191 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
1192 | if (flags[flag]) | |
1193 | *mntrflags |= (1<<flag); | |
1194 | ||
1195 | return 0; | |
1196 | } | |
1197 | ||
9bc383de | 1198 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
1199 | struct net_device *netdev, u8 use_4addr, |
1200 | enum nl80211_iftype iftype) | |
9bc383de | 1201 | { |
ad4bb6f8 | 1202 | if (!use_4addr) { |
f350a0a8 | 1203 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 1204 | return -EBUSY; |
9bc383de | 1205 | return 0; |
ad4bb6f8 | 1206 | } |
9bc383de JB |
1207 | |
1208 | switch (iftype) { | |
1209 | case NL80211_IFTYPE_AP_VLAN: | |
1210 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
1211 | return 0; | |
1212 | break; | |
1213 | case NL80211_IFTYPE_STATION: | |
1214 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
1215 | return 0; | |
1216 | break; | |
1217 | default: | |
1218 | break; | |
1219 | } | |
1220 | ||
1221 | return -EOPNOTSUPP; | |
1222 | } | |
1223 | ||
55682965 JB |
1224 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
1225 | { | |
79c97e97 | 1226 | struct cfg80211_registered_device *rdev; |
2ec600d6 | 1227 | struct vif_params params; |
e36d56b6 | 1228 | int err; |
04a773ad | 1229 | enum nl80211_iftype otype, ntype; |
55682965 | 1230 | struct net_device *dev; |
92ffe055 | 1231 | u32 _flags, *flags = NULL; |
ac7f9cfa | 1232 | bool change = false; |
55682965 | 1233 | |
2ec600d6 LCC |
1234 | memset(¶ms, 0, sizeof(params)); |
1235 | ||
3b85875a JB |
1236 | rtnl_lock(); |
1237 | ||
463d0183 | 1238 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
55682965 | 1239 | if (err) |
3b85875a JB |
1240 | goto unlock_rtnl; |
1241 | ||
04a773ad | 1242 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 1243 | |
723b038d | 1244 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 1245 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 1246 | if (otype != ntype) |
ac7f9cfa | 1247 | change = true; |
04a773ad | 1248 | if (ntype > NL80211_IFTYPE_MAX) { |
ac7f9cfa | 1249 | err = -EINVAL; |
723b038d | 1250 | goto unlock; |
ac7f9cfa | 1251 | } |
723b038d JB |
1252 | } |
1253 | ||
92ffe055 | 1254 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
04a773ad | 1255 | if (ntype != NL80211_IFTYPE_MESH_POINT) { |
92ffe055 JB |
1256 | err = -EINVAL; |
1257 | goto unlock; | |
1258 | } | |
2ec600d6 LCC |
1259 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
1260 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
ac7f9cfa | 1261 | change = true; |
2ec600d6 LCC |
1262 | } |
1263 | ||
8b787643 FF |
1264 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
1265 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
1266 | change = true; | |
ad4bb6f8 | 1267 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de JB |
1268 | if (err) |
1269 | goto unlock; | |
8b787643 FF |
1270 | } else { |
1271 | params.use_4addr = -1; | |
1272 | } | |
1273 | ||
92ffe055 | 1274 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
04a773ad | 1275 | if (ntype != NL80211_IFTYPE_MONITOR) { |
92ffe055 JB |
1276 | err = -EINVAL; |
1277 | goto unlock; | |
1278 | } | |
1279 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | |
1280 | &_flags); | |
ac7f9cfa JB |
1281 | if (err) |
1282 | goto unlock; | |
1283 | ||
1284 | flags = &_flags; | |
1285 | change = true; | |
92ffe055 | 1286 | } |
3b85875a | 1287 | |
ac7f9cfa | 1288 | if (change) |
3d54d255 | 1289 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
1290 | else |
1291 | err = 0; | |
60719ffd | 1292 | |
9bc383de JB |
1293 | if (!err && params.use_4addr != -1) |
1294 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
1295 | ||
55682965 | 1296 | unlock: |
e36d56b6 | 1297 | dev_put(dev); |
79c97e97 | 1298 | cfg80211_unlock_rdev(rdev); |
3b85875a JB |
1299 | unlock_rtnl: |
1300 | rtnl_unlock(); | |
55682965 JB |
1301 | return err; |
1302 | } | |
1303 | ||
1304 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
1305 | { | |
79c97e97 | 1306 | struct cfg80211_registered_device *rdev; |
2ec600d6 | 1307 | struct vif_params params; |
55682965 JB |
1308 | int err; |
1309 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 1310 | u32 flags; |
55682965 | 1311 | |
2ec600d6 LCC |
1312 | memset(¶ms, 0, sizeof(params)); |
1313 | ||
55682965 JB |
1314 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
1315 | return -EINVAL; | |
1316 | ||
1317 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
1318 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
1319 | if (type > NL80211_IFTYPE_MAX) | |
1320 | return -EINVAL; | |
1321 | } | |
1322 | ||
3b85875a JB |
1323 | rtnl_lock(); |
1324 | ||
79c97e97 JB |
1325 | rdev = cfg80211_get_dev_from_info(info); |
1326 | if (IS_ERR(rdev)) { | |
1327 | err = PTR_ERR(rdev); | |
3b85875a JB |
1328 | goto unlock_rtnl; |
1329 | } | |
55682965 | 1330 | |
79c97e97 JB |
1331 | if (!rdev->ops->add_virtual_intf || |
1332 | !(rdev->wiphy.interface_modes & (1 << type))) { | |
55682965 JB |
1333 | err = -EOPNOTSUPP; |
1334 | goto unlock; | |
1335 | } | |
1336 | ||
2ec600d6 LCC |
1337 | if (type == NL80211_IFTYPE_MESH_POINT && |
1338 | info->attrs[NL80211_ATTR_MESH_ID]) { | |
1339 | params.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); | |
1340 | params.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
1341 | } | |
1342 | ||
9bc383de | 1343 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 1344 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 1345 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de JB |
1346 | if (err) |
1347 | goto unlock; | |
1348 | } | |
8b787643 | 1349 | |
66f7ac50 MW |
1350 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
1351 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
1352 | &flags); | |
79c97e97 | 1353 | err = rdev->ops->add_virtual_intf(&rdev->wiphy, |
66f7ac50 | 1354 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), |
2ec600d6 | 1355 | type, err ? NULL : &flags, ¶ms); |
2ec600d6 | 1356 | |
55682965 | 1357 | unlock: |
79c97e97 | 1358 | cfg80211_unlock_rdev(rdev); |
3b85875a JB |
1359 | unlock_rtnl: |
1360 | rtnl_unlock(); | |
55682965 JB |
1361 | return err; |
1362 | } | |
1363 | ||
1364 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
1365 | { | |
79c97e97 | 1366 | struct cfg80211_registered_device *rdev; |
463d0183 | 1367 | int err; |
55682965 JB |
1368 | struct net_device *dev; |
1369 | ||
3b85875a JB |
1370 | rtnl_lock(); |
1371 | ||
463d0183 | 1372 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
55682965 | 1373 | if (err) |
3b85875a | 1374 | goto unlock_rtnl; |
55682965 | 1375 | |
79c97e97 | 1376 | if (!rdev->ops->del_virtual_intf) { |
55682965 JB |
1377 | err = -EOPNOTSUPP; |
1378 | goto out; | |
1379 | } | |
1380 | ||
463d0183 | 1381 | err = rdev->ops->del_virtual_intf(&rdev->wiphy, dev); |
55682965 JB |
1382 | |
1383 | out: | |
79c97e97 | 1384 | cfg80211_unlock_rdev(rdev); |
463d0183 | 1385 | dev_put(dev); |
3b85875a JB |
1386 | unlock_rtnl: |
1387 | rtnl_unlock(); | |
55682965 JB |
1388 | return err; |
1389 | } | |
1390 | ||
41ade00f JB |
1391 | struct get_key_cookie { |
1392 | struct sk_buff *msg; | |
1393 | int error; | |
b9454e83 | 1394 | int idx; |
41ade00f JB |
1395 | }; |
1396 | ||
1397 | static void get_key_callback(void *c, struct key_params *params) | |
1398 | { | |
b9454e83 | 1399 | struct nlattr *key; |
41ade00f JB |
1400 | struct get_key_cookie *cookie = c; |
1401 | ||
1402 | if (params->key) | |
1403 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_DATA, | |
1404 | params->key_len, params->key); | |
1405 | ||
1406 | if (params->seq) | |
1407 | NLA_PUT(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
1408 | params->seq_len, params->seq); | |
1409 | ||
1410 | if (params->cipher) | |
1411 | NLA_PUT_U32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
1412 | params->cipher); | |
1413 | ||
b9454e83 JB |
1414 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
1415 | if (!key) | |
1416 | goto nla_put_failure; | |
1417 | ||
1418 | if (params->key) | |
1419 | NLA_PUT(cookie->msg, NL80211_KEY_DATA, | |
1420 | params->key_len, params->key); | |
1421 | ||
1422 | if (params->seq) | |
1423 | NLA_PUT(cookie->msg, NL80211_KEY_SEQ, | |
1424 | params->seq_len, params->seq); | |
1425 | ||
1426 | if (params->cipher) | |
1427 | NLA_PUT_U32(cookie->msg, NL80211_KEY_CIPHER, | |
1428 | params->cipher); | |
1429 | ||
1430 | NLA_PUT_U8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx); | |
1431 | ||
1432 | nla_nest_end(cookie->msg, key); | |
1433 | ||
41ade00f JB |
1434 | return; |
1435 | nla_put_failure: | |
1436 | cookie->error = 1; | |
1437 | } | |
1438 | ||
1439 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
1440 | { | |
79c97e97 | 1441 | struct cfg80211_registered_device *rdev; |
41ade00f JB |
1442 | int err; |
1443 | struct net_device *dev; | |
1444 | u8 key_idx = 0; | |
1445 | u8 *mac_addr = NULL; | |
1446 | struct get_key_cookie cookie = { | |
1447 | .error = 0, | |
1448 | }; | |
1449 | void *hdr; | |
1450 | struct sk_buff *msg; | |
1451 | ||
1452 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
1453 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
1454 | ||
3cfcf6ac | 1455 | if (key_idx > 5) |
41ade00f JB |
1456 | return -EINVAL; |
1457 | ||
1458 | if (info->attrs[NL80211_ATTR_MAC]) | |
1459 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1460 | ||
3b85875a JB |
1461 | rtnl_lock(); |
1462 | ||
463d0183 | 1463 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
41ade00f | 1464 | if (err) |
3b85875a | 1465 | goto unlock_rtnl; |
41ade00f | 1466 | |
79c97e97 | 1467 | if (!rdev->ops->get_key) { |
41ade00f JB |
1468 | err = -EOPNOTSUPP; |
1469 | goto out; | |
1470 | } | |
1471 | ||
fd2120ca | 1472 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
41ade00f JB |
1473 | if (!msg) { |
1474 | err = -ENOMEM; | |
1475 | goto out; | |
1476 | } | |
1477 | ||
1478 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
1479 | NL80211_CMD_NEW_KEY); | |
1480 | ||
1481 | if (IS_ERR(hdr)) { | |
1482 | err = PTR_ERR(hdr); | |
6c95e2a2 | 1483 | goto free_msg; |
41ade00f JB |
1484 | } |
1485 | ||
1486 | cookie.msg = msg; | |
b9454e83 | 1487 | cookie.idx = key_idx; |
41ade00f JB |
1488 | |
1489 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
1490 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_idx); | |
1491 | if (mac_addr) | |
1492 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
1493 | ||
79c97e97 | 1494 | err = rdev->ops->get_key(&rdev->wiphy, dev, key_idx, mac_addr, |
41ade00f | 1495 | &cookie, get_key_callback); |
41ade00f JB |
1496 | |
1497 | if (err) | |
6c95e2a2 | 1498 | goto free_msg; |
41ade00f JB |
1499 | |
1500 | if (cookie.error) | |
1501 | goto nla_put_failure; | |
1502 | ||
1503 | genlmsg_end(msg, hdr); | |
134e6375 | 1504 | err = genlmsg_reply(msg, info); |
41ade00f JB |
1505 | goto out; |
1506 | ||
1507 | nla_put_failure: | |
1508 | err = -ENOBUFS; | |
6c95e2a2 | 1509 | free_msg: |
41ade00f JB |
1510 | nlmsg_free(msg); |
1511 | out: | |
79c97e97 | 1512 | cfg80211_unlock_rdev(rdev); |
41ade00f | 1513 | dev_put(dev); |
3b85875a JB |
1514 | unlock_rtnl: |
1515 | rtnl_unlock(); | |
1516 | ||
41ade00f JB |
1517 | return err; |
1518 | } | |
1519 | ||
1520 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
1521 | { | |
79c97e97 | 1522 | struct cfg80211_registered_device *rdev; |
b9454e83 | 1523 | struct key_parse key; |
41ade00f JB |
1524 | int err; |
1525 | struct net_device *dev; | |
3cfcf6ac JM |
1526 | int (*func)(struct wiphy *wiphy, struct net_device *netdev, |
1527 | u8 key_index); | |
41ade00f | 1528 | |
b9454e83 JB |
1529 | err = nl80211_parse_key(info, &key); |
1530 | if (err) | |
1531 | return err; | |
41ade00f | 1532 | |
b9454e83 | 1533 | if (key.idx < 0) |
41ade00f JB |
1534 | return -EINVAL; |
1535 | ||
b9454e83 JB |
1536 | /* only support setting default key */ |
1537 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
1538 | return -EINVAL; |
1539 | ||
3b85875a JB |
1540 | rtnl_lock(); |
1541 | ||
463d0183 | 1542 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
41ade00f | 1543 | if (err) |
3b85875a | 1544 | goto unlock_rtnl; |
41ade00f | 1545 | |
b9454e83 | 1546 | if (key.def) |
79c97e97 | 1547 | func = rdev->ops->set_default_key; |
3cfcf6ac | 1548 | else |
79c97e97 | 1549 | func = rdev->ops->set_default_mgmt_key; |
3cfcf6ac JM |
1550 | |
1551 | if (!func) { | |
41ade00f JB |
1552 | err = -EOPNOTSUPP; |
1553 | goto out; | |
1554 | } | |
1555 | ||
fffd0934 JB |
1556 | wdev_lock(dev->ieee80211_ptr); |
1557 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
1558 | if (!err) | |
1559 | err = func(&rdev->wiphy, dev, key.idx); | |
1560 | ||
3d23e349 | 1561 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 1562 | if (!err) { |
79c97e97 | 1563 | if (func == rdev->ops->set_default_key) |
b9454e83 | 1564 | dev->ieee80211_ptr->wext.default_key = key.idx; |
08645126 | 1565 | else |
b9454e83 | 1566 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; |
08645126 JB |
1567 | } |
1568 | #endif | |
fffd0934 | 1569 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f JB |
1570 | |
1571 | out: | |
79c97e97 | 1572 | cfg80211_unlock_rdev(rdev); |
41ade00f | 1573 | dev_put(dev); |
3b85875a JB |
1574 | |
1575 | unlock_rtnl: | |
1576 | rtnl_unlock(); | |
1577 | ||
41ade00f JB |
1578 | return err; |
1579 | } | |
1580 | ||
1581 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
1582 | { | |
79c97e97 | 1583 | struct cfg80211_registered_device *rdev; |
fffd0934 | 1584 | int err; |
41ade00f | 1585 | struct net_device *dev; |
b9454e83 | 1586 | struct key_parse key; |
41ade00f JB |
1587 | u8 *mac_addr = NULL; |
1588 | ||
b9454e83 JB |
1589 | err = nl80211_parse_key(info, &key); |
1590 | if (err) | |
1591 | return err; | |
41ade00f | 1592 | |
b9454e83 | 1593 | if (!key.p.key) |
41ade00f JB |
1594 | return -EINVAL; |
1595 | ||
41ade00f JB |
1596 | if (info->attrs[NL80211_ATTR_MAC]) |
1597 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1598 | ||
3b85875a JB |
1599 | rtnl_lock(); |
1600 | ||
463d0183 | 1601 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
41ade00f | 1602 | if (err) |
3b85875a | 1603 | goto unlock_rtnl; |
41ade00f | 1604 | |
fffd0934 JB |
1605 | if (!rdev->ops->add_key) { |
1606 | err = -EOPNOTSUPP; | |
25e47c18 JB |
1607 | goto out; |
1608 | } | |
1609 | ||
fffd0934 JB |
1610 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, mac_addr)) { |
1611 | err = -EINVAL; | |
41ade00f JB |
1612 | goto out; |
1613 | } | |
1614 | ||
fffd0934 JB |
1615 | wdev_lock(dev->ieee80211_ptr); |
1616 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
1617 | if (!err) | |
1618 | err = rdev->ops->add_key(&rdev->wiphy, dev, key.idx, | |
1619 | mac_addr, &key.p); | |
1620 | wdev_unlock(dev->ieee80211_ptr); | |
41ade00f JB |
1621 | |
1622 | out: | |
79c97e97 | 1623 | cfg80211_unlock_rdev(rdev); |
41ade00f | 1624 | dev_put(dev); |
3b85875a JB |
1625 | unlock_rtnl: |
1626 | rtnl_unlock(); | |
1627 | ||
41ade00f JB |
1628 | return err; |
1629 | } | |
1630 | ||
1631 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
1632 | { | |
79c97e97 | 1633 | struct cfg80211_registered_device *rdev; |
41ade00f JB |
1634 | int err; |
1635 | struct net_device *dev; | |
41ade00f | 1636 | u8 *mac_addr = NULL; |
b9454e83 | 1637 | struct key_parse key; |
41ade00f | 1638 | |
b9454e83 JB |
1639 | err = nl80211_parse_key(info, &key); |
1640 | if (err) | |
1641 | return err; | |
41ade00f JB |
1642 | |
1643 | if (info->attrs[NL80211_ATTR_MAC]) | |
1644 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1645 | ||
3b85875a JB |
1646 | rtnl_lock(); |
1647 | ||
463d0183 | 1648 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
41ade00f | 1649 | if (err) |
3b85875a | 1650 | goto unlock_rtnl; |
41ade00f | 1651 | |
79c97e97 | 1652 | if (!rdev->ops->del_key) { |
41ade00f JB |
1653 | err = -EOPNOTSUPP; |
1654 | goto out; | |
1655 | } | |
1656 | ||
fffd0934 JB |
1657 | wdev_lock(dev->ieee80211_ptr); |
1658 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
1659 | if (!err) | |
1660 | err = rdev->ops->del_key(&rdev->wiphy, dev, key.idx, mac_addr); | |
41ade00f | 1661 | |
3d23e349 | 1662 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 1663 | if (!err) { |
b9454e83 | 1664 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 1665 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 1666 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
1667 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
1668 | } | |
1669 | #endif | |
fffd0934 | 1670 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 1671 | |
41ade00f | 1672 | out: |
79c97e97 | 1673 | cfg80211_unlock_rdev(rdev); |
41ade00f | 1674 | dev_put(dev); |
3b85875a JB |
1675 | |
1676 | unlock_rtnl: | |
1677 | rtnl_unlock(); | |
1678 | ||
41ade00f JB |
1679 | return err; |
1680 | } | |
1681 | ||
ed1b6cc7 JB |
1682 | static int nl80211_addset_beacon(struct sk_buff *skb, struct genl_info *info) |
1683 | { | |
1684 | int (*call)(struct wiphy *wiphy, struct net_device *dev, | |
1685 | struct beacon_parameters *info); | |
79c97e97 | 1686 | struct cfg80211_registered_device *rdev; |
ed1b6cc7 JB |
1687 | int err; |
1688 | struct net_device *dev; | |
1689 | struct beacon_parameters params; | |
1690 | int haveinfo = 0; | |
1691 | ||
f4a11bb0 JB |
1692 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_BEACON_TAIL])) |
1693 | return -EINVAL; | |
1694 | ||
3b85875a JB |
1695 | rtnl_lock(); |
1696 | ||
463d0183 | 1697 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
ed1b6cc7 | 1698 | if (err) |
3b85875a | 1699 | goto unlock_rtnl; |
ed1b6cc7 | 1700 | |
074ac8df JB |
1701 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1702 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
eec60b03 JM |
1703 | err = -EOPNOTSUPP; |
1704 | goto out; | |
1705 | } | |
1706 | ||
ed1b6cc7 JB |
1707 | switch (info->genlhdr->cmd) { |
1708 | case NL80211_CMD_NEW_BEACON: | |
1709 | /* these are required for NEW_BEACON */ | |
1710 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
1711 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
1712 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) { | |
1713 | err = -EINVAL; | |
1714 | goto out; | |
1715 | } | |
1716 | ||
79c97e97 | 1717 | call = rdev->ops->add_beacon; |
ed1b6cc7 JB |
1718 | break; |
1719 | case NL80211_CMD_SET_BEACON: | |
79c97e97 | 1720 | call = rdev->ops->set_beacon; |
ed1b6cc7 JB |
1721 | break; |
1722 | default: | |
1723 | WARN_ON(1); | |
1724 | err = -EOPNOTSUPP; | |
1725 | goto out; | |
1726 | } | |
1727 | ||
1728 | if (!call) { | |
1729 | err = -EOPNOTSUPP; | |
1730 | goto out; | |
1731 | } | |
1732 | ||
1733 | memset(¶ms, 0, sizeof(params)); | |
1734 | ||
1735 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
1736 | params.interval = | |
1737 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
1738 | haveinfo = 1; | |
1739 | } | |
1740 | ||
1741 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
1742 | params.dtim_period = | |
1743 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
1744 | haveinfo = 1; | |
1745 | } | |
1746 | ||
1747 | if (info->attrs[NL80211_ATTR_BEACON_HEAD]) { | |
1748 | params.head = nla_data(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
1749 | params.head_len = | |
1750 | nla_len(info->attrs[NL80211_ATTR_BEACON_HEAD]); | |
1751 | haveinfo = 1; | |
1752 | } | |
1753 | ||
1754 | if (info->attrs[NL80211_ATTR_BEACON_TAIL]) { | |
1755 | params.tail = nla_data(info->attrs[NL80211_ATTR_BEACON_TAIL]); | |
1756 | params.tail_len = | |
1757 | nla_len(info->attrs[NL80211_ATTR_BEACON_TAIL]); | |
1758 | haveinfo = 1; | |
1759 | } | |
1760 | ||
1761 | if (!haveinfo) { | |
1762 | err = -EINVAL; | |
1763 | goto out; | |
1764 | } | |
1765 | ||
79c97e97 | 1766 | err = call(&rdev->wiphy, dev, ¶ms); |
ed1b6cc7 JB |
1767 | |
1768 | out: | |
79c97e97 | 1769 | cfg80211_unlock_rdev(rdev); |
ed1b6cc7 | 1770 | dev_put(dev); |
3b85875a JB |
1771 | unlock_rtnl: |
1772 | rtnl_unlock(); | |
1773 | ||
ed1b6cc7 JB |
1774 | return err; |
1775 | } | |
1776 | ||
1777 | static int nl80211_del_beacon(struct sk_buff *skb, struct genl_info *info) | |
1778 | { | |
79c97e97 | 1779 | struct cfg80211_registered_device *rdev; |
ed1b6cc7 JB |
1780 | int err; |
1781 | struct net_device *dev; | |
1782 | ||
3b85875a JB |
1783 | rtnl_lock(); |
1784 | ||
463d0183 | 1785 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
ed1b6cc7 | 1786 | if (err) |
3b85875a | 1787 | goto unlock_rtnl; |
ed1b6cc7 | 1788 | |
79c97e97 | 1789 | if (!rdev->ops->del_beacon) { |
ed1b6cc7 JB |
1790 | err = -EOPNOTSUPP; |
1791 | goto out; | |
1792 | } | |
1793 | ||
074ac8df JB |
1794 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
1795 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
eec60b03 JM |
1796 | err = -EOPNOTSUPP; |
1797 | goto out; | |
1798 | } | |
79c97e97 | 1799 | err = rdev->ops->del_beacon(&rdev->wiphy, dev); |
ed1b6cc7 JB |
1800 | |
1801 | out: | |
79c97e97 | 1802 | cfg80211_unlock_rdev(rdev); |
ed1b6cc7 | 1803 | dev_put(dev); |
3b85875a JB |
1804 | unlock_rtnl: |
1805 | rtnl_unlock(); | |
1806 | ||
ed1b6cc7 JB |
1807 | return err; |
1808 | } | |
1809 | ||
5727ef1b JB |
1810 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
1811 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
1812 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
1813 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 1814 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
5727ef1b JB |
1815 | }; |
1816 | ||
eccb8e8f JB |
1817 | static int parse_station_flags(struct genl_info *info, |
1818 | struct station_parameters *params) | |
5727ef1b JB |
1819 | { |
1820 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 1821 | struct nlattr *nla; |
5727ef1b JB |
1822 | int flag; |
1823 | ||
eccb8e8f JB |
1824 | /* |
1825 | * Try parsing the new attribute first so userspace | |
1826 | * can specify both for older kernels. | |
1827 | */ | |
1828 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
1829 | if (nla) { | |
1830 | struct nl80211_sta_flag_update *sta_flags; | |
1831 | ||
1832 | sta_flags = nla_data(nla); | |
1833 | params->sta_flags_mask = sta_flags->mask; | |
1834 | params->sta_flags_set = sta_flags->set; | |
1835 | if ((params->sta_flags_mask | | |
1836 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
1837 | return -EINVAL; | |
1838 | return 0; | |
1839 | } | |
1840 | ||
1841 | /* if present, parse the old attribute */ | |
5727ef1b | 1842 | |
eccb8e8f | 1843 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
1844 | if (!nla) |
1845 | return 0; | |
1846 | ||
1847 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
1848 | nla, sta_flags_policy)) | |
1849 | return -EINVAL; | |
1850 | ||
eccb8e8f JB |
1851 | params->sta_flags_mask = (1 << __NL80211_STA_FLAG_AFTER_LAST) - 1; |
1852 | params->sta_flags_mask &= ~1; | |
5727ef1b JB |
1853 | |
1854 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) | |
1855 | if (flags[flag]) | |
eccb8e8f | 1856 | params->sta_flags_set |= (1<<flag); |
5727ef1b JB |
1857 | |
1858 | return 0; | |
1859 | } | |
1860 | ||
fd5b74dc JB |
1861 | static int nl80211_send_station(struct sk_buff *msg, u32 pid, u32 seq, |
1862 | int flags, struct net_device *dev, | |
98b62183 | 1863 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
1864 | { |
1865 | void *hdr; | |
420e7fab HR |
1866 | struct nlattr *sinfoattr, *txrate; |
1867 | u16 bitrate; | |
fd5b74dc JB |
1868 | |
1869 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
1870 | if (!hdr) | |
1871 | return -1; | |
1872 | ||
1873 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
1874 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr); | |
1875 | ||
f5ea9120 JB |
1876 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, sinfo->generation); |
1877 | ||
2ec600d6 LCC |
1878 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
1879 | if (!sinfoattr) | |
fd5b74dc | 1880 | goto nla_put_failure; |
2ec600d6 LCC |
1881 | if (sinfo->filled & STATION_INFO_INACTIVE_TIME) |
1882 | NLA_PUT_U32(msg, NL80211_STA_INFO_INACTIVE_TIME, | |
1883 | sinfo->inactive_time); | |
1884 | if (sinfo->filled & STATION_INFO_RX_BYTES) | |
1885 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_BYTES, | |
1886 | sinfo->rx_bytes); | |
1887 | if (sinfo->filled & STATION_INFO_TX_BYTES) | |
1888 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_BYTES, | |
1889 | sinfo->tx_bytes); | |
1890 | if (sinfo->filled & STATION_INFO_LLID) | |
1891 | NLA_PUT_U16(msg, NL80211_STA_INFO_LLID, | |
1892 | sinfo->llid); | |
1893 | if (sinfo->filled & STATION_INFO_PLID) | |
1894 | NLA_PUT_U16(msg, NL80211_STA_INFO_PLID, | |
1895 | sinfo->plid); | |
1896 | if (sinfo->filled & STATION_INFO_PLINK_STATE) | |
1897 | NLA_PUT_U8(msg, NL80211_STA_INFO_PLINK_STATE, | |
1898 | sinfo->plink_state); | |
420e7fab HR |
1899 | if (sinfo->filled & STATION_INFO_SIGNAL) |
1900 | NLA_PUT_U8(msg, NL80211_STA_INFO_SIGNAL, | |
1901 | sinfo->signal); | |
1902 | if (sinfo->filled & STATION_INFO_TX_BITRATE) { | |
1903 | txrate = nla_nest_start(msg, NL80211_STA_INFO_TX_BITRATE); | |
1904 | if (!txrate) | |
1905 | goto nla_put_failure; | |
1906 | ||
254416aa JL |
1907 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ |
1908 | bitrate = cfg80211_calculate_bitrate(&sinfo->txrate); | |
420e7fab HR |
1909 | if (bitrate > 0) |
1910 | NLA_PUT_U16(msg, NL80211_RATE_INFO_BITRATE, bitrate); | |
2ec600d6 | 1911 | |
420e7fab HR |
1912 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_MCS) |
1913 | NLA_PUT_U8(msg, NL80211_RATE_INFO_MCS, | |
1914 | sinfo->txrate.mcs); | |
1915 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_40_MHZ_WIDTH) | |
1916 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_40_MHZ_WIDTH); | |
1917 | if (sinfo->txrate.flags & RATE_INFO_FLAGS_SHORT_GI) | |
1918 | NLA_PUT_FLAG(msg, NL80211_RATE_INFO_SHORT_GI); | |
1919 | ||
1920 | nla_nest_end(msg, txrate); | |
1921 | } | |
98c8a60a JM |
1922 | if (sinfo->filled & STATION_INFO_RX_PACKETS) |
1923 | NLA_PUT_U32(msg, NL80211_STA_INFO_RX_PACKETS, | |
1924 | sinfo->rx_packets); | |
1925 | if (sinfo->filled & STATION_INFO_TX_PACKETS) | |
1926 | NLA_PUT_U32(msg, NL80211_STA_INFO_TX_PACKETS, | |
1927 | sinfo->tx_packets); | |
2ec600d6 | 1928 | nla_nest_end(msg, sinfoattr); |
fd5b74dc JB |
1929 | |
1930 | return genlmsg_end(msg, hdr); | |
1931 | ||
1932 | nla_put_failure: | |
bc3ed28c TG |
1933 | genlmsg_cancel(msg, hdr); |
1934 | return -EMSGSIZE; | |
fd5b74dc JB |
1935 | } |
1936 | ||
2ec600d6 | 1937 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 1938 | struct netlink_callback *cb) |
2ec600d6 | 1939 | { |
2ec600d6 LCC |
1940 | struct station_info sinfo; |
1941 | struct cfg80211_registered_device *dev; | |
bba95fef | 1942 | struct net_device *netdev; |
2ec600d6 | 1943 | u8 mac_addr[ETH_ALEN]; |
bba95fef JB |
1944 | int ifidx = cb->args[0]; |
1945 | int sta_idx = cb->args[1]; | |
2ec600d6 | 1946 | int err; |
2ec600d6 | 1947 | |
a043897a HS |
1948 | if (!ifidx) |
1949 | ifidx = nl80211_get_ifidx(cb); | |
1950 | if (ifidx < 0) | |
1951 | return ifidx; | |
2ec600d6 | 1952 | |
3b85875a JB |
1953 | rtnl_lock(); |
1954 | ||
463d0183 | 1955 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
3b85875a JB |
1956 | if (!netdev) { |
1957 | err = -ENODEV; | |
1958 | goto out_rtnl; | |
1959 | } | |
2ec600d6 | 1960 | |
463d0183 | 1961 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
bba95fef JB |
1962 | if (IS_ERR(dev)) { |
1963 | err = PTR_ERR(dev); | |
3b85875a | 1964 | goto out_rtnl; |
bba95fef JB |
1965 | } |
1966 | ||
1967 | if (!dev->ops->dump_station) { | |
eec60b03 | 1968 | err = -EOPNOTSUPP; |
bba95fef JB |
1969 | goto out_err; |
1970 | } | |
1971 | ||
bba95fef JB |
1972 | while (1) { |
1973 | err = dev->ops->dump_station(&dev->wiphy, netdev, sta_idx, | |
1974 | mac_addr, &sinfo); | |
1975 | if (err == -ENOENT) | |
1976 | break; | |
1977 | if (err) | |
3b85875a | 1978 | goto out_err; |
bba95fef JB |
1979 | |
1980 | if (nl80211_send_station(skb, | |
1981 | NETLINK_CB(cb->skb).pid, | |
1982 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
1983 | netdev, mac_addr, | |
1984 | &sinfo) < 0) | |
1985 | goto out; | |
1986 | ||
1987 | sta_idx++; | |
1988 | } | |
1989 | ||
1990 | ||
1991 | out: | |
1992 | cb->args[1] = sta_idx; | |
1993 | err = skb->len; | |
bba95fef | 1994 | out_err: |
4d0c8aea | 1995 | cfg80211_unlock_rdev(dev); |
3b85875a JB |
1996 | out_rtnl: |
1997 | rtnl_unlock(); | |
bba95fef JB |
1998 | |
1999 | return err; | |
2ec600d6 | 2000 | } |
fd5b74dc | 2001 | |
5727ef1b JB |
2002 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
2003 | { | |
79c97e97 | 2004 | struct cfg80211_registered_device *rdev; |
fd5b74dc JB |
2005 | int err; |
2006 | struct net_device *dev; | |
2ec600d6 | 2007 | struct station_info sinfo; |
fd5b74dc JB |
2008 | struct sk_buff *msg; |
2009 | u8 *mac_addr = NULL; | |
2010 | ||
2ec600d6 | 2011 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
2012 | |
2013 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2014 | return -EINVAL; | |
2015 | ||
2016 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2017 | ||
3b85875a JB |
2018 | rtnl_lock(); |
2019 | ||
463d0183 | 2020 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
fd5b74dc | 2021 | if (err) |
3b85875a | 2022 | goto out_rtnl; |
fd5b74dc | 2023 | |
79c97e97 | 2024 | if (!rdev->ops->get_station) { |
fd5b74dc JB |
2025 | err = -EOPNOTSUPP; |
2026 | goto out; | |
2027 | } | |
2028 | ||
79c97e97 | 2029 | err = rdev->ops->get_station(&rdev->wiphy, dev, mac_addr, &sinfo); |
2ec600d6 LCC |
2030 | if (err) |
2031 | goto out; | |
2032 | ||
fd2120ca | 2033 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc JB |
2034 | if (!msg) |
2035 | goto out; | |
2036 | ||
2037 | if (nl80211_send_station(msg, info->snd_pid, info->snd_seq, 0, | |
2ec600d6 | 2038 | dev, mac_addr, &sinfo) < 0) |
fd5b74dc JB |
2039 | goto out_free; |
2040 | ||
134e6375 | 2041 | err = genlmsg_reply(msg, info); |
fd5b74dc JB |
2042 | goto out; |
2043 | ||
2044 | out_free: | |
2045 | nlmsg_free(msg); | |
fd5b74dc | 2046 | out: |
79c97e97 | 2047 | cfg80211_unlock_rdev(rdev); |
fd5b74dc | 2048 | dev_put(dev); |
3b85875a JB |
2049 | out_rtnl: |
2050 | rtnl_unlock(); | |
2051 | ||
fd5b74dc | 2052 | return err; |
5727ef1b JB |
2053 | } |
2054 | ||
2055 | /* | |
c258d2de | 2056 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 2057 | */ |
463d0183 | 2058 | static int get_vlan(struct genl_info *info, |
5727ef1b JB |
2059 | struct cfg80211_registered_device *rdev, |
2060 | struct net_device **vlan) | |
2061 | { | |
463d0183 | 2062 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
5727ef1b JB |
2063 | *vlan = NULL; |
2064 | ||
2065 | if (vlanattr) { | |
463d0183 JB |
2066 | *vlan = dev_get_by_index(genl_info_net(info), |
2067 | nla_get_u32(vlanattr)); | |
5727ef1b JB |
2068 | if (!*vlan) |
2069 | return -ENODEV; | |
2070 | if (!(*vlan)->ieee80211_ptr) | |
2071 | return -EINVAL; | |
2072 | if ((*vlan)->ieee80211_ptr->wiphy != &rdev->wiphy) | |
2073 | return -EINVAL; | |
c258d2de FF |
2074 | if (!netif_running(*vlan)) |
2075 | return -ENETDOWN; | |
5727ef1b JB |
2076 | } |
2077 | return 0; | |
2078 | } | |
2079 | ||
2080 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) | |
2081 | { | |
79c97e97 | 2082 | struct cfg80211_registered_device *rdev; |
5727ef1b JB |
2083 | int err; |
2084 | struct net_device *dev; | |
2085 | struct station_parameters params; | |
2086 | u8 *mac_addr = NULL; | |
2087 | ||
2088 | memset(¶ms, 0, sizeof(params)); | |
2089 | ||
2090 | params.listen_interval = -1; | |
2091 | ||
2092 | if (info->attrs[NL80211_ATTR_STA_AID]) | |
2093 | return -EINVAL; | |
2094 | ||
2095 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2096 | return -EINVAL; | |
2097 | ||
2098 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2099 | ||
2100 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
2101 | params.supported_rates = | |
2102 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2103 | params.supported_rates_len = | |
2104 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2105 | } | |
2106 | ||
2107 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
2108 | params.listen_interval = | |
2109 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
2110 | ||
36aedc90 JM |
2111 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2112 | params.ht_capa = | |
2113 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
2114 | ||
eccb8e8f | 2115 | if (parse_station_flags(info, ¶ms)) |
5727ef1b JB |
2116 | return -EINVAL; |
2117 | ||
2ec600d6 LCC |
2118 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) |
2119 | params.plink_action = | |
2120 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); | |
2121 | ||
3b85875a JB |
2122 | rtnl_lock(); |
2123 | ||
463d0183 | 2124 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
5727ef1b | 2125 | if (err) |
3b85875a | 2126 | goto out_rtnl; |
5727ef1b | 2127 | |
463d0183 | 2128 | err = get_vlan(info, rdev, ¶ms.vlan); |
a97f4424 | 2129 | if (err) |
034d655e | 2130 | goto out; |
a97f4424 JB |
2131 | |
2132 | /* validate settings */ | |
2133 | err = 0; | |
2134 | ||
2135 | switch (dev->ieee80211_ptr->iftype) { | |
2136 | case NL80211_IFTYPE_AP: | |
2137 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 2138 | case NL80211_IFTYPE_P2P_GO: |
a97f4424 JB |
2139 | /* disallow mesh-specific things */ |
2140 | if (params.plink_action) | |
2141 | err = -EINVAL; | |
2142 | break; | |
074ac8df | 2143 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 JB |
2144 | case NL80211_IFTYPE_STATION: |
2145 | /* disallow everything but AUTHORIZED flag */ | |
2146 | if (params.plink_action) | |
2147 | err = -EINVAL; | |
2148 | if (params.vlan) | |
2149 | err = -EINVAL; | |
2150 | if (params.supported_rates) | |
2151 | err = -EINVAL; | |
2152 | if (params.ht_capa) | |
2153 | err = -EINVAL; | |
2154 | if (params.listen_interval >= 0) | |
2155 | err = -EINVAL; | |
2156 | if (params.sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
2157 | err = -EINVAL; | |
2158 | break; | |
2159 | case NL80211_IFTYPE_MESH_POINT: | |
2160 | /* disallow things mesh doesn't support */ | |
2161 | if (params.vlan) | |
2162 | err = -EINVAL; | |
2163 | if (params.ht_capa) | |
2164 | err = -EINVAL; | |
2165 | if (params.listen_interval >= 0) | |
2166 | err = -EINVAL; | |
2167 | if (params.supported_rates) | |
2168 | err = -EINVAL; | |
2169 | if (params.sta_flags_mask) | |
2170 | err = -EINVAL; | |
2171 | break; | |
2172 | default: | |
2173 | err = -EINVAL; | |
034d655e JB |
2174 | } |
2175 | ||
5727ef1b JB |
2176 | if (err) |
2177 | goto out; | |
2178 | ||
79c97e97 | 2179 | if (!rdev->ops->change_station) { |
5727ef1b JB |
2180 | err = -EOPNOTSUPP; |
2181 | goto out; | |
2182 | } | |
2183 | ||
79c97e97 | 2184 | err = rdev->ops->change_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
2185 | |
2186 | out: | |
2187 | if (params.vlan) | |
2188 | dev_put(params.vlan); | |
79c97e97 | 2189 | cfg80211_unlock_rdev(rdev); |
5727ef1b | 2190 | dev_put(dev); |
3b85875a JB |
2191 | out_rtnl: |
2192 | rtnl_unlock(); | |
2193 | ||
5727ef1b JB |
2194 | return err; |
2195 | } | |
2196 | ||
2197 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
2198 | { | |
79c97e97 | 2199 | struct cfg80211_registered_device *rdev; |
5727ef1b JB |
2200 | int err; |
2201 | struct net_device *dev; | |
2202 | struct station_parameters params; | |
2203 | u8 *mac_addr = NULL; | |
2204 | ||
2205 | memset(¶ms, 0, sizeof(params)); | |
2206 | ||
2207 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2208 | return -EINVAL; | |
2209 | ||
5727ef1b JB |
2210 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
2211 | return -EINVAL; | |
2212 | ||
2213 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
2214 | return -EINVAL; | |
2215 | ||
0e956c13 TLSC |
2216 | if (!info->attrs[NL80211_ATTR_STA_AID]) |
2217 | return -EINVAL; | |
2218 | ||
5727ef1b JB |
2219 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
2220 | params.supported_rates = | |
2221 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2222 | params.supported_rates_len = | |
2223 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
2224 | params.listen_interval = | |
2225 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 2226 | |
0e956c13 TLSC |
2227 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); |
2228 | if (!params.aid || params.aid > IEEE80211_MAX_AID) | |
2229 | return -EINVAL; | |
51b50fbe | 2230 | |
36aedc90 JM |
2231 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
2232 | params.ht_capa = | |
2233 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 2234 | |
eccb8e8f | 2235 | if (parse_station_flags(info, ¶ms)) |
5727ef1b JB |
2236 | return -EINVAL; |
2237 | ||
3b85875a JB |
2238 | rtnl_lock(); |
2239 | ||
463d0183 | 2240 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
5727ef1b | 2241 | if (err) |
3b85875a | 2242 | goto out_rtnl; |
5727ef1b | 2243 | |
0e956c13 | 2244 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
074ac8df JB |
2245 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
2246 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
0e956c13 TLSC |
2247 | err = -EINVAL; |
2248 | goto out; | |
2249 | } | |
2250 | ||
463d0183 | 2251 | err = get_vlan(info, rdev, ¶ms.vlan); |
a97f4424 | 2252 | if (err) |
e80cf853 | 2253 | goto out; |
a97f4424 JB |
2254 | |
2255 | /* validate settings */ | |
2256 | err = 0; | |
2257 | ||
79c97e97 | 2258 | if (!rdev->ops->add_station) { |
5727ef1b JB |
2259 | err = -EOPNOTSUPP; |
2260 | goto out; | |
2261 | } | |
2262 | ||
35a8efe1 JM |
2263 | if (!netif_running(dev)) { |
2264 | err = -ENETDOWN; | |
2265 | goto out; | |
2266 | } | |
2267 | ||
79c97e97 | 2268 | err = rdev->ops->add_station(&rdev->wiphy, dev, mac_addr, ¶ms); |
5727ef1b JB |
2269 | |
2270 | out: | |
2271 | if (params.vlan) | |
2272 | dev_put(params.vlan); | |
79c97e97 | 2273 | cfg80211_unlock_rdev(rdev); |
5727ef1b | 2274 | dev_put(dev); |
3b85875a JB |
2275 | out_rtnl: |
2276 | rtnl_unlock(); | |
2277 | ||
5727ef1b JB |
2278 | return err; |
2279 | } | |
2280 | ||
2281 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
2282 | { | |
79c97e97 | 2283 | struct cfg80211_registered_device *rdev; |
5727ef1b JB |
2284 | int err; |
2285 | struct net_device *dev; | |
2286 | u8 *mac_addr = NULL; | |
2287 | ||
2288 | if (info->attrs[NL80211_ATTR_MAC]) | |
2289 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2290 | ||
3b85875a JB |
2291 | rtnl_lock(); |
2292 | ||
463d0183 | 2293 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
5727ef1b | 2294 | if (err) |
3b85875a | 2295 | goto out_rtnl; |
5727ef1b | 2296 | |
e80cf853 | 2297 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 2298 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df JB |
2299 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
2300 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
e80cf853 JB |
2301 | err = -EINVAL; |
2302 | goto out; | |
2303 | } | |
2304 | ||
79c97e97 | 2305 | if (!rdev->ops->del_station) { |
5727ef1b JB |
2306 | err = -EOPNOTSUPP; |
2307 | goto out; | |
2308 | } | |
2309 | ||
79c97e97 | 2310 | err = rdev->ops->del_station(&rdev->wiphy, dev, mac_addr); |
5727ef1b JB |
2311 | |
2312 | out: | |
79c97e97 | 2313 | cfg80211_unlock_rdev(rdev); |
5727ef1b | 2314 | dev_put(dev); |
3b85875a JB |
2315 | out_rtnl: |
2316 | rtnl_unlock(); | |
2317 | ||
5727ef1b JB |
2318 | return err; |
2319 | } | |
2320 | ||
2ec600d6 LCC |
2321 | static int nl80211_send_mpath(struct sk_buff *msg, u32 pid, u32 seq, |
2322 | int flags, struct net_device *dev, | |
2323 | u8 *dst, u8 *next_hop, | |
2324 | struct mpath_info *pinfo) | |
2325 | { | |
2326 | void *hdr; | |
2327 | struct nlattr *pinfoattr; | |
2328 | ||
2329 | hdr = nl80211hdr_put(msg, pid, seq, flags, NL80211_CMD_NEW_STATION); | |
2330 | if (!hdr) | |
2331 | return -1; | |
2332 | ||
2333 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2334 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, dst); | |
2335 | NLA_PUT(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop); | |
2336 | ||
f5ea9120 JB |
2337 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, pinfo->generation); |
2338 | ||
2ec600d6 LCC |
2339 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
2340 | if (!pinfoattr) | |
2341 | goto nla_put_failure; | |
2342 | if (pinfo->filled & MPATH_INFO_FRAME_QLEN) | |
2343 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
2344 | pinfo->frame_qlen); | |
d19b3bf6 RP |
2345 | if (pinfo->filled & MPATH_INFO_SN) |
2346 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_SN, | |
2347 | pinfo->sn); | |
2ec600d6 LCC |
2348 | if (pinfo->filled & MPATH_INFO_METRIC) |
2349 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_METRIC, | |
2350 | pinfo->metric); | |
2351 | if (pinfo->filled & MPATH_INFO_EXPTIME) | |
2352 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_EXPTIME, | |
2353 | pinfo->exptime); | |
2354 | if (pinfo->filled & MPATH_INFO_FLAGS) | |
2355 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_FLAGS, | |
2356 | pinfo->flags); | |
2357 | if (pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) | |
2358 | NLA_PUT_U32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
2359 | pinfo->discovery_timeout); | |
2360 | if (pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) | |
2361 | NLA_PUT_U8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
2362 | pinfo->discovery_retries); | |
2363 | ||
2364 | nla_nest_end(msg, pinfoattr); | |
2365 | ||
2366 | return genlmsg_end(msg, hdr); | |
2367 | ||
2368 | nla_put_failure: | |
bc3ed28c TG |
2369 | genlmsg_cancel(msg, hdr); |
2370 | return -EMSGSIZE; | |
2ec600d6 LCC |
2371 | } |
2372 | ||
2373 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 2374 | struct netlink_callback *cb) |
2ec600d6 | 2375 | { |
2ec600d6 LCC |
2376 | struct mpath_info pinfo; |
2377 | struct cfg80211_registered_device *dev; | |
bba95fef | 2378 | struct net_device *netdev; |
2ec600d6 LCC |
2379 | u8 dst[ETH_ALEN]; |
2380 | u8 next_hop[ETH_ALEN]; | |
bba95fef JB |
2381 | int ifidx = cb->args[0]; |
2382 | int path_idx = cb->args[1]; | |
2ec600d6 | 2383 | int err; |
2ec600d6 | 2384 | |
a043897a HS |
2385 | if (!ifidx) |
2386 | ifidx = nl80211_get_ifidx(cb); | |
2387 | if (ifidx < 0) | |
2388 | return ifidx; | |
bba95fef | 2389 | |
3b85875a JB |
2390 | rtnl_lock(); |
2391 | ||
463d0183 | 2392 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
3b85875a JB |
2393 | if (!netdev) { |
2394 | err = -ENODEV; | |
2395 | goto out_rtnl; | |
2396 | } | |
bba95fef | 2397 | |
463d0183 | 2398 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
bba95fef JB |
2399 | if (IS_ERR(dev)) { |
2400 | err = PTR_ERR(dev); | |
3b85875a | 2401 | goto out_rtnl; |
bba95fef JB |
2402 | } |
2403 | ||
2404 | if (!dev->ops->dump_mpath) { | |
eec60b03 | 2405 | err = -EOPNOTSUPP; |
bba95fef JB |
2406 | goto out_err; |
2407 | } | |
2408 | ||
eec60b03 JM |
2409 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2410 | err = -EOPNOTSUPP; | |
0448b5fc | 2411 | goto out_err; |
eec60b03 JM |
2412 | } |
2413 | ||
bba95fef JB |
2414 | while (1) { |
2415 | err = dev->ops->dump_mpath(&dev->wiphy, netdev, path_idx, | |
2416 | dst, next_hop, &pinfo); | |
2417 | if (err == -ENOENT) | |
2ec600d6 | 2418 | break; |
bba95fef | 2419 | if (err) |
3b85875a | 2420 | goto out_err; |
2ec600d6 | 2421 | |
bba95fef JB |
2422 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).pid, |
2423 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
2424 | netdev, dst, next_hop, | |
2425 | &pinfo) < 0) | |
2426 | goto out; | |
2ec600d6 | 2427 | |
bba95fef | 2428 | path_idx++; |
2ec600d6 | 2429 | } |
2ec600d6 | 2430 | |
2ec600d6 | 2431 | |
bba95fef JB |
2432 | out: |
2433 | cb->args[1] = path_idx; | |
2434 | err = skb->len; | |
bba95fef | 2435 | out_err: |
4d0c8aea | 2436 | cfg80211_unlock_rdev(dev); |
3b85875a JB |
2437 | out_rtnl: |
2438 | rtnl_unlock(); | |
bba95fef JB |
2439 | |
2440 | return err; | |
2ec600d6 LCC |
2441 | } |
2442 | ||
2443 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
2444 | { | |
79c97e97 | 2445 | struct cfg80211_registered_device *rdev; |
2ec600d6 LCC |
2446 | int err; |
2447 | struct net_device *dev; | |
2448 | struct mpath_info pinfo; | |
2449 | struct sk_buff *msg; | |
2450 | u8 *dst = NULL; | |
2451 | u8 next_hop[ETH_ALEN]; | |
2452 | ||
2453 | memset(&pinfo, 0, sizeof(pinfo)); | |
2454 | ||
2455 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2456 | return -EINVAL; | |
2457 | ||
2458 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2459 | ||
3b85875a JB |
2460 | rtnl_lock(); |
2461 | ||
463d0183 | 2462 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2ec600d6 | 2463 | if (err) |
3b85875a | 2464 | goto out_rtnl; |
2ec600d6 | 2465 | |
79c97e97 | 2466 | if (!rdev->ops->get_mpath) { |
2ec600d6 LCC |
2467 | err = -EOPNOTSUPP; |
2468 | goto out; | |
2469 | } | |
2470 | ||
eec60b03 JM |
2471 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2472 | err = -EOPNOTSUPP; | |
2473 | goto out; | |
2474 | } | |
2475 | ||
79c97e97 | 2476 | err = rdev->ops->get_mpath(&rdev->wiphy, dev, dst, next_hop, &pinfo); |
2ec600d6 LCC |
2477 | if (err) |
2478 | goto out; | |
2479 | ||
fd2120ca | 2480 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 LCC |
2481 | if (!msg) |
2482 | goto out; | |
2483 | ||
2484 | if (nl80211_send_mpath(msg, info->snd_pid, info->snd_seq, 0, | |
2485 | dev, dst, next_hop, &pinfo) < 0) | |
2486 | goto out_free; | |
2487 | ||
134e6375 | 2488 | err = genlmsg_reply(msg, info); |
2ec600d6 LCC |
2489 | goto out; |
2490 | ||
2491 | out_free: | |
2492 | nlmsg_free(msg); | |
2ec600d6 | 2493 | out: |
79c97e97 | 2494 | cfg80211_unlock_rdev(rdev); |
2ec600d6 | 2495 | dev_put(dev); |
3b85875a JB |
2496 | out_rtnl: |
2497 | rtnl_unlock(); | |
2498 | ||
2ec600d6 LCC |
2499 | return err; |
2500 | } | |
2501 | ||
2502 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
2503 | { | |
79c97e97 | 2504 | struct cfg80211_registered_device *rdev; |
2ec600d6 LCC |
2505 | int err; |
2506 | struct net_device *dev; | |
2507 | u8 *dst = NULL; | |
2508 | u8 *next_hop = NULL; | |
2509 | ||
2510 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2511 | return -EINVAL; | |
2512 | ||
2513 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
2514 | return -EINVAL; | |
2515 | ||
2516 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2517 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
2518 | ||
3b85875a JB |
2519 | rtnl_lock(); |
2520 | ||
463d0183 | 2521 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2ec600d6 | 2522 | if (err) |
3b85875a | 2523 | goto out_rtnl; |
2ec600d6 | 2524 | |
79c97e97 | 2525 | if (!rdev->ops->change_mpath) { |
2ec600d6 LCC |
2526 | err = -EOPNOTSUPP; |
2527 | goto out; | |
2528 | } | |
2529 | ||
eec60b03 JM |
2530 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2531 | err = -EOPNOTSUPP; | |
2532 | goto out; | |
2533 | } | |
2534 | ||
35a8efe1 JM |
2535 | if (!netif_running(dev)) { |
2536 | err = -ENETDOWN; | |
2537 | goto out; | |
2538 | } | |
2539 | ||
79c97e97 | 2540 | err = rdev->ops->change_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
2541 | |
2542 | out: | |
79c97e97 | 2543 | cfg80211_unlock_rdev(rdev); |
2ec600d6 | 2544 | dev_put(dev); |
3b85875a JB |
2545 | out_rtnl: |
2546 | rtnl_unlock(); | |
2547 | ||
2ec600d6 LCC |
2548 | return err; |
2549 | } | |
2550 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) | |
2551 | { | |
79c97e97 | 2552 | struct cfg80211_registered_device *rdev; |
2ec600d6 LCC |
2553 | int err; |
2554 | struct net_device *dev; | |
2555 | u8 *dst = NULL; | |
2556 | u8 *next_hop = NULL; | |
2557 | ||
2558 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2559 | return -EINVAL; | |
2560 | ||
2561 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
2562 | return -EINVAL; | |
2563 | ||
2564 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2565 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
2566 | ||
3b85875a JB |
2567 | rtnl_lock(); |
2568 | ||
463d0183 | 2569 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2ec600d6 | 2570 | if (err) |
3b85875a | 2571 | goto out_rtnl; |
2ec600d6 | 2572 | |
79c97e97 | 2573 | if (!rdev->ops->add_mpath) { |
2ec600d6 LCC |
2574 | err = -EOPNOTSUPP; |
2575 | goto out; | |
2576 | } | |
2577 | ||
eec60b03 JM |
2578 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) { |
2579 | err = -EOPNOTSUPP; | |
2580 | goto out; | |
2581 | } | |
2582 | ||
35a8efe1 JM |
2583 | if (!netif_running(dev)) { |
2584 | err = -ENETDOWN; | |
2585 | goto out; | |
2586 | } | |
2587 | ||
79c97e97 | 2588 | err = rdev->ops->add_mpath(&rdev->wiphy, dev, dst, next_hop); |
2ec600d6 LCC |
2589 | |
2590 | out: | |
79c97e97 | 2591 | cfg80211_unlock_rdev(rdev); |
2ec600d6 | 2592 | dev_put(dev); |
3b85875a JB |
2593 | out_rtnl: |
2594 | rtnl_unlock(); | |
2595 | ||
2ec600d6 LCC |
2596 | return err; |
2597 | } | |
2598 | ||
2599 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
2600 | { | |
79c97e97 | 2601 | struct cfg80211_registered_device *rdev; |
2ec600d6 LCC |
2602 | int err; |
2603 | struct net_device *dev; | |
2604 | u8 *dst = NULL; | |
2605 | ||
2606 | if (info->attrs[NL80211_ATTR_MAC]) | |
2607 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2608 | ||
3b85875a JB |
2609 | rtnl_lock(); |
2610 | ||
463d0183 | 2611 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2ec600d6 | 2612 | if (err) |
3b85875a | 2613 | goto out_rtnl; |
2ec600d6 | 2614 | |
79c97e97 | 2615 | if (!rdev->ops->del_mpath) { |
2ec600d6 LCC |
2616 | err = -EOPNOTSUPP; |
2617 | goto out; | |
2618 | } | |
2619 | ||
79c97e97 | 2620 | err = rdev->ops->del_mpath(&rdev->wiphy, dev, dst); |
2ec600d6 LCC |
2621 | |
2622 | out: | |
79c97e97 | 2623 | cfg80211_unlock_rdev(rdev); |
2ec600d6 | 2624 | dev_put(dev); |
3b85875a JB |
2625 | out_rtnl: |
2626 | rtnl_unlock(); | |
2627 | ||
2ec600d6 LCC |
2628 | return err; |
2629 | } | |
2630 | ||
9f1ba906 JM |
2631 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
2632 | { | |
79c97e97 | 2633 | struct cfg80211_registered_device *rdev; |
9f1ba906 JM |
2634 | int err; |
2635 | struct net_device *dev; | |
2636 | struct bss_parameters params; | |
2637 | ||
2638 | memset(¶ms, 0, sizeof(params)); | |
2639 | /* default to not changing parameters */ | |
2640 | params.use_cts_prot = -1; | |
2641 | params.use_short_preamble = -1; | |
2642 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 2643 | params.ap_isolate = -1; |
9f1ba906 JM |
2644 | |
2645 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
2646 | params.use_cts_prot = | |
2647 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
2648 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
2649 | params.use_short_preamble = | |
2650 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
2651 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
2652 | params.use_short_slot_time = | |
2653 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
2654 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
2655 | params.basic_rates = | |
2656 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
2657 | params.basic_rates_len = | |
2658 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
2659 | } | |
fd8aaaf3 FF |
2660 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
2661 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
9f1ba906 | 2662 | |
3b85875a JB |
2663 | rtnl_lock(); |
2664 | ||
463d0183 | 2665 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
9f1ba906 | 2666 | if (err) |
3b85875a | 2667 | goto out_rtnl; |
9f1ba906 | 2668 | |
79c97e97 | 2669 | if (!rdev->ops->change_bss) { |
9f1ba906 JM |
2670 | err = -EOPNOTSUPP; |
2671 | goto out; | |
2672 | } | |
2673 | ||
074ac8df JB |
2674 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
2675 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
eec60b03 JM |
2676 | err = -EOPNOTSUPP; |
2677 | goto out; | |
2678 | } | |
2679 | ||
79c97e97 | 2680 | err = rdev->ops->change_bss(&rdev->wiphy, dev, ¶ms); |
9f1ba906 JM |
2681 | |
2682 | out: | |
79c97e97 | 2683 | cfg80211_unlock_rdev(rdev); |
9f1ba906 | 2684 | dev_put(dev); |
3b85875a JB |
2685 | out_rtnl: |
2686 | rtnl_unlock(); | |
2687 | ||
9f1ba906 JM |
2688 | return err; |
2689 | } | |
2690 | ||
b54452b0 | 2691 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
2692 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
2693 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
2694 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
2695 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
2696 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
2697 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
2698 | }; | |
2699 | ||
2700 | static int parse_reg_rule(struct nlattr *tb[], | |
2701 | struct ieee80211_reg_rule *reg_rule) | |
2702 | { | |
2703 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
2704 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
2705 | ||
2706 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
2707 | return -EINVAL; | |
2708 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
2709 | return -EINVAL; | |
2710 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
2711 | return -EINVAL; | |
2712 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
2713 | return -EINVAL; | |
2714 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
2715 | return -EINVAL; | |
2716 | ||
2717 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
2718 | ||
2719 | freq_range->start_freq_khz = | |
2720 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
2721 | freq_range->end_freq_khz = | |
2722 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
2723 | freq_range->max_bandwidth_khz = | |
2724 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
2725 | ||
2726 | power_rule->max_eirp = | |
2727 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
2728 | ||
2729 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
2730 | power_rule->max_antenna_gain = | |
2731 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
2732 | ||
2733 | return 0; | |
2734 | } | |
2735 | ||
2736 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
2737 | { | |
2738 | int r; | |
2739 | char *data = NULL; | |
2740 | ||
80778f18 LR |
2741 | /* |
2742 | * You should only get this when cfg80211 hasn't yet initialized | |
2743 | * completely when built-in to the kernel right between the time | |
2744 | * window between nl80211_init() and regulatory_init(), if that is | |
2745 | * even possible. | |
2746 | */ | |
2747 | mutex_lock(&cfg80211_mutex); | |
2748 | if (unlikely(!cfg80211_regdomain)) { | |
fe33eb39 LR |
2749 | mutex_unlock(&cfg80211_mutex); |
2750 | return -EINPROGRESS; | |
80778f18 | 2751 | } |
fe33eb39 | 2752 | mutex_unlock(&cfg80211_mutex); |
80778f18 | 2753 | |
fe33eb39 LR |
2754 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
2755 | return -EINVAL; | |
b2e1b302 LR |
2756 | |
2757 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
2758 | ||
fe33eb39 LR |
2759 | r = regulatory_hint_user(data); |
2760 | ||
b2e1b302 LR |
2761 | return r; |
2762 | } | |
2763 | ||
93da9cc1 | 2764 | static int nl80211_get_mesh_params(struct sk_buff *skb, |
2765 | struct genl_info *info) | |
2766 | { | |
79c97e97 | 2767 | struct cfg80211_registered_device *rdev; |
93da9cc1 | 2768 | struct mesh_config cur_params; |
2769 | int err; | |
2770 | struct net_device *dev; | |
2771 | void *hdr; | |
2772 | struct nlattr *pinfoattr; | |
2773 | struct sk_buff *msg; | |
2774 | ||
3b85875a JB |
2775 | rtnl_lock(); |
2776 | ||
93da9cc1 | 2777 | /* Look up our device */ |
463d0183 | 2778 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
93da9cc1 | 2779 | if (err) |
3b85875a | 2780 | goto out_rtnl; |
93da9cc1 | 2781 | |
79c97e97 | 2782 | if (!rdev->ops->get_mesh_params) { |
f3f92586 JM |
2783 | err = -EOPNOTSUPP; |
2784 | goto out; | |
2785 | } | |
2786 | ||
93da9cc1 | 2787 | /* Get the mesh params */ |
79c97e97 | 2788 | err = rdev->ops->get_mesh_params(&rdev->wiphy, dev, &cur_params); |
93da9cc1 | 2789 | if (err) |
2790 | goto out; | |
2791 | ||
2792 | /* Draw up a netlink message to send back */ | |
fd2120ca | 2793 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
93da9cc1 | 2794 | if (!msg) { |
2795 | err = -ENOBUFS; | |
2796 | goto out; | |
2797 | } | |
2798 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2799 | NL80211_CMD_GET_MESH_PARAMS); | |
2800 | if (!hdr) | |
2801 | goto nla_put_failure; | |
2802 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_PARAMS); | |
2803 | if (!pinfoattr) | |
2804 | goto nla_put_failure; | |
2805 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
2806 | NLA_PUT_U16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
2807 | cur_params.dot11MeshRetryTimeout); | |
2808 | NLA_PUT_U16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
2809 | cur_params.dot11MeshConfirmTimeout); | |
2810 | NLA_PUT_U16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
2811 | cur_params.dot11MeshHoldingTimeout); | |
2812 | NLA_PUT_U16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
2813 | cur_params.dot11MeshMaxPeerLinks); | |
2814 | NLA_PUT_U8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
2815 | cur_params.dot11MeshMaxRetries); | |
2816 | NLA_PUT_U8(msg, NL80211_MESHCONF_TTL, | |
2817 | cur_params.dot11MeshTTL); | |
2818 | NLA_PUT_U8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
2819 | cur_params.auto_open_plinks); | |
2820 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
2821 | cur_params.dot11MeshHWMPmaxPREQretries); | |
2822 | NLA_PUT_U32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
2823 | cur_params.path_refresh_time); | |
2824 | NLA_PUT_U16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
2825 | cur_params.min_discovery_timeout); | |
2826 | NLA_PUT_U32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
2827 | cur_params.dot11MeshHWMPactivePathTimeout); | |
2828 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
2829 | cur_params.dot11MeshHWMPpreqMinInterval); | |
2830 | NLA_PUT_U16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
2831 | cur_params.dot11MeshHWMPnetDiameterTraversalTime); | |
63c5723b RP |
2832 | NLA_PUT_U8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, |
2833 | cur_params.dot11MeshHWMPRootMode); | |
93da9cc1 | 2834 | nla_nest_end(msg, pinfoattr); |
2835 | genlmsg_end(msg, hdr); | |
134e6375 | 2836 | err = genlmsg_reply(msg, info); |
93da9cc1 | 2837 | goto out; |
2838 | ||
3b85875a | 2839 | nla_put_failure: |
93da9cc1 | 2840 | genlmsg_cancel(msg, hdr); |
d080e275 | 2841 | nlmsg_free(msg); |
93da9cc1 | 2842 | err = -EMSGSIZE; |
3b85875a | 2843 | out: |
93da9cc1 | 2844 | /* Cleanup */ |
79c97e97 | 2845 | cfg80211_unlock_rdev(rdev); |
93da9cc1 | 2846 | dev_put(dev); |
3b85875a JB |
2847 | out_rtnl: |
2848 | rtnl_unlock(); | |
2849 | ||
93da9cc1 | 2850 | return err; |
2851 | } | |
2852 | ||
2853 | #define FILL_IN_MESH_PARAM_IF_SET(table, cfg, param, mask, attr_num, nla_fn) \ | |
2854 | do {\ | |
2855 | if (table[attr_num]) {\ | |
2856 | cfg.param = nla_fn(table[attr_num]); \ | |
2857 | mask |= (1 << (attr_num - 1)); \ | |
2858 | } \ | |
2859 | } while (0);\ | |
2860 | ||
b54452b0 | 2861 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 2862 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
2863 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
2864 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
2865 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
2866 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
2867 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
2868 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, | |
2869 | ||
2870 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, | |
2871 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
2872 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
2873 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
2874 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
2875 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, | |
2876 | }; | |
2877 | ||
2878 | static int nl80211_set_mesh_params(struct sk_buff *skb, struct genl_info *info) | |
2879 | { | |
2880 | int err; | |
2881 | u32 mask; | |
79c97e97 | 2882 | struct cfg80211_registered_device *rdev; |
93da9cc1 | 2883 | struct net_device *dev; |
2884 | struct mesh_config cfg; | |
2885 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; | |
2886 | struct nlattr *parent_attr; | |
2887 | ||
2888 | parent_attr = info->attrs[NL80211_ATTR_MESH_PARAMS]; | |
2889 | if (!parent_attr) | |
2890 | return -EINVAL; | |
2891 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
2892 | parent_attr, nl80211_meshconf_params_policy)) | |
2893 | return -EINVAL; | |
2894 | ||
3b85875a JB |
2895 | rtnl_lock(); |
2896 | ||
463d0183 | 2897 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
93da9cc1 | 2898 | if (err) |
3b85875a | 2899 | goto out_rtnl; |
93da9cc1 | 2900 | |
79c97e97 | 2901 | if (!rdev->ops->set_mesh_params) { |
f3f92586 JM |
2902 | err = -EOPNOTSUPP; |
2903 | goto out; | |
2904 | } | |
2905 | ||
93da9cc1 | 2906 | /* This makes sure that there aren't more than 32 mesh config |
2907 | * parameters (otherwise our bitfield scheme would not work.) */ | |
2908 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
2909 | ||
2910 | /* Fill in the params struct */ | |
2911 | mask = 0; | |
2912 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, | |
2913 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, nla_get_u16); | |
2914 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, | |
2915 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, nla_get_u16); | |
2916 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, | |
2917 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, nla_get_u16); | |
2918 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, | |
2919 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, nla_get_u16); | |
2920 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, | |
2921 | mask, NL80211_MESHCONF_MAX_RETRIES, nla_get_u8); | |
2922 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, | |
2923 | mask, NL80211_MESHCONF_TTL, nla_get_u8); | |
2924 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, | |
2925 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, nla_get_u8); | |
2926 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, | |
2927 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, | |
2928 | nla_get_u8); | |
2929 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, | |
2930 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, nla_get_u32); | |
2931 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, | |
2932 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
2933 | nla_get_u16); | |
2934 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, | |
2935 | mask, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
2936 | nla_get_u32); | |
2937 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, | |
2938 | mask, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
2939 | nla_get_u16); | |
2940 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
2941 | dot11MeshHWMPnetDiameterTraversalTime, | |
2942 | mask, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
2943 | nla_get_u16); | |
63c5723b RP |
2944 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
2945 | dot11MeshHWMPRootMode, mask, | |
2946 | NL80211_MESHCONF_HWMP_ROOTMODE, | |
2947 | nla_get_u8); | |
93da9cc1 | 2948 | |
2949 | /* Apply changes */ | |
79c97e97 | 2950 | err = rdev->ops->set_mesh_params(&rdev->wiphy, dev, &cfg, mask); |
93da9cc1 | 2951 | |
f3f92586 | 2952 | out: |
93da9cc1 | 2953 | /* cleanup */ |
79c97e97 | 2954 | cfg80211_unlock_rdev(rdev); |
93da9cc1 | 2955 | dev_put(dev); |
3b85875a JB |
2956 | out_rtnl: |
2957 | rtnl_unlock(); | |
2958 | ||
93da9cc1 | 2959 | return err; |
2960 | } | |
2961 | ||
2962 | #undef FILL_IN_MESH_PARAM_IF_SET | |
2963 | ||
f130347c LR |
2964 | static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info) |
2965 | { | |
2966 | struct sk_buff *msg; | |
2967 | void *hdr = NULL; | |
2968 | struct nlattr *nl_reg_rules; | |
2969 | unsigned int i; | |
2970 | int err = -EINVAL; | |
2971 | ||
a1794390 | 2972 | mutex_lock(&cfg80211_mutex); |
f130347c LR |
2973 | |
2974 | if (!cfg80211_regdomain) | |
2975 | goto out; | |
2976 | ||
fd2120ca | 2977 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
f130347c LR |
2978 | if (!msg) { |
2979 | err = -ENOBUFS; | |
2980 | goto out; | |
2981 | } | |
2982 | ||
2983 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2984 | NL80211_CMD_GET_REG); | |
2985 | if (!hdr) | |
2986 | goto nla_put_failure; | |
2987 | ||
2988 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, | |
2989 | cfg80211_regdomain->alpha2); | |
2990 | ||
2991 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); | |
2992 | if (!nl_reg_rules) | |
2993 | goto nla_put_failure; | |
2994 | ||
2995 | for (i = 0; i < cfg80211_regdomain->n_reg_rules; i++) { | |
2996 | struct nlattr *nl_reg_rule; | |
2997 | const struct ieee80211_reg_rule *reg_rule; | |
2998 | const struct ieee80211_freq_range *freq_range; | |
2999 | const struct ieee80211_power_rule *power_rule; | |
3000 | ||
3001 | reg_rule = &cfg80211_regdomain->reg_rules[i]; | |
3002 | freq_range = ®_rule->freq_range; | |
3003 | power_rule = ®_rule->power_rule; | |
3004 | ||
3005 | nl_reg_rule = nla_nest_start(msg, i); | |
3006 | if (!nl_reg_rule) | |
3007 | goto nla_put_failure; | |
3008 | ||
3009 | NLA_PUT_U32(msg, NL80211_ATTR_REG_RULE_FLAGS, | |
3010 | reg_rule->flags); | |
3011 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
3012 | freq_range->start_freq_khz); | |
3013 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
3014 | freq_range->end_freq_khz); | |
3015 | NLA_PUT_U32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
3016 | freq_range->max_bandwidth_khz); | |
3017 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, | |
3018 | power_rule->max_antenna_gain); | |
3019 | NLA_PUT_U32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
3020 | power_rule->max_eirp); | |
3021 | ||
3022 | nla_nest_end(msg, nl_reg_rule); | |
3023 | } | |
3024 | ||
3025 | nla_nest_end(msg, nl_reg_rules); | |
3026 | ||
3027 | genlmsg_end(msg, hdr); | |
134e6375 | 3028 | err = genlmsg_reply(msg, info); |
f130347c LR |
3029 | goto out; |
3030 | ||
3031 | nla_put_failure: | |
3032 | genlmsg_cancel(msg, hdr); | |
d080e275 | 3033 | nlmsg_free(msg); |
f130347c LR |
3034 | err = -EMSGSIZE; |
3035 | out: | |
a1794390 | 3036 | mutex_unlock(&cfg80211_mutex); |
f130347c LR |
3037 | return err; |
3038 | } | |
3039 | ||
b2e1b302 LR |
3040 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
3041 | { | |
3042 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
3043 | struct nlattr *nl_reg_rule; | |
3044 | char *alpha2 = NULL; | |
3045 | int rem_reg_rules = 0, r = 0; | |
3046 | u32 num_rules = 0, rule_idx = 0, size_of_regd; | |
3047 | struct ieee80211_regdomain *rd = NULL; | |
3048 | ||
3049 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
3050 | return -EINVAL; | |
3051 | ||
3052 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
3053 | return -EINVAL; | |
3054 | ||
3055 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
3056 | ||
3057 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | |
3058 | rem_reg_rules) { | |
3059 | num_rules++; | |
3060 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 3061 | return -EINVAL; |
b2e1b302 LR |
3062 | } |
3063 | ||
61405e97 LR |
3064 | mutex_lock(&cfg80211_mutex); |
3065 | ||
d0e18f83 LR |
3066 | if (!reg_is_valid_request(alpha2)) { |
3067 | r = -EINVAL; | |
3068 | goto bad_reg; | |
3069 | } | |
b2e1b302 LR |
3070 | |
3071 | size_of_regd = sizeof(struct ieee80211_regdomain) + | |
3072 | (num_rules * sizeof(struct ieee80211_reg_rule)); | |
3073 | ||
3074 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
d0e18f83 LR |
3075 | if (!rd) { |
3076 | r = -ENOMEM; | |
3077 | goto bad_reg; | |
3078 | } | |
b2e1b302 LR |
3079 | |
3080 | rd->n_reg_rules = num_rules; | |
3081 | rd->alpha2[0] = alpha2[0]; | |
3082 | rd->alpha2[1] = alpha2[1]; | |
3083 | ||
3084 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], | |
3085 | rem_reg_rules) { | |
3086 | nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, | |
3087 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
3088 | reg_rule_policy); | |
3089 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); | |
3090 | if (r) | |
3091 | goto bad_reg; | |
3092 | ||
3093 | rule_idx++; | |
3094 | ||
d0e18f83 LR |
3095 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
3096 | r = -EINVAL; | |
b2e1b302 | 3097 | goto bad_reg; |
d0e18f83 | 3098 | } |
b2e1b302 LR |
3099 | } |
3100 | ||
3101 | BUG_ON(rule_idx != num_rules); | |
3102 | ||
b2e1b302 | 3103 | r = set_regdom(rd); |
61405e97 | 3104 | |
a1794390 | 3105 | mutex_unlock(&cfg80211_mutex); |
d0e18f83 | 3106 | |
b2e1b302 LR |
3107 | return r; |
3108 | ||
d2372b31 | 3109 | bad_reg: |
61405e97 | 3110 | mutex_unlock(&cfg80211_mutex); |
b2e1b302 | 3111 | kfree(rd); |
d0e18f83 | 3112 | return r; |
b2e1b302 LR |
3113 | } |
3114 | ||
83f5e2cf JB |
3115 | static int validate_scan_freqs(struct nlattr *freqs) |
3116 | { | |
3117 | struct nlattr *attr1, *attr2; | |
3118 | int n_channels = 0, tmp1, tmp2; | |
3119 | ||
3120 | nla_for_each_nested(attr1, freqs, tmp1) { | |
3121 | n_channels++; | |
3122 | /* | |
3123 | * Some hardware has a limited channel list for | |
3124 | * scanning, and it is pretty much nonsensical | |
3125 | * to scan for a channel twice, so disallow that | |
3126 | * and don't require drivers to check that the | |
3127 | * channel list they get isn't longer than what | |
3128 | * they can scan, as long as they can scan all | |
3129 | * the channels they registered at once. | |
3130 | */ | |
3131 | nla_for_each_nested(attr2, freqs, tmp2) | |
3132 | if (attr1 != attr2 && | |
3133 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
3134 | return 0; | |
3135 | } | |
3136 | ||
3137 | return n_channels; | |
3138 | } | |
3139 | ||
2a519311 JB |
3140 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
3141 | { | |
79c97e97 | 3142 | struct cfg80211_registered_device *rdev; |
2a519311 JB |
3143 | struct net_device *dev; |
3144 | struct cfg80211_scan_request *request; | |
3145 | struct cfg80211_ssid *ssid; | |
3146 | struct ieee80211_channel *channel; | |
3147 | struct nlattr *attr; | |
3148 | struct wiphy *wiphy; | |
83f5e2cf | 3149 | int err, tmp, n_ssids = 0, n_channels, i; |
2a519311 | 3150 | enum ieee80211_band band; |
70692ad2 | 3151 | size_t ie_len; |
2a519311 | 3152 | |
f4a11bb0 JB |
3153 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3154 | return -EINVAL; | |
3155 | ||
3b85875a JB |
3156 | rtnl_lock(); |
3157 | ||
463d0183 | 3158 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
2a519311 | 3159 | if (err) |
3b85875a | 3160 | goto out_rtnl; |
2a519311 | 3161 | |
79c97e97 | 3162 | wiphy = &rdev->wiphy; |
2a519311 | 3163 | |
79c97e97 | 3164 | if (!rdev->ops->scan) { |
2a519311 JB |
3165 | err = -EOPNOTSUPP; |
3166 | goto out; | |
3167 | } | |
3168 | ||
35a8efe1 JM |
3169 | if (!netif_running(dev)) { |
3170 | err = -ENETDOWN; | |
3171 | goto out; | |
3172 | } | |
3173 | ||
79c97e97 | 3174 | if (rdev->scan_req) { |
2a519311 | 3175 | err = -EBUSY; |
3b85875a | 3176 | goto out; |
2a519311 JB |
3177 | } |
3178 | ||
3179 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
3180 | n_channels = validate_scan_freqs( |
3181 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
2a519311 JB |
3182 | if (!n_channels) { |
3183 | err = -EINVAL; | |
3b85875a | 3184 | goto out; |
2a519311 JB |
3185 | } |
3186 | } else { | |
83f5e2cf JB |
3187 | n_channels = 0; |
3188 | ||
2a519311 JB |
3189 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) |
3190 | if (wiphy->bands[band]) | |
3191 | n_channels += wiphy->bands[band]->n_channels; | |
3192 | } | |
3193 | ||
3194 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
3195 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
3196 | n_ssids++; | |
3197 | ||
3198 | if (n_ssids > wiphy->max_scan_ssids) { | |
3199 | err = -EINVAL; | |
3b85875a | 3200 | goto out; |
2a519311 JB |
3201 | } |
3202 | ||
70692ad2 JM |
3203 | if (info->attrs[NL80211_ATTR_IE]) |
3204 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
3205 | else | |
3206 | ie_len = 0; | |
3207 | ||
18a83659 JB |
3208 | if (ie_len > wiphy->max_scan_ie_len) { |
3209 | err = -EINVAL; | |
3210 | goto out; | |
3211 | } | |
3212 | ||
2a519311 JB |
3213 | request = kzalloc(sizeof(*request) |
3214 | + sizeof(*ssid) * n_ssids | |
70692ad2 JM |
3215 | + sizeof(channel) * n_channels |
3216 | + ie_len, GFP_KERNEL); | |
2a519311 JB |
3217 | if (!request) { |
3218 | err = -ENOMEM; | |
3b85875a | 3219 | goto out; |
2a519311 JB |
3220 | } |
3221 | ||
2a519311 | 3222 | if (n_ssids) |
5ba63533 | 3223 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 3224 | request->n_ssids = n_ssids; |
70692ad2 JM |
3225 | if (ie_len) { |
3226 | if (request->ssids) | |
3227 | request->ie = (void *)(request->ssids + n_ssids); | |
3228 | else | |
3229 | request->ie = (void *)(request->channels + n_channels); | |
3230 | } | |
2a519311 | 3231 | |
584991dc | 3232 | i = 0; |
2a519311 JB |
3233 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
3234 | /* user specified, bail out if channel not found */ | |
2a519311 | 3235 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
3236 | struct ieee80211_channel *chan; |
3237 | ||
3238 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
3239 | ||
3240 | if (!chan) { | |
2a519311 JB |
3241 | err = -EINVAL; |
3242 | goto out_free; | |
3243 | } | |
584991dc JB |
3244 | |
3245 | /* ignore disabled channels */ | |
3246 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3247 | continue; | |
3248 | ||
3249 | request->channels[i] = chan; | |
2a519311 JB |
3250 | i++; |
3251 | } | |
3252 | } else { | |
3253 | /* all channels */ | |
2a519311 JB |
3254 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
3255 | int j; | |
3256 | if (!wiphy->bands[band]) | |
3257 | continue; | |
3258 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
3259 | struct ieee80211_channel *chan; |
3260 | ||
3261 | chan = &wiphy->bands[band]->channels[j]; | |
3262 | ||
3263 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
3264 | continue; | |
3265 | ||
3266 | request->channels[i] = chan; | |
2a519311 JB |
3267 | i++; |
3268 | } | |
3269 | } | |
3270 | } | |
3271 | ||
584991dc JB |
3272 | if (!i) { |
3273 | err = -EINVAL; | |
3274 | goto out_free; | |
3275 | } | |
3276 | ||
3277 | request->n_channels = i; | |
3278 | ||
2a519311 JB |
3279 | i = 0; |
3280 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) { | |
3281 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { | |
3282 | if (request->ssids[i].ssid_len > IEEE80211_MAX_SSID_LEN) { | |
3283 | err = -EINVAL; | |
3284 | goto out_free; | |
3285 | } | |
3286 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); | |
3287 | request->ssids[i].ssid_len = nla_len(attr); | |
3288 | i++; | |
3289 | } | |
3290 | } | |
3291 | ||
70692ad2 JM |
3292 | if (info->attrs[NL80211_ATTR_IE]) { |
3293 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
3294 | memcpy((void *)request->ie, |
3295 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
3296 | request->ie_len); |
3297 | } | |
3298 | ||
463d0183 | 3299 | request->dev = dev; |
79c97e97 | 3300 | request->wiphy = &rdev->wiphy; |
2a519311 | 3301 | |
79c97e97 JB |
3302 | rdev->scan_req = request; |
3303 | err = rdev->ops->scan(&rdev->wiphy, dev, request); | |
2a519311 | 3304 | |
463d0183 | 3305 | if (!err) { |
79c97e97 | 3306 | nl80211_send_scan_start(rdev, dev); |
463d0183 JB |
3307 | dev_hold(dev); |
3308 | } | |
a538e2d5 | 3309 | |
2a519311 JB |
3310 | out_free: |
3311 | if (err) { | |
79c97e97 | 3312 | rdev->scan_req = NULL; |
2a519311 JB |
3313 | kfree(request); |
3314 | } | |
2a519311 | 3315 | out: |
79c97e97 | 3316 | cfg80211_unlock_rdev(rdev); |
2a519311 | 3317 | dev_put(dev); |
3b85875a JB |
3318 | out_rtnl: |
3319 | rtnl_unlock(); | |
3320 | ||
2a519311 JB |
3321 | return err; |
3322 | } | |
3323 | ||
3324 | static int nl80211_send_bss(struct sk_buff *msg, u32 pid, u32 seq, int flags, | |
3325 | struct cfg80211_registered_device *rdev, | |
48ab905d JB |
3326 | struct wireless_dev *wdev, |
3327 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 3328 | { |
48ab905d | 3329 | struct cfg80211_bss *res = &intbss->pub; |
2a519311 JB |
3330 | void *hdr; |
3331 | struct nlattr *bss; | |
48ab905d JB |
3332 | int i; |
3333 | ||
3334 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 JB |
3335 | |
3336 | hdr = nl80211hdr_put(msg, pid, seq, flags, | |
3337 | NL80211_CMD_NEW_SCAN_RESULTS); | |
3338 | if (!hdr) | |
3339 | return -1; | |
3340 | ||
f5ea9120 | 3341 | NLA_PUT_U32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation); |
48ab905d | 3342 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex); |
2a519311 JB |
3343 | |
3344 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
3345 | if (!bss) | |
3346 | goto nla_put_failure; | |
3347 | if (!is_zero_ether_addr(res->bssid)) | |
3348 | NLA_PUT(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid); | |
3349 | if (res->information_elements && res->len_information_elements) | |
3350 | NLA_PUT(msg, NL80211_BSS_INFORMATION_ELEMENTS, | |
3351 | res->len_information_elements, | |
3352 | res->information_elements); | |
34a6eddb JM |
3353 | if (res->beacon_ies && res->len_beacon_ies && |
3354 | res->beacon_ies != res->information_elements) | |
3355 | NLA_PUT(msg, NL80211_BSS_BEACON_IES, | |
3356 | res->len_beacon_ies, res->beacon_ies); | |
2a519311 JB |
3357 | if (res->tsf) |
3358 | NLA_PUT_U64(msg, NL80211_BSS_TSF, res->tsf); | |
3359 | if (res->beacon_interval) | |
3360 | NLA_PUT_U16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval); | |
3361 | NLA_PUT_U16(msg, NL80211_BSS_CAPABILITY, res->capability); | |
3362 | NLA_PUT_U32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq); | |
7c89606e HS |
3363 | NLA_PUT_U32(msg, NL80211_BSS_SEEN_MS_AGO, |
3364 | jiffies_to_msecs(jiffies - intbss->ts)); | |
2a519311 | 3365 | |
77965c97 | 3366 | switch (rdev->wiphy.signal_type) { |
2a519311 JB |
3367 | case CFG80211_SIGNAL_TYPE_MBM: |
3368 | NLA_PUT_U32(msg, NL80211_BSS_SIGNAL_MBM, res->signal); | |
3369 | break; | |
3370 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
3371 | NLA_PUT_U8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal); | |
3372 | break; | |
3373 | default: | |
3374 | break; | |
3375 | } | |
3376 | ||
48ab905d | 3377 | switch (wdev->iftype) { |
074ac8df | 3378 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d JB |
3379 | case NL80211_IFTYPE_STATION: |
3380 | if (intbss == wdev->current_bss) | |
3381 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3382 | NL80211_BSS_STATUS_ASSOCIATED); | |
3383 | else for (i = 0; i < MAX_AUTH_BSSES; i++) { | |
3384 | if (intbss != wdev->auth_bsses[i]) | |
3385 | continue; | |
3386 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3387 | NL80211_BSS_STATUS_AUTHENTICATED); | |
3388 | break; | |
3389 | } | |
3390 | break; | |
3391 | case NL80211_IFTYPE_ADHOC: | |
3392 | if (intbss == wdev->current_bss) | |
3393 | NLA_PUT_U32(msg, NL80211_BSS_STATUS, | |
3394 | NL80211_BSS_STATUS_IBSS_JOINED); | |
3395 | break; | |
3396 | default: | |
3397 | break; | |
3398 | } | |
3399 | ||
2a519311 JB |
3400 | nla_nest_end(msg, bss); |
3401 | ||
3402 | return genlmsg_end(msg, hdr); | |
3403 | ||
3404 | nla_put_failure: | |
3405 | genlmsg_cancel(msg, hdr); | |
3406 | return -EMSGSIZE; | |
3407 | } | |
3408 | ||
3409 | static int nl80211_dump_scan(struct sk_buff *skb, | |
3410 | struct netlink_callback *cb) | |
3411 | { | |
48ab905d JB |
3412 | struct cfg80211_registered_device *rdev; |
3413 | struct net_device *dev; | |
2a519311 | 3414 | struct cfg80211_internal_bss *scan; |
48ab905d | 3415 | struct wireless_dev *wdev; |
2a519311 JB |
3416 | int ifidx = cb->args[0]; |
3417 | int start = cb->args[1], idx = 0; | |
3418 | int err; | |
3419 | ||
a043897a HS |
3420 | if (!ifidx) |
3421 | ifidx = nl80211_get_ifidx(cb); | |
3422 | if (ifidx < 0) | |
3423 | return ifidx; | |
3424 | cb->args[0] = ifidx; | |
2a519311 | 3425 | |
463d0183 | 3426 | dev = dev_get_by_index(sock_net(skb->sk), ifidx); |
48ab905d | 3427 | if (!dev) |
2a519311 JB |
3428 | return -ENODEV; |
3429 | ||
463d0183 | 3430 | rdev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); |
48ab905d JB |
3431 | if (IS_ERR(rdev)) { |
3432 | err = PTR_ERR(rdev); | |
2a519311 JB |
3433 | goto out_put_netdev; |
3434 | } | |
3435 | ||
48ab905d | 3436 | wdev = dev->ieee80211_ptr; |
2a519311 | 3437 | |
48ab905d JB |
3438 | wdev_lock(wdev); |
3439 | spin_lock_bh(&rdev->bss_lock); | |
3440 | cfg80211_bss_expire(rdev); | |
3441 | ||
3442 | list_for_each_entry(scan, &rdev->bss_list, list) { | |
2a519311 JB |
3443 | if (++idx <= start) |
3444 | continue; | |
3445 | if (nl80211_send_bss(skb, | |
3446 | NETLINK_CB(cb->skb).pid, | |
3447 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
48ab905d | 3448 | rdev, wdev, scan) < 0) { |
2a519311 JB |
3449 | idx--; |
3450 | goto out; | |
3451 | } | |
3452 | } | |
3453 | ||
3454 | out: | |
48ab905d JB |
3455 | spin_unlock_bh(&rdev->bss_lock); |
3456 | wdev_unlock(wdev); | |
2a519311 JB |
3457 | |
3458 | cb->args[1] = idx; | |
3459 | err = skb->len; | |
48ab905d | 3460 | cfg80211_unlock_rdev(rdev); |
2a519311 | 3461 | out_put_netdev: |
48ab905d | 3462 | dev_put(dev); |
2a519311 JB |
3463 | |
3464 | return err; | |
3465 | } | |
3466 | ||
61fa713c HS |
3467 | static int nl80211_send_survey(struct sk_buff *msg, u32 pid, u32 seq, |
3468 | int flags, struct net_device *dev, | |
3469 | struct survey_info *survey) | |
3470 | { | |
3471 | void *hdr; | |
3472 | struct nlattr *infoattr; | |
3473 | ||
3474 | /* Survey without a channel doesn't make sense */ | |
3475 | if (!survey->channel) | |
3476 | return -EINVAL; | |
3477 | ||
3478 | hdr = nl80211hdr_put(msg, pid, seq, flags, | |
3479 | NL80211_CMD_NEW_SURVEY_RESULTS); | |
3480 | if (!hdr) | |
3481 | return -ENOMEM; | |
3482 | ||
3483 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, dev->ifindex); | |
3484 | ||
3485 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
3486 | if (!infoattr) | |
3487 | goto nla_put_failure; | |
3488 | ||
3489 | NLA_PUT_U32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
3490 | survey->channel->center_freq); | |
3491 | if (survey->filled & SURVEY_INFO_NOISE_DBM) | |
3492 | NLA_PUT_U8(msg, NL80211_SURVEY_INFO_NOISE, | |
3493 | survey->noise); | |
17e5a808 FF |
3494 | if (survey->filled & SURVEY_INFO_IN_USE) |
3495 | NLA_PUT_FLAG(msg, NL80211_SURVEY_INFO_IN_USE); | |
61fa713c HS |
3496 | |
3497 | nla_nest_end(msg, infoattr); | |
3498 | ||
3499 | return genlmsg_end(msg, hdr); | |
3500 | ||
3501 | nla_put_failure: | |
3502 | genlmsg_cancel(msg, hdr); | |
3503 | return -EMSGSIZE; | |
3504 | } | |
3505 | ||
3506 | static int nl80211_dump_survey(struct sk_buff *skb, | |
3507 | struct netlink_callback *cb) | |
3508 | { | |
3509 | struct survey_info survey; | |
3510 | struct cfg80211_registered_device *dev; | |
3511 | struct net_device *netdev; | |
3512 | int ifidx = cb->args[0]; | |
3513 | int survey_idx = cb->args[1]; | |
3514 | int res; | |
3515 | ||
3516 | if (!ifidx) | |
3517 | ifidx = nl80211_get_ifidx(cb); | |
3518 | if (ifidx < 0) | |
3519 | return ifidx; | |
3520 | cb->args[0] = ifidx; | |
3521 | ||
3522 | rtnl_lock(); | |
3523 | ||
3524 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); | |
3525 | if (!netdev) { | |
3526 | res = -ENODEV; | |
3527 | goto out_rtnl; | |
3528 | } | |
3529 | ||
3530 | dev = cfg80211_get_dev_from_ifindex(sock_net(skb->sk), ifidx); | |
3531 | if (IS_ERR(dev)) { | |
3532 | res = PTR_ERR(dev); | |
3533 | goto out_rtnl; | |
3534 | } | |
3535 | ||
3536 | if (!dev->ops->dump_survey) { | |
3537 | res = -EOPNOTSUPP; | |
3538 | goto out_err; | |
3539 | } | |
3540 | ||
3541 | while (1) { | |
3542 | res = dev->ops->dump_survey(&dev->wiphy, netdev, survey_idx, | |
3543 | &survey); | |
3544 | if (res == -ENOENT) | |
3545 | break; | |
3546 | if (res) | |
3547 | goto out_err; | |
3548 | ||
3549 | if (nl80211_send_survey(skb, | |
3550 | NETLINK_CB(cb->skb).pid, | |
3551 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
3552 | netdev, | |
3553 | &survey) < 0) | |
3554 | goto out; | |
3555 | survey_idx++; | |
3556 | } | |
3557 | ||
3558 | out: | |
3559 | cb->args[1] = survey_idx; | |
3560 | res = skb->len; | |
3561 | out_err: | |
3562 | cfg80211_unlock_rdev(dev); | |
3563 | out_rtnl: | |
3564 | rtnl_unlock(); | |
3565 | ||
3566 | return res; | |
3567 | } | |
3568 | ||
255e737e JM |
3569 | static bool nl80211_valid_auth_type(enum nl80211_auth_type auth_type) |
3570 | { | |
b23aa676 SO |
3571 | return auth_type <= NL80211_AUTHTYPE_MAX; |
3572 | } | |
3573 | ||
3574 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) | |
3575 | { | |
3576 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
3577 | NL80211_WPA_VERSION_2)); | |
3578 | } | |
3579 | ||
3580 | static bool nl80211_valid_akm_suite(u32 akm) | |
3581 | { | |
3582 | return akm == WLAN_AKM_SUITE_8021X || | |
3583 | akm == WLAN_AKM_SUITE_PSK; | |
3584 | } | |
3585 | ||
3586 | static bool nl80211_valid_cipher_suite(u32 cipher) | |
3587 | { | |
3588 | return cipher == WLAN_CIPHER_SUITE_WEP40 || | |
3589 | cipher == WLAN_CIPHER_SUITE_WEP104 || | |
3590 | cipher == WLAN_CIPHER_SUITE_TKIP || | |
3591 | cipher == WLAN_CIPHER_SUITE_CCMP || | |
3592 | cipher == WLAN_CIPHER_SUITE_AES_CMAC; | |
255e737e JM |
3593 | } |
3594 | ||
b23aa676 | 3595 | |
636a5d36 JM |
3596 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
3597 | { | |
79c97e97 | 3598 | struct cfg80211_registered_device *rdev; |
636a5d36 | 3599 | struct net_device *dev; |
19957bb3 JB |
3600 | struct ieee80211_channel *chan; |
3601 | const u8 *bssid, *ssid, *ie = NULL; | |
3602 | int err, ssid_len, ie_len = 0; | |
3603 | enum nl80211_auth_type auth_type; | |
fffd0934 | 3604 | struct key_parse key; |
d5cdfacb | 3605 | bool local_state_change; |
636a5d36 | 3606 | |
f4a11bb0 JB |
3607 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3608 | return -EINVAL; | |
3609 | ||
3610 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3611 | return -EINVAL; | |
3612 | ||
1778092e JM |
3613 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
3614 | return -EINVAL; | |
3615 | ||
19957bb3 JB |
3616 | if (!info->attrs[NL80211_ATTR_SSID]) |
3617 | return -EINVAL; | |
3618 | ||
3619 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
3620 | return -EINVAL; | |
3621 | ||
fffd0934 JB |
3622 | err = nl80211_parse_key(info, &key); |
3623 | if (err) | |
3624 | return err; | |
3625 | ||
3626 | if (key.idx >= 0) { | |
3627 | if (!key.p.key || !key.p.key_len) | |
3628 | return -EINVAL; | |
3629 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
3630 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
3631 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
3632 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
3633 | return -EINVAL; | |
3634 | if (key.idx > 4) | |
3635 | return -EINVAL; | |
3636 | } else { | |
3637 | key.p.key_len = 0; | |
3638 | key.p.key = NULL; | |
3639 | } | |
3640 | ||
636a5d36 JM |
3641 | rtnl_lock(); |
3642 | ||
463d0183 | 3643 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
636a5d36 JM |
3644 | if (err) |
3645 | goto unlock_rtnl; | |
3646 | ||
afea0b7a JB |
3647 | if (key.idx >= 0) { |
3648 | int i; | |
3649 | bool ok = false; | |
3650 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
3651 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
3652 | ok = true; | |
3653 | break; | |
3654 | } | |
3655 | } | |
3656 | if (!ok) { | |
3657 | err = -EINVAL; | |
3658 | goto out; | |
3659 | } | |
3660 | } | |
3661 | ||
79c97e97 | 3662 | if (!rdev->ops->auth) { |
636a5d36 JM |
3663 | err = -EOPNOTSUPP; |
3664 | goto out; | |
3665 | } | |
3666 | ||
074ac8df JB |
3667 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
3668 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
eec60b03 JM |
3669 | err = -EOPNOTSUPP; |
3670 | goto out; | |
3671 | } | |
3672 | ||
35a8efe1 JM |
3673 | if (!netif_running(dev)) { |
3674 | err = -ENETDOWN; | |
3675 | goto out; | |
3676 | } | |
3677 | ||
19957bb3 | 3678 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
79c97e97 | 3679 | chan = ieee80211_get_channel(&rdev->wiphy, |
19957bb3 JB |
3680 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); |
3681 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { | |
3682 | err = -EINVAL; | |
3683 | goto out; | |
636a5d36 JM |
3684 | } |
3685 | ||
19957bb3 JB |
3686 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
3687 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
3688 | |
3689 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
3690 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
3691 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
3692 | } |
3693 | ||
19957bb3 JB |
3694 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
3695 | if (!nl80211_valid_auth_type(auth_type)) { | |
1778092e JM |
3696 | err = -EINVAL; |
3697 | goto out; | |
636a5d36 JM |
3698 | } |
3699 | ||
d5cdfacb JM |
3700 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
3701 | ||
79c97e97 | 3702 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, |
fffd0934 | 3703 | ssid, ssid_len, ie, ie_len, |
d5cdfacb JM |
3704 | key.p.key, key.p.key_len, key.idx, |
3705 | local_state_change); | |
636a5d36 JM |
3706 | |
3707 | out: | |
79c97e97 | 3708 | cfg80211_unlock_rdev(rdev); |
636a5d36 JM |
3709 | dev_put(dev); |
3710 | unlock_rtnl: | |
3711 | rtnl_unlock(); | |
3712 | return err; | |
3713 | } | |
3714 | ||
c0692b8f JB |
3715 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
3716 | struct genl_info *info, | |
3dc27d25 JB |
3717 | struct cfg80211_crypto_settings *settings, |
3718 | int cipher_limit) | |
b23aa676 | 3719 | { |
c0b2bbd8 JB |
3720 | memset(settings, 0, sizeof(*settings)); |
3721 | ||
b23aa676 SO |
3722 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
3723 | ||
c0692b8f JB |
3724 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
3725 | u16 proto; | |
3726 | proto = nla_get_u16( | |
3727 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
3728 | settings->control_port_ethertype = cpu_to_be16(proto); | |
3729 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
3730 | proto != ETH_P_PAE) | |
3731 | return -EINVAL; | |
3732 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
3733 | settings->control_port_no_encrypt = true; | |
3734 | } else | |
3735 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
3736 | ||
b23aa676 SO |
3737 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
3738 | void *data; | |
3739 | int len, i; | |
3740 | ||
3741 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
3742 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
3743 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
3744 | ||
3745 | if (len % sizeof(u32)) | |
3746 | return -EINVAL; | |
3747 | ||
3dc27d25 | 3748 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
3749 | return -EINVAL; |
3750 | ||
3751 | memcpy(settings->ciphers_pairwise, data, len); | |
3752 | ||
3753 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
3754 | if (!nl80211_valid_cipher_suite( | |
3755 | settings->ciphers_pairwise[i])) | |
3756 | return -EINVAL; | |
3757 | } | |
3758 | ||
3759 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
3760 | settings->cipher_group = | |
3761 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
3762 | if (!nl80211_valid_cipher_suite(settings->cipher_group)) | |
3763 | return -EINVAL; | |
3764 | } | |
3765 | ||
3766 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
3767 | settings->wpa_versions = | |
3768 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
3769 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
3770 | return -EINVAL; | |
3771 | } | |
3772 | ||
3773 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
3774 | void *data; | |
3775 | int len, i; | |
3776 | ||
3777 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
3778 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
3779 | settings->n_akm_suites = len / sizeof(u32); | |
3780 | ||
3781 | if (len % sizeof(u32)) | |
3782 | return -EINVAL; | |
3783 | ||
3784 | memcpy(settings->akm_suites, data, len); | |
3785 | ||
3786 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
3787 | if (!nl80211_valid_akm_suite(settings->akm_suites[i])) | |
3788 | return -EINVAL; | |
3789 | } | |
3790 | ||
3791 | return 0; | |
3792 | } | |
3793 | ||
636a5d36 JM |
3794 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
3795 | { | |
19957bb3 | 3796 | struct cfg80211_registered_device *rdev; |
636a5d36 | 3797 | struct net_device *dev; |
19957bb3 | 3798 | struct cfg80211_crypto_settings crypto; |
f444de05 | 3799 | struct ieee80211_channel *chan; |
3e5d7649 | 3800 | const u8 *bssid, *ssid, *ie = NULL, *prev_bssid = NULL; |
19957bb3 JB |
3801 | int err, ssid_len, ie_len = 0; |
3802 | bool use_mfp = false; | |
636a5d36 | 3803 | |
f4a11bb0 JB |
3804 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3805 | return -EINVAL; | |
3806 | ||
3807 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
3808 | !info->attrs[NL80211_ATTR_SSID] || |
3809 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
3810 | return -EINVAL; |
3811 | ||
636a5d36 JM |
3812 | rtnl_lock(); |
3813 | ||
463d0183 | 3814 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
636a5d36 JM |
3815 | if (err) |
3816 | goto unlock_rtnl; | |
3817 | ||
19957bb3 | 3818 | if (!rdev->ops->assoc) { |
636a5d36 JM |
3819 | err = -EOPNOTSUPP; |
3820 | goto out; | |
3821 | } | |
3822 | ||
074ac8df JB |
3823 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
3824 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
eec60b03 JM |
3825 | err = -EOPNOTSUPP; |
3826 | goto out; | |
3827 | } | |
3828 | ||
35a8efe1 JM |
3829 | if (!netif_running(dev)) { |
3830 | err = -ENETDOWN; | |
3831 | goto out; | |
3832 | } | |
3833 | ||
19957bb3 | 3834 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 3835 | |
19957bb3 JB |
3836 | chan = ieee80211_get_channel(&rdev->wiphy, |
3837 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
3838 | if (!chan || (chan->flags & IEEE80211_CHAN_DISABLED)) { | |
3839 | err = -EINVAL; | |
3840 | goto out; | |
636a5d36 JM |
3841 | } |
3842 | ||
19957bb3 JB |
3843 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
3844 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
3845 | |
3846 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
3847 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
3848 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
3849 | } |
3850 | ||
dc6382ce | 3851 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 3852 | enum nl80211_mfp mfp = |
dc6382ce | 3853 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 3854 | if (mfp == NL80211_MFP_REQUIRED) |
19957bb3 | 3855 | use_mfp = true; |
4f5dadce | 3856 | else if (mfp != NL80211_MFP_NO) { |
dc6382ce JM |
3857 | err = -EINVAL; |
3858 | goto out; | |
3859 | } | |
3860 | } | |
3861 | ||
3e5d7649 JB |
3862 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
3863 | prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
3864 | ||
c0692b8f | 3865 | err = nl80211_crypto_settings(rdev, info, &crypto, 1); |
b23aa676 | 3866 | if (!err) |
3e5d7649 JB |
3867 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, prev_bssid, |
3868 | ssid, ssid_len, ie, ie_len, use_mfp, | |
19957bb3 | 3869 | &crypto); |
636a5d36 JM |
3870 | |
3871 | out: | |
4d0c8aea | 3872 | cfg80211_unlock_rdev(rdev); |
636a5d36 JM |
3873 | dev_put(dev); |
3874 | unlock_rtnl: | |
3875 | rtnl_unlock(); | |
3876 | return err; | |
3877 | } | |
3878 | ||
3879 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
3880 | { | |
79c97e97 | 3881 | struct cfg80211_registered_device *rdev; |
636a5d36 | 3882 | struct net_device *dev; |
19957bb3 JB |
3883 | const u8 *ie = NULL, *bssid; |
3884 | int err, ie_len = 0; | |
3885 | u16 reason_code; | |
d5cdfacb | 3886 | bool local_state_change; |
636a5d36 | 3887 | |
f4a11bb0 JB |
3888 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3889 | return -EINVAL; | |
3890 | ||
3891 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3892 | return -EINVAL; | |
3893 | ||
3894 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
3895 | return -EINVAL; | |
3896 | ||
636a5d36 JM |
3897 | rtnl_lock(); |
3898 | ||
463d0183 | 3899 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
636a5d36 JM |
3900 | if (err) |
3901 | goto unlock_rtnl; | |
3902 | ||
79c97e97 | 3903 | if (!rdev->ops->deauth) { |
636a5d36 JM |
3904 | err = -EOPNOTSUPP; |
3905 | goto out; | |
3906 | } | |
3907 | ||
074ac8df JB |
3908 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
3909 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
eec60b03 JM |
3910 | err = -EOPNOTSUPP; |
3911 | goto out; | |
3912 | } | |
3913 | ||
35a8efe1 JM |
3914 | if (!netif_running(dev)) { |
3915 | err = -ENETDOWN; | |
3916 | goto out; | |
3917 | } | |
3918 | ||
19957bb3 | 3919 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 3920 | |
19957bb3 JB |
3921 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
3922 | if (reason_code == 0) { | |
f4a11bb0 JB |
3923 | /* Reason Code 0 is reserved */ |
3924 | err = -EINVAL; | |
3925 | goto out; | |
255e737e | 3926 | } |
636a5d36 JM |
3927 | |
3928 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
3929 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
3930 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
3931 | } |
3932 | ||
d5cdfacb JM |
3933 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
3934 | ||
3935 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
3936 | local_state_change); | |
636a5d36 JM |
3937 | |
3938 | out: | |
79c97e97 | 3939 | cfg80211_unlock_rdev(rdev); |
636a5d36 JM |
3940 | dev_put(dev); |
3941 | unlock_rtnl: | |
3942 | rtnl_unlock(); | |
3943 | return err; | |
3944 | } | |
3945 | ||
3946 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
3947 | { | |
79c97e97 | 3948 | struct cfg80211_registered_device *rdev; |
636a5d36 | 3949 | struct net_device *dev; |
19957bb3 JB |
3950 | const u8 *ie = NULL, *bssid; |
3951 | int err, ie_len = 0; | |
3952 | u16 reason_code; | |
d5cdfacb | 3953 | bool local_state_change; |
636a5d36 | 3954 | |
f4a11bb0 JB |
3955 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
3956 | return -EINVAL; | |
3957 | ||
3958 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3959 | return -EINVAL; | |
3960 | ||
3961 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
3962 | return -EINVAL; | |
3963 | ||
636a5d36 JM |
3964 | rtnl_lock(); |
3965 | ||
463d0183 | 3966 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
636a5d36 JM |
3967 | if (err) |
3968 | goto unlock_rtnl; | |
3969 | ||
79c97e97 | 3970 | if (!rdev->ops->disassoc) { |
636a5d36 JM |
3971 | err = -EOPNOTSUPP; |
3972 | goto out; | |
3973 | } | |
3974 | ||
074ac8df JB |
3975 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
3976 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
eec60b03 JM |
3977 | err = -EOPNOTSUPP; |
3978 | goto out; | |
3979 | } | |
3980 | ||
35a8efe1 JM |
3981 | if (!netif_running(dev)) { |
3982 | err = -ENETDOWN; | |
3983 | goto out; | |
3984 | } | |
3985 | ||
19957bb3 | 3986 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 3987 | |
19957bb3 JB |
3988 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
3989 | if (reason_code == 0) { | |
f4a11bb0 JB |
3990 | /* Reason Code 0 is reserved */ |
3991 | err = -EINVAL; | |
3992 | goto out; | |
255e737e | 3993 | } |
636a5d36 JM |
3994 | |
3995 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
3996 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
3997 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
3998 | } |
3999 | ||
d5cdfacb JM |
4000 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
4001 | ||
4002 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
4003 | local_state_change); | |
636a5d36 JM |
4004 | |
4005 | out: | |
79c97e97 | 4006 | cfg80211_unlock_rdev(rdev); |
636a5d36 JM |
4007 | dev_put(dev); |
4008 | unlock_rtnl: | |
4009 | rtnl_unlock(); | |
4010 | return err; | |
4011 | } | |
4012 | ||
04a773ad JB |
4013 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
4014 | { | |
79c97e97 | 4015 | struct cfg80211_registered_device *rdev; |
04a773ad JB |
4016 | struct net_device *dev; |
4017 | struct cfg80211_ibss_params ibss; | |
4018 | struct wiphy *wiphy; | |
fffd0934 | 4019 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
4020 | int err; |
4021 | ||
8e30bc55 JB |
4022 | memset(&ibss, 0, sizeof(ibss)); |
4023 | ||
04a773ad JB |
4024 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
4025 | return -EINVAL; | |
4026 | ||
4027 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
4028 | !info->attrs[NL80211_ATTR_SSID] || | |
4029 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
4030 | return -EINVAL; | |
4031 | ||
8e30bc55 JB |
4032 | ibss.beacon_interval = 100; |
4033 | ||
4034 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
4035 | ibss.beacon_interval = | |
4036 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
4037 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
4038 | return -EINVAL; | |
4039 | } | |
4040 | ||
04a773ad JB |
4041 | rtnl_lock(); |
4042 | ||
463d0183 | 4043 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
04a773ad JB |
4044 | if (err) |
4045 | goto unlock_rtnl; | |
4046 | ||
79c97e97 | 4047 | if (!rdev->ops->join_ibss) { |
04a773ad JB |
4048 | err = -EOPNOTSUPP; |
4049 | goto out; | |
4050 | } | |
4051 | ||
4052 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { | |
4053 | err = -EOPNOTSUPP; | |
4054 | goto out; | |
4055 | } | |
4056 | ||
4057 | if (!netif_running(dev)) { | |
4058 | err = -ENETDOWN; | |
4059 | goto out; | |
4060 | } | |
4061 | ||
79c97e97 | 4062 | wiphy = &rdev->wiphy; |
04a773ad JB |
4063 | |
4064 | if (info->attrs[NL80211_ATTR_MAC]) | |
4065 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4066 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
4067 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4068 | ||
4069 | if (info->attrs[NL80211_ATTR_IE]) { | |
4070 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
4071 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4072 | } | |
4073 | ||
4074 | ibss.channel = ieee80211_get_channel(wiphy, | |
4075 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4076 | if (!ibss.channel || | |
4077 | ibss.channel->flags & IEEE80211_CHAN_NO_IBSS || | |
4078 | ibss.channel->flags & IEEE80211_CHAN_DISABLED) { | |
4079 | err = -EINVAL; | |
4080 | goto out; | |
4081 | } | |
4082 | ||
4083 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; | |
fffd0934 JB |
4084 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
4085 | ||
4086 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { | |
4087 | connkeys = nl80211_parse_connkeys(rdev, | |
4088 | info->attrs[NL80211_ATTR_KEYS]); | |
4089 | if (IS_ERR(connkeys)) { | |
4090 | err = PTR_ERR(connkeys); | |
4091 | connkeys = NULL; | |
4092 | goto out; | |
4093 | } | |
4094 | } | |
04a773ad | 4095 | |
fbd2c8dc TP |
4096 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4097 | u8 *rates = | |
4098 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4099 | int n_rates = | |
4100 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4101 | struct ieee80211_supported_band *sband = | |
4102 | wiphy->bands[ibss.channel->band]; | |
4103 | int i, j; | |
4104 | ||
4105 | if (n_rates == 0) { | |
4106 | err = -EINVAL; | |
4107 | goto out; | |
4108 | } | |
4109 | ||
4110 | for (i = 0; i < n_rates; i++) { | |
4111 | int rate = (rates[i] & 0x7f) * 5; | |
4112 | bool found = false; | |
4113 | ||
4114 | for (j = 0; j < sband->n_bitrates; j++) { | |
4115 | if (sband->bitrates[j].bitrate == rate) { | |
4116 | found = true; | |
4117 | ibss.basic_rates |= BIT(j); | |
4118 | break; | |
4119 | } | |
4120 | } | |
4121 | if (!found) { | |
4122 | err = -EINVAL; | |
4123 | goto out; | |
4124 | } | |
4125 | } | |
fbd2c8dc TP |
4126 | } |
4127 | ||
fffd0934 | 4128 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
04a773ad JB |
4129 | |
4130 | out: | |
79c97e97 | 4131 | cfg80211_unlock_rdev(rdev); |
04a773ad JB |
4132 | dev_put(dev); |
4133 | unlock_rtnl: | |
fffd0934 JB |
4134 | if (err) |
4135 | kfree(connkeys); | |
04a773ad JB |
4136 | rtnl_unlock(); |
4137 | return err; | |
4138 | } | |
4139 | ||
4140 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
4141 | { | |
79c97e97 | 4142 | struct cfg80211_registered_device *rdev; |
04a773ad JB |
4143 | struct net_device *dev; |
4144 | int err; | |
4145 | ||
4146 | rtnl_lock(); | |
4147 | ||
463d0183 | 4148 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
04a773ad JB |
4149 | if (err) |
4150 | goto unlock_rtnl; | |
4151 | ||
79c97e97 | 4152 | if (!rdev->ops->leave_ibss) { |
04a773ad JB |
4153 | err = -EOPNOTSUPP; |
4154 | goto out; | |
4155 | } | |
4156 | ||
4157 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) { | |
4158 | err = -EOPNOTSUPP; | |
4159 | goto out; | |
4160 | } | |
4161 | ||
4162 | if (!netif_running(dev)) { | |
4163 | err = -ENETDOWN; | |
4164 | goto out; | |
4165 | } | |
4166 | ||
79c97e97 | 4167 | err = cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
4168 | |
4169 | out: | |
79c97e97 | 4170 | cfg80211_unlock_rdev(rdev); |
04a773ad JB |
4171 | dev_put(dev); |
4172 | unlock_rtnl: | |
4173 | rtnl_unlock(); | |
4174 | return err; | |
4175 | } | |
4176 | ||
aff89a9b JB |
4177 | #ifdef CONFIG_NL80211_TESTMODE |
4178 | static struct genl_multicast_group nl80211_testmode_mcgrp = { | |
4179 | .name = "testmode", | |
4180 | }; | |
4181 | ||
4182 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) | |
4183 | { | |
4184 | struct cfg80211_registered_device *rdev; | |
4185 | int err; | |
4186 | ||
4187 | if (!info->attrs[NL80211_ATTR_TESTDATA]) | |
4188 | return -EINVAL; | |
4189 | ||
4190 | rtnl_lock(); | |
4191 | ||
4192 | rdev = cfg80211_get_dev_from_info(info); | |
4193 | if (IS_ERR(rdev)) { | |
4194 | err = PTR_ERR(rdev); | |
4195 | goto unlock_rtnl; | |
4196 | } | |
4197 | ||
4198 | err = -EOPNOTSUPP; | |
4199 | if (rdev->ops->testmode_cmd) { | |
4200 | rdev->testmode_info = info; | |
4201 | err = rdev->ops->testmode_cmd(&rdev->wiphy, | |
4202 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), | |
4203 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
4204 | rdev->testmode_info = NULL; | |
4205 | } | |
4206 | ||
4d0c8aea | 4207 | cfg80211_unlock_rdev(rdev); |
aff89a9b JB |
4208 | |
4209 | unlock_rtnl: | |
4210 | rtnl_unlock(); | |
4211 | return err; | |
4212 | } | |
4213 | ||
4214 | static struct sk_buff * | |
4215 | __cfg80211_testmode_alloc_skb(struct cfg80211_registered_device *rdev, | |
4216 | int approxlen, u32 pid, u32 seq, gfp_t gfp) | |
4217 | { | |
4218 | struct sk_buff *skb; | |
4219 | void *hdr; | |
4220 | struct nlattr *data; | |
4221 | ||
4222 | skb = nlmsg_new(approxlen + 100, gfp); | |
4223 | if (!skb) | |
4224 | return NULL; | |
4225 | ||
4226 | hdr = nl80211hdr_put(skb, pid, seq, 0, NL80211_CMD_TESTMODE); | |
4227 | if (!hdr) { | |
4228 | kfree_skb(skb); | |
4229 | return NULL; | |
4230 | } | |
4231 | ||
4232 | NLA_PUT_U32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
4233 | data = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
4234 | ||
4235 | ((void **)skb->cb)[0] = rdev; | |
4236 | ((void **)skb->cb)[1] = hdr; | |
4237 | ((void **)skb->cb)[2] = data; | |
4238 | ||
4239 | return skb; | |
4240 | ||
4241 | nla_put_failure: | |
4242 | kfree_skb(skb); | |
4243 | return NULL; | |
4244 | } | |
4245 | ||
4246 | struct sk_buff *cfg80211_testmode_alloc_reply_skb(struct wiphy *wiphy, | |
4247 | int approxlen) | |
4248 | { | |
4249 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
4250 | ||
4251 | if (WARN_ON(!rdev->testmode_info)) | |
4252 | return NULL; | |
4253 | ||
4254 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, | |
4255 | rdev->testmode_info->snd_pid, | |
4256 | rdev->testmode_info->snd_seq, | |
4257 | GFP_KERNEL); | |
4258 | } | |
4259 | EXPORT_SYMBOL(cfg80211_testmode_alloc_reply_skb); | |
4260 | ||
4261 | int cfg80211_testmode_reply(struct sk_buff *skb) | |
4262 | { | |
4263 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
4264 | void *hdr = ((void **)skb->cb)[1]; | |
4265 | struct nlattr *data = ((void **)skb->cb)[2]; | |
4266 | ||
4267 | if (WARN_ON(!rdev->testmode_info)) { | |
4268 | kfree_skb(skb); | |
4269 | return -EINVAL; | |
4270 | } | |
4271 | ||
4272 | nla_nest_end(skb, data); | |
4273 | genlmsg_end(skb, hdr); | |
4274 | return genlmsg_reply(skb, rdev->testmode_info); | |
4275 | } | |
4276 | EXPORT_SYMBOL(cfg80211_testmode_reply); | |
4277 | ||
4278 | struct sk_buff *cfg80211_testmode_alloc_event_skb(struct wiphy *wiphy, | |
4279 | int approxlen, gfp_t gfp) | |
4280 | { | |
4281 | struct cfg80211_registered_device *rdev = wiphy_to_dev(wiphy); | |
4282 | ||
4283 | return __cfg80211_testmode_alloc_skb(rdev, approxlen, 0, 0, gfp); | |
4284 | } | |
4285 | EXPORT_SYMBOL(cfg80211_testmode_alloc_event_skb); | |
4286 | ||
4287 | void cfg80211_testmode_event(struct sk_buff *skb, gfp_t gfp) | |
4288 | { | |
4289 | void *hdr = ((void **)skb->cb)[1]; | |
4290 | struct nlattr *data = ((void **)skb->cb)[2]; | |
4291 | ||
4292 | nla_nest_end(skb, data); | |
4293 | genlmsg_end(skb, hdr); | |
4294 | genlmsg_multicast(skb, 0, nl80211_testmode_mcgrp.id, gfp); | |
4295 | } | |
4296 | EXPORT_SYMBOL(cfg80211_testmode_event); | |
4297 | #endif | |
4298 | ||
b23aa676 SO |
4299 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
4300 | { | |
79c97e97 | 4301 | struct cfg80211_registered_device *rdev; |
b23aa676 SO |
4302 | struct net_device *dev; |
4303 | struct cfg80211_connect_params connect; | |
4304 | struct wiphy *wiphy; | |
fffd0934 | 4305 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
4306 | int err; |
4307 | ||
4308 | memset(&connect, 0, sizeof(connect)); | |
4309 | ||
4310 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
4311 | return -EINVAL; | |
4312 | ||
4313 | if (!info->attrs[NL80211_ATTR_SSID] || | |
4314 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
4315 | return -EINVAL; | |
4316 | ||
4317 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
4318 | connect.auth_type = | |
4319 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
4320 | if (!nl80211_valid_auth_type(connect.auth_type)) | |
4321 | return -EINVAL; | |
4322 | } else | |
4323 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
4324 | ||
4325 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
4326 | ||
c0692b8f | 4327 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 4328 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
4329 | if (err) |
4330 | return err; | |
4331 | rtnl_lock(); | |
4332 | ||
463d0183 | 4333 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
b23aa676 SO |
4334 | if (err) |
4335 | goto unlock_rtnl; | |
4336 | ||
074ac8df JB |
4337 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4338 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
b23aa676 SO |
4339 | err = -EOPNOTSUPP; |
4340 | goto out; | |
4341 | } | |
4342 | ||
4343 | if (!netif_running(dev)) { | |
4344 | err = -ENETDOWN; | |
4345 | goto out; | |
4346 | } | |
4347 | ||
79c97e97 | 4348 | wiphy = &rdev->wiphy; |
b23aa676 | 4349 | |
b23aa676 SO |
4350 | if (info->attrs[NL80211_ATTR_MAC]) |
4351 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4352 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
4353 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
4354 | ||
4355 | if (info->attrs[NL80211_ATTR_IE]) { | |
4356 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
4357 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
4358 | } | |
4359 | ||
4360 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
4361 | connect.channel = | |
4362 | ieee80211_get_channel(wiphy, | |
4363 | nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ])); | |
4364 | if (!connect.channel || | |
4365 | connect.channel->flags & IEEE80211_CHAN_DISABLED) { | |
4366 | err = -EINVAL; | |
4367 | goto out; | |
4368 | } | |
4369 | } | |
4370 | ||
fffd0934 JB |
4371 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
4372 | connkeys = nl80211_parse_connkeys(rdev, | |
4373 | info->attrs[NL80211_ATTR_KEYS]); | |
4374 | if (IS_ERR(connkeys)) { | |
4375 | err = PTR_ERR(connkeys); | |
4376 | connkeys = NULL; | |
4377 | goto out; | |
4378 | } | |
4379 | } | |
4380 | ||
4381 | err = cfg80211_connect(rdev, dev, &connect, connkeys); | |
b23aa676 SO |
4382 | |
4383 | out: | |
79c97e97 | 4384 | cfg80211_unlock_rdev(rdev); |
b23aa676 SO |
4385 | dev_put(dev); |
4386 | unlock_rtnl: | |
fffd0934 JB |
4387 | if (err) |
4388 | kfree(connkeys); | |
b23aa676 SO |
4389 | rtnl_unlock(); |
4390 | return err; | |
4391 | } | |
4392 | ||
4393 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
4394 | { | |
79c97e97 | 4395 | struct cfg80211_registered_device *rdev; |
b23aa676 SO |
4396 | struct net_device *dev; |
4397 | int err; | |
4398 | u16 reason; | |
4399 | ||
4400 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
4401 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
4402 | else | |
4403 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4404 | ||
4405 | if (reason == 0) | |
4406 | return -EINVAL; | |
4407 | ||
4408 | rtnl_lock(); | |
4409 | ||
463d0183 | 4410 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); |
b23aa676 SO |
4411 | if (err) |
4412 | goto unlock_rtnl; | |
4413 | ||
074ac8df JB |
4414 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4415 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
b23aa676 SO |
4416 | err = -EOPNOTSUPP; |
4417 | goto out; | |
4418 | } | |
4419 | ||
4420 | if (!netif_running(dev)) { | |
4421 | err = -ENETDOWN; | |
4422 | goto out; | |
4423 | } | |
4424 | ||
79c97e97 | 4425 | err = cfg80211_disconnect(rdev, dev, reason, true); |
b23aa676 SO |
4426 | |
4427 | out: | |
79c97e97 | 4428 | cfg80211_unlock_rdev(rdev); |
b23aa676 SO |
4429 | dev_put(dev); |
4430 | unlock_rtnl: | |
4431 | rtnl_unlock(); | |
4432 | return err; | |
4433 | } | |
4434 | ||
463d0183 JB |
4435 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
4436 | { | |
4437 | struct cfg80211_registered_device *rdev; | |
4438 | struct net *net; | |
4439 | int err; | |
4440 | u32 pid; | |
4441 | ||
4442 | if (!info->attrs[NL80211_ATTR_PID]) | |
4443 | return -EINVAL; | |
4444 | ||
4445 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
4446 | ||
4447 | rtnl_lock(); | |
4448 | ||
4449 | rdev = cfg80211_get_dev_from_info(info); | |
4450 | if (IS_ERR(rdev)) { | |
4451 | err = PTR_ERR(rdev); | |
8a8e05e5 | 4452 | goto out_rtnl; |
463d0183 JB |
4453 | } |
4454 | ||
4455 | net = get_net_ns_by_pid(pid); | |
4456 | if (IS_ERR(net)) { | |
4457 | err = PTR_ERR(net); | |
4458 | goto out; | |
4459 | } | |
4460 | ||
4461 | err = 0; | |
4462 | ||
4463 | /* check if anything to do */ | |
4464 | if (net_eq(wiphy_net(&rdev->wiphy), net)) | |
4465 | goto out_put_net; | |
4466 | ||
4467 | err = cfg80211_switch_netns(rdev, net); | |
4468 | out_put_net: | |
4469 | put_net(net); | |
4470 | out: | |
4471 | cfg80211_unlock_rdev(rdev); | |
8a8e05e5 | 4472 | out_rtnl: |
463d0183 JB |
4473 | rtnl_unlock(); |
4474 | return err; | |
4475 | } | |
4476 | ||
67fbb16b SO |
4477 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
4478 | { | |
4479 | struct cfg80211_registered_device *rdev; | |
4480 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, | |
4481 | struct cfg80211_pmksa *pmksa) = NULL; | |
4482 | int err; | |
4483 | struct net_device *dev; | |
4484 | struct cfg80211_pmksa pmksa; | |
4485 | ||
4486 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
4487 | ||
4488 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4489 | return -EINVAL; | |
4490 | ||
4491 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
4492 | return -EINVAL; | |
4493 | ||
4494 | rtnl_lock(); | |
4495 | ||
4496 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4497 | if (err) | |
4498 | goto out_rtnl; | |
4499 | ||
4500 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); | |
4501 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4502 | ||
074ac8df JB |
4503 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4504 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
67fbb16b SO |
4505 | err = -EOPNOTSUPP; |
4506 | goto out; | |
4507 | } | |
4508 | ||
4509 | switch (info->genlhdr->cmd) { | |
4510 | case NL80211_CMD_SET_PMKSA: | |
4511 | rdev_ops = rdev->ops->set_pmksa; | |
4512 | break; | |
4513 | case NL80211_CMD_DEL_PMKSA: | |
4514 | rdev_ops = rdev->ops->del_pmksa; | |
4515 | break; | |
4516 | default: | |
4517 | WARN_ON(1); | |
4518 | break; | |
4519 | } | |
4520 | ||
4521 | if (!rdev_ops) { | |
4522 | err = -EOPNOTSUPP; | |
4523 | goto out; | |
4524 | } | |
4525 | ||
4526 | err = rdev_ops(&rdev->wiphy, dev, &pmksa); | |
4527 | ||
4528 | out: | |
4529 | cfg80211_unlock_rdev(rdev); | |
4530 | dev_put(dev); | |
4531 | out_rtnl: | |
4532 | rtnl_unlock(); | |
4533 | ||
4534 | return err; | |
4535 | } | |
4536 | ||
4537 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
4538 | { | |
4539 | struct cfg80211_registered_device *rdev; | |
4540 | int err; | |
4541 | struct net_device *dev; | |
4542 | ||
4543 | rtnl_lock(); | |
4544 | ||
4545 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4546 | if (err) | |
4547 | goto out_rtnl; | |
4548 | ||
074ac8df JB |
4549 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4550 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
67fbb16b SO |
4551 | err = -EOPNOTSUPP; |
4552 | goto out; | |
4553 | } | |
4554 | ||
4555 | if (!rdev->ops->flush_pmksa) { | |
4556 | err = -EOPNOTSUPP; | |
4557 | goto out; | |
4558 | } | |
4559 | ||
4560 | err = rdev->ops->flush_pmksa(&rdev->wiphy, dev); | |
4561 | ||
4562 | out: | |
4563 | cfg80211_unlock_rdev(rdev); | |
4564 | dev_put(dev); | |
4565 | out_rtnl: | |
4566 | rtnl_unlock(); | |
4567 | ||
4568 | return err; | |
4569 | ||
4570 | } | |
4571 | ||
9588bbd5 JM |
4572 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
4573 | struct genl_info *info) | |
4574 | { | |
4575 | struct cfg80211_registered_device *rdev; | |
4576 | struct net_device *dev; | |
4577 | struct ieee80211_channel *chan; | |
4578 | struct sk_buff *msg; | |
4579 | void *hdr; | |
4580 | u64 cookie; | |
4581 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
4582 | u32 freq, duration; | |
4583 | int err; | |
4584 | ||
4585 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
4586 | !info->attrs[NL80211_ATTR_DURATION]) | |
4587 | return -EINVAL; | |
4588 | ||
4589 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
4590 | ||
4591 | /* | |
4592 | * We should be on that channel for at least one jiffie, | |
4593 | * and more than 5 seconds seems excessive. | |
4594 | */ | |
4595 | if (!duration || !msecs_to_jiffies(duration) || duration > 5000) | |
4596 | return -EINVAL; | |
4597 | ||
4598 | rtnl_lock(); | |
4599 | ||
4600 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4601 | if (err) | |
4602 | goto unlock_rtnl; | |
4603 | ||
4604 | if (!rdev->ops->remain_on_channel) { | |
4605 | err = -EOPNOTSUPP; | |
4606 | goto out; | |
4607 | } | |
4608 | ||
4609 | if (!netif_running(dev)) { | |
4610 | err = -ENETDOWN; | |
4611 | goto out; | |
4612 | } | |
4613 | ||
4614 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
4615 | channel_type = nla_get_u32( | |
4616 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
4617 | if (channel_type != NL80211_CHAN_NO_HT && | |
4618 | channel_type != NL80211_CHAN_HT20 && | |
4619 | channel_type != NL80211_CHAN_HT40PLUS && | |
579d7534 | 4620 | channel_type != NL80211_CHAN_HT40MINUS) { |
9588bbd5 JM |
4621 | err = -EINVAL; |
4622 | goto out; | |
579d7534 | 4623 | } |
9588bbd5 JM |
4624 | } |
4625 | ||
4626 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
4627 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4628 | if (chan == NULL) { | |
4629 | err = -EINVAL; | |
4630 | goto out; | |
4631 | } | |
4632 | ||
4633 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4634 | if (!msg) { | |
4635 | err = -ENOMEM; | |
4636 | goto out; | |
4637 | } | |
4638 | ||
4639 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
4640 | NL80211_CMD_REMAIN_ON_CHANNEL); | |
4641 | ||
4642 | if (IS_ERR(hdr)) { | |
4643 | err = PTR_ERR(hdr); | |
4644 | goto free_msg; | |
4645 | } | |
4646 | ||
4647 | err = rdev->ops->remain_on_channel(&rdev->wiphy, dev, chan, | |
4648 | channel_type, duration, &cookie); | |
4649 | ||
4650 | if (err) | |
4651 | goto free_msg; | |
4652 | ||
4653 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
4654 | ||
4655 | genlmsg_end(msg, hdr); | |
4656 | err = genlmsg_reply(msg, info); | |
4657 | goto out; | |
4658 | ||
4659 | nla_put_failure: | |
4660 | err = -ENOBUFS; | |
4661 | free_msg: | |
4662 | nlmsg_free(msg); | |
4663 | out: | |
4664 | cfg80211_unlock_rdev(rdev); | |
4665 | dev_put(dev); | |
4666 | unlock_rtnl: | |
4667 | rtnl_unlock(); | |
4668 | return err; | |
4669 | } | |
4670 | ||
4671 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
4672 | struct genl_info *info) | |
4673 | { | |
4674 | struct cfg80211_registered_device *rdev; | |
4675 | struct net_device *dev; | |
4676 | u64 cookie; | |
4677 | int err; | |
4678 | ||
4679 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
4680 | return -EINVAL; | |
4681 | ||
4682 | rtnl_lock(); | |
4683 | ||
4684 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4685 | if (err) | |
4686 | goto unlock_rtnl; | |
4687 | ||
4688 | if (!rdev->ops->cancel_remain_on_channel) { | |
4689 | err = -EOPNOTSUPP; | |
4690 | goto out; | |
4691 | } | |
4692 | ||
4693 | if (!netif_running(dev)) { | |
4694 | err = -ENETDOWN; | |
4695 | goto out; | |
4696 | } | |
4697 | ||
4698 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
4699 | ||
4700 | err = rdev->ops->cancel_remain_on_channel(&rdev->wiphy, dev, cookie); | |
4701 | ||
4702 | out: | |
4703 | cfg80211_unlock_rdev(rdev); | |
4704 | dev_put(dev); | |
4705 | unlock_rtnl: | |
4706 | rtnl_unlock(); | |
4707 | return err; | |
4708 | } | |
4709 | ||
13ae75b1 JM |
4710 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
4711 | u8 *rates, u8 rates_len) | |
4712 | { | |
4713 | u8 i; | |
4714 | u32 mask = 0; | |
4715 | ||
4716 | for (i = 0; i < rates_len; i++) { | |
4717 | int rate = (rates[i] & 0x7f) * 5; | |
4718 | int ridx; | |
4719 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
4720 | struct ieee80211_rate *srate = | |
4721 | &sband->bitrates[ridx]; | |
4722 | if (rate == srate->bitrate) { | |
4723 | mask |= 1 << ridx; | |
4724 | break; | |
4725 | } | |
4726 | } | |
4727 | if (ridx == sband->n_bitrates) | |
4728 | return 0; /* rate not found */ | |
4729 | } | |
4730 | ||
4731 | return mask; | |
4732 | } | |
4733 | ||
b54452b0 | 4734 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
4735 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
4736 | .len = NL80211_MAX_SUPP_RATES }, | |
4737 | }; | |
4738 | ||
4739 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
4740 | struct genl_info *info) | |
4741 | { | |
4742 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4743 | struct cfg80211_registered_device *rdev; | |
4744 | struct cfg80211_bitrate_mask mask; | |
4745 | int err, rem, i; | |
4746 | struct net_device *dev; | |
4747 | struct nlattr *tx_rates; | |
4748 | struct ieee80211_supported_band *sband; | |
4749 | ||
4750 | if (info->attrs[NL80211_ATTR_TX_RATES] == NULL) | |
4751 | return -EINVAL; | |
4752 | ||
4753 | rtnl_lock(); | |
4754 | ||
4755 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4756 | if (err) | |
4757 | goto unlock_rtnl; | |
4758 | ||
4759 | if (!rdev->ops->set_bitrate_mask) { | |
4760 | err = -EOPNOTSUPP; | |
4761 | goto unlock; | |
4762 | } | |
4763 | ||
4764 | memset(&mask, 0, sizeof(mask)); | |
4765 | /* Default to all rates enabled */ | |
4766 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
4767 | sband = rdev->wiphy.bands[i]; | |
4768 | mask.control[i].legacy = | |
4769 | sband ? (1 << sband->n_bitrates) - 1 : 0; | |
4770 | } | |
4771 | ||
4772 | /* | |
4773 | * The nested attribute uses enum nl80211_band as the index. This maps | |
4774 | * directly to the enum ieee80211_band values used in cfg80211. | |
4775 | */ | |
4776 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) | |
4777 | { | |
4778 | enum ieee80211_band band = nla_type(tx_rates); | |
4779 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { | |
4780 | err = -EINVAL; | |
4781 | goto unlock; | |
4782 | } | |
4783 | sband = rdev->wiphy.bands[band]; | |
4784 | if (sband == NULL) { | |
4785 | err = -EINVAL; | |
4786 | goto unlock; | |
4787 | } | |
4788 | nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), | |
4789 | nla_len(tx_rates), nl80211_txattr_policy); | |
4790 | if (tb[NL80211_TXRATE_LEGACY]) { | |
4791 | mask.control[band].legacy = rateset_to_mask( | |
4792 | sband, | |
4793 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
4794 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
4795 | if (mask.control[band].legacy == 0) { | |
4796 | err = -EINVAL; | |
4797 | goto unlock; | |
4798 | } | |
4799 | } | |
4800 | } | |
4801 | ||
4802 | err = rdev->ops->set_bitrate_mask(&rdev->wiphy, dev, NULL, &mask); | |
4803 | ||
4804 | unlock: | |
4805 | dev_put(dev); | |
4806 | cfg80211_unlock_rdev(rdev); | |
4807 | unlock_rtnl: | |
4808 | rtnl_unlock(); | |
4809 | return err; | |
4810 | } | |
4811 | ||
2e161f78 | 4812 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 JM |
4813 | { |
4814 | struct cfg80211_registered_device *rdev; | |
4815 | struct net_device *dev; | |
2e161f78 | 4816 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
4817 | int err; |
4818 | ||
4819 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
4820 | return -EINVAL; | |
4821 | ||
2e161f78 JB |
4822 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
4823 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 JM |
4824 | |
4825 | rtnl_lock(); | |
4826 | ||
4827 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4828 | if (err) | |
4829 | goto unlock_rtnl; | |
4830 | ||
9d38d85d | 4831 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 4832 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
4833 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
4834 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4835 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
4836 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
026331c4 JM |
4837 | err = -EOPNOTSUPP; |
4838 | goto out; | |
4839 | } | |
4840 | ||
4841 | /* not much point in registering if we can't reply */ | |
2e161f78 | 4842 | if (!rdev->ops->mgmt_tx) { |
026331c4 JM |
4843 | err = -EOPNOTSUPP; |
4844 | goto out; | |
4845 | } | |
4846 | ||
2e161f78 JB |
4847 | err = cfg80211_mlme_register_mgmt(dev->ieee80211_ptr, info->snd_pid, |
4848 | frame_type, | |
026331c4 JM |
4849 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
4850 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
4851 | out: | |
4852 | cfg80211_unlock_rdev(rdev); | |
4853 | dev_put(dev); | |
4854 | unlock_rtnl: | |
4855 | rtnl_unlock(); | |
4856 | return err; | |
4857 | } | |
4858 | ||
2e161f78 | 4859 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 JM |
4860 | { |
4861 | struct cfg80211_registered_device *rdev; | |
4862 | struct net_device *dev; | |
4863 | struct ieee80211_channel *chan; | |
4864 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; | |
252aa631 | 4865 | bool channel_type_valid = false; |
026331c4 JM |
4866 | u32 freq; |
4867 | int err; | |
4868 | void *hdr; | |
4869 | u64 cookie; | |
4870 | struct sk_buff *msg; | |
4871 | ||
4872 | if (!info->attrs[NL80211_ATTR_FRAME] || | |
4873 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
4874 | return -EINVAL; | |
4875 | ||
4876 | rtnl_lock(); | |
4877 | ||
4878 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4879 | if (err) | |
4880 | goto unlock_rtnl; | |
4881 | ||
2e161f78 | 4882 | if (!rdev->ops->mgmt_tx) { |
026331c4 JM |
4883 | err = -EOPNOTSUPP; |
4884 | goto out; | |
4885 | } | |
4886 | ||
9d38d85d | 4887 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
074ac8df | 4888 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && |
663fcafd JB |
4889 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT && |
4890 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4891 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && | |
4892 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
026331c4 JM |
4893 | err = -EOPNOTSUPP; |
4894 | goto out; | |
4895 | } | |
4896 | ||
4897 | if (!netif_running(dev)) { | |
4898 | err = -ENETDOWN; | |
4899 | goto out; | |
4900 | } | |
4901 | ||
4902 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | |
4903 | channel_type = nla_get_u32( | |
4904 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
4905 | if (channel_type != NL80211_CHAN_NO_HT && | |
4906 | channel_type != NL80211_CHAN_HT20 && | |
4907 | channel_type != NL80211_CHAN_HT40PLUS && | |
579d7534 | 4908 | channel_type != NL80211_CHAN_HT40MINUS) { |
026331c4 JM |
4909 | err = -EINVAL; |
4910 | goto out; | |
579d7534 | 4911 | } |
252aa631 | 4912 | channel_type_valid = true; |
026331c4 JM |
4913 | } |
4914 | ||
4915 | freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
4916 | chan = rdev_freq_to_chan(rdev, freq, channel_type); | |
4917 | if (chan == NULL) { | |
4918 | err = -EINVAL; | |
4919 | goto out; | |
4920 | } | |
4921 | ||
4922 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4923 | if (!msg) { | |
4924 | err = -ENOMEM; | |
4925 | goto out; | |
4926 | } | |
4927 | ||
4928 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
2e161f78 | 4929 | NL80211_CMD_FRAME); |
026331c4 JM |
4930 | |
4931 | if (IS_ERR(hdr)) { | |
4932 | err = PTR_ERR(hdr); | |
4933 | goto free_msg; | |
4934 | } | |
2e161f78 JB |
4935 | err = cfg80211_mlme_mgmt_tx(rdev, dev, chan, channel_type, |
4936 | channel_type_valid, | |
4937 | nla_data(info->attrs[NL80211_ATTR_FRAME]), | |
4938 | nla_len(info->attrs[NL80211_ATTR_FRAME]), | |
4939 | &cookie); | |
026331c4 JM |
4940 | if (err) |
4941 | goto free_msg; | |
4942 | ||
4943 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
4944 | ||
4945 | genlmsg_end(msg, hdr); | |
4946 | err = genlmsg_reply(msg, info); | |
4947 | goto out; | |
4948 | ||
4949 | nla_put_failure: | |
4950 | err = -ENOBUFS; | |
4951 | free_msg: | |
4952 | nlmsg_free(msg); | |
4953 | out: | |
4954 | cfg80211_unlock_rdev(rdev); | |
4955 | dev_put(dev); | |
4956 | unlock_rtnl: | |
4957 | rtnl_unlock(); | |
4958 | return err; | |
4959 | } | |
4960 | ||
ffb9eb3d KV |
4961 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
4962 | { | |
4963 | struct cfg80211_registered_device *rdev; | |
4964 | struct wireless_dev *wdev; | |
4965 | struct net_device *dev; | |
4966 | u8 ps_state; | |
4967 | bool state; | |
4968 | int err; | |
4969 | ||
4970 | if (!info->attrs[NL80211_ATTR_PS_STATE]) { | |
4971 | err = -EINVAL; | |
4972 | goto out; | |
4973 | } | |
4974 | ||
4975 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
4976 | ||
4977 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) { | |
4978 | err = -EINVAL; | |
4979 | goto out; | |
4980 | } | |
4981 | ||
4982 | rtnl_lock(); | |
4983 | ||
4984 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
4985 | if (err) | |
92e44948 | 4986 | goto unlock_rtnl; |
ffb9eb3d KV |
4987 | |
4988 | wdev = dev->ieee80211_ptr; | |
4989 | ||
4990 | if (!rdev->ops->set_power_mgmt) { | |
4991 | err = -EOPNOTSUPP; | |
4992 | goto unlock_rdev; | |
4993 | } | |
4994 | ||
4995 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
4996 | ||
4997 | if (state == wdev->ps) | |
4998 | goto unlock_rdev; | |
4999 | ||
5000 | wdev->ps = state; | |
5001 | ||
5002 | if (rdev->ops->set_power_mgmt(wdev->wiphy, dev, wdev->ps, | |
5003 | wdev->ps_timeout)) | |
5004 | /* assume this means it's off */ | |
5005 | wdev->ps = false; | |
5006 | ||
5007 | unlock_rdev: | |
5008 | cfg80211_unlock_rdev(rdev); | |
5009 | dev_put(dev); | |
92e44948 | 5010 | unlock_rtnl: |
ffb9eb3d KV |
5011 | rtnl_unlock(); |
5012 | ||
5013 | out: | |
5014 | return err; | |
5015 | } | |
5016 | ||
5017 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
5018 | { | |
5019 | struct cfg80211_registered_device *rdev; | |
5020 | enum nl80211_ps_state ps_state; | |
5021 | struct wireless_dev *wdev; | |
5022 | struct net_device *dev; | |
5023 | struct sk_buff *msg; | |
5024 | void *hdr; | |
5025 | int err; | |
5026 | ||
5027 | rtnl_lock(); | |
5028 | ||
5029 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
5030 | if (err) | |
5031 | goto unlock_rtnl; | |
5032 | ||
5033 | wdev = dev->ieee80211_ptr; | |
5034 | ||
5035 | if (!rdev->ops->set_power_mgmt) { | |
5036 | err = -EOPNOTSUPP; | |
5037 | goto out; | |
5038 | } | |
5039 | ||
5040 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5041 | if (!msg) { | |
5042 | err = -ENOMEM; | |
5043 | goto out; | |
5044 | } | |
5045 | ||
5046 | hdr = nl80211hdr_put(msg, info->snd_pid, info->snd_seq, 0, | |
5047 | NL80211_CMD_GET_POWER_SAVE); | |
5048 | if (!hdr) { | |
5049 | err = -ENOMEM; | |
5050 | goto free_msg; | |
5051 | } | |
5052 | ||
5053 | if (wdev->ps) | |
5054 | ps_state = NL80211_PS_ENABLED; | |
5055 | else | |
5056 | ps_state = NL80211_PS_DISABLED; | |
5057 | ||
5058 | NLA_PUT_U32(msg, NL80211_ATTR_PS_STATE, ps_state); | |
5059 | ||
5060 | genlmsg_end(msg, hdr); | |
5061 | err = genlmsg_reply(msg, info); | |
5062 | goto out; | |
5063 | ||
5064 | nla_put_failure: | |
5065 | err = -ENOBUFS; | |
5066 | ||
5067 | free_msg: | |
5068 | nlmsg_free(msg); | |
5069 | ||
5070 | out: | |
5071 | cfg80211_unlock_rdev(rdev); | |
5072 | dev_put(dev); | |
5073 | ||
5074 | unlock_rtnl: | |
5075 | rtnl_unlock(); | |
5076 | ||
5077 | return err; | |
5078 | } | |
5079 | ||
d6dc1a38 JO |
5080 | static struct nla_policy |
5081 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] __read_mostly = { | |
5082 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, | |
5083 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
5084 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
5085 | }; | |
5086 | ||
5087 | static int nl80211_set_cqm_rssi(struct genl_info *info, | |
5088 | s32 threshold, u32 hysteresis) | |
5089 | { | |
5090 | struct cfg80211_registered_device *rdev; | |
5091 | struct wireless_dev *wdev; | |
5092 | struct net_device *dev; | |
5093 | int err; | |
5094 | ||
5095 | if (threshold > 0) | |
5096 | return -EINVAL; | |
5097 | ||
5098 | rtnl_lock(); | |
5099 | ||
5100 | err = get_rdev_dev_by_info_ifindex(info, &rdev, &dev); | |
5101 | if (err) | |
2234362c | 5102 | goto unlock_rtnl; |
d6dc1a38 JO |
5103 | |
5104 | wdev = dev->ieee80211_ptr; | |
5105 | ||
5106 | if (!rdev->ops->set_cqm_rssi_config) { | |
5107 | err = -EOPNOTSUPP; | |
5108 | goto unlock_rdev; | |
5109 | } | |
5110 | ||
074ac8df JB |
5111 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
5112 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) { | |
d6dc1a38 JO |
5113 | err = -EOPNOTSUPP; |
5114 | goto unlock_rdev; | |
5115 | } | |
5116 | ||
5117 | err = rdev->ops->set_cqm_rssi_config(wdev->wiphy, dev, | |
5118 | threshold, hysteresis); | |
5119 | ||
2234362c | 5120 | unlock_rdev: |
d6dc1a38 JO |
5121 | cfg80211_unlock_rdev(rdev); |
5122 | dev_put(dev); | |
2234362c | 5123 | unlock_rtnl: |
d6dc1a38 JO |
5124 | rtnl_unlock(); |
5125 | ||
5126 | return err; | |
5127 | } | |
5128 | ||
5129 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
5130 | { | |
5131 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
5132 | struct nlattr *cqm; | |
5133 | int err; | |
5134 | ||
5135 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
5136 | if (!cqm) { | |
5137 | err = -EINVAL; | |
5138 | goto out; | |
5139 | } | |
5140 | ||
5141 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
5142 | nl80211_attr_cqm_policy); | |
5143 | if (err) | |
5144 | goto out; | |
5145 | ||
5146 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
5147 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
5148 | s32 threshold; | |
5149 | u32 hysteresis; | |
5150 | threshold = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
5151 | hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
5152 | err = nl80211_set_cqm_rssi(info, threshold, hysteresis); | |
5153 | } else | |
5154 | err = -EINVAL; | |
5155 | ||
5156 | out: | |
5157 | return err; | |
5158 | } | |
5159 | ||
55682965 JB |
5160 | static struct genl_ops nl80211_ops[] = { |
5161 | { | |
5162 | .cmd = NL80211_CMD_GET_WIPHY, | |
5163 | .doit = nl80211_get_wiphy, | |
5164 | .dumpit = nl80211_dump_wiphy, | |
5165 | .policy = nl80211_policy, | |
5166 | /* can be retrieved by unprivileged users */ | |
5167 | }, | |
5168 | { | |
5169 | .cmd = NL80211_CMD_SET_WIPHY, | |
5170 | .doit = nl80211_set_wiphy, | |
5171 | .policy = nl80211_policy, | |
5172 | .flags = GENL_ADMIN_PERM, | |
5173 | }, | |
5174 | { | |
5175 | .cmd = NL80211_CMD_GET_INTERFACE, | |
5176 | .doit = nl80211_get_interface, | |
5177 | .dumpit = nl80211_dump_interface, | |
5178 | .policy = nl80211_policy, | |
5179 | /* can be retrieved by unprivileged users */ | |
5180 | }, | |
5181 | { | |
5182 | .cmd = NL80211_CMD_SET_INTERFACE, | |
5183 | .doit = nl80211_set_interface, | |
5184 | .policy = nl80211_policy, | |
5185 | .flags = GENL_ADMIN_PERM, | |
5186 | }, | |
5187 | { | |
5188 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
5189 | .doit = nl80211_new_interface, | |
5190 | .policy = nl80211_policy, | |
5191 | .flags = GENL_ADMIN_PERM, | |
5192 | }, | |
5193 | { | |
5194 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
5195 | .doit = nl80211_del_interface, | |
5196 | .policy = nl80211_policy, | |
41ade00f JB |
5197 | .flags = GENL_ADMIN_PERM, |
5198 | }, | |
5199 | { | |
5200 | .cmd = NL80211_CMD_GET_KEY, | |
5201 | .doit = nl80211_get_key, | |
5202 | .policy = nl80211_policy, | |
5203 | .flags = GENL_ADMIN_PERM, | |
5204 | }, | |
5205 | { | |
5206 | .cmd = NL80211_CMD_SET_KEY, | |
5207 | .doit = nl80211_set_key, | |
5208 | .policy = nl80211_policy, | |
5209 | .flags = GENL_ADMIN_PERM, | |
5210 | }, | |
5211 | { | |
5212 | .cmd = NL80211_CMD_NEW_KEY, | |
5213 | .doit = nl80211_new_key, | |
5214 | .policy = nl80211_policy, | |
5215 | .flags = GENL_ADMIN_PERM, | |
5216 | }, | |
5217 | { | |
5218 | .cmd = NL80211_CMD_DEL_KEY, | |
5219 | .doit = nl80211_del_key, | |
5220 | .policy = nl80211_policy, | |
55682965 JB |
5221 | .flags = GENL_ADMIN_PERM, |
5222 | }, | |
ed1b6cc7 JB |
5223 | { |
5224 | .cmd = NL80211_CMD_SET_BEACON, | |
5225 | .policy = nl80211_policy, | |
5226 | .flags = GENL_ADMIN_PERM, | |
5227 | .doit = nl80211_addset_beacon, | |
5228 | }, | |
5229 | { | |
5230 | .cmd = NL80211_CMD_NEW_BEACON, | |
5231 | .policy = nl80211_policy, | |
5232 | .flags = GENL_ADMIN_PERM, | |
5233 | .doit = nl80211_addset_beacon, | |
5234 | }, | |
5235 | { | |
5236 | .cmd = NL80211_CMD_DEL_BEACON, | |
5237 | .policy = nl80211_policy, | |
5238 | .flags = GENL_ADMIN_PERM, | |
5239 | .doit = nl80211_del_beacon, | |
5240 | }, | |
5727ef1b JB |
5241 | { |
5242 | .cmd = NL80211_CMD_GET_STATION, | |
5243 | .doit = nl80211_get_station, | |
2ec600d6 | 5244 | .dumpit = nl80211_dump_station, |
5727ef1b | 5245 | .policy = nl80211_policy, |
5727ef1b JB |
5246 | }, |
5247 | { | |
5248 | .cmd = NL80211_CMD_SET_STATION, | |
5249 | .doit = nl80211_set_station, | |
5250 | .policy = nl80211_policy, | |
5251 | .flags = GENL_ADMIN_PERM, | |
5252 | }, | |
5253 | { | |
5254 | .cmd = NL80211_CMD_NEW_STATION, | |
5255 | .doit = nl80211_new_station, | |
5256 | .policy = nl80211_policy, | |
5257 | .flags = GENL_ADMIN_PERM, | |
5258 | }, | |
5259 | { | |
5260 | .cmd = NL80211_CMD_DEL_STATION, | |
5261 | .doit = nl80211_del_station, | |
5262 | .policy = nl80211_policy, | |
2ec600d6 LCC |
5263 | .flags = GENL_ADMIN_PERM, |
5264 | }, | |
5265 | { | |
5266 | .cmd = NL80211_CMD_GET_MPATH, | |
5267 | .doit = nl80211_get_mpath, | |
5268 | .dumpit = nl80211_dump_mpath, | |
5269 | .policy = nl80211_policy, | |
5270 | .flags = GENL_ADMIN_PERM, | |
5271 | }, | |
5272 | { | |
5273 | .cmd = NL80211_CMD_SET_MPATH, | |
5274 | .doit = nl80211_set_mpath, | |
5275 | .policy = nl80211_policy, | |
5276 | .flags = GENL_ADMIN_PERM, | |
5277 | }, | |
5278 | { | |
5279 | .cmd = NL80211_CMD_NEW_MPATH, | |
5280 | .doit = nl80211_new_mpath, | |
5281 | .policy = nl80211_policy, | |
5282 | .flags = GENL_ADMIN_PERM, | |
5283 | }, | |
5284 | { | |
5285 | .cmd = NL80211_CMD_DEL_MPATH, | |
5286 | .doit = nl80211_del_mpath, | |
5287 | .policy = nl80211_policy, | |
9f1ba906 JM |
5288 | .flags = GENL_ADMIN_PERM, |
5289 | }, | |
5290 | { | |
5291 | .cmd = NL80211_CMD_SET_BSS, | |
5292 | .doit = nl80211_set_bss, | |
5293 | .policy = nl80211_policy, | |
b2e1b302 LR |
5294 | .flags = GENL_ADMIN_PERM, |
5295 | }, | |
f130347c LR |
5296 | { |
5297 | .cmd = NL80211_CMD_GET_REG, | |
5298 | .doit = nl80211_get_reg, | |
5299 | .policy = nl80211_policy, | |
5300 | /* can be retrieved by unprivileged users */ | |
5301 | }, | |
b2e1b302 LR |
5302 | { |
5303 | .cmd = NL80211_CMD_SET_REG, | |
5304 | .doit = nl80211_set_reg, | |
5305 | .policy = nl80211_policy, | |
5306 | .flags = GENL_ADMIN_PERM, | |
5307 | }, | |
5308 | { | |
5309 | .cmd = NL80211_CMD_REQ_SET_REG, | |
5310 | .doit = nl80211_req_set_reg, | |
5311 | .policy = nl80211_policy, | |
93da9cc1 | 5312 | .flags = GENL_ADMIN_PERM, |
5313 | }, | |
5314 | { | |
5315 | .cmd = NL80211_CMD_GET_MESH_PARAMS, | |
5316 | .doit = nl80211_get_mesh_params, | |
5317 | .policy = nl80211_policy, | |
5318 | /* can be retrieved by unprivileged users */ | |
5319 | }, | |
5320 | { | |
5321 | .cmd = NL80211_CMD_SET_MESH_PARAMS, | |
5322 | .doit = nl80211_set_mesh_params, | |
5323 | .policy = nl80211_policy, | |
9aed3cc1 JM |
5324 | .flags = GENL_ADMIN_PERM, |
5325 | }, | |
2a519311 JB |
5326 | { |
5327 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
5328 | .doit = nl80211_trigger_scan, | |
5329 | .policy = nl80211_policy, | |
5330 | .flags = GENL_ADMIN_PERM, | |
5331 | }, | |
5332 | { | |
5333 | .cmd = NL80211_CMD_GET_SCAN, | |
5334 | .policy = nl80211_policy, | |
5335 | .dumpit = nl80211_dump_scan, | |
5336 | }, | |
636a5d36 JM |
5337 | { |
5338 | .cmd = NL80211_CMD_AUTHENTICATE, | |
5339 | .doit = nl80211_authenticate, | |
5340 | .policy = nl80211_policy, | |
5341 | .flags = GENL_ADMIN_PERM, | |
5342 | }, | |
5343 | { | |
5344 | .cmd = NL80211_CMD_ASSOCIATE, | |
5345 | .doit = nl80211_associate, | |
5346 | .policy = nl80211_policy, | |
5347 | .flags = GENL_ADMIN_PERM, | |
5348 | }, | |
5349 | { | |
5350 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
5351 | .doit = nl80211_deauthenticate, | |
5352 | .policy = nl80211_policy, | |
5353 | .flags = GENL_ADMIN_PERM, | |
5354 | }, | |
5355 | { | |
5356 | .cmd = NL80211_CMD_DISASSOCIATE, | |
5357 | .doit = nl80211_disassociate, | |
5358 | .policy = nl80211_policy, | |
5359 | .flags = GENL_ADMIN_PERM, | |
5360 | }, | |
04a773ad JB |
5361 | { |
5362 | .cmd = NL80211_CMD_JOIN_IBSS, | |
5363 | .doit = nl80211_join_ibss, | |
5364 | .policy = nl80211_policy, | |
5365 | .flags = GENL_ADMIN_PERM, | |
5366 | }, | |
5367 | { | |
5368 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
5369 | .doit = nl80211_leave_ibss, | |
5370 | .policy = nl80211_policy, | |
5371 | .flags = GENL_ADMIN_PERM, | |
5372 | }, | |
aff89a9b JB |
5373 | #ifdef CONFIG_NL80211_TESTMODE |
5374 | { | |
5375 | .cmd = NL80211_CMD_TESTMODE, | |
5376 | .doit = nl80211_testmode_do, | |
5377 | .policy = nl80211_policy, | |
5378 | .flags = GENL_ADMIN_PERM, | |
5379 | }, | |
5380 | #endif | |
b23aa676 SO |
5381 | { |
5382 | .cmd = NL80211_CMD_CONNECT, | |
5383 | .doit = nl80211_connect, | |
5384 | .policy = nl80211_policy, | |
5385 | .flags = GENL_ADMIN_PERM, | |
5386 | }, | |
5387 | { | |
5388 | .cmd = NL80211_CMD_DISCONNECT, | |
5389 | .doit = nl80211_disconnect, | |
5390 | .policy = nl80211_policy, | |
5391 | .flags = GENL_ADMIN_PERM, | |
5392 | }, | |
463d0183 JB |
5393 | { |
5394 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
5395 | .doit = nl80211_wiphy_netns, | |
5396 | .policy = nl80211_policy, | |
5397 | .flags = GENL_ADMIN_PERM, | |
5398 | }, | |
61fa713c HS |
5399 | { |
5400 | .cmd = NL80211_CMD_GET_SURVEY, | |
5401 | .policy = nl80211_policy, | |
5402 | .dumpit = nl80211_dump_survey, | |
5403 | }, | |
67fbb16b SO |
5404 | { |
5405 | .cmd = NL80211_CMD_SET_PMKSA, | |
5406 | .doit = nl80211_setdel_pmksa, | |
5407 | .policy = nl80211_policy, | |
5408 | .flags = GENL_ADMIN_PERM, | |
5409 | }, | |
5410 | { | |
5411 | .cmd = NL80211_CMD_DEL_PMKSA, | |
5412 | .doit = nl80211_setdel_pmksa, | |
5413 | .policy = nl80211_policy, | |
5414 | .flags = GENL_ADMIN_PERM, | |
5415 | }, | |
5416 | { | |
5417 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
5418 | .doit = nl80211_flush_pmksa, | |
5419 | .policy = nl80211_policy, | |
5420 | .flags = GENL_ADMIN_PERM, | |
5421 | }, | |
9588bbd5 JM |
5422 | { |
5423 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
5424 | .doit = nl80211_remain_on_channel, | |
5425 | .policy = nl80211_policy, | |
5426 | .flags = GENL_ADMIN_PERM, | |
5427 | }, | |
5428 | { | |
5429 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
5430 | .doit = nl80211_cancel_remain_on_channel, | |
5431 | .policy = nl80211_policy, | |
5432 | .flags = GENL_ADMIN_PERM, | |
5433 | }, | |
13ae75b1 JM |
5434 | { |
5435 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
5436 | .doit = nl80211_set_tx_bitrate_mask, | |
5437 | .policy = nl80211_policy, | |
5438 | .flags = GENL_ADMIN_PERM, | |
5439 | }, | |
026331c4 | 5440 | { |
2e161f78 JB |
5441 | .cmd = NL80211_CMD_REGISTER_FRAME, |
5442 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
5443 | .policy = nl80211_policy, |
5444 | .flags = GENL_ADMIN_PERM, | |
5445 | }, | |
5446 | { | |
2e161f78 JB |
5447 | .cmd = NL80211_CMD_FRAME, |
5448 | .doit = nl80211_tx_mgmt, | |
026331c4 JM |
5449 | .policy = nl80211_policy, |
5450 | .flags = GENL_ADMIN_PERM, | |
5451 | }, | |
ffb9eb3d KV |
5452 | { |
5453 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
5454 | .doit = nl80211_set_power_save, | |
5455 | .policy = nl80211_policy, | |
5456 | .flags = GENL_ADMIN_PERM, | |
5457 | }, | |
5458 | { | |
5459 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
5460 | .doit = nl80211_get_power_save, | |
5461 | .policy = nl80211_policy, | |
5462 | /* can be retrieved by unprivileged users */ | |
5463 | }, | |
d6dc1a38 JO |
5464 | { |
5465 | .cmd = NL80211_CMD_SET_CQM, | |
5466 | .doit = nl80211_set_cqm, | |
5467 | .policy = nl80211_policy, | |
5468 | .flags = GENL_ADMIN_PERM, | |
5469 | }, | |
f444de05 JB |
5470 | { |
5471 | .cmd = NL80211_CMD_SET_CHANNEL, | |
5472 | .doit = nl80211_set_channel, | |
5473 | .policy = nl80211_policy, | |
5474 | .flags = GENL_ADMIN_PERM, | |
5475 | }, | |
55682965 | 5476 | }; |
9588bbd5 | 5477 | |
6039f6d2 JM |
5478 | static struct genl_multicast_group nl80211_mlme_mcgrp = { |
5479 | .name = "mlme", | |
5480 | }; | |
55682965 JB |
5481 | |
5482 | /* multicast groups */ | |
5483 | static struct genl_multicast_group nl80211_config_mcgrp = { | |
5484 | .name = "config", | |
5485 | }; | |
2a519311 JB |
5486 | static struct genl_multicast_group nl80211_scan_mcgrp = { |
5487 | .name = "scan", | |
5488 | }; | |
73d54c9e LR |
5489 | static struct genl_multicast_group nl80211_regulatory_mcgrp = { |
5490 | .name = "regulatory", | |
5491 | }; | |
55682965 JB |
5492 | |
5493 | /* notification functions */ | |
5494 | ||
5495 | void nl80211_notify_dev_rename(struct cfg80211_registered_device *rdev) | |
5496 | { | |
5497 | struct sk_buff *msg; | |
5498 | ||
fd2120ca | 5499 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
5500 | if (!msg) |
5501 | return; | |
5502 | ||
5503 | if (nl80211_send_wiphy(msg, 0, 0, 0, rdev) < 0) { | |
5504 | nlmsg_free(msg); | |
5505 | return; | |
5506 | } | |
5507 | ||
463d0183 JB |
5508 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5509 | nl80211_config_mcgrp.id, GFP_KERNEL); | |
55682965 JB |
5510 | } |
5511 | ||
362a415d JB |
5512 | static int nl80211_add_scan_req(struct sk_buff *msg, |
5513 | struct cfg80211_registered_device *rdev) | |
5514 | { | |
5515 | struct cfg80211_scan_request *req = rdev->scan_req; | |
5516 | struct nlattr *nest; | |
5517 | int i; | |
5518 | ||
667503dd JB |
5519 | ASSERT_RDEV_LOCK(rdev); |
5520 | ||
362a415d JB |
5521 | if (WARN_ON(!req)) |
5522 | return 0; | |
5523 | ||
5524 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
5525 | if (!nest) | |
5526 | goto nla_put_failure; | |
5527 | for (i = 0; i < req->n_ssids; i++) | |
5528 | NLA_PUT(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid); | |
5529 | nla_nest_end(msg, nest); | |
5530 | ||
5531 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
5532 | if (!nest) | |
5533 | goto nla_put_failure; | |
5534 | for (i = 0; i < req->n_channels; i++) | |
5535 | NLA_PUT_U32(msg, i, req->channels[i]->center_freq); | |
5536 | nla_nest_end(msg, nest); | |
5537 | ||
5538 | if (req->ie) | |
5539 | NLA_PUT(msg, NL80211_ATTR_IE, req->ie_len, req->ie); | |
5540 | ||
5541 | return 0; | |
5542 | nla_put_failure: | |
5543 | return -ENOBUFS; | |
5544 | } | |
5545 | ||
a538e2d5 JB |
5546 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
5547 | struct cfg80211_registered_device *rdev, | |
5548 | struct net_device *netdev, | |
5549 | u32 pid, u32 seq, int flags, | |
5550 | u32 cmd) | |
2a519311 JB |
5551 | { |
5552 | void *hdr; | |
5553 | ||
5554 | hdr = nl80211hdr_put(msg, pid, seq, flags, cmd); | |
5555 | if (!hdr) | |
5556 | return -1; | |
5557 | ||
b5850a7a | 5558 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); |
2a519311 JB |
5559 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); |
5560 | ||
362a415d JB |
5561 | /* ignore errors and send incomplete event anyway */ |
5562 | nl80211_add_scan_req(msg, rdev); | |
2a519311 JB |
5563 | |
5564 | return genlmsg_end(msg, hdr); | |
5565 | ||
5566 | nla_put_failure: | |
5567 | genlmsg_cancel(msg, hdr); | |
5568 | return -EMSGSIZE; | |
5569 | } | |
5570 | ||
a538e2d5 JB |
5571 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
5572 | struct net_device *netdev) | |
5573 | { | |
5574 | struct sk_buff *msg; | |
5575 | ||
5576 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); | |
5577 | if (!msg) | |
5578 | return; | |
5579 | ||
5580 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
5581 | NL80211_CMD_TRIGGER_SCAN) < 0) { | |
5582 | nlmsg_free(msg); | |
5583 | return; | |
5584 | } | |
5585 | ||
463d0183 JB |
5586 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5587 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
a538e2d5 JB |
5588 | } |
5589 | ||
2a519311 JB |
5590 | void nl80211_send_scan_done(struct cfg80211_registered_device *rdev, |
5591 | struct net_device *netdev) | |
5592 | { | |
5593 | struct sk_buff *msg; | |
5594 | ||
fd2120ca | 5595 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
5596 | if (!msg) |
5597 | return; | |
5598 | ||
a538e2d5 JB |
5599 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
5600 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 JB |
5601 | nlmsg_free(msg); |
5602 | return; | |
5603 | } | |
5604 | ||
463d0183 JB |
5605 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5606 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
5607 | } |
5608 | ||
5609 | void nl80211_send_scan_aborted(struct cfg80211_registered_device *rdev, | |
5610 | struct net_device *netdev) | |
5611 | { | |
5612 | struct sk_buff *msg; | |
5613 | ||
fd2120ca | 5614 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 JB |
5615 | if (!msg) |
5616 | return; | |
5617 | ||
a538e2d5 JB |
5618 | if (nl80211_send_scan_msg(msg, rdev, netdev, 0, 0, 0, |
5619 | NL80211_CMD_SCAN_ABORTED) < 0) { | |
2a519311 JB |
5620 | nlmsg_free(msg); |
5621 | return; | |
5622 | } | |
5623 | ||
463d0183 JB |
5624 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5625 | nl80211_scan_mcgrp.id, GFP_KERNEL); | |
2a519311 JB |
5626 | } |
5627 | ||
73d54c9e LR |
5628 | /* |
5629 | * This can happen on global regulatory changes or device specific settings | |
5630 | * based on custom world regulatory domains. | |
5631 | */ | |
5632 | void nl80211_send_reg_change_event(struct regulatory_request *request) | |
5633 | { | |
5634 | struct sk_buff *msg; | |
5635 | void *hdr; | |
5636 | ||
fd2120ca | 5637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
73d54c9e LR |
5638 | if (!msg) |
5639 | return; | |
5640 | ||
5641 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE); | |
5642 | if (!hdr) { | |
5643 | nlmsg_free(msg); | |
5644 | return; | |
5645 | } | |
5646 | ||
5647 | /* Userspace can always count this one always being set */ | |
5648 | NLA_PUT_U8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator); | |
5649 | ||
5650 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') | |
5651 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
5652 | NL80211_REGDOM_TYPE_WORLD); | |
5653 | else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') | |
5654 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
5655 | NL80211_REGDOM_TYPE_CUSTOM_WORLD); | |
5656 | else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
5657 | request->intersect) | |
5658 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
5659 | NL80211_REGDOM_TYPE_INTERSECTION); | |
5660 | else { | |
5661 | NLA_PUT_U8(msg, NL80211_ATTR_REG_TYPE, | |
5662 | NL80211_REGDOM_TYPE_COUNTRY); | |
5663 | NLA_PUT_STRING(msg, NL80211_ATTR_REG_ALPHA2, request->alpha2); | |
5664 | } | |
5665 | ||
5666 | if (wiphy_idx_valid(request->wiphy_idx)) | |
5667 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx); | |
5668 | ||
5669 | if (genlmsg_end(msg, hdr) < 0) { | |
5670 | nlmsg_free(msg); | |
5671 | return; | |
5672 | } | |
5673 | ||
bc43b28c | 5674 | rcu_read_lock(); |
463d0183 | 5675 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, |
bc43b28c JB |
5676 | GFP_ATOMIC); |
5677 | rcu_read_unlock(); | |
73d54c9e LR |
5678 | |
5679 | return; | |
5680 | ||
5681 | nla_put_failure: | |
5682 | genlmsg_cancel(msg, hdr); | |
5683 | nlmsg_free(msg); | |
5684 | } | |
5685 | ||
6039f6d2 JM |
5686 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
5687 | struct net_device *netdev, | |
5688 | const u8 *buf, size_t len, | |
e6d6e342 | 5689 | enum nl80211_commands cmd, gfp_t gfp) |
6039f6d2 JM |
5690 | { |
5691 | struct sk_buff *msg; | |
5692 | void *hdr; | |
5693 | ||
e6d6e342 | 5694 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
5695 | if (!msg) |
5696 | return; | |
5697 | ||
5698 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
5699 | if (!hdr) { | |
5700 | nlmsg_free(msg); | |
5701 | return; | |
5702 | } | |
5703 | ||
5704 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5705 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5706 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
5707 | ||
5708 | if (genlmsg_end(msg, hdr) < 0) { | |
5709 | nlmsg_free(msg); | |
5710 | return; | |
5711 | } | |
5712 | ||
463d0183 JB |
5713 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5714 | nl80211_mlme_mcgrp.id, gfp); | |
6039f6d2 JM |
5715 | return; |
5716 | ||
5717 | nla_put_failure: | |
5718 | genlmsg_cancel(msg, hdr); | |
5719 | nlmsg_free(msg); | |
5720 | } | |
5721 | ||
5722 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
5723 | struct net_device *netdev, const u8 *buf, |
5724 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
5725 | { |
5726 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 5727 | NL80211_CMD_AUTHENTICATE, gfp); |
6039f6d2 JM |
5728 | } |
5729 | ||
5730 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
5731 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 5732 | size_t len, gfp_t gfp) |
6039f6d2 | 5733 | { |
e6d6e342 JB |
5734 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
5735 | NL80211_CMD_ASSOCIATE, gfp); | |
6039f6d2 JM |
5736 | } |
5737 | ||
53b46b84 | 5738 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
5739 | struct net_device *netdev, const u8 *buf, |
5740 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
5741 | { |
5742 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 5743 | NL80211_CMD_DEAUTHENTICATE, gfp); |
6039f6d2 JM |
5744 | } |
5745 | ||
53b46b84 JM |
5746 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
5747 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 5748 | size_t len, gfp_t gfp) |
6039f6d2 JM |
5749 | { |
5750 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
e6d6e342 | 5751 | NL80211_CMD_DISASSOCIATE, gfp); |
6039f6d2 JM |
5752 | } |
5753 | ||
1b06bb40 LR |
5754 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
5755 | struct net_device *netdev, int cmd, | |
e6d6e342 | 5756 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
5757 | { |
5758 | struct sk_buff *msg; | |
5759 | void *hdr; | |
5760 | ||
e6d6e342 | 5761 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
5762 | if (!msg) |
5763 | return; | |
5764 | ||
5765 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
5766 | if (!hdr) { | |
5767 | nlmsg_free(msg); | |
5768 | return; | |
5769 | } | |
5770 | ||
5771 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5772 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5773 | NLA_PUT_FLAG(msg, NL80211_ATTR_TIMED_OUT); | |
5774 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
5775 | ||
5776 | if (genlmsg_end(msg, hdr) < 0) { | |
5777 | nlmsg_free(msg); | |
5778 | return; | |
5779 | } | |
5780 | ||
463d0183 JB |
5781 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5782 | nl80211_mlme_mcgrp.id, gfp); | |
1965c853 JM |
5783 | return; |
5784 | ||
5785 | nla_put_failure: | |
5786 | genlmsg_cancel(msg, hdr); | |
5787 | nlmsg_free(msg); | |
5788 | } | |
5789 | ||
5790 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
5791 | struct net_device *netdev, const u8 *addr, |
5792 | gfp_t gfp) | |
1965c853 JM |
5793 | { |
5794 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 5795 | addr, gfp); |
1965c853 JM |
5796 | } |
5797 | ||
5798 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
5799 | struct net_device *netdev, const u8 *addr, |
5800 | gfp_t gfp) | |
1965c853 | 5801 | { |
e6d6e342 JB |
5802 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
5803 | addr, gfp); | |
1965c853 JM |
5804 | } |
5805 | ||
b23aa676 SO |
5806 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
5807 | struct net_device *netdev, const u8 *bssid, | |
5808 | const u8 *req_ie, size_t req_ie_len, | |
5809 | const u8 *resp_ie, size_t resp_ie_len, | |
5810 | u16 status, gfp_t gfp) | |
5811 | { | |
5812 | struct sk_buff *msg; | |
5813 | void *hdr; | |
5814 | ||
5815 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
5816 | if (!msg) | |
5817 | return; | |
5818 | ||
5819 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
5820 | if (!hdr) { | |
5821 | nlmsg_free(msg); | |
5822 | return; | |
5823 | } | |
5824 | ||
5825 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5826 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5827 | if (bssid) | |
5828 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
5829 | NLA_PUT_U16(msg, NL80211_ATTR_STATUS_CODE, status); | |
5830 | if (req_ie) | |
5831 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); | |
5832 | if (resp_ie) | |
5833 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); | |
5834 | ||
5835 | if (genlmsg_end(msg, hdr) < 0) { | |
5836 | nlmsg_free(msg); | |
5837 | return; | |
5838 | } | |
5839 | ||
463d0183 JB |
5840 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5841 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
5842 | return; |
5843 | ||
5844 | nla_put_failure: | |
5845 | genlmsg_cancel(msg, hdr); | |
5846 | nlmsg_free(msg); | |
5847 | ||
5848 | } | |
5849 | ||
5850 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
5851 | struct net_device *netdev, const u8 *bssid, | |
5852 | const u8 *req_ie, size_t req_ie_len, | |
5853 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
5854 | { | |
5855 | struct sk_buff *msg; | |
5856 | void *hdr; | |
5857 | ||
5858 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
5859 | if (!msg) | |
5860 | return; | |
5861 | ||
5862 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
5863 | if (!hdr) { | |
5864 | nlmsg_free(msg); | |
5865 | return; | |
5866 | } | |
5867 | ||
5868 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5869 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5870 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
5871 | if (req_ie) | |
5872 | NLA_PUT(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie); | |
5873 | if (resp_ie) | |
5874 | NLA_PUT(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie); | |
5875 | ||
5876 | if (genlmsg_end(msg, hdr) < 0) { | |
5877 | nlmsg_free(msg); | |
5878 | return; | |
5879 | } | |
5880 | ||
463d0183 JB |
5881 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5882 | nl80211_mlme_mcgrp.id, gfp); | |
b23aa676 SO |
5883 | return; |
5884 | ||
5885 | nla_put_failure: | |
5886 | genlmsg_cancel(msg, hdr); | |
5887 | nlmsg_free(msg); | |
5888 | ||
5889 | } | |
5890 | ||
5891 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
5892 | struct net_device *netdev, u16 reason, | |
667503dd | 5893 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
5894 | { |
5895 | struct sk_buff *msg; | |
5896 | void *hdr; | |
5897 | ||
667503dd | 5898 | msg = nlmsg_new(NLMSG_GOODSIZE, GFP_KERNEL); |
b23aa676 SO |
5899 | if (!msg) |
5900 | return; | |
5901 | ||
5902 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
5903 | if (!hdr) { | |
5904 | nlmsg_free(msg); | |
5905 | return; | |
5906 | } | |
5907 | ||
5908 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5909 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5910 | if (from_ap && reason) | |
5911 | NLA_PUT_U16(msg, NL80211_ATTR_REASON_CODE, reason); | |
5912 | if (from_ap) | |
5913 | NLA_PUT_FLAG(msg, NL80211_ATTR_DISCONNECTED_BY_AP); | |
5914 | if (ie) | |
5915 | NLA_PUT(msg, NL80211_ATTR_IE, ie_len, ie); | |
5916 | ||
5917 | if (genlmsg_end(msg, hdr) < 0) { | |
5918 | nlmsg_free(msg); | |
5919 | return; | |
5920 | } | |
5921 | ||
463d0183 JB |
5922 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5923 | nl80211_mlme_mcgrp.id, GFP_KERNEL); | |
b23aa676 SO |
5924 | return; |
5925 | ||
5926 | nla_put_failure: | |
5927 | genlmsg_cancel(msg, hdr); | |
5928 | nlmsg_free(msg); | |
5929 | ||
5930 | } | |
5931 | ||
04a773ad JB |
5932 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
5933 | struct net_device *netdev, const u8 *bssid, | |
5934 | gfp_t gfp) | |
5935 | { | |
5936 | struct sk_buff *msg; | |
5937 | void *hdr; | |
5938 | ||
fd2120ca | 5939 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
5940 | if (!msg) |
5941 | return; | |
5942 | ||
5943 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
5944 | if (!hdr) { | |
5945 | nlmsg_free(msg); | |
5946 | return; | |
5947 | } | |
5948 | ||
5949 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5950 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5951 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid); | |
5952 | ||
5953 | if (genlmsg_end(msg, hdr) < 0) { | |
5954 | nlmsg_free(msg); | |
5955 | return; | |
5956 | } | |
5957 | ||
463d0183 JB |
5958 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
5959 | nl80211_mlme_mcgrp.id, gfp); | |
04a773ad JB |
5960 | return; |
5961 | ||
5962 | nla_put_failure: | |
5963 | genlmsg_cancel(msg, hdr); | |
5964 | nlmsg_free(msg); | |
5965 | } | |
5966 | ||
a3b8b056 JM |
5967 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
5968 | struct net_device *netdev, const u8 *addr, | |
5969 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 5970 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
5971 | { |
5972 | struct sk_buff *msg; | |
5973 | void *hdr; | |
5974 | ||
e6d6e342 | 5975 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
5976 | if (!msg) |
5977 | return; | |
5978 | ||
5979 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
5980 | if (!hdr) { | |
5981 | nlmsg_free(msg); | |
5982 | return; | |
5983 | } | |
5984 | ||
5985 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
5986 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
5987 | if (addr) | |
5988 | NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); | |
5989 | NLA_PUT_U32(msg, NL80211_ATTR_KEY_TYPE, key_type); | |
5990 | NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, key_id); | |
5991 | if (tsc) | |
5992 | NLA_PUT(msg, NL80211_ATTR_KEY_SEQ, 6, tsc); | |
5993 | ||
5994 | if (genlmsg_end(msg, hdr) < 0) { | |
5995 | nlmsg_free(msg); | |
5996 | return; | |
5997 | } | |
5998 | ||
463d0183 JB |
5999 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, |
6000 | nl80211_mlme_mcgrp.id, gfp); | |
a3b8b056 JM |
6001 | return; |
6002 | ||
6003 | nla_put_failure: | |
6004 | genlmsg_cancel(msg, hdr); | |
6005 | nlmsg_free(msg); | |
6006 | } | |
6007 | ||
6bad8766 LR |
6008 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
6009 | struct ieee80211_channel *channel_before, | |
6010 | struct ieee80211_channel *channel_after) | |
6011 | { | |
6012 | struct sk_buff *msg; | |
6013 | void *hdr; | |
6014 | struct nlattr *nl_freq; | |
6015 | ||
fd2120ca | 6016 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
6017 | if (!msg) |
6018 | return; | |
6019 | ||
6020 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
6021 | if (!hdr) { | |
6022 | nlmsg_free(msg); | |
6023 | return; | |
6024 | } | |
6025 | ||
6026 | /* | |
6027 | * Since we are applying the beacon hint to a wiphy we know its | |
6028 | * wiphy_idx is valid | |
6029 | */ | |
6030 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)); | |
6031 | ||
6032 | /* Before */ | |
6033 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
6034 | if (!nl_freq) | |
6035 | goto nla_put_failure; | |
6036 | if (nl80211_msg_put_channel(msg, channel_before)) | |
6037 | goto nla_put_failure; | |
6038 | nla_nest_end(msg, nl_freq); | |
6039 | ||
6040 | /* After */ | |
6041 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
6042 | if (!nl_freq) | |
6043 | goto nla_put_failure; | |
6044 | if (nl80211_msg_put_channel(msg, channel_after)) | |
6045 | goto nla_put_failure; | |
6046 | nla_nest_end(msg, nl_freq); | |
6047 | ||
6048 | if (genlmsg_end(msg, hdr) < 0) { | |
6049 | nlmsg_free(msg); | |
6050 | return; | |
6051 | } | |
6052 | ||
463d0183 JB |
6053 | rcu_read_lock(); |
6054 | genlmsg_multicast_allns(msg, 0, nl80211_regulatory_mcgrp.id, | |
6055 | GFP_ATOMIC); | |
6056 | rcu_read_unlock(); | |
6bad8766 LR |
6057 | |
6058 | return; | |
6059 | ||
6060 | nla_put_failure: | |
6061 | genlmsg_cancel(msg, hdr); | |
6062 | nlmsg_free(msg); | |
6063 | } | |
6064 | ||
9588bbd5 JM |
6065 | static void nl80211_send_remain_on_chan_event( |
6066 | int cmd, struct cfg80211_registered_device *rdev, | |
6067 | struct net_device *netdev, u64 cookie, | |
6068 | struct ieee80211_channel *chan, | |
6069 | enum nl80211_channel_type channel_type, | |
6070 | unsigned int duration, gfp_t gfp) | |
6071 | { | |
6072 | struct sk_buff *msg; | |
6073 | void *hdr; | |
6074 | ||
6075 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
6076 | if (!msg) | |
6077 | return; | |
6078 | ||
6079 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
6080 | if (!hdr) { | |
6081 | nlmsg_free(msg); | |
6082 | return; | |
6083 | } | |
6084 | ||
6085 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6086 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6087 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq); | |
6088 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, channel_type); | |
6089 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
6090 | ||
6091 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL) | |
6092 | NLA_PUT_U32(msg, NL80211_ATTR_DURATION, duration); | |
6093 | ||
6094 | if (genlmsg_end(msg, hdr) < 0) { | |
6095 | nlmsg_free(msg); | |
6096 | return; | |
6097 | } | |
6098 | ||
6099 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6100 | nl80211_mlme_mcgrp.id, gfp); | |
6101 | return; | |
6102 | ||
6103 | nla_put_failure: | |
6104 | genlmsg_cancel(msg, hdr); | |
6105 | nlmsg_free(msg); | |
6106 | } | |
6107 | ||
6108 | void nl80211_send_remain_on_channel(struct cfg80211_registered_device *rdev, | |
6109 | struct net_device *netdev, u64 cookie, | |
6110 | struct ieee80211_channel *chan, | |
6111 | enum nl80211_channel_type channel_type, | |
6112 | unsigned int duration, gfp_t gfp) | |
6113 | { | |
6114 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, | |
6115 | rdev, netdev, cookie, chan, | |
6116 | channel_type, duration, gfp); | |
6117 | } | |
6118 | ||
6119 | void nl80211_send_remain_on_channel_cancel( | |
6120 | struct cfg80211_registered_device *rdev, struct net_device *netdev, | |
6121 | u64 cookie, struct ieee80211_channel *chan, | |
6122 | enum nl80211_channel_type channel_type, gfp_t gfp) | |
6123 | { | |
6124 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
6125 | rdev, netdev, cookie, chan, | |
6126 | channel_type, 0, gfp); | |
6127 | } | |
6128 | ||
98b62183 JB |
6129 | void nl80211_send_sta_event(struct cfg80211_registered_device *rdev, |
6130 | struct net_device *dev, const u8 *mac_addr, | |
6131 | struct station_info *sinfo, gfp_t gfp) | |
6132 | { | |
6133 | struct sk_buff *msg; | |
6134 | ||
6135 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
6136 | if (!msg) | |
6137 | return; | |
6138 | ||
6139 | if (nl80211_send_station(msg, 0, 0, 0, dev, mac_addr, sinfo) < 0) { | |
6140 | nlmsg_free(msg); | |
6141 | return; | |
6142 | } | |
6143 | ||
6144 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6145 | nl80211_mlme_mcgrp.id, gfp); | |
6146 | } | |
6147 | ||
2e161f78 JB |
6148 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
6149 | struct net_device *netdev, u32 nlpid, | |
6150 | int freq, const u8 *buf, size_t len, gfp_t gfp) | |
026331c4 JM |
6151 | { |
6152 | struct sk_buff *msg; | |
6153 | void *hdr; | |
6154 | int err; | |
6155 | ||
6156 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
6157 | if (!msg) | |
6158 | return -ENOMEM; | |
6159 | ||
2e161f78 | 6160 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
6161 | if (!hdr) { |
6162 | nlmsg_free(msg); | |
6163 | return -ENOMEM; | |
6164 | } | |
6165 | ||
6166 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6167 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6168 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq); | |
6169 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
6170 | ||
6171 | err = genlmsg_end(msg, hdr); | |
6172 | if (err < 0) { | |
6173 | nlmsg_free(msg); | |
6174 | return err; | |
6175 | } | |
6176 | ||
6177 | err = genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlpid); | |
6178 | if (err < 0) | |
6179 | return err; | |
6180 | return 0; | |
6181 | ||
6182 | nla_put_failure: | |
6183 | genlmsg_cancel(msg, hdr); | |
6184 | nlmsg_free(msg); | |
6185 | return -ENOBUFS; | |
6186 | } | |
6187 | ||
2e161f78 JB |
6188 | void nl80211_send_mgmt_tx_status(struct cfg80211_registered_device *rdev, |
6189 | struct net_device *netdev, u64 cookie, | |
6190 | const u8 *buf, size_t len, bool ack, | |
6191 | gfp_t gfp) | |
026331c4 JM |
6192 | { |
6193 | struct sk_buff *msg; | |
6194 | void *hdr; | |
6195 | ||
6196 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
6197 | if (!msg) | |
6198 | return; | |
6199 | ||
2e161f78 | 6200 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
6201 | if (!hdr) { |
6202 | nlmsg_free(msg); | |
6203 | return; | |
6204 | } | |
6205 | ||
6206 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6207 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6208 | NLA_PUT(msg, NL80211_ATTR_FRAME, len, buf); | |
6209 | NLA_PUT_U64(msg, NL80211_ATTR_COOKIE, cookie); | |
6210 | if (ack) | |
6211 | NLA_PUT_FLAG(msg, NL80211_ATTR_ACK); | |
6212 | ||
6213 | if (genlmsg_end(msg, hdr) < 0) { | |
6214 | nlmsg_free(msg); | |
6215 | return; | |
6216 | } | |
6217 | ||
6218 | genlmsg_multicast(msg, 0, nl80211_mlme_mcgrp.id, gfp); | |
6219 | return; | |
6220 | ||
6221 | nla_put_failure: | |
6222 | genlmsg_cancel(msg, hdr); | |
6223 | nlmsg_free(msg); | |
6224 | } | |
6225 | ||
d6dc1a38 JO |
6226 | void |
6227 | nl80211_send_cqm_rssi_notify(struct cfg80211_registered_device *rdev, | |
6228 | struct net_device *netdev, | |
6229 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
6230 | gfp_t gfp) | |
6231 | { | |
6232 | struct sk_buff *msg; | |
6233 | struct nlattr *pinfoattr; | |
6234 | void *hdr; | |
6235 | ||
6236 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
6237 | if (!msg) | |
6238 | return; | |
6239 | ||
6240 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
6241 | if (!hdr) { | |
6242 | nlmsg_free(msg); | |
6243 | return; | |
6244 | } | |
6245 | ||
6246 | NLA_PUT_U32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx); | |
6247 | NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex); | |
6248 | ||
6249 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_CQM); | |
6250 | if (!pinfoattr) | |
6251 | goto nla_put_failure; | |
6252 | ||
6253 | NLA_PUT_U32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
6254 | rssi_event); | |
6255 | ||
6256 | nla_nest_end(msg, pinfoattr); | |
6257 | ||
6258 | if (genlmsg_end(msg, hdr) < 0) { | |
6259 | nlmsg_free(msg); | |
6260 | return; | |
6261 | } | |
6262 | ||
6263 | genlmsg_multicast_netns(wiphy_net(&rdev->wiphy), msg, 0, | |
6264 | nl80211_mlme_mcgrp.id, gfp); | |
6265 | return; | |
6266 | ||
6267 | nla_put_failure: | |
6268 | genlmsg_cancel(msg, hdr); | |
6269 | nlmsg_free(msg); | |
6270 | } | |
6271 | ||
026331c4 JM |
6272 | static int nl80211_netlink_notify(struct notifier_block * nb, |
6273 | unsigned long state, | |
6274 | void *_notify) | |
6275 | { | |
6276 | struct netlink_notify *notify = _notify; | |
6277 | struct cfg80211_registered_device *rdev; | |
6278 | struct wireless_dev *wdev; | |
6279 | ||
6280 | if (state != NETLINK_URELEASE) | |
6281 | return NOTIFY_DONE; | |
6282 | ||
6283 | rcu_read_lock(); | |
6284 | ||
6285 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) | |
6286 | list_for_each_entry_rcu(wdev, &rdev->netdev_list, list) | |
2e161f78 | 6287 | cfg80211_mlme_unregister_socket(wdev, notify->pid); |
026331c4 JM |
6288 | |
6289 | rcu_read_unlock(); | |
6290 | ||
6291 | return NOTIFY_DONE; | |
6292 | } | |
6293 | ||
6294 | static struct notifier_block nl80211_netlink_notifier = { | |
6295 | .notifier_call = nl80211_netlink_notify, | |
6296 | }; | |
6297 | ||
55682965 JB |
6298 | /* initialisation/exit functions */ |
6299 | ||
6300 | int nl80211_init(void) | |
6301 | { | |
0d63cbb5 | 6302 | int err; |
55682965 | 6303 | |
0d63cbb5 MM |
6304 | err = genl_register_family_with_ops(&nl80211_fam, |
6305 | nl80211_ops, ARRAY_SIZE(nl80211_ops)); | |
55682965 JB |
6306 | if (err) |
6307 | return err; | |
6308 | ||
55682965 JB |
6309 | err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); |
6310 | if (err) | |
6311 | goto err_out; | |
6312 | ||
2a519311 JB |
6313 | err = genl_register_mc_group(&nl80211_fam, &nl80211_scan_mcgrp); |
6314 | if (err) | |
6315 | goto err_out; | |
6316 | ||
73d54c9e LR |
6317 | err = genl_register_mc_group(&nl80211_fam, &nl80211_regulatory_mcgrp); |
6318 | if (err) | |
6319 | goto err_out; | |
6320 | ||
6039f6d2 JM |
6321 | err = genl_register_mc_group(&nl80211_fam, &nl80211_mlme_mcgrp); |
6322 | if (err) | |
6323 | goto err_out; | |
6324 | ||
aff89a9b JB |
6325 | #ifdef CONFIG_NL80211_TESTMODE |
6326 | err = genl_register_mc_group(&nl80211_fam, &nl80211_testmode_mcgrp); | |
6327 | if (err) | |
6328 | goto err_out; | |
6329 | #endif | |
6330 | ||
026331c4 JM |
6331 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
6332 | if (err) | |
6333 | goto err_out; | |
6334 | ||
55682965 JB |
6335 | return 0; |
6336 | err_out: | |
6337 | genl_unregister_family(&nl80211_fam); | |
6338 | return err; | |
6339 | } | |
6340 | ||
6341 | void nl80211_exit(void) | |
6342 | { | |
026331c4 | 6343 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
6344 | genl_unregister_family(&nl80211_fam); |
6345 | } |