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