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