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