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