]>
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 |
55682965 JB |
6 | */ |
7 | ||
8 | #include <linux/if.h> | |
9 | #include <linux/module.h> | |
10 | #include <linux/err.h> | |
5a0e3ad6 | 11 | #include <linux/slab.h> |
55682965 JB |
12 | #include <linux/list.h> |
13 | #include <linux/if_ether.h> | |
14 | #include <linux/ieee80211.h> | |
15 | #include <linux/nl80211.h> | |
16 | #include <linux/rtnetlink.h> | |
17 | #include <linux/netlink.h> | |
2a519311 | 18 | #include <linux/etherdevice.h> |
463d0183 | 19 | #include <net/net_namespace.h> |
55682965 JB |
20 | #include <net/genetlink.h> |
21 | #include <net/cfg80211.h> | |
463d0183 | 22 | #include <net/sock.h> |
2a0e047e | 23 | #include <net/inet_connection_sock.h> |
55682965 JB |
24 | #include "core.h" |
25 | #include "nl80211.h" | |
b2e1b302 | 26 | #include "reg.h" |
e35e4d28 | 27 | #include "rdev-ops.h" |
55682965 | 28 | |
5fb628e9 JM |
29 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
30 | struct genl_info *info, | |
31 | struct cfg80211_crypto_settings *settings, | |
32 | int cipher_limit); | |
33 | ||
f84f771d | 34 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 | 35 | struct genl_info *info); |
f84f771d | 36 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
37 | struct genl_info *info); |
38 | ||
55682965 JB |
39 | /* the netlink family */ |
40 | static struct genl_family nl80211_fam = { | |
fb4e1568 MH |
41 | .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */ |
42 | .name = NL80211_GENL_NAME, /* have users key off the name instead */ | |
43 | .hdrsize = 0, /* no private header */ | |
44 | .version = 1, /* no particular meaning now */ | |
55682965 | 45 | .maxattr = NL80211_ATTR_MAX, |
463d0183 | 46 | .netnsok = true, |
4c476991 JB |
47 | .pre_doit = nl80211_pre_doit, |
48 | .post_doit = nl80211_post_doit, | |
55682965 JB |
49 | }; |
50 | ||
2a94fe48 JB |
51 | /* multicast groups */ |
52 | enum nl80211_multicast_groups { | |
53 | NL80211_MCGRP_CONFIG, | |
54 | NL80211_MCGRP_SCAN, | |
55 | NL80211_MCGRP_REGULATORY, | |
56 | NL80211_MCGRP_MLME, | |
567ffc35 | 57 | NL80211_MCGRP_VENDOR, |
2a94fe48 JB |
58 | NL80211_MCGRP_TESTMODE /* keep last - ifdef! */ |
59 | }; | |
60 | ||
61 | static const struct genl_multicast_group nl80211_mcgrps[] = { | |
71b836ec JB |
62 | [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG }, |
63 | [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN }, | |
64 | [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG }, | |
65 | [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME }, | |
66 | [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR }, | |
2a94fe48 | 67 | #ifdef CONFIG_NL80211_TESTMODE |
71b836ec | 68 | [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE } |
2a94fe48 JB |
69 | #endif |
70 | }; | |
71 | ||
89a54e48 JB |
72 | /* returns ERR_PTR values */ |
73 | static struct wireless_dev * | |
74 | __cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs) | |
55682965 | 75 | { |
89a54e48 JB |
76 | struct cfg80211_registered_device *rdev; |
77 | struct wireless_dev *result = NULL; | |
78 | bool have_ifidx = attrs[NL80211_ATTR_IFINDEX]; | |
79 | bool have_wdev_id = attrs[NL80211_ATTR_WDEV]; | |
80 | u64 wdev_id; | |
81 | int wiphy_idx = -1; | |
82 | int ifidx = -1; | |
55682965 | 83 | |
5fe231e8 | 84 | ASSERT_RTNL(); |
55682965 | 85 | |
89a54e48 JB |
86 | if (!have_ifidx && !have_wdev_id) |
87 | return ERR_PTR(-EINVAL); | |
55682965 | 88 | |
89a54e48 JB |
89 | if (have_ifidx) |
90 | ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
91 | if (have_wdev_id) { | |
92 | wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
93 | wiphy_idx = wdev_id >> 32; | |
55682965 JB |
94 | } |
95 | ||
89a54e48 JB |
96 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
97 | struct wireless_dev *wdev; | |
98 | ||
99 | if (wiphy_net(&rdev->wiphy) != netns) | |
100 | continue; | |
101 | ||
102 | if (have_wdev_id && rdev->wiphy_idx != wiphy_idx) | |
103 | continue; | |
104 | ||
89a54e48 JB |
105 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
106 | if (have_ifidx && wdev->netdev && | |
107 | wdev->netdev->ifindex == ifidx) { | |
108 | result = wdev; | |
109 | break; | |
110 | } | |
111 | if (have_wdev_id && wdev->identifier == (u32)wdev_id) { | |
112 | result = wdev; | |
113 | break; | |
114 | } | |
115 | } | |
89a54e48 JB |
116 | |
117 | if (result) | |
118 | break; | |
119 | } | |
120 | ||
121 | if (result) | |
122 | return result; | |
123 | return ERR_PTR(-ENODEV); | |
55682965 JB |
124 | } |
125 | ||
a9455408 | 126 | static struct cfg80211_registered_device * |
878d9ec7 | 127 | __cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs) |
a9455408 | 128 | { |
7fee4778 JB |
129 | struct cfg80211_registered_device *rdev = NULL, *tmp; |
130 | struct net_device *netdev; | |
a9455408 | 131 | |
5fe231e8 | 132 | ASSERT_RTNL(); |
a9455408 | 133 | |
878d9ec7 | 134 | if (!attrs[NL80211_ATTR_WIPHY] && |
89a54e48 JB |
135 | !attrs[NL80211_ATTR_IFINDEX] && |
136 | !attrs[NL80211_ATTR_WDEV]) | |
7fee4778 JB |
137 | return ERR_PTR(-EINVAL); |
138 | ||
878d9ec7 | 139 | if (attrs[NL80211_ATTR_WIPHY]) |
7fee4778 | 140 | rdev = cfg80211_rdev_by_wiphy_idx( |
878d9ec7 | 141 | nla_get_u32(attrs[NL80211_ATTR_WIPHY])); |
a9455408 | 142 | |
89a54e48 JB |
143 | if (attrs[NL80211_ATTR_WDEV]) { |
144 | u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]); | |
145 | struct wireless_dev *wdev; | |
146 | bool found = false; | |
147 | ||
148 | tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32); | |
149 | if (tmp) { | |
150 | /* make sure wdev exists */ | |
89a54e48 JB |
151 | list_for_each_entry(wdev, &tmp->wdev_list, list) { |
152 | if (wdev->identifier != (u32)wdev_id) | |
153 | continue; | |
154 | found = true; | |
155 | break; | |
156 | } | |
89a54e48 JB |
157 | |
158 | if (!found) | |
159 | tmp = NULL; | |
160 | ||
161 | if (rdev && tmp != rdev) | |
162 | return ERR_PTR(-EINVAL); | |
163 | rdev = tmp; | |
164 | } | |
165 | } | |
166 | ||
878d9ec7 JB |
167 | if (attrs[NL80211_ATTR_IFINDEX]) { |
168 | int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]); | |
7f2b8562 | 169 | netdev = __dev_get_by_index(netns, ifindex); |
7fee4778 JB |
170 | if (netdev) { |
171 | if (netdev->ieee80211_ptr) | |
f26cbf40 ZG |
172 | tmp = wiphy_to_rdev( |
173 | netdev->ieee80211_ptr->wiphy); | |
7fee4778 JB |
174 | else |
175 | tmp = NULL; | |
176 | ||
7fee4778 JB |
177 | /* not wireless device -- return error */ |
178 | if (!tmp) | |
179 | return ERR_PTR(-EINVAL); | |
180 | ||
181 | /* mismatch -- return error */ | |
182 | if (rdev && tmp != rdev) | |
183 | return ERR_PTR(-EINVAL); | |
184 | ||
185 | rdev = tmp; | |
a9455408 | 186 | } |
a9455408 | 187 | } |
a9455408 | 188 | |
4f7eff10 JB |
189 | if (!rdev) |
190 | return ERR_PTR(-ENODEV); | |
a9455408 | 191 | |
4f7eff10 JB |
192 | if (netns != wiphy_net(&rdev->wiphy)) |
193 | return ERR_PTR(-ENODEV); | |
194 | ||
195 | return rdev; | |
a9455408 JB |
196 | } |
197 | ||
198 | /* | |
199 | * This function returns a pointer to the driver | |
200 | * that the genl_info item that is passed refers to. | |
a9455408 JB |
201 | * |
202 | * The result of this can be a PTR_ERR and hence must | |
203 | * be checked with IS_ERR() for errors. | |
204 | */ | |
205 | static struct cfg80211_registered_device * | |
4f7eff10 | 206 | cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info) |
a9455408 | 207 | { |
5fe231e8 | 208 | return __cfg80211_rdev_from_attrs(netns, info->attrs); |
a9455408 JB |
209 | } |
210 | ||
55682965 | 211 | /* policy for the attributes */ |
8cd4d456 | 212 | static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { |
55682965 JB |
213 | [NL80211_ATTR_WIPHY] = { .type = NLA_U32 }, |
214 | [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING, | |
079e24ed | 215 | .len = 20-1 }, |
31888487 | 216 | [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED }, |
3d9d1d66 | 217 | |
72bdcf34 | 218 | [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 }, |
094d05dc | 219 | [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 }, |
3d9d1d66 JB |
220 | [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 }, |
221 | [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 }, | |
222 | [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 }, | |
223 | ||
b9a5f8ca JM |
224 | [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 }, |
225 | [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 }, | |
226 | [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 }, | |
227 | [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 }, | |
81077e82 | 228 | [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 }, |
3057dbfd | 229 | [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG }, |
55682965 JB |
230 | |
231 | [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 }, | |
232 | [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 }, | |
233 | [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 }, | |
41ade00f | 234 | |
e007b857 EP |
235 | [NL80211_ATTR_MAC] = { .len = ETH_ALEN }, |
236 | [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN }, | |
41ade00f | 237 | |
b9454e83 | 238 | [NL80211_ATTR_KEY] = { .type = NLA_NESTED, }, |
41ade00f JB |
239 | [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY, |
240 | .len = WLAN_MAX_KEY_LEN }, | |
241 | [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 }, | |
242 | [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 }, | |
243 | [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG }, | |
81962267 | 244 | [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 }, |
e31b8213 | 245 | [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 }, |
ed1b6cc7 JB |
246 | |
247 | [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 }, | |
248 | [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 }, | |
249 | [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY, | |
250 | .len = IEEE80211_MAX_DATA_LEN }, | |
251 | [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY, | |
252 | .len = IEEE80211_MAX_DATA_LEN }, | |
5727ef1b JB |
253 | [NL80211_ATTR_STA_AID] = { .type = NLA_U16 }, |
254 | [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED }, | |
255 | [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 }, | |
256 | [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY, | |
257 | .len = NL80211_MAX_SUPP_RATES }, | |
2ec600d6 | 258 | [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 }, |
5727ef1b | 259 | [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 }, |
0a9542ee | 260 | [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ }, |
2ec600d6 | 261 | [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY, |
a4f606ea | 262 | .len = IEEE80211_MAX_MESH_ID_LEN }, |
2ec600d6 | 263 | [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 }, |
9f1ba906 | 264 | |
b2e1b302 LR |
265 | [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, |
266 | [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED }, | |
267 | ||
9f1ba906 JM |
268 | [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 }, |
269 | [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 }, | |
270 | [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 }, | |
90c97a04 JM |
271 | [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY, |
272 | .len = NL80211_MAX_SUPP_RATES }, | |
50b12f59 | 273 | [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 }, |
36aedc90 | 274 | |
24bdd9f4 | 275 | [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED }, |
15d5dda6 | 276 | [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG }, |
93da9cc1 | 277 | |
6c739419 | 278 | [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN }, |
9aed3cc1 JM |
279 | |
280 | [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 }, | |
281 | [NL80211_ATTR_IE] = { .type = NLA_BINARY, | |
282 | .len = IEEE80211_MAX_DATA_LEN }, | |
2a519311 JB |
283 | [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED }, |
284 | [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED }, | |
636a5d36 JM |
285 | |
286 | [NL80211_ATTR_SSID] = { .type = NLA_BINARY, | |
287 | .len = IEEE80211_MAX_SSID_LEN }, | |
288 | [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 }, | |
289 | [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 }, | |
04a773ad | 290 | [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG }, |
1965c853 | 291 | [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG }, |
dc6382ce | 292 | [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 }, |
eccb8e8f JB |
293 | [NL80211_ATTR_STA_FLAGS2] = { |
294 | .len = sizeof(struct nl80211_sta_flag_update), | |
295 | }, | |
3f77316c | 296 | [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG }, |
c0692b8f JB |
297 | [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 }, |
298 | [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG }, | |
b23aa676 SO |
299 | [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG }, |
300 | [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 }, | |
301 | [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 }, | |
463d0183 | 302 | [NL80211_ATTR_PID] = { .type = NLA_U32 }, |
8b787643 | 303 | [NL80211_ATTR_4ADDR] = { .type = NLA_U8 }, |
67fbb16b SO |
304 | [NL80211_ATTR_PMKID] = { .type = NLA_BINARY, |
305 | .len = WLAN_PMKID_LEN }, | |
9588bbd5 JM |
306 | [NL80211_ATTR_DURATION] = { .type = NLA_U32 }, |
307 | [NL80211_ATTR_COOKIE] = { .type = NLA_U64 }, | |
13ae75b1 | 308 | [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED }, |
026331c4 JM |
309 | [NL80211_ATTR_FRAME] = { .type = NLA_BINARY, |
310 | .len = IEEE80211_MAX_DATA_LEN }, | |
311 | [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, }, | |
ffb9eb3d | 312 | [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 }, |
d6dc1a38 | 313 | [NL80211_ATTR_CQM] = { .type = NLA_NESTED, }, |
d5cdfacb | 314 | [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG }, |
fd8aaaf3 | 315 | [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 }, |
98d2ff8b JO |
316 | [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 }, |
317 | [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 }, | |
2e161f78 | 318 | [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 }, |
afe0cbf8 BR |
319 | [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 }, |
320 | [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 }, | |
885a46d0 | 321 | [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 }, |
f7ca38df | 322 | [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG }, |
dbd2fd65 | 323 | [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED }, |
ff1b6e69 | 324 | [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED }, |
9c3990aa | 325 | [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 }, |
bbe6ad6d | 326 | [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 }, |
e5497d76 | 327 | [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED }, |
34850ab2 | 328 | [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED }, |
32e9de84 | 329 | [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 }, |
9946ecfb JM |
330 | [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY, |
331 | .len = IEEE80211_MAX_DATA_LEN }, | |
332 | [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY, | |
333 | .len = IEEE80211_MAX_DATA_LEN }, | |
f4b34b55 | 334 | [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG }, |
a1f1c21c | 335 | [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED }, |
e9f935e3 | 336 | [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG }, |
109086ce AN |
337 | [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 }, |
338 | [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 }, | |
339 | [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 }, | |
340 | [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG }, | |
341 | [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG }, | |
31fa97c5 | 342 | [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG }, |
e247bd90 | 343 | [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG }, |
00f740e1 AN |
344 | [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY, |
345 | .len = IEEE80211_MAX_DATA_LEN }, | |
8b60b078 | 346 | [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 }, |
7e7c8926 BG |
347 | [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG }, |
348 | [NL80211_ATTR_HT_CAPABILITY_MASK] = { | |
349 | .len = NL80211_HT_CAPABILITY_LEN | |
350 | }, | |
1d9d9213 | 351 | [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 }, |
1b658f11 | 352 | [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 }, |
4486ea98 | 353 | [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 }, |
89a54e48 | 354 | [NL80211_ATTR_WDEV] = { .type = NLA_U64 }, |
57b5ce07 | 355 | [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 }, |
e39e5b5e | 356 | [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, }, |
f461be3e | 357 | [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN }, |
ed473771 | 358 | [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 }, |
53cabad7 JB |
359 | [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 }, |
360 | [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 }, | |
77765eaf VT |
361 | [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 }, |
362 | [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED }, | |
9d62a986 JM |
363 | [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 }, |
364 | [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, }, | |
3713b4e3 | 365 | [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, }, |
ee2aca34 JB |
366 | [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG }, |
367 | [NL80211_ATTR_VHT_CAPABILITY_MASK] = { | |
368 | .len = NL80211_VHT_CAPABILITY_LEN, | |
369 | }, | |
355199e0 JM |
370 | [NL80211_ATTR_MDID] = { .type = NLA_U16 }, |
371 | [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY, | |
372 | .len = IEEE80211_MAX_DATA_LEN }, | |
5e4b6f56 | 373 | [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 }, |
16ef1fe2 SW |
374 | [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 }, |
375 | [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG }, | |
376 | [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED }, | |
9a774c78 AO |
377 | [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY }, |
378 | [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY }, | |
c01fc9ad SD |
379 | [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY }, |
380 | [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY }, | |
5336fa88 | 381 | [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG }, |
60f4a7b1 | 382 | [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 }, |
ad7e718c JB |
383 | [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 }, |
384 | [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 }, | |
385 | [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY }, | |
fa9ffc74 KP |
386 | [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY, |
387 | .len = IEEE80211_QOS_MAP_LEN_MAX }, | |
1df4a510 JM |
388 | [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN }, |
389 | [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 }, | |
df942e7b | 390 | [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 }, |
18e5ca65 | 391 | [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG }, |
34d22ce2 | 392 | [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY }, |
bab5ab7d | 393 | [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG }, |
960d01ac JB |
394 | [NL80211_ATTR_TSID] = { .type = NLA_U8 }, |
395 | [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 }, | |
396 | [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 }, | |
18998c38 | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
ad2b26ab | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
1bdd716c | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
4b681c82 | 400 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, |
9c748934 | 401 | [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 }, |
05050753 | 402 | [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG }, |
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 | ||
97990a06 JB |
481 | static int nl80211_prepare_wdev_dump(struct sk_buff *skb, |
482 | struct netlink_callback *cb, | |
483 | struct cfg80211_registered_device **rdev, | |
484 | struct wireless_dev **wdev) | |
a043897a | 485 | { |
97990a06 | 486 | int err; |
a043897a | 487 | |
97990a06 | 488 | rtnl_lock(); |
a043897a | 489 | |
97990a06 JB |
490 | if (!cb->args[0]) { |
491 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
492 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
493 | nl80211_policy); | |
494 | if (err) | |
495 | goto out_unlock; | |
67748893 | 496 | |
97990a06 JB |
497 | *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk), |
498 | nl80211_fam.attrbuf); | |
499 | if (IS_ERR(*wdev)) { | |
500 | err = PTR_ERR(*wdev); | |
501 | goto out_unlock; | |
502 | } | |
f26cbf40 | 503 | *rdev = wiphy_to_rdev((*wdev)->wiphy); |
c319d50b JB |
504 | /* 0 is the first index - add 1 to parse only once */ |
505 | cb->args[0] = (*rdev)->wiphy_idx + 1; | |
97990a06 JB |
506 | cb->args[1] = (*wdev)->identifier; |
507 | } else { | |
c319d50b JB |
508 | /* subtract the 1 again here */ |
509 | struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1); | |
97990a06 | 510 | struct wireless_dev *tmp; |
67748893 | 511 | |
97990a06 JB |
512 | if (!wiphy) { |
513 | err = -ENODEV; | |
514 | goto out_unlock; | |
515 | } | |
f26cbf40 | 516 | *rdev = wiphy_to_rdev(wiphy); |
97990a06 | 517 | *wdev = NULL; |
67748893 | 518 | |
97990a06 JB |
519 | list_for_each_entry(tmp, &(*rdev)->wdev_list, list) { |
520 | if (tmp->identifier == cb->args[1]) { | |
521 | *wdev = tmp; | |
522 | break; | |
523 | } | |
524 | } | |
67748893 | 525 | |
97990a06 JB |
526 | if (!*wdev) { |
527 | err = -ENODEV; | |
528 | goto out_unlock; | |
529 | } | |
67748893 JB |
530 | } |
531 | ||
67748893 | 532 | return 0; |
97990a06 | 533 | out_unlock: |
67748893 JB |
534 | rtnl_unlock(); |
535 | return err; | |
536 | } | |
537 | ||
97990a06 | 538 | static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev) |
67748893 | 539 | { |
67748893 JB |
540 | rtnl_unlock(); |
541 | } | |
542 | ||
f4a11bb0 JB |
543 | /* IE validation */ |
544 | static bool is_valid_ie_attr(const struct nlattr *attr) | |
545 | { | |
546 | const u8 *pos; | |
547 | int len; | |
548 | ||
549 | if (!attr) | |
550 | return true; | |
551 | ||
552 | pos = nla_data(attr); | |
553 | len = nla_len(attr); | |
554 | ||
555 | while (len) { | |
556 | u8 elemlen; | |
557 | ||
558 | if (len < 2) | |
559 | return false; | |
560 | len -= 2; | |
561 | ||
562 | elemlen = pos[1]; | |
563 | if (elemlen > len) | |
564 | return false; | |
565 | ||
566 | len -= elemlen; | |
567 | pos += 2 + elemlen; | |
568 | } | |
569 | ||
570 | return true; | |
571 | } | |
572 | ||
55682965 | 573 | /* message building helper */ |
15e47304 | 574 | static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq, |
55682965 JB |
575 | int flags, u8 cmd) |
576 | { | |
577 | /* since there is no private header just add the generic one */ | |
15e47304 | 578 | return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd); |
55682965 JB |
579 | } |
580 | ||
5dab3b8a | 581 | static int nl80211_msg_put_channel(struct sk_buff *msg, |
cdc89b97 JB |
582 | struct ieee80211_channel *chan, |
583 | bool large) | |
5dab3b8a | 584 | { |
ea077c1c RL |
585 | /* Some channels must be completely excluded from the |
586 | * list to protect old user-space tools from breaking | |
587 | */ | |
588 | if (!large && chan->flags & | |
589 | (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ)) | |
590 | return 0; | |
591 | ||
9360ffd1 DM |
592 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ, |
593 | chan->center_freq)) | |
594 | goto nla_put_failure; | |
5dab3b8a | 595 | |
9360ffd1 DM |
596 | if ((chan->flags & IEEE80211_CHAN_DISABLED) && |
597 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED)) | |
598 | goto nla_put_failure; | |
8fe02e16 LR |
599 | if (chan->flags & IEEE80211_CHAN_NO_IR) { |
600 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR)) | |
601 | goto nla_put_failure; | |
602 | if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS)) | |
603 | goto nla_put_failure; | |
604 | } | |
cdc89b97 JB |
605 | if (chan->flags & IEEE80211_CHAN_RADAR) { |
606 | if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR)) | |
607 | goto nla_put_failure; | |
608 | if (large) { | |
609 | u32 time; | |
610 | ||
611 | time = elapsed_jiffies_msecs(chan->dfs_state_entered); | |
612 | ||
613 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE, | |
614 | chan->dfs_state)) | |
615 | goto nla_put_failure; | |
616 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME, | |
617 | time)) | |
618 | goto nla_put_failure; | |
089027e5 JD |
619 | if (nla_put_u32(msg, |
620 | NL80211_FREQUENCY_ATTR_DFS_CAC_TIME, | |
621 | chan->dfs_cac_ms)) | |
622 | goto nla_put_failure; | |
cdc89b97 JB |
623 | } |
624 | } | |
5dab3b8a | 625 | |
fe1abafd JB |
626 | if (large) { |
627 | if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) && | |
628 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS)) | |
629 | goto nla_put_failure; | |
630 | if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) && | |
631 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS)) | |
632 | goto nla_put_failure; | |
633 | if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) && | |
634 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ)) | |
635 | goto nla_put_failure; | |
636 | if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) && | |
637 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ)) | |
638 | goto nla_put_failure; | |
570dbde1 DS |
639 | if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) && |
640 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY)) | |
641 | goto nla_put_failure; | |
642 | if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) && | |
643 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT)) | |
644 | goto nla_put_failure; | |
ea077c1c RL |
645 | if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) && |
646 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ)) | |
647 | goto nla_put_failure; | |
648 | if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) && | |
649 | nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ)) | |
650 | goto nla_put_failure; | |
fe1abafd JB |
651 | } |
652 | ||
9360ffd1 DM |
653 | if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER, |
654 | DBM_TO_MBM(chan->max_power))) | |
655 | goto nla_put_failure; | |
5dab3b8a LR |
656 | |
657 | return 0; | |
658 | ||
659 | nla_put_failure: | |
660 | return -ENOBUFS; | |
661 | } | |
662 | ||
55682965 JB |
663 | /* netlink command implementations */ |
664 | ||
b9454e83 JB |
665 | struct key_parse { |
666 | struct key_params p; | |
667 | int idx; | |
e31b8213 | 668 | int type; |
b9454e83 | 669 | bool def, defmgmt; |
dbd2fd65 | 670 | bool def_uni, def_multi; |
b9454e83 JB |
671 | }; |
672 | ||
673 | static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k) | |
674 | { | |
675 | struct nlattr *tb[NL80211_KEY_MAX + 1]; | |
676 | int err = nla_parse_nested(tb, NL80211_KEY_MAX, key, | |
677 | nl80211_key_policy); | |
678 | if (err) | |
679 | return err; | |
680 | ||
681 | k->def = !!tb[NL80211_KEY_DEFAULT]; | |
682 | k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT]; | |
683 | ||
dbd2fd65 JB |
684 | if (k->def) { |
685 | k->def_uni = true; | |
686 | k->def_multi = true; | |
687 | } | |
688 | if (k->defmgmt) | |
689 | k->def_multi = true; | |
690 | ||
b9454e83 JB |
691 | if (tb[NL80211_KEY_IDX]) |
692 | k->idx = nla_get_u8(tb[NL80211_KEY_IDX]); | |
693 | ||
694 | if (tb[NL80211_KEY_DATA]) { | |
695 | k->p.key = nla_data(tb[NL80211_KEY_DATA]); | |
696 | k->p.key_len = nla_len(tb[NL80211_KEY_DATA]); | |
697 | } | |
698 | ||
699 | if (tb[NL80211_KEY_SEQ]) { | |
700 | k->p.seq = nla_data(tb[NL80211_KEY_SEQ]); | |
701 | k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]); | |
702 | } | |
703 | ||
704 | if (tb[NL80211_KEY_CIPHER]) | |
705 | k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]); | |
706 | ||
e31b8213 JB |
707 | if (tb[NL80211_KEY_TYPE]) { |
708 | k->type = nla_get_u32(tb[NL80211_KEY_TYPE]); | |
709 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
710 | return -EINVAL; | |
711 | } | |
712 | ||
dbd2fd65 JB |
713 | if (tb[NL80211_KEY_DEFAULT_TYPES]) { |
714 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
2da8f419 JB |
715 | err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, |
716 | tb[NL80211_KEY_DEFAULT_TYPES], | |
717 | nl80211_key_default_policy); | |
dbd2fd65 JB |
718 | if (err) |
719 | return err; | |
720 | ||
721 | k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST]; | |
722 | k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST]; | |
723 | } | |
724 | ||
b9454e83 JB |
725 | return 0; |
726 | } | |
727 | ||
728 | static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k) | |
729 | { | |
730 | if (info->attrs[NL80211_ATTR_KEY_DATA]) { | |
731 | k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]); | |
732 | k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]); | |
733 | } | |
734 | ||
735 | if (info->attrs[NL80211_ATTR_KEY_SEQ]) { | |
736 | k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
737 | k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]); | |
738 | } | |
739 | ||
740 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
741 | k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
742 | ||
743 | if (info->attrs[NL80211_ATTR_KEY_CIPHER]) | |
744 | k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]); | |
745 | ||
746 | k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT]; | |
747 | k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT]; | |
748 | ||
dbd2fd65 JB |
749 | if (k->def) { |
750 | k->def_uni = true; | |
751 | k->def_multi = true; | |
752 | } | |
753 | if (k->defmgmt) | |
754 | k->def_multi = true; | |
755 | ||
e31b8213 JB |
756 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { |
757 | k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
758 | if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES) | |
759 | return -EINVAL; | |
760 | } | |
761 | ||
dbd2fd65 JB |
762 | if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) { |
763 | struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES]; | |
764 | int err = nla_parse_nested( | |
765 | kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1, | |
766 | info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES], | |
767 | nl80211_key_default_policy); | |
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(struct genl_info *info, struct key_parse *k) | |
779 | { | |
780 | int err; | |
781 | ||
782 | memset(k, 0, sizeof(*k)); | |
783 | k->idx = -1; | |
e31b8213 | 784 | k->type = -1; |
b9454e83 JB |
785 | |
786 | if (info->attrs[NL80211_ATTR_KEY]) | |
787 | err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k); | |
788 | else | |
789 | err = nl80211_parse_key_old(info, k); | |
790 | ||
791 | if (err) | |
792 | return err; | |
793 | ||
794 | if (k->def && k->defmgmt) | |
795 | return -EINVAL; | |
796 | ||
dbd2fd65 JB |
797 | if (k->defmgmt) { |
798 | if (k->def_uni || !k->def_multi) | |
799 | return -EINVAL; | |
800 | } | |
801 | ||
b9454e83 JB |
802 | if (k->idx != -1) { |
803 | if (k->defmgmt) { | |
804 | if (k->idx < 4 || k->idx > 5) | |
805 | return -EINVAL; | |
806 | } else if (k->def) { | |
807 | if (k->idx < 0 || k->idx > 3) | |
808 | return -EINVAL; | |
809 | } else { | |
810 | if (k->idx < 0 || k->idx > 5) | |
811 | return -EINVAL; | |
812 | } | |
813 | } | |
814 | ||
815 | return 0; | |
816 | } | |
817 | ||
fffd0934 JB |
818 | static struct cfg80211_cached_keys * |
819 | nl80211_parse_connkeys(struct cfg80211_registered_device *rdev, | |
de7044ee | 820 | struct nlattr *keys, bool *no_ht) |
fffd0934 JB |
821 | { |
822 | struct key_parse parse; | |
823 | struct nlattr *key; | |
824 | struct cfg80211_cached_keys *result; | |
825 | int rem, err, def = 0; | |
826 | ||
827 | result = kzalloc(sizeof(*result), GFP_KERNEL); | |
828 | if (!result) | |
829 | return ERR_PTR(-ENOMEM); | |
830 | ||
831 | result->def = -1; | |
832 | result->defmgmt = -1; | |
833 | ||
834 | nla_for_each_nested(key, keys, rem) { | |
835 | memset(&parse, 0, sizeof(parse)); | |
836 | parse.idx = -1; | |
837 | ||
838 | err = nl80211_parse_key_new(key, &parse); | |
839 | if (err) | |
840 | goto error; | |
841 | err = -EINVAL; | |
842 | if (!parse.p.key) | |
843 | goto error; | |
844 | if (parse.idx < 0 || parse.idx > 4) | |
845 | goto error; | |
846 | if (parse.def) { | |
847 | if (def) | |
848 | goto error; | |
849 | def = 1; | |
850 | result->def = parse.idx; | |
dbd2fd65 JB |
851 | if (!parse.def_uni || !parse.def_multi) |
852 | goto error; | |
fffd0934 JB |
853 | } else if (parse.defmgmt) |
854 | goto error; | |
855 | err = cfg80211_validate_key_settings(rdev, &parse.p, | |
e31b8213 | 856 | parse.idx, false, NULL); |
fffd0934 JB |
857 | if (err) |
858 | goto error; | |
859 | result->params[parse.idx].cipher = parse.p.cipher; | |
860 | result->params[parse.idx].key_len = parse.p.key_len; | |
861 | result->params[parse.idx].key = result->data[parse.idx]; | |
862 | memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len); | |
de7044ee SM |
863 | |
864 | if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 || | |
865 | parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) { | |
866 | if (no_ht) | |
867 | *no_ht = true; | |
868 | } | |
fffd0934 JB |
869 | } |
870 | ||
871 | return result; | |
872 | error: | |
873 | kfree(result); | |
874 | return ERR_PTR(err); | |
875 | } | |
876 | ||
877 | static int nl80211_key_allowed(struct wireless_dev *wdev) | |
878 | { | |
879 | ASSERT_WDEV_LOCK(wdev); | |
880 | ||
fffd0934 JB |
881 | switch (wdev->iftype) { |
882 | case NL80211_IFTYPE_AP: | |
883 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 884 | case NL80211_IFTYPE_P2P_GO: |
ff973af7 | 885 | case NL80211_IFTYPE_MESH_POINT: |
fffd0934 JB |
886 | break; |
887 | case NL80211_IFTYPE_ADHOC: | |
fffd0934 | 888 | case NL80211_IFTYPE_STATION: |
074ac8df | 889 | case NL80211_IFTYPE_P2P_CLIENT: |
ceca7b71 | 890 | if (!wdev->current_bss) |
fffd0934 JB |
891 | return -ENOLINK; |
892 | break; | |
de4fcbad | 893 | case NL80211_IFTYPE_UNSPECIFIED: |
6e0bd6c3 | 894 | case NL80211_IFTYPE_OCB: |
de4fcbad JB |
895 | case NL80211_IFTYPE_MONITOR: |
896 | case NL80211_IFTYPE_P2P_DEVICE: | |
897 | case NL80211_IFTYPE_WDS: | |
898 | case NUM_NL80211_IFTYPES: | |
fffd0934 JB |
899 | return -EINVAL; |
900 | } | |
901 | ||
902 | return 0; | |
903 | } | |
904 | ||
664834de JM |
905 | static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy, |
906 | struct nlattr *tb) | |
907 | { | |
908 | struct ieee80211_channel *chan; | |
909 | ||
910 | if (tb == NULL) | |
911 | return NULL; | |
912 | chan = ieee80211_get_channel(wiphy, nla_get_u32(tb)); | |
913 | if (!chan || chan->flags & IEEE80211_CHAN_DISABLED) | |
914 | return NULL; | |
915 | return chan; | |
916 | } | |
917 | ||
7527a782 JB |
918 | static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes) |
919 | { | |
920 | struct nlattr *nl_modes = nla_nest_start(msg, attr); | |
921 | int i; | |
922 | ||
923 | if (!nl_modes) | |
924 | goto nla_put_failure; | |
925 | ||
926 | i = 0; | |
927 | while (ifmodes) { | |
9360ffd1 DM |
928 | if ((ifmodes & 1) && nla_put_flag(msg, i)) |
929 | goto nla_put_failure; | |
7527a782 JB |
930 | ifmodes >>= 1; |
931 | i++; | |
932 | } | |
933 | ||
934 | nla_nest_end(msg, nl_modes); | |
935 | return 0; | |
936 | ||
937 | nla_put_failure: | |
938 | return -ENOBUFS; | |
939 | } | |
940 | ||
941 | static int nl80211_put_iface_combinations(struct wiphy *wiphy, | |
cdc89b97 JB |
942 | struct sk_buff *msg, |
943 | bool large) | |
7527a782 JB |
944 | { |
945 | struct nlattr *nl_combis; | |
946 | int i, j; | |
947 | ||
948 | nl_combis = nla_nest_start(msg, | |
949 | NL80211_ATTR_INTERFACE_COMBINATIONS); | |
950 | if (!nl_combis) | |
951 | goto nla_put_failure; | |
952 | ||
953 | for (i = 0; i < wiphy->n_iface_combinations; i++) { | |
954 | const struct ieee80211_iface_combination *c; | |
955 | struct nlattr *nl_combi, *nl_limits; | |
956 | ||
957 | c = &wiphy->iface_combinations[i]; | |
958 | ||
959 | nl_combi = nla_nest_start(msg, i + 1); | |
960 | if (!nl_combi) | |
961 | goto nla_put_failure; | |
962 | ||
963 | nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS); | |
964 | if (!nl_limits) | |
965 | goto nla_put_failure; | |
966 | ||
967 | for (j = 0; j < c->n_limits; j++) { | |
968 | struct nlattr *nl_limit; | |
969 | ||
970 | nl_limit = nla_nest_start(msg, j + 1); | |
971 | if (!nl_limit) | |
972 | goto nla_put_failure; | |
9360ffd1 DM |
973 | if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX, |
974 | c->limits[j].max)) | |
975 | goto nla_put_failure; | |
7527a782 JB |
976 | if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES, |
977 | c->limits[j].types)) | |
978 | goto nla_put_failure; | |
979 | nla_nest_end(msg, nl_limit); | |
980 | } | |
981 | ||
982 | nla_nest_end(msg, nl_limits); | |
983 | ||
9360ffd1 DM |
984 | if (c->beacon_int_infra_match && |
985 | nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH)) | |
986 | goto nla_put_failure; | |
987 | if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS, | |
988 | c->num_different_channels) || | |
989 | nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM, | |
990 | c->max_interfaces)) | |
991 | goto nla_put_failure; | |
cdc89b97 | 992 | if (large && |
8c48b50a FF |
993 | (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS, |
994 | c->radar_detect_widths) || | |
995 | nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS, | |
996 | c->radar_detect_regions))) | |
cdc89b97 | 997 | goto nla_put_failure; |
7527a782 JB |
998 | |
999 | nla_nest_end(msg, nl_combi); | |
1000 | } | |
1001 | ||
1002 | nla_nest_end(msg, nl_combis); | |
1003 | ||
1004 | return 0; | |
1005 | nla_put_failure: | |
1006 | return -ENOBUFS; | |
1007 | } | |
1008 | ||
3713b4e3 | 1009 | #ifdef CONFIG_PM |
b56cf720 JB |
1010 | static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev, |
1011 | struct sk_buff *msg) | |
1012 | { | |
964dc9e2 | 1013 | const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp; |
b56cf720 JB |
1014 | struct nlattr *nl_tcp; |
1015 | ||
1016 | if (!tcp) | |
1017 | return 0; | |
1018 | ||
1019 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
1020 | if (!nl_tcp) | |
1021 | return -ENOBUFS; | |
1022 | ||
1023 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1024 | tcp->data_payload_max)) | |
1025 | return -ENOBUFS; | |
1026 | ||
1027 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
1028 | tcp->data_payload_max)) | |
1029 | return -ENOBUFS; | |
1030 | ||
1031 | if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ)) | |
1032 | return -ENOBUFS; | |
1033 | ||
1034 | if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
1035 | sizeof(*tcp->tok), tcp->tok)) | |
1036 | return -ENOBUFS; | |
1037 | ||
1038 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
1039 | tcp->data_interval_max)) | |
1040 | return -ENOBUFS; | |
1041 | ||
1042 | if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
1043 | tcp->wake_payload_max)) | |
1044 | return -ENOBUFS; | |
1045 | ||
1046 | nla_nest_end(msg, nl_tcp); | |
1047 | return 0; | |
1048 | } | |
1049 | ||
3713b4e3 | 1050 | static int nl80211_send_wowlan(struct sk_buff *msg, |
1b8ec87a | 1051 | struct cfg80211_registered_device *rdev, |
b56cf720 | 1052 | bool large) |
55682965 | 1053 | { |
3713b4e3 | 1054 | struct nlattr *nl_wowlan; |
55682965 | 1055 | |
1b8ec87a | 1056 | if (!rdev->wiphy.wowlan) |
3713b4e3 | 1057 | return 0; |
55682965 | 1058 | |
3713b4e3 JB |
1059 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED); |
1060 | if (!nl_wowlan) | |
1061 | return -ENOBUFS; | |
9360ffd1 | 1062 | |
1b8ec87a | 1063 | if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) && |
3713b4e3 | 1064 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
1b8ec87a | 1065 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) && |
3713b4e3 | 1066 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
1b8ec87a | 1067 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) && |
3713b4e3 | 1068 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
1b8ec87a | 1069 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) && |
3713b4e3 | 1070 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) || |
1b8ec87a | 1071 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) && |
3713b4e3 | 1072 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
1b8ec87a | 1073 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) && |
3713b4e3 | 1074 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
1b8ec87a | 1075 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) && |
3713b4e3 | 1076 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
1b8ec87a | 1077 | ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) && |
3713b4e3 JB |
1078 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
1079 | return -ENOBUFS; | |
9360ffd1 | 1080 | |
1b8ec87a | 1081 | if (rdev->wiphy.wowlan->n_patterns) { |
50ac6607 | 1082 | struct nl80211_pattern_support pat = { |
1b8ec87a ZG |
1083 | .max_patterns = rdev->wiphy.wowlan->n_patterns, |
1084 | .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len, | |
1085 | .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len, | |
1086 | .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset, | |
3713b4e3 | 1087 | }; |
9360ffd1 | 1088 | |
3713b4e3 JB |
1089 | if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, |
1090 | sizeof(pat), &pat)) | |
1091 | return -ENOBUFS; | |
1092 | } | |
9360ffd1 | 1093 | |
75453ccb LC |
1094 | if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) && |
1095 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT, | |
1096 | rdev->wiphy.wowlan->max_nd_match_sets)) | |
1097 | return -ENOBUFS; | |
1098 | ||
1b8ec87a | 1099 | if (large && nl80211_send_wowlan_tcp_caps(rdev, msg)) |
b56cf720 JB |
1100 | return -ENOBUFS; |
1101 | ||
8cd4d456 LC |
1102 | /* TODO: send wowlan net detect */ |
1103 | ||
3713b4e3 | 1104 | nla_nest_end(msg, nl_wowlan); |
9360ffd1 | 1105 | |
3713b4e3 JB |
1106 | return 0; |
1107 | } | |
1108 | #endif | |
9360ffd1 | 1109 | |
be29b99a | 1110 | static int nl80211_send_coalesce(struct sk_buff *msg, |
1b8ec87a | 1111 | struct cfg80211_registered_device *rdev) |
be29b99a AK |
1112 | { |
1113 | struct nl80211_coalesce_rule_support rule; | |
1114 | ||
1b8ec87a | 1115 | if (!rdev->wiphy.coalesce) |
be29b99a AK |
1116 | return 0; |
1117 | ||
1b8ec87a ZG |
1118 | rule.max_rules = rdev->wiphy.coalesce->n_rules; |
1119 | rule.max_delay = rdev->wiphy.coalesce->max_delay; | |
1120 | rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns; | |
1121 | rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len; | |
1122 | rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len; | |
1123 | rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset; | |
be29b99a AK |
1124 | |
1125 | if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule)) | |
1126 | return -ENOBUFS; | |
1127 | ||
1128 | return 0; | |
1129 | } | |
1130 | ||
3713b4e3 JB |
1131 | static int nl80211_send_band_rateinfo(struct sk_buff *msg, |
1132 | struct ieee80211_supported_band *sband) | |
1133 | { | |
1134 | struct nlattr *nl_rates, *nl_rate; | |
1135 | struct ieee80211_rate *rate; | |
1136 | int i; | |
87bbbe22 | 1137 | |
3713b4e3 JB |
1138 | /* add HT info */ |
1139 | if (sband->ht_cap.ht_supported && | |
1140 | (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET, | |
1141 | sizeof(sband->ht_cap.mcs), | |
1142 | &sband->ht_cap.mcs) || | |
1143 | nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA, | |
1144 | sband->ht_cap.cap) || | |
1145 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR, | |
1146 | sband->ht_cap.ampdu_factor) || | |
1147 | nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY, | |
1148 | sband->ht_cap.ampdu_density))) | |
1149 | return -ENOBUFS; | |
afe0cbf8 | 1150 | |
3713b4e3 JB |
1151 | /* add VHT info */ |
1152 | if (sband->vht_cap.vht_supported && | |
1153 | (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET, | |
1154 | sizeof(sband->vht_cap.vht_mcs), | |
1155 | &sband->vht_cap.vht_mcs) || | |
1156 | nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA, | |
1157 | sband->vht_cap.cap))) | |
1158 | return -ENOBUFS; | |
f59ac048 | 1159 | |
3713b4e3 JB |
1160 | /* add bitrates */ |
1161 | nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES); | |
1162 | if (!nl_rates) | |
1163 | return -ENOBUFS; | |
ee688b00 | 1164 | |
3713b4e3 JB |
1165 | for (i = 0; i < sband->n_bitrates; i++) { |
1166 | nl_rate = nla_nest_start(msg, i); | |
1167 | if (!nl_rate) | |
1168 | return -ENOBUFS; | |
ee688b00 | 1169 | |
3713b4e3 JB |
1170 | rate = &sband->bitrates[i]; |
1171 | if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE, | |
1172 | rate->bitrate)) | |
1173 | return -ENOBUFS; | |
1174 | if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) && | |
1175 | nla_put_flag(msg, | |
1176 | NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE)) | |
1177 | return -ENOBUFS; | |
ee688b00 | 1178 | |
3713b4e3 JB |
1179 | nla_nest_end(msg, nl_rate); |
1180 | } | |
d51626df | 1181 | |
3713b4e3 | 1182 | nla_nest_end(msg, nl_rates); |
bf0c111e | 1183 | |
3713b4e3 JB |
1184 | return 0; |
1185 | } | |
ee688b00 | 1186 | |
3713b4e3 JB |
1187 | static int |
1188 | nl80211_send_mgmt_stypes(struct sk_buff *msg, | |
1189 | const struct ieee80211_txrx_stypes *mgmt_stypes) | |
1190 | { | |
1191 | u16 stypes; | |
1192 | struct nlattr *nl_ftypes, *nl_ifs; | |
1193 | enum nl80211_iftype ift; | |
1194 | int i; | |
ee688b00 | 1195 | |
3713b4e3 JB |
1196 | if (!mgmt_stypes) |
1197 | return 0; | |
5dab3b8a | 1198 | |
3713b4e3 JB |
1199 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES); |
1200 | if (!nl_ifs) | |
1201 | return -ENOBUFS; | |
e2f367f2 | 1202 | |
3713b4e3 JB |
1203 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1204 | nl_ftypes = nla_nest_start(msg, ift); | |
1205 | if (!nl_ftypes) | |
1206 | return -ENOBUFS; | |
1207 | i = 0; | |
1208 | stypes = mgmt_stypes[ift].tx; | |
1209 | while (stypes) { | |
1210 | if ((stypes & 1) && | |
1211 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1212 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1213 | return -ENOBUFS; | |
1214 | stypes >>= 1; | |
1215 | i++; | |
ee688b00 | 1216 | } |
3713b4e3 JB |
1217 | nla_nest_end(msg, nl_ftypes); |
1218 | } | |
ee688b00 | 1219 | |
3713b4e3 | 1220 | nla_nest_end(msg, nl_ifs); |
ee688b00 | 1221 | |
3713b4e3 JB |
1222 | nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES); |
1223 | if (!nl_ifs) | |
1224 | return -ENOBUFS; | |
ee688b00 | 1225 | |
3713b4e3 JB |
1226 | for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) { |
1227 | nl_ftypes = nla_nest_start(msg, ift); | |
1228 | if (!nl_ftypes) | |
1229 | return -ENOBUFS; | |
1230 | i = 0; | |
1231 | stypes = mgmt_stypes[ift].rx; | |
1232 | while (stypes) { | |
1233 | if ((stypes & 1) && | |
1234 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, | |
1235 | (i << 4) | IEEE80211_FTYPE_MGMT)) | |
1236 | return -ENOBUFS; | |
1237 | stypes >>= 1; | |
1238 | i++; | |
1239 | } | |
1240 | nla_nest_end(msg, nl_ftypes); | |
1241 | } | |
1242 | nla_nest_end(msg, nl_ifs); | |
ee688b00 | 1243 | |
3713b4e3 JB |
1244 | return 0; |
1245 | } | |
ee688b00 | 1246 | |
86e8cf98 JB |
1247 | struct nl80211_dump_wiphy_state { |
1248 | s64 filter_wiphy; | |
1249 | long start; | |
1250 | long split_start, band_start, chan_start; | |
1251 | bool split; | |
1252 | }; | |
1253 | ||
1b8ec87a | 1254 | static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev, |
3bb20556 | 1255 | enum nl80211_commands cmd, |
3713b4e3 | 1256 | struct sk_buff *msg, u32 portid, u32 seq, |
86e8cf98 | 1257 | int flags, struct nl80211_dump_wiphy_state *state) |
3713b4e3 JB |
1258 | { |
1259 | void *hdr; | |
1260 | struct nlattr *nl_bands, *nl_band; | |
1261 | struct nlattr *nl_freqs, *nl_freq; | |
1262 | struct nlattr *nl_cmds; | |
1263 | enum ieee80211_band band; | |
1264 | struct ieee80211_channel *chan; | |
1265 | int i; | |
1266 | const struct ieee80211_txrx_stypes *mgmt_stypes = | |
1b8ec87a | 1267 | rdev->wiphy.mgmt_stypes; |
fe1abafd | 1268 | u32 features; |
ee688b00 | 1269 | |
3bb20556 | 1270 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
3713b4e3 JB |
1271 | if (!hdr) |
1272 | return -ENOBUFS; | |
ee688b00 | 1273 | |
86e8cf98 JB |
1274 | if (WARN_ON(!state)) |
1275 | return -EINVAL; | |
ee688b00 | 1276 | |
1b8ec87a | 1277 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
3713b4e3 | 1278 | nla_put_string(msg, NL80211_ATTR_WIPHY_NAME, |
1b8ec87a | 1279 | wiphy_name(&rdev->wiphy)) || |
3713b4e3 JB |
1280 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
1281 | cfg80211_rdev_list_generation)) | |
8fdc621d JB |
1282 | goto nla_put_failure; |
1283 | ||
3bb20556 JB |
1284 | if (cmd != NL80211_CMD_NEW_WIPHY) |
1285 | goto finish; | |
1286 | ||
86e8cf98 | 1287 | switch (state->split_start) { |
3713b4e3 JB |
1288 | case 0: |
1289 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT, | |
1b8ec87a | 1290 | rdev->wiphy.retry_short) || |
3713b4e3 | 1291 | nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG, |
1b8ec87a | 1292 | rdev->wiphy.retry_long) || |
3713b4e3 | 1293 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, |
1b8ec87a | 1294 | rdev->wiphy.frag_threshold) || |
3713b4e3 | 1295 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, |
1b8ec87a | 1296 | rdev->wiphy.rts_threshold) || |
3713b4e3 | 1297 | nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS, |
1b8ec87a | 1298 | rdev->wiphy.coverage_class) || |
3713b4e3 | 1299 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS, |
1b8ec87a | 1300 | rdev->wiphy.max_scan_ssids) || |
3713b4e3 | 1301 | nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS, |
1b8ec87a | 1302 | rdev->wiphy.max_sched_scan_ssids) || |
3713b4e3 | 1303 | nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN, |
1b8ec87a | 1304 | rdev->wiphy.max_scan_ie_len) || |
3713b4e3 | 1305 | nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN, |
1b8ec87a | 1306 | rdev->wiphy.max_sched_scan_ie_len) || |
3713b4e3 | 1307 | nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS, |
1b8ec87a | 1308 | rdev->wiphy.max_match_sets)) |
9360ffd1 | 1309 | goto nla_put_failure; |
3713b4e3 | 1310 | |
1b8ec87a | 1311 | if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) && |
3713b4e3 | 1312 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN)) |
aa430da4 | 1313 | goto nla_put_failure; |
1b8ec87a | 1314 | if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) && |
3713b4e3 JB |
1315 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH)) |
1316 | goto nla_put_failure; | |
1b8ec87a | 1317 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) && |
3713b4e3 JB |
1318 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD)) |
1319 | goto nla_put_failure; | |
1b8ec87a | 1320 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) && |
3713b4e3 JB |
1321 | nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT)) |
1322 | goto nla_put_failure; | |
1b8ec87a | 1323 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) && |
3713b4e3 JB |
1324 | nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT)) |
1325 | goto nla_put_failure; | |
1b8ec87a | 1326 | if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) && |
3713b4e3 | 1327 | nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP)) |
9360ffd1 | 1328 | goto nla_put_failure; |
86e8cf98 JB |
1329 | state->split_start++; |
1330 | if (state->split) | |
3713b4e3 JB |
1331 | break; |
1332 | case 1: | |
1333 | if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES, | |
1b8ec87a ZG |
1334 | sizeof(u32) * rdev->wiphy.n_cipher_suites, |
1335 | rdev->wiphy.cipher_suites)) | |
3713b4e3 | 1336 | goto nla_put_failure; |
4745fc09 | 1337 | |
3713b4e3 | 1338 | if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS, |
1b8ec87a | 1339 | rdev->wiphy.max_num_pmkids)) |
3713b4e3 | 1340 | goto nla_put_failure; |
b23aa676 | 1341 | |
1b8ec87a | 1342 | if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && |
3713b4e3 | 1343 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE)) |
9360ffd1 | 1344 | goto nla_put_failure; |
b23aa676 | 1345 | |
3713b4e3 | 1346 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX, |
1b8ec87a | 1347 | rdev->wiphy.available_antennas_tx) || |
3713b4e3 | 1348 | nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX, |
1b8ec87a | 1349 | rdev->wiphy.available_antennas_rx)) |
9360ffd1 | 1350 | goto nla_put_failure; |
b23aa676 | 1351 | |
1b8ec87a | 1352 | if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) && |
3713b4e3 | 1353 | nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD, |
1b8ec87a | 1354 | rdev->wiphy.probe_resp_offload)) |
3713b4e3 | 1355 | goto nla_put_failure; |
8fdc621d | 1356 | |
1b8ec87a ZG |
1357 | if ((rdev->wiphy.available_antennas_tx || |
1358 | rdev->wiphy.available_antennas_rx) && | |
1359 | rdev->ops->get_antenna) { | |
3713b4e3 JB |
1360 | u32 tx_ant = 0, rx_ant = 0; |
1361 | int res; | |
1b8ec87a | 1362 | res = rdev_get_antenna(rdev, &tx_ant, &rx_ant); |
3713b4e3 JB |
1363 | if (!res) { |
1364 | if (nla_put_u32(msg, | |
1365 | NL80211_ATTR_WIPHY_ANTENNA_TX, | |
1366 | tx_ant) || | |
1367 | nla_put_u32(msg, | |
1368 | NL80211_ATTR_WIPHY_ANTENNA_RX, | |
1369 | rx_ant)) | |
1370 | goto nla_put_failure; | |
1371 | } | |
1372 | } | |
a293911d | 1373 | |
86e8cf98 JB |
1374 | state->split_start++; |
1375 | if (state->split) | |
3713b4e3 JB |
1376 | break; |
1377 | case 2: | |
1378 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES, | |
1b8ec87a | 1379 | rdev->wiphy.interface_modes)) |
3713b4e3 | 1380 | goto nla_put_failure; |
86e8cf98 JB |
1381 | state->split_start++; |
1382 | if (state->split) | |
3713b4e3 JB |
1383 | break; |
1384 | case 3: | |
1385 | nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS); | |
1386 | if (!nl_bands) | |
1387 | goto nla_put_failure; | |
f7ca38df | 1388 | |
86e8cf98 JB |
1389 | for (band = state->band_start; |
1390 | band < IEEE80211_NUM_BANDS; band++) { | |
3713b4e3 | 1391 | struct ieee80211_supported_band *sband; |
2e161f78 | 1392 | |
1b8ec87a | 1393 | sband = rdev->wiphy.bands[band]; |
2e161f78 | 1394 | |
3713b4e3 JB |
1395 | if (!sband) |
1396 | continue; | |
1397 | ||
1398 | nl_band = nla_nest_start(msg, band); | |
1399 | if (!nl_band) | |
2e161f78 | 1400 | goto nla_put_failure; |
3713b4e3 | 1401 | |
86e8cf98 | 1402 | switch (state->chan_start) { |
3713b4e3 JB |
1403 | case 0: |
1404 | if (nl80211_send_band_rateinfo(msg, sband)) | |
9360ffd1 | 1405 | goto nla_put_failure; |
86e8cf98 JB |
1406 | state->chan_start++; |
1407 | if (state->split) | |
3713b4e3 JB |
1408 | break; |
1409 | default: | |
1410 | /* add frequencies */ | |
1411 | nl_freqs = nla_nest_start( | |
1412 | msg, NL80211_BAND_ATTR_FREQS); | |
1413 | if (!nl_freqs) | |
1414 | goto nla_put_failure; | |
1415 | ||
86e8cf98 | 1416 | for (i = state->chan_start - 1; |
3713b4e3 JB |
1417 | i < sband->n_channels; |
1418 | i++) { | |
1419 | nl_freq = nla_nest_start(msg, i); | |
1420 | if (!nl_freq) | |
1421 | goto nla_put_failure; | |
1422 | ||
1423 | chan = &sband->channels[i]; | |
1424 | ||
86e8cf98 JB |
1425 | if (nl80211_msg_put_channel( |
1426 | msg, chan, | |
1427 | state->split)) | |
3713b4e3 JB |
1428 | goto nla_put_failure; |
1429 | ||
1430 | nla_nest_end(msg, nl_freq); | |
86e8cf98 | 1431 | if (state->split) |
3713b4e3 JB |
1432 | break; |
1433 | } | |
1434 | if (i < sband->n_channels) | |
86e8cf98 | 1435 | state->chan_start = i + 2; |
3713b4e3 | 1436 | else |
86e8cf98 | 1437 | state->chan_start = 0; |
3713b4e3 JB |
1438 | nla_nest_end(msg, nl_freqs); |
1439 | } | |
1440 | ||
1441 | nla_nest_end(msg, nl_band); | |
1442 | ||
86e8cf98 | 1443 | if (state->split) { |
3713b4e3 | 1444 | /* start again here */ |
86e8cf98 | 1445 | if (state->chan_start) |
3713b4e3 JB |
1446 | band--; |
1447 | break; | |
2e161f78 | 1448 | } |
2e161f78 | 1449 | } |
3713b4e3 | 1450 | nla_nest_end(msg, nl_bands); |
2e161f78 | 1451 | |
3713b4e3 | 1452 | if (band < IEEE80211_NUM_BANDS) |
86e8cf98 | 1453 | state->band_start = band + 1; |
3713b4e3 | 1454 | else |
86e8cf98 | 1455 | state->band_start = 0; |
74b70a4e | 1456 | |
3713b4e3 | 1457 | /* if bands & channels are done, continue outside */ |
86e8cf98 JB |
1458 | if (state->band_start == 0 && state->chan_start == 0) |
1459 | state->split_start++; | |
1460 | if (state->split) | |
3713b4e3 JB |
1461 | break; |
1462 | case 4: | |
1463 | nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS); | |
1464 | if (!nl_cmds) | |
2e161f78 JB |
1465 | goto nla_put_failure; |
1466 | ||
3713b4e3 JB |
1467 | i = 0; |
1468 | #define CMD(op, n) \ | |
1469 | do { \ | |
1b8ec87a | 1470 | if (rdev->ops->op) { \ |
3713b4e3 JB |
1471 | i++; \ |
1472 | if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \ | |
1473 | goto nla_put_failure; \ | |
1474 | } \ | |
1475 | } while (0) | |
1476 | ||
1477 | CMD(add_virtual_intf, NEW_INTERFACE); | |
1478 | CMD(change_virtual_intf, SET_INTERFACE); | |
1479 | CMD(add_key, NEW_KEY); | |
1480 | CMD(start_ap, START_AP); | |
1481 | CMD(add_station, NEW_STATION); | |
1482 | CMD(add_mpath, NEW_MPATH); | |
1483 | CMD(update_mesh_config, SET_MESH_CONFIG); | |
1484 | CMD(change_bss, SET_BSS); | |
1485 | CMD(auth, AUTHENTICATE); | |
1486 | CMD(assoc, ASSOCIATE); | |
1487 | CMD(deauth, DEAUTHENTICATE); | |
1488 | CMD(disassoc, DISASSOCIATE); | |
1489 | CMD(join_ibss, JOIN_IBSS); | |
1490 | CMD(join_mesh, JOIN_MESH); | |
1491 | CMD(set_pmksa, SET_PMKSA); | |
1492 | CMD(del_pmksa, DEL_PMKSA); | |
1493 | CMD(flush_pmksa, FLUSH_PMKSA); | |
1b8ec87a | 1494 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) |
3713b4e3 JB |
1495 | CMD(remain_on_channel, REMAIN_ON_CHANNEL); |
1496 | CMD(set_bitrate_mask, SET_TX_BITRATE_MASK); | |
1497 | CMD(mgmt_tx, FRAME); | |
1498 | CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL); | |
1b8ec87a | 1499 | if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) { |
3713b4e3 JB |
1500 | i++; |
1501 | if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS)) | |
2e161f78 | 1502 | goto nla_put_failure; |
2e161f78 | 1503 | } |
1b8ec87a ZG |
1504 | if (rdev->ops->set_monitor_channel || rdev->ops->start_ap || |
1505 | rdev->ops->join_mesh) { | |
3713b4e3 JB |
1506 | i++; |
1507 | if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL)) | |
1508 | goto nla_put_failure; | |
1509 | } | |
1510 | CMD(set_wds_peer, SET_WDS_PEER); | |
1b8ec87a | 1511 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
3713b4e3 JB |
1512 | CMD(tdls_mgmt, TDLS_MGMT); |
1513 | CMD(tdls_oper, TDLS_OPER); | |
1514 | } | |
1b8ec87a | 1515 | if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) |
3713b4e3 JB |
1516 | CMD(sched_scan_start, START_SCHED_SCAN); |
1517 | CMD(probe_client, PROBE_CLIENT); | |
1518 | CMD(set_noack_map, SET_NOACK_MAP); | |
1b8ec87a | 1519 | if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) { |
3713b4e3 JB |
1520 | i++; |
1521 | if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS)) | |
1522 | goto nla_put_failure; | |
1523 | } | |
1524 | CMD(start_p2p_device, START_P2P_DEVICE); | |
1525 | CMD(set_mcast_rate, SET_MCAST_RATE); | |
02df00eb JB |
1526 | #ifdef CONFIG_NL80211_TESTMODE |
1527 | CMD(testmode_cmd, TESTMODE); | |
1528 | #endif | |
86e8cf98 | 1529 | if (state->split) { |
5de17984 AS |
1530 | CMD(crit_proto_start, CRIT_PROTOCOL_START); |
1531 | CMD(crit_proto_stop, CRIT_PROTOCOL_STOP); | |
1b8ec87a | 1532 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH) |
16ef1fe2 | 1533 | CMD(channel_switch, CHANNEL_SWITCH); |
02df00eb | 1534 | CMD(set_qos_map, SET_QOS_MAP); |
723e73ac JB |
1535 | if (rdev->wiphy.features & |
1536 | NL80211_FEATURE_SUPPORTS_WMM_ADMISSION) | |
960d01ac | 1537 | CMD(add_tx_ts, ADD_TX_TS); |
5de17984 | 1538 | } |
02df00eb | 1539 | /* add into the if now */ |
3713b4e3 | 1540 | #undef CMD |
ff1b6e69 | 1541 | |
1b8ec87a | 1542 | if (rdev->ops->connect || rdev->ops->auth) { |
3713b4e3 JB |
1543 | i++; |
1544 | if (nla_put_u32(msg, i, NL80211_CMD_CONNECT)) | |
9360ffd1 | 1545 | goto nla_put_failure; |
ff1b6e69 JB |
1546 | } |
1547 | ||
1b8ec87a | 1548 | if (rdev->ops->disconnect || rdev->ops->deauth) { |
3713b4e3 JB |
1549 | i++; |
1550 | if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT)) | |
1551 | goto nla_put_failure; | |
1552 | } | |
1553 | ||
1554 | nla_nest_end(msg, nl_cmds); | |
86e8cf98 JB |
1555 | state->split_start++; |
1556 | if (state->split) | |
3713b4e3 JB |
1557 | break; |
1558 | case 5: | |
1b8ec87a ZG |
1559 | if (rdev->ops->remain_on_channel && |
1560 | (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) && | |
3713b4e3 JB |
1561 | nla_put_u32(msg, |
1562 | NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION, | |
1b8ec87a | 1563 | rdev->wiphy.max_remain_on_channel_duration)) |
3713b4e3 JB |
1564 | goto nla_put_failure; |
1565 | ||
1b8ec87a | 1566 | if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) && |
3713b4e3 JB |
1567 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) |
1568 | goto nla_put_failure; | |
1569 | ||
1570 | if (nl80211_send_mgmt_stypes(msg, mgmt_stypes)) | |
1571 | goto nla_put_failure; | |
86e8cf98 JB |
1572 | state->split_start++; |
1573 | if (state->split) | |
3713b4e3 JB |
1574 | break; |
1575 | case 6: | |
1576 | #ifdef CONFIG_PM | |
1b8ec87a | 1577 | if (nl80211_send_wowlan(msg, rdev, state->split)) |
3713b4e3 | 1578 | goto nla_put_failure; |
86e8cf98 JB |
1579 | state->split_start++; |
1580 | if (state->split) | |
3713b4e3 JB |
1581 | break; |
1582 | #else | |
86e8cf98 | 1583 | state->split_start++; |
dfb89c56 | 1584 | #endif |
3713b4e3 JB |
1585 | case 7: |
1586 | if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES, | |
1b8ec87a | 1587 | rdev->wiphy.software_iftypes)) |
3713b4e3 | 1588 | goto nla_put_failure; |
ff1b6e69 | 1589 | |
1b8ec87a | 1590 | if (nl80211_put_iface_combinations(&rdev->wiphy, msg, |
86e8cf98 | 1591 | state->split)) |
3713b4e3 | 1592 | goto nla_put_failure; |
7527a782 | 1593 | |
86e8cf98 JB |
1594 | state->split_start++; |
1595 | if (state->split) | |
3713b4e3 JB |
1596 | break; |
1597 | case 8: | |
1b8ec87a | 1598 | if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) && |
3713b4e3 | 1599 | nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME, |
1b8ec87a | 1600 | rdev->wiphy.ap_sme_capa)) |
3713b4e3 | 1601 | goto nla_put_failure; |
7527a782 | 1602 | |
1b8ec87a | 1603 | features = rdev->wiphy.features; |
fe1abafd JB |
1604 | /* |
1605 | * We can only add the per-channel limit information if the | |
1606 | * dump is split, otherwise it makes it too big. Therefore | |
1607 | * only advertise it in that case. | |
1608 | */ | |
86e8cf98 | 1609 | if (state->split) |
fe1abafd JB |
1610 | features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS; |
1611 | if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features)) | |
3713b4e3 | 1612 | goto nla_put_failure; |
562a7480 | 1613 | |
1b8ec87a | 1614 | if (rdev->wiphy.ht_capa_mod_mask && |
3713b4e3 | 1615 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, |
1b8ec87a ZG |
1616 | sizeof(*rdev->wiphy.ht_capa_mod_mask), |
1617 | rdev->wiphy.ht_capa_mod_mask)) | |
3713b4e3 | 1618 | goto nla_put_failure; |
1f074bd8 | 1619 | |
1b8ec87a ZG |
1620 | if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME && |
1621 | rdev->wiphy.max_acl_mac_addrs && | |
3713b4e3 | 1622 | nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX, |
1b8ec87a | 1623 | rdev->wiphy.max_acl_mac_addrs)) |
3713b4e3 | 1624 | goto nla_put_failure; |
7e7c8926 | 1625 | |
3713b4e3 JB |
1626 | /* |
1627 | * Any information below this point is only available to | |
1628 | * applications that can deal with it being split. This | |
1629 | * helps ensure that newly added capabilities don't break | |
1630 | * older tools by overrunning their buffers. | |
1631 | * | |
1632 | * We still increment split_start so that in the split | |
1633 | * case we'll continue with more data in the next round, | |
1634 | * but break unconditionally so unsplit data stops here. | |
1635 | */ | |
86e8cf98 | 1636 | state->split_start++; |
3713b4e3 JB |
1637 | break; |
1638 | case 9: | |
1b8ec87a | 1639 | if (rdev->wiphy.extended_capabilities && |
fe1abafd | 1640 | (nla_put(msg, NL80211_ATTR_EXT_CAPA, |
1b8ec87a ZG |
1641 | rdev->wiphy.extended_capabilities_len, |
1642 | rdev->wiphy.extended_capabilities) || | |
fe1abafd | 1643 | nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK, |
1b8ec87a ZG |
1644 | rdev->wiphy.extended_capabilities_len, |
1645 | rdev->wiphy.extended_capabilities_mask))) | |
fe1abafd | 1646 | goto nla_put_failure; |
a50df0c4 | 1647 | |
1b8ec87a | 1648 | if (rdev->wiphy.vht_capa_mod_mask && |
ee2aca34 | 1649 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, |
1b8ec87a ZG |
1650 | sizeof(*rdev->wiphy.vht_capa_mod_mask), |
1651 | rdev->wiphy.vht_capa_mod_mask)) | |
ee2aca34 JB |
1652 | goto nla_put_failure; |
1653 | ||
be29b99a AK |
1654 | state->split_start++; |
1655 | break; | |
1656 | case 10: | |
1b8ec87a | 1657 | if (nl80211_send_coalesce(msg, rdev)) |
be29b99a AK |
1658 | goto nla_put_failure; |
1659 | ||
1b8ec87a | 1660 | if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) && |
01e0daa4 FF |
1661 | (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) || |
1662 | nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ))) | |
1663 | goto nla_put_failure; | |
b43504cf | 1664 | |
1b8ec87a | 1665 | if (rdev->wiphy.max_ap_assoc_sta && |
b43504cf | 1666 | nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA, |
1b8ec87a | 1667 | rdev->wiphy.max_ap_assoc_sta)) |
b43504cf JM |
1668 | goto nla_put_failure; |
1669 | ||
ad7e718c JB |
1670 | state->split_start++; |
1671 | break; | |
1672 | case 11: | |
1b8ec87a | 1673 | if (rdev->wiphy.n_vendor_commands) { |
567ffc35 JB |
1674 | const struct nl80211_vendor_cmd_info *info; |
1675 | struct nlattr *nested; | |
1676 | ||
1677 | nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | |
1678 | if (!nested) | |
1679 | goto nla_put_failure; | |
1680 | ||
1b8ec87a ZG |
1681 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { |
1682 | info = &rdev->wiphy.vendor_commands[i].info; | |
567ffc35 JB |
1683 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1684 | goto nla_put_failure; | |
1685 | } | |
1686 | nla_nest_end(msg, nested); | |
1687 | } | |
1688 | ||
1b8ec87a | 1689 | if (rdev->wiphy.n_vendor_events) { |
567ffc35 JB |
1690 | const struct nl80211_vendor_cmd_info *info; |
1691 | struct nlattr *nested; | |
ad7e718c | 1692 | |
567ffc35 JB |
1693 | nested = nla_nest_start(msg, |
1694 | NL80211_ATTR_VENDOR_EVENTS); | |
1695 | if (!nested) | |
ad7e718c | 1696 | goto nla_put_failure; |
567ffc35 | 1697 | |
1b8ec87a ZG |
1698 | for (i = 0; i < rdev->wiphy.n_vendor_events; i++) { |
1699 | info = &rdev->wiphy.vendor_events[i]; | |
567ffc35 JB |
1700 | if (nla_put(msg, i + 1, sizeof(*info), info)) |
1701 | goto nla_put_failure; | |
1702 | } | |
1703 | nla_nest_end(msg, nested); | |
1704 | } | |
9a774c78 AO |
1705 | state->split_start++; |
1706 | break; | |
1707 | case 12: | |
1708 | if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH && | |
1709 | nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS, | |
1710 | rdev->wiphy.max_num_csa_counters)) | |
1711 | goto nla_put_failure; | |
01e0daa4 | 1712 | |
1bdd716c AN |
1713 | if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
1714 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
1715 | goto nla_put_failure; | |
1716 | ||
d75bb06b GKS |
1717 | if (nla_put(msg, NL80211_ATTR_EXT_FEATURES, |
1718 | sizeof(rdev->wiphy.ext_features), | |
1719 | rdev->wiphy.ext_features)) | |
1720 | goto nla_put_failure; | |
1721 | ||
3713b4e3 | 1722 | /* done */ |
86e8cf98 | 1723 | state->split_start = 0; |
3713b4e3 JB |
1724 | break; |
1725 | } | |
3bb20556 | 1726 | finish: |
053c095a JB |
1727 | genlmsg_end(msg, hdr); |
1728 | return 0; | |
55682965 JB |
1729 | |
1730 | nla_put_failure: | |
bc3ed28c TG |
1731 | genlmsg_cancel(msg, hdr); |
1732 | return -EMSGSIZE; | |
55682965 JB |
1733 | } |
1734 | ||
86e8cf98 JB |
1735 | static int nl80211_dump_wiphy_parse(struct sk_buff *skb, |
1736 | struct netlink_callback *cb, | |
1737 | struct nl80211_dump_wiphy_state *state) | |
1738 | { | |
1739 | struct nlattr **tb = nl80211_fam.attrbuf; | |
1740 | int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
1741 | tb, nl80211_fam.maxattr, nl80211_policy); | |
1742 | /* ignore parse errors for backward compatibility */ | |
1743 | if (ret) | |
1744 | return 0; | |
1745 | ||
1746 | state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP]; | |
1747 | if (tb[NL80211_ATTR_WIPHY]) | |
1748 | state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | |
1749 | if (tb[NL80211_ATTR_WDEV]) | |
1750 | state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32; | |
1751 | if (tb[NL80211_ATTR_IFINDEX]) { | |
1752 | struct net_device *netdev; | |
1753 | struct cfg80211_registered_device *rdev; | |
1754 | int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | |
1755 | ||
7f2b8562 | 1756 | netdev = __dev_get_by_index(sock_net(skb->sk), ifidx); |
86e8cf98 JB |
1757 | if (!netdev) |
1758 | return -ENODEV; | |
1759 | if (netdev->ieee80211_ptr) { | |
f26cbf40 | 1760 | rdev = wiphy_to_rdev( |
86e8cf98 JB |
1761 | netdev->ieee80211_ptr->wiphy); |
1762 | state->filter_wiphy = rdev->wiphy_idx; | |
1763 | } | |
86e8cf98 JB |
1764 | } |
1765 | ||
1766 | return 0; | |
1767 | } | |
1768 | ||
55682965 JB |
1769 | static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb) |
1770 | { | |
645e77de | 1771 | int idx = 0, ret; |
86e8cf98 | 1772 | struct nl80211_dump_wiphy_state *state = (void *)cb->args[0]; |
1b8ec87a | 1773 | struct cfg80211_registered_device *rdev; |
3a5a423b | 1774 | |
5fe231e8 | 1775 | rtnl_lock(); |
86e8cf98 JB |
1776 | if (!state) { |
1777 | state = kzalloc(sizeof(*state), GFP_KERNEL); | |
57ed5cd6 JL |
1778 | if (!state) { |
1779 | rtnl_unlock(); | |
86e8cf98 | 1780 | return -ENOMEM; |
3713b4e3 | 1781 | } |
86e8cf98 JB |
1782 | state->filter_wiphy = -1; |
1783 | ret = nl80211_dump_wiphy_parse(skb, cb, state); | |
1784 | if (ret) { | |
1785 | kfree(state); | |
1786 | rtnl_unlock(); | |
1787 | return ret; | |
3713b4e3 | 1788 | } |
86e8cf98 | 1789 | cb->args[0] = (long)state; |
3713b4e3 JB |
1790 | } |
1791 | ||
1b8ec87a ZG |
1792 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
1793 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 1794 | continue; |
86e8cf98 | 1795 | if (++idx <= state->start) |
55682965 | 1796 | continue; |
86e8cf98 | 1797 | if (state->filter_wiphy != -1 && |
1b8ec87a | 1798 | state->filter_wiphy != rdev->wiphy_idx) |
3713b4e3 JB |
1799 | continue; |
1800 | /* attempt to fit multiple wiphy data chunks into the skb */ | |
1801 | do { | |
3bb20556 JB |
1802 | ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, |
1803 | skb, | |
3713b4e3 JB |
1804 | NETLINK_CB(cb->skb).portid, |
1805 | cb->nlh->nlmsg_seq, | |
86e8cf98 | 1806 | NLM_F_MULTI, state); |
3713b4e3 JB |
1807 | if (ret < 0) { |
1808 | /* | |
1809 | * If sending the wiphy data didn't fit (ENOBUFS | |
1810 | * or EMSGSIZE returned), this SKB is still | |
1811 | * empty (so it's not too big because another | |
1812 | * wiphy dataset is already in the skb) and | |
1813 | * we've not tried to adjust the dump allocation | |
1814 | * yet ... then adjust the alloc size to be | |
1815 | * bigger, and return 1 but with the empty skb. | |
1816 | * This results in an empty message being RX'ed | |
1817 | * in userspace, but that is ignored. | |
1818 | * | |
1819 | * We can then retry with the larger buffer. | |
1820 | */ | |
1821 | if ((ret == -ENOBUFS || ret == -EMSGSIZE) && | |
f12cb289 | 1822 | !skb->len && !state->split && |
3713b4e3 JB |
1823 | cb->min_dump_alloc < 4096) { |
1824 | cb->min_dump_alloc = 4096; | |
f12cb289 | 1825 | state->split_start = 0; |
d98cae64 | 1826 | rtnl_unlock(); |
3713b4e3 JB |
1827 | return 1; |
1828 | } | |
1829 | idx--; | |
1830 | break; | |
645e77de | 1831 | } |
86e8cf98 | 1832 | } while (state->split_start > 0); |
3713b4e3 | 1833 | break; |
55682965 | 1834 | } |
5fe231e8 | 1835 | rtnl_unlock(); |
55682965 | 1836 | |
86e8cf98 | 1837 | state->start = idx; |
55682965 JB |
1838 | |
1839 | return skb->len; | |
1840 | } | |
1841 | ||
86e8cf98 JB |
1842 | static int nl80211_dump_wiphy_done(struct netlink_callback *cb) |
1843 | { | |
1844 | kfree((void *)cb->args[0]); | |
1845 | return 0; | |
1846 | } | |
1847 | ||
55682965 JB |
1848 | static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info) |
1849 | { | |
1850 | struct sk_buff *msg; | |
1b8ec87a | 1851 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
86e8cf98 | 1852 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 1853 | |
645e77de | 1854 | msg = nlmsg_new(4096, GFP_KERNEL); |
55682965 | 1855 | if (!msg) |
4c476991 | 1856 | return -ENOMEM; |
55682965 | 1857 | |
3bb20556 JB |
1858 | if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg, |
1859 | info->snd_portid, info->snd_seq, 0, | |
86e8cf98 | 1860 | &state) < 0) { |
4c476991 JB |
1861 | nlmsg_free(msg); |
1862 | return -ENOBUFS; | |
1863 | } | |
55682965 | 1864 | |
134e6375 | 1865 | return genlmsg_reply(msg, info); |
55682965 JB |
1866 | } |
1867 | ||
31888487 JM |
1868 | static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = { |
1869 | [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 }, | |
1870 | [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 }, | |
1871 | [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 }, | |
1872 | [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 }, | |
1873 | [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 }, | |
1874 | }; | |
1875 | ||
1876 | static int parse_txq_params(struct nlattr *tb[], | |
1877 | struct ieee80211_txq_params *txq_params) | |
1878 | { | |
a3304b0a | 1879 | if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] || |
31888487 JM |
1880 | !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] || |
1881 | !tb[NL80211_TXQ_ATTR_AIFS]) | |
1882 | return -EINVAL; | |
1883 | ||
a3304b0a | 1884 | txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]); |
31888487 JM |
1885 | txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]); |
1886 | txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]); | |
1887 | txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]); | |
1888 | txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]); | |
1889 | ||
a3304b0a JB |
1890 | if (txq_params->ac >= NL80211_NUM_ACS) |
1891 | return -EINVAL; | |
1892 | ||
31888487 JM |
1893 | return 0; |
1894 | } | |
1895 | ||
f444de05 JB |
1896 | static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev) |
1897 | { | |
1898 | /* | |
cc1d2806 JB |
1899 | * You can only set the channel explicitly for WDS interfaces, |
1900 | * all others have their channel managed via their respective | |
1901 | * "establish a connection" command (connect, join, ...) | |
1902 | * | |
1903 | * For AP/GO and mesh mode, the channel can be set with the | |
1904 | * channel userspace API, but is only stored and passed to the | |
1905 | * low-level driver when the AP starts or the mesh is joined. | |
1906 | * This is for backward compatibility, userspace can also give | |
1907 | * the channel in the start-ap or join-mesh commands instead. | |
f444de05 JB |
1908 | * |
1909 | * Monitors are special as they are normally slaved to | |
e8c9bd5b JB |
1910 | * whatever else is going on, so they have their own special |
1911 | * operation to set the monitor channel if possible. | |
f444de05 JB |
1912 | */ |
1913 | return !wdev || | |
1914 | wdev->iftype == NL80211_IFTYPE_AP || | |
f444de05 | 1915 | wdev->iftype == NL80211_IFTYPE_MESH_POINT || |
074ac8df JB |
1916 | wdev->iftype == NL80211_IFTYPE_MONITOR || |
1917 | wdev->iftype == NL80211_IFTYPE_P2P_GO; | |
f444de05 JB |
1918 | } |
1919 | ||
683b6d3b JB |
1920 | static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev, |
1921 | struct genl_info *info, | |
1922 | struct cfg80211_chan_def *chandef) | |
1923 | { | |
dbeca2ea | 1924 | u32 control_freq; |
683b6d3b JB |
1925 | |
1926 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
1927 | return -EINVAL; | |
1928 | ||
1929 | control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
1930 | ||
1931 | chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq); | |
3d9d1d66 JB |
1932 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
1933 | chandef->center_freq1 = control_freq; | |
1934 | chandef->center_freq2 = 0; | |
683b6d3b JB |
1935 | |
1936 | /* Primary channel not allowed */ | |
1937 | if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED) | |
1938 | return -EINVAL; | |
1939 | ||
3d9d1d66 JB |
1940 | if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
1941 | enum nl80211_channel_type chantype; | |
1942 | ||
1943 | chantype = nla_get_u32( | |
1944 | info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | |
1945 | ||
1946 | switch (chantype) { | |
1947 | case NL80211_CHAN_NO_HT: | |
1948 | case NL80211_CHAN_HT20: | |
1949 | case NL80211_CHAN_HT40PLUS: | |
1950 | case NL80211_CHAN_HT40MINUS: | |
1951 | cfg80211_chandef_create(chandef, chandef->chan, | |
1952 | chantype); | |
1953 | break; | |
1954 | default: | |
1955 | return -EINVAL; | |
1956 | } | |
1957 | } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) { | |
1958 | chandef->width = | |
1959 | nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]); | |
1960 | if (info->attrs[NL80211_ATTR_CENTER_FREQ1]) | |
1961 | chandef->center_freq1 = | |
1962 | nla_get_u32( | |
1963 | info->attrs[NL80211_ATTR_CENTER_FREQ1]); | |
1964 | if (info->attrs[NL80211_ATTR_CENTER_FREQ2]) | |
1965 | chandef->center_freq2 = | |
1966 | nla_get_u32( | |
1967 | info->attrs[NL80211_ATTR_CENTER_FREQ2]); | |
1968 | } | |
1969 | ||
9f5e8f6e | 1970 | if (!cfg80211_chandef_valid(chandef)) |
3d9d1d66 JB |
1971 | return -EINVAL; |
1972 | ||
9f5e8f6e JB |
1973 | if (!cfg80211_chandef_usable(&rdev->wiphy, chandef, |
1974 | IEEE80211_CHAN_DISABLED)) | |
3d9d1d66 JB |
1975 | return -EINVAL; |
1976 | ||
2f301ab2 SW |
1977 | if ((chandef->width == NL80211_CHAN_WIDTH_5 || |
1978 | chandef->width == NL80211_CHAN_WIDTH_10) && | |
1979 | !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ)) | |
1980 | return -EINVAL; | |
1981 | ||
683b6d3b JB |
1982 | return 0; |
1983 | } | |
1984 | ||
f444de05 | 1985 | static int __nl80211_set_channel(struct cfg80211_registered_device *rdev, |
e16821bc | 1986 | struct net_device *dev, |
f444de05 JB |
1987 | struct genl_info *info) |
1988 | { | |
683b6d3b | 1989 | struct cfg80211_chan_def chandef; |
f444de05 | 1990 | int result; |
e8c9bd5b | 1991 | enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR; |
e16821bc | 1992 | struct wireless_dev *wdev = NULL; |
e8c9bd5b | 1993 | |
e16821bc JM |
1994 | if (dev) |
1995 | wdev = dev->ieee80211_ptr; | |
f444de05 JB |
1996 | if (!nl80211_can_set_dev_channel(wdev)) |
1997 | return -EOPNOTSUPP; | |
e16821bc JM |
1998 | if (wdev) |
1999 | iftype = wdev->iftype; | |
f444de05 | 2000 | |
683b6d3b JB |
2001 | result = nl80211_parse_chandef(rdev, info, &chandef); |
2002 | if (result) | |
2003 | return result; | |
f444de05 | 2004 | |
e8c9bd5b | 2005 | switch (iftype) { |
aa430da4 JB |
2006 | case NL80211_IFTYPE_AP: |
2007 | case NL80211_IFTYPE_P2P_GO: | |
174e0cd2 | 2008 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) { |
aa430da4 JB |
2009 | result = -EINVAL; |
2010 | break; | |
2011 | } | |
e16821bc JM |
2012 | if (wdev->beacon_interval) { |
2013 | if (!dev || !rdev->ops->set_ap_chanwidth || | |
2014 | !(rdev->wiphy.features & | |
2015 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) { | |
2016 | result = -EBUSY; | |
2017 | break; | |
2018 | } | |
2019 | ||
2020 | /* Only allow dynamic channel width changes */ | |
2021 | if (chandef.chan != wdev->preset_chandef.chan) { | |
2022 | result = -EBUSY; | |
2023 | break; | |
2024 | } | |
2025 | result = rdev_set_ap_chanwidth(rdev, dev, &chandef); | |
2026 | if (result) | |
2027 | break; | |
2028 | } | |
683b6d3b | 2029 | wdev->preset_chandef = chandef; |
aa430da4 JB |
2030 | result = 0; |
2031 | break; | |
cc1d2806 | 2032 | case NL80211_IFTYPE_MESH_POINT: |
683b6d3b | 2033 | result = cfg80211_set_mesh_channel(rdev, wdev, &chandef); |
cc1d2806 | 2034 | break; |
e8c9bd5b | 2035 | case NL80211_IFTYPE_MONITOR: |
683b6d3b | 2036 | result = cfg80211_set_monitor_channel(rdev, &chandef); |
e8c9bd5b | 2037 | break; |
aa430da4 | 2038 | default: |
e8c9bd5b | 2039 | result = -EINVAL; |
f444de05 | 2040 | } |
f444de05 JB |
2041 | |
2042 | return result; | |
2043 | } | |
2044 | ||
2045 | static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info) | |
2046 | { | |
4c476991 JB |
2047 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2048 | struct net_device *netdev = info->user_ptr[1]; | |
f444de05 | 2049 | |
e16821bc | 2050 | return __nl80211_set_channel(rdev, netdev, info); |
f444de05 JB |
2051 | } |
2052 | ||
e8347eba BJ |
2053 | static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info) |
2054 | { | |
43b19952 JB |
2055 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2056 | struct net_device *dev = info->user_ptr[1]; | |
2057 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
388ac775 | 2058 | const u8 *bssid; |
e8347eba BJ |
2059 | |
2060 | if (!info->attrs[NL80211_ATTR_MAC]) | |
2061 | return -EINVAL; | |
2062 | ||
43b19952 JB |
2063 | if (netif_running(dev)) |
2064 | return -EBUSY; | |
e8347eba | 2065 | |
43b19952 JB |
2066 | if (!rdev->ops->set_wds_peer) |
2067 | return -EOPNOTSUPP; | |
e8347eba | 2068 | |
43b19952 JB |
2069 | if (wdev->iftype != NL80211_IFTYPE_WDS) |
2070 | return -EOPNOTSUPP; | |
e8347eba BJ |
2071 | |
2072 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
e35e4d28 | 2073 | return rdev_set_wds_peer(rdev, dev, bssid); |
e8347eba BJ |
2074 | } |
2075 | ||
2076 | ||
55682965 JB |
2077 | static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info) |
2078 | { | |
2079 | struct cfg80211_registered_device *rdev; | |
f444de05 JB |
2080 | struct net_device *netdev = NULL; |
2081 | struct wireless_dev *wdev; | |
a1e567c8 | 2082 | int result = 0, rem_txq_params = 0; |
31888487 | 2083 | struct nlattr *nl_txq_params; |
b9a5f8ca JM |
2084 | u32 changed; |
2085 | u8 retry_short = 0, retry_long = 0; | |
2086 | u32 frag_threshold = 0, rts_threshold = 0; | |
81077e82 | 2087 | u8 coverage_class = 0; |
55682965 | 2088 | |
5fe231e8 JB |
2089 | ASSERT_RTNL(); |
2090 | ||
f444de05 JB |
2091 | /* |
2092 | * Try to find the wiphy and netdev. Normally this | |
2093 | * function shouldn't need the netdev, but this is | |
2094 | * done for backward compatibility -- previously | |
2095 | * setting the channel was done per wiphy, but now | |
2096 | * it is per netdev. Previous userland like hostapd | |
2097 | * also passed a netdev to set_wiphy, so that it is | |
2098 | * possible to let that go to the right netdev! | |
2099 | */ | |
4bbf4d56 | 2100 | |
f444de05 JB |
2101 | if (info->attrs[NL80211_ATTR_IFINDEX]) { |
2102 | int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]); | |
2103 | ||
7f2b8562 | 2104 | netdev = __dev_get_by_index(genl_info_net(info), ifindex); |
5fe231e8 | 2105 | if (netdev && netdev->ieee80211_ptr) |
f26cbf40 | 2106 | rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy); |
5fe231e8 | 2107 | else |
f444de05 | 2108 | netdev = NULL; |
4bbf4d56 JB |
2109 | } |
2110 | ||
f444de05 | 2111 | if (!netdev) { |
878d9ec7 JB |
2112 | rdev = __cfg80211_rdev_from_attrs(genl_info_net(info), |
2113 | info->attrs); | |
5fe231e8 | 2114 | if (IS_ERR(rdev)) |
4c476991 | 2115 | return PTR_ERR(rdev); |
f444de05 JB |
2116 | wdev = NULL; |
2117 | netdev = NULL; | |
2118 | result = 0; | |
71fe96bf | 2119 | } else |
f444de05 | 2120 | wdev = netdev->ieee80211_ptr; |
f444de05 JB |
2121 | |
2122 | /* | |
2123 | * end workaround code, by now the rdev is available | |
2124 | * and locked, and wdev may or may not be NULL. | |
2125 | */ | |
4bbf4d56 JB |
2126 | |
2127 | if (info->attrs[NL80211_ATTR_WIPHY_NAME]) | |
31888487 JM |
2128 | result = cfg80211_dev_rename( |
2129 | rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME])); | |
4bbf4d56 | 2130 | |
4bbf4d56 | 2131 | if (result) |
7f2b8562 | 2132 | return result; |
31888487 JM |
2133 | |
2134 | if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) { | |
2135 | struct ieee80211_txq_params txq_params; | |
2136 | struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1]; | |
2137 | ||
7f2b8562 YX |
2138 | if (!rdev->ops->set_txq_params) |
2139 | return -EOPNOTSUPP; | |
31888487 | 2140 | |
7f2b8562 YX |
2141 | if (!netdev) |
2142 | return -EINVAL; | |
f70f01c2 | 2143 | |
133a3ff2 | 2144 | if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
7f2b8562 YX |
2145 | netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
2146 | return -EINVAL; | |
133a3ff2 | 2147 | |
7f2b8562 YX |
2148 | if (!netif_running(netdev)) |
2149 | return -ENETDOWN; | |
2b5f8b0b | 2150 | |
31888487 JM |
2151 | nla_for_each_nested(nl_txq_params, |
2152 | info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS], | |
2153 | rem_txq_params) { | |
ae811e21 JB |
2154 | result = nla_parse(tb, NL80211_TXQ_ATTR_MAX, |
2155 | nla_data(nl_txq_params), | |
2156 | nla_len(nl_txq_params), | |
2157 | txq_params_policy); | |
2158 | if (result) | |
2159 | return result; | |
31888487 JM |
2160 | result = parse_txq_params(tb, &txq_params); |
2161 | if (result) | |
7f2b8562 | 2162 | return result; |
31888487 | 2163 | |
e35e4d28 HG |
2164 | result = rdev_set_txq_params(rdev, netdev, |
2165 | &txq_params); | |
31888487 | 2166 | if (result) |
7f2b8562 | 2167 | return result; |
31888487 JM |
2168 | } |
2169 | } | |
55682965 | 2170 | |
72bdcf34 | 2171 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
e16821bc JM |
2172 | result = __nl80211_set_channel( |
2173 | rdev, | |
2174 | nl80211_can_set_dev_channel(wdev) ? netdev : NULL, | |
2175 | info); | |
72bdcf34 | 2176 | if (result) |
7f2b8562 | 2177 | return result; |
72bdcf34 JM |
2178 | } |
2179 | ||
98d2ff8b | 2180 | if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) { |
c8442118 | 2181 | struct wireless_dev *txp_wdev = wdev; |
98d2ff8b JO |
2182 | enum nl80211_tx_power_setting type; |
2183 | int idx, mbm = 0; | |
2184 | ||
c8442118 JB |
2185 | if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER)) |
2186 | txp_wdev = NULL; | |
2187 | ||
7f2b8562 YX |
2188 | if (!rdev->ops->set_tx_power) |
2189 | return -EOPNOTSUPP; | |
98d2ff8b JO |
2190 | |
2191 | idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING; | |
2192 | type = nla_get_u32(info->attrs[idx]); | |
2193 | ||
2194 | if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] && | |
7f2b8562 YX |
2195 | (type != NL80211_TX_POWER_AUTOMATIC)) |
2196 | return -EINVAL; | |
98d2ff8b JO |
2197 | |
2198 | if (type != NL80211_TX_POWER_AUTOMATIC) { | |
2199 | idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL; | |
2200 | mbm = nla_get_u32(info->attrs[idx]); | |
2201 | } | |
2202 | ||
c8442118 | 2203 | result = rdev_set_tx_power(rdev, txp_wdev, type, mbm); |
98d2ff8b | 2204 | if (result) |
7f2b8562 | 2205 | return result; |
98d2ff8b JO |
2206 | } |
2207 | ||
afe0cbf8 BR |
2208 | if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] && |
2209 | info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) { | |
2210 | u32 tx_ant, rx_ant; | |
7f531e03 BR |
2211 | if ((!rdev->wiphy.available_antennas_tx && |
2212 | !rdev->wiphy.available_antennas_rx) || | |
7f2b8562 YX |
2213 | !rdev->ops->set_antenna) |
2214 | return -EOPNOTSUPP; | |
afe0cbf8 BR |
2215 | |
2216 | tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]); | |
2217 | rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]); | |
2218 | ||
a7ffac95 | 2219 | /* reject antenna configurations which don't match the |
7f531e03 BR |
2220 | * available antenna masks, except for the "all" mask */ |
2221 | if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) || | |
7f2b8562 YX |
2222 | (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx))) |
2223 | return -EINVAL; | |
a7ffac95 | 2224 | |
7f531e03 BR |
2225 | tx_ant = tx_ant & rdev->wiphy.available_antennas_tx; |
2226 | rx_ant = rx_ant & rdev->wiphy.available_antennas_rx; | |
a7ffac95 | 2227 | |
e35e4d28 | 2228 | result = rdev_set_antenna(rdev, tx_ant, rx_ant); |
afe0cbf8 | 2229 | if (result) |
7f2b8562 | 2230 | return result; |
afe0cbf8 BR |
2231 | } |
2232 | ||
b9a5f8ca JM |
2233 | changed = 0; |
2234 | ||
2235 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) { | |
2236 | retry_short = nla_get_u8( | |
2237 | info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]); | |
7f2b8562 YX |
2238 | if (retry_short == 0) |
2239 | return -EINVAL; | |
2240 | ||
b9a5f8ca JM |
2241 | changed |= WIPHY_PARAM_RETRY_SHORT; |
2242 | } | |
2243 | ||
2244 | if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) { | |
2245 | retry_long = nla_get_u8( | |
2246 | info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]); | |
7f2b8562 YX |
2247 | if (retry_long == 0) |
2248 | return -EINVAL; | |
2249 | ||
b9a5f8ca JM |
2250 | changed |= WIPHY_PARAM_RETRY_LONG; |
2251 | } | |
2252 | ||
2253 | if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) { | |
2254 | frag_threshold = nla_get_u32( | |
2255 | info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]); | |
7f2b8562 YX |
2256 | if (frag_threshold < 256) |
2257 | return -EINVAL; | |
2258 | ||
b9a5f8ca JM |
2259 | if (frag_threshold != (u32) -1) { |
2260 | /* | |
2261 | * Fragments (apart from the last one) are required to | |
2262 | * have even length. Make the fragmentation code | |
2263 | * simpler by stripping LSB should someone try to use | |
2264 | * odd threshold value. | |
2265 | */ | |
2266 | frag_threshold &= ~0x1; | |
2267 | } | |
2268 | changed |= WIPHY_PARAM_FRAG_THRESHOLD; | |
2269 | } | |
2270 | ||
2271 | if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) { | |
2272 | rts_threshold = nla_get_u32( | |
2273 | info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]); | |
2274 | changed |= WIPHY_PARAM_RTS_THRESHOLD; | |
2275 | } | |
2276 | ||
81077e82 | 2277 | if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) { |
3057dbfd LB |
2278 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) |
2279 | return -EINVAL; | |
2280 | ||
81077e82 LT |
2281 | coverage_class = nla_get_u8( |
2282 | info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]); | |
2283 | changed |= WIPHY_PARAM_COVERAGE_CLASS; | |
2284 | } | |
2285 | ||
3057dbfd LB |
2286 | if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) { |
2287 | if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION)) | |
2288 | return -EOPNOTSUPP; | |
2289 | ||
2290 | changed |= WIPHY_PARAM_DYN_ACK; | |
81077e82 LT |
2291 | } |
2292 | ||
b9a5f8ca JM |
2293 | if (changed) { |
2294 | u8 old_retry_short, old_retry_long; | |
2295 | u32 old_frag_threshold, old_rts_threshold; | |
81077e82 | 2296 | u8 old_coverage_class; |
b9a5f8ca | 2297 | |
7f2b8562 YX |
2298 | if (!rdev->ops->set_wiphy_params) |
2299 | return -EOPNOTSUPP; | |
b9a5f8ca JM |
2300 | |
2301 | old_retry_short = rdev->wiphy.retry_short; | |
2302 | old_retry_long = rdev->wiphy.retry_long; | |
2303 | old_frag_threshold = rdev->wiphy.frag_threshold; | |
2304 | old_rts_threshold = rdev->wiphy.rts_threshold; | |
81077e82 | 2305 | old_coverage_class = rdev->wiphy.coverage_class; |
b9a5f8ca JM |
2306 | |
2307 | if (changed & WIPHY_PARAM_RETRY_SHORT) | |
2308 | rdev->wiphy.retry_short = retry_short; | |
2309 | if (changed & WIPHY_PARAM_RETRY_LONG) | |
2310 | rdev->wiphy.retry_long = retry_long; | |
2311 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) | |
2312 | rdev->wiphy.frag_threshold = frag_threshold; | |
2313 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) | |
2314 | rdev->wiphy.rts_threshold = rts_threshold; | |
81077e82 LT |
2315 | if (changed & WIPHY_PARAM_COVERAGE_CLASS) |
2316 | rdev->wiphy.coverage_class = coverage_class; | |
b9a5f8ca | 2317 | |
e35e4d28 | 2318 | result = rdev_set_wiphy_params(rdev, changed); |
b9a5f8ca JM |
2319 | if (result) { |
2320 | rdev->wiphy.retry_short = old_retry_short; | |
2321 | rdev->wiphy.retry_long = old_retry_long; | |
2322 | rdev->wiphy.frag_threshold = old_frag_threshold; | |
2323 | rdev->wiphy.rts_threshold = old_rts_threshold; | |
81077e82 | 2324 | rdev->wiphy.coverage_class = old_coverage_class; |
b9a5f8ca JM |
2325 | } |
2326 | } | |
7f2b8562 | 2327 | return 0; |
55682965 JB |
2328 | } |
2329 | ||
71bbc994 JB |
2330 | static inline u64 wdev_id(struct wireless_dev *wdev) |
2331 | { | |
2332 | return (u64)wdev->identifier | | |
f26cbf40 | 2333 | ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32); |
71bbc994 | 2334 | } |
55682965 | 2335 | |
683b6d3b | 2336 | static int nl80211_send_chandef(struct sk_buff *msg, |
d2859df5 | 2337 | const struct cfg80211_chan_def *chandef) |
683b6d3b | 2338 | { |
601555cd JB |
2339 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
2340 | return -EINVAL; | |
3d9d1d66 | 2341 | |
683b6d3b JB |
2342 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
2343 | chandef->chan->center_freq)) | |
2344 | return -ENOBUFS; | |
3d9d1d66 JB |
2345 | switch (chandef->width) { |
2346 | case NL80211_CHAN_WIDTH_20_NOHT: | |
2347 | case NL80211_CHAN_WIDTH_20: | |
2348 | case NL80211_CHAN_WIDTH_40: | |
2349 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | |
2350 | cfg80211_get_chandef_type(chandef))) | |
2351 | return -ENOBUFS; | |
2352 | break; | |
2353 | default: | |
2354 | break; | |
2355 | } | |
2356 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width)) | |
2357 | return -ENOBUFS; | |
2358 | if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1)) | |
2359 | return -ENOBUFS; | |
2360 | if (chandef->center_freq2 && | |
2361 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2)) | |
683b6d3b JB |
2362 | return -ENOBUFS; |
2363 | return 0; | |
2364 | } | |
2365 | ||
15e47304 | 2366 | static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags, |
d726405a | 2367 | struct cfg80211_registered_device *rdev, |
8f894be2 | 2368 | struct wireless_dev *wdev, bool removal) |
55682965 | 2369 | { |
72fb2abc | 2370 | struct net_device *dev = wdev->netdev; |
8f894be2 | 2371 | u8 cmd = NL80211_CMD_NEW_INTERFACE; |
55682965 JB |
2372 | void *hdr; |
2373 | ||
8f894be2 TB |
2374 | if (removal) |
2375 | cmd = NL80211_CMD_DEL_INTERFACE; | |
2376 | ||
2377 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); | |
55682965 JB |
2378 | if (!hdr) |
2379 | return -1; | |
2380 | ||
72fb2abc JB |
2381 | if (dev && |
2382 | (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
98104fde | 2383 | nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name))) |
72fb2abc JB |
2384 | goto nla_put_failure; |
2385 | ||
2386 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
2387 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) || | |
71bbc994 | 2388 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
98104fde | 2389 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) || |
9360ffd1 DM |
2390 | nla_put_u32(msg, NL80211_ATTR_GENERATION, |
2391 | rdev->devlist_generation ^ | |
2392 | (cfg80211_rdev_list_generation << 2))) | |
2393 | goto nla_put_failure; | |
f5ea9120 | 2394 | |
5b7ccaf3 | 2395 | if (rdev->ops->get_channel) { |
683b6d3b JB |
2396 | int ret; |
2397 | struct cfg80211_chan_def chandef; | |
2398 | ||
2399 | ret = rdev_get_channel(rdev, wdev, &chandef); | |
2400 | if (ret == 0) { | |
2401 | if (nl80211_send_chandef(msg, &chandef)) | |
2402 | goto nla_put_failure; | |
2403 | } | |
d91df0e3 PF |
2404 | } |
2405 | ||
b84e7a05 AQ |
2406 | if (wdev->ssid_len) { |
2407 | if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid)) | |
2408 | goto nla_put_failure; | |
2409 | } | |
2410 | ||
053c095a JB |
2411 | genlmsg_end(msg, hdr); |
2412 | return 0; | |
55682965 JB |
2413 | |
2414 | nla_put_failure: | |
bc3ed28c TG |
2415 | genlmsg_cancel(msg, hdr); |
2416 | return -EMSGSIZE; | |
55682965 JB |
2417 | } |
2418 | ||
2419 | static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb) | |
2420 | { | |
2421 | int wp_idx = 0; | |
2422 | int if_idx = 0; | |
2423 | int wp_start = cb->args[0]; | |
2424 | int if_start = cb->args[1]; | |
f5ea9120 | 2425 | struct cfg80211_registered_device *rdev; |
55682965 JB |
2426 | struct wireless_dev *wdev; |
2427 | ||
5fe231e8 | 2428 | rtnl_lock(); |
f5ea9120 JB |
2429 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { |
2430 | if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk))) | |
463d0183 | 2431 | continue; |
bba95fef JB |
2432 | if (wp_idx < wp_start) { |
2433 | wp_idx++; | |
55682965 | 2434 | continue; |
bba95fef | 2435 | } |
55682965 JB |
2436 | if_idx = 0; |
2437 | ||
89a54e48 | 2438 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
bba95fef JB |
2439 | if (if_idx < if_start) { |
2440 | if_idx++; | |
55682965 | 2441 | continue; |
bba95fef | 2442 | } |
15e47304 | 2443 | if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid, |
55682965 | 2444 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
8f894be2 | 2445 | rdev, wdev, false) < 0) { |
bba95fef JB |
2446 | goto out; |
2447 | } | |
2448 | if_idx++; | |
55682965 | 2449 | } |
bba95fef JB |
2450 | |
2451 | wp_idx++; | |
55682965 | 2452 | } |
bba95fef | 2453 | out: |
5fe231e8 | 2454 | rtnl_unlock(); |
55682965 JB |
2455 | |
2456 | cb->args[0] = wp_idx; | |
2457 | cb->args[1] = if_idx; | |
2458 | ||
2459 | return skb->len; | |
2460 | } | |
2461 | ||
2462 | static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info) | |
2463 | { | |
2464 | struct sk_buff *msg; | |
1b8ec87a | 2465 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
72fb2abc | 2466 | struct wireless_dev *wdev = info->user_ptr[1]; |
55682965 | 2467 | |
fd2120ca | 2468 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 | 2469 | if (!msg) |
4c476991 | 2470 | return -ENOMEM; |
55682965 | 2471 | |
15e47304 | 2472 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2473 | rdev, wdev, false) < 0) { |
4c476991 JB |
2474 | nlmsg_free(msg); |
2475 | return -ENOBUFS; | |
2476 | } | |
55682965 | 2477 | |
134e6375 | 2478 | return genlmsg_reply(msg, info); |
55682965 JB |
2479 | } |
2480 | ||
66f7ac50 MW |
2481 | static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = { |
2482 | [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG }, | |
2483 | [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG }, | |
2484 | [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG }, | |
2485 | [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG }, | |
2486 | [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG }, | |
e057d3c3 | 2487 | [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG }, |
66f7ac50 MW |
2488 | }; |
2489 | ||
2490 | static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags) | |
2491 | { | |
2492 | struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1]; | |
2493 | int flag; | |
2494 | ||
2495 | *mntrflags = 0; | |
2496 | ||
2497 | if (!nla) | |
2498 | return -EINVAL; | |
2499 | ||
2500 | if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX, | |
2501 | nla, mntr_flags_policy)) | |
2502 | return -EINVAL; | |
2503 | ||
2504 | for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++) | |
2505 | if (flags[flag]) | |
2506 | *mntrflags |= (1<<flag); | |
2507 | ||
2508 | return 0; | |
2509 | } | |
2510 | ||
9bc383de | 2511 | static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev, |
ad4bb6f8 JB |
2512 | struct net_device *netdev, u8 use_4addr, |
2513 | enum nl80211_iftype iftype) | |
9bc383de | 2514 | { |
ad4bb6f8 | 2515 | if (!use_4addr) { |
f350a0a8 | 2516 | if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT)) |
ad4bb6f8 | 2517 | return -EBUSY; |
9bc383de | 2518 | return 0; |
ad4bb6f8 | 2519 | } |
9bc383de JB |
2520 | |
2521 | switch (iftype) { | |
2522 | case NL80211_IFTYPE_AP_VLAN: | |
2523 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP) | |
2524 | return 0; | |
2525 | break; | |
2526 | case NL80211_IFTYPE_STATION: | |
2527 | if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION) | |
2528 | return 0; | |
2529 | break; | |
2530 | default: | |
2531 | break; | |
2532 | } | |
2533 | ||
2534 | return -EOPNOTSUPP; | |
2535 | } | |
2536 | ||
55682965 JB |
2537 | static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info) |
2538 | { | |
4c476991 | 2539 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2540 | struct vif_params params; |
e36d56b6 | 2541 | int err; |
04a773ad | 2542 | enum nl80211_iftype otype, ntype; |
4c476991 | 2543 | struct net_device *dev = info->user_ptr[1]; |
92ffe055 | 2544 | u32 _flags, *flags = NULL; |
ac7f9cfa | 2545 | bool change = false; |
55682965 | 2546 | |
2ec600d6 LCC |
2547 | memset(¶ms, 0, sizeof(params)); |
2548 | ||
04a773ad | 2549 | otype = ntype = dev->ieee80211_ptr->iftype; |
55682965 | 2550 | |
723b038d | 2551 | if (info->attrs[NL80211_ATTR_IFTYPE]) { |
ac7f9cfa | 2552 | ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); |
04a773ad | 2553 | if (otype != ntype) |
ac7f9cfa | 2554 | change = true; |
4c476991 JB |
2555 | if (ntype > NL80211_IFTYPE_MAX) |
2556 | return -EINVAL; | |
723b038d JB |
2557 | } |
2558 | ||
92ffe055 | 2559 | if (info->attrs[NL80211_ATTR_MESH_ID]) { |
29cbe68c JB |
2560 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
2561 | ||
4c476991 JB |
2562 | if (ntype != NL80211_IFTYPE_MESH_POINT) |
2563 | return -EINVAL; | |
29cbe68c JB |
2564 | if (netif_running(dev)) |
2565 | return -EBUSY; | |
2566 | ||
2567 | wdev_lock(wdev); | |
2568 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2569 | IEEE80211_MAX_MESH_ID_LEN); | |
2570 | wdev->mesh_id_up_len = | |
2571 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2572 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2573 | wdev->mesh_id_up_len); | |
2574 | wdev_unlock(wdev); | |
2ec600d6 LCC |
2575 | } |
2576 | ||
8b787643 FF |
2577 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
2578 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); | |
2579 | change = true; | |
ad4bb6f8 | 2580 | err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype); |
9bc383de | 2581 | if (err) |
4c476991 | 2582 | return err; |
8b787643 FF |
2583 | } else { |
2584 | params.use_4addr = -1; | |
2585 | } | |
2586 | ||
92ffe055 | 2587 | if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) { |
4c476991 JB |
2588 | if (ntype != NL80211_IFTYPE_MONITOR) |
2589 | return -EINVAL; | |
92ffe055 JB |
2590 | err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS], |
2591 | &_flags); | |
ac7f9cfa | 2592 | if (err) |
4c476991 | 2593 | return err; |
ac7f9cfa JB |
2594 | |
2595 | flags = &_flags; | |
2596 | change = true; | |
92ffe055 | 2597 | } |
3b85875a | 2598 | |
18003297 | 2599 | if (flags && (*flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2600 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2601 | return -EOPNOTSUPP; | |
2602 | ||
ac7f9cfa | 2603 | if (change) |
3d54d255 | 2604 | err = cfg80211_change_iface(rdev, dev, ntype, flags, ¶ms); |
ac7f9cfa JB |
2605 | else |
2606 | err = 0; | |
60719ffd | 2607 | |
9bc383de JB |
2608 | if (!err && params.use_4addr != -1) |
2609 | dev->ieee80211_ptr->use_4addr = params.use_4addr; | |
2610 | ||
55682965 JB |
2611 | return err; |
2612 | } | |
2613 | ||
2614 | static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info) | |
2615 | { | |
4c476991 | 2616 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 2617 | struct vif_params params; |
84efbb84 | 2618 | struct wireless_dev *wdev; |
8f894be2 | 2619 | struct sk_buff *msg, *event; |
55682965 JB |
2620 | int err; |
2621 | enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED; | |
66f7ac50 | 2622 | u32 flags; |
55682965 | 2623 | |
78f22b6a JB |
2624 | /* to avoid failing a new interface creation due to pending removal */ |
2625 | cfg80211_destroy_ifaces(rdev); | |
2626 | ||
2ec600d6 LCC |
2627 | memset(¶ms, 0, sizeof(params)); |
2628 | ||
55682965 JB |
2629 | if (!info->attrs[NL80211_ATTR_IFNAME]) |
2630 | return -EINVAL; | |
2631 | ||
2632 | if (info->attrs[NL80211_ATTR_IFTYPE]) { | |
2633 | type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]); | |
2634 | if (type > NL80211_IFTYPE_MAX) | |
2635 | return -EINVAL; | |
2636 | } | |
2637 | ||
79c97e97 | 2638 | if (!rdev->ops->add_virtual_intf || |
4c476991 JB |
2639 | !(rdev->wiphy.interface_modes & (1 << type))) |
2640 | return -EOPNOTSUPP; | |
55682965 | 2641 | |
e8f479b1 BG |
2642 | if ((type == NL80211_IFTYPE_P2P_DEVICE || |
2643 | rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) && | |
2644 | info->attrs[NL80211_ATTR_MAC]) { | |
1c18f145 AS |
2645 | nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC], |
2646 | ETH_ALEN); | |
2647 | if (!is_valid_ether_addr(params.macaddr)) | |
2648 | return -EADDRNOTAVAIL; | |
2649 | } | |
2650 | ||
9bc383de | 2651 | if (info->attrs[NL80211_ATTR_4ADDR]) { |
8b787643 | 2652 | params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]); |
ad4bb6f8 | 2653 | err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type); |
9bc383de | 2654 | if (err) |
4c476991 | 2655 | return err; |
9bc383de | 2656 | } |
8b787643 | 2657 | |
1c90f9d4 JB |
2658 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2659 | if (!msg) | |
2660 | return -ENOMEM; | |
2661 | ||
66f7ac50 MW |
2662 | err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ? |
2663 | info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL, | |
2664 | &flags); | |
e057d3c3 | 2665 | |
18003297 | 2666 | if (!err && (flags & MONITOR_FLAG_ACTIVE) && |
e057d3c3 FF |
2667 | !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR)) |
2668 | return -EOPNOTSUPP; | |
2669 | ||
e35e4d28 HG |
2670 | wdev = rdev_add_virtual_intf(rdev, |
2671 | nla_data(info->attrs[NL80211_ATTR_IFNAME]), | |
2672 | type, err ? NULL : &flags, ¶ms); | |
d687cbb7 RM |
2673 | if (WARN_ON(!wdev)) { |
2674 | nlmsg_free(msg); | |
2675 | return -EPROTO; | |
2676 | } else if (IS_ERR(wdev)) { | |
1c90f9d4 | 2677 | nlmsg_free(msg); |
84efbb84 | 2678 | return PTR_ERR(wdev); |
1c90f9d4 | 2679 | } |
2ec600d6 | 2680 | |
18e5ca65 | 2681 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
78f22b6a JB |
2682 | wdev->owner_nlportid = info->snd_portid; |
2683 | ||
98104fde JB |
2684 | switch (type) { |
2685 | case NL80211_IFTYPE_MESH_POINT: | |
2686 | if (!info->attrs[NL80211_ATTR_MESH_ID]) | |
2687 | break; | |
29cbe68c JB |
2688 | wdev_lock(wdev); |
2689 | BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN != | |
2690 | IEEE80211_MAX_MESH_ID_LEN); | |
2691 | wdev->mesh_id_up_len = | |
2692 | nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
2693 | memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]), | |
2694 | wdev->mesh_id_up_len); | |
2695 | wdev_unlock(wdev); | |
98104fde JB |
2696 | break; |
2697 | case NL80211_IFTYPE_P2P_DEVICE: | |
2698 | /* | |
2699 | * P2P Device doesn't have a netdev, so doesn't go | |
2700 | * through the netdev notifier and must be added here | |
2701 | */ | |
2702 | mutex_init(&wdev->mtx); | |
2703 | INIT_LIST_HEAD(&wdev->event_list); | |
2704 | spin_lock_init(&wdev->event_lock); | |
2705 | INIT_LIST_HEAD(&wdev->mgmt_registrations); | |
2706 | spin_lock_init(&wdev->mgmt_registrations_lock); | |
2707 | ||
98104fde JB |
2708 | wdev->identifier = ++rdev->wdev_id; |
2709 | list_add_rcu(&wdev->list, &rdev->wdev_list); | |
2710 | rdev->devlist_generation++; | |
98104fde JB |
2711 | break; |
2712 | default: | |
2713 | break; | |
29cbe68c JB |
2714 | } |
2715 | ||
15e47304 | 2716 | if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0, |
8f894be2 | 2717 | rdev, wdev, false) < 0) { |
1c90f9d4 JB |
2718 | nlmsg_free(msg); |
2719 | return -ENOBUFS; | |
2720 | } | |
2721 | ||
8f894be2 TB |
2722 | event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2723 | if (event) { | |
2724 | if (nl80211_send_iface(event, 0, 0, 0, | |
2725 | rdev, wdev, false) < 0) { | |
2726 | nlmsg_free(event); | |
2727 | goto out; | |
2728 | } | |
2729 | ||
2730 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2731 | event, 0, NL80211_MCGRP_CONFIG, | |
2732 | GFP_KERNEL); | |
2733 | } | |
2734 | ||
2735 | out: | |
1c90f9d4 | 2736 | return genlmsg_reply(msg, info); |
55682965 JB |
2737 | } |
2738 | ||
2739 | static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info) | |
2740 | { | |
4c476991 | 2741 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
84efbb84 | 2742 | struct wireless_dev *wdev = info->user_ptr[1]; |
8f894be2 TB |
2743 | struct sk_buff *msg; |
2744 | int status; | |
55682965 | 2745 | |
4c476991 JB |
2746 | if (!rdev->ops->del_virtual_intf) |
2747 | return -EOPNOTSUPP; | |
55682965 | 2748 | |
8f894be2 TB |
2749 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2750 | if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) { | |
2751 | nlmsg_free(msg); | |
2752 | msg = NULL; | |
2753 | } | |
2754 | ||
84efbb84 JB |
2755 | /* |
2756 | * If we remove a wireless device without a netdev then clear | |
2757 | * user_ptr[1] so that nl80211_post_doit won't dereference it | |
2758 | * to check if it needs to do dev_put(). Otherwise it crashes | |
2759 | * since the wdev has been freed, unlike with a netdev where | |
2760 | * we need the dev_put() for the netdev to really be freed. | |
2761 | */ | |
2762 | if (!wdev->netdev) | |
2763 | info->user_ptr[1] = NULL; | |
2764 | ||
8f894be2 TB |
2765 | status = rdev_del_virtual_intf(rdev, wdev); |
2766 | if (status >= 0 && msg) | |
2767 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), | |
2768 | msg, 0, NL80211_MCGRP_CONFIG, | |
2769 | GFP_KERNEL); | |
2770 | else | |
2771 | nlmsg_free(msg); | |
2772 | ||
2773 | return status; | |
55682965 JB |
2774 | } |
2775 | ||
1d9d9213 SW |
2776 | static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info) |
2777 | { | |
2778 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
2779 | struct net_device *dev = info->user_ptr[1]; | |
2780 | u16 noack_map; | |
2781 | ||
2782 | if (!info->attrs[NL80211_ATTR_NOACK_MAP]) | |
2783 | return -EINVAL; | |
2784 | ||
2785 | if (!rdev->ops->set_noack_map) | |
2786 | return -EOPNOTSUPP; | |
2787 | ||
2788 | noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]); | |
2789 | ||
e35e4d28 | 2790 | return rdev_set_noack_map(rdev, dev, noack_map); |
1d9d9213 SW |
2791 | } |
2792 | ||
41ade00f JB |
2793 | struct get_key_cookie { |
2794 | struct sk_buff *msg; | |
2795 | int error; | |
b9454e83 | 2796 | int idx; |
41ade00f JB |
2797 | }; |
2798 | ||
2799 | static void get_key_callback(void *c, struct key_params *params) | |
2800 | { | |
b9454e83 | 2801 | struct nlattr *key; |
41ade00f JB |
2802 | struct get_key_cookie *cookie = c; |
2803 | ||
9360ffd1 DM |
2804 | if ((params->key && |
2805 | nla_put(cookie->msg, NL80211_ATTR_KEY_DATA, | |
2806 | params->key_len, params->key)) || | |
2807 | (params->seq && | |
2808 | nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ, | |
2809 | params->seq_len, params->seq)) || | |
2810 | (params->cipher && | |
2811 | nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER, | |
2812 | params->cipher))) | |
2813 | goto nla_put_failure; | |
41ade00f | 2814 | |
b9454e83 JB |
2815 | key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY); |
2816 | if (!key) | |
2817 | goto nla_put_failure; | |
2818 | ||
9360ffd1 DM |
2819 | if ((params->key && |
2820 | nla_put(cookie->msg, NL80211_KEY_DATA, | |
2821 | params->key_len, params->key)) || | |
2822 | (params->seq && | |
2823 | nla_put(cookie->msg, NL80211_KEY_SEQ, | |
2824 | params->seq_len, params->seq)) || | |
2825 | (params->cipher && | |
2826 | nla_put_u32(cookie->msg, NL80211_KEY_CIPHER, | |
2827 | params->cipher))) | |
2828 | goto nla_put_failure; | |
b9454e83 | 2829 | |
9360ffd1 DM |
2830 | if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx)) |
2831 | goto nla_put_failure; | |
b9454e83 JB |
2832 | |
2833 | nla_nest_end(cookie->msg, key); | |
2834 | ||
41ade00f JB |
2835 | return; |
2836 | nla_put_failure: | |
2837 | cookie->error = 1; | |
2838 | } | |
2839 | ||
2840 | static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info) | |
2841 | { | |
4c476991 | 2842 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 2843 | int err; |
4c476991 | 2844 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2845 | u8 key_idx = 0; |
e31b8213 JB |
2846 | const u8 *mac_addr = NULL; |
2847 | bool pairwise; | |
41ade00f JB |
2848 | struct get_key_cookie cookie = { |
2849 | .error = 0, | |
2850 | }; | |
2851 | void *hdr; | |
2852 | struct sk_buff *msg; | |
2853 | ||
2854 | if (info->attrs[NL80211_ATTR_KEY_IDX]) | |
2855 | key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]); | |
2856 | ||
3cfcf6ac | 2857 | if (key_idx > 5) |
41ade00f JB |
2858 | return -EINVAL; |
2859 | ||
2860 | if (info->attrs[NL80211_ATTR_MAC]) | |
2861 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
2862 | ||
e31b8213 JB |
2863 | pairwise = !!mac_addr; |
2864 | if (info->attrs[NL80211_ATTR_KEY_TYPE]) { | |
2865 | u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]); | |
2866 | if (kt >= NUM_NL80211_KEYTYPES) | |
2867 | return -EINVAL; | |
2868 | if (kt != NL80211_KEYTYPE_GROUP && | |
2869 | kt != NL80211_KEYTYPE_PAIRWISE) | |
2870 | return -EINVAL; | |
2871 | pairwise = kt == NL80211_KEYTYPE_PAIRWISE; | |
2872 | } | |
2873 | ||
4c476991 JB |
2874 | if (!rdev->ops->get_key) |
2875 | return -EOPNOTSUPP; | |
41ade00f | 2876 | |
0fa7b391 JB |
2877 | if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
2878 | return -ENOENT; | |
2879 | ||
fd2120ca | 2880 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
2881 | if (!msg) |
2882 | return -ENOMEM; | |
41ade00f | 2883 | |
15e47304 | 2884 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
41ade00f | 2885 | NL80211_CMD_NEW_KEY); |
cb35fba3 | 2886 | if (!hdr) |
9fe271af | 2887 | goto nla_put_failure; |
41ade00f JB |
2888 | |
2889 | cookie.msg = msg; | |
b9454e83 | 2890 | cookie.idx = key_idx; |
41ade00f | 2891 | |
9360ffd1 DM |
2892 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
2893 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) | |
2894 | goto nla_put_failure; | |
2895 | if (mac_addr && | |
2896 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr)) | |
2897 | goto nla_put_failure; | |
41ade00f | 2898 | |
e35e4d28 HG |
2899 | err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie, |
2900 | get_key_callback); | |
41ade00f JB |
2901 | |
2902 | if (err) | |
6c95e2a2 | 2903 | goto free_msg; |
41ade00f JB |
2904 | |
2905 | if (cookie.error) | |
2906 | goto nla_put_failure; | |
2907 | ||
2908 | genlmsg_end(msg, hdr); | |
4c476991 | 2909 | return genlmsg_reply(msg, info); |
41ade00f JB |
2910 | |
2911 | nla_put_failure: | |
2912 | err = -ENOBUFS; | |
6c95e2a2 | 2913 | free_msg: |
41ade00f | 2914 | nlmsg_free(msg); |
41ade00f JB |
2915 | return err; |
2916 | } | |
2917 | ||
2918 | static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info) | |
2919 | { | |
4c476991 | 2920 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
b9454e83 | 2921 | struct key_parse key; |
41ade00f | 2922 | int err; |
4c476991 | 2923 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 2924 | |
b9454e83 JB |
2925 | err = nl80211_parse_key(info, &key); |
2926 | if (err) | |
2927 | return err; | |
41ade00f | 2928 | |
b9454e83 | 2929 | if (key.idx < 0) |
41ade00f JB |
2930 | return -EINVAL; |
2931 | ||
b9454e83 JB |
2932 | /* only support setting default key */ |
2933 | if (!key.def && !key.defmgmt) | |
41ade00f JB |
2934 | return -EINVAL; |
2935 | ||
dbd2fd65 | 2936 | wdev_lock(dev->ieee80211_ptr); |
3cfcf6ac | 2937 | |
dbd2fd65 JB |
2938 | if (key.def) { |
2939 | if (!rdev->ops->set_default_key) { | |
2940 | err = -EOPNOTSUPP; | |
2941 | goto out; | |
2942 | } | |
41ade00f | 2943 | |
dbd2fd65 JB |
2944 | err = nl80211_key_allowed(dev->ieee80211_ptr); |
2945 | if (err) | |
2946 | goto out; | |
2947 | ||
e35e4d28 | 2948 | err = rdev_set_default_key(rdev, dev, key.idx, |
dbd2fd65 JB |
2949 | key.def_uni, key.def_multi); |
2950 | ||
2951 | if (err) | |
2952 | goto out; | |
fffd0934 | 2953 | |
3d23e349 | 2954 | #ifdef CONFIG_CFG80211_WEXT |
dbd2fd65 JB |
2955 | dev->ieee80211_ptr->wext.default_key = key.idx; |
2956 | #endif | |
2957 | } else { | |
2958 | if (key.def_uni || !key.def_multi) { | |
2959 | err = -EINVAL; | |
2960 | goto out; | |
2961 | } | |
2962 | ||
2963 | if (!rdev->ops->set_default_mgmt_key) { | |
2964 | err = -EOPNOTSUPP; | |
2965 | goto out; | |
2966 | } | |
2967 | ||
2968 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
2969 | if (err) | |
2970 | goto out; | |
2971 | ||
e35e4d28 | 2972 | err = rdev_set_default_mgmt_key(rdev, dev, key.idx); |
dbd2fd65 JB |
2973 | if (err) |
2974 | goto out; | |
2975 | ||
2976 | #ifdef CONFIG_CFG80211_WEXT | |
2977 | dev->ieee80211_ptr->wext.default_mgmt_key = key.idx; | |
08645126 | 2978 | #endif |
dbd2fd65 JB |
2979 | } |
2980 | ||
2981 | out: | |
fffd0934 | 2982 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 2983 | |
41ade00f JB |
2984 | return err; |
2985 | } | |
2986 | ||
2987 | static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info) | |
2988 | { | |
4c476991 | 2989 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fffd0934 | 2990 | int err; |
4c476991 | 2991 | struct net_device *dev = info->user_ptr[1]; |
b9454e83 | 2992 | struct key_parse key; |
e31b8213 | 2993 | const u8 *mac_addr = NULL; |
41ade00f | 2994 | |
b9454e83 JB |
2995 | err = nl80211_parse_key(info, &key); |
2996 | if (err) | |
2997 | return err; | |
41ade00f | 2998 | |
b9454e83 | 2999 | if (!key.p.key) |
41ade00f JB |
3000 | return -EINVAL; |
3001 | ||
41ade00f JB |
3002 | if (info->attrs[NL80211_ATTR_MAC]) |
3003 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3004 | ||
e31b8213 JB |
3005 | if (key.type == -1) { |
3006 | if (mac_addr) | |
3007 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3008 | else | |
3009 | key.type = NL80211_KEYTYPE_GROUP; | |
3010 | } | |
3011 | ||
3012 | /* for now */ | |
3013 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3014 | key.type != NL80211_KEYTYPE_GROUP) | |
3015 | return -EINVAL; | |
3016 | ||
4c476991 JB |
3017 | if (!rdev->ops->add_key) |
3018 | return -EOPNOTSUPP; | |
25e47c18 | 3019 | |
e31b8213 JB |
3020 | if (cfg80211_validate_key_settings(rdev, &key.p, key.idx, |
3021 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3022 | mac_addr)) | |
4c476991 | 3023 | return -EINVAL; |
41ade00f | 3024 | |
fffd0934 JB |
3025 | wdev_lock(dev->ieee80211_ptr); |
3026 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
3027 | if (!err) | |
e35e4d28 HG |
3028 | err = rdev_add_key(rdev, dev, key.idx, |
3029 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3030 | mac_addr, &key.p); | |
fffd0934 | 3031 | wdev_unlock(dev->ieee80211_ptr); |
41ade00f | 3032 | |
41ade00f JB |
3033 | return err; |
3034 | } | |
3035 | ||
3036 | static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info) | |
3037 | { | |
4c476991 | 3038 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
41ade00f | 3039 | int err; |
4c476991 | 3040 | struct net_device *dev = info->user_ptr[1]; |
41ade00f | 3041 | u8 *mac_addr = NULL; |
b9454e83 | 3042 | struct key_parse key; |
41ade00f | 3043 | |
b9454e83 JB |
3044 | err = nl80211_parse_key(info, &key); |
3045 | if (err) | |
3046 | return err; | |
41ade00f JB |
3047 | |
3048 | if (info->attrs[NL80211_ATTR_MAC]) | |
3049 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3050 | ||
e31b8213 JB |
3051 | if (key.type == -1) { |
3052 | if (mac_addr) | |
3053 | key.type = NL80211_KEYTYPE_PAIRWISE; | |
3054 | else | |
3055 | key.type = NL80211_KEYTYPE_GROUP; | |
3056 | } | |
3057 | ||
3058 | /* for now */ | |
3059 | if (key.type != NL80211_KEYTYPE_PAIRWISE && | |
3060 | key.type != NL80211_KEYTYPE_GROUP) | |
3061 | return -EINVAL; | |
3062 | ||
4c476991 JB |
3063 | if (!rdev->ops->del_key) |
3064 | return -EOPNOTSUPP; | |
41ade00f | 3065 | |
fffd0934 JB |
3066 | wdev_lock(dev->ieee80211_ptr); |
3067 | err = nl80211_key_allowed(dev->ieee80211_ptr); | |
e31b8213 | 3068 | |
0fa7b391 | 3069 | if (key.type == NL80211_KEYTYPE_GROUP && mac_addr && |
e31b8213 JB |
3070 | !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN)) |
3071 | err = -ENOENT; | |
3072 | ||
fffd0934 | 3073 | if (!err) |
e35e4d28 HG |
3074 | err = rdev_del_key(rdev, dev, key.idx, |
3075 | key.type == NL80211_KEYTYPE_PAIRWISE, | |
3076 | mac_addr); | |
41ade00f | 3077 | |
3d23e349 | 3078 | #ifdef CONFIG_CFG80211_WEXT |
08645126 | 3079 | if (!err) { |
b9454e83 | 3080 | if (key.idx == dev->ieee80211_ptr->wext.default_key) |
08645126 | 3081 | dev->ieee80211_ptr->wext.default_key = -1; |
b9454e83 | 3082 | else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key) |
08645126 JB |
3083 | dev->ieee80211_ptr->wext.default_mgmt_key = -1; |
3084 | } | |
3085 | #endif | |
fffd0934 | 3086 | wdev_unlock(dev->ieee80211_ptr); |
08645126 | 3087 | |
41ade00f JB |
3088 | return err; |
3089 | } | |
3090 | ||
77765eaf VT |
3091 | /* This function returns an error or the number of nested attributes */ |
3092 | static int validate_acl_mac_addrs(struct nlattr *nl_attr) | |
3093 | { | |
3094 | struct nlattr *attr; | |
3095 | int n_entries = 0, tmp; | |
3096 | ||
3097 | nla_for_each_nested(attr, nl_attr, tmp) { | |
3098 | if (nla_len(attr) != ETH_ALEN) | |
3099 | return -EINVAL; | |
3100 | ||
3101 | n_entries++; | |
3102 | } | |
3103 | ||
3104 | return n_entries; | |
3105 | } | |
3106 | ||
3107 | /* | |
3108 | * This function parses ACL information and allocates memory for ACL data. | |
3109 | * On successful return, the calling function is responsible to free the | |
3110 | * ACL buffer returned by this function. | |
3111 | */ | |
3112 | static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy, | |
3113 | struct genl_info *info) | |
3114 | { | |
3115 | enum nl80211_acl_policy acl_policy; | |
3116 | struct nlattr *attr; | |
3117 | struct cfg80211_acl_data *acl; | |
3118 | int i = 0, n_entries, tmp; | |
3119 | ||
3120 | if (!wiphy->max_acl_mac_addrs) | |
3121 | return ERR_PTR(-EOPNOTSUPP); | |
3122 | ||
3123 | if (!info->attrs[NL80211_ATTR_ACL_POLICY]) | |
3124 | return ERR_PTR(-EINVAL); | |
3125 | ||
3126 | acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]); | |
3127 | if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED && | |
3128 | acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED) | |
3129 | return ERR_PTR(-EINVAL); | |
3130 | ||
3131 | if (!info->attrs[NL80211_ATTR_MAC_ADDRS]) | |
3132 | return ERR_PTR(-EINVAL); | |
3133 | ||
3134 | n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]); | |
3135 | if (n_entries < 0) | |
3136 | return ERR_PTR(n_entries); | |
3137 | ||
3138 | if (n_entries > wiphy->max_acl_mac_addrs) | |
3139 | return ERR_PTR(-ENOTSUPP); | |
3140 | ||
3141 | acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries), | |
3142 | GFP_KERNEL); | |
3143 | if (!acl) | |
3144 | return ERR_PTR(-ENOMEM); | |
3145 | ||
3146 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) { | |
3147 | memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN); | |
3148 | i++; | |
3149 | } | |
3150 | ||
3151 | acl->n_acl_entries = n_entries; | |
3152 | acl->acl_policy = acl_policy; | |
3153 | ||
3154 | return acl; | |
3155 | } | |
3156 | ||
3157 | static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info) | |
3158 | { | |
3159 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3160 | struct net_device *dev = info->user_ptr[1]; | |
3161 | struct cfg80211_acl_data *acl; | |
3162 | int err; | |
3163 | ||
3164 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3165 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3166 | return -EOPNOTSUPP; | |
3167 | ||
3168 | if (!dev->ieee80211_ptr->beacon_interval) | |
3169 | return -EINVAL; | |
3170 | ||
3171 | acl = parse_acl_data(&rdev->wiphy, info); | |
3172 | if (IS_ERR(acl)) | |
3173 | return PTR_ERR(acl); | |
3174 | ||
3175 | err = rdev_set_mac_acl(rdev, dev, acl); | |
3176 | ||
3177 | kfree(acl); | |
3178 | ||
3179 | return err; | |
3180 | } | |
3181 | ||
a1193be8 | 3182 | static int nl80211_parse_beacon(struct nlattr *attrs[], |
8860020e | 3183 | struct cfg80211_beacon_data *bcn) |
ed1b6cc7 | 3184 | { |
8860020e | 3185 | bool haveinfo = false; |
ed1b6cc7 | 3186 | |
a1193be8 SW |
3187 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) || |
3188 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) || | |
3189 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) || | |
3190 | !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP])) | |
f4a11bb0 JB |
3191 | return -EINVAL; |
3192 | ||
8860020e | 3193 | memset(bcn, 0, sizeof(*bcn)); |
ed1b6cc7 | 3194 | |
a1193be8 SW |
3195 | if (attrs[NL80211_ATTR_BEACON_HEAD]) { |
3196 | bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]); | |
3197 | bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]); | |
8860020e JB |
3198 | if (!bcn->head_len) |
3199 | return -EINVAL; | |
3200 | haveinfo = true; | |
ed1b6cc7 JB |
3201 | } |
3202 | ||
a1193be8 SW |
3203 | if (attrs[NL80211_ATTR_BEACON_TAIL]) { |
3204 | bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]); | |
3205 | bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]); | |
8860020e | 3206 | haveinfo = true; |
ed1b6cc7 JB |
3207 | } |
3208 | ||
4c476991 JB |
3209 | if (!haveinfo) |
3210 | return -EINVAL; | |
3b85875a | 3211 | |
a1193be8 SW |
3212 | if (attrs[NL80211_ATTR_IE]) { |
3213 | bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]); | |
3214 | bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]); | |
9946ecfb JM |
3215 | } |
3216 | ||
a1193be8 | 3217 | if (attrs[NL80211_ATTR_IE_PROBE_RESP]) { |
8860020e | 3218 | bcn->proberesp_ies = |
a1193be8 | 3219 | nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
8860020e | 3220 | bcn->proberesp_ies_len = |
a1193be8 | 3221 | nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]); |
9946ecfb JM |
3222 | } |
3223 | ||
a1193be8 | 3224 | if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) { |
8860020e | 3225 | bcn->assocresp_ies = |
a1193be8 | 3226 | nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
8860020e | 3227 | bcn->assocresp_ies_len = |
a1193be8 | 3228 | nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]); |
9946ecfb JM |
3229 | } |
3230 | ||
a1193be8 SW |
3231 | if (attrs[NL80211_ATTR_PROBE_RESP]) { |
3232 | bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]); | |
3233 | bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]); | |
00f740e1 AN |
3234 | } |
3235 | ||
8860020e JB |
3236 | return 0; |
3237 | } | |
3238 | ||
46c1dd0c FF |
3239 | static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev, |
3240 | struct cfg80211_ap_settings *params) | |
3241 | { | |
3242 | struct wireless_dev *wdev; | |
3243 | bool ret = false; | |
3244 | ||
89a54e48 | 3245 | list_for_each_entry(wdev, &rdev->wdev_list, list) { |
46c1dd0c FF |
3246 | if (wdev->iftype != NL80211_IFTYPE_AP && |
3247 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
3248 | continue; | |
3249 | ||
683b6d3b | 3250 | if (!wdev->preset_chandef.chan) |
46c1dd0c FF |
3251 | continue; |
3252 | ||
683b6d3b | 3253 | params->chandef = wdev->preset_chandef; |
46c1dd0c FF |
3254 | ret = true; |
3255 | break; | |
3256 | } | |
3257 | ||
46c1dd0c FF |
3258 | return ret; |
3259 | } | |
3260 | ||
e39e5b5e JM |
3261 | static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev, |
3262 | enum nl80211_auth_type auth_type, | |
3263 | enum nl80211_commands cmd) | |
3264 | { | |
3265 | if (auth_type > NL80211_AUTHTYPE_MAX) | |
3266 | return false; | |
3267 | ||
3268 | switch (cmd) { | |
3269 | case NL80211_CMD_AUTHENTICATE: | |
3270 | if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) && | |
3271 | auth_type == NL80211_AUTHTYPE_SAE) | |
3272 | return false; | |
3273 | return true; | |
3274 | case NL80211_CMD_CONNECT: | |
3275 | case NL80211_CMD_START_AP: | |
3276 | /* SAE not supported yet */ | |
3277 | if (auth_type == NL80211_AUTHTYPE_SAE) | |
3278 | return false; | |
3279 | return true; | |
3280 | default: | |
3281 | return false; | |
3282 | } | |
3283 | } | |
3284 | ||
8860020e JB |
3285 | static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info) |
3286 | { | |
3287 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3288 | struct net_device *dev = info->user_ptr[1]; | |
3289 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3290 | struct cfg80211_ap_settings params; | |
3291 | int err; | |
3292 | ||
3293 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3294 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3295 | return -EOPNOTSUPP; | |
3296 | ||
3297 | if (!rdev->ops->start_ap) | |
3298 | return -EOPNOTSUPP; | |
3299 | ||
3300 | if (wdev->beacon_interval) | |
3301 | return -EALREADY; | |
3302 | ||
3303 | memset(¶ms, 0, sizeof(params)); | |
3304 | ||
3305 | /* these are required for START_AP */ | |
3306 | if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] || | |
3307 | !info->attrs[NL80211_ATTR_DTIM_PERIOD] || | |
3308 | !info->attrs[NL80211_ATTR_BEACON_HEAD]) | |
3309 | return -EINVAL; | |
3310 | ||
a1193be8 | 3311 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon); |
8860020e JB |
3312 | if (err) |
3313 | return err; | |
3314 | ||
3315 | params.beacon_interval = | |
3316 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
3317 | params.dtim_period = | |
3318 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
3319 | ||
3320 | err = cfg80211_validate_beacon_int(rdev, params.beacon_interval); | |
3321 | if (err) | |
3322 | return err; | |
3323 | ||
3324 | /* | |
3325 | * In theory, some of these attributes should be required here | |
3326 | * but since they were not used when the command was originally | |
3327 | * added, keep them optional for old user space programs to let | |
3328 | * them continue to work with drivers that do not need the | |
3329 | * additional information -- drivers must check! | |
3330 | */ | |
3331 | if (info->attrs[NL80211_ATTR_SSID]) { | |
3332 | params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); | |
3333 | params.ssid_len = | |
3334 | nla_len(info->attrs[NL80211_ATTR_SSID]); | |
3335 | if (params.ssid_len == 0 || | |
3336 | params.ssid_len > IEEE80211_MAX_SSID_LEN) | |
3337 | return -EINVAL; | |
3338 | } | |
3339 | ||
3340 | if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) { | |
3341 | params.hidden_ssid = nla_get_u32( | |
3342 | info->attrs[NL80211_ATTR_HIDDEN_SSID]); | |
3343 | if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE && | |
3344 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN && | |
3345 | params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS) | |
3346 | return -EINVAL; | |
3347 | } | |
3348 | ||
3349 | params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; | |
3350 | ||
3351 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
3352 | params.auth_type = nla_get_u32( | |
3353 | info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
3354 | if (!nl80211_valid_auth_type(rdev, params.auth_type, |
3355 | NL80211_CMD_START_AP)) | |
8860020e JB |
3356 | return -EINVAL; |
3357 | } else | |
3358 | params.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
3359 | ||
3360 | err = nl80211_crypto_settings(rdev, info, ¶ms.crypto, | |
3361 | NL80211_MAX_NR_CIPHER_SUITES); | |
3362 | if (err) | |
3363 | return err; | |
3364 | ||
1b658f11 VT |
3365 | if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) { |
3366 | if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER)) | |
3367 | return -EOPNOTSUPP; | |
3368 | params.inactivity_timeout = nla_get_u16( | |
3369 | info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]); | |
3370 | } | |
3371 | ||
53cabad7 JB |
3372 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
3373 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3374 | return -EINVAL; | |
3375 | params.p2p_ctwindow = | |
3376 | nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
3377 | if (params.p2p_ctwindow > 127) | |
3378 | return -EINVAL; | |
3379 | if (params.p2p_ctwindow != 0 && | |
3380 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
3381 | return -EINVAL; | |
3382 | } | |
3383 | ||
3384 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
3385 | u8 tmp; | |
3386 | ||
3387 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3388 | return -EINVAL; | |
3389 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
3390 | if (tmp > 1) | |
3391 | return -EINVAL; | |
3392 | params.p2p_opp_ps = tmp; | |
3393 | if (params.p2p_opp_ps != 0 && | |
3394 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
3395 | return -EINVAL; | |
3396 | } | |
3397 | ||
aa430da4 | 3398 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
3399 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
3400 | if (err) | |
3401 | return err; | |
3402 | } else if (wdev->preset_chandef.chan) { | |
3403 | params.chandef = wdev->preset_chandef; | |
46c1dd0c | 3404 | } else if (!nl80211_get_ap_channel(rdev, ¶ms)) |
aa430da4 JB |
3405 | return -EINVAL; |
3406 | ||
174e0cd2 IP |
3407 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
3408 | wdev->iftype)) | |
aa430da4 JB |
3409 | return -EINVAL; |
3410 | ||
77765eaf VT |
3411 | if (info->attrs[NL80211_ATTR_ACL_POLICY]) { |
3412 | params.acl = parse_acl_data(&rdev->wiphy, info); | |
3413 | if (IS_ERR(params.acl)) | |
3414 | return PTR_ERR(params.acl); | |
3415 | } | |
3416 | ||
18998c38 EP |
3417 | if (info->attrs[NL80211_ATTR_SMPS_MODE]) { |
3418 | params.smps_mode = | |
3419 | nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]); | |
3420 | switch (params.smps_mode) { | |
3421 | case NL80211_SMPS_OFF: | |
3422 | break; | |
3423 | case NL80211_SMPS_STATIC: | |
3424 | if (!(rdev->wiphy.features & | |
3425 | NL80211_FEATURE_STATIC_SMPS)) | |
3426 | return -EINVAL; | |
3427 | break; | |
3428 | case NL80211_SMPS_DYNAMIC: | |
3429 | if (!(rdev->wiphy.features & | |
3430 | NL80211_FEATURE_DYNAMIC_SMPS)) | |
3431 | return -EINVAL; | |
3432 | break; | |
3433 | default: | |
3434 | return -EINVAL; | |
3435 | } | |
3436 | } else { | |
3437 | params.smps_mode = NL80211_SMPS_OFF; | |
3438 | } | |
3439 | ||
c56589ed | 3440 | wdev_lock(wdev); |
e35e4d28 | 3441 | err = rdev_start_ap(rdev, dev, ¶ms); |
46c1dd0c | 3442 | if (!err) { |
683b6d3b | 3443 | wdev->preset_chandef = params.chandef; |
8860020e | 3444 | wdev->beacon_interval = params.beacon_interval; |
9e0e2961 | 3445 | wdev->chandef = params.chandef; |
06e191e2 AQ |
3446 | wdev->ssid_len = params.ssid_len; |
3447 | memcpy(wdev->ssid, params.ssid, wdev->ssid_len); | |
46c1dd0c | 3448 | } |
c56589ed | 3449 | wdev_unlock(wdev); |
77765eaf VT |
3450 | |
3451 | kfree(params.acl); | |
3452 | ||
56d1893d | 3453 | return err; |
ed1b6cc7 JB |
3454 | } |
3455 | ||
8860020e JB |
3456 | static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info) |
3457 | { | |
3458 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
3459 | struct net_device *dev = info->user_ptr[1]; | |
3460 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
3461 | struct cfg80211_beacon_data params; | |
3462 | int err; | |
3463 | ||
3464 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
3465 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
3466 | return -EOPNOTSUPP; | |
3467 | ||
3468 | if (!rdev->ops->change_beacon) | |
3469 | return -EOPNOTSUPP; | |
3470 | ||
3471 | if (!wdev->beacon_interval) | |
3472 | return -EINVAL; | |
3473 | ||
a1193be8 | 3474 | err = nl80211_parse_beacon(info->attrs, ¶ms); |
8860020e JB |
3475 | if (err) |
3476 | return err; | |
3477 | ||
c56589ed SW |
3478 | wdev_lock(wdev); |
3479 | err = rdev_change_beacon(rdev, dev, ¶ms); | |
3480 | wdev_unlock(wdev); | |
3481 | ||
3482 | return err; | |
8860020e JB |
3483 | } |
3484 | ||
3485 | static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info) | |
ed1b6cc7 | 3486 | { |
4c476991 JB |
3487 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3488 | struct net_device *dev = info->user_ptr[1]; | |
ed1b6cc7 | 3489 | |
7c8d5e03 | 3490 | return cfg80211_stop_ap(rdev, dev, false); |
ed1b6cc7 JB |
3491 | } |
3492 | ||
5727ef1b JB |
3493 | static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = { |
3494 | [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG }, | |
3495 | [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG }, | |
3496 | [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG }, | |
0e46724a | 3497 | [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG }, |
b39c48fa | 3498 | [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG }, |
d83023da | 3499 | [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG }, |
5727ef1b JB |
3500 | }; |
3501 | ||
eccb8e8f | 3502 | static int parse_station_flags(struct genl_info *info, |
bdd3ae3d | 3503 | enum nl80211_iftype iftype, |
eccb8e8f | 3504 | struct station_parameters *params) |
5727ef1b JB |
3505 | { |
3506 | struct nlattr *flags[NL80211_STA_FLAG_MAX + 1]; | |
eccb8e8f | 3507 | struct nlattr *nla; |
5727ef1b JB |
3508 | int flag; |
3509 | ||
eccb8e8f JB |
3510 | /* |
3511 | * Try parsing the new attribute first so userspace | |
3512 | * can specify both for older kernels. | |
3513 | */ | |
3514 | nla = info->attrs[NL80211_ATTR_STA_FLAGS2]; | |
3515 | if (nla) { | |
3516 | struct nl80211_sta_flag_update *sta_flags; | |
3517 | ||
3518 | sta_flags = nla_data(nla); | |
3519 | params->sta_flags_mask = sta_flags->mask; | |
3520 | params->sta_flags_set = sta_flags->set; | |
77ee7c89 | 3521 | params->sta_flags_set &= params->sta_flags_mask; |
eccb8e8f JB |
3522 | if ((params->sta_flags_mask | |
3523 | params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID)) | |
3524 | return -EINVAL; | |
3525 | return 0; | |
3526 | } | |
3527 | ||
3528 | /* if present, parse the old attribute */ | |
5727ef1b | 3529 | |
eccb8e8f | 3530 | nla = info->attrs[NL80211_ATTR_STA_FLAGS]; |
5727ef1b JB |
3531 | if (!nla) |
3532 | return 0; | |
3533 | ||
3534 | if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX, | |
3535 | nla, sta_flags_policy)) | |
3536 | return -EINVAL; | |
3537 | ||
bdd3ae3d JB |
3538 | /* |
3539 | * Only allow certain flags for interface types so that | |
3540 | * other attributes are silently ignored. Remember that | |
3541 | * this is backward compatibility code with old userspace | |
3542 | * and shouldn't be hit in other cases anyway. | |
3543 | */ | |
3544 | switch (iftype) { | |
3545 | case NL80211_IFTYPE_AP: | |
3546 | case NL80211_IFTYPE_AP_VLAN: | |
3547 | case NL80211_IFTYPE_P2P_GO: | |
3548 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3549 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
3550 | BIT(NL80211_STA_FLAG_WME) | | |
3551 | BIT(NL80211_STA_FLAG_MFP); | |
3552 | break; | |
3553 | case NL80211_IFTYPE_P2P_CLIENT: | |
3554 | case NL80211_IFTYPE_STATION: | |
3555 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
3556 | BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3557 | break; | |
3558 | case NL80211_IFTYPE_MESH_POINT: | |
3559 | params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3560 | BIT(NL80211_STA_FLAG_MFP) | | |
3561 | BIT(NL80211_STA_FLAG_AUTHORIZED); | |
3562 | default: | |
3563 | return -EINVAL; | |
3564 | } | |
5727ef1b | 3565 | |
3383b5a6 JB |
3566 | for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) { |
3567 | if (flags[flag]) { | |
eccb8e8f | 3568 | params->sta_flags_set |= (1<<flag); |
5727ef1b | 3569 | |
3383b5a6 JB |
3570 | /* no longer support new API additions in old API */ |
3571 | if (flag > NL80211_STA_FLAG_MAX_OLD_API) | |
3572 | return -EINVAL; | |
3573 | } | |
3574 | } | |
3575 | ||
5727ef1b JB |
3576 | return 0; |
3577 | } | |
3578 | ||
c8dcfd8a FF |
3579 | static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info, |
3580 | int attr) | |
3581 | { | |
3582 | struct nlattr *rate; | |
8eb41c8d VK |
3583 | u32 bitrate; |
3584 | u16 bitrate_compat; | |
b51f3bee | 3585 | enum nl80211_attrs rate_flg; |
c8dcfd8a FF |
3586 | |
3587 | rate = nla_nest_start(msg, attr); | |
3588 | if (!rate) | |
db9c64cf | 3589 | return false; |
c8dcfd8a FF |
3590 | |
3591 | /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */ | |
3592 | bitrate = cfg80211_calculate_bitrate(info); | |
8eb41c8d VK |
3593 | /* report 16-bit bitrate only if we can */ |
3594 | bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0; | |
db9c64cf JB |
3595 | if (bitrate > 0 && |
3596 | nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate)) | |
3597 | return false; | |
3598 | if (bitrate_compat > 0 && | |
3599 | nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat)) | |
3600 | return false; | |
3601 | ||
b51f3bee JB |
3602 | switch (info->bw) { |
3603 | case RATE_INFO_BW_5: | |
3604 | rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH; | |
3605 | break; | |
3606 | case RATE_INFO_BW_10: | |
3607 | rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH; | |
3608 | break; | |
3609 | default: | |
3610 | WARN_ON(1); | |
3611 | /* fall through */ | |
3612 | case RATE_INFO_BW_20: | |
3613 | rate_flg = 0; | |
3614 | break; | |
3615 | case RATE_INFO_BW_40: | |
3616 | rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH; | |
3617 | break; | |
3618 | case RATE_INFO_BW_80: | |
3619 | rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH; | |
3620 | break; | |
3621 | case RATE_INFO_BW_160: | |
3622 | rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH; | |
3623 | break; | |
3624 | } | |
3625 | ||
3626 | if (rate_flg && nla_put_flag(msg, rate_flg)) | |
3627 | return false; | |
3628 | ||
db9c64cf JB |
3629 | if (info->flags & RATE_INFO_FLAGS_MCS) { |
3630 | if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs)) | |
3631 | return false; | |
db9c64cf JB |
3632 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3633 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3634 | return false; | |
3635 | } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) { | |
3636 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs)) | |
3637 | return false; | |
3638 | if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss)) | |
3639 | return false; | |
db9c64cf JB |
3640 | if (info->flags & RATE_INFO_FLAGS_SHORT_GI && |
3641 | nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI)) | |
3642 | return false; | |
3643 | } | |
c8dcfd8a FF |
3644 | |
3645 | nla_nest_end(msg, rate); | |
3646 | return true; | |
c8dcfd8a FF |
3647 | } |
3648 | ||
119363c7 FF |
3649 | static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal, |
3650 | int id) | |
3651 | { | |
3652 | void *attr; | |
3653 | int i = 0; | |
3654 | ||
3655 | if (!mask) | |
3656 | return true; | |
3657 | ||
3658 | attr = nla_nest_start(msg, id); | |
3659 | if (!attr) | |
3660 | return false; | |
3661 | ||
3662 | for (i = 0; i < IEEE80211_MAX_CHAINS; i++) { | |
3663 | if (!(mask & BIT(i))) | |
3664 | continue; | |
3665 | ||
3666 | if (nla_put_u8(msg, i, signal[i])) | |
3667 | return false; | |
3668 | } | |
3669 | ||
3670 | nla_nest_end(msg, attr); | |
3671 | ||
3672 | return true; | |
3673 | } | |
3674 | ||
cf5ead82 JB |
3675 | static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid, |
3676 | u32 seq, int flags, | |
66266b3a JL |
3677 | struct cfg80211_registered_device *rdev, |
3678 | struct net_device *dev, | |
98b62183 | 3679 | const u8 *mac_addr, struct station_info *sinfo) |
fd5b74dc JB |
3680 | { |
3681 | void *hdr; | |
f4263c98 | 3682 | struct nlattr *sinfoattr, *bss_param; |
fd5b74dc | 3683 | |
cf5ead82 | 3684 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
fd5b74dc JB |
3685 | if (!hdr) |
3686 | return -1; | |
3687 | ||
9360ffd1 DM |
3688 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
3689 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
3690 | nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation)) | |
3691 | goto nla_put_failure; | |
f5ea9120 | 3692 | |
2ec600d6 LCC |
3693 | sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO); |
3694 | if (!sinfoattr) | |
fd5b74dc | 3695 | goto nla_put_failure; |
319090bf JB |
3696 | |
3697 | #define PUT_SINFO(attr, memb, type) do { \ | |
3698 | if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \ | |
3699 | nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \ | |
3700 | sinfo->memb)) \ | |
3701 | goto nla_put_failure; \ | |
3702 | } while (0) | |
3703 | ||
3704 | PUT_SINFO(CONNECTED_TIME, connected_time, u32); | |
3705 | PUT_SINFO(INACTIVE_TIME, inactive_time, u32); | |
3706 | ||
3707 | if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) | | |
3708 | BIT(NL80211_STA_INFO_RX_BYTES64)) && | |
9360ffd1 | 3709 | nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES, |
42745e03 | 3710 | (u32)sinfo->rx_bytes)) |
9360ffd1 | 3711 | goto nla_put_failure; |
319090bf JB |
3712 | |
3713 | if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) | | |
3714 | BIT(NL80211_STA_INFO_TX_BYTES64)) && | |
9360ffd1 | 3715 | nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES, |
42745e03 VK |
3716 | (u32)sinfo->tx_bytes)) |
3717 | goto nla_put_failure; | |
319090bf JB |
3718 | |
3719 | PUT_SINFO(RX_BYTES64, rx_bytes, u64); | |
3720 | PUT_SINFO(TX_BYTES64, tx_bytes, u64); | |
3721 | PUT_SINFO(LLID, llid, u16); | |
3722 | PUT_SINFO(PLID, plid, u16); | |
3723 | PUT_SINFO(PLINK_STATE, plink_state, u8); | |
3724 | ||
66266b3a JL |
3725 | switch (rdev->wiphy.signal_type) { |
3726 | case CFG80211_SIGNAL_TYPE_MBM: | |
319090bf JB |
3727 | PUT_SINFO(SIGNAL, signal, u8); |
3728 | PUT_SINFO(SIGNAL_AVG, signal_avg, u8); | |
66266b3a JL |
3729 | break; |
3730 | default: | |
3731 | break; | |
3732 | } | |
319090bf | 3733 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) { |
119363c7 FF |
3734 | if (!nl80211_put_signal(msg, sinfo->chains, |
3735 | sinfo->chain_signal, | |
3736 | NL80211_STA_INFO_CHAIN_SIGNAL)) | |
3737 | goto nla_put_failure; | |
3738 | } | |
319090bf | 3739 | if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) { |
119363c7 FF |
3740 | if (!nl80211_put_signal(msg, sinfo->chains, |
3741 | sinfo->chain_signal_avg, | |
3742 | NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) | |
3743 | goto nla_put_failure; | |
3744 | } | |
319090bf | 3745 | if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) { |
c8dcfd8a FF |
3746 | if (!nl80211_put_sta_rate(msg, &sinfo->txrate, |
3747 | NL80211_STA_INFO_TX_BITRATE)) | |
3748 | goto nla_put_failure; | |
3749 | } | |
319090bf | 3750 | if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) { |
c8dcfd8a FF |
3751 | if (!nl80211_put_sta_rate(msg, &sinfo->rxrate, |
3752 | NL80211_STA_INFO_RX_BITRATE)) | |
420e7fab | 3753 | goto nla_put_failure; |
420e7fab | 3754 | } |
319090bf JB |
3755 | |
3756 | PUT_SINFO(RX_PACKETS, rx_packets, u32); | |
3757 | PUT_SINFO(TX_PACKETS, tx_packets, u32); | |
3758 | PUT_SINFO(TX_RETRIES, tx_retries, u32); | |
3759 | PUT_SINFO(TX_FAILED, tx_failed, u32); | |
3760 | PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32); | |
3761 | PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32); | |
3762 | PUT_SINFO(LOCAL_PM, local_pm, u32); | |
3763 | PUT_SINFO(PEER_PM, peer_pm, u32); | |
3764 | PUT_SINFO(NONPEER_PM, nonpeer_pm, u32); | |
3765 | ||
3766 | if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) { | |
f4263c98 PS |
3767 | bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM); |
3768 | if (!bss_param) | |
3769 | goto nla_put_failure; | |
3770 | ||
9360ffd1 DM |
3771 | if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) && |
3772 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) || | |
3773 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) && | |
3774 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) || | |
3775 | ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) && | |
3776 | nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) || | |
3777 | nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD, | |
3778 | sinfo->bss_param.dtim_period) || | |
3779 | nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL, | |
3780 | sinfo->bss_param.beacon_interval)) | |
3781 | goto nla_put_failure; | |
f4263c98 PS |
3782 | |
3783 | nla_nest_end(msg, bss_param); | |
3784 | } | |
319090bf | 3785 | if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) && |
9360ffd1 DM |
3786 | nla_put(msg, NL80211_STA_INFO_STA_FLAGS, |
3787 | sizeof(struct nl80211_sta_flag_update), | |
3788 | &sinfo->sta_flags)) | |
3789 | goto nla_put_failure; | |
319090bf JB |
3790 | |
3791 | PUT_SINFO(T_OFFSET, t_offset, u64); | |
3792 | PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64); | |
a76b1942 JB |
3793 | PUT_SINFO(BEACON_RX, rx_beacon, u64); |
3794 | PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8); | |
319090bf JB |
3795 | |
3796 | #undef PUT_SINFO | |
6de39808 JB |
3797 | |
3798 | if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) { | |
3799 | struct nlattr *tidsattr; | |
3800 | int tid; | |
3801 | ||
3802 | tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS); | |
3803 | if (!tidsattr) | |
3804 | goto nla_put_failure; | |
3805 | ||
3806 | for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) { | |
3807 | struct cfg80211_tid_stats *tidstats; | |
3808 | struct nlattr *tidattr; | |
3809 | ||
3810 | tidstats = &sinfo->pertid[tid]; | |
3811 | ||
3812 | if (!tidstats->filled) | |
3813 | continue; | |
3814 | ||
3815 | tidattr = nla_nest_start(msg, tid + 1); | |
3816 | if (!tidattr) | |
3817 | goto nla_put_failure; | |
3818 | ||
3819 | #define PUT_TIDVAL(attr, memb, type) do { \ | |
3820 | if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \ | |
3821 | nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \ | |
3822 | tidstats->memb)) \ | |
3823 | goto nla_put_failure; \ | |
3824 | } while (0) | |
3825 | ||
3826 | PUT_TIDVAL(RX_MSDU, rx_msdu, u64); | |
3827 | PUT_TIDVAL(TX_MSDU, tx_msdu, u64); | |
3828 | PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64); | |
3829 | PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64); | |
3830 | ||
3831 | #undef PUT_TIDVAL | |
3832 | nla_nest_end(msg, tidattr); | |
3833 | } | |
3834 | ||
3835 | nla_nest_end(msg, tidsattr); | |
3836 | } | |
3837 | ||
2ec600d6 | 3838 | nla_nest_end(msg, sinfoattr); |
fd5b74dc | 3839 | |
319090bf | 3840 | if (sinfo->assoc_req_ies_len && |
9360ffd1 DM |
3841 | nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len, |
3842 | sinfo->assoc_req_ies)) | |
3843 | goto nla_put_failure; | |
50d3dfb7 | 3844 | |
053c095a JB |
3845 | genlmsg_end(msg, hdr); |
3846 | return 0; | |
fd5b74dc JB |
3847 | |
3848 | nla_put_failure: | |
bc3ed28c TG |
3849 | genlmsg_cancel(msg, hdr); |
3850 | return -EMSGSIZE; | |
fd5b74dc JB |
3851 | } |
3852 | ||
2ec600d6 | 3853 | static int nl80211_dump_station(struct sk_buff *skb, |
bba95fef | 3854 | struct netlink_callback *cb) |
2ec600d6 | 3855 | { |
2ec600d6 | 3856 | struct station_info sinfo; |
1b8ec87a | 3857 | struct cfg80211_registered_device *rdev; |
97990a06 | 3858 | struct wireless_dev *wdev; |
2ec600d6 | 3859 | u8 mac_addr[ETH_ALEN]; |
97990a06 | 3860 | int sta_idx = cb->args[2]; |
2ec600d6 | 3861 | int err; |
2ec600d6 | 3862 | |
1b8ec87a | 3863 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
3864 | if (err) |
3865 | return err; | |
bba95fef | 3866 | |
97990a06 JB |
3867 | if (!wdev->netdev) { |
3868 | err = -EINVAL; | |
3869 | goto out_err; | |
3870 | } | |
3871 | ||
1b8ec87a | 3872 | if (!rdev->ops->dump_station) { |
eec60b03 | 3873 | err = -EOPNOTSUPP; |
bba95fef JB |
3874 | goto out_err; |
3875 | } | |
3876 | ||
bba95fef | 3877 | while (1) { |
f612cedf | 3878 | memset(&sinfo, 0, sizeof(sinfo)); |
1b8ec87a | 3879 | err = rdev_dump_station(rdev, wdev->netdev, sta_idx, |
e35e4d28 | 3880 | mac_addr, &sinfo); |
bba95fef JB |
3881 | if (err == -ENOENT) |
3882 | break; | |
3883 | if (err) | |
3b85875a | 3884 | goto out_err; |
bba95fef | 3885 | |
cf5ead82 | 3886 | if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION, |
15e47304 | 3887 | NETLINK_CB(cb->skb).portid, |
bba95fef | 3888 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
1b8ec87a | 3889 | rdev, wdev->netdev, mac_addr, |
bba95fef JB |
3890 | &sinfo) < 0) |
3891 | goto out; | |
3892 | ||
3893 | sta_idx++; | |
3894 | } | |
3895 | ||
3896 | ||
3897 | out: | |
97990a06 | 3898 | cb->args[2] = sta_idx; |
bba95fef | 3899 | err = skb->len; |
bba95fef | 3900 | out_err: |
1b8ec87a | 3901 | nl80211_finish_wdev_dump(rdev); |
bba95fef JB |
3902 | |
3903 | return err; | |
2ec600d6 | 3904 | } |
fd5b74dc | 3905 | |
5727ef1b JB |
3906 | static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info) |
3907 | { | |
4c476991 JB |
3908 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
3909 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 | 3910 | struct station_info sinfo; |
fd5b74dc JB |
3911 | struct sk_buff *msg; |
3912 | u8 *mac_addr = NULL; | |
4c476991 | 3913 | int err; |
fd5b74dc | 3914 | |
2ec600d6 | 3915 | memset(&sinfo, 0, sizeof(sinfo)); |
fd5b74dc JB |
3916 | |
3917 | if (!info->attrs[NL80211_ATTR_MAC]) | |
3918 | return -EINVAL; | |
3919 | ||
3920 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
3921 | ||
4c476991 JB |
3922 | if (!rdev->ops->get_station) |
3923 | return -EOPNOTSUPP; | |
3b85875a | 3924 | |
e35e4d28 | 3925 | err = rdev_get_station(rdev, dev, mac_addr, &sinfo); |
fd5b74dc | 3926 | if (err) |
4c476991 | 3927 | return err; |
2ec600d6 | 3928 | |
fd2120ca | 3929 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
fd5b74dc | 3930 | if (!msg) |
4c476991 | 3931 | return -ENOMEM; |
fd5b74dc | 3932 | |
cf5ead82 JB |
3933 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, |
3934 | info->snd_portid, info->snd_seq, 0, | |
66266b3a | 3935 | rdev, dev, mac_addr, &sinfo) < 0) { |
4c476991 JB |
3936 | nlmsg_free(msg); |
3937 | return -ENOBUFS; | |
3938 | } | |
3b85875a | 3939 | |
4c476991 | 3940 | return genlmsg_reply(msg, info); |
5727ef1b JB |
3941 | } |
3942 | ||
77ee7c89 JB |
3943 | int cfg80211_check_station_change(struct wiphy *wiphy, |
3944 | struct station_parameters *params, | |
3945 | enum cfg80211_station_type statype) | |
3946 | { | |
3947 | if (params->listen_interval != -1) | |
3948 | return -EINVAL; | |
c72e1140 AN |
3949 | if (params->aid && |
3950 | !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
77ee7c89 JB |
3951 | return -EINVAL; |
3952 | ||
3953 | /* When you run into this, adjust the code below for the new flag */ | |
3954 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
3955 | ||
3956 | switch (statype) { | |
eef941e6 TP |
3957 | case CFG80211_STA_MESH_PEER_KERNEL: |
3958 | case CFG80211_STA_MESH_PEER_USER: | |
77ee7c89 JB |
3959 | /* |
3960 | * No ignoring the TDLS flag here -- the userspace mesh | |
3961 | * code doesn't have the bug of including TDLS in the | |
3962 | * mask everywhere. | |
3963 | */ | |
3964 | if (params->sta_flags_mask & | |
3965 | ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
3966 | BIT(NL80211_STA_FLAG_MFP) | | |
3967 | BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
3968 | return -EINVAL; | |
3969 | break; | |
3970 | case CFG80211_STA_TDLS_PEER_SETUP: | |
3971 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
3972 | if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
3973 | return -EINVAL; | |
3974 | /* ignore since it can't change */ | |
3975 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3976 | break; | |
3977 | default: | |
3978 | /* disallow mesh-specific things */ | |
3979 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) | |
3980 | return -EINVAL; | |
3981 | if (params->local_pm) | |
3982 | return -EINVAL; | |
3983 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) | |
3984 | return -EINVAL; | |
3985 | } | |
3986 | ||
3987 | if (statype != CFG80211_STA_TDLS_PEER_SETUP && | |
3988 | statype != CFG80211_STA_TDLS_PEER_ACTIVE) { | |
3989 | /* TDLS can't be set, ... */ | |
3990 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) | |
3991 | return -EINVAL; | |
3992 | /* | |
3993 | * ... but don't bother the driver with it. This works around | |
3994 | * a hostapd/wpa_supplicant issue -- it always includes the | |
3995 | * TLDS_PEER flag in the mask even for AP mode. | |
3996 | */ | |
3997 | params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3998 | } | |
3999 | ||
4000 | if (statype != CFG80211_STA_TDLS_PEER_SETUP) { | |
4001 | /* reject other things that can't change */ | |
4002 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) | |
4003 | return -EINVAL; | |
4004 | if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY) | |
4005 | return -EINVAL; | |
4006 | if (params->supported_rates) | |
4007 | return -EINVAL; | |
4008 | if (params->ext_capab || params->ht_capa || params->vht_capa) | |
4009 | return -EINVAL; | |
4010 | } | |
4011 | ||
4012 | if (statype != CFG80211_STA_AP_CLIENT) { | |
4013 | if (params->vlan) | |
4014 | return -EINVAL; | |
4015 | } | |
4016 | ||
4017 | switch (statype) { | |
4018 | case CFG80211_STA_AP_MLME_CLIENT: | |
4019 | /* Use this only for authorizing/unauthorizing a station */ | |
4020 | if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))) | |
4021 | return -EOPNOTSUPP; | |
4022 | break; | |
4023 | case CFG80211_STA_AP_CLIENT: | |
4024 | /* accept only the listed bits */ | |
4025 | if (params->sta_flags_mask & | |
4026 | ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4027 | BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4028 | BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4029 | BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) | | |
4030 | BIT(NL80211_STA_FLAG_WME) | | |
4031 | BIT(NL80211_STA_FLAG_MFP))) | |
4032 | return -EINVAL; | |
4033 | ||
4034 | /* but authenticated/associated only if driver handles it */ | |
4035 | if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4036 | params->sta_flags_mask & | |
4037 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4038 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4039 | return -EINVAL; | |
4040 | break; | |
4041 | case CFG80211_STA_IBSS: | |
4042 | case CFG80211_STA_AP_STA: | |
4043 | /* reject any changes other than AUTHORIZED */ | |
4044 | if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED)) | |
4045 | return -EINVAL; | |
4046 | break; | |
4047 | case CFG80211_STA_TDLS_PEER_SETUP: | |
4048 | /* reject any changes other than AUTHORIZED or WME */ | |
4049 | if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) | | |
4050 | BIT(NL80211_STA_FLAG_WME))) | |
4051 | return -EINVAL; | |
4052 | /* force (at least) rates when authorizing */ | |
4053 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) && | |
4054 | !params->supported_rates) | |
4055 | return -EINVAL; | |
4056 | break; | |
4057 | case CFG80211_STA_TDLS_PEER_ACTIVE: | |
4058 | /* reject any changes */ | |
4059 | return -EINVAL; | |
eef941e6 | 4060 | case CFG80211_STA_MESH_PEER_KERNEL: |
77ee7c89 JB |
4061 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) |
4062 | return -EINVAL; | |
4063 | break; | |
eef941e6 | 4064 | case CFG80211_STA_MESH_PEER_USER: |
77ee7c89 JB |
4065 | if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION) |
4066 | return -EINVAL; | |
4067 | break; | |
4068 | } | |
4069 | ||
4070 | return 0; | |
4071 | } | |
4072 | EXPORT_SYMBOL(cfg80211_check_station_change); | |
4073 | ||
5727ef1b | 4074 | /* |
c258d2de | 4075 | * Get vlan interface making sure it is running and on the right wiphy. |
5727ef1b | 4076 | */ |
80b99899 JB |
4077 | static struct net_device *get_vlan(struct genl_info *info, |
4078 | struct cfg80211_registered_device *rdev) | |
5727ef1b | 4079 | { |
463d0183 | 4080 | struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN]; |
80b99899 JB |
4081 | struct net_device *v; |
4082 | int ret; | |
4083 | ||
4084 | if (!vlanattr) | |
4085 | return NULL; | |
4086 | ||
4087 | v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr)); | |
4088 | if (!v) | |
4089 | return ERR_PTR(-ENODEV); | |
4090 | ||
4091 | if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) { | |
4092 | ret = -EINVAL; | |
4093 | goto error; | |
5727ef1b | 4094 | } |
80b99899 | 4095 | |
77ee7c89 JB |
4096 | if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
4097 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && | |
4098 | v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) { | |
4099 | ret = -EINVAL; | |
4100 | goto error; | |
4101 | } | |
4102 | ||
80b99899 JB |
4103 | if (!netif_running(v)) { |
4104 | ret = -ENETDOWN; | |
4105 | goto error; | |
4106 | } | |
4107 | ||
4108 | return v; | |
4109 | error: | |
4110 | dev_put(v); | |
4111 | return ERR_PTR(ret); | |
5727ef1b JB |
4112 | } |
4113 | ||
94e860f1 JB |
4114 | static const struct nla_policy |
4115 | nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = { | |
df881293 JM |
4116 | [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 }, |
4117 | [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 }, | |
4118 | }; | |
4119 | ||
ff276691 JB |
4120 | static int nl80211_parse_sta_wme(struct genl_info *info, |
4121 | struct station_parameters *params) | |
df881293 | 4122 | { |
df881293 JM |
4123 | struct nlattr *tb[NL80211_STA_WME_MAX + 1]; |
4124 | struct nlattr *nla; | |
4125 | int err; | |
4126 | ||
df881293 JM |
4127 | /* parse WME attributes if present */ |
4128 | if (!info->attrs[NL80211_ATTR_STA_WME]) | |
4129 | return 0; | |
4130 | ||
4131 | nla = info->attrs[NL80211_ATTR_STA_WME]; | |
4132 | err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla, | |
4133 | nl80211_sta_wme_policy); | |
4134 | if (err) | |
4135 | return err; | |
4136 | ||
4137 | if (tb[NL80211_STA_WME_UAPSD_QUEUES]) | |
4138 | params->uapsd_queues = nla_get_u8( | |
4139 | tb[NL80211_STA_WME_UAPSD_QUEUES]); | |
4140 | if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK) | |
4141 | return -EINVAL; | |
4142 | ||
4143 | if (tb[NL80211_STA_WME_MAX_SP]) | |
4144 | params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]); | |
4145 | ||
4146 | if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK) | |
4147 | return -EINVAL; | |
4148 | ||
4149 | params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD; | |
4150 | ||
4151 | return 0; | |
4152 | } | |
4153 | ||
c01fc9ad SD |
4154 | static int nl80211_parse_sta_channel_info(struct genl_info *info, |
4155 | struct station_parameters *params) | |
4156 | { | |
4157 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) { | |
4158 | params->supported_channels = | |
4159 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4160 | params->supported_channels_len = | |
4161 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]); | |
4162 | /* | |
4163 | * Need to include at least one (first channel, number of | |
4164 | * channels) tuple for each subband, and must have proper | |
4165 | * tuples for the rest of the data as well. | |
4166 | */ | |
4167 | if (params->supported_channels_len < 2) | |
4168 | return -EINVAL; | |
4169 | if (params->supported_channels_len % 2) | |
4170 | return -EINVAL; | |
4171 | } | |
4172 | ||
4173 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) { | |
4174 | params->supported_oper_classes = | |
4175 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4176 | params->supported_oper_classes_len = | |
4177 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]); | |
4178 | /* | |
4179 | * The value of the Length field of the Supported Operating | |
4180 | * Classes element is between 2 and 253. | |
4181 | */ | |
4182 | if (params->supported_oper_classes_len < 2 || | |
4183 | params->supported_oper_classes_len > 253) | |
4184 | return -EINVAL; | |
4185 | } | |
4186 | return 0; | |
4187 | } | |
4188 | ||
ff276691 JB |
4189 | static int nl80211_set_station_tdls(struct genl_info *info, |
4190 | struct station_parameters *params) | |
4191 | { | |
c01fc9ad | 4192 | int err; |
ff276691 | 4193 | /* Dummy STA entry gets updated once the peer capabilities are known */ |
5e4b6f56 JM |
4194 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
4195 | params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); | |
ff276691 JB |
4196 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4197 | params->ht_capa = | |
4198 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
4199 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) | |
4200 | params->vht_capa = | |
4201 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4202 | ||
c01fc9ad SD |
4203 | err = nl80211_parse_sta_channel_info(info, params); |
4204 | if (err) | |
4205 | return err; | |
4206 | ||
ff276691 JB |
4207 | return nl80211_parse_sta_wme(info, params); |
4208 | } | |
4209 | ||
5727ef1b JB |
4210 | static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info) |
4211 | { | |
4c476991 | 4212 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 4213 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b | 4214 | struct station_parameters params; |
77ee7c89 JB |
4215 | u8 *mac_addr; |
4216 | int err; | |
5727ef1b JB |
4217 | |
4218 | memset(¶ms, 0, sizeof(params)); | |
4219 | ||
4220 | params.listen_interval = -1; | |
4221 | ||
77ee7c89 JB |
4222 | if (!rdev->ops->change_station) |
4223 | return -EOPNOTSUPP; | |
4224 | ||
5727ef1b JB |
4225 | if (info->attrs[NL80211_ATTR_STA_AID]) |
4226 | return -EINVAL; | |
4227 | ||
4228 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4229 | return -EINVAL; | |
4230 | ||
4231 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4232 | ||
4233 | if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) { | |
4234 | params.supported_rates = | |
4235 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4236 | params.supported_rates_len = | |
4237 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4238 | } | |
4239 | ||
9d62a986 JM |
4240 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4241 | params.capability = | |
4242 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4243 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4244 | } | |
4245 | ||
4246 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4247 | params.ext_capab = | |
4248 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4249 | params.ext_capab_len = | |
4250 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4251 | } | |
4252 | ||
df881293 | 4253 | if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
ba23d206 | 4254 | return -EINVAL; |
36aedc90 | 4255 | |
bdd3ae3d | 4256 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4257 | return -EINVAL; |
4258 | ||
f8bacc21 | 4259 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
2ec600d6 | 4260 | params.plink_action = |
f8bacc21 JB |
4261 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4262 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4263 | return -EINVAL; | |
4264 | } | |
2ec600d6 | 4265 | |
f8bacc21 | 4266 | if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) { |
9c3990aa | 4267 | params.plink_state = |
f8bacc21 JB |
4268 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]); |
4269 | if (params.plink_state >= NUM_NL80211_PLINK_STATES) | |
4270 | return -EINVAL; | |
4271 | params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE; | |
4272 | } | |
9c3990aa | 4273 | |
3b1c5a53 MP |
4274 | if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) { |
4275 | enum nl80211_mesh_power_mode pm = nla_get_u32( | |
4276 | info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]); | |
4277 | ||
4278 | if (pm <= NL80211_MESH_POWER_UNKNOWN || | |
4279 | pm > NL80211_MESH_POWER_MAX) | |
4280 | return -EINVAL; | |
4281 | ||
4282 | params.local_pm = pm; | |
4283 | } | |
4284 | ||
77ee7c89 JB |
4285 | /* Include parameters for TDLS peer (will check later) */ |
4286 | err = nl80211_set_station_tdls(info, ¶ms); | |
4287 | if (err) | |
4288 | return err; | |
4289 | ||
4290 | params.vlan = get_vlan(info, rdev); | |
4291 | if (IS_ERR(params.vlan)) | |
4292 | return PTR_ERR(params.vlan); | |
4293 | ||
a97f4424 JB |
4294 | switch (dev->ieee80211_ptr->iftype) { |
4295 | case NL80211_IFTYPE_AP: | |
4296 | case NL80211_IFTYPE_AP_VLAN: | |
074ac8df | 4297 | case NL80211_IFTYPE_P2P_GO: |
074ac8df | 4298 | case NL80211_IFTYPE_P2P_CLIENT: |
a97f4424 | 4299 | case NL80211_IFTYPE_STATION: |
267335d6 | 4300 | case NL80211_IFTYPE_ADHOC: |
a97f4424 | 4301 | case NL80211_IFTYPE_MESH_POINT: |
a97f4424 JB |
4302 | break; |
4303 | default: | |
77ee7c89 JB |
4304 | err = -EOPNOTSUPP; |
4305 | goto out_put_vlan; | |
034d655e JB |
4306 | } |
4307 | ||
77ee7c89 | 4308 | /* driver will call cfg80211_check_station_change() */ |
e35e4d28 | 4309 | err = rdev_change_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4310 | |
77ee7c89 | 4311 | out_put_vlan: |
5727ef1b JB |
4312 | if (params.vlan) |
4313 | dev_put(params.vlan); | |
3b85875a | 4314 | |
5727ef1b JB |
4315 | return err; |
4316 | } | |
4317 | ||
4318 | static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info) | |
4319 | { | |
4c476991 | 4320 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
5727ef1b | 4321 | int err; |
4c476991 | 4322 | struct net_device *dev = info->user_ptr[1]; |
5727ef1b JB |
4323 | struct station_parameters params; |
4324 | u8 *mac_addr = NULL; | |
4325 | ||
4326 | memset(¶ms, 0, sizeof(params)); | |
4327 | ||
984c311b JB |
4328 | if (!rdev->ops->add_station) |
4329 | return -EOPNOTSUPP; | |
4330 | ||
5727ef1b JB |
4331 | if (!info->attrs[NL80211_ATTR_MAC]) |
4332 | return -EINVAL; | |
4333 | ||
5727ef1b JB |
4334 | if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]) |
4335 | return -EINVAL; | |
4336 | ||
4337 | if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) | |
4338 | return -EINVAL; | |
4339 | ||
5e4b6f56 JM |
4340 | if (!info->attrs[NL80211_ATTR_STA_AID] && |
4341 | !info->attrs[NL80211_ATTR_PEER_AID]) | |
0e956c13 TLSC |
4342 | return -EINVAL; |
4343 | ||
5727ef1b JB |
4344 | mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]); |
4345 | params.supported_rates = | |
4346 | nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4347 | params.supported_rates_len = | |
4348 | nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]); | |
4349 | params.listen_interval = | |
4350 | nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]); | |
51b50fbe | 4351 | |
3d124ea2 | 4352 | if (info->attrs[NL80211_ATTR_PEER_AID]) |
5e4b6f56 | 4353 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]); |
3d124ea2 JM |
4354 | else |
4355 | params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]); | |
0e956c13 TLSC |
4356 | if (!params.aid || params.aid > IEEE80211_MAX_AID) |
4357 | return -EINVAL; | |
51b50fbe | 4358 | |
9d62a986 JM |
4359 | if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) { |
4360 | params.capability = | |
4361 | nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]); | |
4362 | params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY; | |
4363 | } | |
4364 | ||
4365 | if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) { | |
4366 | params.ext_capab = | |
4367 | nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4368 | params.ext_capab_len = | |
4369 | nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]); | |
4370 | } | |
4371 | ||
36aedc90 JM |
4372 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) |
4373 | params.ht_capa = | |
4374 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]); | |
5727ef1b | 4375 | |
f461be3e MP |
4376 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) |
4377 | params.vht_capa = | |
4378 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]); | |
4379 | ||
60f4a7b1 MK |
4380 | if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) { |
4381 | params.opmode_notif_used = true; | |
4382 | params.opmode_notif = | |
4383 | nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]); | |
4384 | } | |
4385 | ||
f8bacc21 | 4386 | if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) { |
96b78dff | 4387 | params.plink_action = |
f8bacc21 JB |
4388 | nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]); |
4389 | if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS) | |
4390 | return -EINVAL; | |
4391 | } | |
96b78dff | 4392 | |
c01fc9ad SD |
4393 | err = nl80211_parse_sta_channel_info(info, ¶ms); |
4394 | if (err) | |
4395 | return err; | |
4396 | ||
ff276691 JB |
4397 | err = nl80211_parse_sta_wme(info, ¶ms); |
4398 | if (err) | |
4399 | return err; | |
bdd90d5e | 4400 | |
bdd3ae3d | 4401 | if (parse_station_flags(info, dev->ieee80211_ptr->iftype, ¶ms)) |
5727ef1b JB |
4402 | return -EINVAL; |
4403 | ||
77ee7c89 JB |
4404 | /* When you run into this, adjust the code below for the new flag */ |
4405 | BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7); | |
4406 | ||
bdd90d5e JB |
4407 | switch (dev->ieee80211_ptr->iftype) { |
4408 | case NL80211_IFTYPE_AP: | |
4409 | case NL80211_IFTYPE_AP_VLAN: | |
4410 | case NL80211_IFTYPE_P2P_GO: | |
984c311b JB |
4411 | /* ignore WME attributes if iface/sta is not capable */ |
4412 | if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) || | |
4413 | !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) | |
4414 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
c75786c9 | 4415 | |
bdd90d5e | 4416 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4417 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4418 | info->attrs[NL80211_ATTR_PEER_AID]) | |
4319e193 | 4419 | return -EINVAL; |
bdd90d5e JB |
4420 | /* but don't bother the driver with it */ |
4421 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER); | |
3b9ce80c | 4422 | |
d582cffb JB |
4423 | /* allow authenticated/associated only if driver handles it */ |
4424 | if (!(rdev->wiphy.features & | |
4425 | NL80211_FEATURE_FULL_AP_CLIENT_STATE) && | |
4426 | params.sta_flags_mask & | |
4427 | (BIT(NL80211_STA_FLAG_AUTHENTICATED) | | |
4428 | BIT(NL80211_STA_FLAG_ASSOCIATED))) | |
4429 | return -EINVAL; | |
4430 | ||
bdd90d5e JB |
4431 | /* must be last in here for error handling */ |
4432 | params.vlan = get_vlan(info, rdev); | |
4433 | if (IS_ERR(params.vlan)) | |
4434 | return PTR_ERR(params.vlan); | |
4435 | break; | |
4436 | case NL80211_IFTYPE_MESH_POINT: | |
984c311b JB |
4437 | /* ignore uAPSD data */ |
4438 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4439 | ||
d582cffb JB |
4440 | /* associated is disallowed */ |
4441 | if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) | |
4442 | return -EINVAL; | |
bdd90d5e | 4443 | /* TDLS peers cannot be added */ |
3d124ea2 JM |
4444 | if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) || |
4445 | info->attrs[NL80211_ATTR_PEER_AID]) | |
bdd90d5e JB |
4446 | return -EINVAL; |
4447 | break; | |
4448 | case NL80211_IFTYPE_STATION: | |
93d08f0b | 4449 | case NL80211_IFTYPE_P2P_CLIENT: |
984c311b JB |
4450 | /* ignore uAPSD data */ |
4451 | params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD; | |
4452 | ||
77ee7c89 JB |
4453 | /* these are disallowed */ |
4454 | if (params.sta_flags_mask & | |
4455 | (BIT(NL80211_STA_FLAG_ASSOCIATED) | | |
4456 | BIT(NL80211_STA_FLAG_AUTHENTICATED))) | |
d582cffb | 4457 | return -EINVAL; |
bdd90d5e JB |
4458 | /* Only TDLS peers can be added */ |
4459 | if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) | |
4460 | return -EINVAL; | |
4461 | /* Can only add if TDLS ... */ | |
4462 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS)) | |
4463 | return -EOPNOTSUPP; | |
4464 | /* ... with external setup is supported */ | |
4465 | if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP)) | |
4466 | return -EOPNOTSUPP; | |
77ee7c89 JB |
4467 | /* |
4468 | * Older wpa_supplicant versions always mark the TDLS peer | |
4469 | * as authorized, but it shouldn't yet be. | |
4470 | */ | |
4471 | params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED); | |
bdd90d5e JB |
4472 | break; |
4473 | default: | |
4474 | return -EOPNOTSUPP; | |
c75786c9 EP |
4475 | } |
4476 | ||
bdd90d5e | 4477 | /* be aware of params.vlan when changing code here */ |
5727ef1b | 4478 | |
e35e4d28 | 4479 | err = rdev_add_station(rdev, dev, mac_addr, ¶ms); |
5727ef1b | 4480 | |
5727ef1b JB |
4481 | if (params.vlan) |
4482 | dev_put(params.vlan); | |
5727ef1b JB |
4483 | return err; |
4484 | } | |
4485 | ||
4486 | static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info) | |
4487 | { | |
4c476991 JB |
4488 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4489 | struct net_device *dev = info->user_ptr[1]; | |
89c771e5 JM |
4490 | struct station_del_parameters params; |
4491 | ||
4492 | memset(¶ms, 0, sizeof(params)); | |
5727ef1b JB |
4493 | |
4494 | if (info->attrs[NL80211_ATTR_MAC]) | |
89c771e5 | 4495 | params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]); |
5727ef1b | 4496 | |
e80cf853 | 4497 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
d5d9de02 | 4498 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN && |
074ac8df | 4499 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT && |
4c476991 JB |
4500 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4501 | return -EINVAL; | |
5727ef1b | 4502 | |
4c476991 JB |
4503 | if (!rdev->ops->del_station) |
4504 | return -EOPNOTSUPP; | |
3b85875a | 4505 | |
98856866 JM |
4506 | if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) { |
4507 | params.subtype = | |
4508 | nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]); | |
4509 | if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 && | |
4510 | params.subtype != IEEE80211_STYPE_DEAUTH >> 4) | |
4511 | return -EINVAL; | |
4512 | } else { | |
4513 | /* Default to Deauthentication frame */ | |
4514 | params.subtype = IEEE80211_STYPE_DEAUTH >> 4; | |
4515 | } | |
4516 | ||
4517 | if (info->attrs[NL80211_ATTR_REASON_CODE]) { | |
4518 | params.reason_code = | |
4519 | nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
4520 | if (params.reason_code == 0) | |
4521 | return -EINVAL; /* 0 is reserved */ | |
4522 | } else { | |
4523 | /* Default to reason code 2 */ | |
4524 | params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID; | |
4525 | } | |
4526 | ||
89c771e5 | 4527 | return rdev_del_station(rdev, dev, ¶ms); |
5727ef1b JB |
4528 | } |
4529 | ||
15e47304 | 4530 | static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq, |
2ec600d6 LCC |
4531 | int flags, struct net_device *dev, |
4532 | u8 *dst, u8 *next_hop, | |
4533 | struct mpath_info *pinfo) | |
4534 | { | |
4535 | void *hdr; | |
4536 | struct nlattr *pinfoattr; | |
4537 | ||
1ef4c850 | 4538 | hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH); |
2ec600d6 LCC |
4539 | if (!hdr) |
4540 | return -1; | |
4541 | ||
9360ffd1 DM |
4542 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
4543 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | |
4544 | nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) || | |
4545 | nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation)) | |
4546 | goto nla_put_failure; | |
f5ea9120 | 4547 | |
2ec600d6 LCC |
4548 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO); |
4549 | if (!pinfoattr) | |
4550 | goto nla_put_failure; | |
9360ffd1 DM |
4551 | if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) && |
4552 | nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN, | |
4553 | pinfo->frame_qlen)) | |
4554 | goto nla_put_failure; | |
4555 | if (((pinfo->filled & MPATH_INFO_SN) && | |
4556 | nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) || | |
4557 | ((pinfo->filled & MPATH_INFO_METRIC) && | |
4558 | nla_put_u32(msg, NL80211_MPATH_INFO_METRIC, | |
4559 | pinfo->metric)) || | |
4560 | ((pinfo->filled & MPATH_INFO_EXPTIME) && | |
4561 | nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME, | |
4562 | pinfo->exptime)) || | |
4563 | ((pinfo->filled & MPATH_INFO_FLAGS) && | |
4564 | nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS, | |
4565 | pinfo->flags)) || | |
4566 | ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) && | |
4567 | nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT, | |
4568 | pinfo->discovery_timeout)) || | |
4569 | ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) && | |
4570 | nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES, | |
4571 | pinfo->discovery_retries))) | |
4572 | goto nla_put_failure; | |
2ec600d6 LCC |
4573 | |
4574 | nla_nest_end(msg, pinfoattr); | |
4575 | ||
053c095a JB |
4576 | genlmsg_end(msg, hdr); |
4577 | return 0; | |
2ec600d6 LCC |
4578 | |
4579 | nla_put_failure: | |
bc3ed28c TG |
4580 | genlmsg_cancel(msg, hdr); |
4581 | return -EMSGSIZE; | |
2ec600d6 LCC |
4582 | } |
4583 | ||
4584 | static int nl80211_dump_mpath(struct sk_buff *skb, | |
bba95fef | 4585 | struct netlink_callback *cb) |
2ec600d6 | 4586 | { |
2ec600d6 | 4587 | struct mpath_info pinfo; |
1b8ec87a | 4588 | struct cfg80211_registered_device *rdev; |
97990a06 | 4589 | struct wireless_dev *wdev; |
2ec600d6 LCC |
4590 | u8 dst[ETH_ALEN]; |
4591 | u8 next_hop[ETH_ALEN]; | |
97990a06 | 4592 | int path_idx = cb->args[2]; |
2ec600d6 | 4593 | int err; |
2ec600d6 | 4594 | |
1b8ec87a | 4595 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
4596 | if (err) |
4597 | return err; | |
bba95fef | 4598 | |
1b8ec87a | 4599 | if (!rdev->ops->dump_mpath) { |
eec60b03 | 4600 | err = -EOPNOTSUPP; |
bba95fef JB |
4601 | goto out_err; |
4602 | } | |
4603 | ||
97990a06 | 4604 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { |
eec60b03 | 4605 | err = -EOPNOTSUPP; |
0448b5fc | 4606 | goto out_err; |
eec60b03 JM |
4607 | } |
4608 | ||
bba95fef | 4609 | while (1) { |
1b8ec87a | 4610 | err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst, |
97990a06 | 4611 | next_hop, &pinfo); |
bba95fef | 4612 | if (err == -ENOENT) |
2ec600d6 | 4613 | break; |
bba95fef | 4614 | if (err) |
3b85875a | 4615 | goto out_err; |
2ec600d6 | 4616 | |
15e47304 | 4617 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, |
bba95fef | 4618 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
97990a06 | 4619 | wdev->netdev, dst, next_hop, |
bba95fef JB |
4620 | &pinfo) < 0) |
4621 | goto out; | |
2ec600d6 | 4622 | |
bba95fef | 4623 | path_idx++; |
2ec600d6 | 4624 | } |
2ec600d6 | 4625 | |
2ec600d6 | 4626 | |
bba95fef | 4627 | out: |
97990a06 | 4628 | cb->args[2] = path_idx; |
bba95fef | 4629 | err = skb->len; |
bba95fef | 4630 | out_err: |
1b8ec87a | 4631 | nl80211_finish_wdev_dump(rdev); |
bba95fef | 4632 | return err; |
2ec600d6 LCC |
4633 | } |
4634 | ||
4635 | static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info) | |
4636 | { | |
4c476991 | 4637 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
2ec600d6 | 4638 | int err; |
4c476991 | 4639 | struct net_device *dev = info->user_ptr[1]; |
2ec600d6 LCC |
4640 | struct mpath_info pinfo; |
4641 | struct sk_buff *msg; | |
4642 | u8 *dst = NULL; | |
4643 | u8 next_hop[ETH_ALEN]; | |
4644 | ||
4645 | memset(&pinfo, 0, sizeof(pinfo)); | |
4646 | ||
4647 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4648 | return -EINVAL; | |
4649 | ||
4650 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4651 | ||
4c476991 JB |
4652 | if (!rdev->ops->get_mpath) |
4653 | return -EOPNOTSUPP; | |
2ec600d6 | 4654 | |
4c476991 JB |
4655 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4656 | return -EOPNOTSUPP; | |
eec60b03 | 4657 | |
e35e4d28 | 4658 | err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo); |
2ec600d6 | 4659 | if (err) |
4c476991 | 4660 | return err; |
2ec600d6 | 4661 | |
fd2120ca | 4662 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2ec600d6 | 4663 | if (!msg) |
4c476991 | 4664 | return -ENOMEM; |
2ec600d6 | 4665 | |
15e47304 | 4666 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, |
4c476991 JB |
4667 | dev, dst, next_hop, &pinfo) < 0) { |
4668 | nlmsg_free(msg); | |
4669 | return -ENOBUFS; | |
4670 | } | |
3b85875a | 4671 | |
4c476991 | 4672 | return genlmsg_reply(msg, info); |
2ec600d6 LCC |
4673 | } |
4674 | ||
4675 | static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info) | |
4676 | { | |
4c476991 JB |
4677 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4678 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4679 | u8 *dst = NULL; |
4680 | u8 *next_hop = NULL; | |
4681 | ||
4682 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4683 | return -EINVAL; | |
4684 | ||
4685 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4686 | return -EINVAL; | |
4687 | ||
4688 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4689 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4690 | ||
4c476991 JB |
4691 | if (!rdev->ops->change_mpath) |
4692 | return -EOPNOTSUPP; | |
35a8efe1 | 4693 | |
4c476991 JB |
4694 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4695 | return -EOPNOTSUPP; | |
2ec600d6 | 4696 | |
e35e4d28 | 4697 | return rdev_change_mpath(rdev, dev, dst, next_hop); |
2ec600d6 | 4698 | } |
4c476991 | 4699 | |
2ec600d6 LCC |
4700 | static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info) |
4701 | { | |
4c476991 JB |
4702 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4703 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4704 | u8 *dst = NULL; |
4705 | u8 *next_hop = NULL; | |
4706 | ||
4707 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4708 | return -EINVAL; | |
4709 | ||
4710 | if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]) | |
4711 | return -EINVAL; | |
4712 | ||
4713 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4714 | next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]); | |
4715 | ||
4c476991 JB |
4716 | if (!rdev->ops->add_mpath) |
4717 | return -EOPNOTSUPP; | |
35a8efe1 | 4718 | |
4c476991 JB |
4719 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) |
4720 | return -EOPNOTSUPP; | |
2ec600d6 | 4721 | |
e35e4d28 | 4722 | return rdev_add_mpath(rdev, dev, dst, next_hop); |
2ec600d6 LCC |
4723 | } |
4724 | ||
4725 | static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info) | |
4726 | { | |
4c476991 JB |
4727 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4728 | struct net_device *dev = info->user_ptr[1]; | |
2ec600d6 LCC |
4729 | u8 *dst = NULL; |
4730 | ||
4731 | if (info->attrs[NL80211_ATTR_MAC]) | |
4732 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4733 | ||
4c476991 JB |
4734 | if (!rdev->ops->del_mpath) |
4735 | return -EOPNOTSUPP; | |
3b85875a | 4736 | |
e35e4d28 | 4737 | return rdev_del_mpath(rdev, dev, dst); |
2ec600d6 LCC |
4738 | } |
4739 | ||
66be7d2b HR |
4740 | static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info) |
4741 | { | |
4742 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
4743 | int err; | |
4744 | struct net_device *dev = info->user_ptr[1]; | |
4745 | struct mpath_info pinfo; | |
4746 | struct sk_buff *msg; | |
4747 | u8 *dst = NULL; | |
4748 | u8 mpp[ETH_ALEN]; | |
4749 | ||
4750 | memset(&pinfo, 0, sizeof(pinfo)); | |
4751 | ||
4752 | if (!info->attrs[NL80211_ATTR_MAC]) | |
4753 | return -EINVAL; | |
4754 | ||
4755 | dst = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
4756 | ||
4757 | if (!rdev->ops->get_mpp) | |
4758 | return -EOPNOTSUPP; | |
4759 | ||
4760 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
4761 | return -EOPNOTSUPP; | |
4762 | ||
4763 | err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo); | |
4764 | if (err) | |
4765 | return err; | |
4766 | ||
4767 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4768 | if (!msg) | |
4769 | return -ENOMEM; | |
4770 | ||
4771 | if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0, | |
4772 | dev, dst, mpp, &pinfo) < 0) { | |
4773 | nlmsg_free(msg); | |
4774 | return -ENOBUFS; | |
4775 | } | |
4776 | ||
4777 | return genlmsg_reply(msg, info); | |
4778 | } | |
4779 | ||
4780 | static int nl80211_dump_mpp(struct sk_buff *skb, | |
4781 | struct netlink_callback *cb) | |
4782 | { | |
4783 | struct mpath_info pinfo; | |
4784 | struct cfg80211_registered_device *rdev; | |
4785 | struct wireless_dev *wdev; | |
4786 | u8 dst[ETH_ALEN]; | |
4787 | u8 mpp[ETH_ALEN]; | |
4788 | int path_idx = cb->args[2]; | |
4789 | int err; | |
4790 | ||
4791 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); | |
4792 | if (err) | |
4793 | return err; | |
4794 | ||
4795 | if (!rdev->ops->dump_mpp) { | |
4796 | err = -EOPNOTSUPP; | |
4797 | goto out_err; | |
4798 | } | |
4799 | ||
4800 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) { | |
4801 | err = -EOPNOTSUPP; | |
4802 | goto out_err; | |
4803 | } | |
4804 | ||
4805 | while (1) { | |
4806 | err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst, | |
4807 | mpp, &pinfo); | |
4808 | if (err == -ENOENT) | |
4809 | break; | |
4810 | if (err) | |
4811 | goto out_err; | |
4812 | ||
4813 | if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid, | |
4814 | cb->nlh->nlmsg_seq, NLM_F_MULTI, | |
4815 | wdev->netdev, dst, mpp, | |
4816 | &pinfo) < 0) | |
4817 | goto out; | |
4818 | ||
4819 | path_idx++; | |
4820 | } | |
4821 | ||
4822 | out: | |
4823 | cb->args[2] = path_idx; | |
4824 | err = skb->len; | |
4825 | out_err: | |
4826 | nl80211_finish_wdev_dump(rdev); | |
4827 | return err; | |
4828 | } | |
4829 | ||
9f1ba906 JM |
4830 | static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info) |
4831 | { | |
4c476991 JB |
4832 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4833 | struct net_device *dev = info->user_ptr[1]; | |
c56589ed | 4834 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
9f1ba906 | 4835 | struct bss_parameters params; |
c56589ed | 4836 | int err; |
9f1ba906 JM |
4837 | |
4838 | memset(¶ms, 0, sizeof(params)); | |
4839 | /* default to not changing parameters */ | |
4840 | params.use_cts_prot = -1; | |
4841 | params.use_short_preamble = -1; | |
4842 | params.use_short_slot_time = -1; | |
fd8aaaf3 | 4843 | params.ap_isolate = -1; |
50b12f59 | 4844 | params.ht_opmode = -1; |
53cabad7 JB |
4845 | params.p2p_ctwindow = -1; |
4846 | params.p2p_opp_ps = -1; | |
9f1ba906 JM |
4847 | |
4848 | if (info->attrs[NL80211_ATTR_BSS_CTS_PROT]) | |
4849 | params.use_cts_prot = | |
4850 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]); | |
4851 | if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]) | |
4852 | params.use_short_preamble = | |
4853 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]); | |
4854 | if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]) | |
4855 | params.use_short_slot_time = | |
4856 | nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]); | |
90c97a04 JM |
4857 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
4858 | params.basic_rates = | |
4859 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4860 | params.basic_rates_len = | |
4861 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
4862 | } | |
fd8aaaf3 FF |
4863 | if (info->attrs[NL80211_ATTR_AP_ISOLATE]) |
4864 | params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]); | |
50b12f59 HS |
4865 | if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE]) |
4866 | params.ht_opmode = | |
4867 | nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]); | |
9f1ba906 | 4868 | |
53cabad7 JB |
4869 | if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) { |
4870 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4871 | return -EINVAL; | |
4872 | params.p2p_ctwindow = | |
4873 | nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]); | |
4874 | if (params.p2p_ctwindow < 0) | |
4875 | return -EINVAL; | |
4876 | if (params.p2p_ctwindow != 0 && | |
4877 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN)) | |
4878 | return -EINVAL; | |
4879 | } | |
4880 | ||
4881 | if (info->attrs[NL80211_ATTR_P2P_OPPPS]) { | |
4882 | u8 tmp; | |
4883 | ||
4884 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) | |
4885 | return -EINVAL; | |
4886 | tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]); | |
4887 | if (tmp > 1) | |
4888 | return -EINVAL; | |
4889 | params.p2p_opp_ps = tmp; | |
4890 | if (params.p2p_opp_ps && | |
4891 | !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS)) | |
4892 | return -EINVAL; | |
4893 | } | |
4894 | ||
4c476991 JB |
4895 | if (!rdev->ops->change_bss) |
4896 | return -EOPNOTSUPP; | |
9f1ba906 | 4897 | |
074ac8df | 4898 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP && |
4c476991 JB |
4899 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) |
4900 | return -EOPNOTSUPP; | |
3b85875a | 4901 | |
c56589ed SW |
4902 | wdev_lock(wdev); |
4903 | err = rdev_change_bss(rdev, dev, ¶ms); | |
4904 | wdev_unlock(wdev); | |
4905 | ||
4906 | return err; | |
9f1ba906 JM |
4907 | } |
4908 | ||
b54452b0 | 4909 | static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = { |
b2e1b302 LR |
4910 | [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 }, |
4911 | [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 }, | |
4912 | [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 }, | |
4913 | [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 }, | |
4914 | [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 }, | |
4915 | [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 }, | |
089027e5 | 4916 | [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 }, |
b2e1b302 LR |
4917 | }; |
4918 | ||
4919 | static int parse_reg_rule(struct nlattr *tb[], | |
4920 | struct ieee80211_reg_rule *reg_rule) | |
4921 | { | |
4922 | struct ieee80211_freq_range *freq_range = ®_rule->freq_range; | |
4923 | struct ieee80211_power_rule *power_rule = ®_rule->power_rule; | |
4924 | ||
4925 | if (!tb[NL80211_ATTR_REG_RULE_FLAGS]) | |
4926 | return -EINVAL; | |
4927 | if (!tb[NL80211_ATTR_FREQ_RANGE_START]) | |
4928 | return -EINVAL; | |
4929 | if (!tb[NL80211_ATTR_FREQ_RANGE_END]) | |
4930 | return -EINVAL; | |
b0dfd2ea JD |
4931 | if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]) |
4932 | return -EINVAL; | |
b2e1b302 LR |
4933 | if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]) |
4934 | return -EINVAL; | |
4935 | ||
4936 | reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]); | |
4937 | ||
4938 | freq_range->start_freq_khz = | |
4939 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]); | |
4940 | freq_range->end_freq_khz = | |
4941 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]); | |
b0dfd2ea JD |
4942 | freq_range->max_bandwidth_khz = |
4943 | nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]); | |
b2e1b302 LR |
4944 | |
4945 | power_rule->max_eirp = | |
4946 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]); | |
4947 | ||
4948 | if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]) | |
4949 | power_rule->max_antenna_gain = | |
4950 | nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]); | |
4951 | ||
089027e5 JD |
4952 | if (tb[NL80211_ATTR_DFS_CAC_TIME]) |
4953 | reg_rule->dfs_cac_ms = | |
4954 | nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]); | |
4955 | ||
b2e1b302 LR |
4956 | return 0; |
4957 | } | |
4958 | ||
4959 | static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info) | |
4960 | { | |
b2e1b302 | 4961 | char *data = NULL; |
05050753 | 4962 | bool is_indoor; |
57b5ce07 | 4963 | enum nl80211_user_reg_hint_type user_reg_hint_type; |
05050753 I |
4964 | u32 owner_nlportid; |
4965 | ||
b2e1b302 | 4966 | |
80778f18 LR |
4967 | /* |
4968 | * You should only get this when cfg80211 hasn't yet initialized | |
4969 | * completely when built-in to the kernel right between the time | |
4970 | * window between nl80211_init() and regulatory_init(), if that is | |
4971 | * even possible. | |
4972 | */ | |
458f4f9e | 4973 | if (unlikely(!rcu_access_pointer(cfg80211_regdomain))) |
fe33eb39 | 4974 | return -EINPROGRESS; |
80778f18 | 4975 | |
57b5ce07 LR |
4976 | if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]) |
4977 | user_reg_hint_type = | |
4978 | nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]); | |
4979 | else | |
4980 | user_reg_hint_type = NL80211_USER_REG_HINT_USER; | |
4981 | ||
4982 | switch (user_reg_hint_type) { | |
4983 | case NL80211_USER_REG_HINT_USER: | |
4984 | case NL80211_USER_REG_HINT_CELL_BASE: | |
52616f2b IP |
4985 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) |
4986 | return -EINVAL; | |
4987 | ||
4988 | data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
4989 | return regulatory_hint_user(data, user_reg_hint_type); | |
4990 | case NL80211_USER_REG_HINT_INDOOR: | |
05050753 I |
4991 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) { |
4992 | owner_nlportid = info->snd_portid; | |
4993 | is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR]; | |
4994 | } else { | |
4995 | owner_nlportid = 0; | |
4996 | is_indoor = true; | |
4997 | } | |
4998 | ||
4999 | return regulatory_hint_indoor(is_indoor, owner_nlportid); | |
57b5ce07 LR |
5000 | default: |
5001 | return -EINVAL; | |
5002 | } | |
b2e1b302 LR |
5003 | } |
5004 | ||
24bdd9f4 | 5005 | static int nl80211_get_mesh_config(struct sk_buff *skb, |
29cbe68c | 5006 | struct genl_info *info) |
93da9cc1 | 5007 | { |
4c476991 | 5008 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 5009 | struct net_device *dev = info->user_ptr[1]; |
29cbe68c JB |
5010 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5011 | struct mesh_config cur_params; | |
5012 | int err = 0; | |
93da9cc1 | 5013 | void *hdr; |
5014 | struct nlattr *pinfoattr; | |
5015 | struct sk_buff *msg; | |
5016 | ||
29cbe68c JB |
5017 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5018 | return -EOPNOTSUPP; | |
5019 | ||
24bdd9f4 | 5020 | if (!rdev->ops->get_mesh_config) |
4c476991 | 5021 | return -EOPNOTSUPP; |
f3f92586 | 5022 | |
29cbe68c JB |
5023 | wdev_lock(wdev); |
5024 | /* If not connected, get default parameters */ | |
5025 | if (!wdev->mesh_id_len) | |
5026 | memcpy(&cur_params, &default_mesh_config, sizeof(cur_params)); | |
5027 | else | |
e35e4d28 | 5028 | err = rdev_get_mesh_config(rdev, dev, &cur_params); |
29cbe68c JB |
5029 | wdev_unlock(wdev); |
5030 | ||
93da9cc1 | 5031 | if (err) |
4c476991 | 5032 | return err; |
93da9cc1 | 5033 | |
5034 | /* Draw up a netlink message to send back */ | |
fd2120ca | 5035 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
4c476991 JB |
5036 | if (!msg) |
5037 | return -ENOMEM; | |
15e47304 | 5038 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
24bdd9f4 | 5039 | NL80211_CMD_GET_MESH_CONFIG); |
93da9cc1 | 5040 | if (!hdr) |
efe1cf0c | 5041 | goto out; |
24bdd9f4 | 5042 | pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
93da9cc1 | 5043 | if (!pinfoattr) |
5044 | goto nla_put_failure; | |
9360ffd1 DM |
5045 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
5046 | nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT, | |
5047 | cur_params.dot11MeshRetryTimeout) || | |
5048 | nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT, | |
5049 | cur_params.dot11MeshConfirmTimeout) || | |
5050 | nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT, | |
5051 | cur_params.dot11MeshHoldingTimeout) || | |
5052 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | |
5053 | cur_params.dot11MeshMaxPeerLinks) || | |
5054 | nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES, | |
5055 | cur_params.dot11MeshMaxRetries) || | |
5056 | nla_put_u8(msg, NL80211_MESHCONF_TTL, | |
5057 | cur_params.dot11MeshTTL) || | |
5058 | nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL, | |
5059 | cur_params.element_ttl) || | |
5060 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | |
5061 | cur_params.auto_open_plinks) || | |
7eab0f64 JL |
5062 | nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5063 | cur_params.dot11MeshNbrOffsetMaxNeighbor) || | |
9360ffd1 DM |
5064 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5065 | cur_params.dot11MeshHWMPmaxPREQretries) || | |
5066 | nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME, | |
5067 | cur_params.path_refresh_time) || | |
5068 | nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, | |
5069 | cur_params.min_discovery_timeout) || | |
5070 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, | |
5071 | cur_params.dot11MeshHWMPactivePathTimeout) || | |
5072 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
5073 | cur_params.dot11MeshHWMPpreqMinInterval) || | |
5074 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
5075 | cur_params.dot11MeshHWMPperrMinInterval) || | |
5076 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, | |
5077 | cur_params.dot11MeshHWMPnetDiameterTraversalTime) || | |
5078 | nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5079 | cur_params.dot11MeshHWMPRootMode) || | |
5080 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
5081 | cur_params.dot11MeshHWMPRannInterval) || | |
5082 | nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
5083 | cur_params.dot11MeshGateAnnouncementProtocol) || | |
5084 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, | |
5085 | cur_params.dot11MeshForwarding) || | |
5086 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | |
70c33eaa AN |
5087 | cur_params.rssi_threshold) || |
5088 | nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE, | |
ac1073a6 CYY |
5089 | cur_params.ht_opmode) || |
5090 | nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, | |
5091 | cur_params.dot11MeshHWMPactivePathToRootTimeout) || | |
5092 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, | |
728b19e5 CYY |
5093 | cur_params.dot11MeshHWMProotInterval) || |
5094 | nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, | |
3b1c5a53 MP |
5095 | cur_params.dot11MeshHWMPconfirmationInterval) || |
5096 | nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE, | |
5097 | cur_params.power_mode) || | |
5098 | nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW, | |
8e7c0538 CT |
5099 | cur_params.dot11MeshAwakeWindowDuration) || |
5100 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | |
5101 | cur_params.plink_timeout)) | |
9360ffd1 | 5102 | goto nla_put_failure; |
93da9cc1 | 5103 | nla_nest_end(msg, pinfoattr); |
5104 | genlmsg_end(msg, hdr); | |
4c476991 | 5105 | return genlmsg_reply(msg, info); |
93da9cc1 | 5106 | |
3b85875a | 5107 | nla_put_failure: |
93da9cc1 | 5108 | genlmsg_cancel(msg, hdr); |
efe1cf0c | 5109 | out: |
d080e275 | 5110 | nlmsg_free(msg); |
4c476991 | 5111 | return -ENOBUFS; |
93da9cc1 | 5112 | } |
5113 | ||
b54452b0 | 5114 | static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = { |
93da9cc1 | 5115 | [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 }, |
5116 | [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 }, | |
5117 | [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 }, | |
5118 | [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 }, | |
5119 | [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 }, | |
5120 | [NL80211_MESHCONF_TTL] = { .type = NLA_U8 }, | |
45904f21 | 5121 | [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 }, |
93da9cc1 | 5122 | [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 }, |
d299a1f2 | 5123 | [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 }, |
93da9cc1 | 5124 | [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 }, |
5125 | [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 }, | |
5126 | [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 }, | |
5127 | [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 }, | |
5128 | [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 }, | |
dca7e943 | 5129 | [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 }, |
93da9cc1 | 5130 | [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 }, |
699403db | 5131 | [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 }, |
0507e159 | 5132 | [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 }, |
16dd7267 | 5133 | [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 }, |
94f90656 | 5134 | [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 }, |
a4f606ea CYY |
5135 | [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 }, |
5136 | [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 }, | |
ac1073a6 CYY |
5137 | [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 }, |
5138 | [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 }, | |
728b19e5 | 5139 | [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 }, |
3b1c5a53 MP |
5140 | [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 }, |
5141 | [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 }, | |
8e7c0538 | 5142 | [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 }, |
93da9cc1 | 5143 | }; |
5144 | ||
c80d545d JC |
5145 | static const struct nla_policy |
5146 | nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = { | |
d299a1f2 | 5147 | [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 }, |
c80d545d JC |
5148 | [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 }, |
5149 | [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 }, | |
15d5dda6 | 5150 | [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG }, |
6e16d90b | 5151 | [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 }, |
bb2798d4 | 5152 | [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG }, |
581a8b0f | 5153 | [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY, |
a4f606ea | 5154 | .len = IEEE80211_MAX_DATA_LEN }, |
b130e5ce | 5155 | [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG }, |
c80d545d JC |
5156 | }; |
5157 | ||
24bdd9f4 | 5158 | static int nl80211_parse_mesh_config(struct genl_info *info, |
bd90fdcc JB |
5159 | struct mesh_config *cfg, |
5160 | u32 *mask_out) | |
93da9cc1 | 5161 | { |
93da9cc1 | 5162 | struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1]; |
bd90fdcc | 5163 | u32 mask = 0; |
93da9cc1 | 5164 | |
ea54fba2 MP |
5165 | #define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \ |
5166 | do { \ | |
5167 | if (tb[attr]) { \ | |
5168 | if (fn(tb[attr]) < min || fn(tb[attr]) > max) \ | |
5169 | return -EINVAL; \ | |
5170 | cfg->param = fn(tb[attr]); \ | |
5171 | mask |= (1 << (attr - 1)); \ | |
5172 | } \ | |
5173 | } while (0) | |
bd90fdcc JB |
5174 | |
5175 | ||
24bdd9f4 | 5176 | if (!info->attrs[NL80211_ATTR_MESH_CONFIG]) |
93da9cc1 | 5177 | return -EINVAL; |
5178 | if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX, | |
24bdd9f4 | 5179 | info->attrs[NL80211_ATTR_MESH_CONFIG], |
bd90fdcc | 5180 | nl80211_meshconf_params_policy)) |
93da9cc1 | 5181 | return -EINVAL; |
5182 | ||
93da9cc1 | 5183 | /* This makes sure that there aren't more than 32 mesh config |
5184 | * parameters (otherwise our bitfield scheme would not work.) */ | |
5185 | BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32); | |
5186 | ||
5187 | /* Fill in the params struct */ | |
ea54fba2 | 5188 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255, |
a4f606ea CYY |
5189 | mask, NL80211_MESHCONF_RETRY_TIMEOUT, |
5190 | nla_get_u16); | |
ea54fba2 | 5191 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255, |
a4f606ea CYY |
5192 | mask, NL80211_MESHCONF_CONFIRM_TIMEOUT, |
5193 | nla_get_u16); | |
ea54fba2 | 5194 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255, |
a4f606ea CYY |
5195 | mask, NL80211_MESHCONF_HOLDING_TIMEOUT, |
5196 | nla_get_u16); | |
ea54fba2 | 5197 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255, |
a4f606ea CYY |
5198 | mask, NL80211_MESHCONF_MAX_PEER_LINKS, |
5199 | nla_get_u16); | |
ea54fba2 | 5200 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16, |
a4f606ea CYY |
5201 | mask, NL80211_MESHCONF_MAX_RETRIES, |
5202 | nla_get_u8); | |
ea54fba2 | 5203 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255, |
a4f606ea | 5204 | mask, NL80211_MESHCONF_TTL, nla_get_u8); |
ea54fba2 | 5205 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255, |
a4f606ea CYY |
5206 | mask, NL80211_MESHCONF_ELEMENT_TTL, |
5207 | nla_get_u8); | |
ea54fba2 | 5208 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1, |
a4f606ea CYY |
5209 | mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
5210 | nla_get_u8); | |
ea54fba2 MP |
5211 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor, |
5212 | 1, 255, mask, | |
a4f606ea CYY |
5213 | NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, |
5214 | nla_get_u32); | |
ea54fba2 | 5215 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255, |
a4f606ea CYY |
5216 | mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, |
5217 | nla_get_u8); | |
ea54fba2 | 5218 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535, |
a4f606ea CYY |
5219 | mask, NL80211_MESHCONF_PATH_REFRESH_TIME, |
5220 | nla_get_u32); | |
ea54fba2 | 5221 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535, |
a4f606ea CYY |
5222 | mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, |
5223 | nla_get_u16); | |
ea54fba2 MP |
5224 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout, |
5225 | 1, 65535, mask, | |
a4f606ea CYY |
5226 | NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, |
5227 | nla_get_u32); | |
93da9cc1 | 5228 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval, |
ea54fba2 MP |
5229 | 1, 65535, mask, |
5230 | NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, | |
a4f606ea | 5231 | nla_get_u16); |
dca7e943 | 5232 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval, |
ea54fba2 MP |
5233 | 1, 65535, mask, |
5234 | NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, | |
a4f606ea | 5235 | nla_get_u16); |
93da9cc1 | 5236 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5237 | dot11MeshHWMPnetDiameterTraversalTime, |
5238 | 1, 65535, mask, | |
a4f606ea CYY |
5239 | NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
5240 | nla_get_u16); | |
ea54fba2 MP |
5241 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4, |
5242 | mask, NL80211_MESHCONF_HWMP_ROOTMODE, | |
5243 | nla_get_u8); | |
5244 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535, | |
5245 | mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL, | |
a4f606ea | 5246 | nla_get_u16); |
63c5723b | 5247 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, |
ea54fba2 MP |
5248 | dot11MeshGateAnnouncementProtocol, 0, 1, |
5249 | mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS, | |
a4f606ea | 5250 | nla_get_u8); |
ea54fba2 | 5251 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1, |
a4f606ea CYY |
5252 | mask, NL80211_MESHCONF_FORWARDING, |
5253 | nla_get_u8); | |
83374fe9 | 5254 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0, |
a4f606ea | 5255 | mask, NL80211_MESHCONF_RSSI_THRESHOLD, |
83374fe9 | 5256 | nla_get_s32); |
ea54fba2 | 5257 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16, |
a4f606ea | 5258 | mask, NL80211_MESHCONF_HT_OPMODE, |
ac1073a6 CYY |
5259 | nla_get_u16); |
5260 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout, | |
ea54fba2 | 5261 | 1, 65535, mask, |
ac1073a6 CYY |
5262 | NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, |
5263 | nla_get_u32); | |
ea54fba2 | 5264 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535, |
ac1073a6 | 5265 | mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL, |
728b19e5 CYY |
5266 | nla_get_u16); |
5267 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, | |
ea54fba2 MP |
5268 | dot11MeshHWMPconfirmationInterval, |
5269 | 1, 65535, mask, | |
728b19e5 | 5270 | NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, |
a4f606ea | 5271 | nla_get_u16); |
3b1c5a53 MP |
5272 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode, |
5273 | NL80211_MESH_POWER_ACTIVE, | |
5274 | NL80211_MESH_POWER_MAX, | |
5275 | mask, NL80211_MESHCONF_POWER_MODE, | |
5276 | nla_get_u32); | |
5277 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration, | |
5278 | 0, 65535, mask, | |
5279 | NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16); | |
31f909a2 | 5280 | FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff, |
8e7c0538 CT |
5281 | mask, NL80211_MESHCONF_PLINK_TIMEOUT, |
5282 | nla_get_u32); | |
bd90fdcc JB |
5283 | if (mask_out) |
5284 | *mask_out = mask; | |
c80d545d | 5285 | |
bd90fdcc JB |
5286 | return 0; |
5287 | ||
5288 | #undef FILL_IN_MESH_PARAM_IF_SET | |
5289 | } | |
5290 | ||
c80d545d JC |
5291 | static int nl80211_parse_mesh_setup(struct genl_info *info, |
5292 | struct mesh_setup *setup) | |
5293 | { | |
bb2798d4 | 5294 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
c80d545d JC |
5295 | struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1]; |
5296 | ||
5297 | if (!info->attrs[NL80211_ATTR_MESH_SETUP]) | |
5298 | return -EINVAL; | |
5299 | if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX, | |
5300 | info->attrs[NL80211_ATTR_MESH_SETUP], | |
5301 | nl80211_mesh_setup_params_policy)) | |
5302 | return -EINVAL; | |
5303 | ||
d299a1f2 JC |
5304 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC]) |
5305 | setup->sync_method = | |
5306 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ? | |
5307 | IEEE80211_SYNC_METHOD_VENDOR : | |
5308 | IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET; | |
5309 | ||
c80d545d JC |
5310 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL]) |
5311 | setup->path_sel_proto = | |
5312 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ? | |
5313 | IEEE80211_PATH_PROTOCOL_VENDOR : | |
5314 | IEEE80211_PATH_PROTOCOL_HWMP; | |
5315 | ||
5316 | if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC]) | |
5317 | setup->path_metric = | |
5318 | (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ? | |
5319 | IEEE80211_PATH_METRIC_VENDOR : | |
5320 | IEEE80211_PATH_METRIC_AIRTIME; | |
5321 | ||
581a8b0f JC |
5322 | |
5323 | if (tb[NL80211_MESH_SETUP_IE]) { | |
c80d545d | 5324 | struct nlattr *ieattr = |
581a8b0f | 5325 | tb[NL80211_MESH_SETUP_IE]; |
c80d545d JC |
5326 | if (!is_valid_ie_attr(ieattr)) |
5327 | return -EINVAL; | |
581a8b0f JC |
5328 | setup->ie = nla_data(ieattr); |
5329 | setup->ie_len = nla_len(ieattr); | |
c80d545d | 5330 | } |
bb2798d4 TP |
5331 | if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] && |
5332 | !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM)) | |
5333 | return -EINVAL; | |
5334 | setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]); | |
b130e5ce JC |
5335 | setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]); |
5336 | setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]); | |
bb2798d4 TP |
5337 | if (setup->is_secure) |
5338 | setup->user_mpm = true; | |
c80d545d | 5339 | |
6e16d90b CT |
5340 | if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) { |
5341 | if (!setup->user_mpm) | |
5342 | return -EINVAL; | |
5343 | setup->auth_id = | |
5344 | nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]); | |
5345 | } | |
5346 | ||
c80d545d JC |
5347 | return 0; |
5348 | } | |
5349 | ||
24bdd9f4 | 5350 | static int nl80211_update_mesh_config(struct sk_buff *skb, |
29cbe68c | 5351 | struct genl_info *info) |
bd90fdcc JB |
5352 | { |
5353 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
5354 | struct net_device *dev = info->user_ptr[1]; | |
29cbe68c | 5355 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
bd90fdcc JB |
5356 | struct mesh_config cfg; |
5357 | u32 mask; | |
5358 | int err; | |
5359 | ||
29cbe68c JB |
5360 | if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) |
5361 | return -EOPNOTSUPP; | |
5362 | ||
24bdd9f4 | 5363 | if (!rdev->ops->update_mesh_config) |
bd90fdcc JB |
5364 | return -EOPNOTSUPP; |
5365 | ||
24bdd9f4 | 5366 | err = nl80211_parse_mesh_config(info, &cfg, &mask); |
bd90fdcc JB |
5367 | if (err) |
5368 | return err; | |
5369 | ||
29cbe68c JB |
5370 | wdev_lock(wdev); |
5371 | if (!wdev->mesh_id_len) | |
5372 | err = -ENOLINK; | |
5373 | ||
5374 | if (!err) | |
e35e4d28 | 5375 | err = rdev_update_mesh_config(rdev, dev, mask, &cfg); |
29cbe68c JB |
5376 | |
5377 | wdev_unlock(wdev); | |
5378 | ||
5379 | return err; | |
93da9cc1 | 5380 | } |
5381 | ||
ad30ca2c AN |
5382 | static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom, |
5383 | struct sk_buff *msg) | |
f130347c | 5384 | { |
f130347c LR |
5385 | struct nlattr *nl_reg_rules; |
5386 | unsigned int i; | |
f130347c | 5387 | |
458f4f9e JB |
5388 | if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) || |
5389 | (regdom->dfs_region && | |
5390 | nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region))) | |
ad30ca2c | 5391 | goto nla_put_failure; |
458f4f9e | 5392 | |
f130347c LR |
5393 | nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES); |
5394 | if (!nl_reg_rules) | |
ad30ca2c | 5395 | goto nla_put_failure; |
f130347c | 5396 | |
458f4f9e | 5397 | for (i = 0; i < regdom->n_reg_rules; i++) { |
f130347c LR |
5398 | struct nlattr *nl_reg_rule; |
5399 | const struct ieee80211_reg_rule *reg_rule; | |
5400 | const struct ieee80211_freq_range *freq_range; | |
5401 | const struct ieee80211_power_rule *power_rule; | |
97524820 | 5402 | unsigned int max_bandwidth_khz; |
f130347c | 5403 | |
458f4f9e | 5404 | reg_rule = ®dom->reg_rules[i]; |
f130347c LR |
5405 | freq_range = ®_rule->freq_range; |
5406 | power_rule = ®_rule->power_rule; | |
5407 | ||
5408 | nl_reg_rule = nla_nest_start(msg, i); | |
5409 | if (!nl_reg_rule) | |
ad30ca2c | 5410 | goto nla_put_failure; |
f130347c | 5411 | |
97524820 JD |
5412 | max_bandwidth_khz = freq_range->max_bandwidth_khz; |
5413 | if (!max_bandwidth_khz) | |
5414 | max_bandwidth_khz = reg_get_max_bandwidth(regdom, | |
5415 | reg_rule); | |
5416 | ||
9360ffd1 DM |
5417 | if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS, |
5418 | reg_rule->flags) || | |
5419 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START, | |
5420 | freq_range->start_freq_khz) || | |
5421 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END, | |
5422 | freq_range->end_freq_khz) || | |
5423 | nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW, | |
97524820 | 5424 | max_bandwidth_khz) || |
9360ffd1 DM |
5425 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN, |
5426 | power_rule->max_antenna_gain) || | |
5427 | nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP, | |
089027e5 JD |
5428 | power_rule->max_eirp) || |
5429 | nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME, | |
5430 | reg_rule->dfs_cac_ms)) | |
ad30ca2c | 5431 | goto nla_put_failure; |
f130347c LR |
5432 | |
5433 | nla_nest_end(msg, nl_reg_rule); | |
5434 | } | |
5435 | ||
5436 | nla_nest_end(msg, nl_reg_rules); | |
ad30ca2c AN |
5437 | return 0; |
5438 | ||
5439 | nla_put_failure: | |
5440 | return -EMSGSIZE; | |
5441 | } | |
5442 | ||
5443 | static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info) | |
5444 | { | |
5445 | const struct ieee80211_regdomain *regdom = NULL; | |
5446 | struct cfg80211_registered_device *rdev; | |
5447 | struct wiphy *wiphy = NULL; | |
5448 | struct sk_buff *msg; | |
5449 | void *hdr; | |
5450 | ||
5451 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
5452 | if (!msg) | |
5453 | return -ENOBUFS; | |
5454 | ||
5455 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
5456 | NL80211_CMD_GET_REG); | |
5457 | if (!hdr) | |
5458 | goto put_failure; | |
5459 | ||
5460 | if (info->attrs[NL80211_ATTR_WIPHY]) { | |
1bdd716c AN |
5461 | bool self_managed; |
5462 | ||
ad30ca2c AN |
5463 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
5464 | if (IS_ERR(rdev)) { | |
5465 | nlmsg_free(msg); | |
5466 | return PTR_ERR(rdev); | |
5467 | } | |
5468 | ||
5469 | wiphy = &rdev->wiphy; | |
1bdd716c AN |
5470 | self_managed = wiphy->regulatory_flags & |
5471 | REGULATORY_WIPHY_SELF_MANAGED; | |
ad30ca2c AN |
5472 | regdom = get_wiphy_regdom(wiphy); |
5473 | ||
1bdd716c AN |
5474 | /* a self-managed-reg device must have a private regdom */ |
5475 | if (WARN_ON(!regdom && self_managed)) { | |
5476 | nlmsg_free(msg); | |
5477 | return -EINVAL; | |
5478 | } | |
5479 | ||
ad30ca2c AN |
5480 | if (regdom && |
5481 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5482 | goto nla_put_failure; | |
5483 | } | |
5484 | ||
5485 | if (!wiphy && reg_last_request_cell_base() && | |
5486 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5487 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5488 | goto nla_put_failure; | |
5489 | ||
5490 | rcu_read_lock(); | |
5491 | ||
5492 | if (!regdom) | |
5493 | regdom = rcu_dereference(cfg80211_regdomain); | |
5494 | ||
5495 | if (nl80211_put_regdom(regdom, msg)) | |
5496 | goto nla_put_failure_rcu; | |
5497 | ||
5498 | rcu_read_unlock(); | |
f130347c LR |
5499 | |
5500 | genlmsg_end(msg, hdr); | |
5fe231e8 | 5501 | return genlmsg_reply(msg, info); |
f130347c | 5502 | |
458f4f9e JB |
5503 | nla_put_failure_rcu: |
5504 | rcu_read_unlock(); | |
f130347c LR |
5505 | nla_put_failure: |
5506 | genlmsg_cancel(msg, hdr); | |
efe1cf0c | 5507 | put_failure: |
d080e275 | 5508 | nlmsg_free(msg); |
5fe231e8 | 5509 | return -EMSGSIZE; |
f130347c LR |
5510 | } |
5511 | ||
ad30ca2c AN |
5512 | static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb, |
5513 | u32 seq, int flags, struct wiphy *wiphy, | |
5514 | const struct ieee80211_regdomain *regdom) | |
5515 | { | |
5516 | void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, | |
5517 | NL80211_CMD_GET_REG); | |
5518 | ||
5519 | if (!hdr) | |
5520 | return -1; | |
5521 | ||
5522 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); | |
5523 | ||
5524 | if (nl80211_put_regdom(regdom, msg)) | |
5525 | goto nla_put_failure; | |
5526 | ||
5527 | if (!wiphy && reg_last_request_cell_base() && | |
5528 | nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE, | |
5529 | NL80211_USER_REG_HINT_CELL_BASE)) | |
5530 | goto nla_put_failure; | |
5531 | ||
5532 | if (wiphy && | |
5533 | nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) | |
5534 | goto nla_put_failure; | |
5535 | ||
1bdd716c AN |
5536 | if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && |
5537 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
5538 | goto nla_put_failure; | |
5539 | ||
053c095a JB |
5540 | genlmsg_end(msg, hdr); |
5541 | return 0; | |
ad30ca2c AN |
5542 | |
5543 | nla_put_failure: | |
5544 | genlmsg_cancel(msg, hdr); | |
5545 | return -EMSGSIZE; | |
5546 | } | |
5547 | ||
5548 | static int nl80211_get_reg_dump(struct sk_buff *skb, | |
5549 | struct netlink_callback *cb) | |
5550 | { | |
5551 | const struct ieee80211_regdomain *regdom = NULL; | |
5552 | struct cfg80211_registered_device *rdev; | |
5553 | int err, reg_idx, start = cb->args[2]; | |
5554 | ||
5555 | rtnl_lock(); | |
5556 | ||
5557 | if (cfg80211_regdomain && start == 0) { | |
5558 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5559 | NLM_F_MULTI, NULL, | |
5560 | rtnl_dereference(cfg80211_regdomain)); | |
5561 | if (err < 0) | |
5562 | goto out_err; | |
5563 | } | |
5564 | ||
5565 | /* the global regdom is idx 0 */ | |
5566 | reg_idx = 1; | |
5567 | list_for_each_entry(rdev, &cfg80211_rdev_list, list) { | |
5568 | regdom = get_wiphy_regdom(&rdev->wiphy); | |
5569 | if (!regdom) | |
5570 | continue; | |
5571 | ||
5572 | if (++reg_idx <= start) | |
5573 | continue; | |
5574 | ||
5575 | err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq, | |
5576 | NLM_F_MULTI, &rdev->wiphy, regdom); | |
5577 | if (err < 0) { | |
5578 | reg_idx--; | |
5579 | break; | |
5580 | } | |
5581 | } | |
5582 | ||
5583 | cb->args[2] = reg_idx; | |
5584 | err = skb->len; | |
5585 | out_err: | |
5586 | rtnl_unlock(); | |
5587 | return err; | |
5588 | } | |
5589 | ||
b2e1b302 LR |
5590 | static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info) |
5591 | { | |
5592 | struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1]; | |
5593 | struct nlattr *nl_reg_rule; | |
ea372c54 JB |
5594 | char *alpha2; |
5595 | int rem_reg_rules, r; | |
b2e1b302 | 5596 | u32 num_rules = 0, rule_idx = 0, size_of_regd; |
4c7d3982 | 5597 | enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET; |
ea372c54 | 5598 | struct ieee80211_regdomain *rd; |
b2e1b302 LR |
5599 | |
5600 | if (!info->attrs[NL80211_ATTR_REG_ALPHA2]) | |
5601 | return -EINVAL; | |
5602 | ||
5603 | if (!info->attrs[NL80211_ATTR_REG_RULES]) | |
5604 | return -EINVAL; | |
5605 | ||
5606 | alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]); | |
5607 | ||
8b60b078 LR |
5608 | if (info->attrs[NL80211_ATTR_DFS_REGION]) |
5609 | dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]); | |
5610 | ||
b2e1b302 | 5611 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5612 | rem_reg_rules) { |
b2e1b302 LR |
5613 | num_rules++; |
5614 | if (num_rules > NL80211_MAX_SUPP_REG_RULES) | |
4776c6e7 | 5615 | return -EINVAL; |
b2e1b302 LR |
5616 | } |
5617 | ||
e438768f LR |
5618 | if (!reg_is_valid_request(alpha2)) |
5619 | return -EINVAL; | |
5620 | ||
b2e1b302 | 5621 | size_of_regd = sizeof(struct ieee80211_regdomain) + |
1a919318 | 5622 | num_rules * sizeof(struct ieee80211_reg_rule); |
b2e1b302 LR |
5623 | |
5624 | rd = kzalloc(size_of_regd, GFP_KERNEL); | |
6913b49a JB |
5625 | if (!rd) |
5626 | return -ENOMEM; | |
b2e1b302 LR |
5627 | |
5628 | rd->n_reg_rules = num_rules; | |
5629 | rd->alpha2[0] = alpha2[0]; | |
5630 | rd->alpha2[1] = alpha2[1]; | |
5631 | ||
8b60b078 LR |
5632 | /* |
5633 | * Disable DFS master mode if the DFS region was | |
5634 | * not supported or known on this kernel. | |
5635 | */ | |
5636 | if (reg_supported_dfs_region(dfs_region)) | |
5637 | rd->dfs_region = dfs_region; | |
5638 | ||
b2e1b302 | 5639 | nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES], |
1a919318 | 5640 | rem_reg_rules) { |
ae811e21 JB |
5641 | r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX, |
5642 | nla_data(nl_reg_rule), nla_len(nl_reg_rule), | |
5643 | reg_rule_policy); | |
5644 | if (r) | |
5645 | goto bad_reg; | |
b2e1b302 LR |
5646 | r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]); |
5647 | if (r) | |
5648 | goto bad_reg; | |
5649 | ||
5650 | rule_idx++; | |
5651 | ||
d0e18f83 LR |
5652 | if (rule_idx > NL80211_MAX_SUPP_REG_RULES) { |
5653 | r = -EINVAL; | |
b2e1b302 | 5654 | goto bad_reg; |
d0e18f83 | 5655 | } |
b2e1b302 LR |
5656 | } |
5657 | ||
b2e1b302 | 5658 | r = set_regdom(rd); |
6913b49a | 5659 | /* set_regdom took ownership */ |
1a919318 | 5660 | rd = NULL; |
b2e1b302 | 5661 | |
d2372b31 | 5662 | bad_reg: |
b2e1b302 | 5663 | kfree(rd); |
d0e18f83 | 5664 | return r; |
b2e1b302 LR |
5665 | } |
5666 | ||
83f5e2cf JB |
5667 | static int validate_scan_freqs(struct nlattr *freqs) |
5668 | { | |
5669 | struct nlattr *attr1, *attr2; | |
5670 | int n_channels = 0, tmp1, tmp2; | |
5671 | ||
5672 | nla_for_each_nested(attr1, freqs, tmp1) { | |
5673 | n_channels++; | |
5674 | /* | |
5675 | * Some hardware has a limited channel list for | |
5676 | * scanning, and it is pretty much nonsensical | |
5677 | * to scan for a channel twice, so disallow that | |
5678 | * and don't require drivers to check that the | |
5679 | * channel list they get isn't longer than what | |
5680 | * they can scan, as long as they can scan all | |
5681 | * the channels they registered at once. | |
5682 | */ | |
5683 | nla_for_each_nested(attr2, freqs, tmp2) | |
5684 | if (attr1 != attr2 && | |
5685 | nla_get_u32(attr1) == nla_get_u32(attr2)) | |
5686 | return 0; | |
5687 | } | |
5688 | ||
5689 | return n_channels; | |
5690 | } | |
5691 | ||
ad2b26ab JB |
5692 | static int nl80211_parse_random_mac(struct nlattr **attrs, |
5693 | u8 *mac_addr, u8 *mac_addr_mask) | |
5694 | { | |
5695 | int i; | |
5696 | ||
5697 | if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) { | |
5698 | memset(mac_addr, 0, ETH_ALEN); | |
5699 | memset(mac_addr_mask, 0, ETH_ALEN); | |
5700 | mac_addr[0] = 0x2; | |
5701 | mac_addr_mask[0] = 0x3; | |
5702 | ||
5703 | return 0; | |
5704 | } | |
5705 | ||
5706 | /* need both or none */ | |
5707 | if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK]) | |
5708 | return -EINVAL; | |
5709 | ||
5710 | memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN); | |
5711 | memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN); | |
5712 | ||
5713 | /* don't allow or configure an mcast address */ | |
5714 | if (!is_multicast_ether_addr(mac_addr_mask) || | |
5715 | is_multicast_ether_addr(mac_addr)) | |
5716 | return -EINVAL; | |
5717 | ||
5718 | /* | |
5719 | * allow users to pass a MAC address that has bits set outside | |
5720 | * of the mask, but don't bother drivers with having to deal | |
5721 | * with such bits | |
5722 | */ | |
5723 | for (i = 0; i < ETH_ALEN; i++) | |
5724 | mac_addr[i] &= mac_addr_mask[i]; | |
5725 | ||
5726 | return 0; | |
5727 | } | |
5728 | ||
2a519311 JB |
5729 | static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info) |
5730 | { | |
4c476991 | 5731 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fd014284 | 5732 | struct wireless_dev *wdev = info->user_ptr[1]; |
2a519311 | 5733 | struct cfg80211_scan_request *request; |
2a519311 JB |
5734 | struct nlattr *attr; |
5735 | struct wiphy *wiphy; | |
83f5e2cf | 5736 | int err, tmp, n_ssids = 0, n_channels, i; |
70692ad2 | 5737 | size_t ie_len; |
2a519311 | 5738 | |
f4a11bb0 JB |
5739 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
5740 | return -EINVAL; | |
5741 | ||
79c97e97 | 5742 | wiphy = &rdev->wiphy; |
2a519311 | 5743 | |
4c476991 JB |
5744 | if (!rdev->ops->scan) |
5745 | return -EOPNOTSUPP; | |
2a519311 | 5746 | |
f9d15d16 | 5747 | if (rdev->scan_req || rdev->scan_msg) { |
f9f47529 JB |
5748 | err = -EBUSY; |
5749 | goto unlock; | |
5750 | } | |
2a519311 JB |
5751 | |
5752 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { | |
83f5e2cf JB |
5753 | n_channels = validate_scan_freqs( |
5754 | info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]); | |
f9f47529 JB |
5755 | if (!n_channels) { |
5756 | err = -EINVAL; | |
5757 | goto unlock; | |
5758 | } | |
2a519311 | 5759 | } else { |
bdfbec2d | 5760 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
2a519311 JB |
5761 | } |
5762 | ||
5763 | if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) | |
5764 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) | |
5765 | n_ssids++; | |
5766 | ||
f9f47529 JB |
5767 | if (n_ssids > wiphy->max_scan_ssids) { |
5768 | err = -EINVAL; | |
5769 | goto unlock; | |
5770 | } | |
2a519311 | 5771 | |
70692ad2 JM |
5772 | if (info->attrs[NL80211_ATTR_IE]) |
5773 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
5774 | else | |
5775 | ie_len = 0; | |
5776 | ||
f9f47529 JB |
5777 | if (ie_len > wiphy->max_scan_ie_len) { |
5778 | err = -EINVAL; | |
5779 | goto unlock; | |
5780 | } | |
18a83659 | 5781 | |
2a519311 | 5782 | request = kzalloc(sizeof(*request) |
a2cd43c5 LC |
5783 | + sizeof(*request->ssids) * n_ssids |
5784 | + sizeof(*request->channels) * n_channels | |
70692ad2 | 5785 | + ie_len, GFP_KERNEL); |
f9f47529 JB |
5786 | if (!request) { |
5787 | err = -ENOMEM; | |
5788 | goto unlock; | |
5789 | } | |
2a519311 | 5790 | |
2a519311 | 5791 | if (n_ssids) |
5ba63533 | 5792 | request->ssids = (void *)&request->channels[n_channels]; |
2a519311 | 5793 | request->n_ssids = n_ssids; |
70692ad2 | 5794 | if (ie_len) { |
13874e4b | 5795 | if (n_ssids) |
70692ad2 JM |
5796 | request->ie = (void *)(request->ssids + n_ssids); |
5797 | else | |
5798 | request->ie = (void *)(request->channels + n_channels); | |
5799 | } | |
2a519311 | 5800 | |
584991dc | 5801 | i = 0; |
2a519311 JB |
5802 | if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
5803 | /* user specified, bail out if channel not found */ | |
2a519311 | 5804 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) { |
584991dc JB |
5805 | struct ieee80211_channel *chan; |
5806 | ||
5807 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
5808 | ||
5809 | if (!chan) { | |
2a519311 JB |
5810 | err = -EINVAL; |
5811 | goto out_free; | |
5812 | } | |
584991dc JB |
5813 | |
5814 | /* ignore disabled channels */ | |
5815 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5816 | continue; | |
5817 | ||
5818 | request->channels[i] = chan; | |
2a519311 JB |
5819 | i++; |
5820 | } | |
5821 | } else { | |
34850ab2 JB |
5822 | enum ieee80211_band band; |
5823 | ||
2a519311 | 5824 | /* all channels */ |
2a519311 JB |
5825 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { |
5826 | int j; | |
5827 | if (!wiphy->bands[band]) | |
5828 | continue; | |
5829 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
584991dc JB |
5830 | struct ieee80211_channel *chan; |
5831 | ||
5832 | chan = &wiphy->bands[band]->channels[j]; | |
5833 | ||
5834 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
5835 | continue; | |
5836 | ||
5837 | request->channels[i] = chan; | |
2a519311 JB |
5838 | i++; |
5839 | } | |
5840 | } | |
5841 | } | |
5842 | ||
584991dc JB |
5843 | if (!i) { |
5844 | err = -EINVAL; | |
5845 | goto out_free; | |
5846 | } | |
5847 | ||
5848 | request->n_channels = i; | |
5849 | ||
2a519311 | 5850 | i = 0; |
13874e4b | 5851 | if (n_ssids) { |
2a519311 | 5852 | nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) { |
57a27e1d | 5853 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
2a519311 JB |
5854 | err = -EINVAL; |
5855 | goto out_free; | |
5856 | } | |
57a27e1d | 5857 | request->ssids[i].ssid_len = nla_len(attr); |
2a519311 | 5858 | memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr)); |
2a519311 JB |
5859 | i++; |
5860 | } | |
5861 | } | |
5862 | ||
70692ad2 JM |
5863 | if (info->attrs[NL80211_ATTR_IE]) { |
5864 | request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
de95a54b JB |
5865 | memcpy((void *)request->ie, |
5866 | nla_data(info->attrs[NL80211_ATTR_IE]), | |
70692ad2 JM |
5867 | request->ie_len); |
5868 | } | |
5869 | ||
34850ab2 | 5870 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) |
a401d2bb JB |
5871 | if (wiphy->bands[i]) |
5872 | request->rates[i] = | |
5873 | (1 << wiphy->bands[i]->n_bitrates) - 1; | |
34850ab2 JB |
5874 | |
5875 | if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) { | |
5876 | nla_for_each_nested(attr, | |
5877 | info->attrs[NL80211_ATTR_SCAN_SUPP_RATES], | |
5878 | tmp) { | |
5879 | enum ieee80211_band band = nla_type(attr); | |
5880 | ||
84404623 | 5881 | if (band < 0 || band >= IEEE80211_NUM_BANDS) { |
34850ab2 JB |
5882 | err = -EINVAL; |
5883 | goto out_free; | |
5884 | } | |
1b09cd82 FF |
5885 | |
5886 | if (!wiphy->bands[band]) | |
5887 | continue; | |
5888 | ||
34850ab2 JB |
5889 | err = ieee80211_get_ratemask(wiphy->bands[band], |
5890 | nla_data(attr), | |
5891 | nla_len(attr), | |
5892 | &request->rates[band]); | |
5893 | if (err) | |
5894 | goto out_free; | |
5895 | } | |
5896 | } | |
5897 | ||
46856bbf | 5898 | if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 SL |
5899 | request->flags = nla_get_u32( |
5900 | info->attrs[NL80211_ATTR_SCAN_FLAGS]); | |
00c3a6ed JB |
5901 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
5902 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
5903 | err = -EOPNOTSUPP; |
5904 | goto out_free; | |
5905 | } | |
ad2b26ab JB |
5906 | |
5907 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
5908 | if (!(wiphy->features & | |
5909 | NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) { | |
5910 | err = -EOPNOTSUPP; | |
5911 | goto out_free; | |
5912 | } | |
5913 | ||
5914 | if (wdev->current_bss) { | |
5915 | err = -EOPNOTSUPP; | |
5916 | goto out_free; | |
5917 | } | |
5918 | ||
5919 | err = nl80211_parse_random_mac(info->attrs, | |
5920 | request->mac_addr, | |
5921 | request->mac_addr_mask); | |
5922 | if (err) | |
5923 | goto out_free; | |
5924 | } | |
46856bbf | 5925 | } |
ed473771 | 5926 | |
e9f935e3 RM |
5927 | request->no_cck = |
5928 | nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); | |
5929 | ||
fd014284 | 5930 | request->wdev = wdev; |
79c97e97 | 5931 | request->wiphy = &rdev->wiphy; |
15d6030b | 5932 | request->scan_start = jiffies; |
2a519311 | 5933 | |
79c97e97 | 5934 | rdev->scan_req = request; |
e35e4d28 | 5935 | err = rdev_scan(rdev, request); |
2a519311 | 5936 | |
463d0183 | 5937 | if (!err) { |
fd014284 JB |
5938 | nl80211_send_scan_start(rdev, wdev); |
5939 | if (wdev->netdev) | |
5940 | dev_hold(wdev->netdev); | |
4c476991 | 5941 | } else { |
2a519311 | 5942 | out_free: |
79c97e97 | 5943 | rdev->scan_req = NULL; |
2a519311 JB |
5944 | kfree(request); |
5945 | } | |
3b85875a | 5946 | |
f9f47529 | 5947 | unlock: |
2a519311 JB |
5948 | return err; |
5949 | } | |
5950 | ||
256da02d | 5951 | static struct cfg80211_sched_scan_request * |
ad2b26ab | 5952 | nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev, |
256da02d | 5953 | struct nlattr **attrs) |
807f8a8c LC |
5954 | { |
5955 | struct cfg80211_sched_scan_request *request; | |
807f8a8c | 5956 | struct nlattr *attr; |
a1f1c21c | 5957 | int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i; |
bbe6ad6d | 5958 | u32 interval; |
807f8a8c LC |
5959 | enum ieee80211_band band; |
5960 | size_t ie_len; | |
a1f1c21c | 5961 | struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1]; |
ea73cbce | 5962 | s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF; |
807f8a8c | 5963 | |
256da02d LC |
5964 | if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE])) |
5965 | return ERR_PTR(-EINVAL); | |
807f8a8c | 5966 | |
256da02d LC |
5967 | if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]) |
5968 | return ERR_PTR(-EINVAL); | |
bbe6ad6d | 5969 | |
256da02d | 5970 | interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]); |
bbe6ad6d | 5971 | if (interval == 0) |
256da02d | 5972 | return ERR_PTR(-EINVAL); |
807f8a8c | 5973 | |
256da02d | 5974 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c | 5975 | n_channels = validate_scan_freqs( |
256da02d | 5976 | attrs[NL80211_ATTR_SCAN_FREQUENCIES]); |
807f8a8c | 5977 | if (!n_channels) |
256da02d | 5978 | return ERR_PTR(-EINVAL); |
807f8a8c | 5979 | } else { |
bdfbec2d | 5980 | n_channels = ieee80211_get_num_supported_channels(wiphy); |
807f8a8c LC |
5981 | } |
5982 | ||
256da02d LC |
5983 | if (attrs[NL80211_ATTR_SCAN_SSIDS]) |
5984 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], | |
807f8a8c LC |
5985 | tmp) |
5986 | n_ssids++; | |
5987 | ||
93b6aa69 | 5988 | if (n_ssids > wiphy->max_sched_scan_ssids) |
256da02d | 5989 | return ERR_PTR(-EINVAL); |
807f8a8c | 5990 | |
ea73cbce JB |
5991 | /* |
5992 | * First, count the number of 'real' matchsets. Due to an issue with | |
5993 | * the old implementation, matchsets containing only the RSSI attribute | |
5994 | * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default' | |
5995 | * RSSI for all matchsets, rather than their own matchset for reporting | |
5996 | * all APs with a strong RSSI. This is needed to be compatible with | |
5997 | * older userspace that treated a matchset with only the RSSI as the | |
5998 | * global RSSI for all other matchsets - if there are other matchsets. | |
5999 | */ | |
256da02d | 6000 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6001 | nla_for_each_nested(attr, |
256da02d | 6002 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
ea73cbce JB |
6003 | tmp) { |
6004 | struct nlattr *rssi; | |
6005 | ||
6006 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, | |
6007 | nla_data(attr), nla_len(attr), | |
6008 | nl80211_match_policy); | |
6009 | if (err) | |
256da02d | 6010 | return ERR_PTR(err); |
ea73cbce JB |
6011 | /* add other standalone attributes here */ |
6012 | if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) { | |
6013 | n_match_sets++; | |
6014 | continue; | |
6015 | } | |
6016 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6017 | if (rssi) | |
6018 | default_match_rssi = nla_get_s32(rssi); | |
6019 | } | |
6020 | } | |
6021 | ||
6022 | /* However, if there's no other matchset, add the RSSI one */ | |
6023 | if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF) | |
6024 | n_match_sets = 1; | |
a1f1c21c LC |
6025 | |
6026 | if (n_match_sets > wiphy->max_match_sets) | |
256da02d | 6027 | return ERR_PTR(-EINVAL); |
a1f1c21c | 6028 | |
256da02d LC |
6029 | if (attrs[NL80211_ATTR_IE]) |
6030 | ie_len = nla_len(attrs[NL80211_ATTR_IE]); | |
807f8a8c LC |
6031 | else |
6032 | ie_len = 0; | |
6033 | ||
5a865bad | 6034 | if (ie_len > wiphy->max_sched_scan_ie_len) |
256da02d | 6035 | return ERR_PTR(-EINVAL); |
c10841ca | 6036 | |
807f8a8c | 6037 | request = kzalloc(sizeof(*request) |
a2cd43c5 | 6038 | + sizeof(*request->ssids) * n_ssids |
a1f1c21c | 6039 | + sizeof(*request->match_sets) * n_match_sets |
a2cd43c5 | 6040 | + sizeof(*request->channels) * n_channels |
807f8a8c | 6041 | + ie_len, GFP_KERNEL); |
256da02d LC |
6042 | if (!request) |
6043 | return ERR_PTR(-ENOMEM); | |
807f8a8c LC |
6044 | |
6045 | if (n_ssids) | |
6046 | request->ssids = (void *)&request->channels[n_channels]; | |
6047 | request->n_ssids = n_ssids; | |
6048 | if (ie_len) { | |
13874e4b | 6049 | if (n_ssids) |
807f8a8c LC |
6050 | request->ie = (void *)(request->ssids + n_ssids); |
6051 | else | |
6052 | request->ie = (void *)(request->channels + n_channels); | |
6053 | } | |
6054 | ||
a1f1c21c LC |
6055 | if (n_match_sets) { |
6056 | if (request->ie) | |
6057 | request->match_sets = (void *)(request->ie + ie_len); | |
13874e4b | 6058 | else if (n_ssids) |
a1f1c21c LC |
6059 | request->match_sets = |
6060 | (void *)(request->ssids + n_ssids); | |
6061 | else | |
6062 | request->match_sets = | |
6063 | (void *)(request->channels + n_channels); | |
6064 | } | |
6065 | request->n_match_sets = n_match_sets; | |
6066 | ||
807f8a8c | 6067 | i = 0; |
256da02d | 6068 | if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) { |
807f8a8c LC |
6069 | /* user specified, bail out if channel not found */ |
6070 | nla_for_each_nested(attr, | |
256da02d | 6071 | attrs[NL80211_ATTR_SCAN_FREQUENCIES], |
807f8a8c LC |
6072 | tmp) { |
6073 | struct ieee80211_channel *chan; | |
6074 | ||
6075 | chan = ieee80211_get_channel(wiphy, nla_get_u32(attr)); | |
6076 | ||
6077 | if (!chan) { | |
6078 | err = -EINVAL; | |
6079 | goto out_free; | |
6080 | } | |
6081 | ||
6082 | /* ignore disabled channels */ | |
6083 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6084 | continue; | |
6085 | ||
6086 | request->channels[i] = chan; | |
6087 | i++; | |
6088 | } | |
6089 | } else { | |
6090 | /* all channels */ | |
6091 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
6092 | int j; | |
6093 | if (!wiphy->bands[band]) | |
6094 | continue; | |
6095 | for (j = 0; j < wiphy->bands[band]->n_channels; j++) { | |
6096 | struct ieee80211_channel *chan; | |
6097 | ||
6098 | chan = &wiphy->bands[band]->channels[j]; | |
6099 | ||
6100 | if (chan->flags & IEEE80211_CHAN_DISABLED) | |
6101 | continue; | |
6102 | ||
6103 | request->channels[i] = chan; | |
6104 | i++; | |
6105 | } | |
6106 | } | |
6107 | } | |
6108 | ||
6109 | if (!i) { | |
6110 | err = -EINVAL; | |
6111 | goto out_free; | |
6112 | } | |
6113 | ||
6114 | request->n_channels = i; | |
6115 | ||
6116 | i = 0; | |
13874e4b | 6117 | if (n_ssids) { |
256da02d | 6118 | nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS], |
807f8a8c | 6119 | tmp) { |
57a27e1d | 6120 | if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) { |
807f8a8c LC |
6121 | err = -EINVAL; |
6122 | goto out_free; | |
6123 | } | |
57a27e1d | 6124 | request->ssids[i].ssid_len = nla_len(attr); |
807f8a8c LC |
6125 | memcpy(request->ssids[i].ssid, nla_data(attr), |
6126 | nla_len(attr)); | |
807f8a8c LC |
6127 | i++; |
6128 | } | |
6129 | } | |
6130 | ||
a1f1c21c | 6131 | i = 0; |
256da02d | 6132 | if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) { |
a1f1c21c | 6133 | nla_for_each_nested(attr, |
256da02d | 6134 | attrs[NL80211_ATTR_SCHED_SCAN_MATCH], |
a1f1c21c | 6135 | tmp) { |
88e920b4 | 6136 | struct nlattr *ssid, *rssi; |
a1f1c21c | 6137 | |
ae811e21 JB |
6138 | err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX, |
6139 | nla_data(attr), nla_len(attr), | |
6140 | nl80211_match_policy); | |
6141 | if (err) | |
6142 | goto out_free; | |
4a4ab0d7 | 6143 | ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]; |
a1f1c21c | 6144 | if (ssid) { |
ea73cbce JB |
6145 | if (WARN_ON(i >= n_match_sets)) { |
6146 | /* this indicates a programming error, | |
6147 | * the loop above should have verified | |
6148 | * things properly | |
6149 | */ | |
6150 | err = -EINVAL; | |
6151 | goto out_free; | |
6152 | } | |
6153 | ||
a1f1c21c LC |
6154 | if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) { |
6155 | err = -EINVAL; | |
6156 | goto out_free; | |
6157 | } | |
6158 | memcpy(request->match_sets[i].ssid.ssid, | |
6159 | nla_data(ssid), nla_len(ssid)); | |
6160 | request->match_sets[i].ssid.ssid_len = | |
6161 | nla_len(ssid); | |
ea73cbce JB |
6162 | /* special attribute - old implemenation w/a */ |
6163 | request->match_sets[i].rssi_thold = | |
6164 | default_match_rssi; | |
6165 | rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI]; | |
6166 | if (rssi) | |
6167 | request->match_sets[i].rssi_thold = | |
6168 | nla_get_s32(rssi); | |
a1f1c21c LC |
6169 | } |
6170 | i++; | |
6171 | } | |
ea73cbce JB |
6172 | |
6173 | /* there was no other matchset, so the RSSI one is alone */ | |
f89f46cf | 6174 | if (i == 0 && n_match_sets) |
ea73cbce JB |
6175 | request->match_sets[0].rssi_thold = default_match_rssi; |
6176 | ||
6177 | request->min_rssi_thold = INT_MAX; | |
6178 | for (i = 0; i < n_match_sets; i++) | |
6179 | request->min_rssi_thold = | |
6180 | min(request->match_sets[i].rssi_thold, | |
6181 | request->min_rssi_thold); | |
6182 | } else { | |
6183 | request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF; | |
a1f1c21c LC |
6184 | } |
6185 | ||
9900e484 JB |
6186 | if (ie_len) { |
6187 | request->ie_len = ie_len; | |
807f8a8c | 6188 | memcpy((void *)request->ie, |
256da02d | 6189 | nla_data(attrs[NL80211_ATTR_IE]), |
807f8a8c LC |
6190 | request->ie_len); |
6191 | } | |
6192 | ||
256da02d | 6193 | if (attrs[NL80211_ATTR_SCAN_FLAGS]) { |
ed473771 | 6194 | request->flags = nla_get_u32( |
256da02d | 6195 | attrs[NL80211_ATTR_SCAN_FLAGS]); |
00c3a6ed JB |
6196 | if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) && |
6197 | !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) { | |
46856bbf SL |
6198 | err = -EOPNOTSUPP; |
6199 | goto out_free; | |
6200 | } | |
ad2b26ab JB |
6201 | |
6202 | if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) { | |
6203 | u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR; | |
6204 | ||
6205 | if (!wdev) /* must be net-detect */ | |
6206 | flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR; | |
6207 | ||
6208 | if (!(wiphy->features & flg)) { | |
6209 | err = -EOPNOTSUPP; | |
6210 | goto out_free; | |
6211 | } | |
6212 | ||
6213 | if (wdev && wdev->current_bss) { | |
6214 | err = -EOPNOTSUPP; | |
6215 | goto out_free; | |
6216 | } | |
6217 | ||
6218 | err = nl80211_parse_random_mac(attrs, request->mac_addr, | |
6219 | request->mac_addr_mask); | |
6220 | if (err) | |
6221 | goto out_free; | |
6222 | } | |
46856bbf | 6223 | } |
ed473771 | 6224 | |
9c748934 LC |
6225 | if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY]) |
6226 | request->delay = | |
6227 | nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]); | |
6228 | ||
bbe6ad6d | 6229 | request->interval = interval; |
15d6030b | 6230 | request->scan_start = jiffies; |
807f8a8c | 6231 | |
256da02d | 6232 | return request; |
807f8a8c LC |
6233 | |
6234 | out_free: | |
6235 | kfree(request); | |
256da02d LC |
6236 | return ERR_PTR(err); |
6237 | } | |
6238 | ||
6239 | static int nl80211_start_sched_scan(struct sk_buff *skb, | |
6240 | struct genl_info *info) | |
6241 | { | |
6242 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6243 | struct net_device *dev = info->user_ptr[1]; | |
ad2b26ab | 6244 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
31a60ed1 | 6245 | struct cfg80211_sched_scan_request *sched_scan_req; |
256da02d LC |
6246 | int err; |
6247 | ||
6248 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6249 | !rdev->ops->sched_scan_start) | |
6250 | return -EOPNOTSUPP; | |
6251 | ||
6252 | if (rdev->sched_scan_req) | |
6253 | return -EINPROGRESS; | |
6254 | ||
31a60ed1 JR |
6255 | sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev, |
6256 | info->attrs); | |
6257 | ||
6258 | err = PTR_ERR_OR_ZERO(sched_scan_req); | |
256da02d LC |
6259 | if (err) |
6260 | goto out_err; | |
6261 | ||
31a60ed1 | 6262 | err = rdev_sched_scan_start(rdev, dev, sched_scan_req); |
256da02d LC |
6263 | if (err) |
6264 | goto out_free; | |
6265 | ||
31a60ed1 JR |
6266 | sched_scan_req->dev = dev; |
6267 | sched_scan_req->wiphy = &rdev->wiphy; | |
6268 | ||
93a1e86c JR |
6269 | if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) |
6270 | sched_scan_req->owner_nlportid = info->snd_portid; | |
6271 | ||
31a60ed1 | 6272 | rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req); |
256da02d LC |
6273 | |
6274 | nl80211_send_sched_scan(rdev, dev, | |
6275 | NL80211_CMD_START_SCHED_SCAN); | |
6276 | return 0; | |
6277 | ||
6278 | out_free: | |
31a60ed1 | 6279 | kfree(sched_scan_req); |
256da02d | 6280 | out_err: |
807f8a8c LC |
6281 | return err; |
6282 | } | |
6283 | ||
6284 | static int nl80211_stop_sched_scan(struct sk_buff *skb, | |
6285 | struct genl_info *info) | |
6286 | { | |
6287 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6288 | ||
6289 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) || | |
6290 | !rdev->ops->sched_scan_stop) | |
6291 | return -EOPNOTSUPP; | |
6292 | ||
5fe231e8 | 6293 | return __cfg80211_stop_sched_scan(rdev, false); |
807f8a8c LC |
6294 | } |
6295 | ||
04f39047 SW |
6296 | static int nl80211_start_radar_detection(struct sk_buff *skb, |
6297 | struct genl_info *info) | |
6298 | { | |
6299 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6300 | struct net_device *dev = info->user_ptr[1]; | |
6301 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6302 | struct cfg80211_chan_def chandef; | |
55f7435c | 6303 | enum nl80211_dfs_regions dfs_region; |
31559f35 | 6304 | unsigned int cac_time_ms; |
04f39047 SW |
6305 | int err; |
6306 | ||
55f7435c LR |
6307 | dfs_region = reg_get_dfs_region(wdev->wiphy); |
6308 | if (dfs_region == NL80211_DFS_UNSET) | |
6309 | return -EINVAL; | |
6310 | ||
04f39047 SW |
6311 | err = nl80211_parse_chandef(rdev, info, &chandef); |
6312 | if (err) | |
6313 | return err; | |
6314 | ||
ff311bc1 SW |
6315 | if (netif_carrier_ok(dev)) |
6316 | return -EBUSY; | |
6317 | ||
04f39047 SW |
6318 | if (wdev->cac_started) |
6319 | return -EBUSY; | |
6320 | ||
2beb6dab | 6321 | err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, |
00ec75fc | 6322 | wdev->iftype); |
04f39047 SW |
6323 | if (err < 0) |
6324 | return err; | |
6325 | ||
6326 | if (err == 0) | |
6327 | return -EINVAL; | |
6328 | ||
fe7c3a1f | 6329 | if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef)) |
04f39047 SW |
6330 | return -EINVAL; |
6331 | ||
6332 | if (!rdev->ops->start_radar_detection) | |
6333 | return -EOPNOTSUPP; | |
6334 | ||
31559f35 JD |
6335 | cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef); |
6336 | if (WARN_ON(!cac_time_ms)) | |
6337 | cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS; | |
6338 | ||
6339 | err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef, | |
6340 | cac_time_ms); | |
04f39047 | 6341 | if (!err) { |
9e0e2961 | 6342 | wdev->chandef = chandef; |
04f39047 SW |
6343 | wdev->cac_started = true; |
6344 | wdev->cac_start_time = jiffies; | |
31559f35 | 6345 | wdev->cac_time_ms = cac_time_ms; |
04f39047 | 6346 | } |
04f39047 SW |
6347 | return err; |
6348 | } | |
6349 | ||
16ef1fe2 SW |
6350 | static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info) |
6351 | { | |
6352 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
6353 | struct net_device *dev = info->user_ptr[1]; | |
6354 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
6355 | struct cfg80211_csa_settings params; | |
6356 | /* csa_attrs is defined static to avoid waste of stack size - this | |
6357 | * function is called under RTNL lock, so this should not be a problem. | |
6358 | */ | |
6359 | static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1]; | |
16ef1fe2 | 6360 | int err; |
ee4bc9e7 | 6361 | bool need_new_beacon = false; |
9a774c78 | 6362 | int len, i; |
252e07ca | 6363 | u32 cs_count; |
16ef1fe2 SW |
6364 | |
6365 | if (!rdev->ops->channel_switch || | |
6366 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)) | |
6367 | return -EOPNOTSUPP; | |
6368 | ||
ee4bc9e7 SW |
6369 | switch (dev->ieee80211_ptr->iftype) { |
6370 | case NL80211_IFTYPE_AP: | |
6371 | case NL80211_IFTYPE_P2P_GO: | |
6372 | need_new_beacon = true; | |
6373 | ||
6374 | /* useless if AP is not running */ | |
6375 | if (!wdev->beacon_interval) | |
1ff79dfa | 6376 | return -ENOTCONN; |
ee4bc9e7 SW |
6377 | break; |
6378 | case NL80211_IFTYPE_ADHOC: | |
1ff79dfa JB |
6379 | if (!wdev->ssid_len) |
6380 | return -ENOTCONN; | |
6381 | break; | |
c6da674a | 6382 | case NL80211_IFTYPE_MESH_POINT: |
1ff79dfa JB |
6383 | if (!wdev->mesh_id_len) |
6384 | return -ENOTCONN; | |
ee4bc9e7 SW |
6385 | break; |
6386 | default: | |
16ef1fe2 | 6387 | return -EOPNOTSUPP; |
ee4bc9e7 | 6388 | } |
16ef1fe2 SW |
6389 | |
6390 | memset(¶ms, 0, sizeof(params)); | |
6391 | ||
6392 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
6393 | !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]) | |
6394 | return -EINVAL; | |
6395 | ||
6396 | /* only important for AP, IBSS and mesh create IEs internally */ | |
d0a361a5 | 6397 | if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES]) |
16ef1fe2 SW |
6398 | return -EINVAL; |
6399 | ||
252e07ca LC |
6400 | /* Even though the attribute is u32, the specification says |
6401 | * u8, so let's make sure we don't overflow. | |
6402 | */ | |
6403 | cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]); | |
6404 | if (cs_count > 255) | |
6405 | return -EINVAL; | |
6406 | ||
6407 | params.count = cs_count; | |
16ef1fe2 | 6408 | |
ee4bc9e7 SW |
6409 | if (!need_new_beacon) |
6410 | goto skip_beacons; | |
6411 | ||
16ef1fe2 SW |
6412 | err = nl80211_parse_beacon(info->attrs, ¶ms.beacon_after); |
6413 | if (err) | |
6414 | return err; | |
6415 | ||
6416 | err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX, | |
6417 | info->attrs[NL80211_ATTR_CSA_IES], | |
6418 | nl80211_policy); | |
6419 | if (err) | |
6420 | return err; | |
6421 | ||
6422 | err = nl80211_parse_beacon(csa_attrs, ¶ms.beacon_csa); | |
6423 | if (err) | |
6424 | return err; | |
6425 | ||
6426 | if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]) | |
6427 | return -EINVAL; | |
6428 | ||
9a774c78 AO |
6429 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); |
6430 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6431 | return -EINVAL; |
6432 | ||
9a774c78 AO |
6433 | params.n_counter_offsets_beacon = len / sizeof(u16); |
6434 | if (rdev->wiphy.max_num_csa_counters && | |
6435 | (params.n_counter_offsets_beacon > | |
6436 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 SW |
6437 | return -EINVAL; |
6438 | ||
9a774c78 AO |
6439 | params.counter_offsets_beacon = |
6440 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]); | |
6441 | ||
6442 | /* sanity checks - counters should fit and be the same */ | |
6443 | for (i = 0; i < params.n_counter_offsets_beacon; i++) { | |
6444 | u16 offset = params.counter_offsets_beacon[i]; | |
6445 | ||
6446 | if (offset >= params.beacon_csa.tail_len) | |
6447 | return -EINVAL; | |
6448 | ||
6449 | if (params.beacon_csa.tail[offset] != params.count) | |
6450 | return -EINVAL; | |
6451 | } | |
6452 | ||
16ef1fe2 | 6453 | if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) { |
9a774c78 AO |
6454 | len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); |
6455 | if (!len || (len % sizeof(u16))) | |
16ef1fe2 SW |
6456 | return -EINVAL; |
6457 | ||
9a774c78 AO |
6458 | params.n_counter_offsets_presp = len / sizeof(u16); |
6459 | if (rdev->wiphy.max_num_csa_counters && | |
6460 | (params.n_counter_offsets_beacon > | |
6461 | rdev->wiphy.max_num_csa_counters)) | |
16ef1fe2 | 6462 | return -EINVAL; |
9a774c78 AO |
6463 | |
6464 | params.counter_offsets_presp = | |
6465 | nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]); | |
6466 | ||
6467 | /* sanity checks - counters should fit and be the same */ | |
6468 | for (i = 0; i < params.n_counter_offsets_presp; i++) { | |
6469 | u16 offset = params.counter_offsets_presp[i]; | |
6470 | ||
6471 | if (offset >= params.beacon_csa.probe_resp_len) | |
6472 | return -EINVAL; | |
6473 | ||
6474 | if (params.beacon_csa.probe_resp[offset] != | |
6475 | params.count) | |
6476 | return -EINVAL; | |
6477 | } | |
16ef1fe2 SW |
6478 | } |
6479 | ||
ee4bc9e7 | 6480 | skip_beacons: |
16ef1fe2 SW |
6481 | err = nl80211_parse_chandef(rdev, info, ¶ms.chandef); |
6482 | if (err) | |
6483 | return err; | |
6484 | ||
174e0cd2 IP |
6485 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, ¶ms.chandef, |
6486 | wdev->iftype)) | |
16ef1fe2 SW |
6487 | return -EINVAL; |
6488 | ||
2beb6dab LC |
6489 | err = cfg80211_chandef_dfs_required(wdev->wiphy, |
6490 | ¶ms.chandef, | |
6491 | wdev->iftype); | |
6492 | if (err < 0) | |
6493 | return err; | |
6494 | ||
dcc6c2f5 | 6495 | if (err > 0) |
2beb6dab | 6496 | params.radar_required = true; |
16ef1fe2 | 6497 | |
16ef1fe2 SW |
6498 | if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX]) |
6499 | params.block_tx = true; | |
6500 | ||
c56589ed SW |
6501 | wdev_lock(wdev); |
6502 | err = rdev_channel_switch(rdev, dev, ¶ms); | |
6503 | wdev_unlock(wdev); | |
6504 | ||
6505 | return err; | |
16ef1fe2 SW |
6506 | } |
6507 | ||
9720bb3a JB |
6508 | static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb, |
6509 | u32 seq, int flags, | |
2a519311 | 6510 | struct cfg80211_registered_device *rdev, |
48ab905d JB |
6511 | struct wireless_dev *wdev, |
6512 | struct cfg80211_internal_bss *intbss) | |
2a519311 | 6513 | { |
48ab905d | 6514 | struct cfg80211_bss *res = &intbss->pub; |
9caf0364 | 6515 | const struct cfg80211_bss_ies *ies; |
2a519311 JB |
6516 | void *hdr; |
6517 | struct nlattr *bss; | |
48ab905d JB |
6518 | |
6519 | ASSERT_WDEV_LOCK(wdev); | |
2a519311 | 6520 | |
15e47304 | 6521 | hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags, |
2a519311 JB |
6522 | NL80211_CMD_NEW_SCAN_RESULTS); |
6523 | if (!hdr) | |
6524 | return -1; | |
6525 | ||
9720bb3a JB |
6526 | genl_dump_check_consistent(cb, hdr, &nl80211_fam); |
6527 | ||
97990a06 JB |
6528 | if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation)) |
6529 | goto nla_put_failure; | |
6530 | if (wdev->netdev && | |
9360ffd1 DM |
6531 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex)) |
6532 | goto nla_put_failure; | |
97990a06 JB |
6533 | if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) |
6534 | goto nla_put_failure; | |
2a519311 JB |
6535 | |
6536 | bss = nla_nest_start(msg, NL80211_ATTR_BSS); | |
6537 | if (!bss) | |
6538 | goto nla_put_failure; | |
9360ffd1 | 6539 | if ((!is_zero_ether_addr(res->bssid) && |
9caf0364 | 6540 | nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid))) |
9360ffd1 | 6541 | goto nla_put_failure; |
9caf0364 JB |
6542 | |
6543 | rcu_read_lock(); | |
0e227084 JB |
6544 | /* indicate whether we have probe response data or not */ |
6545 | if (rcu_access_pointer(res->proberesp_ies) && | |
6546 | nla_put_flag(msg, NL80211_BSS_PRESP_DATA)) | |
6547 | goto fail_unlock_rcu; | |
6548 | ||
6549 | /* this pointer prefers to be pointed to probe response data | |
6550 | * but is always valid | |
6551 | */ | |
9caf0364 | 6552 | ies = rcu_dereference(res->ies); |
8cef2c9d JB |
6553 | if (ies) { |
6554 | if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf)) | |
6555 | goto fail_unlock_rcu; | |
8cef2c9d JB |
6556 | if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS, |
6557 | ies->len, ies->data)) | |
6558 | goto fail_unlock_rcu; | |
9caf0364 | 6559 | } |
0e227084 JB |
6560 | |
6561 | /* and this pointer is always (unless driver didn't know) beacon data */ | |
9caf0364 | 6562 | ies = rcu_dereference(res->beacon_ies); |
0e227084 JB |
6563 | if (ies && ies->from_beacon) { |
6564 | if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf)) | |
8cef2c9d JB |
6565 | goto fail_unlock_rcu; |
6566 | if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES, | |
6567 | ies->len, ies->data)) | |
6568 | goto fail_unlock_rcu; | |
9caf0364 JB |
6569 | } |
6570 | rcu_read_unlock(); | |
6571 | ||
9360ffd1 DM |
6572 | if (res->beacon_interval && |
6573 | nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval)) | |
6574 | goto nla_put_failure; | |
6575 | if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) || | |
6576 | nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) || | |
dcd6eac1 | 6577 | nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) || |
9360ffd1 DM |
6578 | nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO, |
6579 | jiffies_to_msecs(jiffies - intbss->ts))) | |
6580 | goto nla_put_failure; | |
2a519311 | 6581 | |
77965c97 | 6582 | switch (rdev->wiphy.signal_type) { |
2a519311 | 6583 | case CFG80211_SIGNAL_TYPE_MBM: |
9360ffd1 DM |
6584 | if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal)) |
6585 | goto nla_put_failure; | |
2a519311 JB |
6586 | break; |
6587 | case CFG80211_SIGNAL_TYPE_UNSPEC: | |
9360ffd1 DM |
6588 | if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal)) |
6589 | goto nla_put_failure; | |
2a519311 JB |
6590 | break; |
6591 | default: | |
6592 | break; | |
6593 | } | |
6594 | ||
48ab905d | 6595 | switch (wdev->iftype) { |
074ac8df | 6596 | case NL80211_IFTYPE_P2P_CLIENT: |
48ab905d | 6597 | case NL80211_IFTYPE_STATION: |
9360ffd1 DM |
6598 | if (intbss == wdev->current_bss && |
6599 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6600 | NL80211_BSS_STATUS_ASSOCIATED)) | |
6601 | goto nla_put_failure; | |
48ab905d JB |
6602 | break; |
6603 | case NL80211_IFTYPE_ADHOC: | |
9360ffd1 DM |
6604 | if (intbss == wdev->current_bss && |
6605 | nla_put_u32(msg, NL80211_BSS_STATUS, | |
6606 | NL80211_BSS_STATUS_IBSS_JOINED)) | |
6607 | goto nla_put_failure; | |
48ab905d JB |
6608 | break; |
6609 | default: | |
6610 | break; | |
6611 | } | |
6612 | ||
2a519311 JB |
6613 | nla_nest_end(msg, bss); |
6614 | ||
053c095a JB |
6615 | genlmsg_end(msg, hdr); |
6616 | return 0; | |
2a519311 | 6617 | |
8cef2c9d JB |
6618 | fail_unlock_rcu: |
6619 | rcu_read_unlock(); | |
2a519311 JB |
6620 | nla_put_failure: |
6621 | genlmsg_cancel(msg, hdr); | |
6622 | return -EMSGSIZE; | |
6623 | } | |
6624 | ||
97990a06 | 6625 | static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb) |
2a519311 | 6626 | { |
48ab905d | 6627 | struct cfg80211_registered_device *rdev; |
2a519311 | 6628 | struct cfg80211_internal_bss *scan; |
48ab905d | 6629 | struct wireless_dev *wdev; |
97990a06 | 6630 | int start = cb->args[2], idx = 0; |
2a519311 JB |
6631 | int err; |
6632 | ||
97990a06 | 6633 | err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6634 | if (err) |
6635 | return err; | |
2a519311 | 6636 | |
48ab905d JB |
6637 | wdev_lock(wdev); |
6638 | spin_lock_bh(&rdev->bss_lock); | |
6639 | cfg80211_bss_expire(rdev); | |
6640 | ||
9720bb3a JB |
6641 | cb->seq = rdev->bss_generation; |
6642 | ||
48ab905d | 6643 | list_for_each_entry(scan, &rdev->bss_list, list) { |
2a519311 JB |
6644 | if (++idx <= start) |
6645 | continue; | |
9720bb3a | 6646 | if (nl80211_send_bss(skb, cb, |
2a519311 | 6647 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
48ab905d | 6648 | rdev, wdev, scan) < 0) { |
2a519311 | 6649 | idx--; |
67748893 | 6650 | break; |
2a519311 JB |
6651 | } |
6652 | } | |
6653 | ||
48ab905d JB |
6654 | spin_unlock_bh(&rdev->bss_lock); |
6655 | wdev_unlock(wdev); | |
2a519311 | 6656 | |
97990a06 JB |
6657 | cb->args[2] = idx; |
6658 | nl80211_finish_wdev_dump(rdev); | |
2a519311 | 6659 | |
67748893 | 6660 | return skb->len; |
2a519311 JB |
6661 | } |
6662 | ||
15e47304 | 6663 | static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq, |
11f78ac3 JB |
6664 | int flags, struct net_device *dev, |
6665 | bool allow_radio_stats, | |
6666 | struct survey_info *survey) | |
61fa713c HS |
6667 | { |
6668 | void *hdr; | |
6669 | struct nlattr *infoattr; | |
6670 | ||
11f78ac3 JB |
6671 | /* skip radio stats if userspace didn't request them */ |
6672 | if (!survey->channel && !allow_radio_stats) | |
6673 | return 0; | |
6674 | ||
15e47304 | 6675 | hdr = nl80211hdr_put(msg, portid, seq, flags, |
61fa713c HS |
6676 | NL80211_CMD_NEW_SURVEY_RESULTS); |
6677 | if (!hdr) | |
6678 | return -ENOMEM; | |
6679 | ||
9360ffd1 DM |
6680 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
6681 | goto nla_put_failure; | |
61fa713c HS |
6682 | |
6683 | infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO); | |
6684 | if (!infoattr) | |
6685 | goto nla_put_failure; | |
6686 | ||
11f78ac3 JB |
6687 | if (survey->channel && |
6688 | nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY, | |
9360ffd1 DM |
6689 | survey->channel->center_freq)) |
6690 | goto nla_put_failure; | |
6691 | ||
6692 | if ((survey->filled & SURVEY_INFO_NOISE_DBM) && | |
6693 | nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise)) | |
6694 | goto nla_put_failure; | |
6695 | if ((survey->filled & SURVEY_INFO_IN_USE) && | |
6696 | nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE)) | |
6697 | goto nla_put_failure; | |
4ed20beb JB |
6698 | if ((survey->filled & SURVEY_INFO_TIME) && |
6699 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME, | |
6700 | survey->time)) | |
9360ffd1 | 6701 | goto nla_put_failure; |
4ed20beb JB |
6702 | if ((survey->filled & SURVEY_INFO_TIME_BUSY) && |
6703 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY, | |
6704 | survey->time_busy)) | |
9360ffd1 | 6705 | goto nla_put_failure; |
4ed20beb JB |
6706 | if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) && |
6707 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY, | |
6708 | survey->time_ext_busy)) | |
9360ffd1 | 6709 | goto nla_put_failure; |
4ed20beb JB |
6710 | if ((survey->filled & SURVEY_INFO_TIME_RX) && |
6711 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX, | |
6712 | survey->time_rx)) | |
9360ffd1 | 6713 | goto nla_put_failure; |
4ed20beb JB |
6714 | if ((survey->filled & SURVEY_INFO_TIME_TX) && |
6715 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX, | |
6716 | survey->time_tx)) | |
9360ffd1 | 6717 | goto nla_put_failure; |
052536ab JB |
6718 | if ((survey->filled & SURVEY_INFO_TIME_SCAN) && |
6719 | nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN, | |
6720 | survey->time_scan)) | |
6721 | goto nla_put_failure; | |
61fa713c HS |
6722 | |
6723 | nla_nest_end(msg, infoattr); | |
6724 | ||
053c095a JB |
6725 | genlmsg_end(msg, hdr); |
6726 | return 0; | |
61fa713c HS |
6727 | |
6728 | nla_put_failure: | |
6729 | genlmsg_cancel(msg, hdr); | |
6730 | return -EMSGSIZE; | |
6731 | } | |
6732 | ||
11f78ac3 | 6733 | static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb) |
61fa713c HS |
6734 | { |
6735 | struct survey_info survey; | |
1b8ec87a | 6736 | struct cfg80211_registered_device *rdev; |
97990a06 JB |
6737 | struct wireless_dev *wdev; |
6738 | int survey_idx = cb->args[2]; | |
61fa713c | 6739 | int res; |
11f78ac3 | 6740 | bool radio_stats; |
61fa713c | 6741 | |
1b8ec87a | 6742 | res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev); |
67748893 JB |
6743 | if (res) |
6744 | return res; | |
61fa713c | 6745 | |
11f78ac3 JB |
6746 | /* prepare_wdev_dump parsed the attributes */ |
6747 | radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS]; | |
6748 | ||
97990a06 JB |
6749 | if (!wdev->netdev) { |
6750 | res = -EINVAL; | |
6751 | goto out_err; | |
6752 | } | |
6753 | ||
1b8ec87a | 6754 | if (!rdev->ops->dump_survey) { |
61fa713c HS |
6755 | res = -EOPNOTSUPP; |
6756 | goto out_err; | |
6757 | } | |
6758 | ||
6759 | while (1) { | |
1b8ec87a | 6760 | res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey); |
61fa713c HS |
6761 | if (res == -ENOENT) |
6762 | break; | |
6763 | if (res) | |
6764 | goto out_err; | |
6765 | ||
11f78ac3 JB |
6766 | /* don't send disabled channels, but do send non-channel data */ |
6767 | if (survey.channel && | |
6768 | survey.channel->flags & IEEE80211_CHAN_DISABLED) { | |
180cdc79 LR |
6769 | survey_idx++; |
6770 | continue; | |
6771 | } | |
6772 | ||
61fa713c | 6773 | if (nl80211_send_survey(skb, |
15e47304 | 6774 | NETLINK_CB(cb->skb).portid, |
61fa713c | 6775 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
11f78ac3 | 6776 | wdev->netdev, radio_stats, &survey) < 0) |
61fa713c HS |
6777 | goto out; |
6778 | survey_idx++; | |
6779 | } | |
6780 | ||
6781 | out: | |
97990a06 | 6782 | cb->args[2] = survey_idx; |
61fa713c HS |
6783 | res = skb->len; |
6784 | out_err: | |
1b8ec87a | 6785 | nl80211_finish_wdev_dump(rdev); |
61fa713c HS |
6786 | return res; |
6787 | } | |
6788 | ||
b23aa676 SO |
6789 | static bool nl80211_valid_wpa_versions(u32 wpa_versions) |
6790 | { | |
6791 | return !(wpa_versions & ~(NL80211_WPA_VERSION_1 | | |
6792 | NL80211_WPA_VERSION_2)); | |
6793 | } | |
6794 | ||
636a5d36 JM |
6795 | static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info) |
6796 | { | |
4c476991 JB |
6797 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6798 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 6799 | struct ieee80211_channel *chan; |
e39e5b5e JM |
6800 | const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL; |
6801 | int err, ssid_len, ie_len = 0, sae_data_len = 0; | |
19957bb3 | 6802 | enum nl80211_auth_type auth_type; |
fffd0934 | 6803 | struct key_parse key; |
d5cdfacb | 6804 | bool local_state_change; |
636a5d36 | 6805 | |
f4a11bb0 JB |
6806 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
6807 | return -EINVAL; | |
6808 | ||
6809 | if (!info->attrs[NL80211_ATTR_MAC]) | |
6810 | return -EINVAL; | |
6811 | ||
1778092e JM |
6812 | if (!info->attrs[NL80211_ATTR_AUTH_TYPE]) |
6813 | return -EINVAL; | |
6814 | ||
19957bb3 JB |
6815 | if (!info->attrs[NL80211_ATTR_SSID]) |
6816 | return -EINVAL; | |
6817 | ||
6818 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
6819 | return -EINVAL; | |
6820 | ||
fffd0934 JB |
6821 | err = nl80211_parse_key(info, &key); |
6822 | if (err) | |
6823 | return err; | |
6824 | ||
6825 | if (key.idx >= 0) { | |
e31b8213 JB |
6826 | if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP) |
6827 | return -EINVAL; | |
fffd0934 JB |
6828 | if (!key.p.key || !key.p.key_len) |
6829 | return -EINVAL; | |
6830 | if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 || | |
6831 | key.p.key_len != WLAN_KEY_LEN_WEP40) && | |
6832 | (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 || | |
6833 | key.p.key_len != WLAN_KEY_LEN_WEP104)) | |
6834 | return -EINVAL; | |
6835 | if (key.idx > 4) | |
6836 | return -EINVAL; | |
6837 | } else { | |
6838 | key.p.key_len = 0; | |
6839 | key.p.key = NULL; | |
6840 | } | |
6841 | ||
afea0b7a JB |
6842 | if (key.idx >= 0) { |
6843 | int i; | |
6844 | bool ok = false; | |
6845 | for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) { | |
6846 | if (key.p.cipher == rdev->wiphy.cipher_suites[i]) { | |
6847 | ok = true; | |
6848 | break; | |
6849 | } | |
6850 | } | |
4c476991 JB |
6851 | if (!ok) |
6852 | return -EINVAL; | |
afea0b7a JB |
6853 | } |
6854 | ||
4c476991 JB |
6855 | if (!rdev->ops->auth) |
6856 | return -EOPNOTSUPP; | |
636a5d36 | 6857 | |
074ac8df | 6858 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
6859 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
6860 | return -EOPNOTSUPP; | |
eec60b03 | 6861 | |
19957bb3 | 6862 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
664834de JM |
6863 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
6864 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
6865 | if (!chan) | |
4c476991 | 6866 | return -EINVAL; |
636a5d36 | 6867 | |
19957bb3 JB |
6868 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
6869 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
6870 | |
6871 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
6872 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
6873 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
6874 | } |
6875 | ||
19957bb3 | 6876 | auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); |
e39e5b5e | 6877 | if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE)) |
4c476991 | 6878 | return -EINVAL; |
636a5d36 | 6879 | |
e39e5b5e JM |
6880 | if (auth_type == NL80211_AUTHTYPE_SAE && |
6881 | !info->attrs[NL80211_ATTR_SAE_DATA]) | |
6882 | return -EINVAL; | |
6883 | ||
6884 | if (info->attrs[NL80211_ATTR_SAE_DATA]) { | |
6885 | if (auth_type != NL80211_AUTHTYPE_SAE) | |
6886 | return -EINVAL; | |
6887 | sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6888 | sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]); | |
6889 | /* need to include at least Auth Transaction and Status Code */ | |
6890 | if (sae_data_len < 4) | |
6891 | return -EINVAL; | |
6892 | } | |
6893 | ||
d5cdfacb JM |
6894 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
6895 | ||
95de817b JB |
6896 | /* |
6897 | * Since we no longer track auth state, ignore | |
6898 | * requests to only change local state. | |
6899 | */ | |
6900 | if (local_state_change) | |
6901 | return 0; | |
6902 | ||
91bf9b26 JB |
6903 | wdev_lock(dev->ieee80211_ptr); |
6904 | err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid, | |
6905 | ssid, ssid_len, ie, ie_len, | |
6906 | key.p.key, key.p.key_len, key.idx, | |
6907 | sae_data, sae_data_len); | |
6908 | wdev_unlock(dev->ieee80211_ptr); | |
6909 | return err; | |
636a5d36 JM |
6910 | } |
6911 | ||
c0692b8f JB |
6912 | static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev, |
6913 | struct genl_info *info, | |
3dc27d25 JB |
6914 | struct cfg80211_crypto_settings *settings, |
6915 | int cipher_limit) | |
b23aa676 | 6916 | { |
c0b2bbd8 JB |
6917 | memset(settings, 0, sizeof(*settings)); |
6918 | ||
b23aa676 SO |
6919 | settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT]; |
6920 | ||
c0692b8f JB |
6921 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) { |
6922 | u16 proto; | |
6923 | proto = nla_get_u16( | |
6924 | info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]); | |
6925 | settings->control_port_ethertype = cpu_to_be16(proto); | |
6926 | if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) && | |
6927 | proto != ETH_P_PAE) | |
6928 | return -EINVAL; | |
6929 | if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT]) | |
6930 | settings->control_port_no_encrypt = true; | |
6931 | } else | |
6932 | settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE); | |
6933 | ||
b23aa676 SO |
6934 | if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) { |
6935 | void *data; | |
6936 | int len, i; | |
6937 | ||
6938 | data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6939 | len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]); | |
6940 | settings->n_ciphers_pairwise = len / sizeof(u32); | |
6941 | ||
6942 | if (len % sizeof(u32)) | |
6943 | return -EINVAL; | |
6944 | ||
3dc27d25 | 6945 | if (settings->n_ciphers_pairwise > cipher_limit) |
b23aa676 SO |
6946 | return -EINVAL; |
6947 | ||
6948 | memcpy(settings->ciphers_pairwise, data, len); | |
6949 | ||
6950 | for (i = 0; i < settings->n_ciphers_pairwise; i++) | |
38ba3c57 JM |
6951 | if (!cfg80211_supported_cipher_suite( |
6952 | &rdev->wiphy, | |
b23aa676 SO |
6953 | settings->ciphers_pairwise[i])) |
6954 | return -EINVAL; | |
6955 | } | |
6956 | ||
6957 | if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) { | |
6958 | settings->cipher_group = | |
6959 | nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]); | |
38ba3c57 JM |
6960 | if (!cfg80211_supported_cipher_suite(&rdev->wiphy, |
6961 | settings->cipher_group)) | |
b23aa676 SO |
6962 | return -EINVAL; |
6963 | } | |
6964 | ||
6965 | if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) { | |
6966 | settings->wpa_versions = | |
6967 | nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]); | |
6968 | if (!nl80211_valid_wpa_versions(settings->wpa_versions)) | |
6969 | return -EINVAL; | |
6970 | } | |
6971 | ||
6972 | if (info->attrs[NL80211_ATTR_AKM_SUITES]) { | |
6973 | void *data; | |
6d30240e | 6974 | int len; |
b23aa676 SO |
6975 | |
6976 | data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6977 | len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]); | |
6978 | settings->n_akm_suites = len / sizeof(u32); | |
6979 | ||
6980 | if (len % sizeof(u32)) | |
6981 | return -EINVAL; | |
6982 | ||
1b9ca027 JM |
6983 | if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES) |
6984 | return -EINVAL; | |
6985 | ||
b23aa676 | 6986 | memcpy(settings->akm_suites, data, len); |
b23aa676 SO |
6987 | } |
6988 | ||
6989 | return 0; | |
6990 | } | |
6991 | ||
636a5d36 JM |
6992 | static int nl80211_associate(struct sk_buff *skb, struct genl_info *info) |
6993 | { | |
4c476991 JB |
6994 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
6995 | struct net_device *dev = info->user_ptr[1]; | |
f444de05 | 6996 | struct ieee80211_channel *chan; |
f62fab73 JB |
6997 | struct cfg80211_assoc_request req = {}; |
6998 | const u8 *bssid, *ssid; | |
6999 | int err, ssid_len = 0; | |
636a5d36 | 7000 | |
f4a11bb0 JB |
7001 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7002 | return -EINVAL; | |
7003 | ||
7004 | if (!info->attrs[NL80211_ATTR_MAC] || | |
19957bb3 JB |
7005 | !info->attrs[NL80211_ATTR_SSID] || |
7006 | !info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
f4a11bb0 JB |
7007 | return -EINVAL; |
7008 | ||
4c476991 JB |
7009 | if (!rdev->ops->assoc) |
7010 | return -EOPNOTSUPP; | |
636a5d36 | 7011 | |
074ac8df | 7012 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7013 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7014 | return -EOPNOTSUPP; | |
eec60b03 | 7015 | |
19957bb3 | 7016 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7017 | |
664834de JM |
7018 | chan = nl80211_get_valid_chan(&rdev->wiphy, |
7019 | info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7020 | if (!chan) | |
4c476991 | 7021 | return -EINVAL; |
636a5d36 | 7022 | |
19957bb3 JB |
7023 | ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7024 | ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
636a5d36 JM |
7025 | |
7026 | if (info->attrs[NL80211_ATTR_IE]) { | |
f62fab73 JB |
7027 | req.ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7028 | req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7029 | } |
7030 | ||
dc6382ce | 7031 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
4f5dadce | 7032 | enum nl80211_mfp mfp = |
dc6382ce | 7033 | nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); |
4f5dadce | 7034 | if (mfp == NL80211_MFP_REQUIRED) |
f62fab73 | 7035 | req.use_mfp = true; |
4c476991 JB |
7036 | else if (mfp != NL80211_MFP_NO) |
7037 | return -EINVAL; | |
dc6382ce JM |
7038 | } |
7039 | ||
3e5d7649 | 7040 | if (info->attrs[NL80211_ATTR_PREV_BSSID]) |
f62fab73 | 7041 | req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]); |
3e5d7649 | 7042 | |
7e7c8926 | 7043 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
f62fab73 | 7044 | req.flags |= ASSOC_REQ_DISABLE_HT; |
7e7c8926 BG |
7045 | |
7046 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
f62fab73 JB |
7047 | memcpy(&req.ht_capa_mask, |
7048 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7049 | sizeof(req.ht_capa_mask)); | |
7e7c8926 BG |
7050 | |
7051 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
f62fab73 | 7052 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7e7c8926 | 7053 | return -EINVAL; |
f62fab73 JB |
7054 | memcpy(&req.ht_capa, |
7055 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7056 | sizeof(req.ht_capa)); | |
7e7c8926 BG |
7057 | } |
7058 | ||
ee2aca34 | 7059 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
f62fab73 | 7060 | req.flags |= ASSOC_REQ_DISABLE_VHT; |
ee2aca34 JB |
7061 | |
7062 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
f62fab73 JB |
7063 | memcpy(&req.vht_capa_mask, |
7064 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7065 | sizeof(req.vht_capa_mask)); | |
ee2aca34 JB |
7066 | |
7067 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
f62fab73 | 7068 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) |
ee2aca34 | 7069 | return -EINVAL; |
f62fab73 JB |
7070 | memcpy(&req.vht_capa, |
7071 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7072 | sizeof(req.vht_capa)); | |
ee2aca34 JB |
7073 | } |
7074 | ||
bab5ab7d AK |
7075 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7076 | if (!(rdev->wiphy.features & | |
7077 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7078 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7079 | return -EINVAL; | |
7080 | req.flags |= ASSOC_REQ_USE_RRM; | |
7081 | } | |
7082 | ||
f62fab73 | 7083 | err = nl80211_crypto_settings(rdev, info, &req.crypto, 1); |
91bf9b26 JB |
7084 | if (!err) { |
7085 | wdev_lock(dev->ieee80211_ptr); | |
f62fab73 JB |
7086 | err = cfg80211_mlme_assoc(rdev, dev, chan, bssid, |
7087 | ssid, ssid_len, &req); | |
91bf9b26 JB |
7088 | wdev_unlock(dev->ieee80211_ptr); |
7089 | } | |
636a5d36 | 7090 | |
636a5d36 JM |
7091 | return err; |
7092 | } | |
7093 | ||
7094 | static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info) | |
7095 | { | |
4c476991 JB |
7096 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7097 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7098 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7099 | int ie_len = 0, err; |
19957bb3 | 7100 | u16 reason_code; |
d5cdfacb | 7101 | bool local_state_change; |
636a5d36 | 7102 | |
f4a11bb0 JB |
7103 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7104 | return -EINVAL; | |
7105 | ||
7106 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7107 | return -EINVAL; | |
7108 | ||
7109 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7110 | return -EINVAL; | |
7111 | ||
4c476991 JB |
7112 | if (!rdev->ops->deauth) |
7113 | return -EOPNOTSUPP; | |
636a5d36 | 7114 | |
074ac8df | 7115 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7116 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7117 | return -EOPNOTSUPP; | |
eec60b03 | 7118 | |
19957bb3 | 7119 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7120 | |
19957bb3 JB |
7121 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7122 | if (reason_code == 0) { | |
f4a11bb0 | 7123 | /* Reason Code 0 is reserved */ |
4c476991 | 7124 | return -EINVAL; |
255e737e | 7125 | } |
636a5d36 JM |
7126 | |
7127 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7128 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7129 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7130 | } |
7131 | ||
d5cdfacb JM |
7132 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7133 | ||
91bf9b26 JB |
7134 | wdev_lock(dev->ieee80211_ptr); |
7135 | err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code, | |
7136 | local_state_change); | |
7137 | wdev_unlock(dev->ieee80211_ptr); | |
7138 | return err; | |
636a5d36 JM |
7139 | } |
7140 | ||
7141 | static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info) | |
7142 | { | |
4c476991 JB |
7143 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7144 | struct net_device *dev = info->user_ptr[1]; | |
19957bb3 | 7145 | const u8 *ie = NULL, *bssid; |
91bf9b26 | 7146 | int ie_len = 0, err; |
19957bb3 | 7147 | u16 reason_code; |
d5cdfacb | 7148 | bool local_state_change; |
636a5d36 | 7149 | |
f4a11bb0 JB |
7150 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7151 | return -EINVAL; | |
7152 | ||
7153 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7154 | return -EINVAL; | |
7155 | ||
7156 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7157 | return -EINVAL; | |
7158 | ||
4c476991 JB |
7159 | if (!rdev->ops->disassoc) |
7160 | return -EOPNOTSUPP; | |
636a5d36 | 7161 | |
074ac8df | 7162 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7163 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7164 | return -EOPNOTSUPP; | |
eec60b03 | 7165 | |
19957bb3 | 7166 | bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
636a5d36 | 7167 | |
19957bb3 JB |
7168 | reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); |
7169 | if (reason_code == 0) { | |
f4a11bb0 | 7170 | /* Reason Code 0 is reserved */ |
4c476991 | 7171 | return -EINVAL; |
255e737e | 7172 | } |
636a5d36 JM |
7173 | |
7174 | if (info->attrs[NL80211_ATTR_IE]) { | |
19957bb3 JB |
7175 | ie = nla_data(info->attrs[NL80211_ATTR_IE]); |
7176 | ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
636a5d36 JM |
7177 | } |
7178 | ||
d5cdfacb JM |
7179 | local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE]; |
7180 | ||
91bf9b26 JB |
7181 | wdev_lock(dev->ieee80211_ptr); |
7182 | err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code, | |
7183 | local_state_change); | |
7184 | wdev_unlock(dev->ieee80211_ptr); | |
7185 | return err; | |
636a5d36 JM |
7186 | } |
7187 | ||
dd5b4cc7 FF |
7188 | static bool |
7189 | nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev, | |
7190 | int mcast_rate[IEEE80211_NUM_BANDS], | |
7191 | int rateval) | |
7192 | { | |
7193 | struct wiphy *wiphy = &rdev->wiphy; | |
7194 | bool found = false; | |
7195 | int band, i; | |
7196 | ||
7197 | for (band = 0; band < IEEE80211_NUM_BANDS; band++) { | |
7198 | struct ieee80211_supported_band *sband; | |
7199 | ||
7200 | sband = wiphy->bands[band]; | |
7201 | if (!sband) | |
7202 | continue; | |
7203 | ||
7204 | for (i = 0; i < sband->n_bitrates; i++) { | |
7205 | if (sband->bitrates[i].bitrate == rateval) { | |
7206 | mcast_rate[band] = i + 1; | |
7207 | found = true; | |
7208 | break; | |
7209 | } | |
7210 | } | |
7211 | } | |
7212 | ||
7213 | return found; | |
7214 | } | |
7215 | ||
04a773ad JB |
7216 | static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info) |
7217 | { | |
4c476991 JB |
7218 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7219 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad JB |
7220 | struct cfg80211_ibss_params ibss; |
7221 | struct wiphy *wiphy; | |
fffd0934 | 7222 | struct cfg80211_cached_keys *connkeys = NULL; |
04a773ad JB |
7223 | int err; |
7224 | ||
8e30bc55 JB |
7225 | memset(&ibss, 0, sizeof(ibss)); |
7226 | ||
04a773ad JB |
7227 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) |
7228 | return -EINVAL; | |
7229 | ||
683b6d3b | 7230 | if (!info->attrs[NL80211_ATTR_SSID] || |
04a773ad JB |
7231 | !nla_len(info->attrs[NL80211_ATTR_SSID])) |
7232 | return -EINVAL; | |
7233 | ||
8e30bc55 JB |
7234 | ibss.beacon_interval = 100; |
7235 | ||
7236 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { | |
7237 | ibss.beacon_interval = | |
7238 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
7239 | if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000) | |
7240 | return -EINVAL; | |
7241 | } | |
7242 | ||
4c476991 JB |
7243 | if (!rdev->ops->join_ibss) |
7244 | return -EOPNOTSUPP; | |
04a773ad | 7245 | |
4c476991 JB |
7246 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7247 | return -EOPNOTSUPP; | |
04a773ad | 7248 | |
79c97e97 | 7249 | wiphy = &rdev->wiphy; |
04a773ad | 7250 | |
39193498 | 7251 | if (info->attrs[NL80211_ATTR_MAC]) { |
04a773ad | 7252 | ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); |
39193498 JB |
7253 | |
7254 | if (!is_valid_ether_addr(ibss.bssid)) | |
7255 | return -EINVAL; | |
7256 | } | |
04a773ad JB |
7257 | ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7258 | ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7259 | ||
7260 | if (info->attrs[NL80211_ATTR_IE]) { | |
7261 | ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7262 | ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7263 | } | |
7264 | ||
683b6d3b JB |
7265 | err = nl80211_parse_chandef(rdev, info, &ibss.chandef); |
7266 | if (err) | |
7267 | return err; | |
04a773ad | 7268 | |
174e0cd2 IP |
7269 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef, |
7270 | NL80211_IFTYPE_ADHOC)) | |
54858ee5 AS |
7271 | return -EINVAL; |
7272 | ||
2f301ab2 | 7273 | switch (ibss.chandef.width) { |
bf372645 SW |
7274 | case NL80211_CHAN_WIDTH_5: |
7275 | case NL80211_CHAN_WIDTH_10: | |
2f301ab2 SW |
7276 | case NL80211_CHAN_WIDTH_20_NOHT: |
7277 | break; | |
7278 | case NL80211_CHAN_WIDTH_20: | |
7279 | case NL80211_CHAN_WIDTH_40: | |
ffc11991 JD |
7280 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) |
7281 | return -EINVAL; | |
7282 | break; | |
7283 | case NL80211_CHAN_WIDTH_80: | |
7284 | case NL80211_CHAN_WIDTH_80P80: | |
7285 | case NL80211_CHAN_WIDTH_160: | |
7286 | if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)) | |
7287 | return -EINVAL; | |
7288 | if (!wiphy_ext_feature_isset(&rdev->wiphy, | |
7289 | NL80211_EXT_FEATURE_VHT_IBSS)) | |
7290 | return -EINVAL; | |
7291 | break; | |
2f301ab2 | 7292 | default: |
c04d6150 | 7293 | return -EINVAL; |
2f301ab2 | 7294 | } |
db9c64cf | 7295 | |
04a773ad | 7296 | ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED]; |
fffd0934 JB |
7297 | ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY]; |
7298 | ||
fbd2c8dc TP |
7299 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
7300 | u8 *rates = | |
7301 | nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7302 | int n_rates = | |
7303 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
7304 | struct ieee80211_supported_band *sband = | |
683b6d3b | 7305 | wiphy->bands[ibss.chandef.chan->band]; |
fbd2c8dc | 7306 | |
34850ab2 JB |
7307 | err = ieee80211_get_ratemask(sband, rates, n_rates, |
7308 | &ibss.basic_rates); | |
7309 | if (err) | |
7310 | return err; | |
fbd2c8dc | 7311 | } |
dd5b4cc7 | 7312 | |
803768f5 SW |
7313 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) |
7314 | memcpy(&ibss.ht_capa_mask, | |
7315 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7316 | sizeof(ibss.ht_capa_mask)); | |
7317 | ||
7318 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
7319 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7320 | return -EINVAL; | |
7321 | memcpy(&ibss.ht_capa, | |
7322 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7323 | sizeof(ibss.ht_capa)); | |
7324 | } | |
7325 | ||
dd5b4cc7 FF |
7326 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
7327 | !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate, | |
7328 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
7329 | return -EINVAL; | |
fbd2c8dc | 7330 | |
4c476991 | 7331 | if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
de7044ee SM |
7332 | bool no_ht = false; |
7333 | ||
4c476991 | 7334 | connkeys = nl80211_parse_connkeys(rdev, |
de7044ee SM |
7335 | info->attrs[NL80211_ATTR_KEYS], |
7336 | &no_ht); | |
4c476991 JB |
7337 | if (IS_ERR(connkeys)) |
7338 | return PTR_ERR(connkeys); | |
de7044ee | 7339 | |
3d9d1d66 JB |
7340 | if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) && |
7341 | no_ht) { | |
de7044ee SM |
7342 | kfree(connkeys); |
7343 | return -EINVAL; | |
7344 | } | |
4c476991 | 7345 | } |
04a773ad | 7346 | |
267335d6 AQ |
7347 | ibss.control_port = |
7348 | nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]); | |
7349 | ||
5336fa88 SW |
7350 | ibss.userspace_handles_dfs = |
7351 | nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]); | |
7352 | ||
4c476991 | 7353 | err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys); |
fffd0934 | 7354 | if (err) |
b47f610b | 7355 | kzfree(connkeys); |
04a773ad JB |
7356 | return err; |
7357 | } | |
7358 | ||
7359 | static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info) | |
7360 | { | |
4c476991 JB |
7361 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7362 | struct net_device *dev = info->user_ptr[1]; | |
04a773ad | 7363 | |
4c476991 JB |
7364 | if (!rdev->ops->leave_ibss) |
7365 | return -EOPNOTSUPP; | |
04a773ad | 7366 | |
4c476991 JB |
7367 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC) |
7368 | return -EOPNOTSUPP; | |
04a773ad | 7369 | |
4c476991 | 7370 | return cfg80211_leave_ibss(rdev, dev, false); |
04a773ad JB |
7371 | } |
7372 | ||
f4e583c8 AQ |
7373 | static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info) |
7374 | { | |
7375 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7376 | struct net_device *dev = info->user_ptr[1]; | |
7377 | int mcast_rate[IEEE80211_NUM_BANDS]; | |
7378 | u32 nla_rate; | |
7379 | int err; | |
7380 | ||
7381 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC && | |
7382 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT) | |
7383 | return -EOPNOTSUPP; | |
7384 | ||
7385 | if (!rdev->ops->set_mcast_rate) | |
7386 | return -EOPNOTSUPP; | |
7387 | ||
7388 | memset(mcast_rate, 0, sizeof(mcast_rate)); | |
7389 | ||
7390 | if (!info->attrs[NL80211_ATTR_MCAST_RATE]) | |
7391 | return -EINVAL; | |
7392 | ||
7393 | nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]); | |
7394 | if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate)) | |
7395 | return -EINVAL; | |
7396 | ||
7397 | err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate); | |
7398 | ||
7399 | return err; | |
7400 | } | |
7401 | ||
ad7e718c JB |
7402 | static struct sk_buff * |
7403 | __cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev, | |
6c09e791 AK |
7404 | struct wireless_dev *wdev, int approxlen, |
7405 | u32 portid, u32 seq, enum nl80211_commands cmd, | |
567ffc35 JB |
7406 | enum nl80211_attrs attr, |
7407 | const struct nl80211_vendor_cmd_info *info, | |
7408 | gfp_t gfp) | |
ad7e718c JB |
7409 | { |
7410 | struct sk_buff *skb; | |
7411 | void *hdr; | |
7412 | struct nlattr *data; | |
7413 | ||
7414 | skb = nlmsg_new(approxlen + 100, gfp); | |
7415 | if (!skb) | |
7416 | return NULL; | |
7417 | ||
7418 | hdr = nl80211hdr_put(skb, portid, seq, 0, cmd); | |
7419 | if (!hdr) { | |
7420 | kfree_skb(skb); | |
7421 | return NULL; | |
7422 | } | |
7423 | ||
7424 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
7425 | goto nla_put_failure; | |
567ffc35 JB |
7426 | |
7427 | if (info) { | |
7428 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID, | |
7429 | info->vendor_id)) | |
7430 | goto nla_put_failure; | |
7431 | if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD, | |
7432 | info->subcmd)) | |
7433 | goto nla_put_failure; | |
7434 | } | |
7435 | ||
6c09e791 AK |
7436 | if (wdev) { |
7437 | if (nla_put_u64(skb, NL80211_ATTR_WDEV, | |
7438 | wdev_id(wdev))) | |
7439 | goto nla_put_failure; | |
7440 | if (wdev->netdev && | |
7441 | nla_put_u32(skb, NL80211_ATTR_IFINDEX, | |
7442 | wdev->netdev->ifindex)) | |
7443 | goto nla_put_failure; | |
7444 | } | |
7445 | ||
ad7e718c JB |
7446 | data = nla_nest_start(skb, attr); |
7447 | ||
7448 | ((void **)skb->cb)[0] = rdev; | |
7449 | ((void **)skb->cb)[1] = hdr; | |
7450 | ((void **)skb->cb)[2] = data; | |
7451 | ||
7452 | return skb; | |
7453 | ||
7454 | nla_put_failure: | |
7455 | kfree_skb(skb); | |
7456 | return NULL; | |
7457 | } | |
f4e583c8 | 7458 | |
e03ad6ea | 7459 | struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy, |
6c09e791 | 7460 | struct wireless_dev *wdev, |
e03ad6ea JB |
7461 | enum nl80211_commands cmd, |
7462 | enum nl80211_attrs attr, | |
7463 | int vendor_event_idx, | |
7464 | int approxlen, gfp_t gfp) | |
7465 | { | |
f26cbf40 | 7466 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
e03ad6ea JB |
7467 | const struct nl80211_vendor_cmd_info *info; |
7468 | ||
7469 | switch (cmd) { | |
7470 | case NL80211_CMD_TESTMODE: | |
7471 | if (WARN_ON(vendor_event_idx != -1)) | |
7472 | return NULL; | |
7473 | info = NULL; | |
7474 | break; | |
7475 | case NL80211_CMD_VENDOR: | |
7476 | if (WARN_ON(vendor_event_idx < 0 || | |
7477 | vendor_event_idx >= wiphy->n_vendor_events)) | |
7478 | return NULL; | |
7479 | info = &wiphy->vendor_events[vendor_event_idx]; | |
7480 | break; | |
7481 | default: | |
7482 | WARN_ON(1); | |
7483 | return NULL; | |
7484 | } | |
7485 | ||
6c09e791 | 7486 | return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0, |
e03ad6ea JB |
7487 | cmd, attr, info, gfp); |
7488 | } | |
7489 | EXPORT_SYMBOL(__cfg80211_alloc_event_skb); | |
7490 | ||
7491 | void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp) | |
7492 | { | |
7493 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
7494 | void *hdr = ((void **)skb->cb)[1]; | |
7495 | struct nlattr *data = ((void **)skb->cb)[2]; | |
7496 | enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE; | |
7497 | ||
bd8c78e7 JB |
7498 | /* clear CB data for netlink core to own from now on */ |
7499 | memset(skb->cb, 0, sizeof(skb->cb)); | |
7500 | ||
e03ad6ea JB |
7501 | nla_nest_end(skb, data); |
7502 | genlmsg_end(skb, hdr); | |
7503 | ||
7504 | if (data->nla_type == NL80211_ATTR_VENDOR_DATA) | |
7505 | mcgrp = NL80211_MCGRP_VENDOR; | |
7506 | ||
7507 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0, | |
7508 | mcgrp, gfp); | |
7509 | } | |
7510 | EXPORT_SYMBOL(__cfg80211_send_event_skb); | |
7511 | ||
aff89a9b | 7512 | #ifdef CONFIG_NL80211_TESTMODE |
aff89a9b JB |
7513 | static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info) |
7514 | { | |
4c476991 | 7515 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
fc73f11f DS |
7516 | struct wireless_dev *wdev = |
7517 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
aff89a9b JB |
7518 | int err; |
7519 | ||
fc73f11f DS |
7520 | if (!rdev->ops->testmode_cmd) |
7521 | return -EOPNOTSUPP; | |
7522 | ||
7523 | if (IS_ERR(wdev)) { | |
7524 | err = PTR_ERR(wdev); | |
7525 | if (err != -EINVAL) | |
7526 | return err; | |
7527 | wdev = NULL; | |
7528 | } else if (wdev->wiphy != &rdev->wiphy) { | |
7529 | return -EINVAL; | |
7530 | } | |
7531 | ||
aff89a9b JB |
7532 | if (!info->attrs[NL80211_ATTR_TESTDATA]) |
7533 | return -EINVAL; | |
7534 | ||
ad7e718c | 7535 | rdev->cur_cmd_info = info; |
fc73f11f | 7536 | err = rdev_testmode_cmd(rdev, wdev, |
aff89a9b JB |
7537 | nla_data(info->attrs[NL80211_ATTR_TESTDATA]), |
7538 | nla_len(info->attrs[NL80211_ATTR_TESTDATA])); | |
ad7e718c | 7539 | rdev->cur_cmd_info = NULL; |
aff89a9b | 7540 | |
aff89a9b JB |
7541 | return err; |
7542 | } | |
7543 | ||
71063f0e WYG |
7544 | static int nl80211_testmode_dump(struct sk_buff *skb, |
7545 | struct netlink_callback *cb) | |
7546 | { | |
00918d33 | 7547 | struct cfg80211_registered_device *rdev; |
71063f0e WYG |
7548 | int err; |
7549 | long phy_idx; | |
7550 | void *data = NULL; | |
7551 | int data_len = 0; | |
7552 | ||
5fe231e8 JB |
7553 | rtnl_lock(); |
7554 | ||
71063f0e WYG |
7555 | if (cb->args[0]) { |
7556 | /* | |
7557 | * 0 is a valid index, but not valid for args[0], | |
7558 | * so we need to offset by 1. | |
7559 | */ | |
7560 | phy_idx = cb->args[0] - 1; | |
7561 | } else { | |
7562 | err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize, | |
7563 | nl80211_fam.attrbuf, nl80211_fam.maxattr, | |
7564 | nl80211_policy); | |
7565 | if (err) | |
5fe231e8 | 7566 | goto out_err; |
00918d33 | 7567 | |
2bd7e35d JB |
7568 | rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk), |
7569 | nl80211_fam.attrbuf); | |
7570 | if (IS_ERR(rdev)) { | |
5fe231e8 JB |
7571 | err = PTR_ERR(rdev); |
7572 | goto out_err; | |
00918d33 | 7573 | } |
2bd7e35d JB |
7574 | phy_idx = rdev->wiphy_idx; |
7575 | rdev = NULL; | |
2bd7e35d | 7576 | |
71063f0e WYG |
7577 | if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]) |
7578 | cb->args[1] = | |
7579 | (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA]; | |
7580 | } | |
7581 | ||
7582 | if (cb->args[1]) { | |
7583 | data = nla_data((void *)cb->args[1]); | |
7584 | data_len = nla_len((void *)cb->args[1]); | |
7585 | } | |
7586 | ||
00918d33 JB |
7587 | rdev = cfg80211_rdev_by_wiphy_idx(phy_idx); |
7588 | if (!rdev) { | |
5fe231e8 JB |
7589 | err = -ENOENT; |
7590 | goto out_err; | |
71063f0e | 7591 | } |
71063f0e | 7592 | |
00918d33 | 7593 | if (!rdev->ops->testmode_dump) { |
71063f0e WYG |
7594 | err = -EOPNOTSUPP; |
7595 | goto out_err; | |
7596 | } | |
7597 | ||
7598 | while (1) { | |
15e47304 | 7599 | void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid, |
71063f0e WYG |
7600 | cb->nlh->nlmsg_seq, NLM_F_MULTI, |
7601 | NL80211_CMD_TESTMODE); | |
7602 | struct nlattr *tmdata; | |
7603 | ||
cb35fba3 DC |
7604 | if (!hdr) |
7605 | break; | |
7606 | ||
9360ffd1 | 7607 | if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) { |
71063f0e WYG |
7608 | genlmsg_cancel(skb, hdr); |
7609 | break; | |
7610 | } | |
7611 | ||
7612 | tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA); | |
7613 | if (!tmdata) { | |
7614 | genlmsg_cancel(skb, hdr); | |
7615 | break; | |
7616 | } | |
e35e4d28 | 7617 | err = rdev_testmode_dump(rdev, skb, cb, data, data_len); |
71063f0e WYG |
7618 | nla_nest_end(skb, tmdata); |
7619 | ||
7620 | if (err == -ENOBUFS || err == -ENOENT) { | |
7621 | genlmsg_cancel(skb, hdr); | |
7622 | break; | |
7623 | } else if (err) { | |
7624 | genlmsg_cancel(skb, hdr); | |
7625 | goto out_err; | |
7626 | } | |
7627 | ||
7628 | genlmsg_end(skb, hdr); | |
7629 | } | |
7630 | ||
7631 | err = skb->len; | |
7632 | /* see above */ | |
7633 | cb->args[0] = phy_idx + 1; | |
7634 | out_err: | |
5fe231e8 | 7635 | rtnl_unlock(); |
71063f0e WYG |
7636 | return err; |
7637 | } | |
aff89a9b JB |
7638 | #endif |
7639 | ||
b23aa676 SO |
7640 | static int nl80211_connect(struct sk_buff *skb, struct genl_info *info) |
7641 | { | |
4c476991 JB |
7642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7643 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 SO |
7644 | struct cfg80211_connect_params connect; |
7645 | struct wiphy *wiphy; | |
fffd0934 | 7646 | struct cfg80211_cached_keys *connkeys = NULL; |
b23aa676 SO |
7647 | int err; |
7648 | ||
7649 | memset(&connect, 0, sizeof(connect)); | |
7650 | ||
7651 | if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
7652 | return -EINVAL; | |
7653 | ||
7654 | if (!info->attrs[NL80211_ATTR_SSID] || | |
7655 | !nla_len(info->attrs[NL80211_ATTR_SSID])) | |
7656 | return -EINVAL; | |
7657 | ||
7658 | if (info->attrs[NL80211_ATTR_AUTH_TYPE]) { | |
7659 | connect.auth_type = | |
7660 | nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]); | |
e39e5b5e JM |
7661 | if (!nl80211_valid_auth_type(rdev, connect.auth_type, |
7662 | NL80211_CMD_CONNECT)) | |
b23aa676 SO |
7663 | return -EINVAL; |
7664 | } else | |
7665 | connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC; | |
7666 | ||
7667 | connect.privacy = info->attrs[NL80211_ATTR_PRIVACY]; | |
7668 | ||
c0692b8f | 7669 | err = nl80211_crypto_settings(rdev, info, &connect.crypto, |
3dc27d25 | 7670 | NL80211_MAX_NR_CIPHER_SUITES); |
b23aa676 SO |
7671 | if (err) |
7672 | return err; | |
b23aa676 | 7673 | |
074ac8df | 7674 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7675 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7676 | return -EOPNOTSUPP; | |
b23aa676 | 7677 | |
79c97e97 | 7678 | wiphy = &rdev->wiphy; |
b23aa676 | 7679 | |
4486ea98 BS |
7680 | connect.bg_scan_period = -1; |
7681 | if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] && | |
7682 | (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) { | |
7683 | connect.bg_scan_period = | |
7684 | nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]); | |
7685 | } | |
7686 | ||
b23aa676 SO |
7687 | if (info->attrs[NL80211_ATTR_MAC]) |
7688 | connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
1df4a510 JM |
7689 | else if (info->attrs[NL80211_ATTR_MAC_HINT]) |
7690 | connect.bssid_hint = | |
7691 | nla_data(info->attrs[NL80211_ATTR_MAC_HINT]); | |
b23aa676 SO |
7692 | connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]); |
7693 | connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]); | |
7694 | ||
7695 | if (info->attrs[NL80211_ATTR_IE]) { | |
7696 | connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
7697 | connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
7698 | } | |
7699 | ||
cee00a95 JM |
7700 | if (info->attrs[NL80211_ATTR_USE_MFP]) { |
7701 | connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]); | |
7702 | if (connect.mfp != NL80211_MFP_REQUIRED && | |
7703 | connect.mfp != NL80211_MFP_NO) | |
7704 | return -EINVAL; | |
7705 | } else { | |
7706 | connect.mfp = NL80211_MFP_NO; | |
7707 | } | |
7708 | ||
b23aa676 | 7709 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
664834de JM |
7710 | connect.channel = nl80211_get_valid_chan( |
7711 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]); | |
7712 | if (!connect.channel) | |
1df4a510 JM |
7713 | return -EINVAL; |
7714 | } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) { | |
664834de JM |
7715 | connect.channel_hint = nl80211_get_valid_chan( |
7716 | wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]); | |
7717 | if (!connect.channel_hint) | |
4c476991 | 7718 | return -EINVAL; |
b23aa676 SO |
7719 | } |
7720 | ||
fffd0934 JB |
7721 | if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) { |
7722 | connkeys = nl80211_parse_connkeys(rdev, | |
de7044ee | 7723 | info->attrs[NL80211_ATTR_KEYS], NULL); |
4c476991 JB |
7724 | if (IS_ERR(connkeys)) |
7725 | return PTR_ERR(connkeys); | |
fffd0934 JB |
7726 | } |
7727 | ||
7e7c8926 BG |
7728 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT])) |
7729 | connect.flags |= ASSOC_REQ_DISABLE_HT; | |
7730 | ||
7731 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) | |
7732 | memcpy(&connect.ht_capa_mask, | |
7733 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]), | |
7734 | sizeof(connect.ht_capa_mask)); | |
7735 | ||
7736 | if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) { | |
b4e4f47e | 7737 | if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) { |
b47f610b | 7738 | kzfree(connkeys); |
7e7c8926 | 7739 | return -EINVAL; |
b4e4f47e | 7740 | } |
7e7c8926 BG |
7741 | memcpy(&connect.ht_capa, |
7742 | nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]), | |
7743 | sizeof(connect.ht_capa)); | |
7744 | } | |
7745 | ||
ee2aca34 JB |
7746 | if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT])) |
7747 | connect.flags |= ASSOC_REQ_DISABLE_VHT; | |
7748 | ||
7749 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) | |
7750 | memcpy(&connect.vht_capa_mask, | |
7751 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]), | |
7752 | sizeof(connect.vht_capa_mask)); | |
7753 | ||
7754 | if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) { | |
7755 | if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) { | |
b47f610b | 7756 | kzfree(connkeys); |
ee2aca34 JB |
7757 | return -EINVAL; |
7758 | } | |
7759 | memcpy(&connect.vht_capa, | |
7760 | nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]), | |
7761 | sizeof(connect.vht_capa)); | |
7762 | } | |
7763 | ||
bab5ab7d AK |
7764 | if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) { |
7765 | if (!(rdev->wiphy.features & | |
7766 | NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) || | |
7767 | !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) | |
7768 | return -EINVAL; | |
7769 | connect.flags |= ASSOC_REQ_USE_RRM; | |
7770 | } | |
7771 | ||
83739b03 JB |
7772 | wdev_lock(dev->ieee80211_ptr); |
7773 | err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL); | |
7774 | wdev_unlock(dev->ieee80211_ptr); | |
fffd0934 | 7775 | if (err) |
b47f610b | 7776 | kzfree(connkeys); |
b23aa676 SO |
7777 | return err; |
7778 | } | |
7779 | ||
7780 | static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info) | |
7781 | { | |
4c476991 JB |
7782 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7783 | struct net_device *dev = info->user_ptr[1]; | |
b23aa676 | 7784 | u16 reason; |
83739b03 | 7785 | int ret; |
b23aa676 SO |
7786 | |
7787 | if (!info->attrs[NL80211_ATTR_REASON_CODE]) | |
7788 | reason = WLAN_REASON_DEAUTH_LEAVING; | |
7789 | else | |
7790 | reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]); | |
7791 | ||
7792 | if (reason == 0) | |
7793 | return -EINVAL; | |
7794 | ||
074ac8df | 7795 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7796 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7797 | return -EOPNOTSUPP; | |
b23aa676 | 7798 | |
83739b03 JB |
7799 | wdev_lock(dev->ieee80211_ptr); |
7800 | ret = cfg80211_disconnect(rdev, dev, reason, true); | |
7801 | wdev_unlock(dev->ieee80211_ptr); | |
7802 | return ret; | |
b23aa676 SO |
7803 | } |
7804 | ||
463d0183 JB |
7805 | static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) |
7806 | { | |
4c476991 | 7807 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
463d0183 JB |
7808 | struct net *net; |
7809 | int err; | |
463d0183 | 7810 | |
4b681c82 VK |
7811 | if (info->attrs[NL80211_ATTR_PID]) { |
7812 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | |
7813 | ||
7814 | net = get_net_ns_by_pid(pid); | |
7815 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | |
7816 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | |
463d0183 | 7817 | |
4b681c82 VK |
7818 | net = get_net_ns_by_fd(fd); |
7819 | } else { | |
7820 | return -EINVAL; | |
7821 | } | |
463d0183 | 7822 | |
4c476991 JB |
7823 | if (IS_ERR(net)) |
7824 | return PTR_ERR(net); | |
463d0183 JB |
7825 | |
7826 | err = 0; | |
7827 | ||
7828 | /* check if anything to do */ | |
4c476991 JB |
7829 | if (!net_eq(wiphy_net(&rdev->wiphy), net)) |
7830 | err = cfg80211_switch_netns(rdev, net); | |
463d0183 | 7831 | |
463d0183 | 7832 | put_net(net); |
463d0183 JB |
7833 | return err; |
7834 | } | |
7835 | ||
67fbb16b SO |
7836 | static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info) |
7837 | { | |
4c476991 | 7838 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
67fbb16b SO |
7839 | int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev, |
7840 | struct cfg80211_pmksa *pmksa) = NULL; | |
4c476991 | 7841 | struct net_device *dev = info->user_ptr[1]; |
67fbb16b SO |
7842 | struct cfg80211_pmksa pmksa; |
7843 | ||
7844 | memset(&pmksa, 0, sizeof(struct cfg80211_pmksa)); | |
7845 | ||
7846 | if (!info->attrs[NL80211_ATTR_MAC]) | |
7847 | return -EINVAL; | |
7848 | ||
7849 | if (!info->attrs[NL80211_ATTR_PMKID]) | |
7850 | return -EINVAL; | |
7851 | ||
67fbb16b SO |
7852 | pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]); |
7853 | pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7854 | ||
074ac8df | 7855 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7856 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7857 | return -EOPNOTSUPP; | |
67fbb16b SO |
7858 | |
7859 | switch (info->genlhdr->cmd) { | |
7860 | case NL80211_CMD_SET_PMKSA: | |
7861 | rdev_ops = rdev->ops->set_pmksa; | |
7862 | break; | |
7863 | case NL80211_CMD_DEL_PMKSA: | |
7864 | rdev_ops = rdev->ops->del_pmksa; | |
7865 | break; | |
7866 | default: | |
7867 | WARN_ON(1); | |
7868 | break; | |
7869 | } | |
7870 | ||
4c476991 JB |
7871 | if (!rdev_ops) |
7872 | return -EOPNOTSUPP; | |
67fbb16b | 7873 | |
4c476991 | 7874 | return rdev_ops(&rdev->wiphy, dev, &pmksa); |
67fbb16b SO |
7875 | } |
7876 | ||
7877 | static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info) | |
7878 | { | |
4c476991 JB |
7879 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
7880 | struct net_device *dev = info->user_ptr[1]; | |
67fbb16b | 7881 | |
074ac8df | 7882 | if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
7883 | dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT) |
7884 | return -EOPNOTSUPP; | |
67fbb16b | 7885 | |
4c476991 JB |
7886 | if (!rdev->ops->flush_pmksa) |
7887 | return -EOPNOTSUPP; | |
67fbb16b | 7888 | |
e35e4d28 | 7889 | return rdev_flush_pmksa(rdev, dev); |
67fbb16b SO |
7890 | } |
7891 | ||
109086ce AN |
7892 | static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info) |
7893 | { | |
7894 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7895 | struct net_device *dev = info->user_ptr[1]; | |
7896 | u8 action_code, dialog_token; | |
df942e7b | 7897 | u32 peer_capability = 0; |
109086ce AN |
7898 | u16 status_code; |
7899 | u8 *peer; | |
31fa97c5 | 7900 | bool initiator; |
109086ce AN |
7901 | |
7902 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7903 | !rdev->ops->tdls_mgmt) | |
7904 | return -EOPNOTSUPP; | |
7905 | ||
7906 | if (!info->attrs[NL80211_ATTR_TDLS_ACTION] || | |
7907 | !info->attrs[NL80211_ATTR_STATUS_CODE] || | |
7908 | !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] || | |
7909 | !info->attrs[NL80211_ATTR_IE] || | |
7910 | !info->attrs[NL80211_ATTR_MAC]) | |
7911 | return -EINVAL; | |
7912 | ||
7913 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7914 | action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]); | |
7915 | status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]); | |
7916 | dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]); | |
31fa97c5 | 7917 | initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]); |
df942e7b SDU |
7918 | if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]) |
7919 | peer_capability = | |
7920 | nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]); | |
109086ce | 7921 | |
e35e4d28 | 7922 | return rdev_tdls_mgmt(rdev, dev, peer, action_code, |
df942e7b | 7923 | dialog_token, status_code, peer_capability, |
31fa97c5 | 7924 | initiator, |
e35e4d28 HG |
7925 | nla_data(info->attrs[NL80211_ATTR_IE]), |
7926 | nla_len(info->attrs[NL80211_ATTR_IE])); | |
109086ce AN |
7927 | } |
7928 | ||
7929 | static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info) | |
7930 | { | |
7931 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
7932 | struct net_device *dev = info->user_ptr[1]; | |
7933 | enum nl80211_tdls_operation operation; | |
7934 | u8 *peer; | |
7935 | ||
7936 | if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) || | |
7937 | !rdev->ops->tdls_oper) | |
7938 | return -EOPNOTSUPP; | |
7939 | ||
7940 | if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] || | |
7941 | !info->attrs[NL80211_ATTR_MAC]) | |
7942 | return -EINVAL; | |
7943 | ||
7944 | operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]); | |
7945 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
7946 | ||
e35e4d28 | 7947 | return rdev_tdls_oper(rdev, dev, peer, operation); |
109086ce AN |
7948 | } |
7949 | ||
9588bbd5 JM |
7950 | static int nl80211_remain_on_channel(struct sk_buff *skb, |
7951 | struct genl_info *info) | |
7952 | { | |
4c476991 | 7953 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 7954 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 7955 | struct cfg80211_chan_def chandef; |
9588bbd5 JM |
7956 | struct sk_buff *msg; |
7957 | void *hdr; | |
7958 | u64 cookie; | |
683b6d3b | 7959 | u32 duration; |
9588bbd5 JM |
7960 | int err; |
7961 | ||
7962 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] || | |
7963 | !info->attrs[NL80211_ATTR_DURATION]) | |
7964 | return -EINVAL; | |
7965 | ||
7966 | duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); | |
7967 | ||
ebf348fc JB |
7968 | if (!rdev->ops->remain_on_channel || |
7969 | !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)) | |
7970 | return -EOPNOTSUPP; | |
7971 | ||
9588bbd5 | 7972 | /* |
ebf348fc JB |
7973 | * We should be on that channel for at least a minimum amount of |
7974 | * time (10ms) but no longer than the driver supports. | |
9588bbd5 | 7975 | */ |
ebf348fc | 7976 | if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
a293911d | 7977 | duration > rdev->wiphy.max_remain_on_channel_duration) |
9588bbd5 JM |
7978 | return -EINVAL; |
7979 | ||
683b6d3b JB |
7980 | err = nl80211_parse_chandef(rdev, info, &chandef); |
7981 | if (err) | |
7982 | return err; | |
9588bbd5 JM |
7983 | |
7984 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
7985 | if (!msg) |
7986 | return -ENOMEM; | |
9588bbd5 | 7987 | |
15e47304 | 7988 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
9588bbd5 | 7989 | NL80211_CMD_REMAIN_ON_CHANNEL); |
cb35fba3 DC |
7990 | if (!hdr) { |
7991 | err = -ENOBUFS; | |
9588bbd5 JM |
7992 | goto free_msg; |
7993 | } | |
7994 | ||
683b6d3b JB |
7995 | err = rdev_remain_on_channel(rdev, wdev, chandef.chan, |
7996 | duration, &cookie); | |
9588bbd5 JM |
7997 | |
7998 | if (err) | |
7999 | goto free_msg; | |
8000 | ||
9360ffd1 DM |
8001 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8002 | goto nla_put_failure; | |
9588bbd5 JM |
8003 | |
8004 | genlmsg_end(msg, hdr); | |
4c476991 JB |
8005 | |
8006 | return genlmsg_reply(msg, info); | |
9588bbd5 JM |
8007 | |
8008 | nla_put_failure: | |
8009 | err = -ENOBUFS; | |
8010 | free_msg: | |
8011 | nlmsg_free(msg); | |
9588bbd5 JM |
8012 | return err; |
8013 | } | |
8014 | ||
8015 | static int nl80211_cancel_remain_on_channel(struct sk_buff *skb, | |
8016 | struct genl_info *info) | |
8017 | { | |
4c476991 | 8018 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8019 | struct wireless_dev *wdev = info->user_ptr[1]; |
9588bbd5 | 8020 | u64 cookie; |
9588bbd5 JM |
8021 | |
8022 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8023 | return -EINVAL; | |
8024 | ||
4c476991 JB |
8025 | if (!rdev->ops->cancel_remain_on_channel) |
8026 | return -EOPNOTSUPP; | |
9588bbd5 | 8027 | |
9588bbd5 JM |
8028 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); |
8029 | ||
e35e4d28 | 8030 | return rdev_cancel_remain_on_channel(rdev, wdev, cookie); |
9588bbd5 JM |
8031 | } |
8032 | ||
13ae75b1 JM |
8033 | static u32 rateset_to_mask(struct ieee80211_supported_band *sband, |
8034 | u8 *rates, u8 rates_len) | |
8035 | { | |
8036 | u8 i; | |
8037 | u32 mask = 0; | |
8038 | ||
8039 | for (i = 0; i < rates_len; i++) { | |
8040 | int rate = (rates[i] & 0x7f) * 5; | |
8041 | int ridx; | |
8042 | for (ridx = 0; ridx < sband->n_bitrates; ridx++) { | |
8043 | struct ieee80211_rate *srate = | |
8044 | &sband->bitrates[ridx]; | |
8045 | if (rate == srate->bitrate) { | |
8046 | mask |= 1 << ridx; | |
8047 | break; | |
8048 | } | |
8049 | } | |
8050 | if (ridx == sband->n_bitrates) | |
8051 | return 0; /* rate not found */ | |
8052 | } | |
8053 | ||
8054 | return mask; | |
8055 | } | |
8056 | ||
24db78c0 SW |
8057 | static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband, |
8058 | u8 *rates, u8 rates_len, | |
8059 | u8 mcs[IEEE80211_HT_MCS_MASK_LEN]) | |
8060 | { | |
8061 | u8 i; | |
8062 | ||
8063 | memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN); | |
8064 | ||
8065 | for (i = 0; i < rates_len; i++) { | |
8066 | int ridx, rbit; | |
8067 | ||
8068 | ridx = rates[i] / 8; | |
8069 | rbit = BIT(rates[i] % 8); | |
8070 | ||
8071 | /* check validity */ | |
910570b5 | 8072 | if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN)) |
24db78c0 SW |
8073 | return false; |
8074 | ||
8075 | /* check availability */ | |
8076 | if (sband->ht_cap.mcs.rx_mask[ridx] & rbit) | |
8077 | mcs[ridx] |= rbit; | |
8078 | else | |
8079 | return false; | |
8080 | } | |
8081 | ||
8082 | return true; | |
8083 | } | |
8084 | ||
204e35a9 JD |
8085 | static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map) |
8086 | { | |
8087 | u16 mcs_mask = 0; | |
8088 | ||
8089 | switch (vht_mcs_map) { | |
8090 | case IEEE80211_VHT_MCS_NOT_SUPPORTED: | |
8091 | break; | |
8092 | case IEEE80211_VHT_MCS_SUPPORT_0_7: | |
8093 | mcs_mask = 0x00FF; | |
8094 | break; | |
8095 | case IEEE80211_VHT_MCS_SUPPORT_0_8: | |
8096 | mcs_mask = 0x01FF; | |
8097 | break; | |
8098 | case IEEE80211_VHT_MCS_SUPPORT_0_9: | |
8099 | mcs_mask = 0x03FF; | |
8100 | break; | |
8101 | default: | |
8102 | break; | |
8103 | } | |
8104 | ||
8105 | return mcs_mask; | |
8106 | } | |
8107 | ||
8108 | static void vht_build_mcs_mask(u16 vht_mcs_map, | |
8109 | u16 vht_mcs_mask[NL80211_VHT_NSS_MAX]) | |
8110 | { | |
8111 | u8 nss; | |
8112 | ||
8113 | for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) { | |
8114 | vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03); | |
8115 | vht_mcs_map >>= 2; | |
8116 | } | |
8117 | } | |
8118 | ||
8119 | static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband, | |
8120 | struct nl80211_txrate_vht *txrate, | |
8121 | u16 mcs[NL80211_VHT_NSS_MAX]) | |
8122 | { | |
8123 | u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8124 | u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {}; | |
8125 | u8 i; | |
8126 | ||
8127 | if (!sband->vht_cap.vht_supported) | |
8128 | return false; | |
8129 | ||
8130 | memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX); | |
8131 | ||
8132 | /* Build vht_mcs_mask from VHT capabilities */ | |
8133 | vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask); | |
8134 | ||
8135 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) { | |
8136 | if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i]) | |
8137 | mcs[i] = txrate->mcs[i]; | |
8138 | else | |
8139 | return false; | |
8140 | } | |
8141 | ||
8142 | return true; | |
8143 | } | |
8144 | ||
b54452b0 | 8145 | static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = { |
13ae75b1 JM |
8146 | [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY, |
8147 | .len = NL80211_MAX_SUPP_RATES }, | |
d1e33e65 JD |
8148 | [NL80211_TXRATE_HT] = { .type = NLA_BINARY, |
8149 | .len = NL80211_MAX_SUPP_HT_RATES }, | |
204e35a9 | 8150 | [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)}, |
0b9323f6 | 8151 | [NL80211_TXRATE_GI] = { .type = NLA_U8 }, |
13ae75b1 JM |
8152 | }; |
8153 | ||
8154 | static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb, | |
8155 | struct genl_info *info) | |
8156 | { | |
8157 | struct nlattr *tb[NL80211_TXRATE_MAX + 1]; | |
4c476991 | 8158 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
13ae75b1 | 8159 | struct cfg80211_bitrate_mask mask; |
4c476991 JB |
8160 | int rem, i; |
8161 | struct net_device *dev = info->user_ptr[1]; | |
13ae75b1 JM |
8162 | struct nlattr *tx_rates; |
8163 | struct ieee80211_supported_band *sband; | |
204e35a9 | 8164 | u16 vht_tx_mcs_map; |
13ae75b1 | 8165 | |
4c476991 JB |
8166 | if (!rdev->ops->set_bitrate_mask) |
8167 | return -EOPNOTSUPP; | |
13ae75b1 JM |
8168 | |
8169 | memset(&mask, 0, sizeof(mask)); | |
8170 | /* Default to all rates enabled */ | |
8171 | for (i = 0; i < IEEE80211_NUM_BANDS; i++) { | |
8172 | sband = rdev->wiphy.bands[i]; | |
7869303b JD |
8173 | |
8174 | if (!sband) | |
8175 | continue; | |
8176 | ||
8177 | mask.control[i].legacy = (1 << sband->n_bitrates) - 1; | |
d1e33e65 | 8178 | memcpy(mask.control[i].ht_mcs, |
7869303b | 8179 | sband->ht_cap.mcs.rx_mask, |
d1e33e65 | 8180 | sizeof(mask.control[i].ht_mcs)); |
204e35a9 JD |
8181 | |
8182 | if (!sband->vht_cap.vht_supported) | |
8183 | continue; | |
8184 | ||
8185 | vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map); | |
8186 | vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs); | |
13ae75b1 JM |
8187 | } |
8188 | ||
b9243ab0 JD |
8189 | /* if no rates are given set it back to the defaults */ |
8190 | if (!info->attrs[NL80211_ATTR_TX_RATES]) | |
8191 | goto out; | |
8192 | ||
13ae75b1 JM |
8193 | /* |
8194 | * The nested attribute uses enum nl80211_band as the index. This maps | |
8195 | * directly to the enum ieee80211_band values used in cfg80211. | |
8196 | */ | |
24db78c0 | 8197 | BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8); |
ae811e21 | 8198 | nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) { |
13ae75b1 | 8199 | enum ieee80211_band band = nla_type(tx_rates); |
ae811e21 JB |
8200 | int err; |
8201 | ||
4c476991 JB |
8202 | if (band < 0 || band >= IEEE80211_NUM_BANDS) |
8203 | return -EINVAL; | |
13ae75b1 | 8204 | sband = rdev->wiphy.bands[band]; |
4c476991 JB |
8205 | if (sband == NULL) |
8206 | return -EINVAL; | |
ae811e21 JB |
8207 | err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates), |
8208 | nla_len(tx_rates), nl80211_txattr_policy); | |
8209 | if (err) | |
8210 | return err; | |
13ae75b1 JM |
8211 | if (tb[NL80211_TXRATE_LEGACY]) { |
8212 | mask.control[band].legacy = rateset_to_mask( | |
8213 | sband, | |
8214 | nla_data(tb[NL80211_TXRATE_LEGACY]), | |
8215 | nla_len(tb[NL80211_TXRATE_LEGACY])); | |
218d2e26 BS |
8216 | if ((mask.control[band].legacy == 0) && |
8217 | nla_len(tb[NL80211_TXRATE_LEGACY])) | |
8218 | return -EINVAL; | |
24db78c0 | 8219 | } |
d1e33e65 | 8220 | if (tb[NL80211_TXRATE_HT]) { |
24db78c0 SW |
8221 | if (!ht_rateset_to_mask( |
8222 | sband, | |
d1e33e65 JD |
8223 | nla_data(tb[NL80211_TXRATE_HT]), |
8224 | nla_len(tb[NL80211_TXRATE_HT]), | |
8225 | mask.control[band].ht_mcs)) | |
24db78c0 SW |
8226 | return -EINVAL; |
8227 | } | |
204e35a9 JD |
8228 | if (tb[NL80211_TXRATE_VHT]) { |
8229 | if (!vht_set_mcs_mask( | |
8230 | sband, | |
8231 | nla_data(tb[NL80211_TXRATE_VHT]), | |
8232 | mask.control[band].vht_mcs)) | |
8233 | return -EINVAL; | |
8234 | } | |
0b9323f6 JD |
8235 | if (tb[NL80211_TXRATE_GI]) { |
8236 | mask.control[band].gi = | |
8237 | nla_get_u8(tb[NL80211_TXRATE_GI]); | |
8238 | if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI) | |
8239 | return -EINVAL; | |
8240 | } | |
24db78c0 SW |
8241 | |
8242 | if (mask.control[band].legacy == 0) { | |
204e35a9 JD |
8243 | /* don't allow empty legacy rates if HT or VHT |
8244 | * are not even supported. | |
8245 | */ | |
8246 | if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported || | |
8247 | rdev->wiphy.bands[band]->vht_cap.vht_supported)) | |
24db78c0 SW |
8248 | return -EINVAL; |
8249 | ||
8250 | for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) | |
d1e33e65 | 8251 | if (mask.control[band].ht_mcs[i]) |
204e35a9 JD |
8252 | goto out; |
8253 | ||
8254 | for (i = 0; i < NL80211_VHT_NSS_MAX; i++) | |
8255 | if (mask.control[band].vht_mcs[i]) | |
8256 | goto out; | |
24db78c0 SW |
8257 | |
8258 | /* legacy and mcs rates may not be both empty */ | |
204e35a9 | 8259 | return -EINVAL; |
13ae75b1 JM |
8260 | } |
8261 | } | |
8262 | ||
b9243ab0 | 8263 | out: |
e35e4d28 | 8264 | return rdev_set_bitrate_mask(rdev, dev, NULL, &mask); |
13ae75b1 JM |
8265 | } |
8266 | ||
2e161f78 | 8267 | static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8268 | { |
4c476991 | 8269 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8270 | struct wireless_dev *wdev = info->user_ptr[1]; |
2e161f78 | 8271 | u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION; |
026331c4 JM |
8272 | |
8273 | if (!info->attrs[NL80211_ATTR_FRAME_MATCH]) | |
8274 | return -EINVAL; | |
8275 | ||
2e161f78 JB |
8276 | if (info->attrs[NL80211_ATTR_FRAME_TYPE]) |
8277 | frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]); | |
026331c4 | 8278 | |
71bbc994 JB |
8279 | switch (wdev->iftype) { |
8280 | case NL80211_IFTYPE_STATION: | |
8281 | case NL80211_IFTYPE_ADHOC: | |
8282 | case NL80211_IFTYPE_P2P_CLIENT: | |
8283 | case NL80211_IFTYPE_AP: | |
8284 | case NL80211_IFTYPE_AP_VLAN: | |
8285 | case NL80211_IFTYPE_MESH_POINT: | |
8286 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8287 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8288 | break; |
8289 | default: | |
4c476991 | 8290 | return -EOPNOTSUPP; |
71bbc994 | 8291 | } |
026331c4 JM |
8292 | |
8293 | /* not much point in registering if we can't reply */ | |
4c476991 JB |
8294 | if (!rdev->ops->mgmt_tx) |
8295 | return -EOPNOTSUPP; | |
026331c4 | 8296 | |
15e47304 | 8297 | return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type, |
026331c4 JM |
8298 | nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]), |
8299 | nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH])); | |
026331c4 JM |
8300 | } |
8301 | ||
2e161f78 | 8302 | static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info) |
026331c4 | 8303 | { |
4c476991 | 8304 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
71bbc994 | 8305 | struct wireless_dev *wdev = info->user_ptr[1]; |
683b6d3b | 8306 | struct cfg80211_chan_def chandef; |
026331c4 | 8307 | int err; |
d64d373f | 8308 | void *hdr = NULL; |
026331c4 | 8309 | u64 cookie; |
e247bd90 | 8310 | struct sk_buff *msg = NULL; |
b176e629 AO |
8311 | struct cfg80211_mgmt_tx_params params = { |
8312 | .dont_wait_for_ack = | |
8313 | info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK], | |
8314 | }; | |
026331c4 | 8315 | |
683b6d3b | 8316 | if (!info->attrs[NL80211_ATTR_FRAME]) |
026331c4 JM |
8317 | return -EINVAL; |
8318 | ||
4c476991 JB |
8319 | if (!rdev->ops->mgmt_tx) |
8320 | return -EOPNOTSUPP; | |
026331c4 | 8321 | |
71bbc994 | 8322 | switch (wdev->iftype) { |
ea141b75 AQ |
8323 | case NL80211_IFTYPE_P2P_DEVICE: |
8324 | if (!info->attrs[NL80211_ATTR_WIPHY_FREQ]) | |
8325 | return -EINVAL; | |
71bbc994 JB |
8326 | case NL80211_IFTYPE_STATION: |
8327 | case NL80211_IFTYPE_ADHOC: | |
8328 | case NL80211_IFTYPE_P2P_CLIENT: | |
8329 | case NL80211_IFTYPE_AP: | |
8330 | case NL80211_IFTYPE_AP_VLAN: | |
8331 | case NL80211_IFTYPE_MESH_POINT: | |
8332 | case NL80211_IFTYPE_P2P_GO: | |
8333 | break; | |
8334 | default: | |
4c476991 | 8335 | return -EOPNOTSUPP; |
71bbc994 | 8336 | } |
026331c4 | 8337 | |
f7ca38df | 8338 | if (info->attrs[NL80211_ATTR_DURATION]) { |
7c4ef712 | 8339 | if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
f7ca38df | 8340 | return -EINVAL; |
b176e629 | 8341 | params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]); |
ebf348fc JB |
8342 | |
8343 | /* | |
8344 | * We should wait on the channel for at least a minimum amount | |
8345 | * of time (10ms) but no longer than the driver supports. | |
8346 | */ | |
b176e629 AO |
8347 | if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME || |
8348 | params.wait > rdev->wiphy.max_remain_on_channel_duration) | |
ebf348fc JB |
8349 | return -EINVAL; |
8350 | ||
f7ca38df JB |
8351 | } |
8352 | ||
b176e629 | 8353 | params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK]; |
f7ca38df | 8354 | |
b176e629 | 8355 | if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX)) |
7c4ef712 JB |
8356 | return -EINVAL; |
8357 | ||
b176e629 | 8358 | params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]); |
e9f935e3 | 8359 | |
ea141b75 AQ |
8360 | /* get the channel if any has been specified, otherwise pass NULL to |
8361 | * the driver. The latter will use the current one | |
8362 | */ | |
8363 | chandef.chan = NULL; | |
8364 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { | |
8365 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
8366 | if (err) | |
8367 | return err; | |
8368 | } | |
8369 | ||
b176e629 | 8370 | if (!chandef.chan && params.offchan) |
ea141b75 | 8371 | return -EINVAL; |
026331c4 | 8372 | |
34d22ce2 AO |
8373 | params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]); |
8374 | params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]); | |
8375 | ||
8376 | if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) { | |
8377 | int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8378 | int i; | |
8379 | ||
8380 | if (len % sizeof(u16)) | |
8381 | return -EINVAL; | |
8382 | ||
8383 | params.n_csa_offsets = len / sizeof(u16); | |
8384 | params.csa_offsets = | |
8385 | nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]); | |
8386 | ||
8387 | /* check that all the offsets fit the frame */ | |
8388 | for (i = 0; i < params.n_csa_offsets; i++) { | |
8389 | if (params.csa_offsets[i] >= params.len) | |
8390 | return -EINVAL; | |
8391 | } | |
8392 | } | |
8393 | ||
b176e629 | 8394 | if (!params.dont_wait_for_ack) { |
e247bd90 JB |
8395 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
8396 | if (!msg) | |
8397 | return -ENOMEM; | |
026331c4 | 8398 | |
15e47304 | 8399 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
e247bd90 | 8400 | NL80211_CMD_FRAME); |
cb35fba3 DC |
8401 | if (!hdr) { |
8402 | err = -ENOBUFS; | |
e247bd90 JB |
8403 | goto free_msg; |
8404 | } | |
026331c4 | 8405 | } |
e247bd90 | 8406 | |
b176e629 AO |
8407 | params.chan = chandef.chan; |
8408 | err = cfg80211_mlme_mgmt_tx(rdev, wdev, ¶ms, &cookie); | |
026331c4 JM |
8409 | if (err) |
8410 | goto free_msg; | |
8411 | ||
e247bd90 | 8412 | if (msg) { |
9360ffd1 DM |
8413 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
8414 | goto nla_put_failure; | |
026331c4 | 8415 | |
e247bd90 JB |
8416 | genlmsg_end(msg, hdr); |
8417 | return genlmsg_reply(msg, info); | |
8418 | } | |
8419 | ||
8420 | return 0; | |
026331c4 JM |
8421 | |
8422 | nla_put_failure: | |
8423 | err = -ENOBUFS; | |
8424 | free_msg: | |
8425 | nlmsg_free(msg); | |
026331c4 JM |
8426 | return err; |
8427 | } | |
8428 | ||
f7ca38df JB |
8429 | static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info) |
8430 | { | |
8431 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
71bbc994 | 8432 | struct wireless_dev *wdev = info->user_ptr[1]; |
f7ca38df JB |
8433 | u64 cookie; |
8434 | ||
8435 | if (!info->attrs[NL80211_ATTR_COOKIE]) | |
8436 | return -EINVAL; | |
8437 | ||
8438 | if (!rdev->ops->mgmt_tx_cancel_wait) | |
8439 | return -EOPNOTSUPP; | |
8440 | ||
71bbc994 JB |
8441 | switch (wdev->iftype) { |
8442 | case NL80211_IFTYPE_STATION: | |
8443 | case NL80211_IFTYPE_ADHOC: | |
8444 | case NL80211_IFTYPE_P2P_CLIENT: | |
8445 | case NL80211_IFTYPE_AP: | |
8446 | case NL80211_IFTYPE_AP_VLAN: | |
8447 | case NL80211_IFTYPE_P2P_GO: | |
98104fde | 8448 | case NL80211_IFTYPE_P2P_DEVICE: |
71bbc994 JB |
8449 | break; |
8450 | default: | |
f7ca38df | 8451 | return -EOPNOTSUPP; |
71bbc994 | 8452 | } |
f7ca38df JB |
8453 | |
8454 | cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]); | |
8455 | ||
e35e4d28 | 8456 | return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie); |
f7ca38df JB |
8457 | } |
8458 | ||
ffb9eb3d KV |
8459 | static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info) |
8460 | { | |
4c476991 | 8461 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d | 8462 | struct wireless_dev *wdev; |
4c476991 | 8463 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8464 | u8 ps_state; |
8465 | bool state; | |
8466 | int err; | |
8467 | ||
4c476991 JB |
8468 | if (!info->attrs[NL80211_ATTR_PS_STATE]) |
8469 | return -EINVAL; | |
ffb9eb3d KV |
8470 | |
8471 | ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]); | |
8472 | ||
4c476991 JB |
8473 | if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED) |
8474 | return -EINVAL; | |
ffb9eb3d KV |
8475 | |
8476 | wdev = dev->ieee80211_ptr; | |
8477 | ||
4c476991 JB |
8478 | if (!rdev->ops->set_power_mgmt) |
8479 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8480 | |
8481 | state = (ps_state == NL80211_PS_ENABLED) ? true : false; | |
8482 | ||
8483 | if (state == wdev->ps) | |
4c476991 | 8484 | return 0; |
ffb9eb3d | 8485 | |
e35e4d28 | 8486 | err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout); |
4c476991 JB |
8487 | if (!err) |
8488 | wdev->ps = state; | |
ffb9eb3d KV |
8489 | return err; |
8490 | } | |
8491 | ||
8492 | static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info) | |
8493 | { | |
4c476991 | 8494 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
ffb9eb3d KV |
8495 | enum nl80211_ps_state ps_state; |
8496 | struct wireless_dev *wdev; | |
4c476991 | 8497 | struct net_device *dev = info->user_ptr[1]; |
ffb9eb3d KV |
8498 | struct sk_buff *msg; |
8499 | void *hdr; | |
8500 | int err; | |
8501 | ||
ffb9eb3d KV |
8502 | wdev = dev->ieee80211_ptr; |
8503 | ||
4c476991 JB |
8504 | if (!rdev->ops->set_power_mgmt) |
8505 | return -EOPNOTSUPP; | |
ffb9eb3d KV |
8506 | |
8507 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
4c476991 JB |
8508 | if (!msg) |
8509 | return -ENOMEM; | |
ffb9eb3d | 8510 | |
15e47304 | 8511 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ffb9eb3d KV |
8512 | NL80211_CMD_GET_POWER_SAVE); |
8513 | if (!hdr) { | |
4c476991 | 8514 | err = -ENOBUFS; |
ffb9eb3d KV |
8515 | goto free_msg; |
8516 | } | |
8517 | ||
8518 | if (wdev->ps) | |
8519 | ps_state = NL80211_PS_ENABLED; | |
8520 | else | |
8521 | ps_state = NL80211_PS_DISABLED; | |
8522 | ||
9360ffd1 DM |
8523 | if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state)) |
8524 | goto nla_put_failure; | |
ffb9eb3d KV |
8525 | |
8526 | genlmsg_end(msg, hdr); | |
4c476991 | 8527 | return genlmsg_reply(msg, info); |
ffb9eb3d | 8528 | |
4c476991 | 8529 | nla_put_failure: |
ffb9eb3d | 8530 | err = -ENOBUFS; |
4c476991 | 8531 | free_msg: |
ffb9eb3d | 8532 | nlmsg_free(msg); |
ffb9eb3d KV |
8533 | return err; |
8534 | } | |
8535 | ||
94e860f1 JB |
8536 | static const struct nla_policy |
8537 | nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = { | |
d6dc1a38 JO |
8538 | [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 }, |
8539 | [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 }, | |
8540 | [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 }, | |
84f10708 TP |
8541 | [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 }, |
8542 | [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 }, | |
8543 | [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 }, | |
d6dc1a38 JO |
8544 | }; |
8545 | ||
84f10708 | 8546 | static int nl80211_set_cqm_txe(struct genl_info *info, |
d9d8b019 | 8547 | u32 rate, u32 pkts, u32 intvl) |
84f10708 TP |
8548 | { |
8549 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
84f10708 | 8550 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8551 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
84f10708 | 8552 | |
d9d8b019 | 8553 | if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL) |
84f10708 TP |
8554 | return -EINVAL; |
8555 | ||
84f10708 TP |
8556 | if (!rdev->ops->set_cqm_txe_config) |
8557 | return -EOPNOTSUPP; | |
8558 | ||
8559 | if (wdev->iftype != NL80211_IFTYPE_STATION && | |
8560 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) | |
8561 | return -EOPNOTSUPP; | |
8562 | ||
e35e4d28 | 8563 | return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl); |
84f10708 TP |
8564 | } |
8565 | ||
d6dc1a38 JO |
8566 | static int nl80211_set_cqm_rssi(struct genl_info *info, |
8567 | s32 threshold, u32 hysteresis) | |
8568 | { | |
4c476991 | 8569 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
4c476991 | 8570 | struct net_device *dev = info->user_ptr[1]; |
1da5fcc8 | 8571 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
d6dc1a38 JO |
8572 | |
8573 | if (threshold > 0) | |
8574 | return -EINVAL; | |
8575 | ||
1da5fcc8 JB |
8576 | /* disabling - hysteresis should also be zero then */ |
8577 | if (threshold == 0) | |
8578 | hysteresis = 0; | |
d6dc1a38 | 8579 | |
4c476991 JB |
8580 | if (!rdev->ops->set_cqm_rssi_config) |
8581 | return -EOPNOTSUPP; | |
d6dc1a38 | 8582 | |
074ac8df | 8583 | if (wdev->iftype != NL80211_IFTYPE_STATION && |
4c476991 JB |
8584 | wdev->iftype != NL80211_IFTYPE_P2P_CLIENT) |
8585 | return -EOPNOTSUPP; | |
d6dc1a38 | 8586 | |
e35e4d28 | 8587 | return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis); |
d6dc1a38 JO |
8588 | } |
8589 | ||
8590 | static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info) | |
8591 | { | |
8592 | struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1]; | |
8593 | struct nlattr *cqm; | |
8594 | int err; | |
8595 | ||
8596 | cqm = info->attrs[NL80211_ATTR_CQM]; | |
1da5fcc8 JB |
8597 | if (!cqm) |
8598 | return -EINVAL; | |
d6dc1a38 JO |
8599 | |
8600 | err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm, | |
8601 | nl80211_attr_cqm_policy); | |
8602 | if (err) | |
1da5fcc8 | 8603 | return err; |
d6dc1a38 JO |
8604 | |
8605 | if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] && | |
8606 | attrs[NL80211_ATTR_CQM_RSSI_HYST]) { | |
1da5fcc8 JB |
8607 | s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]); |
8608 | u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]); | |
d6dc1a38 | 8609 | |
1da5fcc8 JB |
8610 | return nl80211_set_cqm_rssi(info, threshold, hysteresis); |
8611 | } | |
8612 | ||
8613 | if (attrs[NL80211_ATTR_CQM_TXE_RATE] && | |
8614 | attrs[NL80211_ATTR_CQM_TXE_PKTS] && | |
8615 | attrs[NL80211_ATTR_CQM_TXE_INTVL]) { | |
8616 | u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]); | |
8617 | u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]); | |
8618 | u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]); | |
8619 | ||
8620 | return nl80211_set_cqm_txe(info, rate, pkts, intvl); | |
8621 | } | |
8622 | ||
8623 | return -EINVAL; | |
d6dc1a38 JO |
8624 | } |
8625 | ||
6e0bd6c3 RL |
8626 | static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info) |
8627 | { | |
8628 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8629 | struct net_device *dev = info->user_ptr[1]; | |
8630 | struct ocb_setup setup = {}; | |
8631 | int err; | |
8632 | ||
8633 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); | |
8634 | if (err) | |
8635 | return err; | |
8636 | ||
8637 | return cfg80211_join_ocb(rdev, dev, &setup); | |
8638 | } | |
8639 | ||
8640 | static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info) | |
8641 | { | |
8642 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8643 | struct net_device *dev = info->user_ptr[1]; | |
8644 | ||
8645 | return cfg80211_leave_ocb(rdev, dev); | |
8646 | } | |
8647 | ||
29cbe68c JB |
8648 | static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info) |
8649 | { | |
8650 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8651 | struct net_device *dev = info->user_ptr[1]; | |
8652 | struct mesh_config cfg; | |
c80d545d | 8653 | struct mesh_setup setup; |
29cbe68c JB |
8654 | int err; |
8655 | ||
8656 | /* start with default */ | |
8657 | memcpy(&cfg, &default_mesh_config, sizeof(cfg)); | |
c80d545d | 8658 | memcpy(&setup, &default_mesh_setup, sizeof(setup)); |
29cbe68c | 8659 | |
24bdd9f4 | 8660 | if (info->attrs[NL80211_ATTR_MESH_CONFIG]) { |
29cbe68c | 8661 | /* and parse parameters if given */ |
24bdd9f4 | 8662 | err = nl80211_parse_mesh_config(info, &cfg, NULL); |
29cbe68c JB |
8663 | if (err) |
8664 | return err; | |
8665 | } | |
8666 | ||
8667 | if (!info->attrs[NL80211_ATTR_MESH_ID] || | |
8668 | !nla_len(info->attrs[NL80211_ATTR_MESH_ID])) | |
8669 | return -EINVAL; | |
8670 | ||
c80d545d JC |
8671 | setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]); |
8672 | setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]); | |
8673 | ||
4bb62344 CYY |
8674 | if (info->attrs[NL80211_ATTR_MCAST_RATE] && |
8675 | !nl80211_parse_mcast_rate(rdev, setup.mcast_rate, | |
8676 | nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]))) | |
8677 | return -EINVAL; | |
8678 | ||
9bdbf04d MP |
8679 | if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) { |
8680 | setup.beacon_interval = | |
8681 | nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]); | |
8682 | if (setup.beacon_interval < 10 || | |
8683 | setup.beacon_interval > 10000) | |
8684 | return -EINVAL; | |
8685 | } | |
8686 | ||
8687 | if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) { | |
8688 | setup.dtim_period = | |
8689 | nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]); | |
8690 | if (setup.dtim_period < 1 || setup.dtim_period > 100) | |
8691 | return -EINVAL; | |
8692 | } | |
8693 | ||
c80d545d JC |
8694 | if (info->attrs[NL80211_ATTR_MESH_SETUP]) { |
8695 | /* parse additional setup parameters if given */ | |
8696 | err = nl80211_parse_mesh_setup(info, &setup); | |
8697 | if (err) | |
8698 | return err; | |
8699 | } | |
8700 | ||
d37bb18a TP |
8701 | if (setup.user_mpm) |
8702 | cfg.auto_open_plinks = false; | |
8703 | ||
cc1d2806 | 8704 | if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) { |
683b6d3b JB |
8705 | err = nl80211_parse_chandef(rdev, info, &setup.chandef); |
8706 | if (err) | |
8707 | return err; | |
cc1d2806 JB |
8708 | } else { |
8709 | /* cfg80211_join_mesh() will sort it out */ | |
683b6d3b | 8710 | setup.chandef.chan = NULL; |
cc1d2806 JB |
8711 | } |
8712 | ||
ffb3cf30 AN |
8713 | if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) { |
8714 | u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8715 | int n_rates = | |
8716 | nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]); | |
8717 | struct ieee80211_supported_band *sband; | |
8718 | ||
8719 | if (!setup.chandef.chan) | |
8720 | return -EINVAL; | |
8721 | ||
8722 | sband = rdev->wiphy.bands[setup.chandef.chan->band]; | |
8723 | ||
8724 | err = ieee80211_get_ratemask(sband, rates, n_rates, | |
8725 | &setup.basic_rates); | |
8726 | if (err) | |
8727 | return err; | |
8728 | } | |
8729 | ||
c80d545d | 8730 | return cfg80211_join_mesh(rdev, dev, &setup, &cfg); |
29cbe68c JB |
8731 | } |
8732 | ||
8733 | static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info) | |
8734 | { | |
8735 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8736 | struct net_device *dev = info->user_ptr[1]; | |
8737 | ||
8738 | return cfg80211_leave_mesh(rdev, dev); | |
8739 | } | |
8740 | ||
dfb89c56 | 8741 | #ifdef CONFIG_PM |
bb92d199 AK |
8742 | static int nl80211_send_wowlan_patterns(struct sk_buff *msg, |
8743 | struct cfg80211_registered_device *rdev) | |
8744 | { | |
6abb9cb9 | 8745 | struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config; |
bb92d199 AK |
8746 | struct nlattr *nl_pats, *nl_pat; |
8747 | int i, pat_len; | |
8748 | ||
6abb9cb9 | 8749 | if (!wowlan->n_patterns) |
bb92d199 AK |
8750 | return 0; |
8751 | ||
8752 | nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN); | |
8753 | if (!nl_pats) | |
8754 | return -ENOBUFS; | |
8755 | ||
6abb9cb9 | 8756 | for (i = 0; i < wowlan->n_patterns; i++) { |
bb92d199 AK |
8757 | nl_pat = nla_nest_start(msg, i + 1); |
8758 | if (!nl_pat) | |
8759 | return -ENOBUFS; | |
6abb9cb9 | 8760 | pat_len = wowlan->patterns[i].pattern_len; |
50ac6607 | 8761 | if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8), |
6abb9cb9 | 8762 | wowlan->patterns[i].mask) || |
50ac6607 AK |
8763 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, |
8764 | wowlan->patterns[i].pattern) || | |
8765 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
6abb9cb9 | 8766 | wowlan->patterns[i].pkt_offset)) |
bb92d199 AK |
8767 | return -ENOBUFS; |
8768 | nla_nest_end(msg, nl_pat); | |
8769 | } | |
8770 | nla_nest_end(msg, nl_pats); | |
8771 | ||
8772 | return 0; | |
8773 | } | |
8774 | ||
2a0e047e JB |
8775 | static int nl80211_send_wowlan_tcp(struct sk_buff *msg, |
8776 | struct cfg80211_wowlan_tcp *tcp) | |
8777 | { | |
8778 | struct nlattr *nl_tcp; | |
8779 | ||
8780 | if (!tcp) | |
8781 | return 0; | |
8782 | ||
8783 | nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION); | |
8784 | if (!nl_tcp) | |
8785 | return -ENOBUFS; | |
8786 | ||
8787 | if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) || | |
8788 | nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) || | |
8789 | nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) || | |
8790 | nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) || | |
8791 | nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) || | |
8792 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD, | |
8793 | tcp->payload_len, tcp->payload) || | |
8794 | nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL, | |
8795 | tcp->data_interval) || | |
8796 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD, | |
8797 | tcp->wake_len, tcp->wake_data) || | |
8798 | nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK, | |
8799 | DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask)) | |
8800 | return -ENOBUFS; | |
8801 | ||
8802 | if (tcp->payload_seq.len && | |
8803 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ, | |
8804 | sizeof(tcp->payload_seq), &tcp->payload_seq)) | |
8805 | return -ENOBUFS; | |
8806 | ||
8807 | if (tcp->payload_tok.len && | |
8808 | nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN, | |
8809 | sizeof(tcp->payload_tok) + tcp->tokens_size, | |
8810 | &tcp->payload_tok)) | |
8811 | return -ENOBUFS; | |
8812 | ||
e248ad30 JB |
8813 | nla_nest_end(msg, nl_tcp); |
8814 | ||
2a0e047e JB |
8815 | return 0; |
8816 | } | |
8817 | ||
75453ccb LC |
8818 | static int nl80211_send_wowlan_nd(struct sk_buff *msg, |
8819 | struct cfg80211_sched_scan_request *req) | |
8820 | { | |
8821 | struct nlattr *nd, *freqs, *matches, *match; | |
8822 | int i; | |
8823 | ||
8824 | if (!req) | |
8825 | return 0; | |
8826 | ||
8827 | nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT); | |
8828 | if (!nd) | |
8829 | return -ENOBUFS; | |
8830 | ||
8831 | if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval)) | |
8832 | return -ENOBUFS; | |
8833 | ||
8834 | freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
8835 | if (!freqs) | |
8836 | return -ENOBUFS; | |
8837 | ||
8838 | for (i = 0; i < req->n_channels; i++) | |
8839 | nla_put_u32(msg, i, req->channels[i]->center_freq); | |
8840 | ||
8841 | nla_nest_end(msg, freqs); | |
8842 | ||
8843 | if (req->n_match_sets) { | |
8844 | matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH); | |
8845 | for (i = 0; i < req->n_match_sets; i++) { | |
8846 | match = nla_nest_start(msg, i); | |
8847 | nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID, | |
8848 | req->match_sets[i].ssid.ssid_len, | |
8849 | req->match_sets[i].ssid.ssid); | |
8850 | nla_nest_end(msg, match); | |
8851 | } | |
8852 | nla_nest_end(msg, matches); | |
8853 | } | |
8854 | ||
8855 | nla_nest_end(msg, nd); | |
8856 | ||
8857 | return 0; | |
8858 | } | |
8859 | ||
ff1b6e69 JB |
8860 | static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info) |
8861 | { | |
8862 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
8863 | struct sk_buff *msg; | |
8864 | void *hdr; | |
2a0e047e | 8865 | u32 size = NLMSG_DEFAULT_SIZE; |
ff1b6e69 | 8866 | |
964dc9e2 | 8867 | if (!rdev->wiphy.wowlan) |
ff1b6e69 JB |
8868 | return -EOPNOTSUPP; |
8869 | ||
6abb9cb9 | 8870 | if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) { |
2a0e047e | 8871 | /* adjust size to have room for all the data */ |
6abb9cb9 JB |
8872 | size += rdev->wiphy.wowlan_config->tcp->tokens_size + |
8873 | rdev->wiphy.wowlan_config->tcp->payload_len + | |
8874 | rdev->wiphy.wowlan_config->tcp->wake_len + | |
8875 | rdev->wiphy.wowlan_config->tcp->wake_len / 8; | |
2a0e047e JB |
8876 | } |
8877 | ||
8878 | msg = nlmsg_new(size, GFP_KERNEL); | |
ff1b6e69 JB |
8879 | if (!msg) |
8880 | return -ENOMEM; | |
8881 | ||
15e47304 | 8882 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
ff1b6e69 JB |
8883 | NL80211_CMD_GET_WOWLAN); |
8884 | if (!hdr) | |
8885 | goto nla_put_failure; | |
8886 | ||
6abb9cb9 | 8887 | if (rdev->wiphy.wowlan_config) { |
ff1b6e69 JB |
8888 | struct nlattr *nl_wowlan; |
8889 | ||
8890 | nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
8891 | if (!nl_wowlan) | |
8892 | goto nla_put_failure; | |
8893 | ||
6abb9cb9 | 8894 | if ((rdev->wiphy.wowlan_config->any && |
9360ffd1 | 8895 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
6abb9cb9 | 8896 | (rdev->wiphy.wowlan_config->disconnect && |
9360ffd1 | 8897 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
6abb9cb9 | 8898 | (rdev->wiphy.wowlan_config->magic_pkt && |
9360ffd1 | 8899 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
6abb9cb9 | 8900 | (rdev->wiphy.wowlan_config->gtk_rekey_failure && |
9360ffd1 | 8901 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
6abb9cb9 | 8902 | (rdev->wiphy.wowlan_config->eap_identity_req && |
9360ffd1 | 8903 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
6abb9cb9 | 8904 | (rdev->wiphy.wowlan_config->four_way_handshake && |
9360ffd1 | 8905 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
6abb9cb9 | 8906 | (rdev->wiphy.wowlan_config->rfkill_release && |
9360ffd1 DM |
8907 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) |
8908 | goto nla_put_failure; | |
2a0e047e | 8909 | |
bb92d199 AK |
8910 | if (nl80211_send_wowlan_patterns(msg, rdev)) |
8911 | goto nla_put_failure; | |
2a0e047e | 8912 | |
6abb9cb9 JB |
8913 | if (nl80211_send_wowlan_tcp(msg, |
8914 | rdev->wiphy.wowlan_config->tcp)) | |
2a0e047e | 8915 | goto nla_put_failure; |
75453ccb LC |
8916 | |
8917 | if (nl80211_send_wowlan_nd( | |
8918 | msg, | |
8919 | rdev->wiphy.wowlan_config->nd_config)) | |
8920 | goto nla_put_failure; | |
2a0e047e | 8921 | |
ff1b6e69 JB |
8922 | nla_nest_end(msg, nl_wowlan); |
8923 | } | |
8924 | ||
8925 | genlmsg_end(msg, hdr); | |
8926 | return genlmsg_reply(msg, info); | |
8927 | ||
8928 | nla_put_failure: | |
8929 | nlmsg_free(msg); | |
8930 | return -ENOBUFS; | |
8931 | } | |
8932 | ||
2a0e047e JB |
8933 | static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev, |
8934 | struct nlattr *attr, | |
8935 | struct cfg80211_wowlan *trig) | |
8936 | { | |
8937 | struct nlattr *tb[NUM_NL80211_WOWLAN_TCP]; | |
8938 | struct cfg80211_wowlan_tcp *cfg; | |
8939 | struct nl80211_wowlan_tcp_data_token *tok = NULL; | |
8940 | struct nl80211_wowlan_tcp_data_seq *seq = NULL; | |
8941 | u32 size; | |
8942 | u32 data_size, wake_size, tokens_size = 0, wake_mask_size; | |
8943 | int err, port; | |
8944 | ||
964dc9e2 | 8945 | if (!rdev->wiphy.wowlan->tcp) |
2a0e047e JB |
8946 | return -EINVAL; |
8947 | ||
8948 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP, | |
8949 | nla_data(attr), nla_len(attr), | |
8950 | nl80211_wowlan_tcp_policy); | |
8951 | if (err) | |
8952 | return err; | |
8953 | ||
8954 | if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] || | |
8955 | !tb[NL80211_WOWLAN_TCP_DST_IPV4] || | |
8956 | !tb[NL80211_WOWLAN_TCP_DST_MAC] || | |
8957 | !tb[NL80211_WOWLAN_TCP_DST_PORT] || | |
8958 | !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] || | |
8959 | !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] || | |
8960 | !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] || | |
8961 | !tb[NL80211_WOWLAN_TCP_WAKE_MASK]) | |
8962 | return -EINVAL; | |
8963 | ||
8964 | data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]); | |
964dc9e2 | 8965 | if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max) |
2a0e047e JB |
8966 | return -EINVAL; |
8967 | ||
8968 | if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) > | |
964dc9e2 | 8969 | rdev->wiphy.wowlan->tcp->data_interval_max || |
723d568a | 8970 | nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0) |
2a0e047e JB |
8971 | return -EINVAL; |
8972 | ||
8973 | wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]); | |
964dc9e2 | 8974 | if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max) |
2a0e047e JB |
8975 | return -EINVAL; |
8976 | ||
8977 | wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]); | |
8978 | if (wake_mask_size != DIV_ROUND_UP(wake_size, 8)) | |
8979 | return -EINVAL; | |
8980 | ||
8981 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) { | |
8982 | u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8983 | ||
8984 | tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]); | |
8985 | tokens_size = tokln - sizeof(*tok); | |
8986 | ||
8987 | if (!tok->len || tokens_size % tok->len) | |
8988 | return -EINVAL; | |
964dc9e2 | 8989 | if (!rdev->wiphy.wowlan->tcp->tok) |
2a0e047e | 8990 | return -EINVAL; |
964dc9e2 | 8991 | if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len) |
2a0e047e | 8992 | return -EINVAL; |
964dc9e2 | 8993 | if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len) |
2a0e047e | 8994 | return -EINVAL; |
964dc9e2 | 8995 | if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize) |
2a0e047e JB |
8996 | return -EINVAL; |
8997 | if (tok->offset + tok->len > data_size) | |
8998 | return -EINVAL; | |
8999 | } | |
9000 | ||
9001 | if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) { | |
9002 | seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]); | |
964dc9e2 | 9003 | if (!rdev->wiphy.wowlan->tcp->seq) |
2a0e047e JB |
9004 | return -EINVAL; |
9005 | if (seq->len == 0 || seq->len > 4) | |
9006 | return -EINVAL; | |
9007 | if (seq->len + seq->offset > data_size) | |
9008 | return -EINVAL; | |
9009 | } | |
9010 | ||
9011 | size = sizeof(*cfg); | |
9012 | size += data_size; | |
9013 | size += wake_size + wake_mask_size; | |
9014 | size += tokens_size; | |
9015 | ||
9016 | cfg = kzalloc(size, GFP_KERNEL); | |
9017 | if (!cfg) | |
9018 | return -ENOMEM; | |
9019 | cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]); | |
9020 | cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]); | |
9021 | memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]), | |
9022 | ETH_ALEN); | |
9023 | if (tb[NL80211_WOWLAN_TCP_SRC_PORT]) | |
9024 | port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]); | |
9025 | else | |
9026 | port = 0; | |
9027 | #ifdef CONFIG_INET | |
9028 | /* allocate a socket and port for it and use it */ | |
9029 | err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM, | |
9030 | IPPROTO_TCP, &cfg->sock, 1); | |
9031 | if (err) { | |
9032 | kfree(cfg); | |
9033 | return err; | |
9034 | } | |
9035 | if (inet_csk_get_port(cfg->sock->sk, port)) { | |
9036 | sock_release(cfg->sock); | |
9037 | kfree(cfg); | |
9038 | return -EADDRINUSE; | |
9039 | } | |
9040 | cfg->src_port = inet_sk(cfg->sock->sk)->inet_num; | |
9041 | #else | |
9042 | if (!port) { | |
9043 | kfree(cfg); | |
9044 | return -EINVAL; | |
9045 | } | |
9046 | cfg->src_port = port; | |
9047 | #endif | |
9048 | ||
9049 | cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]); | |
9050 | cfg->payload_len = data_size; | |
9051 | cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size; | |
9052 | memcpy((void *)cfg->payload, | |
9053 | nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]), | |
9054 | data_size); | |
9055 | if (seq) | |
9056 | cfg->payload_seq = *seq; | |
9057 | cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]); | |
9058 | cfg->wake_len = wake_size; | |
9059 | cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size; | |
9060 | memcpy((void *)cfg->wake_data, | |
9061 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]), | |
9062 | wake_size); | |
9063 | cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size + | |
9064 | data_size + wake_size; | |
9065 | memcpy((void *)cfg->wake_mask, | |
9066 | nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]), | |
9067 | wake_mask_size); | |
9068 | if (tok) { | |
9069 | cfg->tokens_size = tokens_size; | |
9070 | memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size); | |
9071 | } | |
9072 | ||
9073 | trig->tcp = cfg; | |
9074 | ||
9075 | return 0; | |
9076 | } | |
9077 | ||
8cd4d456 LC |
9078 | static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev, |
9079 | const struct wiphy_wowlan_support *wowlan, | |
9080 | struct nlattr *attr, | |
9081 | struct cfg80211_wowlan *trig) | |
9082 | { | |
9083 | struct nlattr **tb; | |
9084 | int err; | |
9085 | ||
9086 | tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL); | |
9087 | if (!tb) | |
9088 | return -ENOMEM; | |
9089 | ||
9090 | if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) { | |
9091 | err = -EOPNOTSUPP; | |
9092 | goto out; | |
9093 | } | |
9094 | ||
9095 | err = nla_parse(tb, NL80211_ATTR_MAX, | |
9096 | nla_data(attr), nla_len(attr), | |
9097 | nl80211_policy); | |
9098 | if (err) | |
9099 | goto out; | |
9100 | ||
ad2b26ab | 9101 | trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb); |
8cd4d456 LC |
9102 | err = PTR_ERR_OR_ZERO(trig->nd_config); |
9103 | if (err) | |
9104 | trig->nd_config = NULL; | |
9105 | ||
9106 | out: | |
9107 | kfree(tb); | |
9108 | return err; | |
9109 | } | |
9110 | ||
ff1b6e69 JB |
9111 | static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info) |
9112 | { | |
9113 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9114 | struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG]; | |
ff1b6e69 | 9115 | struct cfg80211_wowlan new_triggers = {}; |
ae33bd81 | 9116 | struct cfg80211_wowlan *ntrig; |
964dc9e2 | 9117 | const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan; |
ff1b6e69 | 9118 | int err, i; |
6abb9cb9 | 9119 | bool prev_enabled = rdev->wiphy.wowlan_config; |
98fc4386 | 9120 | bool regular = false; |
ff1b6e69 | 9121 | |
964dc9e2 | 9122 | if (!wowlan) |
ff1b6e69 JB |
9123 | return -EOPNOTSUPP; |
9124 | ||
ae33bd81 JB |
9125 | if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) { |
9126 | cfg80211_rdev_free_wowlan(rdev); | |
6abb9cb9 | 9127 | rdev->wiphy.wowlan_config = NULL; |
ae33bd81 JB |
9128 | goto set_wakeup; |
9129 | } | |
ff1b6e69 JB |
9130 | |
9131 | err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG, | |
9132 | nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9133 | nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]), | |
9134 | nl80211_wowlan_policy); | |
9135 | if (err) | |
9136 | return err; | |
9137 | ||
9138 | if (tb[NL80211_WOWLAN_TRIG_ANY]) { | |
9139 | if (!(wowlan->flags & WIPHY_WOWLAN_ANY)) | |
9140 | return -EINVAL; | |
9141 | new_triggers.any = true; | |
9142 | } | |
9143 | ||
9144 | if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) { | |
9145 | if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT)) | |
9146 | return -EINVAL; | |
9147 | new_triggers.disconnect = true; | |
98fc4386 | 9148 | regular = true; |
ff1b6e69 JB |
9149 | } |
9150 | ||
9151 | if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) { | |
9152 | if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT)) | |
9153 | return -EINVAL; | |
9154 | new_triggers.magic_pkt = true; | |
98fc4386 | 9155 | regular = true; |
ff1b6e69 JB |
9156 | } |
9157 | ||
77dbbb13 JB |
9158 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED]) |
9159 | return -EINVAL; | |
9160 | ||
9161 | if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) { | |
9162 | if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE)) | |
9163 | return -EINVAL; | |
9164 | new_triggers.gtk_rekey_failure = true; | |
98fc4386 | 9165 | regular = true; |
77dbbb13 JB |
9166 | } |
9167 | ||
9168 | if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) { | |
9169 | if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ)) | |
9170 | return -EINVAL; | |
9171 | new_triggers.eap_identity_req = true; | |
98fc4386 | 9172 | regular = true; |
77dbbb13 JB |
9173 | } |
9174 | ||
9175 | if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) { | |
9176 | if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE)) | |
9177 | return -EINVAL; | |
9178 | new_triggers.four_way_handshake = true; | |
98fc4386 | 9179 | regular = true; |
77dbbb13 JB |
9180 | } |
9181 | ||
9182 | if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) { | |
9183 | if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE)) | |
9184 | return -EINVAL; | |
9185 | new_triggers.rfkill_release = true; | |
98fc4386 | 9186 | regular = true; |
77dbbb13 JB |
9187 | } |
9188 | ||
ff1b6e69 JB |
9189 | if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) { |
9190 | struct nlattr *pat; | |
9191 | int n_patterns = 0; | |
bb92d199 | 9192 | int rem, pat_len, mask_len, pkt_offset; |
50ac6607 | 9193 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; |
ff1b6e69 | 9194 | |
98fc4386 JB |
9195 | regular = true; |
9196 | ||
ff1b6e69 JB |
9197 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], |
9198 | rem) | |
9199 | n_patterns++; | |
9200 | if (n_patterns > wowlan->n_patterns) | |
9201 | return -EINVAL; | |
9202 | ||
9203 | new_triggers.patterns = kcalloc(n_patterns, | |
9204 | sizeof(new_triggers.patterns[0]), | |
9205 | GFP_KERNEL); | |
9206 | if (!new_triggers.patterns) | |
9207 | return -ENOMEM; | |
9208 | ||
9209 | new_triggers.n_patterns = n_patterns; | |
9210 | i = 0; | |
9211 | ||
9212 | nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN], | |
9213 | rem) { | |
922bd80f JB |
9214 | u8 *mask_pat; |
9215 | ||
50ac6607 AK |
9216 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9217 | nla_len(pat), NULL); | |
ff1b6e69 | 9218 | err = -EINVAL; |
50ac6607 AK |
9219 | if (!pat_tb[NL80211_PKTPAT_MASK] || |
9220 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
ff1b6e69 | 9221 | goto error; |
50ac6607 | 9222 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); |
ff1b6e69 | 9223 | mask_len = DIV_ROUND_UP(pat_len, 8); |
50ac6607 | 9224 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) |
ff1b6e69 JB |
9225 | goto error; |
9226 | if (pat_len > wowlan->pattern_max_len || | |
9227 | pat_len < wowlan->pattern_min_len) | |
9228 | goto error; | |
9229 | ||
50ac6607 | 9230 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) |
bb92d199 AK |
9231 | pkt_offset = 0; |
9232 | else | |
9233 | pkt_offset = nla_get_u32( | |
50ac6607 | 9234 | pat_tb[NL80211_PKTPAT_OFFSET]); |
bb92d199 AK |
9235 | if (pkt_offset > wowlan->max_pkt_offset) |
9236 | goto error; | |
9237 | new_triggers.patterns[i].pkt_offset = pkt_offset; | |
9238 | ||
922bd80f JB |
9239 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9240 | if (!mask_pat) { | |
ff1b6e69 JB |
9241 | err = -ENOMEM; |
9242 | goto error; | |
9243 | } | |
922bd80f JB |
9244 | new_triggers.patterns[i].mask = mask_pat; |
9245 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
ff1b6e69 | 9246 | mask_len); |
922bd80f JB |
9247 | mask_pat += mask_len; |
9248 | new_triggers.patterns[i].pattern = mask_pat; | |
ff1b6e69 | 9249 | new_triggers.patterns[i].pattern_len = pat_len; |
922bd80f | 9250 | memcpy(mask_pat, |
50ac6607 | 9251 | nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
ff1b6e69 JB |
9252 | pat_len); |
9253 | i++; | |
9254 | } | |
9255 | } | |
9256 | ||
2a0e047e | 9257 | if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) { |
98fc4386 | 9258 | regular = true; |
2a0e047e JB |
9259 | err = nl80211_parse_wowlan_tcp( |
9260 | rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION], | |
9261 | &new_triggers); | |
9262 | if (err) | |
9263 | goto error; | |
9264 | } | |
9265 | ||
8cd4d456 | 9266 | if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) { |
98fc4386 | 9267 | regular = true; |
8cd4d456 LC |
9268 | err = nl80211_parse_wowlan_nd( |
9269 | rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT], | |
9270 | &new_triggers); | |
9271 | if (err) | |
9272 | goto error; | |
9273 | } | |
9274 | ||
98fc4386 JB |
9275 | /* The 'any' trigger means the device continues operating more or less |
9276 | * as in its normal operation mode and wakes up the host on most of the | |
9277 | * normal interrupts (like packet RX, ...) | |
9278 | * It therefore makes little sense to combine with the more constrained | |
9279 | * wakeup trigger modes. | |
9280 | */ | |
9281 | if (new_triggers.any && regular) { | |
9282 | err = -EINVAL; | |
9283 | goto error; | |
9284 | } | |
9285 | ||
ae33bd81 JB |
9286 | ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL); |
9287 | if (!ntrig) { | |
9288 | err = -ENOMEM; | |
9289 | goto error; | |
ff1b6e69 | 9290 | } |
ae33bd81 | 9291 | cfg80211_rdev_free_wowlan(rdev); |
6abb9cb9 | 9292 | rdev->wiphy.wowlan_config = ntrig; |
ff1b6e69 | 9293 | |
ae33bd81 | 9294 | set_wakeup: |
6abb9cb9 JB |
9295 | if (rdev->ops->set_wakeup && |
9296 | prev_enabled != !!rdev->wiphy.wowlan_config) | |
9297 | rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config); | |
6d52563f | 9298 | |
ff1b6e69 JB |
9299 | return 0; |
9300 | error: | |
9301 | for (i = 0; i < new_triggers.n_patterns; i++) | |
9302 | kfree(new_triggers.patterns[i].mask); | |
9303 | kfree(new_triggers.patterns); | |
2a0e047e JB |
9304 | if (new_triggers.tcp && new_triggers.tcp->sock) |
9305 | sock_release(new_triggers.tcp->sock); | |
9306 | kfree(new_triggers.tcp); | |
ff1b6e69 JB |
9307 | return err; |
9308 | } | |
dfb89c56 | 9309 | #endif |
ff1b6e69 | 9310 | |
be29b99a AK |
9311 | static int nl80211_send_coalesce_rules(struct sk_buff *msg, |
9312 | struct cfg80211_registered_device *rdev) | |
9313 | { | |
9314 | struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules; | |
9315 | int i, j, pat_len; | |
9316 | struct cfg80211_coalesce_rules *rule; | |
9317 | ||
9318 | if (!rdev->coalesce->n_rules) | |
9319 | return 0; | |
9320 | ||
9321 | nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE); | |
9322 | if (!nl_rules) | |
9323 | return -ENOBUFS; | |
9324 | ||
9325 | for (i = 0; i < rdev->coalesce->n_rules; i++) { | |
9326 | nl_rule = nla_nest_start(msg, i + 1); | |
9327 | if (!nl_rule) | |
9328 | return -ENOBUFS; | |
9329 | ||
9330 | rule = &rdev->coalesce->rules[i]; | |
9331 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY, | |
9332 | rule->delay)) | |
9333 | return -ENOBUFS; | |
9334 | ||
9335 | if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION, | |
9336 | rule->condition)) | |
9337 | return -ENOBUFS; | |
9338 | ||
9339 | nl_pats = nla_nest_start(msg, | |
9340 | NL80211_ATTR_COALESCE_RULE_PKT_PATTERN); | |
9341 | if (!nl_pats) | |
9342 | return -ENOBUFS; | |
9343 | ||
9344 | for (j = 0; j < rule->n_patterns; j++) { | |
9345 | nl_pat = nla_nest_start(msg, j + 1); | |
9346 | if (!nl_pat) | |
9347 | return -ENOBUFS; | |
9348 | pat_len = rule->patterns[j].pattern_len; | |
9349 | if (nla_put(msg, NL80211_PKTPAT_MASK, | |
9350 | DIV_ROUND_UP(pat_len, 8), | |
9351 | rule->patterns[j].mask) || | |
9352 | nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len, | |
9353 | rule->patterns[j].pattern) || | |
9354 | nla_put_u32(msg, NL80211_PKTPAT_OFFSET, | |
9355 | rule->patterns[j].pkt_offset)) | |
9356 | return -ENOBUFS; | |
9357 | nla_nest_end(msg, nl_pat); | |
9358 | } | |
9359 | nla_nest_end(msg, nl_pats); | |
9360 | nla_nest_end(msg, nl_rule); | |
9361 | } | |
9362 | nla_nest_end(msg, nl_rules); | |
9363 | ||
9364 | return 0; | |
9365 | } | |
9366 | ||
9367 | static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9368 | { | |
9369 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9370 | struct sk_buff *msg; | |
9371 | void *hdr; | |
9372 | ||
9373 | if (!rdev->wiphy.coalesce) | |
9374 | return -EOPNOTSUPP; | |
9375 | ||
9376 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9377 | if (!msg) | |
9378 | return -ENOMEM; | |
9379 | ||
9380 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9381 | NL80211_CMD_GET_COALESCE); | |
9382 | if (!hdr) | |
9383 | goto nla_put_failure; | |
9384 | ||
9385 | if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev)) | |
9386 | goto nla_put_failure; | |
9387 | ||
9388 | genlmsg_end(msg, hdr); | |
9389 | return genlmsg_reply(msg, info); | |
9390 | ||
9391 | nla_put_failure: | |
9392 | nlmsg_free(msg); | |
9393 | return -ENOBUFS; | |
9394 | } | |
9395 | ||
9396 | void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev) | |
9397 | { | |
9398 | struct cfg80211_coalesce *coalesce = rdev->coalesce; | |
9399 | int i, j; | |
9400 | struct cfg80211_coalesce_rules *rule; | |
9401 | ||
9402 | if (!coalesce) | |
9403 | return; | |
9404 | ||
9405 | for (i = 0; i < coalesce->n_rules; i++) { | |
9406 | rule = &coalesce->rules[i]; | |
9407 | for (j = 0; j < rule->n_patterns; j++) | |
9408 | kfree(rule->patterns[j].mask); | |
9409 | kfree(rule->patterns); | |
9410 | } | |
9411 | kfree(coalesce->rules); | |
9412 | kfree(coalesce); | |
9413 | rdev->coalesce = NULL; | |
9414 | } | |
9415 | ||
9416 | static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev, | |
9417 | struct nlattr *rule, | |
9418 | struct cfg80211_coalesce_rules *new_rule) | |
9419 | { | |
9420 | int err, i; | |
9421 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9422 | struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat; | |
9423 | int rem, pat_len, mask_len, pkt_offset, n_patterns = 0; | |
9424 | struct nlattr *pat_tb[NUM_NL80211_PKTPAT]; | |
9425 | ||
9426 | err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule), | |
9427 | nla_len(rule), nl80211_coalesce_policy); | |
9428 | if (err) | |
9429 | return err; | |
9430 | ||
9431 | if (tb[NL80211_ATTR_COALESCE_RULE_DELAY]) | |
9432 | new_rule->delay = | |
9433 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]); | |
9434 | if (new_rule->delay > coalesce->max_delay) | |
9435 | return -EINVAL; | |
9436 | ||
9437 | if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION]) | |
9438 | new_rule->condition = | |
9439 | nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]); | |
9440 | if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH && | |
9441 | new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH) | |
9442 | return -EINVAL; | |
9443 | ||
9444 | if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN]) | |
9445 | return -EINVAL; | |
9446 | ||
9447 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9448 | rem) | |
9449 | n_patterns++; | |
9450 | if (n_patterns > coalesce->n_patterns) | |
9451 | return -EINVAL; | |
9452 | ||
9453 | new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]), | |
9454 | GFP_KERNEL); | |
9455 | if (!new_rule->patterns) | |
9456 | return -ENOMEM; | |
9457 | ||
9458 | new_rule->n_patterns = n_patterns; | |
9459 | i = 0; | |
9460 | ||
9461 | nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN], | |
9462 | rem) { | |
922bd80f JB |
9463 | u8 *mask_pat; |
9464 | ||
be29b99a AK |
9465 | nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat), |
9466 | nla_len(pat), NULL); | |
9467 | if (!pat_tb[NL80211_PKTPAT_MASK] || | |
9468 | !pat_tb[NL80211_PKTPAT_PATTERN]) | |
9469 | return -EINVAL; | |
9470 | pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]); | |
9471 | mask_len = DIV_ROUND_UP(pat_len, 8); | |
9472 | if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len) | |
9473 | return -EINVAL; | |
9474 | if (pat_len > coalesce->pattern_max_len || | |
9475 | pat_len < coalesce->pattern_min_len) | |
9476 | return -EINVAL; | |
9477 | ||
9478 | if (!pat_tb[NL80211_PKTPAT_OFFSET]) | |
9479 | pkt_offset = 0; | |
9480 | else | |
9481 | pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]); | |
9482 | if (pkt_offset > coalesce->max_pkt_offset) | |
9483 | return -EINVAL; | |
9484 | new_rule->patterns[i].pkt_offset = pkt_offset; | |
9485 | ||
922bd80f JB |
9486 | mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL); |
9487 | if (!mask_pat) | |
be29b99a | 9488 | return -ENOMEM; |
922bd80f JB |
9489 | |
9490 | new_rule->patterns[i].mask = mask_pat; | |
9491 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]), | |
9492 | mask_len); | |
9493 | ||
9494 | mask_pat += mask_len; | |
9495 | new_rule->patterns[i].pattern = mask_pat; | |
be29b99a | 9496 | new_rule->patterns[i].pattern_len = pat_len; |
922bd80f JB |
9497 | memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]), |
9498 | pat_len); | |
be29b99a AK |
9499 | i++; |
9500 | } | |
9501 | ||
9502 | return 0; | |
9503 | } | |
9504 | ||
9505 | static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info) | |
9506 | { | |
9507 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9508 | const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce; | |
9509 | struct cfg80211_coalesce new_coalesce = {}; | |
9510 | struct cfg80211_coalesce *n_coalesce; | |
9511 | int err, rem_rule, n_rules = 0, i, j; | |
9512 | struct nlattr *rule; | |
9513 | struct cfg80211_coalesce_rules *tmp_rule; | |
9514 | ||
9515 | if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce) | |
9516 | return -EOPNOTSUPP; | |
9517 | ||
9518 | if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) { | |
9519 | cfg80211_rdev_free_coalesce(rdev); | |
9520 | rdev->ops->set_coalesce(&rdev->wiphy, NULL); | |
9521 | return 0; | |
9522 | } | |
9523 | ||
9524 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9525 | rem_rule) | |
9526 | n_rules++; | |
9527 | if (n_rules > coalesce->n_rules) | |
9528 | return -EINVAL; | |
9529 | ||
9530 | new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]), | |
9531 | GFP_KERNEL); | |
9532 | if (!new_coalesce.rules) | |
9533 | return -ENOMEM; | |
9534 | ||
9535 | new_coalesce.n_rules = n_rules; | |
9536 | i = 0; | |
9537 | ||
9538 | nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE], | |
9539 | rem_rule) { | |
9540 | err = nl80211_parse_coalesce_rule(rdev, rule, | |
9541 | &new_coalesce.rules[i]); | |
9542 | if (err) | |
9543 | goto error; | |
9544 | ||
9545 | i++; | |
9546 | } | |
9547 | ||
9548 | err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce); | |
9549 | if (err) | |
9550 | goto error; | |
9551 | ||
9552 | n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL); | |
9553 | if (!n_coalesce) { | |
9554 | err = -ENOMEM; | |
9555 | goto error; | |
9556 | } | |
9557 | cfg80211_rdev_free_coalesce(rdev); | |
9558 | rdev->coalesce = n_coalesce; | |
9559 | ||
9560 | return 0; | |
9561 | error: | |
9562 | for (i = 0; i < new_coalesce.n_rules; i++) { | |
9563 | tmp_rule = &new_coalesce.rules[i]; | |
9564 | for (j = 0; j < tmp_rule->n_patterns; j++) | |
9565 | kfree(tmp_rule->patterns[j].mask); | |
9566 | kfree(tmp_rule->patterns); | |
9567 | } | |
9568 | kfree(new_coalesce.rules); | |
9569 | ||
9570 | return err; | |
9571 | } | |
9572 | ||
e5497d76 JB |
9573 | static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info) |
9574 | { | |
9575 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9576 | struct net_device *dev = info->user_ptr[1]; | |
9577 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9578 | struct nlattr *tb[NUM_NL80211_REKEY_DATA]; | |
9579 | struct cfg80211_gtk_rekey_data rekey_data; | |
9580 | int err; | |
9581 | ||
9582 | if (!info->attrs[NL80211_ATTR_REKEY_DATA]) | |
9583 | return -EINVAL; | |
9584 | ||
9585 | err = nla_parse(tb, MAX_NL80211_REKEY_DATA, | |
9586 | nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9587 | nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]), | |
9588 | nl80211_rekey_policy); | |
9589 | if (err) | |
9590 | return err; | |
9591 | ||
9592 | if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN) | |
9593 | return -ERANGE; | |
9594 | if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN) | |
9595 | return -ERANGE; | |
9596 | if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN) | |
9597 | return -ERANGE; | |
9598 | ||
78f686ca JB |
9599 | rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]); |
9600 | rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]); | |
9601 | rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]); | |
e5497d76 JB |
9602 | |
9603 | wdev_lock(wdev); | |
9604 | if (!wdev->current_bss) { | |
9605 | err = -ENOTCONN; | |
9606 | goto out; | |
9607 | } | |
9608 | ||
9609 | if (!rdev->ops->set_rekey_data) { | |
9610 | err = -EOPNOTSUPP; | |
9611 | goto out; | |
9612 | } | |
9613 | ||
e35e4d28 | 9614 | err = rdev_set_rekey_data(rdev, dev, &rekey_data); |
e5497d76 JB |
9615 | out: |
9616 | wdev_unlock(wdev); | |
9617 | return err; | |
9618 | } | |
9619 | ||
28946da7 JB |
9620 | static int nl80211_register_unexpected_frame(struct sk_buff *skb, |
9621 | struct genl_info *info) | |
9622 | { | |
9623 | struct net_device *dev = info->user_ptr[1]; | |
9624 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9625 | ||
9626 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9627 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9628 | return -EINVAL; | |
9629 | ||
15e47304 | 9630 | if (wdev->ap_unexpected_nlportid) |
28946da7 JB |
9631 | return -EBUSY; |
9632 | ||
15e47304 | 9633 | wdev->ap_unexpected_nlportid = info->snd_portid; |
28946da7 JB |
9634 | return 0; |
9635 | } | |
9636 | ||
7f6cf311 JB |
9637 | static int nl80211_probe_client(struct sk_buff *skb, |
9638 | struct genl_info *info) | |
9639 | { | |
9640 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9641 | struct net_device *dev = info->user_ptr[1]; | |
9642 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
9643 | struct sk_buff *msg; | |
9644 | void *hdr; | |
9645 | const u8 *addr; | |
9646 | u64 cookie; | |
9647 | int err; | |
9648 | ||
9649 | if (wdev->iftype != NL80211_IFTYPE_AP && | |
9650 | wdev->iftype != NL80211_IFTYPE_P2P_GO) | |
9651 | return -EOPNOTSUPP; | |
9652 | ||
9653 | if (!info->attrs[NL80211_ATTR_MAC]) | |
9654 | return -EINVAL; | |
9655 | ||
9656 | if (!rdev->ops->probe_client) | |
9657 | return -EOPNOTSUPP; | |
9658 | ||
9659 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9660 | if (!msg) | |
9661 | return -ENOMEM; | |
9662 | ||
15e47304 | 9663 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, |
7f6cf311 | 9664 | NL80211_CMD_PROBE_CLIENT); |
cb35fba3 DC |
9665 | if (!hdr) { |
9666 | err = -ENOBUFS; | |
7f6cf311 JB |
9667 | goto free_msg; |
9668 | } | |
9669 | ||
9670 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
9671 | ||
e35e4d28 | 9672 | err = rdev_probe_client(rdev, dev, addr, &cookie); |
7f6cf311 JB |
9673 | if (err) |
9674 | goto free_msg; | |
9675 | ||
9360ffd1 DM |
9676 | if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
9677 | goto nla_put_failure; | |
7f6cf311 JB |
9678 | |
9679 | genlmsg_end(msg, hdr); | |
9680 | ||
9681 | return genlmsg_reply(msg, info); | |
9682 | ||
9683 | nla_put_failure: | |
9684 | err = -ENOBUFS; | |
9685 | free_msg: | |
9686 | nlmsg_free(msg); | |
9687 | return err; | |
9688 | } | |
9689 | ||
5e760230 JB |
9690 | static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info) |
9691 | { | |
9692 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
37c73b5f BG |
9693 | struct cfg80211_beacon_registration *reg, *nreg; |
9694 | int rv; | |
5e760230 JB |
9695 | |
9696 | if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS)) | |
9697 | return -EOPNOTSUPP; | |
9698 | ||
37c73b5f BG |
9699 | nreg = kzalloc(sizeof(*nreg), GFP_KERNEL); |
9700 | if (!nreg) | |
9701 | return -ENOMEM; | |
9702 | ||
9703 | /* First, check if already registered. */ | |
9704 | spin_lock_bh(&rdev->beacon_registrations_lock); | |
9705 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
9706 | if (reg->nlportid == info->snd_portid) { | |
9707 | rv = -EALREADY; | |
9708 | goto out_err; | |
9709 | } | |
9710 | } | |
9711 | /* Add it to the list */ | |
9712 | nreg->nlportid = info->snd_portid; | |
9713 | list_add(&nreg->list, &rdev->beacon_registrations); | |
5e760230 | 9714 | |
37c73b5f | 9715 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
5e760230 JB |
9716 | |
9717 | return 0; | |
37c73b5f BG |
9718 | out_err: |
9719 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
9720 | kfree(nreg); | |
9721 | return rv; | |
5e760230 JB |
9722 | } |
9723 | ||
98104fde JB |
9724 | static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info) |
9725 | { | |
9726 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9727 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9728 | int err; | |
9729 | ||
9730 | if (!rdev->ops->start_p2p_device) | |
9731 | return -EOPNOTSUPP; | |
9732 | ||
9733 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9734 | return -EOPNOTSUPP; | |
9735 | ||
9736 | if (wdev->p2p_started) | |
9737 | return 0; | |
9738 | ||
b6a55015 LC |
9739 | if (rfkill_blocked(rdev->rfkill)) |
9740 | return -ERFKILL; | |
98104fde | 9741 | |
eeb126e9 | 9742 | err = rdev_start_p2p_device(rdev, wdev); |
98104fde JB |
9743 | if (err) |
9744 | return err; | |
9745 | ||
9746 | wdev->p2p_started = true; | |
98104fde | 9747 | rdev->opencount++; |
98104fde JB |
9748 | |
9749 | return 0; | |
9750 | } | |
9751 | ||
9752 | static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info) | |
9753 | { | |
9754 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9755 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9756 | ||
9757 | if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE) | |
9758 | return -EOPNOTSUPP; | |
9759 | ||
9760 | if (!rdev->ops->stop_p2p_device) | |
9761 | return -EOPNOTSUPP; | |
9762 | ||
f9f47529 | 9763 | cfg80211_stop_p2p_device(rdev, wdev); |
98104fde JB |
9764 | |
9765 | return 0; | |
9766 | } | |
9767 | ||
3713b4e3 JB |
9768 | static int nl80211_get_protocol_features(struct sk_buff *skb, |
9769 | struct genl_info *info) | |
9770 | { | |
9771 | void *hdr; | |
9772 | struct sk_buff *msg; | |
9773 | ||
9774 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
9775 | if (!msg) | |
9776 | return -ENOMEM; | |
9777 | ||
9778 | hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0, | |
9779 | NL80211_CMD_GET_PROTOCOL_FEATURES); | |
9780 | if (!hdr) | |
9781 | goto nla_put_failure; | |
9782 | ||
9783 | if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES, | |
9784 | NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP)) | |
9785 | goto nla_put_failure; | |
9786 | ||
9787 | genlmsg_end(msg, hdr); | |
9788 | return genlmsg_reply(msg, info); | |
9789 | ||
9790 | nla_put_failure: | |
9791 | kfree_skb(msg); | |
9792 | return -ENOBUFS; | |
9793 | } | |
9794 | ||
355199e0 JM |
9795 | static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info) |
9796 | { | |
9797 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9798 | struct cfg80211_update_ft_ies_params ft_params; | |
9799 | struct net_device *dev = info->user_ptr[1]; | |
9800 | ||
9801 | if (!rdev->ops->update_ft_ies) | |
9802 | return -EOPNOTSUPP; | |
9803 | ||
9804 | if (!info->attrs[NL80211_ATTR_MDID] || | |
9805 | !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE])) | |
9806 | return -EINVAL; | |
9807 | ||
9808 | memset(&ft_params, 0, sizeof(ft_params)); | |
9809 | ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]); | |
9810 | ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]); | |
9811 | ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]); | |
9812 | ||
9813 | return rdev_update_ft_ies(rdev, dev, &ft_params); | |
9814 | } | |
9815 | ||
5de17984 AS |
9816 | static int nl80211_crit_protocol_start(struct sk_buff *skb, |
9817 | struct genl_info *info) | |
9818 | { | |
9819 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9820 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9821 | enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC; | |
9822 | u16 duration; | |
9823 | int ret; | |
9824 | ||
9825 | if (!rdev->ops->crit_proto_start) | |
9826 | return -EOPNOTSUPP; | |
9827 | ||
9828 | if (WARN_ON(!rdev->ops->crit_proto_stop)) | |
9829 | return -EINVAL; | |
9830 | ||
9831 | if (rdev->crit_proto_nlportid) | |
9832 | return -EBUSY; | |
9833 | ||
9834 | /* determine protocol if provided */ | |
9835 | if (info->attrs[NL80211_ATTR_CRIT_PROT_ID]) | |
9836 | proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]); | |
9837 | ||
9838 | if (proto >= NUM_NL80211_CRIT_PROTO) | |
9839 | return -EINVAL; | |
9840 | ||
9841 | /* timeout must be provided */ | |
9842 | if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]) | |
9843 | return -EINVAL; | |
9844 | ||
9845 | duration = | |
9846 | nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]); | |
9847 | ||
9848 | if (duration > NL80211_CRIT_PROTO_MAX_DURATION) | |
9849 | return -ERANGE; | |
9850 | ||
9851 | ret = rdev_crit_proto_start(rdev, wdev, proto, duration); | |
9852 | if (!ret) | |
9853 | rdev->crit_proto_nlportid = info->snd_portid; | |
9854 | ||
9855 | return ret; | |
9856 | } | |
9857 | ||
9858 | static int nl80211_crit_protocol_stop(struct sk_buff *skb, | |
9859 | struct genl_info *info) | |
9860 | { | |
9861 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9862 | struct wireless_dev *wdev = info->user_ptr[1]; | |
9863 | ||
9864 | if (!rdev->ops->crit_proto_stop) | |
9865 | return -EOPNOTSUPP; | |
9866 | ||
9867 | if (rdev->crit_proto_nlportid) { | |
9868 | rdev->crit_proto_nlportid = 0; | |
9869 | rdev_crit_proto_stop(rdev, wdev); | |
9870 | } | |
9871 | return 0; | |
9872 | } | |
9873 | ||
ad7e718c JB |
9874 | static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info) |
9875 | { | |
9876 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9877 | struct wireless_dev *wdev = | |
9878 | __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs); | |
9879 | int i, err; | |
9880 | u32 vid, subcmd; | |
9881 | ||
9882 | if (!rdev->wiphy.vendor_commands) | |
9883 | return -EOPNOTSUPP; | |
9884 | ||
9885 | if (IS_ERR(wdev)) { | |
9886 | err = PTR_ERR(wdev); | |
9887 | if (err != -EINVAL) | |
9888 | return err; | |
9889 | wdev = NULL; | |
9890 | } else if (wdev->wiphy != &rdev->wiphy) { | |
9891 | return -EINVAL; | |
9892 | } | |
9893 | ||
9894 | if (!info->attrs[NL80211_ATTR_VENDOR_ID] || | |
9895 | !info->attrs[NL80211_ATTR_VENDOR_SUBCMD]) | |
9896 | return -EINVAL; | |
9897 | ||
9898 | vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]); | |
9899 | subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]); | |
9900 | for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) { | |
9901 | const struct wiphy_vendor_command *vcmd; | |
9902 | void *data = NULL; | |
9903 | int len = 0; | |
9904 | ||
9905 | vcmd = &rdev->wiphy.vendor_commands[i]; | |
9906 | ||
9907 | if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd) | |
9908 | continue; | |
9909 | ||
9910 | if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV | | |
9911 | WIPHY_VENDOR_CMD_NEED_NETDEV)) { | |
9912 | if (!wdev) | |
9913 | return -EINVAL; | |
9914 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV && | |
9915 | !wdev->netdev) | |
9916 | return -EINVAL; | |
9917 | ||
9918 | if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) { | |
9919 | if (wdev->netdev && | |
9920 | !netif_running(wdev->netdev)) | |
9921 | return -ENETDOWN; | |
9922 | if (!wdev->netdev && !wdev->p2p_started) | |
9923 | return -ENETDOWN; | |
9924 | } | |
9925 | } else { | |
9926 | wdev = NULL; | |
9927 | } | |
9928 | ||
9929 | if (info->attrs[NL80211_ATTR_VENDOR_DATA]) { | |
9930 | data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9931 | len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]); | |
9932 | } | |
9933 | ||
9934 | rdev->cur_cmd_info = info; | |
9935 | err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev, | |
9936 | data, len); | |
9937 | rdev->cur_cmd_info = NULL; | |
9938 | return err; | |
9939 | } | |
9940 | ||
9941 | return -EOPNOTSUPP; | |
9942 | } | |
9943 | ||
9944 | struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy, | |
9945 | enum nl80211_commands cmd, | |
9946 | enum nl80211_attrs attr, | |
9947 | int approxlen) | |
9948 | { | |
f26cbf40 | 9949 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ad7e718c JB |
9950 | |
9951 | if (WARN_ON(!rdev->cur_cmd_info)) | |
9952 | return NULL; | |
9953 | ||
6c09e791 | 9954 | return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen, |
ad7e718c JB |
9955 | rdev->cur_cmd_info->snd_portid, |
9956 | rdev->cur_cmd_info->snd_seq, | |
567ffc35 | 9957 | cmd, attr, NULL, GFP_KERNEL); |
ad7e718c JB |
9958 | } |
9959 | EXPORT_SYMBOL(__cfg80211_alloc_reply_skb); | |
9960 | ||
9961 | int cfg80211_vendor_cmd_reply(struct sk_buff *skb) | |
9962 | { | |
9963 | struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0]; | |
9964 | void *hdr = ((void **)skb->cb)[1]; | |
9965 | struct nlattr *data = ((void **)skb->cb)[2]; | |
9966 | ||
bd8c78e7 JB |
9967 | /* clear CB data for netlink core to own from now on */ |
9968 | memset(skb->cb, 0, sizeof(skb->cb)); | |
9969 | ||
ad7e718c JB |
9970 | if (WARN_ON(!rdev->cur_cmd_info)) { |
9971 | kfree_skb(skb); | |
9972 | return -EINVAL; | |
9973 | } | |
9974 | ||
9975 | nla_nest_end(skb, data); | |
9976 | genlmsg_end(skb, hdr); | |
9977 | return genlmsg_reply(skb, rdev->cur_cmd_info); | |
9978 | } | |
9979 | EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply); | |
9980 | ||
9981 | ||
fa9ffc74 KP |
9982 | static int nl80211_set_qos_map(struct sk_buff *skb, |
9983 | struct genl_info *info) | |
9984 | { | |
9985 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
9986 | struct cfg80211_qos_map *qos_map = NULL; | |
9987 | struct net_device *dev = info->user_ptr[1]; | |
9988 | u8 *pos, len, num_des, des_len, des; | |
9989 | int ret; | |
9990 | ||
9991 | if (!rdev->ops->set_qos_map) | |
9992 | return -EOPNOTSUPP; | |
9993 | ||
9994 | if (info->attrs[NL80211_ATTR_QOS_MAP]) { | |
9995 | pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9996 | len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]); | |
9997 | ||
9998 | if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN || | |
9999 | len > IEEE80211_QOS_MAP_LEN_MAX) | |
10000 | return -EINVAL; | |
10001 | ||
10002 | qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL); | |
10003 | if (!qos_map) | |
10004 | return -ENOMEM; | |
10005 | ||
10006 | num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1; | |
10007 | if (num_des) { | |
10008 | des_len = num_des * | |
10009 | sizeof(struct cfg80211_dscp_exception); | |
10010 | memcpy(qos_map->dscp_exception, pos, des_len); | |
10011 | qos_map->num_des = num_des; | |
10012 | for (des = 0; des < num_des; des++) { | |
10013 | if (qos_map->dscp_exception[des].up > 7) { | |
10014 | kfree(qos_map); | |
10015 | return -EINVAL; | |
10016 | } | |
10017 | } | |
10018 | pos += des_len; | |
10019 | } | |
10020 | memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN); | |
10021 | } | |
10022 | ||
10023 | wdev_lock(dev->ieee80211_ptr); | |
10024 | ret = nl80211_key_allowed(dev->ieee80211_ptr); | |
10025 | if (!ret) | |
10026 | ret = rdev_set_qos_map(rdev, dev, qos_map); | |
10027 | wdev_unlock(dev->ieee80211_ptr); | |
10028 | ||
10029 | kfree(qos_map); | |
10030 | return ret; | |
10031 | } | |
10032 | ||
960d01ac JB |
10033 | static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info) |
10034 | { | |
10035 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10036 | struct net_device *dev = info->user_ptr[1]; | |
10037 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10038 | const u8 *peer; | |
10039 | u8 tsid, up; | |
10040 | u16 admitted_time = 0; | |
10041 | int err; | |
10042 | ||
723e73ac | 10043 | if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)) |
960d01ac JB |
10044 | return -EOPNOTSUPP; |
10045 | ||
10046 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] || | |
10047 | !info->attrs[NL80211_ATTR_USER_PRIO]) | |
10048 | return -EINVAL; | |
10049 | ||
10050 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10051 | if (tsid >= IEEE80211_NUM_TIDS) | |
10052 | return -EINVAL; | |
10053 | ||
10054 | up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]); | |
10055 | if (up >= IEEE80211_NUM_UPS) | |
10056 | return -EINVAL; | |
10057 | ||
10058 | /* WMM uses TIDs 0-7 even for TSPEC */ | |
723e73ac | 10059 | if (tsid >= IEEE80211_FIRST_TSPEC_TSID) { |
960d01ac | 10060 | /* TODO: handle 802.11 TSPEC/admission control |
723e73ac JB |
10061 | * need more attributes for that (e.g. BA session requirement); |
10062 | * change the WMM adminssion test above to allow both then | |
960d01ac JB |
10063 | */ |
10064 | return -EINVAL; | |
10065 | } | |
10066 | ||
10067 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10068 | ||
10069 | if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) { | |
10070 | admitted_time = | |
10071 | nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]); | |
10072 | if (!admitted_time) | |
10073 | return -EINVAL; | |
10074 | } | |
10075 | ||
10076 | wdev_lock(wdev); | |
10077 | switch (wdev->iftype) { | |
10078 | case NL80211_IFTYPE_STATION: | |
10079 | case NL80211_IFTYPE_P2P_CLIENT: | |
10080 | if (wdev->current_bss) | |
10081 | break; | |
10082 | err = -ENOTCONN; | |
10083 | goto out; | |
10084 | default: | |
10085 | err = -EOPNOTSUPP; | |
10086 | goto out; | |
10087 | } | |
10088 | ||
10089 | err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time); | |
10090 | ||
10091 | out: | |
10092 | wdev_unlock(wdev); | |
10093 | return err; | |
10094 | } | |
10095 | ||
10096 | static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info) | |
10097 | { | |
10098 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10099 | struct net_device *dev = info->user_ptr[1]; | |
10100 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10101 | const u8 *peer; | |
10102 | u8 tsid; | |
10103 | int err; | |
10104 | ||
10105 | if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC]) | |
10106 | return -EINVAL; | |
10107 | ||
10108 | tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]); | |
10109 | peer = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10110 | ||
10111 | wdev_lock(wdev); | |
10112 | err = rdev_del_tx_ts(rdev, dev, tsid, peer); | |
10113 | wdev_unlock(wdev); | |
10114 | ||
10115 | return err; | |
10116 | } | |
10117 | ||
1057d35e AN |
10118 | static int nl80211_tdls_channel_switch(struct sk_buff *skb, |
10119 | struct genl_info *info) | |
10120 | { | |
10121 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10122 | struct net_device *dev = info->user_ptr[1]; | |
10123 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10124 | struct cfg80211_chan_def chandef = {}; | |
10125 | const u8 *addr; | |
10126 | u8 oper_class; | |
10127 | int err; | |
10128 | ||
10129 | if (!rdev->ops->tdls_channel_switch || | |
10130 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10131 | return -EOPNOTSUPP; | |
10132 | ||
10133 | switch (dev->ieee80211_ptr->iftype) { | |
10134 | case NL80211_IFTYPE_STATION: | |
10135 | case NL80211_IFTYPE_P2P_CLIENT: | |
10136 | break; | |
10137 | default: | |
10138 | return -EOPNOTSUPP; | |
10139 | } | |
10140 | ||
10141 | if (!info->attrs[NL80211_ATTR_MAC] || | |
10142 | !info->attrs[NL80211_ATTR_OPER_CLASS]) | |
10143 | return -EINVAL; | |
10144 | ||
10145 | err = nl80211_parse_chandef(rdev, info, &chandef); | |
10146 | if (err) | |
10147 | return err; | |
10148 | ||
10149 | /* | |
10150 | * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012 | |
10151 | * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the | |
10152 | * specification is not defined for them. | |
10153 | */ | |
10154 | if (chandef.chan->band == IEEE80211_BAND_2GHZ && | |
10155 | chandef.width != NL80211_CHAN_WIDTH_20_NOHT && | |
10156 | chandef.width != NL80211_CHAN_WIDTH_20) | |
10157 | return -EINVAL; | |
10158 | ||
10159 | /* we will be active on the TDLS link */ | |
10160 | if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype)) | |
10161 | return -EINVAL; | |
10162 | ||
10163 | /* don't allow switching to DFS channels */ | |
10164 | if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype)) | |
10165 | return -EINVAL; | |
10166 | ||
10167 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10168 | oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]); | |
10169 | ||
10170 | wdev_lock(wdev); | |
10171 | err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef); | |
10172 | wdev_unlock(wdev); | |
10173 | ||
10174 | return err; | |
10175 | } | |
10176 | ||
10177 | static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb, | |
10178 | struct genl_info *info) | |
10179 | { | |
10180 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | |
10181 | struct net_device *dev = info->user_ptr[1]; | |
10182 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
10183 | const u8 *addr; | |
10184 | ||
10185 | if (!rdev->ops->tdls_channel_switch || | |
10186 | !rdev->ops->tdls_cancel_channel_switch || | |
10187 | !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH)) | |
10188 | return -EOPNOTSUPP; | |
10189 | ||
10190 | switch (dev->ieee80211_ptr->iftype) { | |
10191 | case NL80211_IFTYPE_STATION: | |
10192 | case NL80211_IFTYPE_P2P_CLIENT: | |
10193 | break; | |
10194 | default: | |
10195 | return -EOPNOTSUPP; | |
10196 | } | |
10197 | ||
10198 | if (!info->attrs[NL80211_ATTR_MAC]) | |
10199 | return -EINVAL; | |
10200 | ||
10201 | addr = nla_data(info->attrs[NL80211_ATTR_MAC]); | |
10202 | ||
10203 | wdev_lock(wdev); | |
10204 | rdev_tdls_cancel_channel_switch(rdev, dev, addr); | |
10205 | wdev_unlock(wdev); | |
10206 | ||
10207 | return 0; | |
10208 | } | |
10209 | ||
4c476991 JB |
10210 | #define NL80211_FLAG_NEED_WIPHY 0x01 |
10211 | #define NL80211_FLAG_NEED_NETDEV 0x02 | |
10212 | #define NL80211_FLAG_NEED_RTNL 0x04 | |
41265714 JB |
10213 | #define NL80211_FLAG_CHECK_NETDEV_UP 0x08 |
10214 | #define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\ | |
10215 | NL80211_FLAG_CHECK_NETDEV_UP) | |
1bf614ef | 10216 | #define NL80211_FLAG_NEED_WDEV 0x10 |
98104fde | 10217 | /* If a netdev is associated, it must be UP, P2P must be started */ |
1bf614ef JB |
10218 | #define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\ |
10219 | NL80211_FLAG_CHECK_NETDEV_UP) | |
5393b917 | 10220 | #define NL80211_FLAG_CLEAR_SKB 0x20 |
4c476991 | 10221 | |
f84f771d | 10222 | static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10223 | struct genl_info *info) |
10224 | { | |
10225 | struct cfg80211_registered_device *rdev; | |
89a54e48 | 10226 | struct wireless_dev *wdev; |
4c476991 | 10227 | struct net_device *dev; |
4c476991 JB |
10228 | bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL; |
10229 | ||
10230 | if (rtnl) | |
10231 | rtnl_lock(); | |
10232 | ||
10233 | if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) { | |
4f7eff10 | 10234 | rdev = cfg80211_get_dev_from_info(genl_info_net(info), info); |
4c476991 JB |
10235 | if (IS_ERR(rdev)) { |
10236 | if (rtnl) | |
10237 | rtnl_unlock(); | |
10238 | return PTR_ERR(rdev); | |
10239 | } | |
10240 | info->user_ptr[0] = rdev; | |
1bf614ef JB |
10241 | } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV || |
10242 | ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
5fe231e8 JB |
10243 | ASSERT_RTNL(); |
10244 | ||
89a54e48 JB |
10245 | wdev = __cfg80211_wdev_from_attrs(genl_info_net(info), |
10246 | info->attrs); | |
10247 | if (IS_ERR(wdev)) { | |
4c476991 JB |
10248 | if (rtnl) |
10249 | rtnl_unlock(); | |
89a54e48 | 10250 | return PTR_ERR(wdev); |
4c476991 | 10251 | } |
89a54e48 | 10252 | |
89a54e48 | 10253 | dev = wdev->netdev; |
f26cbf40 | 10254 | rdev = wiphy_to_rdev(wdev->wiphy); |
89a54e48 | 10255 | |
1bf614ef JB |
10256 | if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) { |
10257 | if (!dev) { | |
1bf614ef JB |
10258 | if (rtnl) |
10259 | rtnl_unlock(); | |
10260 | return -EINVAL; | |
10261 | } | |
10262 | ||
10263 | info->user_ptr[1] = dev; | |
10264 | } else { | |
10265 | info->user_ptr[1] = wdev; | |
41265714 | 10266 | } |
1bf614ef JB |
10267 | |
10268 | if (dev) { | |
10269 | if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP && | |
10270 | !netif_running(dev)) { | |
1bf614ef JB |
10271 | if (rtnl) |
10272 | rtnl_unlock(); | |
10273 | return -ENETDOWN; | |
10274 | } | |
10275 | ||
10276 | dev_hold(dev); | |
98104fde JB |
10277 | } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) { |
10278 | if (!wdev->p2p_started) { | |
98104fde JB |
10279 | if (rtnl) |
10280 | rtnl_unlock(); | |
10281 | return -ENETDOWN; | |
10282 | } | |
41265714 | 10283 | } |
89a54e48 | 10284 | |
4c476991 | 10285 | info->user_ptr[0] = rdev; |
4c476991 JB |
10286 | } |
10287 | ||
10288 | return 0; | |
10289 | } | |
10290 | ||
f84f771d | 10291 | static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb, |
4c476991 JB |
10292 | struct genl_info *info) |
10293 | { | |
1bf614ef JB |
10294 | if (info->user_ptr[1]) { |
10295 | if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) { | |
10296 | struct wireless_dev *wdev = info->user_ptr[1]; | |
10297 | ||
10298 | if (wdev->netdev) | |
10299 | dev_put(wdev->netdev); | |
10300 | } else { | |
10301 | dev_put(info->user_ptr[1]); | |
10302 | } | |
10303 | } | |
5393b917 | 10304 | |
4c476991 JB |
10305 | if (ops->internal_flags & NL80211_FLAG_NEED_RTNL) |
10306 | rtnl_unlock(); | |
5393b917 JB |
10307 | |
10308 | /* If needed, clear the netlink message payload from the SKB | |
10309 | * as it might contain key data that shouldn't stick around on | |
10310 | * the heap after the SKB is freed. The netlink message header | |
10311 | * is still needed for further processing, so leave it intact. | |
10312 | */ | |
10313 | if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) { | |
10314 | struct nlmsghdr *nlh = nlmsg_hdr(skb); | |
10315 | ||
10316 | memset(nlmsg_data(nlh), 0, nlmsg_len(nlh)); | |
10317 | } | |
4c476991 JB |
10318 | } |
10319 | ||
4534de83 | 10320 | static const struct genl_ops nl80211_ops[] = { |
55682965 JB |
10321 | { |
10322 | .cmd = NL80211_CMD_GET_WIPHY, | |
10323 | .doit = nl80211_get_wiphy, | |
10324 | .dumpit = nl80211_dump_wiphy, | |
86e8cf98 | 10325 | .done = nl80211_dump_wiphy_done, |
55682965 JB |
10326 | .policy = nl80211_policy, |
10327 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10328 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10329 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10330 | }, |
10331 | { | |
10332 | .cmd = NL80211_CMD_SET_WIPHY, | |
10333 | .doit = nl80211_set_wiphy, | |
10334 | .policy = nl80211_policy, | |
10335 | .flags = GENL_ADMIN_PERM, | |
4c476991 | 10336 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
55682965 JB |
10337 | }, |
10338 | { | |
10339 | .cmd = NL80211_CMD_GET_INTERFACE, | |
10340 | .doit = nl80211_get_interface, | |
10341 | .dumpit = nl80211_dump_interface, | |
10342 | .policy = nl80211_policy, | |
10343 | /* can be retrieved by unprivileged users */ | |
5fe231e8 JB |
10344 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
10345 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10346 | }, |
10347 | { | |
10348 | .cmd = NL80211_CMD_SET_INTERFACE, | |
10349 | .doit = nl80211_set_interface, | |
10350 | .policy = nl80211_policy, | |
10351 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10352 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10353 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10354 | }, |
10355 | { | |
10356 | .cmd = NL80211_CMD_NEW_INTERFACE, | |
10357 | .doit = nl80211_new_interface, | |
10358 | .policy = nl80211_policy, | |
10359 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10360 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10361 | NL80211_FLAG_NEED_RTNL, | |
55682965 JB |
10362 | }, |
10363 | { | |
10364 | .cmd = NL80211_CMD_DEL_INTERFACE, | |
10365 | .doit = nl80211_del_interface, | |
10366 | .policy = nl80211_policy, | |
41ade00f | 10367 | .flags = GENL_ADMIN_PERM, |
84efbb84 | 10368 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10369 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10370 | }, |
10371 | { | |
10372 | .cmd = NL80211_CMD_GET_KEY, | |
10373 | .doit = nl80211_get_key, | |
10374 | .policy = nl80211_policy, | |
10375 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10376 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10377 | NL80211_FLAG_NEED_RTNL, |
41ade00f JB |
10378 | }, |
10379 | { | |
10380 | .cmd = NL80211_CMD_SET_KEY, | |
10381 | .doit = nl80211_set_key, | |
10382 | .policy = nl80211_policy, | |
10383 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10384 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10385 | NL80211_FLAG_NEED_RTNL | |
10386 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10387 | }, |
10388 | { | |
10389 | .cmd = NL80211_CMD_NEW_KEY, | |
10390 | .doit = nl80211_new_key, | |
10391 | .policy = nl80211_policy, | |
10392 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10393 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10394 | NL80211_FLAG_NEED_RTNL | |
10395 | NL80211_FLAG_CLEAR_SKB, | |
41ade00f JB |
10396 | }, |
10397 | { | |
10398 | .cmd = NL80211_CMD_DEL_KEY, | |
10399 | .doit = nl80211_del_key, | |
10400 | .policy = nl80211_policy, | |
55682965 | 10401 | .flags = GENL_ADMIN_PERM, |
41265714 | 10402 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10403 | NL80211_FLAG_NEED_RTNL, |
55682965 | 10404 | }, |
ed1b6cc7 JB |
10405 | { |
10406 | .cmd = NL80211_CMD_SET_BEACON, | |
10407 | .policy = nl80211_policy, | |
10408 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10409 | .doit = nl80211_set_beacon, |
2b5f8b0b | 10410 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10411 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10412 | }, |
10413 | { | |
8860020e | 10414 | .cmd = NL80211_CMD_START_AP, |
ed1b6cc7 JB |
10415 | .policy = nl80211_policy, |
10416 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10417 | .doit = nl80211_start_ap, |
2b5f8b0b | 10418 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10419 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 JB |
10420 | }, |
10421 | { | |
8860020e | 10422 | .cmd = NL80211_CMD_STOP_AP, |
ed1b6cc7 JB |
10423 | .policy = nl80211_policy, |
10424 | .flags = GENL_ADMIN_PERM, | |
8860020e | 10425 | .doit = nl80211_stop_ap, |
2b5f8b0b | 10426 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10427 | NL80211_FLAG_NEED_RTNL, |
ed1b6cc7 | 10428 | }, |
5727ef1b JB |
10429 | { |
10430 | .cmd = NL80211_CMD_GET_STATION, | |
10431 | .doit = nl80211_get_station, | |
2ec600d6 | 10432 | .dumpit = nl80211_dump_station, |
5727ef1b | 10433 | .policy = nl80211_policy, |
4c476991 JB |
10434 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10435 | NL80211_FLAG_NEED_RTNL, | |
5727ef1b JB |
10436 | }, |
10437 | { | |
10438 | .cmd = NL80211_CMD_SET_STATION, | |
10439 | .doit = nl80211_set_station, | |
10440 | .policy = nl80211_policy, | |
10441 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10442 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10443 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10444 | }, |
10445 | { | |
10446 | .cmd = NL80211_CMD_NEW_STATION, | |
10447 | .doit = nl80211_new_station, | |
10448 | .policy = nl80211_policy, | |
10449 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10450 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10451 | NL80211_FLAG_NEED_RTNL, |
5727ef1b JB |
10452 | }, |
10453 | { | |
10454 | .cmd = NL80211_CMD_DEL_STATION, | |
10455 | .doit = nl80211_del_station, | |
10456 | .policy = nl80211_policy, | |
2ec600d6 | 10457 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10458 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10459 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10460 | }, |
10461 | { | |
10462 | .cmd = NL80211_CMD_GET_MPATH, | |
10463 | .doit = nl80211_get_mpath, | |
10464 | .dumpit = nl80211_dump_mpath, | |
10465 | .policy = nl80211_policy, | |
10466 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10467 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10468 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 | 10469 | }, |
66be7d2b HR |
10470 | { |
10471 | .cmd = NL80211_CMD_GET_MPP, | |
10472 | .doit = nl80211_get_mpp, | |
10473 | .dumpit = nl80211_dump_mpp, | |
10474 | .policy = nl80211_policy, | |
10475 | .flags = GENL_ADMIN_PERM, | |
10476 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10477 | NL80211_FLAG_NEED_RTNL, | |
10478 | }, | |
2ec600d6 LCC |
10479 | { |
10480 | .cmd = NL80211_CMD_SET_MPATH, | |
10481 | .doit = nl80211_set_mpath, | |
10482 | .policy = nl80211_policy, | |
10483 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10484 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10485 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10486 | }, |
10487 | { | |
10488 | .cmd = NL80211_CMD_NEW_MPATH, | |
10489 | .doit = nl80211_new_mpath, | |
10490 | .policy = nl80211_policy, | |
10491 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10492 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10493 | NL80211_FLAG_NEED_RTNL, |
2ec600d6 LCC |
10494 | }, |
10495 | { | |
10496 | .cmd = NL80211_CMD_DEL_MPATH, | |
10497 | .doit = nl80211_del_mpath, | |
10498 | .policy = nl80211_policy, | |
9f1ba906 | 10499 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10500 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10501 | NL80211_FLAG_NEED_RTNL, |
9f1ba906 JM |
10502 | }, |
10503 | { | |
10504 | .cmd = NL80211_CMD_SET_BSS, | |
10505 | .doit = nl80211_set_bss, | |
10506 | .policy = nl80211_policy, | |
b2e1b302 | 10507 | .flags = GENL_ADMIN_PERM, |
2b5f8b0b | 10508 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10509 | NL80211_FLAG_NEED_RTNL, |
b2e1b302 | 10510 | }, |
f130347c LR |
10511 | { |
10512 | .cmd = NL80211_CMD_GET_REG, | |
ad30ca2c AN |
10513 | .doit = nl80211_get_reg_do, |
10514 | .dumpit = nl80211_get_reg_dump, | |
f130347c | 10515 | .policy = nl80211_policy, |
5fe231e8 | 10516 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
f130347c LR |
10517 | /* can be retrieved by unprivileged users */ |
10518 | }, | |
b2e1b302 LR |
10519 | { |
10520 | .cmd = NL80211_CMD_SET_REG, | |
10521 | .doit = nl80211_set_reg, | |
10522 | .policy = nl80211_policy, | |
10523 | .flags = GENL_ADMIN_PERM, | |
5fe231e8 | 10524 | .internal_flags = NL80211_FLAG_NEED_RTNL, |
b2e1b302 LR |
10525 | }, |
10526 | { | |
10527 | .cmd = NL80211_CMD_REQ_SET_REG, | |
10528 | .doit = nl80211_req_set_reg, | |
10529 | .policy = nl80211_policy, | |
93da9cc1 | 10530 | .flags = GENL_ADMIN_PERM, |
10531 | }, | |
10532 | { | |
24bdd9f4 JC |
10533 | .cmd = NL80211_CMD_GET_MESH_CONFIG, |
10534 | .doit = nl80211_get_mesh_config, | |
93da9cc1 | 10535 | .policy = nl80211_policy, |
10536 | /* can be retrieved by unprivileged users */ | |
2b5f8b0b | 10537 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10538 | NL80211_FLAG_NEED_RTNL, |
93da9cc1 | 10539 | }, |
10540 | { | |
24bdd9f4 JC |
10541 | .cmd = NL80211_CMD_SET_MESH_CONFIG, |
10542 | .doit = nl80211_update_mesh_config, | |
93da9cc1 | 10543 | .policy = nl80211_policy, |
9aed3cc1 | 10544 | .flags = GENL_ADMIN_PERM, |
29cbe68c | 10545 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10546 | NL80211_FLAG_NEED_RTNL, |
9aed3cc1 | 10547 | }, |
2a519311 JB |
10548 | { |
10549 | .cmd = NL80211_CMD_TRIGGER_SCAN, | |
10550 | .doit = nl80211_trigger_scan, | |
10551 | .policy = nl80211_policy, | |
10552 | .flags = GENL_ADMIN_PERM, | |
fd014284 | 10553 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10554 | NL80211_FLAG_NEED_RTNL, |
2a519311 JB |
10555 | }, |
10556 | { | |
10557 | .cmd = NL80211_CMD_GET_SCAN, | |
10558 | .policy = nl80211_policy, | |
10559 | .dumpit = nl80211_dump_scan, | |
10560 | }, | |
807f8a8c LC |
10561 | { |
10562 | .cmd = NL80211_CMD_START_SCHED_SCAN, | |
10563 | .doit = nl80211_start_sched_scan, | |
10564 | .policy = nl80211_policy, | |
10565 | .flags = GENL_ADMIN_PERM, | |
10566 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10567 | NL80211_FLAG_NEED_RTNL, | |
10568 | }, | |
10569 | { | |
10570 | .cmd = NL80211_CMD_STOP_SCHED_SCAN, | |
10571 | .doit = nl80211_stop_sched_scan, | |
10572 | .policy = nl80211_policy, | |
10573 | .flags = GENL_ADMIN_PERM, | |
10574 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10575 | NL80211_FLAG_NEED_RTNL, | |
10576 | }, | |
636a5d36 JM |
10577 | { |
10578 | .cmd = NL80211_CMD_AUTHENTICATE, | |
10579 | .doit = nl80211_authenticate, | |
10580 | .policy = nl80211_policy, | |
10581 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10582 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
5393b917 JB |
10583 | NL80211_FLAG_NEED_RTNL | |
10584 | NL80211_FLAG_CLEAR_SKB, | |
636a5d36 JM |
10585 | }, |
10586 | { | |
10587 | .cmd = NL80211_CMD_ASSOCIATE, | |
10588 | .doit = nl80211_associate, | |
10589 | .policy = nl80211_policy, | |
10590 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10591 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10592 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10593 | }, |
10594 | { | |
10595 | .cmd = NL80211_CMD_DEAUTHENTICATE, | |
10596 | .doit = nl80211_deauthenticate, | |
10597 | .policy = nl80211_policy, | |
10598 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10599 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10600 | NL80211_FLAG_NEED_RTNL, |
636a5d36 JM |
10601 | }, |
10602 | { | |
10603 | .cmd = NL80211_CMD_DISASSOCIATE, | |
10604 | .doit = nl80211_disassociate, | |
10605 | .policy = nl80211_policy, | |
10606 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10607 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10608 | NL80211_FLAG_NEED_RTNL, |
636a5d36 | 10609 | }, |
04a773ad JB |
10610 | { |
10611 | .cmd = NL80211_CMD_JOIN_IBSS, | |
10612 | .doit = nl80211_join_ibss, | |
10613 | .policy = nl80211_policy, | |
10614 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10615 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10616 | NL80211_FLAG_NEED_RTNL, |
04a773ad JB |
10617 | }, |
10618 | { | |
10619 | .cmd = NL80211_CMD_LEAVE_IBSS, | |
10620 | .doit = nl80211_leave_ibss, | |
10621 | .policy = nl80211_policy, | |
10622 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10623 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10624 | NL80211_FLAG_NEED_RTNL, |
04a773ad | 10625 | }, |
aff89a9b JB |
10626 | #ifdef CONFIG_NL80211_TESTMODE |
10627 | { | |
10628 | .cmd = NL80211_CMD_TESTMODE, | |
10629 | .doit = nl80211_testmode_do, | |
71063f0e | 10630 | .dumpit = nl80211_testmode_dump, |
aff89a9b JB |
10631 | .policy = nl80211_policy, |
10632 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10633 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10634 | NL80211_FLAG_NEED_RTNL, | |
aff89a9b JB |
10635 | }, |
10636 | #endif | |
b23aa676 SO |
10637 | { |
10638 | .cmd = NL80211_CMD_CONNECT, | |
10639 | .doit = nl80211_connect, | |
10640 | .policy = nl80211_policy, | |
10641 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10642 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10643 | NL80211_FLAG_NEED_RTNL, |
b23aa676 SO |
10644 | }, |
10645 | { | |
10646 | .cmd = NL80211_CMD_DISCONNECT, | |
10647 | .doit = nl80211_disconnect, | |
10648 | .policy = nl80211_policy, | |
10649 | .flags = GENL_ADMIN_PERM, | |
41265714 | 10650 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10651 | NL80211_FLAG_NEED_RTNL, |
b23aa676 | 10652 | }, |
463d0183 JB |
10653 | { |
10654 | .cmd = NL80211_CMD_SET_WIPHY_NETNS, | |
10655 | .doit = nl80211_wiphy_netns, | |
10656 | .policy = nl80211_policy, | |
10657 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10658 | .internal_flags = NL80211_FLAG_NEED_WIPHY | |
10659 | NL80211_FLAG_NEED_RTNL, | |
463d0183 | 10660 | }, |
61fa713c HS |
10661 | { |
10662 | .cmd = NL80211_CMD_GET_SURVEY, | |
10663 | .policy = nl80211_policy, | |
10664 | .dumpit = nl80211_dump_survey, | |
10665 | }, | |
67fbb16b SO |
10666 | { |
10667 | .cmd = NL80211_CMD_SET_PMKSA, | |
10668 | .doit = nl80211_setdel_pmksa, | |
10669 | .policy = nl80211_policy, | |
10670 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10671 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10672 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10673 | }, |
10674 | { | |
10675 | .cmd = NL80211_CMD_DEL_PMKSA, | |
10676 | .doit = nl80211_setdel_pmksa, | |
10677 | .policy = nl80211_policy, | |
10678 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10679 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10680 | NL80211_FLAG_NEED_RTNL, |
67fbb16b SO |
10681 | }, |
10682 | { | |
10683 | .cmd = NL80211_CMD_FLUSH_PMKSA, | |
10684 | .doit = nl80211_flush_pmksa, | |
10685 | .policy = nl80211_policy, | |
10686 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10687 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
4c476991 | 10688 | NL80211_FLAG_NEED_RTNL, |
67fbb16b | 10689 | }, |
9588bbd5 JM |
10690 | { |
10691 | .cmd = NL80211_CMD_REMAIN_ON_CHANNEL, | |
10692 | .doit = nl80211_remain_on_channel, | |
10693 | .policy = nl80211_policy, | |
10694 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10695 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10696 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 JM |
10697 | }, |
10698 | { | |
10699 | .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, | |
10700 | .doit = nl80211_cancel_remain_on_channel, | |
10701 | .policy = nl80211_policy, | |
10702 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10703 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10704 | NL80211_FLAG_NEED_RTNL, |
9588bbd5 | 10705 | }, |
13ae75b1 JM |
10706 | { |
10707 | .cmd = NL80211_CMD_SET_TX_BITRATE_MASK, | |
10708 | .doit = nl80211_set_tx_bitrate_mask, | |
10709 | .policy = nl80211_policy, | |
10710 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10711 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10712 | NL80211_FLAG_NEED_RTNL, | |
13ae75b1 | 10713 | }, |
026331c4 | 10714 | { |
2e161f78 JB |
10715 | .cmd = NL80211_CMD_REGISTER_FRAME, |
10716 | .doit = nl80211_register_mgmt, | |
026331c4 JM |
10717 | .policy = nl80211_policy, |
10718 | .flags = GENL_ADMIN_PERM, | |
71bbc994 | 10719 | .internal_flags = NL80211_FLAG_NEED_WDEV | |
4c476991 | 10720 | NL80211_FLAG_NEED_RTNL, |
026331c4 JM |
10721 | }, |
10722 | { | |
2e161f78 JB |
10723 | .cmd = NL80211_CMD_FRAME, |
10724 | .doit = nl80211_tx_mgmt, | |
026331c4 | 10725 | .policy = nl80211_policy, |
f7ca38df | 10726 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10727 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
f7ca38df JB |
10728 | NL80211_FLAG_NEED_RTNL, |
10729 | }, | |
10730 | { | |
10731 | .cmd = NL80211_CMD_FRAME_WAIT_CANCEL, | |
10732 | .doit = nl80211_tx_mgmt_cancel_wait, | |
10733 | .policy = nl80211_policy, | |
026331c4 | 10734 | .flags = GENL_ADMIN_PERM, |
71bbc994 | 10735 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | |
4c476991 | 10736 | NL80211_FLAG_NEED_RTNL, |
026331c4 | 10737 | }, |
ffb9eb3d KV |
10738 | { |
10739 | .cmd = NL80211_CMD_SET_POWER_SAVE, | |
10740 | .doit = nl80211_set_power_save, | |
10741 | .policy = nl80211_policy, | |
10742 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10743 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10744 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d KV |
10745 | }, |
10746 | { | |
10747 | .cmd = NL80211_CMD_GET_POWER_SAVE, | |
10748 | .doit = nl80211_get_power_save, | |
10749 | .policy = nl80211_policy, | |
10750 | /* can be retrieved by unprivileged users */ | |
4c476991 JB |
10751 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10752 | NL80211_FLAG_NEED_RTNL, | |
ffb9eb3d | 10753 | }, |
d6dc1a38 JO |
10754 | { |
10755 | .cmd = NL80211_CMD_SET_CQM, | |
10756 | .doit = nl80211_set_cqm, | |
10757 | .policy = nl80211_policy, | |
10758 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10759 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10760 | NL80211_FLAG_NEED_RTNL, | |
d6dc1a38 | 10761 | }, |
f444de05 JB |
10762 | { |
10763 | .cmd = NL80211_CMD_SET_CHANNEL, | |
10764 | .doit = nl80211_set_channel, | |
10765 | .policy = nl80211_policy, | |
10766 | .flags = GENL_ADMIN_PERM, | |
4c476991 JB |
10767 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10768 | NL80211_FLAG_NEED_RTNL, | |
f444de05 | 10769 | }, |
e8347eba BJ |
10770 | { |
10771 | .cmd = NL80211_CMD_SET_WDS_PEER, | |
10772 | .doit = nl80211_set_wds_peer, | |
10773 | .policy = nl80211_policy, | |
10774 | .flags = GENL_ADMIN_PERM, | |
43b19952 JB |
10775 | .internal_flags = NL80211_FLAG_NEED_NETDEV | |
10776 | NL80211_FLAG_NEED_RTNL, | |
e8347eba | 10777 | }, |
29cbe68c JB |
10778 | { |
10779 | .cmd = NL80211_CMD_JOIN_MESH, | |
10780 | .doit = nl80211_join_mesh, | |
10781 | .policy = nl80211_policy, | |
10782 | .flags = GENL_ADMIN_PERM, | |
10783 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10784 | NL80211_FLAG_NEED_RTNL, | |
10785 | }, | |
10786 | { | |
10787 | .cmd = NL80211_CMD_LEAVE_MESH, | |
10788 | .doit = nl80211_leave_mesh, | |
10789 | .policy = nl80211_policy, | |
10790 | .flags = GENL_ADMIN_PERM, | |
10791 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10792 | NL80211_FLAG_NEED_RTNL, | |
10793 | }, | |
6e0bd6c3 RL |
10794 | { |
10795 | .cmd = NL80211_CMD_JOIN_OCB, | |
10796 | .doit = nl80211_join_ocb, | |
10797 | .policy = nl80211_policy, | |
10798 | .flags = GENL_ADMIN_PERM, | |
10799 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10800 | NL80211_FLAG_NEED_RTNL, | |
10801 | }, | |
10802 | { | |
10803 | .cmd = NL80211_CMD_LEAVE_OCB, | |
10804 | .doit = nl80211_leave_ocb, | |
10805 | .policy = nl80211_policy, | |
10806 | .flags = GENL_ADMIN_PERM, | |
10807 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10808 | NL80211_FLAG_NEED_RTNL, | |
10809 | }, | |
dfb89c56 | 10810 | #ifdef CONFIG_PM |
ff1b6e69 JB |
10811 | { |
10812 | .cmd = NL80211_CMD_GET_WOWLAN, | |
10813 | .doit = nl80211_get_wowlan, | |
10814 | .policy = nl80211_policy, | |
10815 | /* can be retrieved by unprivileged users */ | |
10816 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10817 | NL80211_FLAG_NEED_RTNL, | |
10818 | }, | |
10819 | { | |
10820 | .cmd = NL80211_CMD_SET_WOWLAN, | |
10821 | .doit = nl80211_set_wowlan, | |
10822 | .policy = nl80211_policy, | |
10823 | .flags = GENL_ADMIN_PERM, | |
10824 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10825 | NL80211_FLAG_NEED_RTNL, | |
10826 | }, | |
dfb89c56 | 10827 | #endif |
e5497d76 JB |
10828 | { |
10829 | .cmd = NL80211_CMD_SET_REKEY_OFFLOAD, | |
10830 | .doit = nl80211_set_rekey_data, | |
10831 | .policy = nl80211_policy, | |
10832 | .flags = GENL_ADMIN_PERM, | |
10833 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
5393b917 JB |
10834 | NL80211_FLAG_NEED_RTNL | |
10835 | NL80211_FLAG_CLEAR_SKB, | |
e5497d76 | 10836 | }, |
109086ce AN |
10837 | { |
10838 | .cmd = NL80211_CMD_TDLS_MGMT, | |
10839 | .doit = nl80211_tdls_mgmt, | |
10840 | .policy = nl80211_policy, | |
10841 | .flags = GENL_ADMIN_PERM, | |
10842 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10843 | NL80211_FLAG_NEED_RTNL, | |
10844 | }, | |
10845 | { | |
10846 | .cmd = NL80211_CMD_TDLS_OPER, | |
10847 | .doit = nl80211_tdls_oper, | |
10848 | .policy = nl80211_policy, | |
10849 | .flags = GENL_ADMIN_PERM, | |
10850 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10851 | NL80211_FLAG_NEED_RTNL, | |
10852 | }, | |
28946da7 JB |
10853 | { |
10854 | .cmd = NL80211_CMD_UNEXPECTED_FRAME, | |
10855 | .doit = nl80211_register_unexpected_frame, | |
10856 | .policy = nl80211_policy, | |
10857 | .flags = GENL_ADMIN_PERM, | |
10858 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10859 | NL80211_FLAG_NEED_RTNL, | |
10860 | }, | |
7f6cf311 JB |
10861 | { |
10862 | .cmd = NL80211_CMD_PROBE_CLIENT, | |
10863 | .doit = nl80211_probe_client, | |
10864 | .policy = nl80211_policy, | |
10865 | .flags = GENL_ADMIN_PERM, | |
2b5f8b0b | 10866 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | |
7f6cf311 JB |
10867 | NL80211_FLAG_NEED_RTNL, |
10868 | }, | |
5e760230 JB |
10869 | { |
10870 | .cmd = NL80211_CMD_REGISTER_BEACONS, | |
10871 | .doit = nl80211_register_beacons, | |
10872 | .policy = nl80211_policy, | |
10873 | .flags = GENL_ADMIN_PERM, | |
10874 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10875 | NL80211_FLAG_NEED_RTNL, | |
10876 | }, | |
1d9d9213 SW |
10877 | { |
10878 | .cmd = NL80211_CMD_SET_NOACK_MAP, | |
10879 | .doit = nl80211_set_noack_map, | |
10880 | .policy = nl80211_policy, | |
10881 | .flags = GENL_ADMIN_PERM, | |
10882 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10883 | NL80211_FLAG_NEED_RTNL, | |
10884 | }, | |
98104fde JB |
10885 | { |
10886 | .cmd = NL80211_CMD_START_P2P_DEVICE, | |
10887 | .doit = nl80211_start_p2p_device, | |
10888 | .policy = nl80211_policy, | |
10889 | .flags = GENL_ADMIN_PERM, | |
10890 | .internal_flags = NL80211_FLAG_NEED_WDEV | | |
10891 | NL80211_FLAG_NEED_RTNL, | |
10892 | }, | |
10893 | { | |
10894 | .cmd = NL80211_CMD_STOP_P2P_DEVICE, | |
10895 | .doit = nl80211_stop_p2p_device, | |
10896 | .policy = nl80211_policy, | |
10897 | .flags = GENL_ADMIN_PERM, | |
10898 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10899 | NL80211_FLAG_NEED_RTNL, | |
10900 | }, | |
f4e583c8 AQ |
10901 | { |
10902 | .cmd = NL80211_CMD_SET_MCAST_RATE, | |
10903 | .doit = nl80211_set_mcast_rate, | |
77765eaf VT |
10904 | .policy = nl80211_policy, |
10905 | .flags = GENL_ADMIN_PERM, | |
10906 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10907 | NL80211_FLAG_NEED_RTNL, | |
10908 | }, | |
10909 | { | |
10910 | .cmd = NL80211_CMD_SET_MAC_ACL, | |
10911 | .doit = nl80211_set_mac_acl, | |
f4e583c8 AQ |
10912 | .policy = nl80211_policy, |
10913 | .flags = GENL_ADMIN_PERM, | |
10914 | .internal_flags = NL80211_FLAG_NEED_NETDEV | | |
10915 | NL80211_FLAG_NEED_RTNL, | |
10916 | }, | |
04f39047 SW |
10917 | { |
10918 | .cmd = NL80211_CMD_RADAR_DETECT, | |
10919 | .doit = nl80211_start_radar_detection, | |
10920 | .policy = nl80211_policy, | |
10921 | .flags = GENL_ADMIN_PERM, | |
10922 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10923 | NL80211_FLAG_NEED_RTNL, | |
10924 | }, | |
3713b4e3 JB |
10925 | { |
10926 | .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES, | |
10927 | .doit = nl80211_get_protocol_features, | |
10928 | .policy = nl80211_policy, | |
10929 | }, | |
355199e0 JM |
10930 | { |
10931 | .cmd = NL80211_CMD_UPDATE_FT_IES, | |
10932 | .doit = nl80211_update_ft_ies, | |
10933 | .policy = nl80211_policy, | |
10934 | .flags = GENL_ADMIN_PERM, | |
10935 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10936 | NL80211_FLAG_NEED_RTNL, | |
10937 | }, | |
5de17984 AS |
10938 | { |
10939 | .cmd = NL80211_CMD_CRIT_PROTOCOL_START, | |
10940 | .doit = nl80211_crit_protocol_start, | |
10941 | .policy = nl80211_policy, | |
10942 | .flags = GENL_ADMIN_PERM, | |
10943 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10944 | NL80211_FLAG_NEED_RTNL, | |
10945 | }, | |
10946 | { | |
10947 | .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP, | |
10948 | .doit = nl80211_crit_protocol_stop, | |
10949 | .policy = nl80211_policy, | |
10950 | .flags = GENL_ADMIN_PERM, | |
10951 | .internal_flags = NL80211_FLAG_NEED_WDEV_UP | | |
10952 | NL80211_FLAG_NEED_RTNL, | |
be29b99a AK |
10953 | }, |
10954 | { | |
10955 | .cmd = NL80211_CMD_GET_COALESCE, | |
10956 | .doit = nl80211_get_coalesce, | |
10957 | .policy = nl80211_policy, | |
10958 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10959 | NL80211_FLAG_NEED_RTNL, | |
10960 | }, | |
10961 | { | |
10962 | .cmd = NL80211_CMD_SET_COALESCE, | |
10963 | .doit = nl80211_set_coalesce, | |
10964 | .policy = nl80211_policy, | |
10965 | .flags = GENL_ADMIN_PERM, | |
10966 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10967 | NL80211_FLAG_NEED_RTNL, | |
16ef1fe2 SW |
10968 | }, |
10969 | { | |
10970 | .cmd = NL80211_CMD_CHANNEL_SWITCH, | |
10971 | .doit = nl80211_channel_switch, | |
10972 | .policy = nl80211_policy, | |
10973 | .flags = GENL_ADMIN_PERM, | |
10974 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10975 | NL80211_FLAG_NEED_RTNL, | |
10976 | }, | |
ad7e718c JB |
10977 | { |
10978 | .cmd = NL80211_CMD_VENDOR, | |
10979 | .doit = nl80211_vendor_cmd, | |
10980 | .policy = nl80211_policy, | |
10981 | .flags = GENL_ADMIN_PERM, | |
10982 | .internal_flags = NL80211_FLAG_NEED_WIPHY | | |
10983 | NL80211_FLAG_NEED_RTNL, | |
10984 | }, | |
fa9ffc74 KP |
10985 | { |
10986 | .cmd = NL80211_CMD_SET_QOS_MAP, | |
10987 | .doit = nl80211_set_qos_map, | |
10988 | .policy = nl80211_policy, | |
10989 | .flags = GENL_ADMIN_PERM, | |
10990 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10991 | NL80211_FLAG_NEED_RTNL, | |
10992 | }, | |
960d01ac JB |
10993 | { |
10994 | .cmd = NL80211_CMD_ADD_TX_TS, | |
10995 | .doit = nl80211_add_tx_ts, | |
10996 | .policy = nl80211_policy, | |
10997 | .flags = GENL_ADMIN_PERM, | |
10998 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
10999 | NL80211_FLAG_NEED_RTNL, | |
11000 | }, | |
11001 | { | |
11002 | .cmd = NL80211_CMD_DEL_TX_TS, | |
11003 | .doit = nl80211_del_tx_ts, | |
11004 | .policy = nl80211_policy, | |
11005 | .flags = GENL_ADMIN_PERM, | |
11006 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11007 | NL80211_FLAG_NEED_RTNL, | |
11008 | }, | |
1057d35e AN |
11009 | { |
11010 | .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH, | |
11011 | .doit = nl80211_tdls_channel_switch, | |
11012 | .policy = nl80211_policy, | |
11013 | .flags = GENL_ADMIN_PERM, | |
11014 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11015 | NL80211_FLAG_NEED_RTNL, | |
11016 | }, | |
11017 | { | |
11018 | .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH, | |
11019 | .doit = nl80211_tdls_cancel_channel_switch, | |
11020 | .policy = nl80211_policy, | |
11021 | .flags = GENL_ADMIN_PERM, | |
11022 | .internal_flags = NL80211_FLAG_NEED_NETDEV_UP | | |
11023 | NL80211_FLAG_NEED_RTNL, | |
11024 | }, | |
55682965 | 11025 | }; |
9588bbd5 | 11026 | |
55682965 JB |
11027 | /* notification functions */ |
11028 | ||
3bb20556 JB |
11029 | void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev, |
11030 | enum nl80211_commands cmd) | |
55682965 JB |
11031 | { |
11032 | struct sk_buff *msg; | |
86e8cf98 | 11033 | struct nl80211_dump_wiphy_state state = {}; |
55682965 | 11034 | |
3bb20556 JB |
11035 | WARN_ON(cmd != NL80211_CMD_NEW_WIPHY && |
11036 | cmd != NL80211_CMD_DEL_WIPHY); | |
11037 | ||
fd2120ca | 11038 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
55682965 JB |
11039 | if (!msg) |
11040 | return; | |
11041 | ||
3bb20556 | 11042 | if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) { |
55682965 JB |
11043 | nlmsg_free(msg); |
11044 | return; | |
11045 | } | |
11046 | ||
68eb5503 | 11047 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11048 | NL80211_MCGRP_CONFIG, GFP_KERNEL); |
55682965 JB |
11049 | } |
11050 | ||
362a415d JB |
11051 | static int nl80211_add_scan_req(struct sk_buff *msg, |
11052 | struct cfg80211_registered_device *rdev) | |
11053 | { | |
11054 | struct cfg80211_scan_request *req = rdev->scan_req; | |
11055 | struct nlattr *nest; | |
11056 | int i; | |
11057 | ||
11058 | if (WARN_ON(!req)) | |
11059 | return 0; | |
11060 | ||
11061 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS); | |
11062 | if (!nest) | |
11063 | goto nla_put_failure; | |
9360ffd1 DM |
11064 | for (i = 0; i < req->n_ssids; i++) { |
11065 | if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid)) | |
11066 | goto nla_put_failure; | |
11067 | } | |
362a415d JB |
11068 | nla_nest_end(msg, nest); |
11069 | ||
11070 | nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
11071 | if (!nest) | |
11072 | goto nla_put_failure; | |
9360ffd1 DM |
11073 | for (i = 0; i < req->n_channels; i++) { |
11074 | if (nla_put_u32(msg, i, req->channels[i]->center_freq)) | |
11075 | goto nla_put_failure; | |
11076 | } | |
362a415d JB |
11077 | nla_nest_end(msg, nest); |
11078 | ||
9360ffd1 DM |
11079 | if (req->ie && |
11080 | nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie)) | |
11081 | goto nla_put_failure; | |
362a415d | 11082 | |
ae917c9f JB |
11083 | if (req->flags && |
11084 | nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags)) | |
11085 | goto nla_put_failure; | |
ed473771 | 11086 | |
362a415d JB |
11087 | return 0; |
11088 | nla_put_failure: | |
11089 | return -ENOBUFS; | |
11090 | } | |
11091 | ||
a538e2d5 JB |
11092 | static int nl80211_send_scan_msg(struct sk_buff *msg, |
11093 | struct cfg80211_registered_device *rdev, | |
fd014284 | 11094 | struct wireless_dev *wdev, |
15e47304 | 11095 | u32 portid, u32 seq, int flags, |
a538e2d5 | 11096 | u32 cmd) |
2a519311 JB |
11097 | { |
11098 | void *hdr; | |
11099 | ||
15e47304 | 11100 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
2a519311 JB |
11101 | if (!hdr) |
11102 | return -1; | |
11103 | ||
9360ffd1 | 11104 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
fd014284 JB |
11105 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11106 | wdev->netdev->ifindex)) || | |
11107 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
9360ffd1 | 11108 | goto nla_put_failure; |
2a519311 | 11109 | |
362a415d JB |
11110 | /* ignore errors and send incomplete event anyway */ |
11111 | nl80211_add_scan_req(msg, rdev); | |
2a519311 | 11112 | |
053c095a JB |
11113 | genlmsg_end(msg, hdr); |
11114 | return 0; | |
2a519311 JB |
11115 | |
11116 | nla_put_failure: | |
11117 | genlmsg_cancel(msg, hdr); | |
11118 | return -EMSGSIZE; | |
11119 | } | |
11120 | ||
807f8a8c LC |
11121 | static int |
11122 | nl80211_send_sched_scan_msg(struct sk_buff *msg, | |
11123 | struct cfg80211_registered_device *rdev, | |
11124 | struct net_device *netdev, | |
15e47304 | 11125 | u32 portid, u32 seq, int flags, u32 cmd) |
807f8a8c LC |
11126 | { |
11127 | void *hdr; | |
11128 | ||
15e47304 | 11129 | hdr = nl80211hdr_put(msg, portid, seq, flags, cmd); |
807f8a8c LC |
11130 | if (!hdr) |
11131 | return -1; | |
11132 | ||
9360ffd1 DM |
11133 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11134 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
11135 | goto nla_put_failure; | |
807f8a8c | 11136 | |
053c095a JB |
11137 | genlmsg_end(msg, hdr); |
11138 | return 0; | |
807f8a8c LC |
11139 | |
11140 | nla_put_failure: | |
11141 | genlmsg_cancel(msg, hdr); | |
11142 | return -EMSGSIZE; | |
11143 | } | |
11144 | ||
a538e2d5 | 11145 | void nl80211_send_scan_start(struct cfg80211_registered_device *rdev, |
fd014284 | 11146 | struct wireless_dev *wdev) |
a538e2d5 JB |
11147 | { |
11148 | struct sk_buff *msg; | |
11149 | ||
58050fce | 11150 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
a538e2d5 JB |
11151 | if (!msg) |
11152 | return; | |
11153 | ||
fd014284 | 11154 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
a538e2d5 JB |
11155 | NL80211_CMD_TRIGGER_SCAN) < 0) { |
11156 | nlmsg_free(msg); | |
11157 | return; | |
11158 | } | |
11159 | ||
68eb5503 | 11160 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11161 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
a538e2d5 JB |
11162 | } |
11163 | ||
f9d15d16 JB |
11164 | struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev, |
11165 | struct wireless_dev *wdev, bool aborted) | |
2a519311 JB |
11166 | { |
11167 | struct sk_buff *msg; | |
11168 | ||
fd2120ca | 11169 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
2a519311 | 11170 | if (!msg) |
f9d15d16 | 11171 | return NULL; |
2a519311 | 11172 | |
fd014284 | 11173 | if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0, |
f9d15d16 JB |
11174 | aborted ? NL80211_CMD_SCAN_ABORTED : |
11175 | NL80211_CMD_NEW_SCAN_RESULTS) < 0) { | |
2a519311 | 11176 | nlmsg_free(msg); |
f9d15d16 | 11177 | return NULL; |
2a519311 JB |
11178 | } |
11179 | ||
f9d15d16 | 11180 | return msg; |
2a519311 JB |
11181 | } |
11182 | ||
f9d15d16 JB |
11183 | void nl80211_send_scan_result(struct cfg80211_registered_device *rdev, |
11184 | struct sk_buff *msg) | |
2a519311 | 11185 | { |
2a519311 JB |
11186 | if (!msg) |
11187 | return; | |
11188 | ||
68eb5503 | 11189 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11190 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
2a519311 JB |
11191 | } |
11192 | ||
807f8a8c LC |
11193 | void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev, |
11194 | struct net_device *netdev) | |
11195 | { | |
11196 | struct sk_buff *msg; | |
11197 | ||
11198 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11199 | if (!msg) | |
11200 | return; | |
11201 | ||
11202 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, | |
11203 | NL80211_CMD_SCHED_SCAN_RESULTS) < 0) { | |
11204 | nlmsg_free(msg); | |
11205 | return; | |
11206 | } | |
11207 | ||
68eb5503 | 11208 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11209 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11210 | } |
11211 | ||
11212 | void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev, | |
11213 | struct net_device *netdev, u32 cmd) | |
11214 | { | |
11215 | struct sk_buff *msg; | |
11216 | ||
58050fce | 11217 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
807f8a8c LC |
11218 | if (!msg) |
11219 | return; | |
11220 | ||
11221 | if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) { | |
11222 | nlmsg_free(msg); | |
11223 | return; | |
11224 | } | |
11225 | ||
68eb5503 | 11226 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11227 | NL80211_MCGRP_SCAN, GFP_KERNEL); |
807f8a8c LC |
11228 | } |
11229 | ||
b0d7aa59 JD |
11230 | static bool nl80211_reg_change_event_fill(struct sk_buff *msg, |
11231 | struct regulatory_request *request) | |
73d54c9e | 11232 | { |
73d54c9e | 11233 | /* Userspace can always count this one always being set */ |
9360ffd1 DM |
11234 | if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator)) |
11235 | goto nla_put_failure; | |
11236 | ||
11237 | if (request->alpha2[0] == '0' && request->alpha2[1] == '0') { | |
11238 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11239 | NL80211_REGDOM_TYPE_WORLD)) | |
11240 | goto nla_put_failure; | |
11241 | } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') { | |
11242 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11243 | NL80211_REGDOM_TYPE_CUSTOM_WORLD)) | |
11244 | goto nla_put_failure; | |
11245 | } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') || | |
11246 | request->intersect) { | |
11247 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11248 | NL80211_REGDOM_TYPE_INTERSECTION)) | |
11249 | goto nla_put_failure; | |
11250 | } else { | |
11251 | if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE, | |
11252 | NL80211_REGDOM_TYPE_COUNTRY) || | |
11253 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, | |
11254 | request->alpha2)) | |
11255 | goto nla_put_failure; | |
11256 | } | |
11257 | ||
ad30ca2c AN |
11258 | if (request->wiphy_idx != WIPHY_IDX_INVALID) { |
11259 | struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx); | |
11260 | ||
11261 | if (wiphy && | |
11262 | nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx)) | |
11263 | goto nla_put_failure; | |
1bdd716c AN |
11264 | |
11265 | if (wiphy && | |
11266 | wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED && | |
11267 | nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG)) | |
11268 | goto nla_put_failure; | |
ad30ca2c | 11269 | } |
73d54c9e | 11270 | |
b0d7aa59 JD |
11271 | return true; |
11272 | ||
11273 | nla_put_failure: | |
11274 | return false; | |
11275 | } | |
11276 | ||
11277 | /* | |
11278 | * This can happen on global regulatory changes or device specific settings | |
11279 | * based on custom regulatory domains. | |
11280 | */ | |
11281 | void nl80211_common_reg_change_event(enum nl80211_commands cmd_id, | |
11282 | struct regulatory_request *request) | |
11283 | { | |
11284 | struct sk_buff *msg; | |
11285 | void *hdr; | |
11286 | ||
11287 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
11288 | if (!msg) | |
11289 | return; | |
11290 | ||
11291 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id); | |
11292 | if (!hdr) { | |
11293 | nlmsg_free(msg); | |
11294 | return; | |
11295 | } | |
11296 | ||
11297 | if (nl80211_reg_change_event_fill(msg, request) == false) | |
11298 | goto nla_put_failure; | |
11299 | ||
3b7b72ee | 11300 | genlmsg_end(msg, hdr); |
73d54c9e | 11301 | |
bc43b28c | 11302 | rcu_read_lock(); |
68eb5503 | 11303 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11304 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
bc43b28c | 11305 | rcu_read_unlock(); |
73d54c9e LR |
11306 | |
11307 | return; | |
11308 | ||
11309 | nla_put_failure: | |
11310 | genlmsg_cancel(msg, hdr); | |
11311 | nlmsg_free(msg); | |
11312 | } | |
11313 | ||
6039f6d2 JM |
11314 | static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev, |
11315 | struct net_device *netdev, | |
11316 | const u8 *buf, size_t len, | |
b0b6aa2c EP |
11317 | enum nl80211_commands cmd, gfp_t gfp, |
11318 | int uapsd_queues) | |
6039f6d2 JM |
11319 | { |
11320 | struct sk_buff *msg; | |
11321 | void *hdr; | |
11322 | ||
e6d6e342 | 11323 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
6039f6d2 JM |
11324 | if (!msg) |
11325 | return; | |
11326 | ||
11327 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11328 | if (!hdr) { | |
11329 | nlmsg_free(msg); | |
11330 | return; | |
11331 | } | |
11332 | ||
9360ffd1 DM |
11333 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11334 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11335 | nla_put(msg, NL80211_ATTR_FRAME, len, buf)) | |
11336 | goto nla_put_failure; | |
6039f6d2 | 11337 | |
b0b6aa2c EP |
11338 | if (uapsd_queues >= 0) { |
11339 | struct nlattr *nla_wmm = | |
11340 | nla_nest_start(msg, NL80211_ATTR_STA_WME); | |
11341 | if (!nla_wmm) | |
11342 | goto nla_put_failure; | |
11343 | ||
11344 | if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | |
11345 | uapsd_queues)) | |
11346 | goto nla_put_failure; | |
11347 | ||
11348 | nla_nest_end(msg, nla_wmm); | |
11349 | } | |
11350 | ||
3b7b72ee | 11351 | genlmsg_end(msg, hdr); |
6039f6d2 | 11352 | |
68eb5503 | 11353 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11354 | NL80211_MCGRP_MLME, gfp); |
6039f6d2 JM |
11355 | return; |
11356 | ||
11357 | nla_put_failure: | |
11358 | genlmsg_cancel(msg, hdr); | |
11359 | nlmsg_free(msg); | |
11360 | } | |
11361 | ||
11362 | void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11363 | struct net_device *netdev, const u8 *buf, |
11364 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11365 | { |
11366 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11367 | NL80211_CMD_AUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11368 | } |
11369 | ||
11370 | void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev, | |
11371 | struct net_device *netdev, const u8 *buf, | |
b0b6aa2c | 11372 | size_t len, gfp_t gfp, int uapsd_queues) |
6039f6d2 | 11373 | { |
e6d6e342 | 11374 | nl80211_send_mlme_event(rdev, netdev, buf, len, |
b0b6aa2c | 11375 | NL80211_CMD_ASSOCIATE, gfp, uapsd_queues); |
6039f6d2 JM |
11376 | } |
11377 | ||
53b46b84 | 11378 | void nl80211_send_deauth(struct cfg80211_registered_device *rdev, |
e6d6e342 JB |
11379 | struct net_device *netdev, const u8 *buf, |
11380 | size_t len, gfp_t gfp) | |
6039f6d2 JM |
11381 | { |
11382 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11383 | NL80211_CMD_DEAUTHENTICATE, gfp, -1); |
6039f6d2 JM |
11384 | } |
11385 | ||
53b46b84 JM |
11386 | void nl80211_send_disassoc(struct cfg80211_registered_device *rdev, |
11387 | struct net_device *netdev, const u8 *buf, | |
e6d6e342 | 11388 | size_t len, gfp_t gfp) |
6039f6d2 JM |
11389 | { |
11390 | nl80211_send_mlme_event(rdev, netdev, buf, len, | |
b0b6aa2c | 11391 | NL80211_CMD_DISASSOCIATE, gfp, -1); |
6039f6d2 JM |
11392 | } |
11393 | ||
6ff57cf8 JB |
11394 | void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf, |
11395 | size_t len) | |
cf4e594e | 11396 | { |
947add36 JB |
11397 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11398 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 11399 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
6ff57cf8 JB |
11400 | const struct ieee80211_mgmt *mgmt = (void *)buf; |
11401 | u32 cmd; | |
947add36 | 11402 | |
6ff57cf8 JB |
11403 | if (WARN_ON(len < 2)) |
11404 | return; | |
cf4e594e | 11405 | |
6ff57cf8 JB |
11406 | if (ieee80211_is_deauth(mgmt->frame_control)) |
11407 | cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE; | |
11408 | else | |
11409 | cmd = NL80211_CMD_UNPROT_DISASSOCIATE; | |
947add36 | 11410 | |
6ff57cf8 | 11411 | trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len); |
b0b6aa2c | 11412 | nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1); |
cf4e594e | 11413 | } |
6ff57cf8 | 11414 | EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt); |
cf4e594e | 11415 | |
1b06bb40 LR |
11416 | static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev, |
11417 | struct net_device *netdev, int cmd, | |
e6d6e342 | 11418 | const u8 *addr, gfp_t gfp) |
1965c853 JM |
11419 | { |
11420 | struct sk_buff *msg; | |
11421 | void *hdr; | |
11422 | ||
e6d6e342 | 11423 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
1965c853 JM |
11424 | if (!msg) |
11425 | return; | |
11426 | ||
11427 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11428 | if (!hdr) { | |
11429 | nlmsg_free(msg); | |
11430 | return; | |
11431 | } | |
11432 | ||
9360ffd1 DM |
11433 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11434 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11435 | nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) || | |
11436 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11437 | goto nla_put_failure; | |
1965c853 | 11438 | |
3b7b72ee | 11439 | genlmsg_end(msg, hdr); |
1965c853 | 11440 | |
68eb5503 | 11441 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11442 | NL80211_MCGRP_MLME, gfp); |
1965c853 JM |
11443 | return; |
11444 | ||
11445 | nla_put_failure: | |
11446 | genlmsg_cancel(msg, hdr); | |
11447 | nlmsg_free(msg); | |
11448 | } | |
11449 | ||
11450 | void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11451 | struct net_device *netdev, const u8 *addr, |
11452 | gfp_t gfp) | |
1965c853 JM |
11453 | { |
11454 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE, | |
e6d6e342 | 11455 | addr, gfp); |
1965c853 JM |
11456 | } |
11457 | ||
11458 | void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev, | |
e6d6e342 JB |
11459 | struct net_device *netdev, const u8 *addr, |
11460 | gfp_t gfp) | |
1965c853 | 11461 | { |
e6d6e342 JB |
11462 | nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE, |
11463 | addr, gfp); | |
1965c853 JM |
11464 | } |
11465 | ||
b23aa676 SO |
11466 | void nl80211_send_connect_result(struct cfg80211_registered_device *rdev, |
11467 | struct net_device *netdev, const u8 *bssid, | |
11468 | const u8 *req_ie, size_t req_ie_len, | |
11469 | const u8 *resp_ie, size_t resp_ie_len, | |
11470 | u16 status, gfp_t gfp) | |
11471 | { | |
11472 | struct sk_buff *msg; | |
11473 | void *hdr; | |
11474 | ||
58050fce | 11475 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11476 | if (!msg) |
11477 | return; | |
11478 | ||
11479 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT); | |
11480 | if (!hdr) { | |
11481 | nlmsg_free(msg); | |
11482 | return; | |
11483 | } | |
11484 | ||
9360ffd1 DM |
11485 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11486 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11487 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) || | |
11488 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) || | |
11489 | (req_ie && | |
11490 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11491 | (resp_ie && | |
11492 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11493 | goto nla_put_failure; | |
b23aa676 | 11494 | |
3b7b72ee | 11495 | genlmsg_end(msg, hdr); |
b23aa676 | 11496 | |
68eb5503 | 11497 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11498 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11499 | return; |
11500 | ||
11501 | nla_put_failure: | |
11502 | genlmsg_cancel(msg, hdr); | |
11503 | nlmsg_free(msg); | |
11504 | ||
11505 | } | |
11506 | ||
11507 | void nl80211_send_roamed(struct cfg80211_registered_device *rdev, | |
11508 | struct net_device *netdev, const u8 *bssid, | |
11509 | const u8 *req_ie, size_t req_ie_len, | |
11510 | const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp) | |
11511 | { | |
11512 | struct sk_buff *msg; | |
11513 | void *hdr; | |
11514 | ||
58050fce | 11515 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
b23aa676 SO |
11516 | if (!msg) |
11517 | return; | |
11518 | ||
11519 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM); | |
11520 | if (!hdr) { | |
11521 | nlmsg_free(msg); | |
11522 | return; | |
11523 | } | |
11524 | ||
9360ffd1 DM |
11525 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11526 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11527 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) || | |
11528 | (req_ie && | |
11529 | nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) || | |
11530 | (resp_ie && | |
11531 | nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie))) | |
11532 | goto nla_put_failure; | |
b23aa676 | 11533 | |
3b7b72ee | 11534 | genlmsg_end(msg, hdr); |
b23aa676 | 11535 | |
68eb5503 | 11536 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11537 | NL80211_MCGRP_MLME, gfp); |
b23aa676 SO |
11538 | return; |
11539 | ||
11540 | nla_put_failure: | |
11541 | genlmsg_cancel(msg, hdr); | |
11542 | nlmsg_free(msg); | |
11543 | ||
11544 | } | |
11545 | ||
11546 | void nl80211_send_disconnected(struct cfg80211_registered_device *rdev, | |
11547 | struct net_device *netdev, u16 reason, | |
667503dd | 11548 | const u8 *ie, size_t ie_len, bool from_ap) |
b23aa676 SO |
11549 | { |
11550 | struct sk_buff *msg; | |
11551 | void *hdr; | |
11552 | ||
58050fce | 11553 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); |
b23aa676 SO |
11554 | if (!msg) |
11555 | return; | |
11556 | ||
11557 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT); | |
11558 | if (!hdr) { | |
11559 | nlmsg_free(msg); | |
11560 | return; | |
11561 | } | |
11562 | ||
9360ffd1 DM |
11563 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11564 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11565 | (from_ap && reason && | |
11566 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) || | |
11567 | (from_ap && | |
11568 | nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) || | |
11569 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) | |
11570 | goto nla_put_failure; | |
b23aa676 | 11571 | |
3b7b72ee | 11572 | genlmsg_end(msg, hdr); |
b23aa676 | 11573 | |
68eb5503 | 11574 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11575 | NL80211_MCGRP_MLME, GFP_KERNEL); |
b23aa676 SO |
11576 | return; |
11577 | ||
11578 | nla_put_failure: | |
11579 | genlmsg_cancel(msg, hdr); | |
11580 | nlmsg_free(msg); | |
11581 | ||
11582 | } | |
11583 | ||
04a773ad JB |
11584 | void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev, |
11585 | struct net_device *netdev, const u8 *bssid, | |
11586 | gfp_t gfp) | |
11587 | { | |
11588 | struct sk_buff *msg; | |
11589 | void *hdr; | |
11590 | ||
fd2120ca | 11591 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
04a773ad JB |
11592 | if (!msg) |
11593 | return; | |
11594 | ||
11595 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS); | |
11596 | if (!hdr) { | |
11597 | nlmsg_free(msg); | |
11598 | return; | |
11599 | } | |
11600 | ||
9360ffd1 DM |
11601 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11602 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11603 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
11604 | goto nla_put_failure; | |
04a773ad | 11605 | |
3b7b72ee | 11606 | genlmsg_end(msg, hdr); |
04a773ad | 11607 | |
68eb5503 | 11608 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11609 | NL80211_MCGRP_MLME, gfp); |
04a773ad JB |
11610 | return; |
11611 | ||
11612 | nla_put_failure: | |
11613 | genlmsg_cancel(msg, hdr); | |
11614 | nlmsg_free(msg); | |
11615 | } | |
11616 | ||
947add36 JB |
11617 | void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr, |
11618 | const u8* ie, u8 ie_len, gfp_t gfp) | |
c93b5e71 | 11619 | { |
947add36 | 11620 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
f26cbf40 | 11621 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
c93b5e71 JC |
11622 | struct sk_buff *msg; |
11623 | void *hdr; | |
11624 | ||
947add36 JB |
11625 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT)) |
11626 | return; | |
11627 | ||
11628 | trace_cfg80211_notify_new_peer_candidate(dev, addr); | |
11629 | ||
c93b5e71 JC |
11630 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
11631 | if (!msg) | |
11632 | return; | |
11633 | ||
11634 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE); | |
11635 | if (!hdr) { | |
11636 | nlmsg_free(msg); | |
11637 | return; | |
11638 | } | |
11639 | ||
9360ffd1 | 11640 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 JB |
11641 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || |
11642 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
9360ffd1 DM |
11643 | (ie_len && ie && |
11644 | nla_put(msg, NL80211_ATTR_IE, ie_len , ie))) | |
11645 | goto nla_put_failure; | |
c93b5e71 | 11646 | |
3b7b72ee | 11647 | genlmsg_end(msg, hdr); |
c93b5e71 | 11648 | |
68eb5503 | 11649 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11650 | NL80211_MCGRP_MLME, gfp); |
c93b5e71 JC |
11651 | return; |
11652 | ||
11653 | nla_put_failure: | |
11654 | genlmsg_cancel(msg, hdr); | |
11655 | nlmsg_free(msg); | |
11656 | } | |
947add36 | 11657 | EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate); |
c93b5e71 | 11658 | |
a3b8b056 JM |
11659 | void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev, |
11660 | struct net_device *netdev, const u8 *addr, | |
11661 | enum nl80211_key_type key_type, int key_id, | |
e6d6e342 | 11662 | const u8 *tsc, gfp_t gfp) |
a3b8b056 JM |
11663 | { |
11664 | struct sk_buff *msg; | |
11665 | void *hdr; | |
11666 | ||
e6d6e342 | 11667 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
a3b8b056 JM |
11668 | if (!msg) |
11669 | return; | |
11670 | ||
11671 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE); | |
11672 | if (!hdr) { | |
11673 | nlmsg_free(msg); | |
11674 | return; | |
11675 | } | |
11676 | ||
9360ffd1 DM |
11677 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11678 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
11679 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | |
11680 | nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) || | |
11681 | (key_id != -1 && | |
11682 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) || | |
11683 | (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc))) | |
11684 | goto nla_put_failure; | |
a3b8b056 | 11685 | |
3b7b72ee | 11686 | genlmsg_end(msg, hdr); |
a3b8b056 | 11687 | |
68eb5503 | 11688 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11689 | NL80211_MCGRP_MLME, gfp); |
a3b8b056 JM |
11690 | return; |
11691 | ||
11692 | nla_put_failure: | |
11693 | genlmsg_cancel(msg, hdr); | |
11694 | nlmsg_free(msg); | |
11695 | } | |
11696 | ||
6bad8766 LR |
11697 | void nl80211_send_beacon_hint_event(struct wiphy *wiphy, |
11698 | struct ieee80211_channel *channel_before, | |
11699 | struct ieee80211_channel *channel_after) | |
11700 | { | |
11701 | struct sk_buff *msg; | |
11702 | void *hdr; | |
11703 | struct nlattr *nl_freq; | |
11704 | ||
fd2120ca | 11705 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC); |
6bad8766 LR |
11706 | if (!msg) |
11707 | return; | |
11708 | ||
11709 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT); | |
11710 | if (!hdr) { | |
11711 | nlmsg_free(msg); | |
11712 | return; | |
11713 | } | |
11714 | ||
11715 | /* | |
11716 | * Since we are applying the beacon hint to a wiphy we know its | |
11717 | * wiphy_idx is valid | |
11718 | */ | |
9360ffd1 DM |
11719 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy))) |
11720 | goto nla_put_failure; | |
6bad8766 LR |
11721 | |
11722 | /* Before */ | |
11723 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE); | |
11724 | if (!nl_freq) | |
11725 | goto nla_put_failure; | |
cdc89b97 | 11726 | if (nl80211_msg_put_channel(msg, channel_before, false)) |
6bad8766 LR |
11727 | goto nla_put_failure; |
11728 | nla_nest_end(msg, nl_freq); | |
11729 | ||
11730 | /* After */ | |
11731 | nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER); | |
11732 | if (!nl_freq) | |
11733 | goto nla_put_failure; | |
cdc89b97 | 11734 | if (nl80211_msg_put_channel(msg, channel_after, false)) |
6bad8766 LR |
11735 | goto nla_put_failure; |
11736 | nla_nest_end(msg, nl_freq); | |
11737 | ||
3b7b72ee | 11738 | genlmsg_end(msg, hdr); |
6bad8766 | 11739 | |
463d0183 | 11740 | rcu_read_lock(); |
68eb5503 | 11741 | genlmsg_multicast_allns(&nl80211_fam, msg, 0, |
2a94fe48 | 11742 | NL80211_MCGRP_REGULATORY, GFP_ATOMIC); |
463d0183 | 11743 | rcu_read_unlock(); |
6bad8766 LR |
11744 | |
11745 | return; | |
11746 | ||
11747 | nla_put_failure: | |
11748 | genlmsg_cancel(msg, hdr); | |
11749 | nlmsg_free(msg); | |
11750 | } | |
11751 | ||
9588bbd5 JM |
11752 | static void nl80211_send_remain_on_chan_event( |
11753 | int cmd, struct cfg80211_registered_device *rdev, | |
71bbc994 | 11754 | struct wireless_dev *wdev, u64 cookie, |
9588bbd5 | 11755 | struct ieee80211_channel *chan, |
9588bbd5 JM |
11756 | unsigned int duration, gfp_t gfp) |
11757 | { | |
11758 | struct sk_buff *msg; | |
11759 | void *hdr; | |
11760 | ||
11761 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
11762 | if (!msg) | |
11763 | return; | |
11764 | ||
11765 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); | |
11766 | if (!hdr) { | |
11767 | nlmsg_free(msg); | |
11768 | return; | |
11769 | } | |
11770 | ||
9360ffd1 | 11771 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
11772 | (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
11773 | wdev->netdev->ifindex)) || | |
00f53350 | 11774 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 | 11775 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) || |
42d97a59 JB |
11776 | nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
11777 | NL80211_CHAN_NO_HT) || | |
9360ffd1 DM |
11778 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) |
11779 | goto nla_put_failure; | |
9588bbd5 | 11780 | |
9360ffd1 DM |
11781 | if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL && |
11782 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) | |
11783 | goto nla_put_failure; | |
9588bbd5 | 11784 | |
3b7b72ee | 11785 | genlmsg_end(msg, hdr); |
9588bbd5 | 11786 | |
68eb5503 | 11787 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11788 | NL80211_MCGRP_MLME, gfp); |
9588bbd5 JM |
11789 | return; |
11790 | ||
11791 | nla_put_failure: | |
11792 | genlmsg_cancel(msg, hdr); | |
11793 | nlmsg_free(msg); | |
11794 | } | |
11795 | ||
947add36 JB |
11796 | void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie, |
11797 | struct ieee80211_channel *chan, | |
11798 | unsigned int duration, gfp_t gfp) | |
9588bbd5 | 11799 | { |
947add36 | 11800 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11801 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11802 | |
11803 | trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration); | |
9588bbd5 | 11804 | nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL, |
71bbc994 | 11805 | rdev, wdev, cookie, chan, |
42d97a59 | 11806 | duration, gfp); |
9588bbd5 | 11807 | } |
947add36 | 11808 | EXPORT_SYMBOL(cfg80211_ready_on_channel); |
9588bbd5 | 11809 | |
947add36 JB |
11810 | void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie, |
11811 | struct ieee80211_channel *chan, | |
11812 | gfp_t gfp) | |
9588bbd5 | 11813 | { |
947add36 | 11814 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 11815 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
11816 | |
11817 | trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan); | |
9588bbd5 | 11818 | nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL, |
42d97a59 | 11819 | rdev, wdev, cookie, chan, 0, gfp); |
9588bbd5 | 11820 | } |
947add36 | 11821 | EXPORT_SYMBOL(cfg80211_remain_on_channel_expired); |
9588bbd5 | 11822 | |
947add36 JB |
11823 | void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr, |
11824 | struct station_info *sinfo, gfp_t gfp) | |
98b62183 | 11825 | { |
947add36 | 11826 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11827 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
98b62183 JB |
11828 | struct sk_buff *msg; |
11829 | ||
947add36 JB |
11830 | trace_cfg80211_new_sta(dev, mac_addr, sinfo); |
11831 | ||
58050fce | 11832 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
98b62183 JB |
11833 | if (!msg) |
11834 | return; | |
11835 | ||
cf5ead82 | 11836 | if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0, |
66266b3a | 11837 | rdev, dev, mac_addr, sinfo) < 0) { |
98b62183 JB |
11838 | nlmsg_free(msg); |
11839 | return; | |
11840 | } | |
11841 | ||
68eb5503 | 11842 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11843 | NL80211_MCGRP_MLME, gfp); |
98b62183 | 11844 | } |
947add36 | 11845 | EXPORT_SYMBOL(cfg80211_new_sta); |
98b62183 | 11846 | |
cf5ead82 JB |
11847 | void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr, |
11848 | struct station_info *sinfo, gfp_t gfp) | |
ec15e68b | 11849 | { |
947add36 | 11850 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11851 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ec15e68b | 11852 | struct sk_buff *msg; |
cf5ead82 JB |
11853 | struct station_info empty_sinfo = {}; |
11854 | ||
11855 | if (!sinfo) | |
11856 | sinfo = &empty_sinfo; | |
ec15e68b | 11857 | |
947add36 JB |
11858 | trace_cfg80211_del_sta(dev, mac_addr); |
11859 | ||
58050fce | 11860 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
ec15e68b JM |
11861 | if (!msg) |
11862 | return; | |
11863 | ||
cf5ead82 | 11864 | if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0, |
57007121 | 11865 | rdev, dev, mac_addr, sinfo) < 0) { |
ec15e68b JM |
11866 | nlmsg_free(msg); |
11867 | return; | |
11868 | } | |
11869 | ||
68eb5503 | 11870 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11871 | NL80211_MCGRP_MLME, gfp); |
ec15e68b | 11872 | } |
cf5ead82 | 11873 | EXPORT_SYMBOL(cfg80211_del_sta_sinfo); |
ec15e68b | 11874 | |
947add36 JB |
11875 | void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr, |
11876 | enum nl80211_connect_failed_reason reason, | |
11877 | gfp_t gfp) | |
ed44a951 | 11878 | { |
947add36 | 11879 | struct wiphy *wiphy = dev->ieee80211_ptr->wiphy; |
f26cbf40 | 11880 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
ed44a951 PP |
11881 | struct sk_buff *msg; |
11882 | void *hdr; | |
11883 | ||
11884 | msg = nlmsg_new(NLMSG_GOODSIZE, gfp); | |
11885 | if (!msg) | |
11886 | return; | |
11887 | ||
11888 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED); | |
11889 | if (!hdr) { | |
11890 | nlmsg_free(msg); | |
11891 | return; | |
11892 | } | |
11893 | ||
11894 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11895 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) || | |
11896 | nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason)) | |
11897 | goto nla_put_failure; | |
11898 | ||
11899 | genlmsg_end(msg, hdr); | |
11900 | ||
68eb5503 | 11901 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 11902 | NL80211_MCGRP_MLME, gfp); |
ed44a951 PP |
11903 | return; |
11904 | ||
11905 | nla_put_failure: | |
11906 | genlmsg_cancel(msg, hdr); | |
11907 | nlmsg_free(msg); | |
11908 | } | |
947add36 | 11909 | EXPORT_SYMBOL(cfg80211_conn_failed); |
ed44a951 | 11910 | |
b92ab5d8 JB |
11911 | static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd, |
11912 | const u8 *addr, gfp_t gfp) | |
28946da7 JB |
11913 | { |
11914 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 11915 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
28946da7 JB |
11916 | struct sk_buff *msg; |
11917 | void *hdr; | |
15e47304 | 11918 | u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid); |
28946da7 | 11919 | |
15e47304 | 11920 | if (!nlportid) |
28946da7 JB |
11921 | return false; |
11922 | ||
11923 | msg = nlmsg_new(100, gfp); | |
11924 | if (!msg) | |
11925 | return true; | |
11926 | ||
b92ab5d8 | 11927 | hdr = nl80211hdr_put(msg, 0, 0, 0, cmd); |
28946da7 JB |
11928 | if (!hdr) { |
11929 | nlmsg_free(msg); | |
11930 | return true; | |
11931 | } | |
11932 | ||
9360ffd1 DM |
11933 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
11934 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
11935 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | |
11936 | goto nla_put_failure; | |
28946da7 | 11937 | |
9c90a9f6 | 11938 | genlmsg_end(msg, hdr); |
15e47304 | 11939 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
28946da7 JB |
11940 | return true; |
11941 | ||
11942 | nla_put_failure: | |
11943 | genlmsg_cancel(msg, hdr); | |
11944 | nlmsg_free(msg); | |
11945 | return true; | |
11946 | } | |
11947 | ||
947add36 JB |
11948 | bool cfg80211_rx_spurious_frame(struct net_device *dev, |
11949 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11950 | { |
947add36 JB |
11951 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11952 | bool ret; | |
11953 | ||
11954 | trace_cfg80211_rx_spurious_frame(dev, addr); | |
11955 | ||
11956 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11957 | wdev->iftype != NL80211_IFTYPE_P2P_GO)) { | |
11958 | trace_cfg80211_return_bool(false); | |
11959 | return false; | |
11960 | } | |
11961 | ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME, | |
11962 | addr, gfp); | |
11963 | trace_cfg80211_return_bool(ret); | |
11964 | return ret; | |
b92ab5d8 | 11965 | } |
947add36 | 11966 | EXPORT_SYMBOL(cfg80211_rx_spurious_frame); |
b92ab5d8 | 11967 | |
947add36 JB |
11968 | bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev, |
11969 | const u8 *addr, gfp_t gfp) | |
b92ab5d8 | 11970 | { |
947add36 JB |
11971 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
11972 | bool ret; | |
11973 | ||
11974 | trace_cfg80211_rx_unexpected_4addr_frame(dev, addr); | |
11975 | ||
11976 | if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP && | |
11977 | wdev->iftype != NL80211_IFTYPE_P2P_GO && | |
11978 | wdev->iftype != NL80211_IFTYPE_AP_VLAN)) { | |
11979 | trace_cfg80211_return_bool(false); | |
11980 | return false; | |
11981 | } | |
11982 | ret = __nl80211_unexpected_frame(dev, | |
11983 | NL80211_CMD_UNEXPECTED_4ADDR_FRAME, | |
11984 | addr, gfp); | |
11985 | trace_cfg80211_return_bool(ret); | |
11986 | return ret; | |
b92ab5d8 | 11987 | } |
947add36 | 11988 | EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame); |
b92ab5d8 | 11989 | |
2e161f78 | 11990 | int nl80211_send_mgmt(struct cfg80211_registered_device *rdev, |
15e47304 | 11991 | struct wireless_dev *wdev, u32 nlportid, |
804483e9 | 11992 | int freq, int sig_dbm, |
19504cf5 | 11993 | const u8 *buf, size_t len, u32 flags, gfp_t gfp) |
026331c4 | 11994 | { |
71bbc994 | 11995 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
11996 | struct sk_buff *msg; |
11997 | void *hdr; | |
026331c4 JM |
11998 | |
11999 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12000 | if (!msg) | |
12001 | return -ENOMEM; | |
12002 | ||
2e161f78 | 12003 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
026331c4 JM |
12004 | if (!hdr) { |
12005 | nlmsg_free(msg); | |
12006 | return -ENOMEM; | |
12007 | } | |
12008 | ||
9360ffd1 | 12009 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12010 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12011 | netdev->ifindex)) || | |
a838490b | 12012 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
12013 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
12014 | (sig_dbm && | |
12015 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
19504cf5 VK |
12016 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
12017 | (flags && | |
12018 | nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags))) | |
9360ffd1 | 12019 | goto nla_put_failure; |
026331c4 | 12020 | |
3b7b72ee | 12021 | genlmsg_end(msg, hdr); |
026331c4 | 12022 | |
15e47304 | 12023 | return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); |
026331c4 JM |
12024 | |
12025 | nla_put_failure: | |
12026 | genlmsg_cancel(msg, hdr); | |
12027 | nlmsg_free(msg); | |
12028 | return -ENOBUFS; | |
12029 | } | |
12030 | ||
947add36 JB |
12031 | void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie, |
12032 | const u8 *buf, size_t len, bool ack, gfp_t gfp) | |
026331c4 | 12033 | { |
947add36 | 12034 | struct wiphy *wiphy = wdev->wiphy; |
f26cbf40 | 12035 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
71bbc994 | 12036 | struct net_device *netdev = wdev->netdev; |
026331c4 JM |
12037 | struct sk_buff *msg; |
12038 | void *hdr; | |
12039 | ||
947add36 JB |
12040 | trace_cfg80211_mgmt_tx_status(wdev, cookie, ack); |
12041 | ||
026331c4 JM |
12042 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
12043 | if (!msg) | |
12044 | return; | |
12045 | ||
2e161f78 | 12046 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS); |
026331c4 JM |
12047 | if (!hdr) { |
12048 | nlmsg_free(msg); | |
12049 | return; | |
12050 | } | |
12051 | ||
9360ffd1 | 12052 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
71bbc994 JB |
12053 | (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, |
12054 | netdev->ifindex)) || | |
a838490b | 12055 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) || |
9360ffd1 DM |
12056 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
12057 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12058 | (ack && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12059 | goto nla_put_failure; | |
026331c4 | 12060 | |
3b7b72ee | 12061 | genlmsg_end(msg, hdr); |
026331c4 | 12062 | |
68eb5503 | 12063 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12064 | NL80211_MCGRP_MLME, gfp); |
026331c4 JM |
12065 | return; |
12066 | ||
12067 | nla_put_failure: | |
12068 | genlmsg_cancel(msg, hdr); | |
12069 | nlmsg_free(msg); | |
12070 | } | |
947add36 | 12071 | EXPORT_SYMBOL(cfg80211_mgmt_tx_status); |
026331c4 | 12072 | |
5b97f49d JB |
12073 | static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev, |
12074 | const char *mac, gfp_t gfp) | |
d6dc1a38 | 12075 | { |
947add36 | 12076 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
5b97f49d JB |
12077 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
12078 | struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12079 | void **cb; | |
947add36 | 12080 | |
d6dc1a38 | 12081 | if (!msg) |
5b97f49d | 12082 | return NULL; |
d6dc1a38 | 12083 | |
5b97f49d JB |
12084 | cb = (void **)msg->cb; |
12085 | ||
12086 | cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM); | |
12087 | if (!cb[0]) { | |
d6dc1a38 | 12088 | nlmsg_free(msg); |
5b97f49d | 12089 | return NULL; |
d6dc1a38 JO |
12090 | } |
12091 | ||
9360ffd1 | 12092 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
947add36 | 12093 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex)) |
9360ffd1 | 12094 | goto nla_put_failure; |
d6dc1a38 | 12095 | |
5b97f49d | 12096 | if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac)) |
d6dc1a38 JO |
12097 | goto nla_put_failure; |
12098 | ||
5b97f49d JB |
12099 | cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM); |
12100 | if (!cb[1]) | |
9360ffd1 | 12101 | goto nla_put_failure; |
d6dc1a38 | 12102 | |
5b97f49d | 12103 | cb[2] = rdev; |
d6dc1a38 | 12104 | |
5b97f49d JB |
12105 | return msg; |
12106 | nla_put_failure: | |
12107 | nlmsg_free(msg); | |
12108 | return NULL; | |
12109 | } | |
12110 | ||
12111 | static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp) | |
12112 | { | |
12113 | void **cb = (void **)msg->cb; | |
12114 | struct cfg80211_registered_device *rdev = cb[2]; | |
12115 | ||
12116 | nla_nest_end(msg, cb[1]); | |
12117 | genlmsg_end(msg, cb[0]); | |
12118 | ||
12119 | memset(msg->cb, 0, sizeof(msg->cb)); | |
d6dc1a38 | 12120 | |
68eb5503 | 12121 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12122 | NL80211_MCGRP_MLME, gfp); |
5b97f49d JB |
12123 | } |
12124 | ||
12125 | void cfg80211_cqm_rssi_notify(struct net_device *dev, | |
12126 | enum nl80211_cqm_rssi_threshold_event rssi_event, | |
12127 | gfp_t gfp) | |
12128 | { | |
12129 | struct sk_buff *msg; | |
12130 | ||
12131 | trace_cfg80211_cqm_rssi_notify(dev, rssi_event); | |
12132 | ||
98f03342 JB |
12133 | if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW && |
12134 | rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH)) | |
12135 | return; | |
12136 | ||
5b97f49d JB |
12137 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); |
12138 | if (!msg) | |
12139 | return; | |
12140 | ||
12141 | if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT, | |
12142 | rssi_event)) | |
12143 | goto nla_put_failure; | |
12144 | ||
12145 | cfg80211_send_cqm(msg, gfp); | |
12146 | ||
d6dc1a38 JO |
12147 | return; |
12148 | ||
12149 | nla_put_failure: | |
d6dc1a38 JO |
12150 | nlmsg_free(msg); |
12151 | } | |
947add36 | 12152 | EXPORT_SYMBOL(cfg80211_cqm_rssi_notify); |
d6dc1a38 | 12153 | |
5b97f49d JB |
12154 | void cfg80211_cqm_txe_notify(struct net_device *dev, |
12155 | const u8 *peer, u32 num_packets, | |
12156 | u32 rate, u32 intvl, gfp_t gfp) | |
12157 | { | |
12158 | struct sk_buff *msg; | |
12159 | ||
12160 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12161 | if (!msg) | |
12162 | return; | |
12163 | ||
12164 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets)) | |
12165 | goto nla_put_failure; | |
12166 | ||
12167 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate)) | |
12168 | goto nla_put_failure; | |
12169 | ||
12170 | if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl)) | |
12171 | goto nla_put_failure; | |
12172 | ||
12173 | cfg80211_send_cqm(msg, gfp); | |
12174 | return; | |
12175 | ||
12176 | nla_put_failure: | |
12177 | nlmsg_free(msg); | |
12178 | } | |
12179 | EXPORT_SYMBOL(cfg80211_cqm_txe_notify); | |
12180 | ||
12181 | void cfg80211_cqm_pktloss_notify(struct net_device *dev, | |
12182 | const u8 *peer, u32 num_packets, gfp_t gfp) | |
12183 | { | |
12184 | struct sk_buff *msg; | |
12185 | ||
12186 | trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets); | |
12187 | ||
12188 | msg = cfg80211_prepare_cqm(dev, peer, gfp); | |
12189 | if (!msg) | |
12190 | return; | |
12191 | ||
12192 | if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets)) | |
12193 | goto nla_put_failure; | |
12194 | ||
12195 | cfg80211_send_cqm(msg, gfp); | |
12196 | return; | |
12197 | ||
12198 | nla_put_failure: | |
12199 | nlmsg_free(msg); | |
12200 | } | |
12201 | EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify); | |
12202 | ||
98f03342 JB |
12203 | void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp) |
12204 | { | |
12205 | struct sk_buff *msg; | |
12206 | ||
12207 | msg = cfg80211_prepare_cqm(dev, NULL, gfp); | |
12208 | if (!msg) | |
12209 | return; | |
12210 | ||
12211 | if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT)) | |
12212 | goto nla_put_failure; | |
12213 | ||
12214 | cfg80211_send_cqm(msg, gfp); | |
12215 | return; | |
12216 | ||
12217 | nla_put_failure: | |
12218 | nlmsg_free(msg); | |
12219 | } | |
12220 | EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify); | |
12221 | ||
947add36 JB |
12222 | static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev, |
12223 | struct net_device *netdev, const u8 *bssid, | |
12224 | const u8 *replay_ctr, gfp_t gfp) | |
e5497d76 JB |
12225 | { |
12226 | struct sk_buff *msg; | |
12227 | struct nlattr *rekey_attr; | |
12228 | void *hdr; | |
12229 | ||
58050fce | 12230 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
e5497d76 JB |
12231 | if (!msg) |
12232 | return; | |
12233 | ||
12234 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD); | |
12235 | if (!hdr) { | |
12236 | nlmsg_free(msg); | |
12237 | return; | |
12238 | } | |
12239 | ||
9360ffd1 DM |
12240 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12241 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12242 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) | |
12243 | goto nla_put_failure; | |
e5497d76 JB |
12244 | |
12245 | rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA); | |
12246 | if (!rekey_attr) | |
12247 | goto nla_put_failure; | |
12248 | ||
9360ffd1 DM |
12249 | if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, |
12250 | NL80211_REPLAY_CTR_LEN, replay_ctr)) | |
12251 | goto nla_put_failure; | |
e5497d76 JB |
12252 | |
12253 | nla_nest_end(msg, rekey_attr); | |
12254 | ||
3b7b72ee | 12255 | genlmsg_end(msg, hdr); |
e5497d76 | 12256 | |
68eb5503 | 12257 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12258 | NL80211_MCGRP_MLME, gfp); |
e5497d76 JB |
12259 | return; |
12260 | ||
12261 | nla_put_failure: | |
12262 | genlmsg_cancel(msg, hdr); | |
12263 | nlmsg_free(msg); | |
12264 | } | |
12265 | ||
947add36 JB |
12266 | void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid, |
12267 | const u8 *replay_ctr, gfp_t gfp) | |
12268 | { | |
12269 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12270 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12271 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12272 | |
12273 | trace_cfg80211_gtk_rekey_notify(dev, bssid); | |
12274 | nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp); | |
12275 | } | |
12276 | EXPORT_SYMBOL(cfg80211_gtk_rekey_notify); | |
12277 | ||
12278 | static void | |
12279 | nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev, | |
12280 | struct net_device *netdev, int index, | |
12281 | const u8 *bssid, bool preauth, gfp_t gfp) | |
c9df56b4 JM |
12282 | { |
12283 | struct sk_buff *msg; | |
12284 | struct nlattr *attr; | |
12285 | void *hdr; | |
12286 | ||
58050fce | 12287 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
c9df56b4 JM |
12288 | if (!msg) |
12289 | return; | |
12290 | ||
12291 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE); | |
12292 | if (!hdr) { | |
12293 | nlmsg_free(msg); | |
12294 | return; | |
12295 | } | |
12296 | ||
9360ffd1 DM |
12297 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12298 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) | |
12299 | goto nla_put_failure; | |
c9df56b4 JM |
12300 | |
12301 | attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE); | |
12302 | if (!attr) | |
12303 | goto nla_put_failure; | |
12304 | ||
9360ffd1 DM |
12305 | if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) || |
12306 | nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) || | |
12307 | (preauth && | |
12308 | nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH))) | |
12309 | goto nla_put_failure; | |
c9df56b4 JM |
12310 | |
12311 | nla_nest_end(msg, attr); | |
12312 | ||
3b7b72ee | 12313 | genlmsg_end(msg, hdr); |
c9df56b4 | 12314 | |
68eb5503 | 12315 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12316 | NL80211_MCGRP_MLME, gfp); |
c9df56b4 JM |
12317 | return; |
12318 | ||
12319 | nla_put_failure: | |
12320 | genlmsg_cancel(msg, hdr); | |
12321 | nlmsg_free(msg); | |
12322 | } | |
12323 | ||
947add36 JB |
12324 | void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index, |
12325 | const u8 *bssid, bool preauth, gfp_t gfp) | |
12326 | { | |
12327 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12328 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12329 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 JB |
12330 | |
12331 | trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth); | |
12332 | nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp); | |
12333 | } | |
12334 | EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify); | |
12335 | ||
12336 | static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev, | |
12337 | struct net_device *netdev, | |
12338 | struct cfg80211_chan_def *chandef, | |
f8d7552e LC |
12339 | gfp_t gfp, |
12340 | enum nl80211_commands notif, | |
12341 | u8 count) | |
5314526b TP |
12342 | { |
12343 | struct sk_buff *msg; | |
12344 | void *hdr; | |
12345 | ||
58050fce | 12346 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
5314526b TP |
12347 | if (!msg) |
12348 | return; | |
12349 | ||
f8d7552e | 12350 | hdr = nl80211hdr_put(msg, 0, 0, 0, notif); |
5314526b TP |
12351 | if (!hdr) { |
12352 | nlmsg_free(msg); | |
12353 | return; | |
12354 | } | |
12355 | ||
683b6d3b JB |
12356 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex)) |
12357 | goto nla_put_failure; | |
12358 | ||
12359 | if (nl80211_send_chandef(msg, chandef)) | |
7eab0f64 | 12360 | goto nla_put_failure; |
5314526b | 12361 | |
f8d7552e LC |
12362 | if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) && |
12363 | (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count))) | |
12364 | goto nla_put_failure; | |
12365 | ||
5314526b TP |
12366 | genlmsg_end(msg, hdr); |
12367 | ||
68eb5503 | 12368 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12369 | NL80211_MCGRP_MLME, gfp); |
5314526b TP |
12370 | return; |
12371 | ||
12372 | nla_put_failure: | |
12373 | genlmsg_cancel(msg, hdr); | |
12374 | nlmsg_free(msg); | |
12375 | } | |
12376 | ||
947add36 JB |
12377 | void cfg80211_ch_switch_notify(struct net_device *dev, |
12378 | struct cfg80211_chan_def *chandef) | |
84f10708 | 12379 | { |
947add36 JB |
12380 | struct wireless_dev *wdev = dev->ieee80211_ptr; |
12381 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12382 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
947add36 | 12383 | |
e487eaeb | 12384 | ASSERT_WDEV_LOCK(wdev); |
947add36 | 12385 | |
e487eaeb | 12386 | trace_cfg80211_ch_switch_notify(dev, chandef); |
947add36 | 12387 | |
9e0e2961 | 12388 | wdev->chandef = *chandef; |
96f55f12 | 12389 | wdev->preset_chandef = *chandef; |
f8d7552e LC |
12390 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, |
12391 | NL80211_CMD_CH_SWITCH_NOTIFY, 0); | |
947add36 JB |
12392 | } |
12393 | EXPORT_SYMBOL(cfg80211_ch_switch_notify); | |
12394 | ||
f8d7552e LC |
12395 | void cfg80211_ch_switch_started_notify(struct net_device *dev, |
12396 | struct cfg80211_chan_def *chandef, | |
12397 | u8 count) | |
12398 | { | |
12399 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
12400 | struct wiphy *wiphy = wdev->wiphy; | |
12401 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); | |
12402 | ||
12403 | trace_cfg80211_ch_switch_started_notify(dev, chandef); | |
12404 | ||
12405 | nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL, | |
12406 | NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count); | |
12407 | } | |
12408 | EXPORT_SYMBOL(cfg80211_ch_switch_started_notify); | |
12409 | ||
04f39047 SW |
12410 | void |
12411 | nl80211_radar_notify(struct cfg80211_registered_device *rdev, | |
d2859df5 | 12412 | const struct cfg80211_chan_def *chandef, |
04f39047 SW |
12413 | enum nl80211_radar_event event, |
12414 | struct net_device *netdev, gfp_t gfp) | |
12415 | { | |
12416 | struct sk_buff *msg; | |
12417 | void *hdr; | |
12418 | ||
12419 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12420 | if (!msg) | |
12421 | return; | |
12422 | ||
12423 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT); | |
12424 | if (!hdr) { | |
12425 | nlmsg_free(msg); | |
12426 | return; | |
12427 | } | |
12428 | ||
12429 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx)) | |
12430 | goto nla_put_failure; | |
12431 | ||
12432 | /* NOP and radar events don't need a netdev parameter */ | |
12433 | if (netdev) { | |
12434 | struct wireless_dev *wdev = netdev->ieee80211_ptr; | |
12435 | ||
12436 | if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12437 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12438 | goto nla_put_failure; | |
12439 | } | |
12440 | ||
12441 | if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event)) | |
12442 | goto nla_put_failure; | |
12443 | ||
12444 | if (nl80211_send_chandef(msg, chandef)) | |
12445 | goto nla_put_failure; | |
12446 | ||
9c90a9f6 | 12447 | genlmsg_end(msg, hdr); |
04f39047 | 12448 | |
68eb5503 | 12449 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12450 | NL80211_MCGRP_MLME, gfp); |
04f39047 SW |
12451 | return; |
12452 | ||
12453 | nla_put_failure: | |
12454 | genlmsg_cancel(msg, hdr); | |
12455 | nlmsg_free(msg); | |
12456 | } | |
12457 | ||
7f6cf311 JB |
12458 | void cfg80211_probe_status(struct net_device *dev, const u8 *addr, |
12459 | u64 cookie, bool acked, gfp_t gfp) | |
12460 | { | |
12461 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12462 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
7f6cf311 JB |
12463 | struct sk_buff *msg; |
12464 | void *hdr; | |
7f6cf311 | 12465 | |
4ee3e063 BL |
12466 | trace_cfg80211_probe_status(dev, addr, cookie, acked); |
12467 | ||
58050fce | 12468 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); |
4ee3e063 | 12469 | |
7f6cf311 JB |
12470 | if (!msg) |
12471 | return; | |
12472 | ||
12473 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT); | |
12474 | if (!hdr) { | |
12475 | nlmsg_free(msg); | |
12476 | return; | |
12477 | } | |
12478 | ||
9360ffd1 DM |
12479 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12480 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12481 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | |
12482 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) || | |
12483 | (acked && nla_put_flag(msg, NL80211_ATTR_ACK))) | |
12484 | goto nla_put_failure; | |
7f6cf311 | 12485 | |
9c90a9f6 | 12486 | genlmsg_end(msg, hdr); |
7f6cf311 | 12487 | |
68eb5503 | 12488 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12489 | NL80211_MCGRP_MLME, gfp); |
7f6cf311 JB |
12490 | return; |
12491 | ||
12492 | nla_put_failure: | |
12493 | genlmsg_cancel(msg, hdr); | |
12494 | nlmsg_free(msg); | |
12495 | } | |
12496 | EXPORT_SYMBOL(cfg80211_probe_status); | |
12497 | ||
5e760230 JB |
12498 | void cfg80211_report_obss_beacon(struct wiphy *wiphy, |
12499 | const u8 *frame, size_t len, | |
37c73b5f | 12500 | int freq, int sig_dbm) |
5e760230 | 12501 | { |
f26cbf40 | 12502 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
5e760230 JB |
12503 | struct sk_buff *msg; |
12504 | void *hdr; | |
37c73b5f | 12505 | struct cfg80211_beacon_registration *reg; |
5e760230 | 12506 | |
4ee3e063 BL |
12507 | trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm); |
12508 | ||
37c73b5f BG |
12509 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12510 | list_for_each_entry(reg, &rdev->beacon_registrations, list) { | |
12511 | msg = nlmsg_new(len + 100, GFP_ATOMIC); | |
12512 | if (!msg) { | |
12513 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
12514 | return; | |
12515 | } | |
5e760230 | 12516 | |
37c73b5f BG |
12517 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME); |
12518 | if (!hdr) | |
12519 | goto nla_put_failure; | |
5e760230 | 12520 | |
37c73b5f BG |
12521 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12522 | (freq && | |
12523 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | |
12524 | (sig_dbm && | |
12525 | nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) || | |
12526 | nla_put(msg, NL80211_ATTR_FRAME, len, frame)) | |
12527 | goto nla_put_failure; | |
5e760230 | 12528 | |
37c73b5f | 12529 | genlmsg_end(msg, hdr); |
5e760230 | 12530 | |
37c73b5f BG |
12531 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid); |
12532 | } | |
12533 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
5e760230 JB |
12534 | return; |
12535 | ||
12536 | nla_put_failure: | |
37c73b5f BG |
12537 | spin_unlock_bh(&rdev->beacon_registrations_lock); |
12538 | if (hdr) | |
12539 | genlmsg_cancel(msg, hdr); | |
5e760230 JB |
12540 | nlmsg_free(msg); |
12541 | } | |
12542 | EXPORT_SYMBOL(cfg80211_report_obss_beacon); | |
12543 | ||
cd8f7cb4 | 12544 | #ifdef CONFIG_PM |
8cd4d456 LC |
12545 | static int cfg80211_net_detect_results(struct sk_buff *msg, |
12546 | struct cfg80211_wowlan_wakeup *wakeup) | |
12547 | { | |
12548 | struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect; | |
12549 | struct nlattr *nl_results, *nl_match, *nl_freqs; | |
12550 | int i, j; | |
12551 | ||
12552 | nl_results = nla_nest_start( | |
12553 | msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS); | |
12554 | if (!nl_results) | |
12555 | return -EMSGSIZE; | |
12556 | ||
12557 | for (i = 0; i < nd->n_matches; i++) { | |
12558 | struct cfg80211_wowlan_nd_match *match = nd->matches[i]; | |
12559 | ||
12560 | nl_match = nla_nest_start(msg, i); | |
12561 | if (!nl_match) | |
12562 | break; | |
12563 | ||
12564 | /* The SSID attribute is optional in nl80211, but for | |
12565 | * simplicity reasons it's always present in the | |
12566 | * cfg80211 structure. If a driver can't pass the | |
12567 | * SSID, that needs to be changed. A zero length SSID | |
12568 | * is still a valid SSID (wildcard), so it cannot be | |
12569 | * used for this purpose. | |
12570 | */ | |
12571 | if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len, | |
12572 | match->ssid.ssid)) { | |
12573 | nla_nest_cancel(msg, nl_match); | |
12574 | goto out; | |
12575 | } | |
12576 | ||
12577 | if (match->n_channels) { | |
12578 | nl_freqs = nla_nest_start( | |
12579 | msg, NL80211_ATTR_SCAN_FREQUENCIES); | |
12580 | if (!nl_freqs) { | |
12581 | nla_nest_cancel(msg, nl_match); | |
12582 | goto out; | |
12583 | } | |
12584 | ||
12585 | for (j = 0; j < match->n_channels; j++) { | |
12586 | if (nla_put_u32(msg, | |
12587 | NL80211_ATTR_WIPHY_FREQ, | |
12588 | match->channels[j])) { | |
12589 | nla_nest_cancel(msg, nl_freqs); | |
12590 | nla_nest_cancel(msg, nl_match); | |
12591 | goto out; | |
12592 | } | |
12593 | } | |
12594 | ||
12595 | nla_nest_end(msg, nl_freqs); | |
12596 | } | |
12597 | ||
12598 | nla_nest_end(msg, nl_match); | |
12599 | } | |
12600 | ||
12601 | out: | |
12602 | nla_nest_end(msg, nl_results); | |
12603 | return 0; | |
12604 | } | |
12605 | ||
cd8f7cb4 JB |
12606 | void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev, |
12607 | struct cfg80211_wowlan_wakeup *wakeup, | |
12608 | gfp_t gfp) | |
12609 | { | |
f26cbf40 | 12610 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
cd8f7cb4 JB |
12611 | struct sk_buff *msg; |
12612 | void *hdr; | |
9c90a9f6 | 12613 | int size = 200; |
cd8f7cb4 JB |
12614 | |
12615 | trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup); | |
12616 | ||
12617 | if (wakeup) | |
12618 | size += wakeup->packet_present_len; | |
12619 | ||
12620 | msg = nlmsg_new(size, gfp); | |
12621 | if (!msg) | |
12622 | return; | |
12623 | ||
12624 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN); | |
12625 | if (!hdr) | |
12626 | goto free_msg; | |
12627 | ||
12628 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12629 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12630 | goto free_msg; | |
12631 | ||
12632 | if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX, | |
12633 | wdev->netdev->ifindex)) | |
12634 | goto free_msg; | |
12635 | ||
12636 | if (wakeup) { | |
12637 | struct nlattr *reasons; | |
12638 | ||
12639 | reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS); | |
7fa322c8 JB |
12640 | if (!reasons) |
12641 | goto free_msg; | |
cd8f7cb4 JB |
12642 | |
12643 | if (wakeup->disconnect && | |
12644 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) | |
12645 | goto free_msg; | |
12646 | if (wakeup->magic_pkt && | |
12647 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) | |
12648 | goto free_msg; | |
12649 | if (wakeup->gtk_rekey_failure && | |
12650 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) | |
12651 | goto free_msg; | |
12652 | if (wakeup->eap_identity_req && | |
12653 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) | |
12654 | goto free_msg; | |
12655 | if (wakeup->four_way_handshake && | |
12656 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) | |
12657 | goto free_msg; | |
12658 | if (wakeup->rfkill_release && | |
12659 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)) | |
12660 | goto free_msg; | |
12661 | ||
12662 | if (wakeup->pattern_idx >= 0 && | |
12663 | nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN, | |
12664 | wakeup->pattern_idx)) | |
12665 | goto free_msg; | |
12666 | ||
ae917c9f JB |
12667 | if (wakeup->tcp_match && |
12668 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH)) | |
12669 | goto free_msg; | |
2a0e047e | 12670 | |
ae917c9f JB |
12671 | if (wakeup->tcp_connlost && |
12672 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST)) | |
12673 | goto free_msg; | |
2a0e047e | 12674 | |
ae917c9f JB |
12675 | if (wakeup->tcp_nomoretokens && |
12676 | nla_put_flag(msg, | |
12677 | NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS)) | |
12678 | goto free_msg; | |
2a0e047e | 12679 | |
cd8f7cb4 JB |
12680 | if (wakeup->packet) { |
12681 | u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211; | |
12682 | u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN; | |
12683 | ||
12684 | if (!wakeup->packet_80211) { | |
12685 | pkt_attr = | |
12686 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023; | |
12687 | len_attr = | |
12688 | NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN; | |
12689 | } | |
12690 | ||
12691 | if (wakeup->packet_len && | |
12692 | nla_put_u32(msg, len_attr, wakeup->packet_len)) | |
12693 | goto free_msg; | |
12694 | ||
12695 | if (nla_put(msg, pkt_attr, wakeup->packet_present_len, | |
12696 | wakeup->packet)) | |
12697 | goto free_msg; | |
12698 | } | |
12699 | ||
8cd4d456 LC |
12700 | if (wakeup->net_detect && |
12701 | cfg80211_net_detect_results(msg, wakeup)) | |
12702 | goto free_msg; | |
12703 | ||
cd8f7cb4 JB |
12704 | nla_nest_end(msg, reasons); |
12705 | } | |
12706 | ||
9c90a9f6 | 12707 | genlmsg_end(msg, hdr); |
cd8f7cb4 | 12708 | |
68eb5503 | 12709 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12710 | NL80211_MCGRP_MLME, gfp); |
cd8f7cb4 JB |
12711 | return; |
12712 | ||
12713 | free_msg: | |
12714 | nlmsg_free(msg); | |
12715 | } | |
12716 | EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup); | |
12717 | #endif | |
12718 | ||
3475b094 JM |
12719 | void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer, |
12720 | enum nl80211_tdls_operation oper, | |
12721 | u16 reason_code, gfp_t gfp) | |
12722 | { | |
12723 | struct wireless_dev *wdev = dev->ieee80211_ptr; | |
f26cbf40 | 12724 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy); |
3475b094 JM |
12725 | struct sk_buff *msg; |
12726 | void *hdr; | |
3475b094 JM |
12727 | |
12728 | trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper, | |
12729 | reason_code); | |
12730 | ||
12731 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12732 | if (!msg) | |
12733 | return; | |
12734 | ||
12735 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER); | |
12736 | if (!hdr) { | |
12737 | nlmsg_free(msg); | |
12738 | return; | |
12739 | } | |
12740 | ||
12741 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12742 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) || | |
12743 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) || | |
12744 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) || | |
12745 | (reason_code > 0 && | |
12746 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) | |
12747 | goto nla_put_failure; | |
12748 | ||
9c90a9f6 | 12749 | genlmsg_end(msg, hdr); |
3475b094 | 12750 | |
68eb5503 | 12751 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12752 | NL80211_MCGRP_MLME, gfp); |
3475b094 JM |
12753 | return; |
12754 | ||
12755 | nla_put_failure: | |
12756 | genlmsg_cancel(msg, hdr); | |
12757 | nlmsg_free(msg); | |
12758 | } | |
12759 | EXPORT_SYMBOL(cfg80211_tdls_oper_request); | |
12760 | ||
026331c4 JM |
12761 | static int nl80211_netlink_notify(struct notifier_block * nb, |
12762 | unsigned long state, | |
12763 | void *_notify) | |
12764 | { | |
12765 | struct netlink_notify *notify = _notify; | |
12766 | struct cfg80211_registered_device *rdev; | |
12767 | struct wireless_dev *wdev; | |
37c73b5f | 12768 | struct cfg80211_beacon_registration *reg, *tmp; |
026331c4 JM |
12769 | |
12770 | if (state != NETLINK_URELEASE) | |
12771 | return NOTIFY_DONE; | |
12772 | ||
12773 | rcu_read_lock(); | |
12774 | ||
5e760230 | 12775 | list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) { |
78f22b6a | 12776 | bool schedule_destroy_work = false; |
93a1e86c JR |
12777 | bool schedule_scan_stop = false; |
12778 | struct cfg80211_sched_scan_request *sched_scan_req = | |
12779 | rcu_dereference(rdev->sched_scan_req); | |
12780 | ||
12781 | if (sched_scan_req && notify->portid && | |
12782 | sched_scan_req->owner_nlportid == notify->portid) | |
12783 | schedule_scan_stop = true; | |
78f22b6a JB |
12784 | |
12785 | list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) { | |
15e47304 | 12786 | cfg80211_mlme_unregister_socket(wdev, notify->portid); |
37c73b5f | 12787 | |
78f22b6a JB |
12788 | if (wdev->owner_nlportid == notify->portid) |
12789 | schedule_destroy_work = true; | |
12790 | } | |
12791 | ||
37c73b5f BG |
12792 | spin_lock_bh(&rdev->beacon_registrations_lock); |
12793 | list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations, | |
12794 | list) { | |
12795 | if (reg->nlportid == notify->portid) { | |
12796 | list_del(®->list); | |
12797 | kfree(reg); | |
12798 | break; | |
12799 | } | |
12800 | } | |
12801 | spin_unlock_bh(&rdev->beacon_registrations_lock); | |
78f22b6a JB |
12802 | |
12803 | if (schedule_destroy_work) { | |
12804 | struct cfg80211_iface_destroy *destroy; | |
12805 | ||
12806 | destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC); | |
12807 | if (destroy) { | |
12808 | destroy->nlportid = notify->portid; | |
12809 | spin_lock(&rdev->destroy_list_lock); | |
12810 | list_add(&destroy->list, &rdev->destroy_list); | |
12811 | spin_unlock(&rdev->destroy_list_lock); | |
12812 | schedule_work(&rdev->destroy_work); | |
12813 | } | |
93a1e86c JR |
12814 | } else if (schedule_scan_stop) { |
12815 | sched_scan_req->owner_nlportid = 0; | |
12816 | ||
12817 | if (rdev->ops->sched_scan_stop && | |
12818 | rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) | |
12819 | schedule_work(&rdev->sched_scan_stop_wk); | |
78f22b6a | 12820 | } |
5e760230 | 12821 | } |
026331c4 JM |
12822 | |
12823 | rcu_read_unlock(); | |
12824 | ||
05050753 I |
12825 | /* |
12826 | * It is possible that the user space process that is controlling the | |
12827 | * indoor setting disappeared, so notify the regulatory core. | |
12828 | */ | |
12829 | regulatory_netlink_notify(notify->portid); | |
6784c7db | 12830 | return NOTIFY_OK; |
026331c4 JM |
12831 | } |
12832 | ||
12833 | static struct notifier_block nl80211_netlink_notifier = { | |
12834 | .notifier_call = nl80211_netlink_notify, | |
12835 | }; | |
12836 | ||
355199e0 JM |
12837 | void cfg80211_ft_event(struct net_device *netdev, |
12838 | struct cfg80211_ft_event_params *ft_event) | |
12839 | { | |
12840 | struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy; | |
f26cbf40 | 12841 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
355199e0 JM |
12842 | struct sk_buff *msg; |
12843 | void *hdr; | |
355199e0 JM |
12844 | |
12845 | trace_cfg80211_ft_event(wiphy, netdev, ft_event); | |
12846 | ||
12847 | if (!ft_event->target_ap) | |
12848 | return; | |
12849 | ||
12850 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12851 | if (!msg) | |
12852 | return; | |
12853 | ||
12854 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT); | |
ae917c9f JB |
12855 | if (!hdr) |
12856 | goto out; | |
355199e0 | 12857 | |
ae917c9f JB |
12858 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || |
12859 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) || | |
12860 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap)) | |
12861 | goto out; | |
355199e0 | 12862 | |
ae917c9f JB |
12863 | if (ft_event->ies && |
12864 | nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies)) | |
12865 | goto out; | |
12866 | if (ft_event->ric_ies && | |
12867 | nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len, | |
12868 | ft_event->ric_ies)) | |
12869 | goto out; | |
355199e0 | 12870 | |
9c90a9f6 | 12871 | genlmsg_end(msg, hdr); |
355199e0 | 12872 | |
68eb5503 | 12873 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0, |
2a94fe48 | 12874 | NL80211_MCGRP_MLME, GFP_KERNEL); |
ae917c9f JB |
12875 | return; |
12876 | out: | |
12877 | nlmsg_free(msg); | |
355199e0 JM |
12878 | } |
12879 | EXPORT_SYMBOL(cfg80211_ft_event); | |
12880 | ||
5de17984 AS |
12881 | void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp) |
12882 | { | |
12883 | struct cfg80211_registered_device *rdev; | |
12884 | struct sk_buff *msg; | |
12885 | void *hdr; | |
12886 | u32 nlportid; | |
12887 | ||
f26cbf40 | 12888 | rdev = wiphy_to_rdev(wdev->wiphy); |
5de17984 AS |
12889 | if (!rdev->crit_proto_nlportid) |
12890 | return; | |
12891 | ||
12892 | nlportid = rdev->crit_proto_nlportid; | |
12893 | rdev->crit_proto_nlportid = 0; | |
12894 | ||
12895 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp); | |
12896 | if (!msg) | |
12897 | return; | |
12898 | ||
12899 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP); | |
12900 | if (!hdr) | |
12901 | goto nla_put_failure; | |
12902 | ||
12903 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12904 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12905 | goto nla_put_failure; | |
12906 | ||
12907 | genlmsg_end(msg, hdr); | |
12908 | ||
12909 | genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid); | |
12910 | return; | |
12911 | ||
12912 | nla_put_failure: | |
12913 | if (hdr) | |
12914 | genlmsg_cancel(msg, hdr); | |
12915 | nlmsg_free(msg); | |
12916 | ||
12917 | } | |
12918 | EXPORT_SYMBOL(cfg80211_crit_proto_stopped); | |
12919 | ||
348baf0e JB |
12920 | void nl80211_send_ap_stopped(struct wireless_dev *wdev) |
12921 | { | |
12922 | struct wiphy *wiphy = wdev->wiphy; | |
f26cbf40 | 12923 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
348baf0e JB |
12924 | struct sk_buff *msg; |
12925 | void *hdr; | |
12926 | ||
12927 | msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); | |
12928 | if (!msg) | |
12929 | return; | |
12930 | ||
12931 | hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP); | |
12932 | if (!hdr) | |
12933 | goto out; | |
12934 | ||
12935 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) || | |
12936 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) || | |
12937 | nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev))) | |
12938 | goto out; | |
12939 | ||
12940 | genlmsg_end(msg, hdr); | |
12941 | ||
12942 | genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0, | |
12943 | NL80211_MCGRP_MLME, GFP_KERNEL); | |
12944 | return; | |
12945 | out: | |
12946 | nlmsg_free(msg); | |
12947 | } | |
12948 | ||
55682965 JB |
12949 | /* initialisation/exit functions */ |
12950 | ||
12951 | int nl80211_init(void) | |
12952 | { | |
0d63cbb5 | 12953 | int err; |
55682965 | 12954 | |
2a94fe48 JB |
12955 | err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops, |
12956 | nl80211_mcgrps); | |
55682965 JB |
12957 | if (err) |
12958 | return err; | |
12959 | ||
026331c4 JM |
12960 | err = netlink_register_notifier(&nl80211_netlink_notifier); |
12961 | if (err) | |
12962 | goto err_out; | |
12963 | ||
55682965 JB |
12964 | return 0; |
12965 | err_out: | |
12966 | genl_unregister_family(&nl80211_fam); | |
12967 | return err; | |
12968 | } | |
12969 | ||
12970 | void nl80211_exit(void) | |
12971 | { | |
026331c4 | 12972 | netlink_unregister_notifier(&nl80211_netlink_notifier); |
55682965 JB |
12973 | genl_unregister_family(&nl80211_fam); |
12974 | } |