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