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