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 |
0c9ca11b | 6 | * Copyright 2015-2016 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> | |
2a519311 | 19 | #include <linux/etherdevice.h> |
463d0183 | 20 | #include <net/net_namespace.h> |
55682965 JB |
21 | #include <net/genetlink.h> |
22 | #include <net/cfg80211.h> | |
463d0183 | 23 | #include <net/sock.h> |
2a0e047e | 24 | #include <net/inet_connection_sock.h> |
55682965 JB |
25 | #include "core.h" |
26 | #include "nl80211.h" | |
b2e1b302 | 27 | #include "reg.h" |
e35e4d28 | 28 | #include "rdev-ops.h" |
55682965 | 29 | |
5fb628e9 JM |
30 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
31 | struct genl_info *info, | |
32 | struct cfg80211_crypto_settings *settings, | |
33 | int cipher_limit); | |
34 | ||
55682965 | 35 | /* the netlink family */ |
489111e5 | 36 | static struct genl_family nl80211_fam; |
55682965 | 37 | |
2a94fe48 JB |
38 | /* multicast groups */ |
39 | enum nl80211_multicast_groups { | |
40 | NL80211_MCGRP_CONFIG, | |
41 | NL80211_MCGRP_SCAN, | |
42 | NL80211_MCGRP_REGULATORY, | |
43 | NL80211_MCGRP_MLME, | |
567ffc35 | 44 | NL80211_MCGRP_VENDOR, |
50bcd31d | 45 | NL80211_MCGRP_NAN, |
2a94fe48 JB |
46 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
47 | }; | |
48 | ||
49 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
50 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
51 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
52 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
53 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
54 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
50bcd31d | 55 | [NL80211_MCGRP_NAN] = { .name = NL80211_MULTICAST_GROUP_NAN }, |
2a94fe48 | 56 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 57 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
58 | #endif |
59 | }; | |
60 | ||
89a54e48 JB |
61 | /* returns ERR_PTR values */ |
62 | static struct wireless_dev * | |
63 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 64 | { |
89a54e48 JB |
65 | struct cfg80211_registered_device *rdev; |
66 | struct wireless_dev *result = NULL; | |
67 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
68 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
69 | u64 wdev_id; | |
70 | int wiphy_idx = -1; | |
71 | int ifidx = -1; | |
55682965 | 72 | |
5fe231e8 | 73 | ASSERT_RTNL(); |
55682965 | 74 | |
89a54e48 JB |
75 | if (!have_ifidx && !have_wdev_id) |
76 | return ERR_PTR(-EINVAL); | |
55682965 | 77 | |
89a54e48 JB |
78 | if (have_ifidx) |
79 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
80 | if (have_wdev_id) { | |
81 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
82 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
83 | } |
84 | ||
89a54e48 JB |
85 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
86 | struct wireless_dev *wdev; | |
87 | ||
88 | if (wiphy_net(&rdev->wiphy) != netns) | |
89 | continue; | |
90 | ||
91 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
92 | continue; | |
93 | ||
53873f13 | 94 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
89a54e48 JB |
95 | if (have_ifidx && wdev->netdev && |
96 | wdev->netdev->ifindex == ifidx) { | |
97 | result = wdev; | |
98 | break; | |
99 | } | |
100 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
101 | result = wdev; | |
102 | break; | |
103 | } | |
104 | } | |
89a54e48 JB |
105 | |
106 | if (result) | |
107 | break; | |
108 | } | |
109 | ||
110 | if (result) | |
111 | return result; | |
112 | return ERR_PTR(-ENODEV); | |
55682965 JB |
113 | } |
114 | ||
a9455408 | 115 | static struct cfg80211_registered_device * |
878d9ec7 | 116 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 117 | { |
7fee4778 JB |
118 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
119 | struct net_device *netdev; | |
a9455408 | 120 | |
5fe231e8 | 121 | ASSERT_RTNL(); |
a9455408 | 122 | |
878d9ec7 | 123 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
124 | !attrs[NL80211_ATTR_IFINDEX] && |
125 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
126 | return ERR_PTR(-EINVAL); |
127 | ||
878d9ec7 | 128 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 129 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 130 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 131 | |
89a54e48 JB |
132 | if (attrs[NL80211_ATTR_WDEV]) { |
133 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
134 | struct wireless_dev *wdev; | |
135 | bool found = false; | |
136 | ||
137 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
138 | if (tmp) { | |
139 | /* make sure wdev exists */ | |
53873f13 | 140 | list_for_each_entry(wdev, &tmp->wiphy.wdev_list, list) { |
89a54e48 JB |
141 | if (wdev->identifier != (u32)wdev_id) |
142 | continue; | |
143 | found = true; | |
144 | break; | |
145 | } | |
89a54e48 JB |
146 | |
147 | if (!found) | |
148 | tmp = NULL; | |
149 | ||
150 | if (rdev && tmp != rdev) | |
151 | return ERR_PTR(-EINVAL); | |
152 | rdev = tmp; | |
153 | } | |
154 | } | |
155 | ||
878d9ec7 JB |
156 | if (attrs[NL80211_ATTR_IFINDEX]) { |
157 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7a087e74 | 158 | |
7f2b8562 | 159 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
160 | if (netdev) { |
161 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
162 | tmp = wiphy_to_rdev( |
163 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
164 | else |
165 | tmp = NULL; | |
166 | ||
7fee4778 JB |
167 | /* not wireless device -- return error */ |
168 | if (!tmp) | |
169 | return ERR_PTR(-EINVAL); | |
170 | ||
171 | /* mismatch -- return error */ | |
172 | if (rdev && tmp != rdev) | |
173 | return ERR_PTR(-EINVAL); | |
174 | ||
175 | rdev = tmp; | |
a9455408 | 176 | } |
a9455408 | 177 | } |
a9455408 | 178 | |
4f7eff10 JB |
179 | if (!rdev) |
180 | return ERR_PTR(-ENODEV); | |
a9455408 | 181 | |
4f7eff10 JB |
182 | if (netns != wiphy_net(&rdev->wiphy)) |
183 | return ERR_PTR(-ENODEV); | |
184 | ||
185 | return rdev; | |
a9455408 JB |
186 | } |
187 | ||
188 | /* | |
189 | * This function returns a pointer to the driver | |
190 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
191 | * |
192 | * The result of this can be a PTR_ERR and hence must | |
193 | * be checked with IS_ERR() for errors. | |
194 | */ | |
195 | static struct cfg80211_registered_device * | |
4f7eff10 | 196 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 197 | { |
5fe231e8 | 198 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
199 | } |
200 | ||
55682965 | 201 | /* policy for the attributes */ |
8cd4d456 | 202 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
203 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
204 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 205 | .len = 20-1 }, |
31888487 | 206 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 207 | |
72bdcf34 | 208 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 209 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
210 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
211 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
212 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
213 | ||
b9a5f8ca JM |
214 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
215 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
216 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
217 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 218 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 219 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
220 | |
221 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
223 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 224 | |
e007b857 EP |
225 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
226 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 227 | |
b9454e83 | 228 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
229 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
230 | .len = WLAN_MAX_KEY_LEN }, | |
231 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
232 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 234 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 235 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
236 | |
237 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
238 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
239 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
240 | .len = IEEE80211_MAX_DATA_LEN }, | |
241 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
242 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
243 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
244 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
245 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
246 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
247 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 248 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 249 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 250 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 251 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 252 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 253 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 254 | |
b2e1b302 LR |
255 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
256 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
257 | ||
9f1ba906 JM |
258 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
259 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
260 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
261 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
262 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 263 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 264 | |
24bdd9f4 | 265 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 266 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 267 | |
6c739419 | 268 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
269 | |
270 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
271 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
272 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
273 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
274 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
275 | |
276 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
277 | .len = IEEE80211_MAX_SSID_LEN }, | |
278 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
279 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 280 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 281 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 282 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
283 | [NL80211_ATTR_STA_FLAGS2] = { |
284 | .len = sizeof(struct nl80211_sta_flag_update), | |
285 | }, | |
3f77316c | 286 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
287 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
288 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
289 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
290 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
291 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 292 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 293 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
294 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
295 | .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 }, |
e39e5b5e | 346 | [NL80211_ATTR_SAE_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 }, | |
77765eaf VT |
351 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
352 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
353 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
354 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 355 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
356 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
357 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
358 | .len = NL80211_VHT_CAPABILITY_LEN, | |
359 | }, | |
355199e0 JM |
360 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
361 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
362 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 363 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
364 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
365 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
366 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
367 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
368 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
369 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
370 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 371 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 372 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
373 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
374 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
375 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
376 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
377 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
378 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
379 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 380 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 381 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 382 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 383 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
384 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
385 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
386 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 387 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 388 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 389 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 390 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 391 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
05050753 | 392 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
34d50519 | 393 | [NL80211_ATTR_PBSS] = { .type = NLA_FLAG }, |
38de03d2 | 394 | [NL80211_ATTR_BSS_SELECT] = { .type = NLA_NESTED }, |
17b94247 | 395 | [NL80211_ATTR_STA_SUPPORT_P2P_PS] = { .type = NLA_U8 }, |
c6e6a0c8 AE |
396 | [NL80211_ATTR_MU_MIMO_GROUP_DATA] = { |
397 | .len = VHT_MUMIMO_GROUPS_DATA_LEN | |
398 | }, | |
399 | [NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR] = { .len = ETH_ALEN }, | |
cb3b7d87 AB |
400 | [NL80211_ATTR_NAN_MASTER_PREF] = { .type = NLA_U8 }, |
401 | [NL80211_ATTR_NAN_DUAL] = { .type = NLA_U8 }, | |
a442b761 | 402 | [NL80211_ATTR_NAN_FUNC] = { .type = NLA_NESTED }, |
55682965 JB |
403 | }; |
404 | ||
e31b8213 | 405 | /* policy for the key attributes */ |
b54452b0 | 406 | static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = { |
fffd0934 | 407 | [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN }, |
b9454e83 JB |
408 | [NL80211_KEY_IDX] = { .type = NLA_U8 }, |
409 | [NL80211_KEY_CIPHER] = { .type = NLA_U32 }, | |
81962267 | 410 | [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
b9454e83 JB |
411 | [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG }, |
412 | [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG }, | |
e31b8213 | 413 | [NL80211_KEY_TYPE] = { .type = NLA_U32 }, |
dbd2fd65 JB |
414 | [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
415 | }; | |
416 | ||
417 | /* policy for the key default flags */ | |
418 | static const struct nla_policy | |
419 | nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = { | |
420 | [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG }, | |
421 | [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG }, | |
b9454e83 JB |
422 | }; |
423 | ||
ff1b6e69 JB |
424 | /* policy for WoWLAN attributes */ |
425 | static const struct nla_policy | |
426 | nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = { | |
427 | [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG }, | |
428 | [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG }, | |
429 | [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG }, | |
430 | [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED }, | |
77dbbb13 JB |
431 | [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG }, |
432 | [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG }, | |
433 | [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG }, | |
434 | [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG }, | |
2a0e047e | 435 | [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED }, |
8cd4d456 | 436 | [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED }, |
2a0e047e JB |
437 | }; |
438 | ||
439 | static const struct nla_policy | |
440 | nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = { | |
441 | [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 }, | |
442 | [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 }, | |
443 | [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN }, | |
444 | [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 }, | |
445 | [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 }, | |
446 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 }, | |
447 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = { | |
448 | .len = sizeof(struct nl80211_wowlan_tcp_data_seq) | |
449 | }, | |
450 | [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = { | |
451 | .len = sizeof(struct nl80211_wowlan_tcp_data_token) | |
452 | }, | |
453 | [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 }, | |
454 | [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 }, | |
455 | [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 }, | |
ff1b6e69 JB |
456 | }; |
457 | ||
be29b99a AK |
458 | /* policy for coalesce rule attributes */ |
459 | static const struct nla_policy | |
460 | nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = { | |
461 | [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 }, | |
462 | [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 }, | |
463 | [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED }, | |
464 | }; | |
465 | ||
e5497d76 JB |
466 | /* policy for GTK rekey offload attributes */ |
467 | static const struct nla_policy | |
468 | nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = { | |
469 | [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN }, | |
470 | [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN }, | |
471 | [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN }, | |
472 | }; | |
473 | ||
a1f1c21c LC |
474 | static const struct nla_policy |
475 | nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = { | |
4a4ab0d7 | 476 | [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY, |
a1f1c21c | 477 | .len = IEEE80211_MAX_SSID_LEN }, |
88e920b4 | 478 | [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 }, |
a1f1c21c LC |
479 | }; |
480 | ||
3b06d277 AS |
481 | static const struct nla_policy |
482 | nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = { | |
483 | [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 }, | |
484 | [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 }, | |
485 | }; | |
486 | ||
38de03d2 AS |
487 | static const struct nla_policy |
488 | nl80211_bss_select_policy[NL80211_BSS_SELECT_ATTR_MAX + 1] = { | |
489 | [NL80211_BSS_SELECT_ATTR_RSSI] = { .type = NLA_FLAG }, | |
490 | [NL80211_BSS_SELECT_ATTR_BAND_PREF] = { .type = NLA_U32 }, | |
491 | [NL80211_BSS_SELECT_ATTR_RSSI_ADJUST] = { | |
492 | .len = sizeof(struct nl80211_bss_select_rssi_adjust) | |
493 | }, | |
494 | }; | |
495 | ||
a442b761 AB |
496 | /* policy for NAN function attributes */ |
497 | static const struct nla_policy | |
498 | nl80211_nan_func_policy[NL80211_NAN_FUNC_ATTR_MAX + 1] = { | |
499 | [NL80211_NAN_FUNC_TYPE] = { .type = NLA_U8 }, | |
500 | [NL80211_NAN_FUNC_SERVICE_ID] = { .type = NLA_BINARY, | |
501 | .len = NL80211_NAN_FUNC_SERVICE_ID_LEN }, | |
502 | [NL80211_NAN_FUNC_PUBLISH_TYPE] = { .type = NLA_U8 }, | |
503 | [NL80211_NAN_FUNC_PUBLISH_BCAST] = { .type = NLA_FLAG }, | |
504 | [NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE] = { .type = NLA_FLAG }, | |
505 | [NL80211_NAN_FUNC_FOLLOW_UP_ID] = { .type = NLA_U8 }, | |
506 | [NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID] = { .type = NLA_U8 }, | |
507 | [NL80211_NAN_FUNC_FOLLOW_UP_DEST] = { .len = ETH_ALEN }, | |
508 | [NL80211_NAN_FUNC_CLOSE_RANGE] = { .type = NLA_FLAG }, | |
509 | [NL80211_NAN_FUNC_TTL] = { .type = NLA_U32 }, | |
510 | [NL80211_NAN_FUNC_SERVICE_INFO] = { .type = NLA_BINARY, | |
511 | .len = NL80211_NAN_FUNC_SERVICE_SPEC_INFO_MAX_LEN }, | |
512 | [NL80211_NAN_FUNC_SRF] = { .type = NLA_NESTED }, | |
513 | [NL80211_NAN_FUNC_RX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
514 | [NL80211_NAN_FUNC_TX_MATCH_FILTER] = { .type = NLA_NESTED }, | |
515 | [NL80211_NAN_FUNC_INSTANCE_ID] = { .type = NLA_U8 }, | |
516 | [NL80211_NAN_FUNC_TERM_REASON] = { .type = NLA_U8 }, | |
517 | }; | |
518 | ||
519 | /* policy for Service Response Filter attributes */ | |
520 | static const struct nla_policy | |
521 | nl80211_nan_srf_policy[NL80211_NAN_SRF_ATTR_MAX + 1] = { | |
522 | [NL80211_NAN_SRF_INCLUDE] = { .type = NLA_FLAG }, | |
523 | [NL80211_NAN_SRF_BF] = { .type = NLA_BINARY, | |
524 | .len = NL80211_NAN_FUNC_SRF_MAX_LEN }, | |
525 | [NL80211_NAN_SRF_BF_IDX] = { .type = NLA_U8 }, | |
526 | [NL80211_NAN_SRF_MAC_ADDRS] = { .type = NLA_NESTED }, | |
527 | }; | |
528 | ||
97990a06 JB |
529 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
530 | struct netlink_callback *cb, | |
531 | struct cfg80211_registered_device **rdev, | |
532 | struct wireless_dev **wdev) | |
a043897a | 533 | { |
97990a06 | 534 | int err; |
a043897a | 535 | |
97990a06 | 536 | rtnl_lock(); |
a043897a | 537 | |
97990a06 JB |
538 | if (!cb->args[0]) { |
539 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
c90c39da JB |
540 | genl_family_attrbuf(&nl80211_fam), |
541 | nl80211_fam.maxattr, nl80211_policy); | |
97990a06 JB |
542 | if (err) |
543 | goto out_unlock; | |
67748893 | 544 | |
c90c39da JB |
545 | *wdev = __cfg80211_wdev_from_attrs( |
546 | sock_net(skb->sk), | |
547 | genl_family_attrbuf(&nl80211_fam)); | |
97990a06 JB |
548 | if (IS_ERR(*wdev)) { |
549 | err = PTR_ERR(*wdev); | |
550 | goto out_unlock; | |
551 | } | |
f26cbf40 | 552 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
553 | /* 0 is the first index - add 1 to parse only once */ |
554 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
555 | cb->args[1] = (*wdev)->identifier; |
556 | } else { | |
c319d50b JB |
557 | /* subtract the 1 again here */ |
558 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 559 | struct wireless_dev *tmp; |
67748893 | 560 | |
97990a06 JB |
561 | if (!wiphy) { |
562 | err = -ENODEV; | |
563 | goto out_unlock; | |
564 | } | |
f26cbf40 | 565 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 566 | *wdev = NULL; |
67748893 | 567 | |
53873f13 | 568 | list_for_each_entry(tmp, &(*rdev)->wiphy.wdev_list, list) { |
97990a06 JB |
569 | if (tmp->identifier == cb->args[1]) { |
570 | *wdev = tmp; | |
571 | break; | |
572 | } | |
573 | } | |
67748893 | 574 | |
97990a06 JB |
575 | if (!*wdev) { |
576 | err = -ENODEV; | |
577 | goto out_unlock; | |
578 | } | |
67748893 JB |
579 | } |
580 | ||
67748893 | 581 | return 0; |
97990a06 | 582 | out_unlock: |
67748893 JB |
583 | rtnl_unlock(); |
584 | return err; | |
585 | } | |
586 | ||
97990a06 | 587 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 588 | { |
67748893 JB |
589 | rtnl_unlock(); |
590 | } | |
591 | ||
f4a11bb0 JB |
592 | /* IE validation */ |
593 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
594 | { | |
595 | const u8 *pos; | |
596 | int len; | |
597 | ||
598 | if (!attr) | |
599 | return true; | |
600 | ||
601 | pos = nla_data(attr); | |
602 | len = nla_len(attr); | |
603 | ||
604 | while (len) { | |
605 | u8 elemlen; | |
606 | ||
607 | if (len < 2) | |
608 | return false; | |
609 | len -= 2; | |
610 | ||
611 | elemlen = pos[1]; | |
612 | if (elemlen > len) | |
613 | return false; | |
614 | ||
615 | len -= elemlen; | |
616 | pos += 2 + elemlen; | |
617 | } | |
618 | ||
619 | return true; | |
620 | } | |
621 | ||
55682965 | 622 | /* message building helper */ |
15e47304 | 623 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
624 | int flags, u8 cmd) |
625 | { | |
626 | /* since there is no private header just add the generic one */ | |
15e47304 | 627 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
628 | } |
629 | ||
5dab3b8a | 630 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
631 | struct ieee80211_channel *chan, |
632 | bool large) | |
5dab3b8a | 633 | { |
ea077c1c RL |
634 | /* Some channels must be completely excluded from the |
635 | * list to protect old user-space tools from breaking | |
636 | */ | |
637 | if (!large && chan->flags & | |
638 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
639 | return 0; | |
640 | ||
9360ffd1 DM |
641 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
642 | chan->center_freq)) | |
643 | goto nla_put_failure; | |
5dab3b8a | 644 | |
9360ffd1 DM |
645 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
646 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
647 | goto nla_put_failure; | |
8fe02e16 LR |
648 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
649 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
650 | goto nla_put_failure; | |
651 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
652 | goto nla_put_failure; | |
653 | } | |
cdc89b97 JB |
654 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
655 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
656 | goto nla_put_failure; | |
657 | if (large) { | |
658 | u32 time; | |
659 | ||
660 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
661 | ||
662 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
663 | chan->dfs_state)) | |
664 | goto nla_put_failure; | |
665 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
666 | time)) | |
667 | goto nla_put_failure; | |
089027e5 JD |
668 | if (nla_put_u32(msg, |
669 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
670 | chan->dfs_cac_ms)) | |
671 | goto nla_put_failure; | |
cdc89b97 JB |
672 | } |
673 | } | |
5dab3b8a | 674 | |
fe1abafd JB |
675 | if (large) { |
676 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
677 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
678 | goto nla_put_failure; | |
679 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
680 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
681 | goto nla_put_failure; | |
682 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
683 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
684 | goto nla_put_failure; | |
685 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
686 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
687 | goto nla_put_failure; | |
570dbde1 DS |
688 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
689 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
690 | goto nla_put_failure; | |
06f207fc AN |
691 | if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) && |
692 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT)) | |
570dbde1 | 693 | goto nla_put_failure; |
ea077c1c RL |
694 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
695 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
696 | goto nla_put_failure; | |
697 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
698 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
699 | goto nla_put_failure; | |
fe1abafd JB |
700 | } |
701 | ||
9360ffd1 DM |
702 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
703 | DBM_TO_MBM(chan->max_power))) | |
704 | goto nla_put_failure; | |
5dab3b8a LR |
705 | |
706 | return 0; | |
707 | ||
708 | nla_put_failure: | |
709 | return -ENOBUFS; | |
710 | } | |
711 | ||
55682965 JB |
712 | /* netlink command implementations */ |
713 | ||
b9454e83 JB |
714 | struct key_parse { |
715 | struct key_params p; | |
716 | int idx; | |
e31b8213 | 717 | int type; |
b9454e83 | 718 | bool def, defmgmt; |
dbd2fd65 | 719 | bool def_uni, def_multi; |
b9454e83 JB |
720 | }; |
721 | ||
722 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
723 | { | |
724 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
725 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
726 | nl80211_key_policy); | |
727 | if (err) | |
728 | return err; | |
729 | ||
730 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
731 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
732 | ||
dbd2fd65 JB |
733 | if (k->def) { |
734 | k->def_uni = true; | |
735 | k->def_multi = true; | |
736 | } | |
737 | if (k->defmgmt) | |
738 | k->def_multi = true; | |
739 | ||
b9454e83 JB |
740 | if (tb[NL80211_KEY_IDX]) |
741 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
742 | ||
743 | if (tb[NL80211_KEY_DATA]) { | |
744 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
745 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
746 | } | |
747 | ||
748 | if (tb[NL80211_KEY_SEQ]) { | |
749 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
750 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
751 | } | |
752 | ||
753 | if (tb[NL80211_KEY_CIPHER]) | |
754 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
755 | ||
e31b8213 JB |
756 | if (tb[NL80211_KEY_TYPE]) { |
757 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
758 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
759 | return -EINVAL; | |
760 | } | |
761 | ||
dbd2fd65 JB |
762 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
763 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
7a087e74 | 764 | |
2da8f419 JB |
765 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
766 | tb[NL80211_KEY_DEFAULT_TYPES], | |
767 | nl80211_key_default_policy); | |
dbd2fd65 JB |
768 | if (err) |
769 | return err; | |
770 | ||
771 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
772 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
773 | } | |
774 | ||
b9454e83 JB |
775 | return 0; |
776 | } | |
777 | ||
778 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
779 | { | |
780 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
781 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
782 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
783 | } | |
784 | ||
785 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
786 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
787 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
788 | } | |
789 | ||
790 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
791 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
792 | ||
793 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
794 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
795 | ||
796 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
797 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
798 | ||
dbd2fd65 JB |
799 | if (k->def) { |
800 | k->def_uni = true; | |
801 | k->def_multi = true; | |
802 | } | |
803 | if (k->defmgmt) | |
804 | k->def_multi = true; | |
805 | ||
e31b8213 JB |
806 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
807 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
808 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
809 | return -EINVAL; | |
810 | } | |
811 | ||
dbd2fd65 JB |
812 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
813 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
814 | int err = nla_parse_nested( | |
815 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
816 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
817 | nl80211_key_default_policy); | |
818 | if (err) | |
819 | return err; | |
820 | ||
821 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
822 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
823 | } | |
824 | ||
b9454e83 JB |
825 | return 0; |
826 | } | |
827 | ||
828 | static int nl80211_parse_key(struct genl_info *info, struct key_parse *k) | |
829 | { | |
830 | int err; | |
831 | ||
832 | memset(k, 0, sizeof(*k)); | |
833 | k->idx = -1; | |
e31b8213 | 834 | k->type = -1; |
b9454e83 JB |
835 | |
836 | if (info->attrs[NL80211_ATTR_KEY]) | |
837 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
838 | else | |
839 | err = nl80211_parse_key_old(info, k); | |
840 | ||
841 | if (err) | |
842 | return err; | |
843 | ||
844 | if (k->def && k->defmgmt) | |
845 | return -EINVAL; | |
846 | ||
dbd2fd65 JB |
847 | if (k->defmgmt) { |
848 | if (k->def_uni || !k->def_multi) | |
849 | return -EINVAL; | |
850 | } | |
851 | ||
b9454e83 JB |
852 | if (k->idx != -1) { |
853 | if (k->defmgmt) { | |
854 | if (k->idx < 4 || k->idx > 5) | |
855 | return -EINVAL; | |
856 | } else if (k->def) { | |
857 | if (k->idx < 0 || k->idx > 3) | |
858 | return -EINVAL; | |
859 | } else { | |
860 | if (k->idx < 0 || k->idx > 5) | |
861 | return -EINVAL; | |
862 | } | |
863 | } | |
864 | ||
865 | return 0; | |
866 | } | |
867 | ||
fffd0934 JB |
868 | static struct cfg80211_cached_keys * |
869 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 870 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
871 | { |
872 | struct key_parse parse; | |
873 | struct nlattr *key; | |
874 | struct cfg80211_cached_keys *result; | |
875 | int rem, err, def = 0; | |
f1c1f17a JB |
876 | bool have_key = false; |
877 | ||
878 | nla_for_each_nested(key, keys, rem) { | |
879 | have_key = true; | |
880 | break; | |
881 | } | |
882 | ||
883 | if (!have_key) | |
884 | return NULL; | |
fffd0934 JB |
885 | |
886 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
887 | if (!result) | |
888 | return ERR_PTR(-ENOMEM); | |
889 | ||
890 | result->def = -1; | |
fffd0934 JB |
891 | |
892 | nla_for_each_nested(key, keys, rem) { | |
893 | memset(&parse, 0, sizeof(parse)); | |
894 | parse.idx = -1; | |
895 | ||
896 | err = nl80211_parse_key_new(key, &parse); | |
897 | if (err) | |
898 | goto error; | |
899 | err = -EINVAL; | |
900 | if (!parse.p.key) | |
901 | goto error; | |
42ee231c | 902 | if (parse.idx < 0 || parse.idx > 3) |
fffd0934 JB |
903 | goto error; |
904 | if (parse.def) { | |
905 | if (def) | |
906 | goto error; | |
907 | def = 1; | |
908 | result->def = parse.idx; | |
dbd2fd65 JB |
909 | if (!parse.def_uni || !parse.def_multi) |
910 | goto error; | |
fffd0934 JB |
911 | } else if (parse.defmgmt) |
912 | goto error; | |
913 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 914 | parse.idx, false, NULL); |
fffd0934 JB |
915 | if (err) |
916 | goto error; | |
386b1f27 JB |
917 | if (parse.p.cipher != WLAN_CIPHER_SUITE_WEP40 && |
918 | parse.p.cipher != WLAN_CIPHER_SUITE_WEP104) { | |
919 | err = -EINVAL; | |
920 | goto error; | |
921 | } | |
fffd0934 JB |
922 | result->params[parse.idx].cipher = parse.p.cipher; |
923 | result->params[parse.idx].key_len = parse.p.key_len; | |
924 | result->params[parse.idx].key = result->data[parse.idx]; | |
925 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee | 926 | |
386b1f27 JB |
927 | /* must be WEP key if we got here */ |
928 | if (no_ht) | |
929 | *no_ht = true; | |
fffd0934 JB |
930 | } |
931 | ||
f1c1f17a JB |
932 | if (result->def < 0) { |
933 | err = -EINVAL; | |
934 | goto error; | |
935 | } | |
936 | ||
fffd0934 JB |
937 | return result; |
938 | error: | |
939 | kfree(result); | |
940 | return ERR_PTR(err); | |
941 | } | |
942 | ||
943 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
944 | { | |
945 | ASSERT_WDEV_LOCK(wdev); | |
946 | ||
fffd0934 JB |
947 | switch (wdev->iftype) { |
948 | case NL80211_IFTYPE_AP: | |
949 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 950 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 951 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
952 | break; |
953 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 954 | case NL80211_IFTYPE_STATION: |
074ac8df | 955 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 956 | if (!wdev->current_bss) |
fffd0934 JB |
957 | return -ENOLINK; |
958 | break; | |
de4fcbad | 959 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 960 | case NL80211_IFTYPE_OCB: |
de4fcbad | 961 | case NL80211_IFTYPE_MONITOR: |
cb3b7d87 | 962 | case NL80211_IFTYPE_NAN: |
de4fcbad JB |
963 | case NL80211_IFTYPE_P2P_DEVICE: |
964 | case NL80211_IFTYPE_WDS: | |
965 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
966 | return -EINVAL; |
967 | } | |
968 | ||
969 | return 0; | |
970 | } | |
971 | ||
664834de JM |
972 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
973 | struct nlattr *tb) | |
974 | { | |
975 | struct ieee80211_channel *chan; | |
976 | ||
977 | if (tb == NULL) | |
978 | return NULL; | |
979 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
980 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
981 | return NULL; | |
982 | return chan; | |
983 | } | |
984 | ||
7527a782 JB |
985 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
986 | { | |
987 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
988 | int i; | |
989 | ||
990 | if (!nl_modes) | |
991 | goto nla_put_failure; | |
992 | ||
993 | i = 0; | |
994 | while (ifmodes) { | |
9360ffd1 DM |
995 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
996 | goto nla_put_failure; | |
7527a782 JB |
997 | ifmodes >>= 1; |
998 | i++; | |
999 | } | |
1000 | ||
1001 | nla_nest_end(msg, nl_modes); | |
1002 | return 0; | |
1003 | ||
1004 | nla_put_failure: | |
1005 | return -ENOBUFS; | |
1006 | } | |
1007 | ||
1008 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
1009 | struct sk_buff *msg, |
1010 | bool large) | |
7527a782 JB |
1011 | { |
1012 | struct nlattr *nl_combis; | |
1013 | int i, j; | |
1014 | ||
1015 | nl_combis = nla_nest_start(msg, | |
1016 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
1017 | if (!nl_combis) | |
1018 | goto nla_put_failure; | |
1019 | ||
1020 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
1021 | const struct ieee80211_iface_combination *c; | |
1022 | struct nlattr *nl_combi, *nl_limits; | |
1023 | ||
1024 | c = &wiphy->iface_combinations[i]; | |
1025 | ||
1026 | nl_combi = nla_nest_start(msg, i + 1); | |
1027 | if (!nl_combi) | |
1028 | goto nla_put_failure; | |
1029 | ||
1030 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
1031 | if (!nl_limits) | |
1032 | goto nla_put_failure; | |
1033 | ||
1034 | for (j = 0; j < c->n_limits; j++) { | |
1035 | struct nlattr *nl_limit; | |
1036 | ||
1037 | nl_limit = nla_nest_start(msg, j + 1); | |
1038 | if (!nl_limit) | |
1039 | goto nla_put_failure; | |
9360ffd1 DM |
1040 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
1041 | c->limits[j].max)) | |
1042 | goto nla_put_failure; | |
7527a782 JB |
1043 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
1044 | c->limits[j].types)) | |
1045 | goto nla_put_failure; | |
1046 | nla_nest_end(msg, nl_limit); | |
1047 | } | |
1048 | ||
1049 | nla_nest_end(msg, nl_limits); | |
1050 | ||
9360ffd1 DM |
1051 | if (c->beacon_int_infra_match && |
1052 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
1053 | goto nla_put_failure; | |
1054 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
1055 | c->num_different_channels) || | |
1056 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
1057 | c->max_interfaces)) | |
1058 | goto nla_put_failure; | |
cdc89b97 | 1059 | if (large && |
8c48b50a FF |
1060 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
1061 | c->radar_detect_widths) || | |
1062 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
1063 | c->radar_detect_regions))) | |
cdc89b97 | 1064 | goto nla_put_failure; |
7527a782 JB |
1065 | |
1066 | nla_nest_end(msg, nl_combi); | |
1067 | } | |
1068 | ||
1069 | nla_nest_end(msg, nl_combis); | |
1070 | ||
1071 | return 0; | |
1072 | nla_put_failure: | |
1073 | return -ENOBUFS; | |
1074 | } | |
1075 | ||
3713b4e3 | 1076 | #ifdef CONFIG_PM |
b56cf720 JB |
1077 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1078 | struct sk_buff *msg) | |
1079 | { | |
964dc9e2 | 1080 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1081 | struct nlattr *nl_tcp; |
1082 | ||
1083 | if (!tcp) | |
1084 | return 0; | |
1085 | ||
1086 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1087 | if (!nl_tcp) | |
1088 | return -ENOBUFS; | |
1089 | ||
1090 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1091 | tcp->data_payload_max)) | |
1092 | return -ENOBUFS; | |
1093 | ||
1094 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1095 | tcp->data_payload_max)) | |
1096 | return -ENOBUFS; | |
1097 | ||
1098 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1099 | return -ENOBUFS; | |
1100 | ||
1101 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1102 | sizeof(*tcp->tok), tcp->tok)) | |
1103 | return -ENOBUFS; | |
1104 | ||
1105 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1106 | tcp->data_interval_max)) | |
1107 | return -ENOBUFS; | |
1108 | ||
1109 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1110 | tcp->wake_payload_max)) | |
1111 | return -ENOBUFS; | |
1112 | ||
1113 | nla_nest_end(msg, nl_tcp); | |
1114 | return 0; | |
1115 | } | |
1116 | ||
3713b4e3 | 1117 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1118 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1119 | bool large) |
55682965 | 1120 | { |
3713b4e3 | 1121 | struct nlattr *nl_wowlan; |
55682965 | 1122 | |
1b8ec87a | 1123 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1124 | return 0; |
55682965 | 1125 | |
3713b4e3 JB |
1126 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1127 | if (!nl_wowlan) | |
1128 | return -ENOBUFS; | |
9360ffd1 | 1129 | |
1b8ec87a | 1130 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1131 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1132 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1133 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1134 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1135 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1136 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1137 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1138 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1139 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1140 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1141 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1142 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1143 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1144 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1145 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1146 | return -ENOBUFS; | |
9360ffd1 | 1147 | |
1b8ec87a | 1148 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1149 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1150 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1151 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1152 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1153 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1154 | }; |
9360ffd1 | 1155 | |
3713b4e3 JB |
1156 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1157 | sizeof(pat), &pat)) | |
1158 | return -ENOBUFS; | |
1159 | } | |
9360ffd1 | 1160 | |
75453ccb LC |
1161 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1162 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1163 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1164 | return -ENOBUFS; | |
1165 | ||
1b8ec87a | 1166 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1167 | return -ENOBUFS; |
1168 | ||
3713b4e3 | 1169 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1170 | |
3713b4e3 JB |
1171 | return 0; |
1172 | } | |
1173 | #endif | |
9360ffd1 | 1174 | |
be29b99a | 1175 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1176 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1177 | { |
1178 | struct nl80211_coalesce_rule_support rule; | |
1179 | ||
1b8ec87a | 1180 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1181 | return 0; |
1182 | ||
1b8ec87a ZG |
1183 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1184 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1185 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1186 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1187 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1188 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1189 | |
1190 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1191 | return -ENOBUFS; | |
1192 | ||
1193 | return 0; | |
1194 | } | |
1195 | ||
3713b4e3 JB |
1196 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1197 | struct ieee80211_supported_band *sband) | |
1198 | { | |
1199 | struct nlattr *nl_rates, *nl_rate; | |
1200 | struct ieee80211_rate *rate; | |
1201 | int i; | |
87bbbe22 | 1202 | |
3713b4e3 JB |
1203 | /* add HT info */ |
1204 | if (sband->ht_cap.ht_supported && | |
1205 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1206 | sizeof(sband->ht_cap.mcs), | |
1207 | &sband->ht_cap.mcs) || | |
1208 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1209 | sband->ht_cap.cap) || | |
1210 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1211 | sband->ht_cap.ampdu_factor) || | |
1212 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1213 | sband->ht_cap.ampdu_density))) | |
1214 | return -ENOBUFS; | |
afe0cbf8 | 1215 | |
3713b4e3 JB |
1216 | /* add VHT info */ |
1217 | if (sband->vht_cap.vht_supported && | |
1218 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1219 | sizeof(sband->vht_cap.vht_mcs), | |
1220 | &sband->vht_cap.vht_mcs) || | |
1221 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1222 | sband->vht_cap.cap))) | |
1223 | return -ENOBUFS; | |
f59ac048 | 1224 | |
3713b4e3 JB |
1225 | /* add bitrates */ |
1226 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1227 | if (!nl_rates) | |
1228 | return -ENOBUFS; | |
ee688b00 | 1229 | |
3713b4e3 JB |
1230 | for (i = 0; i < sband->n_bitrates; i++) { |
1231 | nl_rate = nla_nest_start(msg, i); | |
1232 | if (!nl_rate) | |
1233 | return -ENOBUFS; | |
ee688b00 | 1234 | |
3713b4e3 JB |
1235 | rate = &sband->bitrates[i]; |
1236 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1237 | rate->bitrate)) | |
1238 | return -ENOBUFS; | |
1239 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1240 | nla_put_flag(msg, | |
1241 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1242 | return -ENOBUFS; | |
ee688b00 | 1243 | |
3713b4e3 JB |
1244 | nla_nest_end(msg, nl_rate); |
1245 | } | |
d51626df | 1246 | |
3713b4e3 | 1247 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1248 | |
3713b4e3 JB |
1249 | return 0; |
1250 | } | |
ee688b00 | 1251 | |
3713b4e3 JB |
1252 | static int |
1253 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1254 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1255 | { | |
1256 | u16 stypes; | |
1257 | struct nlattr *nl_ftypes, *nl_ifs; | |
1258 | enum nl80211_iftype ift; | |
1259 | int i; | |
ee688b00 | 1260 | |
3713b4e3 JB |
1261 | if (!mgmt_stypes) |
1262 | return 0; | |
5dab3b8a | 1263 | |
3713b4e3 JB |
1264 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1265 | if (!nl_ifs) | |
1266 | return -ENOBUFS; | |
e2f367f2 | 1267 | |
3713b4e3 JB |
1268 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1269 | nl_ftypes = nla_nest_start(msg, ift); | |
1270 | if (!nl_ftypes) | |
1271 | return -ENOBUFS; | |
1272 | i = 0; | |
1273 | stypes = mgmt_stypes[ift].tx; | |
1274 | while (stypes) { | |
1275 | if ((stypes & 1) && | |
1276 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1277 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1278 | return -ENOBUFS; | |
1279 | stypes >>= 1; | |
1280 | i++; | |
ee688b00 | 1281 | } |
3713b4e3 JB |
1282 | nla_nest_end(msg, nl_ftypes); |
1283 | } | |
ee688b00 | 1284 | |
3713b4e3 | 1285 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1286 | |
3713b4e3 JB |
1287 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1288 | if (!nl_ifs) | |
1289 | return -ENOBUFS; | |
ee688b00 | 1290 | |
3713b4e3 JB |
1291 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1292 | nl_ftypes = nla_nest_start(msg, ift); | |
1293 | if (!nl_ftypes) | |
1294 | return -ENOBUFS; | |
1295 | i = 0; | |
1296 | stypes = mgmt_stypes[ift].rx; | |
1297 | while (stypes) { | |
1298 | if ((stypes & 1) && | |
1299 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1300 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1301 | return -ENOBUFS; | |
1302 | stypes >>= 1; | |
1303 | i++; | |
1304 | } | |
1305 | nla_nest_end(msg, nl_ftypes); | |
1306 | } | |
1307 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1308 | |
3713b4e3 JB |
1309 | return 0; |
1310 | } | |
ee688b00 | 1311 | |
86e8cf98 JB |
1312 | struct nl80211_dump_wiphy_state { |
1313 | s64 filter_wiphy; | |
1314 | long start; | |
019ae3a9 | 1315 | long split_start, band_start, chan_start, capa_start; |
86e8cf98 JB |
1316 | bool split; |
1317 | }; | |
1318 | ||
1b8ec87a | 1319 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1320 | enum nl80211_commands cmd, |
3713b4e3 | 1321 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1322 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1323 | { |
1324 | void *hdr; | |
1325 | struct nlattr *nl_bands, *nl_band; | |
1326 | struct nlattr *nl_freqs, *nl_freq; | |
1327 | struct nlattr *nl_cmds; | |
57fbcce3 | 1328 | enum nl80211_band band; |
3713b4e3 JB |
1329 | struct ieee80211_channel *chan; |
1330 | int i; | |
1331 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1332 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1333 | u32 features; |
ee688b00 | 1334 | |
3bb20556 | 1335 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1336 | if (!hdr) |
1337 | return -ENOBUFS; | |
ee688b00 | 1338 | |
86e8cf98 JB |
1339 | if (WARN_ON(!state)) |
1340 | return -EINVAL; | |
ee688b00 | 1341 | |
1b8ec87a | 1342 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1343 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1344 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1345 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1346 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1347 | goto nla_put_failure; |
1348 | ||
3bb20556 JB |
1349 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1350 | goto finish; | |
1351 | ||
86e8cf98 | 1352 | switch (state->split_start) { |
3713b4e3 JB |
1353 | case 0: |
1354 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1355 | rdev->wiphy.retry_short) || |
3713b4e3 | 1356 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1357 | rdev->wiphy.retry_long) || |
3713b4e3 | 1358 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1359 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1360 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1361 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1362 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1363 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1364 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1365 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1366 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1367 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1368 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1369 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1370 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1371 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1372 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
3b06d277 AS |
1373 | rdev->wiphy.max_match_sets) || |
1374 | nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS, | |
1375 | rdev->wiphy.max_sched_scan_plans) || | |
1376 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL, | |
1377 | rdev->wiphy.max_sched_scan_plan_interval) || | |
1378 | nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS, | |
1379 | rdev->wiphy.max_sched_scan_plan_iterations)) | |
9360ffd1 | 1380 | goto nla_put_failure; |
3713b4e3 | 1381 | |
1b8ec87a | 1382 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1383 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1384 | goto nla_put_failure; |
1b8ec87a | 1385 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1386 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1387 | goto nla_put_failure; | |
1b8ec87a | 1388 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1389 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1390 | goto nla_put_failure; | |
1b8ec87a | 1391 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1392 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1393 | goto nla_put_failure; | |
1b8ec87a | 1394 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1395 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1396 | goto nla_put_failure; | |
1b8ec87a | 1397 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1398 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1399 | goto nla_put_failure; |
86e8cf98 JB |
1400 | state->split_start++; |
1401 | if (state->split) | |
3713b4e3 JB |
1402 | break; |
1403 | case 1: | |
1404 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1405 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1406 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1407 | goto nla_put_failure; |
4745fc09 | 1408 | |
3713b4e3 | 1409 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1410 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1411 | goto nla_put_failure; |
b23aa676 | 1412 | |
1b8ec87a | 1413 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1414 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1415 | goto nla_put_failure; |
b23aa676 | 1416 | |
3713b4e3 | 1417 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1418 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1419 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1420 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1421 | goto nla_put_failure; |
b23aa676 | 1422 | |
1b8ec87a | 1423 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1424 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1425 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1426 | goto nla_put_failure; |
8fdc621d | 1427 | |
1b8ec87a ZG |
1428 | if ((rdev->wiphy.available_antennas_tx || |
1429 | rdev->wiphy.available_antennas_rx) && | |
1430 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1431 | u32 tx_ant = 0, rx_ant = 0; |
1432 | int res; | |
7a087e74 | 1433 | |
1b8ec87a | 1434 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1435 | if (!res) { |
1436 | if (nla_put_u32(msg, | |
1437 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1438 | tx_ant) || | |
1439 | nla_put_u32(msg, | |
1440 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1441 | rx_ant)) | |
1442 | goto nla_put_failure; | |
1443 | } | |
1444 | } | |
a293911d | 1445 | |
86e8cf98 JB |
1446 | state->split_start++; |
1447 | if (state->split) | |
3713b4e3 JB |
1448 | break; |
1449 | case 2: | |
1450 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1451 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1452 | goto nla_put_failure; |
86e8cf98 JB |
1453 | state->split_start++; |
1454 | if (state->split) | |
3713b4e3 JB |
1455 | break; |
1456 | case 3: | |
1457 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1458 | if (!nl_bands) | |
1459 | goto nla_put_failure; | |
f7ca38df | 1460 | |
86e8cf98 | 1461 | for (band = state->band_start; |
57fbcce3 | 1462 | band < NUM_NL80211_BANDS; band++) { |
3713b4e3 | 1463 | struct ieee80211_supported_band *sband; |
2e161f78 | 1464 | |
1b8ec87a | 1465 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1466 | |
3713b4e3 JB |
1467 | if (!sband) |
1468 | continue; | |
1469 | ||
1470 | nl_band = nla_nest_start(msg, band); | |
1471 | if (!nl_band) | |
2e161f78 | 1472 | goto nla_put_failure; |
3713b4e3 | 1473 | |
86e8cf98 | 1474 | switch (state->chan_start) { |
3713b4e3 JB |
1475 | case 0: |
1476 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1477 | goto nla_put_failure; |
86e8cf98 JB |
1478 | state->chan_start++; |
1479 | if (state->split) | |
3713b4e3 JB |
1480 | break; |
1481 | default: | |
1482 | /* add frequencies */ | |
1483 | nl_freqs = nla_nest_start( | |
1484 | msg, NL80211_BAND_ATTR_FREQS); | |
1485 | if (!nl_freqs) | |
1486 | goto nla_put_failure; | |
1487 | ||
86e8cf98 | 1488 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1489 | i < sband->n_channels; |
1490 | i++) { | |
1491 | nl_freq = nla_nest_start(msg, i); | |
1492 | if (!nl_freq) | |
1493 | goto nla_put_failure; | |
1494 | ||
1495 | chan = &sband->channels[i]; | |
1496 | ||
86e8cf98 JB |
1497 | if (nl80211_msg_put_channel( |
1498 | msg, chan, | |
1499 | state->split)) | |
3713b4e3 JB |
1500 | goto nla_put_failure; |
1501 | ||
1502 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1503 | if (state->split) |
3713b4e3 JB |
1504 | break; |
1505 | } | |
1506 | if (i < sband->n_channels) | |
86e8cf98 | 1507 | state->chan_start = i + 2; |
3713b4e3 | 1508 | else |
86e8cf98 | 1509 | state->chan_start = 0; |
3713b4e3 JB |
1510 | nla_nest_end(msg, nl_freqs); |
1511 | } | |
1512 | ||
1513 | nla_nest_end(msg, nl_band); | |
1514 | ||
86e8cf98 | 1515 | if (state->split) { |
3713b4e3 | 1516 | /* start again here */ |
86e8cf98 | 1517 | if (state->chan_start) |
3713b4e3 JB |
1518 | band--; |
1519 | break; | |
2e161f78 | 1520 | } |
2e161f78 | 1521 | } |
3713b4e3 | 1522 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1523 | |
57fbcce3 | 1524 | if (band < NUM_NL80211_BANDS) |
86e8cf98 | 1525 | state->band_start = band + 1; |
3713b4e3 | 1526 | else |
86e8cf98 | 1527 | state->band_start = 0; |
74b70a4e | 1528 | |
3713b4e3 | 1529 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1530 | if (state->band_start == 0 && state->chan_start == 0) |
1531 | state->split_start++; | |
1532 | if (state->split) | |
3713b4e3 JB |
1533 | break; |
1534 | case 4: | |
1535 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1536 | if (!nl_cmds) | |
2e161f78 JB |
1537 | goto nla_put_failure; |
1538 | ||
3713b4e3 JB |
1539 | i = 0; |
1540 | #define CMD(op, n) \ | |
1541 | do { \ | |
1b8ec87a | 1542 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1543 | i++; \ |
1544 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1545 | goto nla_put_failure; \ | |
1546 | } \ | |
1547 | } while (0) | |
1548 | ||
1549 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1550 | CMD(change_virtual_intf, SET_INTERFACE); | |
1551 | CMD(add_key, NEW_KEY); | |
1552 | CMD(start_ap, START_AP); | |
1553 | CMD(add_station, NEW_STATION); | |
1554 | CMD(add_mpath, NEW_MPATH); | |
1555 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1556 | CMD(change_bss, SET_BSS); | |
1557 | CMD(auth, AUTHENTICATE); | |
1558 | CMD(assoc, ASSOCIATE); | |
1559 | CMD(deauth, DEAUTHENTICATE); | |
1560 | CMD(disassoc, DISASSOCIATE); | |
1561 | CMD(join_ibss, JOIN_IBSS); | |
1562 | CMD(join_mesh, JOIN_MESH); | |
1563 | CMD(set_pmksa, SET_PMKSA); | |
1564 | CMD(del_pmksa, DEL_PMKSA); | |
1565 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1566 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1567 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1568 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1569 | CMD(mgmt_tx, FRAME); | |
1570 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1571 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1572 | i++; |
1573 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1574 | goto nla_put_failure; |
2e161f78 | 1575 | } |
1b8ec87a ZG |
1576 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1577 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1578 | i++; |
1579 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1580 | goto nla_put_failure; | |
1581 | } | |
1582 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1583 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1584 | CMD(tdls_mgmt, TDLS_MGMT); |
1585 | CMD(tdls_oper, TDLS_OPER); | |
1586 | } | |
1b8ec87a | 1587 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1588 | CMD(sched_scan_start, START_SCHED_SCAN); |
1589 | CMD(probe_client, PROBE_CLIENT); | |
1590 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1591 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1592 | i++; |
1593 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1594 | goto nla_put_failure; | |
1595 | } | |
1596 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1597 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1598 | #ifdef CONFIG_NL80211_TESTMODE |
1599 | CMD(testmode_cmd, TESTMODE); | |
1600 | #endif | |
86e8cf98 | 1601 | if (state->split) { |
5de17984 AS |
1602 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1603 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1604 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1605 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1606 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1607 | if (rdev->wiphy.features & |
1608 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1609 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1610 | } |
02df00eb | 1611 | /* add into the if now */ |
3713b4e3 | 1612 | #undef CMD |
ff1b6e69 | 1613 | |
1b8ec87a | 1614 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1615 | i++; |
1616 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1617 | goto nla_put_failure; |
ff1b6e69 JB |
1618 | } |
1619 | ||
1b8ec87a | 1620 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1621 | i++; |
1622 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1623 | goto nla_put_failure; | |
1624 | } | |
1625 | ||
1626 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1627 | state->split_start++; |
1628 | if (state->split) | |
3713b4e3 JB |
1629 | break; |
1630 | case 5: | |
1b8ec87a ZG |
1631 | if (rdev->ops->remain_on_channel && |
1632 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1633 | nla_put_u32(msg, |
1634 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1635 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1636 | goto nla_put_failure; |
1637 | ||
1b8ec87a | 1638 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1639 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1640 | goto nla_put_failure; | |
1641 | ||
1642 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1643 | goto nla_put_failure; | |
86e8cf98 JB |
1644 | state->split_start++; |
1645 | if (state->split) | |
3713b4e3 JB |
1646 | break; |
1647 | case 6: | |
1648 | #ifdef CONFIG_PM | |
1b8ec87a | 1649 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1650 | goto nla_put_failure; |
86e8cf98 JB |
1651 | state->split_start++; |
1652 | if (state->split) | |
3713b4e3 JB |
1653 | break; |
1654 | #else | |
86e8cf98 | 1655 | state->split_start++; |
dfb89c56 | 1656 | #endif |
3713b4e3 JB |
1657 | case 7: |
1658 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1659 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1660 | goto nla_put_failure; |
ff1b6e69 | 1661 | |
1b8ec87a | 1662 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1663 | state->split)) |
3713b4e3 | 1664 | goto nla_put_failure; |
7527a782 | 1665 | |
86e8cf98 JB |
1666 | state->split_start++; |
1667 | if (state->split) | |
3713b4e3 JB |
1668 | break; |
1669 | case 8: | |
1b8ec87a | 1670 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1671 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1672 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1673 | goto nla_put_failure; |
7527a782 | 1674 | |
1b8ec87a | 1675 | features = rdev->wiphy.features; |
fe1abafd JB |
1676 | /* |
1677 | * We can only add the per-channel limit information if the | |
1678 | * dump is split, otherwise it makes it too big. Therefore | |
1679 | * only advertise it in that case. | |
1680 | */ | |
86e8cf98 | 1681 | if (state->split) |
fe1abafd JB |
1682 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1683 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1684 | goto nla_put_failure; |
562a7480 | 1685 | |
1b8ec87a | 1686 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1687 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1688 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1689 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1690 | goto nla_put_failure; |
1f074bd8 | 1691 | |
1b8ec87a ZG |
1692 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1693 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1694 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1695 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1696 | goto nla_put_failure; |
7e7c8926 | 1697 | |
3713b4e3 JB |
1698 | /* |
1699 | * Any information below this point is only available to | |
1700 | * applications that can deal with it being split. This | |
1701 | * helps ensure that newly added capabilities don't break | |
1702 | * older tools by overrunning their buffers. | |
1703 | * | |
1704 | * We still increment split_start so that in the split | |
1705 | * case we'll continue with more data in the next round, | |
1706 | * but break unconditionally so unsplit data stops here. | |
1707 | */ | |
86e8cf98 | 1708 | state->split_start++; |
3713b4e3 JB |
1709 | break; |
1710 | case 9: | |
1b8ec87a | 1711 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1712 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1713 | rdev->wiphy.extended_capabilities_len, |
1714 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1715 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1716 | rdev->wiphy.extended_capabilities_len, |
1717 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1718 | goto nla_put_failure; |
a50df0c4 | 1719 | |
1b8ec87a | 1720 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1721 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1722 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1723 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1724 | goto nla_put_failure; |
1725 | ||
be29b99a AK |
1726 | state->split_start++; |
1727 | break; | |
1728 | case 10: | |
1b8ec87a | 1729 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1730 | goto nla_put_failure; |
1731 | ||
1b8ec87a | 1732 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1733 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1734 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1735 | goto nla_put_failure; | |
b43504cf | 1736 | |
1b8ec87a | 1737 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1738 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1739 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1740 | goto nla_put_failure; |
1741 | ||
ad7e718c JB |
1742 | state->split_start++; |
1743 | break; | |
1744 | case 11: | |
1b8ec87a | 1745 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1746 | const struct nl80211_vendor_cmd_info *info; |
1747 | struct nlattr *nested; | |
1748 | ||
1749 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1750 | if (!nested) | |
1751 | goto nla_put_failure; | |
1752 | ||
1b8ec87a ZG |
1753 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1754 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1755 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1756 | goto nla_put_failure; | |
1757 | } | |
1758 | nla_nest_end(msg, nested); | |
1759 | } | |
1760 | ||
1b8ec87a | 1761 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1762 | const struct nl80211_vendor_cmd_info *info; |
1763 | struct nlattr *nested; | |
ad7e718c | 1764 | |
567ffc35 JB |
1765 | nested = nla_nest_start(msg, |
1766 | NL80211_ATTR_VENDOR_EVENTS); | |
1767 | if (!nested) | |
ad7e718c | 1768 | goto nla_put_failure; |
567ffc35 | 1769 | |
1b8ec87a ZG |
1770 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1771 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1772 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1773 | goto nla_put_failure; | |
1774 | } | |
1775 | nla_nest_end(msg, nested); | |
1776 | } | |
9a774c78 AO |
1777 | state->split_start++; |
1778 | break; | |
1779 | case 12: | |
1780 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1781 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1782 | rdev->wiphy.max_num_csa_counters)) | |
1783 | goto nla_put_failure; | |
01e0daa4 | 1784 | |
1bdd716c AN |
1785 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1786 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1787 | goto nla_put_failure; | |
1788 | ||
d75bb06b GKS |
1789 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1790 | sizeof(rdev->wiphy.ext_features), | |
1791 | rdev->wiphy.ext_features)) | |
1792 | goto nla_put_failure; | |
1793 | ||
38de03d2 AS |
1794 | if (rdev->wiphy.bss_select_support) { |
1795 | struct nlattr *nested; | |
1796 | u32 bss_select_support = rdev->wiphy.bss_select_support; | |
1797 | ||
1798 | nested = nla_nest_start(msg, NL80211_ATTR_BSS_SELECT); | |
1799 | if (!nested) | |
1800 | goto nla_put_failure; | |
1801 | ||
1802 | i = 0; | |
1803 | while (bss_select_support) { | |
1804 | if ((bss_select_support & 1) && | |
1805 | nla_put_flag(msg, i)) | |
1806 | goto nla_put_failure; | |
1807 | i++; | |
1808 | bss_select_support >>= 1; | |
1809 | } | |
1810 | nla_nest_end(msg, nested); | |
1811 | } | |
1812 | ||
019ae3a9 KV |
1813 | state->split_start++; |
1814 | break; | |
1815 | case 13: | |
1816 | if (rdev->wiphy.num_iftype_ext_capab && | |
1817 | rdev->wiphy.iftype_ext_capab) { | |
1818 | struct nlattr *nested_ext_capab, *nested; | |
1819 | ||
1820 | nested = nla_nest_start(msg, | |
1821 | NL80211_ATTR_IFTYPE_EXT_CAPA); | |
1822 | if (!nested) | |
1823 | goto nla_put_failure; | |
1824 | ||
1825 | for (i = state->capa_start; | |
1826 | i < rdev->wiphy.num_iftype_ext_capab; i++) { | |
1827 | const struct wiphy_iftype_ext_capab *capab; | |
1828 | ||
1829 | capab = &rdev->wiphy.iftype_ext_capab[i]; | |
1830 | ||
1831 | nested_ext_capab = nla_nest_start(msg, i); | |
1832 | if (!nested_ext_capab || | |
1833 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, | |
1834 | capab->iftype) || | |
1835 | nla_put(msg, NL80211_ATTR_EXT_CAPA, | |
1836 | capab->extended_capabilities_len, | |
1837 | capab->extended_capabilities) || | |
1838 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, | |
1839 | capab->extended_capabilities_len, | |
1840 | capab->extended_capabilities_mask)) | |
1841 | goto nla_put_failure; | |
1842 | ||
1843 | nla_nest_end(msg, nested_ext_capab); | |
1844 | if (state->split) | |
1845 | break; | |
1846 | } | |
1847 | nla_nest_end(msg, nested); | |
1848 | if (i < rdev->wiphy.num_iftype_ext_capab) { | |
1849 | state->capa_start = i + 1; | |
1850 | break; | |
1851 | } | |
1852 | } | |
1853 | ||
3713b4e3 | 1854 | /* done */ |
86e8cf98 | 1855 | state->split_start = 0; |
3713b4e3 JB |
1856 | break; |
1857 | } | |
3bb20556 | 1858 | finish: |
053c095a JB |
1859 | genlmsg_end(msg, hdr); |
1860 | return 0; | |
55682965 JB |
1861 | |
1862 | nla_put_failure: | |
bc3ed28c TG |
1863 | genlmsg_cancel(msg, hdr); |
1864 | return -EMSGSIZE; | |
55682965 JB |
1865 | } |
1866 | ||
86e8cf98 JB |
1867 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1868 | struct netlink_callback *cb, | |
1869 | struct nl80211_dump_wiphy_state *state) | |
1870 | { | |
c90c39da | 1871 | struct nlattr **tb = genl_family_attrbuf(&nl80211_fam); |
86e8cf98 JB |
1872 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
1873 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1874 | /* ignore parse errors for backward compatibility */ | |
1875 | if (ret) | |
1876 | return 0; | |
1877 | ||
1878 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1879 | if (tb[NL80211_ATTR_WIPHY]) | |
1880 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1881 | if (tb[NL80211_ATTR_WDEV]) | |
1882 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1883 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1884 | struct net_device *netdev; | |
1885 | struct cfg80211_registered_device *rdev; | |
1886 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1887 | ||
7f2b8562 | 1888 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1889 | if (!netdev) |
1890 | return -ENODEV; | |
1891 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1892 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1893 | netdev->ieee80211_ptr->wiphy); |
1894 | state->filter_wiphy = rdev->wiphy_idx; | |
1895 | } | |
86e8cf98 JB |
1896 | } |
1897 | ||
1898 | return 0; | |
1899 | } | |
1900 | ||
55682965 JB |
1901 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1902 | { | |
645e77de | 1903 | int idx = 0, ret; |
86e8cf98 | 1904 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1905 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1906 | |
5fe231e8 | 1907 | rtnl_lock(); |
86e8cf98 JB |
1908 | if (!state) { |
1909 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1910 | if (!state) { |
1911 | rtnl_unlock(); | |
86e8cf98 | 1912 | return -ENOMEM; |
3713b4e3 | 1913 | } |
86e8cf98 JB |
1914 | state->filter_wiphy = -1; |
1915 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1916 | if (ret) { | |
1917 | kfree(state); | |
1918 | rtnl_unlock(); | |
1919 | return ret; | |
3713b4e3 | 1920 | } |
86e8cf98 | 1921 | cb->args[0] = (long)state; |
3713b4e3 JB |
1922 | } |
1923 | ||
1b8ec87a ZG |
1924 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1925 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1926 | continue; |
86e8cf98 | 1927 | if (++idx <= state->start) |
55682965 | 1928 | continue; |
86e8cf98 | 1929 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1930 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1931 | continue; |
1932 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1933 | do { | |
3bb20556 JB |
1934 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1935 | skb, | |
3713b4e3 JB |
1936 | NETLINK_CB(cb->skb).portid, |
1937 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1938 | NLM_F_MULTI, state); |
3713b4e3 JB |
1939 | if (ret < 0) { |
1940 | /* | |
1941 | * If sending the wiphy data didn't fit (ENOBUFS | |
1942 | * or EMSGSIZE returned), this SKB is still | |
1943 | * empty (so it's not too big because another | |
1944 | * wiphy dataset is already in the skb) and | |
1945 | * we've not tried to adjust the dump allocation | |
1946 | * yet ... then adjust the alloc size to be | |
1947 | * bigger, and return 1 but with the empty skb. | |
1948 | * This results in an empty message being RX'ed | |
1949 | * in userspace, but that is ignored. | |
1950 | * | |
1951 | * We can then retry with the larger buffer. | |
1952 | */ | |
1953 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1954 | !skb->len && !state->split && |
3713b4e3 JB |
1955 | cb->min_dump_alloc < 4096) { |
1956 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1957 | state->split_start = 0; |
d98cae64 | 1958 | rtnl_unlock(); |
3713b4e3 JB |
1959 | return 1; |
1960 | } | |
1961 | idx--; | |
1962 | break; | |
645e77de | 1963 | } |
86e8cf98 | 1964 | } while (state->split_start > 0); |
3713b4e3 | 1965 | break; |
55682965 | 1966 | } |
5fe231e8 | 1967 | rtnl_unlock(); |
55682965 | 1968 | |
86e8cf98 | 1969 | state->start = idx; |
55682965 JB |
1970 | |
1971 | return skb->len; | |
1972 | } | |
1973 | ||
86e8cf98 JB |
1974 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1975 | { | |
1976 | kfree((void *)cb->args[0]); | |
1977 | return 0; | |
1978 | } | |
1979 | ||
55682965 JB |
1980 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1981 | { | |
1982 | struct sk_buff *msg; | |
1b8ec87a | 1983 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1984 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1985 | |
645e77de | 1986 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1987 | if (!msg) |
4c476991 | 1988 | return -ENOMEM; |
55682965 | 1989 | |
3bb20556 JB |
1990 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1991 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1992 | &state) < 0) { |
4c476991 JB |
1993 | nlmsg_free(msg); |
1994 | return -ENOBUFS; | |
1995 | } | |
55682965 | 1996 | |
134e6375 | 1997 | return genlmsg_reply(msg, info); |
55682965 JB |
1998 | } |
1999 | ||
31888487 JM |
2000 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
2001 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
2002 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
2003 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
2004 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
2005 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
2006 | }; | |
2007 | ||
2008 | static int parse_txq_params(struct nlattr *tb[], | |
2009 | struct ieee80211_txq_params *txq_params) | |
2010 | { | |
a3304b0a | 2011 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
2012 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
2013 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
2014 | return -EINVAL; | |
2015 | ||
a3304b0a | 2016 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
2017 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
2018 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
2019 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
2020 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
2021 | ||
a3304b0a JB |
2022 | if (txq_params->ac >= NL80211_NUM_ACS) |
2023 | return -EINVAL; | |
2024 | ||
31888487 JM |
2025 | return 0; |
2026 | } | |
2027 | ||
f444de05 JB |
2028 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
2029 | { | |
2030 | /* | |
cc1d2806 JB |
2031 | * You can only set the channel explicitly for WDS interfaces, |
2032 | * all others have their channel managed via their respective | |
2033 | * "establish a connection" command (connect, join, ...) | |
2034 | * | |
2035 | * For AP/GO and mesh mode, the channel can be set with the | |
2036 | * channel userspace API, but is only stored and passed to the | |
2037 | * low-level driver when the AP starts or the mesh is joined. | |
2038 | * This is for backward compatibility, userspace can also give | |
2039 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
2040 | * |
2041 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
2042 | * whatever else is going on, so they have their own special |
2043 | * operation to set the monitor channel if possible. | |
f444de05 JB |
2044 | */ |
2045 | return !wdev || | |
2046 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 2047 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
2048 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
2049 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
2050 | } |
2051 | ||
683b6d3b JB |
2052 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
2053 | struct genl_info *info, | |
2054 | struct cfg80211_chan_def *chandef) | |
2055 | { | |
dbeca2ea | 2056 | u32 control_freq; |
683b6d3b JB |
2057 | |
2058 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
2059 | return -EINVAL; | |
2060 | ||
2061 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
2062 | ||
2063 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
2064 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
2065 | chandef->center_freq1 = control_freq; | |
2066 | chandef->center_freq2 = 0; | |
683b6d3b JB |
2067 | |
2068 | /* Primary channel not allowed */ | |
2069 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
2070 | return -EINVAL; | |
2071 | ||
3d9d1d66 JB |
2072 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
2073 | enum nl80211_channel_type chantype; | |
2074 | ||
2075 | chantype = nla_get_u32( | |
2076 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
2077 | ||
2078 | switch (chantype) { | |
2079 | case NL80211_CHAN_NO_HT: | |
2080 | case NL80211_CHAN_HT20: | |
2081 | case NL80211_CHAN_HT40PLUS: | |
2082 | case NL80211_CHAN_HT40MINUS: | |
2083 | cfg80211_chandef_create(chandef, chandef->chan, | |
2084 | chantype); | |
2085 | break; | |
2086 | default: | |
2087 | return -EINVAL; | |
2088 | } | |
2089 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
2090 | chandef->width = | |
2091 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
2092 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
2093 | chandef->center_freq1 = | |
2094 | nla_get_u32( | |
2095 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
2096 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
2097 | chandef->center_freq2 = | |
2098 | nla_get_u32( | |
2099 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
2100 | } | |
2101 | ||
9f5e8f6e | 2102 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
2103 | return -EINVAL; |
2104 | ||
9f5e8f6e JB |
2105 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
2106 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
2107 | return -EINVAL; |
2108 | ||
2f301ab2 SW |
2109 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
2110 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
2111 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
2112 | return -EINVAL; | |
2113 | ||
683b6d3b JB |
2114 | return 0; |
2115 | } | |
2116 | ||
f444de05 | 2117 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 2118 | struct net_device *dev, |
f444de05 JB |
2119 | struct genl_info *info) |
2120 | { | |
683b6d3b | 2121 | struct cfg80211_chan_def chandef; |
f444de05 | 2122 | int result; |
e8c9bd5b | 2123 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 2124 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 2125 | |
e16821bc JM |
2126 | if (dev) |
2127 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
2128 | if (!nl80211_can_set_dev_channel(wdev)) |
2129 | return -EOPNOTSUPP; | |
e16821bc JM |
2130 | if (wdev) |
2131 | iftype = wdev->iftype; | |
f444de05 | 2132 | |
683b6d3b JB |
2133 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2134 | if (result) | |
2135 | return result; | |
f444de05 | 2136 | |
e8c9bd5b | 2137 | switch (iftype) { |
aa430da4 JB |
2138 | case NL80211_IFTYPE_AP: |
2139 | case NL80211_IFTYPE_P2P_GO: | |
923b352f AN |
2140 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
2141 | iftype)) { | |
aa430da4 JB |
2142 | result = -EINVAL; |
2143 | break; | |
2144 | } | |
e16821bc JM |
2145 | if (wdev->beacon_interval) { |
2146 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2147 | !(rdev->wiphy.features & | |
2148 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2149 | result = -EBUSY; | |
2150 | break; | |
2151 | } | |
2152 | ||
2153 | /* Only allow dynamic channel width changes */ | |
2154 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2155 | result = -EBUSY; | |
2156 | break; | |
2157 | } | |
2158 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2159 | if (result) | |
2160 | break; | |
2161 | } | |
683b6d3b | 2162 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2163 | result = 0; |
2164 | break; | |
cc1d2806 | 2165 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2166 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2167 | break; |
e8c9bd5b | 2168 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2169 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2170 | break; |
aa430da4 | 2171 | default: |
e8c9bd5b | 2172 | result = -EINVAL; |
f444de05 | 2173 | } |
f444de05 JB |
2174 | |
2175 | return result; | |
2176 | } | |
2177 | ||
2178 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2179 | { | |
4c476991 JB |
2180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2181 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2182 | |
e16821bc | 2183 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2184 | } |
2185 | ||
e8347eba BJ |
2186 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2187 | { | |
43b19952 JB |
2188 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2189 | struct net_device *dev = info->user_ptr[1]; | |
2190 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2191 | const u8 *bssid; |
e8347eba BJ |
2192 | |
2193 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2194 | return -EINVAL; | |
2195 | ||
43b19952 JB |
2196 | if (netif_running(dev)) |
2197 | return -EBUSY; | |
e8347eba | 2198 | |
43b19952 JB |
2199 | if (!rdev->ops->set_wds_peer) |
2200 | return -EOPNOTSUPP; | |
e8347eba | 2201 | |
43b19952 JB |
2202 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2203 | return -EOPNOTSUPP; | |
e8347eba BJ |
2204 | |
2205 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2206 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2207 | } |
2208 | ||
55682965 JB |
2209 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2210 | { | |
2211 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2212 | struct net_device *netdev = NULL; |
2213 | struct wireless_dev *wdev; | |
a1e567c8 | 2214 | int result = 0, rem_txq_params = 0; |
31888487 | 2215 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2216 | u32 changed; |
2217 | u8 retry_short = 0, retry_long = 0; | |
2218 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2219 | u8 coverage_class = 0; |
55682965 | 2220 | |
5fe231e8 JB |
2221 | ASSERT_RTNL(); |
2222 | ||
f444de05 JB |
2223 | /* |
2224 | * Try to find the wiphy and netdev. Normally this | |
2225 | * function shouldn't need the netdev, but this is | |
2226 | * done for backward compatibility -- previously | |
2227 | * setting the channel was done per wiphy, but now | |
2228 | * it is per netdev. Previous userland like hostapd | |
2229 | * also passed a netdev to set_wiphy, so that it is | |
2230 | * possible to let that go to the right netdev! | |
2231 | */ | |
4bbf4d56 | 2232 | |
f444de05 JB |
2233 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2234 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2235 | ||
7f2b8562 | 2236 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2237 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2238 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2239 | else |
f444de05 | 2240 | netdev = NULL; |
4bbf4d56 JB |
2241 | } |
2242 | ||
f444de05 | 2243 | if (!netdev) { |
878d9ec7 JB |
2244 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2245 | info->attrs); | |
5fe231e8 | 2246 | if (IS_ERR(rdev)) |
4c476991 | 2247 | return PTR_ERR(rdev); |
f444de05 JB |
2248 | wdev = NULL; |
2249 | netdev = NULL; | |
2250 | result = 0; | |
71fe96bf | 2251 | } else |
f444de05 | 2252 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2253 | |
2254 | /* | |
2255 | * end workaround code, by now the rdev is available | |
2256 | * and locked, and wdev may or may not be NULL. | |
2257 | */ | |
4bbf4d56 JB |
2258 | |
2259 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2260 | result = cfg80211_dev_rename( |
2261 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2262 | |
4bbf4d56 | 2263 | if (result) |
7f2b8562 | 2264 | return result; |
31888487 JM |
2265 | |
2266 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2267 | struct ieee80211_txq_params txq_params; | |
2268 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2269 | ||
7f2b8562 YX |
2270 | if (!rdev->ops->set_txq_params) |
2271 | return -EOPNOTSUPP; | |
31888487 | 2272 | |
7f2b8562 YX |
2273 | if (!netdev) |
2274 | return -EINVAL; | |
f70f01c2 | 2275 | |
133a3ff2 | 2276 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2277 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2278 | return -EINVAL; | |
133a3ff2 | 2279 | |
7f2b8562 YX |
2280 | if (!netif_running(netdev)) |
2281 | return -ENETDOWN; | |
2b5f8b0b | 2282 | |
31888487 JM |
2283 | nla_for_each_nested(nl_txq_params, |
2284 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2285 | rem_txq_params) { | |
ae811e21 JB |
2286 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2287 | nla_data(nl_txq_params), | |
2288 | nla_len(nl_txq_params), | |
2289 | txq_params_policy); | |
2290 | if (result) | |
2291 | return result; | |
31888487 JM |
2292 | result = parse_txq_params(tb, &txq_params); |
2293 | if (result) | |
7f2b8562 | 2294 | return result; |
31888487 | 2295 | |
e35e4d28 HG |
2296 | result = rdev_set_txq_params(rdev, netdev, |
2297 | &txq_params); | |
31888487 | 2298 | if (result) |
7f2b8562 | 2299 | return result; |
31888487 JM |
2300 | } |
2301 | } | |
55682965 | 2302 | |
72bdcf34 | 2303 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2304 | result = __nl80211_set_channel( |
2305 | rdev, | |
2306 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2307 | info); | |
72bdcf34 | 2308 | if (result) |
7f2b8562 | 2309 | return result; |
72bdcf34 JM |
2310 | } |
2311 | ||
98d2ff8b | 2312 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2313 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2314 | enum nl80211_tx_power_setting type; |
2315 | int idx, mbm = 0; | |
2316 | ||
c8442118 JB |
2317 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2318 | txp_wdev = NULL; | |
2319 | ||
7f2b8562 YX |
2320 | if (!rdev->ops->set_tx_power) |
2321 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2322 | |
2323 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2324 | type = nla_get_u32(info->attrs[idx]); | |
2325 | ||
2326 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2327 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2328 | return -EINVAL; | |
98d2ff8b JO |
2329 | |
2330 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2331 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2332 | mbm = nla_get_u32(info->attrs[idx]); | |
2333 | } | |
2334 | ||
c8442118 | 2335 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2336 | if (result) |
7f2b8562 | 2337 | return result; |
98d2ff8b JO |
2338 | } |
2339 | ||
afe0cbf8 BR |
2340 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2341 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2342 | u32 tx_ant, rx_ant; | |
7a087e74 | 2343 | |
7f531e03 BR |
2344 | if ((!rdev->wiphy.available_antennas_tx && |
2345 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2346 | !rdev->ops->set_antenna) |
2347 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2348 | |
2349 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2350 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2351 | ||
a7ffac95 | 2352 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2353 | * available antenna masks, except for the "all" mask */ |
2354 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2355 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2356 | return -EINVAL; | |
a7ffac95 | 2357 | |
7f531e03 BR |
2358 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2359 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2360 | |
e35e4d28 | 2361 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2362 | if (result) |
7f2b8562 | 2363 | return result; |
afe0cbf8 BR |
2364 | } |
2365 | ||
b9a5f8ca JM |
2366 | changed = 0; |
2367 | ||
2368 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2369 | retry_short = nla_get_u8( | |
2370 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2371 | if (retry_short == 0) |
2372 | return -EINVAL; | |
2373 | ||
b9a5f8ca JM |
2374 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2375 | } | |
2376 | ||
2377 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2378 | retry_long = nla_get_u8( | |
2379 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2380 | if (retry_long == 0) |
2381 | return -EINVAL; | |
2382 | ||
b9a5f8ca JM |
2383 | changed |= WIPHY_PARAM_RETRY_LONG; |
2384 | } | |
2385 | ||
2386 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2387 | frag_threshold = nla_get_u32( | |
2388 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2389 | if (frag_threshold < 256) |
2390 | return -EINVAL; | |
2391 | ||
b9a5f8ca JM |
2392 | if (frag_threshold != (u32) -1) { |
2393 | /* | |
2394 | * Fragments (apart from the last one) are required to | |
2395 | * have even length. Make the fragmentation code | |
2396 | * simpler by stripping LSB should someone try to use | |
2397 | * odd threshold value. | |
2398 | */ | |
2399 | frag_threshold &= ~0x1; | |
2400 | } | |
2401 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2402 | } | |
2403 | ||
2404 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2405 | rts_threshold = nla_get_u32( | |
2406 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2407 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2408 | } | |
2409 | ||
81077e82 | 2410 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2411 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2412 | return -EINVAL; | |
2413 | ||
81077e82 LT |
2414 | coverage_class = nla_get_u8( |
2415 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2416 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2417 | } | |
2418 | ||
3057dbfd LB |
2419 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2420 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2421 | return -EOPNOTSUPP; | |
2422 | ||
2423 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2424 | } |
2425 | ||
b9a5f8ca JM |
2426 | if (changed) { |
2427 | u8 old_retry_short, old_retry_long; | |
2428 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2429 | u8 old_coverage_class; |
b9a5f8ca | 2430 | |
7f2b8562 YX |
2431 | if (!rdev->ops->set_wiphy_params) |
2432 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2433 | |
2434 | old_retry_short = rdev->wiphy.retry_short; | |
2435 | old_retry_long = rdev->wiphy.retry_long; | |
2436 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2437 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2438 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2439 | |
2440 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2441 | rdev->wiphy.retry_short = retry_short; | |
2442 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2443 | rdev->wiphy.retry_long = retry_long; | |
2444 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2445 | rdev->wiphy.frag_threshold = frag_threshold; | |
2446 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2447 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2448 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2449 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2450 | |
e35e4d28 | 2451 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2452 | if (result) { |
2453 | rdev->wiphy.retry_short = old_retry_short; | |
2454 | rdev->wiphy.retry_long = old_retry_long; | |
2455 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2456 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2457 | rdev->wiphy.coverage_class = old_coverage_class; |
9189ee31 | 2458 | return result; |
b9a5f8ca JM |
2459 | } |
2460 | } | |
7f2b8562 | 2461 | return 0; |
55682965 JB |
2462 | } |
2463 | ||
71bbc994 JB |
2464 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2465 | { | |
2466 | return (u64)wdev->identifier | | |
f26cbf40 | 2467 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2468 | } |
55682965 | 2469 | |
683b6d3b | 2470 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2471 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2472 | { |
601555cd JB |
2473 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2474 | return -EINVAL; | |
3d9d1d66 | 2475 | |
683b6d3b JB |
2476 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2477 | chandef->chan->center_freq)) | |
2478 | return -ENOBUFS; | |
3d9d1d66 JB |
2479 | switch (chandef->width) { |
2480 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2481 | case NL80211_CHAN_WIDTH_20: | |
2482 | case NL80211_CHAN_WIDTH_40: | |
2483 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2484 | cfg80211_get_chandef_type(chandef))) | |
2485 | return -ENOBUFS; | |
2486 | break; | |
2487 | default: | |
2488 | break; | |
2489 | } | |
2490 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2491 | return -ENOBUFS; | |
2492 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2493 | return -ENOBUFS; | |
2494 | if (chandef->center_freq2 && | |
2495 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2496 | return -ENOBUFS; |
2497 | return 0; | |
2498 | } | |
2499 | ||
15e47304 | 2500 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2501 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2502 | struct wireless_dev *wdev, bool removal) |
55682965 | 2503 | { |
72fb2abc | 2504 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2505 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2506 | void *hdr; |
2507 | ||
8f894be2 TB |
2508 | if (removal) |
2509 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2510 | ||
2511 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2512 | if (!hdr) |
2513 | return -1; | |
2514 | ||
72fb2abc JB |
2515 | if (dev && |
2516 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2517 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2518 | goto nla_put_failure; |
2519 | ||
2520 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2521 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
2dad624e ND |
2522 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
2523 | NL80211_ATTR_PAD) || | |
98104fde | 2524 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2525 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2526 | rdev->devlist_generation ^ | |
2527 | (cfg80211_rdev_list_generation << 2))) | |
2528 | goto nla_put_failure; | |
f5ea9120 | 2529 | |
5b7ccaf3 | 2530 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2531 | int ret; |
2532 | struct cfg80211_chan_def chandef; | |
2533 | ||
2534 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2535 | if (ret == 0) { | |
2536 | if (nl80211_send_chandef(msg, &chandef)) | |
2537 | goto nla_put_failure; | |
2538 | } | |
d91df0e3 PF |
2539 | } |
2540 | ||
d55d0d59 RM |
2541 | if (rdev->ops->get_tx_power) { |
2542 | int dbm, ret; | |
2543 | ||
2544 | ret = rdev_get_tx_power(rdev, wdev, &dbm); | |
2545 | if (ret == 0 && | |
2546 | nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL, | |
2547 | DBM_TO_MBM(dbm))) | |
2548 | goto nla_put_failure; | |
2549 | } | |
2550 | ||
b84e7a05 AQ |
2551 | if (wdev->ssid_len) { |
2552 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2553 | goto nla_put_failure; | |
2554 | } | |
2555 | ||
053c095a JB |
2556 | genlmsg_end(msg, hdr); |
2557 | return 0; | |
55682965 JB |
2558 | |
2559 | nla_put_failure: | |
bc3ed28c TG |
2560 | genlmsg_cancel(msg, hdr); |
2561 | return -EMSGSIZE; | |
55682965 JB |
2562 | } |
2563 | ||
2564 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2565 | { | |
2566 | int wp_idx = 0; | |
2567 | int if_idx = 0; | |
2568 | int wp_start = cb->args[0]; | |
2569 | int if_start = cb->args[1]; | |
b7fb44da | 2570 | int filter_wiphy = -1; |
f5ea9120 | 2571 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2572 | struct wireless_dev *wdev; |
2573 | ||
5fe231e8 | 2574 | rtnl_lock(); |
b7fb44da DK |
2575 | if (!cb->args[2]) { |
2576 | struct nl80211_dump_wiphy_state state = { | |
2577 | .filter_wiphy = -1, | |
2578 | }; | |
2579 | int ret; | |
2580 | ||
2581 | ret = nl80211_dump_wiphy_parse(skb, cb, &state); | |
2582 | if (ret) | |
2583 | return ret; | |
2584 | ||
2585 | filter_wiphy = state.filter_wiphy; | |
2586 | ||
2587 | /* | |
2588 | * if filtering, set cb->args[2] to +1 since 0 is the default | |
2589 | * value needed to determine that parsing is necessary. | |
2590 | */ | |
2591 | if (filter_wiphy >= 0) | |
2592 | cb->args[2] = filter_wiphy + 1; | |
2593 | else | |
2594 | cb->args[2] = -1; | |
2595 | } else if (cb->args[2] > 0) { | |
2596 | filter_wiphy = cb->args[2] - 1; | |
2597 | } | |
2598 | ||
f5ea9120 JB |
2599 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2600 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2601 | continue; |
bba95fef JB |
2602 | if (wp_idx < wp_start) { |
2603 | wp_idx++; | |
55682965 | 2604 | continue; |
bba95fef | 2605 | } |
b7fb44da DK |
2606 | |
2607 | if (filter_wiphy >= 0 && filter_wiphy != rdev->wiphy_idx) | |
2608 | continue; | |
2609 | ||
55682965 JB |
2610 | if_idx = 0; |
2611 | ||
53873f13 | 2612 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
bba95fef JB |
2613 | if (if_idx < if_start) { |
2614 | if_idx++; | |
55682965 | 2615 | continue; |
bba95fef | 2616 | } |
15e47304 | 2617 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2618 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2619 | rdev, wdev, false) < 0) { |
bba95fef JB |
2620 | goto out; |
2621 | } | |
2622 | if_idx++; | |
55682965 | 2623 | } |
bba95fef JB |
2624 | |
2625 | wp_idx++; | |
55682965 | 2626 | } |
bba95fef | 2627 | out: |
5fe231e8 | 2628 | rtnl_unlock(); |
55682965 JB |
2629 | |
2630 | cb->args[0] = wp_idx; | |
2631 | cb->args[1] = if_idx; | |
2632 | ||
2633 | return skb->len; | |
2634 | } | |
2635 | ||
2636 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2637 | { | |
2638 | struct sk_buff *msg; | |
1b8ec87a | 2639 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2640 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2641 | |
fd2120ca | 2642 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2643 | if (!msg) |
4c476991 | 2644 | return -ENOMEM; |
55682965 | 2645 | |
15e47304 | 2646 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2647 | rdev, wdev, false) < 0) { |
4c476991 JB |
2648 | nlmsg_free(msg); |
2649 | return -ENOBUFS; | |
2650 | } | |
55682965 | 2651 | |
134e6375 | 2652 | return genlmsg_reply(msg, info); |
55682965 JB |
2653 | } |
2654 | ||
66f7ac50 MW |
2655 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2656 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2657 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2658 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2659 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2660 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2661 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2662 | }; |
2663 | ||
2664 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2665 | { | |
2666 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2667 | int flag; | |
2668 | ||
2669 | *mntrflags = 0; | |
2670 | ||
2671 | if (!nla) | |
2672 | return -EINVAL; | |
2673 | ||
2674 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2675 | nla, mntr_flags_policy)) | |
2676 | return -EINVAL; | |
2677 | ||
2678 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2679 | if (flags[flag]) | |
2680 | *mntrflags |= (1<<flag); | |
2681 | ||
2682 | return 0; | |
2683 | } | |
2684 | ||
9bc383de | 2685 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2686 | struct net_device *netdev, u8 use_4addr, |
2687 | enum nl80211_iftype iftype) | |
9bc383de | 2688 | { |
ad4bb6f8 | 2689 | if (!use_4addr) { |
f350a0a8 | 2690 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2691 | return -EBUSY; |
9bc383de | 2692 | return 0; |
ad4bb6f8 | 2693 | } |
9bc383de JB |
2694 | |
2695 | switch (iftype) { | |
2696 | case NL80211_IFTYPE_AP_VLAN: | |
2697 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2698 | return 0; | |
2699 | break; | |
2700 | case NL80211_IFTYPE_STATION: | |
2701 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2702 | return 0; | |
2703 | break; | |
2704 | default: | |
2705 | break; | |
2706 | } | |
2707 | ||
2708 | return -EOPNOTSUPP; | |
2709 | } | |
2710 | ||
55682965 JB |
2711 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2712 | { | |
4c476991 | 2713 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2714 | struct vif_params params; |
e36d56b6 | 2715 | int err; |
04a773ad | 2716 | enum nl80211_iftype otype, ntype; |
4c476991 | 2717 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2718 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2719 | bool change = false; |
55682965 | 2720 | |
2ec600d6 LCC |
2721 | memset(¶ms, 0, sizeof(params)); |
2722 | ||
04a773ad | 2723 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2724 | |
723b038d | 2725 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2726 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2727 | if (otype != ntype) |
ac7f9cfa | 2728 | change = true; |
4c476991 JB |
2729 | if (ntype > NL80211_IFTYPE_MAX) |
2730 | return -EINVAL; | |
723b038d JB |
2731 | } |
2732 | ||
92ffe055 | 2733 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2734 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2735 | ||
4c476991 JB |
2736 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2737 | return -EINVAL; | |
29cbe68c JB |
2738 | if (netif_running(dev)) |
2739 | return -EBUSY; | |
2740 | ||
2741 | wdev_lock(wdev); | |
2742 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2743 | IEEE80211_MAX_MESH_ID_LEN); | |
2744 | wdev->mesh_id_up_len = | |
2745 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2746 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2747 | wdev->mesh_id_up_len); | |
2748 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2749 | } |
2750 | ||
8b787643 FF |
2751 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2752 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2753 | change = true; | |
ad4bb6f8 | 2754 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2755 | if (err) |
4c476991 | 2756 | return err; |
8b787643 FF |
2757 | } else { |
2758 | params.use_4addr = -1; | |
2759 | } | |
2760 | ||
92ffe055 | 2761 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2762 | if (ntype != NL80211_IFTYPE_MONITOR) |
2763 | return -EINVAL; | |
92ffe055 JB |
2764 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2765 | &_flags); | |
ac7f9cfa | 2766 | if (err) |
4c476991 | 2767 | return err; |
ac7f9cfa JB |
2768 | |
2769 | flags = &_flags; | |
2770 | change = true; | |
92ffe055 | 2771 | } |
3b85875a | 2772 | |
c6e6a0c8 AE |
2773 | if (info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]) { |
2774 | const u8 *mumimo_groups; | |
2775 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
2776 | ||
2777 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
2778 | return -EOPNOTSUPP; | |
2779 | ||
2780 | mumimo_groups = | |
2781 | nla_data(info->attrs[NL80211_ATTR_MU_MIMO_GROUP_DATA]); | |
2782 | ||
2783 | /* bits 0 and 63 are reserved and must be zero */ | |
2784 | if ((mumimo_groups[0] & BIT(7)) || | |
2785 | (mumimo_groups[VHT_MUMIMO_GROUPS_DATA_LEN - 1] & BIT(0))) | |
2786 | return -EINVAL; | |
2787 | ||
2788 | memcpy(params.vht_mumimo_groups, mumimo_groups, | |
2789 | VHT_MUMIMO_GROUPS_DATA_LEN); | |
2790 | change = true; | |
2791 | } | |
2792 | ||
2793 | if (info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR]) { | |
2794 | u32 cap_flag = NL80211_EXT_FEATURE_MU_MIMO_AIR_SNIFFER; | |
2795 | ||
2796 | if (!wiphy_ext_feature_isset(&rdev->wiphy, cap_flag)) | |
2797 | return -EOPNOTSUPP; | |
2798 | ||
2799 | nla_memcpy(params.macaddr, | |
2800 | info->attrs[NL80211_ATTR_MU_MIMO_FOLLOW_MAC_ADDR], | |
2801 | ETH_ALEN); | |
2802 | change = true; | |
2803 | } | |
2804 | ||
18003297 | 2805 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2806 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2807 | return -EOPNOTSUPP; | |
2808 | ||
ac7f9cfa | 2809 | if (change) |
3d54d255 | 2810 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2811 | else |
2812 | err = 0; | |
60719ffd | 2813 | |
9bc383de JB |
2814 | if (!err && params.use_4addr != -1) |
2815 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2816 | ||
55682965 JB |
2817 | return err; |
2818 | } | |
2819 | ||
2820 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2821 | { | |
4c476991 | 2822 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2823 | struct vif_params params; |
84efbb84 | 2824 | struct wireless_dev *wdev; |
896ff063 | 2825 | struct sk_buff *msg; |
55682965 JB |
2826 | int err; |
2827 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2828 | u32 flags; |
55682965 | 2829 | |
78f22b6a JB |
2830 | /* to avoid failing a new interface creation due to pending removal */ |
2831 | cfg80211_destroy_ifaces(rdev); | |
2832 | ||
2ec600d6 LCC |
2833 | memset(¶ms, 0, sizeof(params)); |
2834 | ||
55682965 JB |
2835 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2836 | return -EINVAL; | |
2837 | ||
2838 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2839 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2840 | if (type > NL80211_IFTYPE_MAX) | |
2841 | return -EINVAL; | |
2842 | } | |
2843 | ||
79c97e97 | 2844 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2845 | !(rdev->wiphy.interface_modes & (1 << type))) |
2846 | return -EOPNOTSUPP; | |
55682965 | 2847 | |
cb3b7d87 | 2848 | if ((type == NL80211_IFTYPE_P2P_DEVICE || type == NL80211_IFTYPE_NAN || |
e8f479b1 BG |
2849 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && |
2850 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2851 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2852 | ETH_ALEN); | |
2853 | if (!is_valid_ether_addr(params.macaddr)) | |
2854 | return -EADDRNOTAVAIL; | |
2855 | } | |
2856 | ||
9bc383de | 2857 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2858 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2859 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2860 | if (err) |
4c476991 | 2861 | return err; |
9bc383de | 2862 | } |
8b787643 | 2863 | |
66f7ac50 MW |
2864 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2865 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2866 | &flags); | |
e057d3c3 | 2867 | |
18003297 | 2868 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2869 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2870 | return -EOPNOTSUPP; | |
2871 | ||
a18c7192 JB |
2872 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2873 | if (!msg) | |
2874 | return -ENOMEM; | |
2875 | ||
e35e4d28 HG |
2876 | wdev = rdev_add_virtual_intf(rdev, |
2877 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
6bab2e19 TG |
2878 | NET_NAME_USER, type, err ? NULL : &flags, |
2879 | ¶ms); | |
d687cbb7 RM |
2880 | if (WARN_ON(!wdev)) { |
2881 | nlmsg_free(msg); | |
2882 | return -EPROTO; | |
2883 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2884 | nlmsg_free(msg); |
84efbb84 | 2885 | return PTR_ERR(wdev); |
1c90f9d4 | 2886 | } |
2ec600d6 | 2887 | |
18e5ca65 | 2888 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2889 | wdev->owner_nlportid = info->snd_portid; |
2890 | ||
98104fde JB |
2891 | switch (type) { |
2892 | case NL80211_IFTYPE_MESH_POINT: | |
2893 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2894 | break; | |
29cbe68c JB |
2895 | wdev_lock(wdev); |
2896 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2897 | IEEE80211_MAX_MESH_ID_LEN); | |
2898 | wdev->mesh_id_up_len = | |
2899 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2900 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2901 | wdev->mesh_id_up_len); | |
2902 | wdev_unlock(wdev); | |
98104fde | 2903 | break; |
cb3b7d87 | 2904 | case NL80211_IFTYPE_NAN: |
98104fde JB |
2905 | case NL80211_IFTYPE_P2P_DEVICE: |
2906 | /* | |
cb3b7d87 | 2907 | * P2P Device and NAN do not have a netdev, so don't go |
98104fde JB |
2908 | * through the netdev notifier and must be added here |
2909 | */ | |
2910 | mutex_init(&wdev->mtx); | |
2911 | INIT_LIST_HEAD(&wdev->event_list); | |
2912 | spin_lock_init(&wdev->event_lock); | |
2913 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2914 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2915 | ||
98104fde | 2916 | wdev->identifier = ++rdev->wdev_id; |
53873f13 | 2917 | list_add_rcu(&wdev->list, &rdev->wiphy.wdev_list); |
98104fde | 2918 | rdev->devlist_generation++; |
98104fde JB |
2919 | break; |
2920 | default: | |
2921 | break; | |
29cbe68c JB |
2922 | } |
2923 | ||
15e47304 | 2924 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2925 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2926 | nlmsg_free(msg); |
2927 | return -ENOBUFS; | |
2928 | } | |
2929 | ||
896ff063 DK |
2930 | /* |
2931 | * For wdevs which have no associated netdev object (e.g. of type | |
2932 | * NL80211_IFTYPE_P2P_DEVICE), emit the NEW_INTERFACE event here. | |
2933 | * For all other types, the event will be generated from the | |
2934 | * netdev notifier | |
2935 | */ | |
2936 | if (!wdev->netdev) | |
2937 | nl80211_notify_iface(rdev, wdev, NL80211_CMD_NEW_INTERFACE); | |
8f894be2 | 2938 | |
1c90f9d4 | 2939 | return genlmsg_reply(msg, info); |
55682965 JB |
2940 | } |
2941 | ||
2942 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2943 | { | |
4c476991 | 2944 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2945 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2946 | |
4c476991 JB |
2947 | if (!rdev->ops->del_virtual_intf) |
2948 | return -EOPNOTSUPP; | |
55682965 | 2949 | |
84efbb84 JB |
2950 | /* |
2951 | * If we remove a wireless device without a netdev then clear | |
2952 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2953 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2954 | * since the wdev has been freed, unlike with a netdev where | |
2955 | * we need the dev_put() for the netdev to really be freed. | |
2956 | */ | |
2957 | if (!wdev->netdev) | |
2958 | info->user_ptr[1] = NULL; | |
2959 | ||
7f8ed01e | 2960 | return rdev_del_virtual_intf(rdev, wdev); |
55682965 JB |
2961 | } |
2962 | ||
1d9d9213 SW |
2963 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2964 | { | |
2965 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2966 | struct net_device *dev = info->user_ptr[1]; | |
2967 | u16 noack_map; | |
2968 | ||
2969 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2970 | return -EINVAL; | |
2971 | ||
2972 | if (!rdev->ops->set_noack_map) | |
2973 | return -EOPNOTSUPP; | |
2974 | ||
2975 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2976 | ||
e35e4d28 | 2977 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2978 | } |
2979 | ||
41ade00f JB |
2980 | struct get_key_cookie { |
2981 | struct sk_buff *msg; | |
2982 | int error; | |
b9454e83 | 2983 | int idx; |
41ade00f JB |
2984 | }; |
2985 | ||
2986 | static void get_key_callback(void *c, struct key_params *params) | |
2987 | { | |
b9454e83 | 2988 | struct nlattr *key; |
41ade00f JB |
2989 | struct get_key_cookie *cookie = c; |
2990 | ||
9360ffd1 DM |
2991 | if ((params->key && |
2992 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2993 | params->key_len, params->key)) || | |
2994 | (params->seq && | |
2995 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2996 | params->seq_len, params->seq)) || | |
2997 | (params->cipher && | |
2998 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2999 | params->cipher))) | |
3000 | goto nla_put_failure; | |
41ade00f | 3001 | |
b9454e83 JB |
3002 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
3003 | if (!key) | |
3004 | goto nla_put_failure; | |
3005 | ||
9360ffd1 DM |
3006 | if ((params->key && |
3007 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
3008 | params->key_len, params->key)) || | |
3009 | (params->seq && | |
3010 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
3011 | params->seq_len, params->seq)) || | |
3012 | (params->cipher && | |
3013 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
3014 | params->cipher))) | |
3015 | goto nla_put_failure; | |
b9454e83 | 3016 | |
9360ffd1 DM |
3017 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
3018 | goto nla_put_failure; | |
b9454e83 JB |
3019 | |
3020 | nla_nest_end(cookie->msg, key); | |
3021 | ||
41ade00f JB |
3022 | return; |
3023 | nla_put_failure: | |
3024 | cookie->error = 1; | |
3025 | } | |
3026 | ||
3027 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
3028 | { | |
4c476991 | 3029 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3030 | int err; |
4c476991 | 3031 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3032 | u8 key_idx = 0; |
e31b8213 JB |
3033 | const u8 *mac_addr = NULL; |
3034 | bool pairwise; | |
41ade00f JB |
3035 | struct get_key_cookie cookie = { |
3036 | .error = 0, | |
3037 | }; | |
3038 | void *hdr; | |
3039 | struct sk_buff *msg; | |
3040 | ||
3041 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
3042 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
3043 | ||
3cfcf6ac | 3044 | if (key_idx > 5) |
41ade00f JB |
3045 | return -EINVAL; |
3046 | ||
3047 | if (info->attrs[NL80211_ATTR_MAC]) | |
3048 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3049 | ||
e31b8213 JB |
3050 | pairwise = !!mac_addr; |
3051 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
3052 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
7a087e74 | 3053 | |
e31b8213 JB |
3054 | if (kt >= NUM_NL80211_KEYTYPES) |
3055 | return -EINVAL; | |
3056 | if (kt != NL80211_KEYTYPE_GROUP && | |
3057 | kt != NL80211_KEYTYPE_PAIRWISE) | |
3058 | return -EINVAL; | |
3059 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
3060 | } | |
3061 | ||
4c476991 JB |
3062 | if (!rdev->ops->get_key) |
3063 | return -EOPNOTSUPP; | |
41ade00f | 3064 | |
0fa7b391 JB |
3065 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3066 | return -ENOENT; | |
3067 | ||
fd2120ca | 3068 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
3069 | if (!msg) |
3070 | return -ENOMEM; | |
41ade00f | 3071 | |
15e47304 | 3072 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 3073 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 3074 | if (!hdr) |
9fe271af | 3075 | goto nla_put_failure; |
41ade00f JB |
3076 | |
3077 | cookie.msg = msg; | |
b9454e83 | 3078 | cookie.idx = key_idx; |
41ade00f | 3079 | |
9360ffd1 DM |
3080 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3081 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
3082 | goto nla_put_failure; | |
3083 | if (mac_addr && | |
3084 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
3085 | goto nla_put_failure; | |
41ade00f | 3086 | |
e35e4d28 HG |
3087 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
3088 | get_key_callback); | |
41ade00f JB |
3089 | |
3090 | if (err) | |
6c95e2a2 | 3091 | goto free_msg; |
41ade00f JB |
3092 | |
3093 | if (cookie.error) | |
3094 | goto nla_put_failure; | |
3095 | ||
3096 | genlmsg_end(msg, hdr); | |
4c476991 | 3097 | return genlmsg_reply(msg, info); |
41ade00f JB |
3098 | |
3099 | nla_put_failure: | |
3100 | err = -ENOBUFS; | |
6c95e2a2 | 3101 | free_msg: |
41ade00f | 3102 | nlmsg_free(msg); |
41ade00f JB |
3103 | return err; |
3104 | } | |
3105 | ||
3106 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
3107 | { | |
4c476991 | 3108 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 3109 | struct key_parse key; |
41ade00f | 3110 | int err; |
4c476991 | 3111 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3112 | |
b9454e83 JB |
3113 | err = nl80211_parse_key(info, &key); |
3114 | if (err) | |
3115 | return err; | |
41ade00f | 3116 | |
b9454e83 | 3117 | if (key.idx < 0) |
41ade00f JB |
3118 | return -EINVAL; |
3119 | ||
b9454e83 JB |
3120 | /* only support setting default key */ |
3121 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
3122 | return -EINVAL; |
3123 | ||
dbd2fd65 | 3124 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 3125 | |
dbd2fd65 JB |
3126 | if (key.def) { |
3127 | if (!rdev->ops->set_default_key) { | |
3128 | err = -EOPNOTSUPP; | |
3129 | goto out; | |
3130 | } | |
41ade00f | 3131 | |
dbd2fd65 JB |
3132 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
3133 | if (err) | |
3134 | goto out; | |
3135 | ||
e35e4d28 | 3136 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
3137 | key.def_uni, key.def_multi); |
3138 | ||
3139 | if (err) | |
3140 | goto out; | |
fffd0934 | 3141 | |
3d23e349 | 3142 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
3143 | dev->ieee80211_ptr->wext.default_key = key.idx; |
3144 | #endif | |
3145 | } else { | |
3146 | if (key.def_uni || !key.def_multi) { | |
3147 | err = -EINVAL; | |
3148 | goto out; | |
3149 | } | |
3150 | ||
3151 | if (!rdev->ops->set_default_mgmt_key) { | |
3152 | err = -EOPNOTSUPP; | |
3153 | goto out; | |
3154 | } | |
3155 | ||
3156 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3157 | if (err) | |
3158 | goto out; | |
3159 | ||
e35e4d28 | 3160 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
3161 | if (err) |
3162 | goto out; | |
3163 | ||
3164 | #ifdef CONFIG_CFG80211_WEXT | |
3165 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 3166 | #endif |
dbd2fd65 JB |
3167 | } |
3168 | ||
3169 | out: | |
fffd0934 | 3170 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3171 | |
41ade00f JB |
3172 | return err; |
3173 | } | |
3174 | ||
3175 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
3176 | { | |
4c476991 | 3177 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 3178 | int err; |
4c476991 | 3179 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 3180 | struct key_parse key; |
e31b8213 | 3181 | const u8 *mac_addr = NULL; |
41ade00f | 3182 | |
b9454e83 JB |
3183 | err = nl80211_parse_key(info, &key); |
3184 | if (err) | |
3185 | return err; | |
41ade00f | 3186 | |
b9454e83 | 3187 | if (!key.p.key) |
41ade00f JB |
3188 | return -EINVAL; |
3189 | ||
41ade00f JB |
3190 | if (info->attrs[NL80211_ATTR_MAC]) |
3191 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3192 | ||
e31b8213 JB |
3193 | if (key.type == -1) { |
3194 | if (mac_addr) | |
3195 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3196 | else | |
3197 | key.type = NL80211_KEYTYPE_GROUP; | |
3198 | } | |
3199 | ||
3200 | /* for now */ | |
3201 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3202 | key.type != NL80211_KEYTYPE_GROUP) | |
3203 | return -EINVAL; | |
3204 | ||
4c476991 JB |
3205 | if (!rdev->ops->add_key) |
3206 | return -EOPNOTSUPP; | |
25e47c18 | 3207 | |
e31b8213 JB |
3208 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3209 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3210 | mac_addr)) | |
4c476991 | 3211 | return -EINVAL; |
41ade00f | 3212 | |
fffd0934 JB |
3213 | wdev_lock(dev->ieee80211_ptr); |
3214 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3215 | if (!err) | |
e35e4d28 HG |
3216 | err = rdev_add_key(rdev, dev, key.idx, |
3217 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3218 | mac_addr, &key.p); | |
fffd0934 | 3219 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3220 | |
41ade00f JB |
3221 | return err; |
3222 | } | |
3223 | ||
3224 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3225 | { | |
4c476991 | 3226 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3227 | int err; |
4c476991 | 3228 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3229 | u8 *mac_addr = NULL; |
b9454e83 | 3230 | struct key_parse key; |
41ade00f | 3231 | |
b9454e83 JB |
3232 | err = nl80211_parse_key(info, &key); |
3233 | if (err) | |
3234 | return err; | |
41ade00f JB |
3235 | |
3236 | if (info->attrs[NL80211_ATTR_MAC]) | |
3237 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3238 | ||
e31b8213 JB |
3239 | if (key.type == -1) { |
3240 | if (mac_addr) | |
3241 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3242 | else | |
3243 | key.type = NL80211_KEYTYPE_GROUP; | |
3244 | } | |
3245 | ||
3246 | /* for now */ | |
3247 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3248 | key.type != NL80211_KEYTYPE_GROUP) | |
3249 | return -EINVAL; | |
3250 | ||
4c476991 JB |
3251 | if (!rdev->ops->del_key) |
3252 | return -EOPNOTSUPP; | |
41ade00f | 3253 | |
fffd0934 JB |
3254 | wdev_lock(dev->ieee80211_ptr); |
3255 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 3256 | |
0fa7b391 | 3257 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
3258 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3259 | err = -ENOENT; | |
3260 | ||
fffd0934 | 3261 | if (!err) |
e35e4d28 HG |
3262 | err = rdev_del_key(rdev, dev, key.idx, |
3263 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3264 | mac_addr); | |
41ade00f | 3265 | |
3d23e349 | 3266 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3267 | if (!err) { |
b9454e83 | 3268 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3269 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3270 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3271 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3272 | } | |
3273 | #endif | |
fffd0934 | 3274 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3275 | |
41ade00f JB |
3276 | return err; |
3277 | } | |
3278 | ||
77765eaf VT |
3279 | /* This function returns an error or the number of nested attributes */ |
3280 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3281 | { | |
3282 | struct nlattr *attr; | |
3283 | int n_entries = 0, tmp; | |
3284 | ||
3285 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3286 | if (nla_len(attr) != ETH_ALEN) | |
3287 | return -EINVAL; | |
3288 | ||
3289 | n_entries++; | |
3290 | } | |
3291 | ||
3292 | return n_entries; | |
3293 | } | |
3294 | ||
3295 | /* | |
3296 | * This function parses ACL information and allocates memory for ACL data. | |
3297 | * On successful return, the calling function is responsible to free the | |
3298 | * ACL buffer returned by this function. | |
3299 | */ | |
3300 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3301 | struct genl_info *info) | |
3302 | { | |
3303 | enum nl80211_acl_policy acl_policy; | |
3304 | struct nlattr *attr; | |
3305 | struct cfg80211_acl_data *acl; | |
3306 | int i = 0, n_entries, tmp; | |
3307 | ||
3308 | if (!wiphy->max_acl_mac_addrs) | |
3309 | return ERR_PTR(-EOPNOTSUPP); | |
3310 | ||
3311 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3312 | return ERR_PTR(-EINVAL); | |
3313 | ||
3314 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3315 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3316 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3317 | return ERR_PTR(-EINVAL); | |
3318 | ||
3319 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3320 | return ERR_PTR(-EINVAL); | |
3321 | ||
3322 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3323 | if (n_entries < 0) | |
3324 | return ERR_PTR(n_entries); | |
3325 | ||
3326 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3327 | return ERR_PTR(-ENOTSUPP); | |
3328 | ||
3329 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3330 | GFP_KERNEL); | |
3331 | if (!acl) | |
3332 | return ERR_PTR(-ENOMEM); | |
3333 | ||
3334 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3335 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3336 | i++; | |
3337 | } | |
3338 | ||
3339 | acl->n_acl_entries = n_entries; | |
3340 | acl->acl_policy = acl_policy; | |
3341 | ||
3342 | return acl; | |
3343 | } | |
3344 | ||
3345 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3346 | { | |
3347 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3348 | struct net_device *dev = info->user_ptr[1]; | |
3349 | struct cfg80211_acl_data *acl; | |
3350 | int err; | |
3351 | ||
3352 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3353 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3354 | return -EOPNOTSUPP; | |
3355 | ||
3356 | if (!dev->ieee80211_ptr->beacon_interval) | |
3357 | return -EINVAL; | |
3358 | ||
3359 | acl = parse_acl_data(&rdev->wiphy, info); | |
3360 | if (IS_ERR(acl)) | |
3361 | return PTR_ERR(acl); | |
3362 | ||
3363 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3364 | ||
3365 | kfree(acl); | |
3366 | ||
3367 | return err; | |
3368 | } | |
3369 | ||
a7c7fbff PK |
3370 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
3371 | u8 *rates, u8 rates_len) | |
3372 | { | |
3373 | u8 i; | |
3374 | u32 mask = 0; | |
3375 | ||
3376 | for (i = 0; i < rates_len; i++) { | |
3377 | int rate = (rates[i] & 0x7f) * 5; | |
3378 | int ridx; | |
3379 | ||
3380 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
3381 | struct ieee80211_rate *srate = | |
3382 | &sband->bitrates[ridx]; | |
3383 | if (rate == srate->bitrate) { | |
3384 | mask |= 1 << ridx; | |
3385 | break; | |
3386 | } | |
3387 | } | |
3388 | if (ridx == sband->n_bitrates) | |
3389 | return 0; /* rate not found */ | |
3390 | } | |
3391 | ||
3392 | return mask; | |
3393 | } | |
3394 | ||
3395 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, | |
3396 | u8 *rates, u8 rates_len, | |
3397 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
3398 | { | |
3399 | u8 i; | |
3400 | ||
3401 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
3402 | ||
3403 | for (i = 0; i < rates_len; i++) { | |
3404 | int ridx, rbit; | |
3405 | ||
3406 | ridx = rates[i] / 8; | |
3407 | rbit = BIT(rates[i] % 8); | |
3408 | ||
3409 | /* check validity */ | |
3410 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) | |
3411 | return false; | |
3412 | ||
3413 | /* check availability */ | |
3414 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
3415 | mcs[ridx] |= rbit; | |
3416 | else | |
3417 | return false; | |
3418 | } | |
3419 | ||
3420 | return true; | |
3421 | } | |
3422 | ||
3423 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) | |
3424 | { | |
3425 | u16 mcs_mask = 0; | |
3426 | ||
3427 | switch (vht_mcs_map) { | |
3428 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
3429 | break; | |
3430 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
3431 | mcs_mask = 0x00FF; | |
3432 | break; | |
3433 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
3434 | mcs_mask = 0x01FF; | |
3435 | break; | |
3436 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
3437 | mcs_mask = 0x03FF; | |
3438 | break; | |
3439 | default: | |
3440 | break; | |
3441 | } | |
3442 | ||
3443 | return mcs_mask; | |
3444 | } | |
3445 | ||
3446 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
3447 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
3448 | { | |
3449 | u8 nss; | |
3450 | ||
3451 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
3452 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
3453 | vht_mcs_map >>= 2; | |
3454 | } | |
3455 | } | |
3456 | ||
3457 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
3458 | struct nl80211_txrate_vht *txrate, | |
3459 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
3460 | { | |
3461 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
3462 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
3463 | u8 i; | |
3464 | ||
3465 | if (!sband->vht_cap.vht_supported) | |
3466 | return false; | |
3467 | ||
3468 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
3469 | ||
3470 | /* Build vht_mcs_mask from VHT capabilities */ | |
3471 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
3472 | ||
3473 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
3474 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
3475 | mcs[i] = txrate->mcs[i]; | |
3476 | else | |
3477 | return false; | |
3478 | } | |
3479 | ||
3480 | return true; | |
3481 | } | |
3482 | ||
3483 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { | |
3484 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, | |
3485 | .len = NL80211_MAX_SUPP_RATES }, | |
3486 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, | |
3487 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
3488 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, | |
3489 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, | |
3490 | }; | |
3491 | ||
3492 | static int nl80211_parse_tx_bitrate_mask(struct genl_info *info, | |
3493 | struct cfg80211_bitrate_mask *mask) | |
3494 | { | |
3495 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
3496 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3497 | int rem, i; | |
3498 | struct nlattr *tx_rates; | |
3499 | struct ieee80211_supported_band *sband; | |
3500 | u16 vht_tx_mcs_map; | |
3501 | ||
3502 | memset(mask, 0, sizeof(*mask)); | |
3503 | /* Default to all rates enabled */ | |
3504 | for (i = 0; i < NUM_NL80211_BANDS; i++) { | |
3505 | sband = rdev->wiphy.bands[i]; | |
3506 | ||
3507 | if (!sband) | |
3508 | continue; | |
3509 | ||
3510 | mask->control[i].legacy = (1 << sband->n_bitrates) - 1; | |
3511 | memcpy(mask->control[i].ht_mcs, | |
3512 | sband->ht_cap.mcs.rx_mask, | |
3513 | sizeof(mask->control[i].ht_mcs)); | |
3514 | ||
3515 | if (!sband->vht_cap.vht_supported) | |
3516 | continue; | |
3517 | ||
3518 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
3519 | vht_build_mcs_mask(vht_tx_mcs_map, mask->control[i].vht_mcs); | |
3520 | } | |
3521 | ||
3522 | /* if no rates are given set it back to the defaults */ | |
3523 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
3524 | goto out; | |
3525 | ||
3526 | /* The nested attribute uses enum nl80211_band as the index. This maps | |
3527 | * directly to the enum nl80211_band values used in cfg80211. | |
3528 | */ | |
3529 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); | |
3530 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { | |
3531 | enum nl80211_band band = nla_type(tx_rates); | |
3532 | int err; | |
3533 | ||
3534 | if (band < 0 || band >= NUM_NL80211_BANDS) | |
3535 | return -EINVAL; | |
3536 | sband = rdev->wiphy.bands[band]; | |
3537 | if (sband == NULL) | |
3538 | return -EINVAL; | |
3539 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), | |
3540 | nla_len(tx_rates), nl80211_txattr_policy); | |
3541 | if (err) | |
3542 | return err; | |
3543 | if (tb[NL80211_TXRATE_LEGACY]) { | |
3544 | mask->control[band].legacy = rateset_to_mask( | |
3545 | sband, | |
3546 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
3547 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
3548 | if ((mask->control[band].legacy == 0) && | |
3549 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
3550 | return -EINVAL; | |
3551 | } | |
3552 | if (tb[NL80211_TXRATE_HT]) { | |
3553 | if (!ht_rateset_to_mask( | |
3554 | sband, | |
3555 | nla_data(tb[NL80211_TXRATE_HT]), | |
3556 | nla_len(tb[NL80211_TXRATE_HT]), | |
3557 | mask->control[band].ht_mcs)) | |
3558 | return -EINVAL; | |
3559 | } | |
3560 | if (tb[NL80211_TXRATE_VHT]) { | |
3561 | if (!vht_set_mcs_mask( | |
3562 | sband, | |
3563 | nla_data(tb[NL80211_TXRATE_VHT]), | |
3564 | mask->control[band].vht_mcs)) | |
3565 | return -EINVAL; | |
3566 | } | |
3567 | if (tb[NL80211_TXRATE_GI]) { | |
3568 | mask->control[band].gi = | |
3569 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
3570 | if (mask->control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
3571 | return -EINVAL; | |
3572 | } | |
3573 | ||
3574 | if (mask->control[band].legacy == 0) { | |
3575 | /* don't allow empty legacy rates if HT or VHT | |
3576 | * are not even supported. | |
3577 | */ | |
3578 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
3579 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
3580 | return -EINVAL; | |
3581 | ||
3582 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
3583 | if (mask->control[band].ht_mcs[i]) | |
3584 | goto out; | |
3585 | ||
3586 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
3587 | if (mask->control[band].vht_mcs[i]) | |
3588 | goto out; | |
3589 | ||
3590 | /* legacy and mcs rates may not be both empty */ | |
3591 | return -EINVAL; | |
3592 | } | |
3593 | } | |
3594 | ||
3595 | out: | |
3596 | return 0; | |
3597 | } | |
3598 | ||
8564e382 JB |
3599 | static int validate_beacon_tx_rate(struct cfg80211_registered_device *rdev, |
3600 | enum nl80211_band band, | |
3601 | struct cfg80211_bitrate_mask *beacon_rate) | |
a7c7fbff | 3602 | { |
8564e382 JB |
3603 | u32 count_ht, count_vht, i; |
3604 | u32 rate = beacon_rate->control[band].legacy; | |
a7c7fbff PK |
3605 | |
3606 | /* Allow only one rate */ | |
3607 | if (hweight32(rate) > 1) | |
3608 | return -EINVAL; | |
3609 | ||
3610 | count_ht = 0; | |
3611 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) { | |
8564e382 | 3612 | if (hweight8(beacon_rate->control[band].ht_mcs[i]) > 1) { |
a7c7fbff | 3613 | return -EINVAL; |
8564e382 | 3614 | } else if (beacon_rate->control[band].ht_mcs[i]) { |
a7c7fbff PK |
3615 | count_ht++; |
3616 | if (count_ht > 1) | |
3617 | return -EINVAL; | |
3618 | } | |
3619 | if (count_ht && rate) | |
3620 | return -EINVAL; | |
3621 | } | |
3622 | ||
3623 | count_vht = 0; | |
3624 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8564e382 | 3625 | if (hweight16(beacon_rate->control[band].vht_mcs[i]) > 1) { |
a7c7fbff | 3626 | return -EINVAL; |
8564e382 | 3627 | } else if (beacon_rate->control[band].vht_mcs[i]) { |
a7c7fbff PK |
3628 | count_vht++; |
3629 | if (count_vht > 1) | |
3630 | return -EINVAL; | |
3631 | } | |
3632 | if (count_vht && rate) | |
3633 | return -EINVAL; | |
3634 | } | |
3635 | ||
3636 | if ((count_ht && count_vht) || (!rate && !count_ht && !count_vht)) | |
3637 | return -EINVAL; | |
3638 | ||
8564e382 JB |
3639 | if (rate && |
3640 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3641 | NL80211_EXT_FEATURE_BEACON_RATE_LEGACY)) | |
3642 | return -EINVAL; | |
3643 | if (count_ht && | |
3644 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3645 | NL80211_EXT_FEATURE_BEACON_RATE_HT)) | |
3646 | return -EINVAL; | |
3647 | if (count_vht && | |
3648 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
3649 | NL80211_EXT_FEATURE_BEACON_RATE_VHT)) | |
3650 | return -EINVAL; | |
3651 | ||
a7c7fbff PK |
3652 | return 0; |
3653 | } | |
3654 | ||
a1193be8 | 3655 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3656 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3657 | { |
8860020e | 3658 | bool haveinfo = false; |
ed1b6cc7 | 3659 | |
a1193be8 SW |
3660 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3661 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3662 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3663 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3664 | return -EINVAL; |
3665 | ||
8860020e | 3666 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3667 | |
a1193be8 SW |
3668 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3669 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3670 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3671 | if (!bcn->head_len) |
3672 | return -EINVAL; | |
3673 | haveinfo = true; | |
ed1b6cc7 JB |
3674 | } |
3675 | ||
a1193be8 SW |
3676 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3677 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3678 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3679 | haveinfo = true; |
ed1b6cc7 JB |
3680 | } |
3681 | ||
4c476991 JB |
3682 | if (!haveinfo) |
3683 | return -EINVAL; | |
3b85875a | 3684 | |
a1193be8 SW |
3685 | if (attrs[NL80211_ATTR_IE]) { |
3686 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3687 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3688 | } |
3689 | ||
a1193be8 | 3690 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3691 | bcn->proberesp_ies = |
a1193be8 | 3692 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3693 | bcn->proberesp_ies_len = |
a1193be8 | 3694 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3695 | } |
3696 | ||
a1193be8 | 3697 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3698 | bcn->assocresp_ies = |
a1193be8 | 3699 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3700 | bcn->assocresp_ies_len = |
a1193be8 | 3701 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3702 | } |
3703 | ||
a1193be8 SW |
3704 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3705 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3706 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3707 | } |
3708 | ||
8860020e JB |
3709 | return 0; |
3710 | } | |
3711 | ||
46c1dd0c FF |
3712 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3713 | struct cfg80211_ap_settings *params) | |
3714 | { | |
3715 | struct wireless_dev *wdev; | |
3716 | bool ret = false; | |
3717 | ||
53873f13 | 3718 | list_for_each_entry(wdev, &rdev->wiphy.wdev_list, list) { |
46c1dd0c FF |
3719 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3720 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3721 | continue; | |
3722 | ||
683b6d3b | 3723 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3724 | continue; |
3725 | ||
683b6d3b | 3726 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3727 | ret = true; |
3728 | break; | |
3729 | } | |
3730 | ||
46c1dd0c FF |
3731 | return ret; |
3732 | } | |
3733 | ||
e39e5b5e JM |
3734 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3735 | enum nl80211_auth_type auth_type, | |
3736 | enum nl80211_commands cmd) | |
3737 | { | |
3738 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3739 | return false; | |
3740 | ||
3741 | switch (cmd) { | |
3742 | case NL80211_CMD_AUTHENTICATE: | |
3743 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3744 | auth_type == NL80211_AUTHTYPE_SAE) | |
3745 | return false; | |
3746 | return true; | |
3747 | case NL80211_CMD_CONNECT: | |
3748 | case NL80211_CMD_START_AP: | |
3749 | /* SAE not supported yet */ | |
3750 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3751 | return false; | |
3752 | return true; | |
3753 | default: | |
3754 | return false; | |
3755 | } | |
3756 | } | |
3757 | ||
8860020e JB |
3758 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3759 | { | |
3760 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3761 | struct net_device *dev = info->user_ptr[1]; | |
3762 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3763 | struct cfg80211_ap_settings params; | |
3764 | int err; | |
3765 | ||
3766 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3767 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3768 | return -EOPNOTSUPP; | |
3769 | ||
3770 | if (!rdev->ops->start_ap) | |
3771 | return -EOPNOTSUPP; | |
3772 | ||
3773 | if (wdev->beacon_interval) | |
3774 | return -EALREADY; | |
3775 | ||
3776 | memset(¶ms, 0, sizeof(params)); | |
3777 | ||
3778 | /* these are required for START_AP */ | |
3779 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3780 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3781 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3782 | return -EINVAL; | |
3783 | ||
a1193be8 | 3784 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3785 | if (err) |
3786 | return err; | |
3787 | ||
3788 | params.beacon_interval = | |
3789 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3790 | params.dtim_period = | |
3791 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3792 | ||
3793 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3794 | if (err) | |
3795 | return err; | |
3796 | ||
3797 | /* | |
3798 | * In theory, some of these attributes should be required here | |
3799 | * but since they were not used when the command was originally | |
3800 | * added, keep them optional for old user space programs to let | |
3801 | * them continue to work with drivers that do not need the | |
3802 | * additional information -- drivers must check! | |
3803 | */ | |
3804 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3805 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3806 | params.ssid_len = | |
3807 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3808 | if (params.ssid_len == 0 || | |
3809 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3810 | return -EINVAL; | |
3811 | } | |
3812 | ||
3813 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3814 | params.hidden_ssid = nla_get_u32( | |
3815 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3816 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3817 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3818 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3819 | return -EINVAL; | |
3820 | } | |
3821 | ||
3822 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3823 | ||
3824 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3825 | params.auth_type = nla_get_u32( | |
3826 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3827 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3828 | NL80211_CMD_START_AP)) | |
8860020e JB |
3829 | return -EINVAL; |
3830 | } else | |
3831 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3832 | ||
3833 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3834 | NL80211_MAX_NR_CIPHER_SUITES); | |
3835 | if (err) | |
3836 | return err; | |
3837 | ||
1b658f11 VT |
3838 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3839 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3840 | return -EOPNOTSUPP; | |
3841 | params.inactivity_timeout = nla_get_u16( | |
3842 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3843 | } | |
3844 | ||
53cabad7 JB |
3845 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3846 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3847 | return -EINVAL; | |
3848 | params.p2p_ctwindow = | |
3849 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3850 | if (params.p2p_ctwindow > 127) | |
3851 | return -EINVAL; | |
3852 | if (params.p2p_ctwindow != 0 && | |
3853 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3854 | return -EINVAL; | |
3855 | } | |
3856 | ||
3857 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3858 | u8 tmp; | |
3859 | ||
3860 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3861 | return -EINVAL; | |
3862 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3863 | if (tmp > 1) | |
3864 | return -EINVAL; | |
3865 | params.p2p_opp_ps = tmp; | |
3866 | if (params.p2p_opp_ps != 0 && | |
3867 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3868 | return -EINVAL; | |
3869 | } | |
3870 | ||
aa430da4 | 3871 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3872 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3873 | if (err) | |
3874 | return err; | |
3875 | } else if (wdev->preset_chandef.chan) { | |
3876 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3877 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3878 | return -EINVAL; |
3879 | ||
923b352f AN |
3880 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
3881 | wdev->iftype)) | |
aa430da4 JB |
3882 | return -EINVAL; |
3883 | ||
a7c7fbff PK |
3884 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
3885 | err = nl80211_parse_tx_bitrate_mask(info, ¶ms.beacon_rate); | |
3886 | if (err) | |
3887 | return err; | |
3888 | ||
8564e382 JB |
3889 | err = validate_beacon_tx_rate(rdev, params.chandef.chan->band, |
3890 | ¶ms.beacon_rate); | |
a7c7fbff PK |
3891 | if (err) |
3892 | return err; | |
3893 | } | |
3894 | ||
18998c38 EP |
3895 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3896 | params.smps_mode = | |
3897 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3898 | switch (params.smps_mode) { | |
3899 | case NL80211_SMPS_OFF: | |
3900 | break; | |
3901 | case NL80211_SMPS_STATIC: | |
3902 | if (!(rdev->wiphy.features & | |
3903 | NL80211_FEATURE_STATIC_SMPS)) | |
3904 | return -EINVAL; | |
3905 | break; | |
3906 | case NL80211_SMPS_DYNAMIC: | |
3907 | if (!(rdev->wiphy.features & | |
3908 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3909 | return -EINVAL; | |
3910 | break; | |
3911 | default: | |
3912 | return -EINVAL; | |
3913 | } | |
3914 | } else { | |
3915 | params.smps_mode = NL80211_SMPS_OFF; | |
3916 | } | |
3917 | ||
6e8ef842 PK |
3918 | params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
3919 | if (params.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) | |
3920 | return -EOPNOTSUPP; | |
3921 | ||
4baf6bea OO |
3922 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3923 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3924 | if (IS_ERR(params.acl)) | |
3925 | return PTR_ERR(params.acl); | |
3926 | } | |
3927 | ||
c56589ed | 3928 | wdev_lock(wdev); |
e35e4d28 | 3929 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3930 | if (!err) { |
683b6d3b | 3931 | wdev->preset_chandef = params.chandef; |
8860020e | 3932 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3933 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3934 | wdev->ssid_len = params.ssid_len; |
3935 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3936 | } |
c56589ed | 3937 | wdev_unlock(wdev); |
77765eaf VT |
3938 | |
3939 | kfree(params.acl); | |
3940 | ||
56d1893d | 3941 | return err; |
ed1b6cc7 JB |
3942 | } |
3943 | ||
8860020e JB |
3944 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3945 | { | |
3946 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3947 | struct net_device *dev = info->user_ptr[1]; | |
3948 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3949 | struct cfg80211_beacon_data params; | |
3950 | int err; | |
3951 | ||
3952 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3953 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3954 | return -EOPNOTSUPP; | |
3955 | ||
3956 | if (!rdev->ops->change_beacon) | |
3957 | return -EOPNOTSUPP; | |
3958 | ||
3959 | if (!wdev->beacon_interval) | |
3960 | return -EINVAL; | |
3961 | ||
a1193be8 | 3962 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3963 | if (err) |
3964 | return err; | |
3965 | ||
c56589ed SW |
3966 | wdev_lock(wdev); |
3967 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3968 | wdev_unlock(wdev); | |
3969 | ||
3970 | return err; | |
8860020e JB |
3971 | } |
3972 | ||
3973 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3974 | { |
4c476991 JB |
3975 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3976 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3977 | |
7c8d5e03 | 3978 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3979 | } |
3980 | ||
5727ef1b JB |
3981 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3982 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3983 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3984 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3985 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3986 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3987 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3988 | }; |
3989 | ||
eccb8e8f | 3990 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3991 | enum nl80211_iftype iftype, |
eccb8e8f | 3992 | struct station_parameters *params) |
5727ef1b JB |
3993 | { |
3994 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3995 | struct nlattr *nla; |
5727ef1b JB |
3996 | int flag; |
3997 | ||
eccb8e8f JB |
3998 | /* |
3999 | * Try parsing the new attribute first so userspace | |
4000 | * can specify both for older kernels. | |
4001 | */ | |
4002 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
4003 | if (nla) { | |
4004 | struct nl80211_sta_flag_update *sta_flags; | |
4005 | ||
4006 | sta_flags = nla_data(nla); | |
4007 | params->sta_flags_mask = sta_flags->mask; | |
4008 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 4009 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
4010 | if ((params->sta_flags_mask | |
4011 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
4012 | return -EINVAL; | |
4013 | return 0; | |
4014 | } | |
4015 | ||
4016 | /* if present, parse the old attribute */ | |
5727ef1b | 4017 | |
eccb8e8f | 4018 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
4019 | if (!nla) |
4020 | return 0; | |
4021 | ||
4022 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
4023 | nla, sta_flags_policy)) | |
4024 | return -EINVAL; | |
4025 | ||
bdd3ae3d JB |
4026 | /* |
4027 | * Only allow certain flags for interface types so that | |
4028 | * other attributes are silently ignored. Remember that | |
4029 | * this is backward compatibility code with old userspace | |
4030 | * and shouldn't be hit in other cases anyway. | |
4031 | */ | |
4032 | switch (iftype) { | |
4033 | case NL80211_IFTYPE_AP: | |
4034 | case NL80211_IFTYPE_AP_VLAN: | |
4035 | case NL80211_IFTYPE_P2P_GO: | |
4036 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4037 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4038 | BIT(NL80211_STA_FLAG_WME) | | |
4039 | BIT(NL80211_STA_FLAG_MFP); | |
4040 | break; | |
4041 | case NL80211_IFTYPE_P2P_CLIENT: | |
4042 | case NL80211_IFTYPE_STATION: | |
4043 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4044 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4045 | break; | |
4046 | case NL80211_IFTYPE_MESH_POINT: | |
4047 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4048 | BIT(NL80211_STA_FLAG_MFP) | | |
4049 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
4050 | default: | |
4051 | return -EINVAL; | |
4052 | } | |
5727ef1b | 4053 | |
3383b5a6 JB |
4054 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
4055 | if (flags[flag]) { | |
eccb8e8f | 4056 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 4057 | |
3383b5a6 JB |
4058 | /* no longer support new API additions in old API */ |
4059 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
4060 | return -EINVAL; | |
4061 | } | |
4062 | } | |
4063 | ||
5727ef1b JB |
4064 | return 0; |
4065 | } | |
4066 | ||
c8dcfd8a FF |
4067 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
4068 | int attr) | |
4069 | { | |
4070 | struct nlattr *rate; | |
8eb41c8d VK |
4071 | u32 bitrate; |
4072 | u16 bitrate_compat; | |
b51f3bee | 4073 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
4074 | |
4075 | rate = nla_nest_start(msg, attr); | |
4076 | if (!rate) | |
db9c64cf | 4077 | return false; |
c8dcfd8a FF |
4078 | |
4079 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
4080 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
4081 | /* report 16-bit bitrate only if we can */ |
4082 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
4083 | if (bitrate > 0 && |
4084 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
4085 | return false; | |
4086 | if (bitrate_compat > 0 && | |
4087 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
4088 | return false; | |
4089 | ||
b51f3bee JB |
4090 | switch (info->bw) { |
4091 | case RATE_INFO_BW_5: | |
4092 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
4093 | break; | |
4094 | case RATE_INFO_BW_10: | |
4095 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
4096 | break; | |
4097 | default: | |
4098 | WARN_ON(1); | |
4099 | /* fall through */ | |
4100 | case RATE_INFO_BW_20: | |
4101 | rate_flg = 0; | |
4102 | break; | |
4103 | case RATE_INFO_BW_40: | |
4104 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
4105 | break; | |
4106 | case RATE_INFO_BW_80: | |
4107 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
4108 | break; | |
4109 | case RATE_INFO_BW_160: | |
4110 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
4111 | break; | |
4112 | } | |
4113 | ||
4114 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
4115 | return false; | |
4116 | ||
db9c64cf JB |
4117 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
4118 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
4119 | return false; | |
db9c64cf JB |
4120 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4121 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4122 | return false; | |
4123 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
4124 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
4125 | return false; | |
4126 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
4127 | return false; | |
db9c64cf JB |
4128 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
4129 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
4130 | return false; | |
4131 | } | |
c8dcfd8a FF |
4132 | |
4133 | nla_nest_end(msg, rate); | |
4134 | return true; | |
c8dcfd8a FF |
4135 | } |
4136 | ||
119363c7 FF |
4137 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
4138 | int id) | |
4139 | { | |
4140 | void *attr; | |
4141 | int i = 0; | |
4142 | ||
4143 | if (!mask) | |
4144 | return true; | |
4145 | ||
4146 | attr = nla_nest_start(msg, id); | |
4147 | if (!attr) | |
4148 | return false; | |
4149 | ||
4150 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
4151 | if (!(mask & BIT(i))) | |
4152 | continue; | |
4153 | ||
4154 | if (nla_put_u8(msg, i, signal[i])) | |
4155 | return false; | |
4156 | } | |
4157 | ||
4158 | nla_nest_end(msg, attr); | |
4159 | ||
4160 | return true; | |
4161 | } | |
4162 | ||
cf5ead82 JB |
4163 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
4164 | u32 seq, int flags, | |
66266b3a JL |
4165 | struct cfg80211_registered_device *rdev, |
4166 | struct net_device *dev, | |
98b62183 | 4167 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
4168 | { |
4169 | void *hdr; | |
f4263c98 | 4170 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 4171 | |
cf5ead82 | 4172 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
4173 | if (!hdr) |
4174 | return -1; | |
4175 | ||
9360ffd1 DM |
4176 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4177 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
4178 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
4179 | goto nla_put_failure; | |
f5ea9120 | 4180 | |
2ec600d6 LCC |
4181 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
4182 | if (!sinfoattr) | |
fd5b74dc | 4183 | goto nla_put_failure; |
319090bf JB |
4184 | |
4185 | #define PUT_SINFO(attr, memb, type) do { \ | |
d686b920 | 4186 | BUILD_BUG_ON(sizeof(type) == sizeof(u64)); \ |
739960f1 | 4187 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ |
319090bf JB |
4188 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ |
4189 | sinfo->memb)) \ | |
4190 | goto nla_put_failure; \ | |
4191 | } while (0) | |
d686b920 JB |
4192 | #define PUT_SINFO_U64(attr, memb) do { \ |
4193 | if (sinfo->filled & (1ULL << NL80211_STA_INFO_ ## attr) && \ | |
4194 | nla_put_u64_64bit(msg, NL80211_STA_INFO_ ## attr, \ | |
4195 | sinfo->memb, NL80211_STA_INFO_PAD)) \ | |
4196 | goto nla_put_failure; \ | |
4197 | } while (0) | |
319090bf JB |
4198 | |
4199 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
4200 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
4201 | ||
4202 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
4203 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 4204 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 4205 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 4206 | goto nla_put_failure; |
319090bf JB |
4207 | |
4208 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
4209 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 4210 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
4211 | (u32)sinfo->tx_bytes)) |
4212 | goto nla_put_failure; | |
319090bf | 4213 | |
d686b920 JB |
4214 | PUT_SINFO_U64(RX_BYTES64, rx_bytes); |
4215 | PUT_SINFO_U64(TX_BYTES64, tx_bytes); | |
319090bf JB |
4216 | PUT_SINFO(LLID, llid, u16); |
4217 | PUT_SINFO(PLID, plid, u16); | |
4218 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
d686b920 | 4219 | PUT_SINFO_U64(RX_DURATION, rx_duration); |
319090bf | 4220 | |
66266b3a JL |
4221 | switch (rdev->wiphy.signal_type) { |
4222 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
4223 | PUT_SINFO(SIGNAL, signal, u8); |
4224 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
4225 | break; |
4226 | default: | |
4227 | break; | |
4228 | } | |
319090bf | 4229 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
4230 | if (!nl80211_put_signal(msg, sinfo->chains, |
4231 | sinfo->chain_signal, | |
4232 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
4233 | goto nla_put_failure; | |
4234 | } | |
319090bf | 4235 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
4236 | if (!nl80211_put_signal(msg, sinfo->chains, |
4237 | sinfo->chain_signal_avg, | |
4238 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
4239 | goto nla_put_failure; | |
4240 | } | |
319090bf | 4241 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
4242 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
4243 | NL80211_STA_INFO_TX_BITRATE)) | |
4244 | goto nla_put_failure; | |
4245 | } | |
319090bf | 4246 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
4247 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
4248 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 4249 | goto nla_put_failure; |
420e7fab | 4250 | } |
319090bf JB |
4251 | |
4252 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
4253 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
4254 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
4255 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
4256 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
4257 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
4258 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
4259 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
4260 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
4261 | ||
4262 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
4263 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
4264 | if (!bss_param) | |
4265 | goto nla_put_failure; | |
4266 | ||
9360ffd1 DM |
4267 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
4268 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
4269 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
4270 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
4271 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
4272 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
4273 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
4274 | sinfo->bss_param.dtim_period) || | |
4275 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
4276 | sinfo->bss_param.beacon_interval)) | |
4277 | goto nla_put_failure; | |
f4263c98 PS |
4278 | |
4279 | nla_nest_end(msg, bss_param); | |
4280 | } | |
319090bf | 4281 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
4282 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
4283 | sizeof(struct nl80211_sta_flag_update), | |
4284 | &sinfo->sta_flags)) | |
4285 | goto nla_put_failure; | |
319090bf | 4286 | |
d686b920 JB |
4287 | PUT_SINFO_U64(T_OFFSET, t_offset); |
4288 | PUT_SINFO_U64(RX_DROP_MISC, rx_dropped_misc); | |
4289 | PUT_SINFO_U64(BEACON_RX, rx_beacon); | |
a76b1942 | 4290 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); |
319090bf JB |
4291 | |
4292 | #undef PUT_SINFO | |
d686b920 | 4293 | #undef PUT_SINFO_U64 |
6de39808 JB |
4294 | |
4295 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
4296 | struct nlattr *tidsattr; | |
4297 | int tid; | |
4298 | ||
4299 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
4300 | if (!tidsattr) | |
4301 | goto nla_put_failure; | |
4302 | ||
4303 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
4304 | struct cfg80211_tid_stats *tidstats; | |
4305 | struct nlattr *tidattr; | |
4306 | ||
4307 | tidstats = &sinfo->pertid[tid]; | |
4308 | ||
4309 | if (!tidstats->filled) | |
4310 | continue; | |
4311 | ||
4312 | tidattr = nla_nest_start(msg, tid + 1); | |
4313 | if (!tidattr) | |
4314 | goto nla_put_failure; | |
4315 | ||
d686b920 | 4316 | #define PUT_TIDVAL_U64(attr, memb) do { \ |
6de39808 | 4317 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ |
d686b920 JB |
4318 | nla_put_u64_64bit(msg, NL80211_TID_STATS_ ## attr, \ |
4319 | tidstats->memb, NL80211_TID_STATS_PAD)) \ | |
6de39808 JB |
4320 | goto nla_put_failure; \ |
4321 | } while (0) | |
4322 | ||
d686b920 JB |
4323 | PUT_TIDVAL_U64(RX_MSDU, rx_msdu); |
4324 | PUT_TIDVAL_U64(TX_MSDU, tx_msdu); | |
4325 | PUT_TIDVAL_U64(TX_MSDU_RETRIES, tx_msdu_retries); | |
4326 | PUT_TIDVAL_U64(TX_MSDU_FAILED, tx_msdu_failed); | |
6de39808 | 4327 | |
d686b920 | 4328 | #undef PUT_TIDVAL_U64 |
6de39808 JB |
4329 | nla_nest_end(msg, tidattr); |
4330 | } | |
4331 | ||
4332 | nla_nest_end(msg, tidsattr); | |
4333 | } | |
4334 | ||
2ec600d6 | 4335 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 4336 | |
319090bf | 4337 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
4338 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
4339 | sinfo->assoc_req_ies)) | |
4340 | goto nla_put_failure; | |
50d3dfb7 | 4341 | |
053c095a JB |
4342 | genlmsg_end(msg, hdr); |
4343 | return 0; | |
fd5b74dc JB |
4344 | |
4345 | nla_put_failure: | |
bc3ed28c TG |
4346 | genlmsg_cancel(msg, hdr); |
4347 | return -EMSGSIZE; | |
fd5b74dc JB |
4348 | } |
4349 | ||
2ec600d6 | 4350 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 4351 | struct netlink_callback *cb) |
2ec600d6 | 4352 | { |
2ec600d6 | 4353 | struct station_info sinfo; |
1b8ec87a | 4354 | struct cfg80211_registered_device *rdev; |
97990a06 | 4355 | struct wireless_dev *wdev; |
2ec600d6 | 4356 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 4357 | int sta_idx = cb->args[2]; |
2ec600d6 | 4358 | int err; |
2ec600d6 | 4359 | |
1b8ec87a | 4360 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4361 | if (err) |
4362 | return err; | |
bba95fef | 4363 | |
97990a06 JB |
4364 | if (!wdev->netdev) { |
4365 | err = -EINVAL; | |
4366 | goto out_err; | |
4367 | } | |
4368 | ||
1b8ec87a | 4369 | if (!rdev->ops->dump_station) { |
eec60b03 | 4370 | err = -EOPNOTSUPP; |
bba95fef JB |
4371 | goto out_err; |
4372 | } | |
4373 | ||
bba95fef | 4374 | while (1) { |
f612cedf | 4375 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 4376 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 4377 | mac_addr, &sinfo); |
bba95fef JB |
4378 | if (err == -ENOENT) |
4379 | break; | |
4380 | if (err) | |
3b85875a | 4381 | goto out_err; |
bba95fef | 4382 | |
cf5ead82 | 4383 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 4384 | NETLINK_CB(cb->skb).portid, |
bba95fef | 4385 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 4386 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
4387 | &sinfo) < 0) |
4388 | goto out; | |
4389 | ||
4390 | sta_idx++; | |
4391 | } | |
4392 | ||
bba95fef | 4393 | out: |
97990a06 | 4394 | cb->args[2] = sta_idx; |
bba95fef | 4395 | err = skb->len; |
bba95fef | 4396 | out_err: |
1b8ec87a | 4397 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
4398 | |
4399 | return err; | |
2ec600d6 | 4400 | } |
fd5b74dc | 4401 | |
5727ef1b JB |
4402 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
4403 | { | |
4c476991 JB |
4404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4405 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 4406 | struct station_info sinfo; |
fd5b74dc JB |
4407 | struct sk_buff *msg; |
4408 | u8 *mac_addr = NULL; | |
4c476991 | 4409 | int err; |
fd5b74dc | 4410 | |
2ec600d6 | 4411 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
4412 | |
4413 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4414 | return -EINVAL; | |
4415 | ||
4416 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4417 | ||
4c476991 JB |
4418 | if (!rdev->ops->get_station) |
4419 | return -EOPNOTSUPP; | |
3b85875a | 4420 | |
e35e4d28 | 4421 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 4422 | if (err) |
4c476991 | 4423 | return err; |
2ec600d6 | 4424 | |
fd2120ca | 4425 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 4426 | if (!msg) |
4c476991 | 4427 | return -ENOMEM; |
fd5b74dc | 4428 | |
cf5ead82 JB |
4429 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
4430 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 4431 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
4432 | nlmsg_free(msg); |
4433 | return -ENOBUFS; | |
4434 | } | |
3b85875a | 4435 | |
4c476991 | 4436 | return genlmsg_reply(msg, info); |
5727ef1b JB |
4437 | } |
4438 | ||
77ee7c89 JB |
4439 | int cfg80211_check_station_change(struct wiphy *wiphy, |
4440 | struct station_parameters *params, | |
4441 | enum cfg80211_station_type statype) | |
4442 | { | |
e4208427 AB |
4443 | if (params->listen_interval != -1 && |
4444 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 | 4445 | return -EINVAL; |
e4208427 | 4446 | |
17b94247 AB |
4447 | if (params->support_p2p_ps != -1 && |
4448 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
4449 | return -EINVAL; | |
4450 | ||
c72e1140 | 4451 | if (params->aid && |
e4208427 AB |
4452 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) && |
4453 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) | |
77ee7c89 JB |
4454 | return -EINVAL; |
4455 | ||
4456 | /* When you run into this, adjust the code below for the new flag */ | |
4457 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4458 | ||
4459 | switch (statype) { | |
eef941e6 TP |
4460 | case CFG80211_STA_MESH_PEER_KERNEL: |
4461 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
4462 | /* |
4463 | * No ignoring the TDLS flag here -- the userspace mesh | |
4464 | * code doesn't have the bug of including TDLS in the | |
4465 | * mask everywhere. | |
4466 | */ | |
4467 | if (params->sta_flags_mask & | |
4468 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4469 | BIT(NL80211_STA_FLAG_MFP) | | |
4470 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4471 | return -EINVAL; | |
4472 | break; | |
4473 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4474 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4475 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4476 | return -EINVAL; | |
4477 | /* ignore since it can't change */ | |
4478 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4479 | break; | |
4480 | default: | |
4481 | /* disallow mesh-specific things */ | |
4482 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
4483 | return -EINVAL; | |
4484 | if (params->local_pm) | |
4485 | return -EINVAL; | |
4486 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
4487 | return -EINVAL; | |
4488 | } | |
4489 | ||
4490 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
4491 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
4492 | /* TDLS can't be set, ... */ | |
4493 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
4494 | return -EINVAL; | |
4495 | /* | |
4496 | * ... but don't bother the driver with it. This works around | |
4497 | * a hostapd/wpa_supplicant issue -- it always includes the | |
4498 | * TLDS_PEER flag in the mask even for AP mode. | |
4499 | */ | |
4500 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
4501 | } | |
4502 | ||
47edb11b AB |
4503 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && |
4504 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4505 | /* reject other things that can't change */ |
4506 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
4507 | return -EINVAL; | |
4508 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4509 | return -EINVAL; | |
4510 | if (params->supported_rates) | |
4511 | return -EINVAL; | |
4512 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4513 | return -EINVAL; | |
4514 | } | |
4515 | ||
47edb11b AB |
4516 | if (statype != CFG80211_STA_AP_CLIENT && |
4517 | statype != CFG80211_STA_AP_CLIENT_UNASSOC) { | |
77ee7c89 JB |
4518 | if (params->vlan) |
4519 | return -EINVAL; | |
4520 | } | |
4521 | ||
4522 | switch (statype) { | |
4523 | case CFG80211_STA_AP_MLME_CLIENT: | |
4524 | /* Use this only for authorizing/unauthorizing a station */ | |
4525 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4526 | return -EOPNOTSUPP; | |
4527 | break; | |
4528 | case CFG80211_STA_AP_CLIENT: | |
47edb11b | 4529 | case CFG80211_STA_AP_CLIENT_UNASSOC: |
77ee7c89 JB |
4530 | /* accept only the listed bits */ |
4531 | if (params->sta_flags_mask & | |
4532 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4533 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4534 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4535 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4536 | BIT(NL80211_STA_FLAG_WME) | | |
4537 | BIT(NL80211_STA_FLAG_MFP))) | |
4538 | return -EINVAL; | |
4539 | ||
4540 | /* but authenticated/associated only if driver handles it */ | |
4541 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4542 | params->sta_flags_mask & | |
4543 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4544 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4545 | return -EINVAL; | |
4546 | break; | |
4547 | case CFG80211_STA_IBSS: | |
4548 | case CFG80211_STA_AP_STA: | |
4549 | /* reject any changes other than AUTHORIZED */ | |
4550 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4551 | return -EINVAL; | |
4552 | break; | |
4553 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4554 | /* reject any changes other than AUTHORIZED or WME */ | |
4555 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4556 | BIT(NL80211_STA_FLAG_WME))) | |
4557 | return -EINVAL; | |
4558 | /* force (at least) rates when authorizing */ | |
4559 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4560 | !params->supported_rates) | |
4561 | return -EINVAL; | |
4562 | break; | |
4563 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4564 | /* reject any changes */ | |
4565 | return -EINVAL; | |
eef941e6 | 4566 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4567 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4568 | return -EINVAL; | |
4569 | break; | |
eef941e6 | 4570 | case CFG80211_STA_MESH_PEER_USER: |
42925040 CYY |
4571 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION && |
4572 | params->plink_action != NL80211_PLINK_ACTION_BLOCK) | |
77ee7c89 JB |
4573 | return -EINVAL; |
4574 | break; | |
4575 | } | |
4576 | ||
4577 | return 0; | |
4578 | } | |
4579 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4580 | ||
5727ef1b | 4581 | /* |
c258d2de | 4582 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4583 | */ |
80b99899 JB |
4584 | static struct net_device *get_vlan(struct genl_info *info, |
4585 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4586 | { |
463d0183 | 4587 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4588 | struct net_device *v; |
4589 | int ret; | |
4590 | ||
4591 | if (!vlanattr) | |
4592 | return NULL; | |
4593 | ||
4594 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4595 | if (!v) | |
4596 | return ERR_PTR(-ENODEV); | |
4597 | ||
4598 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4599 | ret = -EINVAL; | |
4600 | goto error; | |
5727ef1b | 4601 | } |
80b99899 | 4602 | |
77ee7c89 JB |
4603 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4604 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4605 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4606 | ret = -EINVAL; | |
4607 | goto error; | |
4608 | } | |
4609 | ||
80b99899 JB |
4610 | if (!netif_running(v)) { |
4611 | ret = -ENETDOWN; | |
4612 | goto error; | |
4613 | } | |
4614 | ||
4615 | return v; | |
4616 | error: | |
4617 | dev_put(v); | |
4618 | return ERR_PTR(ret); | |
5727ef1b JB |
4619 | } |
4620 | ||
94e860f1 JB |
4621 | static const struct nla_policy |
4622 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4623 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4624 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4625 | }; | |
4626 | ||
ff276691 JB |
4627 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4628 | struct station_parameters *params) | |
df881293 | 4629 | { |
df881293 JM |
4630 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4631 | struct nlattr *nla; | |
4632 | int err; | |
4633 | ||
df881293 JM |
4634 | /* parse WME attributes if present */ |
4635 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4636 | return 0; | |
4637 | ||
4638 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4639 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4640 | nl80211_sta_wme_policy); | |
4641 | if (err) | |
4642 | return err; | |
4643 | ||
4644 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4645 | params->uapsd_queues = nla_get_u8( | |
4646 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4647 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4648 | return -EINVAL; | |
4649 | ||
4650 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4651 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4652 | ||
4653 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4654 | return -EINVAL; | |
4655 | ||
4656 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4657 | ||
4658 | return 0; | |
4659 | } | |
4660 | ||
c01fc9ad SD |
4661 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4662 | struct station_parameters *params) | |
4663 | { | |
4664 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4665 | params->supported_channels = | |
4666 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4667 | params->supported_channels_len = | |
4668 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4669 | /* | |
4670 | * Need to include at least one (first channel, number of | |
4671 | * channels) tuple for each subband, and must have proper | |
4672 | * tuples for the rest of the data as well. | |
4673 | */ | |
4674 | if (params->supported_channels_len < 2) | |
4675 | return -EINVAL; | |
4676 | if (params->supported_channels_len % 2) | |
4677 | return -EINVAL; | |
4678 | } | |
4679 | ||
4680 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4681 | params->supported_oper_classes = | |
4682 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4683 | params->supported_oper_classes_len = | |
4684 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4685 | /* | |
4686 | * The value of the Length field of the Supported Operating | |
4687 | * Classes element is between 2 and 253. | |
4688 | */ | |
4689 | if (params->supported_oper_classes_len < 2 || | |
4690 | params->supported_oper_classes_len > 253) | |
4691 | return -EINVAL; | |
4692 | } | |
4693 | return 0; | |
4694 | } | |
4695 | ||
ff276691 JB |
4696 | static int nl80211_set_station_tdls(struct genl_info *info, |
4697 | struct station_parameters *params) | |
4698 | { | |
c01fc9ad | 4699 | int err; |
ff276691 | 4700 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4701 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4702 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4703 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4704 | params->ht_capa = | |
4705 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4706 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4707 | params->vht_capa = | |
4708 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4709 | ||
c01fc9ad SD |
4710 | err = nl80211_parse_sta_channel_info(info, params); |
4711 | if (err) | |
4712 | return err; | |
4713 | ||
ff276691 JB |
4714 | return nl80211_parse_sta_wme(info, params); |
4715 | } | |
4716 | ||
5727ef1b JB |
4717 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4718 | { | |
4c476991 | 4719 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4720 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4721 | struct station_parameters params; |
77ee7c89 JB |
4722 | u8 *mac_addr; |
4723 | int err; | |
5727ef1b JB |
4724 | |
4725 | memset(¶ms, 0, sizeof(params)); | |
4726 | ||
77ee7c89 JB |
4727 | if (!rdev->ops->change_station) |
4728 | return -EOPNOTSUPP; | |
4729 | ||
e4208427 AB |
4730 | /* |
4731 | * AID and listen_interval properties can be set only for unassociated | |
4732 | * station. Include these parameters here and will check them in | |
4733 | * cfg80211_check_station_change(). | |
4734 | */ | |
a9bc31e4 AB |
4735 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4736 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
e4208427 AB |
4737 | |
4738 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) | |
4739 | params.listen_interval = | |
4740 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
4741 | else | |
4742 | params.listen_interval = -1; | |
5727ef1b | 4743 | |
17b94247 AB |
4744 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4745 | u8 tmp; | |
4746 | ||
4747 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4748 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4749 | return -EINVAL; | |
4750 | ||
4751 | params.support_p2p_ps = tmp; | |
4752 | } else { | |
4753 | params.support_p2p_ps = -1; | |
4754 | } | |
4755 | ||
5727ef1b JB |
4756 | if (!info->attrs[NL80211_ATTR_MAC]) |
4757 | return -EINVAL; | |
4758 | ||
4759 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4760 | ||
4761 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4762 | params.supported_rates = | |
4763 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4764 | params.supported_rates_len = | |
4765 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4766 | } | |
4767 | ||
9d62a986 JM |
4768 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4769 | params.capability = | |
4770 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4771 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4772 | } | |
4773 | ||
4774 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4775 | params.ext_capab = | |
4776 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4777 | params.ext_capab_len = | |
4778 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4779 | } | |
4780 | ||
bdd3ae3d | 4781 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4782 | return -EINVAL; |
4783 | ||
f8bacc21 | 4784 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4785 | params.plink_action = |
f8bacc21 JB |
4786 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4787 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4788 | return -EINVAL; | |
4789 | } | |
2ec600d6 | 4790 | |
f8bacc21 | 4791 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4792 | params.plink_state = |
f8bacc21 JB |
4793 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4794 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4795 | return -EINVAL; | |
7d27a0ba MH |
4796 | if (info->attrs[NL80211_ATTR_MESH_PEER_AID]) { |
4797 | params.peer_aid = nla_get_u16( | |
4798 | info->attrs[NL80211_ATTR_MESH_PEER_AID]); | |
4799 | if (params.peer_aid > IEEE80211_MAX_AID) | |
4800 | return -EINVAL; | |
4801 | } | |
f8bacc21 JB |
4802 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; |
4803 | } | |
9c3990aa | 4804 | |
3b1c5a53 MP |
4805 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4806 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4807 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4808 | ||
4809 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4810 | pm > NL80211_MESH_POWER_MAX) | |
4811 | return -EINVAL; | |
4812 | ||
4813 | params.local_pm = pm; | |
4814 | } | |
4815 | ||
77ee7c89 JB |
4816 | /* Include parameters for TDLS peer (will check later) */ |
4817 | err = nl80211_set_station_tdls(info, ¶ms); | |
4818 | if (err) | |
4819 | return err; | |
4820 | ||
4821 | params.vlan = get_vlan(info, rdev); | |
4822 | if (IS_ERR(params.vlan)) | |
4823 | return PTR_ERR(params.vlan); | |
4824 | ||
a97f4424 JB |
4825 | switch (dev->ieee80211_ptr->iftype) { |
4826 | case NL80211_IFTYPE_AP: | |
4827 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4828 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4829 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4830 | case NL80211_IFTYPE_STATION: |
267335d6 | 4831 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4832 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4833 | break; |
4834 | default: | |
77ee7c89 JB |
4835 | err = -EOPNOTSUPP; |
4836 | goto out_put_vlan; | |
034d655e JB |
4837 | } |
4838 | ||
77ee7c89 | 4839 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4840 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4841 | |
77ee7c89 | 4842 | out_put_vlan: |
5727ef1b JB |
4843 | if (params.vlan) |
4844 | dev_put(params.vlan); | |
3b85875a | 4845 | |
5727ef1b JB |
4846 | return err; |
4847 | } | |
4848 | ||
4849 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4850 | { | |
4c476991 | 4851 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4852 | int err; |
4c476991 | 4853 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4854 | struct station_parameters params; |
4855 | u8 *mac_addr = NULL; | |
bda95eb1 JB |
4856 | u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
4857 | BIT(NL80211_STA_FLAG_ASSOCIATED); | |
5727ef1b JB |
4858 | |
4859 | memset(¶ms, 0, sizeof(params)); | |
4860 | ||
984c311b JB |
4861 | if (!rdev->ops->add_station) |
4862 | return -EOPNOTSUPP; | |
4863 | ||
5727ef1b JB |
4864 | if (!info->attrs[NL80211_ATTR_MAC]) |
4865 | return -EINVAL; | |
4866 | ||
5727ef1b JB |
4867 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4868 | return -EINVAL; | |
4869 | ||
4870 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4871 | return -EINVAL; | |
4872 | ||
5e4b6f56 JM |
4873 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4874 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4875 | return -EINVAL; |
4876 | ||
5727ef1b JB |
4877 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4878 | params.supported_rates = | |
4879 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4880 | params.supported_rates_len = | |
4881 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4882 | params.listen_interval = | |
4883 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4884 | |
17b94247 AB |
4885 | if (info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]) { |
4886 | u8 tmp; | |
4887 | ||
4888 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_STA_SUPPORT_P2P_PS]); | |
4889 | if (tmp >= NUM_NL80211_P2P_PS_STATUS) | |
4890 | return -EINVAL; | |
4891 | ||
4892 | params.support_p2p_ps = tmp; | |
4893 | } else { | |
4894 | /* | |
4895 | * if not specified, assume it's supported for P2P GO interface, | |
4896 | * and is NOT supported for AP interface | |
4897 | */ | |
4898 | params.support_p2p_ps = | |
4899 | dev->ieee80211_ptr->iftype == NL80211_IFTYPE_P2P_GO; | |
4900 | } | |
4901 | ||
3d124ea2 | 4902 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4903 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4904 | else |
4905 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4906 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4907 | return -EINVAL; | |
51b50fbe | 4908 | |
9d62a986 JM |
4909 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4910 | params.capability = | |
4911 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4912 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4913 | } | |
4914 | ||
4915 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4916 | params.ext_capab = | |
4917 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4918 | params.ext_capab_len = | |
4919 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4920 | } | |
4921 | ||
36aedc90 JM |
4922 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4923 | params.ht_capa = | |
4924 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4925 | |
f461be3e MP |
4926 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4927 | params.vht_capa = | |
4928 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4929 | ||
60f4a7b1 MK |
4930 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4931 | params.opmode_notif_used = true; | |
4932 | params.opmode_notif = | |
4933 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4934 | } | |
4935 | ||
f8bacc21 | 4936 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4937 | params.plink_action = |
f8bacc21 JB |
4938 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4939 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4940 | return -EINVAL; | |
4941 | } | |
96b78dff | 4942 | |
c01fc9ad SD |
4943 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4944 | if (err) | |
4945 | return err; | |
4946 | ||
ff276691 JB |
4947 | err = nl80211_parse_sta_wme(info, ¶ms); |
4948 | if (err) | |
4949 | return err; | |
bdd90d5e | 4950 | |
bdd3ae3d | 4951 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4952 | return -EINVAL; |
4953 | ||
496fcc29 JB |
4954 | /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT |
4955 | * as userspace might just pass through the capabilities from the IEs | |
4956 | * directly, rather than enforcing this restriction and returning an | |
4957 | * error in this case. | |
4958 | */ | |
4959 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) { | |
4960 | params.ht_capa = NULL; | |
4961 | params.vht_capa = NULL; | |
4962 | } | |
4963 | ||
77ee7c89 JB |
4964 | /* When you run into this, adjust the code below for the new flag */ |
4965 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4966 | ||
bdd90d5e JB |
4967 | switch (dev->ieee80211_ptr->iftype) { |
4968 | case NL80211_IFTYPE_AP: | |
4969 | case NL80211_IFTYPE_AP_VLAN: | |
4970 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4971 | /* ignore WME attributes if iface/sta is not capable */ |
4972 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4973 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4974 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4975 | |
bdd90d5e | 4976 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4977 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4978 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4979 | return -EINVAL; |
bdd90d5e JB |
4980 | /* but don't bother the driver with it */ |
4981 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4982 | |
d582cffb JB |
4983 | /* allow authenticated/associated only if driver handles it */ |
4984 | if (!(rdev->wiphy.features & | |
4985 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
bda95eb1 | 4986 | params.sta_flags_mask & auth_assoc) |
d582cffb JB |
4987 | return -EINVAL; |
4988 | ||
bda95eb1 JB |
4989 | /* Older userspace, or userspace wanting to be compatible with |
4990 | * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth | |
4991 | * and assoc flags in the mask, but assumes the station will be | |
4992 | * added as associated anyway since this was the required driver | |
4993 | * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was | |
4994 | * introduced. | |
4995 | * In order to not bother drivers with this quirk in the API | |
4996 | * set the flags in both the mask and set for new stations in | |
4997 | * this case. | |
4998 | */ | |
4999 | if (!(params.sta_flags_mask & auth_assoc)) { | |
5000 | params.sta_flags_mask |= auth_assoc; | |
5001 | params.sta_flags_set |= auth_assoc; | |
5002 | } | |
5003 | ||
bdd90d5e JB |
5004 | /* must be last in here for error handling */ |
5005 | params.vlan = get_vlan(info, rdev); | |
5006 | if (IS_ERR(params.vlan)) | |
5007 | return PTR_ERR(params.vlan); | |
5008 | break; | |
5009 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
5010 | /* ignore uAPSD data */ |
5011 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
5012 | ||
d582cffb JB |
5013 | /* associated is disallowed */ |
5014 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
5015 | return -EINVAL; | |
bdd90d5e | 5016 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
5017 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
5018 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
5019 | return -EINVAL; |
5020 | break; | |
5021 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 5022 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
5023 | /* ignore uAPSD data */ |
5024 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
5025 | ||
77ee7c89 JB |
5026 | /* these are disallowed */ |
5027 | if (params.sta_flags_mask & | |
5028 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
5029 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 5030 | return -EINVAL; |
bdd90d5e JB |
5031 | /* Only TDLS peers can be added */ |
5032 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
5033 | return -EINVAL; | |
5034 | /* Can only add if TDLS ... */ | |
5035 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
5036 | return -EOPNOTSUPP; | |
5037 | /* ... with external setup is supported */ | |
5038 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
5039 | return -EOPNOTSUPP; | |
77ee7c89 JB |
5040 | /* |
5041 | * Older wpa_supplicant versions always mark the TDLS peer | |
5042 | * as authorized, but it shouldn't yet be. | |
5043 | */ | |
5044 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
5045 | break; |
5046 | default: | |
5047 | return -EOPNOTSUPP; | |
c75786c9 EP |
5048 | } |
5049 | ||
bdd90d5e | 5050 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 5051 | |
e35e4d28 | 5052 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 5053 | |
5727ef1b JB |
5054 | if (params.vlan) |
5055 | dev_put(params.vlan); | |
5727ef1b JB |
5056 | return err; |
5057 | } | |
5058 | ||
5059 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
5060 | { | |
4c476991 JB |
5061 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5062 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
5063 | struct station_del_parameters params; |
5064 | ||
5065 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
5066 | |
5067 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 5068 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 5069 | |
e80cf853 | 5070 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 5071 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 5072 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
5073 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5074 | return -EINVAL; | |
5727ef1b | 5075 | |
4c476991 JB |
5076 | if (!rdev->ops->del_station) |
5077 | return -EOPNOTSUPP; | |
3b85875a | 5078 | |
98856866 JM |
5079 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
5080 | params.subtype = | |
5081 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
5082 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
5083 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
5084 | return -EINVAL; | |
5085 | } else { | |
5086 | /* Default to Deauthentication frame */ | |
5087 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
5088 | } | |
5089 | ||
5090 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
5091 | params.reason_code = | |
5092 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
5093 | if (params.reason_code == 0) | |
5094 | return -EINVAL; /* 0 is reserved */ | |
5095 | } else { | |
5096 | /* Default to reason code 2 */ | |
5097 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
5098 | } | |
5099 | ||
89c771e5 | 5100 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
5101 | } |
5102 | ||
15e47304 | 5103 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
5104 | int flags, struct net_device *dev, |
5105 | u8 *dst, u8 *next_hop, | |
5106 | struct mpath_info *pinfo) | |
5107 | { | |
5108 | void *hdr; | |
5109 | struct nlattr *pinfoattr; | |
5110 | ||
1ef4c850 | 5111 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
5112 | if (!hdr) |
5113 | return -1; | |
5114 | ||
9360ffd1 DM |
5115 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5116 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
5117 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
5118 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
5119 | goto nla_put_failure; | |
f5ea9120 | 5120 | |
2ec600d6 LCC |
5121 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
5122 | if (!pinfoattr) | |
5123 | goto nla_put_failure; | |
9360ffd1 DM |
5124 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
5125 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
5126 | pinfo->frame_qlen)) | |
5127 | goto nla_put_failure; | |
5128 | if (((pinfo->filled & MPATH_INFO_SN) && | |
5129 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
5130 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
5131 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
5132 | pinfo->metric)) || | |
5133 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
5134 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
5135 | pinfo->exptime)) || | |
5136 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
5137 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
5138 | pinfo->flags)) || | |
5139 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
5140 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
5141 | pinfo->discovery_timeout)) || | |
5142 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
5143 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
5144 | pinfo->discovery_retries))) | |
5145 | goto nla_put_failure; | |
2ec600d6 LCC |
5146 | |
5147 | nla_nest_end(msg, pinfoattr); | |
5148 | ||
053c095a JB |
5149 | genlmsg_end(msg, hdr); |
5150 | return 0; | |
2ec600d6 LCC |
5151 | |
5152 | nla_put_failure: | |
bc3ed28c TG |
5153 | genlmsg_cancel(msg, hdr); |
5154 | return -EMSGSIZE; | |
2ec600d6 LCC |
5155 | } |
5156 | ||
5157 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 5158 | struct netlink_callback *cb) |
2ec600d6 | 5159 | { |
2ec600d6 | 5160 | struct mpath_info pinfo; |
1b8ec87a | 5161 | struct cfg80211_registered_device *rdev; |
97990a06 | 5162 | struct wireless_dev *wdev; |
2ec600d6 LCC |
5163 | u8 dst[ETH_ALEN]; |
5164 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 5165 | int path_idx = cb->args[2]; |
2ec600d6 | 5166 | int err; |
2ec600d6 | 5167 | |
1b8ec87a | 5168 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
5169 | if (err) |
5170 | return err; | |
bba95fef | 5171 | |
1b8ec87a | 5172 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 5173 | err = -EOPNOTSUPP; |
bba95fef JB |
5174 | goto out_err; |
5175 | } | |
5176 | ||
97990a06 | 5177 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 5178 | err = -EOPNOTSUPP; |
0448b5fc | 5179 | goto out_err; |
eec60b03 JM |
5180 | } |
5181 | ||
bba95fef | 5182 | while (1) { |
1b8ec87a | 5183 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 5184 | next_hop, &pinfo); |
bba95fef | 5185 | if (err == -ENOENT) |
2ec600d6 | 5186 | break; |
bba95fef | 5187 | if (err) |
3b85875a | 5188 | goto out_err; |
2ec600d6 | 5189 | |
15e47304 | 5190 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 5191 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 5192 | wdev->netdev, dst, next_hop, |
bba95fef JB |
5193 | &pinfo) < 0) |
5194 | goto out; | |
2ec600d6 | 5195 | |
bba95fef | 5196 | path_idx++; |
2ec600d6 | 5197 | } |
2ec600d6 | 5198 | |
bba95fef | 5199 | out: |
97990a06 | 5200 | cb->args[2] = path_idx; |
bba95fef | 5201 | err = skb->len; |
bba95fef | 5202 | out_err: |
1b8ec87a | 5203 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 5204 | return err; |
2ec600d6 LCC |
5205 | } |
5206 | ||
5207 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
5208 | { | |
4c476991 | 5209 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 5210 | int err; |
4c476991 | 5211 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
5212 | struct mpath_info pinfo; |
5213 | struct sk_buff *msg; | |
5214 | u8 *dst = NULL; | |
5215 | u8 next_hop[ETH_ALEN]; | |
5216 | ||
5217 | memset(&pinfo, 0, sizeof(pinfo)); | |
5218 | ||
5219 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5220 | return -EINVAL; | |
5221 | ||
5222 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5223 | ||
4c476991 JB |
5224 | if (!rdev->ops->get_mpath) |
5225 | return -EOPNOTSUPP; | |
2ec600d6 | 5226 | |
4c476991 JB |
5227 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5228 | return -EOPNOTSUPP; | |
eec60b03 | 5229 | |
e35e4d28 | 5230 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 5231 | if (err) |
4c476991 | 5232 | return err; |
2ec600d6 | 5233 | |
fd2120ca | 5234 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 5235 | if (!msg) |
4c476991 | 5236 | return -ENOMEM; |
2ec600d6 | 5237 | |
15e47304 | 5238 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
5239 | dev, dst, next_hop, &pinfo) < 0) { |
5240 | nlmsg_free(msg); | |
5241 | return -ENOBUFS; | |
5242 | } | |
3b85875a | 5243 | |
4c476991 | 5244 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
5245 | } |
5246 | ||
5247 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
5248 | { | |
4c476991 JB |
5249 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5250 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5251 | u8 *dst = NULL; |
5252 | u8 *next_hop = NULL; | |
5253 | ||
5254 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5255 | return -EINVAL; | |
5256 | ||
5257 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
5258 | return -EINVAL; | |
5259 | ||
5260 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5261 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
5262 | ||
4c476991 JB |
5263 | if (!rdev->ops->change_mpath) |
5264 | return -EOPNOTSUPP; | |
35a8efe1 | 5265 | |
4c476991 JB |
5266 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5267 | return -EOPNOTSUPP; | |
2ec600d6 | 5268 | |
e35e4d28 | 5269 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 5270 | } |
4c476991 | 5271 | |
2ec600d6 LCC |
5272 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
5273 | { | |
4c476991 JB |
5274 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5275 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5276 | u8 *dst = NULL; |
5277 | u8 *next_hop = NULL; | |
5278 | ||
5279 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5280 | return -EINVAL; | |
5281 | ||
5282 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
5283 | return -EINVAL; | |
5284 | ||
5285 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5286 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
5287 | ||
4c476991 JB |
5288 | if (!rdev->ops->add_mpath) |
5289 | return -EOPNOTSUPP; | |
35a8efe1 | 5290 | |
4c476991 JB |
5291 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
5292 | return -EOPNOTSUPP; | |
2ec600d6 | 5293 | |
e35e4d28 | 5294 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
5295 | } |
5296 | ||
5297 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
5298 | { | |
4c476991 JB |
5299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5300 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
5301 | u8 *dst = NULL; |
5302 | ||
5303 | if (info->attrs[NL80211_ATTR_MAC]) | |
5304 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5305 | ||
4c476991 JB |
5306 | if (!rdev->ops->del_mpath) |
5307 | return -EOPNOTSUPP; | |
3b85875a | 5308 | |
e35e4d28 | 5309 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
5310 | } |
5311 | ||
66be7d2b HR |
5312 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
5313 | { | |
5314 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5315 | int err; | |
5316 | struct net_device *dev = info->user_ptr[1]; | |
5317 | struct mpath_info pinfo; | |
5318 | struct sk_buff *msg; | |
5319 | u8 *dst = NULL; | |
5320 | u8 mpp[ETH_ALEN]; | |
5321 | ||
5322 | memset(&pinfo, 0, sizeof(pinfo)); | |
5323 | ||
5324 | if (!info->attrs[NL80211_ATTR_MAC]) | |
5325 | return -EINVAL; | |
5326 | ||
5327 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
5328 | ||
5329 | if (!rdev->ops->get_mpp) | |
5330 | return -EOPNOTSUPP; | |
5331 | ||
5332 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
5333 | return -EOPNOTSUPP; | |
5334 | ||
5335 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
5336 | if (err) | |
5337 | return err; | |
5338 | ||
5339 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5340 | if (!msg) | |
5341 | return -ENOMEM; | |
5342 | ||
5343 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
5344 | dev, dst, mpp, &pinfo) < 0) { | |
5345 | nlmsg_free(msg); | |
5346 | return -ENOBUFS; | |
5347 | } | |
5348 | ||
5349 | return genlmsg_reply(msg, info); | |
5350 | } | |
5351 | ||
5352 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
5353 | struct netlink_callback *cb) | |
5354 | { | |
5355 | struct mpath_info pinfo; | |
5356 | struct cfg80211_registered_device *rdev; | |
5357 | struct wireless_dev *wdev; | |
5358 | u8 dst[ETH_ALEN]; | |
5359 | u8 mpp[ETH_ALEN]; | |
5360 | int path_idx = cb->args[2]; | |
5361 | int err; | |
5362 | ||
5363 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
5364 | if (err) | |
5365 | return err; | |
5366 | ||
5367 | if (!rdev->ops->dump_mpp) { | |
5368 | err = -EOPNOTSUPP; | |
5369 | goto out_err; | |
5370 | } | |
5371 | ||
5372 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
5373 | err = -EOPNOTSUPP; | |
5374 | goto out_err; | |
5375 | } | |
5376 | ||
5377 | while (1) { | |
5378 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
5379 | mpp, &pinfo); | |
5380 | if (err == -ENOENT) | |
5381 | break; | |
5382 | if (err) | |
5383 | goto out_err; | |
5384 | ||
5385 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
5386 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
5387 | wdev->netdev, dst, mpp, | |
5388 | &pinfo) < 0) | |
5389 | goto out; | |
5390 | ||
5391 | path_idx++; | |
5392 | } | |
5393 | ||
5394 | out: | |
5395 | cb->args[2] = path_idx; | |
5396 | err = skb->len; | |
5397 | out_err: | |
5398 | nl80211_finish_wdev_dump(rdev); | |
5399 | return err; | |
5400 | } | |
5401 | ||
9f1ba906 JM |
5402 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
5403 | { | |
4c476991 JB |
5404 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5405 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 5406 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 5407 | struct bss_parameters params; |
c56589ed | 5408 | int err; |
9f1ba906 JM |
5409 | |
5410 | memset(¶ms, 0, sizeof(params)); | |
5411 | /* default to not changing parameters */ | |
5412 | params.use_cts_prot = -1; | |
5413 | params.use_short_preamble = -1; | |
5414 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 5415 | params.ap_isolate = -1; |
50b12f59 | 5416 | params.ht_opmode = -1; |
53cabad7 JB |
5417 | params.p2p_ctwindow = -1; |
5418 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
5419 | |
5420 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
5421 | params.use_cts_prot = | |
5422 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
5423 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
5424 | params.use_short_preamble = | |
5425 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
5426 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
5427 | params.use_short_slot_time = | |
5428 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
5429 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
5430 | params.basic_rates = | |
5431 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5432 | params.basic_rates_len = | |
5433 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
5434 | } | |
fd8aaaf3 FF |
5435 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
5436 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
5437 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
5438 | params.ht_opmode = | |
5439 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 5440 | |
53cabad7 JB |
5441 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
5442 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5443 | return -EINVAL; | |
5444 | params.p2p_ctwindow = | |
5445 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
5446 | if (params.p2p_ctwindow < 0) | |
5447 | return -EINVAL; | |
5448 | if (params.p2p_ctwindow != 0 && | |
5449 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
5450 | return -EINVAL; | |
5451 | } | |
5452 | ||
5453 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
5454 | u8 tmp; | |
5455 | ||
5456 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
5457 | return -EINVAL; | |
5458 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
5459 | if (tmp > 1) | |
5460 | return -EINVAL; | |
5461 | params.p2p_opp_ps = tmp; | |
5462 | if (params.p2p_opp_ps && | |
5463 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
5464 | return -EINVAL; | |
5465 | } | |
5466 | ||
4c476991 JB |
5467 | if (!rdev->ops->change_bss) |
5468 | return -EOPNOTSUPP; | |
9f1ba906 | 5469 | |
074ac8df | 5470 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
5471 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
5472 | return -EOPNOTSUPP; | |
3b85875a | 5473 | |
c56589ed SW |
5474 | wdev_lock(wdev); |
5475 | err = rdev_change_bss(rdev, dev, ¶ms); | |
5476 | wdev_unlock(wdev); | |
5477 | ||
5478 | return err; | |
9f1ba906 JM |
5479 | } |
5480 | ||
b2e1b302 LR |
5481 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) |
5482 | { | |
b2e1b302 | 5483 | char *data = NULL; |
05050753 | 5484 | bool is_indoor; |
57b5ce07 | 5485 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
5486 | u32 owner_nlportid; |
5487 | ||
80778f18 LR |
5488 | /* |
5489 | * You should only get this when cfg80211 hasn't yet initialized | |
5490 | * completely when built-in to the kernel right between the time | |
5491 | * window between nl80211_init() and regulatory_init(), if that is | |
5492 | * even possible. | |
5493 | */ | |
458f4f9e | 5494 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 5495 | return -EINPROGRESS; |
80778f18 | 5496 | |
57b5ce07 LR |
5497 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
5498 | user_reg_hint_type = | |
5499 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
5500 | else | |
5501 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
5502 | ||
5503 | switch (user_reg_hint_type) { | |
5504 | case NL80211_USER_REG_HINT_USER: | |
5505 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
5506 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
5507 | return -EINVAL; | |
5508 | ||
5509 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5510 | return regulatory_hint_user(data, user_reg_hint_type); | |
5511 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
5512 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
5513 | owner_nlportid = info->snd_portid; | |
5514 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
5515 | } else { | |
5516 | owner_nlportid = 0; | |
5517 | is_indoor = true; | |
5518 | } | |
5519 | ||
5520 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
5521 | default: |
5522 | return -EINVAL; | |
5523 | } | |
b2e1b302 LR |
5524 | } |
5525 | ||
24bdd9f4 | 5526 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 5527 | struct genl_info *info) |
93da9cc1 | 5528 | { |
4c476991 | 5529 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 5530 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
5531 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5532 | struct mesh_config cur_params; | |
5533 | int err = 0; | |
93da9cc1 | 5534 | void *hdr; |
5535 | struct nlattr *pinfoattr; | |
5536 | struct sk_buff *msg; | |
5537 | ||
29cbe68c JB |
5538 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5539 | return -EOPNOTSUPP; | |
5540 | ||
24bdd9f4 | 5541 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5542 | return -EOPNOTSUPP; |
f3f92586 | 5543 | |
29cbe68c JB |
5544 | wdev_lock(wdev); |
5545 | /* If not connected, get default parameters */ | |
5546 | if (!wdev->mesh_id_len) | |
5547 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5548 | else | |
e35e4d28 | 5549 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5550 | wdev_unlock(wdev); |
5551 | ||
93da9cc1 | 5552 | if (err) |
4c476991 | 5553 | return err; |
93da9cc1 | 5554 | |
5555 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5556 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5557 | if (!msg) |
5558 | return -ENOMEM; | |
15e47304 | 5559 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5560 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5561 | if (!hdr) |
efe1cf0c | 5562 | goto out; |
24bdd9f4 | 5563 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5564 | if (!pinfoattr) |
5565 | goto nla_put_failure; | |
9360ffd1 DM |
5566 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5567 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5568 | cur_params.dot11MeshRetryTimeout) || | |
5569 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5570 | cur_params.dot11MeshConfirmTimeout) || | |
5571 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5572 | cur_params.dot11MeshHoldingTimeout) || | |
5573 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5574 | cur_params.dot11MeshMaxPeerLinks) || | |
5575 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5576 | cur_params.dot11MeshMaxRetries) || | |
5577 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5578 | cur_params.dot11MeshTTL) || | |
5579 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5580 | cur_params.element_ttl) || | |
5581 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5582 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5583 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5584 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5585 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5586 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5587 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5588 | cur_params.path_refresh_time) || | |
5589 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5590 | cur_params.min_discovery_timeout) || | |
5591 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5592 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5593 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5594 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5595 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5596 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5597 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5598 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5599 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5600 | cur_params.dot11MeshHWMPRootMode) || | |
5601 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5602 | cur_params.dot11MeshHWMPRannInterval) || | |
5603 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5604 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5605 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5606 | cur_params.dot11MeshForwarding) || | |
5607 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5608 | cur_params.rssi_threshold) || |
5609 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5610 | cur_params.ht_opmode) || |
5611 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5612 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5613 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5614 | cur_params.dot11MeshHWMProotInterval) || |
5615 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5616 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5617 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5618 | cur_params.power_mode) || | |
5619 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5620 | cur_params.dot11MeshAwakeWindowDuration) || |
5621 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5622 | cur_params.plink_timeout)) | |
9360ffd1 | 5623 | goto nla_put_failure; |
93da9cc1 | 5624 | nla_nest_end(msg, pinfoattr); |
5625 | genlmsg_end(msg, hdr); | |
4c476991 | 5626 | return genlmsg_reply(msg, info); |
93da9cc1 | 5627 | |
3b85875a | 5628 | nla_put_failure: |
93da9cc1 | 5629 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5630 | out: |
d080e275 | 5631 | nlmsg_free(msg); |
4c476991 | 5632 | return -ENOBUFS; |
93da9cc1 | 5633 | } |
5634 | ||
b54452b0 | 5635 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5636 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5637 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5638 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5639 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5640 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5641 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5642 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5643 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5644 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5645 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5646 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5647 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5648 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5649 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5650 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5651 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5652 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5653 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5654 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5655 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5656 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5657 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5658 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5659 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5660 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5661 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5662 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5663 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5664 | }; |
5665 | ||
c80d545d JC |
5666 | static const struct nla_policy |
5667 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5668 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5669 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5670 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5671 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5672 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5673 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5674 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5675 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5676 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5677 | }; |
5678 | ||
f151d9db AB |
5679 | static int nl80211_check_bool(const struct nlattr *nla, u8 min, u8 max, bool *out) |
5680 | { | |
5681 | u8 val = nla_get_u8(nla); | |
5682 | if (val < min || val > max) | |
5683 | return -EINVAL; | |
5684 | *out = val; | |
5685 | return 0; | |
5686 | } | |
5687 | ||
5688 | static int nl80211_check_u8(const struct nlattr *nla, u8 min, u8 max, u8 *out) | |
5689 | { | |
5690 | u8 val = nla_get_u8(nla); | |
5691 | if (val < min || val > max) | |
5692 | return -EINVAL; | |
5693 | *out = val; | |
5694 | return 0; | |
5695 | } | |
5696 | ||
5697 | static int nl80211_check_u16(const struct nlattr *nla, u16 min, u16 max, u16 *out) | |
5698 | { | |
5699 | u16 val = nla_get_u16(nla); | |
5700 | if (val < min || val > max) | |
5701 | return -EINVAL; | |
5702 | *out = val; | |
5703 | return 0; | |
5704 | } | |
5705 | ||
5706 | static int nl80211_check_u32(const struct nlattr *nla, u32 min, u32 max, u32 *out) | |
5707 | { | |
5708 | u32 val = nla_get_u32(nla); | |
5709 | if (val < min || val > max) | |
5710 | return -EINVAL; | |
5711 | *out = val; | |
5712 | return 0; | |
5713 | } | |
5714 | ||
5715 | static int nl80211_check_s32(const struct nlattr *nla, s32 min, s32 max, s32 *out) | |
5716 | { | |
5717 | s32 val = nla_get_s32(nla); | |
5718 | if (val < min || val > max) | |
5719 | return -EINVAL; | |
5720 | *out = val; | |
5721 | return 0; | |
5722 | } | |
5723 | ||
ff9a71af JB |
5724 | static int nl80211_check_power_mode(const struct nlattr *nla, |
5725 | enum nl80211_mesh_power_mode min, | |
5726 | enum nl80211_mesh_power_mode max, | |
5727 | enum nl80211_mesh_power_mode *out) | |
5728 | { | |
5729 | u32 val = nla_get_u32(nla); | |
5730 | if (val < min || val > max) | |
5731 | return -EINVAL; | |
5732 | *out = val; | |
5733 | return 0; | |
5734 | } | |
5735 | ||
24bdd9f4 | 5736 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5737 | struct mesh_config *cfg, |
5738 | u32 *mask_out) | |
93da9cc1 | 5739 | { |
93da9cc1 | 5740 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5741 | u32 mask = 0; |
9757235f | 5742 | u16 ht_opmode; |
93da9cc1 | 5743 | |
ea54fba2 MP |
5744 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5745 | do { \ | |
5746 | if (tb[attr]) { \ | |
f151d9db | 5747 | if (fn(tb[attr], min, max, &cfg->param)) \ |
ea54fba2 | 5748 | return -EINVAL; \ |
ea54fba2 MP |
5749 | mask |= (1 << (attr - 1)); \ |
5750 | } \ | |
5751 | } while (0) | |
bd90fdcc | 5752 | |
24bdd9f4 | 5753 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5754 | return -EINVAL; |
5755 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5756 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5757 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5758 | return -EINVAL; |
5759 | ||
93da9cc1 | 5760 | /* This makes sure that there aren't more than 32 mesh config |
5761 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5762 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5763 | ||
5764 | /* Fill in the params struct */ | |
ea54fba2 | 5765 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea | 5766 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
f151d9db | 5767 | nl80211_check_u16); |
ea54fba2 | 5768 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea | 5769 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
f151d9db | 5770 | nl80211_check_u16); |
ea54fba2 | 5771 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea | 5772 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
f151d9db | 5773 | nl80211_check_u16); |
ea54fba2 | 5774 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea | 5775 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
f151d9db | 5776 | nl80211_check_u16); |
ea54fba2 | 5777 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea | 5778 | mask, NL80211_MESHCONF_MAX_RETRIES, |
f151d9db | 5779 | nl80211_check_u8); |
ea54fba2 | 5780 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
f151d9db | 5781 | mask, NL80211_MESHCONF_TTL, nl80211_check_u8); |
ea54fba2 | 5782 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea | 5783 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
f151d9db | 5784 | nl80211_check_u8); |
ea54fba2 | 5785 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea | 5786 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
f151d9db | 5787 | nl80211_check_bool); |
ea54fba2 MP |
5788 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5789 | 1, 255, mask, | |
a4f606ea | 5790 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
f151d9db | 5791 | nl80211_check_u32); |
ea54fba2 | 5792 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea | 5793 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
f151d9db | 5794 | nl80211_check_u8); |
ea54fba2 | 5795 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea | 5796 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
f151d9db | 5797 | nl80211_check_u32); |
ea54fba2 | 5798 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea | 5799 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
f151d9db | 5800 | nl80211_check_u16); |
ea54fba2 MP |
5801 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5802 | 1, 65535, mask, | |
a4f606ea | 5803 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
f151d9db | 5804 | nl80211_check_u32); |
93da9cc1 | 5805 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5806 | 1, 65535, mask, |
5807 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
f151d9db | 5808 | nl80211_check_u16); |
dca7e943 | 5809 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5810 | 1, 65535, mask, |
5811 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
f151d9db | 5812 | nl80211_check_u16); |
93da9cc1 | 5813 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5814 | dot11MeshHWMPnetDiameterTraversalTime, |
5815 | 1, 65535, mask, | |
a4f606ea | 5816 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
f151d9db | 5817 | nl80211_check_u16); |
ea54fba2 MP |
5818 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5819 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
f151d9db | 5820 | nl80211_check_u8); |
ea54fba2 MP |
5821 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, |
5822 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
f151d9db | 5823 | nl80211_check_u16); |
63c5723b | 5824 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5825 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5826 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
f151d9db | 5827 | nl80211_check_bool); |
ea54fba2 | 5828 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea | 5829 | mask, NL80211_MESHCONF_FORWARDING, |
f151d9db | 5830 | nl80211_check_bool); |
83374fe9 | 5831 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5832 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
f151d9db | 5833 | nl80211_check_s32); |
9757235f MH |
5834 | /* |
5835 | * Check HT operation mode based on | |
5836 | * IEEE 802.11 2012 8.4.2.59 HT Operation element. | |
5837 | */ | |
5838 | if (tb[NL80211_MESHCONF_HT_OPMODE]) { | |
5839 | ht_opmode = nla_get_u16(tb[NL80211_MESHCONF_HT_OPMODE]); | |
5840 | ||
5841 | if (ht_opmode & ~(IEEE80211_HT_OP_MODE_PROTECTION | | |
5842 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT | | |
5843 | IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5844 | return -EINVAL; | |
5845 | ||
5846 | if ((ht_opmode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT) && | |
5847 | (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5848 | return -EINVAL; | |
5849 | ||
5850 | switch (ht_opmode & IEEE80211_HT_OP_MODE_PROTECTION) { | |
5851 | case IEEE80211_HT_OP_MODE_PROTECTION_NONE: | |
5852 | case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ: | |
5853 | if (ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT) | |
5854 | return -EINVAL; | |
5855 | break; | |
5856 | case IEEE80211_HT_OP_MODE_PROTECTION_NONMEMBER: | |
5857 | case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED: | |
5858 | if (!(ht_opmode & IEEE80211_HT_OP_MODE_NON_HT_STA_PRSNT)) | |
5859 | return -EINVAL; | |
5860 | break; | |
5861 | } | |
5862 | cfg->ht_opmode = ht_opmode; | |
5863 | } | |
ac1073a6 | 5864 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, |
ea54fba2 | 5865 | 1, 65535, mask, |
ac1073a6 | 5866 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
f151d9db | 5867 | nl80211_check_u32); |
ea54fba2 | 5868 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5869 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
f151d9db | 5870 | nl80211_check_u16); |
728b19e5 | 5871 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5872 | dot11MeshHWMPconfirmationInterval, |
5873 | 1, 65535, mask, | |
728b19e5 | 5874 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
f151d9db | 5875 | nl80211_check_u16); |
3b1c5a53 MP |
5876 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5877 | NL80211_MESH_POWER_ACTIVE, | |
5878 | NL80211_MESH_POWER_MAX, | |
5879 | mask, NL80211_MESHCONF_POWER_MODE, | |
ff9a71af | 5880 | nl80211_check_power_mode); |
3b1c5a53 MP |
5881 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, |
5882 | 0, 65535, mask, | |
f151d9db | 5883 | NL80211_MESHCONF_AWAKE_WINDOW, nl80211_check_u16); |
31f909a2 | 5884 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
8e7c0538 | 5885 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
f151d9db | 5886 | nl80211_check_u32); |
bd90fdcc JB |
5887 | if (mask_out) |
5888 | *mask_out = mask; | |
c80d545d | 5889 | |
bd90fdcc JB |
5890 | return 0; |
5891 | ||
5892 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5893 | } | |
5894 | ||
c80d545d JC |
5895 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5896 | struct mesh_setup *setup) | |
5897 | { | |
bb2798d4 | 5898 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5899 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5900 | ||
5901 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5902 | return -EINVAL; | |
5903 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5904 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5905 | nl80211_mesh_setup_params_policy)) | |
5906 | return -EINVAL; | |
5907 | ||
d299a1f2 JC |
5908 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5909 | setup->sync_method = | |
5910 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5911 | IEEE80211_SYNC_METHOD_VENDOR : | |
5912 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5913 | ||
c80d545d JC |
5914 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5915 | setup->path_sel_proto = | |
5916 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5917 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5918 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5919 | ||
5920 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5921 | setup->path_metric = | |
5922 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5923 | IEEE80211_PATH_METRIC_VENDOR : | |
5924 | IEEE80211_PATH_METRIC_AIRTIME; | |
5925 | ||
581a8b0f | 5926 | if (tb[NL80211_MESH_SETUP_IE]) { |
c80d545d | 5927 | struct nlattr *ieattr = |
581a8b0f | 5928 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5929 | if (!is_valid_ie_attr(ieattr)) |
5930 | return -EINVAL; | |
581a8b0f JC |
5931 | setup->ie = nla_data(ieattr); |
5932 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5933 | } |
bb2798d4 TP |
5934 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5935 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5936 | return -EINVAL; | |
5937 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5938 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5939 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5940 | if (setup->is_secure) |
5941 | setup->user_mpm = true; | |
c80d545d | 5942 | |
6e16d90b CT |
5943 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5944 | if (!setup->user_mpm) | |
5945 | return -EINVAL; | |
5946 | setup->auth_id = | |
5947 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5948 | } | |
5949 | ||
c80d545d JC |
5950 | return 0; |
5951 | } | |
5952 | ||
24bdd9f4 | 5953 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5954 | struct genl_info *info) |
bd90fdcc JB |
5955 | { |
5956 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5957 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5958 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5959 | struct mesh_config cfg; |
5960 | u32 mask; | |
5961 | int err; | |
5962 | ||
29cbe68c JB |
5963 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5964 | return -EOPNOTSUPP; | |
5965 | ||
24bdd9f4 | 5966 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5967 | return -EOPNOTSUPP; |
5968 | ||
24bdd9f4 | 5969 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5970 | if (err) |
5971 | return err; | |
5972 | ||
29cbe68c JB |
5973 | wdev_lock(wdev); |
5974 | if (!wdev->mesh_id_len) | |
5975 | err = -ENOLINK; | |
5976 | ||
5977 | if (!err) | |
e35e4d28 | 5978 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5979 | |
5980 | wdev_unlock(wdev); | |
5981 | ||
5982 | return err; | |
93da9cc1 | 5983 | } |
5984 | ||
ad30ca2c AN |
5985 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5986 | struct sk_buff *msg) | |
f130347c | 5987 | { |
f130347c LR |
5988 | struct nlattr *nl_reg_rules; |
5989 | unsigned int i; | |
f130347c | 5990 | |
458f4f9e JB |
5991 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5992 | (regdom->dfs_region && | |
5993 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5994 | goto nla_put_failure; |
458f4f9e | 5995 | |
f130347c LR |
5996 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5997 | if (!nl_reg_rules) | |
ad30ca2c | 5998 | goto nla_put_failure; |
f130347c | 5999 | |
458f4f9e | 6000 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
6001 | struct nlattr *nl_reg_rule; |
6002 | const struct ieee80211_reg_rule *reg_rule; | |
6003 | const struct ieee80211_freq_range *freq_range; | |
6004 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 6005 | unsigned int max_bandwidth_khz; |
f130347c | 6006 | |
458f4f9e | 6007 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
6008 | freq_range = ®_rule->freq_range; |
6009 | power_rule = ®_rule->power_rule; | |
6010 | ||
6011 | nl_reg_rule = nla_nest_start(msg, i); | |
6012 | if (!nl_reg_rule) | |
ad30ca2c | 6013 | goto nla_put_failure; |
f130347c | 6014 | |
97524820 JD |
6015 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
6016 | if (!max_bandwidth_khz) | |
6017 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
6018 | reg_rule); | |
6019 | ||
9360ffd1 DM |
6020 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
6021 | reg_rule->flags) || | |
6022 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
6023 | freq_range->start_freq_khz) || | |
6024 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
6025 | freq_range->end_freq_khz) || | |
6026 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 6027 | max_bandwidth_khz) || |
9360ffd1 DM |
6028 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
6029 | power_rule->max_antenna_gain) || | |
6030 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
6031 | power_rule->max_eirp) || |
6032 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
6033 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 6034 | goto nla_put_failure; |
f130347c LR |
6035 | |
6036 | nla_nest_end(msg, nl_reg_rule); | |
6037 | } | |
6038 | ||
6039 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
6040 | return 0; |
6041 | ||
6042 | nla_put_failure: | |
6043 | return -EMSGSIZE; | |
6044 | } | |
6045 | ||
6046 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
6047 | { | |
6048 | const struct ieee80211_regdomain *regdom = NULL; | |
6049 | struct cfg80211_registered_device *rdev; | |
6050 | struct wiphy *wiphy = NULL; | |
6051 | struct sk_buff *msg; | |
6052 | void *hdr; | |
6053 | ||
6054 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
6055 | if (!msg) | |
6056 | return -ENOBUFS; | |
6057 | ||
6058 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
6059 | NL80211_CMD_GET_REG); | |
6060 | if (!hdr) | |
6061 | goto put_failure; | |
6062 | ||
6063 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
6064 | bool self_managed; |
6065 | ||
ad30ca2c AN |
6066 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
6067 | if (IS_ERR(rdev)) { | |
6068 | nlmsg_free(msg); | |
6069 | return PTR_ERR(rdev); | |
6070 | } | |
6071 | ||
6072 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
6073 | self_managed = wiphy->regulatory_flags & |
6074 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
6075 | regdom = get_wiphy_regdom(wiphy); |
6076 | ||
1bdd716c AN |
6077 | /* a self-managed-reg device must have a private regdom */ |
6078 | if (WARN_ON(!regdom && self_managed)) { | |
6079 | nlmsg_free(msg); | |
6080 | return -EINVAL; | |
6081 | } | |
6082 | ||
ad30ca2c AN |
6083 | if (regdom && |
6084 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6085 | goto nla_put_failure; | |
6086 | } | |
6087 | ||
6088 | if (!wiphy && reg_last_request_cell_base() && | |
6089 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6090 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6091 | goto nla_put_failure; | |
6092 | ||
6093 | rcu_read_lock(); | |
6094 | ||
6095 | if (!regdom) | |
6096 | regdom = rcu_dereference(cfg80211_regdomain); | |
6097 | ||
6098 | if (nl80211_put_regdom(regdom, msg)) | |
6099 | goto nla_put_failure_rcu; | |
6100 | ||
6101 | rcu_read_unlock(); | |
f130347c LR |
6102 | |
6103 | genlmsg_end(msg, hdr); | |
5fe231e8 | 6104 | return genlmsg_reply(msg, info); |
f130347c | 6105 | |
458f4f9e JB |
6106 | nla_put_failure_rcu: |
6107 | rcu_read_unlock(); | |
f130347c LR |
6108 | nla_put_failure: |
6109 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 6110 | put_failure: |
d080e275 | 6111 | nlmsg_free(msg); |
5fe231e8 | 6112 | return -EMSGSIZE; |
f130347c LR |
6113 | } |
6114 | ||
ad30ca2c AN |
6115 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
6116 | u32 seq, int flags, struct wiphy *wiphy, | |
6117 | const struct ieee80211_regdomain *regdom) | |
6118 | { | |
6119 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
6120 | NL80211_CMD_GET_REG); | |
6121 | ||
6122 | if (!hdr) | |
6123 | return -1; | |
6124 | ||
6125 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
6126 | ||
6127 | if (nl80211_put_regdom(regdom, msg)) | |
6128 | goto nla_put_failure; | |
6129 | ||
6130 | if (!wiphy && reg_last_request_cell_base() && | |
6131 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
6132 | NL80211_USER_REG_HINT_CELL_BASE)) | |
6133 | goto nla_put_failure; | |
6134 | ||
6135 | if (wiphy && | |
6136 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
6137 | goto nla_put_failure; | |
6138 | ||
1bdd716c AN |
6139 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
6140 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
6141 | goto nla_put_failure; | |
6142 | ||
053c095a JB |
6143 | genlmsg_end(msg, hdr); |
6144 | return 0; | |
ad30ca2c AN |
6145 | |
6146 | nla_put_failure: | |
6147 | genlmsg_cancel(msg, hdr); | |
6148 | return -EMSGSIZE; | |
6149 | } | |
6150 | ||
6151 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
6152 | struct netlink_callback *cb) | |
6153 | { | |
6154 | const struct ieee80211_regdomain *regdom = NULL; | |
6155 | struct cfg80211_registered_device *rdev; | |
6156 | int err, reg_idx, start = cb->args[2]; | |
6157 | ||
6158 | rtnl_lock(); | |
6159 | ||
6160 | if (cfg80211_regdomain && start == 0) { | |
6161 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6162 | NLM_F_MULTI, NULL, | |
6163 | rtnl_dereference(cfg80211_regdomain)); | |
6164 | if (err < 0) | |
6165 | goto out_err; | |
6166 | } | |
6167 | ||
6168 | /* the global regdom is idx 0 */ | |
6169 | reg_idx = 1; | |
6170 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
6171 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
6172 | if (!regdom) | |
6173 | continue; | |
6174 | ||
6175 | if (++reg_idx <= start) | |
6176 | continue; | |
6177 | ||
6178 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
6179 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
6180 | if (err < 0) { | |
6181 | reg_idx--; | |
6182 | break; | |
6183 | } | |
6184 | } | |
6185 | ||
6186 | cb->args[2] = reg_idx; | |
6187 | err = skb->len; | |
6188 | out_err: | |
6189 | rtnl_unlock(); | |
6190 | return err; | |
6191 | } | |
6192 | ||
b6863036 JB |
6193 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
6194 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { | |
6195 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, | |
6196 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
6197 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
6198 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
6199 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
6200 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
6201 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, | |
6202 | }; | |
6203 | ||
6204 | static int parse_reg_rule(struct nlattr *tb[], | |
6205 | struct ieee80211_reg_rule *reg_rule) | |
6206 | { | |
6207 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
6208 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
6209 | ||
6210 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
6211 | return -EINVAL; | |
6212 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
6213 | return -EINVAL; | |
6214 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
6215 | return -EINVAL; | |
6216 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) | |
6217 | return -EINVAL; | |
6218 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) | |
6219 | return -EINVAL; | |
6220 | ||
6221 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
6222 | ||
6223 | freq_range->start_freq_khz = | |
6224 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
6225 | freq_range->end_freq_khz = | |
6226 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
6227 | freq_range->max_bandwidth_khz = | |
6228 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
6229 | ||
6230 | power_rule->max_eirp = | |
6231 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
6232 | ||
6233 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
6234 | power_rule->max_antenna_gain = | |
6235 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
6236 | ||
6237 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) | |
6238 | reg_rule->dfs_cac_ms = | |
6239 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
6240 | ||
6241 | return 0; | |
6242 | } | |
6243 | ||
b2e1b302 LR |
6244 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
6245 | { | |
6246 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
6247 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
6248 | char *alpha2; |
6249 | int rem_reg_rules, r; | |
b2e1b302 | 6250 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 6251 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 6252 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
6253 | |
6254 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
6255 | return -EINVAL; | |
6256 | ||
6257 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
6258 | return -EINVAL; | |
6259 | ||
6260 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
6261 | ||
8b60b078 LR |
6262 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
6263 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
6264 | ||
b2e1b302 | 6265 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 6266 | rem_reg_rules) { |
b2e1b302 LR |
6267 | num_rules++; |
6268 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 6269 | return -EINVAL; |
b2e1b302 LR |
6270 | } |
6271 | ||
e438768f LR |
6272 | if (!reg_is_valid_request(alpha2)) |
6273 | return -EINVAL; | |
6274 | ||
b2e1b302 | 6275 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 6276 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
6277 | |
6278 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
6279 | if (!rd) |
6280 | return -ENOMEM; | |
b2e1b302 LR |
6281 | |
6282 | rd->n_reg_rules = num_rules; | |
6283 | rd->alpha2[0] = alpha2[0]; | |
6284 | rd->alpha2[1] = alpha2[1]; | |
6285 | ||
8b60b078 LR |
6286 | /* |
6287 | * Disable DFS master mode if the DFS region was | |
6288 | * not supported or known on this kernel. | |
6289 | */ | |
6290 | if (reg_supported_dfs_region(dfs_region)) | |
6291 | rd->dfs_region = dfs_region; | |
6292 | ||
b2e1b302 | 6293 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 6294 | rem_reg_rules) { |
ae811e21 JB |
6295 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
6296 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
6297 | reg_rule_policy); | |
6298 | if (r) | |
6299 | goto bad_reg; | |
b2e1b302 LR |
6300 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
6301 | if (r) | |
6302 | goto bad_reg; | |
6303 | ||
6304 | rule_idx++; | |
6305 | ||
d0e18f83 LR |
6306 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
6307 | r = -EINVAL; | |
b2e1b302 | 6308 | goto bad_reg; |
d0e18f83 | 6309 | } |
b2e1b302 LR |
6310 | } |
6311 | ||
06627990 JB |
6312 | /* set_regdom takes ownership of rd */ |
6313 | return set_regdom(rd, REGD_SOURCE_CRDA); | |
d2372b31 | 6314 | bad_reg: |
b2e1b302 | 6315 | kfree(rd); |
d0e18f83 | 6316 | return r; |
b2e1b302 | 6317 | } |
b6863036 | 6318 | #endif /* CONFIG_CFG80211_CRDA_SUPPORT */ |
b2e1b302 | 6319 | |
83f5e2cf JB |
6320 | static int validate_scan_freqs(struct nlattr *freqs) |
6321 | { | |
6322 | struct nlattr *attr1, *attr2; | |
6323 | int n_channels = 0, tmp1, tmp2; | |
6324 | ||
6325 | nla_for_each_nested(attr1, freqs, tmp1) { | |
6326 | n_channels++; | |
6327 | /* | |
6328 | * Some hardware has a limited channel list for | |
6329 | * scanning, and it is pretty much nonsensical | |
6330 | * to scan for a channel twice, so disallow that | |
6331 | * and don't require drivers to check that the | |
6332 | * channel list they get isn't longer than what | |
6333 | * they can scan, as long as they can scan all | |
6334 | * the channels they registered at once. | |
6335 | */ | |
6336 | nla_for_each_nested(attr2, freqs, tmp2) | |
6337 | if (attr1 != attr2 && | |
6338 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
6339 | return 0; | |
6340 | } | |
6341 | ||
6342 | return n_channels; | |
6343 | } | |
6344 | ||
57fbcce3 | 6345 | static bool is_band_valid(struct wiphy *wiphy, enum nl80211_band b) |
38de03d2 | 6346 | { |
57fbcce3 | 6347 | return b < NUM_NL80211_BANDS && wiphy->bands[b]; |
38de03d2 AS |
6348 | } |
6349 | ||
6350 | static int parse_bss_select(struct nlattr *nla, struct wiphy *wiphy, | |
6351 | struct cfg80211_bss_selection *bss_select) | |
6352 | { | |
6353 | struct nlattr *attr[NL80211_BSS_SELECT_ATTR_MAX + 1]; | |
6354 | struct nlattr *nest; | |
6355 | int err; | |
6356 | bool found = false; | |
6357 | int i; | |
6358 | ||
6359 | /* only process one nested attribute */ | |
6360 | nest = nla_data(nla); | |
6361 | if (!nla_ok(nest, nla_len(nest))) | |
6362 | return -EINVAL; | |
6363 | ||
6364 | err = nla_parse(attr, NL80211_BSS_SELECT_ATTR_MAX, nla_data(nest), | |
6365 | nla_len(nest), nl80211_bss_select_policy); | |
6366 | if (err) | |
6367 | return err; | |
6368 | ||
6369 | /* only one attribute may be given */ | |
6370 | for (i = 0; i <= NL80211_BSS_SELECT_ATTR_MAX; i++) { | |
6371 | if (attr[i]) { | |
6372 | if (found) | |
6373 | return -EINVAL; | |
6374 | found = true; | |
6375 | } | |
6376 | } | |
6377 | ||
6378 | bss_select->behaviour = __NL80211_BSS_SELECT_ATTR_INVALID; | |
6379 | ||
6380 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI]) | |
6381 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI; | |
6382 | ||
6383 | if (attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]) { | |
6384 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_BAND_PREF; | |
6385 | bss_select->param.band_pref = | |
6386 | nla_get_u32(attr[NL80211_BSS_SELECT_ATTR_BAND_PREF]); | |
6387 | if (!is_band_valid(wiphy, bss_select->param.band_pref)) | |
6388 | return -EINVAL; | |
6389 | } | |
6390 | ||
6391 | if (attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]) { | |
6392 | struct nl80211_bss_select_rssi_adjust *adj_param; | |
6393 | ||
6394 | adj_param = nla_data(attr[NL80211_BSS_SELECT_ATTR_RSSI_ADJUST]); | |
6395 | bss_select->behaviour = NL80211_BSS_SELECT_ATTR_RSSI_ADJUST; | |
6396 | bss_select->param.adjust.band = adj_param->band; | |
6397 | bss_select->param.adjust.delta = adj_param->delta; | |
6398 | if (!is_band_valid(wiphy, bss_select->param.adjust.band)) | |
6399 | return -EINVAL; | |
6400 | } | |
6401 | ||
6402 | /* user-space did not provide behaviour attribute */ | |
6403 | if (bss_select->behaviour == __NL80211_BSS_SELECT_ATTR_INVALID) | |
6404 | return -EINVAL; | |
6405 | ||
6406 | if (!(wiphy->bss_select_support & BIT(bss_select->behaviour))) | |
6407 | return -EINVAL; | |
6408 | ||
6409 | return 0; | |
6410 | } | |
6411 | ||
ad2b26ab JB |
6412 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
6413 | u8 *mac_addr, u8 *mac_addr_mask) | |
6414 | { | |
6415 | int i; | |
6416 | ||
6417 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
d2beae10 JP |
6418 | eth_zero_addr(mac_addr); |
6419 | eth_zero_addr(mac_addr_mask); | |
ad2b26ab JB |
6420 | mac_addr[0] = 0x2; |
6421 | mac_addr_mask[0] = 0x3; | |
6422 | ||
6423 | return 0; | |
6424 | } | |
6425 | ||
6426 | /* need both or none */ | |
6427 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
6428 | return -EINVAL; | |
6429 | ||
6430 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
6431 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
6432 | ||
6433 | /* don't allow or configure an mcast address */ | |
6434 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
6435 | is_multicast_ether_addr(mac_addr)) | |
6436 | return -EINVAL; | |
6437 | ||
6438 | /* | |
6439 | * allow users to pass a MAC address that has bits set outside | |
6440 | * of the mask, but don't bother drivers with having to deal | |
6441 | * with such bits | |
6442 | */ | |
6443 | for (i = 0; i < ETH_ALEN; i++) | |
6444 | mac_addr[i] &= mac_addr_mask[i]; | |
6445 | ||
6446 | return 0; | |
6447 | } | |
6448 | ||
2a519311 JB |
6449 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
6450 | { | |
4c476991 | 6451 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 6452 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 6453 | struct cfg80211_scan_request *request; |
2a519311 JB |
6454 | struct nlattr *attr; |
6455 | struct wiphy *wiphy; | |
83f5e2cf | 6456 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 6457 | size_t ie_len; |
2a519311 | 6458 | |
f4a11bb0 JB |
6459 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6460 | return -EINVAL; | |
6461 | ||
79c97e97 | 6462 | wiphy = &rdev->wiphy; |
2a519311 | 6463 | |
cb3b7d87 AB |
6464 | if (wdev->iftype == NL80211_IFTYPE_NAN) |
6465 | return -EOPNOTSUPP; | |
6466 | ||
4c476991 JB |
6467 | if (!rdev->ops->scan) |
6468 | return -EOPNOTSUPP; | |
2a519311 | 6469 | |
f9d15d16 | 6470 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
6471 | err = -EBUSY; |
6472 | goto unlock; | |
6473 | } | |
2a519311 JB |
6474 | |
6475 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
6476 | n_channels = validate_scan_freqs( |
6477 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
6478 | if (!n_channels) { |
6479 | err = -EINVAL; | |
6480 | goto unlock; | |
6481 | } | |
2a519311 | 6482 | } else { |
bdfbec2d | 6483 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
6484 | } |
6485 | ||
6486 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
6487 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
6488 | n_ssids++; | |
6489 | ||
f9f47529 JB |
6490 | if (n_ssids > wiphy->max_scan_ssids) { |
6491 | err = -EINVAL; | |
6492 | goto unlock; | |
6493 | } | |
2a519311 | 6494 | |
70692ad2 JM |
6495 | if (info->attrs[NL80211_ATTR_IE]) |
6496 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
6497 | else | |
6498 | ie_len = 0; | |
6499 | ||
f9f47529 JB |
6500 | if (ie_len > wiphy->max_scan_ie_len) { |
6501 | err = -EINVAL; | |
6502 | goto unlock; | |
6503 | } | |
18a83659 | 6504 | |
2a519311 | 6505 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
6506 | + sizeof(*request->ssids) * n_ssids |
6507 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 6508 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
6509 | if (!request) { |
6510 | err = -ENOMEM; | |
6511 | goto unlock; | |
6512 | } | |
2a519311 | 6513 | |
2a519311 | 6514 | if (n_ssids) |
5ba63533 | 6515 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 6516 | request->n_ssids = n_ssids; |
70692ad2 | 6517 | if (ie_len) { |
13874e4b | 6518 | if (n_ssids) |
70692ad2 JM |
6519 | request->ie = (void *)(request->ssids + n_ssids); |
6520 | else | |
6521 | request->ie = (void *)(request->channels + n_channels); | |
6522 | } | |
2a519311 | 6523 | |
584991dc | 6524 | i = 0; |
2a519311 JB |
6525 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
6526 | /* user specified, bail out if channel not found */ | |
2a519311 | 6527 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
6528 | struct ieee80211_channel *chan; |
6529 | ||
6530 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6531 | ||
6532 | if (!chan) { | |
2a519311 JB |
6533 | err = -EINVAL; |
6534 | goto out_free; | |
6535 | } | |
584991dc JB |
6536 | |
6537 | /* ignore disabled channels */ | |
6538 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6539 | continue; | |
6540 | ||
6541 | request->channels[i] = chan; | |
2a519311 JB |
6542 | i++; |
6543 | } | |
6544 | } else { | |
57fbcce3 | 6545 | enum nl80211_band band; |
34850ab2 | 6546 | |
2a519311 | 6547 | /* all channels */ |
57fbcce3 | 6548 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
2a519311 | 6549 | int j; |
7a087e74 | 6550 | |
2a519311 JB |
6551 | if (!wiphy->bands[band]) |
6552 | continue; | |
6553 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
6554 | struct ieee80211_channel *chan; |
6555 | ||
6556 | chan = &wiphy->bands[band]->channels[j]; | |
6557 | ||
6558 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6559 | continue; | |
6560 | ||
6561 | request->channels[i] = chan; | |
2a519311 JB |
6562 | i++; |
6563 | } | |
6564 | } | |
6565 | } | |
6566 | ||
584991dc JB |
6567 | if (!i) { |
6568 | err = -EINVAL; | |
6569 | goto out_free; | |
6570 | } | |
6571 | ||
6572 | request->n_channels = i; | |
6573 | ||
2a519311 | 6574 | i = 0; |
13874e4b | 6575 | if (n_ssids) { |
2a519311 | 6576 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 6577 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
6578 | err = -EINVAL; |
6579 | goto out_free; | |
6580 | } | |
57a27e1d | 6581 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 6582 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
6583 | i++; |
6584 | } | |
6585 | } | |
6586 | ||
70692ad2 JM |
6587 | if (info->attrs[NL80211_ATTR_IE]) { |
6588 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
6589 | memcpy((void *)request->ie, |
6590 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
6591 | request->ie_len); |
6592 | } | |
6593 | ||
57fbcce3 | 6594 | for (i = 0; i < NUM_NL80211_BANDS; i++) |
a401d2bb JB |
6595 | if (wiphy->bands[i]) |
6596 | request->rates[i] = | |
6597 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
6598 | |
6599 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
6600 | nla_for_each_nested(attr, | |
6601 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
6602 | tmp) { | |
57fbcce3 | 6603 | enum nl80211_band band = nla_type(attr); |
34850ab2 | 6604 | |
57fbcce3 | 6605 | if (band < 0 || band >= NUM_NL80211_BANDS) { |
34850ab2 JB |
6606 | err = -EINVAL; |
6607 | goto out_free; | |
6608 | } | |
1b09cd82 FF |
6609 | |
6610 | if (!wiphy->bands[band]) | |
6611 | continue; | |
6612 | ||
34850ab2 JB |
6613 | err = ieee80211_get_ratemask(wiphy->bands[band], |
6614 | nla_data(attr), | |
6615 | nla_len(attr), | |
6616 | &request->rates[band]); | |
6617 | if (err) | |
6618 | goto out_free; | |
6619 | } | |
6620 | } | |
6621 | ||
1d76250b AS |
6622 | if (info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]) { |
6623 | if (!wiphy_ext_feature_isset(wiphy, | |
6624 | NL80211_EXT_FEATURE_SET_SCAN_DWELL)) { | |
6625 | err = -EOPNOTSUPP; | |
6626 | goto out_free; | |
6627 | } | |
6628 | ||
6629 | request->duration = | |
6630 | nla_get_u16(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION]); | |
6631 | request->duration_mandatory = | |
6632 | nla_get_flag(info->attrs[NL80211_ATTR_MEASUREMENT_DURATION_MANDATORY]); | |
6633 | } | |
6634 | ||
46856bbf | 6635 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
6636 | request->flags = nla_get_u32( |
6637 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
6638 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6639 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6640 | err = -EOPNOTSUPP; |
6641 | goto out_free; | |
6642 | } | |
ad2b26ab JB |
6643 | |
6644 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6645 | if (!(wiphy->features & | |
6646 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
6647 | err = -EOPNOTSUPP; | |
6648 | goto out_free; | |
6649 | } | |
6650 | ||
6651 | if (wdev->current_bss) { | |
6652 | err = -EOPNOTSUPP; | |
6653 | goto out_free; | |
6654 | } | |
6655 | ||
6656 | err = nl80211_parse_random_mac(info->attrs, | |
6657 | request->mac_addr, | |
6658 | request->mac_addr_mask); | |
6659 | if (err) | |
6660 | goto out_free; | |
6661 | } | |
46856bbf | 6662 | } |
ed473771 | 6663 | |
e9f935e3 RM |
6664 | request->no_cck = |
6665 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
6666 | ||
818965d3 JM |
6667 | if (info->attrs[NL80211_ATTR_MAC]) |
6668 | memcpy(request->bssid, nla_data(info->attrs[NL80211_ATTR_MAC]), | |
6669 | ETH_ALEN); | |
6670 | else | |
6671 | eth_broadcast_addr(request->bssid); | |
6672 | ||
fd014284 | 6673 | request->wdev = wdev; |
79c97e97 | 6674 | request->wiphy = &rdev->wiphy; |
15d6030b | 6675 | request->scan_start = jiffies; |
2a519311 | 6676 | |
79c97e97 | 6677 | rdev->scan_req = request; |
e35e4d28 | 6678 | err = rdev_scan(rdev, request); |
2a519311 | 6679 | |
463d0183 | 6680 | if (!err) { |
fd014284 JB |
6681 | nl80211_send_scan_start(rdev, wdev); |
6682 | if (wdev->netdev) | |
6683 | dev_hold(wdev->netdev); | |
4c476991 | 6684 | } else { |
2a519311 | 6685 | out_free: |
79c97e97 | 6686 | rdev->scan_req = NULL; |
2a519311 JB |
6687 | kfree(request); |
6688 | } | |
3b85875a | 6689 | |
f9f47529 | 6690 | unlock: |
2a519311 JB |
6691 | return err; |
6692 | } | |
6693 | ||
91d3ab46 VK |
6694 | static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info) |
6695 | { | |
6696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6697 | struct wireless_dev *wdev = info->user_ptr[1]; | |
6698 | ||
6699 | if (!rdev->ops->abort_scan) | |
6700 | return -EOPNOTSUPP; | |
6701 | ||
6702 | if (rdev->scan_msg) | |
6703 | return 0; | |
6704 | ||
6705 | if (!rdev->scan_req) | |
6706 | return -ENOENT; | |
6707 | ||
6708 | rdev_abort_scan(rdev, wdev); | |
6709 | return 0; | |
6710 | } | |
6711 | ||
3b06d277 AS |
6712 | static int |
6713 | nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans, | |
6714 | struct cfg80211_sched_scan_request *request, | |
6715 | struct nlattr **attrs) | |
6716 | { | |
6717 | int tmp, err, i = 0; | |
6718 | struct nlattr *attr; | |
6719 | ||
6720 | if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { | |
6721 | u32 interval; | |
6722 | ||
6723 | /* | |
6724 | * If scan plans are not specified, | |
6725 | * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this | |
6726 | * case one scan plan will be set with the specified scan | |
6727 | * interval and infinite number of iterations. | |
6728 | */ | |
6729 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6730 | return -EINVAL; | |
6731 | ||
6732 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); | |
6733 | if (!interval) | |
6734 | return -EINVAL; | |
6735 | ||
6736 | request->scan_plans[0].interval = | |
6737 | DIV_ROUND_UP(interval, MSEC_PER_SEC); | |
6738 | if (!request->scan_plans[0].interval) | |
6739 | return -EINVAL; | |
6740 | ||
6741 | if (request->scan_plans[0].interval > | |
6742 | wiphy->max_sched_scan_plan_interval) | |
6743 | request->scan_plans[0].interval = | |
6744 | wiphy->max_sched_scan_plan_interval; | |
6745 | ||
6746 | return 0; | |
6747 | } | |
6748 | ||
6749 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) { | |
6750 | struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1]; | |
6751 | ||
6752 | if (WARN_ON(i >= n_plans)) | |
6753 | return -EINVAL; | |
6754 | ||
6755 | err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX, | |
6756 | nla_data(attr), nla_len(attr), | |
6757 | nl80211_plan_policy); | |
6758 | if (err) | |
6759 | return err; | |
6760 | ||
6761 | if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]) | |
6762 | return -EINVAL; | |
6763 | ||
6764 | request->scan_plans[i].interval = | |
6765 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]); | |
6766 | if (!request->scan_plans[i].interval || | |
6767 | request->scan_plans[i].interval > | |
6768 | wiphy->max_sched_scan_plan_interval) | |
6769 | return -EINVAL; | |
6770 | ||
6771 | if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) { | |
6772 | request->scan_plans[i].iterations = | |
6773 | nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]); | |
6774 | if (!request->scan_plans[i].iterations || | |
6775 | (request->scan_plans[i].iterations > | |
6776 | wiphy->max_sched_scan_plan_iterations)) | |
6777 | return -EINVAL; | |
6778 | } else if (i < n_plans - 1) { | |
6779 | /* | |
6780 | * All scan plans but the last one must specify | |
6781 | * a finite number of iterations | |
6782 | */ | |
6783 | return -EINVAL; | |
6784 | } | |
6785 | ||
6786 | i++; | |
6787 | } | |
6788 | ||
6789 | /* | |
6790 | * The last scan plan must not specify the number of | |
6791 | * iterations, it is supposed to run infinitely | |
6792 | */ | |
6793 | if (request->scan_plans[n_plans - 1].iterations) | |
6794 | return -EINVAL; | |
6795 | ||
6796 | return 0; | |
6797 | } | |
6798 | ||
256da02d | 6799 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 6800 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 6801 | struct nlattr **attrs) |
807f8a8c LC |
6802 | { |
6803 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 6804 | struct nlattr *attr; |
3b06d277 | 6805 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0; |
57fbcce3 | 6806 | enum nl80211_band band; |
807f8a8c | 6807 | size_t ie_len; |
a1f1c21c | 6808 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 6809 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 6810 | |
256da02d LC |
6811 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
6812 | return ERR_PTR(-EINVAL); | |
807f8a8c | 6813 | |
256da02d | 6814 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 6815 | n_channels = validate_scan_freqs( |
256da02d | 6816 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 6817 | if (!n_channels) |
256da02d | 6818 | return ERR_PTR(-EINVAL); |
807f8a8c | 6819 | } else { |
bdfbec2d | 6820 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
6821 | } |
6822 | ||
256da02d LC |
6823 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
6824 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
6825 | tmp) |
6826 | n_ssids++; | |
6827 | ||
93b6aa69 | 6828 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 6829 | return ERR_PTR(-EINVAL); |
807f8a8c | 6830 | |
ea73cbce JB |
6831 | /* |
6832 | * First, count the number of 'real' matchsets. Due to an issue with | |
6833 | * the old implementation, matchsets containing only the RSSI attribute | |
6834 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
6835 | * RSSI for all matchsets, rather than their own matchset for reporting | |
6836 | * all APs with a strong RSSI. This is needed to be compatible with | |
6837 | * older userspace that treated a matchset with only the RSSI as the | |
6838 | * global RSSI for all other matchsets - if there are other matchsets. | |
6839 | */ | |
256da02d | 6840 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6841 | nla_for_each_nested(attr, |
256da02d | 6842 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
6843 | tmp) { |
6844 | struct nlattr *rssi; | |
6845 | ||
6846 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
6847 | nla_data(attr), nla_len(attr), | |
6848 | nl80211_match_policy); | |
6849 | if (err) | |
256da02d | 6850 | return ERR_PTR(err); |
ea73cbce JB |
6851 | /* add other standalone attributes here */ |
6852 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
6853 | n_match_sets++; | |
6854 | continue; | |
6855 | } | |
6856 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6857 | if (rssi) | |
6858 | default_match_rssi = nla_get_s32(rssi); | |
6859 | } | |
6860 | } | |
6861 | ||
6862 | /* However, if there's no other matchset, add the RSSI one */ | |
6863 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6864 | n_match_sets = 1; | |
a1f1c21c LC |
6865 | |
6866 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6867 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6868 | |
256da02d LC |
6869 | if (attrs[NL80211_ATTR_IE]) |
6870 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6871 | else |
6872 | ie_len = 0; | |
6873 | ||
5a865bad | 6874 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6875 | return ERR_PTR(-EINVAL); |
c10841ca | 6876 | |
3b06d277 AS |
6877 | if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) { |
6878 | /* | |
6879 | * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since | |
6880 | * each scan plan already specifies its own interval | |
6881 | */ | |
6882 | if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6883 | return ERR_PTR(-EINVAL); | |
6884 | ||
6885 | nla_for_each_nested(attr, | |
6886 | attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) | |
6887 | n_plans++; | |
6888 | } else { | |
6889 | /* | |
6890 | * The scan interval attribute is kept for backward | |
6891 | * compatibility. If no scan plans are specified and sched scan | |
6892 | * interval is specified, one scan plan will be set with this | |
6893 | * scan interval and infinite number of iterations. | |
6894 | */ | |
6895 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) | |
6896 | return ERR_PTR(-EINVAL); | |
6897 | ||
6898 | n_plans = 1; | |
6899 | } | |
6900 | ||
6901 | if (!n_plans || n_plans > wiphy->max_sched_scan_plans) | |
6902 | return ERR_PTR(-EINVAL); | |
6903 | ||
807f8a8c | 6904 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6905 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6906 | + sizeof(*request->match_sets) * n_match_sets |
3b06d277 | 6907 | + sizeof(*request->scan_plans) * n_plans |
a2cd43c5 | 6908 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6909 | + ie_len, GFP_KERNEL); |
256da02d LC |
6910 | if (!request) |
6911 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6912 | |
6913 | if (n_ssids) | |
6914 | request->ssids = (void *)&request->channels[n_channels]; | |
6915 | request->n_ssids = n_ssids; | |
6916 | if (ie_len) { | |
13874e4b | 6917 | if (n_ssids) |
807f8a8c LC |
6918 | request->ie = (void *)(request->ssids + n_ssids); |
6919 | else | |
6920 | request->ie = (void *)(request->channels + n_channels); | |
6921 | } | |
6922 | ||
a1f1c21c LC |
6923 | if (n_match_sets) { |
6924 | if (request->ie) | |
6925 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 6926 | else if (n_ssids) |
a1f1c21c LC |
6927 | request->match_sets = |
6928 | (void *)(request->ssids + n_ssids); | |
6929 | else | |
6930 | request->match_sets = | |
6931 | (void *)(request->channels + n_channels); | |
6932 | } | |
6933 | request->n_match_sets = n_match_sets; | |
6934 | ||
3b06d277 AS |
6935 | if (n_match_sets) |
6936 | request->scan_plans = (void *)(request->match_sets + | |
6937 | n_match_sets); | |
6938 | else if (request->ie) | |
6939 | request->scan_plans = (void *)(request->ie + ie_len); | |
6940 | else if (n_ssids) | |
6941 | request->scan_plans = (void *)(request->ssids + n_ssids); | |
6942 | else | |
6943 | request->scan_plans = (void *)(request->channels + n_channels); | |
6944 | ||
6945 | request->n_scan_plans = n_plans; | |
6946 | ||
807f8a8c | 6947 | i = 0; |
256da02d | 6948 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6949 | /* user specified, bail out if channel not found */ |
6950 | nla_for_each_nested(attr, | |
256da02d | 6951 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6952 | tmp) { |
6953 | struct ieee80211_channel *chan; | |
6954 | ||
6955 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6956 | ||
6957 | if (!chan) { | |
6958 | err = -EINVAL; | |
6959 | goto out_free; | |
6960 | } | |
6961 | ||
6962 | /* ignore disabled channels */ | |
6963 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6964 | continue; | |
6965 | ||
6966 | request->channels[i] = chan; | |
6967 | i++; | |
6968 | } | |
6969 | } else { | |
6970 | /* all channels */ | |
57fbcce3 | 6971 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
807f8a8c | 6972 | int j; |
7a087e74 | 6973 | |
807f8a8c LC |
6974 | if (!wiphy->bands[band]) |
6975 | continue; | |
6976 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6977 | struct ieee80211_channel *chan; | |
6978 | ||
6979 | chan = &wiphy->bands[band]->channels[j]; | |
6980 | ||
6981 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6982 | continue; | |
6983 | ||
6984 | request->channels[i] = chan; | |
6985 | i++; | |
6986 | } | |
6987 | } | |
6988 | } | |
6989 | ||
6990 | if (!i) { | |
6991 | err = -EINVAL; | |
6992 | goto out_free; | |
6993 | } | |
6994 | ||
6995 | request->n_channels = i; | |
6996 | ||
6997 | i = 0; | |
13874e4b | 6998 | if (n_ssids) { |
256da02d | 6999 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 7000 | tmp) { |
57a27e1d | 7001 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
7002 | err = -EINVAL; |
7003 | goto out_free; | |
7004 | } | |
57a27e1d | 7005 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
7006 | memcpy(request->ssids[i].ssid, nla_data(attr), |
7007 | nla_len(attr)); | |
807f8a8c LC |
7008 | i++; |
7009 | } | |
7010 | } | |
7011 | ||
a1f1c21c | 7012 | i = 0; |
256da02d | 7013 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 7014 | nla_for_each_nested(attr, |
256da02d | 7015 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 7016 | tmp) { |
88e920b4 | 7017 | struct nlattr *ssid, *rssi; |
a1f1c21c | 7018 | |
ae811e21 JB |
7019 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
7020 | nla_data(attr), nla_len(attr), | |
7021 | nl80211_match_policy); | |
7022 | if (err) | |
7023 | goto out_free; | |
4a4ab0d7 | 7024 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 7025 | if (ssid) { |
ea73cbce JB |
7026 | if (WARN_ON(i >= n_match_sets)) { |
7027 | /* this indicates a programming error, | |
7028 | * the loop above should have verified | |
7029 | * things properly | |
7030 | */ | |
7031 | err = -EINVAL; | |
7032 | goto out_free; | |
7033 | } | |
7034 | ||
a1f1c21c LC |
7035 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
7036 | err = -EINVAL; | |
7037 | goto out_free; | |
7038 | } | |
7039 | memcpy(request->match_sets[i].ssid.ssid, | |
7040 | nla_data(ssid), nla_len(ssid)); | |
7041 | request->match_sets[i].ssid.ssid_len = | |
7042 | nla_len(ssid); | |
56ab364f | 7043 | /* special attribute - old implementation w/a */ |
ea73cbce JB |
7044 | request->match_sets[i].rssi_thold = |
7045 | default_match_rssi; | |
7046 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
7047 | if (rssi) | |
7048 | request->match_sets[i].rssi_thold = | |
7049 | nla_get_s32(rssi); | |
a1f1c21c LC |
7050 | } |
7051 | i++; | |
7052 | } | |
ea73cbce JB |
7053 | |
7054 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 7055 | if (i == 0 && n_match_sets) |
ea73cbce JB |
7056 | request->match_sets[0].rssi_thold = default_match_rssi; |
7057 | ||
7058 | request->min_rssi_thold = INT_MAX; | |
7059 | for (i = 0; i < n_match_sets; i++) | |
7060 | request->min_rssi_thold = | |
7061 | min(request->match_sets[i].rssi_thold, | |
7062 | request->min_rssi_thold); | |
7063 | } else { | |
7064 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
7065 | } |
7066 | ||
9900e484 JB |
7067 | if (ie_len) { |
7068 | request->ie_len = ie_len; | |
807f8a8c | 7069 | memcpy((void *)request->ie, |
256da02d | 7070 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
7071 | request->ie_len); |
7072 | } | |
7073 | ||
256da02d | 7074 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 7075 | request->flags = nla_get_u32( |
256da02d | 7076 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
7077 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
7078 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
7079 | err = -EOPNOTSUPP; |
7080 | goto out_free; | |
7081 | } | |
ad2b26ab JB |
7082 | |
7083 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
7084 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
7085 | ||
7086 | if (!wdev) /* must be net-detect */ | |
7087 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
7088 | ||
7089 | if (!(wiphy->features & flg)) { | |
7090 | err = -EOPNOTSUPP; | |
7091 | goto out_free; | |
7092 | } | |
7093 | ||
7094 | if (wdev && wdev->current_bss) { | |
7095 | err = -EOPNOTSUPP; | |
7096 | goto out_free; | |
7097 | } | |
7098 | ||
7099 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
7100 | request->mac_addr_mask); | |
7101 | if (err) | |
7102 | goto out_free; | |
7103 | } | |
46856bbf | 7104 | } |
ed473771 | 7105 | |
9c748934 LC |
7106 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
7107 | request->delay = | |
7108 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
7109 | ||
3b06d277 AS |
7110 | err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs); |
7111 | if (err) | |
7112 | goto out_free; | |
7113 | ||
15d6030b | 7114 | request->scan_start = jiffies; |
807f8a8c | 7115 | |
256da02d | 7116 | return request; |
807f8a8c LC |
7117 | |
7118 | out_free: | |
7119 | kfree(request); | |
256da02d LC |
7120 | return ERR_PTR(err); |
7121 | } | |
7122 | ||
7123 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
7124 | struct genl_info *info) | |
7125 | { | |
7126 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7127 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 7128 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 7129 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
7130 | int err; |
7131 | ||
7132 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
7133 | !rdev->ops->sched_scan_start) | |
7134 | return -EOPNOTSUPP; | |
7135 | ||
7136 | if (rdev->sched_scan_req) | |
7137 | return -EINPROGRESS; | |
7138 | ||
31a60ed1 JR |
7139 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
7140 | info->attrs); | |
7141 | ||
7142 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
7143 | if (err) |
7144 | goto out_err; | |
7145 | ||
31a60ed1 | 7146 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
7147 | if (err) |
7148 | goto out_free; | |
7149 | ||
31a60ed1 JR |
7150 | sched_scan_req->dev = dev; |
7151 | sched_scan_req->wiphy = &rdev->wiphy; | |
7152 | ||
93a1e86c JR |
7153 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
7154 | sched_scan_req->owner_nlportid = info->snd_portid; | |
7155 | ||
31a60ed1 | 7156 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
7157 | |
7158 | nl80211_send_sched_scan(rdev, dev, | |
7159 | NL80211_CMD_START_SCHED_SCAN); | |
7160 | return 0; | |
7161 | ||
7162 | out_free: | |
31a60ed1 | 7163 | kfree(sched_scan_req); |
256da02d | 7164 | out_err: |
807f8a8c LC |
7165 | return err; |
7166 | } | |
7167 | ||
7168 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
7169 | struct genl_info *info) | |
7170 | { | |
7171 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7172 | ||
7173 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
7174 | !rdev->ops->sched_scan_stop) | |
7175 | return -EOPNOTSUPP; | |
7176 | ||
5fe231e8 | 7177 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
7178 | } |
7179 | ||
04f39047 SW |
7180 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
7181 | struct genl_info *info) | |
7182 | { | |
7183 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7184 | struct net_device *dev = info->user_ptr[1]; | |
7185 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7186 | struct cfg80211_chan_def chandef; | |
55f7435c | 7187 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 7188 | unsigned int cac_time_ms; |
04f39047 SW |
7189 | int err; |
7190 | ||
55f7435c LR |
7191 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
7192 | if (dfs_region == NL80211_DFS_UNSET) | |
7193 | return -EINVAL; | |
7194 | ||
04f39047 SW |
7195 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7196 | if (err) | |
7197 | return err; | |
7198 | ||
ff311bc1 SW |
7199 | if (netif_carrier_ok(dev)) |
7200 | return -EBUSY; | |
7201 | ||
04f39047 SW |
7202 | if (wdev->cac_started) |
7203 | return -EBUSY; | |
7204 | ||
2beb6dab | 7205 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 7206 | wdev->iftype); |
04f39047 SW |
7207 | if (err < 0) |
7208 | return err; | |
7209 | ||
7210 | if (err == 0) | |
7211 | return -EINVAL; | |
7212 | ||
fe7c3a1f | 7213 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
7214 | return -EINVAL; |
7215 | ||
7216 | if (!rdev->ops->start_radar_detection) | |
7217 | return -EOPNOTSUPP; | |
7218 | ||
31559f35 JD |
7219 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
7220 | if (WARN_ON(!cac_time_ms)) | |
7221 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
7222 | ||
a1056b1b | 7223 | err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms); |
04f39047 | 7224 | if (!err) { |
9e0e2961 | 7225 | wdev->chandef = chandef; |
04f39047 SW |
7226 | wdev->cac_started = true; |
7227 | wdev->cac_start_time = jiffies; | |
31559f35 | 7228 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 7229 | } |
04f39047 SW |
7230 | return err; |
7231 | } | |
7232 | ||
16ef1fe2 SW |
7233 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
7234 | { | |
7235 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7236 | struct net_device *dev = info->user_ptr[1]; | |
7237 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
7238 | struct cfg80211_csa_settings params; | |
7239 | /* csa_attrs is defined static to avoid waste of stack size - this | |
7240 | * function is called under RTNL lock, so this should not be a problem. | |
7241 | */ | |
7242 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 7243 | int err; |
ee4bc9e7 | 7244 | bool need_new_beacon = false; |
9a774c78 | 7245 | int len, i; |
252e07ca | 7246 | u32 cs_count; |
16ef1fe2 SW |
7247 | |
7248 | if (!rdev->ops->channel_switch || | |
7249 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
7250 | return -EOPNOTSUPP; | |
7251 | ||
ee4bc9e7 SW |
7252 | switch (dev->ieee80211_ptr->iftype) { |
7253 | case NL80211_IFTYPE_AP: | |
7254 | case NL80211_IFTYPE_P2P_GO: | |
7255 | need_new_beacon = true; | |
7256 | ||
7257 | /* useless if AP is not running */ | |
7258 | if (!wdev->beacon_interval) | |
1ff79dfa | 7259 | return -ENOTCONN; |
ee4bc9e7 SW |
7260 | break; |
7261 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
7262 | if (!wdev->ssid_len) |
7263 | return -ENOTCONN; | |
7264 | break; | |
c6da674a | 7265 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
7266 | if (!wdev->mesh_id_len) |
7267 | return -ENOTCONN; | |
ee4bc9e7 SW |
7268 | break; |
7269 | default: | |
16ef1fe2 | 7270 | return -EOPNOTSUPP; |
ee4bc9e7 | 7271 | } |
16ef1fe2 SW |
7272 | |
7273 | memset(¶ms, 0, sizeof(params)); | |
7274 | ||
7275 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7276 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
7277 | return -EINVAL; | |
7278 | ||
7279 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 7280 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
7281 | return -EINVAL; |
7282 | ||
252e07ca LC |
7283 | /* Even though the attribute is u32, the specification says |
7284 | * u8, so let's make sure we don't overflow. | |
7285 | */ | |
7286 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
7287 | if (cs_count > 255) | |
7288 | return -EINVAL; | |
7289 | ||
7290 | params.count = cs_count; | |
16ef1fe2 | 7291 | |
ee4bc9e7 SW |
7292 | if (!need_new_beacon) |
7293 | goto skip_beacons; | |
7294 | ||
16ef1fe2 SW |
7295 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
7296 | if (err) | |
7297 | return err; | |
7298 | ||
7299 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
7300 | info->attrs[NL80211_ATTR_CSA_IES], | |
7301 | nl80211_policy); | |
7302 | if (err) | |
7303 | return err; | |
7304 | ||
7305 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
7306 | if (err) | |
7307 | return err; | |
7308 | ||
7309 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
7310 | return -EINVAL; | |
7311 | ||
9a774c78 AO |
7312 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
7313 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
7314 | return -EINVAL; |
7315 | ||
9a774c78 AO |
7316 | params.n_counter_offsets_beacon = len / sizeof(u16); |
7317 | if (rdev->wiphy.max_num_csa_counters && | |
7318 | (params.n_counter_offsets_beacon > | |
7319 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
7320 | return -EINVAL; |
7321 | ||
9a774c78 AO |
7322 | params.counter_offsets_beacon = |
7323 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
7324 | ||
7325 | /* sanity checks - counters should fit and be the same */ | |
7326 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
7327 | u16 offset = params.counter_offsets_beacon[i]; | |
7328 | ||
7329 | if (offset >= params.beacon_csa.tail_len) | |
7330 | return -EINVAL; | |
7331 | ||
7332 | if (params.beacon_csa.tail[offset] != params.count) | |
7333 | return -EINVAL; | |
7334 | } | |
7335 | ||
16ef1fe2 | 7336 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
7337 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
7338 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
7339 | return -EINVAL; |
7340 | ||
9a774c78 AO |
7341 | params.n_counter_offsets_presp = len / sizeof(u16); |
7342 | if (rdev->wiphy.max_num_csa_counters && | |
ad5987b4 | 7343 | (params.n_counter_offsets_presp > |
9a774c78 | 7344 | rdev->wiphy.max_num_csa_counters)) |
16ef1fe2 | 7345 | return -EINVAL; |
9a774c78 AO |
7346 | |
7347 | params.counter_offsets_presp = | |
7348 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
7349 | ||
7350 | /* sanity checks - counters should fit and be the same */ | |
7351 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
7352 | u16 offset = params.counter_offsets_presp[i]; | |
7353 | ||
7354 | if (offset >= params.beacon_csa.probe_resp_len) | |
7355 | return -EINVAL; | |
7356 | ||
7357 | if (params.beacon_csa.probe_resp[offset] != | |
7358 | params.count) | |
7359 | return -EINVAL; | |
7360 | } | |
16ef1fe2 SW |
7361 | } |
7362 | ||
ee4bc9e7 | 7363 | skip_beacons: |
16ef1fe2 SW |
7364 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
7365 | if (err) | |
7366 | return err; | |
7367 | ||
923b352f AN |
7368 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, ¶ms.chandef, |
7369 | wdev->iftype)) | |
16ef1fe2 SW |
7370 | return -EINVAL; |
7371 | ||
2beb6dab LC |
7372 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
7373 | ¶ms.chandef, | |
7374 | wdev->iftype); | |
7375 | if (err < 0) | |
7376 | return err; | |
7377 | ||
dcc6c2f5 | 7378 | if (err > 0) |
2beb6dab | 7379 | params.radar_required = true; |
16ef1fe2 | 7380 | |
16ef1fe2 SW |
7381 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
7382 | params.block_tx = true; | |
7383 | ||
c56589ed SW |
7384 | wdev_lock(wdev); |
7385 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
7386 | wdev_unlock(wdev); | |
7387 | ||
7388 | return err; | |
16ef1fe2 SW |
7389 | } |
7390 | ||
9720bb3a JB |
7391 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
7392 | u32 seq, int flags, | |
2a519311 | 7393 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
7394 | struct wireless_dev *wdev, |
7395 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 7396 | { |
48ab905d | 7397 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 7398 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
7399 | void *hdr; |
7400 | struct nlattr *bss; | |
48ab905d JB |
7401 | |
7402 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 7403 | |
15e47304 | 7404 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
7405 | NL80211_CMD_NEW_SCAN_RESULTS); |
7406 | if (!hdr) | |
7407 | return -1; | |
7408 | ||
9720bb3a JB |
7409 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
7410 | ||
97990a06 JB |
7411 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
7412 | goto nla_put_failure; | |
7413 | if (wdev->netdev && | |
9360ffd1 DM |
7414 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
7415 | goto nla_put_failure; | |
2dad624e ND |
7416 | if (nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
7417 | NL80211_ATTR_PAD)) | |
97990a06 | 7418 | goto nla_put_failure; |
2a519311 JB |
7419 | |
7420 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
7421 | if (!bss) | |
7422 | goto nla_put_failure; | |
9360ffd1 | 7423 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 7424 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 7425 | goto nla_put_failure; |
9caf0364 JB |
7426 | |
7427 | rcu_read_lock(); | |
0e227084 JB |
7428 | /* indicate whether we have probe response data or not */ |
7429 | if (rcu_access_pointer(res->proberesp_ies) && | |
7430 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
7431 | goto fail_unlock_rcu; | |
7432 | ||
7433 | /* this pointer prefers to be pointed to probe response data | |
7434 | * but is always valid | |
7435 | */ | |
9caf0364 | 7436 | ies = rcu_dereference(res->ies); |
8cef2c9d | 7437 | if (ies) { |
2dad624e ND |
7438 | if (nla_put_u64_64bit(msg, NL80211_BSS_TSF, ies->tsf, |
7439 | NL80211_BSS_PAD)) | |
8cef2c9d | 7440 | goto fail_unlock_rcu; |
8cef2c9d JB |
7441 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
7442 | ies->len, ies->data)) | |
7443 | goto fail_unlock_rcu; | |
9caf0364 | 7444 | } |
0e227084 JB |
7445 | |
7446 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 7447 | ies = rcu_dereference(res->beacon_ies); |
0e227084 | 7448 | if (ies && ies->from_beacon) { |
2dad624e ND |
7449 | if (nla_put_u64_64bit(msg, NL80211_BSS_BEACON_TSF, ies->tsf, |
7450 | NL80211_BSS_PAD)) | |
8cef2c9d JB |
7451 | goto fail_unlock_rcu; |
7452 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
7453 | ies->len, ies->data)) | |
7454 | goto fail_unlock_rcu; | |
9caf0364 JB |
7455 | } |
7456 | rcu_read_unlock(); | |
7457 | ||
9360ffd1 DM |
7458 | if (res->beacon_interval && |
7459 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
7460 | goto nla_put_failure; | |
7461 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
7462 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 7463 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
7464 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
7465 | jiffies_to_msecs(jiffies - intbss->ts))) | |
7466 | goto nla_put_failure; | |
2a519311 | 7467 | |
1d76250b AS |
7468 | if (intbss->parent_tsf && |
7469 | (nla_put_u64_64bit(msg, NL80211_BSS_PARENT_TSF, | |
7470 | intbss->parent_tsf, NL80211_BSS_PAD) || | |
7471 | nla_put(msg, NL80211_BSS_PARENT_BSSID, ETH_ALEN, | |
7472 | intbss->parent_bssid))) | |
7473 | goto nla_put_failure; | |
7474 | ||
6e19bc4b | 7475 | if (intbss->ts_boottime && |
2dad624e ND |
7476 | nla_put_u64_64bit(msg, NL80211_BSS_LAST_SEEN_BOOTTIME, |
7477 | intbss->ts_boottime, NL80211_BSS_PAD)) | |
6e19bc4b DS |
7478 | goto nla_put_failure; |
7479 | ||
77965c97 | 7480 | switch (rdev->wiphy.signal_type) { |
2a519311 | 7481 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
7482 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
7483 | goto nla_put_failure; | |
2a519311 JB |
7484 | break; |
7485 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
7486 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
7487 | goto nla_put_failure; | |
2a519311 JB |
7488 | break; |
7489 | default: | |
7490 | break; | |
7491 | } | |
7492 | ||
48ab905d | 7493 | switch (wdev->iftype) { |
074ac8df | 7494 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 7495 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
7496 | if (intbss == wdev->current_bss && |
7497 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
7498 | NL80211_BSS_STATUS_ASSOCIATED)) | |
7499 | goto nla_put_failure; | |
48ab905d JB |
7500 | break; |
7501 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
7502 | if (intbss == wdev->current_bss && |
7503 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
7504 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
7505 | goto nla_put_failure; | |
48ab905d JB |
7506 | break; |
7507 | default: | |
7508 | break; | |
7509 | } | |
7510 | ||
2a519311 JB |
7511 | nla_nest_end(msg, bss); |
7512 | ||
053c095a JB |
7513 | genlmsg_end(msg, hdr); |
7514 | return 0; | |
2a519311 | 7515 | |
8cef2c9d JB |
7516 | fail_unlock_rcu: |
7517 | rcu_read_unlock(); | |
2a519311 JB |
7518 | nla_put_failure: |
7519 | genlmsg_cancel(msg, hdr); | |
7520 | return -EMSGSIZE; | |
7521 | } | |
7522 | ||
97990a06 | 7523 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 7524 | { |
48ab905d | 7525 | struct cfg80211_registered_device *rdev; |
2a519311 | 7526 | struct cfg80211_internal_bss *scan; |
48ab905d | 7527 | struct wireless_dev *wdev; |
97990a06 | 7528 | int start = cb->args[2], idx = 0; |
2a519311 JB |
7529 | int err; |
7530 | ||
97990a06 | 7531 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
7532 | if (err) |
7533 | return err; | |
2a519311 | 7534 | |
48ab905d JB |
7535 | wdev_lock(wdev); |
7536 | spin_lock_bh(&rdev->bss_lock); | |
7537 | cfg80211_bss_expire(rdev); | |
7538 | ||
9720bb3a JB |
7539 | cb->seq = rdev->bss_generation; |
7540 | ||
48ab905d | 7541 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
7542 | if (++idx <= start) |
7543 | continue; | |
9720bb3a | 7544 | if (nl80211_send_bss(skb, cb, |
2a519311 | 7545 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 7546 | rdev, wdev, scan) < 0) { |
2a519311 | 7547 | idx--; |
67748893 | 7548 | break; |
2a519311 JB |
7549 | } |
7550 | } | |
7551 | ||
48ab905d JB |
7552 | spin_unlock_bh(&rdev->bss_lock); |
7553 | wdev_unlock(wdev); | |
2a519311 | 7554 | |
97990a06 JB |
7555 | cb->args[2] = idx; |
7556 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 7557 | |
67748893 | 7558 | return skb->len; |
2a519311 JB |
7559 | } |
7560 | ||
15e47304 | 7561 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
7562 | int flags, struct net_device *dev, |
7563 | bool allow_radio_stats, | |
7564 | struct survey_info *survey) | |
61fa713c HS |
7565 | { |
7566 | void *hdr; | |
7567 | struct nlattr *infoattr; | |
7568 | ||
11f78ac3 JB |
7569 | /* skip radio stats if userspace didn't request them */ |
7570 | if (!survey->channel && !allow_radio_stats) | |
7571 | return 0; | |
7572 | ||
15e47304 | 7573 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
7574 | NL80211_CMD_NEW_SURVEY_RESULTS); |
7575 | if (!hdr) | |
7576 | return -ENOMEM; | |
7577 | ||
9360ffd1 DM |
7578 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
7579 | goto nla_put_failure; | |
61fa713c HS |
7580 | |
7581 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
7582 | if (!infoattr) | |
7583 | goto nla_put_failure; | |
7584 | ||
11f78ac3 JB |
7585 | if (survey->channel && |
7586 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
7587 | survey->channel->center_freq)) |
7588 | goto nla_put_failure; | |
7589 | ||
7590 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
7591 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
7592 | goto nla_put_failure; | |
7593 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
7594 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
7595 | goto nla_put_failure; | |
4ed20beb | 7596 | if ((survey->filled & SURVEY_INFO_TIME) && |
2dad624e ND |
7597 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME, |
7598 | survey->time, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7599 | goto nla_put_failure; |
4ed20beb | 7600 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
2dad624e ND |
7601 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_BUSY, |
7602 | survey->time_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7603 | goto nla_put_failure; |
4ed20beb | 7604 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
2dad624e ND |
7605 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, |
7606 | survey->time_ext_busy, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7607 | goto nla_put_failure; |
4ed20beb | 7608 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
2dad624e ND |
7609 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_RX, |
7610 | survey->time_rx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7611 | goto nla_put_failure; |
4ed20beb | 7612 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
2dad624e ND |
7613 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_TX, |
7614 | survey->time_tx, NL80211_SURVEY_INFO_PAD)) | |
9360ffd1 | 7615 | goto nla_put_failure; |
052536ab | 7616 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
2dad624e ND |
7617 | nla_put_u64_64bit(msg, NL80211_SURVEY_INFO_TIME_SCAN, |
7618 | survey->time_scan, NL80211_SURVEY_INFO_PAD)) | |
052536ab | 7619 | goto nla_put_failure; |
61fa713c HS |
7620 | |
7621 | nla_nest_end(msg, infoattr); | |
7622 | ||
053c095a JB |
7623 | genlmsg_end(msg, hdr); |
7624 | return 0; | |
61fa713c HS |
7625 | |
7626 | nla_put_failure: | |
7627 | genlmsg_cancel(msg, hdr); | |
7628 | return -EMSGSIZE; | |
7629 | } | |
7630 | ||
11f78ac3 | 7631 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c | 7632 | { |
c90c39da | 7633 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
61fa713c | 7634 | struct survey_info survey; |
1b8ec87a | 7635 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
7636 | struct wireless_dev *wdev; |
7637 | int survey_idx = cb->args[2]; | |
61fa713c | 7638 | int res; |
11f78ac3 | 7639 | bool radio_stats; |
61fa713c | 7640 | |
1b8ec87a | 7641 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
7642 | if (res) |
7643 | return res; | |
61fa713c | 7644 | |
11f78ac3 | 7645 | /* prepare_wdev_dump parsed the attributes */ |
c90c39da | 7646 | radio_stats = attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; |
11f78ac3 | 7647 | |
97990a06 JB |
7648 | if (!wdev->netdev) { |
7649 | res = -EINVAL; | |
7650 | goto out_err; | |
7651 | } | |
7652 | ||
1b8ec87a | 7653 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
7654 | res = -EOPNOTSUPP; |
7655 | goto out_err; | |
7656 | } | |
7657 | ||
7658 | while (1) { | |
1b8ec87a | 7659 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
7660 | if (res == -ENOENT) |
7661 | break; | |
7662 | if (res) | |
7663 | goto out_err; | |
7664 | ||
11f78ac3 JB |
7665 | /* don't send disabled channels, but do send non-channel data */ |
7666 | if (survey.channel && | |
7667 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
7668 | survey_idx++; |
7669 | continue; | |
7670 | } | |
7671 | ||
61fa713c | 7672 | if (nl80211_send_survey(skb, |
15e47304 | 7673 | NETLINK_CB(cb->skb).portid, |
61fa713c | 7674 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 7675 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
7676 | goto out; |
7677 | survey_idx++; | |
7678 | } | |
7679 | ||
7680 | out: | |
97990a06 | 7681 | cb->args[2] = survey_idx; |
61fa713c HS |
7682 | res = skb->len; |
7683 | out_err: | |
1b8ec87a | 7684 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
7685 | return res; |
7686 | } | |
7687 | ||
b23aa676 SO |
7688 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
7689 | { | |
7690 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
7691 | NL80211_WPA_VERSION_2)); | |
7692 | } | |
7693 | ||
636a5d36 JM |
7694 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
7695 | { | |
4c476991 JB |
7696 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7697 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7698 | struct ieee80211_channel *chan; |
e39e5b5e JM |
7699 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
7700 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 7701 | enum nl80211_auth_type auth_type; |
fffd0934 | 7702 | struct key_parse key; |
d5cdfacb | 7703 | bool local_state_change; |
636a5d36 | 7704 | |
f4a11bb0 JB |
7705 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7706 | return -EINVAL; | |
7707 | ||
7708 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7709 | return -EINVAL; | |
7710 | ||
1778092e JM |
7711 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
7712 | return -EINVAL; | |
7713 | ||
19957bb3 JB |
7714 | if (!info->attrs[NL80211_ATTR_SSID]) |
7715 | return -EINVAL; | |
7716 | ||
7717 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
7718 | return -EINVAL; | |
7719 | ||
fffd0934 JB |
7720 | err = nl80211_parse_key(info, &key); |
7721 | if (err) | |
7722 | return err; | |
7723 | ||
7724 | if (key.idx >= 0) { | |
e31b8213 JB |
7725 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
7726 | return -EINVAL; | |
fffd0934 JB |
7727 | if (!key.p.key || !key.p.key_len) |
7728 | return -EINVAL; | |
7729 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
7730 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
7731 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
7732 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
7733 | return -EINVAL; | |
b6b5555b | 7734 | if (key.idx > 3) |
fffd0934 JB |
7735 | return -EINVAL; |
7736 | } else { | |
7737 | key.p.key_len = 0; | |
7738 | key.p.key = NULL; | |
7739 | } | |
7740 | ||
afea0b7a JB |
7741 | if (key.idx >= 0) { |
7742 | int i; | |
7743 | bool ok = false; | |
7a087e74 | 7744 | |
afea0b7a JB |
7745 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { |
7746 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
7747 | ok = true; | |
7748 | break; | |
7749 | } | |
7750 | } | |
4c476991 JB |
7751 | if (!ok) |
7752 | return -EINVAL; | |
afea0b7a JB |
7753 | } |
7754 | ||
4c476991 JB |
7755 | if (!rdev->ops->auth) |
7756 | return -EOPNOTSUPP; | |
636a5d36 | 7757 | |
074ac8df | 7758 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7759 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7760 | return -EOPNOTSUPP; | |
eec60b03 | 7761 | |
19957bb3 | 7762 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
7763 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7764 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7765 | if (!chan) | |
4c476991 | 7766 | return -EINVAL; |
636a5d36 | 7767 | |
19957bb3 JB |
7768 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7769 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7770 | |
7771 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7772 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7773 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7774 | } |
7775 | ||
19957bb3 | 7776 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 7777 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 7778 | return -EINVAL; |
636a5d36 | 7779 | |
e39e5b5e JM |
7780 | if (auth_type == NL80211_AUTHTYPE_SAE && |
7781 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
7782 | return -EINVAL; | |
7783 | ||
7784 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
7785 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
7786 | return -EINVAL; | |
7787 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
7788 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
7789 | /* need to include at least Auth Transaction and Status Code */ | |
7790 | if (sae_data_len < 4) | |
7791 | return -EINVAL; | |
7792 | } | |
7793 | ||
d5cdfacb JM |
7794 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7795 | ||
95de817b JB |
7796 | /* |
7797 | * Since we no longer track auth state, ignore | |
7798 | * requests to only change local state. | |
7799 | */ | |
7800 | if (local_state_change) | |
7801 | return 0; | |
7802 | ||
91bf9b26 JB |
7803 | wdev_lock(dev->ieee80211_ptr); |
7804 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
7805 | ssid, ssid_len, ie, ie_len, | |
7806 | key.p.key, key.p.key_len, key.idx, | |
7807 | sae_data, sae_data_len); | |
7808 | wdev_unlock(dev->ieee80211_ptr); | |
7809 | return err; | |
636a5d36 JM |
7810 | } |
7811 | ||
c0692b8f JB |
7812 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
7813 | struct genl_info *info, | |
3dc27d25 JB |
7814 | struct cfg80211_crypto_settings *settings, |
7815 | int cipher_limit) | |
b23aa676 | 7816 | { |
c0b2bbd8 JB |
7817 | memset(settings, 0, sizeof(*settings)); |
7818 | ||
b23aa676 SO |
7819 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
7820 | ||
c0692b8f JB |
7821 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
7822 | u16 proto; | |
7a087e74 | 7823 | |
c0692b8f JB |
7824 | proto = nla_get_u16( |
7825 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
7826 | settings->control_port_ethertype = cpu_to_be16(proto); | |
7827 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
7828 | proto != ETH_P_PAE) | |
7829 | return -EINVAL; | |
7830 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
7831 | settings->control_port_no_encrypt = true; | |
7832 | } else | |
7833 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
7834 | ||
b23aa676 SO |
7835 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
7836 | void *data; | |
7837 | int len, i; | |
7838 | ||
7839 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
7840 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
7841 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
7842 | ||
7843 | if (len % sizeof(u32)) | |
7844 | return -EINVAL; | |
7845 | ||
3dc27d25 | 7846 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
7847 | return -EINVAL; |
7848 | ||
7849 | memcpy(settings->ciphers_pairwise, data, len); | |
7850 | ||
7851 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
7852 | if (!cfg80211_supported_cipher_suite( |
7853 | &rdev->wiphy, | |
b23aa676 SO |
7854 | settings->ciphers_pairwise[i])) |
7855 | return -EINVAL; | |
7856 | } | |
7857 | ||
7858 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
7859 | settings->cipher_group = | |
7860 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
7861 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
7862 | settings->cipher_group)) | |
b23aa676 SO |
7863 | return -EINVAL; |
7864 | } | |
7865 | ||
7866 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
7867 | settings->wpa_versions = | |
7868 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
7869 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
7870 | return -EINVAL; | |
7871 | } | |
7872 | ||
7873 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
7874 | void *data; | |
6d30240e | 7875 | int len; |
b23aa676 SO |
7876 | |
7877 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
7878 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
7879 | settings->n_akm_suites = len / sizeof(u32); | |
7880 | ||
7881 | if (len % sizeof(u32)) | |
7882 | return -EINVAL; | |
7883 | ||
1b9ca027 JM |
7884 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
7885 | return -EINVAL; | |
7886 | ||
b23aa676 | 7887 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
7888 | } |
7889 | ||
7890 | return 0; | |
7891 | } | |
7892 | ||
636a5d36 JM |
7893 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
7894 | { | |
4c476991 JB |
7895 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7896 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 7897 | struct ieee80211_channel *chan; |
f62fab73 JB |
7898 | struct cfg80211_assoc_request req = {}; |
7899 | const u8 *bssid, *ssid; | |
7900 | int err, ssid_len = 0; | |
636a5d36 | 7901 | |
f4a11bb0 JB |
7902 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7903 | return -EINVAL; | |
7904 | ||
7905 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
7906 | !info->attrs[NL80211_ATTR_SSID] || |
7907 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
7908 | return -EINVAL; |
7909 | ||
4c476991 JB |
7910 | if (!rdev->ops->assoc) |
7911 | return -EOPNOTSUPP; | |
636a5d36 | 7912 | |
074ac8df | 7913 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7914 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7915 | return -EOPNOTSUPP; | |
eec60b03 | 7916 | |
19957bb3 | 7917 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7918 | |
664834de JM |
7919 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7920 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7921 | if (!chan) | |
4c476991 | 7922 | return -EINVAL; |
636a5d36 | 7923 | |
19957bb3 JB |
7924 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7925 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7926 | |
7927 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7928 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7929 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7930 | } |
7931 | ||
dc6382ce | 7932 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7933 | enum nl80211_mfp mfp = |
dc6382ce | 7934 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7935 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7936 | req.use_mfp = true; |
4c476991 JB |
7937 | else if (mfp != NL80211_MFP_NO) |
7938 | return -EINVAL; | |
dc6382ce JM |
7939 | } |
7940 | ||
3e5d7649 | 7941 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7942 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7943 | |
7e7c8926 | 7944 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7945 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7946 | |
7947 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7948 | memcpy(&req.ht_capa_mask, |
7949 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7950 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7951 | |
7952 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7953 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7954 | return -EINVAL; |
f62fab73 JB |
7955 | memcpy(&req.ht_capa, |
7956 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7957 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7958 | } |
7959 | ||
ee2aca34 | 7960 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7961 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7962 | |
7963 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7964 | memcpy(&req.vht_capa_mask, |
7965 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7966 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7967 | |
7968 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7969 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7970 | return -EINVAL; |
f62fab73 JB |
7971 | memcpy(&req.vht_capa, |
7972 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7973 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7974 | } |
7975 | ||
bab5ab7d | 7976 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
7977 | if (!((rdev->wiphy.features & |
7978 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
7979 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
7980 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
7981 | NL80211_EXT_FEATURE_RRM)) | |
bab5ab7d AK |
7982 | return -EINVAL; |
7983 | req.flags |= ASSOC_REQ_USE_RRM; | |
7984 | } | |
7985 | ||
f62fab73 | 7986 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7987 | if (!err) { |
7988 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7989 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7990 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7991 | wdev_unlock(dev->ieee80211_ptr); |
7992 | } | |
636a5d36 | 7993 | |
636a5d36 JM |
7994 | return err; |
7995 | } | |
7996 | ||
7997 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7998 | { | |
4c476991 JB |
7999 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8000 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 8001 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 8002 | int ie_len = 0, err; |
19957bb3 | 8003 | u16 reason_code; |
d5cdfacb | 8004 | bool local_state_change; |
636a5d36 | 8005 | |
f4a11bb0 JB |
8006 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8007 | return -EINVAL; | |
8008 | ||
8009 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8010 | return -EINVAL; | |
8011 | ||
8012 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8013 | return -EINVAL; | |
8014 | ||
4c476991 JB |
8015 | if (!rdev->ops->deauth) |
8016 | return -EOPNOTSUPP; | |
636a5d36 | 8017 | |
074ac8df | 8018 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8019 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8020 | return -EOPNOTSUPP; | |
eec60b03 | 8021 | |
19957bb3 | 8022 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 8023 | |
19957bb3 JB |
8024 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
8025 | if (reason_code == 0) { | |
f4a11bb0 | 8026 | /* Reason Code 0 is reserved */ |
4c476991 | 8027 | return -EINVAL; |
255e737e | 8028 | } |
636a5d36 JM |
8029 | |
8030 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8031 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8032 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8033 | } |
8034 | ||
d5cdfacb JM |
8035 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8036 | ||
91bf9b26 JB |
8037 | wdev_lock(dev->ieee80211_ptr); |
8038 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
8039 | local_state_change); | |
8040 | wdev_unlock(dev->ieee80211_ptr); | |
8041 | return err; | |
636a5d36 JM |
8042 | } |
8043 | ||
8044 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
8045 | { | |
4c476991 JB |
8046 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8047 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 8048 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 8049 | int ie_len = 0, err; |
19957bb3 | 8050 | u16 reason_code; |
d5cdfacb | 8051 | bool local_state_change; |
636a5d36 | 8052 | |
f4a11bb0 JB |
8053 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8054 | return -EINVAL; | |
8055 | ||
8056 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8057 | return -EINVAL; | |
8058 | ||
8059 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8060 | return -EINVAL; | |
8061 | ||
4c476991 JB |
8062 | if (!rdev->ops->disassoc) |
8063 | return -EOPNOTSUPP; | |
636a5d36 | 8064 | |
074ac8df | 8065 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8066 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8067 | return -EOPNOTSUPP; | |
eec60b03 | 8068 | |
19957bb3 | 8069 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 8070 | |
19957bb3 JB |
8071 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
8072 | if (reason_code == 0) { | |
f4a11bb0 | 8073 | /* Reason Code 0 is reserved */ |
4c476991 | 8074 | return -EINVAL; |
255e737e | 8075 | } |
636a5d36 JM |
8076 | |
8077 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
8078 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
8079 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
8080 | } |
8081 | ||
d5cdfacb JM |
8082 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
8083 | ||
91bf9b26 JB |
8084 | wdev_lock(dev->ieee80211_ptr); |
8085 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
8086 | local_state_change); | |
8087 | wdev_unlock(dev->ieee80211_ptr); | |
8088 | return err; | |
636a5d36 JM |
8089 | } |
8090 | ||
dd5b4cc7 FF |
8091 | static bool |
8092 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
57fbcce3 | 8093 | int mcast_rate[NUM_NL80211_BANDS], |
dd5b4cc7 FF |
8094 | int rateval) |
8095 | { | |
8096 | struct wiphy *wiphy = &rdev->wiphy; | |
8097 | bool found = false; | |
8098 | int band, i; | |
8099 | ||
57fbcce3 | 8100 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
dd5b4cc7 FF |
8101 | struct ieee80211_supported_band *sband; |
8102 | ||
8103 | sband = wiphy->bands[band]; | |
8104 | if (!sband) | |
8105 | continue; | |
8106 | ||
8107 | for (i = 0; i < sband->n_bitrates; i++) { | |
8108 | if (sband->bitrates[i].bitrate == rateval) { | |
8109 | mcast_rate[band] = i + 1; | |
8110 | found = true; | |
8111 | break; | |
8112 | } | |
8113 | } | |
8114 | } | |
8115 | ||
8116 | return found; | |
8117 | } | |
8118 | ||
04a773ad JB |
8119 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
8120 | { | |
4c476991 JB |
8121 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8122 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
8123 | struct cfg80211_ibss_params ibss; |
8124 | struct wiphy *wiphy; | |
fffd0934 | 8125 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
8126 | int err; |
8127 | ||
8e30bc55 JB |
8128 | memset(&ibss, 0, sizeof(ibss)); |
8129 | ||
04a773ad JB |
8130 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
8131 | return -EINVAL; | |
8132 | ||
683b6d3b | 8133 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
8134 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
8135 | return -EINVAL; | |
8136 | ||
8e30bc55 JB |
8137 | ibss.beacon_interval = 100; |
8138 | ||
12d20fc9 | 8139 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) |
8e30bc55 JB |
8140 | ibss.beacon_interval = |
8141 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 PK |
8142 | |
8143 | err = cfg80211_validate_beacon_int(rdev, ibss.beacon_interval); | |
8144 | if (err) | |
8145 | return err; | |
8e30bc55 | 8146 | |
4c476991 JB |
8147 | if (!rdev->ops->join_ibss) |
8148 | return -EOPNOTSUPP; | |
04a773ad | 8149 | |
4c476991 JB |
8150 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
8151 | return -EOPNOTSUPP; | |
04a773ad | 8152 | |
79c97e97 | 8153 | wiphy = &rdev->wiphy; |
04a773ad | 8154 | |
39193498 | 8155 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 8156 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
8157 | |
8158 | if (!is_valid_ether_addr(ibss.bssid)) | |
8159 | return -EINVAL; | |
8160 | } | |
04a773ad JB |
8161 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8162 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8163 | ||
8164 | if (info->attrs[NL80211_ATTR_IE]) { | |
8165 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8166 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8167 | } | |
8168 | ||
683b6d3b JB |
8169 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
8170 | if (err) | |
8171 | return err; | |
04a773ad | 8172 | |
174e0cd2 IP |
8173 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
8174 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
8175 | return -EINVAL; |
8176 | ||
2f301ab2 | 8177 | switch (ibss.chandef.width) { |
bf372645 SW |
8178 | case NL80211_CHAN_WIDTH_5: |
8179 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
8180 | case NL80211_CHAN_WIDTH_20_NOHT: |
8181 | break; | |
8182 | case NL80211_CHAN_WIDTH_20: | |
8183 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
8184 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
8185 | return -EINVAL; | |
8186 | break; | |
8187 | case NL80211_CHAN_WIDTH_80: | |
8188 | case NL80211_CHAN_WIDTH_80P80: | |
8189 | case NL80211_CHAN_WIDTH_160: | |
8190 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
8191 | return -EINVAL; | |
8192 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
8193 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
8194 | return -EINVAL; | |
8195 | break; | |
2f301ab2 | 8196 | default: |
c04d6150 | 8197 | return -EINVAL; |
2f301ab2 | 8198 | } |
db9c64cf | 8199 | |
04a773ad | 8200 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
8201 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
8202 | ||
fbd2c8dc TP |
8203 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8204 | u8 *rates = | |
8205 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8206 | int n_rates = | |
8207 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8208 | struct ieee80211_supported_band *sband = | |
683b6d3b | 8209 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 8210 | |
34850ab2 JB |
8211 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
8212 | &ibss.basic_rates); | |
8213 | if (err) | |
8214 | return err; | |
fbd2c8dc | 8215 | } |
dd5b4cc7 | 8216 | |
803768f5 SW |
8217 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
8218 | memcpy(&ibss.ht_capa_mask, | |
8219 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8220 | sizeof(ibss.ht_capa_mask)); | |
8221 | ||
8222 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
8223 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
8224 | return -EINVAL; | |
8225 | memcpy(&ibss.ht_capa, | |
8226 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8227 | sizeof(ibss.ht_capa)); | |
8228 | } | |
8229 | ||
dd5b4cc7 FF |
8230 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8231 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
8232 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8233 | return -EINVAL; | |
fbd2c8dc | 8234 | |
4c476991 | 8235 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
8236 | bool no_ht = false; |
8237 | ||
4c476991 | 8238 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
8239 | info->attrs[NL80211_ATTR_KEYS], |
8240 | &no_ht); | |
4c476991 JB |
8241 | if (IS_ERR(connkeys)) |
8242 | return PTR_ERR(connkeys); | |
de7044ee | 8243 | |
3d9d1d66 JB |
8244 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
8245 | no_ht) { | |
5e950a78 | 8246 | kzfree(connkeys); |
de7044ee SM |
8247 | return -EINVAL; |
8248 | } | |
4c476991 | 8249 | } |
04a773ad | 8250 | |
267335d6 AQ |
8251 | ibss.control_port = |
8252 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
8253 | ||
5336fa88 SW |
8254 | ibss.userspace_handles_dfs = |
8255 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
8256 | ||
4c476991 | 8257 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 8258 | if (err) |
b47f610b | 8259 | kzfree(connkeys); |
04a773ad JB |
8260 | return err; |
8261 | } | |
8262 | ||
8263 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
8264 | { | |
4c476991 JB |
8265 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8266 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 8267 | |
4c476991 JB |
8268 | if (!rdev->ops->leave_ibss) |
8269 | return -EOPNOTSUPP; | |
04a773ad | 8270 | |
4c476991 JB |
8271 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
8272 | return -EOPNOTSUPP; | |
04a773ad | 8273 | |
4c476991 | 8274 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
8275 | } |
8276 | ||
f4e583c8 AQ |
8277 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
8278 | { | |
8279 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8280 | struct net_device *dev = info->user_ptr[1]; | |
57fbcce3 | 8281 | int mcast_rate[NUM_NL80211_BANDS]; |
f4e583c8 AQ |
8282 | u32 nla_rate; |
8283 | int err; | |
8284 | ||
8285 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
876dc930 BVB |
8286 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
8287 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB) | |
f4e583c8 AQ |
8288 | return -EOPNOTSUPP; |
8289 | ||
8290 | if (!rdev->ops->set_mcast_rate) | |
8291 | return -EOPNOTSUPP; | |
8292 | ||
8293 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
8294 | ||
8295 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
8296 | return -EINVAL; | |
8297 | ||
8298 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
8299 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
8300 | return -EINVAL; | |
8301 | ||
a1056b1b | 8302 | err = rdev_set_mcast_rate(rdev, dev, mcast_rate); |
f4e583c8 AQ |
8303 | |
8304 | return err; | |
8305 | } | |
8306 | ||
ad7e718c JB |
8307 | static struct sk_buff * |
8308 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
8309 | struct wireless_dev *wdev, int approxlen, |
8310 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
8311 | enum nl80211_attrs attr, |
8312 | const struct nl80211_vendor_cmd_info *info, | |
8313 | gfp_t gfp) | |
ad7e718c JB |
8314 | { |
8315 | struct sk_buff *skb; | |
8316 | void *hdr; | |
8317 | struct nlattr *data; | |
8318 | ||
8319 | skb = nlmsg_new(approxlen + 100, gfp); | |
8320 | if (!skb) | |
8321 | return NULL; | |
8322 | ||
8323 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
8324 | if (!hdr) { | |
8325 | kfree_skb(skb); | |
8326 | return NULL; | |
8327 | } | |
8328 | ||
8329 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
8330 | goto nla_put_failure; | |
567ffc35 JB |
8331 | |
8332 | if (info) { | |
8333 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
8334 | info->vendor_id)) | |
8335 | goto nla_put_failure; | |
8336 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
8337 | info->subcmd)) | |
8338 | goto nla_put_failure; | |
8339 | } | |
8340 | ||
6c09e791 | 8341 | if (wdev) { |
2dad624e ND |
8342 | if (nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
8343 | wdev_id(wdev), NL80211_ATTR_PAD)) | |
6c09e791 AK |
8344 | goto nla_put_failure; |
8345 | if (wdev->netdev && | |
8346 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
8347 | wdev->netdev->ifindex)) | |
8348 | goto nla_put_failure; | |
8349 | } | |
8350 | ||
ad7e718c | 8351 | data = nla_nest_start(skb, attr); |
76e1fb4b JB |
8352 | if (!data) |
8353 | goto nla_put_failure; | |
ad7e718c JB |
8354 | |
8355 | ((void **)skb->cb)[0] = rdev; | |
8356 | ((void **)skb->cb)[1] = hdr; | |
8357 | ((void **)skb->cb)[2] = data; | |
8358 | ||
8359 | return skb; | |
8360 | ||
8361 | nla_put_failure: | |
8362 | kfree_skb(skb); | |
8363 | return NULL; | |
8364 | } | |
f4e583c8 | 8365 | |
e03ad6ea | 8366 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 8367 | struct wireless_dev *wdev, |
e03ad6ea JB |
8368 | enum nl80211_commands cmd, |
8369 | enum nl80211_attrs attr, | |
8370 | int vendor_event_idx, | |
8371 | int approxlen, gfp_t gfp) | |
8372 | { | |
f26cbf40 | 8373 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
8374 | const struct nl80211_vendor_cmd_info *info; |
8375 | ||
8376 | switch (cmd) { | |
8377 | case NL80211_CMD_TESTMODE: | |
8378 | if (WARN_ON(vendor_event_idx != -1)) | |
8379 | return NULL; | |
8380 | info = NULL; | |
8381 | break; | |
8382 | case NL80211_CMD_VENDOR: | |
8383 | if (WARN_ON(vendor_event_idx < 0 || | |
8384 | vendor_event_idx >= wiphy->n_vendor_events)) | |
8385 | return NULL; | |
8386 | info = &wiphy->vendor_events[vendor_event_idx]; | |
8387 | break; | |
8388 | default: | |
8389 | WARN_ON(1); | |
8390 | return NULL; | |
8391 | } | |
8392 | ||
6c09e791 | 8393 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
e03ad6ea JB |
8394 | cmd, attr, info, gfp); |
8395 | } | |
8396 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
8397 | ||
8398 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
8399 | { | |
8400 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
8401 | void *hdr = ((void **)skb->cb)[1]; | |
8402 | struct nlattr *data = ((void **)skb->cb)[2]; | |
8403 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
8404 | ||
bd8c78e7 JB |
8405 | /* clear CB data for netlink core to own from now on */ |
8406 | memset(skb->cb, 0, sizeof(skb->cb)); | |
8407 | ||
e03ad6ea JB |
8408 | nla_nest_end(skb, data); |
8409 | genlmsg_end(skb, hdr); | |
8410 | ||
8411 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
8412 | mcgrp = NL80211_MCGRP_VENDOR; | |
8413 | ||
8414 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
8415 | mcgrp, gfp); | |
8416 | } | |
8417 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
8418 | ||
aff89a9b | 8419 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
8420 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
8421 | { | |
4c476991 | 8422 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
8423 | struct wireless_dev *wdev = |
8424 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
8425 | int err; |
8426 | ||
fc73f11f DS |
8427 | if (!rdev->ops->testmode_cmd) |
8428 | return -EOPNOTSUPP; | |
8429 | ||
8430 | if (IS_ERR(wdev)) { | |
8431 | err = PTR_ERR(wdev); | |
8432 | if (err != -EINVAL) | |
8433 | return err; | |
8434 | wdev = NULL; | |
8435 | } else if (wdev->wiphy != &rdev->wiphy) { | |
8436 | return -EINVAL; | |
8437 | } | |
8438 | ||
aff89a9b JB |
8439 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
8440 | return -EINVAL; | |
8441 | ||
ad7e718c | 8442 | rdev->cur_cmd_info = info; |
fc73f11f | 8443 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
8444 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
8445 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 8446 | rdev->cur_cmd_info = NULL; |
aff89a9b | 8447 | |
aff89a9b JB |
8448 | return err; |
8449 | } | |
8450 | ||
71063f0e WYG |
8451 | static int nl80211_testmode_dump(struct sk_buff *skb, |
8452 | struct netlink_callback *cb) | |
8453 | { | |
00918d33 | 8454 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
8455 | int err; |
8456 | long phy_idx; | |
8457 | void *data = NULL; | |
8458 | int data_len = 0; | |
8459 | ||
5fe231e8 JB |
8460 | rtnl_lock(); |
8461 | ||
71063f0e WYG |
8462 | if (cb->args[0]) { |
8463 | /* | |
8464 | * 0 is a valid index, but not valid for args[0], | |
8465 | * so we need to offset by 1. | |
8466 | */ | |
8467 | phy_idx = cb->args[0] - 1; | |
8468 | } else { | |
c90c39da JB |
8469 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
8470 | ||
71063f0e | 8471 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, |
c90c39da | 8472 | attrbuf, nl80211_fam.maxattr, nl80211_policy); |
71063f0e | 8473 | if (err) |
5fe231e8 | 8474 | goto out_err; |
00918d33 | 8475 | |
c90c39da | 8476 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
2bd7e35d | 8477 | if (IS_ERR(rdev)) { |
5fe231e8 JB |
8478 | err = PTR_ERR(rdev); |
8479 | goto out_err; | |
00918d33 | 8480 | } |
2bd7e35d JB |
8481 | phy_idx = rdev->wiphy_idx; |
8482 | rdev = NULL; | |
2bd7e35d | 8483 | |
c90c39da JB |
8484 | if (attrbuf[NL80211_ATTR_TESTDATA]) |
8485 | cb->args[1] = (long)attrbuf[NL80211_ATTR_TESTDATA]; | |
71063f0e WYG |
8486 | } |
8487 | ||
8488 | if (cb->args[1]) { | |
8489 | data = nla_data((void *)cb->args[1]); | |
8490 | data_len = nla_len((void *)cb->args[1]); | |
8491 | } | |
8492 | ||
00918d33 JB |
8493 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
8494 | if (!rdev) { | |
5fe231e8 JB |
8495 | err = -ENOENT; |
8496 | goto out_err; | |
71063f0e | 8497 | } |
71063f0e | 8498 | |
00918d33 | 8499 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
8500 | err = -EOPNOTSUPP; |
8501 | goto out_err; | |
8502 | } | |
8503 | ||
8504 | while (1) { | |
15e47304 | 8505 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
8506 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8507 | NL80211_CMD_TESTMODE); | |
8508 | struct nlattr *tmdata; | |
8509 | ||
cb35fba3 DC |
8510 | if (!hdr) |
8511 | break; | |
8512 | ||
9360ffd1 | 8513 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
8514 | genlmsg_cancel(skb, hdr); |
8515 | break; | |
8516 | } | |
8517 | ||
8518 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
8519 | if (!tmdata) { | |
8520 | genlmsg_cancel(skb, hdr); | |
8521 | break; | |
8522 | } | |
e35e4d28 | 8523 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
8524 | nla_nest_end(skb, tmdata); |
8525 | ||
8526 | if (err == -ENOBUFS || err == -ENOENT) { | |
8527 | genlmsg_cancel(skb, hdr); | |
8528 | break; | |
8529 | } else if (err) { | |
8530 | genlmsg_cancel(skb, hdr); | |
8531 | goto out_err; | |
8532 | } | |
8533 | ||
8534 | genlmsg_end(skb, hdr); | |
8535 | } | |
8536 | ||
8537 | err = skb->len; | |
8538 | /* see above */ | |
8539 | cb->args[0] = phy_idx + 1; | |
8540 | out_err: | |
5fe231e8 | 8541 | rtnl_unlock(); |
71063f0e WYG |
8542 | return err; |
8543 | } | |
aff89a9b JB |
8544 | #endif |
8545 | ||
b23aa676 SO |
8546 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
8547 | { | |
4c476991 JB |
8548 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8549 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
8550 | struct cfg80211_connect_params connect; |
8551 | struct wiphy *wiphy; | |
fffd0934 | 8552 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
8553 | int err; |
8554 | ||
8555 | memset(&connect, 0, sizeof(connect)); | |
8556 | ||
8557 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
8558 | return -EINVAL; | |
8559 | ||
8560 | if (!info->attrs[NL80211_ATTR_SSID] || | |
8561 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
8562 | return -EINVAL; | |
8563 | ||
8564 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
8565 | connect.auth_type = | |
8566 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
8567 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
8568 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
8569 | return -EINVAL; |
8570 | } else | |
8571 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
8572 | ||
8573 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
8574 | ||
c0692b8f | 8575 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 8576 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
8577 | if (err) |
8578 | return err; | |
b23aa676 | 8579 | |
074ac8df | 8580 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8581 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8582 | return -EOPNOTSUPP; | |
b23aa676 | 8583 | |
79c97e97 | 8584 | wiphy = &rdev->wiphy; |
b23aa676 | 8585 | |
4486ea98 BS |
8586 | connect.bg_scan_period = -1; |
8587 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
8588 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
8589 | connect.bg_scan_period = | |
8590 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
8591 | } | |
8592 | ||
b23aa676 SO |
8593 | if (info->attrs[NL80211_ATTR_MAC]) |
8594 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
8595 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
8596 | connect.bssid_hint = | |
8597 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
8598 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
8599 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
8600 | ||
8601 | if (info->attrs[NL80211_ATTR_IE]) { | |
8602 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
8603 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
8604 | } | |
8605 | ||
cee00a95 JM |
8606 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
8607 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
8608 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
8609 | connect.mfp != NL80211_MFP_NO) | |
8610 | return -EINVAL; | |
8611 | } else { | |
8612 | connect.mfp = NL80211_MFP_NO; | |
8613 | } | |
8614 | ||
ba6fbacf JM |
8615 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
8616 | connect.prev_bssid = | |
8617 | nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); | |
8618 | ||
b23aa676 | 8619 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
8620 | connect.channel = nl80211_get_valid_chan( |
8621 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
8622 | if (!connect.channel) | |
1df4a510 JM |
8623 | return -EINVAL; |
8624 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
8625 | connect.channel_hint = nl80211_get_valid_chan( |
8626 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
8627 | if (!connect.channel_hint) | |
4c476991 | 8628 | return -EINVAL; |
b23aa676 SO |
8629 | } |
8630 | ||
fffd0934 JB |
8631 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
8632 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 8633 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
8634 | if (IS_ERR(connkeys)) |
8635 | return PTR_ERR(connkeys); | |
fffd0934 JB |
8636 | } |
8637 | ||
7e7c8926 BG |
8638 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
8639 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
8640 | ||
8641 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
8642 | memcpy(&connect.ht_capa_mask, | |
8643 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
8644 | sizeof(connect.ht_capa_mask)); | |
8645 | ||
8646 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 8647 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 8648 | kzfree(connkeys); |
7e7c8926 | 8649 | return -EINVAL; |
b4e4f47e | 8650 | } |
7e7c8926 BG |
8651 | memcpy(&connect.ht_capa, |
8652 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
8653 | sizeof(connect.ht_capa)); | |
8654 | } | |
8655 | ||
ee2aca34 JB |
8656 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
8657 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
8658 | ||
8659 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
8660 | memcpy(&connect.vht_capa_mask, | |
8661 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
8662 | sizeof(connect.vht_capa_mask)); | |
8663 | ||
8664 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
8665 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 8666 | kzfree(connkeys); |
ee2aca34 JB |
8667 | return -EINVAL; |
8668 | } | |
8669 | memcpy(&connect.vht_capa, | |
8670 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
8671 | sizeof(connect.vht_capa)); | |
8672 | } | |
8673 | ||
bab5ab7d | 8674 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
0c9ca11b BL |
8675 | if (!((rdev->wiphy.features & |
8676 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) && | |
8677 | (rdev->wiphy.features & NL80211_FEATURE_QUIET)) && | |
8678 | !wiphy_ext_feature_isset(&rdev->wiphy, | |
8679 | NL80211_EXT_FEATURE_RRM)) { | |
707554b4 | 8680 | kzfree(connkeys); |
bab5ab7d | 8681 | return -EINVAL; |
707554b4 | 8682 | } |
bab5ab7d AK |
8683 | connect.flags |= ASSOC_REQ_USE_RRM; |
8684 | } | |
8685 | ||
34d50519 | 8686 | connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]); |
57fbcce3 | 8687 | if (connect.pbss && !rdev->wiphy.bands[NL80211_BAND_60GHZ]) { |
34d50519 LD |
8688 | kzfree(connkeys); |
8689 | return -EOPNOTSUPP; | |
8690 | } | |
8691 | ||
38de03d2 AS |
8692 | if (info->attrs[NL80211_ATTR_BSS_SELECT]) { |
8693 | /* bss selection makes no sense if bssid is set */ | |
8694 | if (connect.bssid) { | |
8695 | kzfree(connkeys); | |
8696 | return -EINVAL; | |
8697 | } | |
8698 | ||
8699 | err = parse_bss_select(info->attrs[NL80211_ATTR_BSS_SELECT], | |
8700 | wiphy, &connect.bss_select); | |
8701 | if (err) { | |
8702 | kzfree(connkeys); | |
8703 | return err; | |
8704 | } | |
8705 | } | |
8706 | ||
83739b03 | 8707 | wdev_lock(dev->ieee80211_ptr); |
4ce2bd9c JM |
8708 | err = cfg80211_connect(rdev, dev, &connect, connkeys, |
8709 | connect.prev_bssid); | |
83739b03 | 8710 | wdev_unlock(dev->ieee80211_ptr); |
fffd0934 | 8711 | if (err) |
b47f610b | 8712 | kzfree(connkeys); |
b23aa676 SO |
8713 | return err; |
8714 | } | |
8715 | ||
8716 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
8717 | { | |
4c476991 JB |
8718 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8719 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 8720 | u16 reason; |
83739b03 | 8721 | int ret; |
b23aa676 SO |
8722 | |
8723 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
8724 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
8725 | else | |
8726 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
8727 | ||
8728 | if (reason == 0) | |
8729 | return -EINVAL; | |
8730 | ||
074ac8df | 8731 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8732 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8733 | return -EOPNOTSUPP; | |
b23aa676 | 8734 | |
83739b03 JB |
8735 | wdev_lock(dev->ieee80211_ptr); |
8736 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
8737 | wdev_unlock(dev->ieee80211_ptr); | |
8738 | return ret; | |
b23aa676 SO |
8739 | } |
8740 | ||
463d0183 JB |
8741 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
8742 | { | |
4c476991 | 8743 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
8744 | struct net *net; |
8745 | int err; | |
463d0183 | 8746 | |
4b681c82 VK |
8747 | if (info->attrs[NL80211_ATTR_PID]) { |
8748 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
8749 | ||
8750 | net = get_net_ns_by_pid(pid); | |
8751 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
8752 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 8753 | |
4b681c82 VK |
8754 | net = get_net_ns_by_fd(fd); |
8755 | } else { | |
8756 | return -EINVAL; | |
8757 | } | |
463d0183 | 8758 | |
4c476991 JB |
8759 | if (IS_ERR(net)) |
8760 | return PTR_ERR(net); | |
463d0183 JB |
8761 | |
8762 | err = 0; | |
8763 | ||
8764 | /* check if anything to do */ | |
4c476991 JB |
8765 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
8766 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 8767 | |
463d0183 | 8768 | put_net(net); |
463d0183 JB |
8769 | return err; |
8770 | } | |
8771 | ||
67fbb16b SO |
8772 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
8773 | { | |
4c476991 | 8774 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
8775 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
8776 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 8777 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
8778 | struct cfg80211_pmksa pmksa; |
8779 | ||
8780 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
8781 | ||
8782 | if (!info->attrs[NL80211_ATTR_MAC]) | |
8783 | return -EINVAL; | |
8784 | ||
8785 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
8786 | return -EINVAL; | |
8787 | ||
67fbb16b SO |
8788 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
8789 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8790 | ||
074ac8df | 8791 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8792 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8793 | return -EOPNOTSUPP; | |
67fbb16b SO |
8794 | |
8795 | switch (info->genlhdr->cmd) { | |
8796 | case NL80211_CMD_SET_PMKSA: | |
8797 | rdev_ops = rdev->ops->set_pmksa; | |
8798 | break; | |
8799 | case NL80211_CMD_DEL_PMKSA: | |
8800 | rdev_ops = rdev->ops->del_pmksa; | |
8801 | break; | |
8802 | default: | |
8803 | WARN_ON(1); | |
8804 | break; | |
8805 | } | |
8806 | ||
4c476991 JB |
8807 | if (!rdev_ops) |
8808 | return -EOPNOTSUPP; | |
67fbb16b | 8809 | |
4c476991 | 8810 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
8811 | } |
8812 | ||
8813 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
8814 | { | |
4c476991 JB |
8815 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
8816 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 8817 | |
074ac8df | 8818 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8819 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8820 | return -EOPNOTSUPP; | |
67fbb16b | 8821 | |
4c476991 JB |
8822 | if (!rdev->ops->flush_pmksa) |
8823 | return -EOPNOTSUPP; | |
67fbb16b | 8824 | |
e35e4d28 | 8825 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
8826 | } |
8827 | ||
109086ce AN |
8828 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
8829 | { | |
8830 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8831 | struct net_device *dev = info->user_ptr[1]; | |
8832 | u8 action_code, dialog_token; | |
df942e7b | 8833 | u32 peer_capability = 0; |
109086ce AN |
8834 | u16 status_code; |
8835 | u8 *peer; | |
31fa97c5 | 8836 | bool initiator; |
109086ce AN |
8837 | |
8838 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
8839 | !rdev->ops->tdls_mgmt) | |
8840 | return -EOPNOTSUPP; | |
8841 | ||
8842 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
8843 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
8844 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
8845 | !info->attrs[NL80211_ATTR_IE] || | |
8846 | !info->attrs[NL80211_ATTR_MAC]) | |
8847 | return -EINVAL; | |
8848 | ||
8849 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8850 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
8851 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
8852 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 8853 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
8854 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
8855 | peer_capability = | |
8856 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 8857 | |
e35e4d28 | 8858 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 8859 | dialog_token, status_code, peer_capability, |
31fa97c5 | 8860 | initiator, |
e35e4d28 HG |
8861 | nla_data(info->attrs[NL80211_ATTR_IE]), |
8862 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
8863 | } |
8864 | ||
8865 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
8866 | { | |
8867 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8868 | struct net_device *dev = info->user_ptr[1]; | |
8869 | enum nl80211_tdls_operation operation; | |
8870 | u8 *peer; | |
8871 | ||
8872 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
8873 | !rdev->ops->tdls_oper) | |
8874 | return -EOPNOTSUPP; | |
8875 | ||
8876 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
8877 | !info->attrs[NL80211_ATTR_MAC]) | |
8878 | return -EINVAL; | |
8879 | ||
8880 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
8881 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
8882 | ||
e35e4d28 | 8883 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
8884 | } |
8885 | ||
9588bbd5 JM |
8886 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
8887 | struct genl_info *info) | |
8888 | { | |
4c476991 | 8889 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8890 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8891 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
8892 | struct sk_buff *msg; |
8893 | void *hdr; | |
8894 | u64 cookie; | |
683b6d3b | 8895 | u32 duration; |
9588bbd5 JM |
8896 | int err; |
8897 | ||
8898 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
8899 | !info->attrs[NL80211_ATTR_DURATION]) | |
8900 | return -EINVAL; | |
8901 | ||
8902 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
8903 | ||
ebf348fc JB |
8904 | if (!rdev->ops->remain_on_channel || |
8905 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
8906 | return -EOPNOTSUPP; | |
8907 | ||
9588bbd5 | 8908 | /* |
ebf348fc JB |
8909 | * We should be on that channel for at least a minimum amount of |
8910 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 8911 | */ |
ebf348fc | 8912 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 8913 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
8914 | return -EINVAL; |
8915 | ||
683b6d3b JB |
8916 | err = nl80211_parse_chandef(rdev, info, &chandef); |
8917 | if (err) | |
8918 | return err; | |
9588bbd5 JM |
8919 | |
8920 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8921 | if (!msg) |
8922 | return -ENOMEM; | |
9588bbd5 | 8923 | |
15e47304 | 8924 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 8925 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
8926 | if (!hdr) { |
8927 | err = -ENOBUFS; | |
9588bbd5 JM |
8928 | goto free_msg; |
8929 | } | |
8930 | ||
683b6d3b JB |
8931 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
8932 | duration, &cookie); | |
9588bbd5 JM |
8933 | |
8934 | if (err) | |
8935 | goto free_msg; | |
8936 | ||
2dad624e ND |
8937 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
8938 | NL80211_ATTR_PAD)) | |
9360ffd1 | 8939 | goto nla_put_failure; |
9588bbd5 JM |
8940 | |
8941 | genlmsg_end(msg, hdr); | |
4c476991 JB |
8942 | |
8943 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
8944 | |
8945 | nla_put_failure: | |
8946 | err = -ENOBUFS; | |
8947 | free_msg: | |
8948 | nlmsg_free(msg); | |
9588bbd5 JM |
8949 | return err; |
8950 | } | |
8951 | ||
8952 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
8953 | struct genl_info *info) | |
8954 | { | |
4c476991 | 8955 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8956 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 8957 | u64 cookie; |
9588bbd5 JM |
8958 | |
8959 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8960 | return -EINVAL; | |
8961 | ||
4c476991 JB |
8962 | if (!rdev->ops->cancel_remain_on_channel) |
8963 | return -EOPNOTSUPP; | |
9588bbd5 | 8964 | |
9588bbd5 JM |
8965 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
8966 | ||
e35e4d28 | 8967 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
8968 | } |
8969 | ||
13ae75b1 JM |
8970 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, |
8971 | struct genl_info *info) | |
8972 | { | |
13ae75b1 | 8973 | struct cfg80211_bitrate_mask mask; |
a7c7fbff | 8974 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8975 | struct net_device *dev = info->user_ptr[1]; |
a7c7fbff | 8976 | int err; |
13ae75b1 | 8977 | |
4c476991 JB |
8978 | if (!rdev->ops->set_bitrate_mask) |
8979 | return -EOPNOTSUPP; | |
13ae75b1 | 8980 | |
a7c7fbff PK |
8981 | err = nl80211_parse_tx_bitrate_mask(info, &mask); |
8982 | if (err) | |
8983 | return err; | |
13ae75b1 | 8984 | |
e35e4d28 | 8985 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8986 | } |
8987 | ||
2e161f78 | 8988 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8989 | { |
4c476991 | 8990 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8991 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8992 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8993 | |
8994 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8995 | return -EINVAL; | |
8996 | ||
2e161f78 JB |
8997 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8998 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8999 | |
71bbc994 JB |
9000 | switch (wdev->iftype) { |
9001 | case NL80211_IFTYPE_STATION: | |
9002 | case NL80211_IFTYPE_ADHOC: | |
9003 | case NL80211_IFTYPE_P2P_CLIENT: | |
9004 | case NL80211_IFTYPE_AP: | |
9005 | case NL80211_IFTYPE_AP_VLAN: | |
9006 | case NL80211_IFTYPE_MESH_POINT: | |
9007 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 9008 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 9009 | break; |
cb3b7d87 | 9010 | case NL80211_IFTYPE_NAN: |
71bbc994 | 9011 | default: |
4c476991 | 9012 | return -EOPNOTSUPP; |
71bbc994 | 9013 | } |
026331c4 JM |
9014 | |
9015 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
9016 | if (!rdev->ops->mgmt_tx) |
9017 | return -EOPNOTSUPP; | |
026331c4 | 9018 | |
15e47304 | 9019 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
9020 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
9021 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
9022 | } |
9023 | ||
2e161f78 | 9024 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 9025 | { |
4c476991 | 9026 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 9027 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 9028 | struct cfg80211_chan_def chandef; |
026331c4 | 9029 | int err; |
d64d373f | 9030 | void *hdr = NULL; |
026331c4 | 9031 | u64 cookie; |
e247bd90 | 9032 | struct sk_buff *msg = NULL; |
b176e629 AO |
9033 | struct cfg80211_mgmt_tx_params params = { |
9034 | .dont_wait_for_ack = | |
9035 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
9036 | }; | |
026331c4 | 9037 | |
683b6d3b | 9038 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
9039 | return -EINVAL; |
9040 | ||
4c476991 JB |
9041 | if (!rdev->ops->mgmt_tx) |
9042 | return -EOPNOTSUPP; | |
026331c4 | 9043 | |
71bbc994 | 9044 | switch (wdev->iftype) { |
ea141b75 AQ |
9045 | case NL80211_IFTYPE_P2P_DEVICE: |
9046 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
9047 | return -EINVAL; | |
71bbc994 JB |
9048 | case NL80211_IFTYPE_STATION: |
9049 | case NL80211_IFTYPE_ADHOC: | |
9050 | case NL80211_IFTYPE_P2P_CLIENT: | |
9051 | case NL80211_IFTYPE_AP: | |
9052 | case NL80211_IFTYPE_AP_VLAN: | |
9053 | case NL80211_IFTYPE_MESH_POINT: | |
9054 | case NL80211_IFTYPE_P2P_GO: | |
9055 | break; | |
cb3b7d87 | 9056 | case NL80211_IFTYPE_NAN: |
71bbc994 | 9057 | default: |
4c476991 | 9058 | return -EOPNOTSUPP; |
71bbc994 | 9059 | } |
026331c4 | 9060 | |
f7ca38df | 9061 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 9062 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 9063 | return -EINVAL; |
b176e629 | 9064 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
9065 | |
9066 | /* | |
9067 | * We should wait on the channel for at least a minimum amount | |
9068 | * of time (10ms) but no longer than the driver supports. | |
9069 | */ | |
b176e629 AO |
9070 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
9071 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc | 9072 | return -EINVAL; |
f7ca38df JB |
9073 | } |
9074 | ||
b176e629 | 9075 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 9076 | |
b176e629 | 9077 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
9078 | return -EINVAL; |
9079 | ||
b176e629 | 9080 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 9081 | |
ea141b75 AQ |
9082 | /* get the channel if any has been specified, otherwise pass NULL to |
9083 | * the driver. The latter will use the current one | |
9084 | */ | |
9085 | chandef.chan = NULL; | |
9086 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
9087 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
9088 | if (err) | |
9089 | return err; | |
9090 | } | |
9091 | ||
b176e629 | 9092 | if (!chandef.chan && params.offchan) |
ea141b75 | 9093 | return -EINVAL; |
026331c4 | 9094 | |
34d22ce2 AO |
9095 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
9096 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
9097 | ||
9098 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
9099 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
9100 | int i; | |
9101 | ||
9102 | if (len % sizeof(u16)) | |
9103 | return -EINVAL; | |
9104 | ||
9105 | params.n_csa_offsets = len / sizeof(u16); | |
9106 | params.csa_offsets = | |
9107 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
9108 | ||
9109 | /* check that all the offsets fit the frame */ | |
9110 | for (i = 0; i < params.n_csa_offsets; i++) { | |
9111 | if (params.csa_offsets[i] >= params.len) | |
9112 | return -EINVAL; | |
9113 | } | |
9114 | } | |
9115 | ||
b176e629 | 9116 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
9117 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
9118 | if (!msg) | |
9119 | return -ENOMEM; | |
026331c4 | 9120 | |
15e47304 | 9121 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 9122 | NL80211_CMD_FRAME); |
cb35fba3 DC |
9123 | if (!hdr) { |
9124 | err = -ENOBUFS; | |
e247bd90 JB |
9125 | goto free_msg; |
9126 | } | |
026331c4 | 9127 | } |
e247bd90 | 9128 | |
b176e629 AO |
9129 | params.chan = chandef.chan; |
9130 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
9131 | if (err) |
9132 | goto free_msg; | |
9133 | ||
e247bd90 | 9134 | if (msg) { |
2dad624e ND |
9135 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
9136 | NL80211_ATTR_PAD)) | |
9360ffd1 | 9137 | goto nla_put_failure; |
026331c4 | 9138 | |
e247bd90 JB |
9139 | genlmsg_end(msg, hdr); |
9140 | return genlmsg_reply(msg, info); | |
9141 | } | |
9142 | ||
9143 | return 0; | |
026331c4 JM |
9144 | |
9145 | nla_put_failure: | |
9146 | err = -ENOBUFS; | |
9147 | free_msg: | |
9148 | nlmsg_free(msg); | |
026331c4 JM |
9149 | return err; |
9150 | } | |
9151 | ||
f7ca38df JB |
9152 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
9153 | { | |
9154 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 9155 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
9156 | u64 cookie; |
9157 | ||
9158 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
9159 | return -EINVAL; | |
9160 | ||
9161 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
9162 | return -EOPNOTSUPP; | |
9163 | ||
71bbc994 JB |
9164 | switch (wdev->iftype) { |
9165 | case NL80211_IFTYPE_STATION: | |
9166 | case NL80211_IFTYPE_ADHOC: | |
9167 | case NL80211_IFTYPE_P2P_CLIENT: | |
9168 | case NL80211_IFTYPE_AP: | |
9169 | case NL80211_IFTYPE_AP_VLAN: | |
9170 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 9171 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 | 9172 | break; |
cb3b7d87 | 9173 | case NL80211_IFTYPE_NAN: |
71bbc994 | 9174 | default: |
f7ca38df | 9175 | return -EOPNOTSUPP; |
71bbc994 | 9176 | } |
f7ca38df JB |
9177 | |
9178 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
9179 | ||
e35e4d28 | 9180 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
9181 | } |
9182 | ||
ffb9eb3d KV |
9183 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
9184 | { | |
4c476991 | 9185 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 9186 | struct wireless_dev *wdev; |
4c476991 | 9187 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
9188 | u8 ps_state; |
9189 | bool state; | |
9190 | int err; | |
9191 | ||
4c476991 JB |
9192 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
9193 | return -EINVAL; | |
ffb9eb3d KV |
9194 | |
9195 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
9196 | ||
4c476991 JB |
9197 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
9198 | return -EINVAL; | |
ffb9eb3d KV |
9199 | |
9200 | wdev = dev->ieee80211_ptr; | |
9201 | ||
4c476991 JB |
9202 | if (!rdev->ops->set_power_mgmt) |
9203 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
9204 | |
9205 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
9206 | ||
9207 | if (state == wdev->ps) | |
4c476991 | 9208 | return 0; |
ffb9eb3d | 9209 | |
e35e4d28 | 9210 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
9211 | if (!err) |
9212 | wdev->ps = state; | |
ffb9eb3d KV |
9213 | return err; |
9214 | } | |
9215 | ||
9216 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
9217 | { | |
4c476991 | 9218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
9219 | enum nl80211_ps_state ps_state; |
9220 | struct wireless_dev *wdev; | |
4c476991 | 9221 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
9222 | struct sk_buff *msg; |
9223 | void *hdr; | |
9224 | int err; | |
9225 | ||
ffb9eb3d KV |
9226 | wdev = dev->ieee80211_ptr; |
9227 | ||
4c476991 JB |
9228 | if (!rdev->ops->set_power_mgmt) |
9229 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
9230 | |
9231 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
9232 | if (!msg) |
9233 | return -ENOMEM; | |
ffb9eb3d | 9234 | |
15e47304 | 9235 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
9236 | NL80211_CMD_GET_POWER_SAVE); |
9237 | if (!hdr) { | |
4c476991 | 9238 | err = -ENOBUFS; |
ffb9eb3d KV |
9239 | goto free_msg; |
9240 | } | |
9241 | ||
9242 | if (wdev->ps) | |
9243 | ps_state = NL80211_PS_ENABLED; | |
9244 | else | |
9245 | ps_state = NL80211_PS_DISABLED; | |
9246 | ||
9360ffd1 DM |
9247 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
9248 | goto nla_put_failure; | |
ffb9eb3d KV |
9249 | |
9250 | genlmsg_end(msg, hdr); | |
4c476991 | 9251 | return genlmsg_reply(msg, info); |
ffb9eb3d | 9252 | |
4c476991 | 9253 | nla_put_failure: |
ffb9eb3d | 9254 | err = -ENOBUFS; |
4c476991 | 9255 | free_msg: |
ffb9eb3d | 9256 | nlmsg_free(msg); |
ffb9eb3d KV |
9257 | return err; |
9258 | } | |
9259 | ||
94e860f1 JB |
9260 | static const struct nla_policy |
9261 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
9262 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
9263 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
9264 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
9265 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
9266 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
9267 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
9268 | }; |
9269 | ||
84f10708 | 9270 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 9271 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
9272 | { |
9273 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 9274 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 9275 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 9276 | |
d9d8b019 | 9277 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
9278 | return -EINVAL; |
9279 | ||
84f10708 TP |
9280 | if (!rdev->ops->set_cqm_txe_config) |
9281 | return -EOPNOTSUPP; | |
9282 | ||
9283 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
9284 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
9285 | return -EOPNOTSUPP; | |
9286 | ||
e35e4d28 | 9287 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
9288 | } |
9289 | ||
d6dc1a38 JO |
9290 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
9291 | s32 threshold, u32 hysteresis) | |
9292 | { | |
4c476991 | 9293 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 9294 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 9295 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
9296 | |
9297 | if (threshold > 0) | |
9298 | return -EINVAL; | |
9299 | ||
1da5fcc8 JB |
9300 | /* disabling - hysteresis should also be zero then */ |
9301 | if (threshold == 0) | |
9302 | hysteresis = 0; | |
d6dc1a38 | 9303 | |
4c476991 JB |
9304 | if (!rdev->ops->set_cqm_rssi_config) |
9305 | return -EOPNOTSUPP; | |
d6dc1a38 | 9306 | |
074ac8df | 9307 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
9308 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
9309 | return -EOPNOTSUPP; | |
d6dc1a38 | 9310 | |
e35e4d28 | 9311 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
9312 | } |
9313 | ||
9314 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
9315 | { | |
9316 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
9317 | struct nlattr *cqm; | |
9318 | int err; | |
9319 | ||
9320 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
9321 | if (!cqm) |
9322 | return -EINVAL; | |
d6dc1a38 JO |
9323 | |
9324 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
9325 | nl80211_attr_cqm_policy); | |
9326 | if (err) | |
1da5fcc8 | 9327 | return err; |
d6dc1a38 JO |
9328 | |
9329 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
9330 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
9331 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
9332 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 9333 | |
1da5fcc8 JB |
9334 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
9335 | } | |
9336 | ||
9337 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
9338 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
9339 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
9340 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
9341 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
9342 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
9343 | ||
9344 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
9345 | } | |
9346 | ||
9347 | return -EINVAL; | |
d6dc1a38 JO |
9348 | } |
9349 | ||
6e0bd6c3 RL |
9350 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
9351 | { | |
9352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9353 | struct net_device *dev = info->user_ptr[1]; | |
9354 | struct ocb_setup setup = {}; | |
9355 | int err; | |
9356 | ||
9357 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
9358 | if (err) | |
9359 | return err; | |
9360 | ||
9361 | return cfg80211_join_ocb(rdev, dev, &setup); | |
9362 | } | |
9363 | ||
9364 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
9365 | { | |
9366 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9367 | struct net_device *dev = info->user_ptr[1]; | |
9368 | ||
9369 | return cfg80211_leave_ocb(rdev, dev); | |
9370 | } | |
9371 | ||
29cbe68c JB |
9372 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
9373 | { | |
9374 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9375 | struct net_device *dev = info->user_ptr[1]; | |
9376 | struct mesh_config cfg; | |
c80d545d | 9377 | struct mesh_setup setup; |
29cbe68c JB |
9378 | int err; |
9379 | ||
9380 | /* start with default */ | |
9381 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 9382 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 9383 | |
24bdd9f4 | 9384 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 9385 | /* and parse parameters if given */ |
24bdd9f4 | 9386 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
9387 | if (err) |
9388 | return err; | |
9389 | } | |
9390 | ||
9391 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
9392 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
9393 | return -EINVAL; | |
9394 | ||
c80d545d JC |
9395 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
9396 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
9397 | ||
4bb62344 CYY |
9398 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
9399 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
9400 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
9401 | return -EINVAL; | |
9402 | ||
9bdbf04d MP |
9403 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
9404 | setup.beacon_interval = | |
9405 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
12d20fc9 PK |
9406 | |
9407 | err = cfg80211_validate_beacon_int(rdev, setup.beacon_interval); | |
9408 | if (err) | |
9409 | return err; | |
9bdbf04d MP |
9410 | } |
9411 | ||
9412 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
9413 | setup.dtim_period = | |
9414 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
9415 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
9416 | return -EINVAL; | |
9417 | } | |
9418 | ||
c80d545d JC |
9419 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
9420 | /* parse additional setup parameters if given */ | |
9421 | err = nl80211_parse_mesh_setup(info, &setup); | |
9422 | if (err) | |
9423 | return err; | |
9424 | } | |
9425 | ||
d37bb18a TP |
9426 | if (setup.user_mpm) |
9427 | cfg.auto_open_plinks = false; | |
9428 | ||
cc1d2806 | 9429 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
9430 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
9431 | if (err) | |
9432 | return err; | |
cc1d2806 JB |
9433 | } else { |
9434 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 9435 | setup.chandef.chan = NULL; |
cc1d2806 JB |
9436 | } |
9437 | ||
ffb3cf30 AN |
9438 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
9439 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9440 | int n_rates = | |
9441 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
9442 | struct ieee80211_supported_band *sband; | |
9443 | ||
9444 | if (!setup.chandef.chan) | |
9445 | return -EINVAL; | |
9446 | ||
9447 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
9448 | ||
9449 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
9450 | &setup.basic_rates); | |
9451 | if (err) | |
9452 | return err; | |
9453 | } | |
9454 | ||
8564e382 JB |
9455 | if (info->attrs[NL80211_ATTR_TX_RATES]) { |
9456 | err = nl80211_parse_tx_bitrate_mask(info, &setup.beacon_rate); | |
9457 | if (err) | |
9458 | return err; | |
9459 | ||
9460 | err = validate_beacon_tx_rate(rdev, setup.chandef.chan->band, | |
9461 | &setup.beacon_rate); | |
9462 | if (err) | |
9463 | return err; | |
9464 | } | |
9465 | ||
c80d545d | 9466 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
9467 | } |
9468 | ||
9469 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
9470 | { | |
9471 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9472 | struct net_device *dev = info->user_ptr[1]; | |
9473 | ||
9474 | return cfg80211_leave_mesh(rdev, dev); | |
9475 | } | |
9476 | ||
dfb89c56 | 9477 | #ifdef CONFIG_PM |
bb92d199 AK |
9478 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
9479 | struct cfg80211_registered_device *rdev) | |
9480 | { | |
6abb9cb9 | 9481 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
9482 | struct nlattr *nl_pats, *nl_pat; |
9483 | int i, pat_len; | |
9484 | ||
6abb9cb9 | 9485 | if (!wowlan->n_patterns) |
bb92d199 AK |
9486 | return 0; |
9487 | ||
9488 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
9489 | if (!nl_pats) | |
9490 | return -ENOBUFS; | |
9491 | ||
6abb9cb9 | 9492 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
9493 | nl_pat = nla_nest_start(msg, i + 1); |
9494 | if (!nl_pat) | |
9495 | return -ENOBUFS; | |
6abb9cb9 | 9496 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 9497 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 9498 | wowlan->patterns[i].mask) || |
50ac6607 AK |
9499 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
9500 | wowlan->patterns[i].pattern) || | |
9501 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 9502 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
9503 | return -ENOBUFS; |
9504 | nla_nest_end(msg, nl_pat); | |
9505 | } | |
9506 | nla_nest_end(msg, nl_pats); | |
9507 | ||
9508 | return 0; | |
9509 | } | |
9510 | ||
2a0e047e JB |
9511 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
9512 | struct cfg80211_wowlan_tcp *tcp) | |
9513 | { | |
9514 | struct nlattr *nl_tcp; | |
9515 | ||
9516 | if (!tcp) | |
9517 | return 0; | |
9518 | ||
9519 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
9520 | if (!nl_tcp) | |
9521 | return -ENOBUFS; | |
9522 | ||
930345ea JB |
9523 | if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || |
9524 | nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
2a0e047e JB |
9525 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || |
9526 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
9527 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
9528 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
9529 | tcp->payload_len, tcp->payload) || | |
9530 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
9531 | tcp->data_interval) || | |
9532 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
9533 | tcp->wake_len, tcp->wake_data) || | |
9534 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
9535 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
9536 | return -ENOBUFS; | |
9537 | ||
9538 | if (tcp->payload_seq.len && | |
9539 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
9540 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
9541 | return -ENOBUFS; | |
9542 | ||
9543 | if (tcp->payload_tok.len && | |
9544 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
9545 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
9546 | &tcp->payload_tok)) | |
9547 | return -ENOBUFS; | |
9548 | ||
e248ad30 JB |
9549 | nla_nest_end(msg, nl_tcp); |
9550 | ||
2a0e047e JB |
9551 | return 0; |
9552 | } | |
9553 | ||
75453ccb LC |
9554 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
9555 | struct cfg80211_sched_scan_request *req) | |
9556 | { | |
3b06d277 | 9557 | struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan; |
75453ccb LC |
9558 | int i; |
9559 | ||
9560 | if (!req) | |
9561 | return 0; | |
9562 | ||
9563 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
9564 | if (!nd) | |
9565 | return -ENOBUFS; | |
9566 | ||
3b06d277 AS |
9567 | if (req->n_scan_plans == 1 && |
9568 | nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, | |
9569 | req->scan_plans[0].interval * 1000)) | |
75453ccb LC |
9570 | return -ENOBUFS; |
9571 | ||
21fea567 LC |
9572 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay)) |
9573 | return -ENOBUFS; | |
9574 | ||
75453ccb LC |
9575 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); |
9576 | if (!freqs) | |
9577 | return -ENOBUFS; | |
9578 | ||
53b18980 JB |
9579 | for (i = 0; i < req->n_channels; i++) { |
9580 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
9581 | return -ENOBUFS; | |
9582 | } | |
75453ccb LC |
9583 | |
9584 | nla_nest_end(msg, freqs); | |
9585 | ||
9586 | if (req->n_match_sets) { | |
9587 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
76e1fb4b JB |
9588 | if (!matches) |
9589 | return -ENOBUFS; | |
9590 | ||
75453ccb LC |
9591 | for (i = 0; i < req->n_match_sets; i++) { |
9592 | match = nla_nest_start(msg, i); | |
76e1fb4b JB |
9593 | if (!match) |
9594 | return -ENOBUFS; | |
9595 | ||
53b18980 JB |
9596 | if (nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, |
9597 | req->match_sets[i].ssid.ssid_len, | |
9598 | req->match_sets[i].ssid.ssid)) | |
9599 | return -ENOBUFS; | |
75453ccb LC |
9600 | nla_nest_end(msg, match); |
9601 | } | |
9602 | nla_nest_end(msg, matches); | |
9603 | } | |
9604 | ||
3b06d277 AS |
9605 | scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS); |
9606 | if (!scan_plans) | |
9607 | return -ENOBUFS; | |
9608 | ||
9609 | for (i = 0; i < req->n_scan_plans; i++) { | |
9610 | scan_plan = nla_nest_start(msg, i + 1); | |
76e1fb4b JB |
9611 | if (!scan_plan) |
9612 | return -ENOBUFS; | |
9613 | ||
3b06d277 AS |
9614 | if (!scan_plan || |
9615 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL, | |
9616 | req->scan_plans[i].interval) || | |
9617 | (req->scan_plans[i].iterations && | |
9618 | nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS, | |
9619 | req->scan_plans[i].iterations))) | |
9620 | return -ENOBUFS; | |
9621 | nla_nest_end(msg, scan_plan); | |
9622 | } | |
9623 | nla_nest_end(msg, scan_plans); | |
9624 | ||
75453ccb LC |
9625 | nla_nest_end(msg, nd); |
9626 | ||
9627 | return 0; | |
9628 | } | |
9629 | ||
ff1b6e69 JB |
9630 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
9631 | { | |
9632 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9633 | struct sk_buff *msg; | |
9634 | void *hdr; | |
2a0e047e | 9635 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 9636 | |
964dc9e2 | 9637 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
9638 | return -EOPNOTSUPP; |
9639 | ||
6abb9cb9 | 9640 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 9641 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
9642 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
9643 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
9644 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
9645 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
9646 | } |
9647 | ||
9648 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
9649 | if (!msg) |
9650 | return -ENOMEM; | |
9651 | ||
15e47304 | 9652 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
9653 | NL80211_CMD_GET_WOWLAN); |
9654 | if (!hdr) | |
9655 | goto nla_put_failure; | |
9656 | ||
6abb9cb9 | 9657 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
9658 | struct nlattr *nl_wowlan; |
9659 | ||
9660 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
9661 | if (!nl_wowlan) | |
9662 | goto nla_put_failure; | |
9663 | ||
6abb9cb9 | 9664 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 9665 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 9666 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 9667 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 9668 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 9669 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 9670 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 9671 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 9672 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 9673 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 9674 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 9675 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 9676 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
9677 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
9678 | goto nla_put_failure; | |
2a0e047e | 9679 | |
bb92d199 AK |
9680 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
9681 | goto nla_put_failure; | |
2a0e047e | 9682 | |
6abb9cb9 JB |
9683 | if (nl80211_send_wowlan_tcp(msg, |
9684 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 9685 | goto nla_put_failure; |
75453ccb LC |
9686 | |
9687 | if (nl80211_send_wowlan_nd( | |
9688 | msg, | |
9689 | rdev->wiphy.wowlan_config->nd_config)) | |
9690 | goto nla_put_failure; | |
2a0e047e | 9691 | |
ff1b6e69 JB |
9692 | nla_nest_end(msg, nl_wowlan); |
9693 | } | |
9694 | ||
9695 | genlmsg_end(msg, hdr); | |
9696 | return genlmsg_reply(msg, info); | |
9697 | ||
9698 | nla_put_failure: | |
9699 | nlmsg_free(msg); | |
9700 | return -ENOBUFS; | |
9701 | } | |
9702 | ||
2a0e047e JB |
9703 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
9704 | struct nlattr *attr, | |
9705 | struct cfg80211_wowlan *trig) | |
9706 | { | |
9707 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
9708 | struct cfg80211_wowlan_tcp *cfg; | |
9709 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
9710 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
9711 | u32 size; | |
9712 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
9713 | int err, port; | |
9714 | ||
964dc9e2 | 9715 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
9716 | return -EINVAL; |
9717 | ||
9718 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
9719 | nla_data(attr), nla_len(attr), | |
9720 | nl80211_wowlan_tcp_policy); | |
9721 | if (err) | |
9722 | return err; | |
9723 | ||
9724 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
9725 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
9726 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
9727 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
9728 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
9729 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
9730 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
9731 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
9732 | return -EINVAL; | |
9733 | ||
9734 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 9735 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
9736 | return -EINVAL; |
9737 | ||
9738 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 9739 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 9740 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
9741 | return -EINVAL; |
9742 | ||
9743 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 9744 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
9745 | return -EINVAL; |
9746 | ||
9747 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
9748 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
9749 | return -EINVAL; | |
9750 | ||
9751 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
9752 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
9753 | ||
9754 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
9755 | tokens_size = tokln - sizeof(*tok); | |
9756 | ||
9757 | if (!tok->len || tokens_size % tok->len) | |
9758 | return -EINVAL; | |
964dc9e2 | 9759 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 9760 | return -EINVAL; |
964dc9e2 | 9761 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 9762 | return -EINVAL; |
964dc9e2 | 9763 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 9764 | return -EINVAL; |
964dc9e2 | 9765 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
9766 | return -EINVAL; |
9767 | if (tok->offset + tok->len > data_size) | |
9768 | return -EINVAL; | |
9769 | } | |
9770 | ||
9771 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
9772 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 9773 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
9774 | return -EINVAL; |
9775 | if (seq->len == 0 || seq->len > 4) | |
9776 | return -EINVAL; | |
9777 | if (seq->len + seq->offset > data_size) | |
9778 | return -EINVAL; | |
9779 | } | |
9780 | ||
9781 | size = sizeof(*cfg); | |
9782 | size += data_size; | |
9783 | size += wake_size + wake_mask_size; | |
9784 | size += tokens_size; | |
9785 | ||
9786 | cfg = kzalloc(size, GFP_KERNEL); | |
9787 | if (!cfg) | |
9788 | return -ENOMEM; | |
67b61f6c JB |
9789 | cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); |
9790 | cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
2a0e047e JB |
9791 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), |
9792 | ETH_ALEN); | |
9793 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
9794 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
9795 | else | |
9796 | port = 0; | |
9797 | #ifdef CONFIG_INET | |
9798 | /* allocate a socket and port for it and use it */ | |
9799 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
9800 | IPPROTO_TCP, &cfg->sock, 1); | |
9801 | if (err) { | |
9802 | kfree(cfg); | |
9803 | return err; | |
9804 | } | |
9805 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
9806 | sock_release(cfg->sock); | |
9807 | kfree(cfg); | |
9808 | return -EADDRINUSE; | |
9809 | } | |
9810 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
9811 | #else | |
9812 | if (!port) { | |
9813 | kfree(cfg); | |
9814 | return -EINVAL; | |
9815 | } | |
9816 | cfg->src_port = port; | |
9817 | #endif | |
9818 | ||
9819 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9820 | cfg->payload_len = data_size; | |
9821 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9822 | memcpy((void *)cfg->payload, | |
9823 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9824 | data_size); | |
9825 | if (seq) | |
9826 | cfg->payload_seq = *seq; | |
9827 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9828 | cfg->wake_len = wake_size; | |
9829 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9830 | memcpy((void *)cfg->wake_data, | |
9831 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9832 | wake_size); | |
9833 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9834 | data_size + wake_size; | |
9835 | memcpy((void *)cfg->wake_mask, | |
9836 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9837 | wake_mask_size); | |
9838 | if (tok) { | |
9839 | cfg->tokens_size = tokens_size; | |
9840 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9841 | } | |
9842 | ||
9843 | trig->tcp = cfg; | |
9844 | ||
9845 | return 0; | |
9846 | } | |
9847 | ||
8cd4d456 LC |
9848 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9849 | const struct wiphy_wowlan_support *wowlan, | |
9850 | struct nlattr *attr, | |
9851 | struct cfg80211_wowlan *trig) | |
9852 | { | |
9853 | struct nlattr **tb; | |
9854 | int err; | |
9855 | ||
9856 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9857 | if (!tb) | |
9858 | return -ENOMEM; | |
9859 | ||
9860 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9861 | err = -EOPNOTSUPP; | |
9862 | goto out; | |
9863 | } | |
9864 | ||
9865 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9866 | nla_data(attr), nla_len(attr), | |
9867 | nl80211_policy); | |
9868 | if (err) | |
9869 | goto out; | |
9870 | ||
ad2b26ab | 9871 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9872 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9873 | if (err) | |
9874 | trig->nd_config = NULL; | |
9875 | ||
9876 | out: | |
9877 | kfree(tb); | |
9878 | return err; | |
9879 | } | |
9880 | ||
ff1b6e69 JB |
9881 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9882 | { | |
9883 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9884 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9885 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9886 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9887 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9888 | int err, i; |
6abb9cb9 | 9889 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 9890 | bool regular = false; |
ff1b6e69 | 9891 | |
964dc9e2 | 9892 | if (!wowlan) |
ff1b6e69 JB |
9893 | return -EOPNOTSUPP; |
9894 | ||
ae33bd81 JB |
9895 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9896 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9897 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9898 | goto set_wakeup; |
9899 | } | |
ff1b6e69 JB |
9900 | |
9901 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9902 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9903 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9904 | nl80211_wowlan_policy); | |
9905 | if (err) | |
9906 | return err; | |
9907 | ||
9908 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9909 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9910 | return -EINVAL; | |
9911 | new_triggers.any = true; | |
9912 | } | |
9913 | ||
9914 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9915 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9916 | return -EINVAL; | |
9917 | new_triggers.disconnect = true; | |
98fc4386 | 9918 | regular = true; |
ff1b6e69 JB |
9919 | } |
9920 | ||
9921 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9922 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9923 | return -EINVAL; | |
9924 | new_triggers.magic_pkt = true; | |
98fc4386 | 9925 | regular = true; |
ff1b6e69 JB |
9926 | } |
9927 | ||
77dbbb13 JB |
9928 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9929 | return -EINVAL; | |
9930 | ||
9931 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9932 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9933 | return -EINVAL; | |
9934 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 9935 | regular = true; |
77dbbb13 JB |
9936 | } |
9937 | ||
9938 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9939 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9940 | return -EINVAL; | |
9941 | new_triggers.eap_identity_req = true; | |
98fc4386 | 9942 | regular = true; |
77dbbb13 JB |
9943 | } |
9944 | ||
9945 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9946 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9947 | return -EINVAL; | |
9948 | new_triggers.four_way_handshake = true; | |
98fc4386 | 9949 | regular = true; |
77dbbb13 JB |
9950 | } |
9951 | ||
9952 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9953 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9954 | return -EINVAL; | |
9955 | new_triggers.rfkill_release = true; | |
98fc4386 | 9956 | regular = true; |
77dbbb13 JB |
9957 | } |
9958 | ||
ff1b6e69 JB |
9959 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9960 | struct nlattr *pat; | |
9961 | int n_patterns = 0; | |
bb92d199 | 9962 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9963 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 9964 | |
98fc4386 JB |
9965 | regular = true; |
9966 | ||
ff1b6e69 JB |
9967 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
9968 | rem) | |
9969 | n_patterns++; | |
9970 | if (n_patterns > wowlan->n_patterns) | |
9971 | return -EINVAL; | |
9972 | ||
9973 | new_triggers.patterns = kcalloc(n_patterns, | |
9974 | sizeof(new_triggers.patterns[0]), | |
9975 | GFP_KERNEL); | |
9976 | if (!new_triggers.patterns) | |
9977 | return -ENOMEM; | |
9978 | ||
9979 | new_triggers.n_patterns = n_patterns; | |
9980 | i = 0; | |
9981 | ||
9982 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9983 | rem) { | |
922bd80f JB |
9984 | u8 *mask_pat; |
9985 | ||
50ac6607 AK |
9986 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9987 | nla_len(pat), NULL); | |
ff1b6e69 | 9988 | err = -EINVAL; |
50ac6607 AK |
9989 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9990 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9991 | goto error; |
50ac6607 | 9992 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9993 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9994 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9995 | goto error; |
9996 | if (pat_len > wowlan->pattern_max_len || | |
9997 | pat_len < wowlan->pattern_min_len) | |
9998 | goto error; | |
9999 | ||
50ac6607 | 10000 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
10001 | pkt_offset = 0; |
10002 | else | |
10003 | pkt_offset = nla_get_u32( | |
50ac6607 | 10004 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
10005 | if (pkt_offset > wowlan->max_pkt_offset) |
10006 | goto error; | |
10007 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
10008 | ||
922bd80f JB |
10009 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
10010 | if (!mask_pat) { | |
ff1b6e69 JB |
10011 | err = -ENOMEM; |
10012 | goto error; | |
10013 | } | |
922bd80f JB |
10014 | new_triggers.patterns[i].mask = mask_pat; |
10015 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 10016 | mask_len); |
922bd80f JB |
10017 | mask_pat += mask_len; |
10018 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 10019 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 10020 | memcpy(mask_pat, |
50ac6607 | 10021 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
10022 | pat_len); |
10023 | i++; | |
10024 | } | |
10025 | } | |
10026 | ||
2a0e047e | 10027 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 10028 | regular = true; |
2a0e047e JB |
10029 | err = nl80211_parse_wowlan_tcp( |
10030 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
10031 | &new_triggers); | |
10032 | if (err) | |
10033 | goto error; | |
10034 | } | |
10035 | ||
8cd4d456 | 10036 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 10037 | regular = true; |
8cd4d456 LC |
10038 | err = nl80211_parse_wowlan_nd( |
10039 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
10040 | &new_triggers); | |
10041 | if (err) | |
10042 | goto error; | |
10043 | } | |
10044 | ||
98fc4386 JB |
10045 | /* The 'any' trigger means the device continues operating more or less |
10046 | * as in its normal operation mode and wakes up the host on most of the | |
10047 | * normal interrupts (like packet RX, ...) | |
10048 | * It therefore makes little sense to combine with the more constrained | |
10049 | * wakeup trigger modes. | |
10050 | */ | |
10051 | if (new_triggers.any && regular) { | |
10052 | err = -EINVAL; | |
10053 | goto error; | |
10054 | } | |
10055 | ||
ae33bd81 JB |
10056 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
10057 | if (!ntrig) { | |
10058 | err = -ENOMEM; | |
10059 | goto error; | |
ff1b6e69 | 10060 | } |
ae33bd81 | 10061 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 10062 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 10063 | |
ae33bd81 | 10064 | set_wakeup: |
6abb9cb9 JB |
10065 | if (rdev->ops->set_wakeup && |
10066 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
10067 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 10068 | |
ff1b6e69 JB |
10069 | return 0; |
10070 | error: | |
10071 | for (i = 0; i < new_triggers.n_patterns; i++) | |
10072 | kfree(new_triggers.patterns[i].mask); | |
10073 | kfree(new_triggers.patterns); | |
2a0e047e JB |
10074 | if (new_triggers.tcp && new_triggers.tcp->sock) |
10075 | sock_release(new_triggers.tcp->sock); | |
10076 | kfree(new_triggers.tcp); | |
e5dbe070 | 10077 | kfree(new_triggers.nd_config); |
ff1b6e69 JB |
10078 | return err; |
10079 | } | |
dfb89c56 | 10080 | #endif |
ff1b6e69 | 10081 | |
be29b99a AK |
10082 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
10083 | struct cfg80211_registered_device *rdev) | |
10084 | { | |
10085 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
10086 | int i, j, pat_len; | |
10087 | struct cfg80211_coalesce_rules *rule; | |
10088 | ||
10089 | if (!rdev->coalesce->n_rules) | |
10090 | return 0; | |
10091 | ||
10092 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
10093 | if (!nl_rules) | |
10094 | return -ENOBUFS; | |
10095 | ||
10096 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
10097 | nl_rule = nla_nest_start(msg, i + 1); | |
10098 | if (!nl_rule) | |
10099 | return -ENOBUFS; | |
10100 | ||
10101 | rule = &rdev->coalesce->rules[i]; | |
10102 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
10103 | rule->delay)) | |
10104 | return -ENOBUFS; | |
10105 | ||
10106 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
10107 | rule->condition)) | |
10108 | return -ENOBUFS; | |
10109 | ||
10110 | nl_pats = nla_nest_start(msg, | |
10111 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
10112 | if (!nl_pats) | |
10113 | return -ENOBUFS; | |
10114 | ||
10115 | for (j = 0; j < rule->n_patterns; j++) { | |
10116 | nl_pat = nla_nest_start(msg, j + 1); | |
10117 | if (!nl_pat) | |
10118 | return -ENOBUFS; | |
10119 | pat_len = rule->patterns[j].pattern_len; | |
10120 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
10121 | DIV_ROUND_UP(pat_len, 8), | |
10122 | rule->patterns[j].mask) || | |
10123 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
10124 | rule->patterns[j].pattern) || | |
10125 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
10126 | rule->patterns[j].pkt_offset)) | |
10127 | return -ENOBUFS; | |
10128 | nla_nest_end(msg, nl_pat); | |
10129 | } | |
10130 | nla_nest_end(msg, nl_pats); | |
10131 | nla_nest_end(msg, nl_rule); | |
10132 | } | |
10133 | nla_nest_end(msg, nl_rules); | |
10134 | ||
10135 | return 0; | |
10136 | } | |
10137 | ||
10138 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
10139 | { | |
10140 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10141 | struct sk_buff *msg; | |
10142 | void *hdr; | |
10143 | ||
10144 | if (!rdev->wiphy.coalesce) | |
10145 | return -EOPNOTSUPP; | |
10146 | ||
10147 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10148 | if (!msg) | |
10149 | return -ENOMEM; | |
10150 | ||
10151 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
10152 | NL80211_CMD_GET_COALESCE); | |
10153 | if (!hdr) | |
10154 | goto nla_put_failure; | |
10155 | ||
10156 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
10157 | goto nla_put_failure; | |
10158 | ||
10159 | genlmsg_end(msg, hdr); | |
10160 | return genlmsg_reply(msg, info); | |
10161 | ||
10162 | nla_put_failure: | |
10163 | nlmsg_free(msg); | |
10164 | return -ENOBUFS; | |
10165 | } | |
10166 | ||
10167 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
10168 | { | |
10169 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
10170 | int i, j; | |
10171 | struct cfg80211_coalesce_rules *rule; | |
10172 | ||
10173 | if (!coalesce) | |
10174 | return; | |
10175 | ||
10176 | for (i = 0; i < coalesce->n_rules; i++) { | |
10177 | rule = &coalesce->rules[i]; | |
10178 | for (j = 0; j < rule->n_patterns; j++) | |
10179 | kfree(rule->patterns[j].mask); | |
10180 | kfree(rule->patterns); | |
10181 | } | |
10182 | kfree(coalesce->rules); | |
10183 | kfree(coalesce); | |
10184 | rdev->coalesce = NULL; | |
10185 | } | |
10186 | ||
10187 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
10188 | struct nlattr *rule, | |
10189 | struct cfg80211_coalesce_rules *new_rule) | |
10190 | { | |
10191 | int err, i; | |
10192 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
10193 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
10194 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
10195 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
10196 | ||
10197 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
10198 | nla_len(rule), nl80211_coalesce_policy); | |
10199 | if (err) | |
10200 | return err; | |
10201 | ||
10202 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
10203 | new_rule->delay = | |
10204 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
10205 | if (new_rule->delay > coalesce->max_delay) | |
10206 | return -EINVAL; | |
10207 | ||
10208 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
10209 | new_rule->condition = | |
10210 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
10211 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
10212 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
10213 | return -EINVAL; | |
10214 | ||
10215 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
10216 | return -EINVAL; | |
10217 | ||
10218 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
10219 | rem) | |
10220 | n_patterns++; | |
10221 | if (n_patterns > coalesce->n_patterns) | |
10222 | return -EINVAL; | |
10223 | ||
10224 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
10225 | GFP_KERNEL); | |
10226 | if (!new_rule->patterns) | |
10227 | return -ENOMEM; | |
10228 | ||
10229 | new_rule->n_patterns = n_patterns; | |
10230 | i = 0; | |
10231 | ||
10232 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
10233 | rem) { | |
922bd80f JB |
10234 | u8 *mask_pat; |
10235 | ||
be29b99a AK |
10236 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
10237 | nla_len(pat), NULL); | |
10238 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
10239 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
10240 | return -EINVAL; | |
10241 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
10242 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
10243 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
10244 | return -EINVAL; | |
10245 | if (pat_len > coalesce->pattern_max_len || | |
10246 | pat_len < coalesce->pattern_min_len) | |
10247 | return -EINVAL; | |
10248 | ||
10249 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
10250 | pkt_offset = 0; | |
10251 | else | |
10252 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
10253 | if (pkt_offset > coalesce->max_pkt_offset) | |
10254 | return -EINVAL; | |
10255 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
10256 | ||
922bd80f JB |
10257 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
10258 | if (!mask_pat) | |
be29b99a | 10259 | return -ENOMEM; |
922bd80f JB |
10260 | |
10261 | new_rule->patterns[i].mask = mask_pat; | |
10262 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
10263 | mask_len); | |
10264 | ||
10265 | mask_pat += mask_len; | |
10266 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 10267 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
10268 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
10269 | pat_len); | |
be29b99a AK |
10270 | i++; |
10271 | } | |
10272 | ||
10273 | return 0; | |
10274 | } | |
10275 | ||
10276 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
10277 | { | |
10278 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10279 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
10280 | struct cfg80211_coalesce new_coalesce = {}; | |
10281 | struct cfg80211_coalesce *n_coalesce; | |
10282 | int err, rem_rule, n_rules = 0, i, j; | |
10283 | struct nlattr *rule; | |
10284 | struct cfg80211_coalesce_rules *tmp_rule; | |
10285 | ||
10286 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
10287 | return -EOPNOTSUPP; | |
10288 | ||
10289 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
10290 | cfg80211_rdev_free_coalesce(rdev); | |
a1056b1b | 10291 | rdev_set_coalesce(rdev, NULL); |
be29b99a AK |
10292 | return 0; |
10293 | } | |
10294 | ||
10295 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
10296 | rem_rule) | |
10297 | n_rules++; | |
10298 | if (n_rules > coalesce->n_rules) | |
10299 | return -EINVAL; | |
10300 | ||
10301 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
10302 | GFP_KERNEL); | |
10303 | if (!new_coalesce.rules) | |
10304 | return -ENOMEM; | |
10305 | ||
10306 | new_coalesce.n_rules = n_rules; | |
10307 | i = 0; | |
10308 | ||
10309 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
10310 | rem_rule) { | |
10311 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
10312 | &new_coalesce.rules[i]); | |
10313 | if (err) | |
10314 | goto error; | |
10315 | ||
10316 | i++; | |
10317 | } | |
10318 | ||
a1056b1b | 10319 | err = rdev_set_coalesce(rdev, &new_coalesce); |
be29b99a AK |
10320 | if (err) |
10321 | goto error; | |
10322 | ||
10323 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
10324 | if (!n_coalesce) { | |
10325 | err = -ENOMEM; | |
10326 | goto error; | |
10327 | } | |
10328 | cfg80211_rdev_free_coalesce(rdev); | |
10329 | rdev->coalesce = n_coalesce; | |
10330 | ||
10331 | return 0; | |
10332 | error: | |
10333 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
10334 | tmp_rule = &new_coalesce.rules[i]; | |
10335 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
10336 | kfree(tmp_rule->patterns[j].mask); | |
10337 | kfree(tmp_rule->patterns); | |
10338 | } | |
10339 | kfree(new_coalesce.rules); | |
10340 | ||
10341 | return err; | |
10342 | } | |
10343 | ||
e5497d76 JB |
10344 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
10345 | { | |
10346 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10347 | struct net_device *dev = info->user_ptr[1]; | |
10348 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10349 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
10350 | struct cfg80211_gtk_rekey_data rekey_data; | |
10351 | int err; | |
10352 | ||
10353 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
10354 | return -EINVAL; | |
10355 | ||
10356 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
10357 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
10358 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
10359 | nl80211_rekey_policy); | |
10360 | if (err) | |
10361 | return err; | |
10362 | ||
10363 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
10364 | return -ERANGE; | |
10365 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
10366 | return -ERANGE; | |
10367 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
10368 | return -ERANGE; | |
10369 | ||
78f686ca JB |
10370 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
10371 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
10372 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
10373 | |
10374 | wdev_lock(wdev); | |
10375 | if (!wdev->current_bss) { | |
10376 | err = -ENOTCONN; | |
10377 | goto out; | |
10378 | } | |
10379 | ||
10380 | if (!rdev->ops->set_rekey_data) { | |
10381 | err = -EOPNOTSUPP; | |
10382 | goto out; | |
10383 | } | |
10384 | ||
e35e4d28 | 10385 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
10386 | out: |
10387 | wdev_unlock(wdev); | |
10388 | return err; | |
10389 | } | |
10390 | ||
28946da7 JB |
10391 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
10392 | struct genl_info *info) | |
10393 | { | |
10394 | struct net_device *dev = info->user_ptr[1]; | |
10395 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10396 | ||
10397 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
10398 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
10399 | return -EINVAL; | |
10400 | ||
15e47304 | 10401 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
10402 | return -EBUSY; |
10403 | ||
15e47304 | 10404 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
10405 | return 0; |
10406 | } | |
10407 | ||
7f6cf311 JB |
10408 | static int nl80211_probe_client(struct sk_buff *skb, |
10409 | struct genl_info *info) | |
10410 | { | |
10411 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10412 | struct net_device *dev = info->user_ptr[1]; | |
10413 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10414 | struct sk_buff *msg; | |
10415 | void *hdr; | |
10416 | const u8 *addr; | |
10417 | u64 cookie; | |
10418 | int err; | |
10419 | ||
10420 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
10421 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
10422 | return -EOPNOTSUPP; | |
10423 | ||
10424 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10425 | return -EINVAL; | |
10426 | ||
10427 | if (!rdev->ops->probe_client) | |
10428 | return -EOPNOTSUPP; | |
10429 | ||
10430 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10431 | if (!msg) | |
10432 | return -ENOMEM; | |
10433 | ||
15e47304 | 10434 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 10435 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
10436 | if (!hdr) { |
10437 | err = -ENOBUFS; | |
7f6cf311 JB |
10438 | goto free_msg; |
10439 | } | |
10440 | ||
10441 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10442 | ||
e35e4d28 | 10443 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
10444 | if (err) |
10445 | goto free_msg; | |
10446 | ||
2dad624e ND |
10447 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
10448 | NL80211_ATTR_PAD)) | |
9360ffd1 | 10449 | goto nla_put_failure; |
7f6cf311 JB |
10450 | |
10451 | genlmsg_end(msg, hdr); | |
10452 | ||
10453 | return genlmsg_reply(msg, info); | |
10454 | ||
10455 | nla_put_failure: | |
10456 | err = -ENOBUFS; | |
10457 | free_msg: | |
10458 | nlmsg_free(msg); | |
10459 | return err; | |
10460 | } | |
10461 | ||
5e760230 JB |
10462 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
10463 | { | |
10464 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
10465 | struct cfg80211_beacon_registration *reg, *nreg; |
10466 | int rv; | |
5e760230 JB |
10467 | |
10468 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
10469 | return -EOPNOTSUPP; | |
10470 | ||
37c73b5f BG |
10471 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
10472 | if (!nreg) | |
10473 | return -ENOMEM; | |
10474 | ||
10475 | /* First, check if already registered. */ | |
10476 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
10477 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
10478 | if (reg->nlportid == info->snd_portid) { | |
10479 | rv = -EALREADY; | |
10480 | goto out_err; | |
10481 | } | |
10482 | } | |
10483 | /* Add it to the list */ | |
10484 | nreg->nlportid = info->snd_portid; | |
10485 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 10486 | |
37c73b5f | 10487 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
10488 | |
10489 | return 0; | |
37c73b5f BG |
10490 | out_err: |
10491 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
10492 | kfree(nreg); | |
10493 | return rv; | |
5e760230 JB |
10494 | } |
10495 | ||
98104fde JB |
10496 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
10497 | { | |
10498 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10499 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10500 | int err; | |
10501 | ||
10502 | if (!rdev->ops->start_p2p_device) | |
10503 | return -EOPNOTSUPP; | |
10504 | ||
10505 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
10506 | return -EOPNOTSUPP; | |
10507 | ||
10508 | if (wdev->p2p_started) | |
10509 | return 0; | |
10510 | ||
b6a55015 LC |
10511 | if (rfkill_blocked(rdev->rfkill)) |
10512 | return -ERFKILL; | |
98104fde | 10513 | |
eeb126e9 | 10514 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
10515 | if (err) |
10516 | return err; | |
10517 | ||
10518 | wdev->p2p_started = true; | |
98104fde | 10519 | rdev->opencount++; |
98104fde JB |
10520 | |
10521 | return 0; | |
10522 | } | |
10523 | ||
10524 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
10525 | { | |
10526 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10527 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10528 | ||
10529 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
10530 | return -EOPNOTSUPP; | |
10531 | ||
10532 | if (!rdev->ops->stop_p2p_device) | |
10533 | return -EOPNOTSUPP; | |
10534 | ||
f9f47529 | 10535 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
10536 | |
10537 | return 0; | |
10538 | } | |
10539 | ||
cb3b7d87 AB |
10540 | static int nl80211_start_nan(struct sk_buff *skb, struct genl_info *info) |
10541 | { | |
10542 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10543 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10544 | struct cfg80211_nan_conf conf = {}; | |
10545 | int err; | |
10546 | ||
10547 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
10548 | return -EOPNOTSUPP; | |
10549 | ||
10550 | if (wdev->nan_started) | |
10551 | return -EEXIST; | |
10552 | ||
10553 | if (rfkill_blocked(rdev->rfkill)) | |
10554 | return -ERFKILL; | |
10555 | ||
10556 | if (!info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) | |
10557 | return -EINVAL; | |
10558 | ||
10559 | if (!info->attrs[NL80211_ATTR_NAN_DUAL]) | |
10560 | return -EINVAL; | |
10561 | ||
10562 | conf.master_pref = | |
10563 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
10564 | if (!conf.master_pref) | |
10565 | return -EINVAL; | |
10566 | ||
10567 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); | |
10568 | ||
10569 | err = rdev_start_nan(rdev, wdev, &conf); | |
10570 | if (err) | |
10571 | return err; | |
10572 | ||
10573 | wdev->nan_started = true; | |
10574 | rdev->opencount++; | |
10575 | ||
10576 | return 0; | |
10577 | } | |
10578 | ||
10579 | static int nl80211_stop_nan(struct sk_buff *skb, struct genl_info *info) | |
10580 | { | |
10581 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10582 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10583 | ||
10584 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
10585 | return -EOPNOTSUPP; | |
10586 | ||
10587 | cfg80211_stop_nan(rdev, wdev); | |
10588 | ||
10589 | return 0; | |
10590 | } | |
10591 | ||
a442b761 AB |
10592 | static int validate_nan_filter(struct nlattr *filter_attr) |
10593 | { | |
10594 | struct nlattr *attr; | |
10595 | int len = 0, n_entries = 0, rem; | |
10596 | ||
10597 | nla_for_each_nested(attr, filter_attr, rem) { | |
10598 | len += nla_len(attr); | |
10599 | n_entries++; | |
10600 | } | |
10601 | ||
10602 | if (len >= U8_MAX) | |
10603 | return -EINVAL; | |
10604 | ||
10605 | return n_entries; | |
10606 | } | |
10607 | ||
10608 | static int handle_nan_filter(struct nlattr *attr_filter, | |
10609 | struct cfg80211_nan_func *func, | |
10610 | bool tx) | |
10611 | { | |
10612 | struct nlattr *attr; | |
10613 | int n_entries, rem, i; | |
10614 | struct cfg80211_nan_func_filter *filter; | |
10615 | ||
10616 | n_entries = validate_nan_filter(attr_filter); | |
10617 | if (n_entries < 0) | |
10618 | return n_entries; | |
10619 | ||
10620 | BUILD_BUG_ON(sizeof(*func->rx_filters) != sizeof(*func->tx_filters)); | |
10621 | ||
10622 | filter = kcalloc(n_entries, sizeof(*func->rx_filters), GFP_KERNEL); | |
10623 | if (!filter) | |
10624 | return -ENOMEM; | |
10625 | ||
10626 | i = 0; | |
10627 | nla_for_each_nested(attr, attr_filter, rem) { | |
10628 | filter[i].filter = kmemdup(nla_data(attr), nla_len(attr), | |
10629 | GFP_KERNEL); | |
10630 | filter[i].len = nla_len(attr); | |
10631 | i++; | |
10632 | } | |
10633 | if (tx) { | |
10634 | func->num_tx_filters = n_entries; | |
10635 | func->tx_filters = filter; | |
10636 | } else { | |
10637 | func->num_rx_filters = n_entries; | |
10638 | func->rx_filters = filter; | |
10639 | } | |
10640 | ||
10641 | return 0; | |
10642 | } | |
10643 | ||
10644 | static int nl80211_nan_add_func(struct sk_buff *skb, | |
10645 | struct genl_info *info) | |
10646 | { | |
10647 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10648 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10649 | struct nlattr *tb[NUM_NL80211_NAN_FUNC_ATTR], *func_attr; | |
10650 | struct cfg80211_nan_func *func; | |
10651 | struct sk_buff *msg = NULL; | |
10652 | void *hdr = NULL; | |
10653 | int err = 0; | |
10654 | ||
10655 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
10656 | return -EOPNOTSUPP; | |
10657 | ||
10658 | if (!wdev->nan_started) | |
10659 | return -ENOTCONN; | |
10660 | ||
10661 | if (!info->attrs[NL80211_ATTR_NAN_FUNC]) | |
10662 | return -EINVAL; | |
10663 | ||
10664 | if (wdev->owner_nlportid && | |
10665 | wdev->owner_nlportid != info->snd_portid) | |
10666 | return -ENOTCONN; | |
10667 | ||
10668 | err = nla_parse(tb, NL80211_NAN_FUNC_ATTR_MAX, | |
10669 | nla_data(info->attrs[NL80211_ATTR_NAN_FUNC]), | |
10670 | nla_len(info->attrs[NL80211_ATTR_NAN_FUNC]), | |
10671 | nl80211_nan_func_policy); | |
10672 | if (err) | |
10673 | return err; | |
10674 | ||
10675 | func = kzalloc(sizeof(*func), GFP_KERNEL); | |
10676 | if (!func) | |
10677 | return -ENOMEM; | |
10678 | ||
10679 | func->cookie = wdev->wiphy->cookie_counter++; | |
10680 | ||
10681 | if (!tb[NL80211_NAN_FUNC_TYPE] || | |
10682 | nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]) > NL80211_NAN_FUNC_MAX_TYPE) { | |
10683 | err = -EINVAL; | |
10684 | goto out; | |
10685 | } | |
10686 | ||
10687 | ||
10688 | func->type = nla_get_u8(tb[NL80211_NAN_FUNC_TYPE]); | |
10689 | ||
10690 | if (!tb[NL80211_NAN_FUNC_SERVICE_ID]) { | |
10691 | err = -EINVAL; | |
10692 | goto out; | |
10693 | } | |
10694 | ||
10695 | memcpy(func->service_id, nla_data(tb[NL80211_NAN_FUNC_SERVICE_ID]), | |
10696 | sizeof(func->service_id)); | |
10697 | ||
10698 | func->close_range = | |
10699 | nla_get_flag(tb[NL80211_NAN_FUNC_CLOSE_RANGE]); | |
10700 | ||
10701 | if (tb[NL80211_NAN_FUNC_SERVICE_INFO]) { | |
10702 | func->serv_spec_info_len = | |
10703 | nla_len(tb[NL80211_NAN_FUNC_SERVICE_INFO]); | |
10704 | func->serv_spec_info = | |
10705 | kmemdup(nla_data(tb[NL80211_NAN_FUNC_SERVICE_INFO]), | |
10706 | func->serv_spec_info_len, | |
10707 | GFP_KERNEL); | |
10708 | if (!func->serv_spec_info) { | |
10709 | err = -ENOMEM; | |
10710 | goto out; | |
10711 | } | |
10712 | } | |
10713 | ||
10714 | if (tb[NL80211_NAN_FUNC_TTL]) | |
10715 | func->ttl = nla_get_u32(tb[NL80211_NAN_FUNC_TTL]); | |
10716 | ||
10717 | switch (func->type) { | |
10718 | case NL80211_NAN_FUNC_PUBLISH: | |
10719 | if (!tb[NL80211_NAN_FUNC_PUBLISH_TYPE]) { | |
10720 | err = -EINVAL; | |
10721 | goto out; | |
10722 | } | |
10723 | ||
10724 | func->publish_type = | |
10725 | nla_get_u8(tb[NL80211_NAN_FUNC_PUBLISH_TYPE]); | |
10726 | func->publish_bcast = | |
10727 | nla_get_flag(tb[NL80211_NAN_FUNC_PUBLISH_BCAST]); | |
10728 | ||
10729 | if ((!(func->publish_type & NL80211_NAN_SOLICITED_PUBLISH)) && | |
10730 | func->publish_bcast) { | |
10731 | err = -EINVAL; | |
10732 | goto out; | |
10733 | } | |
10734 | break; | |
10735 | case NL80211_NAN_FUNC_SUBSCRIBE: | |
10736 | func->subscribe_active = | |
10737 | nla_get_flag(tb[NL80211_NAN_FUNC_SUBSCRIBE_ACTIVE]); | |
10738 | break; | |
10739 | case NL80211_NAN_FUNC_FOLLOW_UP: | |
10740 | if (!tb[NL80211_NAN_FUNC_FOLLOW_UP_ID] || | |
10741 | !tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]) { | |
10742 | err = -EINVAL; | |
10743 | goto out; | |
10744 | } | |
10745 | ||
10746 | func->followup_id = | |
10747 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_ID]); | |
10748 | func->followup_reqid = | |
10749 | nla_get_u8(tb[NL80211_NAN_FUNC_FOLLOW_UP_REQ_ID]); | |
10750 | memcpy(func->followup_dest.addr, | |
10751 | nla_data(tb[NL80211_NAN_FUNC_FOLLOW_UP_DEST]), | |
10752 | sizeof(func->followup_dest.addr)); | |
10753 | if (func->ttl) { | |
10754 | err = -EINVAL; | |
10755 | goto out; | |
10756 | } | |
10757 | break; | |
10758 | default: | |
10759 | err = -EINVAL; | |
10760 | goto out; | |
10761 | } | |
10762 | ||
10763 | if (tb[NL80211_NAN_FUNC_SRF]) { | |
10764 | struct nlattr *srf_tb[NUM_NL80211_NAN_SRF_ATTR]; | |
10765 | ||
10766 | err = nla_parse(srf_tb, NL80211_NAN_SRF_ATTR_MAX, | |
10767 | nla_data(tb[NL80211_NAN_FUNC_SRF]), | |
10768 | nla_len(tb[NL80211_NAN_FUNC_SRF]), NULL); | |
10769 | if (err) | |
10770 | goto out; | |
10771 | ||
10772 | func->srf_include = | |
10773 | nla_get_flag(srf_tb[NL80211_NAN_SRF_INCLUDE]); | |
10774 | ||
10775 | if (srf_tb[NL80211_NAN_SRF_BF]) { | |
10776 | if (srf_tb[NL80211_NAN_SRF_MAC_ADDRS] || | |
10777 | !srf_tb[NL80211_NAN_SRF_BF_IDX]) { | |
10778 | err = -EINVAL; | |
10779 | goto out; | |
10780 | } | |
10781 | ||
10782 | func->srf_bf_len = | |
10783 | nla_len(srf_tb[NL80211_NAN_SRF_BF]); | |
10784 | func->srf_bf = | |
10785 | kmemdup(nla_data(srf_tb[NL80211_NAN_SRF_BF]), | |
10786 | func->srf_bf_len, GFP_KERNEL); | |
10787 | if (!func->srf_bf) { | |
10788 | err = -ENOMEM; | |
10789 | goto out; | |
10790 | } | |
10791 | ||
10792 | func->srf_bf_idx = | |
10793 | nla_get_u8(srf_tb[NL80211_NAN_SRF_BF_IDX]); | |
10794 | } else { | |
10795 | struct nlattr *attr, *mac_attr = | |
10796 | srf_tb[NL80211_NAN_SRF_MAC_ADDRS]; | |
10797 | int n_entries, rem, i = 0; | |
10798 | ||
10799 | if (!mac_attr) { | |
10800 | err = -EINVAL; | |
10801 | goto out; | |
10802 | } | |
10803 | ||
10804 | n_entries = validate_acl_mac_addrs(mac_attr); | |
10805 | if (n_entries <= 0) { | |
10806 | err = -EINVAL; | |
10807 | goto out; | |
10808 | } | |
10809 | ||
10810 | func->srf_num_macs = n_entries; | |
10811 | func->srf_macs = | |
10812 | kzalloc(sizeof(*func->srf_macs) * n_entries, | |
10813 | GFP_KERNEL); | |
10814 | if (!func->srf_macs) { | |
10815 | err = -ENOMEM; | |
10816 | goto out; | |
10817 | } | |
10818 | ||
10819 | nla_for_each_nested(attr, mac_attr, rem) | |
10820 | memcpy(func->srf_macs[i++].addr, nla_data(attr), | |
10821 | sizeof(*func->srf_macs)); | |
10822 | } | |
10823 | } | |
10824 | ||
10825 | if (tb[NL80211_NAN_FUNC_TX_MATCH_FILTER]) { | |
10826 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_TX_MATCH_FILTER], | |
10827 | func, true); | |
10828 | if (err) | |
10829 | goto out; | |
10830 | } | |
10831 | ||
10832 | if (tb[NL80211_NAN_FUNC_RX_MATCH_FILTER]) { | |
10833 | err = handle_nan_filter(tb[NL80211_NAN_FUNC_RX_MATCH_FILTER], | |
10834 | func, false); | |
10835 | if (err) | |
10836 | goto out; | |
10837 | } | |
10838 | ||
10839 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
10840 | if (!msg) { | |
10841 | err = -ENOMEM; | |
10842 | goto out; | |
10843 | } | |
10844 | ||
10845 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
10846 | NL80211_CMD_ADD_NAN_FUNCTION); | |
10847 | /* This can't really happen - we just allocated 4KB */ | |
10848 | if (WARN_ON(!hdr)) { | |
10849 | err = -ENOMEM; | |
10850 | goto out; | |
10851 | } | |
10852 | ||
10853 | err = rdev_add_nan_func(rdev, wdev, func); | |
10854 | out: | |
10855 | if (err < 0) { | |
10856 | cfg80211_free_nan_func(func); | |
10857 | nlmsg_free(msg); | |
10858 | return err; | |
10859 | } | |
10860 | ||
10861 | /* propagate the instance id and cookie to userspace */ | |
10862 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, func->cookie, | |
10863 | NL80211_ATTR_PAD)) | |
10864 | goto nla_put_failure; | |
10865 | ||
10866 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); | |
10867 | if (!func_attr) | |
10868 | goto nla_put_failure; | |
10869 | ||
10870 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, | |
10871 | func->instance_id)) | |
10872 | goto nla_put_failure; | |
10873 | ||
10874 | nla_nest_end(msg, func_attr); | |
10875 | ||
10876 | genlmsg_end(msg, hdr); | |
10877 | return genlmsg_reply(msg, info); | |
10878 | ||
10879 | nla_put_failure: | |
10880 | nlmsg_free(msg); | |
10881 | return -ENOBUFS; | |
10882 | } | |
10883 | ||
10884 | static int nl80211_nan_del_func(struct sk_buff *skb, | |
10885 | struct genl_info *info) | |
10886 | { | |
10887 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10888 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10889 | u64 cookie; | |
10890 | ||
10891 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
10892 | return -EOPNOTSUPP; | |
10893 | ||
10894 | if (!wdev->nan_started) | |
10895 | return -ENOTCONN; | |
10896 | ||
10897 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
10898 | return -EINVAL; | |
10899 | ||
10900 | if (wdev->owner_nlportid && | |
10901 | wdev->owner_nlportid != info->snd_portid) | |
10902 | return -ENOTCONN; | |
10903 | ||
10904 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
10905 | ||
10906 | rdev_del_nan_func(rdev, wdev, cookie); | |
10907 | ||
10908 | return 0; | |
10909 | } | |
10910 | ||
a5a9dcf2 AB |
10911 | static int nl80211_nan_change_config(struct sk_buff *skb, |
10912 | struct genl_info *info) | |
10913 | { | |
10914 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10915 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10916 | struct cfg80211_nan_conf conf = {}; | |
10917 | u32 changed = 0; | |
10918 | ||
10919 | if (wdev->iftype != NL80211_IFTYPE_NAN) | |
10920 | return -EOPNOTSUPP; | |
10921 | ||
10922 | if (!wdev->nan_started) | |
10923 | return -ENOTCONN; | |
10924 | ||
10925 | if (info->attrs[NL80211_ATTR_NAN_MASTER_PREF]) { | |
10926 | conf.master_pref = | |
10927 | nla_get_u8(info->attrs[NL80211_ATTR_NAN_MASTER_PREF]); | |
10928 | if (conf.master_pref <= 1 || conf.master_pref == 255) | |
10929 | return -EINVAL; | |
10930 | ||
10931 | changed |= CFG80211_NAN_CONF_CHANGED_PREF; | |
10932 | } | |
10933 | ||
10934 | if (info->attrs[NL80211_ATTR_NAN_DUAL]) { | |
10935 | conf.dual = nla_get_u8(info->attrs[NL80211_ATTR_NAN_DUAL]); | |
10936 | changed |= CFG80211_NAN_CONF_CHANGED_DUAL; | |
10937 | } | |
10938 | ||
10939 | if (!changed) | |
10940 | return -EINVAL; | |
10941 | ||
10942 | return rdev_nan_change_conf(rdev, wdev, &conf, changed); | |
10943 | } | |
10944 | ||
50bcd31d AB |
10945 | void cfg80211_nan_match(struct wireless_dev *wdev, |
10946 | struct cfg80211_nan_match_params *match, gfp_t gfp) | |
10947 | { | |
10948 | struct wiphy *wiphy = wdev->wiphy; | |
10949 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
10950 | struct nlattr *match_attr, *local_func_attr, *peer_func_attr; | |
10951 | struct sk_buff *msg; | |
10952 | void *hdr; | |
10953 | ||
10954 | if (WARN_ON(!match->inst_id || !match->peer_inst_id || !match->addr)) | |
10955 | return; | |
10956 | ||
10957 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
10958 | if (!msg) | |
10959 | return; | |
10960 | ||
10961 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NAN_MATCH); | |
10962 | if (!hdr) { | |
10963 | nlmsg_free(msg); | |
10964 | return; | |
10965 | } | |
10966 | ||
10967 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
10968 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
10969 | wdev->netdev->ifindex)) || | |
10970 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
10971 | NL80211_ATTR_PAD)) | |
10972 | goto nla_put_failure; | |
10973 | ||
10974 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, match->cookie, | |
10975 | NL80211_ATTR_PAD) || | |
10976 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, match->addr)) | |
10977 | goto nla_put_failure; | |
10978 | ||
10979 | match_attr = nla_nest_start(msg, NL80211_ATTR_NAN_MATCH); | |
10980 | if (!match_attr) | |
10981 | goto nla_put_failure; | |
10982 | ||
10983 | local_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_LOCAL); | |
10984 | if (!local_func_attr) | |
10985 | goto nla_put_failure; | |
10986 | ||
10987 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->inst_id)) | |
10988 | goto nla_put_failure; | |
10989 | ||
10990 | nla_nest_end(msg, local_func_attr); | |
10991 | ||
10992 | peer_func_attr = nla_nest_start(msg, NL80211_NAN_MATCH_FUNC_PEER); | |
10993 | if (!peer_func_attr) | |
10994 | goto nla_put_failure; | |
10995 | ||
10996 | if (nla_put_u8(msg, NL80211_NAN_FUNC_TYPE, match->type) || | |
10997 | nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, match->peer_inst_id)) | |
10998 | goto nla_put_failure; | |
10999 | ||
11000 | if (match->info && match->info_len && | |
11001 | nla_put(msg, NL80211_NAN_FUNC_SERVICE_INFO, match->info_len, | |
11002 | match->info)) | |
11003 | goto nla_put_failure; | |
11004 | ||
11005 | nla_nest_end(msg, peer_func_attr); | |
11006 | nla_nest_end(msg, match_attr); | |
11007 | genlmsg_end(msg, hdr); | |
11008 | ||
11009 | if (!wdev->owner_nlportid) | |
11010 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
11011 | msg, 0, NL80211_MCGRP_NAN, gfp); | |
11012 | else | |
11013 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
11014 | wdev->owner_nlportid); | |
11015 | ||
11016 | return; | |
11017 | ||
11018 | nla_put_failure: | |
11019 | nlmsg_free(msg); | |
11020 | } | |
11021 | EXPORT_SYMBOL(cfg80211_nan_match); | |
11022 | ||
368e5a7b AB |
11023 | void cfg80211_nan_func_terminated(struct wireless_dev *wdev, |
11024 | u8 inst_id, | |
11025 | enum nl80211_nan_func_term_reason reason, | |
11026 | u64 cookie, gfp_t gfp) | |
11027 | { | |
11028 | struct wiphy *wiphy = wdev->wiphy; | |
11029 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
11030 | struct sk_buff *msg; | |
11031 | struct nlattr *func_attr; | |
11032 | void *hdr; | |
11033 | ||
11034 | if (WARN_ON(!inst_id)) | |
11035 | return; | |
11036 | ||
11037 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11038 | if (!msg) | |
11039 | return; | |
11040 | ||
11041 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_NAN_FUNCTION); | |
11042 | if (!hdr) { | |
11043 | nlmsg_free(msg); | |
11044 | return; | |
11045 | } | |
11046 | ||
11047 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
11048 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
11049 | wdev->netdev->ifindex)) || | |
11050 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), | |
11051 | NL80211_ATTR_PAD)) | |
11052 | goto nla_put_failure; | |
11053 | ||
11054 | if (nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, | |
11055 | NL80211_ATTR_PAD)) | |
11056 | goto nla_put_failure; | |
11057 | ||
11058 | func_attr = nla_nest_start(msg, NL80211_ATTR_NAN_FUNC); | |
11059 | if (!func_attr) | |
11060 | goto nla_put_failure; | |
11061 | ||
11062 | if (nla_put_u8(msg, NL80211_NAN_FUNC_INSTANCE_ID, inst_id) || | |
11063 | nla_put_u8(msg, NL80211_NAN_FUNC_TERM_REASON, reason)) | |
11064 | goto nla_put_failure; | |
11065 | ||
11066 | nla_nest_end(msg, func_attr); | |
11067 | genlmsg_end(msg, hdr); | |
11068 | ||
11069 | if (!wdev->owner_nlportid) | |
11070 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
11071 | msg, 0, NL80211_MCGRP_NAN, gfp); | |
11072 | else | |
11073 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, | |
11074 | wdev->owner_nlportid); | |
11075 | ||
11076 | return; | |
11077 | ||
11078 | nla_put_failure: | |
11079 | nlmsg_free(msg); | |
11080 | } | |
11081 | EXPORT_SYMBOL(cfg80211_nan_func_terminated); | |
11082 | ||
3713b4e3 JB |
11083 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
11084 | struct genl_info *info) | |
11085 | { | |
11086 | void *hdr; | |
11087 | struct sk_buff *msg; | |
11088 | ||
11089 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11090 | if (!msg) | |
11091 | return -ENOMEM; | |
11092 | ||
11093 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
11094 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
11095 | if (!hdr) | |
11096 | goto nla_put_failure; | |
11097 | ||
11098 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
11099 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
11100 | goto nla_put_failure; | |
11101 | ||
11102 | genlmsg_end(msg, hdr); | |
11103 | return genlmsg_reply(msg, info); | |
11104 | ||
11105 | nla_put_failure: | |
11106 | kfree_skb(msg); | |
11107 | return -ENOBUFS; | |
11108 | } | |
11109 | ||
355199e0 JM |
11110 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
11111 | { | |
11112 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11113 | struct cfg80211_update_ft_ies_params ft_params; | |
11114 | struct net_device *dev = info->user_ptr[1]; | |
11115 | ||
11116 | if (!rdev->ops->update_ft_ies) | |
11117 | return -EOPNOTSUPP; | |
11118 | ||
11119 | if (!info->attrs[NL80211_ATTR_MDID] || | |
11120 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
11121 | return -EINVAL; | |
11122 | ||
11123 | memset(&ft_params, 0, sizeof(ft_params)); | |
11124 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
11125 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
11126 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
11127 | ||
11128 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
11129 | } | |
11130 | ||
5de17984 AS |
11131 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
11132 | struct genl_info *info) | |
11133 | { | |
11134 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11135 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11136 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
11137 | u16 duration; | |
11138 | int ret; | |
11139 | ||
11140 | if (!rdev->ops->crit_proto_start) | |
11141 | return -EOPNOTSUPP; | |
11142 | ||
11143 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
11144 | return -EINVAL; | |
11145 | ||
11146 | if (rdev->crit_proto_nlportid) | |
11147 | return -EBUSY; | |
11148 | ||
11149 | /* determine protocol if provided */ | |
11150 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
11151 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
11152 | ||
11153 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
11154 | return -EINVAL; | |
11155 | ||
11156 | /* timeout must be provided */ | |
11157 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
11158 | return -EINVAL; | |
11159 | ||
11160 | duration = | |
11161 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
11162 | ||
11163 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
11164 | return -ERANGE; | |
11165 | ||
11166 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
11167 | if (!ret) | |
11168 | rdev->crit_proto_nlportid = info->snd_portid; | |
11169 | ||
11170 | return ret; | |
11171 | } | |
11172 | ||
11173 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
11174 | struct genl_info *info) | |
11175 | { | |
11176 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11177 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11178 | ||
11179 | if (!rdev->ops->crit_proto_stop) | |
11180 | return -EOPNOTSUPP; | |
11181 | ||
11182 | if (rdev->crit_proto_nlportid) { | |
11183 | rdev->crit_proto_nlportid = 0; | |
11184 | rdev_crit_proto_stop(rdev, wdev); | |
11185 | } | |
11186 | return 0; | |
11187 | } | |
11188 | ||
ad7e718c JB |
11189 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
11190 | { | |
11191 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11192 | struct wireless_dev *wdev = | |
11193 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
11194 | int i, err; | |
11195 | u32 vid, subcmd; | |
11196 | ||
11197 | if (!rdev->wiphy.vendor_commands) | |
11198 | return -EOPNOTSUPP; | |
11199 | ||
11200 | if (IS_ERR(wdev)) { | |
11201 | err = PTR_ERR(wdev); | |
11202 | if (err != -EINVAL) | |
11203 | return err; | |
11204 | wdev = NULL; | |
11205 | } else if (wdev->wiphy != &rdev->wiphy) { | |
11206 | return -EINVAL; | |
11207 | } | |
11208 | ||
11209 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
11210 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
11211 | return -EINVAL; | |
11212 | ||
11213 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
11214 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
11215 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
11216 | const struct wiphy_vendor_command *vcmd; | |
11217 | void *data = NULL; | |
11218 | int len = 0; | |
11219 | ||
11220 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
11221 | ||
11222 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
11223 | continue; | |
11224 | ||
11225 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
11226 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
11227 | if (!wdev) | |
11228 | return -EINVAL; | |
11229 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
11230 | !wdev->netdev) | |
11231 | return -EINVAL; | |
11232 | ||
11233 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
11234 | if (wdev->netdev && | |
11235 | !netif_running(wdev->netdev)) | |
11236 | return -ENETDOWN; | |
11237 | if (!wdev->netdev && !wdev->p2p_started) | |
11238 | return -ENETDOWN; | |
11239 | } | |
7bdbe400 JB |
11240 | |
11241 | if (!vcmd->doit) | |
11242 | return -EOPNOTSUPP; | |
ad7e718c JB |
11243 | } else { |
11244 | wdev = NULL; | |
11245 | } | |
11246 | ||
11247 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
11248 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
11249 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
11250 | } | |
11251 | ||
11252 | rdev->cur_cmd_info = info; | |
11253 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
11254 | data, len); | |
11255 | rdev->cur_cmd_info = NULL; | |
11256 | return err; | |
11257 | } | |
11258 | ||
11259 | return -EOPNOTSUPP; | |
11260 | } | |
11261 | ||
7bdbe400 JB |
11262 | static int nl80211_prepare_vendor_dump(struct sk_buff *skb, |
11263 | struct netlink_callback *cb, | |
11264 | struct cfg80211_registered_device **rdev, | |
11265 | struct wireless_dev **wdev) | |
11266 | { | |
c90c39da | 11267 | struct nlattr **attrbuf = genl_family_attrbuf(&nl80211_fam); |
7bdbe400 JB |
11268 | u32 vid, subcmd; |
11269 | unsigned int i; | |
11270 | int vcmd_idx = -1; | |
11271 | int err; | |
11272 | void *data = NULL; | |
11273 | unsigned int data_len = 0; | |
11274 | ||
11275 | rtnl_lock(); | |
11276 | ||
11277 | if (cb->args[0]) { | |
11278 | /* subtract the 1 again here */ | |
11279 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
11280 | struct wireless_dev *tmp; | |
11281 | ||
11282 | if (!wiphy) { | |
11283 | err = -ENODEV; | |
11284 | goto out_unlock; | |
11285 | } | |
11286 | *rdev = wiphy_to_rdev(wiphy); | |
11287 | *wdev = NULL; | |
11288 | ||
11289 | if (cb->args[1]) { | |
53873f13 | 11290 | list_for_each_entry(tmp, &wiphy->wdev_list, list) { |
7bdbe400 JB |
11291 | if (tmp->identifier == cb->args[1] - 1) { |
11292 | *wdev = tmp; | |
11293 | break; | |
11294 | } | |
11295 | } | |
11296 | } | |
11297 | ||
11298 | /* keep rtnl locked in successful case */ | |
11299 | return 0; | |
11300 | } | |
11301 | ||
11302 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
c90c39da | 11303 | attrbuf, nl80211_fam.maxattr, nl80211_policy); |
7bdbe400 JB |
11304 | if (err) |
11305 | goto out_unlock; | |
11306 | ||
c90c39da JB |
11307 | if (!attrbuf[NL80211_ATTR_VENDOR_ID] || |
11308 | !attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) { | |
7bdbe400 JB |
11309 | err = -EINVAL; |
11310 | goto out_unlock; | |
11311 | } | |
11312 | ||
c90c39da | 11313 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), attrbuf); |
7bdbe400 JB |
11314 | if (IS_ERR(*wdev)) |
11315 | *wdev = NULL; | |
11316 | ||
c90c39da | 11317 | *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), attrbuf); |
7bdbe400 JB |
11318 | if (IS_ERR(*rdev)) { |
11319 | err = PTR_ERR(*rdev); | |
11320 | goto out_unlock; | |
11321 | } | |
11322 | ||
c90c39da JB |
11323 | vid = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_ID]); |
11324 | subcmd = nla_get_u32(attrbuf[NL80211_ATTR_VENDOR_SUBCMD]); | |
7bdbe400 JB |
11325 | |
11326 | for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) { | |
11327 | const struct wiphy_vendor_command *vcmd; | |
11328 | ||
11329 | vcmd = &(*rdev)->wiphy.vendor_commands[i]; | |
11330 | ||
11331 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
11332 | continue; | |
11333 | ||
11334 | if (!vcmd->dumpit) { | |
11335 | err = -EOPNOTSUPP; | |
11336 | goto out_unlock; | |
11337 | } | |
11338 | ||
11339 | vcmd_idx = i; | |
11340 | break; | |
11341 | } | |
11342 | ||
11343 | if (vcmd_idx < 0) { | |
11344 | err = -EOPNOTSUPP; | |
11345 | goto out_unlock; | |
11346 | } | |
11347 | ||
c90c39da JB |
11348 | if (attrbuf[NL80211_ATTR_VENDOR_DATA]) { |
11349 | data = nla_data(attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
11350 | data_len = nla_len(attrbuf[NL80211_ATTR_VENDOR_DATA]); | |
7bdbe400 JB |
11351 | } |
11352 | ||
11353 | /* 0 is the first index - add 1 to parse only once */ | |
11354 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
11355 | /* add 1 to know if it was NULL */ | |
11356 | cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0; | |
11357 | cb->args[2] = vcmd_idx; | |
11358 | cb->args[3] = (unsigned long)data; | |
11359 | cb->args[4] = data_len; | |
11360 | ||
11361 | /* keep rtnl locked in successful case */ | |
11362 | return 0; | |
11363 | out_unlock: | |
11364 | rtnl_unlock(); | |
11365 | return err; | |
11366 | } | |
11367 | ||
11368 | static int nl80211_vendor_cmd_dump(struct sk_buff *skb, | |
11369 | struct netlink_callback *cb) | |
11370 | { | |
11371 | struct cfg80211_registered_device *rdev; | |
11372 | struct wireless_dev *wdev; | |
11373 | unsigned int vcmd_idx; | |
11374 | const struct wiphy_vendor_command *vcmd; | |
11375 | void *data; | |
11376 | int data_len; | |
11377 | int err; | |
11378 | struct nlattr *vendor_data; | |
11379 | ||
11380 | err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev); | |
11381 | if (err) | |
11382 | return err; | |
11383 | ||
11384 | vcmd_idx = cb->args[2]; | |
11385 | data = (void *)cb->args[3]; | |
11386 | data_len = cb->args[4]; | |
11387 | vcmd = &rdev->wiphy.vendor_commands[vcmd_idx]; | |
11388 | ||
11389 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
11390 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
11391 | if (!wdev) | |
11392 | return -EINVAL; | |
11393 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
11394 | !wdev->netdev) | |
11395 | return -EINVAL; | |
11396 | ||
11397 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
11398 | if (wdev->netdev && | |
11399 | !netif_running(wdev->netdev)) | |
11400 | return -ENETDOWN; | |
11401 | if (!wdev->netdev && !wdev->p2p_started) | |
11402 | return -ENETDOWN; | |
11403 | } | |
11404 | } | |
11405 | ||
11406 | while (1) { | |
11407 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, | |
11408 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
11409 | NL80211_CMD_VENDOR); | |
11410 | if (!hdr) | |
11411 | break; | |
11412 | ||
11413 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
11414 | (wdev && nla_put_u64_64bit(skb, NL80211_ATTR_WDEV, |
11415 | wdev_id(wdev), | |
11416 | NL80211_ATTR_PAD))) { | |
7bdbe400 JB |
11417 | genlmsg_cancel(skb, hdr); |
11418 | break; | |
11419 | } | |
11420 | ||
11421 | vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA); | |
11422 | if (!vendor_data) { | |
11423 | genlmsg_cancel(skb, hdr); | |
11424 | break; | |
11425 | } | |
11426 | ||
11427 | err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len, | |
11428 | (unsigned long *)&cb->args[5]); | |
11429 | nla_nest_end(skb, vendor_data); | |
11430 | ||
11431 | if (err == -ENOBUFS || err == -ENOENT) { | |
11432 | genlmsg_cancel(skb, hdr); | |
11433 | break; | |
11434 | } else if (err) { | |
11435 | genlmsg_cancel(skb, hdr); | |
11436 | goto out; | |
11437 | } | |
11438 | ||
11439 | genlmsg_end(skb, hdr); | |
11440 | } | |
11441 | ||
11442 | err = skb->len; | |
11443 | out: | |
11444 | rtnl_unlock(); | |
11445 | return err; | |
11446 | } | |
11447 | ||
ad7e718c JB |
11448 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, |
11449 | enum nl80211_commands cmd, | |
11450 | enum nl80211_attrs attr, | |
11451 | int approxlen) | |
11452 | { | |
f26cbf40 | 11453 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
11454 | |
11455 | if (WARN_ON(!rdev->cur_cmd_info)) | |
11456 | return NULL; | |
11457 | ||
6c09e791 | 11458 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
11459 | rdev->cur_cmd_info->snd_portid, |
11460 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 11461 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
11462 | } |
11463 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
11464 | ||
11465 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
11466 | { | |
11467 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
11468 | void *hdr = ((void **)skb->cb)[1]; | |
11469 | struct nlattr *data = ((void **)skb->cb)[2]; | |
11470 | ||
bd8c78e7 JB |
11471 | /* clear CB data for netlink core to own from now on */ |
11472 | memset(skb->cb, 0, sizeof(skb->cb)); | |
11473 | ||
ad7e718c JB |
11474 | if (WARN_ON(!rdev->cur_cmd_info)) { |
11475 | kfree_skb(skb); | |
11476 | return -EINVAL; | |
11477 | } | |
11478 | ||
11479 | nla_nest_end(skb, data); | |
11480 | genlmsg_end(skb, hdr); | |
11481 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
11482 | } | |
11483 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
11484 | ||
fa9ffc74 KP |
11485 | static int nl80211_set_qos_map(struct sk_buff *skb, |
11486 | struct genl_info *info) | |
11487 | { | |
11488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11489 | struct cfg80211_qos_map *qos_map = NULL; | |
11490 | struct net_device *dev = info->user_ptr[1]; | |
11491 | u8 *pos, len, num_des, des_len, des; | |
11492 | int ret; | |
11493 | ||
11494 | if (!rdev->ops->set_qos_map) | |
11495 | return -EOPNOTSUPP; | |
11496 | ||
11497 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
11498 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
11499 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
11500 | ||
11501 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
11502 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
11503 | return -EINVAL; | |
11504 | ||
11505 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
11506 | if (!qos_map) | |
11507 | return -ENOMEM; | |
11508 | ||
11509 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
11510 | if (num_des) { | |
11511 | des_len = num_des * | |
11512 | sizeof(struct cfg80211_dscp_exception); | |
11513 | memcpy(qos_map->dscp_exception, pos, des_len); | |
11514 | qos_map->num_des = num_des; | |
11515 | for (des = 0; des < num_des; des++) { | |
11516 | if (qos_map->dscp_exception[des].up > 7) { | |
11517 | kfree(qos_map); | |
11518 | return -EINVAL; | |
11519 | } | |
11520 | } | |
11521 | pos += des_len; | |
11522 | } | |
11523 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
11524 | } | |
11525 | ||
11526 | wdev_lock(dev->ieee80211_ptr); | |
11527 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
11528 | if (!ret) | |
11529 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
11530 | wdev_unlock(dev->ieee80211_ptr); | |
11531 | ||
11532 | kfree(qos_map); | |
11533 | return ret; | |
11534 | } | |
11535 | ||
960d01ac JB |
11536 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
11537 | { | |
11538 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11539 | struct net_device *dev = info->user_ptr[1]; | |
11540 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11541 | const u8 *peer; | |
11542 | u8 tsid, up; | |
11543 | u16 admitted_time = 0; | |
11544 | int err; | |
11545 | ||
723e73ac | 11546 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
11547 | return -EOPNOTSUPP; |
11548 | ||
11549 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
11550 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
11551 | return -EINVAL; | |
11552 | ||
11553 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
11554 | if (tsid >= IEEE80211_NUM_TIDS) | |
11555 | return -EINVAL; | |
11556 | ||
11557 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
11558 | if (up >= IEEE80211_NUM_UPS) | |
11559 | return -EINVAL; | |
11560 | ||
11561 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 11562 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 11563 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
11564 | * need more attributes for that (e.g. BA session requirement); |
11565 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
11566 | */ |
11567 | return -EINVAL; | |
11568 | } | |
11569 | ||
11570 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11571 | ||
11572 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
11573 | admitted_time = | |
11574 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
11575 | if (!admitted_time) | |
11576 | return -EINVAL; | |
11577 | } | |
11578 | ||
11579 | wdev_lock(wdev); | |
11580 | switch (wdev->iftype) { | |
11581 | case NL80211_IFTYPE_STATION: | |
11582 | case NL80211_IFTYPE_P2P_CLIENT: | |
11583 | if (wdev->current_bss) | |
11584 | break; | |
11585 | err = -ENOTCONN; | |
11586 | goto out; | |
11587 | default: | |
11588 | err = -EOPNOTSUPP; | |
11589 | goto out; | |
11590 | } | |
11591 | ||
11592 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
11593 | ||
11594 | out: | |
11595 | wdev_unlock(wdev); | |
11596 | return err; | |
11597 | } | |
11598 | ||
11599 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
11600 | { | |
11601 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11602 | struct net_device *dev = info->user_ptr[1]; | |
11603 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11604 | const u8 *peer; | |
11605 | u8 tsid; | |
11606 | int err; | |
11607 | ||
11608 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
11609 | return -EINVAL; | |
11610 | ||
11611 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
11612 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11613 | ||
11614 | wdev_lock(wdev); | |
11615 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
11616 | wdev_unlock(wdev); | |
11617 | ||
11618 | return err; | |
11619 | } | |
11620 | ||
1057d35e AN |
11621 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
11622 | struct genl_info *info) | |
11623 | { | |
11624 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11625 | struct net_device *dev = info->user_ptr[1]; | |
11626 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11627 | struct cfg80211_chan_def chandef = {}; | |
11628 | const u8 *addr; | |
11629 | u8 oper_class; | |
11630 | int err; | |
11631 | ||
11632 | if (!rdev->ops->tdls_channel_switch || | |
11633 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
11634 | return -EOPNOTSUPP; | |
11635 | ||
11636 | switch (dev->ieee80211_ptr->iftype) { | |
11637 | case NL80211_IFTYPE_STATION: | |
11638 | case NL80211_IFTYPE_P2P_CLIENT: | |
11639 | break; | |
11640 | default: | |
11641 | return -EOPNOTSUPP; | |
11642 | } | |
11643 | ||
11644 | if (!info->attrs[NL80211_ATTR_MAC] || | |
11645 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
11646 | return -EINVAL; | |
11647 | ||
11648 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
11649 | if (err) | |
11650 | return err; | |
11651 | ||
11652 | /* | |
11653 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
11654 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
11655 | * specification is not defined for them. | |
11656 | */ | |
57fbcce3 | 11657 | if (chandef.chan->band == NL80211_BAND_2GHZ && |
1057d35e AN |
11658 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && |
11659 | chandef.width != NL80211_CHAN_WIDTH_20) | |
11660 | return -EINVAL; | |
11661 | ||
11662 | /* we will be active on the TDLS link */ | |
923b352f AN |
11663 | if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef, |
11664 | wdev->iftype)) | |
1057d35e AN |
11665 | return -EINVAL; |
11666 | ||
11667 | /* don't allow switching to DFS channels */ | |
11668 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
11669 | return -EINVAL; | |
11670 | ||
11671 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11672 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
11673 | ||
11674 | wdev_lock(wdev); | |
11675 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
11676 | wdev_unlock(wdev); | |
11677 | ||
11678 | return err; | |
11679 | } | |
11680 | ||
11681 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
11682 | struct genl_info *info) | |
11683 | { | |
11684 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
11685 | struct net_device *dev = info->user_ptr[1]; | |
11686 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
11687 | const u8 *addr; | |
11688 | ||
11689 | if (!rdev->ops->tdls_channel_switch || | |
11690 | !rdev->ops->tdls_cancel_channel_switch || | |
11691 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
11692 | return -EOPNOTSUPP; | |
11693 | ||
11694 | switch (dev->ieee80211_ptr->iftype) { | |
11695 | case NL80211_IFTYPE_STATION: | |
11696 | case NL80211_IFTYPE_P2P_CLIENT: | |
11697 | break; | |
11698 | default: | |
11699 | return -EOPNOTSUPP; | |
11700 | } | |
11701 | ||
11702 | if (!info->attrs[NL80211_ATTR_MAC]) | |
11703 | return -EINVAL; | |
11704 | ||
11705 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
11706 | ||
11707 | wdev_lock(wdev); | |
11708 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
11709 | wdev_unlock(wdev); | |
11710 | ||
11711 | return 0; | |
11712 | } | |
11713 | ||
4c476991 JB |
11714 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
11715 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
11716 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
11717 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
11718 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
11719 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 11720 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 11721 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
11722 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
11723 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 11724 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 11725 | |
f84f771d | 11726 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
11727 | struct genl_info *info) |
11728 | { | |
11729 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 11730 | struct wireless_dev *wdev; |
4c476991 | 11731 | struct net_device *dev; |
4c476991 JB |
11732 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
11733 | ||
11734 | if (rtnl) | |
11735 | rtnl_lock(); | |
11736 | ||
11737 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 11738 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
11739 | if (IS_ERR(rdev)) { |
11740 | if (rtnl) | |
11741 | rtnl_unlock(); | |
11742 | return PTR_ERR(rdev); | |
11743 | } | |
11744 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
11745 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
11746 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
11747 | ASSERT_RTNL(); |
11748 | ||
89a54e48 JB |
11749 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
11750 | info->attrs); | |
11751 | if (IS_ERR(wdev)) { | |
4c476991 JB |
11752 | if (rtnl) |
11753 | rtnl_unlock(); | |
89a54e48 | 11754 | return PTR_ERR(wdev); |
4c476991 | 11755 | } |
89a54e48 | 11756 | |
89a54e48 | 11757 | dev = wdev->netdev; |
f26cbf40 | 11758 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 11759 | |
1bf614ef JB |
11760 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
11761 | if (!dev) { | |
1bf614ef JB |
11762 | if (rtnl) |
11763 | rtnl_unlock(); | |
11764 | return -EINVAL; | |
11765 | } | |
11766 | ||
11767 | info->user_ptr[1] = dev; | |
11768 | } else { | |
11769 | info->user_ptr[1] = wdev; | |
41265714 | 11770 | } |
1bf614ef JB |
11771 | |
11772 | if (dev) { | |
11773 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
11774 | !netif_running(dev)) { | |
1bf614ef JB |
11775 | if (rtnl) |
11776 | rtnl_unlock(); | |
11777 | return -ENETDOWN; | |
11778 | } | |
11779 | ||
11780 | dev_hold(dev); | |
98104fde | 11781 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
cb3b7d87 AB |
11782 | if (wdev->iftype == NL80211_IFTYPE_P2P_DEVICE && |
11783 | !wdev->p2p_started) { | |
11784 | if (rtnl) | |
11785 | rtnl_unlock(); | |
11786 | return -ENETDOWN; | |
11787 | } | |
11788 | if (wdev->iftype == NL80211_IFTYPE_NAN && | |
11789 | !wdev->nan_started) { | |
98104fde JB |
11790 | if (rtnl) |
11791 | rtnl_unlock(); | |
11792 | return -ENETDOWN; | |
11793 | } | |
41265714 | 11794 | } |
89a54e48 | 11795 | |
4c476991 | 11796 | info->user_ptr[0] = rdev; |
4c476991 JB |
11797 | } |
11798 | ||
11799 | return 0; | |
11800 | } | |
11801 | ||
f84f771d | 11802 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
11803 | struct genl_info *info) |
11804 | { | |
1bf614ef JB |
11805 | if (info->user_ptr[1]) { |
11806 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
11807 | struct wireless_dev *wdev = info->user_ptr[1]; | |
11808 | ||
11809 | if (wdev->netdev) | |
11810 | dev_put(wdev->netdev); | |
11811 | } else { | |
11812 | dev_put(info->user_ptr[1]); | |
11813 | } | |
11814 | } | |
5393b917 | 11815 | |
4c476991 JB |
11816 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
11817 | rtnl_unlock(); | |
5393b917 JB |
11818 | |
11819 | /* If needed, clear the netlink message payload from the SKB | |
11820 | * as it might contain key data that shouldn't stick around on | |
11821 | * the heap after the SKB is freed. The netlink message header | |
11822 | * is still needed for further processing, so leave it intact. | |
11823 | */ | |
11824 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
11825 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
11826 | ||
11827 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
11828 | } | |
4c476991 JB |
11829 | } |
11830 | ||
4534de83 | 11831 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
11832 | { |
11833 | .cmd = NL80211_CMD_GET_WIPHY, | |
11834 | .doit = nl80211_get_wiphy, | |
11835 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 11836 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
11837 | .policy = nl80211_policy, |
11838 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
11839 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11840 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11841 | }, |
11842 | { | |
11843 | .cmd = NL80211_CMD_SET_WIPHY, | |
11844 | .doit = nl80211_set_wiphy, | |
11845 | .policy = nl80211_policy, | |
5617c6cd | 11846 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 | 11847 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
11848 | }, |
11849 | { | |
11850 | .cmd = NL80211_CMD_GET_INTERFACE, | |
11851 | .doit = nl80211_get_interface, | |
11852 | .dumpit = nl80211_dump_interface, | |
11853 | .policy = nl80211_policy, | |
11854 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
11855 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
11856 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11857 | }, |
11858 | { | |
11859 | .cmd = NL80211_CMD_SET_INTERFACE, | |
11860 | .doit = nl80211_set_interface, | |
11861 | .policy = nl80211_policy, | |
5617c6cd | 11862 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11863 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11864 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11865 | }, |
11866 | { | |
11867 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
11868 | .doit = nl80211_new_interface, | |
11869 | .policy = nl80211_policy, | |
5617c6cd | 11870 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
11871 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
11872 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
11873 | }, |
11874 | { | |
11875 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
11876 | .doit = nl80211_del_interface, | |
11877 | .policy = nl80211_policy, | |
5617c6cd | 11878 | .flags = GENL_UNS_ADMIN_PERM, |
84efbb84 | 11879 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 11880 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
11881 | }, |
11882 | { | |
11883 | .cmd = NL80211_CMD_GET_KEY, | |
11884 | .doit = nl80211_get_key, | |
11885 | .policy = nl80211_policy, | |
5617c6cd | 11886 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11887 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11888 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
11889 | }, |
11890 | { | |
11891 | .cmd = NL80211_CMD_SET_KEY, | |
11892 | .doit = nl80211_set_key, | |
11893 | .policy = nl80211_policy, | |
5617c6cd | 11894 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11895 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11896 | NL80211_FLAG_NEED_RTNL | |
11897 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
11898 | }, |
11899 | { | |
11900 | .cmd = NL80211_CMD_NEW_KEY, | |
11901 | .doit = nl80211_new_key, | |
11902 | .policy = nl80211_policy, | |
5617c6cd | 11903 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11904 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
11905 | NL80211_FLAG_NEED_RTNL | |
11906 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
11907 | }, |
11908 | { | |
11909 | .cmd = NL80211_CMD_DEL_KEY, | |
11910 | .doit = nl80211_del_key, | |
11911 | .policy = nl80211_policy, | |
5617c6cd | 11912 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11913 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11914 | NL80211_FLAG_NEED_RTNL, |
55682965 | 11915 | }, |
ed1b6cc7 JB |
11916 | { |
11917 | .cmd = NL80211_CMD_SET_BEACON, | |
11918 | .policy = nl80211_policy, | |
5617c6cd | 11919 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11920 | .doit = nl80211_set_beacon, |
2b5f8b0b | 11921 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11922 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
11923 | }, |
11924 | { | |
8860020e | 11925 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 | 11926 | .policy = nl80211_policy, |
5617c6cd | 11927 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11928 | .doit = nl80211_start_ap, |
2b5f8b0b | 11929 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11930 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
11931 | }, |
11932 | { | |
8860020e | 11933 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 | 11934 | .policy = nl80211_policy, |
5617c6cd | 11935 | .flags = GENL_UNS_ADMIN_PERM, |
8860020e | 11936 | .doit = nl80211_stop_ap, |
2b5f8b0b | 11937 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11938 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 11939 | }, |
5727ef1b JB |
11940 | { |
11941 | .cmd = NL80211_CMD_GET_STATION, | |
11942 | .doit = nl80211_get_station, | |
2ec600d6 | 11943 | .dumpit = nl80211_dump_station, |
5727ef1b | 11944 | .policy = nl80211_policy, |
4c476991 JB |
11945 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
11946 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
11947 | }, |
11948 | { | |
11949 | .cmd = NL80211_CMD_SET_STATION, | |
11950 | .doit = nl80211_set_station, | |
11951 | .policy = nl80211_policy, | |
5617c6cd | 11952 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11953 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11954 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
11955 | }, |
11956 | { | |
11957 | .cmd = NL80211_CMD_NEW_STATION, | |
11958 | .doit = nl80211_new_station, | |
11959 | .policy = nl80211_policy, | |
5617c6cd | 11960 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11961 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11962 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
11963 | }, |
11964 | { | |
11965 | .cmd = NL80211_CMD_DEL_STATION, | |
11966 | .doit = nl80211_del_station, | |
11967 | .policy = nl80211_policy, | |
5617c6cd | 11968 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 11969 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11970 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11971 | }, |
11972 | { | |
11973 | .cmd = NL80211_CMD_GET_MPATH, | |
11974 | .doit = nl80211_get_mpath, | |
11975 | .dumpit = nl80211_dump_mpath, | |
11976 | .policy = nl80211_policy, | |
5617c6cd | 11977 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11978 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11979 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 11980 | }, |
66be7d2b HR |
11981 | { |
11982 | .cmd = NL80211_CMD_GET_MPP, | |
11983 | .doit = nl80211_get_mpp, | |
11984 | .dumpit = nl80211_dump_mpp, | |
11985 | .policy = nl80211_policy, | |
5617c6cd | 11986 | .flags = GENL_UNS_ADMIN_PERM, |
66be7d2b HR |
11987 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
11988 | NL80211_FLAG_NEED_RTNL, | |
11989 | }, | |
2ec600d6 LCC |
11990 | { |
11991 | .cmd = NL80211_CMD_SET_MPATH, | |
11992 | .doit = nl80211_set_mpath, | |
11993 | .policy = nl80211_policy, | |
5617c6cd | 11994 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 11995 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 11996 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
11997 | }, |
11998 | { | |
11999 | .cmd = NL80211_CMD_NEW_MPATH, | |
12000 | .doit = nl80211_new_mpath, | |
12001 | .policy = nl80211_policy, | |
5617c6cd | 12002 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12003 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12004 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
12005 | }, |
12006 | { | |
12007 | .cmd = NL80211_CMD_DEL_MPATH, | |
12008 | .doit = nl80211_del_mpath, | |
12009 | .policy = nl80211_policy, | |
5617c6cd | 12010 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12011 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12012 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
12013 | }, |
12014 | { | |
12015 | .cmd = NL80211_CMD_SET_BSS, | |
12016 | .doit = nl80211_set_bss, | |
12017 | .policy = nl80211_policy, | |
5617c6cd | 12018 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12019 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12020 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 12021 | }, |
f130347c LR |
12022 | { |
12023 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
12024 | .doit = nl80211_get_reg_do, |
12025 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 12026 | .policy = nl80211_policy, |
5fe231e8 | 12027 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
12028 | /* can be retrieved by unprivileged users */ |
12029 | }, | |
b6863036 | 12030 | #ifdef CONFIG_CFG80211_CRDA_SUPPORT |
b2e1b302 LR |
12031 | { |
12032 | .cmd = NL80211_CMD_SET_REG, | |
12033 | .doit = nl80211_set_reg, | |
12034 | .policy = nl80211_policy, | |
12035 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 12036 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 12037 | }, |
b6863036 | 12038 | #endif |
b2e1b302 LR |
12039 | { |
12040 | .cmd = NL80211_CMD_REQ_SET_REG, | |
12041 | .doit = nl80211_req_set_reg, | |
12042 | .policy = nl80211_policy, | |
93da9cc1 | 12043 | .flags = GENL_ADMIN_PERM, |
12044 | }, | |
12045 | { | |
24bdd9f4 JC |
12046 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
12047 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 12048 | .policy = nl80211_policy, |
12049 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 12050 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12051 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 12052 | }, |
12053 | { | |
24bdd9f4 JC |
12054 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
12055 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 12056 | .policy = nl80211_policy, |
5617c6cd | 12057 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c | 12058 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12059 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 12060 | }, |
2a519311 JB |
12061 | { |
12062 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
12063 | .doit = nl80211_trigger_scan, | |
12064 | .policy = nl80211_policy, | |
5617c6cd | 12065 | .flags = GENL_UNS_ADMIN_PERM, |
fd014284 | 12066 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 12067 | NL80211_FLAG_NEED_RTNL, |
2a519311 | 12068 | }, |
91d3ab46 VK |
12069 | { |
12070 | .cmd = NL80211_CMD_ABORT_SCAN, | |
12071 | .doit = nl80211_abort_scan, | |
12072 | .policy = nl80211_policy, | |
5617c6cd | 12073 | .flags = GENL_UNS_ADMIN_PERM, |
91d3ab46 VK |
12074 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
12075 | NL80211_FLAG_NEED_RTNL, | |
12076 | }, | |
2a519311 JB |
12077 | { |
12078 | .cmd = NL80211_CMD_GET_SCAN, | |
12079 | .policy = nl80211_policy, | |
12080 | .dumpit = nl80211_dump_scan, | |
12081 | }, | |
807f8a8c LC |
12082 | { |
12083 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
12084 | .doit = nl80211_start_sched_scan, | |
12085 | .policy = nl80211_policy, | |
5617c6cd | 12086 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
12087 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12088 | NL80211_FLAG_NEED_RTNL, | |
12089 | }, | |
12090 | { | |
12091 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
12092 | .doit = nl80211_stop_sched_scan, | |
12093 | .policy = nl80211_policy, | |
5617c6cd | 12094 | .flags = GENL_UNS_ADMIN_PERM, |
807f8a8c LC |
12095 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12096 | NL80211_FLAG_NEED_RTNL, | |
12097 | }, | |
636a5d36 JM |
12098 | { |
12099 | .cmd = NL80211_CMD_AUTHENTICATE, | |
12100 | .doit = nl80211_authenticate, | |
12101 | .policy = nl80211_policy, | |
5617c6cd | 12102 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12103 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
12104 | NL80211_FLAG_NEED_RTNL | |
12105 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
12106 | }, |
12107 | { | |
12108 | .cmd = NL80211_CMD_ASSOCIATE, | |
12109 | .doit = nl80211_associate, | |
12110 | .policy = nl80211_policy, | |
5617c6cd | 12111 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12112 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12113 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
12114 | }, |
12115 | { | |
12116 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
12117 | .doit = nl80211_deauthenticate, | |
12118 | .policy = nl80211_policy, | |
5617c6cd | 12119 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12120 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12121 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
12122 | }, |
12123 | { | |
12124 | .cmd = NL80211_CMD_DISASSOCIATE, | |
12125 | .doit = nl80211_disassociate, | |
12126 | .policy = nl80211_policy, | |
5617c6cd | 12127 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12128 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12129 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 12130 | }, |
04a773ad JB |
12131 | { |
12132 | .cmd = NL80211_CMD_JOIN_IBSS, | |
12133 | .doit = nl80211_join_ibss, | |
12134 | .policy = nl80211_policy, | |
5617c6cd | 12135 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12136 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12137 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
12138 | }, |
12139 | { | |
12140 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
12141 | .doit = nl80211_leave_ibss, | |
12142 | .policy = nl80211_policy, | |
5617c6cd | 12143 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12144 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12145 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 12146 | }, |
aff89a9b JB |
12147 | #ifdef CONFIG_NL80211_TESTMODE |
12148 | { | |
12149 | .cmd = NL80211_CMD_TESTMODE, | |
12150 | .doit = nl80211_testmode_do, | |
71063f0e | 12151 | .dumpit = nl80211_testmode_dump, |
aff89a9b | 12152 | .policy = nl80211_policy, |
5617c6cd | 12153 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12154 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12155 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
12156 | }, |
12157 | #endif | |
b23aa676 SO |
12158 | { |
12159 | .cmd = NL80211_CMD_CONNECT, | |
12160 | .doit = nl80211_connect, | |
12161 | .policy = nl80211_policy, | |
5617c6cd | 12162 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12163 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12164 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
12165 | }, |
12166 | { | |
12167 | .cmd = NL80211_CMD_DISCONNECT, | |
12168 | .doit = nl80211_disconnect, | |
12169 | .policy = nl80211_policy, | |
5617c6cd | 12170 | .flags = GENL_UNS_ADMIN_PERM, |
41265714 | 12171 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12172 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 12173 | }, |
463d0183 JB |
12174 | { |
12175 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
12176 | .doit = nl80211_wiphy_netns, | |
12177 | .policy = nl80211_policy, | |
5617c6cd | 12178 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12179 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12180 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 12181 | }, |
61fa713c HS |
12182 | { |
12183 | .cmd = NL80211_CMD_GET_SURVEY, | |
12184 | .policy = nl80211_policy, | |
12185 | .dumpit = nl80211_dump_survey, | |
12186 | }, | |
67fbb16b SO |
12187 | { |
12188 | .cmd = NL80211_CMD_SET_PMKSA, | |
12189 | .doit = nl80211_setdel_pmksa, | |
12190 | .policy = nl80211_policy, | |
5617c6cd | 12191 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12192 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12193 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
12194 | }, |
12195 | { | |
12196 | .cmd = NL80211_CMD_DEL_PMKSA, | |
12197 | .doit = nl80211_setdel_pmksa, | |
12198 | .policy = nl80211_policy, | |
5617c6cd | 12199 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12200 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12201 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
12202 | }, |
12203 | { | |
12204 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
12205 | .doit = nl80211_flush_pmksa, | |
12206 | .policy = nl80211_policy, | |
5617c6cd | 12207 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12208 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 12209 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 12210 | }, |
9588bbd5 JM |
12211 | { |
12212 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
12213 | .doit = nl80211_remain_on_channel, | |
12214 | .policy = nl80211_policy, | |
5617c6cd | 12215 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12216 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 12217 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
12218 | }, |
12219 | { | |
12220 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
12221 | .doit = nl80211_cancel_remain_on_channel, | |
12222 | .policy = nl80211_policy, | |
5617c6cd | 12223 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12224 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 12225 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 12226 | }, |
13ae75b1 JM |
12227 | { |
12228 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
12229 | .doit = nl80211_set_tx_bitrate_mask, | |
12230 | .policy = nl80211_policy, | |
5617c6cd | 12231 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12232 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12233 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 12234 | }, |
026331c4 | 12235 | { |
2e161f78 JB |
12236 | .cmd = NL80211_CMD_REGISTER_FRAME, |
12237 | .doit = nl80211_register_mgmt, | |
026331c4 | 12238 | .policy = nl80211_policy, |
5617c6cd | 12239 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12240 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 12241 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
12242 | }, |
12243 | { | |
2e161f78 JB |
12244 | .cmd = NL80211_CMD_FRAME, |
12245 | .doit = nl80211_tx_mgmt, | |
026331c4 | 12246 | .policy = nl80211_policy, |
5617c6cd | 12247 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12248 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
12249 | NL80211_FLAG_NEED_RTNL, |
12250 | }, | |
12251 | { | |
12252 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
12253 | .doit = nl80211_tx_mgmt_cancel_wait, | |
12254 | .policy = nl80211_policy, | |
5617c6cd | 12255 | .flags = GENL_UNS_ADMIN_PERM, |
71bbc994 | 12256 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 12257 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 12258 | }, |
ffb9eb3d KV |
12259 | { |
12260 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
12261 | .doit = nl80211_set_power_save, | |
12262 | .policy = nl80211_policy, | |
5617c6cd | 12263 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12264 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12265 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
12266 | }, |
12267 | { | |
12268 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
12269 | .doit = nl80211_get_power_save, | |
12270 | .policy = nl80211_policy, | |
12271 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
12272 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12273 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 12274 | }, |
d6dc1a38 JO |
12275 | { |
12276 | .cmd = NL80211_CMD_SET_CQM, | |
12277 | .doit = nl80211_set_cqm, | |
12278 | .policy = nl80211_policy, | |
5617c6cd | 12279 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12280 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12281 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 12282 | }, |
f444de05 JB |
12283 | { |
12284 | .cmd = NL80211_CMD_SET_CHANNEL, | |
12285 | .doit = nl80211_set_channel, | |
12286 | .policy = nl80211_policy, | |
5617c6cd | 12287 | .flags = GENL_UNS_ADMIN_PERM, |
4c476991 JB |
12288 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12289 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 12290 | }, |
e8347eba BJ |
12291 | { |
12292 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
12293 | .doit = nl80211_set_wds_peer, | |
12294 | .policy = nl80211_policy, | |
5617c6cd | 12295 | .flags = GENL_UNS_ADMIN_PERM, |
43b19952 JB |
12296 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12297 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 12298 | }, |
29cbe68c JB |
12299 | { |
12300 | .cmd = NL80211_CMD_JOIN_MESH, | |
12301 | .doit = nl80211_join_mesh, | |
12302 | .policy = nl80211_policy, | |
5617c6cd | 12303 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
12304 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12305 | NL80211_FLAG_NEED_RTNL, | |
12306 | }, | |
12307 | { | |
12308 | .cmd = NL80211_CMD_LEAVE_MESH, | |
12309 | .doit = nl80211_leave_mesh, | |
12310 | .policy = nl80211_policy, | |
5617c6cd | 12311 | .flags = GENL_UNS_ADMIN_PERM, |
29cbe68c JB |
12312 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12313 | NL80211_FLAG_NEED_RTNL, | |
12314 | }, | |
6e0bd6c3 RL |
12315 | { |
12316 | .cmd = NL80211_CMD_JOIN_OCB, | |
12317 | .doit = nl80211_join_ocb, | |
12318 | .policy = nl80211_policy, | |
5617c6cd | 12319 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
12320 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12321 | NL80211_FLAG_NEED_RTNL, | |
12322 | }, | |
12323 | { | |
12324 | .cmd = NL80211_CMD_LEAVE_OCB, | |
12325 | .doit = nl80211_leave_ocb, | |
12326 | .policy = nl80211_policy, | |
5617c6cd | 12327 | .flags = GENL_UNS_ADMIN_PERM, |
6e0bd6c3 RL |
12328 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12329 | NL80211_FLAG_NEED_RTNL, | |
12330 | }, | |
dfb89c56 | 12331 | #ifdef CONFIG_PM |
ff1b6e69 JB |
12332 | { |
12333 | .cmd = NL80211_CMD_GET_WOWLAN, | |
12334 | .doit = nl80211_get_wowlan, | |
12335 | .policy = nl80211_policy, | |
12336 | /* can be retrieved by unprivileged users */ | |
12337 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
12338 | NL80211_FLAG_NEED_RTNL, | |
12339 | }, | |
12340 | { | |
12341 | .cmd = NL80211_CMD_SET_WOWLAN, | |
12342 | .doit = nl80211_set_wowlan, | |
12343 | .policy = nl80211_policy, | |
5617c6cd | 12344 | .flags = GENL_UNS_ADMIN_PERM, |
ff1b6e69 JB |
12345 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12346 | NL80211_FLAG_NEED_RTNL, | |
12347 | }, | |
dfb89c56 | 12348 | #endif |
e5497d76 JB |
12349 | { |
12350 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
12351 | .doit = nl80211_set_rekey_data, | |
12352 | .policy = nl80211_policy, | |
5617c6cd | 12353 | .flags = GENL_UNS_ADMIN_PERM, |
e5497d76 | 12354 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
12355 | NL80211_FLAG_NEED_RTNL | |
12356 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 12357 | }, |
109086ce AN |
12358 | { |
12359 | .cmd = NL80211_CMD_TDLS_MGMT, | |
12360 | .doit = nl80211_tdls_mgmt, | |
12361 | .policy = nl80211_policy, | |
5617c6cd | 12362 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
12363 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12364 | NL80211_FLAG_NEED_RTNL, | |
12365 | }, | |
12366 | { | |
12367 | .cmd = NL80211_CMD_TDLS_OPER, | |
12368 | .doit = nl80211_tdls_oper, | |
12369 | .policy = nl80211_policy, | |
5617c6cd | 12370 | .flags = GENL_UNS_ADMIN_PERM, |
109086ce AN |
12371 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12372 | NL80211_FLAG_NEED_RTNL, | |
12373 | }, | |
28946da7 JB |
12374 | { |
12375 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
12376 | .doit = nl80211_register_unexpected_frame, | |
12377 | .policy = nl80211_policy, | |
5617c6cd | 12378 | .flags = GENL_UNS_ADMIN_PERM, |
28946da7 JB |
12379 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12380 | NL80211_FLAG_NEED_RTNL, | |
12381 | }, | |
7f6cf311 JB |
12382 | { |
12383 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
12384 | .doit = nl80211_probe_client, | |
12385 | .policy = nl80211_policy, | |
5617c6cd | 12386 | .flags = GENL_UNS_ADMIN_PERM, |
2b5f8b0b | 12387 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
12388 | NL80211_FLAG_NEED_RTNL, |
12389 | }, | |
5e760230 JB |
12390 | { |
12391 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
12392 | .doit = nl80211_register_beacons, | |
12393 | .policy = nl80211_policy, | |
5617c6cd | 12394 | .flags = GENL_UNS_ADMIN_PERM, |
5e760230 JB |
12395 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12396 | NL80211_FLAG_NEED_RTNL, | |
12397 | }, | |
1d9d9213 SW |
12398 | { |
12399 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
12400 | .doit = nl80211_set_noack_map, | |
12401 | .policy = nl80211_policy, | |
5617c6cd | 12402 | .flags = GENL_UNS_ADMIN_PERM, |
1d9d9213 SW |
12403 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12404 | NL80211_FLAG_NEED_RTNL, | |
12405 | }, | |
98104fde JB |
12406 | { |
12407 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
12408 | .doit = nl80211_start_p2p_device, | |
12409 | .policy = nl80211_policy, | |
5617c6cd | 12410 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
12411 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
12412 | NL80211_FLAG_NEED_RTNL, | |
12413 | }, | |
12414 | { | |
12415 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
12416 | .doit = nl80211_stop_p2p_device, | |
12417 | .policy = nl80211_policy, | |
5617c6cd | 12418 | .flags = GENL_UNS_ADMIN_PERM, |
98104fde JB |
12419 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
12420 | NL80211_FLAG_NEED_RTNL, | |
cb3b7d87 AB |
12421 | }, |
12422 | { | |
12423 | .cmd = NL80211_CMD_START_NAN, | |
12424 | .doit = nl80211_start_nan, | |
12425 | .policy = nl80211_policy, | |
12426 | .flags = GENL_ADMIN_PERM, | |
12427 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
12428 | NL80211_FLAG_NEED_RTNL, | |
12429 | }, | |
12430 | { | |
12431 | .cmd = NL80211_CMD_STOP_NAN, | |
12432 | .doit = nl80211_stop_nan, | |
12433 | .policy = nl80211_policy, | |
12434 | .flags = GENL_ADMIN_PERM, | |
12435 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
12436 | NL80211_FLAG_NEED_RTNL, | |
a442b761 AB |
12437 | }, |
12438 | { | |
12439 | .cmd = NL80211_CMD_ADD_NAN_FUNCTION, | |
12440 | .doit = nl80211_nan_add_func, | |
12441 | .policy = nl80211_policy, | |
12442 | .flags = GENL_ADMIN_PERM, | |
12443 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
12444 | NL80211_FLAG_NEED_RTNL, | |
12445 | }, | |
12446 | { | |
12447 | .cmd = NL80211_CMD_DEL_NAN_FUNCTION, | |
12448 | .doit = nl80211_nan_del_func, | |
12449 | .policy = nl80211_policy, | |
12450 | .flags = GENL_ADMIN_PERM, | |
12451 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
12452 | NL80211_FLAG_NEED_RTNL, | |
a5a9dcf2 AB |
12453 | }, |
12454 | { | |
12455 | .cmd = NL80211_CMD_CHANGE_NAN_CONFIG, | |
12456 | .doit = nl80211_nan_change_config, | |
12457 | .policy = nl80211_policy, | |
12458 | .flags = GENL_ADMIN_PERM, | |
12459 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
12460 | NL80211_FLAG_NEED_RTNL, | |
98104fde | 12461 | }, |
f4e583c8 AQ |
12462 | { |
12463 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
12464 | .doit = nl80211_set_mcast_rate, | |
77765eaf | 12465 | .policy = nl80211_policy, |
5617c6cd | 12466 | .flags = GENL_UNS_ADMIN_PERM, |
77765eaf VT |
12467 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12468 | NL80211_FLAG_NEED_RTNL, | |
12469 | }, | |
12470 | { | |
12471 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
12472 | .doit = nl80211_set_mac_acl, | |
f4e583c8 | 12473 | .policy = nl80211_policy, |
5617c6cd | 12474 | .flags = GENL_UNS_ADMIN_PERM, |
f4e583c8 AQ |
12475 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
12476 | NL80211_FLAG_NEED_RTNL, | |
12477 | }, | |
04f39047 SW |
12478 | { |
12479 | .cmd = NL80211_CMD_RADAR_DETECT, | |
12480 | .doit = nl80211_start_radar_detection, | |
12481 | .policy = nl80211_policy, | |
5617c6cd | 12482 | .flags = GENL_UNS_ADMIN_PERM, |
04f39047 SW |
12483 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12484 | NL80211_FLAG_NEED_RTNL, | |
12485 | }, | |
3713b4e3 JB |
12486 | { |
12487 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
12488 | .doit = nl80211_get_protocol_features, | |
12489 | .policy = nl80211_policy, | |
12490 | }, | |
355199e0 JM |
12491 | { |
12492 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
12493 | .doit = nl80211_update_ft_ies, | |
12494 | .policy = nl80211_policy, | |
5617c6cd | 12495 | .flags = GENL_UNS_ADMIN_PERM, |
355199e0 JM |
12496 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12497 | NL80211_FLAG_NEED_RTNL, | |
12498 | }, | |
5de17984 AS |
12499 | { |
12500 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
12501 | .doit = nl80211_crit_protocol_start, | |
12502 | .policy = nl80211_policy, | |
5617c6cd | 12503 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
12504 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
12505 | NL80211_FLAG_NEED_RTNL, | |
12506 | }, | |
12507 | { | |
12508 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
12509 | .doit = nl80211_crit_protocol_stop, | |
12510 | .policy = nl80211_policy, | |
5617c6cd | 12511 | .flags = GENL_UNS_ADMIN_PERM, |
5de17984 AS |
12512 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
12513 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
12514 | }, |
12515 | { | |
12516 | .cmd = NL80211_CMD_GET_COALESCE, | |
12517 | .doit = nl80211_get_coalesce, | |
12518 | .policy = nl80211_policy, | |
12519 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
12520 | NL80211_FLAG_NEED_RTNL, | |
12521 | }, | |
12522 | { | |
12523 | .cmd = NL80211_CMD_SET_COALESCE, | |
12524 | .doit = nl80211_set_coalesce, | |
12525 | .policy = nl80211_policy, | |
5617c6cd | 12526 | .flags = GENL_UNS_ADMIN_PERM, |
be29b99a AK |
12527 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12528 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
12529 | }, |
12530 | { | |
12531 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
12532 | .doit = nl80211_channel_switch, | |
12533 | .policy = nl80211_policy, | |
5617c6cd | 12534 | .flags = GENL_UNS_ADMIN_PERM, |
16ef1fe2 SW |
12535 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12536 | NL80211_FLAG_NEED_RTNL, | |
12537 | }, | |
ad7e718c JB |
12538 | { |
12539 | .cmd = NL80211_CMD_VENDOR, | |
12540 | .doit = nl80211_vendor_cmd, | |
7bdbe400 | 12541 | .dumpit = nl80211_vendor_cmd_dump, |
ad7e718c | 12542 | .policy = nl80211_policy, |
5617c6cd | 12543 | .flags = GENL_UNS_ADMIN_PERM, |
ad7e718c JB |
12544 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
12545 | NL80211_FLAG_NEED_RTNL, | |
12546 | }, | |
fa9ffc74 KP |
12547 | { |
12548 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
12549 | .doit = nl80211_set_qos_map, | |
12550 | .policy = nl80211_policy, | |
5617c6cd | 12551 | .flags = GENL_UNS_ADMIN_PERM, |
fa9ffc74 KP |
12552 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12553 | NL80211_FLAG_NEED_RTNL, | |
12554 | }, | |
960d01ac JB |
12555 | { |
12556 | .cmd = NL80211_CMD_ADD_TX_TS, | |
12557 | .doit = nl80211_add_tx_ts, | |
12558 | .policy = nl80211_policy, | |
5617c6cd | 12559 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
12560 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12561 | NL80211_FLAG_NEED_RTNL, | |
12562 | }, | |
12563 | { | |
12564 | .cmd = NL80211_CMD_DEL_TX_TS, | |
12565 | .doit = nl80211_del_tx_ts, | |
12566 | .policy = nl80211_policy, | |
5617c6cd | 12567 | .flags = GENL_UNS_ADMIN_PERM, |
960d01ac JB |
12568 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12569 | NL80211_FLAG_NEED_RTNL, | |
12570 | }, | |
1057d35e AN |
12571 | { |
12572 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
12573 | .doit = nl80211_tdls_channel_switch, | |
12574 | .policy = nl80211_policy, | |
5617c6cd | 12575 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
12576 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12577 | NL80211_FLAG_NEED_RTNL, | |
12578 | }, | |
12579 | { | |
12580 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
12581 | .doit = nl80211_tdls_cancel_channel_switch, | |
12582 | .policy = nl80211_policy, | |
5617c6cd | 12583 | .flags = GENL_UNS_ADMIN_PERM, |
1057d35e AN |
12584 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
12585 | NL80211_FLAG_NEED_RTNL, | |
12586 | }, | |
55682965 | 12587 | }; |
9588bbd5 | 12588 | |
56989f6d | 12589 | static struct genl_family nl80211_fam __ro_after_init = { |
489111e5 JB |
12590 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ |
12591 | .hdrsize = 0, /* no private header */ | |
12592 | .version = 1, /* no particular meaning now */ | |
12593 | .maxattr = NL80211_ATTR_MAX, | |
12594 | .netnsok = true, | |
12595 | .pre_doit = nl80211_pre_doit, | |
12596 | .post_doit = nl80211_post_doit, | |
12597 | .module = THIS_MODULE, | |
12598 | .ops = nl80211_ops, | |
12599 | .n_ops = ARRAY_SIZE(nl80211_ops), | |
12600 | .mcgrps = nl80211_mcgrps, | |
12601 | .n_mcgrps = ARRAY_SIZE(nl80211_mcgrps), | |
12602 | }; | |
12603 | ||
55682965 JB |
12604 | /* notification functions */ |
12605 | ||
3bb20556 JB |
12606 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
12607 | enum nl80211_commands cmd) | |
55682965 JB |
12608 | { |
12609 | struct sk_buff *msg; | |
86e8cf98 | 12610 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 12611 | |
3bb20556 JB |
12612 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
12613 | cmd != NL80211_CMD_DEL_WIPHY); | |
12614 | ||
fd2120ca | 12615 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
12616 | if (!msg) |
12617 | return; | |
12618 | ||
3bb20556 | 12619 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
12620 | nlmsg_free(msg); |
12621 | return; | |
12622 | } | |
12623 | ||
68eb5503 | 12624 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12625 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
12626 | } |
12627 | ||
896ff063 DK |
12628 | void nl80211_notify_iface(struct cfg80211_registered_device *rdev, |
12629 | struct wireless_dev *wdev, | |
12630 | enum nl80211_commands cmd) | |
12631 | { | |
12632 | struct sk_buff *msg; | |
12633 | ||
12634 | WARN_ON(cmd != NL80211_CMD_NEW_INTERFACE && | |
12635 | cmd != NL80211_CMD_DEL_INTERFACE); | |
12636 | ||
12637 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12638 | if (!msg) | |
12639 | return; | |
12640 | ||
12641 | if (nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, | |
12642 | cmd == NL80211_CMD_DEL_INTERFACE) < 0) { | |
12643 | nlmsg_free(msg); | |
12644 | return; | |
12645 | } | |
12646 | ||
12647 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, | |
12648 | NL80211_MCGRP_CONFIG, GFP_KERNEL); | |
12649 | } | |
12650 | ||
362a415d JB |
12651 | static int nl80211_add_scan_req(struct sk_buff *msg, |
12652 | struct cfg80211_registered_device *rdev) | |
12653 | { | |
12654 | struct cfg80211_scan_request *req = rdev->scan_req; | |
12655 | struct nlattr *nest; | |
12656 | int i; | |
12657 | ||
12658 | if (WARN_ON(!req)) | |
12659 | return 0; | |
12660 | ||
12661 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
12662 | if (!nest) | |
12663 | goto nla_put_failure; | |
9360ffd1 DM |
12664 | for (i = 0; i < req->n_ssids; i++) { |
12665 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
12666 | goto nla_put_failure; | |
12667 | } | |
362a415d JB |
12668 | nla_nest_end(msg, nest); |
12669 | ||
12670 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12671 | if (!nest) | |
12672 | goto nla_put_failure; | |
9360ffd1 DM |
12673 | for (i = 0; i < req->n_channels; i++) { |
12674 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
12675 | goto nla_put_failure; | |
12676 | } | |
362a415d JB |
12677 | nla_nest_end(msg, nest); |
12678 | ||
9360ffd1 DM |
12679 | if (req->ie && |
12680 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
12681 | goto nla_put_failure; | |
362a415d | 12682 | |
ae917c9f JB |
12683 | if (req->flags && |
12684 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
12685 | goto nla_put_failure; | |
ed473771 | 12686 | |
1d76250b AS |
12687 | if (req->info.scan_start_tsf && |
12688 | (nla_put_u64_64bit(msg, NL80211_ATTR_SCAN_START_TIME_TSF, | |
12689 | req->info.scan_start_tsf, NL80211_BSS_PAD) || | |
12690 | nla_put(msg, NL80211_ATTR_SCAN_START_TIME_TSF_BSSID, ETH_ALEN, | |
12691 | req->info.tsf_bssid))) | |
12692 | goto nla_put_failure; | |
12693 | ||
362a415d JB |
12694 | return 0; |
12695 | nla_put_failure: | |
12696 | return -ENOBUFS; | |
12697 | } | |
12698 | ||
a538e2d5 JB |
12699 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
12700 | struct cfg80211_registered_device *rdev, | |
fd014284 | 12701 | struct wireless_dev *wdev, |
15e47304 | 12702 | u32 portid, u32 seq, int flags, |
a538e2d5 | 12703 | u32 cmd) |
2a519311 JB |
12704 | { |
12705 | void *hdr; | |
12706 | ||
15e47304 | 12707 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
12708 | if (!hdr) |
12709 | return -1; | |
12710 | ||
9360ffd1 | 12711 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
12712 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12713 | wdev->netdev->ifindex)) || | |
2dad624e ND |
12714 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
12715 | NL80211_ATTR_PAD)) | |
9360ffd1 | 12716 | goto nla_put_failure; |
2a519311 | 12717 | |
362a415d JB |
12718 | /* ignore errors and send incomplete event anyway */ |
12719 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 12720 | |
053c095a JB |
12721 | genlmsg_end(msg, hdr); |
12722 | return 0; | |
2a519311 JB |
12723 | |
12724 | nla_put_failure: | |
12725 | genlmsg_cancel(msg, hdr); | |
12726 | return -EMSGSIZE; | |
12727 | } | |
12728 | ||
807f8a8c LC |
12729 | static int |
12730 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
12731 | struct cfg80211_registered_device *rdev, | |
12732 | struct net_device *netdev, | |
15e47304 | 12733 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
12734 | { |
12735 | void *hdr; | |
12736 | ||
15e47304 | 12737 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
12738 | if (!hdr) |
12739 | return -1; | |
12740 | ||
9360ffd1 DM |
12741 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12742 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12743 | goto nla_put_failure; | |
807f8a8c | 12744 | |
053c095a JB |
12745 | genlmsg_end(msg, hdr); |
12746 | return 0; | |
807f8a8c LC |
12747 | |
12748 | nla_put_failure: | |
12749 | genlmsg_cancel(msg, hdr); | |
12750 | return -EMSGSIZE; | |
12751 | } | |
12752 | ||
a538e2d5 | 12753 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 12754 | struct wireless_dev *wdev) |
a538e2d5 JB |
12755 | { |
12756 | struct sk_buff *msg; | |
12757 | ||
58050fce | 12758 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
12759 | if (!msg) |
12760 | return; | |
12761 | ||
fd014284 | 12762 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
12763 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
12764 | nlmsg_free(msg); | |
12765 | return; | |
12766 | } | |
12767 | ||
68eb5503 | 12768 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12769 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
12770 | } |
12771 | ||
f9d15d16 JB |
12772 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
12773 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
12774 | { |
12775 | struct sk_buff *msg; | |
12776 | ||
fd2120ca | 12777 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 12778 | if (!msg) |
f9d15d16 | 12779 | return NULL; |
2a519311 | 12780 | |
fd014284 | 12781 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
12782 | aborted ? NL80211_CMD_SCAN_ABORTED : |
12783 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 12784 | nlmsg_free(msg); |
f9d15d16 | 12785 | return NULL; |
2a519311 JB |
12786 | } |
12787 | ||
f9d15d16 | 12788 | return msg; |
2a519311 JB |
12789 | } |
12790 | ||
f9d15d16 JB |
12791 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
12792 | struct sk_buff *msg) | |
2a519311 | 12793 | { |
2a519311 JB |
12794 | if (!msg) |
12795 | return; | |
12796 | ||
68eb5503 | 12797 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12798 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
12799 | } |
12800 | ||
807f8a8c LC |
12801 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
12802 | struct net_device *netdev) | |
12803 | { | |
12804 | struct sk_buff *msg; | |
12805 | ||
12806 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12807 | if (!msg) | |
12808 | return; | |
12809 | ||
12810 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
12811 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
12812 | nlmsg_free(msg); | |
12813 | return; | |
12814 | } | |
12815 | ||
68eb5503 | 12816 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12817 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
12818 | } |
12819 | ||
12820 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
12821 | struct net_device *netdev, u32 cmd) | |
12822 | { | |
12823 | struct sk_buff *msg; | |
12824 | ||
58050fce | 12825 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
12826 | if (!msg) |
12827 | return; | |
12828 | ||
12829 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
12830 | nlmsg_free(msg); | |
12831 | return; | |
12832 | } | |
12833 | ||
68eb5503 | 12834 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12835 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
12836 | } |
12837 | ||
b0d7aa59 JD |
12838 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
12839 | struct regulatory_request *request) | |
73d54c9e | 12840 | { |
73d54c9e | 12841 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
12842 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
12843 | goto nla_put_failure; | |
12844 | ||
12845 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
12846 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12847 | NL80211_REGDOM_TYPE_WORLD)) | |
12848 | goto nla_put_failure; | |
12849 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
12850 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12851 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
12852 | goto nla_put_failure; | |
12853 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
12854 | request->intersect) { | |
12855 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12856 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
12857 | goto nla_put_failure; | |
12858 | } else { | |
12859 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
12860 | NL80211_REGDOM_TYPE_COUNTRY) || | |
12861 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
12862 | request->alpha2)) | |
12863 | goto nla_put_failure; | |
12864 | } | |
12865 | ||
ad30ca2c AN |
12866 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
12867 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
12868 | ||
12869 | if (wiphy && | |
12870 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
12871 | goto nla_put_failure; | |
1bdd716c AN |
12872 | |
12873 | if (wiphy && | |
12874 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
12875 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
12876 | goto nla_put_failure; | |
ad30ca2c | 12877 | } |
73d54c9e | 12878 | |
b0d7aa59 JD |
12879 | return true; |
12880 | ||
12881 | nla_put_failure: | |
12882 | return false; | |
12883 | } | |
12884 | ||
12885 | /* | |
12886 | * This can happen on global regulatory changes or device specific settings | |
12887 | * based on custom regulatory domains. | |
12888 | */ | |
12889 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
12890 | struct regulatory_request *request) | |
12891 | { | |
12892 | struct sk_buff *msg; | |
12893 | void *hdr; | |
12894 | ||
12895 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12896 | if (!msg) | |
12897 | return; | |
12898 | ||
12899 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
12900 | if (!hdr) { | |
12901 | nlmsg_free(msg); | |
12902 | return; | |
12903 | } | |
12904 | ||
12905 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
12906 | goto nla_put_failure; | |
12907 | ||
3b7b72ee | 12908 | genlmsg_end(msg, hdr); |
73d54c9e | 12909 | |
bc43b28c | 12910 | rcu_read_lock(); |
68eb5503 | 12911 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 12912 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 12913 | rcu_read_unlock(); |
73d54c9e LR |
12914 | |
12915 | return; | |
12916 | ||
12917 | nla_put_failure: | |
12918 | genlmsg_cancel(msg, hdr); | |
12919 | nlmsg_free(msg); | |
12920 | } | |
12921 | ||
6039f6d2 JM |
12922 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
12923 | struct net_device *netdev, | |
12924 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
12925 | enum nl80211_commands cmd, gfp_t gfp, |
12926 | int uapsd_queues) | |
6039f6d2 JM |
12927 | { |
12928 | struct sk_buff *msg; | |
12929 | void *hdr; | |
12930 | ||
e6d6e342 | 12931 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
12932 | if (!msg) |
12933 | return; | |
12934 | ||
12935 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
12936 | if (!hdr) { | |
12937 | nlmsg_free(msg); | |
12938 | return; | |
12939 | } | |
12940 | ||
9360ffd1 DM |
12941 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12942 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12943 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
12944 | goto nla_put_failure; | |
6039f6d2 | 12945 | |
b0b6aa2c EP |
12946 | if (uapsd_queues >= 0) { |
12947 | struct nlattr *nla_wmm = | |
12948 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
12949 | if (!nla_wmm) | |
12950 | goto nla_put_failure; | |
12951 | ||
12952 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
12953 | uapsd_queues)) | |
12954 | goto nla_put_failure; | |
12955 | ||
12956 | nla_nest_end(msg, nla_wmm); | |
12957 | } | |
12958 | ||
3b7b72ee | 12959 | genlmsg_end(msg, hdr); |
6039f6d2 | 12960 | |
68eb5503 | 12961 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12962 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
12963 | return; |
12964 | ||
12965 | nla_put_failure: | |
12966 | genlmsg_cancel(msg, hdr); | |
12967 | nlmsg_free(msg); | |
12968 | } | |
12969 | ||
12970 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
12971 | struct net_device *netdev, const u8 *buf, |
12972 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
12973 | { |
12974 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12975 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
12976 | } |
12977 | ||
12978 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
12979 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 12980 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 12981 | { |
e6d6e342 | 12982 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 12983 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
12984 | } |
12985 | ||
53b46b84 | 12986 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
12987 | struct net_device *netdev, const u8 *buf, |
12988 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
12989 | { |
12990 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12991 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
12992 | } |
12993 | ||
53b46b84 JM |
12994 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
12995 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 12996 | size_t len, gfp_t gfp) |
6039f6d2 JM |
12997 | { |
12998 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 12999 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
13000 | } |
13001 | ||
6ff57cf8 JB |
13002 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
13003 | size_t len) | |
cf4e594e | 13004 | { |
947add36 JB |
13005 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13006 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13007 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
13008 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
13009 | u32 cmd; | |
947add36 | 13010 | |
6ff57cf8 JB |
13011 | if (WARN_ON(len < 2)) |
13012 | return; | |
cf4e594e | 13013 | |
6ff57cf8 JB |
13014 | if (ieee80211_is_deauth(mgmt->frame_control)) |
13015 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
13016 | else | |
13017 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 13018 | |
6ff57cf8 | 13019 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 13020 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 13021 | } |
6ff57cf8 | 13022 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 13023 | |
1b06bb40 LR |
13024 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
13025 | struct net_device *netdev, int cmd, | |
e6d6e342 | 13026 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
13027 | { |
13028 | struct sk_buff *msg; | |
13029 | void *hdr; | |
13030 | ||
e6d6e342 | 13031 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
13032 | if (!msg) |
13033 | return; | |
13034 | ||
13035 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
13036 | if (!hdr) { | |
13037 | nlmsg_free(msg); | |
13038 | return; | |
13039 | } | |
13040 | ||
9360ffd1 DM |
13041 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13042 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13043 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
13044 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
13045 | goto nla_put_failure; | |
1965c853 | 13046 | |
3b7b72ee | 13047 | genlmsg_end(msg, hdr); |
1965c853 | 13048 | |
68eb5503 | 13049 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13050 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
13051 | return; |
13052 | ||
13053 | nla_put_failure: | |
13054 | genlmsg_cancel(msg, hdr); | |
13055 | nlmsg_free(msg); | |
13056 | } | |
13057 | ||
13058 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
13059 | struct net_device *netdev, const u8 *addr, |
13060 | gfp_t gfp) | |
1965c853 JM |
13061 | { |
13062 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 13063 | addr, gfp); |
1965c853 JM |
13064 | } |
13065 | ||
13066 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
13067 | struct net_device *netdev, const u8 *addr, |
13068 | gfp_t gfp) | |
1965c853 | 13069 | { |
e6d6e342 JB |
13070 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
13071 | addr, gfp); | |
1965c853 JM |
13072 | } |
13073 | ||
b23aa676 SO |
13074 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
13075 | struct net_device *netdev, const u8 *bssid, | |
13076 | const u8 *req_ie, size_t req_ie_len, | |
13077 | const u8 *resp_ie, size_t resp_ie_len, | |
bf1ecd21 | 13078 | int status, gfp_t gfp) |
b23aa676 SO |
13079 | { |
13080 | struct sk_buff *msg; | |
13081 | void *hdr; | |
13082 | ||
58050fce | 13083 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
13084 | if (!msg) |
13085 | return; | |
13086 | ||
13087 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
13088 | if (!hdr) { | |
13089 | nlmsg_free(msg); | |
13090 | return; | |
13091 | } | |
13092 | ||
9360ffd1 DM |
13093 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13094 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13095 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
bf1ecd21 JM |
13096 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, |
13097 | status < 0 ? WLAN_STATUS_UNSPECIFIED_FAILURE : | |
13098 | status) || | |
13099 | (status < 0 && nla_put_flag(msg, NL80211_ATTR_TIMED_OUT)) || | |
9360ffd1 DM |
13100 | (req_ie && |
13101 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
13102 | (resp_ie && | |
13103 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
13104 | goto nla_put_failure; | |
b23aa676 | 13105 | |
3b7b72ee | 13106 | genlmsg_end(msg, hdr); |
b23aa676 | 13107 | |
68eb5503 | 13108 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13109 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
13110 | return; |
13111 | ||
13112 | nla_put_failure: | |
13113 | genlmsg_cancel(msg, hdr); | |
13114 | nlmsg_free(msg); | |
b23aa676 SO |
13115 | } |
13116 | ||
13117 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
13118 | struct net_device *netdev, const u8 *bssid, | |
13119 | const u8 *req_ie, size_t req_ie_len, | |
13120 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
13121 | { | |
13122 | struct sk_buff *msg; | |
13123 | void *hdr; | |
13124 | ||
58050fce | 13125 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
13126 | if (!msg) |
13127 | return; | |
13128 | ||
13129 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
13130 | if (!hdr) { | |
13131 | nlmsg_free(msg); | |
13132 | return; | |
13133 | } | |
13134 | ||
9360ffd1 DM |
13135 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13136 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13137 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
13138 | (req_ie && | |
13139 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
13140 | (resp_ie && | |
13141 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
13142 | goto nla_put_failure; | |
b23aa676 | 13143 | |
3b7b72ee | 13144 | genlmsg_end(msg, hdr); |
b23aa676 | 13145 | |
68eb5503 | 13146 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13147 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
13148 | return; |
13149 | ||
13150 | nla_put_failure: | |
13151 | genlmsg_cancel(msg, hdr); | |
13152 | nlmsg_free(msg); | |
b23aa676 SO |
13153 | } |
13154 | ||
13155 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
13156 | struct net_device *netdev, u16 reason, | |
667503dd | 13157 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
13158 | { |
13159 | struct sk_buff *msg; | |
13160 | void *hdr; | |
13161 | ||
58050fce | 13162 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
13163 | if (!msg) |
13164 | return; | |
13165 | ||
13166 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
13167 | if (!hdr) { | |
13168 | nlmsg_free(msg); | |
13169 | return; | |
13170 | } | |
13171 | ||
9360ffd1 DM |
13172 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13173 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13174 | (from_ap && reason && | |
13175 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
13176 | (from_ap && | |
13177 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
13178 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
13179 | goto nla_put_failure; | |
b23aa676 | 13180 | |
3b7b72ee | 13181 | genlmsg_end(msg, hdr); |
b23aa676 | 13182 | |
68eb5503 | 13183 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13184 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
13185 | return; |
13186 | ||
13187 | nla_put_failure: | |
13188 | genlmsg_cancel(msg, hdr); | |
13189 | nlmsg_free(msg); | |
b23aa676 SO |
13190 | } |
13191 | ||
04a773ad JB |
13192 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
13193 | struct net_device *netdev, const u8 *bssid, | |
13194 | gfp_t gfp) | |
13195 | { | |
13196 | struct sk_buff *msg; | |
13197 | void *hdr; | |
13198 | ||
fd2120ca | 13199 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
13200 | if (!msg) |
13201 | return; | |
13202 | ||
13203 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
13204 | if (!hdr) { | |
13205 | nlmsg_free(msg); | |
13206 | return; | |
13207 | } | |
13208 | ||
9360ffd1 DM |
13209 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13210 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13211 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
13212 | goto nla_put_failure; | |
04a773ad | 13213 | |
3b7b72ee | 13214 | genlmsg_end(msg, hdr); |
04a773ad | 13215 | |
68eb5503 | 13216 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13217 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
13218 | return; |
13219 | ||
13220 | nla_put_failure: | |
13221 | genlmsg_cancel(msg, hdr); | |
13222 | nlmsg_free(msg); | |
13223 | } | |
13224 | ||
947add36 JB |
13225 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
13226 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 13227 | { |
947add36 | 13228 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 13229 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
13230 | struct sk_buff *msg; |
13231 | void *hdr; | |
13232 | ||
947add36 JB |
13233 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
13234 | return; | |
13235 | ||
13236 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
13237 | ||
c93b5e71 JC |
13238 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
13239 | if (!msg) | |
13240 | return; | |
13241 | ||
13242 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
13243 | if (!hdr) { | |
13244 | nlmsg_free(msg); | |
13245 | return; | |
13246 | } | |
13247 | ||
9360ffd1 | 13248 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
13249 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
13250 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
13251 | (ie_len && ie && |
13252 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
13253 | goto nla_put_failure; | |
c93b5e71 | 13254 | |
3b7b72ee | 13255 | genlmsg_end(msg, hdr); |
c93b5e71 | 13256 | |
68eb5503 | 13257 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13258 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
13259 | return; |
13260 | ||
13261 | nla_put_failure: | |
13262 | genlmsg_cancel(msg, hdr); | |
13263 | nlmsg_free(msg); | |
13264 | } | |
947add36 | 13265 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 13266 | |
a3b8b056 JM |
13267 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
13268 | struct net_device *netdev, const u8 *addr, | |
13269 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 13270 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
13271 | { |
13272 | struct sk_buff *msg; | |
13273 | void *hdr; | |
13274 | ||
e6d6e342 | 13275 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
13276 | if (!msg) |
13277 | return; | |
13278 | ||
13279 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
13280 | if (!hdr) { | |
13281 | nlmsg_free(msg); | |
13282 | return; | |
13283 | } | |
13284 | ||
9360ffd1 DM |
13285 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13286 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13287 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
13288 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
13289 | (key_id != -1 && | |
13290 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
13291 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
13292 | goto nla_put_failure; | |
a3b8b056 | 13293 | |
3b7b72ee | 13294 | genlmsg_end(msg, hdr); |
a3b8b056 | 13295 | |
68eb5503 | 13296 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13297 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
13298 | return; |
13299 | ||
13300 | nla_put_failure: | |
13301 | genlmsg_cancel(msg, hdr); | |
13302 | nlmsg_free(msg); | |
13303 | } | |
13304 | ||
6bad8766 LR |
13305 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
13306 | struct ieee80211_channel *channel_before, | |
13307 | struct ieee80211_channel *channel_after) | |
13308 | { | |
13309 | struct sk_buff *msg; | |
13310 | void *hdr; | |
13311 | struct nlattr *nl_freq; | |
13312 | ||
fd2120ca | 13313 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
13314 | if (!msg) |
13315 | return; | |
13316 | ||
13317 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
13318 | if (!hdr) { | |
13319 | nlmsg_free(msg); | |
13320 | return; | |
13321 | } | |
13322 | ||
13323 | /* | |
13324 | * Since we are applying the beacon hint to a wiphy we know its | |
13325 | * wiphy_idx is valid | |
13326 | */ | |
9360ffd1 DM |
13327 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
13328 | goto nla_put_failure; | |
6bad8766 LR |
13329 | |
13330 | /* Before */ | |
13331 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
13332 | if (!nl_freq) | |
13333 | goto nla_put_failure; | |
cdc89b97 | 13334 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
13335 | goto nla_put_failure; |
13336 | nla_nest_end(msg, nl_freq); | |
13337 | ||
13338 | /* After */ | |
13339 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
13340 | if (!nl_freq) | |
13341 | goto nla_put_failure; | |
cdc89b97 | 13342 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
13343 | goto nla_put_failure; |
13344 | nla_nest_end(msg, nl_freq); | |
13345 | ||
3b7b72ee | 13346 | genlmsg_end(msg, hdr); |
6bad8766 | 13347 | |
463d0183 | 13348 | rcu_read_lock(); |
68eb5503 | 13349 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 13350 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 13351 | rcu_read_unlock(); |
6bad8766 LR |
13352 | |
13353 | return; | |
13354 | ||
13355 | nla_put_failure: | |
13356 | genlmsg_cancel(msg, hdr); | |
13357 | nlmsg_free(msg); | |
13358 | } | |
13359 | ||
9588bbd5 JM |
13360 | static void nl80211_send_remain_on_chan_event( |
13361 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 13362 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 13363 | struct ieee80211_channel *chan, |
9588bbd5 JM |
13364 | unsigned int duration, gfp_t gfp) |
13365 | { | |
13366 | struct sk_buff *msg; | |
13367 | void *hdr; | |
13368 | ||
13369 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13370 | if (!msg) | |
13371 | return; | |
13372 | ||
13373 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
13374 | if (!hdr) { | |
13375 | nlmsg_free(msg); | |
13376 | return; | |
13377 | } | |
13378 | ||
9360ffd1 | 13379 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
13380 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
13381 | wdev->netdev->ifindex)) || | |
2dad624e ND |
13382 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13383 | NL80211_ATTR_PAD) || | |
9360ffd1 | 13384 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
13385 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
13386 | NL80211_CHAN_NO_HT) || | |
2dad624e ND |
13387 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
13388 | NL80211_ATTR_PAD)) | |
9360ffd1 | 13389 | goto nla_put_failure; |
9588bbd5 | 13390 | |
9360ffd1 DM |
13391 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
13392 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
13393 | goto nla_put_failure; | |
9588bbd5 | 13394 | |
3b7b72ee | 13395 | genlmsg_end(msg, hdr); |
9588bbd5 | 13396 | |
68eb5503 | 13397 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13398 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
13399 | return; |
13400 | ||
13401 | nla_put_failure: | |
13402 | genlmsg_cancel(msg, hdr); | |
13403 | nlmsg_free(msg); | |
13404 | } | |
13405 | ||
947add36 JB |
13406 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
13407 | struct ieee80211_channel *chan, | |
13408 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 13409 | { |
947add36 | 13410 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 13411 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
13412 | |
13413 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 13414 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 13415 | rdev, wdev, cookie, chan, |
42d97a59 | 13416 | duration, gfp); |
9588bbd5 | 13417 | } |
947add36 | 13418 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 13419 | |
947add36 JB |
13420 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
13421 | struct ieee80211_channel *chan, | |
13422 | gfp_t gfp) | |
9588bbd5 | 13423 | { |
947add36 | 13424 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 13425 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
13426 | |
13427 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 13428 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 13429 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 13430 | } |
947add36 | 13431 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 13432 | |
947add36 JB |
13433 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
13434 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 13435 | { |
947add36 | 13436 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 13437 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
13438 | struct sk_buff *msg; |
13439 | ||
947add36 JB |
13440 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
13441 | ||
58050fce | 13442 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
13443 | if (!msg) |
13444 | return; | |
13445 | ||
cf5ead82 | 13446 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 13447 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
13448 | nlmsg_free(msg); |
13449 | return; | |
13450 | } | |
13451 | ||
68eb5503 | 13452 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13453 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 13454 | } |
947add36 | 13455 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 13456 | |
cf5ead82 JB |
13457 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
13458 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 13459 | { |
947add36 | 13460 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 13461 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 13462 | struct sk_buff *msg; |
cf5ead82 JB |
13463 | struct station_info empty_sinfo = {}; |
13464 | ||
13465 | if (!sinfo) | |
13466 | sinfo = &empty_sinfo; | |
ec15e68b | 13467 | |
947add36 JB |
13468 | trace_cfg80211_del_sta(dev, mac_addr); |
13469 | ||
58050fce | 13470 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
13471 | if (!msg) |
13472 | return; | |
13473 | ||
cf5ead82 | 13474 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 13475 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
13476 | nlmsg_free(msg); |
13477 | return; | |
13478 | } | |
13479 | ||
68eb5503 | 13480 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13481 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 13482 | } |
cf5ead82 | 13483 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 13484 | |
947add36 JB |
13485 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
13486 | enum nl80211_connect_failed_reason reason, | |
13487 | gfp_t gfp) | |
ed44a951 | 13488 | { |
947add36 | 13489 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 13490 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
13491 | struct sk_buff *msg; |
13492 | void *hdr; | |
13493 | ||
13494 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
13495 | if (!msg) | |
13496 | return; | |
13497 | ||
13498 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
13499 | if (!hdr) { | |
13500 | nlmsg_free(msg); | |
13501 | return; | |
13502 | } | |
13503 | ||
13504 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
13505 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
13506 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
13507 | goto nla_put_failure; | |
13508 | ||
13509 | genlmsg_end(msg, hdr); | |
13510 | ||
68eb5503 | 13511 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13512 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
13513 | return; |
13514 | ||
13515 | nla_put_failure: | |
13516 | genlmsg_cancel(msg, hdr); | |
13517 | nlmsg_free(msg); | |
13518 | } | |
947add36 | 13519 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 13520 | |
b92ab5d8 JB |
13521 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
13522 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
13523 | { |
13524 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 13525 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
13526 | struct sk_buff *msg; |
13527 | void *hdr; | |
15e47304 | 13528 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 13529 | |
15e47304 | 13530 | if (!nlportid) |
28946da7 JB |
13531 | return false; |
13532 | ||
13533 | msg = nlmsg_new(100, gfp); | |
13534 | if (!msg) | |
13535 | return true; | |
13536 | ||
b92ab5d8 | 13537 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
13538 | if (!hdr) { |
13539 | nlmsg_free(msg); | |
13540 | return true; | |
13541 | } | |
13542 | ||
9360ffd1 DM |
13543 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13544 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
13545 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
13546 | goto nla_put_failure; | |
28946da7 | 13547 | |
9c90a9f6 | 13548 | genlmsg_end(msg, hdr); |
15e47304 | 13549 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
13550 | return true; |
13551 | ||
13552 | nla_put_failure: | |
13553 | genlmsg_cancel(msg, hdr); | |
13554 | nlmsg_free(msg); | |
13555 | return true; | |
13556 | } | |
13557 | ||
947add36 JB |
13558 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
13559 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 13560 | { |
947add36 JB |
13561 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13562 | bool ret; | |
13563 | ||
13564 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
13565 | ||
13566 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
13567 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
13568 | trace_cfg80211_return_bool(false); | |
13569 | return false; | |
13570 | } | |
13571 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
13572 | addr, gfp); | |
13573 | trace_cfg80211_return_bool(ret); | |
13574 | return ret; | |
b92ab5d8 | 13575 | } |
947add36 | 13576 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 13577 | |
947add36 JB |
13578 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
13579 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 13580 | { |
947add36 JB |
13581 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13582 | bool ret; | |
13583 | ||
13584 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
13585 | ||
13586 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
13587 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
13588 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
13589 | trace_cfg80211_return_bool(false); | |
13590 | return false; | |
13591 | } | |
13592 | ret = __nl80211_unexpected_frame(dev, | |
13593 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
13594 | addr, gfp); | |
13595 | trace_cfg80211_return_bool(ret); | |
13596 | return ret; | |
b92ab5d8 | 13597 | } |
947add36 | 13598 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 13599 | |
2e161f78 | 13600 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 13601 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 13602 | int freq, int sig_dbm, |
19504cf5 | 13603 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 13604 | { |
71bbc994 | 13605 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
13606 | struct sk_buff *msg; |
13607 | void *hdr; | |
026331c4 JM |
13608 | |
13609 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13610 | if (!msg) | |
13611 | return -ENOMEM; | |
13612 | ||
2e161f78 | 13613 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
13614 | if (!hdr) { |
13615 | nlmsg_free(msg); | |
13616 | return -ENOMEM; | |
13617 | } | |
13618 | ||
9360ffd1 | 13619 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
13620 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
13621 | netdev->ifindex)) || | |
2dad624e ND |
13622 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13623 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
13624 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
13625 | (sig_dbm && | |
13626 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
13627 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
13628 | (flags && | |
13629 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 13630 | goto nla_put_failure; |
026331c4 | 13631 | |
3b7b72ee | 13632 | genlmsg_end(msg, hdr); |
026331c4 | 13633 | |
15e47304 | 13634 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
13635 | |
13636 | nla_put_failure: | |
13637 | genlmsg_cancel(msg, hdr); | |
13638 | nlmsg_free(msg); | |
13639 | return -ENOBUFS; | |
13640 | } | |
13641 | ||
947add36 JB |
13642 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
13643 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 13644 | { |
947add36 | 13645 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 13646 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 13647 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
13648 | struct sk_buff *msg; |
13649 | void *hdr; | |
13650 | ||
947add36 JB |
13651 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
13652 | ||
026331c4 JM |
13653 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
13654 | if (!msg) | |
13655 | return; | |
13656 | ||
2e161f78 | 13657 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
13658 | if (!hdr) { |
13659 | nlmsg_free(msg); | |
13660 | return; | |
13661 | } | |
13662 | ||
9360ffd1 | 13663 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
13664 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
13665 | netdev->ifindex)) || | |
2dad624e ND |
13666 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
13667 | NL80211_ATTR_PAD) || | |
9360ffd1 | 13668 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
2dad624e ND |
13669 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
13670 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
13671 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) |
13672 | goto nla_put_failure; | |
026331c4 | 13673 | |
3b7b72ee | 13674 | genlmsg_end(msg, hdr); |
026331c4 | 13675 | |
68eb5503 | 13676 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13677 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
13678 | return; |
13679 | ||
13680 | nla_put_failure: | |
13681 | genlmsg_cancel(msg, hdr); | |
13682 | nlmsg_free(msg); | |
13683 | } | |
947add36 | 13684 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 13685 | |
5b97f49d JB |
13686 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
13687 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 13688 | { |
947add36 | 13689 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
13690 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
13691 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
13692 | void **cb; | |
947add36 | 13693 | |
d6dc1a38 | 13694 | if (!msg) |
5b97f49d | 13695 | return NULL; |
d6dc1a38 | 13696 | |
5b97f49d JB |
13697 | cb = (void **)msg->cb; |
13698 | ||
13699 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
13700 | if (!cb[0]) { | |
d6dc1a38 | 13701 | nlmsg_free(msg); |
5b97f49d | 13702 | return NULL; |
d6dc1a38 JO |
13703 | } |
13704 | ||
9360ffd1 | 13705 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 13706 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 13707 | goto nla_put_failure; |
d6dc1a38 | 13708 | |
5b97f49d | 13709 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
13710 | goto nla_put_failure; |
13711 | ||
5b97f49d JB |
13712 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
13713 | if (!cb[1]) | |
9360ffd1 | 13714 | goto nla_put_failure; |
d6dc1a38 | 13715 | |
5b97f49d | 13716 | cb[2] = rdev; |
d6dc1a38 | 13717 | |
5b97f49d JB |
13718 | return msg; |
13719 | nla_put_failure: | |
13720 | nlmsg_free(msg); | |
13721 | return NULL; | |
13722 | } | |
13723 | ||
13724 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
13725 | { | |
13726 | void **cb = (void **)msg->cb; | |
13727 | struct cfg80211_registered_device *rdev = cb[2]; | |
13728 | ||
13729 | nla_nest_end(msg, cb[1]); | |
13730 | genlmsg_end(msg, cb[0]); | |
13731 | ||
13732 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 13733 | |
68eb5503 | 13734 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13735 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
13736 | } |
13737 | ||
13738 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
13739 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
13740 | gfp_t gfp) | |
13741 | { | |
13742 | struct sk_buff *msg; | |
13743 | ||
13744 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
13745 | ||
98f03342 JB |
13746 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
13747 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
13748 | return; | |
13749 | ||
5b97f49d JB |
13750 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
13751 | if (!msg) | |
13752 | return; | |
13753 | ||
13754 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
13755 | rssi_event)) | |
13756 | goto nla_put_failure; | |
13757 | ||
13758 | cfg80211_send_cqm(msg, gfp); | |
13759 | ||
d6dc1a38 JO |
13760 | return; |
13761 | ||
13762 | nla_put_failure: | |
d6dc1a38 JO |
13763 | nlmsg_free(msg); |
13764 | } | |
947add36 | 13765 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 13766 | |
5b97f49d JB |
13767 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
13768 | const u8 *peer, u32 num_packets, | |
13769 | u32 rate, u32 intvl, gfp_t gfp) | |
13770 | { | |
13771 | struct sk_buff *msg; | |
13772 | ||
13773 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
13774 | if (!msg) | |
13775 | return; | |
13776 | ||
13777 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
13778 | goto nla_put_failure; | |
13779 | ||
13780 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
13781 | goto nla_put_failure; | |
13782 | ||
13783 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
13784 | goto nla_put_failure; | |
13785 | ||
13786 | cfg80211_send_cqm(msg, gfp); | |
13787 | return; | |
13788 | ||
13789 | nla_put_failure: | |
13790 | nlmsg_free(msg); | |
13791 | } | |
13792 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
13793 | ||
13794 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
13795 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
13796 | { | |
13797 | struct sk_buff *msg; | |
13798 | ||
13799 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
13800 | ||
13801 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
13802 | if (!msg) | |
13803 | return; | |
13804 | ||
13805 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
13806 | goto nla_put_failure; | |
13807 | ||
13808 | cfg80211_send_cqm(msg, gfp); | |
13809 | return; | |
13810 | ||
13811 | nla_put_failure: | |
13812 | nlmsg_free(msg); | |
13813 | } | |
13814 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
13815 | ||
98f03342 JB |
13816 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
13817 | { | |
13818 | struct sk_buff *msg; | |
13819 | ||
13820 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
13821 | if (!msg) | |
13822 | return; | |
13823 | ||
13824 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
13825 | goto nla_put_failure; | |
13826 | ||
13827 | cfg80211_send_cqm(msg, gfp); | |
13828 | return; | |
13829 | ||
13830 | nla_put_failure: | |
13831 | nlmsg_free(msg); | |
13832 | } | |
13833 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
13834 | ||
947add36 JB |
13835 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
13836 | struct net_device *netdev, const u8 *bssid, | |
13837 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
13838 | { |
13839 | struct sk_buff *msg; | |
13840 | struct nlattr *rekey_attr; | |
13841 | void *hdr; | |
13842 | ||
58050fce | 13843 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
13844 | if (!msg) |
13845 | return; | |
13846 | ||
13847 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
13848 | if (!hdr) { | |
13849 | nlmsg_free(msg); | |
13850 | return; | |
13851 | } | |
13852 | ||
9360ffd1 DM |
13853 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13854 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
13855 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
13856 | goto nla_put_failure; | |
e5497d76 JB |
13857 | |
13858 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
13859 | if (!rekey_attr) | |
13860 | goto nla_put_failure; | |
13861 | ||
9360ffd1 DM |
13862 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
13863 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
13864 | goto nla_put_failure; | |
e5497d76 JB |
13865 | |
13866 | nla_nest_end(msg, rekey_attr); | |
13867 | ||
3b7b72ee | 13868 | genlmsg_end(msg, hdr); |
e5497d76 | 13869 | |
68eb5503 | 13870 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13871 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
13872 | return; |
13873 | ||
13874 | nla_put_failure: | |
13875 | genlmsg_cancel(msg, hdr); | |
13876 | nlmsg_free(msg); | |
13877 | } | |
13878 | ||
947add36 JB |
13879 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
13880 | const u8 *replay_ctr, gfp_t gfp) | |
13881 | { | |
13882 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13883 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13884 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
13885 | |
13886 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
13887 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
13888 | } | |
13889 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
13890 | ||
13891 | static void | |
13892 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
13893 | struct net_device *netdev, int index, | |
13894 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
13895 | { |
13896 | struct sk_buff *msg; | |
13897 | struct nlattr *attr; | |
13898 | void *hdr; | |
13899 | ||
58050fce | 13900 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
13901 | if (!msg) |
13902 | return; | |
13903 | ||
13904 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
13905 | if (!hdr) { | |
13906 | nlmsg_free(msg); | |
13907 | return; | |
13908 | } | |
13909 | ||
9360ffd1 DM |
13910 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
13911 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
13912 | goto nla_put_failure; | |
c9df56b4 JM |
13913 | |
13914 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
13915 | if (!attr) | |
13916 | goto nla_put_failure; | |
13917 | ||
9360ffd1 DM |
13918 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
13919 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
13920 | (preauth && | |
13921 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
13922 | goto nla_put_failure; | |
c9df56b4 JM |
13923 | |
13924 | nla_nest_end(msg, attr); | |
13925 | ||
3b7b72ee | 13926 | genlmsg_end(msg, hdr); |
c9df56b4 | 13927 | |
68eb5503 | 13928 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13929 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
13930 | return; |
13931 | ||
13932 | nla_put_failure: | |
13933 | genlmsg_cancel(msg, hdr); | |
13934 | nlmsg_free(msg); | |
13935 | } | |
13936 | ||
947add36 JB |
13937 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
13938 | const u8 *bssid, bool preauth, gfp_t gfp) | |
13939 | { | |
13940 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
13941 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13942 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
13943 | |
13944 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
13945 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
13946 | } | |
13947 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
13948 | ||
13949 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
13950 | struct net_device *netdev, | |
13951 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
13952 | gfp_t gfp, |
13953 | enum nl80211_commands notif, | |
13954 | u8 count) | |
5314526b TP |
13955 | { |
13956 | struct sk_buff *msg; | |
13957 | void *hdr; | |
13958 | ||
58050fce | 13959 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
13960 | if (!msg) |
13961 | return; | |
13962 | ||
f8d7552e | 13963 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
13964 | if (!hdr) { |
13965 | nlmsg_free(msg); | |
13966 | return; | |
13967 | } | |
13968 | ||
683b6d3b JB |
13969 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
13970 | goto nla_put_failure; | |
13971 | ||
13972 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 13973 | goto nla_put_failure; |
5314526b | 13974 | |
f8d7552e LC |
13975 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
13976 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
13977 | goto nla_put_failure; | |
13978 | ||
5314526b TP |
13979 | genlmsg_end(msg, hdr); |
13980 | ||
68eb5503 | 13981 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 13982 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
13983 | return; |
13984 | ||
13985 | nla_put_failure: | |
13986 | genlmsg_cancel(msg, hdr); | |
13987 | nlmsg_free(msg); | |
13988 | } | |
13989 | ||
947add36 JB |
13990 | void cfg80211_ch_switch_notify(struct net_device *dev, |
13991 | struct cfg80211_chan_def *chandef) | |
84f10708 | 13992 | { |
947add36 JB |
13993 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
13994 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 13995 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 13996 | |
e487eaeb | 13997 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 13998 | |
e487eaeb | 13999 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 14000 | |
9e0e2961 | 14001 | wdev->chandef = *chandef; |
96f55f12 | 14002 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
14003 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
14004 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
14005 | } |
14006 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
14007 | ||
f8d7552e LC |
14008 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
14009 | struct cfg80211_chan_def *chandef, | |
14010 | u8 count) | |
14011 | { | |
14012 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
14013 | struct wiphy *wiphy = wdev->wiphy; | |
14014 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
14015 | ||
14016 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
14017 | ||
14018 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
14019 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
14020 | } | |
14021 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
14022 | ||
04f39047 SW |
14023 | void |
14024 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 14025 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
14026 | enum nl80211_radar_event event, |
14027 | struct net_device *netdev, gfp_t gfp) | |
14028 | { | |
14029 | struct sk_buff *msg; | |
14030 | void *hdr; | |
14031 | ||
14032 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
14033 | if (!msg) | |
14034 | return; | |
14035 | ||
14036 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
14037 | if (!hdr) { | |
14038 | nlmsg_free(msg); | |
14039 | return; | |
14040 | } | |
14041 | ||
14042 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
14043 | goto nla_put_failure; | |
14044 | ||
14045 | /* NOP and radar events don't need a netdev parameter */ | |
14046 | if (netdev) { | |
14047 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
14048 | ||
14049 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
2dad624e ND |
14050 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14051 | NL80211_ATTR_PAD)) | |
04f39047 SW |
14052 | goto nla_put_failure; |
14053 | } | |
14054 | ||
14055 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
14056 | goto nla_put_failure; | |
14057 | ||
14058 | if (nl80211_send_chandef(msg, chandef)) | |
14059 | goto nla_put_failure; | |
14060 | ||
9c90a9f6 | 14061 | genlmsg_end(msg, hdr); |
04f39047 | 14062 | |
68eb5503 | 14063 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14064 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
14065 | return; |
14066 | ||
14067 | nla_put_failure: | |
14068 | genlmsg_cancel(msg, hdr); | |
14069 | nlmsg_free(msg); | |
14070 | } | |
14071 | ||
7f6cf311 JB |
14072 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
14073 | u64 cookie, bool acked, gfp_t gfp) | |
14074 | { | |
14075 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 14076 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
14077 | struct sk_buff *msg; |
14078 | void *hdr; | |
7f6cf311 | 14079 | |
4ee3e063 BL |
14080 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
14081 | ||
58050fce | 14082 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 14083 | |
7f6cf311 JB |
14084 | if (!msg) |
14085 | return; | |
14086 | ||
14087 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
14088 | if (!hdr) { | |
14089 | nlmsg_free(msg); | |
14090 | return; | |
14091 | } | |
14092 | ||
9360ffd1 DM |
14093 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14094 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
14095 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
2dad624e ND |
14096 | nla_put_u64_64bit(msg, NL80211_ATTR_COOKIE, cookie, |
14097 | NL80211_ATTR_PAD) || | |
9360ffd1 DM |
14098 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) |
14099 | goto nla_put_failure; | |
7f6cf311 | 14100 | |
9c90a9f6 | 14101 | genlmsg_end(msg, hdr); |
7f6cf311 | 14102 | |
68eb5503 | 14103 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14104 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
14105 | return; |
14106 | ||
14107 | nla_put_failure: | |
14108 | genlmsg_cancel(msg, hdr); | |
14109 | nlmsg_free(msg); | |
14110 | } | |
14111 | EXPORT_SYMBOL(cfg80211_probe_status); | |
14112 | ||
5e760230 JB |
14113 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
14114 | const u8 *frame, size_t len, | |
37c73b5f | 14115 | int freq, int sig_dbm) |
5e760230 | 14116 | { |
f26cbf40 | 14117 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
14118 | struct sk_buff *msg; |
14119 | void *hdr; | |
37c73b5f | 14120 | struct cfg80211_beacon_registration *reg; |
5e760230 | 14121 | |
4ee3e063 BL |
14122 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
14123 | ||
37c73b5f BG |
14124 | spin_lock_bh(&rdev->beacon_registrations_lock); |
14125 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
14126 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
14127 | if (!msg) { | |
14128 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
14129 | return; | |
14130 | } | |
5e760230 | 14131 | |
37c73b5f BG |
14132 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
14133 | if (!hdr) | |
14134 | goto nla_put_failure; | |
5e760230 | 14135 | |
37c73b5f BG |
14136 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14137 | (freq && | |
14138 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
14139 | (sig_dbm && | |
14140 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
14141 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
14142 | goto nla_put_failure; | |
5e760230 | 14143 | |
37c73b5f | 14144 | genlmsg_end(msg, hdr); |
5e760230 | 14145 | |
37c73b5f BG |
14146 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
14147 | } | |
14148 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
14149 | return; |
14150 | ||
14151 | nla_put_failure: | |
37c73b5f BG |
14152 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
14153 | if (hdr) | |
14154 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
14155 | nlmsg_free(msg); |
14156 | } | |
14157 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
14158 | ||
cd8f7cb4 | 14159 | #ifdef CONFIG_PM |
8cd4d456 LC |
14160 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
14161 | struct cfg80211_wowlan_wakeup *wakeup) | |
14162 | { | |
14163 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
14164 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
14165 | int i, j; | |
14166 | ||
14167 | nl_results = nla_nest_start( | |
14168 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
14169 | if (!nl_results) | |
14170 | return -EMSGSIZE; | |
14171 | ||
14172 | for (i = 0; i < nd->n_matches; i++) { | |
14173 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
14174 | ||
14175 | nl_match = nla_nest_start(msg, i); | |
14176 | if (!nl_match) | |
14177 | break; | |
14178 | ||
14179 | /* The SSID attribute is optional in nl80211, but for | |
14180 | * simplicity reasons it's always present in the | |
14181 | * cfg80211 structure. If a driver can't pass the | |
14182 | * SSID, that needs to be changed. A zero length SSID | |
14183 | * is still a valid SSID (wildcard), so it cannot be | |
14184 | * used for this purpose. | |
14185 | */ | |
14186 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
14187 | match->ssid.ssid)) { | |
14188 | nla_nest_cancel(msg, nl_match); | |
14189 | goto out; | |
14190 | } | |
14191 | ||
14192 | if (match->n_channels) { | |
14193 | nl_freqs = nla_nest_start( | |
14194 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
14195 | if (!nl_freqs) { | |
14196 | nla_nest_cancel(msg, nl_match); | |
14197 | goto out; | |
14198 | } | |
14199 | ||
14200 | for (j = 0; j < match->n_channels; j++) { | |
5528fae8 | 14201 | if (nla_put_u32(msg, j, match->channels[j])) { |
8cd4d456 LC |
14202 | nla_nest_cancel(msg, nl_freqs); |
14203 | nla_nest_cancel(msg, nl_match); | |
14204 | goto out; | |
14205 | } | |
14206 | } | |
14207 | ||
14208 | nla_nest_end(msg, nl_freqs); | |
14209 | } | |
14210 | ||
14211 | nla_nest_end(msg, nl_match); | |
14212 | } | |
14213 | ||
14214 | out: | |
14215 | nla_nest_end(msg, nl_results); | |
14216 | return 0; | |
14217 | } | |
14218 | ||
cd8f7cb4 JB |
14219 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
14220 | struct cfg80211_wowlan_wakeup *wakeup, | |
14221 | gfp_t gfp) | |
14222 | { | |
f26cbf40 | 14223 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
14224 | struct sk_buff *msg; |
14225 | void *hdr; | |
9c90a9f6 | 14226 | int size = 200; |
cd8f7cb4 JB |
14227 | |
14228 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
14229 | ||
14230 | if (wakeup) | |
14231 | size += wakeup->packet_present_len; | |
14232 | ||
14233 | msg = nlmsg_new(size, gfp); | |
14234 | if (!msg) | |
14235 | return; | |
14236 | ||
14237 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
14238 | if (!hdr) | |
14239 | goto free_msg; | |
14240 | ||
14241 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
14242 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14243 | NL80211_ATTR_PAD)) | |
cd8f7cb4 JB |
14244 | goto free_msg; |
14245 | ||
14246 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
14247 | wdev->netdev->ifindex)) | |
14248 | goto free_msg; | |
14249 | ||
14250 | if (wakeup) { | |
14251 | struct nlattr *reasons; | |
14252 | ||
14253 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
14254 | if (!reasons) |
14255 | goto free_msg; | |
cd8f7cb4 JB |
14256 | |
14257 | if (wakeup->disconnect && | |
14258 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
14259 | goto free_msg; | |
14260 | if (wakeup->magic_pkt && | |
14261 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
14262 | goto free_msg; | |
14263 | if (wakeup->gtk_rekey_failure && | |
14264 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
14265 | goto free_msg; | |
14266 | if (wakeup->eap_identity_req && | |
14267 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
14268 | goto free_msg; | |
14269 | if (wakeup->four_way_handshake && | |
14270 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
14271 | goto free_msg; | |
14272 | if (wakeup->rfkill_release && | |
14273 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
14274 | goto free_msg; | |
14275 | ||
14276 | if (wakeup->pattern_idx >= 0 && | |
14277 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
14278 | wakeup->pattern_idx)) | |
14279 | goto free_msg; | |
14280 | ||
ae917c9f JB |
14281 | if (wakeup->tcp_match && |
14282 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
14283 | goto free_msg; | |
2a0e047e | 14284 | |
ae917c9f JB |
14285 | if (wakeup->tcp_connlost && |
14286 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
14287 | goto free_msg; | |
2a0e047e | 14288 | |
ae917c9f JB |
14289 | if (wakeup->tcp_nomoretokens && |
14290 | nla_put_flag(msg, | |
14291 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
14292 | goto free_msg; | |
2a0e047e | 14293 | |
cd8f7cb4 JB |
14294 | if (wakeup->packet) { |
14295 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
14296 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
14297 | ||
14298 | if (!wakeup->packet_80211) { | |
14299 | pkt_attr = | |
14300 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
14301 | len_attr = | |
14302 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
14303 | } | |
14304 | ||
14305 | if (wakeup->packet_len && | |
14306 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
14307 | goto free_msg; | |
14308 | ||
14309 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
14310 | wakeup->packet)) | |
14311 | goto free_msg; | |
14312 | } | |
14313 | ||
8cd4d456 LC |
14314 | if (wakeup->net_detect && |
14315 | cfg80211_net_detect_results(msg, wakeup)) | |
14316 | goto free_msg; | |
14317 | ||
cd8f7cb4 JB |
14318 | nla_nest_end(msg, reasons); |
14319 | } | |
14320 | ||
9c90a9f6 | 14321 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 14322 | |
68eb5503 | 14323 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14324 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
14325 | return; |
14326 | ||
14327 | free_msg: | |
14328 | nlmsg_free(msg); | |
14329 | } | |
14330 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
14331 | #endif | |
14332 | ||
3475b094 JM |
14333 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
14334 | enum nl80211_tdls_operation oper, | |
14335 | u16 reason_code, gfp_t gfp) | |
14336 | { | |
14337 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 14338 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
14339 | struct sk_buff *msg; |
14340 | void *hdr; | |
3475b094 JM |
14341 | |
14342 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
14343 | reason_code); | |
14344 | ||
14345 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
14346 | if (!msg) | |
14347 | return; | |
14348 | ||
14349 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
14350 | if (!hdr) { | |
14351 | nlmsg_free(msg); | |
14352 | return; | |
14353 | } | |
14354 | ||
14355 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
14356 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
14357 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
14358 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
14359 | (reason_code > 0 && | |
14360 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
14361 | goto nla_put_failure; | |
14362 | ||
9c90a9f6 | 14363 | genlmsg_end(msg, hdr); |
3475b094 | 14364 | |
68eb5503 | 14365 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14366 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
14367 | return; |
14368 | ||
14369 | nla_put_failure: | |
14370 | genlmsg_cancel(msg, hdr); | |
14371 | nlmsg_free(msg); | |
14372 | } | |
14373 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
14374 | ||
026331c4 JM |
14375 | static int nl80211_netlink_notify(struct notifier_block * nb, |
14376 | unsigned long state, | |
14377 | void *_notify) | |
14378 | { | |
14379 | struct netlink_notify *notify = _notify; | |
14380 | struct cfg80211_registered_device *rdev; | |
14381 | struct wireless_dev *wdev; | |
37c73b5f | 14382 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 | 14383 | |
8f815cdd | 14384 | if (state != NETLINK_URELEASE || notify->protocol != NETLINK_GENERIC) |
026331c4 JM |
14385 | return NOTIFY_DONE; |
14386 | ||
14387 | rcu_read_lock(); | |
14388 | ||
5e760230 | 14389 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 14390 | bool schedule_destroy_work = false; |
93a1e86c JR |
14391 | bool schedule_scan_stop = false; |
14392 | struct cfg80211_sched_scan_request *sched_scan_req = | |
14393 | rcu_dereference(rdev->sched_scan_req); | |
14394 | ||
14395 | if (sched_scan_req && notify->portid && | |
14396 | sched_scan_req->owner_nlportid == notify->portid) | |
14397 | schedule_scan_stop = true; | |
78f22b6a | 14398 | |
53873f13 | 14399 | list_for_each_entry_rcu(wdev, &rdev->wiphy.wdev_list, list) { |
15e47304 | 14400 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 14401 | |
78f22b6a JB |
14402 | if (wdev->owner_nlportid == notify->portid) |
14403 | schedule_destroy_work = true; | |
14404 | } | |
14405 | ||
37c73b5f BG |
14406 | spin_lock_bh(&rdev->beacon_registrations_lock); |
14407 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
14408 | list) { | |
14409 | if (reg->nlportid == notify->portid) { | |
14410 | list_del(®->list); | |
14411 | kfree(reg); | |
14412 | break; | |
14413 | } | |
14414 | } | |
14415 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
14416 | |
14417 | if (schedule_destroy_work) { | |
14418 | struct cfg80211_iface_destroy *destroy; | |
14419 | ||
14420 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
14421 | if (destroy) { | |
14422 | destroy->nlportid = notify->portid; | |
14423 | spin_lock(&rdev->destroy_list_lock); | |
14424 | list_add(&destroy->list, &rdev->destroy_list); | |
14425 | spin_unlock(&rdev->destroy_list_lock); | |
14426 | schedule_work(&rdev->destroy_work); | |
14427 | } | |
93a1e86c JR |
14428 | } else if (schedule_scan_stop) { |
14429 | sched_scan_req->owner_nlportid = 0; | |
14430 | ||
14431 | if (rdev->ops->sched_scan_stop && | |
14432 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
14433 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 14434 | } |
5e760230 | 14435 | } |
026331c4 JM |
14436 | |
14437 | rcu_read_unlock(); | |
14438 | ||
05050753 I |
14439 | /* |
14440 | * It is possible that the user space process that is controlling the | |
14441 | * indoor setting disappeared, so notify the regulatory core. | |
14442 | */ | |
14443 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 14444 | return NOTIFY_OK; |
026331c4 JM |
14445 | } |
14446 | ||
14447 | static struct notifier_block nl80211_netlink_notifier = { | |
14448 | .notifier_call = nl80211_netlink_notify, | |
14449 | }; | |
14450 | ||
355199e0 JM |
14451 | void cfg80211_ft_event(struct net_device *netdev, |
14452 | struct cfg80211_ft_event_params *ft_event) | |
14453 | { | |
14454 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 14455 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
14456 | struct sk_buff *msg; |
14457 | void *hdr; | |
355199e0 JM |
14458 | |
14459 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
14460 | ||
14461 | if (!ft_event->target_ap) | |
14462 | return; | |
14463 | ||
14464 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
14465 | if (!msg) | |
14466 | return; | |
14467 | ||
14468 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
14469 | if (!hdr) |
14470 | goto out; | |
355199e0 | 14471 | |
ae917c9f JB |
14472 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
14473 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
14474 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
14475 | goto out; | |
355199e0 | 14476 | |
ae917c9f JB |
14477 | if (ft_event->ies && |
14478 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
14479 | goto out; | |
14480 | if (ft_event->ric_ies && | |
14481 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
14482 | ft_event->ric_ies)) | |
14483 | goto out; | |
355199e0 | 14484 | |
9c90a9f6 | 14485 | genlmsg_end(msg, hdr); |
355199e0 | 14486 | |
68eb5503 | 14487 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 14488 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
14489 | return; |
14490 | out: | |
14491 | nlmsg_free(msg); | |
355199e0 JM |
14492 | } |
14493 | EXPORT_SYMBOL(cfg80211_ft_event); | |
14494 | ||
5de17984 AS |
14495 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
14496 | { | |
14497 | struct cfg80211_registered_device *rdev; | |
14498 | struct sk_buff *msg; | |
14499 | void *hdr; | |
14500 | u32 nlportid; | |
14501 | ||
f26cbf40 | 14502 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
14503 | if (!rdev->crit_proto_nlportid) |
14504 | return; | |
14505 | ||
14506 | nlportid = rdev->crit_proto_nlportid; | |
14507 | rdev->crit_proto_nlportid = 0; | |
14508 | ||
14509 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
14510 | if (!msg) | |
14511 | return; | |
14512 | ||
14513 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
14514 | if (!hdr) | |
14515 | goto nla_put_failure; | |
14516 | ||
14517 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2dad624e ND |
14518 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14519 | NL80211_ATTR_PAD)) | |
5de17984 AS |
14520 | goto nla_put_failure; |
14521 | ||
14522 | genlmsg_end(msg, hdr); | |
14523 | ||
14524 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
14525 | return; | |
14526 | ||
14527 | nla_put_failure: | |
14528 | if (hdr) | |
14529 | genlmsg_cancel(msg, hdr); | |
14530 | nlmsg_free(msg); | |
5de17984 AS |
14531 | } |
14532 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
14533 | ||
348baf0e JB |
14534 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
14535 | { | |
14536 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 14537 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
14538 | struct sk_buff *msg; |
14539 | void *hdr; | |
14540 | ||
14541 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
14542 | if (!msg) | |
14543 | return; | |
14544 | ||
14545 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
14546 | if (!hdr) | |
14547 | goto out; | |
14548 | ||
14549 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
14550 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
2dad624e ND |
14551 | nla_put_u64_64bit(msg, NL80211_ATTR_WDEV, wdev_id(wdev), |
14552 | NL80211_ATTR_PAD)) | |
348baf0e JB |
14553 | goto out; |
14554 | ||
14555 | genlmsg_end(msg, hdr); | |
14556 | ||
14557 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
14558 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
14559 | return; | |
14560 | out: | |
14561 | nlmsg_free(msg); | |
14562 | } | |
14563 | ||
55682965 JB |
14564 | /* initialisation/exit functions */ |
14565 | ||
56989f6d | 14566 | int __init nl80211_init(void) |
55682965 | 14567 | { |
0d63cbb5 | 14568 | int err; |
55682965 | 14569 | |
489111e5 | 14570 | err = genl_register_family(&nl80211_fam); |
55682965 JB |
14571 | if (err) |
14572 | return err; | |
14573 | ||
026331c4 JM |
14574 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
14575 | if (err) | |
14576 | goto err_out; | |
14577 | ||
55682965 JB |
14578 | return 0; |
14579 | err_out: | |
14580 | genl_unregister_family(&nl80211_fam); | |
14581 | return err; | |
14582 | } | |
14583 | ||
14584 | void nl80211_exit(void) | |
14585 | { | |
026331c4 | 14586 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
14587 | genl_unregister_family(&nl80211_fam); |
14588 | } |