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