]>
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> |
2740f0cf | 5 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
66cd794e | 6 | * Copyright 2015-2017 Intel Deutschland GmbH |
55682965 JB |
7 | */ |
8 | ||
9 | #include <linux/if.h> | |
10 | #include <linux/module.h> | |
11 | #include <linux/err.h> | |
5a0e3ad6 | 12 | #include <linux/slab.h> |
55682965 JB |
13 | #include <linux/list.h> |
14 | #include <linux/if_ether.h> | |
15 | #include <linux/ieee80211.h> | |
16 | #include <linux/nl80211.h> | |
17 | #include <linux/rtnetlink.h> | |
18 | #include <linux/netlink.h> | |
c7cb043b | 19 | #include <linux/nospec.h> |
2a519311 | 20 | #include <linux/etherdevice.h> |
463d0183 | 21 | #include <net/net_namespace.h> |
55682965 JB |
22 | #include <net/genetlink.h> |
23 | #include <net/cfg80211.h> | |
463d0183 | 24 | #include <net/sock.h> |
2a0e047e | 25 | #include <net/inet_connection_sock.h> |
55682965 JB |
26 | #include "core.h" |
27 | #include "nl80211.h" | |
b2e1b302 | 28 | #include "reg.h" |
e35e4d28 | 29 | #include "rdev-ops.h" |
55682965 | 30 | |
5fb628e9 JM |
31 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
32 | struct genl_info *info, | |
33 | struct cfg80211_crypto_settings *settings, | |
34 | int cipher_limit); | |
35 | ||
55682965 | 36 | /* the netlink family */ |
489111e5 | 37 | static struct genl_family nl80211_fam; |
55682965 | 38 | |
2a94fe48 JB |
39 | /* multicast groups */ |
40 | enum nl80211_multicast_groups { | |
41 | NL80211_MCGRP_CONFIG, | |
42 | NL80211_MCGRP_SCAN, | |
43 | NL80211_MCGRP_REGULATORY, | |
44 | NL80211_MCGRP_MLME, | |
567ffc35 | 45 | NL80211_MCGRP_VENDOR, |
50bcd31d | 46 | NL80211_MCGRP_NAN, |
2a94fe48 JB |
47 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
48 | }; | |
49 | ||
50 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
51 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
52 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
53 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
54 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
55 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
50bcd31d | 56 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
2a94fe48 | 57 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 58 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
59 | #endif |
60 | }; | |
61 | ||
89a54e48 JB |
62 | /* returns ERR_PTR values */ |
63 | static struct wireless_dev * | |
64 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 65 | { |
89a54e48 JB |
66 | struct cfg80211_registered_device *rdev; |
67 | struct wireless_dev *result = NULL; | |
68 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
69 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
70 | u64 wdev_id; | |
71 | int wiphy_idx = -1; | |
72 | int ifidx = -1; | |
55682965 | 73 | |
5fe231e8 | 74 | ASSERT_RTNL(); |
55682965 | 75 | |
89a54e48 JB |
76 | if (!have_ifidx && !have_wdev_id) |
77 | return ERR_PTR(-EINVAL); | |
55682965 | 78 | |
89a54e48 JB |
79 | if (have_ifidx) |
80 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
81 | if (have_wdev_id) { | |
82 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
83 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
84 | } |
85 | ||
89a54e48 JB |
86 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
87 | struct wireless_dev *wdev; | |
88 | ||
89 | if (wiphy_net(&rdev->wiphy) != netns) | |
90 | continue; | |
91 | ||
92 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
93 | continue; | |
94 | ||
53873f13 | 95 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
89a54e48 JB |
96 | if (have_ifidx && wdev->netdev && |
97 | wdev->netdev->ifindex == ifidx) { | |
98 | result = wdev; | |
99 | break; | |
100 | } | |
101 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
102 | result = wdev; | |
103 | break; | |
104 | } | |
105 | } | |
89a54e48 JB |
106 | |
107 | if (result) | |
108 | break; | |
109 | } | |
110 | ||
111 | if (result) | |
112 | return result; | |
113 | return ERR_PTR(-ENODEV); | |
55682965 JB |
114 | } |
115 | ||
a9455408 | 116 | static struct cfg80211_registered_device * |
878d9ec7 | 117 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 118 | { |
7fee4778 JB |
119 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
120 | struct net_device *netdev; | |
a9455408 | 121 | |
5fe231e8 | 122 | ASSERT_RTNL(); |
a9455408 | 123 | |
878d9ec7 | 124 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
125 | !attrs[NL80211_ATTR_IFINDEX] && |
126 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
127 | return ERR_PTR(-EINVAL); |
128 | ||
878d9ec7 | 129 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 130 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 131 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 132 | |
89a54e48 JB |
133 | if (attrs[NL80211_ATTR_WDEV]) { |
134 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
135 | struct wireless_dev *wdev; | |
136 | bool found = false; | |
137 | ||
138 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
139 | if (tmp) { | |
140 | /* make sure wdev exists */ | |
53873f13 | 141 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
89a54e48 JB |
142 | if (wdev->identifier != (u32)wdev_id) |
143 | continue; | |
144 | found = true; | |
145 | break; | |
146 | } | |
89a54e48 JB |
147 | |
148 | if (!found) | |
149 | tmp = NULL; | |
150 | ||
151 | if (rdev && tmp != rdev) | |
152 | return ERR_PTR(-EINVAL); | |
153 | rdev = tmp; | |
154 | } | |
155 | } | |
156 | ||
878d9ec7 JB |
157 | if (attrs[NL80211_ATTR_IFINDEX]) { |
158 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7a087e74 | 159 | |
7f2b8562 | 160 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
161 | if (netdev) { |
162 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
163 | tmp = wiphy_to_rdev( |
164 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
165 | else |
166 | tmp = NULL; | |
167 | ||
7fee4778 JB |
168 | /* not wireless device -- return error */ |
169 | if (!tmp) | |
170 | return ERR_PTR(-EINVAL); | |
171 | ||
172 | /* mismatch -- return error */ | |
173 | if (rdev && tmp != rdev) | |
174 | return ERR_PTR(-EINVAL); | |
175 | ||
176 | rdev = tmp; | |
a9455408 | 177 | } |
a9455408 | 178 | } |
a9455408 | 179 | |
4f7eff10 JB |
180 | if (!rdev) |
181 | return ERR_PTR(-ENODEV); | |
a9455408 | 182 | |
4f7eff10 JB |
183 | if (netns != wiphy_net(&rdev->wiphy)) |
184 | return ERR_PTR(-ENODEV); | |
185 | ||
186 | return rdev; | |
a9455408 JB |
187 | } |
188 | ||
189 | /* | |
190 | * This function returns a pointer to the driver | |
191 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
192 | * |
193 | * The result of this can be a PTR_ERR and hence must | |
194 | * be checked with IS_ERR() for errors. | |
195 | */ | |
196 | static struct cfg80211_registered_device * | |
4f7eff10 | 197 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 198 | { |
5fe231e8 | 199 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
200 | } |
201 | ||
55682965 | 202 | /* policy for the attributes */ |
8cd4d456 | 203 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
204 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
205 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 206 | .len = 20-1 }, |
31888487 | 207 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 208 | |
72bdcf34 | 209 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 210 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
211 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
212 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
213 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
214 | ||
b9a5f8ca JM |
215 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
216 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
217 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
218 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 219 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 220 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
221 | |
222 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
223 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
224 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 225 | |
e007b857 EP |
226 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
227 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 228 | |
b9454e83 | 229 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
230 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
231 | .len = WLAN_MAX_KEY_LEN }, | |
232 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
233 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
234 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 235 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 236 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
237 | |
238 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
239 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
240 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
241 | .len = IEEE80211_MAX_DATA_LEN }, | |
242 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
243 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
244 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
245 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
246 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
247 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
248 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 249 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 250 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 251 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 252 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 253 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 254 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 255 | |
b2e1b302 LR |
256 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
257 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
258 | ||
9f1ba906 JM |
259 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
260 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
261 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
262 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
263 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 264 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 265 | |
24bdd9f4 | 266 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 267 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 268 | |
6c739419 | 269 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
270 | |
271 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
272 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
273 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
274 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
275 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
276 | |
277 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
278 | .len = IEEE80211_MAX_SSID_LEN }, | |
279 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
280 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 281 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 282 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 283 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
284 | [NL80211_ATTR_STA_FLAGS2] = { |
285 | .len = sizeof(struct nl80211_sta_flag_update), | |
286 | }, | |
3f77316c | 287 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
288 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
289 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
290 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
291 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
292 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 293 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 294 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
9361df14 | 295 | [NL80211_ATTR_PMKID] = { .len = WLAN_PMKID_LEN }, |
9588bbd5 JM |
296 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
297 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 298 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
299 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
300 | .len = IEEE80211_MAX_DATA_LEN }, | |
301 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 302 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 303 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 304 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 305 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
306 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
307 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 308 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
309 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
310 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 311 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 312 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 313 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 314 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 315 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 316 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 317 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 318 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 319 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
320 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
321 | .len = IEEE80211_MAX_DATA_LEN }, | |
322 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
323 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 324 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 325 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 326 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
327 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
328 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
329 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
330 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
331 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 332 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 333 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
334 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
335 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 336 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
337 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
338 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
339 | .len = NL80211_HT_CAPABILITY_LEN | |
340 | }, | |
1d9d9213 | 341 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 342 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 343 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 344 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 345 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
11b6b5a4 | 346 | [NL80211_ATTR_AUTH_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 347 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 348 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
349 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
350 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
8feb69c7 | 351 | [NL80211_ATTR_LOCAL_MESH_POWER_MODE] = {. type = NLA_U32 }, |
77765eaf VT |
352 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
353 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
354 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
355 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 356 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
357 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
358 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
359 | .len = NL80211_VHT_CAPABILITY_LEN, | |
360 | }, | |
355199e0 JM |
361 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
362 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
363 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 364 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
365 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
366 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
367 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
368 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
369 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
370 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
371 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 372 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 373 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
374 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
375 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
376 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
377 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
378 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
379 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
380 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 381 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 382 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 383 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 384 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
385 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
386 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
387 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 388 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 389 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 390 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 391 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 392 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
05050753 | 393 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
34d50519 | 394 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
38de03d2 | 395 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
17b94247 | 396 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
c6e6a0c8 AE |
397 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
398 | .len = VHT_MUMIMO_GROUPS_DATA_LEN | |
399 | }, | |
400 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, | |
cb3b7d87 | 401 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, |
8585989d | 402 | [NL80211_ATTR_BANDS] = { .type = NLA_U32 }, |
a442b761 | 403 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
348bd456 JM |
404 | [NL80211_ATTR_FILS_KEK] = { .type = NLA_BINARY, |
405 | .len = FILS_MAX_KEK_LEN }, | |
406 | [NL80211_ATTR_FILS_NONCES] = { .len = 2 * FILS_NONCE_LEN }, | |
ce0ce13a | 407 | [NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED] = { .type = NLA_FLAG, }, |
2fa436b3 | 408 | [NL80211_ATTR_BSSID] = { .len = ETH_ALEN }, |
bf95ecdb | 409 | [NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] = { .type = NLA_S8 }, |
410 | [NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST] = { | |
411 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
412 | }, | |
3093ebbe | 413 | [NL80211_ATTR_TIMEOUT_REASON] = { .type = NLA_U32 }, |
a3caf744 VK |
414 | [NL80211_ATTR_FILS_ERP_USERNAME] = { .type = NLA_BINARY, |
415 | .len = FILS_ERP_MAX_USERNAME_LEN }, | |
416 | [NL80211_ATTR_FILS_ERP_REALM] = { .type = NLA_BINARY, | |
417 | .len = FILS_ERP_MAX_REALM_LEN }, | |
418 | [NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] = { .type = NLA_U16 }, | |
419 | [NL80211_ATTR_FILS_ERP_RRK] = { .type = NLA_BINARY, | |
420 | .len = FILS_ERP_MAX_RRK_LEN }, | |
421 | [NL80211_ATTR_FILS_CACHE_ID] = { .len = 2 }, | |
422 | [NL80211_ATTR_PMK] = { .type = NLA_BINARY, .len = PMK_MAX_LEN }, | |
ca986ad9 | 423 | [NL80211_ATTR_SCHED_SCAN_MULTI] = { .type = NLA_FLAG }, |
55682965 JB |
424 | }; |
425 | ||
e31b8213 | 426 | /* policy for the key attributes */ |
b54452b0 | 427 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 428 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
429 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
430 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 431 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
432 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
433 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 434 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
435 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
436 | }; | |
437 | ||
438 | /* policy for the key default flags */ | |
439 | static const struct nla_policy | |
440 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
441 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
442 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
443 | }; |
444 | ||
f83ace3b | 445 | #ifdef CONFIG_PM |
ff1b6e69 JB |
446 | /* policy for WoWLAN attributes */ |
447 | static const struct nla_policy | |
448 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
449 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
450 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
451 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
452 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
453 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
454 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
455 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
456 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 457 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 458 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
459 | }; |
460 | ||
461 | static const struct nla_policy | |
462 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
463 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
464 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
465 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
466 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
467 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
468 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
469 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
470 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
471 | }, | |
472 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
473 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
474 | }, | |
475 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
476 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
477 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 | 478 | }; |
f83ace3b | 479 | #endif /* CONFIG_PM */ |
ff1b6e69 | 480 | |
be29b99a AK |
481 | /* policy for coalesce rule attributes */ |
482 | static const struct nla_policy | |
483 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
484 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
485 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
486 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
487 | }; | |
488 | ||
e5497d76 JB |
489 | /* policy for GTK rekey offload attributes */ |
490 | static const struct nla_policy | |
491 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
492 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
493 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
494 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
495 | }; | |
496 | ||
a1f1c21c LC |
497 | static const struct nla_policy |
498 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 499 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 500 | .len = IEEE80211_MAX_SSID_LEN }, |
3007e352 | 501 | [NL80211_SCHED_SCAN_MATCH_ATTR_BSSID] = { .len = ETH_ALEN }, |
88e920b4 | 502 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
503 | }; |
504 | ||
3b06d277 AS |
505 | static const struct nla_policy |
506 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { | |
507 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, | |
508 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, | |
509 | }; | |
510 | ||
38de03d2 AS |
511 | static const struct nla_policy |
512 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { | |
513 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, | |
514 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, | |
515 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { | |
516 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
517 | }, | |
518 | }; | |
519 | ||
a442b761 AB |
520 | /* policy for NAN function attributes */ |
521 | static const struct nla_policy | |
522 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { | |
523 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, | |
0a27844c | 524 | [NL80211_NAN_FUNC_SERVICE_ID] = { |
a442b761 AB |
525 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, |
526 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, | |
527 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, | |
528 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, | |
529 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, | |
530 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, | |
531 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, | |
532 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, | |
533 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, | |
534 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, | |
535 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, | |
536 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, | |
537 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
538 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
539 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, | |
540 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, | |
541 | }; | |
542 | ||
543 | /* policy for Service Response Filter attributes */ | |
544 | static const struct nla_policy | |
545 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { | |
546 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, | |
547 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, | |
548 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, | |
549 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, | |
550 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, | |
551 | }; | |
552 | ||
ad670233 PX |
553 | /* policy for packet pattern attributes */ |
554 | static const struct nla_policy | |
555 | nl80211_packet_pattern_policy[MAX_NL80211_PKTPAT + 1] = { | |
556 | [NL80211_PKTPAT_MASK] = { .type = NLA_BINARY, }, | |
557 | [NL80211_PKTPAT_PATTERN] = { .type = NLA_BINARY, }, | |
558 | [NL80211_PKTPAT_OFFSET] = { .type = NLA_U32 }, | |
559 | }; | |
560 | ||
97990a06 JB |
561 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
562 | struct netlink_callback *cb, | |
563 | struct cfg80211_registered_device **rdev, | |
564 | struct wireless_dev **wdev) | |
a043897a | 565 | { |
97990a06 | 566 | int err; |
a043897a | 567 | |
97990a06 JB |
568 | if (!cb->args[0]) { |
569 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
c90c39da | 570 | genl_family_attrbuf(&nl80211_fam), |
fceb6435 | 571 | nl80211_fam.maxattr, nl80211_policy, NULL); |
97990a06 | 572 | if (err) |
ea90e0dc | 573 | return err; |
67748893 | 574 | |
c90c39da JB |
575 | *wdev = __cfg80211_wdev_from_attrs( |
576 | sock_net(skb->sk), | |
577 | genl_family_attrbuf(&nl80211_fam)); | |
ea90e0dc JB |
578 | if (IS_ERR(*wdev)) |
579 | return PTR_ERR(*wdev); | |
f26cbf40 | 580 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
581 | /* 0 is the first index - add 1 to parse only once */ |
582 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
583 | cb->args[1] = (*wdev)->identifier; |
584 | } else { | |
c319d50b JB |
585 | /* subtract the 1 again here */ |
586 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 587 | struct wireless_dev *tmp; |
67748893 | 588 | |
ea90e0dc JB |
589 | if (!wiphy) |
590 | return -ENODEV; | |
f26cbf40 | 591 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 592 | *wdev = NULL; |
67748893 | 593 | |
53873f13 | 594 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
97990a06 JB |
595 | if (tmp->identifier == cb->args[1]) { |
596 | *wdev = tmp; | |
597 | break; | |
598 | } | |
599 | } | |
67748893 | 600 | |
ea90e0dc JB |
601 | if (!*wdev) |
602 | return -ENODEV; | |
67748893 JB |
603 | } |
604 | ||
67748893 | 605 | return 0; |
67748893 JB |
606 | } |
607 | ||
f4a11bb0 JB |
608 | /* IE validation */ |
609 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
610 | { | |
611 | const u8 *pos; | |
612 | int len; | |
613 | ||
614 | if (!attr) | |
615 | return true; | |
616 | ||
617 | pos = nla_data(attr); | |
618 | len = nla_len(attr); | |
619 | ||
620 | while (len) { | |
621 | u8 elemlen; | |
622 | ||
623 | if (len < 2) | |
624 | return false; | |
625 | len -= 2; | |
626 | ||
627 | elemlen = pos[1]; | |
628 | if (elemlen > len) | |
629 | return false; | |
630 | ||
631 | len -= elemlen; | |
632 | pos += 2 + elemlen; | |
633 | } | |
634 | ||
635 | return true; | |
636 | } | |
637 | ||
55682965 | 638 | /* message building helper */ |
15e47304 | 639 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
640 | int flags, u8 cmd) |
641 | { | |
642 | /* since there is no private header just add the generic one */ | |
15e47304 | 643 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
644 | } |
645 | ||
5dab3b8a | 646 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
647 | struct ieee80211_channel *chan, |
648 | bool large) | |
5dab3b8a | 649 | { |
ea077c1c RL |
650 | /* Some channels must be completely excluded from the |
651 | * list to protect old user-space tools from breaking | |
652 | */ | |
653 | if (!large && chan->flags & | |
654 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
655 | return 0; | |
656 | ||
9360ffd1 DM |
657 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
658 | chan->center_freq)) | |
659 | goto nla_put_failure; | |
5dab3b8a | 660 | |
9360ffd1 DM |
661 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
662 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
663 | goto nla_put_failure; | |
8fe02e16 LR |
664 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
665 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
666 | goto nla_put_failure; | |
667 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
668 | goto nla_put_failure; | |
669 | } | |
cdc89b97 JB |
670 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
671 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
672 | goto nla_put_failure; | |
673 | if (large) { | |
674 | u32 time; | |
675 | ||
676 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
677 | ||
678 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
679 | chan->dfs_state)) | |
680 | goto nla_put_failure; | |
681 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
682 | time)) | |
683 | goto nla_put_failure; | |
089027e5 JD |
684 | if (nla_put_u32(msg, |
685 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
686 | chan->dfs_cac_ms)) | |
687 | goto nla_put_failure; | |
cdc89b97 JB |
688 | } |
689 | } | |
5dab3b8a | 690 | |
fe1abafd JB |
691 | if (large) { |
692 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
693 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
694 | goto nla_put_failure; | |
695 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
696 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
697 | goto nla_put_failure; | |
698 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
699 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
700 | goto nla_put_failure; | |
701 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
702 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
703 | goto nla_put_failure; | |
570dbde1 DS |
704 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
705 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
706 | goto nla_put_failure; | |
06f207fc AN |
707 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
708 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) | |
570dbde1 | 709 | goto nla_put_failure; |
ea077c1c RL |
710 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
711 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
712 | goto nla_put_failure; | |
713 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
714 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
715 | goto nla_put_failure; | |
fe1abafd JB |
716 | } |
717 | ||
9360ffd1 DM |
718 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
719 | DBM_TO_MBM(chan->max_power))) | |
720 | goto nla_put_failure; | |
5dab3b8a LR |
721 | |
722 | return 0; | |
723 | ||
724 | nla_put_failure: | |
725 | return -ENOBUFS; | |
726 | } | |
727 | ||
55682965 JB |
728 | /* netlink command implementations */ |
729 | ||
b9454e83 JB |
730 | struct key_parse { |
731 | struct key_params p; | |
732 | int idx; | |
e31b8213 | 733 | int type; |
b9454e83 | 734 | bool def, defmgmt; |
dbd2fd65 | 735 | bool def_uni, def_multi; |
b9454e83 JB |
736 | }; |
737 | ||
738 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
739 | { | |
740 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
741 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
fceb6435 | 742 | nl80211_key_policy, NULL); |
b9454e83 JB |
743 | if (err) |
744 | return err; | |
745 | ||
746 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
747 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
748 | ||
dbd2fd65 JB |
749 | if (k->def) { |
750 | k->def_uni = true; | |
751 | k->def_multi = true; | |
752 | } | |
753 | if (k->defmgmt) | |
754 | k->def_multi = true; | |
755 | ||
b9454e83 JB |
756 | if (tb[NL80211_KEY_IDX]) |
757 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
758 | ||
759 | if (tb[NL80211_KEY_DATA]) { | |
760 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
761 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
762 | } | |
763 | ||
764 | if (tb[NL80211_KEY_SEQ]) { | |
765 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
766 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
767 | } | |
768 | ||
769 | if (tb[NL80211_KEY_CIPHER]) | |
770 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
771 | ||
e31b8213 JB |
772 | if (tb[NL80211_KEY_TYPE]) { |
773 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
774 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
775 | return -EINVAL; | |
776 | } | |
777 | ||
dbd2fd65 JB |
778 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
779 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
7a087e74 | 780 | |
2da8f419 JB |
781 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
782 | tb[NL80211_KEY_DEFAULT_TYPES], | |
fceb6435 | 783 | nl80211_key_default_policy, NULL); |
dbd2fd65 JB |
784 | if (err) |
785 | return err; | |
786 | ||
787 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
788 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
789 | } | |
790 | ||
b9454e83 JB |
791 | return 0; |
792 | } | |
793 | ||
794 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
795 | { | |
796 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
797 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
798 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
799 | } | |
800 | ||
801 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
802 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
803 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
804 | } | |
805 | ||
806 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
807 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
808 | ||
809 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
810 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
811 | ||
812 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
813 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
814 | ||
dbd2fd65 JB |
815 | if (k->def) { |
816 | k->def_uni = true; | |
817 | k->def_multi = true; | |
818 | } | |
819 | if (k->defmgmt) | |
820 | k->def_multi = true; | |
821 | ||
e31b8213 JB |
822 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
823 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
824 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
825 | return -EINVAL; | |
826 | } | |
827 | ||
dbd2fd65 JB |
828 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
829 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
fceb6435 JB |
830 | int err = nla_parse_nested(kdt, |
831 | NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
832 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
fe52145f JB |
833 | nl80211_key_default_policy, |
834 | info->extack); | |
dbd2fd65 JB |
835 | if (err) |
836 | return err; | |
837 | ||
838 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
839 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
840 | } | |
841 | ||
b9454e83 JB |
842 | return 0; |
843 | } | |
844 | ||
845 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
846 | { | |
847 | int err; | |
848 | ||
849 | memset(k, 0, sizeof(*k)); | |
850 | k->idx = -1; | |
e31b8213 | 851 | k->type = -1; |
b9454e83 JB |
852 | |
853 | if (info->attrs[NL80211_ATTR_KEY]) | |
854 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
855 | else | |
856 | err = nl80211_parse_key_old(info, k); | |
857 | ||
858 | if (err) | |
859 | return err; | |
860 | ||
861 | if (k->def && k->defmgmt) | |
862 | return -EINVAL; | |
863 | ||
dbd2fd65 JB |
864 | if (k->defmgmt) { |
865 | if (k->def_uni || !k->def_multi) | |
866 | return -EINVAL; | |
867 | } | |
868 | ||
b9454e83 JB |
869 | if (k->idx != -1) { |
870 | if (k->defmgmt) { | |
871 | if (k->idx < 4 || k->idx > 5) | |
872 | return -EINVAL; | |
873 | } else if (k->def) { | |
874 | if (k->idx < 0 || k->idx > 3) | |
875 | return -EINVAL; | |
876 | } else { | |
877 | if (k->idx < 0 || k->idx > 5) | |
878 | return -EINVAL; | |
879 | } | |
880 | } | |
881 | ||
882 | return 0; | |
883 | } | |
884 | ||
fffd0934 JB |
885 | static struct cfg80211_cached_keys * |
886 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 887 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
888 | { |
889 | struct key_parse parse; | |
890 | struct nlattr *key; | |
891 | struct cfg80211_cached_keys *result; | |
892 | int rem, err, def = 0; | |
f1c1f17a JB |
893 | bool have_key = false; |
894 | ||
895 | nla_for_each_nested(key, keys, rem) { | |
896 | have_key = true; | |
897 | break; | |
898 | } | |
899 | ||
900 | if (!have_key) | |
901 | return NULL; | |
fffd0934 JB |
902 | |
903 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
904 | if (!result) | |
905 | return ERR_PTR(-ENOMEM); | |
906 | ||
907 | result->def = -1; | |
fffd0934 JB |
908 | |
909 | nla_for_each_nested(key, keys, rem) { | |
910 | memset(&parse, 0, sizeof(parse)); | |
911 | parse.idx = -1; | |
912 | ||
913 | err = nl80211_parse_key_new(key, &parse); | |
914 | if (err) | |
915 | goto error; | |
916 | err = -EINVAL; | |
917 | if (!parse.p.key) | |
918 | goto error; | |
42ee231c | 919 | if (parse.idx < 0 || parse.idx > 3) |
fffd0934 JB |
920 | goto error; |
921 | if (parse.def) { | |
922 | if (def) | |
923 | goto error; | |
924 | def = 1; | |
925 | result->def = parse.idx; | |
dbd2fd65 JB |
926 | if (!parse.def_uni || !parse.def_multi) |
927 | goto error; | |
fffd0934 JB |
928 | } else if (parse.defmgmt) |
929 | goto error; | |
930 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 931 | parse.idx, false, NULL); |
fffd0934 JB |
932 | if (err) |
933 | goto error; | |
386b1f27 JB |
934 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
935 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { | |
936 | err = -EINVAL; | |
937 | goto error; | |
938 | } | |
fffd0934 JB |
939 | result->params[parse.idx].cipher = parse.p.cipher; |
940 | result->params[parse.idx].key_len = parse.p.key_len; | |
941 | result->params[parse.idx].key = result->data[parse.idx]; | |
942 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee | 943 | |
386b1f27 JB |
944 | /* must be WEP key if we got here */ |
945 | if (no_ht) | |
946 | *no_ht = true; | |
fffd0934 JB |
947 | } |
948 | ||
f1c1f17a JB |
949 | if (result->def < 0) { |
950 | err = -EINVAL; | |
951 | goto error; | |
952 | } | |
953 | ||
fffd0934 JB |
954 | return result; |
955 | error: | |
956 | kfree(result); | |
957 | return ERR_PTR(err); | |
958 | } | |
959 | ||
960 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
961 | { | |
962 | ASSERT_WDEV_LOCK(wdev); | |
963 | ||
fffd0934 JB |
964 | switch (wdev->iftype) { |
965 | case NL80211_IFTYPE_AP: | |
966 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 967 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 968 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
969 | break; |
970 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 971 | case NL80211_IFTYPE_STATION: |
074ac8df | 972 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 973 | if (!wdev->current_bss) |
fffd0934 JB |
974 | return -ENOLINK; |
975 | break; | |
de4fcbad | 976 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 977 | case NL80211_IFTYPE_OCB: |
de4fcbad | 978 | case NL80211_IFTYPE_MONITOR: |
cb3b7d87 | 979 | case NL80211_IFTYPE_NAN: |
de4fcbad JB |
980 | case NL80211_IFTYPE_P2P_DEVICE: |
981 | case NL80211_IFTYPE_WDS: | |
982 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
983 | return -EINVAL; |
984 | } | |
985 | ||
986 | return 0; | |
987 | } | |
988 | ||
664834de JM |
989 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
990 | struct nlattr *tb) | |
991 | { | |
992 | struct ieee80211_channel *chan; | |
993 | ||
994 | if (tb == NULL) | |
995 | return NULL; | |
996 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
997 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
998 | return NULL; | |
999 | return chan; | |
1000 | } | |
1001 | ||
7527a782 JB |
1002 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
1003 | { | |
1004 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
1005 | int i; | |
1006 | ||
1007 | if (!nl_modes) | |
1008 | goto nla_put_failure; | |
1009 | ||
1010 | i = 0; | |
1011 | while (ifmodes) { | |
9360ffd1 DM |
1012 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
1013 | goto nla_put_failure; | |
7527a782 JB |
1014 | ifmodes >>= 1; |
1015 | i++; | |
1016 | } | |
1017 | ||
1018 | nla_nest_end(msg, nl_modes); | |
1019 | return 0; | |
1020 | ||
1021 | nla_put_failure: | |
1022 | return -ENOBUFS; | |
1023 | } | |
1024 | ||
1025 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
1026 | struct sk_buff *msg, |
1027 | bool large) | |
7527a782 JB |
1028 | { |
1029 | struct nlattr *nl_combis; | |
1030 | int i, j; | |
1031 | ||
1032 | nl_combis = nla_nest_start(msg, | |
1033 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
1034 | if (!nl_combis) | |
1035 | goto nla_put_failure; | |
1036 | ||
1037 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
1038 | const struct ieee80211_iface_combination *c; | |
1039 | struct nlattr *nl_combi, *nl_limits; | |
1040 | ||
1041 | c = &wiphy->iface_combinations[i]; | |
1042 | ||
1043 | nl_combi = nla_nest_start(msg, i + 1); | |
1044 | if (!nl_combi) | |
1045 | goto nla_put_failure; | |
1046 | ||
1047 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
1048 | if (!nl_limits) | |
1049 | goto nla_put_failure; | |
1050 | ||
1051 | for (j = 0; j < c->n_limits; j++) { | |
1052 | struct nlattr *nl_limit; | |
1053 | ||
1054 | nl_limit = nla_nest_start(msg, j + 1); | |
1055 | if (!nl_limit) | |
1056 | goto nla_put_failure; | |
9360ffd1 DM |
1057 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
1058 | c->limits[j].max)) | |
1059 | goto nla_put_failure; | |
7527a782 JB |
1060 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
1061 | c->limits[j].types)) | |
1062 | goto nla_put_failure; | |
1063 | nla_nest_end(msg, nl_limit); | |
1064 | } | |
1065 | ||
1066 | nla_nest_end(msg, nl_limits); | |
1067 | ||
9360ffd1 DM |
1068 | if (c->beacon_int_infra_match && |
1069 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
1070 | goto nla_put_failure; | |
1071 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
1072 | c->num_different_channels) || | |
1073 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
1074 | c->max_interfaces)) | |
1075 | goto nla_put_failure; | |
cdc89b97 | 1076 | if (large && |
8c48b50a FF |
1077 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
1078 | c->radar_detect_widths) || | |
1079 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
1080 | c->radar_detect_regions))) | |
cdc89b97 | 1081 | goto nla_put_failure; |
0c317a02 PK |
1082 | if (c->beacon_int_min_gcd && |
1083 | nla_put_u32(msg, NL80211_IFACE_COMB_BI_MIN_GCD, | |
1084 | c->beacon_int_min_gcd)) | |
1085 | goto nla_put_failure; | |
7527a782 JB |
1086 | |
1087 | nla_nest_end(msg, nl_combi); | |
1088 | } | |
1089 | ||
1090 | nla_nest_end(msg, nl_combis); | |
1091 | ||
1092 | return 0; | |
1093 | nla_put_failure: | |
1094 | return -ENOBUFS; | |
1095 | } | |
1096 | ||
3713b4e3 | 1097 | #ifdef CONFIG_PM |
b56cf720 JB |
1098 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1099 | struct sk_buff *msg) | |
1100 | { | |
964dc9e2 | 1101 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1102 | struct nlattr *nl_tcp; |
1103 | ||
1104 | if (!tcp) | |
1105 | return 0; | |
1106 | ||
1107 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1108 | if (!nl_tcp) | |
1109 | return -ENOBUFS; | |
1110 | ||
1111 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1112 | tcp->data_payload_max)) | |
1113 | return -ENOBUFS; | |
1114 | ||
1115 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1116 | tcp->data_payload_max)) | |
1117 | return -ENOBUFS; | |
1118 | ||
1119 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1120 | return -ENOBUFS; | |
1121 | ||
1122 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1123 | sizeof(*tcp->tok), tcp->tok)) | |
1124 | return -ENOBUFS; | |
1125 | ||
1126 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1127 | tcp->data_interval_max)) | |
1128 | return -ENOBUFS; | |
1129 | ||
1130 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1131 | tcp->wake_payload_max)) | |
1132 | return -ENOBUFS; | |
1133 | ||
1134 | nla_nest_end(msg, nl_tcp); | |
1135 | return 0; | |
1136 | } | |
1137 | ||
3713b4e3 | 1138 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1139 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1140 | bool large) |
55682965 | 1141 | { |
3713b4e3 | 1142 | struct nlattr *nl_wowlan; |
55682965 | 1143 | |
1b8ec87a | 1144 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1145 | return 0; |
55682965 | 1146 | |
3713b4e3 JB |
1147 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1148 | if (!nl_wowlan) | |
1149 | return -ENOBUFS; | |
9360ffd1 | 1150 | |
1b8ec87a | 1151 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1152 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1153 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1154 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1155 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1156 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1157 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1158 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1159 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1160 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1161 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1162 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1163 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1164 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1165 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1166 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1167 | return -ENOBUFS; | |
9360ffd1 | 1168 | |
1b8ec87a | 1169 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1170 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1171 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1172 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1173 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1174 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1175 | }; |
9360ffd1 | 1176 | |
3713b4e3 JB |
1177 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1178 | sizeof(pat), &pat)) | |
1179 | return -ENOBUFS; | |
1180 | } | |
9360ffd1 | 1181 | |
75453ccb LC |
1182 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1183 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1184 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1185 | return -ENOBUFS; | |
1186 | ||
1b8ec87a | 1187 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1188 | return -ENOBUFS; |
1189 | ||
3713b4e3 | 1190 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1191 | |
3713b4e3 JB |
1192 | return 0; |
1193 | } | |
1194 | #endif | |
9360ffd1 | 1195 | |
be29b99a | 1196 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1197 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1198 | { |
1199 | struct nl80211_coalesce_rule_support rule; | |
1200 | ||
1b8ec87a | 1201 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1202 | return 0; |
1203 | ||
1b8ec87a ZG |
1204 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1205 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1206 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1207 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1208 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1209 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1210 | |
1211 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1212 | return -ENOBUFS; | |
1213 | ||
1214 | return 0; | |
1215 | } | |
1216 | ||
3713b4e3 JB |
1217 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1218 | struct ieee80211_supported_band *sband) | |
1219 | { | |
1220 | struct nlattr *nl_rates, *nl_rate; | |
1221 | struct ieee80211_rate *rate; | |
1222 | int i; | |
87bbbe22 | 1223 | |
3713b4e3 JB |
1224 | /* add HT info */ |
1225 | if (sband->ht_cap.ht_supported && | |
1226 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1227 | sizeof(sband->ht_cap.mcs), | |
1228 | &sband->ht_cap.mcs) || | |
1229 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1230 | sband->ht_cap.cap) || | |
1231 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1232 | sband->ht_cap.ampdu_factor) || | |
1233 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1234 | sband->ht_cap.ampdu_density))) | |
1235 | return -ENOBUFS; | |
afe0cbf8 | 1236 | |
3713b4e3 JB |
1237 | /* add VHT info */ |
1238 | if (sband->vht_cap.vht_supported && | |
1239 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1240 | sizeof(sband->vht_cap.vht_mcs), | |
1241 | &sband->vht_cap.vht_mcs) || | |
1242 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1243 | sband->vht_cap.cap))) | |
1244 | return -ENOBUFS; | |
f59ac048 | 1245 | |
3713b4e3 JB |
1246 | /* add bitrates */ |
1247 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1248 | if (!nl_rates) | |
1249 | return -ENOBUFS; | |
ee688b00 | 1250 | |
3713b4e3 JB |
1251 | for (i = 0; i < sband->n_bitrates; i++) { |
1252 | nl_rate = nla_nest_start(msg, i); | |
1253 | if (!nl_rate) | |
1254 | return -ENOBUFS; | |
ee688b00 | 1255 | |
3713b4e3 JB |
1256 | rate = &sband->bitrates[i]; |
1257 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1258 | rate->bitrate)) | |
1259 | return -ENOBUFS; | |
1260 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1261 | nla_put_flag(msg, | |
1262 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1263 | return -ENOBUFS; | |
ee688b00 | 1264 | |
3713b4e3 JB |
1265 | nla_nest_end(msg, nl_rate); |
1266 | } | |
d51626df | 1267 | |
3713b4e3 | 1268 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1269 | |
3713b4e3 JB |
1270 | return 0; |
1271 | } | |
ee688b00 | 1272 | |
3713b4e3 JB |
1273 | static int |
1274 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1275 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1276 | { | |
1277 | u16 stypes; | |
1278 | struct nlattr *nl_ftypes, *nl_ifs; | |
1279 | enum nl80211_iftype ift; | |
1280 | int i; | |
ee688b00 | 1281 | |
3713b4e3 JB |
1282 | if (!mgmt_stypes) |
1283 | return 0; | |
5dab3b8a | 1284 | |
3713b4e3 JB |
1285 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1286 | if (!nl_ifs) | |
1287 | return -ENOBUFS; | |
e2f367f2 | 1288 | |
3713b4e3 JB |
1289 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1290 | nl_ftypes = nla_nest_start(msg, ift); | |
1291 | if (!nl_ftypes) | |
1292 | return -ENOBUFS; | |
1293 | i = 0; | |
1294 | stypes = mgmt_stypes[ift].tx; | |
1295 | while (stypes) { | |
1296 | if ((stypes & 1) && | |
1297 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1298 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1299 | return -ENOBUFS; | |
1300 | stypes >>= 1; | |
1301 | i++; | |
ee688b00 | 1302 | } |
3713b4e3 JB |
1303 | nla_nest_end(msg, nl_ftypes); |
1304 | } | |
ee688b00 | 1305 | |
3713b4e3 | 1306 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1307 | |
3713b4e3 JB |
1308 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1309 | if (!nl_ifs) | |
1310 | return -ENOBUFS; | |
ee688b00 | 1311 | |
3713b4e3 JB |
1312 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1313 | nl_ftypes = nla_nest_start(msg, ift); | |
1314 | if (!nl_ftypes) | |
1315 | return -ENOBUFS; | |
1316 | i = 0; | |
1317 | stypes = mgmt_stypes[ift].rx; | |
1318 | while (stypes) { | |
1319 | if ((stypes & 1) && | |
1320 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1321 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1322 | return -ENOBUFS; | |
1323 | stypes >>= 1; | |
1324 | i++; | |
1325 | } | |
1326 | nla_nest_end(msg, nl_ftypes); | |
1327 | } | |
1328 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1329 | |
3713b4e3 JB |
1330 | return 0; |
1331 | } | |
ee688b00 | 1332 | |
1794899e JB |
1333 | #define CMD(op, n) \ |
1334 | do { \ | |
1335 | if (rdev->ops->op) { \ | |
1336 | i++; \ | |
1337 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1338 | goto nla_put_failure; \ | |
1339 | } \ | |
1340 | } while (0) | |
1341 | ||
1342 | static int nl80211_add_commands_unsplit(struct cfg80211_registered_device *rdev, | |
1343 | struct sk_buff *msg) | |
1344 | { | |
1345 | int i = 0; | |
1346 | ||
1347 | /* | |
1348 | * do *NOT* add anything into this function, new things need to be | |
1349 | * advertised only to new versions of userspace that can deal with | |
1350 | * the split (and they can't possibly care about new features... | |
1351 | */ | |
1352 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1353 | CMD(change_virtual_intf, SET_INTERFACE); | |
1354 | CMD(add_key, NEW_KEY); | |
1355 | CMD(start_ap, START_AP); | |
1356 | CMD(add_station, NEW_STATION); | |
1357 | CMD(add_mpath, NEW_MPATH); | |
1358 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1359 | CMD(change_bss, SET_BSS); | |
1360 | CMD(auth, AUTHENTICATE); | |
1361 | CMD(assoc, ASSOCIATE); | |
1362 | CMD(deauth, DEAUTHENTICATE); | |
1363 | CMD(disassoc, DISASSOCIATE); | |
1364 | CMD(join_ibss, JOIN_IBSS); | |
1365 | CMD(join_mesh, JOIN_MESH); | |
1366 | CMD(set_pmksa, SET_PMKSA); | |
1367 | CMD(del_pmksa, DEL_PMKSA); | |
1368 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1369 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) | |
1370 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); | |
1371 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1372 | CMD(mgmt_tx, FRAME); | |
1373 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1374 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { | |
1375 | i++; | |
1376 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
1377 | goto nla_put_failure; | |
1378 | } | |
1379 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || | |
1380 | rdev->ops->join_mesh) { | |
1381 | i++; | |
1382 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1383 | goto nla_put_failure; | |
1384 | } | |
1385 | CMD(set_wds_peer, SET_WDS_PEER); | |
1386 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { | |
1387 | CMD(tdls_mgmt, TDLS_MGMT); | |
1388 | CMD(tdls_oper, TDLS_OPER); | |
1389 | } | |
ca986ad9 | 1390 | if (rdev->wiphy.max_sched_scan_reqs) |
1794899e JB |
1391 | CMD(sched_scan_start, START_SCHED_SCAN); |
1392 | CMD(probe_client, PROBE_CLIENT); | |
1393 | CMD(set_noack_map, SET_NOACK_MAP); | |
1394 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { | |
1395 | i++; | |
1396 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1397 | goto nla_put_failure; | |
1398 | } | |
1399 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1400 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
1401 | #ifdef CONFIG_NL80211_TESTMODE | |
1402 | CMD(testmode_cmd, TESTMODE); | |
1403 | #endif | |
1404 | ||
1405 | if (rdev->ops->connect || rdev->ops->auth) { | |
1406 | i++; | |
1407 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
1408 | goto nla_put_failure; | |
1409 | } | |
1410 | ||
1411 | if (rdev->ops->disconnect || rdev->ops->deauth) { | |
1412 | i++; | |
1413 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1414 | goto nla_put_failure; | |
1415 | } | |
1416 | ||
1417 | return i; | |
1418 | nla_put_failure: | |
1419 | return -ENOBUFS; | |
1420 | } | |
1421 | ||
86e8cf98 JB |
1422 | struct nl80211_dump_wiphy_state { |
1423 | s64 filter_wiphy; | |
1424 | long start; | |
019ae3a9 | 1425 | long split_start, band_start, chan_start, capa_start; |
86e8cf98 JB |
1426 | bool split; |
1427 | }; | |
1428 | ||
1b8ec87a | 1429 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1430 | enum nl80211_commands cmd, |
3713b4e3 | 1431 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1432 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1433 | { |
1434 | void *hdr; | |
1435 | struct nlattr *nl_bands, *nl_band; | |
1436 | struct nlattr *nl_freqs, *nl_freq; | |
1437 | struct nlattr *nl_cmds; | |
57fbcce3 | 1438 | enum nl80211_band band; |
3713b4e3 JB |
1439 | struct ieee80211_channel *chan; |
1440 | int i; | |
1441 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1442 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1443 | u32 features; |
ee688b00 | 1444 | |
3bb20556 | 1445 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1446 | if (!hdr) |
1447 | return -ENOBUFS; | |
ee688b00 | 1448 | |
86e8cf98 JB |
1449 | if (WARN_ON(!state)) |
1450 | return -EINVAL; | |
ee688b00 | 1451 | |
1b8ec87a | 1452 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1453 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1454 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1455 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1456 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1457 | goto nla_put_failure; |
1458 | ||
3bb20556 JB |
1459 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1460 | goto finish; | |
1461 | ||
86e8cf98 | 1462 | switch (state->split_start) { |
3713b4e3 JB |
1463 | case 0: |
1464 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1465 | rdev->wiphy.retry_short) || |
3713b4e3 | 1466 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1467 | rdev->wiphy.retry_long) || |
3713b4e3 | 1468 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1469 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1470 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1471 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1472 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1473 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1474 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1475 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1476 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1477 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1478 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1479 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1480 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1481 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1482 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
3b06d277 AS |
1483 | rdev->wiphy.max_match_sets) || |
1484 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, | |
1485 | rdev->wiphy.max_sched_scan_plans) || | |
1486 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, | |
1487 | rdev->wiphy.max_sched_scan_plan_interval) || | |
1488 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, | |
1489 | rdev->wiphy.max_sched_scan_plan_iterations)) | |
9360ffd1 | 1490 | goto nla_put_failure; |
3713b4e3 | 1491 | |
1b8ec87a | 1492 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1493 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1494 | goto nla_put_failure; |
1b8ec87a | 1495 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1496 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1497 | goto nla_put_failure; | |
1b8ec87a | 1498 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1499 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1500 | goto nla_put_failure; | |
1b8ec87a | 1501 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1502 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1503 | goto nla_put_failure; | |
1b8ec87a | 1504 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1505 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1506 | goto nla_put_failure; | |
1b8ec87a | 1507 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1508 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1509 | goto nla_put_failure; |
86e8cf98 JB |
1510 | state->split_start++; |
1511 | if (state->split) | |
3713b4e3 JB |
1512 | break; |
1513 | case 1: | |
1514 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1515 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1516 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1517 | goto nla_put_failure; |
4745fc09 | 1518 | |
3713b4e3 | 1519 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1520 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1521 | goto nla_put_failure; |
b23aa676 | 1522 | |
1b8ec87a | 1523 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1524 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1525 | goto nla_put_failure; |
b23aa676 | 1526 | |
3713b4e3 | 1527 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1528 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1529 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1530 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1531 | goto nla_put_failure; |
b23aa676 | 1532 | |
1b8ec87a | 1533 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1534 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1535 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1536 | goto nla_put_failure; |
8fdc621d | 1537 | |
1b8ec87a ZG |
1538 | if ((rdev->wiphy.available_antennas_tx || |
1539 | rdev->wiphy.available_antennas_rx) && | |
1540 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1541 | u32 tx_ant = 0, rx_ant = 0; |
1542 | int res; | |
7a087e74 | 1543 | |
1b8ec87a | 1544 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1545 | if (!res) { |
1546 | if (nla_put_u32(msg, | |
1547 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1548 | tx_ant) || | |
1549 | nla_put_u32(msg, | |
1550 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1551 | rx_ant)) | |
1552 | goto nla_put_failure; | |
1553 | } | |
1554 | } | |
a293911d | 1555 | |
86e8cf98 JB |
1556 | state->split_start++; |
1557 | if (state->split) | |
3713b4e3 JB |
1558 | break; |
1559 | case 2: | |
1560 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1561 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1562 | goto nla_put_failure; |
86e8cf98 JB |
1563 | state->split_start++; |
1564 | if (state->split) | |
3713b4e3 JB |
1565 | break; |
1566 | case 3: | |
1567 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1568 | if (!nl_bands) | |
1569 | goto nla_put_failure; | |
f7ca38df | 1570 | |
86e8cf98 | 1571 | for (band = state->band_start; |
57fbcce3 | 1572 | band < NUM_NL80211_BANDS; band++) { |
3713b4e3 | 1573 | struct ieee80211_supported_band *sband; |
2e161f78 | 1574 | |
1b8ec87a | 1575 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1576 | |
3713b4e3 JB |
1577 | if (!sband) |
1578 | continue; | |
1579 | ||
1580 | nl_band = nla_nest_start(msg, band); | |
1581 | if (!nl_band) | |
2e161f78 | 1582 | goto nla_put_failure; |
3713b4e3 | 1583 | |
86e8cf98 | 1584 | switch (state->chan_start) { |
3713b4e3 JB |
1585 | case 0: |
1586 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1587 | goto nla_put_failure; |
86e8cf98 JB |
1588 | state->chan_start++; |
1589 | if (state->split) | |
3713b4e3 JB |
1590 | break; |
1591 | default: | |
1592 | /* add frequencies */ | |
1593 | nl_freqs = nla_nest_start( | |
1594 | msg, NL80211_BAND_ATTR_FREQS); | |
1595 | if (!nl_freqs) | |
1596 | goto nla_put_failure; | |
1597 | ||
86e8cf98 | 1598 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1599 | i < sband->n_channels; |
1600 | i++) { | |
1601 | nl_freq = nla_nest_start(msg, i); | |
1602 | if (!nl_freq) | |
1603 | goto nla_put_failure; | |
1604 | ||
1605 | chan = &sband->channels[i]; | |
1606 | ||
86e8cf98 JB |
1607 | if (nl80211_msg_put_channel( |
1608 | msg, chan, | |
1609 | state->split)) | |
3713b4e3 JB |
1610 | goto nla_put_failure; |
1611 | ||
1612 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1613 | if (state->split) |
3713b4e3 JB |
1614 | break; |
1615 | } | |
1616 | if (i < sband->n_channels) | |
86e8cf98 | 1617 | state->chan_start = i + 2; |
3713b4e3 | 1618 | else |
86e8cf98 | 1619 | state->chan_start = 0; |
3713b4e3 JB |
1620 | nla_nest_end(msg, nl_freqs); |
1621 | } | |
1622 | ||
1623 | nla_nest_end(msg, nl_band); | |
1624 | ||
86e8cf98 | 1625 | if (state->split) { |
3713b4e3 | 1626 | /* start again here */ |
86e8cf98 | 1627 | if (state->chan_start) |
3713b4e3 JB |
1628 | band--; |
1629 | break; | |
2e161f78 | 1630 | } |
2e161f78 | 1631 | } |
3713b4e3 | 1632 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1633 | |
57fbcce3 | 1634 | if (band < NUM_NL80211_BANDS) |
86e8cf98 | 1635 | state->band_start = band + 1; |
3713b4e3 | 1636 | else |
86e8cf98 | 1637 | state->band_start = 0; |
74b70a4e | 1638 | |
3713b4e3 | 1639 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1640 | if (state->band_start == 0 && state->chan_start == 0) |
1641 | state->split_start++; | |
1642 | if (state->split) | |
3713b4e3 JB |
1643 | break; |
1644 | case 4: | |
1645 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1646 | if (!nl_cmds) | |
2e161f78 JB |
1647 | goto nla_put_failure; |
1648 | ||
1794899e JB |
1649 | i = nl80211_add_commands_unsplit(rdev, msg); |
1650 | if (i < 0) | |
1651 | goto nla_put_failure; | |
86e8cf98 | 1652 | if (state->split) { |
5de17984 AS |
1653 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1654 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1655 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1656 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1657 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1658 | if (rdev->wiphy.features & |
1659 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1660 | CMD(add_tx_ts, ADD_TX_TS); |
ce0ce13a | 1661 | CMD(set_multicast_to_unicast, SET_MULTICAST_TO_UNICAST); |
088e8df8 | 1662 | CMD(update_connect_params, UPDATE_CONNECT_PARAMS); |
5de17984 | 1663 | } |
3713b4e3 | 1664 | #undef CMD |
ff1b6e69 | 1665 | |
3713b4e3 | 1666 | nla_nest_end(msg, nl_cmds); |
86e8cf98 JB |
1667 | state->split_start++; |
1668 | if (state->split) | |
3713b4e3 JB |
1669 | break; |
1670 | case 5: | |
1b8ec87a ZG |
1671 | if (rdev->ops->remain_on_channel && |
1672 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1673 | nla_put_u32(msg, |
1674 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1675 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1676 | goto nla_put_failure; |
1677 | ||
1b8ec87a | 1678 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1679 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1680 | goto nla_put_failure; | |
1681 | ||
1682 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1683 | goto nla_put_failure; | |
86e8cf98 JB |
1684 | state->split_start++; |
1685 | if (state->split) | |
3713b4e3 JB |
1686 | break; |
1687 | case 6: | |
1688 | #ifdef CONFIG_PM | |
1b8ec87a | 1689 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1690 | goto nla_put_failure; |
86e8cf98 JB |
1691 | state->split_start++; |
1692 | if (state->split) | |
3713b4e3 JB |
1693 | break; |
1694 | #else | |
86e8cf98 | 1695 | state->split_start++; |
dfb89c56 | 1696 | #endif |
3713b4e3 JB |
1697 | case 7: |
1698 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1699 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1700 | goto nla_put_failure; |
ff1b6e69 | 1701 | |
1b8ec87a | 1702 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1703 | state->split)) |
3713b4e3 | 1704 | goto nla_put_failure; |
7527a782 | 1705 | |
86e8cf98 JB |
1706 | state->split_start++; |
1707 | if (state->split) | |
3713b4e3 JB |
1708 | break; |
1709 | case 8: | |
1b8ec87a | 1710 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1711 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1712 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1713 | goto nla_put_failure; |
7527a782 | 1714 | |
1b8ec87a | 1715 | features = rdev->wiphy.features; |
fe1abafd JB |
1716 | /* |
1717 | * We can only add the per-channel limit information if the | |
1718 | * dump is split, otherwise it makes it too big. Therefore | |
1719 | * only advertise it in that case. | |
1720 | */ | |
86e8cf98 | 1721 | if (state->split) |
fe1abafd JB |
1722 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1723 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1724 | goto nla_put_failure; |
562a7480 | 1725 | |
1b8ec87a | 1726 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1727 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1728 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1729 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1730 | goto nla_put_failure; |
1f074bd8 | 1731 | |
1b8ec87a ZG |
1732 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1733 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1734 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1735 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1736 | goto nla_put_failure; |
7e7c8926 | 1737 | |
3713b4e3 JB |
1738 | /* |
1739 | * Any information below this point is only available to | |
1740 | * applications that can deal with it being split. This | |
1741 | * helps ensure that newly added capabilities don't break | |
1742 | * older tools by overrunning their buffers. | |
1743 | * | |
1744 | * We still increment split_start so that in the split | |
1745 | * case we'll continue with more data in the next round, | |
1746 | * but break unconditionally so unsplit data stops here. | |
1747 | */ | |
86e8cf98 | 1748 | state->split_start++; |
3713b4e3 JB |
1749 | break; |
1750 | case 9: | |
1b8ec87a | 1751 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1752 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1753 | rdev->wiphy.extended_capabilities_len, |
1754 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1755 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1756 | rdev->wiphy.extended_capabilities_len, |
1757 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1758 | goto nla_put_failure; |
a50df0c4 | 1759 | |
1b8ec87a | 1760 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1761 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1762 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1763 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1764 | goto nla_put_failure; |
1765 | ||
be29b99a AK |
1766 | state->split_start++; |
1767 | break; | |
1768 | case 10: | |
1b8ec87a | 1769 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1770 | goto nla_put_failure; |
1771 | ||
1b8ec87a | 1772 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1773 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1774 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1775 | goto nla_put_failure; | |
b43504cf | 1776 | |
1b8ec87a | 1777 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1778 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1779 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1780 | goto nla_put_failure; |
1781 | ||
ad7e718c JB |
1782 | state->split_start++; |
1783 | break; | |
1784 | case 11: | |
1b8ec87a | 1785 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1786 | const struct nl80211_vendor_cmd_info *info; |
1787 | struct nlattr *nested; | |
1788 | ||
1789 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1790 | if (!nested) | |
1791 | goto nla_put_failure; | |
1792 | ||
1b8ec87a ZG |
1793 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1794 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1795 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1796 | goto nla_put_failure; | |
1797 | } | |
1798 | nla_nest_end(msg, nested); | |
1799 | } | |
1800 | ||
1b8ec87a | 1801 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1802 | const struct nl80211_vendor_cmd_info *info; |
1803 | struct nlattr *nested; | |
ad7e718c | 1804 | |
567ffc35 JB |
1805 | nested = nla_nest_start(msg, |
1806 | NL80211_ATTR_VENDOR_EVENTS); | |
1807 | if (!nested) | |
ad7e718c | 1808 | goto nla_put_failure; |
567ffc35 | 1809 | |
1b8ec87a ZG |
1810 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1811 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1812 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1813 | goto nla_put_failure; | |
1814 | } | |
1815 | nla_nest_end(msg, nested); | |
1816 | } | |
9a774c78 AO |
1817 | state->split_start++; |
1818 | break; | |
1819 | case 12: | |
1820 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1821 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1822 | rdev->wiphy.max_num_csa_counters)) | |
1823 | goto nla_put_failure; | |
01e0daa4 | 1824 | |
1bdd716c AN |
1825 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1826 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1827 | goto nla_put_failure; | |
1828 | ||
ca986ad9 AVS |
1829 | if (rdev->wiphy.max_sched_scan_reqs && |
1830 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_MAX_REQS, | |
1831 | rdev->wiphy.max_sched_scan_reqs)) | |
1832 | goto nla_put_failure; | |
1833 | ||
d75bb06b GKS |
1834 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1835 | sizeof(rdev->wiphy.ext_features), | |
1836 | rdev->wiphy.ext_features)) | |
1837 | goto nla_put_failure; | |
1838 | ||
38de03d2 AS |
1839 | if (rdev->wiphy.bss_select_support) { |
1840 | struct nlattr *nested; | |
1841 | u32 bss_select_support = rdev->wiphy.bss_select_support; | |
1842 | ||
1843 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); | |
1844 | if (!nested) | |
1845 | goto nla_put_failure; | |
1846 | ||
1847 | i = 0; | |
1848 | while (bss_select_support) { | |
1849 | if ((bss_select_support & 1) && | |
1850 | nla_put_flag(msg, i)) | |
1851 | goto nla_put_failure; | |
1852 | i++; | |
1853 | bss_select_support >>= 1; | |
1854 | } | |
1855 | nla_nest_end(msg, nested); | |
1856 | } | |
1857 | ||
019ae3a9 KV |
1858 | state->split_start++; |
1859 | break; | |
1860 | case 13: | |
1861 | if (rdev->wiphy.num_iftype_ext_capab && | |
1862 | rdev->wiphy.iftype_ext_capab) { | |
1863 | struct nlattr *nested_ext_capab, *nested; | |
1864 | ||
1865 | nested = nla_nest_start(msg, | |
1866 | NL80211_ATTR_IFTYPE_EXT_CAPA); | |
1867 | if (!nested) | |
1868 | goto nla_put_failure; | |
1869 | ||
1870 | for (i = state->capa_start; | |
1871 | i < rdev->wiphy.num_iftype_ext_capab; i++) { | |
1872 | const struct wiphy_iftype_ext_capab *capab; | |
1873 | ||
1874 | capab = &rdev->wiphy.iftype_ext_capab[i]; | |
1875 | ||
1876 | nested_ext_capab = nla_nest_start(msg, i); | |
1877 | if (!nested_ext_capab || | |
1878 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | |
1879 | capab->iftype) || | |
1880 | nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1881 | capab->extended_capabilities_len, | |
1882 | capab->extended_capabilities) || | |
1883 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1884 | capab->extended_capabilities_len, | |
1885 | capab->extended_capabilities_mask)) | |
1886 | goto nla_put_failure; | |
1887 | ||
1888 | nla_nest_end(msg, nested_ext_capab); | |
1889 | if (state->split) | |
1890 | break; | |
1891 | } | |
1892 | nla_nest_end(msg, nested); | |
1893 | if (i < rdev->wiphy.num_iftype_ext_capab) { | |
1894 | state->capa_start = i + 1; | |
1895 | break; | |
1896 | } | |
1897 | } | |
1898 | ||
8585989d LC |
1899 | if (nla_put_u32(msg, NL80211_ATTR_BANDS, |
1900 | rdev->wiphy.nan_supported_bands)) | |
1901 | goto nla_put_failure; | |
1902 | ||
3713b4e3 | 1903 | /* done */ |
86e8cf98 | 1904 | state->split_start = 0; |
3713b4e3 JB |
1905 | break; |
1906 | } | |
3bb20556 | 1907 | finish: |
053c095a JB |
1908 | genlmsg_end(msg, hdr); |
1909 | return 0; | |
55682965 JB |
1910 | |
1911 | nla_put_failure: | |
bc3ed28c TG |
1912 | genlmsg_cancel(msg, hdr); |
1913 | return -EMSGSIZE; | |
55682965 JB |
1914 | } |
1915 | ||
86e8cf98 JB |
1916 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1917 | struct netlink_callback *cb, | |
1918 | struct nl80211_dump_wiphy_state *state) | |
1919 | { | |
c90c39da | 1920 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
fceb6435 JB |
1921 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, tb, |
1922 | nl80211_fam.maxattr, nl80211_policy, NULL); | |
86e8cf98 JB |
1923 | /* ignore parse errors for backward compatibility */ |
1924 | if (ret) | |
1925 | return 0; | |
1926 | ||
1927 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1928 | if (tb[NL80211_ATTR_WIPHY]) | |
1929 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1930 | if (tb[NL80211_ATTR_WDEV]) | |
1931 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1932 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1933 | struct net_device *netdev; | |
1934 | struct cfg80211_registered_device *rdev; | |
1935 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1936 | ||
7f2b8562 | 1937 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1938 | if (!netdev) |
1939 | return -ENODEV; | |
1940 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1941 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1942 | netdev->ieee80211_ptr->wiphy); |
1943 | state->filter_wiphy = rdev->wiphy_idx; | |
1944 | } | |
86e8cf98 JB |
1945 | } |
1946 | ||
1947 | return 0; | |
1948 | } | |
1949 | ||
55682965 JB |
1950 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1951 | { | |
645e77de | 1952 | int idx = 0, ret; |
86e8cf98 | 1953 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1954 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1955 | |
5fe231e8 | 1956 | rtnl_lock(); |
86e8cf98 JB |
1957 | if (!state) { |
1958 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1959 | if (!state) { |
1960 | rtnl_unlock(); | |
86e8cf98 | 1961 | return -ENOMEM; |
3713b4e3 | 1962 | } |
86e8cf98 JB |
1963 | state->filter_wiphy = -1; |
1964 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1965 | if (ret) { | |
1966 | kfree(state); | |
1967 | rtnl_unlock(); | |
1968 | return ret; | |
3713b4e3 | 1969 | } |
86e8cf98 | 1970 | cb->args[0] = (long)state; |
3713b4e3 JB |
1971 | } |
1972 | ||
1b8ec87a ZG |
1973 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1974 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1975 | continue; |
86e8cf98 | 1976 | if (++idx <= state->start) |
55682965 | 1977 | continue; |
86e8cf98 | 1978 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1979 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1980 | continue; |
1981 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1982 | do { | |
3bb20556 JB |
1983 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1984 | skb, | |
3713b4e3 JB |
1985 | NETLINK_CB(cb->skb).portid, |
1986 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1987 | NLM_F_MULTI, state); |
3713b4e3 JB |
1988 | if (ret < 0) { |
1989 | /* | |
1990 | * If sending the wiphy data didn't fit (ENOBUFS | |
1991 | * or EMSGSIZE returned), this SKB is still | |
1992 | * empty (so it's not too big because another | |
1993 | * wiphy dataset is already in the skb) and | |
1994 | * we've not tried to adjust the dump allocation | |
1995 | * yet ... then adjust the alloc size to be | |
1996 | * bigger, and return 1 but with the empty skb. | |
1997 | * This results in an empty message being RX'ed | |
1998 | * in userspace, but that is ignored. | |
1999 | * | |
2000 | * We can then retry with the larger buffer. | |
2001 | */ | |
2002 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 2003 | !skb->len && !state->split && |
3713b4e3 JB |
2004 | cb->min_dump_alloc < 4096) { |
2005 | cb->min_dump_alloc = 4096; | |
f12cb289 | 2006 | state->split_start = 0; |
d98cae64 | 2007 | rtnl_unlock(); |
3713b4e3 JB |
2008 | return 1; |
2009 | } | |
2010 | idx--; | |
2011 | break; | |
645e77de | 2012 | } |
86e8cf98 | 2013 | } while (state->split_start > 0); |
3713b4e3 | 2014 | break; |
55682965 | 2015 | } |
5fe231e8 | 2016 | rtnl_unlock(); |
55682965 | 2017 | |
86e8cf98 | 2018 | state->start = idx; |
55682965 JB |
2019 | |
2020 | return skb->len; | |
2021 | } | |
2022 | ||
86e8cf98 JB |
2023 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
2024 | { | |
2025 | kfree((void *)cb->args[0]); | |
2026 | return 0; | |
2027 | } | |
2028 | ||
55682965 JB |
2029 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
2030 | { | |
2031 | struct sk_buff *msg; | |
1b8ec87a | 2032 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 2033 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 2034 | |
645e77de | 2035 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 2036 | if (!msg) |
4c476991 | 2037 | return -ENOMEM; |
55682965 | 2038 | |
3bb20556 JB |
2039 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
2040 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 2041 | &state) < 0) { |
4c476991 JB |
2042 | nlmsg_free(msg); |
2043 | return -ENOBUFS; | |
2044 | } | |
55682965 | 2045 | |
134e6375 | 2046 | return genlmsg_reply(msg, info); |
55682965 JB |
2047 | } |
2048 | ||
31888487 JM |
2049 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
2050 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
2051 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
2052 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
2053 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
2054 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
2055 | }; | |
2056 | ||
2057 | static int parse_txq_params(struct nlattr *tb[], | |
2058 | struct ieee80211_txq_params *txq_params) | |
2059 | { | |
c7cb043b DW |
2060 | u8 ac; |
2061 | ||
a3304b0a | 2062 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
2063 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
2064 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
2065 | return -EINVAL; | |
2066 | ||
c7cb043b | 2067 | ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
2068 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
2069 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
2070 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
2071 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
2072 | ||
c7cb043b | 2073 | if (ac >= NL80211_NUM_ACS) |
a3304b0a | 2074 | return -EINVAL; |
c7cb043b | 2075 | txq_params->ac = array_index_nospec(ac, NL80211_NUM_ACS); |
31888487 JM |
2076 | return 0; |
2077 | } | |
2078 | ||
f444de05 JB |
2079 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
2080 | { | |
2081 | /* | |
cc1d2806 JB |
2082 | * You can only set the channel explicitly for WDS interfaces, |
2083 | * all others have their channel managed via their respective | |
2084 | * "establish a connection" command (connect, join, ...) | |
2085 | * | |
2086 | * For AP/GO and mesh mode, the channel can be set with the | |
2087 | * channel userspace API, but is only stored and passed to the | |
2088 | * low-level driver when the AP starts or the mesh is joined. | |
2089 | * This is for backward compatibility, userspace can also give | |
2090 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
2091 | * |
2092 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
2093 | * whatever else is going on, so they have their own special |
2094 | * operation to set the monitor channel if possible. | |
f444de05 JB |
2095 | */ |
2096 | return !wdev || | |
2097 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 2098 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
2099 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
2100 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
2101 | } |
2102 | ||
683b6d3b JB |
2103 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
2104 | struct genl_info *info, | |
2105 | struct cfg80211_chan_def *chandef) | |
2106 | { | |
dbeca2ea | 2107 | u32 control_freq; |
683b6d3b JB |
2108 | |
2109 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
2110 | return -EINVAL; | |
2111 | ||
2112 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
2113 | ||
2114 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
2115 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
2116 | chandef->center_freq1 = control_freq; | |
2117 | chandef->center_freq2 = 0; | |
683b6d3b JB |
2118 | |
2119 | /* Primary channel not allowed */ | |
2120 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
2121 | return -EINVAL; | |
2122 | ||
3d9d1d66 JB |
2123 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
2124 | enum nl80211_channel_type chantype; | |
2125 | ||
2126 | chantype = nla_get_u32( | |
2127 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
2128 | ||
2129 | switch (chantype) { | |
2130 | case NL80211_CHAN_NO_HT: | |
2131 | case NL80211_CHAN_HT20: | |
2132 | case NL80211_CHAN_HT40PLUS: | |
2133 | case NL80211_CHAN_HT40MINUS: | |
2134 | cfg80211_chandef_create(chandef, chandef->chan, | |
2135 | chantype); | |
ffa4629e TM |
2136 | /* user input for center_freq is incorrect */ |
2137 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1] && | |
2138 | chandef->center_freq1 != nla_get_u32( | |
2139 | info->attrs[NL80211_ATTR_CENTER_FREQ1])) | |
2140 | return -EINVAL; | |
2141 | /* center_freq2 must be zero */ | |
2142 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2] && | |
2143 | nla_get_u32(info->attrs[NL80211_ATTR_CENTER_FREQ2])) | |
2144 | return -EINVAL; | |
3d9d1d66 JB |
2145 | break; |
2146 | default: | |
2147 | return -EINVAL; | |
2148 | } | |
2149 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
2150 | chandef->width = | |
2151 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
2152 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
2153 | chandef->center_freq1 = | |
2154 | nla_get_u32( | |
2155 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
2156 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
2157 | chandef->center_freq2 = | |
2158 | nla_get_u32( | |
2159 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
2160 | } | |
2161 | ||
9f5e8f6e | 2162 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
2163 | return -EINVAL; |
2164 | ||
9f5e8f6e JB |
2165 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
2166 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
2167 | return -EINVAL; |
2168 | ||
2f301ab2 SW |
2169 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
2170 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
2171 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
2172 | return -EINVAL; | |
2173 | ||
683b6d3b JB |
2174 | return 0; |
2175 | } | |
2176 | ||
f444de05 | 2177 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 2178 | struct net_device *dev, |
f444de05 JB |
2179 | struct genl_info *info) |
2180 | { | |
683b6d3b | 2181 | struct cfg80211_chan_def chandef; |
f444de05 | 2182 | int result; |
e8c9bd5b | 2183 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 2184 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 2185 | |
e16821bc JM |
2186 | if (dev) |
2187 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
2188 | if (!nl80211_can_set_dev_channel(wdev)) |
2189 | return -EOPNOTSUPP; | |
e16821bc JM |
2190 | if (wdev) |
2191 | iftype = wdev->iftype; | |
f444de05 | 2192 | |
683b6d3b JB |
2193 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2194 | if (result) | |
2195 | return result; | |
f444de05 | 2196 | |
e8c9bd5b | 2197 | switch (iftype) { |
aa430da4 JB |
2198 | case NL80211_IFTYPE_AP: |
2199 | case NL80211_IFTYPE_P2P_GO: | |
923b352f AN |
2200 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
2201 | iftype)) { | |
aa430da4 JB |
2202 | result = -EINVAL; |
2203 | break; | |
2204 | } | |
e16821bc JM |
2205 | if (wdev->beacon_interval) { |
2206 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2207 | !(rdev->wiphy.features & | |
2208 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2209 | result = -EBUSY; | |
2210 | break; | |
2211 | } | |
2212 | ||
2213 | /* Only allow dynamic channel width changes */ | |
2214 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2215 | result = -EBUSY; | |
2216 | break; | |
2217 | } | |
2218 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2219 | if (result) | |
2220 | break; | |
2221 | } | |
683b6d3b | 2222 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2223 | result = 0; |
2224 | break; | |
cc1d2806 | 2225 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2226 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2227 | break; |
e8c9bd5b | 2228 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2229 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2230 | break; |
aa430da4 | 2231 | default: |
e8c9bd5b | 2232 | result = -EINVAL; |
f444de05 | 2233 | } |
f444de05 JB |
2234 | |
2235 | return result; | |
2236 | } | |
2237 | ||
2238 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2239 | { | |
4c476991 JB |
2240 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2241 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2242 | |
e16821bc | 2243 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2244 | } |
2245 | ||
e8347eba BJ |
2246 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2247 | { | |
43b19952 JB |
2248 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2249 | struct net_device *dev = info->user_ptr[1]; | |
2250 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2251 | const u8 *bssid; |
e8347eba BJ |
2252 | |
2253 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2254 | return -EINVAL; | |
2255 | ||
43b19952 JB |
2256 | if (netif_running(dev)) |
2257 | return -EBUSY; | |
e8347eba | 2258 | |
43b19952 JB |
2259 | if (!rdev->ops->set_wds_peer) |
2260 | return -EOPNOTSUPP; | |
e8347eba | 2261 | |
43b19952 JB |
2262 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2263 | return -EOPNOTSUPP; | |
e8347eba BJ |
2264 | |
2265 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2266 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2267 | } |
2268 | ||
55682965 JB |
2269 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2270 | { | |
2271 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2272 | struct net_device *netdev = NULL; |
2273 | struct wireless_dev *wdev; | |
a1e567c8 | 2274 | int result = 0, rem_txq_params = 0; |
31888487 | 2275 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2276 | u32 changed; |
2277 | u8 retry_short = 0, retry_long = 0; | |
2278 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2279 | u8 coverage_class = 0; |
55682965 | 2280 | |
5fe231e8 JB |
2281 | ASSERT_RTNL(); |
2282 | ||
f444de05 JB |
2283 | /* |
2284 | * Try to find the wiphy and netdev. Normally this | |
2285 | * function shouldn't need the netdev, but this is | |
2286 | * done for backward compatibility -- previously | |
2287 | * setting the channel was done per wiphy, but now | |
2288 | * it is per netdev. Previous userland like hostapd | |
2289 | * also passed a netdev to set_wiphy, so that it is | |
2290 | * possible to let that go to the right netdev! | |
2291 | */ | |
4bbf4d56 | 2292 | |
f444de05 JB |
2293 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2294 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2295 | ||
7f2b8562 | 2296 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2297 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2298 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2299 | else |
f444de05 | 2300 | netdev = NULL; |
4bbf4d56 JB |
2301 | } |
2302 | ||
f444de05 | 2303 | if (!netdev) { |
878d9ec7 JB |
2304 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2305 | info->attrs); | |
5fe231e8 | 2306 | if (IS_ERR(rdev)) |
4c476991 | 2307 | return PTR_ERR(rdev); |
f444de05 JB |
2308 | wdev = NULL; |
2309 | netdev = NULL; | |
2310 | result = 0; | |
71fe96bf | 2311 | } else |
f444de05 | 2312 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2313 | |
2314 | /* | |
2315 | * end workaround code, by now the rdev is available | |
2316 | * and locked, and wdev may or may not be NULL. | |
2317 | */ | |
4bbf4d56 JB |
2318 | |
2319 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2320 | result = cfg80211_dev_rename( |
2321 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2322 | |
4bbf4d56 | 2323 | if (result) |
7f2b8562 | 2324 | return result; |
31888487 JM |
2325 | |
2326 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2327 | struct ieee80211_txq_params txq_params; | |
2328 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2329 | ||
7f2b8562 YX |
2330 | if (!rdev->ops->set_txq_params) |
2331 | return -EOPNOTSUPP; | |
31888487 | 2332 | |
7f2b8562 YX |
2333 | if (!netdev) |
2334 | return -EINVAL; | |
f70f01c2 | 2335 | |
133a3ff2 | 2336 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2337 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2338 | return -EINVAL; | |
133a3ff2 | 2339 | |
7f2b8562 YX |
2340 | if (!netif_running(netdev)) |
2341 | return -ENETDOWN; | |
2b5f8b0b | 2342 | |
31888487 JM |
2343 | nla_for_each_nested(nl_txq_params, |
2344 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2345 | rem_txq_params) { | |
bfe2c7b1 JB |
2346 | result = nla_parse_nested(tb, NL80211_TXQ_ATTR_MAX, |
2347 | nl_txq_params, | |
fe52145f JB |
2348 | txq_params_policy, |
2349 | info->extack); | |
ae811e21 JB |
2350 | if (result) |
2351 | return result; | |
31888487 JM |
2352 | result = parse_txq_params(tb, &txq_params); |
2353 | if (result) | |
7f2b8562 | 2354 | return result; |
31888487 | 2355 | |
e35e4d28 HG |
2356 | result = rdev_set_txq_params(rdev, netdev, |
2357 | &txq_params); | |
31888487 | 2358 | if (result) |
7f2b8562 | 2359 | return result; |
31888487 JM |
2360 | } |
2361 | } | |
55682965 | 2362 | |
72bdcf34 | 2363 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2364 | result = __nl80211_set_channel( |
2365 | rdev, | |
2366 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2367 | info); | |
72bdcf34 | 2368 | if (result) |
7f2b8562 | 2369 | return result; |
72bdcf34 JM |
2370 | } |
2371 | ||
98d2ff8b | 2372 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2373 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2374 | enum nl80211_tx_power_setting type; |
2375 | int idx, mbm = 0; | |
2376 | ||
c8442118 JB |
2377 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2378 | txp_wdev = NULL; | |
2379 | ||
7f2b8562 YX |
2380 | if (!rdev->ops->set_tx_power) |
2381 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2382 | |
2383 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2384 | type = nla_get_u32(info->attrs[idx]); | |
2385 | ||
2386 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2387 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2388 | return -EINVAL; | |
98d2ff8b JO |
2389 | |
2390 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2391 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2392 | mbm = nla_get_u32(info->attrs[idx]); | |
2393 | } | |
2394 | ||
c8442118 | 2395 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2396 | if (result) |
7f2b8562 | 2397 | return result; |
98d2ff8b JO |
2398 | } |
2399 | ||
afe0cbf8 BR |
2400 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2401 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2402 | u32 tx_ant, rx_ant; | |
7a087e74 | 2403 | |
7f531e03 BR |
2404 | if ((!rdev->wiphy.available_antennas_tx && |
2405 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2406 | !rdev->ops->set_antenna) |
2407 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2408 | |
2409 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2410 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2411 | ||
a7ffac95 | 2412 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2413 | * available antenna masks, except for the "all" mask */ |
2414 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2415 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2416 | return -EINVAL; | |
a7ffac95 | 2417 | |
7f531e03 BR |
2418 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2419 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2420 | |
e35e4d28 | 2421 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2422 | if (result) |
7f2b8562 | 2423 | return result; |
afe0cbf8 BR |
2424 | } |
2425 | ||
b9a5f8ca JM |
2426 | changed = 0; |
2427 | ||
2428 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2429 | retry_short = nla_get_u8( | |
2430 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2431 | if (retry_short == 0) |
2432 | return -EINVAL; | |
2433 | ||
b9a5f8ca JM |
2434 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2435 | } | |
2436 | ||
2437 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2438 | retry_long = nla_get_u8( | |
2439 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2440 | if (retry_long == 0) |
2441 | return -EINVAL; | |
2442 | ||
b9a5f8ca JM |
2443 | changed |= WIPHY_PARAM_RETRY_LONG; |
2444 | } | |
2445 | ||
2446 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2447 | frag_threshold = nla_get_u32( | |
2448 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2449 | if (frag_threshold < 256) |
2450 | return -EINVAL; | |
2451 | ||
b9a5f8ca JM |
2452 | if (frag_threshold != (u32) -1) { |
2453 | /* | |
2454 | * Fragments (apart from the last one) are required to | |
2455 | * have even length. Make the fragmentation code | |
2456 | * simpler by stripping LSB should someone try to use | |
2457 | * odd threshold value. | |
2458 | */ | |
2459 | frag_threshold &= ~0x1; | |
2460 | } | |
2461 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2462 | } | |
2463 | ||
2464 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2465 | rts_threshold = nla_get_u32( | |
2466 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2467 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2468 | } | |
2469 | ||
81077e82 | 2470 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2471 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2472 | return -EINVAL; | |
2473 | ||
81077e82 LT |
2474 | coverage_class = nla_get_u8( |
2475 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2476 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2477 | } | |
2478 | ||
3057dbfd LB |
2479 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2480 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2481 | return -EOPNOTSUPP; | |
2482 | ||
2483 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2484 | } |
2485 | ||
b9a5f8ca JM |
2486 | if (changed) { |
2487 | u8 old_retry_short, old_retry_long; | |
2488 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2489 | u8 old_coverage_class; |
b9a5f8ca | 2490 | |
7f2b8562 YX |
2491 | if (!rdev->ops->set_wiphy_params) |
2492 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2493 | |
2494 | old_retry_short = rdev->wiphy.retry_short; | |
2495 | old_retry_long = rdev->wiphy.retry_long; | |
2496 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2497 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2498 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2499 | |
2500 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2501 | rdev->wiphy.retry_short = retry_short; | |
2502 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2503 | rdev->wiphy.retry_long = retry_long; | |
2504 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2505 | rdev->wiphy.frag_threshold = frag_threshold; | |
2506 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2507 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2508 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2509 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2510 | |
e35e4d28 | 2511 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2512 | if (result) { |
2513 | rdev->wiphy.retry_short = old_retry_short; | |
2514 | rdev->wiphy.retry_long = old_retry_long; | |
2515 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2516 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2517 | rdev->wiphy.coverage_class = old_coverage_class; |
9189ee31 | 2518 | return result; |
b9a5f8ca JM |
2519 | } |
2520 | } | |
7f2b8562 | 2521 | return 0; |
55682965 JB |
2522 | } |
2523 | ||
71bbc994 JB |
2524 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2525 | { | |
2526 | return (u64)wdev->identifier | | |
f26cbf40 | 2527 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2528 | } |
55682965 | 2529 | |
683b6d3b | 2530 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2531 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2532 | { |
601555cd JB |
2533 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2534 | return -EINVAL; | |
3d9d1d66 | 2535 | |
683b6d3b JB |
2536 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2537 | chandef->chan->center_freq)) | |
2538 | return -ENOBUFS; | |
3d9d1d66 JB |
2539 | switch (chandef->width) { |
2540 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2541 | case NL80211_CHAN_WIDTH_20: | |
2542 | case NL80211_CHAN_WIDTH_40: | |
2543 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2544 | cfg80211_get_chandef_type(chandef))) | |
2545 | return -ENOBUFS; | |
2546 | break; | |
2547 | default: | |
2548 | break; | |
2549 | } | |
2550 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2551 | return -ENOBUFS; | |
2552 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2553 | return -ENOBUFS; | |
2554 | if (chandef->center_freq2 && | |
2555 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2556 | return -ENOBUFS; |
2557 | return 0; | |
2558 | } | |
2559 | ||
15e47304 | 2560 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2561 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2562 | struct wireless_dev *wdev, bool removal) |
55682965 | 2563 | { |
72fb2abc | 2564 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2565 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2566 | void *hdr; |
2567 | ||
8f894be2 TB |
2568 | if (removal) |
2569 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2570 | ||
2571 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2572 | if (!hdr) |
2573 | return -1; | |
2574 | ||
72fb2abc JB |
2575 | if (dev && |
2576 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2577 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2578 | goto nla_put_failure; |
2579 | ||
2580 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2581 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
2dad624e ND |
2582 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
2583 | NL80211_ATTR_PAD) || | |
98104fde | 2584 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2585 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2586 | rdev->devlist_generation ^ | |
2587 | (cfg80211_rdev_list_generation << 2))) | |
2588 | goto nla_put_failure; | |
f5ea9120 | 2589 | |
5b7ccaf3 | 2590 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2591 | int ret; |
2592 | struct cfg80211_chan_def chandef; | |
2593 | ||
2594 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2595 | if (ret == 0) { | |
2596 | if (nl80211_send_chandef(msg, &chandef)) | |
2597 | goto nla_put_failure; | |
2598 | } | |
d91df0e3 PF |
2599 | } |
2600 | ||
d55d0d59 RM |
2601 | if (rdev->ops->get_tx_power) { |
2602 | int dbm, ret; | |
2603 | ||
2604 | ret = rdev_get_tx_power(rdev, wdev, &dbm); | |
2605 | if (ret == 0 && | |
2606 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, | |
2607 | DBM_TO_MBM(dbm))) | |
2608 | goto nla_put_failure; | |
2609 | } | |
2610 | ||
44905265 JB |
2611 | wdev_lock(wdev); |
2612 | switch (wdev->iftype) { | |
2613 | case NL80211_IFTYPE_AP: | |
2614 | if (wdev->ssid_len && | |
2615 | nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
4564b187 | 2616 | goto nla_put_failure_locked; |
44905265 JB |
2617 | break; |
2618 | case NL80211_IFTYPE_STATION: | |
2619 | case NL80211_IFTYPE_P2P_CLIENT: | |
2620 | case NL80211_IFTYPE_ADHOC: { | |
2621 | const u8 *ssid_ie; | |
2622 | if (!wdev->current_bss) | |
2623 | break; | |
7a94b8c2 | 2624 | rcu_read_lock(); |
44905265 JB |
2625 | ssid_ie = ieee80211_bss_get_ie(&wdev->current_bss->pub, |
2626 | WLAN_EID_SSID); | |
7a94b8c2 DB |
2627 | if (ssid_ie && |
2628 | nla_put(msg, NL80211_ATTR_SSID, ssid_ie[1], ssid_ie + 2)) | |
2629 | goto nla_put_failure_rcu_locked; | |
2630 | rcu_read_unlock(); | |
44905265 JB |
2631 | break; |
2632 | } | |
2633 | default: | |
2634 | /* nothing */ | |
2635 | break; | |
b84e7a05 | 2636 | } |
44905265 | 2637 | wdev_unlock(wdev); |
b84e7a05 | 2638 | |
053c095a JB |
2639 | genlmsg_end(msg, hdr); |
2640 | return 0; | |
55682965 | 2641 | |
7a94b8c2 DB |
2642 | nla_put_failure_rcu_locked: |
2643 | rcu_read_unlock(); | |
4564b187 JB |
2644 | nla_put_failure_locked: |
2645 | wdev_unlock(wdev); | |
55682965 | 2646 | nla_put_failure: |
bc3ed28c TG |
2647 | genlmsg_cancel(msg, hdr); |
2648 | return -EMSGSIZE; | |
55682965 JB |
2649 | } |
2650 | ||
2651 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2652 | { | |
2653 | int wp_idx = 0; | |
2654 | int if_idx = 0; | |
2655 | int wp_start = cb->args[0]; | |
2656 | int if_start = cb->args[1]; | |
b7fb44da | 2657 | int filter_wiphy = -1; |
f5ea9120 | 2658 | struct cfg80211_registered_device *rdev; |
55682965 | 2659 | struct wireless_dev *wdev; |
ea90e0dc | 2660 | int ret; |
55682965 | 2661 | |
5fe231e8 | 2662 | rtnl_lock(); |
b7fb44da DK |
2663 | if (!cb->args[2]) { |
2664 | struct nl80211_dump_wiphy_state state = { | |
2665 | .filter_wiphy = -1, | |
2666 | }; | |
b7fb44da DK |
2667 | |
2668 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); | |
2669 | if (ret) | |
ea90e0dc | 2670 | goto out_unlock; |
b7fb44da DK |
2671 | |
2672 | filter_wiphy = state.filter_wiphy; | |
2673 | ||
2674 | /* | |
2675 | * if filtering, set cb->args[2] to +1 since 0 is the default | |
2676 | * value needed to determine that parsing is necessary. | |
2677 | */ | |
2678 | if (filter_wiphy >= 0) | |
2679 | cb->args[2] = filter_wiphy + 1; | |
2680 | else | |
2681 | cb->args[2] = -1; | |
2682 | } else if (cb->args[2] > 0) { | |
2683 | filter_wiphy = cb->args[2] - 1; | |
2684 | } | |
2685 | ||
f5ea9120 JB |
2686 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2687 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2688 | continue; |
bba95fef JB |
2689 | if (wp_idx < wp_start) { |
2690 | wp_idx++; | |
55682965 | 2691 | continue; |
bba95fef | 2692 | } |
b7fb44da DK |
2693 | |
2694 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) | |
2695 | continue; | |
2696 | ||
55682965 JB |
2697 | if_idx = 0; |
2698 | ||
53873f13 | 2699 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
bba95fef JB |
2700 | if (if_idx < if_start) { |
2701 | if_idx++; | |
55682965 | 2702 | continue; |
bba95fef | 2703 | } |
15e47304 | 2704 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2705 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2706 | rdev, wdev, false) < 0) { |
bba95fef JB |
2707 | goto out; |
2708 | } | |
2709 | if_idx++; | |
55682965 | 2710 | } |
bba95fef JB |
2711 | |
2712 | wp_idx++; | |
55682965 | 2713 | } |
bba95fef | 2714 | out: |
55682965 JB |
2715 | cb->args[0] = wp_idx; |
2716 | cb->args[1] = if_idx; | |
2717 | ||
ea90e0dc JB |
2718 | ret = skb->len; |
2719 | out_unlock: | |
2720 | rtnl_unlock(); | |
2721 | ||
2722 | return ret; | |
55682965 JB |
2723 | } |
2724 | ||
2725 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2726 | { | |
2727 | struct sk_buff *msg; | |
1b8ec87a | 2728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2729 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2730 | |
fd2120ca | 2731 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2732 | if (!msg) |
4c476991 | 2733 | return -ENOMEM; |
55682965 | 2734 | |
15e47304 | 2735 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2736 | rdev, wdev, false) < 0) { |
4c476991 JB |
2737 | nlmsg_free(msg); |
2738 | return -ENOBUFS; | |
2739 | } | |
55682965 | 2740 | |
134e6375 | 2741 | return genlmsg_reply(msg, info); |
55682965 JB |
2742 | } |
2743 | ||
66f7ac50 MW |
2744 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2745 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2746 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2747 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2748 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2749 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2750 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2751 | }; |
2752 | ||
2753 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2754 | { | |
2755 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2756 | int flag; | |
2757 | ||
2758 | *mntrflags = 0; | |
2759 | ||
2760 | if (!nla) | |
2761 | return -EINVAL; | |
2762 | ||
fceb6435 JB |
2763 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, nla, |
2764 | mntr_flags_policy, NULL)) | |
66f7ac50 MW |
2765 | return -EINVAL; |
2766 | ||
2767 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2768 | if (flags[flag]) | |
2769 | *mntrflags |= (1<<flag); | |
2770 | ||
818a986e JB |
2771 | *mntrflags |= MONITOR_FLAG_CHANGED; |
2772 | ||
66f7ac50 MW |
2773 | return 0; |
2774 | } | |
2775 | ||
1db77596 JB |
2776 | static int nl80211_parse_mon_options(struct cfg80211_registered_device *rdev, |
2777 | enum nl80211_iftype type, | |
2778 | struct genl_info *info, | |
2779 | struct vif_params *params) | |
2780 | { | |
2781 | bool change = false; | |
2782 | int err; | |
2783 | ||
2784 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { | |
2785 | if (type != NL80211_IFTYPE_MONITOR) | |
2786 | return -EINVAL; | |
2787 | ||
2788 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], | |
2789 | ¶ms->flags); | |
2790 | if (err) | |
2791 | return err; | |
2792 | ||
2793 | change = true; | |
2794 | } | |
2795 | ||
2796 | if (params->flags & MONITOR_FLAG_ACTIVE && | |
2797 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) | |
2798 | return -EOPNOTSUPP; | |
2799 | ||
2800 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { | |
2801 | const u8 *mumimo_groups; | |
2802 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
2803 | ||
2804 | if (type != NL80211_IFTYPE_MONITOR) | |
2805 | return -EINVAL; | |
2806 | ||
2807 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
2808 | return -EOPNOTSUPP; | |
2809 | ||
2810 | mumimo_groups = | |
2811 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); | |
2812 | ||
2813 | /* bits 0 and 63 are reserved and must be zero */ | |
4954601f JB |
2814 | if ((mumimo_groups[0] & BIT(0)) || |
2815 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(7))) | |
1db77596 JB |
2816 | return -EINVAL; |
2817 | ||
2818 | params->vht_mumimo_groups = mumimo_groups; | |
2819 | change = true; | |
2820 | } | |
2821 | ||
2822 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { | |
2823 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
2824 | ||
2825 | if (type != NL80211_IFTYPE_MONITOR) | |
2826 | return -EINVAL; | |
2827 | ||
2828 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
2829 | return -EOPNOTSUPP; | |
2830 | ||
2831 | params->vht_mumimo_follow_addr = | |
2832 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]); | |
2833 | change = true; | |
2834 | } | |
2835 | ||
2836 | return change ? 1 : 0; | |
2837 | } | |
2838 | ||
9bc383de | 2839 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2840 | struct net_device *netdev, u8 use_4addr, |
2841 | enum nl80211_iftype iftype) | |
9bc383de | 2842 | { |
ad4bb6f8 | 2843 | if (!use_4addr) { |
f350a0a8 | 2844 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2845 | return -EBUSY; |
9bc383de | 2846 | return 0; |
ad4bb6f8 | 2847 | } |
9bc383de JB |
2848 | |
2849 | switch (iftype) { | |
2850 | case NL80211_IFTYPE_AP_VLAN: | |
2851 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2852 | return 0; | |
2853 | break; | |
2854 | case NL80211_IFTYPE_STATION: | |
2855 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2856 | return 0; | |
2857 | break; | |
2858 | default: | |
2859 | break; | |
2860 | } | |
2861 | ||
2862 | return -EOPNOTSUPP; | |
2863 | } | |
2864 | ||
55682965 JB |
2865 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2866 | { | |
4c476991 | 2867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2868 | struct vif_params params; |
e36d56b6 | 2869 | int err; |
04a773ad | 2870 | enum nl80211_iftype otype, ntype; |
4c476991 | 2871 | struct net_device *dev = info->user_ptr[1]; |
ac7f9cfa | 2872 | bool change = false; |
55682965 | 2873 | |
2ec600d6 LCC |
2874 | memset(¶ms, 0, sizeof(params)); |
2875 | ||
04a773ad | 2876 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2877 | |
723b038d | 2878 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2879 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2880 | if (otype != ntype) |
ac7f9cfa | 2881 | change = true; |
4c476991 JB |
2882 | if (ntype > NL80211_IFTYPE_MAX) |
2883 | return -EINVAL; | |
723b038d JB |
2884 | } |
2885 | ||
92ffe055 | 2886 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2887 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2888 | ||
4c476991 JB |
2889 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2890 | return -EINVAL; | |
29cbe68c JB |
2891 | if (netif_running(dev)) |
2892 | return -EBUSY; | |
2893 | ||
2894 | wdev_lock(wdev); | |
2895 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2896 | IEEE80211_MAX_MESH_ID_LEN); | |
2897 | wdev->mesh_id_up_len = | |
2898 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2899 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2900 | wdev->mesh_id_up_len); | |
2901 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2902 | } |
2903 | ||
8b787643 FF |
2904 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2905 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2906 | change = true; | |
ad4bb6f8 | 2907 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2908 | if (err) |
4c476991 | 2909 | return err; |
8b787643 FF |
2910 | } else { |
2911 | params.use_4addr = -1; | |
2912 | } | |
2913 | ||
1db77596 JB |
2914 | err = nl80211_parse_mon_options(rdev, ntype, info, ¶ms); |
2915 | if (err < 0) | |
2916 | return err; | |
2917 | if (err > 0) | |
c6e6a0c8 | 2918 | change = true; |
e057d3c3 | 2919 | |
ac7f9cfa | 2920 | if (change) |
818a986e | 2921 | err = cfg80211_change_iface(rdev, dev, ntype, ¶ms); |
ac7f9cfa JB |
2922 | else |
2923 | err = 0; | |
60719ffd | 2924 | |
9bc383de JB |
2925 | if (!err && params.use_4addr != -1) |
2926 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2927 | ||
55682965 JB |
2928 | return err; |
2929 | } | |
2930 | ||
2931 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2932 | { | |
4c476991 | 2933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2934 | struct vif_params params; |
84efbb84 | 2935 | struct wireless_dev *wdev; |
896ff063 | 2936 | struct sk_buff *msg; |
55682965 JB |
2937 | int err; |
2938 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
2939 | ||
78f22b6a JB |
2940 | /* to avoid failing a new interface creation due to pending removal */ |
2941 | cfg80211_destroy_ifaces(rdev); | |
2942 | ||
2ec600d6 LCC |
2943 | memset(¶ms, 0, sizeof(params)); |
2944 | ||
55682965 JB |
2945 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2946 | return -EINVAL; | |
2947 | ||
2948 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2949 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2950 | if (type > NL80211_IFTYPE_MAX) | |
2951 | return -EINVAL; | |
2952 | } | |
2953 | ||
79c97e97 | 2954 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2955 | !(rdev->wiphy.interface_modes & (1 << type))) |
2956 | return -EOPNOTSUPP; | |
55682965 | 2957 | |
cb3b7d87 | 2958 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
e8f479b1 BG |
2959 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
2960 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2961 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2962 | ETH_ALEN); | |
2963 | if (!is_valid_ether_addr(params.macaddr)) | |
2964 | return -EADDRNOTAVAIL; | |
2965 | } | |
2966 | ||
9bc383de | 2967 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2968 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2969 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2970 | if (err) |
4c476991 | 2971 | return err; |
9bc383de | 2972 | } |
8b787643 | 2973 | |
1db77596 JB |
2974 | err = nl80211_parse_mon_options(rdev, type, info, ¶ms); |
2975 | if (err < 0) | |
2976 | return err; | |
e057d3c3 | 2977 | |
a18c7192 JB |
2978 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2979 | if (!msg) | |
2980 | return -ENOMEM; | |
2981 | ||
e35e4d28 HG |
2982 | wdev = rdev_add_virtual_intf(rdev, |
2983 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
818a986e | 2984 | NET_NAME_USER, type, ¶ms); |
d687cbb7 RM |
2985 | if (WARN_ON(!wdev)) { |
2986 | nlmsg_free(msg); | |
2987 | return -EPROTO; | |
2988 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2989 | nlmsg_free(msg); |
84efbb84 | 2990 | return PTR_ERR(wdev); |
1c90f9d4 | 2991 | } |
2ec600d6 | 2992 | |
18e5ca65 | 2993 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2994 | wdev->owner_nlportid = info->snd_portid; |
2995 | ||
98104fde JB |
2996 | switch (type) { |
2997 | case NL80211_IFTYPE_MESH_POINT: | |
2998 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2999 | break; | |
29cbe68c JB |
3000 | wdev_lock(wdev); |
3001 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
3002 | IEEE80211_MAX_MESH_ID_LEN); | |
3003 | wdev->mesh_id_up_len = | |
3004 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
3005 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
3006 | wdev->mesh_id_up_len); | |
3007 | wdev_unlock(wdev); | |
98104fde | 3008 | break; |
cb3b7d87 | 3009 | case NL80211_IFTYPE_NAN: |
98104fde JB |
3010 | case NL80211_IFTYPE_P2P_DEVICE: |
3011 | /* | |
cb3b7d87 | 3012 | * P2P Device and NAN do not have a netdev, so don't go |
98104fde JB |
3013 | * through the netdev notifier and must be added here |
3014 | */ | |
3015 | mutex_init(&wdev->mtx); | |
3016 | INIT_LIST_HEAD(&wdev->event_list); | |
3017 | spin_lock_init(&wdev->event_lock); | |
3018 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
3019 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
3020 | ||
98104fde | 3021 | wdev->identifier = ++rdev->wdev_id; |
53873f13 | 3022 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
98104fde | 3023 | rdev->devlist_generation++; |
98104fde JB |
3024 | break; |
3025 | default: | |
3026 | break; | |
29cbe68c JB |
3027 | } |
3028 | ||
15e47304 | 3029 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 3030 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
3031 | nlmsg_free(msg); |
3032 | return -ENOBUFS; | |
3033 | } | |
3034 | ||
896ff063 DK |
3035 | /* |
3036 | * For wdevs which have no associated netdev object (e.g. of type | |
3037 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. | |
3038 | * For all other types, the event will be generated from the | |
3039 | * netdev notifier | |
3040 | */ | |
3041 | if (!wdev->netdev) | |
3042 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); | |
8f894be2 | 3043 | |
1c90f9d4 | 3044 | return genlmsg_reply(msg, info); |
55682965 JB |
3045 | } |
3046 | ||
3047 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
3048 | { | |
4c476991 | 3049 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 3050 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 3051 | |
4c476991 JB |
3052 | if (!rdev->ops->del_virtual_intf) |
3053 | return -EOPNOTSUPP; | |
55682965 | 3054 | |
84efbb84 JB |
3055 | /* |
3056 | * If we remove a wireless device without a netdev then clear | |
3057 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
3058 | * to check if it needs to do dev_put(). Otherwise it crashes | |
3059 | * since the wdev has been freed, unlike with a netdev where | |
3060 | * we need the dev_put() for the netdev to really be freed. | |
3061 | */ | |
3062 | if (!wdev->netdev) | |
3063 | info->user_ptr[1] = NULL; | |
3064 | ||
7f8ed01e | 3065 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
3066 | } |
3067 | ||
1d9d9213 SW |
3068 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
3069 | { | |
3070 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3071 | struct net_device *dev = info->user_ptr[1]; | |
3072 | u16 noack_map; | |
3073 | ||
3074 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
3075 | return -EINVAL; | |
3076 | ||
3077 | if (!rdev->ops->set_noack_map) | |
3078 | return -EOPNOTSUPP; | |
3079 | ||
3080 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
3081 | ||
e35e4d28 | 3082 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
3083 | } |
3084 | ||
41ade00f JB |
3085 | struct get_key_cookie { |
3086 | struct sk_buff *msg; | |
3087 | int error; | |
b9454e83 | 3088 | int idx; |
41ade00f JB |
3089 | }; |
3090 | ||
3091 | static void get_key_callback(void *c, struct key_params *params) | |
3092 | { | |
b9454e83 | 3093 | struct nlattr *key; |
41ade00f JB |
3094 | struct get_key_cookie *cookie = c; |
3095 | ||
9360ffd1 DM |
3096 | if ((params->key && |
3097 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
3098 | params->key_len, params->key)) || | |
3099 | (params->seq && | |
3100 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
3101 | params->seq_len, params->seq)) || | |
3102 | (params->cipher && | |
3103 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
3104 | params->cipher))) | |
3105 | goto nla_put_failure; | |
41ade00f | 3106 | |
b9454e83 JB |
3107 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
3108 | if (!key) | |
3109 | goto nla_put_failure; | |
3110 | ||
9360ffd1 DM |
3111 | if ((params->key && |
3112 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
3113 | params->key_len, params->key)) || | |
3114 | (params->seq && | |
3115 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
3116 | params->seq_len, params->seq)) || | |
3117 | (params->cipher && | |
3118 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
3119 | params->cipher))) | |
3120 | goto nla_put_failure; | |
b9454e83 | 3121 | |
9360ffd1 DM |
3122 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
3123 | goto nla_put_failure; | |
b9454e83 JB |
3124 | |
3125 | nla_nest_end(cookie->msg, key); | |
3126 | ||
41ade00f JB |
3127 | return; |
3128 | nla_put_failure: | |
3129 | cookie->error = 1; | |
3130 | } | |
3131 | ||
3132 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
3133 | { | |
4c476991 | 3134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3135 | int err; |
4c476991 | 3136 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3137 | u8 key_idx = 0; |
e31b8213 JB |
3138 | const u8 *mac_addr = NULL; |
3139 | bool pairwise; | |
41ade00f JB |
3140 | struct get_key_cookie cookie = { |
3141 | .error = 0, | |
3142 | }; | |
3143 | void *hdr; | |
3144 | struct sk_buff *msg; | |
3145 | ||
3146 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
3147 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
3148 | ||
3cfcf6ac | 3149 | if (key_idx > 5) |
41ade00f JB |
3150 | return -EINVAL; |
3151 | ||
3152 | if (info->attrs[NL80211_ATTR_MAC]) | |
3153 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3154 | ||
e31b8213 JB |
3155 | pairwise = !!mac_addr; |
3156 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
3157 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
7a087e74 | 3158 | |
e31b8213 JB |
3159 | if (kt >= NUM_NL80211_KEYTYPES) |
3160 | return -EINVAL; | |
3161 | if (kt != NL80211_KEYTYPE_GROUP && | |
3162 | kt != NL80211_KEYTYPE_PAIRWISE) | |
3163 | return -EINVAL; | |
3164 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
3165 | } | |
3166 | ||
4c476991 JB |
3167 | if (!rdev->ops->get_key) |
3168 | return -EOPNOTSUPP; | |
41ade00f | 3169 | |
0fa7b391 JB |
3170 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3171 | return -ENOENT; | |
3172 | ||
fd2120ca | 3173 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
3174 | if (!msg) |
3175 | return -ENOMEM; | |
41ade00f | 3176 | |
15e47304 | 3177 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 3178 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 3179 | if (!hdr) |
9fe271af | 3180 | goto nla_put_failure; |
41ade00f JB |
3181 | |
3182 | cookie.msg = msg; | |
b9454e83 | 3183 | cookie.idx = key_idx; |
41ade00f | 3184 | |
9360ffd1 DM |
3185 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3186 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
3187 | goto nla_put_failure; | |
3188 | if (mac_addr && | |
3189 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
3190 | goto nla_put_failure; | |
41ade00f | 3191 | |
e35e4d28 HG |
3192 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
3193 | get_key_callback); | |
41ade00f JB |
3194 | |
3195 | if (err) | |
6c95e2a2 | 3196 | goto free_msg; |
41ade00f JB |
3197 | |
3198 | if (cookie.error) | |
3199 | goto nla_put_failure; | |
3200 | ||
3201 | genlmsg_end(msg, hdr); | |
4c476991 | 3202 | return genlmsg_reply(msg, info); |
41ade00f JB |
3203 | |
3204 | nla_put_failure: | |
3205 | err = -ENOBUFS; | |
6c95e2a2 | 3206 | free_msg: |
41ade00f | 3207 | nlmsg_free(msg); |
41ade00f JB |
3208 | return err; |
3209 | } | |
3210 | ||
3211 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
3212 | { | |
4c476991 | 3213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 3214 | struct key_parse key; |
41ade00f | 3215 | int err; |
4c476991 | 3216 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3217 | |
b9454e83 JB |
3218 | err = nl80211_parse_key(info, &key); |
3219 | if (err) | |
3220 | return err; | |
41ade00f | 3221 | |
b9454e83 | 3222 | if (key.idx < 0) |
41ade00f JB |
3223 | return -EINVAL; |
3224 | ||
b9454e83 JB |
3225 | /* only support setting default key */ |
3226 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
3227 | return -EINVAL; |
3228 | ||
dbd2fd65 | 3229 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 3230 | |
dbd2fd65 JB |
3231 | if (key.def) { |
3232 | if (!rdev->ops->set_default_key) { | |
3233 | err = -EOPNOTSUPP; | |
3234 | goto out; | |
3235 | } | |
41ade00f | 3236 | |
dbd2fd65 JB |
3237 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
3238 | if (err) | |
3239 | goto out; | |
3240 | ||
e35e4d28 | 3241 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
3242 | key.def_uni, key.def_multi); |
3243 | ||
3244 | if (err) | |
3245 | goto out; | |
fffd0934 | 3246 | |
3d23e349 | 3247 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
3248 | dev->ieee80211_ptr->wext.default_key = key.idx; |
3249 | #endif | |
3250 | } else { | |
3251 | if (key.def_uni || !key.def_multi) { | |
3252 | err = -EINVAL; | |
3253 | goto out; | |
3254 | } | |
3255 | ||
3256 | if (!rdev->ops->set_default_mgmt_key) { | |
3257 | err = -EOPNOTSUPP; | |
3258 | goto out; | |
3259 | } | |
3260 | ||
3261 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3262 | if (err) | |
3263 | goto out; | |
3264 | ||
e35e4d28 | 3265 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
3266 | if (err) |
3267 | goto out; | |
3268 | ||
3269 | #ifdef CONFIG_CFG80211_WEXT | |
3270 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 3271 | #endif |
dbd2fd65 JB |
3272 | } |
3273 | ||
3274 | out: | |
fffd0934 | 3275 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3276 | |
41ade00f JB |
3277 | return err; |
3278 | } | |
3279 | ||
3280 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
3281 | { | |
4c476991 | 3282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 3283 | int err; |
4c476991 | 3284 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 3285 | struct key_parse key; |
e31b8213 | 3286 | const u8 *mac_addr = NULL; |
41ade00f | 3287 | |
b9454e83 JB |
3288 | err = nl80211_parse_key(info, &key); |
3289 | if (err) | |
3290 | return err; | |
41ade00f | 3291 | |
b9454e83 | 3292 | if (!key.p.key) |
41ade00f JB |
3293 | return -EINVAL; |
3294 | ||
41ade00f JB |
3295 | if (info->attrs[NL80211_ATTR_MAC]) |
3296 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3297 | ||
e31b8213 JB |
3298 | if (key.type == -1) { |
3299 | if (mac_addr) | |
3300 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3301 | else | |
3302 | key.type = NL80211_KEYTYPE_GROUP; | |
3303 | } | |
3304 | ||
3305 | /* for now */ | |
3306 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3307 | key.type != NL80211_KEYTYPE_GROUP) | |
3308 | return -EINVAL; | |
3309 | ||
4c476991 JB |
3310 | if (!rdev->ops->add_key) |
3311 | return -EOPNOTSUPP; | |
25e47c18 | 3312 | |
e31b8213 JB |
3313 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3314 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3315 | mac_addr)) | |
4c476991 | 3316 | return -EINVAL; |
41ade00f | 3317 | |
fffd0934 JB |
3318 | wdev_lock(dev->ieee80211_ptr); |
3319 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3320 | if (!err) | |
e35e4d28 HG |
3321 | err = rdev_add_key(rdev, dev, key.idx, |
3322 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3323 | mac_addr, &key.p); | |
fffd0934 | 3324 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3325 | |
41ade00f JB |
3326 | return err; |
3327 | } | |
3328 | ||
3329 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3330 | { | |
4c476991 | 3331 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3332 | int err; |
4c476991 | 3333 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3334 | u8 *mac_addr = NULL; |
b9454e83 | 3335 | struct key_parse key; |
41ade00f | 3336 | |
b9454e83 JB |
3337 | err = nl80211_parse_key(info, &key); |
3338 | if (err) | |
3339 | return err; | |
41ade00f JB |
3340 | |
3341 | if (info->attrs[NL80211_ATTR_MAC]) | |
3342 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3343 | ||
e31b8213 JB |
3344 | if (key.type == -1) { |
3345 | if (mac_addr) | |
3346 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3347 | else | |
3348 | key.type = NL80211_KEYTYPE_GROUP; | |
3349 | } | |
3350 | ||
3351 | /* for now */ | |
3352 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3353 | key.type != NL80211_KEYTYPE_GROUP) | |
3354 | return -EINVAL; | |
3355 | ||
4c476991 JB |
3356 | if (!rdev->ops->del_key) |
3357 | return -EOPNOTSUPP; | |
41ade00f | 3358 | |
fffd0934 JB |
3359 | wdev_lock(dev->ieee80211_ptr); |
3360 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 3361 | |
0fa7b391 | 3362 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
3363 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3364 | err = -ENOENT; | |
3365 | ||
fffd0934 | 3366 | if (!err) |
e35e4d28 HG |
3367 | err = rdev_del_key(rdev, dev, key.idx, |
3368 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3369 | mac_addr); | |
41ade00f | 3370 | |
3d23e349 | 3371 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3372 | if (!err) { |
b9454e83 | 3373 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3374 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3375 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3376 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3377 | } | |
3378 | #endif | |
fffd0934 | 3379 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3380 | |
41ade00f JB |
3381 | return err; |
3382 | } | |
3383 | ||
77765eaf VT |
3384 | /* This function returns an error or the number of nested attributes */ |
3385 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3386 | { | |
3387 | struct nlattr *attr; | |
3388 | int n_entries = 0, tmp; | |
3389 | ||
3390 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3391 | if (nla_len(attr) != ETH_ALEN) | |
3392 | return -EINVAL; | |
3393 | ||
3394 | n_entries++; | |
3395 | } | |
3396 | ||
3397 | return n_entries; | |
3398 | } | |
3399 | ||
3400 | /* | |
3401 | * This function parses ACL information and allocates memory for ACL data. | |
3402 | * On successful return, the calling function is responsible to free the | |
3403 | * ACL buffer returned by this function. | |
3404 | */ | |
3405 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3406 | struct genl_info *info) | |
3407 | { | |
3408 | enum nl80211_acl_policy acl_policy; | |
3409 | struct nlattr *attr; | |
3410 | struct cfg80211_acl_data *acl; | |
3411 | int i = 0, n_entries, tmp; | |
3412 | ||
3413 | if (!wiphy->max_acl_mac_addrs) | |
3414 | return ERR_PTR(-EOPNOTSUPP); | |
3415 | ||
3416 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3417 | return ERR_PTR(-EINVAL); | |
3418 | ||
3419 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3420 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3421 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3422 | return ERR_PTR(-EINVAL); | |
3423 | ||
3424 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3425 | return ERR_PTR(-EINVAL); | |
3426 | ||
3427 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3428 | if (n_entries < 0) | |
3429 | return ERR_PTR(n_entries); | |
3430 | ||
3431 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3432 | return ERR_PTR(-ENOTSUPP); | |
3433 | ||
3434 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3435 | GFP_KERNEL); | |
3436 | if (!acl) | |
3437 | return ERR_PTR(-ENOMEM); | |
3438 | ||
3439 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3440 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3441 | i++; | |
3442 | } | |
3443 | ||
3444 | acl->n_acl_entries = n_entries; | |
3445 | acl->acl_policy = acl_policy; | |
3446 | ||
3447 | return acl; | |
3448 | } | |
3449 | ||
3450 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3451 | { | |
3452 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3453 | struct net_device *dev = info->user_ptr[1]; | |
3454 | struct cfg80211_acl_data *acl; | |
3455 | int err; | |
3456 | ||
3457 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3458 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3459 | return -EOPNOTSUPP; | |
3460 | ||
3461 | if (!dev->ieee80211_ptr->beacon_interval) | |
3462 | return -EINVAL; | |
3463 | ||
3464 | acl = parse_acl_data(&rdev->wiphy, info); | |
3465 | if (IS_ERR(acl)) | |
3466 | return PTR_ERR(acl); | |
3467 | ||
3468 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3469 | ||
3470 | kfree(acl); | |
3471 | ||
3472 | return err; | |
3473 | } | |
3474 | ||
a7c7fbff PK |
3475 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
3476 | u8 *rates, u8 rates_len) | |
3477 | { | |
3478 | u8 i; | |
3479 | u32 mask = 0; | |
3480 | ||
3481 | for (i = 0; i < rates_len; i++) { | |
3482 | int rate = (rates[i] & 0x7f) * 5; | |
3483 | int ridx; | |
3484 | ||
3485 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
3486 | struct ieee80211_rate *srate = | |
3487 | &sband->bitrates[ridx]; | |
3488 | if (rate == srate->bitrate) { | |
3489 | mask |= 1 << ridx; | |
3490 | break; | |
3491 | } | |
3492 | } | |
3493 | if (ridx == sband->n_bitrates) | |
3494 | return 0; /* rate not found */ | |
3495 | } | |
3496 | ||
3497 | return mask; | |
3498 | } | |
3499 | ||
3500 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, | |
3501 | u8 *rates, u8 rates_len, | |
3502 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
3503 | { | |
3504 | u8 i; | |
3505 | ||
3506 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
3507 | ||
3508 | for (i = 0; i < rates_len; i++) { | |
3509 | int ridx, rbit; | |
3510 | ||
3511 | ridx = rates[i] / 8; | |
3512 | rbit = BIT(rates[i] % 8); | |
3513 | ||
3514 | /* check validity */ | |
3515 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) | |
3516 | return false; | |
3517 | ||
3518 | /* check availability */ | |
434a30a6 | 3519 | ridx = array_index_nospec(ridx, IEEE80211_HT_MCS_MASK_LEN); |
a7c7fbff PK |
3520 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) |
3521 | mcs[ridx] |= rbit; | |
3522 | else | |
3523 | return false; | |
3524 | } | |
3525 | ||
3526 | return true; | |
3527 | } | |
3528 | ||
3529 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) | |
3530 | { | |
3531 | u16 mcs_mask = 0; | |
3532 | ||
3533 | switch (vht_mcs_map) { | |
3534 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
3535 | break; | |
3536 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
3537 | mcs_mask = 0x00FF; | |
3538 | break; | |
3539 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
3540 | mcs_mask = 0x01FF; | |
3541 | break; | |
3542 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
3543 | mcs_mask = 0x03FF; | |
3544 | break; | |
3545 | default: | |
3546 | break; | |
3547 | } | |
3548 | ||
3549 | return mcs_mask; | |
3550 | } | |
3551 | ||
3552 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
3553 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
3554 | { | |
3555 | u8 nss; | |
3556 | ||
3557 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
3558 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
3559 | vht_mcs_map >>= 2; | |
3560 | } | |
3561 | } | |
3562 | ||
3563 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
3564 | struct nl80211_txrate_vht *txrate, | |
3565 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
3566 | { | |
3567 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
3568 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
3569 | u8 i; | |
3570 | ||
3571 | if (!sband->vht_cap.vht_supported) | |
3572 | return false; | |
3573 | ||
3574 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
3575 | ||
3576 | /* Build vht_mcs_mask from VHT capabilities */ | |
3577 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
3578 | ||
3579 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
3580 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
3581 | mcs[i] = txrate->mcs[i]; | |
3582 | else | |
3583 | return false; | |
3584 | } | |
3585 | ||
3586 | return true; | |
3587 | } | |
3588 | ||
3589 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { | |
3590 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, | |
3591 | .len = NL80211_MAX_SUPP_RATES }, | |
3592 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, | |
3593 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
3594 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, | |
3595 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, | |
3596 | }; | |
3597 | ||
3598 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, | |
3599 | struct cfg80211_bitrate_mask *mask) | |
3600 | { | |
3601 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
3602 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3603 | int rem, i; | |
3604 | struct nlattr *tx_rates; | |
3605 | struct ieee80211_supported_band *sband; | |
3606 | u16 vht_tx_mcs_map; | |
3607 | ||
3608 | memset(mask, 0, sizeof(*mask)); | |
3609 | /* Default to all rates enabled */ | |
3610 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
3611 | sband = rdev->wiphy.bands[i]; | |
3612 | ||
3613 | if (!sband) | |
3614 | continue; | |
3615 | ||
3616 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; | |
3617 | memcpy(mask->control[i].ht_mcs, | |
3618 | sband->ht_cap.mcs.rx_mask, | |
3619 | sizeof(mask->control[i].ht_mcs)); | |
3620 | ||
3621 | if (!sband->vht_cap.vht_supported) | |
3622 | continue; | |
3623 | ||
3624 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
3625 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); | |
3626 | } | |
3627 | ||
3628 | /* if no rates are given set it back to the defaults */ | |
3629 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
3630 | goto out; | |
3631 | ||
3632 | /* The nested attribute uses enum nl80211_band as the index. This maps | |
3633 | * directly to the enum nl80211_band values used in cfg80211. | |
3634 | */ | |
3635 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); | |
3636 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { | |
3637 | enum nl80211_band band = nla_type(tx_rates); | |
3638 | int err; | |
3639 | ||
3640 | if (band < 0 || band >= NUM_NL80211_BANDS) | |
3641 | return -EINVAL; | |
3642 | sband = rdev->wiphy.bands[band]; | |
3643 | if (sband == NULL) | |
3644 | return -EINVAL; | |
bfe2c7b1 | 3645 | err = nla_parse_nested(tb, NL80211_TXRATE_MAX, tx_rates, |
fe52145f | 3646 | nl80211_txattr_policy, info->extack); |
a7c7fbff PK |
3647 | if (err) |
3648 | return err; | |
3649 | if (tb[NL80211_TXRATE_LEGACY]) { | |
3650 | mask->control[band].legacy = rateset_to_mask( | |
3651 | sband, | |
3652 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
3653 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
3654 | if ((mask->control[band].legacy == 0) && | |
3655 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
3656 | return -EINVAL; | |
3657 | } | |
3658 | if (tb[NL80211_TXRATE_HT]) { | |
3659 | if (!ht_rateset_to_mask( | |
3660 | sband, | |
3661 | nla_data(tb[NL80211_TXRATE_HT]), | |
3662 | nla_len(tb[NL80211_TXRATE_HT]), | |
3663 | mask->control[band].ht_mcs)) | |
3664 | return -EINVAL; | |
3665 | } | |
3666 | if (tb[NL80211_TXRATE_VHT]) { | |
3667 | if (!vht_set_mcs_mask( | |
3668 | sband, | |
3669 | nla_data(tb[NL80211_TXRATE_VHT]), | |
3670 | mask->control[band].vht_mcs)) | |
3671 | return -EINVAL; | |
3672 | } | |
3673 | if (tb[NL80211_TXRATE_GI]) { | |
3674 | mask->control[band].gi = | |
3675 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
3676 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
3677 | return -EINVAL; | |
3678 | } | |
3679 | ||
3680 | if (mask->control[band].legacy == 0) { | |
3681 | /* don't allow empty legacy rates if HT or VHT | |
3682 | * are not even supported. | |
3683 | */ | |
3684 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
3685 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
3686 | return -EINVAL; | |
3687 | ||
3688 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
3689 | if (mask->control[band].ht_mcs[i]) | |
3690 | goto out; | |
3691 | ||
3692 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
3693 | if (mask->control[band].vht_mcs[i]) | |
3694 | goto out; | |
3695 | ||
3696 | /* legacy and mcs rates may not be both empty */ | |
3697 | return -EINVAL; | |
3698 | } | |
3699 | } | |
3700 | ||
3701 | out: | |
3702 | return 0; | |
3703 | } | |
3704 | ||
8564e382 JB |
3705 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
3706 | enum nl80211_band band, | |
3707 | struct cfg80211_bitrate_mask *beacon_rate) | |
a7c7fbff | 3708 | { |
8564e382 JB |
3709 | u32 count_ht, count_vht, i; |
3710 | u32 rate = beacon_rate->control[band].legacy; | |
a7c7fbff PK |
3711 | |
3712 | /* Allow only one rate */ | |
3713 | if (hweight32(rate) > 1) | |
3714 | return -EINVAL; | |
3715 | ||
3716 | count_ht = 0; | |
3717 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
8564e382 | 3718 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
a7c7fbff | 3719 | return -EINVAL; |
8564e382 | 3720 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
a7c7fbff PK |
3721 | count_ht++; |
3722 | if (count_ht > 1) | |
3723 | return -EINVAL; | |
3724 | } | |
3725 | if (count_ht && rate) | |
3726 | return -EINVAL; | |
3727 | } | |
3728 | ||
3729 | count_vht = 0; | |
3730 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8564e382 | 3731 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
a7c7fbff | 3732 | return -EINVAL; |
8564e382 | 3733 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
a7c7fbff PK |
3734 | count_vht++; |
3735 | if (count_vht > 1) | |
3736 | return -EINVAL; | |
3737 | } | |
3738 | if (count_vht && rate) | |
3739 | return -EINVAL; | |
3740 | } | |
3741 | ||
3742 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) | |
3743 | return -EINVAL; | |
3744 | ||
8564e382 JB |
3745 | if (rate && |
3746 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3747 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) | |
3748 | return -EINVAL; | |
3749 | if (count_ht && | |
3750 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3751 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) | |
3752 | return -EINVAL; | |
3753 | if (count_vht && | |
3754 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3755 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) | |
3756 | return -EINVAL; | |
3757 | ||
a7c7fbff PK |
3758 | return 0; |
3759 | } | |
3760 | ||
a1193be8 | 3761 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3762 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3763 | { |
8860020e | 3764 | bool haveinfo = false; |
ed1b6cc7 | 3765 | |
a1193be8 SW |
3766 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3767 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3768 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3769 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3770 | return -EINVAL; |
3771 | ||
8860020e | 3772 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3773 | |
a1193be8 SW |
3774 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3775 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3776 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3777 | if (!bcn->head_len) |
3778 | return -EINVAL; | |
3779 | haveinfo = true; | |
ed1b6cc7 JB |
3780 | } |
3781 | ||
a1193be8 SW |
3782 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3783 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3784 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3785 | haveinfo = true; |
ed1b6cc7 JB |
3786 | } |
3787 | ||
4c476991 JB |
3788 | if (!haveinfo) |
3789 | return -EINVAL; | |
3b85875a | 3790 | |
a1193be8 SW |
3791 | if (attrs[NL80211_ATTR_IE]) { |
3792 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3793 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3794 | } |
3795 | ||
a1193be8 | 3796 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3797 | bcn->proberesp_ies = |
a1193be8 | 3798 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3799 | bcn->proberesp_ies_len = |
a1193be8 | 3800 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3801 | } |
3802 | ||
a1193be8 | 3803 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3804 | bcn->assocresp_ies = |
a1193be8 | 3805 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3806 | bcn->assocresp_ies_len = |
a1193be8 | 3807 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3808 | } |
3809 | ||
a1193be8 SW |
3810 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3811 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3812 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3813 | } |
3814 | ||
8860020e JB |
3815 | return 0; |
3816 | } | |
3817 | ||
66cd794e JB |
3818 | static void nl80211_check_ap_rate_selectors(struct cfg80211_ap_settings *params, |
3819 | const u8 *rates) | |
3820 | { | |
3821 | int i; | |
3822 | ||
3823 | if (!rates) | |
3824 | return; | |
3825 | ||
3826 | for (i = 0; i < rates[1]; i++) { | |
3827 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_HT_PHY) | |
3828 | params->ht_required = true; | |
3829 | if (rates[2 + i] == BSS_MEMBERSHIP_SELECTOR_VHT_PHY) | |
3830 | params->vht_required = true; | |
3831 | } | |
3832 | } | |
3833 | ||
3834 | /* | |
3835 | * Since the nl80211 API didn't include, from the beginning, attributes about | |
3836 | * HT/VHT requirements/capabilities, we parse them out of the IEs for the | |
3837 | * benefit of drivers that rebuild IEs in the firmware. | |
3838 | */ | |
3839 | static void nl80211_calculate_ap_params(struct cfg80211_ap_settings *params) | |
3840 | { | |
3841 | const struct cfg80211_beacon_data *bcn = ¶ms->beacon; | |
ba83bfb1 IM |
3842 | size_t ies_len = bcn->tail_len; |
3843 | const u8 *ies = bcn->tail; | |
66cd794e JB |
3844 | const u8 *rates; |
3845 | const u8 *cap; | |
3846 | ||
3847 | rates = cfg80211_find_ie(WLAN_EID_SUPP_RATES, ies, ies_len); | |
3848 | nl80211_check_ap_rate_selectors(params, rates); | |
3849 | ||
3850 | rates = cfg80211_find_ie(WLAN_EID_EXT_SUPP_RATES, ies, ies_len); | |
3851 | nl80211_check_ap_rate_selectors(params, rates); | |
3852 | ||
3853 | cap = cfg80211_find_ie(WLAN_EID_HT_CAPABILITY, ies, ies_len); | |
3854 | if (cap && cap[1] >= sizeof(*params->ht_cap)) | |
3855 | params->ht_cap = (void *)(cap + 2); | |
3856 | cap = cfg80211_find_ie(WLAN_EID_VHT_CAPABILITY, ies, ies_len); | |
3857 | if (cap && cap[1] >= sizeof(*params->vht_cap)) | |
3858 | params->vht_cap = (void *)(cap + 2); | |
3859 | } | |
3860 | ||
46c1dd0c FF |
3861 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3862 | struct cfg80211_ap_settings *params) | |
3863 | { | |
3864 | struct wireless_dev *wdev; | |
3865 | bool ret = false; | |
3866 | ||
53873f13 | 3867 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
46c1dd0c FF |
3868 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3869 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3870 | continue; | |
3871 | ||
683b6d3b | 3872 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3873 | continue; |
3874 | ||
683b6d3b | 3875 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3876 | ret = true; |
3877 | break; | |
3878 | } | |
3879 | ||
46c1dd0c FF |
3880 | return ret; |
3881 | } | |
3882 | ||
e39e5b5e JM |
3883 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3884 | enum nl80211_auth_type auth_type, | |
3885 | enum nl80211_commands cmd) | |
3886 | { | |
3887 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3888 | return false; | |
3889 | ||
3890 | switch (cmd) { | |
3891 | case NL80211_CMD_AUTHENTICATE: | |
3892 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3893 | auth_type == NL80211_AUTHTYPE_SAE) | |
3894 | return false; | |
63181060 JM |
3895 | if (!wiphy_ext_feature_isset(&rdev->wiphy, |
3896 | NL80211_EXT_FEATURE_FILS_STA) && | |
3897 | (auth_type == NL80211_AUTHTYPE_FILS_SK || | |
3898 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
3899 | auth_type == NL80211_AUTHTYPE_FILS_PK)) | |
3900 | return false; | |
e39e5b5e JM |
3901 | return true; |
3902 | case NL80211_CMD_CONNECT: | |
a3caf744 VK |
3903 | /* SAE not supported yet */ |
3904 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3905 | return false; | |
3906 | /* FILS with SK PFS or PK not supported yet */ | |
3907 | if (auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
3908 | auth_type == NL80211_AUTHTYPE_FILS_PK) | |
3909 | return false; | |
3910 | if (!wiphy_ext_feature_isset( | |
3911 | &rdev->wiphy, | |
3912 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && | |
3913 | auth_type == NL80211_AUTHTYPE_FILS_SK) | |
3914 | return false; | |
3915 | return true; | |
e39e5b5e JM |
3916 | case NL80211_CMD_START_AP: |
3917 | /* SAE not supported yet */ | |
3918 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3919 | return false; | |
63181060 JM |
3920 | /* FILS not supported yet */ |
3921 | if (auth_type == NL80211_AUTHTYPE_FILS_SK || | |
3922 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
3923 | auth_type == NL80211_AUTHTYPE_FILS_PK) | |
3924 | return false; | |
e39e5b5e JM |
3925 | return true; |
3926 | default: | |
3927 | return false; | |
3928 | } | |
3929 | } | |
3930 | ||
8860020e JB |
3931 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3932 | { | |
3933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3934 | struct net_device *dev = info->user_ptr[1]; | |
3935 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3936 | struct cfg80211_ap_settings params; | |
3937 | int err; | |
3938 | ||
3939 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3940 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3941 | return -EOPNOTSUPP; | |
3942 | ||
3943 | if (!rdev->ops->start_ap) | |
3944 | return -EOPNOTSUPP; | |
3945 | ||
3946 | if (wdev->beacon_interval) | |
3947 | return -EALREADY; | |
3948 | ||
3949 | memset(¶ms, 0, sizeof(params)); | |
3950 | ||
3951 | /* these are required for START_AP */ | |
3952 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3953 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3954 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3955 | return -EINVAL; | |
3956 | ||
a1193be8 | 3957 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3958 | if (err) |
3959 | return err; | |
3960 | ||
3961 | params.beacon_interval = | |
3962 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3963 | params.dtim_period = | |
3964 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3965 | ||
0c317a02 PK |
3966 | err = cfg80211_validate_beacon_int(rdev, dev->ieee80211_ptr->iftype, |
3967 | params.beacon_interval); | |
8860020e JB |
3968 | if (err) |
3969 | return err; | |
3970 | ||
3971 | /* | |
3972 | * In theory, some of these attributes should be required here | |
3973 | * but since they were not used when the command was originally | |
3974 | * added, keep them optional for old user space programs to let | |
3975 | * them continue to work with drivers that do not need the | |
3976 | * additional information -- drivers must check! | |
3977 | */ | |
3978 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3979 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3980 | params.ssid_len = | |
3981 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3982 | if (params.ssid_len == 0 || | |
3983 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3984 | return -EINVAL; | |
3985 | } | |
3986 | ||
3987 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3988 | params.hidden_ssid = nla_get_u32( | |
3989 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3990 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3991 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3992 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3993 | return -EINVAL; | |
3994 | } | |
3995 | ||
3996 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3997 | ||
3998 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3999 | params.auth_type = nla_get_u32( | |
4000 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
4001 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
4002 | NL80211_CMD_START_AP)) | |
8860020e JB |
4003 | return -EINVAL; |
4004 | } else | |
4005 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
4006 | ||
4007 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
4008 | NL80211_MAX_NR_CIPHER_SUITES); | |
4009 | if (err) | |
4010 | return err; | |
4011 | ||
1b658f11 VT |
4012 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
4013 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
4014 | return -EOPNOTSUPP; | |
4015 | params.inactivity_timeout = nla_get_u16( | |
4016 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
4017 | } | |
4018 | ||
53cabad7 JB |
4019 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4020 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4021 | return -EINVAL; | |
4022 | params.p2p_ctwindow = | |
4023 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4024 | if (params.p2p_ctwindow > 127) | |
4025 | return -EINVAL; | |
4026 | if (params.p2p_ctwindow != 0 && | |
4027 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4028 | return -EINVAL; | |
4029 | } | |
4030 | ||
4031 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4032 | u8 tmp; | |
4033 | ||
4034 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4035 | return -EINVAL; | |
4036 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4037 | if (tmp > 1) | |
4038 | return -EINVAL; | |
4039 | params.p2p_opp_ps = tmp; | |
4040 | if (params.p2p_opp_ps != 0 && | |
4041 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4042 | return -EINVAL; | |
4043 | } | |
4044 | ||
aa430da4 | 4045 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
4046 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
4047 | if (err) | |
4048 | return err; | |
4049 | } else if (wdev->preset_chandef.chan) { | |
4050 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 4051 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
4052 | return -EINVAL; |
4053 | ||
923b352f AN |
4054 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
4055 | wdev->iftype)) | |
aa430da4 JB |
4056 | return -EINVAL; |
4057 | ||
a7c7fbff PK |
4058 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
4059 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); | |
4060 | if (err) | |
4061 | return err; | |
4062 | ||
8564e382 JB |
4063 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
4064 | ¶ms.beacon_rate); | |
a7c7fbff PK |
4065 | if (err) |
4066 | return err; | |
4067 | } | |
4068 | ||
18998c38 EP |
4069 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
4070 | params.smps_mode = | |
4071 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
4072 | switch (params.smps_mode) { | |
4073 | case NL80211_SMPS_OFF: | |
4074 | break; | |
4075 | case NL80211_SMPS_STATIC: | |
4076 | if (!(rdev->wiphy.features & | |
4077 | NL80211_FEATURE_STATIC_SMPS)) | |
4078 | return -EINVAL; | |
4079 | break; | |
4080 | case NL80211_SMPS_DYNAMIC: | |
4081 | if (!(rdev->wiphy.features & | |
4082 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
4083 | return -EINVAL; | |
4084 | break; | |
4085 | default: | |
4086 | return -EINVAL; | |
4087 | } | |
4088 | } else { | |
4089 | params.smps_mode = NL80211_SMPS_OFF; | |
4090 | } | |
4091 | ||
6e8ef842 PK |
4092 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
4093 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) | |
4094 | return -EOPNOTSUPP; | |
4095 | ||
4baf6bea OO |
4096 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
4097 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
4098 | if (IS_ERR(params.acl)) | |
4099 | return PTR_ERR(params.acl); | |
4100 | } | |
4101 | ||
66cd794e JB |
4102 | nl80211_calculate_ap_params(¶ms); |
4103 | ||
c56589ed | 4104 | wdev_lock(wdev); |
e35e4d28 | 4105 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 4106 | if (!err) { |
683b6d3b | 4107 | wdev->preset_chandef = params.chandef; |
8860020e | 4108 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 4109 | wdev->chandef = params.chandef; |
06e191e2 AQ |
4110 | wdev->ssid_len = params.ssid_len; |
4111 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 4112 | } |
c56589ed | 4113 | wdev_unlock(wdev); |
77765eaf VT |
4114 | |
4115 | kfree(params.acl); | |
4116 | ||
56d1893d | 4117 | return err; |
ed1b6cc7 JB |
4118 | } |
4119 | ||
8860020e JB |
4120 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
4121 | { | |
4122 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4123 | struct net_device *dev = info->user_ptr[1]; | |
4124 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
4125 | struct cfg80211_beacon_data params; | |
4126 | int err; | |
4127 | ||
4128 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4129 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4130 | return -EOPNOTSUPP; | |
4131 | ||
4132 | if (!rdev->ops->change_beacon) | |
4133 | return -EOPNOTSUPP; | |
4134 | ||
4135 | if (!wdev->beacon_interval) | |
4136 | return -EINVAL; | |
4137 | ||
a1193be8 | 4138 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
4139 | if (err) |
4140 | return err; | |
4141 | ||
c56589ed SW |
4142 | wdev_lock(wdev); |
4143 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
4144 | wdev_unlock(wdev); | |
4145 | ||
4146 | return err; | |
8860020e JB |
4147 | } |
4148 | ||
4149 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 4150 | { |
4c476991 JB |
4151 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4152 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 4153 | |
7c8d5e03 | 4154 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
4155 | } |
4156 | ||
5727ef1b JB |
4157 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
4158 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
4159 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
4160 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 4161 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 4162 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 4163 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
4164 | }; |
4165 | ||
eccb8e8f | 4166 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 4167 | enum nl80211_iftype iftype, |
eccb8e8f | 4168 | struct station_parameters *params) |
5727ef1b JB |
4169 | { |
4170 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 4171 | struct nlattr *nla; |
5727ef1b JB |
4172 | int flag; |
4173 | ||
eccb8e8f JB |
4174 | /* |
4175 | * Try parsing the new attribute first so userspace | |
4176 | * can specify both for older kernels. | |
4177 | */ | |
4178 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
4179 | if (nla) { | |
4180 | struct nl80211_sta_flag_update *sta_flags; | |
4181 | ||
4182 | sta_flags = nla_data(nla); | |
4183 | params->sta_flags_mask = sta_flags->mask; | |
4184 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 4185 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
4186 | if ((params->sta_flags_mask | |
4187 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
4188 | return -EINVAL; | |
4189 | return 0; | |
4190 | } | |
4191 | ||
4192 | /* if present, parse the old attribute */ | |
5727ef1b | 4193 | |
eccb8e8f | 4194 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
4195 | if (!nla) |
4196 | return 0; | |
4197 | ||
fceb6435 | 4198 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, nla, |
fe52145f | 4199 | sta_flags_policy, info->extack)) |
5727ef1b JB |
4200 | return -EINVAL; |
4201 | ||
bdd3ae3d JB |
4202 | /* |
4203 | * Only allow certain flags for interface types so that | |
4204 | * other attributes are silently ignored. Remember that | |
4205 | * this is backward compatibility code with old userspace | |
4206 | * and shouldn't be hit in other cases anyway. | |
4207 | */ | |
4208 | switch (iftype) { | |
4209 | case NL80211_IFTYPE_AP: | |
4210 | case NL80211_IFTYPE_AP_VLAN: | |
4211 | case NL80211_IFTYPE_P2P_GO: | |
4212 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4213 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4214 | BIT(NL80211_STA_FLAG_WME) | | |
4215 | BIT(NL80211_STA_FLAG_MFP); | |
4216 | break; | |
4217 | case NL80211_IFTYPE_P2P_CLIENT: | |
4218 | case NL80211_IFTYPE_STATION: | |
4219 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4220 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4221 | break; | |
4222 | case NL80211_IFTYPE_MESH_POINT: | |
4223 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4224 | BIT(NL80211_STA_FLAG_MFP) | | |
4225 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4226 | default: | |
4227 | return -EINVAL; | |
4228 | } | |
5727ef1b | 4229 | |
3383b5a6 JB |
4230 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
4231 | if (flags[flag]) { | |
eccb8e8f | 4232 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 4233 | |
3383b5a6 JB |
4234 | /* no longer support new API additions in old API */ |
4235 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
4236 | return -EINVAL; | |
4237 | } | |
4238 | } | |
4239 | ||
5727ef1b JB |
4240 | return 0; |
4241 | } | |
4242 | ||
c8dcfd8a FF |
4243 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
4244 | int attr) | |
4245 | { | |
4246 | struct nlattr *rate; | |
8eb41c8d VK |
4247 | u32 bitrate; |
4248 | u16 bitrate_compat; | |
bbf67e45 | 4249 | enum nl80211_rate_info rate_flg; |
c8dcfd8a FF |
4250 | |
4251 | rate = nla_nest_start(msg, attr); | |
4252 | if (!rate) | |
db9c64cf | 4253 | return false; |
c8dcfd8a FF |
4254 | |
4255 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
4256 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
4257 | /* report 16-bit bitrate only if we can */ |
4258 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
4259 | if (bitrate > 0 && |
4260 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
4261 | return false; | |
4262 | if (bitrate_compat > 0 && | |
4263 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
4264 | return false; | |
4265 | ||
b51f3bee JB |
4266 | switch (info->bw) { |
4267 | case RATE_INFO_BW_5: | |
4268 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
4269 | break; | |
4270 | case RATE_INFO_BW_10: | |
4271 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
4272 | break; | |
4273 | default: | |
4274 | WARN_ON(1); | |
4275 | /* fall through */ | |
4276 | case RATE_INFO_BW_20: | |
4277 | rate_flg = 0; | |
4278 | break; | |
4279 | case RATE_INFO_BW_40: | |
4280 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
4281 | break; | |
4282 | case RATE_INFO_BW_80: | |
4283 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
4284 | break; | |
4285 | case RATE_INFO_BW_160: | |
4286 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
4287 | break; | |
4288 | } | |
4289 | ||
4290 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
4291 | return false; | |
4292 | ||
db9c64cf JB |
4293 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
4294 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
4295 | return false; | |
db9c64cf JB |
4296 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4297 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4298 | return false; | |
4299 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
4300 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
4301 | return false; | |
4302 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
4303 | return false; | |
db9c64cf JB |
4304 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4305 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4306 | return false; | |
4307 | } | |
c8dcfd8a FF |
4308 | |
4309 | nla_nest_end(msg, rate); | |
4310 | return true; | |
c8dcfd8a FF |
4311 | } |
4312 | ||
119363c7 FF |
4313 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
4314 | int id) | |
4315 | { | |
4316 | void *attr; | |
4317 | int i = 0; | |
4318 | ||
4319 | if (!mask) | |
4320 | return true; | |
4321 | ||
4322 | attr = nla_nest_start(msg, id); | |
4323 | if (!attr) | |
4324 | return false; | |
4325 | ||
4326 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
4327 | if (!(mask & BIT(i))) | |
4328 | continue; | |
4329 | ||
4330 | if (nla_put_u8(msg, i, signal[i])) | |
4331 | return false; | |
4332 | } | |
4333 | ||
4334 | nla_nest_end(msg, attr); | |
4335 | ||
4336 | return true; | |
4337 | } | |
4338 | ||
cf5ead82 JB |
4339 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
4340 | u32 seq, int flags, | |
66266b3a JL |
4341 | struct cfg80211_registered_device *rdev, |
4342 | struct net_device *dev, | |
98b62183 | 4343 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
4344 | { |
4345 | void *hdr; | |
f4263c98 | 4346 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 4347 | |
cf5ead82 | 4348 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
4349 | if (!hdr) |
4350 | return -1; | |
4351 | ||
9360ffd1 DM |
4352 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4353 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
4354 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
4355 | goto nla_put_failure; | |
f5ea9120 | 4356 | |
2ec600d6 LCC |
4357 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
4358 | if (!sinfoattr) | |
fd5b74dc | 4359 | goto nla_put_failure; |
319090bf JB |
4360 | |
4361 | #define PUT_SINFO(attr, memb, type) do { \ | |
d686b920 | 4362 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
739960f1 | 4363 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
319090bf JB |
4364 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
4365 | sinfo->memb)) \ | |
4366 | goto nla_put_failure; \ | |
4367 | } while (0) | |
d686b920 JB |
4368 | #define PUT_SINFO_U64(attr, memb) do { \ |
4369 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ | |
4370 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ | |
4371 | sinfo->memb, NL80211_STA_INFO_PAD)) \ | |
4372 | goto nla_put_failure; \ | |
4373 | } while (0) | |
319090bf JB |
4374 | |
4375 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
4376 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
4377 | ||
4378 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
4379 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 4380 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 4381 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 4382 | goto nla_put_failure; |
319090bf JB |
4383 | |
4384 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
4385 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 4386 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
4387 | (u32)sinfo->tx_bytes)) |
4388 | goto nla_put_failure; | |
319090bf | 4389 | |
d686b920 JB |
4390 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
4391 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); | |
319090bf JB |
4392 | PUT_SINFO(LLID, llid, u16); |
4393 | PUT_SINFO(PLID, plid, u16); | |
4394 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
d686b920 | 4395 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
319090bf | 4396 | |
66266b3a JL |
4397 | switch (rdev->wiphy.signal_type) { |
4398 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
4399 | PUT_SINFO(SIGNAL, signal, u8); |
4400 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
4401 | break; |
4402 | default: | |
4403 | break; | |
4404 | } | |
319090bf | 4405 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
4406 | if (!nl80211_put_signal(msg, sinfo->chains, |
4407 | sinfo->chain_signal, | |
4408 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
4409 | goto nla_put_failure; | |
4410 | } | |
319090bf | 4411 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
4412 | if (!nl80211_put_signal(msg, sinfo->chains, |
4413 | sinfo->chain_signal_avg, | |
4414 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
4415 | goto nla_put_failure; | |
4416 | } | |
319090bf | 4417 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
4418 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
4419 | NL80211_STA_INFO_TX_BITRATE)) | |
4420 | goto nla_put_failure; | |
4421 | } | |
319090bf | 4422 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
4423 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
4424 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 4425 | goto nla_put_failure; |
420e7fab | 4426 | } |
319090bf JB |
4427 | |
4428 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
4429 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
4430 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
4431 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
4432 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
4433 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
4434 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
4435 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
4436 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
4437 | ||
4438 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
4439 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
4440 | if (!bss_param) | |
4441 | goto nla_put_failure; | |
4442 | ||
9360ffd1 DM |
4443 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
4444 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
4445 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
4446 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
4447 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
4448 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
4449 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
4450 | sinfo->bss_param.dtim_period) || | |
4451 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
4452 | sinfo->bss_param.beacon_interval)) | |
4453 | goto nla_put_failure; | |
f4263c98 PS |
4454 | |
4455 | nla_nest_end(msg, bss_param); | |
4456 | } | |
319090bf | 4457 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
4458 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
4459 | sizeof(struct nl80211_sta_flag_update), | |
4460 | &sinfo->sta_flags)) | |
4461 | goto nla_put_failure; | |
319090bf | 4462 | |
d686b920 JB |
4463 | PUT_SINFO_U64(T_OFFSET, t_offset); |
4464 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); | |
4465 | PUT_SINFO_U64(BEACON_RX, rx_beacon); | |
a76b1942 | 4466 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
319090bf JB |
4467 | |
4468 | #undef PUT_SINFO | |
d686b920 | 4469 | #undef PUT_SINFO_U64 |
6de39808 JB |
4470 | |
4471 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
4472 | struct nlattr *tidsattr; | |
4473 | int tid; | |
4474 | ||
4475 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
4476 | if (!tidsattr) | |
4477 | goto nla_put_failure; | |
4478 | ||
4479 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
4480 | struct cfg80211_tid_stats *tidstats; | |
4481 | struct nlattr *tidattr; | |
4482 | ||
4483 | tidstats = &sinfo->pertid[tid]; | |
4484 | ||
4485 | if (!tidstats->filled) | |
4486 | continue; | |
4487 | ||
4488 | tidattr = nla_nest_start(msg, tid + 1); | |
4489 | if (!tidattr) | |
4490 | goto nla_put_failure; | |
4491 | ||
d686b920 | 4492 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
6de39808 | 4493 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
d686b920 JB |
4494 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
4495 | tidstats->memb, NL80211_TID_STATS_PAD)) \ | |
6de39808 JB |
4496 | goto nla_put_failure; \ |
4497 | } while (0) | |
4498 | ||
d686b920 JB |
4499 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
4500 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); | |
4501 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); | |
4502 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); | |
6de39808 | 4503 | |
d686b920 | 4504 | #undef PUT_TIDVAL_U64 |
6de39808 JB |
4505 | nla_nest_end(msg, tidattr); |
4506 | } | |
4507 | ||
4508 | nla_nest_end(msg, tidsattr); | |
4509 | } | |
4510 | ||
2ec600d6 | 4511 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 4512 | |
319090bf | 4513 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
4514 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
4515 | sinfo->assoc_req_ies)) | |
4516 | goto nla_put_failure; | |
50d3dfb7 | 4517 | |
053c095a JB |
4518 | genlmsg_end(msg, hdr); |
4519 | return 0; | |
fd5b74dc JB |
4520 | |
4521 | nla_put_failure: | |
bc3ed28c TG |
4522 | genlmsg_cancel(msg, hdr); |
4523 | return -EMSGSIZE; | |
fd5b74dc JB |
4524 | } |
4525 | ||
2ec600d6 | 4526 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 4527 | struct netlink_callback *cb) |
2ec600d6 | 4528 | { |
2ec600d6 | 4529 | struct station_info sinfo; |
1b8ec87a | 4530 | struct cfg80211_registered_device *rdev; |
97990a06 | 4531 | struct wireless_dev *wdev; |
2ec600d6 | 4532 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 4533 | int sta_idx = cb->args[2]; |
2ec600d6 | 4534 | int err; |
2ec600d6 | 4535 | |
ea90e0dc | 4536 | rtnl_lock(); |
1b8ec87a | 4537 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 | 4538 | if (err) |
ea90e0dc | 4539 | goto out_err; |
bba95fef | 4540 | |
97990a06 JB |
4541 | if (!wdev->netdev) { |
4542 | err = -EINVAL; | |
4543 | goto out_err; | |
4544 | } | |
4545 | ||
1b8ec87a | 4546 | if (!rdev->ops->dump_station) { |
eec60b03 | 4547 | err = -EOPNOTSUPP; |
bba95fef JB |
4548 | goto out_err; |
4549 | } | |
4550 | ||
bba95fef | 4551 | while (1) { |
f612cedf | 4552 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 4553 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 4554 | mac_addr, &sinfo); |
bba95fef JB |
4555 | if (err == -ENOENT) |
4556 | break; | |
4557 | if (err) | |
3b85875a | 4558 | goto out_err; |
bba95fef | 4559 | |
cf5ead82 | 4560 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 4561 | NETLINK_CB(cb->skb).portid, |
bba95fef | 4562 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 4563 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
4564 | &sinfo) < 0) |
4565 | goto out; | |
4566 | ||
4567 | sta_idx++; | |
4568 | } | |
4569 | ||
bba95fef | 4570 | out: |
97990a06 | 4571 | cb->args[2] = sta_idx; |
bba95fef | 4572 | err = skb->len; |
bba95fef | 4573 | out_err: |
ea90e0dc | 4574 | rtnl_unlock(); |
bba95fef JB |
4575 | |
4576 | return err; | |
2ec600d6 | 4577 | } |
fd5b74dc | 4578 | |
5727ef1b JB |
4579 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
4580 | { | |
4c476991 JB |
4581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4582 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 4583 | struct station_info sinfo; |
fd5b74dc JB |
4584 | struct sk_buff *msg; |
4585 | u8 *mac_addr = NULL; | |
4c476991 | 4586 | int err; |
fd5b74dc | 4587 | |
2ec600d6 | 4588 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
4589 | |
4590 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4591 | return -EINVAL; | |
4592 | ||
4593 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4594 | ||
4c476991 JB |
4595 | if (!rdev->ops->get_station) |
4596 | return -EOPNOTSUPP; | |
3b85875a | 4597 | |
e35e4d28 | 4598 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 4599 | if (err) |
4c476991 | 4600 | return err; |
2ec600d6 | 4601 | |
fd2120ca | 4602 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 4603 | if (!msg) |
4c476991 | 4604 | return -ENOMEM; |
fd5b74dc | 4605 | |
cf5ead82 JB |
4606 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
4607 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 4608 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
4609 | nlmsg_free(msg); |
4610 | return -ENOBUFS; | |
4611 | } | |
3b85875a | 4612 | |
4c476991 | 4613 | return genlmsg_reply(msg, info); |
5727ef1b JB |
4614 | } |
4615 | ||
77ee7c89 JB |
4616 | int cfg80211_check_station_change(struct wiphy *wiphy, |
4617 | struct station_parameters *params, | |
4618 | enum cfg80211_station_type statype) | |
4619 | { | |
e4208427 AB |
4620 | if (params->listen_interval != -1 && |
4621 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 | 4622 | return -EINVAL; |
e4208427 | 4623 | |
17b94247 AB |
4624 | if (params->support_p2p_ps != -1 && |
4625 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
4626 | return -EINVAL; | |
4627 | ||
c72e1140 | 4628 | if (params->aid && |
e4208427 AB |
4629 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
4630 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 JB |
4631 | return -EINVAL; |
4632 | ||
4633 | /* When you run into this, adjust the code below for the new flag */ | |
4634 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4635 | ||
4636 | switch (statype) { | |
eef941e6 TP |
4637 | case CFG80211_STA_MESH_PEER_KERNEL: |
4638 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
4639 | /* |
4640 | * No ignoring the TDLS flag here -- the userspace mesh | |
4641 | * code doesn't have the bug of including TDLS in the | |
4642 | * mask everywhere. | |
4643 | */ | |
4644 | if (params->sta_flags_mask & | |
4645 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4646 | BIT(NL80211_STA_FLAG_MFP) | | |
4647 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4648 | return -EINVAL; | |
4649 | break; | |
4650 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4651 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4652 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4653 | return -EINVAL; | |
4654 | /* ignore since it can't change */ | |
4655 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4656 | break; | |
4657 | default: | |
4658 | /* disallow mesh-specific things */ | |
4659 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
4660 | return -EINVAL; | |
4661 | if (params->local_pm) | |
4662 | return -EINVAL; | |
4663 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
4664 | return -EINVAL; | |
4665 | } | |
4666 | ||
4667 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
4668 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
4669 | /* TDLS can't be set, ... */ | |
4670 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4671 | return -EINVAL; | |
4672 | /* | |
4673 | * ... but don't bother the driver with it. This works around | |
4674 | * a hostapd/wpa_supplicant issue -- it always includes the | |
4675 | * TLDS_PEER flag in the mask even for AP mode. | |
4676 | */ | |
4677 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4678 | } | |
4679 | ||
47edb11b AB |
4680 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
4681 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4682 | /* reject other things that can't change */ |
4683 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
4684 | return -EINVAL; | |
4685 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4686 | return -EINVAL; | |
4687 | if (params->supported_rates) | |
4688 | return -EINVAL; | |
4689 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4690 | return -EINVAL; | |
4691 | } | |
4692 | ||
47edb11b AB |
4693 | if (statype != CFG80211_STA_AP_CLIENT && |
4694 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4695 | if (params->vlan) |
4696 | return -EINVAL; | |
4697 | } | |
4698 | ||
4699 | switch (statype) { | |
4700 | case CFG80211_STA_AP_MLME_CLIENT: | |
4701 | /* Use this only for authorizing/unauthorizing a station */ | |
4702 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4703 | return -EOPNOTSUPP; | |
4704 | break; | |
4705 | case CFG80211_STA_AP_CLIENT: | |
47edb11b | 4706 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
77ee7c89 JB |
4707 | /* accept only the listed bits */ |
4708 | if (params->sta_flags_mask & | |
4709 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4710 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4711 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4712 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4713 | BIT(NL80211_STA_FLAG_WME) | | |
4714 | BIT(NL80211_STA_FLAG_MFP))) | |
4715 | return -EINVAL; | |
4716 | ||
4717 | /* but authenticated/associated only if driver handles it */ | |
4718 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4719 | params->sta_flags_mask & | |
4720 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4721 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4722 | return -EINVAL; | |
4723 | break; | |
4724 | case CFG80211_STA_IBSS: | |
4725 | case CFG80211_STA_AP_STA: | |
4726 | /* reject any changes other than AUTHORIZED */ | |
4727 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4728 | return -EINVAL; | |
4729 | break; | |
4730 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4731 | /* reject any changes other than AUTHORIZED or WME */ | |
4732 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4733 | BIT(NL80211_STA_FLAG_WME))) | |
4734 | return -EINVAL; | |
4735 | /* force (at least) rates when authorizing */ | |
4736 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4737 | !params->supported_rates) | |
4738 | return -EINVAL; | |
4739 | break; | |
4740 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4741 | /* reject any changes */ | |
4742 | return -EINVAL; | |
eef941e6 | 4743 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4744 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4745 | return -EINVAL; | |
4746 | break; | |
eef941e6 | 4747 | case CFG80211_STA_MESH_PEER_USER: |
42925040 CYY |
4748 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
4749 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | |
77ee7c89 JB |
4750 | return -EINVAL; |
4751 | break; | |
4752 | } | |
4753 | ||
06f7c88c BL |
4754 | /* |
4755 | * Older kernel versions ignored this attribute entirely, so don't | |
4756 | * reject attempts to update it but mark it as unused instead so the | |
4757 | * driver won't look at the data. | |
4758 | */ | |
4759 | if (statype != CFG80211_STA_AP_CLIENT_UNASSOC && | |
4760 | statype != CFG80211_STA_TDLS_PEER_SETUP) | |
4761 | params->opmode_notif_used = false; | |
4762 | ||
77ee7c89 JB |
4763 | return 0; |
4764 | } | |
4765 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4766 | ||
5727ef1b | 4767 | /* |
c258d2de | 4768 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4769 | */ |
80b99899 JB |
4770 | static struct net_device *get_vlan(struct genl_info *info, |
4771 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4772 | { |
463d0183 | 4773 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4774 | struct net_device *v; |
4775 | int ret; | |
4776 | ||
4777 | if (!vlanattr) | |
4778 | return NULL; | |
4779 | ||
4780 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4781 | if (!v) | |
4782 | return ERR_PTR(-ENODEV); | |
4783 | ||
4784 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4785 | ret = -EINVAL; | |
4786 | goto error; | |
5727ef1b | 4787 | } |
80b99899 | 4788 | |
77ee7c89 JB |
4789 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4790 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4791 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4792 | ret = -EINVAL; | |
4793 | goto error; | |
4794 | } | |
4795 | ||
80b99899 JB |
4796 | if (!netif_running(v)) { |
4797 | ret = -ENETDOWN; | |
4798 | goto error; | |
4799 | } | |
4800 | ||
4801 | return v; | |
4802 | error: | |
4803 | dev_put(v); | |
4804 | return ERR_PTR(ret); | |
5727ef1b JB |
4805 | } |
4806 | ||
94e860f1 JB |
4807 | static const struct nla_policy |
4808 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4809 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4810 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4811 | }; | |
4812 | ||
ff276691 JB |
4813 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4814 | struct station_parameters *params) | |
df881293 | 4815 | { |
df881293 JM |
4816 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4817 | struct nlattr *nla; | |
4818 | int err; | |
4819 | ||
df881293 JM |
4820 | /* parse WME attributes if present */ |
4821 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4822 | return 0; | |
4823 | ||
4824 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4825 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
fe52145f | 4826 | nl80211_sta_wme_policy, info->extack); |
df881293 JM |
4827 | if (err) |
4828 | return err; | |
4829 | ||
4830 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4831 | params->uapsd_queues = nla_get_u8( | |
4832 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4833 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4834 | return -EINVAL; | |
4835 | ||
4836 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4837 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4838 | ||
4839 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4840 | return -EINVAL; | |
4841 | ||
4842 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4843 | ||
4844 | return 0; | |
4845 | } | |
4846 | ||
c01fc9ad SD |
4847 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4848 | struct station_parameters *params) | |
4849 | { | |
4850 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4851 | params->supported_channels = | |
4852 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4853 | params->supported_channels_len = | |
4854 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4855 | /* | |
4856 | * Need to include at least one (first channel, number of | |
4857 | * channels) tuple for each subband, and must have proper | |
4858 | * tuples for the rest of the data as well. | |
4859 | */ | |
4860 | if (params->supported_channels_len < 2) | |
4861 | return -EINVAL; | |
4862 | if (params->supported_channels_len % 2) | |
4863 | return -EINVAL; | |
4864 | } | |
4865 | ||
4866 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4867 | params->supported_oper_classes = | |
4868 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4869 | params->supported_oper_classes_len = | |
4870 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4871 | /* | |
4872 | * The value of the Length field of the Supported Operating | |
4873 | * Classes element is between 2 and 253. | |
4874 | */ | |
4875 | if (params->supported_oper_classes_len < 2 || | |
4876 | params->supported_oper_classes_len > 253) | |
4877 | return -EINVAL; | |
4878 | } | |
4879 | return 0; | |
4880 | } | |
4881 | ||
ff276691 JB |
4882 | static int nl80211_set_station_tdls(struct genl_info *info, |
4883 | struct station_parameters *params) | |
4884 | { | |
c01fc9ad | 4885 | int err; |
ff276691 | 4886 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4887 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4888 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4889 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4890 | params->ht_capa = | |
4891 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4892 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4893 | params->vht_capa = | |
4894 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4895 | ||
c01fc9ad SD |
4896 | err = nl80211_parse_sta_channel_info(info, params); |
4897 | if (err) | |
4898 | return err; | |
4899 | ||
ff276691 JB |
4900 | return nl80211_parse_sta_wme(info, params); |
4901 | } | |
4902 | ||
5727ef1b JB |
4903 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4904 | { | |
4c476991 | 4905 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4906 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4907 | struct station_parameters params; |
77ee7c89 JB |
4908 | u8 *mac_addr; |
4909 | int err; | |
5727ef1b JB |
4910 | |
4911 | memset(¶ms, 0, sizeof(params)); | |
4912 | ||
77ee7c89 JB |
4913 | if (!rdev->ops->change_station) |
4914 | return -EOPNOTSUPP; | |
4915 | ||
e4208427 AB |
4916 | /* |
4917 | * AID and listen_interval properties can be set only for unassociated | |
4918 | * station. Include these parameters here and will check them in | |
4919 | * cfg80211_check_station_change(). | |
4920 | */ | |
a9bc31e4 AB |
4921 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4922 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
e4208427 AB |
4923 | |
4924 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
4925 | params.listen_interval = | |
4926 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
4927 | else | |
4928 | params.listen_interval = -1; | |
5727ef1b | 4929 | |
17b94247 AB |
4930 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4931 | u8 tmp; | |
4932 | ||
4933 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4934 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4935 | return -EINVAL; | |
4936 | ||
4937 | params.support_p2p_ps = tmp; | |
4938 | } else { | |
4939 | params.support_p2p_ps = -1; | |
4940 | } | |
4941 | ||
5727ef1b JB |
4942 | if (!info->attrs[NL80211_ATTR_MAC]) |
4943 | return -EINVAL; | |
4944 | ||
4945 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4946 | ||
4947 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4948 | params.supported_rates = | |
4949 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4950 | params.supported_rates_len = | |
4951 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4952 | } | |
4953 | ||
9d62a986 JM |
4954 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4955 | params.capability = | |
4956 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4957 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4958 | } | |
4959 | ||
4960 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4961 | params.ext_capab = | |
4962 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4963 | params.ext_capab_len = | |
4964 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4965 | } | |
4966 | ||
bdd3ae3d | 4967 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4968 | return -EINVAL; |
4969 | ||
f8bacc21 | 4970 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4971 | params.plink_action = |
f8bacc21 JB |
4972 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4973 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4974 | return -EINVAL; | |
4975 | } | |
2ec600d6 | 4976 | |
f8bacc21 | 4977 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4978 | params.plink_state = |
f8bacc21 JB |
4979 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4980 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4981 | return -EINVAL; | |
7d27a0ba MH |
4982 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
4983 | params.peer_aid = nla_get_u16( | |
4984 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); | |
4985 | if (params.peer_aid > IEEE80211_MAX_AID) | |
4986 | return -EINVAL; | |
4987 | } | |
f8bacc21 JB |
4988 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
4989 | } | |
9c3990aa | 4990 | |
3b1c5a53 MP |
4991 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4992 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4993 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4994 | ||
4995 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4996 | pm > NL80211_MESH_POWER_MAX) | |
4997 | return -EINVAL; | |
4998 | ||
4999 | params.local_pm = pm; | |
5000 | } | |
5001 | ||
06f7c88c BL |
5002 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
5003 | params.opmode_notif_used = true; | |
5004 | params.opmode_notif = | |
5005 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
5006 | } | |
5007 | ||
77ee7c89 JB |
5008 | /* Include parameters for TDLS peer (will check later) */ |
5009 | err = nl80211_set_station_tdls(info, ¶ms); | |
5010 | if (err) | |
5011 | return err; | |
5012 | ||
5013 | params.vlan = get_vlan(info, rdev); | |
5014 | if (IS_ERR(params.vlan)) | |
5015 | return PTR_ERR(params.vlan); | |
5016 | ||
a97f4424 JB |
5017 | switch (dev->ieee80211_ptr->iftype) { |
5018 | case NL80211_IFTYPE_AP: | |
5019 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 5020 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 5021 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 5022 | case NL80211_IFTYPE_STATION: |
267335d6 | 5023 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 5024 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
5025 | break; |
5026 | default: | |
77ee7c89 JB |
5027 | err = -EOPNOTSUPP; |
5028 | goto out_put_vlan; | |
034d655e JB |
5029 | } |
5030 | ||
77ee7c89 | 5031 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 5032 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 5033 | |
77ee7c89 | 5034 | out_put_vlan: |
5727ef1b JB |
5035 | if (params.vlan) |
5036 | dev_put(params.vlan); | |
3b85875a | 5037 | |
5727ef1b JB |
5038 | return err; |
5039 | } | |
5040 | ||
5041 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
5042 | { | |
4c476991 | 5043 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 5044 | int err; |
4c476991 | 5045 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
5046 | struct station_parameters params; |
5047 | u8 *mac_addr = NULL; | |
bda95eb1 JB |
5048 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
5049 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
5727ef1b JB |
5050 | |
5051 | memset(¶ms, 0, sizeof(params)); | |
5052 | ||
984c311b JB |
5053 | if (!rdev->ops->add_station) |
5054 | return -EOPNOTSUPP; | |
5055 | ||
5727ef1b JB |
5056 | if (!info->attrs[NL80211_ATTR_MAC]) |
5057 | return -EINVAL; | |
5058 | ||
5727ef1b JB |
5059 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
5060 | return -EINVAL; | |
5061 | ||
5062 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
5063 | return -EINVAL; | |
5064 | ||
5e4b6f56 JM |
5065 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
5066 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
5067 | return -EINVAL; |
5068 | ||
5727ef1b JB |
5069 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5070 | params.supported_rates = | |
5071 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
5072 | params.supported_rates_len = | |
5073 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
5074 | params.listen_interval = | |
5075 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 5076 | |
17b94247 AB |
5077 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
5078 | u8 tmp; | |
5079 | ||
5080 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
5081 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
5082 | return -EINVAL; | |
5083 | ||
5084 | params.support_p2p_ps = tmp; | |
5085 | } else { | |
5086 | /* | |
5087 | * if not specified, assume it's supported for P2P GO interface, | |
5088 | * and is NOT supported for AP interface | |
5089 | */ | |
5090 | params.support_p2p_ps = | |
5091 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; | |
5092 | } | |
5093 | ||
3d124ea2 | 5094 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 5095 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
5096 | else |
5097 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
5098 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
5099 | return -EINVAL; | |
51b50fbe | 5100 | |
9d62a986 JM |
5101 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
5102 | params.capability = | |
5103 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
5104 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
5105 | } | |
5106 | ||
5107 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
5108 | params.ext_capab = | |
5109 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
5110 | params.ext_capab_len = | |
5111 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
5112 | } | |
5113 | ||
36aedc90 JM |
5114 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
5115 | params.ht_capa = | |
5116 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 5117 | |
f461be3e MP |
5118 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
5119 | params.vht_capa = | |
5120 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
5121 | ||
60f4a7b1 MK |
5122 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
5123 | params.opmode_notif_used = true; | |
5124 | params.opmode_notif = | |
5125 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
5126 | } | |
5127 | ||
f8bacc21 | 5128 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 5129 | params.plink_action = |
f8bacc21 JB |
5130 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
5131 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
5132 | return -EINVAL; | |
5133 | } | |
96b78dff | 5134 | |
c01fc9ad SD |
5135 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
5136 | if (err) | |
5137 | return err; | |
5138 | ||
ff276691 JB |
5139 | err = nl80211_parse_sta_wme(info, ¶ms); |
5140 | if (err) | |
5141 | return err; | |
bdd90d5e | 5142 | |
bdd3ae3d | 5143 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
5144 | return -EINVAL; |
5145 | ||
496fcc29 JB |
5146 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
5147 | * as userspace might just pass through the capabilities from the IEs | |
5148 | * directly, rather than enforcing this restriction and returning an | |
5149 | * error in this case. | |
5150 | */ | |
5151 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
5152 | params.ht_capa = NULL; | |
5153 | params.vht_capa = NULL; | |
5154 | } | |
5155 | ||
77ee7c89 JB |
5156 | /* When you run into this, adjust the code below for the new flag */ |
5157 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
5158 | ||
bdd90d5e JB |
5159 | switch (dev->ieee80211_ptr->iftype) { |
5160 | case NL80211_IFTYPE_AP: | |
5161 | case NL80211_IFTYPE_AP_VLAN: | |
5162 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
5163 | /* ignore WME attributes if iface/sta is not capable */ |
5164 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
5165 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
5166 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 5167 | |
bdd90d5e | 5168 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
5169 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
5170 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 5171 | return -EINVAL; |
bdd90d5e JB |
5172 | /* but don't bother the driver with it */ |
5173 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 5174 | |
d582cffb JB |
5175 | /* allow authenticated/associated only if driver handles it */ |
5176 | if (!(rdev->wiphy.features & | |
5177 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
bda95eb1 | 5178 | params.sta_flags_mask & auth_assoc) |
d582cffb JB |
5179 | return -EINVAL; |
5180 | ||
bda95eb1 JB |
5181 | /* Older userspace, or userspace wanting to be compatible with |
5182 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth | |
5183 | * and assoc flags in the mask, but assumes the station will be | |
5184 | * added as associated anyway since this was the required driver | |
5185 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was | |
5186 | * introduced. | |
5187 | * In order to not bother drivers with this quirk in the API | |
5188 | * set the flags in both the mask and set for new stations in | |
5189 | * this case. | |
5190 | */ | |
5191 | if (!(params.sta_flags_mask & auth_assoc)) { | |
5192 | params.sta_flags_mask |= auth_assoc; | |
5193 | params.sta_flags_set |= auth_assoc; | |
5194 | } | |
5195 | ||
bdd90d5e JB |
5196 | /* must be last in here for error handling */ |
5197 | params.vlan = get_vlan(info, rdev); | |
5198 | if (IS_ERR(params.vlan)) | |
5199 | return PTR_ERR(params.vlan); | |
5200 | break; | |
5201 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
5202 | /* ignore uAPSD data */ |
5203 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
5204 | ||
d582cffb JB |
5205 | /* associated is disallowed */ |
5206 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
5207 | return -EINVAL; | |
bdd90d5e | 5208 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
5209 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
5210 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
5211 | return -EINVAL; |
5212 | break; | |
5213 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 5214 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
5215 | /* ignore uAPSD data */ |
5216 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
5217 | ||
77ee7c89 JB |
5218 | /* these are disallowed */ |
5219 | if (params.sta_flags_mask & | |
5220 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
5221 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 5222 | return -EINVAL; |
bdd90d5e JB |
5223 | /* Only TDLS peers can be added */ |
5224 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
5225 | return -EINVAL; | |
5226 | /* Can only add if TDLS ... */ | |
5227 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
5228 | return -EOPNOTSUPP; | |
5229 | /* ... with external setup is supported */ | |
5230 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
5231 | return -EOPNOTSUPP; | |
77ee7c89 JB |
5232 | /* |
5233 | * Older wpa_supplicant versions always mark the TDLS peer | |
5234 | * as authorized, but it shouldn't yet be. | |
5235 | */ | |
5236 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
5237 | break; |
5238 | default: | |
5239 | return -EOPNOTSUPP; | |
c75786c9 EP |
5240 | } |
5241 | ||
bdd90d5e | 5242 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 5243 | |
e35e4d28 | 5244 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 5245 | |
5727ef1b JB |
5246 | if (params.vlan) |
5247 | dev_put(params.vlan); | |
5727ef1b JB |
5248 | return err; |
5249 | } | |
5250 | ||
5251 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
5252 | { | |
4c476991 JB |
5253 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5254 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
5255 | struct station_del_parameters params; |
5256 | ||
5257 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
5258 | |
5259 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 5260 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 5261 | |
e80cf853 | 5262 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 5263 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 5264 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5265 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5266 | return -EINVAL; | |
5727ef1b | 5267 | |
4c476991 JB |
5268 | if (!rdev->ops->del_station) |
5269 | return -EOPNOTSUPP; | |
3b85875a | 5270 | |
98856866 JM |
5271 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
5272 | params.subtype = | |
5273 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
5274 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
5275 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
5276 | return -EINVAL; | |
5277 | } else { | |
5278 | /* Default to Deauthentication frame */ | |
5279 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
5280 | } | |
5281 | ||
5282 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
5283 | params.reason_code = | |
5284 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
5285 | if (params.reason_code == 0) | |
5286 | return -EINVAL; /* 0 is reserved */ | |
5287 | } else { | |
5288 | /* Default to reason code 2 */ | |
5289 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
5290 | } | |
5291 | ||
89c771e5 | 5292 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
5293 | } |
5294 | ||
15e47304 | 5295 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
5296 | int flags, struct net_device *dev, |
5297 | u8 *dst, u8 *next_hop, | |
5298 | struct mpath_info *pinfo) | |
5299 | { | |
5300 | void *hdr; | |
5301 | struct nlattr *pinfoattr; | |
5302 | ||
1ef4c850 | 5303 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
5304 | if (!hdr) |
5305 | return -1; | |
5306 | ||
9360ffd1 DM |
5307 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5308 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
5309 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
5310 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
5311 | goto nla_put_failure; | |
f5ea9120 | 5312 | |
2ec600d6 LCC |
5313 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
5314 | if (!pinfoattr) | |
5315 | goto nla_put_failure; | |
9360ffd1 DM |
5316 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
5317 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
5318 | pinfo->frame_qlen)) | |
5319 | goto nla_put_failure; | |
5320 | if (((pinfo->filled & MPATH_INFO_SN) && | |
5321 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
5322 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
5323 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
5324 | pinfo->metric)) || | |
5325 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
5326 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
5327 | pinfo->exptime)) || | |
5328 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
5329 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
5330 | pinfo->flags)) || | |
5331 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
5332 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
5333 | pinfo->discovery_timeout)) || | |
5334 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
5335 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
5336 | pinfo->discovery_retries))) | |
5337 | goto nla_put_failure; | |
2ec600d6 LCC |
5338 | |
5339 | nla_nest_end(msg, pinfoattr); | |
5340 | ||
053c095a JB |
5341 | genlmsg_end(msg, hdr); |
5342 | return 0; | |
2ec600d6 LCC |
5343 | |
5344 | nla_put_failure: | |
bc3ed28c TG |
5345 | genlmsg_cancel(msg, hdr); |
5346 | return -EMSGSIZE; | |
2ec600d6 LCC |
5347 | } |
5348 | ||
5349 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 5350 | struct netlink_callback *cb) |
2ec600d6 | 5351 | { |
2ec600d6 | 5352 | struct mpath_info pinfo; |
1b8ec87a | 5353 | struct cfg80211_registered_device *rdev; |
97990a06 | 5354 | struct wireless_dev *wdev; |
2ec600d6 LCC |
5355 | u8 dst[ETH_ALEN]; |
5356 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 5357 | int path_idx = cb->args[2]; |
2ec600d6 | 5358 | int err; |
2ec600d6 | 5359 | |
ea90e0dc | 5360 | rtnl_lock(); |
1b8ec87a | 5361 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 | 5362 | if (err) |
ea90e0dc | 5363 | goto out_err; |
bba95fef | 5364 | |
1b8ec87a | 5365 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 5366 | err = -EOPNOTSUPP; |
bba95fef JB |
5367 | goto out_err; |
5368 | } | |
5369 | ||
97990a06 | 5370 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 5371 | err = -EOPNOTSUPP; |
0448b5fc | 5372 | goto out_err; |
eec60b03 JM |
5373 | } |
5374 | ||
bba95fef | 5375 | while (1) { |
1b8ec87a | 5376 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 5377 | next_hop, &pinfo); |
bba95fef | 5378 | if (err == -ENOENT) |
2ec600d6 | 5379 | break; |
bba95fef | 5380 | if (err) |
3b85875a | 5381 | goto out_err; |
2ec600d6 | 5382 | |
15e47304 | 5383 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 5384 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5385 | wdev->netdev, dst, next_hop, |
bba95fef JB |
5386 | &pinfo) < 0) |
5387 | goto out; | |
2ec600d6 | 5388 | |
bba95fef | 5389 | path_idx++; |
2ec600d6 | 5390 | } |
2ec600d6 | 5391 | |
bba95fef | 5392 | out: |
97990a06 | 5393 | cb->args[2] = path_idx; |
bba95fef | 5394 | err = skb->len; |
bba95fef | 5395 | out_err: |
ea90e0dc | 5396 | rtnl_unlock(); |
bba95fef | 5397 | return err; |
2ec600d6 LCC |
5398 | } |
5399 | ||
5400 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
5401 | { | |
4c476991 | 5402 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 5403 | int err; |
4c476991 | 5404 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
5405 | struct mpath_info pinfo; |
5406 | struct sk_buff *msg; | |
5407 | u8 *dst = NULL; | |
5408 | u8 next_hop[ETH_ALEN]; | |
5409 | ||
5410 | memset(&pinfo, 0, sizeof(pinfo)); | |
5411 | ||
5412 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5413 | return -EINVAL; | |
5414 | ||
5415 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5416 | ||
4c476991 JB |
5417 | if (!rdev->ops->get_mpath) |
5418 | return -EOPNOTSUPP; | |
2ec600d6 | 5419 | |
4c476991 JB |
5420 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5421 | return -EOPNOTSUPP; | |
eec60b03 | 5422 | |
e35e4d28 | 5423 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 5424 | if (err) |
4c476991 | 5425 | return err; |
2ec600d6 | 5426 | |
fd2120ca | 5427 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 5428 | if (!msg) |
4c476991 | 5429 | return -ENOMEM; |
2ec600d6 | 5430 | |
15e47304 | 5431 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
5432 | dev, dst, next_hop, &pinfo) < 0) { |
5433 | nlmsg_free(msg); | |
5434 | return -ENOBUFS; | |
5435 | } | |
3b85875a | 5436 | |
4c476991 | 5437 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
5438 | } |
5439 | ||
5440 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
5441 | { | |
4c476991 JB |
5442 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5443 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5444 | u8 *dst = NULL; |
5445 | u8 *next_hop = NULL; | |
5446 | ||
5447 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5448 | return -EINVAL; | |
5449 | ||
5450 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
5451 | return -EINVAL; | |
5452 | ||
5453 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5454 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
5455 | ||
4c476991 JB |
5456 | if (!rdev->ops->change_mpath) |
5457 | return -EOPNOTSUPP; | |
35a8efe1 | 5458 | |
4c476991 JB |
5459 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5460 | return -EOPNOTSUPP; | |
2ec600d6 | 5461 | |
e35e4d28 | 5462 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 5463 | } |
4c476991 | 5464 | |
2ec600d6 LCC |
5465 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
5466 | { | |
4c476991 JB |
5467 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5468 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5469 | u8 *dst = NULL; |
5470 | u8 *next_hop = NULL; | |
5471 | ||
5472 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5473 | return -EINVAL; | |
5474 | ||
5475 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
5476 | return -EINVAL; | |
5477 | ||
5478 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5479 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
5480 | ||
4c476991 JB |
5481 | if (!rdev->ops->add_mpath) |
5482 | return -EOPNOTSUPP; | |
35a8efe1 | 5483 | |
4c476991 JB |
5484 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5485 | return -EOPNOTSUPP; | |
2ec600d6 | 5486 | |
e35e4d28 | 5487 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
5488 | } |
5489 | ||
5490 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
5491 | { | |
4c476991 JB |
5492 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5493 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5494 | u8 *dst = NULL; |
5495 | ||
5496 | if (info->attrs[NL80211_ATTR_MAC]) | |
5497 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5498 | ||
4c476991 JB |
5499 | if (!rdev->ops->del_mpath) |
5500 | return -EOPNOTSUPP; | |
3b85875a | 5501 | |
e35e4d28 | 5502 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
5503 | } |
5504 | ||
66be7d2b HR |
5505 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
5506 | { | |
5507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5508 | int err; | |
5509 | struct net_device *dev = info->user_ptr[1]; | |
5510 | struct mpath_info pinfo; | |
5511 | struct sk_buff *msg; | |
5512 | u8 *dst = NULL; | |
5513 | u8 mpp[ETH_ALEN]; | |
5514 | ||
5515 | memset(&pinfo, 0, sizeof(pinfo)); | |
5516 | ||
5517 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5518 | return -EINVAL; | |
5519 | ||
5520 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5521 | ||
5522 | if (!rdev->ops->get_mpp) | |
5523 | return -EOPNOTSUPP; | |
5524 | ||
5525 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
5526 | return -EOPNOTSUPP; | |
5527 | ||
5528 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
5529 | if (err) | |
5530 | return err; | |
5531 | ||
5532 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5533 | if (!msg) | |
5534 | return -ENOMEM; | |
5535 | ||
5536 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
5537 | dev, dst, mpp, &pinfo) < 0) { | |
5538 | nlmsg_free(msg); | |
5539 | return -ENOBUFS; | |
5540 | } | |
5541 | ||
5542 | return genlmsg_reply(msg, info); | |
5543 | } | |
5544 | ||
5545 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
5546 | struct netlink_callback *cb) | |
5547 | { | |
5548 | struct mpath_info pinfo; | |
5549 | struct cfg80211_registered_device *rdev; | |
5550 | struct wireless_dev *wdev; | |
5551 | u8 dst[ETH_ALEN]; | |
5552 | u8 mpp[ETH_ALEN]; | |
5553 | int path_idx = cb->args[2]; | |
5554 | int err; | |
5555 | ||
ea90e0dc | 5556 | rtnl_lock(); |
66be7d2b HR |
5557 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
5558 | if (err) | |
ea90e0dc | 5559 | goto out_err; |
66be7d2b HR |
5560 | |
5561 | if (!rdev->ops->dump_mpp) { | |
5562 | err = -EOPNOTSUPP; | |
5563 | goto out_err; | |
5564 | } | |
5565 | ||
5566 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
5567 | err = -EOPNOTSUPP; | |
5568 | goto out_err; | |
5569 | } | |
5570 | ||
5571 | while (1) { | |
5572 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
5573 | mpp, &pinfo); | |
5574 | if (err == -ENOENT) | |
5575 | break; | |
5576 | if (err) | |
5577 | goto out_err; | |
5578 | ||
5579 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
5580 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
5581 | wdev->netdev, dst, mpp, | |
5582 | &pinfo) < 0) | |
5583 | goto out; | |
5584 | ||
5585 | path_idx++; | |
5586 | } | |
5587 | ||
5588 | out: | |
5589 | cb->args[2] = path_idx; | |
5590 | err = skb->len; | |
5591 | out_err: | |
ea90e0dc | 5592 | rtnl_unlock(); |
66be7d2b HR |
5593 | return err; |
5594 | } | |
5595 | ||
9f1ba906 JM |
5596 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
5597 | { | |
4c476991 JB |
5598 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5599 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 5600 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 5601 | struct bss_parameters params; |
c56589ed | 5602 | int err; |
9f1ba906 JM |
5603 | |
5604 | memset(¶ms, 0, sizeof(params)); | |
5605 | /* default to not changing parameters */ | |
5606 | params.use_cts_prot = -1; | |
5607 | params.use_short_preamble = -1; | |
5608 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 5609 | params.ap_isolate = -1; |
50b12f59 | 5610 | params.ht_opmode = -1; |
53cabad7 JB |
5611 | params.p2p_ctwindow = -1; |
5612 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
5613 | |
5614 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
5615 | params.use_cts_prot = | |
5616 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
5617 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
5618 | params.use_short_preamble = | |
5619 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
5620 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
5621 | params.use_short_slot_time = | |
5622 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
5623 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
5624 | params.basic_rates = | |
5625 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5626 | params.basic_rates_len = | |
5627 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5628 | } | |
fd8aaaf3 FF |
5629 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
5630 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
5631 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
5632 | params.ht_opmode = | |
5633 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 5634 | |
53cabad7 JB |
5635 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
5636 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5637 | return -EINVAL; | |
5638 | params.p2p_ctwindow = | |
5639 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
5640 | if (params.p2p_ctwindow < 0) | |
5641 | return -EINVAL; | |
5642 | if (params.p2p_ctwindow != 0 && | |
5643 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
5644 | return -EINVAL; | |
5645 | } | |
5646 | ||
5647 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
5648 | u8 tmp; | |
5649 | ||
5650 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5651 | return -EINVAL; | |
5652 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
5653 | if (tmp > 1) | |
5654 | return -EINVAL; | |
5655 | params.p2p_opp_ps = tmp; | |
5656 | if (params.p2p_opp_ps && | |
5657 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
5658 | return -EINVAL; | |
5659 | } | |
5660 | ||
4c476991 JB |
5661 | if (!rdev->ops->change_bss) |
5662 | return -EOPNOTSUPP; | |
9f1ba906 | 5663 | |
074ac8df | 5664 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
5665 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5666 | return -EOPNOTSUPP; | |
3b85875a | 5667 | |
c56589ed SW |
5668 | wdev_lock(wdev); |
5669 | err = rdev_change_bss(rdev, dev, ¶ms); | |
5670 | wdev_unlock(wdev); | |
5671 | ||
5672 | return err; | |
9f1ba906 JM |
5673 | } |
5674 | ||
b2e1b302 LR |
5675 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
5676 | { | |
b2e1b302 | 5677 | char *data = NULL; |
05050753 | 5678 | bool is_indoor; |
57b5ce07 | 5679 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
5680 | u32 owner_nlportid; |
5681 | ||
80778f18 LR |
5682 | /* |
5683 | * You should only get this when cfg80211 hasn't yet initialized | |
5684 | * completely when built-in to the kernel right between the time | |
5685 | * window between nl80211_init() and regulatory_init(), if that is | |
5686 | * even possible. | |
5687 | */ | |
458f4f9e | 5688 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 5689 | return -EINPROGRESS; |
80778f18 | 5690 | |
57b5ce07 LR |
5691 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
5692 | user_reg_hint_type = | |
5693 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
5694 | else | |
5695 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
5696 | ||
5697 | switch (user_reg_hint_type) { | |
5698 | case NL80211_USER_REG_HINT_USER: | |
5699 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
5700 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
5701 | return -EINVAL; | |
5702 | ||
5703 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5704 | return regulatory_hint_user(data, user_reg_hint_type); | |
5705 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
5706 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
5707 | owner_nlportid = info->snd_portid; | |
5708 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
5709 | } else { | |
5710 | owner_nlportid = 0; | |
5711 | is_indoor = true; | |
5712 | } | |
5713 | ||
5714 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
5715 | default: |
5716 | return -EINVAL; | |
5717 | } | |
b2e1b302 LR |
5718 | } |
5719 | ||
1ea4ff3e JB |
5720 | static int nl80211_reload_regdb(struct sk_buff *skb, struct genl_info *info) |
5721 | { | |
5722 | return reg_reload_regdb(); | |
5723 | } | |
5724 | ||
24bdd9f4 | 5725 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 5726 | struct genl_info *info) |
93da9cc1 | 5727 | { |
4c476991 | 5728 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 5729 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
5730 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5731 | struct mesh_config cur_params; | |
5732 | int err = 0; | |
93da9cc1 | 5733 | void *hdr; |
5734 | struct nlattr *pinfoattr; | |
5735 | struct sk_buff *msg; | |
5736 | ||
29cbe68c JB |
5737 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5738 | return -EOPNOTSUPP; | |
5739 | ||
24bdd9f4 | 5740 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5741 | return -EOPNOTSUPP; |
f3f92586 | 5742 | |
29cbe68c JB |
5743 | wdev_lock(wdev); |
5744 | /* If not connected, get default parameters */ | |
5745 | if (!wdev->mesh_id_len) | |
5746 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5747 | else | |
e35e4d28 | 5748 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5749 | wdev_unlock(wdev); |
5750 | ||
93da9cc1 | 5751 | if (err) |
4c476991 | 5752 | return err; |
93da9cc1 | 5753 | |
5754 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5755 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5756 | if (!msg) |
5757 | return -ENOMEM; | |
15e47304 | 5758 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5759 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5760 | if (!hdr) |
efe1cf0c | 5761 | goto out; |
24bdd9f4 | 5762 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5763 | if (!pinfoattr) |
5764 | goto nla_put_failure; | |
9360ffd1 DM |
5765 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5766 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5767 | cur_params.dot11MeshRetryTimeout) || | |
5768 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5769 | cur_params.dot11MeshConfirmTimeout) || | |
5770 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5771 | cur_params.dot11MeshHoldingTimeout) || | |
5772 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5773 | cur_params.dot11MeshMaxPeerLinks) || | |
5774 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5775 | cur_params.dot11MeshMaxRetries) || | |
5776 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5777 | cur_params.dot11MeshTTL) || | |
5778 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5779 | cur_params.element_ttl) || | |
5780 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5781 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5782 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5783 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5784 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5785 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5786 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5787 | cur_params.path_refresh_time) || | |
5788 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5789 | cur_params.min_discovery_timeout) || | |
5790 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5791 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5792 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5793 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5794 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5795 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5796 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5797 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5798 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5799 | cur_params.dot11MeshHWMPRootMode) || | |
5800 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5801 | cur_params.dot11MeshHWMPRannInterval) || | |
5802 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5803 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5804 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5805 | cur_params.dot11MeshForwarding) || | |
335d5349 | 5806 | nla_put_s32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
70c33eaa AN |
5807 | cur_params.rssi_threshold) || |
5808 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5809 | cur_params.ht_opmode) || |
5810 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5811 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5812 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5813 | cur_params.dot11MeshHWMProotInterval) || |
5814 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5815 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5816 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5817 | cur_params.power_mode) || | |
5818 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5819 | cur_params.dot11MeshAwakeWindowDuration) || |
5820 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5821 | cur_params.plink_timeout)) | |
9360ffd1 | 5822 | goto nla_put_failure; |
93da9cc1 | 5823 | nla_nest_end(msg, pinfoattr); |
5824 | genlmsg_end(msg, hdr); | |
4c476991 | 5825 | return genlmsg_reply(msg, info); |
93da9cc1 | 5826 | |
3b85875a | 5827 | nla_put_failure: |
93da9cc1 | 5828 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5829 | out: |
d080e275 | 5830 | nlmsg_free(msg); |
4c476991 | 5831 | return -ENOBUFS; |
93da9cc1 | 5832 | } |
5833 | ||
b54452b0 | 5834 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5835 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5836 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5837 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5838 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5839 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5840 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5841 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5842 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5843 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5844 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5845 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5846 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5847 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5848 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5849 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5850 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5851 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5852 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5853 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5854 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5855 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5856 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5857 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5858 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5859 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5860 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5861 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5862 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5863 | }; |
5864 | ||
c80d545d JC |
5865 | static const struct nla_policy |
5866 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5867 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5868 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5869 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5870 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5871 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5872 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5873 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5874 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5875 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5876 | }; |
5877 | ||
f151d9db AB |
5878 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
5879 | { | |
5880 | u8 val = nla_get_u8(nla); | |
5881 | if (val < min || val > max) | |
5882 | return -EINVAL; | |
5883 | *out = val; | |
5884 | return 0; | |
5885 | } | |
5886 | ||
5887 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) | |
5888 | { | |
5889 | u8 val = nla_get_u8(nla); | |
5890 | if (val < min || val > max) | |
5891 | return -EINVAL; | |
5892 | *out = val; | |
5893 | return 0; | |
5894 | } | |
5895 | ||
5896 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) | |
5897 | { | |
5898 | u16 val = nla_get_u16(nla); | |
5899 | if (val < min || val > max) | |
5900 | return -EINVAL; | |
5901 | *out = val; | |
5902 | return 0; | |
5903 | } | |
5904 | ||
5905 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) | |
5906 | { | |
5907 | u32 val = nla_get_u32(nla); | |
5908 | if (val < min || val > max) | |
5909 | return -EINVAL; | |
5910 | *out = val; | |
5911 | return 0; | |
5912 | } | |
5913 | ||
5914 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) | |
5915 | { | |
5916 | s32 val = nla_get_s32(nla); | |
5917 | if (val < min || val > max) | |
5918 | return -EINVAL; | |
5919 | *out = val; | |
5920 | return 0; | |
5921 | } | |
5922 | ||
ff9a71af JB |
5923 | static int nl80211_check_power_mode(const struct nlattr *nla, |
5924 | enum nl80211_mesh_power_mode min, | |
5925 | enum nl80211_mesh_power_mode max, | |
5926 | enum nl80211_mesh_power_mode *out) | |
5927 | { | |
5928 | u32 val = nla_get_u32(nla); | |
5929 | if (val < min || val > max) | |
5930 | return -EINVAL; | |
5931 | *out = val; | |
5932 | return 0; | |
5933 | } | |
5934 | ||
24bdd9f4 | 5935 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5936 | struct mesh_config *cfg, |
5937 | u32 *mask_out) | |
93da9cc1 | 5938 | { |
93da9cc1 | 5939 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5940 | u32 mask = 0; |
9757235f | 5941 | u16 ht_opmode; |
93da9cc1 | 5942 | |
ea54fba2 MP |
5943 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5944 | do { \ | |
5945 | if (tb[attr]) { \ | |
f151d9db | 5946 | if (fn(tb[attr], min, max, &cfg->param)) \ |
ea54fba2 | 5947 | return -EINVAL; \ |
ea54fba2 MP |
5948 | mask |= (1 << (attr - 1)); \ |
5949 | } \ | |
5950 | } while (0) | |
bd90fdcc | 5951 | |
24bdd9f4 | 5952 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5953 | return -EINVAL; |
5954 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5955 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
fe52145f | 5956 | nl80211_meshconf_params_policy, info->extack)) |
93da9cc1 | 5957 | return -EINVAL; |
5958 | ||
93da9cc1 | 5959 | /* This makes sure that there aren't more than 32 mesh config |
5960 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5961 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5962 | ||
5963 | /* Fill in the params struct */ | |
ea54fba2 | 5964 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea | 5965 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
f151d9db | 5966 | nl80211_check_u16); |
ea54fba2 | 5967 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea | 5968 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
f151d9db | 5969 | nl80211_check_u16); |
ea54fba2 | 5970 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea | 5971 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
f151d9db | 5972 | nl80211_check_u16); |
ea54fba2 | 5973 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea | 5974 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
f151d9db | 5975 | nl80211_check_u16); |
ea54fba2 | 5976 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea | 5977 | mask, NL80211_MESHCONF_MAX_RETRIES, |
f151d9db | 5978 | nl80211_check_u8); |
ea54fba2 | 5979 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
f151d9db | 5980 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
ea54fba2 | 5981 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea | 5982 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
f151d9db | 5983 | nl80211_check_u8); |
ea54fba2 | 5984 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea | 5985 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
f151d9db | 5986 | nl80211_check_bool); |
ea54fba2 MP |
5987 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5988 | 1, 255, mask, | |
a4f606ea | 5989 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
f151d9db | 5990 | nl80211_check_u32); |
ea54fba2 | 5991 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea | 5992 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
f151d9db | 5993 | nl80211_check_u8); |
ea54fba2 | 5994 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea | 5995 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
f151d9db | 5996 | nl80211_check_u32); |
ea54fba2 | 5997 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea | 5998 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
f151d9db | 5999 | nl80211_check_u16); |
ea54fba2 MP |
6000 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
6001 | 1, 65535, mask, | |
a4f606ea | 6002 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
f151d9db | 6003 | nl80211_check_u32); |
93da9cc1 | 6004 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
6005 | 1, 65535, mask, |
6006 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
f151d9db | 6007 | nl80211_check_u16); |
dca7e943 | 6008 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
6009 | 1, 65535, mask, |
6010 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
f151d9db | 6011 | nl80211_check_u16); |
93da9cc1 | 6012 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
6013 | dot11MeshHWMPnetDiameterTraversalTime, |
6014 | 1, 65535, mask, | |
a4f606ea | 6015 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
f151d9db | 6016 | nl80211_check_u16); |
ea54fba2 MP |
6017 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
6018 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
f151d9db | 6019 | nl80211_check_u8); |
ea54fba2 MP |
6020 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
6021 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
f151d9db | 6022 | nl80211_check_u16); |
63c5723b | 6023 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
6024 | dot11MeshGateAnnouncementProtocol, 0, 1, |
6025 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
f151d9db | 6026 | nl80211_check_bool); |
ea54fba2 | 6027 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea | 6028 | mask, NL80211_MESHCONF_FORWARDING, |
f151d9db | 6029 | nl80211_check_bool); |
83374fe9 | 6030 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 6031 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
f151d9db | 6032 | nl80211_check_s32); |
9757235f MH |
6033 | /* |
6034 | * Check HT operation mode based on | |
6035 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. | |
6036 | */ | |
6037 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { | |
6038 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); | |
6039 | ||
6040 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | | |
6041 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | | |
6042 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
6043 | return -EINVAL; | |
6044 | ||
6045 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && | |
6046 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
6047 | return -EINVAL; | |
6048 | ||
6049 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { | |
6050 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: | |
6051 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: | |
6052 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) | |
6053 | return -EINVAL; | |
6054 | break; | |
6055 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: | |
6056 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: | |
6057 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
6058 | return -EINVAL; | |
6059 | break; | |
6060 | } | |
6061 | cfg->ht_opmode = ht_opmode; | |
fd551bac | 6062 | mask |= (1 << (NL80211_MESHCONF_HT_OPMODE - 1)); |
9757235f | 6063 | } |
ac1073a6 | 6064 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
ea54fba2 | 6065 | 1, 65535, mask, |
ac1073a6 | 6066 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
f151d9db | 6067 | nl80211_check_u32); |
ea54fba2 | 6068 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 6069 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
f151d9db | 6070 | nl80211_check_u16); |
728b19e5 | 6071 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
6072 | dot11MeshHWMPconfirmationInterval, |
6073 | 1, 65535, mask, | |
728b19e5 | 6074 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
f151d9db | 6075 | nl80211_check_u16); |
3b1c5a53 MP |
6076 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
6077 | NL80211_MESH_POWER_ACTIVE, | |
6078 | NL80211_MESH_POWER_MAX, | |
6079 | mask, NL80211_MESHCONF_POWER_MODE, | |
ff9a71af | 6080 | nl80211_check_power_mode); |
3b1c5a53 MP |
6081 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
6082 | 0, 65535, mask, | |
f151d9db | 6083 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
31f909a2 | 6084 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
8e7c0538 | 6085 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
f151d9db | 6086 | nl80211_check_u32); |
bd90fdcc JB |
6087 | if (mask_out) |
6088 | *mask_out = mask; | |
c80d545d | 6089 | |
bd90fdcc JB |
6090 | return 0; |
6091 | ||
6092 | #undef FILL_IN_MESH_PARAM_IF_SET | |
6093 | } | |
6094 | ||
c80d545d JC |
6095 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
6096 | struct mesh_setup *setup) | |
6097 | { | |
bb2798d4 | 6098 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
6099 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
6100 | ||
6101 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
6102 | return -EINVAL; | |
6103 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
6104 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
fe52145f | 6105 | nl80211_mesh_setup_params_policy, info->extack)) |
c80d545d JC |
6106 | return -EINVAL; |
6107 | ||
d299a1f2 JC |
6108 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
6109 | setup->sync_method = | |
6110 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
6111 | IEEE80211_SYNC_METHOD_VENDOR : | |
6112 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
6113 | ||
c80d545d JC |
6114 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
6115 | setup->path_sel_proto = | |
6116 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
6117 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
6118 | IEEE80211_PATH_PROTOCOL_HWMP; | |
6119 | ||
6120 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
6121 | setup->path_metric = | |
6122 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
6123 | IEEE80211_PATH_METRIC_VENDOR : | |
6124 | IEEE80211_PATH_METRIC_AIRTIME; | |
6125 | ||
581a8b0f | 6126 | if (tb[NL80211_MESH_SETUP_IE]) { |
c80d545d | 6127 | struct nlattr *ieattr = |
581a8b0f | 6128 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
6129 | if (!is_valid_ie_attr(ieattr)) |
6130 | return -EINVAL; | |
581a8b0f JC |
6131 | setup->ie = nla_data(ieattr); |
6132 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 6133 | } |
bb2798d4 TP |
6134 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
6135 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
6136 | return -EINVAL; | |
6137 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
6138 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
6139 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
6140 | if (setup->is_secure) |
6141 | setup->user_mpm = true; | |
c80d545d | 6142 | |
6e16d90b CT |
6143 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
6144 | if (!setup->user_mpm) | |
6145 | return -EINVAL; | |
6146 | setup->auth_id = | |
6147 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
6148 | } | |
6149 | ||
c80d545d JC |
6150 | return 0; |
6151 | } | |
6152 | ||
24bdd9f4 | 6153 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 6154 | struct genl_info *info) |
bd90fdcc JB |
6155 | { |
6156 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6157 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 6158 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
6159 | struct mesh_config cfg; |
6160 | u32 mask; | |
6161 | int err; | |
6162 | ||
29cbe68c JB |
6163 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
6164 | return -EOPNOTSUPP; | |
6165 | ||
24bdd9f4 | 6166 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
6167 | return -EOPNOTSUPP; |
6168 | ||
24bdd9f4 | 6169 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
6170 | if (err) |
6171 | return err; | |
6172 | ||
29cbe68c JB |
6173 | wdev_lock(wdev); |
6174 | if (!wdev->mesh_id_len) | |
6175 | err = -ENOLINK; | |
6176 | ||
6177 | if (!err) | |
e35e4d28 | 6178 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
6179 | |
6180 | wdev_unlock(wdev); | |
6181 | ||
6182 | return err; | |
93da9cc1 | 6183 | } |
6184 | ||
ad30ca2c AN |
6185 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
6186 | struct sk_buff *msg) | |
f130347c | 6187 | { |
f130347c LR |
6188 | struct nlattr *nl_reg_rules; |
6189 | unsigned int i; | |
f130347c | 6190 | |
458f4f9e JB |
6191 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
6192 | (regdom->dfs_region && | |
6193 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 6194 | goto nla_put_failure; |
458f4f9e | 6195 | |
f130347c LR |
6196 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
6197 | if (!nl_reg_rules) | |
ad30ca2c | 6198 | goto nla_put_failure; |
f130347c | 6199 | |
458f4f9e | 6200 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
6201 | struct nlattr *nl_reg_rule; |
6202 | const struct ieee80211_reg_rule *reg_rule; | |
6203 | const struct ieee80211_freq_range *freq_range; | |
6204 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 6205 | unsigned int max_bandwidth_khz; |
f130347c | 6206 | |
458f4f9e | 6207 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
6208 | freq_range = ®_rule->freq_range; |
6209 | power_rule = ®_rule->power_rule; | |
6210 | ||
6211 | nl_reg_rule = nla_nest_start(msg, i); | |
6212 | if (!nl_reg_rule) | |
ad30ca2c | 6213 | goto nla_put_failure; |
f130347c | 6214 | |
97524820 JD |
6215 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
6216 | if (!max_bandwidth_khz) | |
6217 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
6218 | reg_rule); | |
6219 | ||
9360ffd1 DM |
6220 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
6221 | reg_rule->flags) || | |
6222 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
6223 | freq_range->start_freq_khz) || | |
6224 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
6225 | freq_range->end_freq_khz) || | |
6226 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 6227 | max_bandwidth_khz) || |
9360ffd1 DM |
6228 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
6229 | power_rule->max_antenna_gain) || | |
6230 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
6231 | power_rule->max_eirp) || |
6232 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
6233 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 6234 | goto nla_put_failure; |
f130347c LR |
6235 | |
6236 | nla_nest_end(msg, nl_reg_rule); | |
6237 | } | |
6238 | ||
6239 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
6240 | return 0; |
6241 | ||
6242 | nla_put_failure: | |
6243 | return -EMSGSIZE; | |
6244 | } | |
6245 | ||
6246 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
6247 | { | |
6248 | const struct ieee80211_regdomain *regdom = NULL; | |
6249 | struct cfg80211_registered_device *rdev; | |
6250 | struct wiphy *wiphy = NULL; | |
6251 | struct sk_buff *msg; | |
6252 | void *hdr; | |
6253 | ||
6254 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6255 | if (!msg) | |
6256 | return -ENOBUFS; | |
6257 | ||
6258 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
6259 | NL80211_CMD_GET_REG); | |
6260 | if (!hdr) | |
6261 | goto put_failure; | |
6262 | ||
6263 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
6264 | bool self_managed; |
6265 | ||
ad30ca2c AN |
6266 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
6267 | if (IS_ERR(rdev)) { | |
6268 | nlmsg_free(msg); | |
6269 | return PTR_ERR(rdev); | |
6270 | } | |
6271 | ||
6272 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
6273 | self_managed = wiphy->regulatory_flags & |
6274 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
6275 | regdom = get_wiphy_regdom(wiphy); |
6276 | ||
1bdd716c AN |
6277 | /* a self-managed-reg device must have a private regdom */ |
6278 | if (WARN_ON(!regdom && self_managed)) { | |
6279 | nlmsg_free(msg); | |
6280 | return -EINVAL; | |
6281 | } | |
6282 | ||
ad30ca2c AN |
6283 | if (regdom && |
6284 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6285 | goto nla_put_failure; | |
6286 | } | |
6287 | ||
6288 | if (!wiphy && reg_last_request_cell_base() && | |
6289 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6290 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6291 | goto nla_put_failure; | |
6292 | ||
6293 | rcu_read_lock(); | |
6294 | ||
6295 | if (!regdom) | |
6296 | regdom = rcu_dereference(cfg80211_regdomain); | |
6297 | ||
6298 | if (nl80211_put_regdom(regdom, msg)) | |
6299 | goto nla_put_failure_rcu; | |
6300 | ||
6301 | rcu_read_unlock(); | |
f130347c LR |
6302 | |
6303 | genlmsg_end(msg, hdr); | |
5fe231e8 | 6304 | return genlmsg_reply(msg, info); |
f130347c | 6305 | |
458f4f9e JB |
6306 | nla_put_failure_rcu: |
6307 | rcu_read_unlock(); | |
f130347c LR |
6308 | nla_put_failure: |
6309 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 6310 | put_failure: |
d080e275 | 6311 | nlmsg_free(msg); |
5fe231e8 | 6312 | return -EMSGSIZE; |
f130347c LR |
6313 | } |
6314 | ||
ad30ca2c AN |
6315 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
6316 | u32 seq, int flags, struct wiphy *wiphy, | |
6317 | const struct ieee80211_regdomain *regdom) | |
6318 | { | |
6319 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
6320 | NL80211_CMD_GET_REG); | |
6321 | ||
6322 | if (!hdr) | |
6323 | return -1; | |
6324 | ||
0a833c29 | 6325 | genl_dump_check_consistent(cb, hdr); |
ad30ca2c AN |
6326 | |
6327 | if (nl80211_put_regdom(regdom, msg)) | |
6328 | goto nla_put_failure; | |
6329 | ||
6330 | if (!wiphy && reg_last_request_cell_base() && | |
6331 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6332 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6333 | goto nla_put_failure; | |
6334 | ||
6335 | if (wiphy && | |
6336 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6337 | goto nla_put_failure; | |
6338 | ||
1bdd716c AN |
6339 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
6340 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
6341 | goto nla_put_failure; | |
6342 | ||
053c095a JB |
6343 | genlmsg_end(msg, hdr); |
6344 | return 0; | |
ad30ca2c AN |
6345 | |
6346 | nla_put_failure: | |
6347 | genlmsg_cancel(msg, hdr); | |
6348 | return -EMSGSIZE; | |
6349 | } | |
6350 | ||
6351 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
6352 | struct netlink_callback *cb) | |
6353 | { | |
6354 | const struct ieee80211_regdomain *regdom = NULL; | |
6355 | struct cfg80211_registered_device *rdev; | |
6356 | int err, reg_idx, start = cb->args[2]; | |
6357 | ||
6358 | rtnl_lock(); | |
6359 | ||
6360 | if (cfg80211_regdomain && start == 0) { | |
6361 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6362 | NLM_F_MULTI, NULL, | |
6363 | rtnl_dereference(cfg80211_regdomain)); | |
6364 | if (err < 0) | |
6365 | goto out_err; | |
6366 | } | |
6367 | ||
6368 | /* the global regdom is idx 0 */ | |
6369 | reg_idx = 1; | |
6370 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
6371 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
6372 | if (!regdom) | |
6373 | continue; | |
6374 | ||
6375 | if (++reg_idx <= start) | |
6376 | continue; | |
6377 | ||
6378 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6379 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
6380 | if (err < 0) { | |
6381 | reg_idx--; | |
6382 | break; | |
6383 | } | |
6384 | } | |
6385 | ||
6386 | cb->args[2] = reg_idx; | |
6387 | err = skb->len; | |
6388 | out_err: | |
6389 | rtnl_unlock(); | |
6390 | return err; | |
6391 | } | |
6392 | ||
b6863036 JB |
6393 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
6394 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | |
6395 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
6396 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
6397 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
6398 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
6399 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
6400 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
6401 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, | |
6402 | }; | |
6403 | ||
6404 | static int parse_reg_rule(struct nlattr *tb[], | |
6405 | struct ieee80211_reg_rule *reg_rule) | |
6406 | { | |
6407 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
6408 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
6409 | ||
6410 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
6411 | return -EINVAL; | |
6412 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
6413 | return -EINVAL; | |
6414 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
6415 | return -EINVAL; | |
6416 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
6417 | return -EINVAL; | |
6418 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
6419 | return -EINVAL; | |
6420 | ||
6421 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
6422 | ||
6423 | freq_range->start_freq_khz = | |
6424 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
6425 | freq_range->end_freq_khz = | |
6426 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
6427 | freq_range->max_bandwidth_khz = | |
6428 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
6429 | ||
6430 | power_rule->max_eirp = | |
6431 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
6432 | ||
6433 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
6434 | power_rule->max_antenna_gain = | |
6435 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
6436 | ||
6437 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) | |
6438 | reg_rule->dfs_cac_ms = | |
6439 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
6440 | ||
6441 | return 0; | |
6442 | } | |
6443 | ||
b2e1b302 LR |
6444 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
6445 | { | |
6446 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
6447 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
6448 | char *alpha2; |
6449 | int rem_reg_rules, r; | |
b2e1b302 | 6450 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 6451 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 6452 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
6453 | |
6454 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
6455 | return -EINVAL; | |
6456 | ||
6457 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
6458 | return -EINVAL; | |
6459 | ||
6460 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
6461 | ||
8b60b078 LR |
6462 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
6463 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
6464 | ||
b2e1b302 | 6465 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 6466 | rem_reg_rules) { |
b2e1b302 LR |
6467 | num_rules++; |
6468 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 6469 | return -EINVAL; |
b2e1b302 LR |
6470 | } |
6471 | ||
e438768f LR |
6472 | if (!reg_is_valid_request(alpha2)) |
6473 | return -EINVAL; | |
6474 | ||
b2e1b302 | 6475 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 6476 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
6477 | |
6478 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
6479 | if (!rd) |
6480 | return -ENOMEM; | |
b2e1b302 LR |
6481 | |
6482 | rd->n_reg_rules = num_rules; | |
6483 | rd->alpha2[0] = alpha2[0]; | |
6484 | rd->alpha2[1] = alpha2[1]; | |
6485 | ||
8b60b078 LR |
6486 | /* |
6487 | * Disable DFS master mode if the DFS region was | |
6488 | * not supported or known on this kernel. | |
6489 | */ | |
6490 | if (reg_supported_dfs_region(dfs_region)) | |
6491 | rd->dfs_region = dfs_region; | |
6492 | ||
b2e1b302 | 6493 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 6494 | rem_reg_rules) { |
bfe2c7b1 | 6495 | r = nla_parse_nested(tb, NL80211_REG_RULE_ATTR_MAX, |
fe52145f JB |
6496 | nl_reg_rule, reg_rule_policy, |
6497 | info->extack); | |
ae811e21 JB |
6498 | if (r) |
6499 | goto bad_reg; | |
b2e1b302 LR |
6500 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
6501 | if (r) | |
6502 | goto bad_reg; | |
6503 | ||
6504 | rule_idx++; | |
6505 | ||
d0e18f83 LR |
6506 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
6507 | r = -EINVAL; | |
b2e1b302 | 6508 | goto bad_reg; |
d0e18f83 | 6509 | } |
b2e1b302 LR |
6510 | } |
6511 | ||
06627990 JB |
6512 | /* set_regdom takes ownership of rd */ |
6513 | return set_regdom(rd, REGD_SOURCE_CRDA); | |
d2372b31 | 6514 | bad_reg: |
b2e1b302 | 6515 | kfree(rd); |
d0e18f83 | 6516 | return r; |
b2e1b302 | 6517 | } |
b6863036 | 6518 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
b2e1b302 | 6519 | |
83f5e2cf JB |
6520 | static int validate_scan_freqs(struct nlattr *freqs) |
6521 | { | |
6522 | struct nlattr *attr1, *attr2; | |
6523 | int n_channels = 0, tmp1, tmp2; | |
6524 | ||
d7f13f74 SD |
6525 | nla_for_each_nested(attr1, freqs, tmp1) |
6526 | if (nla_len(attr1) != sizeof(u32)) | |
6527 | return 0; | |
6528 | ||
83f5e2cf JB |
6529 | nla_for_each_nested(attr1, freqs, tmp1) { |
6530 | n_channels++; | |
6531 | /* | |
6532 | * Some hardware has a limited channel list for | |
6533 | * scanning, and it is pretty much nonsensical | |
6534 | * to scan for a channel twice, so disallow that | |
6535 | * and don't require drivers to check that the | |
6536 | * channel list they get isn't longer than what | |
6537 | * they can scan, as long as they can scan all | |
6538 | * the channels they registered at once. | |
6539 | */ | |
6540 | nla_for_each_nested(attr2, freqs, tmp2) | |
6541 | if (attr1 != attr2 && | |
6542 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
6543 | return 0; | |
6544 | } | |
6545 | ||
6546 | return n_channels; | |
6547 | } | |
6548 | ||
57fbcce3 | 6549 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
38de03d2 | 6550 | { |
57fbcce3 | 6551 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
38de03d2 AS |
6552 | } |
6553 | ||
6554 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, | |
6555 | struct cfg80211_bss_selection *bss_select) | |
6556 | { | |
6557 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; | |
6558 | struct nlattr *nest; | |
6559 | int err; | |
6560 | bool found = false; | |
6561 | int i; | |
6562 | ||
6563 | /* only process one nested attribute */ | |
6564 | nest = nla_data(nla); | |
6565 | if (!nla_ok(nest, nla_len(nest))) | |
6566 | return -EINVAL; | |
6567 | ||
bfe2c7b1 | 6568 | err = nla_parse_nested(attr, NL80211_BSS_SELECT_ATTR_MAX, nest, |
fceb6435 | 6569 | nl80211_bss_select_policy, NULL); |
38de03d2 AS |
6570 | if (err) |
6571 | return err; | |
6572 | ||
6573 | /* only one attribute may be given */ | |
6574 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { | |
6575 | if (attr[i]) { | |
6576 | if (found) | |
6577 | return -EINVAL; | |
6578 | found = true; | |
6579 | } | |
6580 | } | |
6581 | ||
6582 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; | |
6583 | ||
6584 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) | |
6585 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; | |
6586 | ||
6587 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { | |
6588 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; | |
6589 | bss_select->param.band_pref = | |
6590 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); | |
6591 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) | |
6592 | return -EINVAL; | |
6593 | } | |
6594 | ||
6595 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { | |
6596 | struct nl80211_bss_select_rssi_adjust *adj_param; | |
6597 | ||
6598 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); | |
6599 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; | |
6600 | bss_select->param.adjust.band = adj_param->band; | |
6601 | bss_select->param.adjust.delta = adj_param->delta; | |
6602 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) | |
6603 | return -EINVAL; | |
6604 | } | |
6605 | ||
6606 | /* user-space did not provide behaviour attribute */ | |
6607 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) | |
6608 | return -EINVAL; | |
6609 | ||
6610 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) | |
6611 | return -EINVAL; | |
6612 | ||
6613 | return 0; | |
6614 | } | |
6615 | ||
ad2b26ab JB |
6616 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
6617 | u8 *mac_addr, u8 *mac_addr_mask) | |
6618 | { | |
6619 | int i; | |
6620 | ||
6621 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
d2beae10 JP |
6622 | eth_zero_addr(mac_addr); |
6623 | eth_zero_addr(mac_addr_mask); | |
ad2b26ab JB |
6624 | mac_addr[0] = 0x2; |
6625 | mac_addr_mask[0] = 0x3; | |
6626 | ||
6627 | return 0; | |
6628 | } | |
6629 | ||
6630 | /* need both or none */ | |
6631 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
6632 | return -EINVAL; | |
6633 | ||
6634 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
6635 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
6636 | ||
6637 | /* don't allow or configure an mcast address */ | |
6638 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
6639 | is_multicast_ether_addr(mac_addr)) | |
6640 | return -EINVAL; | |
6641 | ||
6642 | /* | |
6643 | * allow users to pass a MAC address that has bits set outside | |
6644 | * of the mask, but don't bother drivers with having to deal | |
6645 | * with such bits | |
6646 | */ | |
6647 | for (i = 0; i < ETH_ALEN; i++) | |
6648 | mac_addr[i] &= mac_addr_mask[i]; | |
6649 | ||
6650 | return 0; | |
6651 | } | |
6652 | ||
34373d12 VT |
6653 | static bool cfg80211_off_channel_oper_allowed(struct wireless_dev *wdev) |
6654 | { | |
6655 | ASSERT_WDEV_LOCK(wdev); | |
6656 | ||
6657 | if (!cfg80211_beaconing_iface_active(wdev)) | |
6658 | return true; | |
6659 | ||
6660 | if (!(wdev->chandef.chan->flags & IEEE80211_CHAN_RADAR)) | |
6661 | return true; | |
6662 | ||
6663 | return regulatory_pre_cac_allowed(wdev->wiphy); | |
6664 | } | |
6665 | ||
2d23d073 RZ |
6666 | static int |
6667 | nl80211_check_scan_flags(struct wiphy *wiphy, struct wireless_dev *wdev, | |
6668 | void *request, struct nlattr **attrs, | |
6669 | bool is_sched_scan) | |
6670 | { | |
6671 | u8 *mac_addr, *mac_addr_mask; | |
6672 | u32 *flags; | |
6673 | enum nl80211_feature_flags randomness_flag; | |
6674 | ||
6675 | if (!attrs[NL80211_ATTR_SCAN_FLAGS]) | |
6676 | return 0; | |
6677 | ||
6678 | if (is_sched_scan) { | |
6679 | struct cfg80211_sched_scan_request *req = request; | |
6680 | ||
6681 | randomness_flag = wdev ? | |
6682 | NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR : | |
6683 | NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6684 | flags = &req->flags; | |
6685 | mac_addr = req->mac_addr; | |
6686 | mac_addr_mask = req->mac_addr_mask; | |
6687 | } else { | |
6688 | struct cfg80211_scan_request *req = request; | |
6689 | ||
6690 | randomness_flag = NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR; | |
6691 | flags = &req->flags; | |
6692 | mac_addr = req->mac_addr; | |
6693 | mac_addr_mask = req->mac_addr_mask; | |
6694 | } | |
6695 | ||
6696 | *flags = nla_get_u32(attrs[NL80211_ATTR_SCAN_FLAGS]); | |
6697 | ||
6698 | if ((*flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && | |
6699 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) | |
6700 | return -EOPNOTSUPP; | |
6701 | ||
6702 | if (*flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6703 | int err; | |
6704 | ||
6705 | if (!(wiphy->features & randomness_flag) || | |
6706 | (wdev && wdev->current_bss)) | |
6707 | return -EOPNOTSUPP; | |
6708 | ||
6709 | err = nl80211_parse_random_mac(attrs, mac_addr, mac_addr_mask); | |
6710 | if (err) | |
6711 | return err; | |
6712 | } | |
6713 | ||
6714 | if ((*flags & NL80211_SCAN_FLAG_FILS_MAX_CHANNEL_TIME) && | |
6715 | !wiphy_ext_feature_isset(wiphy, | |
6716 | NL80211_EXT_FEATURE_FILS_MAX_CHANNEL_TIME)) | |
6717 | return -EOPNOTSUPP; | |
6718 | ||
6719 | if ((*flags & NL80211_SCAN_FLAG_ACCEPT_BCAST_PROBE_RESP) && | |
6720 | !wiphy_ext_feature_isset(wiphy, | |
6721 | NL80211_EXT_FEATURE_ACCEPT_BCAST_PROBE_RESP)) | |
6722 | return -EOPNOTSUPP; | |
6723 | ||
6724 | if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION) && | |
6725 | !wiphy_ext_feature_isset(wiphy, | |
6726 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION)) | |
6727 | return -EOPNOTSUPP; | |
6728 | ||
6729 | if ((*flags & NL80211_SCAN_FLAG_OCE_PROBE_REQ_HIGH_TX_RATE) && | |
6730 | !wiphy_ext_feature_isset(wiphy, | |
6731 | NL80211_EXT_FEATURE_OCE_PROBE_REQ_HIGH_TX_RATE)) | |
6732 | return -EOPNOTSUPP; | |
6733 | ||
6734 | return 0; | |
6735 | } | |
6736 | ||
2a519311 JB |
6737 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
6738 | { | |
4c476991 | 6739 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 6740 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 6741 | struct cfg80211_scan_request *request; |
2a519311 JB |
6742 | struct nlattr *attr; |
6743 | struct wiphy *wiphy; | |
83f5e2cf | 6744 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 6745 | size_t ie_len; |
2a519311 | 6746 | |
f4a11bb0 JB |
6747 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6748 | return -EINVAL; | |
6749 | ||
79c97e97 | 6750 | wiphy = &rdev->wiphy; |
2a519311 | 6751 | |
cb3b7d87 AB |
6752 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
6753 | return -EOPNOTSUPP; | |
6754 | ||
4c476991 JB |
6755 | if (!rdev->ops->scan) |
6756 | return -EOPNOTSUPP; | |
2a519311 | 6757 | |
f9d15d16 | 6758 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
6759 | err = -EBUSY; |
6760 | goto unlock; | |
6761 | } | |
2a519311 JB |
6762 | |
6763 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
6764 | n_channels = validate_scan_freqs( |
6765 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
6766 | if (!n_channels) { |
6767 | err = -EINVAL; | |
6768 | goto unlock; | |
6769 | } | |
2a519311 | 6770 | } else { |
bdfbec2d | 6771 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
6772 | } |
6773 | ||
6774 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
6775 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
6776 | n_ssids++; | |
6777 | ||
f9f47529 JB |
6778 | if (n_ssids > wiphy->max_scan_ssids) { |
6779 | err = -EINVAL; | |
6780 | goto unlock; | |
6781 | } | |
2a519311 | 6782 | |
70692ad2 JM |
6783 | if (info->attrs[NL80211_ATTR_IE]) |
6784 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6785 | else | |
6786 | ie_len = 0; | |
6787 | ||
f9f47529 JB |
6788 | if (ie_len > wiphy->max_scan_ie_len) { |
6789 | err = -EINVAL; | |
6790 | goto unlock; | |
6791 | } | |
18a83659 | 6792 | |
2a519311 | 6793 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
6794 | + sizeof(*request->ssids) * n_ssids |
6795 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 6796 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
6797 | if (!request) { |
6798 | err = -ENOMEM; | |
6799 | goto unlock; | |
6800 | } | |
2a519311 | 6801 | |
2a519311 | 6802 | if (n_ssids) |
5ba63533 | 6803 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 6804 | request->n_ssids = n_ssids; |
70692ad2 | 6805 | if (ie_len) { |
13874e4b | 6806 | if (n_ssids) |
70692ad2 JM |
6807 | request->ie = (void *)(request->ssids + n_ssids); |
6808 | else | |
6809 | request->ie = (void *)(request->channels + n_channels); | |
6810 | } | |
2a519311 | 6811 | |
584991dc | 6812 | i = 0; |
2a519311 JB |
6813 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
6814 | /* user specified, bail out if channel not found */ | |
2a519311 | 6815 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
6816 | struct ieee80211_channel *chan; |
6817 | ||
6818 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6819 | ||
6820 | if (!chan) { | |
2a519311 JB |
6821 | err = -EINVAL; |
6822 | goto out_free; | |
6823 | } | |
584991dc JB |
6824 | |
6825 | /* ignore disabled channels */ | |
6826 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6827 | continue; | |
6828 | ||
6829 | request->channels[i] = chan; | |
2a519311 JB |
6830 | i++; |
6831 | } | |
6832 | } else { | |
57fbcce3 | 6833 | enum nl80211_band band; |
34850ab2 | 6834 | |
2a519311 | 6835 | /* all channels */ |
57fbcce3 | 6836 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
2a519311 | 6837 | int j; |
7a087e74 | 6838 | |
2a519311 JB |
6839 | if (!wiphy->bands[band]) |
6840 | continue; | |
6841 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
6842 | struct ieee80211_channel *chan; |
6843 | ||
6844 | chan = &wiphy->bands[band]->channels[j]; | |
6845 | ||
6846 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6847 | continue; | |
6848 | ||
6849 | request->channels[i] = chan; | |
2a519311 JB |
6850 | i++; |
6851 | } | |
6852 | } | |
6853 | } | |
6854 | ||
584991dc JB |
6855 | if (!i) { |
6856 | err = -EINVAL; | |
6857 | goto out_free; | |
6858 | } | |
6859 | ||
6860 | request->n_channels = i; | |
6861 | ||
34373d12 VT |
6862 | wdev_lock(wdev); |
6863 | if (!cfg80211_off_channel_oper_allowed(wdev)) { | |
6864 | struct ieee80211_channel *chan; | |
6865 | ||
6866 | if (request->n_channels != 1) { | |
6867 | wdev_unlock(wdev); | |
6868 | err = -EBUSY; | |
6869 | goto out_free; | |
6870 | } | |
6871 | ||
6872 | chan = request->channels[0]; | |
6873 | if (chan->center_freq != wdev->chandef.chan->center_freq) { | |
6874 | wdev_unlock(wdev); | |
6875 | err = -EBUSY; | |
6876 | goto out_free; | |
6877 | } | |
6878 | } | |
6879 | wdev_unlock(wdev); | |
6880 | ||
2a519311 | 6881 | i = 0; |
13874e4b | 6882 | if (n_ssids) { |
2a519311 | 6883 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 6884 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
6885 | err = -EINVAL; |
6886 | goto out_free; | |
6887 | } | |
57a27e1d | 6888 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 6889 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
6890 | i++; |
6891 | } | |
6892 | } | |
6893 | ||
70692ad2 JM |
6894 | if (info->attrs[NL80211_ATTR_IE]) { |
6895 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
6896 | memcpy((void *)request->ie, |
6897 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
6898 | request->ie_len); |
6899 | } | |
6900 | ||
57fbcce3 | 6901 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
a401d2bb JB |
6902 | if (wiphy->bands[i]) |
6903 | request->rates[i] = | |
6904 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
6905 | |
6906 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
6907 | nla_for_each_nested(attr, | |
6908 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
6909 | tmp) { | |
57fbcce3 | 6910 | enum nl80211_band band = nla_type(attr); |
34850ab2 | 6911 | |
57fbcce3 | 6912 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
34850ab2 JB |
6913 | err = -EINVAL; |
6914 | goto out_free; | |
6915 | } | |
1b09cd82 FF |
6916 | |
6917 | if (!wiphy->bands[band]) | |
6918 | continue; | |
6919 | ||
34850ab2 JB |
6920 | err = ieee80211_get_ratemask(wiphy->bands[band], |
6921 | nla_data(attr), | |
6922 | nla_len(attr), | |
6923 | &request->rates[band]); | |
6924 | if (err) | |
6925 | goto out_free; | |
6926 | } | |
6927 | } | |
6928 | ||
1d76250b AS |
6929 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
6930 | if (!wiphy_ext_feature_isset(wiphy, | |
6931 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { | |
6932 | err = -EOPNOTSUPP; | |
6933 | goto out_free; | |
6934 | } | |
6935 | ||
6936 | request->duration = | |
6937 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); | |
6938 | request->duration_mandatory = | |
6939 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); | |
6940 | } | |
6941 | ||
2d23d073 RZ |
6942 | err = nl80211_check_scan_flags(wiphy, wdev, request, info->attrs, |
6943 | false); | |
6944 | if (err) | |
6945 | goto out_free; | |
ed473771 | 6946 | |
e9f935e3 RM |
6947 | request->no_cck = |
6948 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
6949 | ||
2fa436b3 VK |
6950 | /* Initial implementation used NL80211_ATTR_MAC to set the specific |
6951 | * BSSID to scan for. This was problematic because that same attribute | |
6952 | * was already used for another purpose (local random MAC address). The | |
6953 | * NL80211_ATTR_BSSID attribute was added to fix this. For backwards | |
6954 | * compatibility with older userspace components, also use the | |
6955 | * NL80211_ATTR_MAC value here if it can be determined to be used for | |
6956 | * the specific BSSID use case instead of the random MAC address | |
6957 | * (NL80211_ATTR_SCAN_FLAGS is used to enable random MAC address use). | |
6958 | */ | |
6959 | if (info->attrs[NL80211_ATTR_BSSID]) | |
6960 | memcpy(request->bssid, | |
6961 | nla_data(info->attrs[NL80211_ATTR_BSSID]), ETH_ALEN); | |
6962 | else if (!(request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) && | |
6963 | info->attrs[NL80211_ATTR_MAC]) | |
818965d3 JM |
6964 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), |
6965 | ETH_ALEN); | |
6966 | else | |
6967 | eth_broadcast_addr(request->bssid); | |
6968 | ||
fd014284 | 6969 | request->wdev = wdev; |
79c97e97 | 6970 | request->wiphy = &rdev->wiphy; |
15d6030b | 6971 | request->scan_start = jiffies; |
2a519311 | 6972 | |
79c97e97 | 6973 | rdev->scan_req = request; |
e35e4d28 | 6974 | err = rdev_scan(rdev, request); |
2a519311 | 6975 | |
463d0183 | 6976 | if (!err) { |
fd014284 JB |
6977 | nl80211_send_scan_start(rdev, wdev); |
6978 | if (wdev->netdev) | |
6979 | dev_hold(wdev->netdev); | |
4c476991 | 6980 | } else { |
2a519311 | 6981 | out_free: |
79c97e97 | 6982 | rdev->scan_req = NULL; |
2a519311 JB |
6983 | kfree(request); |
6984 | } | |
3b85875a | 6985 | |
f9f47529 | 6986 | unlock: |
2a519311 JB |
6987 | return err; |
6988 | } | |
6989 | ||
91d3ab46 VK |
6990 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
6991 | { | |
6992 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6993 | struct wireless_dev *wdev = info->user_ptr[1]; | |
6994 | ||
6995 | if (!rdev->ops->abort_scan) | |
6996 | return -EOPNOTSUPP; | |
6997 | ||
6998 | if (rdev->scan_msg) | |
6999 | return 0; | |
7000 | ||
7001 | if (!rdev->scan_req) | |
7002 | return -ENOENT; | |
7003 | ||
7004 | rdev_abort_scan(rdev, wdev); | |
7005 | return 0; | |
7006 | } | |
7007 | ||
3b06d277 AS |
7008 | static int |
7009 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, | |
7010 | struct cfg80211_sched_scan_request *request, | |
7011 | struct nlattr **attrs) | |
7012 | { | |
7013 | int tmp, err, i = 0; | |
7014 | struct nlattr *attr; | |
7015 | ||
7016 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | |
7017 | u32 interval; | |
7018 | ||
7019 | /* | |
7020 | * If scan plans are not specified, | |
5a88de53 | 7021 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL will be specified. In this |
3b06d277 AS |
7022 | * case one scan plan will be set with the specified scan |
7023 | * interval and infinite number of iterations. | |
7024 | */ | |
3b06d277 AS |
7025 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
7026 | if (!interval) | |
7027 | return -EINVAL; | |
7028 | ||
7029 | request->scan_plans[0].interval = | |
7030 | DIV_ROUND_UP(interval, MSEC_PER_SEC); | |
7031 | if (!request->scan_plans[0].interval) | |
7032 | return -EINVAL; | |
7033 | ||
7034 | if (request->scan_plans[0].interval > | |
7035 | wiphy->max_sched_scan_plan_interval) | |
7036 | request->scan_plans[0].interval = | |
7037 | wiphy->max_sched_scan_plan_interval; | |
7038 | ||
7039 | return 0; | |
7040 | } | |
7041 | ||
7042 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { | |
7043 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; | |
7044 | ||
7045 | if (WARN_ON(i >= n_plans)) | |
7046 | return -EINVAL; | |
7047 | ||
bfe2c7b1 | 7048 | err = nla_parse_nested(plan, NL80211_SCHED_SCAN_PLAN_MAX, |
fceb6435 | 7049 | attr, nl80211_plan_policy, NULL); |
3b06d277 AS |
7050 | if (err) |
7051 | return err; | |
7052 | ||
7053 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) | |
7054 | return -EINVAL; | |
7055 | ||
7056 | request->scan_plans[i].interval = | |
7057 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); | |
7058 | if (!request->scan_plans[i].interval || | |
7059 | request->scan_plans[i].interval > | |
7060 | wiphy->max_sched_scan_plan_interval) | |
7061 | return -EINVAL; | |
7062 | ||
7063 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { | |
7064 | request->scan_plans[i].iterations = | |
7065 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); | |
7066 | if (!request->scan_plans[i].iterations || | |
7067 | (request->scan_plans[i].iterations > | |
7068 | wiphy->max_sched_scan_plan_iterations)) | |
7069 | return -EINVAL; | |
7070 | } else if (i < n_plans - 1) { | |
7071 | /* | |
7072 | * All scan plans but the last one must specify | |
7073 | * a finite number of iterations | |
7074 | */ | |
7075 | return -EINVAL; | |
7076 | } | |
7077 | ||
7078 | i++; | |
7079 | } | |
7080 | ||
7081 | /* | |
7082 | * The last scan plan must not specify the number of | |
7083 | * iterations, it is supposed to run infinitely | |
7084 | */ | |
7085 | if (request->scan_plans[n_plans - 1].iterations) | |
7086 | return -EINVAL; | |
7087 | ||
7088 | return 0; | |
7089 | } | |
7090 | ||
256da02d | 7091 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 7092 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
aad1e812 | 7093 | struct nlattr **attrs, int max_match_sets) |
807f8a8c LC |
7094 | { |
7095 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 7096 | struct nlattr *attr; |
3b06d277 | 7097 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
57fbcce3 | 7098 | enum nl80211_band band; |
807f8a8c | 7099 | size_t ie_len; |
a1f1c21c | 7100 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 7101 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 7102 | |
256da02d LC |
7103 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
7104 | return ERR_PTR(-EINVAL); | |
807f8a8c | 7105 | |
256da02d | 7106 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 7107 | n_channels = validate_scan_freqs( |
256da02d | 7108 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 7109 | if (!n_channels) |
256da02d | 7110 | return ERR_PTR(-EINVAL); |
807f8a8c | 7111 | } else { |
bdfbec2d | 7112 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
7113 | } |
7114 | ||
256da02d LC |
7115 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
7116 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
7117 | tmp) |
7118 | n_ssids++; | |
7119 | ||
93b6aa69 | 7120 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 7121 | return ERR_PTR(-EINVAL); |
807f8a8c | 7122 | |
ea73cbce JB |
7123 | /* |
7124 | * First, count the number of 'real' matchsets. Due to an issue with | |
7125 | * the old implementation, matchsets containing only the RSSI attribute | |
7126 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
7127 | * RSSI for all matchsets, rather than their own matchset for reporting | |
7128 | * all APs with a strong RSSI. This is needed to be compatible with | |
7129 | * older userspace that treated a matchset with only the RSSI as the | |
7130 | * global RSSI for all other matchsets - if there are other matchsets. | |
7131 | */ | |
256da02d | 7132 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 7133 | nla_for_each_nested(attr, |
256da02d | 7134 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
7135 | tmp) { |
7136 | struct nlattr *rssi; | |
7137 | ||
bfe2c7b1 JB |
7138 | err = nla_parse_nested(tb, |
7139 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
fceb6435 JB |
7140 | attr, nl80211_match_policy, |
7141 | NULL); | |
ea73cbce | 7142 | if (err) |
256da02d | 7143 | return ERR_PTR(err); |
3007e352 AVS |
7144 | |
7145 | /* SSID and BSSID are mutually exclusive */ | |
7146 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] && | |
7147 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) | |
7148 | return ERR_PTR(-EINVAL); | |
7149 | ||
ea73cbce | 7150 | /* add other standalone attributes here */ |
3007e352 AVS |
7151 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID] || |
7152 | tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]) { | |
ea73cbce JB |
7153 | n_match_sets++; |
7154 | continue; | |
7155 | } | |
7156 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
7157 | if (rssi) | |
7158 | default_match_rssi = nla_get_s32(rssi); | |
7159 | } | |
7160 | } | |
7161 | ||
7162 | /* However, if there's no other matchset, add the RSSI one */ | |
7163 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
7164 | n_match_sets = 1; | |
a1f1c21c | 7165 | |
aad1e812 | 7166 | if (n_match_sets > max_match_sets) |
256da02d | 7167 | return ERR_PTR(-EINVAL); |
a1f1c21c | 7168 | |
256da02d LC |
7169 | if (attrs[NL80211_ATTR_IE]) |
7170 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
7171 | else |
7172 | ie_len = 0; | |
7173 | ||
5a865bad | 7174 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 7175 | return ERR_PTR(-EINVAL); |
c10841ca | 7176 | |
3b06d277 AS |
7177 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
7178 | /* | |
7179 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since | |
7180 | * each scan plan already specifies its own interval | |
7181 | */ | |
7182 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
7183 | return ERR_PTR(-EINVAL); | |
7184 | ||
7185 | nla_for_each_nested(attr, | |
7186 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) | |
7187 | n_plans++; | |
7188 | } else { | |
7189 | /* | |
7190 | * The scan interval attribute is kept for backward | |
7191 | * compatibility. If no scan plans are specified and sched scan | |
7192 | * interval is specified, one scan plan will be set with this | |
7193 | * scan interval and infinite number of iterations. | |
7194 | */ | |
7195 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
7196 | return ERR_PTR(-EINVAL); | |
7197 | ||
7198 | n_plans = 1; | |
7199 | } | |
7200 | ||
7201 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) | |
7202 | return ERR_PTR(-EINVAL); | |
7203 | ||
bf95ecdb | 7204 | if (!wiphy_ext_feature_isset( |
7205 | wiphy, NL80211_EXT_FEATURE_SCHED_SCAN_RELATIVE_RSSI) && | |
7206 | (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI] || | |
7207 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST])) | |
7208 | return ERR_PTR(-EINVAL); | |
7209 | ||
807f8a8c | 7210 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 7211 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 7212 | + sizeof(*request->match_sets) * n_match_sets |
3b06d277 | 7213 | + sizeof(*request->scan_plans) * n_plans |
a2cd43c5 | 7214 | + sizeof(*request->channels) * n_channels |
807f8a8c | 7215 | + ie_len, GFP_KERNEL); |
256da02d LC |
7216 | if (!request) |
7217 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
7218 | |
7219 | if (n_ssids) | |
7220 | request->ssids = (void *)&request->channels[n_channels]; | |
7221 | request->n_ssids = n_ssids; | |
7222 | if (ie_len) { | |
13874e4b | 7223 | if (n_ssids) |
807f8a8c LC |
7224 | request->ie = (void *)(request->ssids + n_ssids); |
7225 | else | |
7226 | request->ie = (void *)(request->channels + n_channels); | |
7227 | } | |
7228 | ||
a1f1c21c LC |
7229 | if (n_match_sets) { |
7230 | if (request->ie) | |
7231 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 7232 | else if (n_ssids) |
a1f1c21c LC |
7233 | request->match_sets = |
7234 | (void *)(request->ssids + n_ssids); | |
7235 | else | |
7236 | request->match_sets = | |
7237 | (void *)(request->channels + n_channels); | |
7238 | } | |
7239 | request->n_match_sets = n_match_sets; | |
7240 | ||
3b06d277 AS |
7241 | if (n_match_sets) |
7242 | request->scan_plans = (void *)(request->match_sets + | |
7243 | n_match_sets); | |
7244 | else if (request->ie) | |
7245 | request->scan_plans = (void *)(request->ie + ie_len); | |
7246 | else if (n_ssids) | |
7247 | request->scan_plans = (void *)(request->ssids + n_ssids); | |
7248 | else | |
7249 | request->scan_plans = (void *)(request->channels + n_channels); | |
7250 | ||
7251 | request->n_scan_plans = n_plans; | |
7252 | ||
807f8a8c | 7253 | i = 0; |
256da02d | 7254 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
7255 | /* user specified, bail out if channel not found */ |
7256 | nla_for_each_nested(attr, | |
256da02d | 7257 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
7258 | tmp) { |
7259 | struct ieee80211_channel *chan; | |
7260 | ||
7261 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
7262 | ||
7263 | if (!chan) { | |
7264 | err = -EINVAL; | |
7265 | goto out_free; | |
7266 | } | |
7267 | ||
7268 | /* ignore disabled channels */ | |
7269 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
7270 | continue; | |
7271 | ||
7272 | request->channels[i] = chan; | |
7273 | i++; | |
7274 | } | |
7275 | } else { | |
7276 | /* all channels */ | |
57fbcce3 | 7277 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
807f8a8c | 7278 | int j; |
7a087e74 | 7279 | |
807f8a8c LC |
7280 | if (!wiphy->bands[band]) |
7281 | continue; | |
7282 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
7283 | struct ieee80211_channel *chan; | |
7284 | ||
7285 | chan = &wiphy->bands[band]->channels[j]; | |
7286 | ||
7287 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
7288 | continue; | |
7289 | ||
7290 | request->channels[i] = chan; | |
7291 | i++; | |
7292 | } | |
7293 | } | |
7294 | } | |
7295 | ||
7296 | if (!i) { | |
7297 | err = -EINVAL; | |
7298 | goto out_free; | |
7299 | } | |
7300 | ||
7301 | request->n_channels = i; | |
7302 | ||
7303 | i = 0; | |
13874e4b | 7304 | if (n_ssids) { |
256da02d | 7305 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 7306 | tmp) { |
57a27e1d | 7307 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
7308 | err = -EINVAL; |
7309 | goto out_free; | |
7310 | } | |
57a27e1d | 7311 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
7312 | memcpy(request->ssids[i].ssid, nla_data(attr), |
7313 | nla_len(attr)); | |
807f8a8c LC |
7314 | i++; |
7315 | } | |
7316 | } | |
7317 | ||
a1f1c21c | 7318 | i = 0; |
256da02d | 7319 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 7320 | nla_for_each_nested(attr, |
256da02d | 7321 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 7322 | tmp) { |
3007e352 | 7323 | struct nlattr *ssid, *bssid, *rssi; |
a1f1c21c | 7324 | |
bfe2c7b1 JB |
7325 | err = nla_parse_nested(tb, |
7326 | NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
fceb6435 JB |
7327 | attr, nl80211_match_policy, |
7328 | NULL); | |
ae811e21 JB |
7329 | if (err) |
7330 | goto out_free; | |
4a4ab0d7 | 7331 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
3007e352 AVS |
7332 | bssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_BSSID]; |
7333 | if (ssid || bssid) { | |
ea73cbce JB |
7334 | if (WARN_ON(i >= n_match_sets)) { |
7335 | /* this indicates a programming error, | |
7336 | * the loop above should have verified | |
7337 | * things properly | |
7338 | */ | |
7339 | err = -EINVAL; | |
7340 | goto out_free; | |
7341 | } | |
7342 | ||
3007e352 AVS |
7343 | if (ssid) { |
7344 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { | |
7345 | err = -EINVAL; | |
7346 | goto out_free; | |
7347 | } | |
7348 | memcpy(request->match_sets[i].ssid.ssid, | |
7349 | nla_data(ssid), nla_len(ssid)); | |
7350 | request->match_sets[i].ssid.ssid_len = | |
7351 | nla_len(ssid); | |
7352 | } | |
7353 | if (bssid) { | |
7354 | if (nla_len(bssid) != ETH_ALEN) { | |
7355 | err = -EINVAL; | |
7356 | goto out_free; | |
7357 | } | |
7358 | memcpy(request->match_sets[i].bssid, | |
7359 | nla_data(bssid), ETH_ALEN); | |
a1f1c21c | 7360 | } |
3007e352 | 7361 | |
56ab364f | 7362 | /* special attribute - old implementation w/a */ |
ea73cbce JB |
7363 | request->match_sets[i].rssi_thold = |
7364 | default_match_rssi; | |
7365 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
7366 | if (rssi) | |
7367 | request->match_sets[i].rssi_thold = | |
7368 | nla_get_s32(rssi); | |
a1f1c21c LC |
7369 | } |
7370 | i++; | |
7371 | } | |
ea73cbce JB |
7372 | |
7373 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 7374 | if (i == 0 && n_match_sets) |
ea73cbce JB |
7375 | request->match_sets[0].rssi_thold = default_match_rssi; |
7376 | ||
7377 | request->min_rssi_thold = INT_MAX; | |
7378 | for (i = 0; i < n_match_sets; i++) | |
7379 | request->min_rssi_thold = | |
7380 | min(request->match_sets[i].rssi_thold, | |
7381 | request->min_rssi_thold); | |
7382 | } else { | |
7383 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
7384 | } |
7385 | ||
9900e484 JB |
7386 | if (ie_len) { |
7387 | request->ie_len = ie_len; | |
807f8a8c | 7388 | memcpy((void *)request->ie, |
256da02d | 7389 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
7390 | request->ie_len); |
7391 | } | |
7392 | ||
2d23d073 RZ |
7393 | err = nl80211_check_scan_flags(wiphy, wdev, request, attrs, true); |
7394 | if (err) | |
7395 | goto out_free; | |
ed473771 | 7396 | |
9c748934 LC |
7397 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
7398 | request->delay = | |
7399 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
7400 | ||
bf95ecdb | 7401 | if (attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]) { |
7402 | request->relative_rssi = nla_get_s8( | |
7403 | attrs[NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI]); | |
7404 | request->relative_rssi_set = true; | |
7405 | } | |
7406 | ||
7407 | if (request->relative_rssi_set && | |
7408 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]) { | |
7409 | struct nl80211_bss_select_rssi_adjust *rssi_adjust; | |
7410 | ||
7411 | rssi_adjust = nla_data( | |
7412 | attrs[NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST]); | |
7413 | request->rssi_adjust.band = rssi_adjust->band; | |
7414 | request->rssi_adjust.delta = rssi_adjust->delta; | |
7415 | if (!is_band_valid(wiphy, request->rssi_adjust.band)) { | |
7416 | err = -EINVAL; | |
7417 | goto out_free; | |
7418 | } | |
7419 | } | |
7420 | ||
3b06d277 AS |
7421 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
7422 | if (err) | |
7423 | goto out_free; | |
7424 | ||
15d6030b | 7425 | request->scan_start = jiffies; |
807f8a8c | 7426 | |
256da02d | 7427 | return request; |
807f8a8c LC |
7428 | |
7429 | out_free: | |
7430 | kfree(request); | |
256da02d LC |
7431 | return ERR_PTR(err); |
7432 | } | |
7433 | ||
7434 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
7435 | struct genl_info *info) | |
7436 | { | |
7437 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7438 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 7439 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 7440 | struct cfg80211_sched_scan_request *sched_scan_req; |
ca986ad9 | 7441 | bool want_multi; |
256da02d LC |
7442 | int err; |
7443 | ||
ca986ad9 | 7444 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_start) |
256da02d LC |
7445 | return -EOPNOTSUPP; |
7446 | ||
ca986ad9 AVS |
7447 | want_multi = info->attrs[NL80211_ATTR_SCHED_SCAN_MULTI]; |
7448 | err = cfg80211_sched_scan_req_possible(rdev, want_multi); | |
7449 | if (err) | |
7450 | return err; | |
256da02d | 7451 | |
31a60ed1 | 7452 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
aad1e812 AVS |
7453 | info->attrs, |
7454 | rdev->wiphy.max_match_sets); | |
31a60ed1 JR |
7455 | |
7456 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
7457 | if (err) |
7458 | goto out_err; | |
7459 | ||
ca986ad9 AVS |
7460 | /* leave request id zero for legacy request |
7461 | * or if driver does not support multi-scheduled scan | |
7462 | */ | |
7463 | if (want_multi && rdev->wiphy.max_sched_scan_reqs > 1) { | |
7464 | while (!sched_scan_req->reqid) | |
7465 | sched_scan_req->reqid = rdev->wiphy.cookie_counter++; | |
7466 | } | |
7467 | ||
31a60ed1 | 7468 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
7469 | if (err) |
7470 | goto out_free; | |
7471 | ||
31a60ed1 JR |
7472 | sched_scan_req->dev = dev; |
7473 | sched_scan_req->wiphy = &rdev->wiphy; | |
7474 | ||
93a1e86c JR |
7475 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
7476 | sched_scan_req->owner_nlportid = info->snd_portid; | |
7477 | ||
ca986ad9 | 7478 | cfg80211_add_sched_scan_req(rdev, sched_scan_req); |
256da02d | 7479 | |
96b08fd6 | 7480 | nl80211_send_sched_scan(sched_scan_req, NL80211_CMD_START_SCHED_SCAN); |
256da02d LC |
7481 | return 0; |
7482 | ||
7483 | out_free: | |
31a60ed1 | 7484 | kfree(sched_scan_req); |
256da02d | 7485 | out_err: |
807f8a8c LC |
7486 | return err; |
7487 | } | |
7488 | ||
7489 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
7490 | struct genl_info *info) | |
7491 | { | |
ca986ad9 | 7492 | struct cfg80211_sched_scan_request *req; |
807f8a8c | 7493 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ca986ad9 | 7494 | u64 cookie; |
807f8a8c | 7495 | |
ca986ad9 | 7496 | if (!rdev->wiphy.max_sched_scan_reqs || !rdev->ops->sched_scan_stop) |
807f8a8c LC |
7497 | return -EOPNOTSUPP; |
7498 | ||
ca986ad9 AVS |
7499 | if (info->attrs[NL80211_ATTR_COOKIE]) { |
7500 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
7501 | return __cfg80211_stop_sched_scan(rdev, cookie, false); | |
7502 | } | |
7503 | ||
7504 | req = list_first_or_null_rcu(&rdev->sched_scan_req_list, | |
7505 | struct cfg80211_sched_scan_request, | |
7506 | list); | |
7507 | if (!req || req->reqid || | |
7508 | (req->owner_nlportid && | |
7509 | req->owner_nlportid != info->snd_portid)) | |
7510 | return -ENOENT; | |
7511 | ||
7512 | return cfg80211_stop_sched_scan_req(rdev, req, false); | |
807f8a8c LC |
7513 | } |
7514 | ||
04f39047 SW |
7515 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
7516 | struct genl_info *info) | |
7517 | { | |
7518 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7519 | struct net_device *dev = info->user_ptr[1]; | |
7520 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7521 | struct cfg80211_chan_def chandef; | |
55f7435c | 7522 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 7523 | unsigned int cac_time_ms; |
04f39047 SW |
7524 | int err; |
7525 | ||
55f7435c LR |
7526 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
7527 | if (dfs_region == NL80211_DFS_UNSET) | |
7528 | return -EINVAL; | |
7529 | ||
04f39047 SW |
7530 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7531 | if (err) | |
7532 | return err; | |
7533 | ||
ff311bc1 SW |
7534 | if (netif_carrier_ok(dev)) |
7535 | return -EBUSY; | |
7536 | ||
04f39047 SW |
7537 | if (wdev->cac_started) |
7538 | return -EBUSY; | |
7539 | ||
2beb6dab | 7540 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 7541 | wdev->iftype); |
04f39047 SW |
7542 | if (err < 0) |
7543 | return err; | |
7544 | ||
7545 | if (err == 0) | |
7546 | return -EINVAL; | |
7547 | ||
fe7c3a1f | 7548 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
7549 | return -EINVAL; |
7550 | ||
7551 | if (!rdev->ops->start_radar_detection) | |
7552 | return -EOPNOTSUPP; | |
7553 | ||
31559f35 JD |
7554 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
7555 | if (WARN_ON(!cac_time_ms)) | |
7556 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
7557 | ||
a1056b1b | 7558 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
04f39047 | 7559 | if (!err) { |
9e0e2961 | 7560 | wdev->chandef = chandef; |
04f39047 SW |
7561 | wdev->cac_started = true; |
7562 | wdev->cac_start_time = jiffies; | |
31559f35 | 7563 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 7564 | } |
04f39047 SW |
7565 | return err; |
7566 | } | |
7567 | ||
16ef1fe2 SW |
7568 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
7569 | { | |
7570 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7571 | struct net_device *dev = info->user_ptr[1]; | |
7572 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7573 | struct cfg80211_csa_settings params; | |
7574 | /* csa_attrs is defined static to avoid waste of stack size - this | |
7575 | * function is called under RTNL lock, so this should not be a problem. | |
7576 | */ | |
7577 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 7578 | int err; |
ee4bc9e7 | 7579 | bool need_new_beacon = false; |
8d9de16f | 7580 | bool need_handle_dfs_flag = true; |
9a774c78 | 7581 | int len, i; |
252e07ca | 7582 | u32 cs_count; |
16ef1fe2 SW |
7583 | |
7584 | if (!rdev->ops->channel_switch || | |
7585 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
7586 | return -EOPNOTSUPP; | |
7587 | ||
ee4bc9e7 SW |
7588 | switch (dev->ieee80211_ptr->iftype) { |
7589 | case NL80211_IFTYPE_AP: | |
7590 | case NL80211_IFTYPE_P2P_GO: | |
7591 | need_new_beacon = true; | |
8d9de16f BB |
7592 | /* For all modes except AP the handle_dfs flag needs to be |
7593 | * supplied to tell the kernel that userspace will handle radar | |
7594 | * events when they happen. Otherwise a switch to a channel | |
7595 | * requiring DFS will be rejected. | |
7596 | */ | |
7597 | need_handle_dfs_flag = false; | |
ee4bc9e7 SW |
7598 | |
7599 | /* useless if AP is not running */ | |
7600 | if (!wdev->beacon_interval) | |
1ff79dfa | 7601 | return -ENOTCONN; |
ee4bc9e7 SW |
7602 | break; |
7603 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
7604 | if (!wdev->ssid_len) |
7605 | return -ENOTCONN; | |
7606 | break; | |
c6da674a | 7607 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
7608 | if (!wdev->mesh_id_len) |
7609 | return -ENOTCONN; | |
ee4bc9e7 SW |
7610 | break; |
7611 | default: | |
16ef1fe2 | 7612 | return -EOPNOTSUPP; |
ee4bc9e7 | 7613 | } |
16ef1fe2 SW |
7614 | |
7615 | memset(¶ms, 0, sizeof(params)); | |
7616 | ||
7617 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7618 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
7619 | return -EINVAL; | |
7620 | ||
7621 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 7622 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
7623 | return -EINVAL; |
7624 | ||
252e07ca LC |
7625 | /* Even though the attribute is u32, the specification says |
7626 | * u8, so let's make sure we don't overflow. | |
7627 | */ | |
7628 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
7629 | if (cs_count > 255) | |
7630 | return -EINVAL; | |
7631 | ||
7632 | params.count = cs_count; | |
16ef1fe2 | 7633 | |
ee4bc9e7 SW |
7634 | if (!need_new_beacon) |
7635 | goto skip_beacons; | |
7636 | ||
16ef1fe2 SW |
7637 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
7638 | if (err) | |
7639 | return err; | |
7640 | ||
7641 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
7642 | info->attrs[NL80211_ATTR_CSA_IES], | |
fe52145f | 7643 | nl80211_policy, info->extack); |
16ef1fe2 SW |
7644 | if (err) |
7645 | return err; | |
7646 | ||
7647 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
7648 | if (err) | |
7649 | return err; | |
7650 | ||
7651 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
7652 | return -EINVAL; | |
7653 | ||
9a774c78 AO |
7654 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
7655 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
7656 | return -EINVAL; |
7657 | ||
9a774c78 AO |
7658 | params.n_counter_offsets_beacon = len / sizeof(u16); |
7659 | if (rdev->wiphy.max_num_csa_counters && | |
7660 | (params.n_counter_offsets_beacon > | |
7661 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
7662 | return -EINVAL; |
7663 | ||
9a774c78 AO |
7664 | params.counter_offsets_beacon = |
7665 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
7666 | ||
7667 | /* sanity checks - counters should fit and be the same */ | |
7668 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
7669 | u16 offset = params.counter_offsets_beacon[i]; | |
7670 | ||
7671 | if (offset >= params.beacon_csa.tail_len) | |
7672 | return -EINVAL; | |
7673 | ||
7674 | if (params.beacon_csa.tail[offset] != params.count) | |
7675 | return -EINVAL; | |
7676 | } | |
7677 | ||
16ef1fe2 | 7678 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
7679 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
7680 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
7681 | return -EINVAL; |
7682 | ||
9a774c78 AO |
7683 | params.n_counter_offsets_presp = len / sizeof(u16); |
7684 | if (rdev->wiphy.max_num_csa_counters && | |
ad5987b4 | 7685 | (params.n_counter_offsets_presp > |
9a774c78 | 7686 | rdev->wiphy.max_num_csa_counters)) |
16ef1fe2 | 7687 | return -EINVAL; |
9a774c78 AO |
7688 | |
7689 | params.counter_offsets_presp = | |
7690 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
7691 | ||
7692 | /* sanity checks - counters should fit and be the same */ | |
7693 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
7694 | u16 offset = params.counter_offsets_presp[i]; | |
7695 | ||
7696 | if (offset >= params.beacon_csa.probe_resp_len) | |
7697 | return -EINVAL; | |
7698 | ||
7699 | if (params.beacon_csa.probe_resp[offset] != | |
7700 | params.count) | |
7701 | return -EINVAL; | |
7702 | } | |
16ef1fe2 SW |
7703 | } |
7704 | ||
ee4bc9e7 | 7705 | skip_beacons: |
16ef1fe2 SW |
7706 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
7707 | if (err) | |
7708 | return err; | |
7709 | ||
923b352f AN |
7710 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
7711 | wdev->iftype)) | |
16ef1fe2 SW |
7712 | return -EINVAL; |
7713 | ||
2beb6dab LC |
7714 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
7715 | ¶ms.chandef, | |
7716 | wdev->iftype); | |
7717 | if (err < 0) | |
7718 | return err; | |
7719 | ||
8d9de16f | 7720 | if (err > 0) { |
2beb6dab | 7721 | params.radar_required = true; |
8d9de16f BB |
7722 | if (need_handle_dfs_flag && |
7723 | !nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS])) { | |
7724 | return -EINVAL; | |
7725 | } | |
7726 | } | |
16ef1fe2 | 7727 | |
16ef1fe2 SW |
7728 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
7729 | params.block_tx = true; | |
7730 | ||
c56589ed SW |
7731 | wdev_lock(wdev); |
7732 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
7733 | wdev_unlock(wdev); | |
7734 | ||
7735 | return err; | |
16ef1fe2 SW |
7736 | } |
7737 | ||
9720bb3a JB |
7738 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
7739 | u32 seq, int flags, | |
2a519311 | 7740 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
7741 | struct wireless_dev *wdev, |
7742 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 7743 | { |
48ab905d | 7744 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 7745 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
7746 | void *hdr; |
7747 | struct nlattr *bss; | |
48ab905d JB |
7748 | |
7749 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 7750 | |
15e47304 | 7751 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
7752 | NL80211_CMD_NEW_SCAN_RESULTS); |
7753 | if (!hdr) | |
7754 | return -1; | |
7755 | ||
0a833c29 | 7756 | genl_dump_check_consistent(cb, hdr); |
9720bb3a | 7757 | |
97990a06 JB |
7758 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
7759 | goto nla_put_failure; | |
7760 | if (wdev->netdev && | |
9360ffd1 DM |
7761 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
7762 | goto nla_put_failure; | |
2dad624e ND |
7763 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
7764 | NL80211_ATTR_PAD)) | |
97990a06 | 7765 | goto nla_put_failure; |
2a519311 JB |
7766 | |
7767 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
7768 | if (!bss) | |
7769 | goto nla_put_failure; | |
9360ffd1 | 7770 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 7771 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 7772 | goto nla_put_failure; |
9caf0364 JB |
7773 | |
7774 | rcu_read_lock(); | |
0e227084 JB |
7775 | /* indicate whether we have probe response data or not */ |
7776 | if (rcu_access_pointer(res->proberesp_ies) && | |
7777 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
7778 | goto fail_unlock_rcu; | |
7779 | ||
7780 | /* this pointer prefers to be pointed to probe response data | |
7781 | * but is always valid | |
7782 | */ | |
9caf0364 | 7783 | ies = rcu_dereference(res->ies); |
8cef2c9d | 7784 | if (ies) { |
2dad624e ND |
7785 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
7786 | NL80211_BSS_PAD)) | |
8cef2c9d | 7787 | goto fail_unlock_rcu; |
8cef2c9d JB |
7788 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
7789 | ies->len, ies->data)) | |
7790 | goto fail_unlock_rcu; | |
9caf0364 | 7791 | } |
0e227084 JB |
7792 | |
7793 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 7794 | ies = rcu_dereference(res->beacon_ies); |
0e227084 | 7795 | if (ies && ies->from_beacon) { |
2dad624e ND |
7796 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
7797 | NL80211_BSS_PAD)) | |
8cef2c9d JB |
7798 | goto fail_unlock_rcu; |
7799 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
7800 | ies->len, ies->data)) | |
7801 | goto fail_unlock_rcu; | |
9caf0364 JB |
7802 | } |
7803 | rcu_read_unlock(); | |
7804 | ||
9360ffd1 DM |
7805 | if (res->beacon_interval && |
7806 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
7807 | goto nla_put_failure; | |
7808 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
7809 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 7810 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
7811 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
7812 | jiffies_to_msecs(jiffies - intbss->ts))) | |
7813 | goto nla_put_failure; | |
2a519311 | 7814 | |
1d76250b AS |
7815 | if (intbss->parent_tsf && |
7816 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, | |
7817 | intbss->parent_tsf, NL80211_BSS_PAD) || | |
7818 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, | |
7819 | intbss->parent_bssid))) | |
7820 | goto nla_put_failure; | |
7821 | ||
6e19bc4b | 7822 | if (intbss->ts_boottime && |
2dad624e ND |
7823 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
7824 | intbss->ts_boottime, NL80211_BSS_PAD)) | |
6e19bc4b DS |
7825 | goto nla_put_failure; |
7826 | ||
77965c97 | 7827 | switch (rdev->wiphy.signal_type) { |
2a519311 | 7828 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
7829 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
7830 | goto nla_put_failure; | |
2a519311 JB |
7831 | break; |
7832 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
7833 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
7834 | goto nla_put_failure; | |
2a519311 JB |
7835 | break; |
7836 | default: | |
7837 | break; | |
7838 | } | |
7839 | ||
48ab905d | 7840 | switch (wdev->iftype) { |
074ac8df | 7841 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 7842 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
7843 | if (intbss == wdev->current_bss && |
7844 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
7845 | NL80211_BSS_STATUS_ASSOCIATED)) | |
7846 | goto nla_put_failure; | |
48ab905d JB |
7847 | break; |
7848 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
7849 | if (intbss == wdev->current_bss && |
7850 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
7851 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
7852 | goto nla_put_failure; | |
48ab905d JB |
7853 | break; |
7854 | default: | |
7855 | break; | |
7856 | } | |
7857 | ||
2a519311 JB |
7858 | nla_nest_end(msg, bss); |
7859 | ||
053c095a JB |
7860 | genlmsg_end(msg, hdr); |
7861 | return 0; | |
2a519311 | 7862 | |
8cef2c9d JB |
7863 | fail_unlock_rcu: |
7864 | rcu_read_unlock(); | |
2a519311 JB |
7865 | nla_put_failure: |
7866 | genlmsg_cancel(msg, hdr); | |
7867 | return -EMSGSIZE; | |
7868 | } | |
7869 | ||
97990a06 | 7870 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 7871 | { |
48ab905d | 7872 | struct cfg80211_registered_device *rdev; |
2a519311 | 7873 | struct cfg80211_internal_bss *scan; |
48ab905d | 7874 | struct wireless_dev *wdev; |
97990a06 | 7875 | int start = cb->args[2], idx = 0; |
2a519311 JB |
7876 | int err; |
7877 | ||
ea90e0dc | 7878 | rtnl_lock(); |
97990a06 | 7879 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
ea90e0dc JB |
7880 | if (err) { |
7881 | rtnl_unlock(); | |
67748893 | 7882 | return err; |
ea90e0dc | 7883 | } |
2a519311 | 7884 | |
48ab905d JB |
7885 | wdev_lock(wdev); |
7886 | spin_lock_bh(&rdev->bss_lock); | |
7887 | cfg80211_bss_expire(rdev); | |
7888 | ||
9720bb3a JB |
7889 | cb->seq = rdev->bss_generation; |
7890 | ||
48ab905d | 7891 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
7892 | if (++idx <= start) |
7893 | continue; | |
9720bb3a | 7894 | if (nl80211_send_bss(skb, cb, |
2a519311 | 7895 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 7896 | rdev, wdev, scan) < 0) { |
2a519311 | 7897 | idx--; |
67748893 | 7898 | break; |
2a519311 JB |
7899 | } |
7900 | } | |
7901 | ||
48ab905d JB |
7902 | spin_unlock_bh(&rdev->bss_lock); |
7903 | wdev_unlock(wdev); | |
2a519311 | 7904 | |
97990a06 | 7905 | cb->args[2] = idx; |
ea90e0dc | 7906 | rtnl_unlock(); |
2a519311 | 7907 | |
67748893 | 7908 | return skb->len; |
2a519311 JB |
7909 | } |
7910 | ||
15e47304 | 7911 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
7912 | int flags, struct net_device *dev, |
7913 | bool allow_radio_stats, | |
7914 | struct survey_info *survey) | |
61fa713c HS |
7915 | { |
7916 | void *hdr; | |
7917 | struct nlattr *infoattr; | |
7918 | ||
11f78ac3 JB |
7919 | /* skip radio stats if userspace didn't request them */ |
7920 | if (!survey->channel && !allow_radio_stats) | |
7921 | return 0; | |
7922 | ||
15e47304 | 7923 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
7924 | NL80211_CMD_NEW_SURVEY_RESULTS); |
7925 | if (!hdr) | |
7926 | return -ENOMEM; | |
7927 | ||
9360ffd1 DM |
7928 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
7929 | goto nla_put_failure; | |
61fa713c HS |
7930 | |
7931 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
7932 | if (!infoattr) | |
7933 | goto nla_put_failure; | |
7934 | ||
11f78ac3 JB |
7935 | if (survey->channel && |
7936 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
7937 | survey->channel->center_freq)) |
7938 | goto nla_put_failure; | |
7939 | ||
7940 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
7941 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
7942 | goto nla_put_failure; | |
7943 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
7944 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
7945 | goto nla_put_failure; | |
4ed20beb | 7946 | if ((survey->filled & SURVEY_INFO_TIME) && |
2dad624e ND |
7947 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
7948 | survey->time, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7949 | goto nla_put_failure; |
4ed20beb | 7950 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
2dad624e ND |
7951 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
7952 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7953 | goto nla_put_failure; |
4ed20beb | 7954 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
2dad624e ND |
7955 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
7956 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7957 | goto nla_put_failure; |
4ed20beb | 7958 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
2dad624e ND |
7959 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
7960 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7961 | goto nla_put_failure; |
4ed20beb | 7962 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
2dad624e ND |
7963 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
7964 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7965 | goto nla_put_failure; |
052536ab | 7966 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
2dad624e ND |
7967 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
7968 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) | |
052536ab | 7969 | goto nla_put_failure; |
61fa713c HS |
7970 | |
7971 | nla_nest_end(msg, infoattr); | |
7972 | ||
053c095a JB |
7973 | genlmsg_end(msg, hdr); |
7974 | return 0; | |
61fa713c HS |
7975 | |
7976 | nla_put_failure: | |
7977 | genlmsg_cancel(msg, hdr); | |
7978 | return -EMSGSIZE; | |
7979 | } | |
7980 | ||
11f78ac3 | 7981 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c | 7982 | { |
c90c39da | 7983 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
61fa713c | 7984 | struct survey_info survey; |
1b8ec87a | 7985 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
7986 | struct wireless_dev *wdev; |
7987 | int survey_idx = cb->args[2]; | |
61fa713c | 7988 | int res; |
11f78ac3 | 7989 | bool radio_stats; |
61fa713c | 7990 | |
ea90e0dc | 7991 | rtnl_lock(); |
1b8ec87a | 7992 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 | 7993 | if (res) |
ea90e0dc | 7994 | goto out_err; |
61fa713c | 7995 | |
11f78ac3 | 7996 | /* prepare_wdev_dump parsed the attributes */ |
c90c39da | 7997 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
11f78ac3 | 7998 | |
97990a06 JB |
7999 | if (!wdev->netdev) { |
8000 | res = -EINVAL; | |
8001 | goto out_err; | |
8002 | } | |
8003 | ||
1b8ec87a | 8004 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
8005 | res = -EOPNOTSUPP; |
8006 | goto out_err; | |
8007 | } | |
8008 | ||
8009 | while (1) { | |
1b8ec87a | 8010 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
8011 | if (res == -ENOENT) |
8012 | break; | |
8013 | if (res) | |
8014 | goto out_err; | |
8015 | ||
11f78ac3 JB |
8016 | /* don't send disabled channels, but do send non-channel data */ |
8017 | if (survey.channel && | |
8018 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
8019 | survey_idx++; |
8020 | continue; | |
8021 | } | |
8022 | ||
61fa713c | 8023 | if (nl80211_send_survey(skb, |
15e47304 | 8024 | NETLINK_CB(cb->skb).portid, |
61fa713c | 8025 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 8026 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
8027 | goto out; |
8028 | survey_idx++; | |
8029 | } | |
8030 | ||
8031 | out: | |
97990a06 | 8032 | cb->args[2] = survey_idx; |
61fa713c HS |
8033 | res = skb->len; |
8034 | out_err: | |
ea90e0dc | 8035 | rtnl_unlock(); |
61fa713c HS |
8036 | return res; |
8037 | } | |
8038 | ||
b23aa676 SO |
8039 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
8040 | { | |
8041 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
8042 | NL80211_WPA_VERSION_2)); | |
8043 | } | |
8044 | ||
636a5d36 JM |
8045 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
8046 | { | |
4c476991 JB |
8047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8048 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 8049 | struct ieee80211_channel *chan; |
11b6b5a4 JM |
8050 | const u8 *bssid, *ssid, *ie = NULL, *auth_data = NULL; |
8051 | int err, ssid_len, ie_len = 0, auth_data_len = 0; | |
19957bb3 | 8052 | enum nl80211_auth_type auth_type; |
fffd0934 | 8053 | struct key_parse key; |
d5cdfacb | 8054 | bool local_state_change; |
636a5d36 | 8055 | |
f4a11bb0 JB |
8056 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8057 | return -EINVAL; | |
8058 | ||
8059 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8060 | return -EINVAL; | |
8061 | ||
1778092e JM |
8062 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
8063 | return -EINVAL; | |
8064 | ||
19957bb3 JB |
8065 | if (!info->attrs[NL80211_ATTR_SSID]) |
8066 | return -EINVAL; | |
8067 | ||
8068 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8069 | return -EINVAL; | |
8070 | ||
fffd0934 JB |
8071 | err = nl80211_parse_key(info, &key); |
8072 | if (err) | |
8073 | return err; | |
8074 | ||
8075 | if (key.idx >= 0) { | |
e31b8213 JB |
8076 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
8077 | return -EINVAL; | |
fffd0934 JB |
8078 | if (!key.p.key || !key.p.key_len) |
8079 | return -EINVAL; | |
8080 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
8081 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
8082 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
8083 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
8084 | return -EINVAL; | |
b6b5555b | 8085 | if (key.idx > 3) |
fffd0934 JB |
8086 | return -EINVAL; |
8087 | } else { | |
8088 | key.p.key_len = 0; | |
8089 | key.p.key = NULL; | |
8090 | } | |
8091 | ||
afea0b7a JB |
8092 | if (key.idx >= 0) { |
8093 | int i; | |
8094 | bool ok = false; | |
7a087e74 | 8095 | |
afea0b7a JB |
8096 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
8097 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
8098 | ok = true; | |
8099 | break; | |
8100 | } | |
8101 | } | |
4c476991 JB |
8102 | if (!ok) |
8103 | return -EINVAL; | |
afea0b7a JB |
8104 | } |
8105 | ||
4c476991 JB |
8106 | if (!rdev->ops->auth) |
8107 | return -EOPNOTSUPP; | |
636a5d36 | 8108 | |
074ac8df | 8109 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8110 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8111 | return -EOPNOTSUPP; | |
eec60b03 | 8112 | |
19957bb3 | 8113 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
8114 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
8115 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
8116 | if (!chan) | |
4c476991 | 8117 | return -EINVAL; |
636a5d36 | 8118 | |
19957bb3 JB |
8119 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8120 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
8121 | |
8122 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8123 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8124 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8125 | } |
8126 | ||
19957bb3 | 8127 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 8128 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 8129 | return -EINVAL; |
636a5d36 | 8130 | |
63181060 JM |
8131 | if ((auth_type == NL80211_AUTHTYPE_SAE || |
8132 | auth_type == NL80211_AUTHTYPE_FILS_SK || | |
8133 | auth_type == NL80211_AUTHTYPE_FILS_SK_PFS || | |
8134 | auth_type == NL80211_AUTHTYPE_FILS_PK) && | |
11b6b5a4 | 8135 | !info->attrs[NL80211_ATTR_AUTH_DATA]) |
e39e5b5e JM |
8136 | return -EINVAL; |
8137 | ||
11b6b5a4 | 8138 | if (info->attrs[NL80211_ATTR_AUTH_DATA]) { |
63181060 JM |
8139 | if (auth_type != NL80211_AUTHTYPE_SAE && |
8140 | auth_type != NL80211_AUTHTYPE_FILS_SK && | |
8141 | auth_type != NL80211_AUTHTYPE_FILS_SK_PFS && | |
8142 | auth_type != NL80211_AUTHTYPE_FILS_PK) | |
e39e5b5e | 8143 | return -EINVAL; |
11b6b5a4 JM |
8144 | auth_data = nla_data(info->attrs[NL80211_ATTR_AUTH_DATA]); |
8145 | auth_data_len = nla_len(info->attrs[NL80211_ATTR_AUTH_DATA]); | |
e39e5b5e | 8146 | /* need to include at least Auth Transaction and Status Code */ |
11b6b5a4 | 8147 | if (auth_data_len < 4) |
e39e5b5e JM |
8148 | return -EINVAL; |
8149 | } | |
8150 | ||
d5cdfacb JM |
8151 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8152 | ||
95de817b JB |
8153 | /* |
8154 | * Since we no longer track auth state, ignore | |
8155 | * requests to only change local state. | |
8156 | */ | |
8157 | if (local_state_change) | |
8158 | return 0; | |
8159 | ||
91bf9b26 JB |
8160 | wdev_lock(dev->ieee80211_ptr); |
8161 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
8162 | ssid, ssid_len, ie, ie_len, | |
8163 | key.p.key, key.p.key_len, key.idx, | |
11b6b5a4 | 8164 | auth_data, auth_data_len); |
91bf9b26 JB |
8165 | wdev_unlock(dev->ieee80211_ptr); |
8166 | return err; | |
636a5d36 JM |
8167 | } |
8168 | ||
c0692b8f JB |
8169 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
8170 | struct genl_info *info, | |
3dc27d25 JB |
8171 | struct cfg80211_crypto_settings *settings, |
8172 | int cipher_limit) | |
b23aa676 | 8173 | { |
c0b2bbd8 JB |
8174 | memset(settings, 0, sizeof(*settings)); |
8175 | ||
b23aa676 SO |
8176 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
8177 | ||
c0692b8f JB |
8178 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
8179 | u16 proto; | |
7a087e74 | 8180 | |
c0692b8f JB |
8181 | proto = nla_get_u16( |
8182 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
8183 | settings->control_port_ethertype = cpu_to_be16(proto); | |
8184 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
8185 | proto != ETH_P_PAE) | |
8186 | return -EINVAL; | |
8187 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
8188 | settings->control_port_no_encrypt = true; | |
8189 | } else | |
8190 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
8191 | ||
b23aa676 SO |
8192 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
8193 | void *data; | |
8194 | int len, i; | |
8195 | ||
8196 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
8197 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
8198 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
8199 | ||
8200 | if (len % sizeof(u32)) | |
8201 | return -EINVAL; | |
8202 | ||
3dc27d25 | 8203 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
8204 | return -EINVAL; |
8205 | ||
8206 | memcpy(settings->ciphers_pairwise, data, len); | |
8207 | ||
8208 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
8209 | if (!cfg80211_supported_cipher_suite( |
8210 | &rdev->wiphy, | |
b23aa676 SO |
8211 | settings->ciphers_pairwise[i])) |
8212 | return -EINVAL; | |
8213 | } | |
8214 | ||
8215 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
8216 | settings->cipher_group = | |
8217 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
8218 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
8219 | settings->cipher_group)) | |
b23aa676 SO |
8220 | return -EINVAL; |
8221 | } | |
8222 | ||
8223 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
8224 | settings->wpa_versions = | |
8225 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
8226 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
8227 | return -EINVAL; | |
8228 | } | |
8229 | ||
8230 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
8231 | void *data; | |
6d30240e | 8232 | int len; |
b23aa676 SO |
8233 | |
8234 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
8235 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
8236 | settings->n_akm_suites = len / sizeof(u32); | |
8237 | ||
8238 | if (len % sizeof(u32)) | |
8239 | return -EINVAL; | |
8240 | ||
1b9ca027 JM |
8241 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
8242 | return -EINVAL; | |
8243 | ||
b23aa676 | 8244 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
8245 | } |
8246 | ||
91b5ab62 EP |
8247 | if (info->attrs[NL80211_ATTR_PMK]) { |
8248 | if (nla_len(info->attrs[NL80211_ATTR_PMK]) != WLAN_PMK_LEN) | |
8249 | return -EINVAL; | |
8250 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
8251 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_PSK)) | |
8252 | return -EINVAL; | |
8253 | settings->psk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
8254 | } | |
8255 | ||
b23aa676 SO |
8256 | return 0; |
8257 | } | |
8258 | ||
636a5d36 JM |
8259 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
8260 | { | |
4c476991 JB |
8261 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8262 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 8263 | struct ieee80211_channel *chan; |
f62fab73 JB |
8264 | struct cfg80211_assoc_request req = {}; |
8265 | const u8 *bssid, *ssid; | |
8266 | int err, ssid_len = 0; | |
636a5d36 | 8267 | |
f4a11bb0 JB |
8268 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8269 | return -EINVAL; | |
8270 | ||
8271 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
8272 | !info->attrs[NL80211_ATTR_SSID] || |
8273 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
8274 | return -EINVAL; |
8275 | ||
4c476991 JB |
8276 | if (!rdev->ops->assoc) |
8277 | return -EOPNOTSUPP; | |
636a5d36 | 8278 | |
074ac8df | 8279 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8280 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8281 | return -EOPNOTSUPP; | |
eec60b03 | 8282 | |
19957bb3 | 8283 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 8284 | |
664834de JM |
8285 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
8286 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
8287 | if (!chan) | |
4c476991 | 8288 | return -EINVAL; |
636a5d36 | 8289 | |
19957bb3 JB |
8290 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8291 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
8292 | |
8293 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
8294 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8295 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8296 | } |
8297 | ||
dc6382ce | 8298 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 8299 | enum nl80211_mfp mfp = |
dc6382ce | 8300 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 8301 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 8302 | req.use_mfp = true; |
4c476991 JB |
8303 | else if (mfp != NL80211_MFP_NO) |
8304 | return -EINVAL; | |
dc6382ce JM |
8305 | } |
8306 | ||
3e5d7649 | 8307 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 8308 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 8309 | |
7e7c8926 | 8310 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 8311 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
8312 | |
8313 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
8314 | memcpy(&req.ht_capa_mask, |
8315 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8316 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
8317 | |
8318 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 8319 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 8320 | return -EINVAL; |
f62fab73 JB |
8321 | memcpy(&req.ht_capa, |
8322 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8323 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
8324 | } |
8325 | ||
ee2aca34 | 8326 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 8327 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
8328 | |
8329 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
8330 | memcpy(&req.vht_capa_mask, |
8331 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
8332 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
8333 | |
8334 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 8335 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 8336 | return -EINVAL; |
f62fab73 JB |
8337 | memcpy(&req.vht_capa, |
8338 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
8339 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
8340 | } |
8341 | ||
bab5ab7d | 8342 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
8343 | if (!((rdev->wiphy.features & |
8344 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
8345 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
8346 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
8347 | NL80211_EXT_FEATURE_RRM)) | |
bab5ab7d AK |
8348 | return -EINVAL; |
8349 | req.flags |= ASSOC_REQ_USE_RRM; | |
8350 | } | |
8351 | ||
348bd456 JM |
8352 | if (info->attrs[NL80211_ATTR_FILS_KEK]) { |
8353 | req.fils_kek = nla_data(info->attrs[NL80211_ATTR_FILS_KEK]); | |
8354 | req.fils_kek_len = nla_len(info->attrs[NL80211_ATTR_FILS_KEK]); | |
8355 | if (!info->attrs[NL80211_ATTR_FILS_NONCES]) | |
8356 | return -EINVAL; | |
8357 | req.fils_nonces = | |
8358 | nla_data(info->attrs[NL80211_ATTR_FILS_NONCES]); | |
8359 | } | |
8360 | ||
f62fab73 | 8361 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
8362 | if (!err) { |
8363 | wdev_lock(dev->ieee80211_ptr); | |
bd2522b1 | 8364 | |
f62fab73 JB |
8365 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
8366 | ssid, ssid_len, &req); | |
bd2522b1 AZ |
8367 | |
8368 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
8369 | dev->ieee80211_ptr->conn_owner_nlportid = | |
8370 | info->snd_portid; | |
8371 | memcpy(dev->ieee80211_ptr->disconnect_bssid, | |
8372 | bssid, ETH_ALEN); | |
8373 | } | |
8374 | ||
91bf9b26 JB |
8375 | wdev_unlock(dev->ieee80211_ptr); |
8376 | } | |
636a5d36 | 8377 | |
636a5d36 JM |
8378 | return err; |
8379 | } | |
8380 | ||
8381 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
8382 | { | |
4c476991 JB |
8383 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8384 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 8385 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 8386 | int ie_len = 0, err; |
19957bb3 | 8387 | u16 reason_code; |
d5cdfacb | 8388 | bool local_state_change; |
636a5d36 | 8389 | |
f4a11bb0 JB |
8390 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8391 | return -EINVAL; | |
8392 | ||
8393 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8394 | return -EINVAL; | |
8395 | ||
8396 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8397 | return -EINVAL; | |
8398 | ||
4c476991 JB |
8399 | if (!rdev->ops->deauth) |
8400 | return -EOPNOTSUPP; | |
636a5d36 | 8401 | |
074ac8df | 8402 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8403 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8404 | return -EOPNOTSUPP; | |
eec60b03 | 8405 | |
19957bb3 | 8406 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 8407 | |
19957bb3 JB |
8408 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
8409 | if (reason_code == 0) { | |
f4a11bb0 | 8410 | /* Reason Code 0 is reserved */ |
4c476991 | 8411 | return -EINVAL; |
255e737e | 8412 | } |
636a5d36 JM |
8413 | |
8414 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8415 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8416 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8417 | } |
8418 | ||
d5cdfacb JM |
8419 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8420 | ||
91bf9b26 JB |
8421 | wdev_lock(dev->ieee80211_ptr); |
8422 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
8423 | local_state_change); | |
8424 | wdev_unlock(dev->ieee80211_ptr); | |
8425 | return err; | |
636a5d36 JM |
8426 | } |
8427 | ||
8428 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
8429 | { | |
4c476991 JB |
8430 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8431 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 8432 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 8433 | int ie_len = 0, err; |
19957bb3 | 8434 | u16 reason_code; |
d5cdfacb | 8435 | bool local_state_change; |
636a5d36 | 8436 | |
f4a11bb0 JB |
8437 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8438 | return -EINVAL; | |
8439 | ||
8440 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8441 | return -EINVAL; | |
8442 | ||
8443 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8444 | return -EINVAL; | |
8445 | ||
4c476991 JB |
8446 | if (!rdev->ops->disassoc) |
8447 | return -EOPNOTSUPP; | |
636a5d36 | 8448 | |
074ac8df | 8449 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8450 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8451 | return -EOPNOTSUPP; | |
eec60b03 | 8452 | |
19957bb3 | 8453 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 8454 | |
19957bb3 JB |
8455 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
8456 | if (reason_code == 0) { | |
f4a11bb0 | 8457 | /* Reason Code 0 is reserved */ |
4c476991 | 8458 | return -EINVAL; |
255e737e | 8459 | } |
636a5d36 JM |
8460 | |
8461 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8462 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8463 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8464 | } |
8465 | ||
d5cdfacb JM |
8466 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8467 | ||
91bf9b26 JB |
8468 | wdev_lock(dev->ieee80211_ptr); |
8469 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
8470 | local_state_change); | |
8471 | wdev_unlock(dev->ieee80211_ptr); | |
8472 | return err; | |
636a5d36 JM |
8473 | } |
8474 | ||
dd5b4cc7 FF |
8475 | static bool |
8476 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
57fbcce3 | 8477 | int mcast_rate[NUM_NL80211_BANDS], |
dd5b4cc7 FF |
8478 | int rateval) |
8479 | { | |
8480 | struct wiphy *wiphy = &rdev->wiphy; | |
8481 | bool found = false; | |
8482 | int band, i; | |
8483 | ||
57fbcce3 | 8484 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
dd5b4cc7 FF |
8485 | struct ieee80211_supported_band *sband; |
8486 | ||
8487 | sband = wiphy->bands[band]; | |
8488 | if (!sband) | |
8489 | continue; | |
8490 | ||
8491 | for (i = 0; i < sband->n_bitrates; i++) { | |
8492 | if (sband->bitrates[i].bitrate == rateval) { | |
8493 | mcast_rate[band] = i + 1; | |
8494 | found = true; | |
8495 | break; | |
8496 | } | |
8497 | } | |
8498 | } | |
8499 | ||
8500 | return found; | |
8501 | } | |
8502 | ||
04a773ad JB |
8503 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
8504 | { | |
4c476991 JB |
8505 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8506 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
8507 | struct cfg80211_ibss_params ibss; |
8508 | struct wiphy *wiphy; | |
fffd0934 | 8509 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
8510 | int err; |
8511 | ||
8e30bc55 JB |
8512 | memset(&ibss, 0, sizeof(ibss)); |
8513 | ||
04a773ad JB |
8514 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8515 | return -EINVAL; | |
8516 | ||
683b6d3b | 8517 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
8518 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
8519 | return -EINVAL; | |
8520 | ||
8e30bc55 JB |
8521 | ibss.beacon_interval = 100; |
8522 | ||
12d20fc9 | 8523 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
8e30bc55 JB |
8524 | ibss.beacon_interval = |
8525 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 | 8526 | |
0c317a02 PK |
8527 | err = cfg80211_validate_beacon_int(rdev, NL80211_IFTYPE_ADHOC, |
8528 | ibss.beacon_interval); | |
12d20fc9 PK |
8529 | if (err) |
8530 | return err; | |
8e30bc55 | 8531 | |
4c476991 JB |
8532 | if (!rdev->ops->join_ibss) |
8533 | return -EOPNOTSUPP; | |
04a773ad | 8534 | |
4c476991 JB |
8535 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
8536 | return -EOPNOTSUPP; | |
04a773ad | 8537 | |
79c97e97 | 8538 | wiphy = &rdev->wiphy; |
04a773ad | 8539 | |
39193498 | 8540 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 8541 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
8542 | |
8543 | if (!is_valid_ether_addr(ibss.bssid)) | |
8544 | return -EINVAL; | |
8545 | } | |
04a773ad JB |
8546 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8547 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8548 | ||
8549 | if (info->attrs[NL80211_ATTR_IE]) { | |
8550 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8551 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8552 | } | |
8553 | ||
683b6d3b JB |
8554 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
8555 | if (err) | |
8556 | return err; | |
04a773ad | 8557 | |
174e0cd2 IP |
8558 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
8559 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
8560 | return -EINVAL; |
8561 | ||
2f301ab2 | 8562 | switch (ibss.chandef.width) { |
bf372645 SW |
8563 | case NL80211_CHAN_WIDTH_5: |
8564 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
8565 | case NL80211_CHAN_WIDTH_20_NOHT: |
8566 | break; | |
8567 | case NL80211_CHAN_WIDTH_20: | |
8568 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
8569 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
8570 | return -EINVAL; | |
8571 | break; | |
8572 | case NL80211_CHAN_WIDTH_80: | |
8573 | case NL80211_CHAN_WIDTH_80P80: | |
8574 | case NL80211_CHAN_WIDTH_160: | |
8575 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
8576 | return -EINVAL; | |
8577 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
8578 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
8579 | return -EINVAL; | |
8580 | break; | |
2f301ab2 | 8581 | default: |
c04d6150 | 8582 | return -EINVAL; |
2f301ab2 | 8583 | } |
db9c64cf | 8584 | |
04a773ad | 8585 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
8586 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
8587 | ||
fbd2c8dc TP |
8588 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8589 | u8 *rates = | |
8590 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8591 | int n_rates = | |
8592 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8593 | struct ieee80211_supported_band *sband = | |
683b6d3b | 8594 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 8595 | |
34850ab2 JB |
8596 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
8597 | &ibss.basic_rates); | |
8598 | if (err) | |
8599 | return err; | |
fbd2c8dc | 8600 | } |
dd5b4cc7 | 8601 | |
803768f5 SW |
8602 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
8603 | memcpy(&ibss.ht_capa_mask, | |
8604 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8605 | sizeof(ibss.ht_capa_mask)); | |
8606 | ||
8607 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
8608 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
8609 | return -EINVAL; | |
8610 | memcpy(&ibss.ht_capa, | |
8611 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8612 | sizeof(ibss.ht_capa)); | |
8613 | } | |
8614 | ||
dd5b4cc7 FF |
8615 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8616 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
8617 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8618 | return -EINVAL; | |
fbd2c8dc | 8619 | |
4c476991 | 8620 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
8621 | bool no_ht = false; |
8622 | ||
4c476991 | 8623 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
8624 | info->attrs[NL80211_ATTR_KEYS], |
8625 | &no_ht); | |
4c476991 JB |
8626 | if (IS_ERR(connkeys)) |
8627 | return PTR_ERR(connkeys); | |
de7044ee | 8628 | |
3d9d1d66 JB |
8629 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
8630 | no_ht) { | |
5e950a78 | 8631 | kzfree(connkeys); |
de7044ee SM |
8632 | return -EINVAL; |
8633 | } | |
4c476991 | 8634 | } |
04a773ad | 8635 | |
267335d6 AQ |
8636 | ibss.control_port = |
8637 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
8638 | ||
5336fa88 SW |
8639 | ibss.userspace_handles_dfs = |
8640 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
8641 | ||
4c476991 | 8642 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 8643 | if (err) |
b47f610b | 8644 | kzfree(connkeys); |
04a773ad JB |
8645 | return err; |
8646 | } | |
8647 | ||
8648 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
8649 | { | |
4c476991 JB |
8650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8651 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 8652 | |
4c476991 JB |
8653 | if (!rdev->ops->leave_ibss) |
8654 | return -EOPNOTSUPP; | |
04a773ad | 8655 | |
4c476991 JB |
8656 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
8657 | return -EOPNOTSUPP; | |
04a773ad | 8658 | |
4c476991 | 8659 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
8660 | } |
8661 | ||
f4e583c8 AQ |
8662 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
8663 | { | |
8664 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8665 | struct net_device *dev = info->user_ptr[1]; | |
57fbcce3 | 8666 | int mcast_rate[NUM_NL80211_BANDS]; |
f4e583c8 AQ |
8667 | u32 nla_rate; |
8668 | int err; | |
8669 | ||
8670 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
876dc930 BVB |
8671 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
8672 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) | |
f4e583c8 AQ |
8673 | return -EOPNOTSUPP; |
8674 | ||
8675 | if (!rdev->ops->set_mcast_rate) | |
8676 | return -EOPNOTSUPP; | |
8677 | ||
8678 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
8679 | ||
8680 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
8681 | return -EINVAL; | |
8682 | ||
8683 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
8684 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
8685 | return -EINVAL; | |
8686 | ||
a1056b1b | 8687 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
f4e583c8 AQ |
8688 | |
8689 | return err; | |
8690 | } | |
8691 | ||
ad7e718c JB |
8692 | static struct sk_buff * |
8693 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
8694 | struct wireless_dev *wdev, int approxlen, |
8695 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
8696 | enum nl80211_attrs attr, |
8697 | const struct nl80211_vendor_cmd_info *info, | |
8698 | gfp_t gfp) | |
ad7e718c JB |
8699 | { |
8700 | struct sk_buff *skb; | |
8701 | void *hdr; | |
8702 | struct nlattr *data; | |
8703 | ||
8704 | skb = nlmsg_new(approxlen + 100, gfp); | |
8705 | if (!skb) | |
8706 | return NULL; | |
8707 | ||
8708 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
8709 | if (!hdr) { | |
8710 | kfree_skb(skb); | |
8711 | return NULL; | |
8712 | } | |
8713 | ||
8714 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
8715 | goto nla_put_failure; | |
567ffc35 JB |
8716 | |
8717 | if (info) { | |
8718 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
8719 | info->vendor_id)) | |
8720 | goto nla_put_failure; | |
8721 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
8722 | info->subcmd)) | |
8723 | goto nla_put_failure; | |
8724 | } | |
8725 | ||
6c09e791 | 8726 | if (wdev) { |
2dad624e ND |
8727 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
8728 | wdev_id(wdev), NL80211_ATTR_PAD)) | |
6c09e791 AK |
8729 | goto nla_put_failure; |
8730 | if (wdev->netdev && | |
8731 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
8732 | wdev->netdev->ifindex)) | |
8733 | goto nla_put_failure; | |
8734 | } | |
8735 | ||
ad7e718c | 8736 | data = nla_nest_start(skb, attr); |
76e1fb4b JB |
8737 | if (!data) |
8738 | goto nla_put_failure; | |
ad7e718c JB |
8739 | |
8740 | ((void **)skb->cb)[0] = rdev; | |
8741 | ((void **)skb->cb)[1] = hdr; | |
8742 | ((void **)skb->cb)[2] = data; | |
8743 | ||
8744 | return skb; | |
8745 | ||
8746 | nla_put_failure: | |
8747 | kfree_skb(skb); | |
8748 | return NULL; | |
8749 | } | |
f4e583c8 | 8750 | |
e03ad6ea | 8751 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 8752 | struct wireless_dev *wdev, |
e03ad6ea JB |
8753 | enum nl80211_commands cmd, |
8754 | enum nl80211_attrs attr, | |
8755 | int vendor_event_idx, | |
8756 | int approxlen, gfp_t gfp) | |
8757 | { | |
f26cbf40 | 8758 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
8759 | const struct nl80211_vendor_cmd_info *info; |
8760 | ||
8761 | switch (cmd) { | |
8762 | case NL80211_CMD_TESTMODE: | |
8763 | if (WARN_ON(vendor_event_idx != -1)) | |
8764 | return NULL; | |
8765 | info = NULL; | |
8766 | break; | |
8767 | case NL80211_CMD_VENDOR: | |
8768 | if (WARN_ON(vendor_event_idx < 0 || | |
8769 | vendor_event_idx >= wiphy->n_vendor_events)) | |
8770 | return NULL; | |
8771 | info = &wiphy->vendor_events[vendor_event_idx]; | |
8772 | break; | |
8773 | default: | |
8774 | WARN_ON(1); | |
8775 | return NULL; | |
8776 | } | |
8777 | ||
6c09e791 | 8778 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
e03ad6ea JB |
8779 | cmd, attr, info, gfp); |
8780 | } | |
8781 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
8782 | ||
8783 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
8784 | { | |
8785 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
8786 | void *hdr = ((void **)skb->cb)[1]; | |
8787 | struct nlattr *data = ((void **)skb->cb)[2]; | |
8788 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
8789 | ||
bd8c78e7 JB |
8790 | /* clear CB data for netlink core to own from now on */ |
8791 | memset(skb->cb, 0, sizeof(skb->cb)); | |
8792 | ||
e03ad6ea JB |
8793 | nla_nest_end(skb, data); |
8794 | genlmsg_end(skb, hdr); | |
8795 | ||
8796 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
8797 | mcgrp = NL80211_MCGRP_VENDOR; | |
8798 | ||
8799 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
8800 | mcgrp, gfp); | |
8801 | } | |
8802 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
8803 | ||
aff89a9b | 8804 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
8805 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
8806 | { | |
4c476991 | 8807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
8808 | struct wireless_dev *wdev = |
8809 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
8810 | int err; |
8811 | ||
fc73f11f DS |
8812 | if (!rdev->ops->testmode_cmd) |
8813 | return -EOPNOTSUPP; | |
8814 | ||
8815 | if (IS_ERR(wdev)) { | |
8816 | err = PTR_ERR(wdev); | |
8817 | if (err != -EINVAL) | |
8818 | return err; | |
8819 | wdev = NULL; | |
8820 | } else if (wdev->wiphy != &rdev->wiphy) { | |
8821 | return -EINVAL; | |
8822 | } | |
8823 | ||
aff89a9b JB |
8824 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
8825 | return -EINVAL; | |
8826 | ||
ad7e718c | 8827 | rdev->cur_cmd_info = info; |
fc73f11f | 8828 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
8829 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
8830 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 8831 | rdev->cur_cmd_info = NULL; |
aff89a9b | 8832 | |
aff89a9b JB |
8833 | return err; |
8834 | } | |
8835 | ||
71063f0e WYG |
8836 | static int nl80211_testmode_dump(struct sk_buff *skb, |
8837 | struct netlink_callback *cb) | |
8838 | { | |
00918d33 | 8839 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
8840 | int err; |
8841 | long phy_idx; | |
8842 | void *data = NULL; | |
8843 | int data_len = 0; | |
8844 | ||
5fe231e8 JB |
8845 | rtnl_lock(); |
8846 | ||
71063f0e WYG |
8847 | if (cb->args[0]) { |
8848 | /* | |
8849 | * 0 is a valid index, but not valid for args[0], | |
8850 | * so we need to offset by 1. | |
8851 | */ | |
8852 | phy_idx = cb->args[0] - 1; | |
a4956dca LC |
8853 | |
8854 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); | |
8855 | if (!rdev) { | |
8856 | err = -ENOENT; | |
8857 | goto out_err; | |
8858 | } | |
71063f0e | 8859 | } else { |
c90c39da JB |
8860 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
8861 | ||
71063f0e | 8862 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
fceb6435 JB |
8863 | attrbuf, nl80211_fam.maxattr, |
8864 | nl80211_policy, NULL); | |
71063f0e | 8865 | if (err) |
5fe231e8 | 8866 | goto out_err; |
00918d33 | 8867 | |
c90c39da | 8868 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
2bd7e35d | 8869 | if (IS_ERR(rdev)) { |
5fe231e8 JB |
8870 | err = PTR_ERR(rdev); |
8871 | goto out_err; | |
00918d33 | 8872 | } |
2bd7e35d | 8873 | phy_idx = rdev->wiphy_idx; |
2bd7e35d | 8874 | |
c90c39da JB |
8875 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
8876 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; | |
71063f0e WYG |
8877 | } |
8878 | ||
8879 | if (cb->args[1]) { | |
8880 | data = nla_data((void *)cb->args[1]); | |
8881 | data_len = nla_len((void *)cb->args[1]); | |
8882 | } | |
8883 | ||
00918d33 | 8884 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
8885 | err = -EOPNOTSUPP; |
8886 | goto out_err; | |
8887 | } | |
8888 | ||
8889 | while (1) { | |
15e47304 | 8890 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
8891 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8892 | NL80211_CMD_TESTMODE); | |
8893 | struct nlattr *tmdata; | |
8894 | ||
cb35fba3 DC |
8895 | if (!hdr) |
8896 | break; | |
8897 | ||
9360ffd1 | 8898 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
8899 | genlmsg_cancel(skb, hdr); |
8900 | break; | |
8901 | } | |
8902 | ||
8903 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
8904 | if (!tmdata) { | |
8905 | genlmsg_cancel(skb, hdr); | |
8906 | break; | |
8907 | } | |
e35e4d28 | 8908 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
8909 | nla_nest_end(skb, tmdata); |
8910 | ||
8911 | if (err == -ENOBUFS || err == -ENOENT) { | |
8912 | genlmsg_cancel(skb, hdr); | |
8913 | break; | |
8914 | } else if (err) { | |
8915 | genlmsg_cancel(skb, hdr); | |
8916 | goto out_err; | |
8917 | } | |
8918 | ||
8919 | genlmsg_end(skb, hdr); | |
8920 | } | |
8921 | ||
8922 | err = skb->len; | |
8923 | /* see above */ | |
8924 | cb->args[0] = phy_idx + 1; | |
8925 | out_err: | |
5fe231e8 | 8926 | rtnl_unlock(); |
71063f0e WYG |
8927 | return err; |
8928 | } | |
aff89a9b JB |
8929 | #endif |
8930 | ||
b23aa676 SO |
8931 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
8932 | { | |
4c476991 JB |
8933 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8934 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
8935 | struct cfg80211_connect_params connect; |
8936 | struct wiphy *wiphy; | |
fffd0934 | 8937 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
8938 | int err; |
8939 | ||
8940 | memset(&connect, 0, sizeof(connect)); | |
8941 | ||
8942 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8943 | return -EINVAL; | |
8944 | ||
8945 | if (!info->attrs[NL80211_ATTR_SSID] || | |
8946 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
8947 | return -EINVAL; | |
8948 | ||
8949 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
8950 | connect.auth_type = | |
8951 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
8952 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
8953 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
8954 | return -EINVAL; |
8955 | } else | |
8956 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
8957 | ||
8958 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
8959 | ||
3a00df57 AS |
8960 | if (info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS] && |
8961 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
8962 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
8963 | return -EINVAL; | |
8964 | connect.want_1x = info->attrs[NL80211_ATTR_WANT_1X_4WAY_HS]; | |
8965 | ||
c0692b8f | 8966 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 8967 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
8968 | if (err) |
8969 | return err; | |
b23aa676 | 8970 | |
074ac8df | 8971 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8972 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8973 | return -EOPNOTSUPP; | |
b23aa676 | 8974 | |
79c97e97 | 8975 | wiphy = &rdev->wiphy; |
b23aa676 | 8976 | |
4486ea98 BS |
8977 | connect.bg_scan_period = -1; |
8978 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
8979 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
8980 | connect.bg_scan_period = | |
8981 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
8982 | } | |
8983 | ||
b23aa676 SO |
8984 | if (info->attrs[NL80211_ATTR_MAC]) |
8985 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
8986 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
8987 | connect.bssid_hint = | |
8988 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
8989 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8990 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8991 | ||
8992 | if (info->attrs[NL80211_ATTR_IE]) { | |
8993 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8994 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8995 | } | |
8996 | ||
cee00a95 JM |
8997 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
8998 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
65026002 EG |
8999 | if (connect.mfp == NL80211_MFP_OPTIONAL && |
9000 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
9001 | NL80211_EXT_FEATURE_MFP_OPTIONAL)) | |
9002 | return -EOPNOTSUPP; | |
9003 | ||
cee00a95 | 9004 | if (connect.mfp != NL80211_MFP_REQUIRED && |
65026002 EG |
9005 | connect.mfp != NL80211_MFP_NO && |
9006 | connect.mfp != NL80211_MFP_OPTIONAL) | |
cee00a95 JM |
9007 | return -EINVAL; |
9008 | } else { | |
9009 | connect.mfp = NL80211_MFP_NO; | |
9010 | } | |
9011 | ||
ba6fbacf JM |
9012 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
9013 | connect.prev_bssid = | |
9014 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
9015 | ||
b23aa676 | 9016 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
9017 | connect.channel = nl80211_get_valid_chan( |
9018 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
9019 | if (!connect.channel) | |
1df4a510 JM |
9020 | return -EINVAL; |
9021 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
9022 | connect.channel_hint = nl80211_get_valid_chan( |
9023 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
9024 | if (!connect.channel_hint) | |
4c476991 | 9025 | return -EINVAL; |
b23aa676 SO |
9026 | } |
9027 | ||
fffd0934 JB |
9028 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
9029 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 9030 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
9031 | if (IS_ERR(connkeys)) |
9032 | return PTR_ERR(connkeys); | |
fffd0934 JB |
9033 | } |
9034 | ||
7e7c8926 BG |
9035 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
9036 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
9037 | ||
9038 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
9039 | memcpy(&connect.ht_capa_mask, | |
9040 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
9041 | sizeof(connect.ht_capa_mask)); | |
9042 | ||
9043 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 9044 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 9045 | kzfree(connkeys); |
7e7c8926 | 9046 | return -EINVAL; |
b4e4f47e | 9047 | } |
7e7c8926 BG |
9048 | memcpy(&connect.ht_capa, |
9049 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
9050 | sizeof(connect.ht_capa)); | |
9051 | } | |
9052 | ||
ee2aca34 JB |
9053 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
9054 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
9055 | ||
9056 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
9057 | memcpy(&connect.vht_capa_mask, | |
9058 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
9059 | sizeof(connect.vht_capa_mask)); | |
9060 | ||
9061 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
9062 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 9063 | kzfree(connkeys); |
ee2aca34 JB |
9064 | return -EINVAL; |
9065 | } | |
9066 | memcpy(&connect.vht_capa, | |
9067 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
9068 | sizeof(connect.vht_capa)); | |
9069 | } | |
9070 | ||
bab5ab7d | 9071 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
9072 | if (!((rdev->wiphy.features & |
9073 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
9074 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
9075 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
9076 | NL80211_EXT_FEATURE_RRM)) { | |
707554b4 | 9077 | kzfree(connkeys); |
bab5ab7d | 9078 | return -EINVAL; |
707554b4 | 9079 | } |
bab5ab7d AK |
9080 | connect.flags |= ASSOC_REQ_USE_RRM; |
9081 | } | |
9082 | ||
34d50519 | 9083 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
57fbcce3 | 9084 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
34d50519 LD |
9085 | kzfree(connkeys); |
9086 | return -EOPNOTSUPP; | |
9087 | } | |
9088 | ||
38de03d2 AS |
9089 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
9090 | /* bss selection makes no sense if bssid is set */ | |
9091 | if (connect.bssid) { | |
9092 | kzfree(connkeys); | |
9093 | return -EINVAL; | |
9094 | } | |
9095 | ||
9096 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], | |
9097 | wiphy, &connect.bss_select); | |
9098 | if (err) { | |
9099 | kzfree(connkeys); | |
9100 | return err; | |
9101 | } | |
9102 | } | |
9103 | ||
a3caf744 VK |
9104 | if (wiphy_ext_feature_isset(&rdev->wiphy, |
9105 | NL80211_EXT_FEATURE_FILS_SK_OFFLOAD) && | |
9106 | info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] && | |
9107 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] && | |
9108 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] && | |
9109 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
9110 | connect.fils_erp_username = | |
9111 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
9112 | connect.fils_erp_username_len = | |
9113 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_USERNAME]); | |
9114 | connect.fils_erp_realm = | |
9115 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
9116 | connect.fils_erp_realm_len = | |
9117 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_REALM]); | |
9118 | connect.fils_erp_next_seq_num = | |
9119 | nla_get_u16( | |
9120 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM]); | |
9121 | connect.fils_erp_rrk = | |
9122 | nla_data(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
9123 | connect.fils_erp_rrk_len = | |
9124 | nla_len(info->attrs[NL80211_ATTR_FILS_ERP_RRK]); | |
9125 | } else if (info->attrs[NL80211_ATTR_FILS_ERP_USERNAME] || | |
9126 | info->attrs[NL80211_ATTR_FILS_ERP_REALM] || | |
9127 | info->attrs[NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM] || | |
9128 | info->attrs[NL80211_ATTR_FILS_ERP_RRK]) { | |
9129 | kzfree(connkeys); | |
9130 | return -EINVAL; | |
9131 | } | |
9132 | ||
83739b03 | 9133 | wdev_lock(dev->ieee80211_ptr); |
bd2522b1 | 9134 | |
4ce2bd9c JM |
9135 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
9136 | connect.prev_bssid); | |
fffd0934 | 9137 | if (err) |
b47f610b | 9138 | kzfree(connkeys); |
bd2522b1 AZ |
9139 | |
9140 | if (!err && info->attrs[NL80211_ATTR_SOCKET_OWNER]) { | |
9141 | dev->ieee80211_ptr->conn_owner_nlportid = info->snd_portid; | |
9142 | if (connect.bssid) | |
9143 | memcpy(dev->ieee80211_ptr->disconnect_bssid, | |
9144 | connect.bssid, ETH_ALEN); | |
9145 | else | |
9146 | memset(dev->ieee80211_ptr->disconnect_bssid, | |
9147 | 0, ETH_ALEN); | |
9148 | } | |
9149 | ||
9150 | wdev_unlock(dev->ieee80211_ptr); | |
9151 | ||
b23aa676 SO |
9152 | return err; |
9153 | } | |
9154 | ||
088e8df8 | 9155 | static int nl80211_update_connect_params(struct sk_buff *skb, |
9156 | struct genl_info *info) | |
9157 | { | |
9158 | struct cfg80211_connect_params connect = {}; | |
9159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9160 | struct net_device *dev = info->user_ptr[1]; | |
9161 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9162 | u32 changed = 0; | |
9163 | int ret; | |
9164 | ||
9165 | if (!rdev->ops->update_connect_params) | |
9166 | return -EOPNOTSUPP; | |
9167 | ||
9168 | if (info->attrs[NL80211_ATTR_IE]) { | |
9169 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9170 | return -EINVAL; | |
9171 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9172 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9173 | changed |= UPDATE_ASSOC_IES; | |
9174 | } | |
9175 | ||
9176 | wdev_lock(dev->ieee80211_ptr); | |
9177 | if (!wdev->current_bss) | |
9178 | ret = -ENOLINK; | |
9179 | else | |
9180 | ret = rdev_update_connect_params(rdev, dev, &connect, changed); | |
9181 | wdev_unlock(dev->ieee80211_ptr); | |
9182 | ||
9183 | return ret; | |
9184 | } | |
9185 | ||
b23aa676 SO |
9186 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) |
9187 | { | |
4c476991 JB |
9188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
9189 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 9190 | u16 reason; |
83739b03 | 9191 | int ret; |
b23aa676 SO |
9192 | |
9193 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
9194 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
9195 | else | |
9196 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
9197 | ||
9198 | if (reason == 0) | |
9199 | return -EINVAL; | |
9200 | ||
074ac8df | 9201 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9202 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9203 | return -EOPNOTSUPP; | |
b23aa676 | 9204 | |
83739b03 JB |
9205 | wdev_lock(dev->ieee80211_ptr); |
9206 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
9207 | wdev_unlock(dev->ieee80211_ptr); | |
9208 | return ret; | |
b23aa676 SO |
9209 | } |
9210 | ||
463d0183 JB |
9211 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
9212 | { | |
4c476991 | 9213 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
9214 | struct net *net; |
9215 | int err; | |
463d0183 | 9216 | |
4b681c82 VK |
9217 | if (info->attrs[NL80211_ATTR_PID]) { |
9218 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
9219 | ||
9220 | net = get_net_ns_by_pid(pid); | |
9221 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
9222 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 9223 | |
4b681c82 VK |
9224 | net = get_net_ns_by_fd(fd); |
9225 | } else { | |
9226 | return -EINVAL; | |
9227 | } | |
463d0183 | 9228 | |
4c476991 JB |
9229 | if (IS_ERR(net)) |
9230 | return PTR_ERR(net); | |
463d0183 JB |
9231 | |
9232 | err = 0; | |
9233 | ||
9234 | /* check if anything to do */ | |
4c476991 JB |
9235 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
9236 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 9237 | |
463d0183 | 9238 | put_net(net); |
463d0183 JB |
9239 | return err; |
9240 | } | |
9241 | ||
67fbb16b SO |
9242 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
9243 | { | |
4c476991 | 9244 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
9245 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
9246 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 9247 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
9248 | struct cfg80211_pmksa pmksa; |
9249 | ||
9250 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
9251 | ||
67fbb16b SO |
9252 | if (!info->attrs[NL80211_ATTR_PMKID]) |
9253 | return -EINVAL; | |
9254 | ||
67fbb16b | 9255 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
a3caf744 VK |
9256 | |
9257 | if (info->attrs[NL80211_ATTR_MAC]) { | |
9258 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9259 | } else if (info->attrs[NL80211_ATTR_SSID] && | |
9260 | info->attrs[NL80211_ATTR_FILS_CACHE_ID] && | |
9261 | (info->genlhdr->cmd == NL80211_CMD_DEL_PMKSA || | |
9262 | info->attrs[NL80211_ATTR_PMK])) { | |
9263 | pmksa.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
9264 | pmksa.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
9265 | pmksa.cache_id = | |
9266 | nla_data(info->attrs[NL80211_ATTR_FILS_CACHE_ID]); | |
9267 | } else { | |
9268 | return -EINVAL; | |
9269 | } | |
9270 | if (info->attrs[NL80211_ATTR_PMK]) { | |
9271 | pmksa.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
9272 | pmksa.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); | |
9273 | } | |
67fbb16b | 9274 | |
074ac8df | 9275 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9276 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9277 | return -EOPNOTSUPP; | |
67fbb16b SO |
9278 | |
9279 | switch (info->genlhdr->cmd) { | |
9280 | case NL80211_CMD_SET_PMKSA: | |
9281 | rdev_ops = rdev->ops->set_pmksa; | |
9282 | break; | |
9283 | case NL80211_CMD_DEL_PMKSA: | |
9284 | rdev_ops = rdev->ops->del_pmksa; | |
9285 | break; | |
9286 | default: | |
9287 | WARN_ON(1); | |
9288 | break; | |
9289 | } | |
9290 | ||
4c476991 JB |
9291 | if (!rdev_ops) |
9292 | return -EOPNOTSUPP; | |
67fbb16b | 9293 | |
4c476991 | 9294 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
9295 | } |
9296 | ||
9297 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
9298 | { | |
4c476991 JB |
9299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
9300 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 9301 | |
074ac8df | 9302 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9303 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9304 | return -EOPNOTSUPP; | |
67fbb16b | 9305 | |
4c476991 JB |
9306 | if (!rdev->ops->flush_pmksa) |
9307 | return -EOPNOTSUPP; | |
67fbb16b | 9308 | |
e35e4d28 | 9309 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
9310 | } |
9311 | ||
109086ce AN |
9312 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
9313 | { | |
9314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9315 | struct net_device *dev = info->user_ptr[1]; | |
9316 | u8 action_code, dialog_token; | |
df942e7b | 9317 | u32 peer_capability = 0; |
109086ce AN |
9318 | u16 status_code; |
9319 | u8 *peer; | |
31fa97c5 | 9320 | bool initiator; |
109086ce AN |
9321 | |
9322 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
9323 | !rdev->ops->tdls_mgmt) | |
9324 | return -EOPNOTSUPP; | |
9325 | ||
9326 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
9327 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
9328 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
9329 | !info->attrs[NL80211_ATTR_IE] || | |
9330 | !info->attrs[NL80211_ATTR_MAC]) | |
9331 | return -EINVAL; | |
9332 | ||
9333 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9334 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
9335 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
9336 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 9337 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
9338 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
9339 | peer_capability = | |
9340 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 9341 | |
e35e4d28 | 9342 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 9343 | dialog_token, status_code, peer_capability, |
31fa97c5 | 9344 | initiator, |
e35e4d28 HG |
9345 | nla_data(info->attrs[NL80211_ATTR_IE]), |
9346 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
9347 | } |
9348 | ||
9349 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
9350 | { | |
9351 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9352 | struct net_device *dev = info->user_ptr[1]; | |
9353 | enum nl80211_tdls_operation operation; | |
9354 | u8 *peer; | |
9355 | ||
9356 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
9357 | !rdev->ops->tdls_oper) | |
9358 | return -EOPNOTSUPP; | |
9359 | ||
9360 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
9361 | !info->attrs[NL80211_ATTR_MAC]) | |
9362 | return -EINVAL; | |
9363 | ||
9364 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
9365 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9366 | ||
e35e4d28 | 9367 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
9368 | } |
9369 | ||
9588bbd5 JM |
9370 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
9371 | struct genl_info *info) | |
9372 | { | |
4c476991 | 9373 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 9374 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 9375 | struct cfg80211_chan_def chandef; |
34373d12 | 9376 | const struct cfg80211_chan_def *compat_chandef; |
9588bbd5 JM |
9377 | struct sk_buff *msg; |
9378 | void *hdr; | |
9379 | u64 cookie; | |
683b6d3b | 9380 | u32 duration; |
9588bbd5 JM |
9381 | int err; |
9382 | ||
9383 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
9384 | !info->attrs[NL80211_ATTR_DURATION]) | |
9385 | return -EINVAL; | |
9386 | ||
9387 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
9388 | ||
ebf348fc JB |
9389 | if (!rdev->ops->remain_on_channel || |
9390 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
9391 | return -EOPNOTSUPP; | |
9392 | ||
9588bbd5 | 9393 | /* |
ebf348fc JB |
9394 | * We should be on that channel for at least a minimum amount of |
9395 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 9396 | */ |
ebf348fc | 9397 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 9398 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
9399 | return -EINVAL; |
9400 | ||
683b6d3b JB |
9401 | err = nl80211_parse_chandef(rdev, info, &chandef); |
9402 | if (err) | |
9403 | return err; | |
9588bbd5 | 9404 | |
34373d12 VT |
9405 | wdev_lock(wdev); |
9406 | if (!cfg80211_off_channel_oper_allowed(wdev) && | |
9407 | !cfg80211_chandef_identical(&wdev->chandef, &chandef)) { | |
9408 | compat_chandef = cfg80211_chandef_compatible(&wdev->chandef, | |
9409 | &chandef); | |
9410 | if (compat_chandef != &chandef) { | |
9411 | wdev_unlock(wdev); | |
9412 | return -EBUSY; | |
9413 | } | |
9414 | } | |
9415 | wdev_unlock(wdev); | |
9416 | ||
9588bbd5 | 9417 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
9418 | if (!msg) |
9419 | return -ENOMEM; | |
9588bbd5 | 9420 | |
15e47304 | 9421 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 9422 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
9423 | if (!hdr) { |
9424 | err = -ENOBUFS; | |
9588bbd5 JM |
9425 | goto free_msg; |
9426 | } | |
9427 | ||
683b6d3b JB |
9428 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
9429 | duration, &cookie); | |
9588bbd5 JM |
9430 | |
9431 | if (err) | |
9432 | goto free_msg; | |
9433 | ||
2dad624e ND |
9434 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
9435 | NL80211_ATTR_PAD)) | |
9360ffd1 | 9436 | goto nla_put_failure; |
9588bbd5 JM |
9437 | |
9438 | genlmsg_end(msg, hdr); | |
4c476991 JB |
9439 | |
9440 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
9441 | |
9442 | nla_put_failure: | |
9443 | err = -ENOBUFS; | |
9444 | free_msg: | |
9445 | nlmsg_free(msg); | |
9588bbd5 JM |
9446 | return err; |
9447 | } | |
9448 | ||
9449 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
9450 | struct genl_info *info) | |
9451 | { | |
4c476991 | 9452 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 9453 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 9454 | u64 cookie; |
9588bbd5 JM |
9455 | |
9456 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
9457 | return -EINVAL; | |
9458 | ||
4c476991 JB |
9459 | if (!rdev->ops->cancel_remain_on_channel) |
9460 | return -EOPNOTSUPP; | |
9588bbd5 | 9461 | |
9588bbd5 JM |
9462 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
9463 | ||
e35e4d28 | 9464 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
9465 | } |
9466 | ||
13ae75b1 JM |
9467 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
9468 | struct genl_info *info) | |
9469 | { | |
13ae75b1 | 9470 | struct cfg80211_bitrate_mask mask; |
a7c7fbff | 9471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 9472 | struct net_device *dev = info->user_ptr[1]; |
a7c7fbff | 9473 | int err; |
13ae75b1 | 9474 | |
4c476991 JB |
9475 | if (!rdev->ops->set_bitrate_mask) |
9476 | return -EOPNOTSUPP; | |
13ae75b1 | 9477 | |
a7c7fbff PK |
9478 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
9479 | if (err) | |
9480 | return err; | |
13ae75b1 | 9481 | |
e35e4d28 | 9482 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
9483 | } |
9484 | ||
2e161f78 | 9485 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 9486 | { |
4c476991 | 9487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 9488 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 9489 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
9490 | |
9491 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
9492 | return -EINVAL; | |
9493 | ||
2e161f78 JB |
9494 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
9495 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 9496 | |
71bbc994 JB |
9497 | switch (wdev->iftype) { |
9498 | case NL80211_IFTYPE_STATION: | |
9499 | case NL80211_IFTYPE_ADHOC: | |
9500 | case NL80211_IFTYPE_P2P_CLIENT: | |
9501 | case NL80211_IFTYPE_AP: | |
9502 | case NL80211_IFTYPE_AP_VLAN: | |
9503 | case NL80211_IFTYPE_MESH_POINT: | |
9504 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 9505 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 9506 | break; |
cb3b7d87 | 9507 | case NL80211_IFTYPE_NAN: |
71bbc994 | 9508 | default: |
4c476991 | 9509 | return -EOPNOTSUPP; |
71bbc994 | 9510 | } |
026331c4 JM |
9511 | |
9512 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
9513 | if (!rdev->ops->mgmt_tx) |
9514 | return -EOPNOTSUPP; | |
026331c4 | 9515 | |
15e47304 | 9516 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
9517 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
9518 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
9519 | } |
9520 | ||
2e161f78 | 9521 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 9522 | { |
4c476991 | 9523 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 9524 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 9525 | struct cfg80211_chan_def chandef; |
026331c4 | 9526 | int err; |
d64d373f | 9527 | void *hdr = NULL; |
026331c4 | 9528 | u64 cookie; |
e247bd90 | 9529 | struct sk_buff *msg = NULL; |
b176e629 AO |
9530 | struct cfg80211_mgmt_tx_params params = { |
9531 | .dont_wait_for_ack = | |
9532 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
9533 | }; | |
026331c4 | 9534 | |
683b6d3b | 9535 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
9536 | return -EINVAL; |
9537 | ||
4c476991 JB |
9538 | if (!rdev->ops->mgmt_tx) |
9539 | return -EOPNOTSUPP; | |
026331c4 | 9540 | |
71bbc994 | 9541 | switch (wdev->iftype) { |
ea141b75 AQ |
9542 | case NL80211_IFTYPE_P2P_DEVICE: |
9543 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
9544 | return -EINVAL; | |
71bbc994 JB |
9545 | case NL80211_IFTYPE_STATION: |
9546 | case NL80211_IFTYPE_ADHOC: | |
9547 | case NL80211_IFTYPE_P2P_CLIENT: | |
9548 | case NL80211_IFTYPE_AP: | |
9549 | case NL80211_IFTYPE_AP_VLAN: | |
9550 | case NL80211_IFTYPE_MESH_POINT: | |
9551 | case NL80211_IFTYPE_P2P_GO: | |
9552 | break; | |
cb3b7d87 | 9553 | case NL80211_IFTYPE_NAN: |
71bbc994 | 9554 | default: |
4c476991 | 9555 | return -EOPNOTSUPP; |
71bbc994 | 9556 | } |
026331c4 | 9557 | |
f7ca38df | 9558 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 9559 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 9560 | return -EINVAL; |
b176e629 | 9561 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
9562 | |
9563 | /* | |
9564 | * We should wait on the channel for at least a minimum amount | |
9565 | * of time (10ms) but no longer than the driver supports. | |
9566 | */ | |
b176e629 AO |
9567 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
9568 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc | 9569 | return -EINVAL; |
f7ca38df JB |
9570 | } |
9571 | ||
b176e629 | 9572 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 9573 | |
b176e629 | 9574 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
9575 | return -EINVAL; |
9576 | ||
b176e629 | 9577 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 9578 | |
ea141b75 AQ |
9579 | /* get the channel if any has been specified, otherwise pass NULL to |
9580 | * the driver. The latter will use the current one | |
9581 | */ | |
9582 | chandef.chan = NULL; | |
9583 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
9584 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
9585 | if (err) | |
9586 | return err; | |
9587 | } | |
9588 | ||
b176e629 | 9589 | if (!chandef.chan && params.offchan) |
ea141b75 | 9590 | return -EINVAL; |
026331c4 | 9591 | |
34373d12 VT |
9592 | wdev_lock(wdev); |
9593 | if (params.offchan && !cfg80211_off_channel_oper_allowed(wdev)) { | |
9594 | wdev_unlock(wdev); | |
9595 | return -EBUSY; | |
9596 | } | |
9597 | wdev_unlock(wdev); | |
9598 | ||
34d22ce2 AO |
9599 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
9600 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
9601 | ||
9602 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
9603 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
9604 | int i; | |
9605 | ||
9606 | if (len % sizeof(u16)) | |
9607 | return -EINVAL; | |
9608 | ||
9609 | params.n_csa_offsets = len / sizeof(u16); | |
9610 | params.csa_offsets = | |
9611 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
9612 | ||
9613 | /* check that all the offsets fit the frame */ | |
9614 | for (i = 0; i < params.n_csa_offsets; i++) { | |
9615 | if (params.csa_offsets[i] >= params.len) | |
9616 | return -EINVAL; | |
9617 | } | |
9618 | } | |
9619 | ||
b176e629 | 9620 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
9621 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
9622 | if (!msg) | |
9623 | return -ENOMEM; | |
026331c4 | 9624 | |
15e47304 | 9625 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 9626 | NL80211_CMD_FRAME); |
cb35fba3 DC |
9627 | if (!hdr) { |
9628 | err = -ENOBUFS; | |
e247bd90 JB |
9629 | goto free_msg; |
9630 | } | |
026331c4 | 9631 | } |
e247bd90 | 9632 | |
b176e629 AO |
9633 | params.chan = chandef.chan; |
9634 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
9635 | if (err) |
9636 | goto free_msg; | |
9637 | ||
e247bd90 | 9638 | if (msg) { |
2dad624e ND |
9639 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
9640 | NL80211_ATTR_PAD)) | |
9360ffd1 | 9641 | goto nla_put_failure; |
026331c4 | 9642 | |
e247bd90 JB |
9643 | genlmsg_end(msg, hdr); |
9644 | return genlmsg_reply(msg, info); | |
9645 | } | |
9646 | ||
9647 | return 0; | |
026331c4 JM |
9648 | |
9649 | nla_put_failure: | |
9650 | err = -ENOBUFS; | |
9651 | free_msg: | |
9652 | nlmsg_free(msg); | |
026331c4 JM |
9653 | return err; |
9654 | } | |
9655 | ||
f7ca38df JB |
9656 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
9657 | { | |
9658 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 9659 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
9660 | u64 cookie; |
9661 | ||
9662 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
9663 | return -EINVAL; | |
9664 | ||
9665 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
9666 | return -EOPNOTSUPP; | |
9667 | ||
71bbc994 JB |
9668 | switch (wdev->iftype) { |
9669 | case NL80211_IFTYPE_STATION: | |
9670 | case NL80211_IFTYPE_ADHOC: | |
9671 | case NL80211_IFTYPE_P2P_CLIENT: | |
9672 | case NL80211_IFTYPE_AP: | |
9673 | case NL80211_IFTYPE_AP_VLAN: | |
9674 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 9675 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 9676 | break; |
cb3b7d87 | 9677 | case NL80211_IFTYPE_NAN: |
71bbc994 | 9678 | default: |
f7ca38df | 9679 | return -EOPNOTSUPP; |
71bbc994 | 9680 | } |
f7ca38df JB |
9681 | |
9682 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
9683 | ||
e35e4d28 | 9684 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
9685 | } |
9686 | ||
ffb9eb3d KV |
9687 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
9688 | { | |
4c476991 | 9689 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 9690 | struct wireless_dev *wdev; |
4c476991 | 9691 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
9692 | u8 ps_state; |
9693 | bool state; | |
9694 | int err; | |
9695 | ||
4c476991 JB |
9696 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
9697 | return -EINVAL; | |
ffb9eb3d KV |
9698 | |
9699 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
9700 | ||
4c476991 JB |
9701 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
9702 | return -EINVAL; | |
ffb9eb3d KV |
9703 | |
9704 | wdev = dev->ieee80211_ptr; | |
9705 | ||
4c476991 JB |
9706 | if (!rdev->ops->set_power_mgmt) |
9707 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
9708 | |
9709 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
9710 | ||
9711 | if (state == wdev->ps) | |
4c476991 | 9712 | return 0; |
ffb9eb3d | 9713 | |
e35e4d28 | 9714 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
9715 | if (!err) |
9716 | wdev->ps = state; | |
ffb9eb3d KV |
9717 | return err; |
9718 | } | |
9719 | ||
9720 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
9721 | { | |
4c476991 | 9722 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
9723 | enum nl80211_ps_state ps_state; |
9724 | struct wireless_dev *wdev; | |
4c476991 | 9725 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
9726 | struct sk_buff *msg; |
9727 | void *hdr; | |
9728 | int err; | |
9729 | ||
ffb9eb3d KV |
9730 | wdev = dev->ieee80211_ptr; |
9731 | ||
4c476991 JB |
9732 | if (!rdev->ops->set_power_mgmt) |
9733 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
9734 | |
9735 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
9736 | if (!msg) |
9737 | return -ENOMEM; | |
ffb9eb3d | 9738 | |
15e47304 | 9739 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
9740 | NL80211_CMD_GET_POWER_SAVE); |
9741 | if (!hdr) { | |
4c476991 | 9742 | err = -ENOBUFS; |
ffb9eb3d KV |
9743 | goto free_msg; |
9744 | } | |
9745 | ||
9746 | if (wdev->ps) | |
9747 | ps_state = NL80211_PS_ENABLED; | |
9748 | else | |
9749 | ps_state = NL80211_PS_DISABLED; | |
9750 | ||
9360ffd1 DM |
9751 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
9752 | goto nla_put_failure; | |
ffb9eb3d KV |
9753 | |
9754 | genlmsg_end(msg, hdr); | |
4c476991 | 9755 | return genlmsg_reply(msg, info); |
ffb9eb3d | 9756 | |
4c476991 | 9757 | nla_put_failure: |
ffb9eb3d | 9758 | err = -ENOBUFS; |
4c476991 | 9759 | free_msg: |
ffb9eb3d | 9760 | nlmsg_free(msg); |
ffb9eb3d KV |
9761 | return err; |
9762 | } | |
9763 | ||
94e860f1 JB |
9764 | static const struct nla_policy |
9765 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
4a4b8169 | 9766 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_BINARY }, |
d6dc1a38 JO |
9767 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, |
9768 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
9769 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
9770 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
9771 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
bee427b8 | 9772 | [NL80211_ATTR_CQM_RSSI_LEVEL] = { .type = NLA_S32 }, |
d6dc1a38 JO |
9773 | }; |
9774 | ||
84f10708 | 9775 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 9776 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
9777 | { |
9778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 9779 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 9780 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 9781 | |
d9d8b019 | 9782 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
9783 | return -EINVAL; |
9784 | ||
84f10708 TP |
9785 | if (!rdev->ops->set_cqm_txe_config) |
9786 | return -EOPNOTSUPP; | |
9787 | ||
9788 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
9789 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
9790 | return -EOPNOTSUPP; | |
9791 | ||
e35e4d28 | 9792 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
9793 | } |
9794 | ||
4a4b8169 AZ |
9795 | static int cfg80211_cqm_rssi_update(struct cfg80211_registered_device *rdev, |
9796 | struct net_device *dev) | |
9797 | { | |
9798 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9799 | s32 last, low, high; | |
9800 | u32 hyst; | |
9801 | int i, n; | |
9802 | int err; | |
9803 | ||
9804 | /* RSSI reporting disabled? */ | |
9805 | if (!wdev->cqm_config) | |
9806 | return rdev_set_cqm_rssi_range_config(rdev, dev, 0, 0); | |
9807 | ||
9808 | /* | |
9809 | * Obtain current RSSI value if possible, if not and no RSSI threshold | |
9810 | * event has been received yet, we should receive an event after a | |
9811 | * connection is established and enough beacons received to calculate | |
9812 | * the average. | |
9813 | */ | |
9814 | if (!wdev->cqm_config->last_rssi_event_value && wdev->current_bss && | |
9815 | rdev->ops->get_station) { | |
5762d7d3 | 9816 | struct station_info sinfo = {}; |
4a4b8169 AZ |
9817 | u8 *mac_addr; |
9818 | ||
9819 | mac_addr = wdev->current_bss->pub.bssid; | |
9820 | ||
9821 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); | |
9822 | if (err) | |
9823 | return err; | |
9824 | ||
9825 | if (sinfo.filled & BIT(NL80211_STA_INFO_BEACON_SIGNAL_AVG)) | |
9826 | wdev->cqm_config->last_rssi_event_value = | |
9827 | (s8) sinfo.rx_beacon_signal_avg; | |
9828 | } | |
9829 | ||
9830 | last = wdev->cqm_config->last_rssi_event_value; | |
9831 | hyst = wdev->cqm_config->rssi_hyst; | |
9832 | n = wdev->cqm_config->n_rssi_thresholds; | |
9833 | ||
9834 | for (i = 0; i < n; i++) | |
9835 | if (last < wdev->cqm_config->rssi_thresholds[i]) | |
9836 | break; | |
9837 | ||
9838 | low = i > 0 ? | |
9839 | (wdev->cqm_config->rssi_thresholds[i - 1] - hyst) : S32_MIN; | |
9840 | high = i < n ? | |
9841 | (wdev->cqm_config->rssi_thresholds[i] + hyst - 1) : S32_MAX; | |
9842 | ||
9843 | return rdev_set_cqm_rssi_range_config(rdev, dev, low, high); | |
9844 | } | |
9845 | ||
d6dc1a38 | 9846 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
4a4b8169 AZ |
9847 | const s32 *thresholds, int n_thresholds, |
9848 | u32 hysteresis) | |
d6dc1a38 | 9849 | { |
4c476991 | 9850 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 9851 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 9852 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
4a4b8169 AZ |
9853 | int i, err; |
9854 | s32 prev = S32_MIN; | |
d6dc1a38 | 9855 | |
4a4b8169 AZ |
9856 | /* Check all values negative and sorted */ |
9857 | for (i = 0; i < n_thresholds; i++) { | |
9858 | if (thresholds[i] > 0 || thresholds[i] <= prev) | |
9859 | return -EINVAL; | |
d6dc1a38 | 9860 | |
4a4b8169 AZ |
9861 | prev = thresholds[i]; |
9862 | } | |
d6dc1a38 | 9863 | |
074ac8df | 9864 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9865 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9866 | return -EOPNOTSUPP; | |
d6dc1a38 | 9867 | |
4a4b8169 AZ |
9868 | wdev_lock(wdev); |
9869 | cfg80211_cqm_config_free(wdev); | |
9870 | wdev_unlock(wdev); | |
9871 | ||
9872 | if (n_thresholds <= 1 && rdev->ops->set_cqm_rssi_config) { | |
9873 | if (n_thresholds == 0 || thresholds[0] == 0) /* Disabling */ | |
9874 | return rdev_set_cqm_rssi_config(rdev, dev, 0, 0); | |
9875 | ||
9876 | return rdev_set_cqm_rssi_config(rdev, dev, | |
9877 | thresholds[0], hysteresis); | |
9878 | } | |
9879 | ||
9880 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
9881 | NL80211_EXT_FEATURE_CQM_RSSI_LIST)) | |
9882 | return -EOPNOTSUPP; | |
9883 | ||
9884 | if (n_thresholds == 1 && thresholds[0] == 0) /* Disabling */ | |
9885 | n_thresholds = 0; | |
9886 | ||
9887 | wdev_lock(wdev); | |
9888 | if (n_thresholds) { | |
9889 | struct cfg80211_cqm_config *cqm_config; | |
9890 | ||
9891 | cqm_config = kzalloc(sizeof(struct cfg80211_cqm_config) + | |
9892 | n_thresholds * sizeof(s32), GFP_KERNEL); | |
9893 | if (!cqm_config) { | |
9894 | err = -ENOMEM; | |
9895 | goto unlock; | |
9896 | } | |
9897 | ||
9898 | cqm_config->rssi_hyst = hysteresis; | |
9899 | cqm_config->n_rssi_thresholds = n_thresholds; | |
9900 | memcpy(cqm_config->rssi_thresholds, thresholds, | |
9901 | n_thresholds * sizeof(s32)); | |
9902 | ||
9903 | wdev->cqm_config = cqm_config; | |
9904 | } | |
9905 | ||
9906 | err = cfg80211_cqm_rssi_update(rdev, dev); | |
9907 | ||
9908 | unlock: | |
9909 | wdev_unlock(wdev); | |
9910 | ||
9911 | return err; | |
d6dc1a38 JO |
9912 | } |
9913 | ||
9914 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
9915 | { | |
9916 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
9917 | struct nlattr *cqm; | |
9918 | int err; | |
9919 | ||
9920 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
9921 | if (!cqm) |
9922 | return -EINVAL; | |
d6dc1a38 JO |
9923 | |
9924 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
fe52145f | 9925 | nl80211_attr_cqm_policy, info->extack); |
d6dc1a38 | 9926 | if (err) |
1da5fcc8 | 9927 | return err; |
d6dc1a38 JO |
9928 | |
9929 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
9930 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
4a4b8169 AZ |
9931 | const s32 *thresholds = |
9932 | nla_data(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
9933 | int len = nla_len(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); | |
1da5fcc8 | 9934 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); |
d6dc1a38 | 9935 | |
4a4b8169 AZ |
9936 | if (len % 4) |
9937 | return -EINVAL; | |
9938 | ||
9939 | return nl80211_set_cqm_rssi(info, thresholds, len / 4, | |
9940 | hysteresis); | |
1da5fcc8 JB |
9941 | } |
9942 | ||
9943 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
9944 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
9945 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
9946 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
9947 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
9948 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
9949 | ||
9950 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
9951 | } | |
9952 | ||
9953 | return -EINVAL; | |
d6dc1a38 JO |
9954 | } |
9955 | ||
6e0bd6c3 RL |
9956 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
9957 | { | |
9958 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9959 | struct net_device *dev = info->user_ptr[1]; | |
9960 | struct ocb_setup setup = {}; | |
9961 | int err; | |
9962 | ||
9963 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
9964 | if (err) | |
9965 | return err; | |
9966 | ||
9967 | return cfg80211_join_ocb(rdev, dev, &setup); | |
9968 | } | |
9969 | ||
9970 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
9971 | { | |
9972 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9973 | struct net_device *dev = info->user_ptr[1]; | |
9974 | ||
9975 | return cfg80211_leave_ocb(rdev, dev); | |
9976 | } | |
9977 | ||
29cbe68c JB |
9978 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
9979 | { | |
9980 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9981 | struct net_device *dev = info->user_ptr[1]; | |
9982 | struct mesh_config cfg; | |
c80d545d | 9983 | struct mesh_setup setup; |
29cbe68c JB |
9984 | int err; |
9985 | ||
9986 | /* start with default */ | |
9987 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 9988 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 9989 | |
24bdd9f4 | 9990 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 9991 | /* and parse parameters if given */ |
24bdd9f4 | 9992 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
9993 | if (err) |
9994 | return err; | |
9995 | } | |
9996 | ||
9997 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
9998 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
9999 | return -EINVAL; | |
10000 | ||
c80d545d JC |
10001 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
10002 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
10003 | ||
4bb62344 CYY |
10004 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
10005 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
10006 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
10007 | return -EINVAL; | |
10008 | ||
9bdbf04d MP |
10009 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
10010 | setup.beacon_interval = | |
10011 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 | 10012 | |
0c317a02 PK |
10013 | err = cfg80211_validate_beacon_int(rdev, |
10014 | NL80211_IFTYPE_MESH_POINT, | |
10015 | setup.beacon_interval); | |
12d20fc9 PK |
10016 | if (err) |
10017 | return err; | |
9bdbf04d MP |
10018 | } |
10019 | ||
10020 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
10021 | setup.dtim_period = | |
10022 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
10023 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
10024 | return -EINVAL; | |
10025 | } | |
10026 | ||
c80d545d JC |
10027 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
10028 | /* parse additional setup parameters if given */ | |
10029 | err = nl80211_parse_mesh_setup(info, &setup); | |
10030 | if (err) | |
10031 | return err; | |
10032 | } | |
10033 | ||
d37bb18a TP |
10034 | if (setup.user_mpm) |
10035 | cfg.auto_open_plinks = false; | |
10036 | ||
cc1d2806 | 10037 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
10038 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
10039 | if (err) | |
10040 | return err; | |
cc1d2806 JB |
10041 | } else { |
10042 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 10043 | setup.chandef.chan = NULL; |
cc1d2806 JB |
10044 | } |
10045 | ||
ffb3cf30 AN |
10046 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
10047 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
10048 | int n_rates = | |
10049 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
10050 | struct ieee80211_supported_band *sband; | |
10051 | ||
10052 | if (!setup.chandef.chan) | |
10053 | return -EINVAL; | |
10054 | ||
10055 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
10056 | ||
10057 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
10058 | &setup.basic_rates); | |
10059 | if (err) | |
10060 | return err; | |
10061 | } | |
10062 | ||
8564e382 JB |
10063 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
10064 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); | |
10065 | if (err) | |
10066 | return err; | |
10067 | ||
265698d7 JB |
10068 | if (!setup.chandef.chan) |
10069 | return -EINVAL; | |
10070 | ||
8564e382 JB |
10071 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, |
10072 | &setup.beacon_rate); | |
10073 | if (err) | |
10074 | return err; | |
10075 | } | |
10076 | ||
d37d49c2 BB |
10077 | setup.userspace_handles_dfs = |
10078 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
10079 | ||
c80d545d | 10080 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
10081 | } |
10082 | ||
10083 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
10084 | { | |
10085 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10086 | struct net_device *dev = info->user_ptr[1]; | |
10087 | ||
10088 | return cfg80211_leave_mesh(rdev, dev); | |
10089 | } | |
10090 | ||
dfb89c56 | 10091 | #ifdef CONFIG_PM |
bb92d199 AK |
10092 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
10093 | struct cfg80211_registered_device *rdev) | |
10094 | { | |
6abb9cb9 | 10095 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
10096 | struct nlattr *nl_pats, *nl_pat; |
10097 | int i, pat_len; | |
10098 | ||
6abb9cb9 | 10099 | if (!wowlan->n_patterns) |
bb92d199 AK |
10100 | return 0; |
10101 | ||
10102 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
10103 | if (!nl_pats) | |
10104 | return -ENOBUFS; | |
10105 | ||
6abb9cb9 | 10106 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
10107 | nl_pat = nla_nest_start(msg, i + 1); |
10108 | if (!nl_pat) | |
10109 | return -ENOBUFS; | |
6abb9cb9 | 10110 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 10111 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 10112 | wowlan->patterns[i].mask) || |
50ac6607 AK |
10113 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
10114 | wowlan->patterns[i].pattern) || | |
10115 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 10116 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
10117 | return -ENOBUFS; |
10118 | nla_nest_end(msg, nl_pat); | |
10119 | } | |
10120 | nla_nest_end(msg, nl_pats); | |
10121 | ||
10122 | return 0; | |
10123 | } | |
10124 | ||
2a0e047e JB |
10125 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
10126 | struct cfg80211_wowlan_tcp *tcp) | |
10127 | { | |
10128 | struct nlattr *nl_tcp; | |
10129 | ||
10130 | if (!tcp) | |
10131 | return 0; | |
10132 | ||
10133 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
10134 | if (!nl_tcp) | |
10135 | return -ENOBUFS; | |
10136 | ||
930345ea JB |
10137 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
10138 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
2a0e047e JB |
10139 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
10140 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
10141 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
10142 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
10143 | tcp->payload_len, tcp->payload) || | |
10144 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
10145 | tcp->data_interval) || | |
10146 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
10147 | tcp->wake_len, tcp->wake_data) || | |
10148 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
10149 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
10150 | return -ENOBUFS; | |
10151 | ||
10152 | if (tcp->payload_seq.len && | |
10153 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
10154 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
10155 | return -ENOBUFS; | |
10156 | ||
10157 | if (tcp->payload_tok.len && | |
10158 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
10159 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
10160 | &tcp->payload_tok)) | |
10161 | return -ENOBUFS; | |
10162 | ||
e248ad30 JB |
10163 | nla_nest_end(msg, nl_tcp); |
10164 | ||
2a0e047e JB |
10165 | return 0; |
10166 | } | |
10167 | ||
75453ccb LC |
10168 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
10169 | struct cfg80211_sched_scan_request *req) | |
10170 | { | |
3b06d277 | 10171 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
75453ccb LC |
10172 | int i; |
10173 | ||
10174 | if (!req) | |
10175 | return 0; | |
10176 | ||
10177 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
10178 | if (!nd) | |
10179 | return -ENOBUFS; | |
10180 | ||
3b06d277 AS |
10181 | if (req->n_scan_plans == 1 && |
10182 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, | |
10183 | req->scan_plans[0].interval * 1000)) | |
75453ccb LC |
10184 | return -ENOBUFS; |
10185 | ||
21fea567 LC |
10186 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
10187 | return -ENOBUFS; | |
10188 | ||
bf95ecdb | 10189 | if (req->relative_rssi_set) { |
10190 | struct nl80211_bss_select_rssi_adjust rssi_adjust; | |
10191 | ||
10192 | if (nla_put_s8(msg, NL80211_ATTR_SCHED_SCAN_RELATIVE_RSSI, | |
10193 | req->relative_rssi)) | |
10194 | return -ENOBUFS; | |
10195 | ||
10196 | rssi_adjust.band = req->rssi_adjust.band; | |
10197 | rssi_adjust.delta = req->rssi_adjust.delta; | |
10198 | if (nla_put(msg, NL80211_ATTR_SCHED_SCAN_RSSI_ADJUST, | |
10199 | sizeof(rssi_adjust), &rssi_adjust)) | |
10200 | return -ENOBUFS; | |
10201 | } | |
10202 | ||
75453ccb LC |
10203 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
10204 | if (!freqs) | |
10205 | return -ENOBUFS; | |
10206 | ||
53b18980 JB |
10207 | for (i = 0; i < req->n_channels; i++) { |
10208 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
10209 | return -ENOBUFS; | |
10210 | } | |
75453ccb LC |
10211 | |
10212 | nla_nest_end(msg, freqs); | |
10213 | ||
10214 | if (req->n_match_sets) { | |
10215 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
76e1fb4b JB |
10216 | if (!matches) |
10217 | return -ENOBUFS; | |
10218 | ||
75453ccb LC |
10219 | for (i = 0; i < req->n_match_sets; i++) { |
10220 | match = nla_nest_start(msg, i); | |
76e1fb4b JB |
10221 | if (!match) |
10222 | return -ENOBUFS; | |
10223 | ||
53b18980 JB |
10224 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
10225 | req->match_sets[i].ssid.ssid_len, | |
10226 | req->match_sets[i].ssid.ssid)) | |
10227 | return -ENOBUFS; | |
75453ccb LC |
10228 | nla_nest_end(msg, match); |
10229 | } | |
10230 | nla_nest_end(msg, matches); | |
10231 | } | |
10232 | ||
3b06d277 AS |
10233 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
10234 | if (!scan_plans) | |
10235 | return -ENOBUFS; | |
10236 | ||
10237 | for (i = 0; i < req->n_scan_plans; i++) { | |
10238 | scan_plan = nla_nest_start(msg, i + 1); | |
76e1fb4b JB |
10239 | if (!scan_plan) |
10240 | return -ENOBUFS; | |
10241 | ||
3b06d277 AS |
10242 | if (!scan_plan || |
10243 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, | |
10244 | req->scan_plans[i].interval) || | |
10245 | (req->scan_plans[i].iterations && | |
10246 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, | |
10247 | req->scan_plans[i].iterations))) | |
10248 | return -ENOBUFS; | |
10249 | nla_nest_end(msg, scan_plan); | |
10250 | } | |
10251 | nla_nest_end(msg, scan_plans); | |
10252 | ||
75453ccb LC |
10253 | nla_nest_end(msg, nd); |
10254 | ||
10255 | return 0; | |
10256 | } | |
10257 | ||
ff1b6e69 JB |
10258 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
10259 | { | |
10260 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10261 | struct sk_buff *msg; | |
10262 | void *hdr; | |
2a0e047e | 10263 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 10264 | |
964dc9e2 | 10265 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
10266 | return -EOPNOTSUPP; |
10267 | ||
6abb9cb9 | 10268 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 10269 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
10270 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
10271 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
10272 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
10273 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
10274 | } |
10275 | ||
10276 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
10277 | if (!msg) |
10278 | return -ENOMEM; | |
10279 | ||
15e47304 | 10280 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
10281 | NL80211_CMD_GET_WOWLAN); |
10282 | if (!hdr) | |
10283 | goto nla_put_failure; | |
10284 | ||
6abb9cb9 | 10285 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
10286 | struct nlattr *nl_wowlan; |
10287 | ||
10288 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
10289 | if (!nl_wowlan) | |
10290 | goto nla_put_failure; | |
10291 | ||
6abb9cb9 | 10292 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 10293 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 10294 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 10295 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 10296 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 10297 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 10298 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 10299 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 10300 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 10301 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 10302 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 10303 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 10304 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
10305 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
10306 | goto nla_put_failure; | |
2a0e047e | 10307 | |
bb92d199 AK |
10308 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
10309 | goto nla_put_failure; | |
2a0e047e | 10310 | |
6abb9cb9 JB |
10311 | if (nl80211_send_wowlan_tcp(msg, |
10312 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 10313 | goto nla_put_failure; |
75453ccb LC |
10314 | |
10315 | if (nl80211_send_wowlan_nd( | |
10316 | msg, | |
10317 | rdev->wiphy.wowlan_config->nd_config)) | |
10318 | goto nla_put_failure; | |
2a0e047e | 10319 | |
ff1b6e69 JB |
10320 | nla_nest_end(msg, nl_wowlan); |
10321 | } | |
10322 | ||
10323 | genlmsg_end(msg, hdr); | |
10324 | return genlmsg_reply(msg, info); | |
10325 | ||
10326 | nla_put_failure: | |
10327 | nlmsg_free(msg); | |
10328 | return -ENOBUFS; | |
10329 | } | |
10330 | ||
2a0e047e JB |
10331 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
10332 | struct nlattr *attr, | |
10333 | struct cfg80211_wowlan *trig) | |
10334 | { | |
10335 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
10336 | struct cfg80211_wowlan_tcp *cfg; | |
10337 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
10338 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
10339 | u32 size; | |
10340 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
10341 | int err, port; | |
10342 | ||
964dc9e2 | 10343 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
10344 | return -EINVAL; |
10345 | ||
bfe2c7b1 | 10346 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TCP, attr, |
fceb6435 | 10347 | nl80211_wowlan_tcp_policy, NULL); |
2a0e047e JB |
10348 | if (err) |
10349 | return err; | |
10350 | ||
10351 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
10352 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
10353 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
10354 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
10355 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
10356 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
10357 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
10358 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
10359 | return -EINVAL; | |
10360 | ||
10361 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 10362 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
10363 | return -EINVAL; |
10364 | ||
10365 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 10366 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 10367 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
10368 | return -EINVAL; |
10369 | ||
10370 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 10371 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
10372 | return -EINVAL; |
10373 | ||
10374 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
10375 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
10376 | return -EINVAL; | |
10377 | ||
10378 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
10379 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
10380 | ||
10381 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
10382 | tokens_size = tokln - sizeof(*tok); | |
10383 | ||
10384 | if (!tok->len || tokens_size % tok->len) | |
10385 | return -EINVAL; | |
964dc9e2 | 10386 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 10387 | return -EINVAL; |
964dc9e2 | 10388 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 10389 | return -EINVAL; |
964dc9e2 | 10390 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 10391 | return -EINVAL; |
964dc9e2 | 10392 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
10393 | return -EINVAL; |
10394 | if (tok->offset + tok->len > data_size) | |
10395 | return -EINVAL; | |
10396 | } | |
10397 | ||
10398 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
10399 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 10400 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
10401 | return -EINVAL; |
10402 | if (seq->len == 0 || seq->len > 4) | |
10403 | return -EINVAL; | |
10404 | if (seq->len + seq->offset > data_size) | |
10405 | return -EINVAL; | |
10406 | } | |
10407 | ||
10408 | size = sizeof(*cfg); | |
10409 | size += data_size; | |
10410 | size += wake_size + wake_mask_size; | |
10411 | size += tokens_size; | |
10412 | ||
10413 | cfg = kzalloc(size, GFP_KERNEL); | |
10414 | if (!cfg) | |
10415 | return -ENOMEM; | |
67b61f6c JB |
10416 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
10417 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
2a0e047e JB |
10418 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
10419 | ETH_ALEN); | |
10420 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
10421 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
10422 | else | |
10423 | port = 0; | |
10424 | #ifdef CONFIG_INET | |
10425 | /* allocate a socket and port for it and use it */ | |
10426 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
10427 | IPPROTO_TCP, &cfg->sock, 1); | |
10428 | if (err) { | |
10429 | kfree(cfg); | |
10430 | return err; | |
10431 | } | |
10432 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
10433 | sock_release(cfg->sock); | |
10434 | kfree(cfg); | |
10435 | return -EADDRINUSE; | |
10436 | } | |
10437 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
10438 | #else | |
10439 | if (!port) { | |
10440 | kfree(cfg); | |
10441 | return -EINVAL; | |
10442 | } | |
10443 | cfg->src_port = port; | |
10444 | #endif | |
10445 | ||
10446 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
10447 | cfg->payload_len = data_size; | |
10448 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
10449 | memcpy((void *)cfg->payload, | |
10450 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
10451 | data_size); | |
10452 | if (seq) | |
10453 | cfg->payload_seq = *seq; | |
10454 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
10455 | cfg->wake_len = wake_size; | |
10456 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
10457 | memcpy((void *)cfg->wake_data, | |
10458 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
10459 | wake_size); | |
10460 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
10461 | data_size + wake_size; | |
10462 | memcpy((void *)cfg->wake_mask, | |
10463 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
10464 | wake_mask_size); | |
10465 | if (tok) { | |
10466 | cfg->tokens_size = tokens_size; | |
10467 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
10468 | } | |
10469 | ||
10470 | trig->tcp = cfg; | |
10471 | ||
10472 | return 0; | |
10473 | } | |
10474 | ||
8cd4d456 LC |
10475 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
10476 | const struct wiphy_wowlan_support *wowlan, | |
10477 | struct nlattr *attr, | |
10478 | struct cfg80211_wowlan *trig) | |
10479 | { | |
10480 | struct nlattr **tb; | |
10481 | int err; | |
10482 | ||
10483 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
10484 | if (!tb) | |
10485 | return -ENOMEM; | |
10486 | ||
10487 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
10488 | err = -EOPNOTSUPP; | |
10489 | goto out; | |
10490 | } | |
10491 | ||
fceb6435 JB |
10492 | err = nla_parse_nested(tb, NL80211_ATTR_MAX, attr, nl80211_policy, |
10493 | NULL); | |
8cd4d456 LC |
10494 | if (err) |
10495 | goto out; | |
10496 | ||
aad1e812 AVS |
10497 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb, |
10498 | wowlan->max_nd_match_sets); | |
8cd4d456 LC |
10499 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
10500 | if (err) | |
10501 | trig->nd_config = NULL; | |
10502 | ||
10503 | out: | |
10504 | kfree(tb); | |
10505 | return err; | |
10506 | } | |
10507 | ||
ff1b6e69 JB |
10508 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
10509 | { | |
10510 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10511 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 10512 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 10513 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 10514 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 10515 | int err, i; |
6abb9cb9 | 10516 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 10517 | bool regular = false; |
ff1b6e69 | 10518 | |
964dc9e2 | 10519 | if (!wowlan) |
ff1b6e69 JB |
10520 | return -EOPNOTSUPP; |
10521 | ||
ae33bd81 JB |
10522 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
10523 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 10524 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
10525 | goto set_wakeup; |
10526 | } | |
ff1b6e69 | 10527 | |
bfe2c7b1 JB |
10528 | err = nla_parse_nested(tb, MAX_NL80211_WOWLAN_TRIG, |
10529 | info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS], | |
fe52145f | 10530 | nl80211_wowlan_policy, info->extack); |
ff1b6e69 JB |
10531 | if (err) |
10532 | return err; | |
10533 | ||
10534 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
10535 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
10536 | return -EINVAL; | |
10537 | new_triggers.any = true; | |
10538 | } | |
10539 | ||
10540 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
10541 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
10542 | return -EINVAL; | |
10543 | new_triggers.disconnect = true; | |
98fc4386 | 10544 | regular = true; |
ff1b6e69 JB |
10545 | } |
10546 | ||
10547 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
10548 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
10549 | return -EINVAL; | |
10550 | new_triggers.magic_pkt = true; | |
98fc4386 | 10551 | regular = true; |
ff1b6e69 JB |
10552 | } |
10553 | ||
77dbbb13 JB |
10554 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
10555 | return -EINVAL; | |
10556 | ||
10557 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
10558 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
10559 | return -EINVAL; | |
10560 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 10561 | regular = true; |
77dbbb13 JB |
10562 | } |
10563 | ||
10564 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
10565 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
10566 | return -EINVAL; | |
10567 | new_triggers.eap_identity_req = true; | |
98fc4386 | 10568 | regular = true; |
77dbbb13 JB |
10569 | } |
10570 | ||
10571 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
10572 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
10573 | return -EINVAL; | |
10574 | new_triggers.four_way_handshake = true; | |
98fc4386 | 10575 | regular = true; |
77dbbb13 JB |
10576 | } |
10577 | ||
10578 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
10579 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
10580 | return -EINVAL; | |
10581 | new_triggers.rfkill_release = true; | |
98fc4386 | 10582 | regular = true; |
77dbbb13 JB |
10583 | } |
10584 | ||
ff1b6e69 JB |
10585 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
10586 | struct nlattr *pat; | |
10587 | int n_patterns = 0; | |
bb92d199 | 10588 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 10589 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 10590 | |
98fc4386 JB |
10591 | regular = true; |
10592 | ||
ff1b6e69 JB |
10593 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
10594 | rem) | |
10595 | n_patterns++; | |
10596 | if (n_patterns > wowlan->n_patterns) | |
10597 | return -EINVAL; | |
10598 | ||
10599 | new_triggers.patterns = kcalloc(n_patterns, | |
10600 | sizeof(new_triggers.patterns[0]), | |
10601 | GFP_KERNEL); | |
10602 | if (!new_triggers.patterns) | |
10603 | return -ENOMEM; | |
10604 | ||
10605 | new_triggers.n_patterns = n_patterns; | |
10606 | i = 0; | |
10607 | ||
10608 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
10609 | rem) { | |
922bd80f JB |
10610 | u8 *mask_pat; |
10611 | ||
bfe2c7b1 | 10612 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
ad670233 PX |
10613 | nl80211_packet_pattern_policy, |
10614 | info->extack); | |
ff1b6e69 | 10615 | err = -EINVAL; |
50ac6607 AK |
10616 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
10617 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 10618 | goto error; |
50ac6607 | 10619 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 10620 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 10621 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
10622 | goto error; |
10623 | if (pat_len > wowlan->pattern_max_len || | |
10624 | pat_len < wowlan->pattern_min_len) | |
10625 | goto error; | |
10626 | ||
50ac6607 | 10627 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
10628 | pkt_offset = 0; |
10629 | else | |
10630 | pkt_offset = nla_get_u32( | |
50ac6607 | 10631 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
10632 | if (pkt_offset > wowlan->max_pkt_offset) |
10633 | goto error; | |
10634 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
10635 | ||
922bd80f JB |
10636 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
10637 | if (!mask_pat) { | |
ff1b6e69 JB |
10638 | err = -ENOMEM; |
10639 | goto error; | |
10640 | } | |
922bd80f JB |
10641 | new_triggers.patterns[i].mask = mask_pat; |
10642 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 10643 | mask_len); |
922bd80f JB |
10644 | mask_pat += mask_len; |
10645 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 10646 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 10647 | memcpy(mask_pat, |
50ac6607 | 10648 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
10649 | pat_len); |
10650 | i++; | |
10651 | } | |
10652 | } | |
10653 | ||
2a0e047e | 10654 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 10655 | regular = true; |
2a0e047e JB |
10656 | err = nl80211_parse_wowlan_tcp( |
10657 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
10658 | &new_triggers); | |
10659 | if (err) | |
10660 | goto error; | |
10661 | } | |
10662 | ||
8cd4d456 | 10663 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 10664 | regular = true; |
8cd4d456 LC |
10665 | err = nl80211_parse_wowlan_nd( |
10666 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
10667 | &new_triggers); | |
10668 | if (err) | |
10669 | goto error; | |
10670 | } | |
10671 | ||
98fc4386 JB |
10672 | /* The 'any' trigger means the device continues operating more or less |
10673 | * as in its normal operation mode and wakes up the host on most of the | |
10674 | * normal interrupts (like packet RX, ...) | |
10675 | * It therefore makes little sense to combine with the more constrained | |
10676 | * wakeup trigger modes. | |
10677 | */ | |
10678 | if (new_triggers.any && regular) { | |
10679 | err = -EINVAL; | |
10680 | goto error; | |
10681 | } | |
10682 | ||
ae33bd81 JB |
10683 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
10684 | if (!ntrig) { | |
10685 | err = -ENOMEM; | |
10686 | goto error; | |
ff1b6e69 | 10687 | } |
ae33bd81 | 10688 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 10689 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 10690 | |
ae33bd81 | 10691 | set_wakeup: |
6abb9cb9 JB |
10692 | if (rdev->ops->set_wakeup && |
10693 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
10694 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 10695 | |
ff1b6e69 JB |
10696 | return 0; |
10697 | error: | |
10698 | for (i = 0; i < new_triggers.n_patterns; i++) | |
10699 | kfree(new_triggers.patterns[i].mask); | |
10700 | kfree(new_triggers.patterns); | |
2a0e047e JB |
10701 | if (new_triggers.tcp && new_triggers.tcp->sock) |
10702 | sock_release(new_triggers.tcp->sock); | |
10703 | kfree(new_triggers.tcp); | |
e5dbe070 | 10704 | kfree(new_triggers.nd_config); |
ff1b6e69 JB |
10705 | return err; |
10706 | } | |
dfb89c56 | 10707 | #endif |
ff1b6e69 | 10708 | |
be29b99a AK |
10709 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
10710 | struct cfg80211_registered_device *rdev) | |
10711 | { | |
10712 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
10713 | int i, j, pat_len; | |
10714 | struct cfg80211_coalesce_rules *rule; | |
10715 | ||
10716 | if (!rdev->coalesce->n_rules) | |
10717 | return 0; | |
10718 | ||
10719 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
10720 | if (!nl_rules) | |
10721 | return -ENOBUFS; | |
10722 | ||
10723 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
10724 | nl_rule = nla_nest_start(msg, i + 1); | |
10725 | if (!nl_rule) | |
10726 | return -ENOBUFS; | |
10727 | ||
10728 | rule = &rdev->coalesce->rules[i]; | |
10729 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
10730 | rule->delay)) | |
10731 | return -ENOBUFS; | |
10732 | ||
10733 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
10734 | rule->condition)) | |
10735 | return -ENOBUFS; | |
10736 | ||
10737 | nl_pats = nla_nest_start(msg, | |
10738 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
10739 | if (!nl_pats) | |
10740 | return -ENOBUFS; | |
10741 | ||
10742 | for (j = 0; j < rule->n_patterns; j++) { | |
10743 | nl_pat = nla_nest_start(msg, j + 1); | |
10744 | if (!nl_pat) | |
10745 | return -ENOBUFS; | |
10746 | pat_len = rule->patterns[j].pattern_len; | |
10747 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
10748 | DIV_ROUND_UP(pat_len, 8), | |
10749 | rule->patterns[j].mask) || | |
10750 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
10751 | rule->patterns[j].pattern) || | |
10752 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
10753 | rule->patterns[j].pkt_offset)) | |
10754 | return -ENOBUFS; | |
10755 | nla_nest_end(msg, nl_pat); | |
10756 | } | |
10757 | nla_nest_end(msg, nl_pats); | |
10758 | nla_nest_end(msg, nl_rule); | |
10759 | } | |
10760 | nla_nest_end(msg, nl_rules); | |
10761 | ||
10762 | return 0; | |
10763 | } | |
10764 | ||
10765 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
10766 | { | |
10767 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10768 | struct sk_buff *msg; | |
10769 | void *hdr; | |
10770 | ||
10771 | if (!rdev->wiphy.coalesce) | |
10772 | return -EOPNOTSUPP; | |
10773 | ||
10774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10775 | if (!msg) | |
10776 | return -ENOMEM; | |
10777 | ||
10778 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
10779 | NL80211_CMD_GET_COALESCE); | |
10780 | if (!hdr) | |
10781 | goto nla_put_failure; | |
10782 | ||
10783 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
10784 | goto nla_put_failure; | |
10785 | ||
10786 | genlmsg_end(msg, hdr); | |
10787 | return genlmsg_reply(msg, info); | |
10788 | ||
10789 | nla_put_failure: | |
10790 | nlmsg_free(msg); | |
10791 | return -ENOBUFS; | |
10792 | } | |
10793 | ||
10794 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
10795 | { | |
10796 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
10797 | int i, j; | |
10798 | struct cfg80211_coalesce_rules *rule; | |
10799 | ||
10800 | if (!coalesce) | |
10801 | return; | |
10802 | ||
10803 | for (i = 0; i < coalesce->n_rules; i++) { | |
10804 | rule = &coalesce->rules[i]; | |
10805 | for (j = 0; j < rule->n_patterns; j++) | |
10806 | kfree(rule->patterns[j].mask); | |
10807 | kfree(rule->patterns); | |
10808 | } | |
10809 | kfree(coalesce->rules); | |
10810 | kfree(coalesce); | |
10811 | rdev->coalesce = NULL; | |
10812 | } | |
10813 | ||
10814 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
10815 | struct nlattr *rule, | |
10816 | struct cfg80211_coalesce_rules *new_rule) | |
10817 | { | |
10818 | int err, i; | |
10819 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
10820 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
10821 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
10822 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
10823 | ||
bfe2c7b1 | 10824 | err = nla_parse_nested(tb, NL80211_ATTR_COALESCE_RULE_MAX, rule, |
fceb6435 | 10825 | nl80211_coalesce_policy, NULL); |
be29b99a AK |
10826 | if (err) |
10827 | return err; | |
10828 | ||
10829 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
10830 | new_rule->delay = | |
10831 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
10832 | if (new_rule->delay > coalesce->max_delay) | |
10833 | return -EINVAL; | |
10834 | ||
10835 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
10836 | new_rule->condition = | |
10837 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
10838 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
10839 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
10840 | return -EINVAL; | |
10841 | ||
10842 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
10843 | return -EINVAL; | |
10844 | ||
10845 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
10846 | rem) | |
10847 | n_patterns++; | |
10848 | if (n_patterns > coalesce->n_patterns) | |
10849 | return -EINVAL; | |
10850 | ||
10851 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
10852 | GFP_KERNEL); | |
10853 | if (!new_rule->patterns) | |
10854 | return -ENOMEM; | |
10855 | ||
10856 | new_rule->n_patterns = n_patterns; | |
10857 | i = 0; | |
10858 | ||
10859 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
10860 | rem) { | |
922bd80f JB |
10861 | u8 *mask_pat; |
10862 | ||
ad670233 PX |
10863 | nla_parse_nested(pat_tb, MAX_NL80211_PKTPAT, pat, |
10864 | nl80211_packet_pattern_policy, NULL); | |
be29b99a AK |
10865 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
10866 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
10867 | return -EINVAL; | |
10868 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
10869 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
10870 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
10871 | return -EINVAL; | |
10872 | if (pat_len > coalesce->pattern_max_len || | |
10873 | pat_len < coalesce->pattern_min_len) | |
10874 | return -EINVAL; | |
10875 | ||
10876 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
10877 | pkt_offset = 0; | |
10878 | else | |
10879 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
10880 | if (pkt_offset > coalesce->max_pkt_offset) | |
10881 | return -EINVAL; | |
10882 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
10883 | ||
922bd80f JB |
10884 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
10885 | if (!mask_pat) | |
be29b99a | 10886 | return -ENOMEM; |
922bd80f JB |
10887 | |
10888 | new_rule->patterns[i].mask = mask_pat; | |
10889 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
10890 | mask_len); | |
10891 | ||
10892 | mask_pat += mask_len; | |
10893 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 10894 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
10895 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
10896 | pat_len); | |
be29b99a AK |
10897 | i++; |
10898 | } | |
10899 | ||
10900 | return 0; | |
10901 | } | |
10902 | ||
10903 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
10904 | { | |
10905 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10906 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
10907 | struct cfg80211_coalesce new_coalesce = {}; | |
10908 | struct cfg80211_coalesce *n_coalesce; | |
10909 | int err, rem_rule, n_rules = 0, i, j; | |
10910 | struct nlattr *rule; | |
10911 | struct cfg80211_coalesce_rules *tmp_rule; | |
10912 | ||
10913 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
10914 | return -EOPNOTSUPP; | |
10915 | ||
10916 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
10917 | cfg80211_rdev_free_coalesce(rdev); | |
a1056b1b | 10918 | rdev_set_coalesce(rdev, NULL); |
be29b99a AK |
10919 | return 0; |
10920 | } | |
10921 | ||
10922 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
10923 | rem_rule) | |
10924 | n_rules++; | |
10925 | if (n_rules > coalesce->n_rules) | |
10926 | return -EINVAL; | |
10927 | ||
10928 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
10929 | GFP_KERNEL); | |
10930 | if (!new_coalesce.rules) | |
10931 | return -ENOMEM; | |
10932 | ||
10933 | new_coalesce.n_rules = n_rules; | |
10934 | i = 0; | |
10935 | ||
10936 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
10937 | rem_rule) { | |
10938 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
10939 | &new_coalesce.rules[i]); | |
10940 | if (err) | |
10941 | goto error; | |
10942 | ||
10943 | i++; | |
10944 | } | |
10945 | ||
a1056b1b | 10946 | err = rdev_set_coalesce(rdev, &new_coalesce); |
be29b99a AK |
10947 | if (err) |
10948 | goto error; | |
10949 | ||
10950 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
10951 | if (!n_coalesce) { | |
10952 | err = -ENOMEM; | |
10953 | goto error; | |
10954 | } | |
10955 | cfg80211_rdev_free_coalesce(rdev); | |
10956 | rdev->coalesce = n_coalesce; | |
10957 | ||
10958 | return 0; | |
10959 | error: | |
10960 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
10961 | tmp_rule = &new_coalesce.rules[i]; | |
10962 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
10963 | kfree(tmp_rule->patterns[j].mask); | |
10964 | kfree(tmp_rule->patterns); | |
10965 | } | |
10966 | kfree(new_coalesce.rules); | |
10967 | ||
10968 | return err; | |
10969 | } | |
10970 | ||
e5497d76 JB |
10971 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
10972 | { | |
10973 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10974 | struct net_device *dev = info->user_ptr[1]; | |
10975 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10976 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
10977 | struct cfg80211_gtk_rekey_data rekey_data; | |
10978 | int err; | |
10979 | ||
10980 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
10981 | return -EINVAL; | |
10982 | ||
bfe2c7b1 JB |
10983 | err = nla_parse_nested(tb, MAX_NL80211_REKEY_DATA, |
10984 | info->attrs[NL80211_ATTR_REKEY_DATA], | |
fe52145f | 10985 | nl80211_rekey_policy, info->extack); |
e5497d76 JB |
10986 | if (err) |
10987 | return err; | |
10988 | ||
e785fa0a VD |
10989 | if (!tb[NL80211_REKEY_DATA_REPLAY_CTR] || !tb[NL80211_REKEY_DATA_KEK] || |
10990 | !tb[NL80211_REKEY_DATA_KCK]) | |
10991 | return -EINVAL; | |
e5497d76 JB |
10992 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) |
10993 | return -ERANGE; | |
10994 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
10995 | return -ERANGE; | |
10996 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
10997 | return -ERANGE; | |
10998 | ||
78f686ca JB |
10999 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
11000 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
11001 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
11002 | |
11003 | wdev_lock(wdev); | |
11004 | if (!wdev->current_bss) { | |
11005 | err = -ENOTCONN; | |
11006 | goto out; | |
11007 | } | |
11008 | ||
11009 | if (!rdev->ops->set_rekey_data) { | |
11010 | err = -EOPNOTSUPP; | |
11011 | goto out; | |
11012 | } | |
11013 | ||
e35e4d28 | 11014 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
11015 | out: |
11016 | wdev_unlock(wdev); | |
11017 | return err; | |
11018 | } | |
11019 | ||
28946da7 JB |
11020 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
11021 | struct genl_info *info) | |
11022 | { | |
11023 | struct net_device *dev = info->user_ptr[1]; | |
11024 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11025 | ||
11026 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
11027 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
11028 | return -EINVAL; | |
11029 | ||
15e47304 | 11030 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
11031 | return -EBUSY; |
11032 | ||
15e47304 | 11033 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
11034 | return 0; |
11035 | } | |
11036 | ||
7f6cf311 JB |
11037 | static int nl80211_probe_client(struct sk_buff *skb, |
11038 | struct genl_info *info) | |
11039 | { | |
11040 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11041 | struct net_device *dev = info->user_ptr[1]; | |
11042 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11043 | struct sk_buff *msg; | |
11044 | void *hdr; | |
11045 | const u8 *addr; | |
11046 | u64 cookie; | |
11047 | int err; | |
11048 | ||
11049 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
11050 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
11051 | return -EOPNOTSUPP; | |
11052 | ||
11053 | if (!info->attrs[NL80211_ATTR_MAC]) | |
11054 | return -EINVAL; | |
11055 | ||
11056 | if (!rdev->ops->probe_client) | |
11057 | return -EOPNOTSUPP; | |
11058 | ||
11059 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11060 | if (!msg) | |
11061 | return -ENOMEM; | |
11062 | ||
15e47304 | 11063 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 11064 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
11065 | if (!hdr) { |
11066 | err = -ENOBUFS; | |
7f6cf311 JB |
11067 | goto free_msg; |
11068 | } | |
11069 | ||
11070 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11071 | ||
e35e4d28 | 11072 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
11073 | if (err) |
11074 | goto free_msg; | |
11075 | ||
2dad624e ND |
11076 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
11077 | NL80211_ATTR_PAD)) | |
9360ffd1 | 11078 | goto nla_put_failure; |
7f6cf311 JB |
11079 | |
11080 | genlmsg_end(msg, hdr); | |
11081 | ||
11082 | return genlmsg_reply(msg, info); | |
11083 | ||
11084 | nla_put_failure: | |
11085 | err = -ENOBUFS; | |
11086 | free_msg: | |
11087 | nlmsg_free(msg); | |
11088 | return err; | |
11089 | } | |
11090 | ||
5e760230 JB |
11091 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
11092 | { | |
11093 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
11094 | struct cfg80211_beacon_registration *reg, *nreg; |
11095 | int rv; | |
5e760230 JB |
11096 | |
11097 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
11098 | return -EOPNOTSUPP; | |
11099 | ||
37c73b5f BG |
11100 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
11101 | if (!nreg) | |
11102 | return -ENOMEM; | |
11103 | ||
11104 | /* First, check if already registered. */ | |
11105 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
11106 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
11107 | if (reg->nlportid == info->snd_portid) { | |
11108 | rv = -EALREADY; | |
11109 | goto out_err; | |
11110 | } | |
11111 | } | |
11112 | /* Add it to the list */ | |
11113 | nreg->nlportid = info->snd_portid; | |
11114 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 11115 | |
37c73b5f | 11116 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
11117 | |
11118 | return 0; | |
37c73b5f BG |
11119 | out_err: |
11120 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
11121 | kfree(nreg); | |
11122 | return rv; | |
5e760230 JB |
11123 | } |
11124 | ||
98104fde JB |
11125 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
11126 | { | |
11127 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11128 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11129 | int err; | |
11130 | ||
11131 | if (!rdev->ops->start_p2p_device) | |
11132 | return -EOPNOTSUPP; | |
11133 | ||
11134 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
11135 | return -EOPNOTSUPP; | |
11136 | ||
73c7da3d | 11137 | if (wdev_running(wdev)) |
98104fde JB |
11138 | return 0; |
11139 | ||
b6a55015 LC |
11140 | if (rfkill_blocked(rdev->rfkill)) |
11141 | return -ERFKILL; | |
98104fde | 11142 | |
eeb126e9 | 11143 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
11144 | if (err) |
11145 | return err; | |
11146 | ||
73c7da3d | 11147 | wdev->is_running = true; |
98104fde | 11148 | rdev->opencount++; |
98104fde JB |
11149 | |
11150 | return 0; | |
11151 | } | |
11152 | ||
11153 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
11154 | { | |
11155 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11156 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11157 | ||
11158 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
11159 | return -EOPNOTSUPP; | |
11160 | ||
11161 | if (!rdev->ops->stop_p2p_device) | |
11162 | return -EOPNOTSUPP; | |
11163 | ||
f9f47529 | 11164 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
11165 | |
11166 | return 0; | |
11167 | } | |
11168 | ||
cb3b7d87 AB |
11169 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
11170 | { | |
11171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11172 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11173 | struct cfg80211_nan_conf conf = {}; | |
11174 | int err; | |
11175 | ||
11176 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
11177 | return -EOPNOTSUPP; | |
11178 | ||
eeb04a96 | 11179 | if (wdev_running(wdev)) |
cb3b7d87 AB |
11180 | return -EEXIST; |
11181 | ||
11182 | if (rfkill_blocked(rdev->rfkill)) | |
11183 | return -ERFKILL; | |
11184 | ||
11185 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) | |
11186 | return -EINVAL; | |
11187 | ||
cb3b7d87 AB |
11188 | conf.master_pref = |
11189 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
11190 | if (!conf.master_pref) | |
11191 | return -EINVAL; | |
11192 | ||
8585989d LC |
11193 | if (info->attrs[NL80211_ATTR_BANDS]) { |
11194 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); | |
11195 | ||
11196 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) | |
11197 | return -EOPNOTSUPP; | |
11198 | ||
11199 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) | |
11200 | return -EINVAL; | |
11201 | ||
11202 | conf.bands = bands; | |
11203 | } | |
cb3b7d87 AB |
11204 | |
11205 | err = rdev_start_nan(rdev, wdev, &conf); | |
11206 | if (err) | |
11207 | return err; | |
11208 | ||
73c7da3d | 11209 | wdev->is_running = true; |
cb3b7d87 AB |
11210 | rdev->opencount++; |
11211 | ||
11212 | return 0; | |
11213 | } | |
11214 | ||
11215 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) | |
11216 | { | |
11217 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11218 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11219 | ||
11220 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
11221 | return -EOPNOTSUPP; | |
11222 | ||
11223 | cfg80211_stop_nan(rdev, wdev); | |
11224 | ||
11225 | return 0; | |
11226 | } | |
11227 | ||
a442b761 AB |
11228 | static int validate_nan_filter(struct nlattr *filter_attr) |
11229 | { | |
11230 | struct nlattr *attr; | |
11231 | int len = 0, n_entries = 0, rem; | |
11232 | ||
11233 | nla_for_each_nested(attr, filter_attr, rem) { | |
11234 | len += nla_len(attr); | |
11235 | n_entries++; | |
11236 | } | |
11237 | ||
11238 | if (len >= U8_MAX) | |
11239 | return -EINVAL; | |
11240 | ||
11241 | return n_entries; | |
11242 | } | |
11243 | ||
11244 | static int handle_nan_filter(struct nlattr *attr_filter, | |
11245 | struct cfg80211_nan_func *func, | |
11246 | bool tx) | |
11247 | { | |
11248 | struct nlattr *attr; | |
11249 | int n_entries, rem, i; | |
11250 | struct cfg80211_nan_func_filter *filter; | |
11251 | ||
11252 | n_entries = validate_nan_filter(attr_filter); | |
11253 | if (n_entries < 0) | |
11254 | return n_entries; | |
11255 | ||
11256 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); | |
11257 | ||
11258 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); | |
11259 | if (!filter) | |
11260 | return -ENOMEM; | |
11261 | ||
11262 | i = 0; | |
11263 | nla_for_each_nested(attr, attr_filter, rem) { | |
b15ca182 | 11264 | filter[i].filter = nla_memdup(attr, GFP_KERNEL); |
a442b761 AB |
11265 | filter[i].len = nla_len(attr); |
11266 | i++; | |
11267 | } | |
11268 | if (tx) { | |
11269 | func->num_tx_filters = n_entries; | |
11270 | func->tx_filters = filter; | |
11271 | } else { | |
11272 | func->num_rx_filters = n_entries; | |
11273 | func->rx_filters = filter; | |
11274 | } | |
11275 | ||
11276 | return 0; | |
11277 | } | |
11278 | ||
11279 | static int nl80211_nan_add_func(struct sk_buff *skb, | |
11280 | struct genl_info *info) | |
11281 | { | |
11282 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11283 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11284 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; | |
11285 | struct cfg80211_nan_func *func; | |
11286 | struct sk_buff *msg = NULL; | |
11287 | void *hdr = NULL; | |
11288 | int err = 0; | |
11289 | ||
11290 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
11291 | return -EOPNOTSUPP; | |
11292 | ||
73c7da3d | 11293 | if (!wdev_running(wdev)) |
a442b761 AB |
11294 | return -ENOTCONN; |
11295 | ||
11296 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) | |
11297 | return -EINVAL; | |
11298 | ||
bfe2c7b1 JB |
11299 | err = nla_parse_nested(tb, NL80211_NAN_FUNC_ATTR_MAX, |
11300 | info->attrs[NL80211_ATTR_NAN_FUNC], | |
fe52145f | 11301 | nl80211_nan_func_policy, info->extack); |
a442b761 AB |
11302 | if (err) |
11303 | return err; | |
11304 | ||
11305 | func = kzalloc(sizeof(*func), GFP_KERNEL); | |
11306 | if (!func) | |
11307 | return -ENOMEM; | |
11308 | ||
11309 | func->cookie = wdev->wiphy->cookie_counter++; | |
11310 | ||
11311 | if (!tb[NL80211_NAN_FUNC_TYPE] || | |
11312 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { | |
11313 | err = -EINVAL; | |
11314 | goto out; | |
11315 | } | |
11316 | ||
11317 | ||
11318 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); | |
11319 | ||
11320 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { | |
11321 | err = -EINVAL; | |
11322 | goto out; | |
11323 | } | |
11324 | ||
11325 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), | |
11326 | sizeof(func->service_id)); | |
11327 | ||
11328 | func->close_range = | |
11329 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); | |
11330 | ||
11331 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { | |
11332 | func->serv_spec_info_len = | |
11333 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); | |
11334 | func->serv_spec_info = | |
11335 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), | |
11336 | func->serv_spec_info_len, | |
11337 | GFP_KERNEL); | |
11338 | if (!func->serv_spec_info) { | |
11339 | err = -ENOMEM; | |
11340 | goto out; | |
11341 | } | |
11342 | } | |
11343 | ||
11344 | if (tb[NL80211_NAN_FUNC_TTL]) | |
11345 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); | |
11346 | ||
11347 | switch (func->type) { | |
11348 | case NL80211_NAN_FUNC_PUBLISH: | |
11349 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { | |
11350 | err = -EINVAL; | |
11351 | goto out; | |
11352 | } | |
11353 | ||
11354 | func->publish_type = | |
11355 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); | |
11356 | func->publish_bcast = | |
11357 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); | |
11358 | ||
11359 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && | |
11360 | func->publish_bcast) { | |
11361 | err = -EINVAL; | |
11362 | goto out; | |
11363 | } | |
11364 | break; | |
11365 | case NL80211_NAN_FUNC_SUBSCRIBE: | |
11366 | func->subscribe_active = | |
11367 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); | |
11368 | break; | |
11369 | case NL80211_NAN_FUNC_FOLLOW_UP: | |
11370 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || | |
3ea15452 HC |
11371 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] || |
11372 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]) { | |
a442b761 AB |
11373 | err = -EINVAL; |
11374 | goto out; | |
11375 | } | |
11376 | ||
11377 | func->followup_id = | |
11378 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); | |
11379 | func->followup_reqid = | |
11380 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); | |
11381 | memcpy(func->followup_dest.addr, | |
11382 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), | |
11383 | sizeof(func->followup_dest.addr)); | |
11384 | if (func->ttl) { | |
11385 | err = -EINVAL; | |
11386 | goto out; | |
11387 | } | |
11388 | break; | |
11389 | default: | |
11390 | err = -EINVAL; | |
11391 | goto out; | |
11392 | } | |
11393 | ||
11394 | if (tb[NL80211_NAN_FUNC_SRF]) { | |
11395 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; | |
11396 | ||
bfe2c7b1 JB |
11397 | err = nla_parse_nested(srf_tb, NL80211_NAN_SRF_ATTR_MAX, |
11398 | tb[NL80211_NAN_FUNC_SRF], | |
fe52145f | 11399 | nl80211_nan_srf_policy, info->extack); |
a442b761 AB |
11400 | if (err) |
11401 | goto out; | |
11402 | ||
11403 | func->srf_include = | |
11404 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); | |
11405 | ||
11406 | if (srf_tb[NL80211_NAN_SRF_BF]) { | |
11407 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || | |
11408 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { | |
11409 | err = -EINVAL; | |
11410 | goto out; | |
11411 | } | |
11412 | ||
11413 | func->srf_bf_len = | |
11414 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); | |
11415 | func->srf_bf = | |
11416 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), | |
11417 | func->srf_bf_len, GFP_KERNEL); | |
11418 | if (!func->srf_bf) { | |
11419 | err = -ENOMEM; | |
11420 | goto out; | |
11421 | } | |
11422 | ||
11423 | func->srf_bf_idx = | |
11424 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); | |
11425 | } else { | |
11426 | struct nlattr *attr, *mac_attr = | |
11427 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; | |
11428 | int n_entries, rem, i = 0; | |
11429 | ||
11430 | if (!mac_attr) { | |
11431 | err = -EINVAL; | |
11432 | goto out; | |
11433 | } | |
11434 | ||
11435 | n_entries = validate_acl_mac_addrs(mac_attr); | |
11436 | if (n_entries <= 0) { | |
11437 | err = -EINVAL; | |
11438 | goto out; | |
11439 | } | |
11440 | ||
11441 | func->srf_num_macs = n_entries; | |
11442 | func->srf_macs = | |
11443 | kzalloc(sizeof(*func->srf_macs) * n_entries, | |
11444 | GFP_KERNEL); | |
11445 | if (!func->srf_macs) { | |
11446 | err = -ENOMEM; | |
11447 | goto out; | |
11448 | } | |
11449 | ||
11450 | nla_for_each_nested(attr, mac_attr, rem) | |
11451 | memcpy(func->srf_macs[i++].addr, nla_data(attr), | |
11452 | sizeof(*func->srf_macs)); | |
11453 | } | |
11454 | } | |
11455 | ||
11456 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { | |
11457 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], | |
11458 | func, true); | |
11459 | if (err) | |
11460 | goto out; | |
11461 | } | |
11462 | ||
11463 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { | |
11464 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], | |
11465 | func, false); | |
11466 | if (err) | |
11467 | goto out; | |
11468 | } | |
11469 | ||
11470 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11471 | if (!msg) { | |
11472 | err = -ENOMEM; | |
11473 | goto out; | |
11474 | } | |
11475 | ||
11476 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
11477 | NL80211_CMD_ADD_NAN_FUNCTION); | |
11478 | /* This can't really happen - we just allocated 4KB */ | |
11479 | if (WARN_ON(!hdr)) { | |
11480 | err = -ENOMEM; | |
11481 | goto out; | |
11482 | } | |
11483 | ||
11484 | err = rdev_add_nan_func(rdev, wdev, func); | |
11485 | out: | |
11486 | if (err < 0) { | |
11487 | cfg80211_free_nan_func(func); | |
11488 | nlmsg_free(msg); | |
11489 | return err; | |
11490 | } | |
11491 | ||
11492 | /* propagate the instance id and cookie to userspace */ | |
11493 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, | |
11494 | NL80211_ATTR_PAD)) | |
11495 | goto nla_put_failure; | |
11496 | ||
11497 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); | |
11498 | if (!func_attr) | |
11499 | goto nla_put_failure; | |
11500 | ||
11501 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, | |
11502 | func->instance_id)) | |
11503 | goto nla_put_failure; | |
11504 | ||
11505 | nla_nest_end(msg, func_attr); | |
11506 | ||
11507 | genlmsg_end(msg, hdr); | |
11508 | return genlmsg_reply(msg, info); | |
11509 | ||
11510 | nla_put_failure: | |
11511 | nlmsg_free(msg); | |
11512 | return -ENOBUFS; | |
11513 | } | |
11514 | ||
11515 | static int nl80211_nan_del_func(struct sk_buff *skb, | |
11516 | struct genl_info *info) | |
11517 | { | |
11518 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11519 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11520 | u64 cookie; | |
11521 | ||
11522 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
11523 | return -EOPNOTSUPP; | |
11524 | ||
73c7da3d | 11525 | if (!wdev_running(wdev)) |
a442b761 AB |
11526 | return -ENOTCONN; |
11527 | ||
11528 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
11529 | return -EINVAL; | |
11530 | ||
a442b761 AB |
11531 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
11532 | ||
11533 | rdev_del_nan_func(rdev, wdev, cookie); | |
11534 | ||
11535 | return 0; | |
11536 | } | |
11537 | ||
a5a9dcf2 AB |
11538 | static int nl80211_nan_change_config(struct sk_buff *skb, |
11539 | struct genl_info *info) | |
11540 | { | |
11541 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11542 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11543 | struct cfg80211_nan_conf conf = {}; | |
11544 | u32 changed = 0; | |
11545 | ||
11546 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
11547 | return -EOPNOTSUPP; | |
11548 | ||
73c7da3d | 11549 | if (!wdev_running(wdev)) |
a5a9dcf2 AB |
11550 | return -ENOTCONN; |
11551 | ||
11552 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { | |
11553 | conf.master_pref = | |
11554 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
11555 | if (conf.master_pref <= 1 || conf.master_pref == 255) | |
11556 | return -EINVAL; | |
11557 | ||
11558 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; | |
11559 | } | |
11560 | ||
8585989d LC |
11561 | if (info->attrs[NL80211_ATTR_BANDS]) { |
11562 | u32 bands = nla_get_u32(info->attrs[NL80211_ATTR_BANDS]); | |
11563 | ||
11564 | if (bands & ~(u32)wdev->wiphy->nan_supported_bands) | |
11565 | return -EOPNOTSUPP; | |
11566 | ||
11567 | if (bands && !(bands & BIT(NL80211_BAND_2GHZ))) | |
11568 | return -EINVAL; | |
11569 | ||
11570 | conf.bands = bands; | |
11571 | changed |= CFG80211_NAN_CONF_CHANGED_BANDS; | |
a5a9dcf2 AB |
11572 | } |
11573 | ||
11574 | if (!changed) | |
11575 | return -EINVAL; | |
11576 | ||
11577 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); | |
11578 | } | |
11579 | ||
50bcd31d AB |
11580 | void cfg80211_nan_match(struct wireless_dev *wdev, |
11581 | struct cfg80211_nan_match_params *match, gfp_t gfp) | |
11582 | { | |
11583 | struct wiphy *wiphy = wdev->wiphy; | |
11584 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
11585 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; | |
11586 | struct sk_buff *msg; | |
11587 | void *hdr; | |
11588 | ||
11589 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) | |
11590 | return; | |
11591 | ||
11592 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11593 | if (!msg) | |
11594 | return; | |
11595 | ||
11596 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); | |
11597 | if (!hdr) { | |
11598 | nlmsg_free(msg); | |
11599 | return; | |
11600 | } | |
11601 | ||
11602 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11603 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11604 | wdev->netdev->ifindex)) || | |
11605 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
11606 | NL80211_ATTR_PAD)) | |
11607 | goto nla_put_failure; | |
11608 | ||
11609 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, | |
11610 | NL80211_ATTR_PAD) || | |
11611 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) | |
11612 | goto nla_put_failure; | |
11613 | ||
11614 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); | |
11615 | if (!match_attr) | |
11616 | goto nla_put_failure; | |
11617 | ||
11618 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); | |
11619 | if (!local_func_attr) | |
11620 | goto nla_put_failure; | |
11621 | ||
11622 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) | |
11623 | goto nla_put_failure; | |
11624 | ||
11625 | nla_nest_end(msg, local_func_attr); | |
11626 | ||
11627 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); | |
11628 | if (!peer_func_attr) | |
11629 | goto nla_put_failure; | |
11630 | ||
11631 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || | |
11632 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) | |
11633 | goto nla_put_failure; | |
11634 | ||
11635 | if (match->info && match->info_len && | |
11636 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, | |
11637 | match->info)) | |
11638 | goto nla_put_failure; | |
11639 | ||
11640 | nla_nest_end(msg, peer_func_attr); | |
11641 | nla_nest_end(msg, match_attr); | |
11642 | genlmsg_end(msg, hdr); | |
11643 | ||
11644 | if (!wdev->owner_nlportid) | |
11645 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
11646 | msg, 0, NL80211_MCGRP_NAN, gfp); | |
11647 | else | |
11648 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
11649 | wdev->owner_nlportid); | |
11650 | ||
11651 | return; | |
11652 | ||
11653 | nla_put_failure: | |
11654 | nlmsg_free(msg); | |
11655 | } | |
11656 | EXPORT_SYMBOL(cfg80211_nan_match); | |
11657 | ||
368e5a7b AB |
11658 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
11659 | u8 inst_id, | |
11660 | enum nl80211_nan_func_term_reason reason, | |
11661 | u64 cookie, gfp_t gfp) | |
11662 | { | |
11663 | struct wiphy *wiphy = wdev->wiphy; | |
11664 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
11665 | struct sk_buff *msg; | |
11666 | struct nlattr *func_attr; | |
11667 | void *hdr; | |
11668 | ||
11669 | if (WARN_ON(!inst_id)) | |
11670 | return; | |
11671 | ||
11672 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11673 | if (!msg) | |
11674 | return; | |
11675 | ||
11676 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); | |
11677 | if (!hdr) { | |
11678 | nlmsg_free(msg); | |
11679 | return; | |
11680 | } | |
11681 | ||
11682 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11683 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11684 | wdev->netdev->ifindex)) || | |
11685 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
11686 | NL80211_ATTR_PAD)) | |
11687 | goto nla_put_failure; | |
11688 | ||
11689 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | |
11690 | NL80211_ATTR_PAD)) | |
11691 | goto nla_put_failure; | |
11692 | ||
11693 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); | |
11694 | if (!func_attr) | |
11695 | goto nla_put_failure; | |
11696 | ||
11697 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || | |
11698 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) | |
11699 | goto nla_put_failure; | |
11700 | ||
11701 | nla_nest_end(msg, func_attr); | |
11702 | genlmsg_end(msg, hdr); | |
11703 | ||
11704 | if (!wdev->owner_nlportid) | |
11705 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
11706 | msg, 0, NL80211_MCGRP_NAN, gfp); | |
11707 | else | |
11708 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
11709 | wdev->owner_nlportid); | |
11710 | ||
11711 | return; | |
11712 | ||
11713 | nla_put_failure: | |
11714 | nlmsg_free(msg); | |
11715 | } | |
11716 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); | |
11717 | ||
3713b4e3 JB |
11718 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
11719 | struct genl_info *info) | |
11720 | { | |
11721 | void *hdr; | |
11722 | struct sk_buff *msg; | |
11723 | ||
11724 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11725 | if (!msg) | |
11726 | return -ENOMEM; | |
11727 | ||
11728 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
11729 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
11730 | if (!hdr) | |
11731 | goto nla_put_failure; | |
11732 | ||
11733 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
11734 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
11735 | goto nla_put_failure; | |
11736 | ||
11737 | genlmsg_end(msg, hdr); | |
11738 | return genlmsg_reply(msg, info); | |
11739 | ||
11740 | nla_put_failure: | |
11741 | kfree_skb(msg); | |
11742 | return -ENOBUFS; | |
11743 | } | |
11744 | ||
355199e0 JM |
11745 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
11746 | { | |
11747 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11748 | struct cfg80211_update_ft_ies_params ft_params; | |
11749 | struct net_device *dev = info->user_ptr[1]; | |
11750 | ||
11751 | if (!rdev->ops->update_ft_ies) | |
11752 | return -EOPNOTSUPP; | |
11753 | ||
11754 | if (!info->attrs[NL80211_ATTR_MDID] || | |
11755 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
11756 | return -EINVAL; | |
11757 | ||
11758 | memset(&ft_params, 0, sizeof(ft_params)); | |
11759 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
11760 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
11761 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
11762 | ||
11763 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
11764 | } | |
11765 | ||
5de17984 AS |
11766 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
11767 | struct genl_info *info) | |
11768 | { | |
11769 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11770 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11771 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
11772 | u16 duration; | |
11773 | int ret; | |
11774 | ||
11775 | if (!rdev->ops->crit_proto_start) | |
11776 | return -EOPNOTSUPP; | |
11777 | ||
11778 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
11779 | return -EINVAL; | |
11780 | ||
11781 | if (rdev->crit_proto_nlportid) | |
11782 | return -EBUSY; | |
11783 | ||
11784 | /* determine protocol if provided */ | |
11785 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
11786 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
11787 | ||
11788 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
11789 | return -EINVAL; | |
11790 | ||
11791 | /* timeout must be provided */ | |
11792 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
11793 | return -EINVAL; | |
11794 | ||
11795 | duration = | |
11796 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
11797 | ||
11798 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
11799 | return -ERANGE; | |
11800 | ||
11801 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
11802 | if (!ret) | |
11803 | rdev->crit_proto_nlportid = info->snd_portid; | |
11804 | ||
11805 | return ret; | |
11806 | } | |
11807 | ||
11808 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
11809 | struct genl_info *info) | |
11810 | { | |
11811 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11812 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11813 | ||
11814 | if (!rdev->ops->crit_proto_stop) | |
11815 | return -EOPNOTSUPP; | |
11816 | ||
11817 | if (rdev->crit_proto_nlportid) { | |
11818 | rdev->crit_proto_nlportid = 0; | |
11819 | rdev_crit_proto_stop(rdev, wdev); | |
11820 | } | |
11821 | return 0; | |
11822 | } | |
11823 | ||
ad7e718c JB |
11824 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
11825 | { | |
11826 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11827 | struct wireless_dev *wdev = | |
11828 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
11829 | int i, err; | |
11830 | u32 vid, subcmd; | |
11831 | ||
11832 | if (!rdev->wiphy.vendor_commands) | |
11833 | return -EOPNOTSUPP; | |
11834 | ||
11835 | if (IS_ERR(wdev)) { | |
11836 | err = PTR_ERR(wdev); | |
11837 | if (err != -EINVAL) | |
11838 | return err; | |
11839 | wdev = NULL; | |
11840 | } else if (wdev->wiphy != &rdev->wiphy) { | |
11841 | return -EINVAL; | |
11842 | } | |
11843 | ||
11844 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
11845 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
11846 | return -EINVAL; | |
11847 | ||
11848 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
11849 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
11850 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
11851 | const struct wiphy_vendor_command *vcmd; | |
11852 | void *data = NULL; | |
11853 | int len = 0; | |
11854 | ||
11855 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
11856 | ||
11857 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
11858 | continue; | |
11859 | ||
11860 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
11861 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
11862 | if (!wdev) | |
11863 | return -EINVAL; | |
11864 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
11865 | !wdev->netdev) | |
11866 | return -EINVAL; | |
11867 | ||
11868 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
73c7da3d | 11869 | if (!wdev_running(wdev)) |
ad7e718c JB |
11870 | return -ENETDOWN; |
11871 | } | |
7bdbe400 JB |
11872 | |
11873 | if (!vcmd->doit) | |
11874 | return -EOPNOTSUPP; | |
ad7e718c JB |
11875 | } else { |
11876 | wdev = NULL; | |
11877 | } | |
11878 | ||
11879 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
11880 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
11881 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
11882 | } | |
11883 | ||
11884 | rdev->cur_cmd_info = info; | |
11885 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
11886 | data, len); | |
11887 | rdev->cur_cmd_info = NULL; | |
11888 | return err; | |
11889 | } | |
11890 | ||
11891 | return -EOPNOTSUPP; | |
11892 | } | |
11893 | ||
7bdbe400 JB |
11894 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
11895 | struct netlink_callback *cb, | |
11896 | struct cfg80211_registered_device **rdev, | |
11897 | struct wireless_dev **wdev) | |
11898 | { | |
c90c39da | 11899 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
7bdbe400 JB |
11900 | u32 vid, subcmd; |
11901 | unsigned int i; | |
11902 | int vcmd_idx = -1; | |
11903 | int err; | |
11904 | void *data = NULL; | |
11905 | unsigned int data_len = 0; | |
11906 | ||
7bdbe400 JB |
11907 | if (cb->args[0]) { |
11908 | /* subtract the 1 again here */ | |
11909 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
11910 | struct wireless_dev *tmp; | |
11911 | ||
ea90e0dc JB |
11912 | if (!wiphy) |
11913 | return -ENODEV; | |
7bdbe400 JB |
11914 | *rdev = wiphy_to_rdev(wiphy); |
11915 | *wdev = NULL; | |
11916 | ||
11917 | if (cb->args[1]) { | |
53873f13 | 11918 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
7bdbe400 JB |
11919 | if (tmp->identifier == cb->args[1] - 1) { |
11920 | *wdev = tmp; | |
11921 | break; | |
11922 | } | |
11923 | } | |
11924 | } | |
11925 | ||
11926 | /* keep rtnl locked in successful case */ | |
11927 | return 0; | |
11928 | } | |
11929 | ||
fceb6435 JB |
11930 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, attrbuf, |
11931 | nl80211_fam.maxattr, nl80211_policy, NULL); | |
7bdbe400 | 11932 | if (err) |
ea90e0dc | 11933 | return err; |
7bdbe400 | 11934 | |
c90c39da | 11935 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
ea90e0dc JB |
11936 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) |
11937 | return -EINVAL; | |
7bdbe400 | 11938 | |
c90c39da | 11939 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
7bdbe400 JB |
11940 | if (IS_ERR(*wdev)) |
11941 | *wdev = NULL; | |
11942 | ||
c90c39da | 11943 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
ea90e0dc JB |
11944 | if (IS_ERR(*rdev)) |
11945 | return PTR_ERR(*rdev); | |
7bdbe400 | 11946 | |
c90c39da JB |
11947 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
11948 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); | |
7bdbe400 JB |
11949 | |
11950 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { | |
11951 | const struct wiphy_vendor_command *vcmd; | |
11952 | ||
11953 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; | |
11954 | ||
11955 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
11956 | continue; | |
11957 | ||
ea90e0dc JB |
11958 | if (!vcmd->dumpit) |
11959 | return -EOPNOTSUPP; | |
7bdbe400 JB |
11960 | |
11961 | vcmd_idx = i; | |
11962 | break; | |
11963 | } | |
11964 | ||
ea90e0dc JB |
11965 | if (vcmd_idx < 0) |
11966 | return -EOPNOTSUPP; | |
7bdbe400 | 11967 | |
c90c39da JB |
11968 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
11969 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
11970 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
7bdbe400 JB |
11971 | } |
11972 | ||
11973 | /* 0 is the first index - add 1 to parse only once */ | |
11974 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
11975 | /* add 1 to know if it was NULL */ | |
11976 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; | |
11977 | cb->args[2] = vcmd_idx; | |
11978 | cb->args[3] = (unsigned long)data; | |
11979 | cb->args[4] = data_len; | |
11980 | ||
11981 | /* keep rtnl locked in successful case */ | |
11982 | return 0; | |
7bdbe400 JB |
11983 | } |
11984 | ||
11985 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, | |
11986 | struct netlink_callback *cb) | |
11987 | { | |
11988 | struct cfg80211_registered_device *rdev; | |
11989 | struct wireless_dev *wdev; | |
11990 | unsigned int vcmd_idx; | |
11991 | const struct wiphy_vendor_command *vcmd; | |
11992 | void *data; | |
11993 | int data_len; | |
11994 | int err; | |
11995 | struct nlattr *vendor_data; | |
11996 | ||
ea90e0dc | 11997 | rtnl_lock(); |
7bdbe400 JB |
11998 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); |
11999 | if (err) | |
ea90e0dc | 12000 | goto out; |
7bdbe400 JB |
12001 | |
12002 | vcmd_idx = cb->args[2]; | |
12003 | data = (void *)cb->args[3]; | |
12004 | data_len = cb->args[4]; | |
12005 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; | |
12006 | ||
12007 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
12008 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
ea90e0dc JB |
12009 | if (!wdev) { |
12010 | err = -EINVAL; | |
12011 | goto out; | |
12012 | } | |
7bdbe400 | 12013 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && |
ea90e0dc JB |
12014 | !wdev->netdev) { |
12015 | err = -EINVAL; | |
12016 | goto out; | |
12017 | } | |
7bdbe400 JB |
12018 | |
12019 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
ea90e0dc JB |
12020 | if (!wdev_running(wdev)) { |
12021 | err = -ENETDOWN; | |
12022 | goto out; | |
12023 | } | |
7bdbe400 JB |
12024 | } |
12025 | } | |
12026 | ||
12027 | while (1) { | |
12028 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | |
12029 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
12030 | NL80211_CMD_VENDOR); | |
12031 | if (!hdr) | |
12032 | break; | |
12033 | ||
12034 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
12035 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
12036 | wdev_id(wdev), | |
12037 | NL80211_ATTR_PAD))) { | |
7bdbe400 JB |
12038 | genlmsg_cancel(skb, hdr); |
12039 | break; | |
12040 | } | |
12041 | ||
12042 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); | |
12043 | if (!vendor_data) { | |
12044 | genlmsg_cancel(skb, hdr); | |
12045 | break; | |
12046 | } | |
12047 | ||
12048 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, | |
12049 | (unsigned long *)&cb->args[5]); | |
12050 | nla_nest_end(skb, vendor_data); | |
12051 | ||
12052 | if (err == -ENOBUFS || err == -ENOENT) { | |
12053 | genlmsg_cancel(skb, hdr); | |
12054 | break; | |
12055 | } else if (err) { | |
12056 | genlmsg_cancel(skb, hdr); | |
12057 | goto out; | |
12058 | } | |
12059 | ||
12060 | genlmsg_end(skb, hdr); | |
12061 | } | |
12062 | ||
12063 | err = skb->len; | |
12064 | out: | |
12065 | rtnl_unlock(); | |
12066 | return err; | |
12067 | } | |
12068 | ||
ad7e718c JB |
12069 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
12070 | enum nl80211_commands cmd, | |
12071 | enum nl80211_attrs attr, | |
12072 | int approxlen) | |
12073 | { | |
f26cbf40 | 12074 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
12075 | |
12076 | if (WARN_ON(!rdev->cur_cmd_info)) | |
12077 | return NULL; | |
12078 | ||
6c09e791 | 12079 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
12080 | rdev->cur_cmd_info->snd_portid, |
12081 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 12082 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
12083 | } |
12084 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
12085 | ||
12086 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
12087 | { | |
12088 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
12089 | void *hdr = ((void **)skb->cb)[1]; | |
12090 | struct nlattr *data = ((void **)skb->cb)[2]; | |
12091 | ||
bd8c78e7 JB |
12092 | /* clear CB data for netlink core to own from now on */ |
12093 | memset(skb->cb, 0, sizeof(skb->cb)); | |
12094 | ||
ad7e718c JB |
12095 | if (WARN_ON(!rdev->cur_cmd_info)) { |
12096 | kfree_skb(skb); | |
12097 | return -EINVAL; | |
12098 | } | |
12099 | ||
12100 | nla_nest_end(skb, data); | |
12101 | genlmsg_end(skb, hdr); | |
12102 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
12103 | } | |
12104 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
12105 | ||
fa9ffc74 KP |
12106 | static int nl80211_set_qos_map(struct sk_buff *skb, |
12107 | struct genl_info *info) | |
12108 | { | |
12109 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12110 | struct cfg80211_qos_map *qos_map = NULL; | |
12111 | struct net_device *dev = info->user_ptr[1]; | |
12112 | u8 *pos, len, num_des, des_len, des; | |
12113 | int ret; | |
12114 | ||
12115 | if (!rdev->ops->set_qos_map) | |
12116 | return -EOPNOTSUPP; | |
12117 | ||
12118 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
12119 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
12120 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
12121 | ||
12122 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
12123 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
12124 | return -EINVAL; | |
12125 | ||
12126 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
12127 | if (!qos_map) | |
12128 | return -ENOMEM; | |
12129 | ||
12130 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
12131 | if (num_des) { | |
12132 | des_len = num_des * | |
12133 | sizeof(struct cfg80211_dscp_exception); | |
12134 | memcpy(qos_map->dscp_exception, pos, des_len); | |
12135 | qos_map->num_des = num_des; | |
12136 | for (des = 0; des < num_des; des++) { | |
12137 | if (qos_map->dscp_exception[des].up > 7) { | |
12138 | kfree(qos_map); | |
12139 | return -EINVAL; | |
12140 | } | |
12141 | } | |
12142 | pos += des_len; | |
12143 | } | |
12144 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
12145 | } | |
12146 | ||
12147 | wdev_lock(dev->ieee80211_ptr); | |
12148 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
12149 | if (!ret) | |
12150 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
12151 | wdev_unlock(dev->ieee80211_ptr); | |
12152 | ||
12153 | kfree(qos_map); | |
12154 | return ret; | |
12155 | } | |
12156 | ||
960d01ac JB |
12157 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
12158 | { | |
12159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12160 | struct net_device *dev = info->user_ptr[1]; | |
12161 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12162 | const u8 *peer; | |
12163 | u8 tsid, up; | |
12164 | u16 admitted_time = 0; | |
12165 | int err; | |
12166 | ||
723e73ac | 12167 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
12168 | return -EOPNOTSUPP; |
12169 | ||
12170 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
12171 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
12172 | return -EINVAL; | |
12173 | ||
12174 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
12175 | if (tsid >= IEEE80211_NUM_TIDS) | |
12176 | return -EINVAL; | |
12177 | ||
12178 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
12179 | if (up >= IEEE80211_NUM_UPS) | |
12180 | return -EINVAL; | |
12181 | ||
12182 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 12183 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 12184 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
12185 | * need more attributes for that (e.g. BA session requirement); |
12186 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
12187 | */ |
12188 | return -EINVAL; | |
12189 | } | |
12190 | ||
12191 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
12192 | ||
12193 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
12194 | admitted_time = | |
12195 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
12196 | if (!admitted_time) | |
12197 | return -EINVAL; | |
12198 | } | |
12199 | ||
12200 | wdev_lock(wdev); | |
12201 | switch (wdev->iftype) { | |
12202 | case NL80211_IFTYPE_STATION: | |
12203 | case NL80211_IFTYPE_P2P_CLIENT: | |
12204 | if (wdev->current_bss) | |
12205 | break; | |
12206 | err = -ENOTCONN; | |
12207 | goto out; | |
12208 | default: | |
12209 | err = -EOPNOTSUPP; | |
12210 | goto out; | |
12211 | } | |
12212 | ||
12213 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
12214 | ||
12215 | out: | |
12216 | wdev_unlock(wdev); | |
12217 | return err; | |
12218 | } | |
12219 | ||
12220 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
12221 | { | |
12222 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12223 | struct net_device *dev = info->user_ptr[1]; | |
12224 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12225 | const u8 *peer; | |
12226 | u8 tsid; | |
12227 | int err; | |
12228 | ||
12229 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
12230 | return -EINVAL; | |
12231 | ||
12232 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
12233 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
12234 | ||
12235 | wdev_lock(wdev); | |
12236 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
12237 | wdev_unlock(wdev); | |
12238 | ||
12239 | return err; | |
12240 | } | |
12241 | ||
1057d35e AN |
12242 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
12243 | struct genl_info *info) | |
12244 | { | |
12245 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12246 | struct net_device *dev = info->user_ptr[1]; | |
12247 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12248 | struct cfg80211_chan_def chandef = {}; | |
12249 | const u8 *addr; | |
12250 | u8 oper_class; | |
12251 | int err; | |
12252 | ||
12253 | if (!rdev->ops->tdls_channel_switch || | |
12254 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
12255 | return -EOPNOTSUPP; | |
12256 | ||
12257 | switch (dev->ieee80211_ptr->iftype) { | |
12258 | case NL80211_IFTYPE_STATION: | |
12259 | case NL80211_IFTYPE_P2P_CLIENT: | |
12260 | break; | |
12261 | default: | |
12262 | return -EOPNOTSUPP; | |
12263 | } | |
12264 | ||
12265 | if (!info->attrs[NL80211_ATTR_MAC] || | |
12266 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
12267 | return -EINVAL; | |
12268 | ||
12269 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
12270 | if (err) | |
12271 | return err; | |
12272 | ||
12273 | /* | |
12274 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
12275 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
12276 | * specification is not defined for them. | |
12277 | */ | |
57fbcce3 | 12278 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
1057d35e AN |
12279 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
12280 | chandef.width != NL80211_CHAN_WIDTH_20) | |
12281 | return -EINVAL; | |
12282 | ||
12283 | /* we will be active on the TDLS link */ | |
923b352f AN |
12284 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
12285 | wdev->iftype)) | |
1057d35e AN |
12286 | return -EINVAL; |
12287 | ||
12288 | /* don't allow switching to DFS channels */ | |
12289 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
12290 | return -EINVAL; | |
12291 | ||
12292 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
12293 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
12294 | ||
12295 | wdev_lock(wdev); | |
12296 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
12297 | wdev_unlock(wdev); | |
12298 | ||
12299 | return err; | |
12300 | } | |
12301 | ||
12302 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
12303 | struct genl_info *info) | |
12304 | { | |
12305 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12306 | struct net_device *dev = info->user_ptr[1]; | |
12307 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12308 | const u8 *addr; | |
12309 | ||
12310 | if (!rdev->ops->tdls_channel_switch || | |
12311 | !rdev->ops->tdls_cancel_channel_switch || | |
12312 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
12313 | return -EOPNOTSUPP; | |
12314 | ||
12315 | switch (dev->ieee80211_ptr->iftype) { | |
12316 | case NL80211_IFTYPE_STATION: | |
12317 | case NL80211_IFTYPE_P2P_CLIENT: | |
12318 | break; | |
12319 | default: | |
12320 | return -EOPNOTSUPP; | |
12321 | } | |
12322 | ||
12323 | if (!info->attrs[NL80211_ATTR_MAC]) | |
12324 | return -EINVAL; | |
12325 | ||
12326 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
12327 | ||
12328 | wdev_lock(wdev); | |
12329 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
12330 | wdev_unlock(wdev); | |
12331 | ||
12332 | return 0; | |
12333 | } | |
12334 | ||
ce0ce13a MB |
12335 | static int nl80211_set_multicast_to_unicast(struct sk_buff *skb, |
12336 | struct genl_info *info) | |
12337 | { | |
12338 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12339 | struct net_device *dev = info->user_ptr[1]; | |
12340 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12341 | const struct nlattr *nla; | |
12342 | bool enabled; | |
12343 | ||
ce0ce13a MB |
12344 | if (!rdev->ops->set_multicast_to_unicast) |
12345 | return -EOPNOTSUPP; | |
12346 | ||
12347 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
12348 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
12349 | return -EOPNOTSUPP; | |
12350 | ||
12351 | nla = info->attrs[NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED]; | |
12352 | enabled = nla_get_flag(nla); | |
12353 | ||
12354 | return rdev_set_multicast_to_unicast(rdev, dev, enabled); | |
12355 | } | |
12356 | ||
3a00df57 AS |
12357 | static int nl80211_set_pmk(struct sk_buff *skb, struct genl_info *info) |
12358 | { | |
12359 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12360 | struct net_device *dev = info->user_ptr[1]; | |
12361 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12362 | struct cfg80211_pmk_conf pmk_conf = {}; | |
12363 | int ret; | |
12364 | ||
12365 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
12366 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
12367 | return -EOPNOTSUPP; | |
12368 | ||
12369 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
12370 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
12371 | return -EOPNOTSUPP; | |
12372 | ||
12373 | if (!info->attrs[NL80211_ATTR_MAC] || !info->attrs[NL80211_ATTR_PMK]) | |
12374 | return -EINVAL; | |
12375 | ||
12376 | wdev_lock(wdev); | |
12377 | if (!wdev->current_bss) { | |
12378 | ret = -ENOTCONN; | |
12379 | goto out; | |
12380 | } | |
12381 | ||
12382 | pmk_conf.aa = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
12383 | if (memcmp(pmk_conf.aa, wdev->current_bss->pub.bssid, ETH_ALEN)) { | |
12384 | ret = -EINVAL; | |
12385 | goto out; | |
12386 | } | |
12387 | ||
12388 | pmk_conf.pmk = nla_data(info->attrs[NL80211_ATTR_PMK]); | |
12389 | pmk_conf.pmk_len = nla_len(info->attrs[NL80211_ATTR_PMK]); | |
12390 | if (pmk_conf.pmk_len != WLAN_PMK_LEN && | |
12391 | pmk_conf.pmk_len != WLAN_PMK_LEN_SUITE_B_192) { | |
12392 | ret = -EINVAL; | |
12393 | goto out; | |
12394 | } | |
12395 | ||
12396 | if (info->attrs[NL80211_ATTR_PMKR0_NAME]) { | |
12397 | int r0_name_len = nla_len(info->attrs[NL80211_ATTR_PMKR0_NAME]); | |
12398 | ||
12399 | if (r0_name_len != WLAN_PMK_NAME_LEN) { | |
12400 | ret = -EINVAL; | |
12401 | goto out; | |
12402 | } | |
12403 | ||
12404 | pmk_conf.pmk_r0_name = | |
12405 | nla_data(info->attrs[NL80211_ATTR_PMKR0_NAME]); | |
12406 | } | |
12407 | ||
12408 | ret = rdev_set_pmk(rdev, dev, &pmk_conf); | |
12409 | out: | |
12410 | wdev_unlock(wdev); | |
12411 | return ret; | |
12412 | } | |
12413 | ||
12414 | static int nl80211_del_pmk(struct sk_buff *skb, struct genl_info *info) | |
12415 | { | |
12416 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
12417 | struct net_device *dev = info->user_ptr[1]; | |
12418 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12419 | const u8 *aa; | |
12420 | int ret; | |
12421 | ||
12422 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
12423 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
12424 | return -EOPNOTSUPP; | |
12425 | ||
12426 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
12427 | NL80211_EXT_FEATURE_4WAY_HANDSHAKE_STA_1X)) | |
12428 | return -EOPNOTSUPP; | |
12429 | ||
12430 | if (!info->attrs[NL80211_ATTR_MAC]) | |
12431 | return -EINVAL; | |
12432 | ||
12433 | wdev_lock(wdev); | |
12434 | aa = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
12435 | ret = rdev_del_pmk(rdev, dev, aa); | |
12436 | wdev_unlock(wdev); | |
12437 | ||
12438 | return ret; | |
12439 | } | |
12440 | ||
4c476991 JB |
12441 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
12442 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
12443 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
12444 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
12445 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
12446 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 12447 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 12448 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
12449 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
12450 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 12451 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 12452 | |
f84f771d | 12453 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
12454 | struct genl_info *info) |
12455 | { | |
12456 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 12457 | struct wireless_dev *wdev; |
4c476991 | 12458 | struct net_device *dev; |
4c476991 JB |
12459 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
12460 | ||
12461 | if (rtnl) | |
12462 | rtnl_lock(); | |
12463 | ||
12464 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 12465 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
12466 | if (IS_ERR(rdev)) { |
12467 | if (rtnl) | |
12468 | rtnl_unlock(); | |
12469 | return PTR_ERR(rdev); | |
12470 | } | |
12471 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
12472 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
12473 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
12474 | ASSERT_RTNL(); |
12475 | ||
89a54e48 JB |
12476 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
12477 | info->attrs); | |
12478 | if (IS_ERR(wdev)) { | |
4c476991 JB |
12479 | if (rtnl) |
12480 | rtnl_unlock(); | |
89a54e48 | 12481 | return PTR_ERR(wdev); |
4c476991 | 12482 | } |
89a54e48 | 12483 | |
89a54e48 | 12484 | dev = wdev->netdev; |
f26cbf40 | 12485 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 12486 | |
1bf614ef JB |
12487 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
12488 | if (!dev) { | |
1bf614ef JB |
12489 | if (rtnl) |
12490 | rtnl_unlock(); | |
12491 | return -EINVAL; | |
12492 | } | |
12493 | ||
12494 | info->user_ptr[1] = dev; | |
12495 | } else { | |
12496 | info->user_ptr[1] = wdev; | |
41265714 | 12497 | } |
1bf614ef | 12498 | |
73c7da3d AVS |
12499 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && |
12500 | !wdev_running(wdev)) { | |
12501 | if (rtnl) | |
12502 | rtnl_unlock(); | |
12503 | return -ENETDOWN; | |
12504 | } | |
1bf614ef | 12505 | |
73c7da3d | 12506 | if (dev) |
1bf614ef | 12507 | dev_hold(dev); |
89a54e48 | 12508 | |
4c476991 | 12509 | info->user_ptr[0] = rdev; |
4c476991 JB |
12510 | } |
12511 | ||
12512 | return 0; | |
12513 | } | |
12514 | ||
f84f771d | 12515 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
12516 | struct genl_info *info) |
12517 | { | |
1bf614ef JB |
12518 | if (info->user_ptr[1]) { |
12519 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
12520 | struct wireless_dev *wdev = info->user_ptr[1]; | |
12521 | ||
12522 | if (wdev->netdev) | |
12523 | dev_put(wdev->netdev); | |
12524 | } else { | |
12525 | dev_put(info->user_ptr[1]); | |
12526 | } | |
12527 | } | |
5393b917 | 12528 | |
4c476991 JB |
12529 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
12530 | rtnl_unlock(); | |
5393b917 JB |
12531 | |
12532 | /* If needed, clear the netlink message payload from the SKB | |
12533 | * as it might contain key data that shouldn't stick around on | |
12534 | * the heap after the SKB is freed. The netlink message header | |
12535 | * is still needed for further processing, so leave it intact. | |
12536 | */ | |
12537 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
12538 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
12539 | ||
12540 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
12541 | } | |
4c476991 JB |
12542 | } |
12543 | ||
4534de83 | 12544 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
12545 | { |
12546 | .cmd = NL80211_CMD_GET_WIPHY, | |
12547 | .doit = nl80211_get_wiphy, | |
12548 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 12549 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
12550 | .policy = nl80211_policy, |
12551 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
12552 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12553 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
12554 | }, |
12555 | { | |
12556 | .cmd = NL80211_CMD_SET_WIPHY, | |
12557 | .doit = nl80211_set_wiphy, | |
12558 | .policy = nl80211_policy, | |
5617c6cd | 12559 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 | 12560 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
12561 | }, |
12562 | { | |
12563 | .cmd = NL80211_CMD_GET_INTERFACE, | |
12564 | .doit = nl80211_get_interface, | |
12565 | .dumpit = nl80211_dump_interface, | |
12566 | .policy = nl80211_policy, | |
12567 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
12568 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
12569 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
12570 | }, |
12571 | { | |
12572 | .cmd = NL80211_CMD_SET_INTERFACE, | |
12573 | .doit = nl80211_set_interface, | |
12574 | .policy = nl80211_policy, | |
5617c6cd | 12575 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12576 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12577 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
12578 | }, |
12579 | { | |
12580 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
12581 | .doit = nl80211_new_interface, | |
12582 | .policy = nl80211_policy, | |
5617c6cd | 12583 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12584 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12585 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
12586 | }, |
12587 | { | |
12588 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
12589 | .doit = nl80211_del_interface, | |
12590 | .policy = nl80211_policy, | |
5617c6cd | 12591 | .flags = GENL_UNS_ADMIN_PERM, |
84efbb84 | 12592 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 12593 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
12594 | }, |
12595 | { | |
12596 | .cmd = NL80211_CMD_GET_KEY, | |
12597 | .doit = nl80211_get_key, | |
12598 | .policy = nl80211_policy, | |
5617c6cd | 12599 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12600 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12601 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
12602 | }, |
12603 | { | |
12604 | .cmd = NL80211_CMD_SET_KEY, | |
12605 | .doit = nl80211_set_key, | |
12606 | .policy = nl80211_policy, | |
5617c6cd | 12607 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12608 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
12609 | NL80211_FLAG_NEED_RTNL | |
12610 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
12611 | }, |
12612 | { | |
12613 | .cmd = NL80211_CMD_NEW_KEY, | |
12614 | .doit = nl80211_new_key, | |
12615 | .policy = nl80211_policy, | |
5617c6cd | 12616 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12617 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
12618 | NL80211_FLAG_NEED_RTNL | |
12619 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
12620 | }, |
12621 | { | |
12622 | .cmd = NL80211_CMD_DEL_KEY, | |
12623 | .doit = nl80211_del_key, | |
12624 | .policy = nl80211_policy, | |
5617c6cd | 12625 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12626 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12627 | NL80211_FLAG_NEED_RTNL, |
55682965 | 12628 | }, |
ed1b6cc7 JB |
12629 | { |
12630 | .cmd = NL80211_CMD_SET_BEACON, | |
12631 | .policy = nl80211_policy, | |
5617c6cd | 12632 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 12633 | .doit = nl80211_set_beacon, |
2b5f8b0b | 12634 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12635 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
12636 | }, |
12637 | { | |
8860020e | 12638 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 | 12639 | .policy = nl80211_policy, |
5617c6cd | 12640 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 12641 | .doit = nl80211_start_ap, |
2b5f8b0b | 12642 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12643 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
12644 | }, |
12645 | { | |
8860020e | 12646 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 | 12647 | .policy = nl80211_policy, |
5617c6cd | 12648 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 12649 | .doit = nl80211_stop_ap, |
2b5f8b0b | 12650 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12651 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 12652 | }, |
5727ef1b JB |
12653 | { |
12654 | .cmd = NL80211_CMD_GET_STATION, | |
12655 | .doit = nl80211_get_station, | |
2ec600d6 | 12656 | .dumpit = nl80211_dump_station, |
5727ef1b | 12657 | .policy = nl80211_policy, |
4c476991 JB |
12658 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12659 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
12660 | }, |
12661 | { | |
12662 | .cmd = NL80211_CMD_SET_STATION, | |
12663 | .doit = nl80211_set_station, | |
12664 | .policy = nl80211_policy, | |
5617c6cd | 12665 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12666 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12667 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
12668 | }, |
12669 | { | |
12670 | .cmd = NL80211_CMD_NEW_STATION, | |
12671 | .doit = nl80211_new_station, | |
12672 | .policy = nl80211_policy, | |
5617c6cd | 12673 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12674 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12675 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
12676 | }, |
12677 | { | |
12678 | .cmd = NL80211_CMD_DEL_STATION, | |
12679 | .doit = nl80211_del_station, | |
12680 | .policy = nl80211_policy, | |
5617c6cd | 12681 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12682 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12683 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
12684 | }, |
12685 | { | |
12686 | .cmd = NL80211_CMD_GET_MPATH, | |
12687 | .doit = nl80211_get_mpath, | |
12688 | .dumpit = nl80211_dump_mpath, | |
12689 | .policy = nl80211_policy, | |
5617c6cd | 12690 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12691 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12692 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 12693 | }, |
66be7d2b HR |
12694 | { |
12695 | .cmd = NL80211_CMD_GET_MPP, | |
12696 | .doit = nl80211_get_mpp, | |
12697 | .dumpit = nl80211_dump_mpp, | |
12698 | .policy = nl80211_policy, | |
5617c6cd | 12699 | .flags = GENL_UNS_ADMIN_PERM, |
66be7d2b HR |
12700 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12701 | NL80211_FLAG_NEED_RTNL, | |
12702 | }, | |
2ec600d6 LCC |
12703 | { |
12704 | .cmd = NL80211_CMD_SET_MPATH, | |
12705 | .doit = nl80211_set_mpath, | |
12706 | .policy = nl80211_policy, | |
5617c6cd | 12707 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12708 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12709 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
12710 | }, |
12711 | { | |
12712 | .cmd = NL80211_CMD_NEW_MPATH, | |
12713 | .doit = nl80211_new_mpath, | |
12714 | .policy = nl80211_policy, | |
5617c6cd | 12715 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12716 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12717 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
12718 | }, |
12719 | { | |
12720 | .cmd = NL80211_CMD_DEL_MPATH, | |
12721 | .doit = nl80211_del_mpath, | |
12722 | .policy = nl80211_policy, | |
5617c6cd | 12723 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12724 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12725 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
12726 | }, |
12727 | { | |
12728 | .cmd = NL80211_CMD_SET_BSS, | |
12729 | .doit = nl80211_set_bss, | |
12730 | .policy = nl80211_policy, | |
5617c6cd | 12731 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12732 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12733 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 12734 | }, |
f130347c LR |
12735 | { |
12736 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
12737 | .doit = nl80211_get_reg_do, |
12738 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 12739 | .policy = nl80211_policy, |
5fe231e8 | 12740 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
12741 | /* can be retrieved by unprivileged users */ |
12742 | }, | |
b6863036 | 12743 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
b2e1b302 LR |
12744 | { |
12745 | .cmd = NL80211_CMD_SET_REG, | |
12746 | .doit = nl80211_set_reg, | |
12747 | .policy = nl80211_policy, | |
12748 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 12749 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 12750 | }, |
b6863036 | 12751 | #endif |
b2e1b302 LR |
12752 | { |
12753 | .cmd = NL80211_CMD_REQ_SET_REG, | |
12754 | .doit = nl80211_req_set_reg, | |
12755 | .policy = nl80211_policy, | |
93da9cc1 | 12756 | .flags = GENL_ADMIN_PERM, |
12757 | }, | |
1ea4ff3e JB |
12758 | { |
12759 | .cmd = NL80211_CMD_RELOAD_REGDB, | |
12760 | .doit = nl80211_reload_regdb, | |
12761 | .policy = nl80211_policy, | |
12762 | .flags = GENL_ADMIN_PERM, | |
12763 | }, | |
93da9cc1 | 12764 | { |
24bdd9f4 JC |
12765 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
12766 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 12767 | .policy = nl80211_policy, |
12768 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 12769 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12770 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 12771 | }, |
12772 | { | |
24bdd9f4 JC |
12773 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
12774 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 12775 | .policy = nl80211_policy, |
5617c6cd | 12776 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c | 12777 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12778 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 12779 | }, |
2a519311 JB |
12780 | { |
12781 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
12782 | .doit = nl80211_trigger_scan, | |
12783 | .policy = nl80211_policy, | |
5617c6cd | 12784 | .flags = GENL_UNS_ADMIN_PERM, |
fd014284 | 12785 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 12786 | NL80211_FLAG_NEED_RTNL, |
2a519311 | 12787 | }, |
91d3ab46 VK |
12788 | { |
12789 | .cmd = NL80211_CMD_ABORT_SCAN, | |
12790 | .doit = nl80211_abort_scan, | |
12791 | .policy = nl80211_policy, | |
5617c6cd | 12792 | .flags = GENL_UNS_ADMIN_PERM, |
91d3ab46 VK |
12793 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
12794 | NL80211_FLAG_NEED_RTNL, | |
12795 | }, | |
2a519311 JB |
12796 | { |
12797 | .cmd = NL80211_CMD_GET_SCAN, | |
12798 | .policy = nl80211_policy, | |
12799 | .dumpit = nl80211_dump_scan, | |
12800 | }, | |
807f8a8c LC |
12801 | { |
12802 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
12803 | .doit = nl80211_start_sched_scan, | |
12804 | .policy = nl80211_policy, | |
5617c6cd | 12805 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
12806 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12807 | NL80211_FLAG_NEED_RTNL, | |
12808 | }, | |
12809 | { | |
12810 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
12811 | .doit = nl80211_stop_sched_scan, | |
12812 | .policy = nl80211_policy, | |
5617c6cd | 12813 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
12814 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12815 | NL80211_FLAG_NEED_RTNL, | |
12816 | }, | |
636a5d36 JM |
12817 | { |
12818 | .cmd = NL80211_CMD_AUTHENTICATE, | |
12819 | .doit = nl80211_authenticate, | |
12820 | .policy = nl80211_policy, | |
5617c6cd | 12821 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12822 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
12823 | NL80211_FLAG_NEED_RTNL | |
12824 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
12825 | }, |
12826 | { | |
12827 | .cmd = NL80211_CMD_ASSOCIATE, | |
12828 | .doit = nl80211_associate, | |
12829 | .policy = nl80211_policy, | |
5617c6cd | 12830 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12831 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12832 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
12833 | }, |
12834 | { | |
12835 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
12836 | .doit = nl80211_deauthenticate, | |
12837 | .policy = nl80211_policy, | |
5617c6cd | 12838 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12839 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12840 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
12841 | }, |
12842 | { | |
12843 | .cmd = NL80211_CMD_DISASSOCIATE, | |
12844 | .doit = nl80211_disassociate, | |
12845 | .policy = nl80211_policy, | |
5617c6cd | 12846 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12847 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12848 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 12849 | }, |
04a773ad JB |
12850 | { |
12851 | .cmd = NL80211_CMD_JOIN_IBSS, | |
12852 | .doit = nl80211_join_ibss, | |
12853 | .policy = nl80211_policy, | |
5617c6cd | 12854 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12855 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12856 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
12857 | }, |
12858 | { | |
12859 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
12860 | .doit = nl80211_leave_ibss, | |
12861 | .policy = nl80211_policy, | |
5617c6cd | 12862 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12863 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12864 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 12865 | }, |
aff89a9b JB |
12866 | #ifdef CONFIG_NL80211_TESTMODE |
12867 | { | |
12868 | .cmd = NL80211_CMD_TESTMODE, | |
12869 | .doit = nl80211_testmode_do, | |
71063f0e | 12870 | .dumpit = nl80211_testmode_dump, |
aff89a9b | 12871 | .policy = nl80211_policy, |
5617c6cd | 12872 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12873 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12874 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
12875 | }, |
12876 | #endif | |
b23aa676 SO |
12877 | { |
12878 | .cmd = NL80211_CMD_CONNECT, | |
12879 | .doit = nl80211_connect, | |
12880 | .policy = nl80211_policy, | |
5617c6cd | 12881 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12882 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12883 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 12884 | }, |
088e8df8 | 12885 | { |
12886 | .cmd = NL80211_CMD_UPDATE_CONNECT_PARAMS, | |
12887 | .doit = nl80211_update_connect_params, | |
12888 | .policy = nl80211_policy, | |
12889 | .flags = GENL_ADMIN_PERM, | |
12890 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
12891 | NL80211_FLAG_NEED_RTNL, | |
12892 | }, | |
b23aa676 SO |
12893 | { |
12894 | .cmd = NL80211_CMD_DISCONNECT, | |
12895 | .doit = nl80211_disconnect, | |
12896 | .policy = nl80211_policy, | |
5617c6cd | 12897 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12898 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12899 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 12900 | }, |
463d0183 JB |
12901 | { |
12902 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
12903 | .doit = nl80211_wiphy_netns, | |
12904 | .policy = nl80211_policy, | |
5617c6cd | 12905 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12906 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12907 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 12908 | }, |
61fa713c HS |
12909 | { |
12910 | .cmd = NL80211_CMD_GET_SURVEY, | |
12911 | .policy = nl80211_policy, | |
12912 | .dumpit = nl80211_dump_survey, | |
12913 | }, | |
67fbb16b SO |
12914 | { |
12915 | .cmd = NL80211_CMD_SET_PMKSA, | |
12916 | .doit = nl80211_setdel_pmksa, | |
12917 | .policy = nl80211_policy, | |
5617c6cd | 12918 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12919 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12920 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
12921 | }, |
12922 | { | |
12923 | .cmd = NL80211_CMD_DEL_PMKSA, | |
12924 | .doit = nl80211_setdel_pmksa, | |
12925 | .policy = nl80211_policy, | |
5617c6cd | 12926 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12927 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12928 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
12929 | }, |
12930 | { | |
12931 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
12932 | .doit = nl80211_flush_pmksa, | |
12933 | .policy = nl80211_policy, | |
5617c6cd | 12934 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12935 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12936 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 12937 | }, |
9588bbd5 JM |
12938 | { |
12939 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
12940 | .doit = nl80211_remain_on_channel, | |
12941 | .policy = nl80211_policy, | |
5617c6cd | 12942 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12943 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 12944 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
12945 | }, |
12946 | { | |
12947 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
12948 | .doit = nl80211_cancel_remain_on_channel, | |
12949 | .policy = nl80211_policy, | |
5617c6cd | 12950 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12951 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 12952 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 12953 | }, |
13ae75b1 JM |
12954 | { |
12955 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
12956 | .doit = nl80211_set_tx_bitrate_mask, | |
12957 | .policy = nl80211_policy, | |
5617c6cd | 12958 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12959 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12960 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 12961 | }, |
026331c4 | 12962 | { |
2e161f78 JB |
12963 | .cmd = NL80211_CMD_REGISTER_FRAME, |
12964 | .doit = nl80211_register_mgmt, | |
026331c4 | 12965 | .policy = nl80211_policy, |
5617c6cd | 12966 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12967 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 12968 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
12969 | }, |
12970 | { | |
2e161f78 JB |
12971 | .cmd = NL80211_CMD_FRAME, |
12972 | .doit = nl80211_tx_mgmt, | |
026331c4 | 12973 | .policy = nl80211_policy, |
5617c6cd | 12974 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12975 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
12976 | NL80211_FLAG_NEED_RTNL, |
12977 | }, | |
12978 | { | |
12979 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
12980 | .doit = nl80211_tx_mgmt_cancel_wait, | |
12981 | .policy = nl80211_policy, | |
5617c6cd | 12982 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12983 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 12984 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 12985 | }, |
ffb9eb3d KV |
12986 | { |
12987 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
12988 | .doit = nl80211_set_power_save, | |
12989 | .policy = nl80211_policy, | |
5617c6cd | 12990 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12991 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12992 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
12993 | }, |
12994 | { | |
12995 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
12996 | .doit = nl80211_get_power_save, | |
12997 | .policy = nl80211_policy, | |
12998 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
12999 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13000 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 13001 | }, |
d6dc1a38 JO |
13002 | { |
13003 | .cmd = NL80211_CMD_SET_CQM, | |
13004 | .doit = nl80211_set_cqm, | |
13005 | .policy = nl80211_policy, | |
5617c6cd | 13006 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
13007 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13008 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 13009 | }, |
f444de05 JB |
13010 | { |
13011 | .cmd = NL80211_CMD_SET_CHANNEL, | |
13012 | .doit = nl80211_set_channel, | |
13013 | .policy = nl80211_policy, | |
5617c6cd | 13014 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
13015 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13016 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 13017 | }, |
e8347eba BJ |
13018 | { |
13019 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
13020 | .doit = nl80211_set_wds_peer, | |
13021 | .policy = nl80211_policy, | |
5617c6cd | 13022 | .flags = GENL_UNS_ADMIN_PERM, |
43b19952 JB |
13023 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13024 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 13025 | }, |
29cbe68c JB |
13026 | { |
13027 | .cmd = NL80211_CMD_JOIN_MESH, | |
13028 | .doit = nl80211_join_mesh, | |
13029 | .policy = nl80211_policy, | |
5617c6cd | 13030 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
13031 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13032 | NL80211_FLAG_NEED_RTNL, | |
13033 | }, | |
13034 | { | |
13035 | .cmd = NL80211_CMD_LEAVE_MESH, | |
13036 | .doit = nl80211_leave_mesh, | |
13037 | .policy = nl80211_policy, | |
5617c6cd | 13038 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
13039 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13040 | NL80211_FLAG_NEED_RTNL, | |
13041 | }, | |
6e0bd6c3 RL |
13042 | { |
13043 | .cmd = NL80211_CMD_JOIN_OCB, | |
13044 | .doit = nl80211_join_ocb, | |
13045 | .policy = nl80211_policy, | |
5617c6cd | 13046 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
13047 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13048 | NL80211_FLAG_NEED_RTNL, | |
13049 | }, | |
13050 | { | |
13051 | .cmd = NL80211_CMD_LEAVE_OCB, | |
13052 | .doit = nl80211_leave_ocb, | |
13053 | .policy = nl80211_policy, | |
5617c6cd | 13054 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
13055 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13056 | NL80211_FLAG_NEED_RTNL, | |
13057 | }, | |
dfb89c56 | 13058 | #ifdef CONFIG_PM |
ff1b6e69 JB |
13059 | { |
13060 | .cmd = NL80211_CMD_GET_WOWLAN, | |
13061 | .doit = nl80211_get_wowlan, | |
13062 | .policy = nl80211_policy, | |
13063 | /* can be retrieved by unprivileged users */ | |
13064 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
13065 | NL80211_FLAG_NEED_RTNL, | |
13066 | }, | |
13067 | { | |
13068 | .cmd = NL80211_CMD_SET_WOWLAN, | |
13069 | .doit = nl80211_set_wowlan, | |
13070 | .policy = nl80211_policy, | |
5617c6cd | 13071 | .flags = GENL_UNS_ADMIN_PERM, |
ff1b6e69 JB |
13072 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
13073 | NL80211_FLAG_NEED_RTNL, | |
13074 | }, | |
dfb89c56 | 13075 | #endif |
e5497d76 JB |
13076 | { |
13077 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
13078 | .doit = nl80211_set_rekey_data, | |
13079 | .policy = nl80211_policy, | |
5617c6cd | 13080 | .flags = GENL_UNS_ADMIN_PERM, |
e5497d76 | 13081 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
13082 | NL80211_FLAG_NEED_RTNL | |
13083 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 13084 | }, |
109086ce AN |
13085 | { |
13086 | .cmd = NL80211_CMD_TDLS_MGMT, | |
13087 | .doit = nl80211_tdls_mgmt, | |
13088 | .policy = nl80211_policy, | |
5617c6cd | 13089 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
13090 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13091 | NL80211_FLAG_NEED_RTNL, | |
13092 | }, | |
13093 | { | |
13094 | .cmd = NL80211_CMD_TDLS_OPER, | |
13095 | .doit = nl80211_tdls_oper, | |
13096 | .policy = nl80211_policy, | |
5617c6cd | 13097 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
13098 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13099 | NL80211_FLAG_NEED_RTNL, | |
13100 | }, | |
28946da7 JB |
13101 | { |
13102 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
13103 | .doit = nl80211_register_unexpected_frame, | |
13104 | .policy = nl80211_policy, | |
5617c6cd | 13105 | .flags = GENL_UNS_ADMIN_PERM, |
28946da7 JB |
13106 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13107 | NL80211_FLAG_NEED_RTNL, | |
13108 | }, | |
7f6cf311 JB |
13109 | { |
13110 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
13111 | .doit = nl80211_probe_client, | |
13112 | .policy = nl80211_policy, | |
5617c6cd | 13113 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 13114 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
13115 | NL80211_FLAG_NEED_RTNL, |
13116 | }, | |
5e760230 JB |
13117 | { |
13118 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
13119 | .doit = nl80211_register_beacons, | |
13120 | .policy = nl80211_policy, | |
5617c6cd | 13121 | .flags = GENL_UNS_ADMIN_PERM, |
5e760230 JB |
13122 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
13123 | NL80211_FLAG_NEED_RTNL, | |
13124 | }, | |
1d9d9213 SW |
13125 | { |
13126 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
13127 | .doit = nl80211_set_noack_map, | |
13128 | .policy = nl80211_policy, | |
5617c6cd | 13129 | .flags = GENL_UNS_ADMIN_PERM, |
1d9d9213 SW |
13130 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13131 | NL80211_FLAG_NEED_RTNL, | |
13132 | }, | |
98104fde JB |
13133 | { |
13134 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
13135 | .doit = nl80211_start_p2p_device, | |
13136 | .policy = nl80211_policy, | |
5617c6cd | 13137 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
13138 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
13139 | NL80211_FLAG_NEED_RTNL, | |
13140 | }, | |
13141 | { | |
13142 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
13143 | .doit = nl80211_stop_p2p_device, | |
13144 | .policy = nl80211_policy, | |
5617c6cd | 13145 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
13146 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
13147 | NL80211_FLAG_NEED_RTNL, | |
cb3b7d87 AB |
13148 | }, |
13149 | { | |
13150 | .cmd = NL80211_CMD_START_NAN, | |
13151 | .doit = nl80211_start_nan, | |
13152 | .policy = nl80211_policy, | |
13153 | .flags = GENL_ADMIN_PERM, | |
13154 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
13155 | NL80211_FLAG_NEED_RTNL, | |
13156 | }, | |
13157 | { | |
13158 | .cmd = NL80211_CMD_STOP_NAN, | |
13159 | .doit = nl80211_stop_nan, | |
13160 | .policy = nl80211_policy, | |
13161 | .flags = GENL_ADMIN_PERM, | |
13162 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
13163 | NL80211_FLAG_NEED_RTNL, | |
a442b761 AB |
13164 | }, |
13165 | { | |
13166 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, | |
13167 | .doit = nl80211_nan_add_func, | |
13168 | .policy = nl80211_policy, | |
13169 | .flags = GENL_ADMIN_PERM, | |
13170 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
13171 | NL80211_FLAG_NEED_RTNL, | |
13172 | }, | |
13173 | { | |
13174 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, | |
13175 | .doit = nl80211_nan_del_func, | |
13176 | .policy = nl80211_policy, | |
13177 | .flags = GENL_ADMIN_PERM, | |
13178 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
13179 | NL80211_FLAG_NEED_RTNL, | |
a5a9dcf2 AB |
13180 | }, |
13181 | { | |
13182 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, | |
13183 | .doit = nl80211_nan_change_config, | |
13184 | .policy = nl80211_policy, | |
13185 | .flags = GENL_ADMIN_PERM, | |
13186 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
13187 | NL80211_FLAG_NEED_RTNL, | |
98104fde | 13188 | }, |
f4e583c8 AQ |
13189 | { |
13190 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
13191 | .doit = nl80211_set_mcast_rate, | |
77765eaf | 13192 | .policy = nl80211_policy, |
5617c6cd | 13193 | .flags = GENL_UNS_ADMIN_PERM, |
77765eaf VT |
13194 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13195 | NL80211_FLAG_NEED_RTNL, | |
13196 | }, | |
13197 | { | |
13198 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
13199 | .doit = nl80211_set_mac_acl, | |
f4e583c8 | 13200 | .policy = nl80211_policy, |
5617c6cd | 13201 | .flags = GENL_UNS_ADMIN_PERM, |
f4e583c8 AQ |
13202 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
13203 | NL80211_FLAG_NEED_RTNL, | |
13204 | }, | |
04f39047 SW |
13205 | { |
13206 | .cmd = NL80211_CMD_RADAR_DETECT, | |
13207 | .doit = nl80211_start_radar_detection, | |
13208 | .policy = nl80211_policy, | |
5617c6cd | 13209 | .flags = GENL_UNS_ADMIN_PERM, |
04f39047 SW |
13210 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13211 | NL80211_FLAG_NEED_RTNL, | |
13212 | }, | |
3713b4e3 JB |
13213 | { |
13214 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
13215 | .doit = nl80211_get_protocol_features, | |
13216 | .policy = nl80211_policy, | |
13217 | }, | |
355199e0 JM |
13218 | { |
13219 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
13220 | .doit = nl80211_update_ft_ies, | |
13221 | .policy = nl80211_policy, | |
5617c6cd | 13222 | .flags = GENL_UNS_ADMIN_PERM, |
355199e0 JM |
13223 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13224 | NL80211_FLAG_NEED_RTNL, | |
13225 | }, | |
5de17984 AS |
13226 | { |
13227 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
13228 | .doit = nl80211_crit_protocol_start, | |
13229 | .policy = nl80211_policy, | |
5617c6cd | 13230 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
13231 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
13232 | NL80211_FLAG_NEED_RTNL, | |
13233 | }, | |
13234 | { | |
13235 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
13236 | .doit = nl80211_crit_protocol_stop, | |
13237 | .policy = nl80211_policy, | |
5617c6cd | 13238 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
13239 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
13240 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
13241 | }, |
13242 | { | |
13243 | .cmd = NL80211_CMD_GET_COALESCE, | |
13244 | .doit = nl80211_get_coalesce, | |
13245 | .policy = nl80211_policy, | |
13246 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
13247 | NL80211_FLAG_NEED_RTNL, | |
13248 | }, | |
13249 | { | |
13250 | .cmd = NL80211_CMD_SET_COALESCE, | |
13251 | .doit = nl80211_set_coalesce, | |
13252 | .policy = nl80211_policy, | |
5617c6cd | 13253 | .flags = GENL_UNS_ADMIN_PERM, |
be29b99a AK |
13254 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
13255 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
13256 | }, |
13257 | { | |
13258 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
13259 | .doit = nl80211_channel_switch, | |
13260 | .policy = nl80211_policy, | |
5617c6cd | 13261 | .flags = GENL_UNS_ADMIN_PERM, |
16ef1fe2 SW |
13262 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13263 | NL80211_FLAG_NEED_RTNL, | |
13264 | }, | |
ad7e718c JB |
13265 | { |
13266 | .cmd = NL80211_CMD_VENDOR, | |
13267 | .doit = nl80211_vendor_cmd, | |
7bdbe400 | 13268 | .dumpit = nl80211_vendor_cmd_dump, |
ad7e718c | 13269 | .policy = nl80211_policy, |
5617c6cd | 13270 | .flags = GENL_UNS_ADMIN_PERM, |
ad7e718c JB |
13271 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
13272 | NL80211_FLAG_NEED_RTNL, | |
13273 | }, | |
fa9ffc74 KP |
13274 | { |
13275 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
13276 | .doit = nl80211_set_qos_map, | |
13277 | .policy = nl80211_policy, | |
5617c6cd | 13278 | .flags = GENL_UNS_ADMIN_PERM, |
fa9ffc74 KP |
13279 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13280 | NL80211_FLAG_NEED_RTNL, | |
13281 | }, | |
960d01ac JB |
13282 | { |
13283 | .cmd = NL80211_CMD_ADD_TX_TS, | |
13284 | .doit = nl80211_add_tx_ts, | |
13285 | .policy = nl80211_policy, | |
5617c6cd | 13286 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
13287 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13288 | NL80211_FLAG_NEED_RTNL, | |
13289 | }, | |
13290 | { | |
13291 | .cmd = NL80211_CMD_DEL_TX_TS, | |
13292 | .doit = nl80211_del_tx_ts, | |
13293 | .policy = nl80211_policy, | |
5617c6cd | 13294 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
13295 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13296 | NL80211_FLAG_NEED_RTNL, | |
13297 | }, | |
1057d35e AN |
13298 | { |
13299 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
13300 | .doit = nl80211_tdls_channel_switch, | |
13301 | .policy = nl80211_policy, | |
5617c6cd | 13302 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
13303 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13304 | NL80211_FLAG_NEED_RTNL, | |
13305 | }, | |
13306 | { | |
13307 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
13308 | .doit = nl80211_tdls_cancel_channel_switch, | |
13309 | .policy = nl80211_policy, | |
5617c6cd | 13310 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
13311 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
13312 | NL80211_FLAG_NEED_RTNL, | |
13313 | }, | |
ce0ce13a MB |
13314 | { |
13315 | .cmd = NL80211_CMD_SET_MULTICAST_TO_UNICAST, | |
13316 | .doit = nl80211_set_multicast_to_unicast, | |
13317 | .policy = nl80211_policy, | |
13318 | .flags = GENL_UNS_ADMIN_PERM, | |
13319 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
13320 | NL80211_FLAG_NEED_RTNL, | |
13321 | }, | |
3a00df57 AS |
13322 | { |
13323 | .cmd = NL80211_CMD_SET_PMK, | |
13324 | .doit = nl80211_set_pmk, | |
13325 | .policy = nl80211_policy, | |
13326 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
13327 | NL80211_FLAG_NEED_RTNL, | |
13328 | }, | |
13329 | { | |
13330 | .cmd = NL80211_CMD_DEL_PMK, | |
13331 | .doit = nl80211_del_pmk, | |
13332 | .policy = nl80211_policy, | |
13333 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
13334 | NL80211_FLAG_NEED_RTNL, | |
13335 | }, | |
13336 | ||
55682965 | 13337 | }; |
9588bbd5 | 13338 | |
56989f6d | 13339 | static struct genl_family nl80211_fam __ro_after_init = { |
489111e5 JB |
13340 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
13341 | .hdrsize = 0, /* no private header */ | |
13342 | .version = 1, /* no particular meaning now */ | |
13343 | .maxattr = NL80211_ATTR_MAX, | |
13344 | .netnsok = true, | |
13345 | .pre_doit = nl80211_pre_doit, | |
13346 | .post_doit = nl80211_post_doit, | |
13347 | .module = THIS_MODULE, | |
13348 | .ops = nl80211_ops, | |
13349 | .n_ops = ARRAY_SIZE(nl80211_ops), | |
13350 | .mcgrps = nl80211_mcgrps, | |
13351 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), | |
13352 | }; | |
13353 | ||
55682965 JB |
13354 | /* notification functions */ |
13355 | ||
3bb20556 JB |
13356 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
13357 | enum nl80211_commands cmd) | |
55682965 JB |
13358 | { |
13359 | struct sk_buff *msg; | |
86e8cf98 | 13360 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 13361 | |
3bb20556 JB |
13362 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
13363 | cmd != NL80211_CMD_DEL_WIPHY); | |
13364 | ||
fd2120ca | 13365 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
13366 | if (!msg) |
13367 | return; | |
13368 | ||
3bb20556 | 13369 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
13370 | nlmsg_free(msg); |
13371 | return; | |
13372 | } | |
13373 | ||
68eb5503 | 13374 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13375 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
13376 | } |
13377 | ||
896ff063 DK |
13378 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
13379 | struct wireless_dev *wdev, | |
13380 | enum nl80211_commands cmd) | |
13381 | { | |
13382 | struct sk_buff *msg; | |
13383 | ||
13384 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && | |
13385 | cmd != NL80211_CMD_DEL_INTERFACE); | |
13386 | ||
13387 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13388 | if (!msg) | |
13389 | return; | |
13390 | ||
13391 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, | |
13392 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { | |
13393 | nlmsg_free(msg); | |
13394 | return; | |
13395 | } | |
13396 | ||
13397 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
13398 | NL80211_MCGRP_CONFIG, GFP_KERNEL); | |
13399 | } | |
13400 | ||
362a415d JB |
13401 | static int nl80211_add_scan_req(struct sk_buff *msg, |
13402 | struct cfg80211_registered_device *rdev) | |
13403 | { | |
13404 | struct cfg80211_scan_request *req = rdev->scan_req; | |
13405 | struct nlattr *nest; | |
13406 | int i; | |
13407 | ||
13408 | if (WARN_ON(!req)) | |
13409 | return 0; | |
13410 | ||
13411 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
13412 | if (!nest) | |
13413 | goto nla_put_failure; | |
9360ffd1 DM |
13414 | for (i = 0; i < req->n_ssids; i++) { |
13415 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
13416 | goto nla_put_failure; | |
13417 | } | |
362a415d JB |
13418 | nla_nest_end(msg, nest); |
13419 | ||
13420 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
13421 | if (!nest) | |
13422 | goto nla_put_failure; | |
9360ffd1 DM |
13423 | for (i = 0; i < req->n_channels; i++) { |
13424 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
13425 | goto nla_put_failure; | |
13426 | } | |
362a415d JB |
13427 | nla_nest_end(msg, nest); |
13428 | ||
9360ffd1 DM |
13429 | if (req->ie && |
13430 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
13431 | goto nla_put_failure; | |
362a415d | 13432 | |
ae917c9f JB |
13433 | if (req->flags && |
13434 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
13435 | goto nla_put_failure; | |
ed473771 | 13436 | |
1d76250b AS |
13437 | if (req->info.scan_start_tsf && |
13438 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, | |
13439 | req->info.scan_start_tsf, NL80211_BSS_PAD) || | |
13440 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, | |
13441 | req->info.tsf_bssid))) | |
13442 | goto nla_put_failure; | |
13443 | ||
362a415d JB |
13444 | return 0; |
13445 | nla_put_failure: | |
13446 | return -ENOBUFS; | |
13447 | } | |
13448 | ||
505a2e88 | 13449 | static int nl80211_prep_scan_msg(struct sk_buff *msg, |
a538e2d5 | 13450 | struct cfg80211_registered_device *rdev, |
fd014284 | 13451 | struct wireless_dev *wdev, |
15e47304 | 13452 | u32 portid, u32 seq, int flags, |
a538e2d5 | 13453 | u32 cmd) |
2a519311 JB |
13454 | { |
13455 | void *hdr; | |
13456 | ||
15e47304 | 13457 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
13458 | if (!hdr) |
13459 | return -1; | |
13460 | ||
9360ffd1 | 13461 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
13462 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
13463 | wdev->netdev->ifindex)) || | |
2dad624e ND |
13464 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13465 | NL80211_ATTR_PAD)) | |
9360ffd1 | 13466 | goto nla_put_failure; |
2a519311 | 13467 | |
362a415d JB |
13468 | /* ignore errors and send incomplete event anyway */ |
13469 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 13470 | |
053c095a JB |
13471 | genlmsg_end(msg, hdr); |
13472 | return 0; | |
2a519311 JB |
13473 | |
13474 | nla_put_failure: | |
13475 | genlmsg_cancel(msg, hdr); | |
13476 | return -EMSGSIZE; | |
13477 | } | |
13478 | ||
807f8a8c | 13479 | static int |
505a2e88 | 13480 | nl80211_prep_sched_scan_msg(struct sk_buff *msg, |
96b08fd6 | 13481 | struct cfg80211_sched_scan_request *req, u32 cmd) |
807f8a8c LC |
13482 | { |
13483 | void *hdr; | |
13484 | ||
96b08fd6 | 13485 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
807f8a8c LC |
13486 | if (!hdr) |
13487 | return -1; | |
13488 | ||
96b08fd6 AVS |
13489 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, |
13490 | wiphy_to_rdev(req->wiphy)->wiphy_idx) || | |
13491 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, req->dev->ifindex) || | |
13492 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, req->reqid, | |
13493 | NL80211_ATTR_PAD)) | |
9360ffd1 | 13494 | goto nla_put_failure; |
807f8a8c | 13495 | |
053c095a JB |
13496 | genlmsg_end(msg, hdr); |
13497 | return 0; | |
807f8a8c LC |
13498 | |
13499 | nla_put_failure: | |
13500 | genlmsg_cancel(msg, hdr); | |
13501 | return -EMSGSIZE; | |
13502 | } | |
13503 | ||
a538e2d5 | 13504 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 13505 | struct wireless_dev *wdev) |
a538e2d5 JB |
13506 | { |
13507 | struct sk_buff *msg; | |
13508 | ||
58050fce | 13509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
13510 | if (!msg) |
13511 | return; | |
13512 | ||
505a2e88 | 13513 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
13514 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
13515 | nlmsg_free(msg); | |
13516 | return; | |
13517 | } | |
13518 | ||
68eb5503 | 13519 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13520 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
13521 | } |
13522 | ||
f9d15d16 JB |
13523 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
13524 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
13525 | { |
13526 | struct sk_buff *msg; | |
13527 | ||
fd2120ca | 13528 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 13529 | if (!msg) |
f9d15d16 | 13530 | return NULL; |
2a519311 | 13531 | |
505a2e88 | 13532 | if (nl80211_prep_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
13533 | aborted ? NL80211_CMD_SCAN_ABORTED : |
13534 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 13535 | nlmsg_free(msg); |
f9d15d16 | 13536 | return NULL; |
2a519311 JB |
13537 | } |
13538 | ||
f9d15d16 | 13539 | return msg; |
2a519311 JB |
13540 | } |
13541 | ||
505a2e88 AVS |
13542 | /* send message created by nl80211_build_scan_msg() */ |
13543 | void nl80211_send_scan_msg(struct cfg80211_registered_device *rdev, | |
13544 | struct sk_buff *msg) | |
807f8a8c | 13545 | { |
807f8a8c LC |
13546 | if (!msg) |
13547 | return; | |
13548 | ||
68eb5503 | 13549 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13550 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
13551 | } |
13552 | ||
96b08fd6 | 13553 | void nl80211_send_sched_scan(struct cfg80211_sched_scan_request *req, u32 cmd) |
807f8a8c LC |
13554 | { |
13555 | struct sk_buff *msg; | |
13556 | ||
58050fce | 13557 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
13558 | if (!msg) |
13559 | return; | |
13560 | ||
96b08fd6 | 13561 | if (nl80211_prep_sched_scan_msg(msg, req, cmd) < 0) { |
807f8a8c LC |
13562 | nlmsg_free(msg); |
13563 | return; | |
13564 | } | |
13565 | ||
96b08fd6 | 13566 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(req->wiphy), msg, 0, |
2a94fe48 | 13567 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
13568 | } |
13569 | ||
b0d7aa59 JD |
13570 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
13571 | struct regulatory_request *request) | |
73d54c9e | 13572 | { |
73d54c9e | 13573 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
13574 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
13575 | goto nla_put_failure; | |
13576 | ||
13577 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
13578 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
13579 | NL80211_REGDOM_TYPE_WORLD)) | |
13580 | goto nla_put_failure; | |
13581 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
13582 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
13583 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
13584 | goto nla_put_failure; | |
13585 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
13586 | request->intersect) { | |
13587 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
13588 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
13589 | goto nla_put_failure; | |
13590 | } else { | |
13591 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
13592 | NL80211_REGDOM_TYPE_COUNTRY) || | |
13593 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
13594 | request->alpha2)) | |
13595 | goto nla_put_failure; | |
13596 | } | |
13597 | ||
ad30ca2c AN |
13598 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
13599 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
13600 | ||
13601 | if (wiphy && | |
13602 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
13603 | goto nla_put_failure; | |
1bdd716c AN |
13604 | |
13605 | if (wiphy && | |
13606 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
13607 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
13608 | goto nla_put_failure; | |
ad30ca2c | 13609 | } |
73d54c9e | 13610 | |
b0d7aa59 JD |
13611 | return true; |
13612 | ||
13613 | nla_put_failure: | |
13614 | return false; | |
13615 | } | |
13616 | ||
13617 | /* | |
13618 | * This can happen on global regulatory changes or device specific settings | |
13619 | * based on custom regulatory domains. | |
13620 | */ | |
13621 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
13622 | struct regulatory_request *request) | |
13623 | { | |
13624 | struct sk_buff *msg; | |
13625 | void *hdr; | |
13626 | ||
13627 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13628 | if (!msg) | |
13629 | return; | |
13630 | ||
13631 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
13632 | if (!hdr) { | |
13633 | nlmsg_free(msg); | |
13634 | return; | |
13635 | } | |
13636 | ||
13637 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
13638 | goto nla_put_failure; | |
13639 | ||
3b7b72ee | 13640 | genlmsg_end(msg, hdr); |
73d54c9e | 13641 | |
bc43b28c | 13642 | rcu_read_lock(); |
68eb5503 | 13643 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 13644 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 13645 | rcu_read_unlock(); |
73d54c9e LR |
13646 | |
13647 | return; | |
13648 | ||
13649 | nla_put_failure: | |
13650 | genlmsg_cancel(msg, hdr); | |
13651 | nlmsg_free(msg); | |
13652 | } | |
13653 | ||
6039f6d2 JM |
13654 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
13655 | struct net_device *netdev, | |
13656 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
13657 | enum nl80211_commands cmd, gfp_t gfp, |
13658 | int uapsd_queues) | |
6039f6d2 JM |
13659 | { |
13660 | struct sk_buff *msg; | |
13661 | void *hdr; | |
13662 | ||
4ef8c1c9 | 13663 | msg = nlmsg_new(100 + len, gfp); |
6039f6d2 JM |
13664 | if (!msg) |
13665 | return; | |
13666 | ||
13667 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
13668 | if (!hdr) { | |
13669 | nlmsg_free(msg); | |
13670 | return; | |
13671 | } | |
13672 | ||
9360ffd1 DM |
13673 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13674 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13675 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
13676 | goto nla_put_failure; | |
6039f6d2 | 13677 | |
b0b6aa2c EP |
13678 | if (uapsd_queues >= 0) { |
13679 | struct nlattr *nla_wmm = | |
13680 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
13681 | if (!nla_wmm) | |
13682 | goto nla_put_failure; | |
13683 | ||
13684 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
13685 | uapsd_queues)) | |
13686 | goto nla_put_failure; | |
13687 | ||
13688 | nla_nest_end(msg, nla_wmm); | |
13689 | } | |
13690 | ||
3b7b72ee | 13691 | genlmsg_end(msg, hdr); |
6039f6d2 | 13692 | |
68eb5503 | 13693 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13694 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
13695 | return; |
13696 | ||
13697 | nla_put_failure: | |
13698 | genlmsg_cancel(msg, hdr); | |
13699 | nlmsg_free(msg); | |
13700 | } | |
13701 | ||
13702 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
13703 | struct net_device *netdev, const u8 *buf, |
13704 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
13705 | { |
13706 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 13707 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
13708 | } |
13709 | ||
13710 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
13711 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 13712 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 13713 | { |
e6d6e342 | 13714 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 13715 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
13716 | } |
13717 | ||
53b46b84 | 13718 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
13719 | struct net_device *netdev, const u8 *buf, |
13720 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
13721 | { |
13722 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 13723 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
13724 | } |
13725 | ||
53b46b84 JM |
13726 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
13727 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 13728 | size_t len, gfp_t gfp) |
6039f6d2 JM |
13729 | { |
13730 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 13731 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
13732 | } |
13733 | ||
6ff57cf8 JB |
13734 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
13735 | size_t len) | |
cf4e594e | 13736 | { |
947add36 JB |
13737 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13738 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13739 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
13740 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
13741 | u32 cmd; | |
947add36 | 13742 | |
6ff57cf8 JB |
13743 | if (WARN_ON(len < 2)) |
13744 | return; | |
cf4e594e | 13745 | |
6ff57cf8 JB |
13746 | if (ieee80211_is_deauth(mgmt->frame_control)) |
13747 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
13748 | else | |
13749 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 13750 | |
6ff57cf8 | 13751 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 13752 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 13753 | } |
6ff57cf8 | 13754 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 13755 | |
1b06bb40 LR |
13756 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
13757 | struct net_device *netdev, int cmd, | |
e6d6e342 | 13758 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
13759 | { |
13760 | struct sk_buff *msg; | |
13761 | void *hdr; | |
13762 | ||
e6d6e342 | 13763 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
13764 | if (!msg) |
13765 | return; | |
13766 | ||
13767 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
13768 | if (!hdr) { | |
13769 | nlmsg_free(msg); | |
13770 | return; | |
13771 | } | |
13772 | ||
9360ffd1 DM |
13773 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13774 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13775 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
13776 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
13777 | goto nla_put_failure; | |
1965c853 | 13778 | |
3b7b72ee | 13779 | genlmsg_end(msg, hdr); |
1965c853 | 13780 | |
68eb5503 | 13781 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13782 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
13783 | return; |
13784 | ||
13785 | nla_put_failure: | |
13786 | genlmsg_cancel(msg, hdr); | |
13787 | nlmsg_free(msg); | |
13788 | } | |
13789 | ||
13790 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
13791 | struct net_device *netdev, const u8 *addr, |
13792 | gfp_t gfp) | |
1965c853 JM |
13793 | { |
13794 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 13795 | addr, gfp); |
1965c853 JM |
13796 | } |
13797 | ||
13798 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
13799 | struct net_device *netdev, const u8 *addr, |
13800 | gfp_t gfp) | |
1965c853 | 13801 | { |
e6d6e342 JB |
13802 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
13803 | addr, gfp); | |
1965c853 JM |
13804 | } |
13805 | ||
b23aa676 | 13806 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
5349a0f7 VK |
13807 | struct net_device *netdev, |
13808 | struct cfg80211_connect_resp_params *cr, | |
3093ebbe | 13809 | gfp_t gfp) |
b23aa676 SO |
13810 | { |
13811 | struct sk_buff *msg; | |
13812 | void *hdr; | |
13813 | ||
a3caf744 VK |
13814 | msg = nlmsg_new(100 + cr->req_ie_len + cr->resp_ie_len + |
13815 | cr->fils_kek_len + cr->pmk_len + | |
13816 | (cr->pmkid ? WLAN_PMKID_LEN : 0), gfp); | |
b23aa676 SO |
13817 | if (!msg) |
13818 | return; | |
13819 | ||
13820 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
13821 | if (!hdr) { | |
13822 | nlmsg_free(msg); | |
13823 | return; | |
13824 | } | |
13825 | ||
9360ffd1 DM |
13826 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13827 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
5349a0f7 VK |
13828 | (cr->bssid && |
13829 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, cr->bssid)) || | |
bf1ecd21 | 13830 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
5349a0f7 VK |
13831 | cr->status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : |
13832 | cr->status) || | |
13833 | (cr->status < 0 && | |
3093ebbe | 13834 | (nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || |
5349a0f7 VK |
13835 | nla_put_u32(msg, NL80211_ATTR_TIMEOUT_REASON, |
13836 | cr->timeout_reason))) || | |
13837 | (cr->req_ie && | |
13838 | nla_put(msg, NL80211_ATTR_REQ_IE, cr->req_ie_len, cr->req_ie)) || | |
13839 | (cr->resp_ie && | |
13840 | nla_put(msg, NL80211_ATTR_RESP_IE, cr->resp_ie_len, | |
a3caf744 VK |
13841 | cr->resp_ie)) || |
13842 | (cr->update_erp_next_seq_num && | |
13843 | nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | |
13844 | cr->fils_erp_next_seq_num)) || | |
13845 | (cr->status == WLAN_STATUS_SUCCESS && | |
13846 | ((cr->fils_kek && | |
13847 | nla_put(msg, NL80211_ATTR_FILS_KEK, cr->fils_kek_len, | |
13848 | cr->fils_kek)) || | |
13849 | (cr->pmk && | |
13850 | nla_put(msg, NL80211_ATTR_PMK, cr->pmk_len, cr->pmk)) || | |
13851 | (cr->pmkid && | |
13852 | nla_put(msg, NL80211_ATTR_PMKID, WLAN_PMKID_LEN, cr->pmkid))))) | |
9360ffd1 | 13853 | goto nla_put_failure; |
b23aa676 | 13854 | |
3b7b72ee | 13855 | genlmsg_end(msg, hdr); |
b23aa676 | 13856 | |
68eb5503 | 13857 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13858 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
13859 | return; |
13860 | ||
13861 | nla_put_failure: | |
13862 | genlmsg_cancel(msg, hdr); | |
13863 | nlmsg_free(msg); | |
b23aa676 SO |
13864 | } |
13865 | ||
13866 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
29ce6ecb AS |
13867 | struct net_device *netdev, |
13868 | struct cfg80211_roam_info *info, gfp_t gfp) | |
b23aa676 SO |
13869 | { |
13870 | struct sk_buff *msg; | |
13871 | void *hdr; | |
29ce6ecb | 13872 | const u8 *bssid = info->bss ? info->bss->bssid : info->bssid; |
b23aa676 | 13873 | |
29ce6ecb | 13874 | msg = nlmsg_new(100 + info->req_ie_len + info->resp_ie_len, gfp); |
b23aa676 SO |
13875 | if (!msg) |
13876 | return; | |
13877 | ||
13878 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
13879 | if (!hdr) { | |
13880 | nlmsg_free(msg); | |
13881 | return; | |
13882 | } | |
13883 | ||
9360ffd1 DM |
13884 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13885 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13886 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
29ce6ecb AS |
13887 | (info->req_ie && |
13888 | nla_put(msg, NL80211_ATTR_REQ_IE, info->req_ie_len, | |
13889 | info->req_ie)) || | |
13890 | (info->resp_ie && | |
13891 | nla_put(msg, NL80211_ATTR_RESP_IE, info->resp_ie_len, | |
503c1fb9 | 13892 | info->resp_ie))) |
9360ffd1 | 13893 | goto nla_put_failure; |
b23aa676 | 13894 | |
3b7b72ee | 13895 | genlmsg_end(msg, hdr); |
b23aa676 | 13896 | |
68eb5503 | 13897 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13898 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
13899 | return; |
13900 | ||
503c1fb9 AS |
13901 | nla_put_failure: |
13902 | genlmsg_cancel(msg, hdr); | |
13903 | nlmsg_free(msg); | |
13904 | } | |
13905 | ||
13906 | void nl80211_send_port_authorized(struct cfg80211_registered_device *rdev, | |
13907 | struct net_device *netdev, const u8 *bssid) | |
13908 | { | |
13909 | struct sk_buff *msg; | |
13910 | void *hdr; | |
13911 | ||
13912 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
13913 | if (!msg) | |
13914 | return; | |
13915 | ||
13916 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PORT_AUTHORIZED); | |
13917 | if (!hdr) { | |
13918 | nlmsg_free(msg); | |
13919 | return; | |
13920 | } | |
13921 | ||
13922 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
13923 | goto nla_put_failure; | |
13924 | ||
13925 | genlmsg_end(msg, hdr); | |
13926 | ||
13927 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
13928 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
13929 | return; | |
13930 | ||
b23aa676 SO |
13931 | nla_put_failure: |
13932 | genlmsg_cancel(msg, hdr); | |
13933 | nlmsg_free(msg); | |
b23aa676 SO |
13934 | } |
13935 | ||
13936 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
13937 | struct net_device *netdev, u16 reason, | |
667503dd | 13938 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
13939 | { |
13940 | struct sk_buff *msg; | |
13941 | void *hdr; | |
13942 | ||
4ef8c1c9 | 13943 | msg = nlmsg_new(100 + ie_len, GFP_KERNEL); |
b23aa676 SO |
13944 | if (!msg) |
13945 | return; | |
13946 | ||
13947 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
13948 | if (!hdr) { | |
13949 | nlmsg_free(msg); | |
13950 | return; | |
13951 | } | |
13952 | ||
9360ffd1 DM |
13953 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13954 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13955 | (from_ap && reason && | |
13956 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
13957 | (from_ap && | |
13958 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
13959 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
13960 | goto nla_put_failure; | |
b23aa676 | 13961 | |
3b7b72ee | 13962 | genlmsg_end(msg, hdr); |
b23aa676 | 13963 | |
68eb5503 | 13964 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13965 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
13966 | return; |
13967 | ||
13968 | nla_put_failure: | |
13969 | genlmsg_cancel(msg, hdr); | |
13970 | nlmsg_free(msg); | |
b23aa676 SO |
13971 | } |
13972 | ||
04a773ad JB |
13973 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
13974 | struct net_device *netdev, const u8 *bssid, | |
13975 | gfp_t gfp) | |
13976 | { | |
13977 | struct sk_buff *msg; | |
13978 | void *hdr; | |
13979 | ||
fd2120ca | 13980 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
13981 | if (!msg) |
13982 | return; | |
13983 | ||
13984 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
13985 | if (!hdr) { | |
13986 | nlmsg_free(msg); | |
13987 | return; | |
13988 | } | |
13989 | ||
9360ffd1 DM |
13990 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13991 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13992 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
13993 | goto nla_put_failure; | |
04a773ad | 13994 | |
3b7b72ee | 13995 | genlmsg_end(msg, hdr); |
04a773ad | 13996 | |
68eb5503 | 13997 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13998 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
13999 | return; |
14000 | ||
14001 | nla_put_failure: | |
14002 | genlmsg_cancel(msg, hdr); | |
14003 | nlmsg_free(msg); | |
14004 | } | |
14005 | ||
947add36 JB |
14006 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
14007 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 14008 | { |
947add36 | 14009 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 14010 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
14011 | struct sk_buff *msg; |
14012 | void *hdr; | |
14013 | ||
947add36 JB |
14014 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
14015 | return; | |
14016 | ||
14017 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
14018 | ||
4ef8c1c9 | 14019 | msg = nlmsg_new(100 + ie_len, gfp); |
c93b5e71 JC |
14020 | if (!msg) |
14021 | return; | |
14022 | ||
14023 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
14024 | if (!hdr) { | |
14025 | nlmsg_free(msg); | |
14026 | return; | |
14027 | } | |
14028 | ||
9360ffd1 | 14029 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
14030 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
14031 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
14032 | (ie_len && ie && |
14033 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
14034 | goto nla_put_failure; | |
c93b5e71 | 14035 | |
3b7b72ee | 14036 | genlmsg_end(msg, hdr); |
c93b5e71 | 14037 | |
68eb5503 | 14038 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14039 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
14040 | return; |
14041 | ||
14042 | nla_put_failure: | |
14043 | genlmsg_cancel(msg, hdr); | |
14044 | nlmsg_free(msg); | |
14045 | } | |
947add36 | 14046 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 14047 | |
a3b8b056 JM |
14048 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
14049 | struct net_device *netdev, const u8 *addr, | |
14050 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 14051 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
14052 | { |
14053 | struct sk_buff *msg; | |
14054 | void *hdr; | |
14055 | ||
e6d6e342 | 14056 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
14057 | if (!msg) |
14058 | return; | |
14059 | ||
14060 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
14061 | if (!hdr) { | |
14062 | nlmsg_free(msg); | |
14063 | return; | |
14064 | } | |
14065 | ||
9360ffd1 DM |
14066 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14067 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
14068 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
14069 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
14070 | (key_id != -1 && | |
14071 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
14072 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
14073 | goto nla_put_failure; | |
a3b8b056 | 14074 | |
3b7b72ee | 14075 | genlmsg_end(msg, hdr); |
a3b8b056 | 14076 | |
68eb5503 | 14077 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14078 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
14079 | return; |
14080 | ||
14081 | nla_put_failure: | |
14082 | genlmsg_cancel(msg, hdr); | |
14083 | nlmsg_free(msg); | |
14084 | } | |
14085 | ||
6bad8766 LR |
14086 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
14087 | struct ieee80211_channel *channel_before, | |
14088 | struct ieee80211_channel *channel_after) | |
14089 | { | |
14090 | struct sk_buff *msg; | |
14091 | void *hdr; | |
14092 | struct nlattr *nl_freq; | |
14093 | ||
fd2120ca | 14094 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
14095 | if (!msg) |
14096 | return; | |
14097 | ||
14098 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
14099 | if (!hdr) { | |
14100 | nlmsg_free(msg); | |
14101 | return; | |
14102 | } | |
14103 | ||
14104 | /* | |
14105 | * Since we are applying the beacon hint to a wiphy we know its | |
14106 | * wiphy_idx is valid | |
14107 | */ | |
9360ffd1 DM |
14108 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
14109 | goto nla_put_failure; | |
6bad8766 LR |
14110 | |
14111 | /* Before */ | |
14112 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
14113 | if (!nl_freq) | |
14114 | goto nla_put_failure; | |
cdc89b97 | 14115 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
14116 | goto nla_put_failure; |
14117 | nla_nest_end(msg, nl_freq); | |
14118 | ||
14119 | /* After */ | |
14120 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
14121 | if (!nl_freq) | |
14122 | goto nla_put_failure; | |
cdc89b97 | 14123 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
14124 | goto nla_put_failure; |
14125 | nla_nest_end(msg, nl_freq); | |
14126 | ||
3b7b72ee | 14127 | genlmsg_end(msg, hdr); |
6bad8766 | 14128 | |
463d0183 | 14129 | rcu_read_lock(); |
68eb5503 | 14130 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 14131 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 14132 | rcu_read_unlock(); |
6bad8766 LR |
14133 | |
14134 | return; | |
14135 | ||
14136 | nla_put_failure: | |
14137 | genlmsg_cancel(msg, hdr); | |
14138 | nlmsg_free(msg); | |
14139 | } | |
14140 | ||
9588bbd5 JM |
14141 | static void nl80211_send_remain_on_chan_event( |
14142 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 14143 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 14144 | struct ieee80211_channel *chan, |
9588bbd5 JM |
14145 | unsigned int duration, gfp_t gfp) |
14146 | { | |
14147 | struct sk_buff *msg; | |
14148 | void *hdr; | |
14149 | ||
14150 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
14151 | if (!msg) | |
14152 | return; | |
14153 | ||
14154 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
14155 | if (!hdr) { | |
14156 | nlmsg_free(msg); | |
14157 | return; | |
14158 | } | |
14159 | ||
9360ffd1 | 14160 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
14161 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
14162 | wdev->netdev->ifindex)) || | |
2dad624e ND |
14163 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14164 | NL80211_ATTR_PAD) || | |
9360ffd1 | 14165 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
14166 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
14167 | NL80211_CHAN_NO_HT) || | |
2dad624e ND |
14168 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
14169 | NL80211_ATTR_PAD)) | |
9360ffd1 | 14170 | goto nla_put_failure; |
9588bbd5 | 14171 | |
9360ffd1 DM |
14172 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
14173 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
14174 | goto nla_put_failure; | |
9588bbd5 | 14175 | |
3b7b72ee | 14176 | genlmsg_end(msg, hdr); |
9588bbd5 | 14177 | |
68eb5503 | 14178 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14179 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
14180 | return; |
14181 | ||
14182 | nla_put_failure: | |
14183 | genlmsg_cancel(msg, hdr); | |
14184 | nlmsg_free(msg); | |
14185 | } | |
14186 | ||
947add36 JB |
14187 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
14188 | struct ieee80211_channel *chan, | |
14189 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 14190 | { |
947add36 | 14191 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 14192 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
14193 | |
14194 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 14195 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 14196 | rdev, wdev, cookie, chan, |
42d97a59 | 14197 | duration, gfp); |
9588bbd5 | 14198 | } |
947add36 | 14199 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 14200 | |
947add36 JB |
14201 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
14202 | struct ieee80211_channel *chan, | |
14203 | gfp_t gfp) | |
9588bbd5 | 14204 | { |
947add36 | 14205 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 14206 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
14207 | |
14208 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 14209 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 14210 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 14211 | } |
947add36 | 14212 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 14213 | |
947add36 JB |
14214 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
14215 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 14216 | { |
947add36 | 14217 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 14218 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
14219 | struct sk_buff *msg; |
14220 | ||
947add36 JB |
14221 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
14222 | ||
58050fce | 14223 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
14224 | if (!msg) |
14225 | return; | |
14226 | ||
cf5ead82 | 14227 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 14228 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
14229 | nlmsg_free(msg); |
14230 | return; | |
14231 | } | |
14232 | ||
68eb5503 | 14233 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14234 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 14235 | } |
947add36 | 14236 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 14237 | |
cf5ead82 JB |
14238 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
14239 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 14240 | { |
947add36 | 14241 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 14242 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 14243 | struct sk_buff *msg; |
cf5ead82 JB |
14244 | struct station_info empty_sinfo = {}; |
14245 | ||
14246 | if (!sinfo) | |
14247 | sinfo = &empty_sinfo; | |
ec15e68b | 14248 | |
947add36 JB |
14249 | trace_cfg80211_del_sta(dev, mac_addr); |
14250 | ||
58050fce | 14251 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
14252 | if (!msg) |
14253 | return; | |
14254 | ||
cf5ead82 | 14255 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 14256 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
14257 | nlmsg_free(msg); |
14258 | return; | |
14259 | } | |
14260 | ||
68eb5503 | 14261 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14262 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 14263 | } |
cf5ead82 | 14264 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 14265 | |
947add36 JB |
14266 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
14267 | enum nl80211_connect_failed_reason reason, | |
14268 | gfp_t gfp) | |
ed44a951 | 14269 | { |
947add36 | 14270 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 14271 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
14272 | struct sk_buff *msg; |
14273 | void *hdr; | |
14274 | ||
14275 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
14276 | if (!msg) | |
14277 | return; | |
14278 | ||
14279 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
14280 | if (!hdr) { | |
14281 | nlmsg_free(msg); | |
14282 | return; | |
14283 | } | |
14284 | ||
14285 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
14286 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
14287 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
14288 | goto nla_put_failure; | |
14289 | ||
14290 | genlmsg_end(msg, hdr); | |
14291 | ||
68eb5503 | 14292 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14293 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
14294 | return; |
14295 | ||
14296 | nla_put_failure: | |
14297 | genlmsg_cancel(msg, hdr); | |
14298 | nlmsg_free(msg); | |
14299 | } | |
947add36 | 14300 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 14301 | |
b92ab5d8 JB |
14302 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
14303 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
14304 | { |
14305 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 14306 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
14307 | struct sk_buff *msg; |
14308 | void *hdr; | |
6aa7de05 | 14309 | u32 nlportid = READ_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 14310 | |
15e47304 | 14311 | if (!nlportid) |
28946da7 JB |
14312 | return false; |
14313 | ||
14314 | msg = nlmsg_new(100, gfp); | |
14315 | if (!msg) | |
14316 | return true; | |
14317 | ||
b92ab5d8 | 14318 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
14319 | if (!hdr) { |
14320 | nlmsg_free(msg); | |
14321 | return true; | |
14322 | } | |
14323 | ||
9360ffd1 DM |
14324 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14325 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
14326 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
14327 | goto nla_put_failure; | |
28946da7 | 14328 | |
9c90a9f6 | 14329 | genlmsg_end(msg, hdr); |
15e47304 | 14330 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
14331 | return true; |
14332 | ||
14333 | nla_put_failure: | |
14334 | genlmsg_cancel(msg, hdr); | |
14335 | nlmsg_free(msg); | |
14336 | return true; | |
14337 | } | |
14338 | ||
947add36 JB |
14339 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
14340 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 14341 | { |
947add36 JB |
14342 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
14343 | bool ret; | |
14344 | ||
14345 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
14346 | ||
14347 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
14348 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
14349 | trace_cfg80211_return_bool(false); | |
14350 | return false; | |
14351 | } | |
14352 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
14353 | addr, gfp); | |
14354 | trace_cfg80211_return_bool(ret); | |
14355 | return ret; | |
b92ab5d8 | 14356 | } |
947add36 | 14357 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 14358 | |
947add36 JB |
14359 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
14360 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 14361 | { |
947add36 JB |
14362 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
14363 | bool ret; | |
14364 | ||
14365 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
14366 | ||
14367 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
14368 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
14369 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
14370 | trace_cfg80211_return_bool(false); | |
14371 | return false; | |
14372 | } | |
14373 | ret = __nl80211_unexpected_frame(dev, | |
14374 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
14375 | addr, gfp); | |
14376 | trace_cfg80211_return_bool(ret); | |
14377 | return ret; | |
b92ab5d8 | 14378 | } |
947add36 | 14379 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 14380 | |
2e161f78 | 14381 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 14382 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 14383 | int freq, int sig_dbm, |
19504cf5 | 14384 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 14385 | { |
71bbc994 | 14386 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
14387 | struct sk_buff *msg; |
14388 | void *hdr; | |
026331c4 | 14389 | |
4ef8c1c9 | 14390 | msg = nlmsg_new(100 + len, gfp); |
026331c4 JM |
14391 | if (!msg) |
14392 | return -ENOMEM; | |
14393 | ||
2e161f78 | 14394 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
14395 | if (!hdr) { |
14396 | nlmsg_free(msg); | |
14397 | return -ENOMEM; | |
14398 | } | |
14399 | ||
9360ffd1 | 14400 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
14401 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
14402 | netdev->ifindex)) || | |
2dad624e ND |
14403 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14404 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
14405 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
14406 | (sig_dbm && | |
14407 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
14408 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
14409 | (flags && | |
14410 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 14411 | goto nla_put_failure; |
026331c4 | 14412 | |
3b7b72ee | 14413 | genlmsg_end(msg, hdr); |
026331c4 | 14414 | |
15e47304 | 14415 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
14416 | |
14417 | nla_put_failure: | |
14418 | genlmsg_cancel(msg, hdr); | |
14419 | nlmsg_free(msg); | |
14420 | return -ENOBUFS; | |
14421 | } | |
14422 | ||
947add36 JB |
14423 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
14424 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 14425 | { |
947add36 | 14426 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 14427 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 14428 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
14429 | struct sk_buff *msg; |
14430 | void *hdr; | |
14431 | ||
947add36 JB |
14432 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
14433 | ||
4ef8c1c9 | 14434 | msg = nlmsg_new(100 + len, gfp); |
026331c4 JM |
14435 | if (!msg) |
14436 | return; | |
14437 | ||
2e161f78 | 14438 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
14439 | if (!hdr) { |
14440 | nlmsg_free(msg); | |
14441 | return; | |
14442 | } | |
14443 | ||
9360ffd1 | 14444 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
14445 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
14446 | netdev->ifindex)) || | |
2dad624e ND |
14447 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14448 | NL80211_ATTR_PAD) || | |
9360ffd1 | 14449 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
2dad624e ND |
14450 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
14451 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
14452 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
14453 | goto nla_put_failure; | |
026331c4 | 14454 | |
3b7b72ee | 14455 | genlmsg_end(msg, hdr); |
026331c4 | 14456 | |
68eb5503 | 14457 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14458 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
14459 | return; |
14460 | ||
14461 | nla_put_failure: | |
14462 | genlmsg_cancel(msg, hdr); | |
14463 | nlmsg_free(msg); | |
14464 | } | |
947add36 | 14465 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 14466 | |
5b97f49d JB |
14467 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
14468 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 14469 | { |
947add36 | 14470 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
14471 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
14472 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
14473 | void **cb; | |
947add36 | 14474 | |
d6dc1a38 | 14475 | if (!msg) |
5b97f49d | 14476 | return NULL; |
d6dc1a38 | 14477 | |
5b97f49d JB |
14478 | cb = (void **)msg->cb; |
14479 | ||
14480 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
14481 | if (!cb[0]) { | |
d6dc1a38 | 14482 | nlmsg_free(msg); |
5b97f49d | 14483 | return NULL; |
d6dc1a38 JO |
14484 | } |
14485 | ||
9360ffd1 | 14486 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 14487 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 14488 | goto nla_put_failure; |
d6dc1a38 | 14489 | |
5b97f49d | 14490 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
14491 | goto nla_put_failure; |
14492 | ||
5b97f49d JB |
14493 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
14494 | if (!cb[1]) | |
9360ffd1 | 14495 | goto nla_put_failure; |
d6dc1a38 | 14496 | |
5b97f49d | 14497 | cb[2] = rdev; |
d6dc1a38 | 14498 | |
5b97f49d JB |
14499 | return msg; |
14500 | nla_put_failure: | |
14501 | nlmsg_free(msg); | |
14502 | return NULL; | |
14503 | } | |
14504 | ||
14505 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
14506 | { | |
14507 | void **cb = (void **)msg->cb; | |
14508 | struct cfg80211_registered_device *rdev = cb[2]; | |
14509 | ||
14510 | nla_nest_end(msg, cb[1]); | |
14511 | genlmsg_end(msg, cb[0]); | |
14512 | ||
14513 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 14514 | |
68eb5503 | 14515 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14516 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
14517 | } |
14518 | ||
14519 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
14520 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
bee427b8 | 14521 | s32 rssi_level, gfp_t gfp) |
5b97f49d JB |
14522 | { |
14523 | struct sk_buff *msg; | |
4a4b8169 AZ |
14524 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
14525 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); | |
5b97f49d | 14526 | |
bee427b8 | 14527 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event, rssi_level); |
5b97f49d | 14528 | |
98f03342 JB |
14529 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
14530 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
14531 | return; | |
14532 | ||
4a4b8169 AZ |
14533 | if (wdev->cqm_config) { |
14534 | wdev->cqm_config->last_rssi_event_value = rssi_level; | |
14535 | ||
14536 | cfg80211_cqm_rssi_update(rdev, dev); | |
14537 | ||
14538 | if (rssi_level == 0) | |
14539 | rssi_level = wdev->cqm_config->last_rssi_event_value; | |
14540 | } | |
14541 | ||
5b97f49d JB |
14542 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
14543 | if (!msg) | |
14544 | return; | |
14545 | ||
14546 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
14547 | rssi_event)) | |
14548 | goto nla_put_failure; | |
14549 | ||
bee427b8 AZ |
14550 | if (rssi_level && nla_put_s32(msg, NL80211_ATTR_CQM_RSSI_LEVEL, |
14551 | rssi_level)) | |
14552 | goto nla_put_failure; | |
14553 | ||
5b97f49d JB |
14554 | cfg80211_send_cqm(msg, gfp); |
14555 | ||
d6dc1a38 JO |
14556 | return; |
14557 | ||
14558 | nla_put_failure: | |
d6dc1a38 JO |
14559 | nlmsg_free(msg); |
14560 | } | |
947add36 | 14561 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 14562 | |
5b97f49d JB |
14563 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
14564 | const u8 *peer, u32 num_packets, | |
14565 | u32 rate, u32 intvl, gfp_t gfp) | |
14566 | { | |
14567 | struct sk_buff *msg; | |
14568 | ||
14569 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
14570 | if (!msg) | |
14571 | return; | |
14572 | ||
14573 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
14574 | goto nla_put_failure; | |
14575 | ||
14576 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
14577 | goto nla_put_failure; | |
14578 | ||
14579 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
14580 | goto nla_put_failure; | |
14581 | ||
14582 | cfg80211_send_cqm(msg, gfp); | |
14583 | return; | |
14584 | ||
14585 | nla_put_failure: | |
14586 | nlmsg_free(msg); | |
14587 | } | |
14588 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
14589 | ||
14590 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
14591 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
14592 | { | |
14593 | struct sk_buff *msg; | |
14594 | ||
14595 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
14596 | ||
14597 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
14598 | if (!msg) | |
14599 | return; | |
14600 | ||
14601 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
14602 | goto nla_put_failure; | |
14603 | ||
14604 | cfg80211_send_cqm(msg, gfp); | |
14605 | return; | |
14606 | ||
14607 | nla_put_failure: | |
14608 | nlmsg_free(msg); | |
14609 | } | |
14610 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
14611 | ||
98f03342 JB |
14612 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
14613 | { | |
14614 | struct sk_buff *msg; | |
14615 | ||
14616 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
14617 | if (!msg) | |
14618 | return; | |
14619 | ||
14620 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
14621 | goto nla_put_failure; | |
14622 | ||
14623 | cfg80211_send_cqm(msg, gfp); | |
14624 | return; | |
14625 | ||
14626 | nla_put_failure: | |
14627 | nlmsg_free(msg); | |
14628 | } | |
14629 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
14630 | ||
947add36 JB |
14631 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
14632 | struct net_device *netdev, const u8 *bssid, | |
14633 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
14634 | { |
14635 | struct sk_buff *msg; | |
14636 | struct nlattr *rekey_attr; | |
14637 | void *hdr; | |
14638 | ||
58050fce | 14639 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
14640 | if (!msg) |
14641 | return; | |
14642 | ||
14643 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
14644 | if (!hdr) { | |
14645 | nlmsg_free(msg); | |
14646 | return; | |
14647 | } | |
14648 | ||
9360ffd1 DM |
14649 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14650 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
14651 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
14652 | goto nla_put_failure; | |
e5497d76 JB |
14653 | |
14654 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
14655 | if (!rekey_attr) | |
14656 | goto nla_put_failure; | |
14657 | ||
9360ffd1 DM |
14658 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
14659 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
14660 | goto nla_put_failure; | |
e5497d76 JB |
14661 | |
14662 | nla_nest_end(msg, rekey_attr); | |
14663 | ||
3b7b72ee | 14664 | genlmsg_end(msg, hdr); |
e5497d76 | 14665 | |
68eb5503 | 14666 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14667 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
14668 | return; |
14669 | ||
14670 | nla_put_failure: | |
14671 | genlmsg_cancel(msg, hdr); | |
14672 | nlmsg_free(msg); | |
14673 | } | |
14674 | ||
947add36 JB |
14675 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
14676 | const u8 *replay_ctr, gfp_t gfp) | |
14677 | { | |
14678 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
14679 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 14680 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
14681 | |
14682 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
14683 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
14684 | } | |
14685 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
14686 | ||
14687 | static void | |
14688 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
14689 | struct net_device *netdev, int index, | |
14690 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
14691 | { |
14692 | struct sk_buff *msg; | |
14693 | struct nlattr *attr; | |
14694 | void *hdr; | |
14695 | ||
58050fce | 14696 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
14697 | if (!msg) |
14698 | return; | |
14699 | ||
14700 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
14701 | if (!hdr) { | |
14702 | nlmsg_free(msg); | |
14703 | return; | |
14704 | } | |
14705 | ||
9360ffd1 DM |
14706 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14707 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
14708 | goto nla_put_failure; | |
c9df56b4 JM |
14709 | |
14710 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
14711 | if (!attr) | |
14712 | goto nla_put_failure; | |
14713 | ||
9360ffd1 DM |
14714 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
14715 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
14716 | (preauth && | |
14717 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
14718 | goto nla_put_failure; | |
c9df56b4 JM |
14719 | |
14720 | nla_nest_end(msg, attr); | |
14721 | ||
3b7b72ee | 14722 | genlmsg_end(msg, hdr); |
c9df56b4 | 14723 | |
68eb5503 | 14724 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14725 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
14726 | return; |
14727 | ||
14728 | nla_put_failure: | |
14729 | genlmsg_cancel(msg, hdr); | |
14730 | nlmsg_free(msg); | |
14731 | } | |
14732 | ||
947add36 JB |
14733 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
14734 | const u8 *bssid, bool preauth, gfp_t gfp) | |
14735 | { | |
14736 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
14737 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 14738 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
14739 | |
14740 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
14741 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
14742 | } | |
14743 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
14744 | ||
14745 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
14746 | struct net_device *netdev, | |
14747 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
14748 | gfp_t gfp, |
14749 | enum nl80211_commands notif, | |
14750 | u8 count) | |
5314526b TP |
14751 | { |
14752 | struct sk_buff *msg; | |
14753 | void *hdr; | |
14754 | ||
58050fce | 14755 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
14756 | if (!msg) |
14757 | return; | |
14758 | ||
f8d7552e | 14759 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
14760 | if (!hdr) { |
14761 | nlmsg_free(msg); | |
14762 | return; | |
14763 | } | |
14764 | ||
683b6d3b JB |
14765 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
14766 | goto nla_put_failure; | |
14767 | ||
14768 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 14769 | goto nla_put_failure; |
5314526b | 14770 | |
f8d7552e LC |
14771 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
14772 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
14773 | goto nla_put_failure; | |
14774 | ||
5314526b TP |
14775 | genlmsg_end(msg, hdr); |
14776 | ||
68eb5503 | 14777 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14778 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
14779 | return; |
14780 | ||
14781 | nla_put_failure: | |
14782 | genlmsg_cancel(msg, hdr); | |
14783 | nlmsg_free(msg); | |
14784 | } | |
14785 | ||
947add36 JB |
14786 | void cfg80211_ch_switch_notify(struct net_device *dev, |
14787 | struct cfg80211_chan_def *chandef) | |
84f10708 | 14788 | { |
947add36 JB |
14789 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
14790 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 14791 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 14792 | |
e487eaeb | 14793 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 14794 | |
e487eaeb | 14795 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 14796 | |
9e0e2961 | 14797 | wdev->chandef = *chandef; |
96f55f12 | 14798 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
14799 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
14800 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
14801 | } |
14802 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
14803 | ||
f8d7552e LC |
14804 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
14805 | struct cfg80211_chan_def *chandef, | |
14806 | u8 count) | |
14807 | { | |
14808 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
14809 | struct wiphy *wiphy = wdev->wiphy; | |
14810 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
14811 | ||
14812 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
14813 | ||
14814 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
14815 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
14816 | } | |
14817 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
14818 | ||
04f39047 SW |
14819 | void |
14820 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 14821 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
14822 | enum nl80211_radar_event event, |
14823 | struct net_device *netdev, gfp_t gfp) | |
14824 | { | |
14825 | struct sk_buff *msg; | |
14826 | void *hdr; | |
14827 | ||
14828 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
14829 | if (!msg) | |
14830 | return; | |
14831 | ||
14832 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
14833 | if (!hdr) { | |
14834 | nlmsg_free(msg); | |
14835 | return; | |
14836 | } | |
14837 | ||
14838 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
14839 | goto nla_put_failure; | |
14840 | ||
14841 | /* NOP and radar events don't need a netdev parameter */ | |
14842 | if (netdev) { | |
14843 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
14844 | ||
14845 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
2dad624e ND |
14846 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14847 | NL80211_ATTR_PAD)) | |
04f39047 SW |
14848 | goto nla_put_failure; |
14849 | } | |
14850 | ||
14851 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
14852 | goto nla_put_failure; | |
14853 | ||
14854 | if (nl80211_send_chandef(msg, chandef)) | |
14855 | goto nla_put_failure; | |
14856 | ||
9c90a9f6 | 14857 | genlmsg_end(msg, hdr); |
04f39047 | 14858 | |
68eb5503 | 14859 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14860 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
14861 | return; |
14862 | ||
14863 | nla_put_failure: | |
14864 | genlmsg_cancel(msg, hdr); | |
14865 | nlmsg_free(msg); | |
14866 | } | |
14867 | ||
7f6cf311 JB |
14868 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
14869 | u64 cookie, bool acked, gfp_t gfp) | |
14870 | { | |
14871 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 14872 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
14873 | struct sk_buff *msg; |
14874 | void *hdr; | |
7f6cf311 | 14875 | |
4ee3e063 BL |
14876 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
14877 | ||
58050fce | 14878 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 14879 | |
7f6cf311 JB |
14880 | if (!msg) |
14881 | return; | |
14882 | ||
14883 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
14884 | if (!hdr) { | |
14885 | nlmsg_free(msg); | |
14886 | return; | |
14887 | } | |
14888 | ||
9360ffd1 DM |
14889 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14890 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
14891 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2dad624e ND |
14892 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
14893 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
14894 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
14895 | goto nla_put_failure; | |
7f6cf311 | 14896 | |
9c90a9f6 | 14897 | genlmsg_end(msg, hdr); |
7f6cf311 | 14898 | |
68eb5503 | 14899 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14900 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
14901 | return; |
14902 | ||
14903 | nla_put_failure: | |
14904 | genlmsg_cancel(msg, hdr); | |
14905 | nlmsg_free(msg); | |
14906 | } | |
14907 | EXPORT_SYMBOL(cfg80211_probe_status); | |
14908 | ||
5e760230 JB |
14909 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
14910 | const u8 *frame, size_t len, | |
37c73b5f | 14911 | int freq, int sig_dbm) |
5e760230 | 14912 | { |
f26cbf40 | 14913 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
14914 | struct sk_buff *msg; |
14915 | void *hdr; | |
37c73b5f | 14916 | struct cfg80211_beacon_registration *reg; |
5e760230 | 14917 | |
4ee3e063 BL |
14918 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
14919 | ||
37c73b5f BG |
14920 | spin_lock_bh(&rdev->beacon_registrations_lock); |
14921 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
14922 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
14923 | if (!msg) { | |
14924 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
14925 | return; | |
14926 | } | |
5e760230 | 14927 | |
37c73b5f BG |
14928 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
14929 | if (!hdr) | |
14930 | goto nla_put_failure; | |
5e760230 | 14931 | |
37c73b5f BG |
14932 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14933 | (freq && | |
14934 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
14935 | (sig_dbm && | |
14936 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
14937 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
14938 | goto nla_put_failure; | |
5e760230 | 14939 | |
37c73b5f | 14940 | genlmsg_end(msg, hdr); |
5e760230 | 14941 | |
37c73b5f BG |
14942 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
14943 | } | |
14944 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
14945 | return; |
14946 | ||
14947 | nla_put_failure: | |
37c73b5f BG |
14948 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
14949 | if (hdr) | |
14950 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
14951 | nlmsg_free(msg); |
14952 | } | |
14953 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
14954 | ||
cd8f7cb4 | 14955 | #ifdef CONFIG_PM |
8cd4d456 LC |
14956 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
14957 | struct cfg80211_wowlan_wakeup *wakeup) | |
14958 | { | |
14959 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
14960 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
14961 | int i, j; | |
14962 | ||
14963 | nl_results = nla_nest_start( | |
14964 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
14965 | if (!nl_results) | |
14966 | return -EMSGSIZE; | |
14967 | ||
14968 | for (i = 0; i < nd->n_matches; i++) { | |
14969 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
14970 | ||
14971 | nl_match = nla_nest_start(msg, i); | |
14972 | if (!nl_match) | |
14973 | break; | |
14974 | ||
14975 | /* The SSID attribute is optional in nl80211, but for | |
14976 | * simplicity reasons it's always present in the | |
14977 | * cfg80211 structure. If a driver can't pass the | |
14978 | * SSID, that needs to be changed. A zero length SSID | |
14979 | * is still a valid SSID (wildcard), so it cannot be | |
14980 | * used for this purpose. | |
14981 | */ | |
14982 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
14983 | match->ssid.ssid)) { | |
14984 | nla_nest_cancel(msg, nl_match); | |
14985 | goto out; | |
14986 | } | |
14987 | ||
14988 | if (match->n_channels) { | |
14989 | nl_freqs = nla_nest_start( | |
14990 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
14991 | if (!nl_freqs) { | |
14992 | nla_nest_cancel(msg, nl_match); | |
14993 | goto out; | |
14994 | } | |
14995 | ||
14996 | for (j = 0; j < match->n_channels; j++) { | |
5528fae8 | 14997 | if (nla_put_u32(msg, j, match->channels[j])) { |
8cd4d456 LC |
14998 | nla_nest_cancel(msg, nl_freqs); |
14999 | nla_nest_cancel(msg, nl_match); | |
15000 | goto out; | |
15001 | } | |
15002 | } | |
15003 | ||
15004 | nla_nest_end(msg, nl_freqs); | |
15005 | } | |
15006 | ||
15007 | nla_nest_end(msg, nl_match); | |
15008 | } | |
15009 | ||
15010 | out: | |
15011 | nla_nest_end(msg, nl_results); | |
15012 | return 0; | |
15013 | } | |
15014 | ||
cd8f7cb4 JB |
15015 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
15016 | struct cfg80211_wowlan_wakeup *wakeup, | |
15017 | gfp_t gfp) | |
15018 | { | |
f26cbf40 | 15019 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
15020 | struct sk_buff *msg; |
15021 | void *hdr; | |
9c90a9f6 | 15022 | int size = 200; |
cd8f7cb4 JB |
15023 | |
15024 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
15025 | ||
15026 | if (wakeup) | |
15027 | size += wakeup->packet_present_len; | |
15028 | ||
15029 | msg = nlmsg_new(size, gfp); | |
15030 | if (!msg) | |
15031 | return; | |
15032 | ||
15033 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
15034 | if (!hdr) | |
15035 | goto free_msg; | |
15036 | ||
15037 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
15038 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
15039 | NL80211_ATTR_PAD)) | |
cd8f7cb4 JB |
15040 | goto free_msg; |
15041 | ||
15042 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
15043 | wdev->netdev->ifindex)) | |
15044 | goto free_msg; | |
15045 | ||
15046 | if (wakeup) { | |
15047 | struct nlattr *reasons; | |
15048 | ||
15049 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
15050 | if (!reasons) |
15051 | goto free_msg; | |
cd8f7cb4 JB |
15052 | |
15053 | if (wakeup->disconnect && | |
15054 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
15055 | goto free_msg; | |
15056 | if (wakeup->magic_pkt && | |
15057 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
15058 | goto free_msg; | |
15059 | if (wakeup->gtk_rekey_failure && | |
15060 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
15061 | goto free_msg; | |
15062 | if (wakeup->eap_identity_req && | |
15063 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
15064 | goto free_msg; | |
15065 | if (wakeup->four_way_handshake && | |
15066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
15067 | goto free_msg; | |
15068 | if (wakeup->rfkill_release && | |
15069 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
15070 | goto free_msg; | |
15071 | ||
15072 | if (wakeup->pattern_idx >= 0 && | |
15073 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
15074 | wakeup->pattern_idx)) | |
15075 | goto free_msg; | |
15076 | ||
ae917c9f JB |
15077 | if (wakeup->tcp_match && |
15078 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
15079 | goto free_msg; | |
2a0e047e | 15080 | |
ae917c9f JB |
15081 | if (wakeup->tcp_connlost && |
15082 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
15083 | goto free_msg; | |
2a0e047e | 15084 | |
ae917c9f JB |
15085 | if (wakeup->tcp_nomoretokens && |
15086 | nla_put_flag(msg, | |
15087 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
15088 | goto free_msg; | |
2a0e047e | 15089 | |
cd8f7cb4 JB |
15090 | if (wakeup->packet) { |
15091 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
15092 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
15093 | ||
15094 | if (!wakeup->packet_80211) { | |
15095 | pkt_attr = | |
15096 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
15097 | len_attr = | |
15098 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
15099 | } | |
15100 | ||
15101 | if (wakeup->packet_len && | |
15102 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
15103 | goto free_msg; | |
15104 | ||
15105 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
15106 | wakeup->packet)) | |
15107 | goto free_msg; | |
15108 | } | |
15109 | ||
8cd4d456 LC |
15110 | if (wakeup->net_detect && |
15111 | cfg80211_net_detect_results(msg, wakeup)) | |
15112 | goto free_msg; | |
15113 | ||
cd8f7cb4 JB |
15114 | nla_nest_end(msg, reasons); |
15115 | } | |
15116 | ||
9c90a9f6 | 15117 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 15118 | |
68eb5503 | 15119 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15120 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
15121 | return; |
15122 | ||
15123 | free_msg: | |
15124 | nlmsg_free(msg); | |
15125 | } | |
15126 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
15127 | #endif | |
15128 | ||
3475b094 JM |
15129 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
15130 | enum nl80211_tdls_operation oper, | |
15131 | u16 reason_code, gfp_t gfp) | |
15132 | { | |
15133 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 15134 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
15135 | struct sk_buff *msg; |
15136 | void *hdr; | |
3475b094 JM |
15137 | |
15138 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
15139 | reason_code); | |
15140 | ||
15141 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
15142 | if (!msg) | |
15143 | return; | |
15144 | ||
15145 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
15146 | if (!hdr) { | |
15147 | nlmsg_free(msg); | |
15148 | return; | |
15149 | } | |
15150 | ||
15151 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
15152 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
15153 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
15154 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
15155 | (reason_code > 0 && | |
15156 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
15157 | goto nla_put_failure; | |
15158 | ||
9c90a9f6 | 15159 | genlmsg_end(msg, hdr); |
3475b094 | 15160 | |
68eb5503 | 15161 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15162 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
15163 | return; |
15164 | ||
15165 | nla_put_failure: | |
15166 | genlmsg_cancel(msg, hdr); | |
15167 | nlmsg_free(msg); | |
15168 | } | |
15169 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
15170 | ||
026331c4 JM |
15171 | static int nl80211_netlink_notify(struct notifier_block * nb, |
15172 | unsigned long state, | |
15173 | void *_notify) | |
15174 | { | |
15175 | struct netlink_notify *notify = _notify; | |
15176 | struct cfg80211_registered_device *rdev; | |
15177 | struct wireless_dev *wdev; | |
37c73b5f | 15178 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 | 15179 | |
8f815cdd | 15180 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
026331c4 JM |
15181 | return NOTIFY_DONE; |
15182 | ||
15183 | rcu_read_lock(); | |
15184 | ||
5e760230 | 15185 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
ca986ad9 | 15186 | struct cfg80211_sched_scan_request *sched_scan_req; |
753aacfd | 15187 | |
ca986ad9 AVS |
15188 | list_for_each_entry_rcu(sched_scan_req, |
15189 | &rdev->sched_scan_req_list, | |
15190 | list) { | |
15191 | if (sched_scan_req->owner_nlportid == notify->portid) { | |
15192 | sched_scan_req->nl_owner_dead = true; | |
753aacfd | 15193 | schedule_work(&rdev->sched_scan_stop_wk); |
ca986ad9 | 15194 | } |
753aacfd | 15195 | } |
78f22b6a | 15196 | |
53873f13 | 15197 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
15e47304 | 15198 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 15199 | |
ab81007a JB |
15200 | if (wdev->owner_nlportid == notify->portid) { |
15201 | wdev->nl_owner_dead = true; | |
15202 | schedule_work(&rdev->destroy_work); | |
15203 | } else if (wdev->conn_owner_nlportid == notify->portid) { | |
bd2522b1 | 15204 | schedule_work(&wdev->disconnect_wk); |
ab81007a | 15205 | } |
78f22b6a JB |
15206 | } |
15207 | ||
37c73b5f BG |
15208 | spin_lock_bh(&rdev->beacon_registrations_lock); |
15209 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
15210 | list) { | |
15211 | if (reg->nlportid == notify->portid) { | |
15212 | list_del(®->list); | |
15213 | kfree(reg); | |
15214 | break; | |
15215 | } | |
15216 | } | |
15217 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 | 15218 | } |
026331c4 JM |
15219 | |
15220 | rcu_read_unlock(); | |
15221 | ||
05050753 I |
15222 | /* |
15223 | * It is possible that the user space process that is controlling the | |
15224 | * indoor setting disappeared, so notify the regulatory core. | |
15225 | */ | |
15226 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 15227 | return NOTIFY_OK; |
026331c4 JM |
15228 | } |
15229 | ||
15230 | static struct notifier_block nl80211_netlink_notifier = { | |
15231 | .notifier_call = nl80211_netlink_notify, | |
15232 | }; | |
15233 | ||
355199e0 JM |
15234 | void cfg80211_ft_event(struct net_device *netdev, |
15235 | struct cfg80211_ft_event_params *ft_event) | |
15236 | { | |
15237 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 15238 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
15239 | struct sk_buff *msg; |
15240 | void *hdr; | |
355199e0 JM |
15241 | |
15242 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
15243 | ||
15244 | if (!ft_event->target_ap) | |
15245 | return; | |
15246 | ||
4ef8c1c9 | 15247 | msg = nlmsg_new(100 + ft_event->ric_ies_len, GFP_KERNEL); |
355199e0 JM |
15248 | if (!msg) |
15249 | return; | |
15250 | ||
15251 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
15252 | if (!hdr) |
15253 | goto out; | |
355199e0 | 15254 | |
ae917c9f JB |
15255 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
15256 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
15257 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
15258 | goto out; | |
355199e0 | 15259 | |
ae917c9f JB |
15260 | if (ft_event->ies && |
15261 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
15262 | goto out; | |
15263 | if (ft_event->ric_ies && | |
15264 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
15265 | ft_event->ric_ies)) | |
15266 | goto out; | |
355199e0 | 15267 | |
9c90a9f6 | 15268 | genlmsg_end(msg, hdr); |
355199e0 | 15269 | |
68eb5503 | 15270 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 15271 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
15272 | return; |
15273 | out: | |
15274 | nlmsg_free(msg); | |
355199e0 JM |
15275 | } |
15276 | EXPORT_SYMBOL(cfg80211_ft_event); | |
15277 | ||
5de17984 AS |
15278 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
15279 | { | |
15280 | struct cfg80211_registered_device *rdev; | |
15281 | struct sk_buff *msg; | |
15282 | void *hdr; | |
15283 | u32 nlportid; | |
15284 | ||
f26cbf40 | 15285 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
15286 | if (!rdev->crit_proto_nlportid) |
15287 | return; | |
15288 | ||
15289 | nlportid = rdev->crit_proto_nlportid; | |
15290 | rdev->crit_proto_nlportid = 0; | |
15291 | ||
15292 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
15293 | if (!msg) | |
15294 | return; | |
15295 | ||
15296 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
15297 | if (!hdr) | |
15298 | goto nla_put_failure; | |
15299 | ||
15300 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
15301 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
15302 | NL80211_ATTR_PAD)) | |
5de17984 AS |
15303 | goto nla_put_failure; |
15304 | ||
15305 | genlmsg_end(msg, hdr); | |
15306 | ||
15307 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
15308 | return; | |
15309 | ||
15310 | nla_put_failure: | |
15311 | if (hdr) | |
15312 | genlmsg_cancel(msg, hdr); | |
15313 | nlmsg_free(msg); | |
5de17984 AS |
15314 | } |
15315 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
15316 | ||
348baf0e JB |
15317 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
15318 | { | |
15319 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 15320 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
15321 | struct sk_buff *msg; |
15322 | void *hdr; | |
15323 | ||
15324 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
15325 | if (!msg) | |
15326 | return; | |
15327 | ||
15328 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
15329 | if (!hdr) | |
15330 | goto out; | |
15331 | ||
15332 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
15333 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
2dad624e ND |
15334 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
15335 | NL80211_ATTR_PAD)) | |
348baf0e JB |
15336 | goto out; |
15337 | ||
15338 | genlmsg_end(msg, hdr); | |
15339 | ||
15340 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
15341 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
15342 | return; | |
15343 | out: | |
15344 | nlmsg_free(msg); | |
15345 | } | |
15346 | ||
55682965 JB |
15347 | /* initialisation/exit functions */ |
15348 | ||
56989f6d | 15349 | int __init nl80211_init(void) |
55682965 | 15350 | { |
0d63cbb5 | 15351 | int err; |
55682965 | 15352 | |
489111e5 | 15353 | err = genl_register_family(&nl80211_fam); |
55682965 JB |
15354 | if (err) |
15355 | return err; | |
15356 | ||
026331c4 JM |
15357 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
15358 | if (err) | |
15359 | goto err_out; | |
15360 | ||
55682965 JB |
15361 | return 0; |
15362 | err_out: | |
15363 | genl_unregister_family(&nl80211_fam); | |
15364 | return err; | |
15365 | } | |
15366 | ||
15367 | void nl80211_exit(void) | |
15368 | { | |
026331c4 | 15369 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
15370 | genl_unregister_family(&nl80211_fam); |
15371 | } |